forked from werneazc/gsysc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgsysPort.cc
427 lines (397 loc) · 10.6 KB
/
gsysPort.cc
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
/*
** This file is part of gSysC.
**
** gSysC 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
** (at your option) any later version.
**
** gSysC 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 gSysC with the file ``LICENSE''; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "gsysPort.h"
#include "gsysSignal.h"
#include "gsysConnection.h"
#include "gsysHierarchyWindow.h"
#include "gsysHierarchy.h"
#include "gsysRegister.h"
/*
* constructor
*/
gsysPort::gsysPort(short type)
{
// initialize global variables
portDirection = type;
initialDirection = -1;
endPort = false;
connSignal = 0;
realPort = 0;
activated = false;
highlighted = false;
}
/*
* destructor
*/
gsysPort::~gsysPort()
{
// free pointer variables and lists
delete connSignal; connSignal = 0;
delete name; name = 0;
delete parent; parent = 0;
lines.clear();
realPort = 0; // SystemC must delete the port
}
/*
* set pointer to corresponding SystemC port
*/
void gsysPort::setReal(void* real)
{
realPort = real;
}
/*
* get pointer to corresponding SystemC port
*/
void* gsysPort::getReal()
{
return realPort;
}
/*
* get type of port (in- (=0), out- (=1) or inout-port (=2))
*/
short gsysPort::getType()
{
return portDirection;
}
/*
* set the initial direction to give information, where the next routing node can be found
*/
void gsysPort::setInitDir(short dir)
{
initialDirection = dir;
}
/*
* get the initialil direction for routing
*/
short gsysPort::getInitDir()
{
return initialDirection;
}
/*
* method to test, whether this port is not connected to any signal
*/
bool gsysPort::isEndPort()
{
return endPort;
}
/*
* set varbiable 'endPort', which means the port is not connected to any signal
*/
void gsysPort::setEndPort(bool newPort)
{
endPort = newPort;
}
/*
* set the value of the port
*/
void gsysPort::setValue(char* myValue)
{
#ifdef DEBUG_GSYSC
cout<<"-- Port("<<this<<")->setValue() of port '"<<name<<"' called with parameter "<<myValue<<std::endl;
#endif
if(connSignal!=0) connSignal->setValue(myValue);
}
/*
* get the port value
*/
char* gsysPort::getValue()
{
#ifdef DEBUG_GSYSC
if(connSignal!=0)
cout<<"oOo port("<<this<<")->getValue(): The connected signal("<<connSignal<<") has value '"<<connSignal->getValue()<<"'"<<endl;
else
cout<<"aAa port("<<this<<")->getValue(): No signal connected to this port!"<<endl;
#endif
if(connSignal!=0) return connSignal->getValue();
else return (char*)">>UNDEFINED<<";
}
/*
* method to save the port value (forward to gsysSignal-object)
*/
void gsysPort::saveValue()
{
if(connSignal!=0) connSignal->saveValue();
}
/*
* method to check, whether the port value has changed
* within the last simulation step
*/
bool gsysPort::sthChanged()
{
if(connSignal!=0) return connSignal->sthChanged();
return false;
}
/*
* set the port name
*/
void gsysPort::setName(char* name)
{
this->name = name;
}
/*
* get the port name
*/
char* gsysPort::getName()
{
return name;
}
/*
* set a pointer to the parent hierarchy module
*/
void gsysPort::setParent(gsysHierarchy* newParent)
{
parent = newParent;
}
/*
* get a pointer to the parent module
*/
gsysHierarchy* gsysPort::getParent()
{
return parent;
}
/*
* set the destination point for direct connection to a side port
*/
void gsysPort::setDest(QPoint dest)
{
destination = dest;
}
/*
* get the destination port for connection to a side port
* (if point is 0/0, then no connection to side port is assumed)
*/
QPoint gsysPort::getDest()
{
return destination;
}
/*
* get connected signal (as pointer)
*/
gsysSignal* gsysPort::getSignal()
{
return connSignal;
}
/*
* set a pointer to the connected signal
*/
void gsysPort::setSignal(gsysSignal* sig)
{
#ifdef DEBUG_GSYSC
cout<<" *** port "<<name<<"("<<this<<") gets connected to signal "<<sig->getName()<<"("<<sig<<")."<<endl;
#endif
connSignal = sig;
}
/*
* add an graphical element to the list of all drawn elements,
* that represent the port an its connection to the routing nodes
*/
void gsysPort::addLineElem(Q3CanvasPolygonalItem* line)
{
lines.push_back(line);
}
/*
* get the list of graphical representations
*/
vector<Q3CanvasPolygonalItem*> gsysPort::getCanvasItems()
{
return lines;
}
/*
* highlight the connected signal after the user clicked on this port
*/
void gsysPort::activate()
{
if(!activated)
{
for(int i=0; i<lines.size(); i++)
if(lines[i]->rtti() == Q3CanvasLine::RTTI)
{
Q3CanvasLine* aktLine = (Q3CanvasLine*)lines[i];
if(highlighted)
{
aktLine->setZ(80);
if(connSignal!=0 && connSignal->getConn()!=0 && connSignal->getConn()->getParentWindow())
{
aktLine->setBrush(QColor(connSignal->getConn()->getParentWindow()->activeChangedSig)); // violet
aktLine->setPen(QColor(connSignal->getConn()->getParentWindow()->activeChangedSig)); // violet
}
else
{
aktLine->setBrush(QColor("#FF00FF")); // violet
aktLine->setPen(QColor("#FF00FF")); // violet
}
}
else
{
aktLine->setZ(60);
if(connSignal!=0 && connSignal->getConn()!=0 && connSignal->getConn()->getParentWindow())
{
aktLine->setBrush(QColor(connSignal->getConn()->getParentWindow()->activeSignal)); // dark orange
aktLine->setPen(QColor(connSignal->getConn()->getParentWindow()->activeSignal)); // dark orange
}
else
{
aktLine->setBrush(QColor("#FF7F00")); // dark orange
aktLine->setPen(QColor("#FF7F00")); // dark orange
}
}
aktLine->setActive(true);
aktLine->canvas()->update();
aktLine = 0;
}
activated = true;
}
}
/*
* de-highlight the connected signal
*/
void gsysPort::deactivate()
{
if(activated)
{
for(int i=0; i<lines.size(); i++)
if(lines[i]->rtti() == Q3CanvasLine::RTTI)
{
Q3CanvasLine* aktLine = (Q3CanvasLine*)lines[i];
if(highlighted)
{
aktLine->setZ(40);
if(connSignal!=0 && connSignal->getConn()!=0 && connSignal->getConn()->getParentWindow())
{
aktLine->setBrush(QColor(connSignal->getConn()->getParentWindow()->changedSignal)); // red
aktLine->setPen(QColor(connSignal->getConn()->getParentWindow()->changedSignal)); // red
}
else
{
aktLine->setBrush(QColor("#FF0000")); // red
aktLine->setPen(QColor("#FF0000")); // red
}
}
else
{
aktLine->setZ(20);
if(connSignal!=0 && connSignal->getConn()!=0 && connSignal->getConn()->getParentWindow())
{
aktLine->setBrush(QColor(connSignal->getConn()->getParentWindow()->normalSignal)); // black
aktLine->setPen(QColor(connSignal->getConn()->getParentWindow()->normalSignal)); // black
}
else
{
aktLine->setBrush(QColor("#000000")); // black
aktLine->setPen(QColor("#000000")); // black
}
}
aktLine->setActive(true);
aktLine->canvas()->update();
aktLine = 0;
}
activated = false;
}
}
/*
* highlight the connected signal, because the port/signal-value has changed
*/
void gsysPort::highlight()
{
if(!highlighted)
{
for(int i=0; i<lines.size(); i++)
if(lines[i]->rtti() == Q3CanvasLine::RTTI)
{
Q3CanvasLine* aktLine = (Q3CanvasLine*)lines[i];
if(activated)
{
aktLine->setZ(80);
if(connSignal!=0 && connSignal->getConn()!=0 && connSignal->getConn()->getParentWindow())
{
aktLine->setBrush(QColor(connSignal->getConn()->getParentWindow()->activeChangedSig)); // violet
aktLine->setPen(QColor(connSignal->getConn()->getParentWindow()->activeChangedSig)); // violet
}
else
{
aktLine->setBrush(QColor("#FF00FF")); // violet
aktLine->setPen(QColor("#FF00FF")); // violet
}
}
else
{
aktLine->setZ(40);
if(connSignal!=0 && connSignal->getConn()!=0 && connSignal->getConn()->getParentWindow())
{
aktLine->setBrush(QColor(connSignal->getConn()->getParentWindow()->changedSignal)); // red
aktLine->setPen(QColor(connSignal->getConn()->getParentWindow()->changedSignal)); // red
}
else
{
aktLine->setBrush(QColor("#FF0000")); // red
aktLine->setPen(QColor("#FF0000")); // red
}
}
aktLine->setActive(true);
aktLine->canvas()->update();
aktLine = 0;
}
highlighted = true;
}
}
/*
* de-highlight the connected signal
*/
void gsysPort::deHighlight()
{
if(highlighted)
{
for(int i=0; i<lines.size(); i++)
if(lines[i]->rtti() == Q3CanvasLine::RTTI)
{
Q3CanvasLine* aktLine = (Q3CanvasLine*)lines[i];
if(activated)
{
aktLine->setZ(60);
if(connSignal!=0 && connSignal->getConn()!=0 && connSignal->getConn()->getParentWindow())
{
aktLine->setBrush(QColor(connSignal->getConn()->getParentWindow()->activeSignal)); // orange
aktLine->setPen(QColor(connSignal->getConn()->getParentWindow()->activeSignal)); // orange
}
else
{
aktLine->setBrush(QColor("#FF7F00")); // orange
aktLine->setPen(QColor("#FF7F00")); // orange
}
}
else
{
aktLine->setZ(20);
if(connSignal!=0 && connSignal->getConn()!=0 && connSignal->getConn()->getParentWindow())
{
aktLine->setBrush(QColor(connSignal->getConn()->getParentWindow()->normalSignal)); // black
aktLine->setPen(QColor(connSignal->getConn()->getParentWindow()->normalSignal)); // black
}
else
{
aktLine->setBrush(QColor("#000000")); // black
aktLine->setPen(QColor("#000000")); // black
}
}
aktLine->setActive(true);
aktLine->canvas()->update();
aktLine = 0;
}
highlighted = false;
}
}