Skip to content

Commit 4d6172b

Browse files
author
navrkald
committed
Functionality to begin/end in stepping mode.
* Self arrow is now visible when selected by dashed line. * Tooltips to FA editing buttons. * Make fully functional formal editor of FA. * Add functionality when delete symol from FA in formal and internal view, then deletes all transitions with this deleted symbol.
1 parent 1ec881a commit 4d6172b

File tree

9 files changed

+166
-41
lines changed

9 files changed

+166
-41
lines changed

RegularConvertor/algorithms/fatodfa.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ FaToDFA::FaToDFA(modes _mode, AlgorithmWidget* _algorithm_widget, FA_widget* _no
6363
connect(this->algorithm_widget, SIGNAL(showCorrectSolutionPressed()), this, SLOT(showCorrectSolution()));
6464
connect(this->algorithm_widget, SIGNAL(showUserSolutionPressed()), this, SLOT(showUserSolution()));
6565
connect(this->algorithm_widget, SIGNAL(beginPressed()), this, SLOT(toBegin()));
66-
connect(this->algorithm_widget, SIGNAL(beginPressed()), this, SLOT(toEnd()));
66+
connect(this->algorithm_widget, SIGNAL(endPressed()), this, SLOT(toEnd()));
6767

6868
//
6969
// Connect timers.
@@ -409,12 +409,37 @@ void FaToDFA::showUserSolution()
409409

410410
void FaToDFA::toBegin()
411411
{
412-
not_dfa_widget->setFA(new FiniteAutomata(FA));
412+
algorithm_widget->enableNext();
413+
actPos=0;
414+
steps s = history.at(actPos);
415+
416+
num = s.num ;
417+
actInstruction = s.actInstruction;
418+
prewInstruction = s.prewInstruction;
419+
DFA = s.DFA;
420+
dfa_widget->setFA(new FiniteAutomata(DFA));
421+
act_state = s.act_state;
422+
discovered_state = s.discovered_state;
423+
Q_new = s.Q_new;
424+
a = s.a;
425+
p = s.p;
426+
q = s.q;
427+
r = s.r;
428+
r_prime = s.r_prime;
429+
alphabet = s.alphabet;
430+
rules = s.rules;
431+
rules_prime = s.rules_prime;
432+
433+
showVariables();
434+
setActInstruction();
435+
dfa_widget->clearStatus();
436+
algorithm_widget->disablePrev();
413437
}
414438

415439
void FaToDFA::toEnd()
416440
{
417-
runAlgorithm(0);
441+
while(actInstruction != last_instruction)
442+
nextStep();
418443
}
419444

420445
void FaToDFA::removeFuture()

RegularConvertor/algorithms/regexptofa.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ RegExpToFA::RegExpToFA(AlgorithmWidget* _algorithm_widget, modes _mode, RegExpWi
8484
connect(this->algorithm_widget, SIGNAL(showCorrectSolutionPressed()), this, SLOT(showCorrectSolution()));
8585
connect(this->algorithm_widget, SIGNAL(showUserSolutionPressed()), this, SLOT(showUserSolution()));
8686
connect(this->algorithm_widget, SIGNAL(beginPressed()), this, SLOT(toBegin()));
87-
connect(this->algorithm_widget, SIGNAL(beginPressed()), this, SLOT(toEnd()));
87+
connect(this->algorithm_widget, SIGNAL(endPressed()), this, SLOT(toEnd()));
8888

8989
//
9090
// Connect timers.
@@ -448,13 +448,22 @@ void RegExpToFA::setExample(RegExp *_re)
448448

449449
void RegExpToFA::toBegin()
450450
{
451-
re_widget->setRegExp(re);
451+
actPos=0;
452+
num = history.at(actPos).num;
453+
actInstruction = history.at(actPos).actInstruction;
454+
RegExp* tmp_re = history.at(actPos).re;
455+
re_widget->setRegExp(new RegExp(*tmp_re));
456+
452457
re_widget->modelChanged();
458+
setActInstruction();
453459
}
454460

455461
void RegExpToFA::toEnd()
456462
{
457-
runAlgorithm(0);
463+
while(!nodesToProcede.empty())
464+
{
465+
nextStep();
466+
}
458467
}
459468

460469

RegularConvertor/algorithms/removeepsilon.cpp

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ RemoveEpsilon::RemoveEpsilon(modes _mode, AlgorithmWidget* _algorithm_widget, FA
7171
connect(this->algorithm_widget, SIGNAL(showCorrectSolutionPressed()), this, SLOT(showCorrectSolution()));
7272
connect(this->algorithm_widget, SIGNAL(showUserSolutionPressed()), this, SLOT(showUserSolution()));
7373
connect(this->algorithm_widget, SIGNAL(beginPressed()), this, SLOT(toBegin()));
74-
connect(this->algorithm_widget, SIGNAL(beginPressed()), this, SLOT(toEnd()));
74+
connect(this->algorithm_widget, SIGNAL(endPressed()), this, SLOT(toEnd()));
7575

7676
//
7777
// Connect timers.
@@ -403,8 +403,6 @@ void RemoveEpsilon::prevStep()
403403
prewInstruction = s.prewInstruction;
404404
non_epsilon_FA = s.non_epsilon_FA;
405405
not_epsilon_fa_widget->setFA(new FiniteAutomata(non_epsilon_FA));
406-
// epsilon_closer_list_widget = s.epsilon_closer_list_widget;
407-
// epsilon_closer_list_widget->setParent((QWidget*)s.parrent);
408406
p = s.p;
409407
p_prime = s.p_prime;
410408
non_epsilon_rule = s.non_epsilon_rule;
@@ -580,12 +578,34 @@ void RemoveEpsilon::showUserSolution()
580578

581579
void RemoveEpsilon::toBegin()
582580
{
583-
epsilon_fa_widget->setFA(new FiniteAutomata(FA));
581+
algorithm_widget->enableNext();
582+
actPos = 0;
583+
steps s = history.at(actPos);
584+
num = s.num;
585+
actInstruction = s.actInstruction;
586+
prewInstruction = s.prewInstruction;
587+
non_epsilon_FA = s.non_epsilon_FA;
588+
not_epsilon_fa_widget->setFA(new FiniteAutomata(non_epsilon_FA));
589+
p = s.p;
590+
p_prime = s.p_prime;
591+
non_epsilon_rule = s.non_epsilon_rule;
592+
non_epsilon_prime_rule = s.non_epsilon_prime_rule;
593+
epsilon_closer = s.epsilon_closer;
594+
epsilon_closers = s.epsilon_closers;
595+
p_list = s.p_list;
596+
p_prime_list = s.p_prime_list;
597+
non_epsilon_rule_list = s.non_epsilon_rule_list;
598+
showVariables();
599+
setActInstruction();
600+
setEpsilonCloserWidget();
601+
not_epsilon_fa_widget->clearStatus();
602+
algorithm_widget->disablePrev();
584603
}
585604

586605
void RemoveEpsilon::toEnd()
587606
{
588-
runAlgorithm(0);
607+
while(actInstruction != last_instruction)
608+
nextStep();
589609
}
590610

591611
void RemoveEpsilon::checkSolution()

RegularConvertor/finite_machine/arrow.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ QWidget *)
167167
this->displayText = symbols.join(", ");
168168
painter->drawText(textPos(),this->displayText);
169169

170+
if (isSelected())
171+
{
172+
painter->setPen(QPen(myColor, 1, Qt::DashLine));
173+
}
174+
170175
if(getStartItemPos() == getEndItemPos())
171176
{//jedna se o self smycku
172177

RegularConvertor/finite_machine/diagramscene.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void DiagramScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
3535
return;
3636

3737
clicked = true;
38-
StateNode* newNode;
38+
StateNode* newNode = 0;
3939
switch(this->actMode)
4040
{
4141
case AddNode:
@@ -46,6 +46,7 @@ void DiagramScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
4646
FA->coordinates[newNode->getName()] = mouseEvent->scenePos().toPoint();
4747
if(newNode->getName() == "0" && startingState == NULL)
4848
newNode->setStartinState();
49+
4950
emit FA_changed(FA);
5051
break;
5152
case AddArrow:
@@ -70,6 +71,11 @@ void DiagramScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
7071
// elipse->setFlag(QGraphicsItem::ItemIsSelectable, true);
7172
// elipse->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
7273
QGraphicsScene::mousePressEvent(mouseEvent);
74+
75+
//cant unselect node because selection set also mouse release event :(
76+
// // Unselect node
77+
// if(newNode != 0)
78+
// newNode->setSelected(false);
7379
}
7480

7581
void DiagramScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)

RegularConvertor/finite_machine/fa_widget.cpp

Lines changed: 81 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ FA_widget::FA_widget(QWidget *parent) :
3333

3434
//set init checked to AddNodeBut
3535
AddNodeBut->setChecked(true);
36+
//MoveNodeBut->setChecked(true);
37+
38+
MoveNodeBut->setToolTip(tr("If this button is activated, you can select and move with items in scene."));
39+
AddNodeBut->setToolTip(tr("If this button is activated, left mouse click into screene creates new node."));
40+
AddArrowBut->setToolTip(tr("If this button is activated, you can create transition between nodes. <br>(Click on from item, hold mouse left button and release on arrow target.)"));
41+
DeleteNodeBut->setToolTip(tr("Click on this button deletes all selected items. <br>(You can select multiple items when holding control button.)"));
3642

3743
//adjust size of button according text in
3844
// MoveNodeBut->setMaximumWidth(MoveNodeBut->fontMetrics().boundingRect(MoveNodeBut->text()).width()+15);
@@ -57,7 +63,8 @@ FA_widget::FA_widget(QWidget *parent) :
5763
//notify changes in formal view
5864
connect(this->ui->statesLineEdit,SIGNAL(editingFinished()),this,SLOT(statesEdited()));
5965
connect(this->ui->endingStatesLineEdit,SIGNAL(editingFinished()),this,SLOT(endingStatesEdited()));
60-
connect(this->ui->alphabetLineEdit,SIGNAL(editingFinished()),this,SLOT(alphaberEdited()));
66+
connect(this->ui->alphabetLineEdit,SIGNAL(editingFinished()),this,SLOT(alphabetEdited()));
67+
connect(this->ui->alphabetLineEdit,SIGNAL(textEdited(QString)),this,SLOT(alphabetEdited()));
6168

6269
//add items to scene
6370
connect(this,SIGNAL(addNodes(QSet<QString>)),this->scene,SLOT(addNodes(QSet<QString>)));
@@ -111,7 +118,7 @@ void FA_widget::setupValidators()
111118
{
112119
QRegExp listOfIdentifiers("^(\\w+(,\\s*\\w+)*,?)?$");
113120
//hint [^,] mean what ever char not ','
114-
QRegExp listOfSymbols("^\\S(,\\s*\\S)*$");
121+
QRegExp listOfSymbols("^(\\S(,\\s*\\S)*)?$");
115122
QRegExp emptyRegExp("^$");
116123
statesValidator = new QRegExpValidator(listOfIdentifiers, this);
117124
alphabetValidator = new QRegExpValidator(listOfSymbols, this);
@@ -184,7 +191,9 @@ void FA_widget::statesEdited()
184191
if(ui->statesLineEdit->text() == "")
185192
{
186193
emit removeNodes(FA->states);
187-
FA->states.clear();
194+
FA->removeStates(FA->states);
195+
//FA->states.clear();
196+
188197
emit FA_changed(FA);
189198
return;
190199
}
@@ -194,19 +203,34 @@ void FA_widget::statesEdited()
194203
QSet <QString> setOfStatesLineEdit = unique_list_of_states.toSet();
195204
QSet <QString> statesToDel = FA->states - setOfStatesLineEdit;
196205
QSet <QString> statesToAdd = setOfStatesLineEdit - FA->states;
197-
FA->states =setOfStatesLineEdit;
206+
FA->removeStates(statesToDel);
207+
foreach(QString state_to_add, statesToAdd)
208+
FA->addState(state_to_add);
198209
if(!statesToDel.empty())
199210
{
200-
emit FA_changed(FA);
211+
//remove nodes emits in scene FA_changed()
201212
emit removeNodes(statesToDel);
213+
214+
// this block of code removes rules in formal view that consist of
215+
foreach(QString state_to_del,statesToDel)
216+
{
217+
QList<QListWidgetItem *> items_to_dell = ui->rulesListWidget->findItems(state_to_del+" ",Qt::MatchStartsWith);
218+
items_to_dell.append(ui->rulesListWidget->findItems(" "+state_to_del,Qt::MatchEndsWith));
219+
foreach(QListWidgetItem* item,items_to_dell.toSet())
220+
{
221+
ui->rulesListWidget->takeItem(ui->rulesListWidget->row(item));
222+
delete item;
223+
}
224+
}
225+
202226
}
203227
if(!statesToAdd.empty())
204228
{
205229
emit addNodes(statesToAdd);
206230
emit FA_changed(FA);
207231
}
208232
updateStates();
209-
emit FA_changed(FA);
233+
// not needed emit FA_changed(FA)(emit only if there is some changes (add or nemove nodes));
210234
}
211235

212236
void FA_widget::endingStatesEdited()
@@ -220,29 +244,57 @@ void FA_widget::endingStatesEdited()
220244
QSet <QString> endingStatesToAdd = setOfEndigStates - FA->finalStates;
221245
FA->finalStates = setOfEndigStates;
222246
if(!endingStatesToDel.empty())
247+
{
223248
emit removeEndingNodes(endingStatesToDel);
249+
//FA changed is emited in node
250+
}
224251
if(!endingStatesToAdd.empty())
252+
{
225253
emit addEndingNodes(endingStatesToAdd);
226-
227-
emit FA_changed(FA);
254+
// FA changed is emited in node
255+
}
228256
}
229257

230-
void FA_widget::alphaberEdited()
258+
void FA_widget::alphabetEdited()
231259
{
232-
QStringList SortedUniqueList = getSortedUniqueList(ui->alphabetLineEdit->text());
233-
ui->alphabetLineEdit->setText(SortedUniqueList.join(", "));
260+
QString text = ui->alphabetLineEdit->text();
261+
int pos = 0;
262+
if (alphabetValidator->validate(text, pos) == QValidator::Acceptable)
263+
{
264+
QStringList SortedUniqueList = getSortedUniqueList(ui->alphabetLineEdit->text());
265+
ui->alphabetLineEdit->setText(SortedUniqueList.join(", "));
234266

235267

236-
QSet <QString> setOfAlphabet = SortedUniqueList.toSet();
237-
QSet <QString> symbolsToDel = FA->alphabet - setOfAlphabet;
238-
QSet <QString> symbolsToAdd = setOfAlphabet - FA->alphabet;
239-
FA->alphabet = SortedUniqueList.toSet();
240-
if(!symbolsToDel.empty())
241-
emit removeSymbols(symbolsToDel);
242-
if(!symbolsToAdd.empty())
243-
emit addSymbols(symbolsToAdd);
268+
QSet <QString> setOfAlphabet = SortedUniqueList.toSet();
269+
QSet <QString> symbolsToDel = FA->alphabet - setOfAlphabet;
270+
QSet <QString> symbolsToAdd = setOfAlphabet - FA->alphabet;
271+
if(!symbolsToDel.empty())
272+
{
273+
foreach(QString symbol, symbolsToDel)
274+
{
275+
// This block of code removes rules from formal view where delete symbols appears
276+
//QList<QListWidgetItem *> items_to_dell = ui->rulesListWidget->findItems(" "+symbol+" ->",Qt::MatchContains);
277+
QList<QListWidgetItem *> items_to_dell = ui->rulesListWidget->findItems("^\\S+ "+symbol+" -> \\S+$",Qt::MatchRegExp);
278+
foreach(QListWidgetItem* item,items_to_dell.toSet())
279+
{
280+
ui->rulesListWidget->takeItem(ui->rulesListWidget->row(item));
281+
delete item;
282+
}
283+
emit removeEdges(FA->findRule_Symbol(symbol).toSet());
284+
FA->removeSymbol(symbol);
285+
}
286+
emit FA_changed(FA);
287+
}
244288

245-
emit FA_changed(FA);
289+
if(!symbolsToAdd.empty())
290+
{
291+
foreach(QString symbol, symbolsToAdd)
292+
{
293+
FA->addSymbol(symbol);
294+
}
295+
emit FA_changed(FA);
296+
}
297+
}
246298
//TODO! osetrit kdyz se vyskytuji symboly abecedy v prechodech
247299
}
248300

@@ -268,7 +320,8 @@ void FA_widget::updateStates()
268320
QStringList items_string_list = items;
269321
QString awailableStates = "(" + items_string_list.join( "|" ) + ")";
270322
endingStatesValidator->setRegExp(QRegExp("^" + awailableStates + "+(,\\s*" + awailableStates + ")*,?$")); // RegExp: ^\\w+(,\\s*\\w+)*,?$
271-
//TODO! osetrit kdyz se smaze uzel ktery se vyskytuje v prechodech
323+
QStringList endingStates = FA->finalStates.toList();
324+
ui->endingStatesLineEdit->setText(endingStates.join(", "));
272325
}
273326

274327
void FA_widget::emitAddEdge(ComputationalRules rule)
@@ -289,6 +342,9 @@ void FA_widget::emitAddEndingNode(QString node)
289342
void FA_widget::on_startStateComboBox_activated(const QString &arg1)
290343
{
291344
statesEdited(); //zavolame explicitne protoze "strati fokus, tak aby to fungovalo"
345+
//because prew function erase selected item in gui
346+
int index = ui->startStateComboBox->findText(arg1);
347+
ui->startStateComboBox->setCurrentIndex(index);
292348
if(arg1 != "")
293349
{
294350
FA->startState = QString(arg1);
@@ -304,7 +360,7 @@ void FA_widget::on_addRuleToolButton_clicked()
304360
{
305361
//updatovani stavu a abecedy (zavolame explicitne protoze "nestrati fokus, tak aby to fungovalo")
306362
statesEdited();
307-
alphaberEdited();
363+
alphabetEdited();
308364

309365
if(FA->states.isEmpty())
310366
{
@@ -349,7 +405,7 @@ void FA_widget::on_removeRuleToolButton_clicked()
349405
{
350406
//updatovani stavu a abecedy (zavolame explicitne protoze "nestrati fokus, tak aby to fungovalo")
351407
statesEdited();
352-
alphaberEdited();
408+
alphabetEdited();
353409

354410
QList<QListWidgetItem *> items = ui->rulesListWidget->selectedItems();
355411

@@ -371,7 +427,7 @@ void FA_widget::on_rulesListWidget_itemDoubleClicked(QListWidgetItem *item)
371427
{
372428
//updatovani stavu a abecedy (zavolame explicitne protoze "nestrati fokus, tak aby to fungovalo")
373429
statesEdited();
374-
alphaberEdited();
430+
alphabetEdited();
375431

376432
ComputationalRules oldrule(item->text());
377433

@@ -435,7 +491,7 @@ void FA_widget::on_tabWidget_currentChanged(int index)
435491
ui->endingStatesLineEdit->setText(endingStates.join(", "));
436492

437493
}
438-
emit FA_changed(FA);
494+
// not needed emit, we set only old data from FA graphic - emit FA_changed(FA);
439495
}
440496

441497
//vymaze selected items

0 commit comments

Comments
 (0)