v1.0
This commit is contained in:
parent
a956c1e10e
commit
a483471152
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 6.0.0, 2021-12-16T13:42:03. -->
|
||||
<!-- Written by QtCreator 6.0.0, 2021-12-16T21:38:54. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
|
||||
163
mainwindow.cpp
163
mainwindow.cpp
@ -7,15 +7,23 @@
|
||||
#define LABEL_Y 30
|
||||
#define LINE_X 200
|
||||
#define LINE_Y 30
|
||||
#define X 30
|
||||
#define Y 500
|
||||
#define SIZE 100
|
||||
|
||||
QString filepath=QDir::currentPath();
|
||||
QStringList K;
|
||||
QStringList Sigma;
|
||||
QStringList Gamma;
|
||||
QStringList Q0;
|
||||
QStringList B;
|
||||
QStringList F;
|
||||
|
||||
QString function[SIZE][5];
|
||||
|
||||
QString q;
|
||||
int now;
|
||||
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
@ -114,13 +122,24 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
btn_step->setText("下一步");
|
||||
|
||||
//纸带
|
||||
for(int i=0;i<24;i++)
|
||||
for(int i=0;i<25;i++)
|
||||
{
|
||||
label[i]=new MyLabel(this);
|
||||
label[i]->setPos(30+40*i,500);
|
||||
label[i]->setPos(X+40*i,Y);
|
||||
label[i]->hide();
|
||||
}
|
||||
|
||||
label_now=new MyLabel(this);
|
||||
label_now->setStyleSheet("border-width: 2px;border-style: solid;border-color: rgb(236, 255, 251);background-color: rgb(20, 250, 20);");
|
||||
label_now->setFixedSize(40,35);
|
||||
label_now->hide();
|
||||
|
||||
label_fun = new QLabel(this);
|
||||
label_fun->setGeometry(X+50,Y-40, 500,30);
|
||||
label_fun->setAlignment(Qt::AlignCenter);
|
||||
label_fun->setText("状态转移函数:");
|
||||
|
||||
//connect
|
||||
QObject::connect(btn_import, SIGNAL(clicked()), this, SLOT(importFile()));
|
||||
QObject::connect(btn_confirm, SIGNAL(clicked()), this, SLOT(startSimulate()));
|
||||
QObject::connect(btn_step, SIGNAL(clicked()), this, SLOT(nextStep()));
|
||||
@ -133,33 +152,59 @@ MainWindow::~MainWindow()
|
||||
|
||||
void MainWindow::importFile()
|
||||
{
|
||||
qDebug()<<"import1";
|
||||
K.clear();
|
||||
Sigma.clear();
|
||||
Gamma.clear();
|
||||
Q0.clear();
|
||||
B.clear();
|
||||
F.clear();
|
||||
int row=list_file->currentRow();
|
||||
list_func->clear();
|
||||
QFile file(filepath + "/" + QString::number(row) + ".txt");
|
||||
qDebug()<<"import3";
|
||||
if(file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
QTextStream in(&file);
|
||||
QString temp;
|
||||
int i=0;
|
||||
while(1)
|
||||
{
|
||||
temp=in.readLine();
|
||||
if(temp.size()==0)
|
||||
break;
|
||||
break;
|
||||
qDebug()<<"import1";
|
||||
QStringList list = temp.split(" ");
|
||||
list_func->addItem(" δ(q"+list[0]+","+list[1]+")=(q"+list[2]+","+list[3]+","+list[4]+") ");
|
||||
append(&K,"q"+list[0]);
|
||||
append(&Sigma,list[1]);
|
||||
qDebug()<<"import2";
|
||||
list[0]="q"+list[0];
|
||||
if(list.size()>2)
|
||||
list[2]="q"+list[2];
|
||||
qDebug()<<"import3";
|
||||
if(list.contains("#"))
|
||||
append(&F,"q"+list[0]);
|
||||
{
|
||||
function[i][0]=list[0];
|
||||
function[i][1]=list[1];
|
||||
}
|
||||
else
|
||||
for(int j=0;j<5;j++)
|
||||
function[i][j]=list[j];
|
||||
qDebug()<<"import4";
|
||||
if(list.contains("#"))
|
||||
append(&F,list[0]);
|
||||
else
|
||||
{
|
||||
qDebug()<<"import6";
|
||||
list_func->addItem(" δ("+list[0]+","+list[1]+")=("+list[2]+","+list[3]+","+list[4]+") ");
|
||||
append(&K,list[0]);
|
||||
append(&Sigma,list[1]);
|
||||
qDebug()<<"import7";
|
||||
}
|
||||
qDebug()<<"import5"<<i;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
QString k,sigma,q0,b,f;
|
||||
qDebug()<<"import126";
|
||||
|
||||
q0="q0";
|
||||
for(int i=0;i<K.size();i++)
|
||||
@ -169,6 +214,7 @@ void MainWindow::importFile()
|
||||
for(int i=0;i<F.size();i++)
|
||||
f+=(F[i]+" ");
|
||||
b="B";
|
||||
Q0.append("q0");
|
||||
|
||||
line_k->setText(k);
|
||||
line_sigma->setText(sigma);
|
||||
@ -181,24 +227,84 @@ void MainWindow::importFile()
|
||||
line_q0->setEnabled(false);
|
||||
line_B->setEnabled(false);
|
||||
line_F->setEnabled(false);
|
||||
|
||||
qDebug()<<"import12";
|
||||
}
|
||||
|
||||
void MainWindow::startSimulate()
|
||||
{
|
||||
QString str=line_str->text();
|
||||
for(int i=0;i<25;i++)
|
||||
label[i]->hide();
|
||||
//qDebug()<<"1";
|
||||
if(line_str->text().length()==0)
|
||||
return;
|
||||
str="BBB"+line_str->text()+"BB";
|
||||
label[2]->setText("B");
|
||||
label[2]->show();
|
||||
for(int i=0;i<str.length();i++)
|
||||
{
|
||||
label[i+3]->setText(str[i]);
|
||||
label[i+3]->show();
|
||||
label[i+4]->setText("B");
|
||||
label[i+4]->show();
|
||||
}
|
||||
// for(int i=3;i<str.length();i++)
|
||||
// {
|
||||
// label[i]->setText(str[i]);
|
||||
// label[i]->show();
|
||||
// }
|
||||
|
||||
now = 3;
|
||||
label_now->setPos(X+40*3,Y+55);
|
||||
label_now->show();
|
||||
|
||||
q=Q0[0];
|
||||
label_now->setText(q);
|
||||
|
||||
update(0);
|
||||
}
|
||||
|
||||
void MainWindow::nextStep()
|
||||
{
|
||||
bool flag=false;
|
||||
QChar c = str[now];
|
||||
QString comp;
|
||||
qDebug()<<"next0";
|
||||
comp+=c;
|
||||
qDebug()<<"next1";
|
||||
for(int i=0;i<SIZE;i++)
|
||||
{
|
||||
qDebug()<<"next2";
|
||||
qDebug()<<q<<function[i][0];
|
||||
if(function[i][0]==q&&function[i][1]==comp)
|
||||
{
|
||||
flag=true;
|
||||
qDebug()<<"next3";
|
||||
q=function[i][2];
|
||||
str[now]=function[i][3][0];
|
||||
label_fun->setText("δ("+function[i][0]+","+function[i][1]+")=("+function[i][2]+","+function[i][3]+","+function[i][4]+")");
|
||||
qDebug()<<("δ("+function[i][0]+","+function[i][1]+")=("+function[i][2]+","+function[i][3]+","+function[i][4]+")");
|
||||
if(comp=="B" && now==str.length()-1)
|
||||
{
|
||||
str+="B";
|
||||
}
|
||||
|
||||
if(function[i][4]=="R"){
|
||||
now++;
|
||||
update(1);
|
||||
}else if(function[i][4]=="L"){
|
||||
now--;
|
||||
update(-1);
|
||||
}else{
|
||||
update(0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if(function[i][0].length()==0)
|
||||
break;
|
||||
}
|
||||
if(flag==false)
|
||||
QMessageBox::warning(0 , " 失败! ", " 失败! ",QMessageBox::Ok | QMessageBox::Default , QMessageBox::Cancel | QMessageBox::Escape );
|
||||
|
||||
if(F.contains(q))
|
||||
{
|
||||
QMessageBox::information(0 , " 成功! "," 成功! ", QMessageBox::Ok | QMessageBox::Default , QMessageBox::Cancel | QMessageBox::Escape );
|
||||
//终止状态
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::loadFileList()
|
||||
@ -230,3 +336,26 @@ void MainWindow::append(QStringList* list,QString in)
|
||||
if(flag==0)
|
||||
list->append(in);
|
||||
}
|
||||
|
||||
void MainWindow::update(int move_q)
|
||||
{
|
||||
|
||||
label_now->setPos(label_now->pos().width()+move_q*40,label_now->pos().height());
|
||||
label_now->setText(q);
|
||||
qDebug()<<"update"<<move_q;
|
||||
for(int i=0;i<str.length();i++)
|
||||
{
|
||||
label[i]->setText(str[i]);
|
||||
label[i]->show();
|
||||
if(i<=2&&str[i]=='B'&&str[i+1]=='B')
|
||||
label[i]->hide();
|
||||
if(i==str.length()-2&&str[i]=='B')
|
||||
{
|
||||
label[i]->setText(str[i+1]);
|
||||
label[i]->show();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
qDebug()<<"ipdate2";
|
||||
}
|
||||
|
||||
@ -33,11 +33,12 @@ public:
|
||||
~MainWindow();
|
||||
void loadFileList();
|
||||
void append(QStringList* list,QString in);
|
||||
|
||||
void update(int move_q);
|
||||
public slots:
|
||||
void nextStep();
|
||||
void importFile();
|
||||
void startSimulate();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
QLabel *label_k,*label_sigma,*label_gamma,*label_q0,*label_B,*label_F;
|
||||
@ -49,7 +50,9 @@ private:
|
||||
QGroupBox *group_1;
|
||||
QListWidget *list_file,*list_func;
|
||||
QPushButton *btn_import,*btn_confirm,*btn_step;
|
||||
|
||||
QString str;
|
||||
MyLabel* label[25];
|
||||
MyLabel* label_now;
|
||||
QLabel* label_fun;
|
||||
};
|
||||
#endif // MAINWINDOW_H
|
||||
|
||||
15
mylabel.cpp
15
mylabel.cpp
@ -46,3 +46,18 @@ void MyLabel::setPos(int x,int y)
|
||||
{
|
||||
label->setGeometry(x,y,40,55);
|
||||
}
|
||||
|
||||
void MyLabel::setStyleSheet(QString sheet)
|
||||
{
|
||||
label->setStyleSheet(sheet);
|
||||
}
|
||||
|
||||
void MyLabel::setFixedSize(int x, int y)
|
||||
{
|
||||
label->setFixedSize(x,y);
|
||||
}
|
||||
|
||||
QSize MyLabel::pos()
|
||||
{
|
||||
return QSize(label->geometry().x(),label->geometry().y());
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
#include <QMainWindow>
|
||||
#include <QFont>
|
||||
#include <QFrame>
|
||||
|
||||
#include <QSize>
|
||||
class MyLabel
|
||||
{
|
||||
public:
|
||||
@ -18,10 +18,11 @@ public:
|
||||
void hide();
|
||||
void show();
|
||||
void setPos(int x,int y);
|
||||
void setStyleSheet(QString sheet);
|
||||
void setFixedSize(int x,int y);
|
||||
QSize pos();
|
||||
private:
|
||||
QLabel *label;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // MYLABEL_H
|
||||
|
||||
Loading…
Reference in New Issue
Block a user