-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMachineManager.cpp
238 lines (211 loc) · 7.29 KB
/
MachineManager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*
Copyright (C) 2000,2001 Stefan Duffner
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "MachineManager.h"
#include "Error.h"
#include "Machine.h"
#include "MainWindow.h"
#include "Project.h"
#include "TransitionInfo.h"
#include "UndoBuffer.h"
//#include "dialogs/DMachineProperties.h"
#include "MachinePropertiesDlgImpl.h"
/// Constructor
MachineManager::MachineManager(QObject *parent, const char *name)
: QObject(parent, name) {
main = (MainWindow *)parent;
// machine_props = new DMachineProperties;
machine_props = new MachinePropertiesDlgImpl((QWidget *)parent, 0, true);
}
/// Destructor
MachineManager::~MachineManager() { delete machine_props; }
/**
* Adds a new machine to the project @a p
*/
int MachineManager::addMachine(Project *p) {
int result;
QString n, v, a, d;
int nb, ni, no;
QFont f("Helvetica", 8);
f.setStyleHint(QFont::Helvetica);
// f.setStyleStrategy(QFont::PreferBitmap);
QFont sf, tf;
int atype = 1;
QString inames, onames, onamesm;
int type;
bool draw_it;
int ires;
Error err;
machine_props->enableType(true);
machine_props->setType(0);
machine_props->setNumMooreOutputs(0);
machine_props->setMooreOutputNames("");
machine_props->setNumInputs(1);
machine_props->setMealyInputNames("");
machine_props->setNumOutputs(0);
machine_props->setMealyOutputNames("");
machine_props->setSFont(f);
machine_props->setTFont(f);
machine_props->selectFirst();
machine_props->setArrowType(atype);
machine_props->setDrawITrans(true);
machine_props->setName("FSM");
while (true) {
result = machine_props->exec();
if (result) {
n = machine_props->getName();
if (n.length() <= 0)
n = "FSM";
v = machine_props->getVersion();
a = machine_props->getAuthor();
d = machine_props->getDescription();
type = machine_props->getType();
nb = machine_props->getNumMooreOutputs();
ni = machine_props->getNumInputs();
no = machine_props->getNumOutputs();
onamesm = machine_props->getMooreOutputNames();
inames = machine_props->getMealyInputNames();
onames = machine_props->getMealyOutputNames();
sf = machine_props->getSFont();
tf = machine_props->getTFont();
atype = machine_props->getArrowType();
draw_it = machine_props->getDrawITrans();
p->addMachine(n, v, a, d, type, nb, onamesm, ni, inames, no, onames, sf,
tf, atype, draw_it);
p->getMain()->updateIOView(p->machine);
if (nb != p->machine->translateNames(onamesm).size() ||
ni != p->machine->translateNames(inames).size() ||
no != p->machine->translateNames(onames).size()) {
ires = err.warningOkCancel(
tr("Warning.\nThe number of bits does not match the number of "
"signal names. \nDo you want to proceed?"));
if (ires == QMessageBox::Ok)
break;
else
continue;
}
}
break;
}
return result;
}
/**
* Edits the machine in the project @a p.
*/
void MachineManager::editMachine(Project *p) {
bool result;
int mtype, numbit, numin, numout;
int nnumbit, nnumin, nnumout;
QString name, nname, version, author, description, nversion, nauthor,
ndescription;
Machine *m;
Error err;
int ires;
QFont sf, tf;
int atype;
QString inames, onames, onamesm;
QStringList ilist, olist;
bool draw_it;
m = p->machine;
numbit = m->getNumMooreOutputs();
machine_props->enableType(false);
mtype = m->getType();
numin = m->getNumInputs();
numout = m->getNumOutputs();
name = m->getName();
version = m->getVersion();
author = m->getAuthor();
description = m->getDescription();
sf = m->getSFont();
tf = m->getTFont();
atype = m->getArrowType();
onamesm = m->getMooreOutputNames();
inames = m->getMealyInputNames();
onames = m->getMealyOutputNames();
ilist = m->getInputNameList();
olist = m->getOutputNameList();
numbit = m->getNumMooreOutputs();
numin = m->getNumInputs();
numout = m->getNumOutputs();
draw_it = m->getDrawITrans();
machine_props->setName(name);
machine_props->setVersion(version);
machine_props->setAuthor(author);
machine_props->setDescription(description);
machine_props->setType(mtype);
machine_props->setNumMooreOutputs(numbit);
machine_props->setNumInputs(numin);
machine_props->setNumOutputs(numout);
machine_props->setMooreOutputNames(onamesm);
machine_props->setMealyInputNames(inames);
machine_props->setMealyOutputNames(onames);
machine_props->setSFont(sf);
machine_props->setTFont(tf);
machine_props->setArrowType(atype);
machine_props->setDrawITrans(draw_it);
machine_props->selectFirst();
result = machine_props->exec();
if (result) {
nname = machine_props->getName();
if (nname.length() <= 0)
nname = "FSM";
nversion = machine_props->getVersion();
mtype = machine_props->getType();
nnumbit = machine_props->getNumMooreOutputs();
nnumin = machine_props->getNumInputs();
nnumout = machine_props->getNumOutputs();
nauthor = machine_props->getAuthor();
ndescription = machine_props->getDescription();
QList<GState *> states = m->getSList();
if (nnumbit < numbit || nnumin < numin || nnumout < numout) {
ires = err.warningOkCancel(
tr("Warning.\nReducing the number of bits may result in data loss. "
"\nDo you want to proceed?"));
if (ires != QMessageBox::Ok)
return;
}
if (nnumbit !=
m->translateNames(machine_props->getMooreOutputNames()).size() ||
nnumin !=
m->translateNames(machine_props->getMealyInputNames()).size() ||
nnumout !=
m->translateNames(machine_props->getMealyOutputNames()).size()) {
ires = err.warningOkCancel(
tr("Warning.\nThe number of bits does not match the number of signal "
"names. \nDo you want to proceed?"));
if (ires != QMessageBox::Ok)
return;
}
p->getUndoBuffer()->changeMachine(m);
m->setName(nname);
m->setVersion(nversion);
m->setAuthor(nauthor);
m->setDescription(ndescription);
m->setType(mtype);
m->setNumMooreOutputs(nnumbit);
m->setNumInputs(nnumin);
m->setNumOutputs(nnumout);
m->setMooreOutputNames(nnumbit, machine_props->getMooreOutputNames());
m->setMealyInputNames(nnumin, machine_props->getMealyInputNames());
m->setMealyOutputNames(nnumout, machine_props->getMealyOutputNames());
m->setSFont(machine_props->getSFont());
m->setTFont(machine_props->getTFont());
m->setArrowType(machine_props->getArrowType());
m->setDrawITrans(machine_props->getDrawITrans());
if (!m->getDrawITrans())
m->getInitialTransition()->select(false);
p->getMain()->updateIOView(m);
main->project->setChanged();
}
}