Skip to content

Commit 282cd19

Browse files
author
navrkald
committed
Implemented save/load to file.
Also added some more words to technical report, but its not finished.
1 parent 7b26cc7 commit 282cd19

File tree

10 files changed

+208
-48
lines changed

10 files changed

+208
-48
lines changed

RegularConvertor/finite_machine/computationalrules.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ComputationalRules// : public QObject
1515
ComputationalRules(QString _from, QString _to, QString _symbol);
1616
ComputationalRules(QString rule);
1717
ComputationalRules(const ComputationalRules& _object);//Toto je kopirovaci konstruktor
18-
ComputationalRules &operator=(const ComputationalRules& _rule);
18+
ComputationalRules& operator=(const ComputationalRules& _rule);
1919
QString toString() const{return from + " " + symbol + "-> " + to;}
2020

2121

RegularConvertor/mainwindow.cpp

Lines changed: 86 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -940,42 +940,79 @@ void MainWindow::on_Determinization_advanced_example_4_triggered()
940940
}
941941
void MainWindow::on_action_save_triggered()
942942
{
943-
QFile file("/tmp/test.txt");
943+
if(activeConversion == none)
944+
{
945+
showStatusMessage(tr("ERROR: No conversion selected!"));
946+
return;
947+
}
948+
QString filename = "";
949+
if((filename = QFileDialog::getSaveFileName(this,tr("Save conversion"))) == "")
950+
return;
951+
952+
QFile file(filename);
944953
file.open(QIODevice::WriteOnly);
945954
QDataStream out(&file); // we will serialize the data into the file
946955
out << activeConversion << mode;
947956
switch(activeConversion)
948957
{
949-
case none:
950-
break;
951958
case RE_to_FA:
952-
out << *reg_exp_algorithm->re;
959+
{
960+
// In play mode does not make sence to save output fa
961+
if(mode == Algorithm::PLAY_MODE)
962+
{
963+
out << reg_exp_algorithm->re->regexp;
964+
}
965+
else
966+
{
967+
out << *reg_exp_algorithm->re;
968+
}
969+
}
953970
break;
954971
case REMOVE_EPSILON:
972+
if(mode == Algorithm::PLAY_MODE)
973+
{
974+
out << remove_epsilon_algorithm->FA;
975+
}
976+
else
977+
{
955978
out << remove_epsilon_algorithm->FA << remove_epsilon_algorithm->non_epsilon_FA;
979+
}
956980
break;
957981
case DFA:
958-
out << DFA_algorithm->FA << DFA_algorithm->DFA;
982+
if(mode == Algorithm::PLAY_MODE)
983+
{
984+
out << DFA_algorithm->FA;
985+
}
986+
else
987+
{
988+
out << DFA_algorithm->FA << DFA_algorithm->DFA;
989+
}
990+
break;
991+
// This should never happend
992+
case none:
959993
break;
960994
}
961995
file.close();
962996
}
963997

964998
void MainWindow::on_action_open_file_triggered()
965999
{
966-
QFile read("/tmp/test.txt");
1000+
QString filename = "";
1001+
if((filename = QFileDialog::getOpenFileName(this, tr("Open conversion")))=="")
1002+
return;
1003+
1004+
QFile read(filename);
9671005
read.open(QIODevice::ReadOnly);
9681006
QDataStream in(&read); // read the data serialized from the file
9691007
FiniteAutomata FA;
9701008
//
971-
Conversions conversion;
1009+
Conversions conversion = none;
1010+
Algorithm::modes tmp_mode = Algorithm::NONE;
1011+
9721012
in >> conversion;
973-
in >> mode;
974-
switch (mode)
1013+
in >> tmp_mode;
1014+
switch (tmp_mode)
9751015
{
976-
case Algorithm::NONE:
977-
978-
break;
9791016
case Algorithm::CHECK_MODE:
9801017
on_action_check_mode_triggered();
9811018
break;
@@ -985,44 +1022,64 @@ void MainWindow::on_action_open_file_triggered()
9851022
case Algorithm::STEP_MODE:
9861023
on_action_step_mode_triggered();
9871024
break;
1025+
case Algorithm::NONE:
1026+
showStatusMessage(tr("ERROR: Input file in wrong format!"));
1027+
return;
1028+
break;
9881029
}
1030+
mode = tmp_mode;
9891031

9901032
switch(conversion)
9911033
{
992-
case none:
993-
qDebug() << "Conversion: none";
994-
break;
9951034
case RE_to_FA:
9961035
{
997-
qDebug() << "Conversion: RE_to_FA";
998-
RegExp re;
999-
in >> re;
1000-
prepareREtoFA(new RegExp(re));
1036+
if(mode == Algorithm::PLAY_MODE)
1037+
{
1038+
QString regexp_str;
1039+
in >> regexp_str;
1040+
prepareREtoFA(new RegExp(regexp_str));
1041+
}
1042+
else
1043+
{
1044+
RegExp re;
1045+
in >> re;
1046+
prepareREtoFA(new RegExp(re));
1047+
}
10011048
}
10021049
break;
10031050
case REMOVE_EPSILON:
10041051
{
1005-
qDebug() << "Conversion: REMOVE_EPSILON";
10061052
FiniteAutomata in_FA;
1007-
FiniteAutomata out_FA;
1008-
in >> in_FA >> out_FA;
1053+
in >> in_FA;
10091054
prepareRemoveEpsilon();
10101055
remove_epsilon_algorithm->setInputFA(in_FA);
1011-
remove_epsilon_algorithm->setOutputFA(out_FA);
1056+
if(mode != Algorithm::PLAY_MODE)
1057+
{
1058+
FiniteAutomata out_FA;
1059+
in >> out_FA;
1060+
remove_epsilon_algorithm->setOutputFA(out_FA);
1061+
}
10121062
}
10131063
break;
10141064
case DFA:
1015-
qDebug() << "Conversion: DFA";
1065+
{
10161066
FiniteAutomata in_FA;
1017-
FiniteAutomata out_FA;
1018-
in >> in_FA >> out_FA;
1067+
in >> in_FA;
10191068
prepareDFA();
10201069
DFA_algorithm->setInputFA(in_FA);
1021-
DFA_algorithm->setOutputFA(out_FA);
1070+
if(mode != Algorithm::PLAY_MODE)
1071+
{
1072+
FiniteAutomata out_FA;
1073+
in >> out_FA;
1074+
DFA_algorithm->setOutputFA(out_FA);
1075+
}
1076+
}
1077+
break;
1078+
case none:
1079+
showStatusMessage(tr("ERROR: Input file in wrong format!"));
1080+
return;
10221081
break;
10231082
}
1024-
1025-
qDebug() << FA;
10261083
}
10271084

10281085
QDataStream& operator>>(QDataStream& in, MainWindow::Conversions& e)

RegularConvertor/mainwindow.ui

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
3131
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
3232
p, li { white-space: pre-wrap; }
33-
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
34-
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Sans Serif'; font-size:12pt;&quot;&gt;Welcome in program Regular Convertor!&lt;/span&gt;&lt;/p&gt;
35-
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:12pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
36-
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:10pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
37-
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Sans Serif'; font-size:10pt;&quot;&gt;Please choose &lt;/span&gt;&lt;span style=&quot; font-family:'Sans Serif'; font-size:10pt; font-weight:600;&quot;&gt;mode and conversion&lt;/span&gt;&lt;span style=&quot; font-family:'Sans Serif'; font-size:10pt;&quot;&gt; or choose &lt;/span&gt;&lt;span style=&quot; font-family:'Sans Serif'; font-size:10pt; font-weight:600;&quot;&gt;example&lt;/span&gt;&lt;span style=&quot; font-family:'Sans Serif'; font-size:10pt;&quot;&gt;.&lt;/span&gt;&lt;/p&gt;
38-
&lt;p align=&quot;center&quot; style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:9pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
39-
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Sans Serif'; font-size:9pt;&quot;&gt;You can also change program language.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
33+
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
34+
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:12pt;&quot;&gt;Welcome in program Regular Convertor!&lt;/span&gt;&lt;/p&gt;
35+
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:12pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
36+
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
37+
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt;Please choose &lt;/span&gt;&lt;span style=&quot; font-size:10pt; font-weight:600;&quot;&gt;mode and conversion&lt;/span&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt; or choose &lt;/span&gt;&lt;span style=&quot; font-size:10pt; font-weight:600;&quot;&gt;example&lt;/span&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt;.&lt;/span&gt;&lt;/p&gt;
38+
&lt;p align=&quot;center&quot; style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
39+
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;You can also change program language.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
4040
</property>
4141
</widget>
4242
</item>
@@ -48,7 +48,7 @@ p, li { white-space: pre-wrap; }
4848
<x>0</x>
4949
<y>0</y>
5050
<width>816</width>
51-
<height>21</height>
51+
<height>20</height>
5252
</rect>
5353
</property>
5454
<widget class="QMenu" name="menuSoubor">
@@ -343,21 +343,21 @@ p, li { white-space: pre-wrap; }
343343
</action>
344344
<action name="action_save">
345345
<property name="checkable">
346-
<bool>true</bool>
346+
<bool>false</bool>
347347
</property>
348348
<property name="enabled">
349-
<bool>false</bool>
349+
<bool>true</bool>
350350
</property>
351351
<property name="text">
352352
<string>Save</string>
353353
</property>
354354
</action>
355355
<action name="action_open_file">
356356
<property name="checkable">
357-
<bool>true</bool>
357+
<bool>false</bool>
358358
</property>
359359
<property name="enabled">
360-
<bool>false</bool>
360+
<bool>true</bool>
361361
</property>
362362
<property name="text">
363363
<string>Open</string>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,38 @@
11
#include "charpos.h"
2+
#include <QDataStream>
23

34
bool operator==(const CharPos& c1, const CharPos& c2)
45
{
56
return c1.charter == c2.charter && c1.pos == c2.pos && c1.terminal == c2.terminal &&
67
c1.bold == c2.bold;
78
}
9+
10+
11+
QDataStream &operator<<(QDataStream &out, const CharPos& ch)
12+
{
13+
out << ch.charter << ch.pos << ch.terminal << ch.bold;
14+
return out;
15+
}
16+
17+
18+
QDataStream &operator>>(QDataStream &in, CharPos& ch)
19+
{
20+
qint32 tmp_pos;
21+
in >> ch.charter;
22+
in >> tmp_pos;
23+
in >> ch.terminal;
24+
in >> ch.bold;
25+
ch.pos = (int)tmp_pos;
26+
return in;
27+
}
28+
29+
30+
//CharPos operator=(const CharPos c)
31+
//{
32+
// CharPos r;
33+
// r.bold = c.bold;
34+
// r.charter = c.charter;
35+
// r.pos = c.pos;
36+
// r.terminal = c.terminal;
37+
// return r;
38+
//}

RegularConvertor/reg_exp/charpos.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include <QString>
55
#include <QList>
6+
#include "finite_machine/computationalrules.h"
7+
68

79
//Struktura ve které jsou uloženy data v uzlu stromu reprezentujici regulární výraz
810

@@ -21,12 +23,25 @@ struct CharPos
2123
terminal = _terminal;
2224
bold = _bold;
2325
}
26+
// CharPos operator=(const CharPos c)
27+
// {
28+
// CharPos r;
29+
// r.bold = c.bold;
30+
// r.charter = c.charter;
31+
// r.pos = c.pos;
32+
// r.terminal = c.terminal;
33+
// return r;
34+
// }
2435
};
2536

26-
//operator nad strukturou
37+
//operators above structure
2738
bool operator==(const CharPos& c1, const CharPos& c2);
2839

40+
2941
//pomocná konstanta dolaru, ktery s pouziva pri syntakticke analyze RV
3042
const CharPos dolar("$",-1,true, false);
43+
const CharPos emptyString (EMPTYSET,0,true);
44+
QDataStream &operator<<(QDataStream& out, const CharPos& ch);
45+
QDataStream &operator>>(QDataStream& in, CharPos& ch);
3146

3247
#endif // CHARPOS_H

RegularConvertor/reg_exp/regexp.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
RegExp::RegExp()
1212
{
13-
CharPos emptyString (EMPTYSET,0,true);
1413
rootNode = new RegExpNode(emptyString);
1514
}
1615

@@ -157,11 +156,13 @@ void RegExp::clean()
157156
QDataStream &operator<<(QDataStream &out, const RegExp &reg_exp)
158157
{
159158
out << reg_exp.regexp;
159+
RegExpNode::save(reg_exp.rootNode, out);
160160
return out;
161161
}
162162

163163
QDataStream &operator>>(QDataStream &in, RegExp &reg_exp)
164164
{
165165
in >> reg_exp.regexp;
166+
reg_exp.rootNode = RegExpNode::load(in);
166167
return in;
167168
}

RegularConvertor/reg_exp/regexp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "charpos.h"
88
#include "regexpnode.h"
99

10-
#define EMPTY_SET
1110

1211
class RegExp
1312
{
@@ -18,6 +17,8 @@ class RegExp
1817

1918
bool init(QString _strToVal);
2019
QList<CharPos> addConcOperator(QString _reqExp);
20+
21+
2122
RegExpParser parser;
2223
RegExpNode* rootNode;
2324
QString regexp;
@@ -37,7 +38,6 @@ class RegExp
3738
static bool isAlphabetChar(QString symbol);
3839
static QString precedenceTable[7][7];
3940
void clean();
40-
4141
};
4242

4343
QDataStream &operator<<(QDataStream &out, const RegExp &reg_exp);

0 commit comments

Comments
 (0)