Salome HOME
Bug fix: don't set "Loading" state for MacroNodes in InitialState() function (called...
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_CanvasNodePrs.cxx
1 //  SUPERV SUPERVGUI : GUI for Supervisor component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE
4 //
5 //  File   : SUPERVGUI_GanvasNodePrs.cxx
6 //  Author : Natalia KOPNOVA
7 //  Module : SUPERV
8
9 using namespace std;
10 #include "SUPERVGUI_CanvasNodePrs.h"
11 #include "SUPERVGUI_CanvasNode.h"
12 #include "SUPERVGUI_CanvasPort.h"
13 #include "SUPERVGUI_Canvas.h"
14 #include "SUPERVGUI_CanvasCellNodePrs.h"
15
16 //#define CHECKTIME
17
18 #ifdef CHECKTIME
19 #include <sys/timeb.h>
20 #endif
21
22 #define PORT_MARGIN 2
23 #undef PORT_HEIGHT // to avoid warning message
24 #define PORT_HEIGHT LABEL_HEIGHT
25 #define TEXT_MARGIN 5
26
27
28 //=====================================================================
29 // Node presentation
30 //=====================================================================
31 SUPERVGUI_CanvasNodePrs::SUPERVGUI_CanvasNodePrs(QCanvas* theCanvas, 
32                                                  SUPERVGUI_CanvasNode* theNode,
33                                                  bool theCellPrs):
34   QCanvasPolygonalItem(theCanvas),
35   myNode(theNode)
36 {
37   Trace("SUPERVGUI_CanvasNodePrs::SUPERVGUI_CanvasNodePrs");
38   myWidth = LABEL_WIDTH;
39   if (2*(PORT_WIDTH+PORT_MARGIN) > myWidth)
40     myWidth = 2*(PORT_WIDTH+PORT_MARGIN);
41
42   myTitleHeight = LABEL_HEIGHT;
43   myLabelHeight = LABEL_HEIGHT;
44   myStatusHeight = LABEL_HEIGHT;
45   myPortHeight = 2*PORT_MARGIN;
46   myStreamHeight = 0;
47   myGateHeight = PORT_HEIGHT + 2*PORT_MARGIN;
48
49   myLabelVisible = true;
50   myPortVisible = true;
51   myCellPrs = theCellPrs;
52
53   myColor = MAIN_BACK;
54
55   if (!myCellPrs) {
56     // create in/out connection points prs
57     myPointIn = new SUPERVGUI_CanvasHookPrs(theCanvas, this, true);
58     myPointOut = new SUPERVGUI_CanvasHookPrs(theCanvas, this, false);
59   }
60
61   cout<<" ===> 0.2 conatructor NodePrs : CanvasArray has ......"<<endl;
62   //setZ(0);
63   
64   cout<<" ===> 0.3 conatructor NodePrs : CanvasArray has ......"<<endl;
65   if (!myCellPrs) {
66     cout<<" ===> 0.35 conatructor NodePrs : CanvasArray has ......"<<endl;
67     setZ(0);
68     setState(myNode->getEngine()->State());
69     updatePorts();
70   }
71   
72   cout<<" ===> 0.4 conatructor NodePrs : CanvasArray has ......"<<endl;
73
74   QCanvasItemList anIL2 = canvas()->allItems();
75   cout<<" ===> 1 conatructor NodePrs : CanvasArray has "<<anIL2.count()<<" children!"<<endl;
76 }
77
78
79 SUPERVGUI_CanvasNodePrs::~SUPERVGUI_CanvasNodePrs() 
80 {
81   MESSAGE("SUPERVGUI_CanvasNodePrs::~SUPERVGUI_CanvasNodePrs");
82   if (!myCellPrs) {
83     if (myPointIn) delete myPointIn;
84     if (myPointOut) delete myPointOut;
85   }
86   hide();
87 }
88
89 int SUPERVGUI_CanvasNodePrs::rtti() const
90 {
91   return SUPERVGUI_Canvas::Rtti_Node;
92 }
93
94 int SUPERVGUI_CanvasNodePrs::width() const
95 {
96   return myWidth;
97 }
98
99 int SUPERVGUI_CanvasNodePrs::height() const
100 {
101   return getTitleHeight() + getLabelHeight() + getStatusHeight() +
102     getBodyHeight() + getGateHeight();
103 }
104
105 int SUPERVGUI_CanvasNodePrs::getTitleHeight() const
106 {
107   return myTitleHeight;
108 }
109
110 int SUPERVGUI_CanvasNodePrs::getLabelHeight() const
111 {
112   if (isLabelVisible())
113     return myLabelHeight;
114   return 0;
115 }
116
117 int SUPERVGUI_CanvasNodePrs::getStatusHeight() const
118 {
119   return myStatusHeight;
120 }
121
122 int SUPERVGUI_CanvasNodePrs::getBodyHeight() const
123 {
124   if (isPortVisible())
125     return myPortHeight + myStreamHeight;
126   return 0;
127 }
128
129 int SUPERVGUI_CanvasNodePrs::getPortHeight() const
130 {
131   if (isPortVisible())
132     return myPortHeight;
133   return 0;
134 }
135
136 int SUPERVGUI_CanvasNodePrs::getStreamHeight() const
137 {
138   if (isPortVisible())
139     return myStreamHeight;
140   return 0;
141 }
142
143 int SUPERVGUI_CanvasNodePrs::getGateHeight() const
144 {
145   if (isPortVisible())
146     return myGateHeight;
147   return 0;
148 }
149
150 QPointArray SUPERVGUI_CanvasNodePrs::areaPoints() const
151 {
152   int w = width();
153   int h = height()+1;
154
155   QPointArray aPnts(4);
156   aPnts[0] = QPoint((int)x(), (int)y());
157   aPnts[1] = aPnts[0] + QPoint(w, 0);
158   aPnts[2] = aPnts[1] + QPoint(0, h);
159   aPnts[3] = aPnts[0] + QPoint(0, h);
160   return aPnts;
161 }
162
163 QObject* SUPERVGUI_CanvasNodePrs::getObject(const QPoint& thePos) const
164 {
165   QObject* anObj = myNode;
166
167   // check if it's a port
168   const QObjectList* list = myNode->children();
169   if (list) {
170     QObjectListIt it(*list);
171     SUPERVGUI_CanvasPort* aPort;
172     while (QObject* obj = it.current()) {
173       ++it;
174       if (obj->inherits("SUPERVGUI_CanvasPort")) {
175         aPort = (SUPERVGUI_CanvasPort*) obj;
176         if (aPort->getPrs()->getPortRect().contains(thePos, true)) {
177           anObj = aPort;
178           break;
179         }
180       }
181     }
182   }
183   return anObj;
184 }
185
186 void SUPERVGUI_CanvasNodePrs::moveBy(double dx, double dy) 
187 {
188   int aX = (int) (x()+dx);
189   int aY = (int) (y()+dy);
190   int xx = aX - (int)x();
191   int yy = aY - (int)y();
192
193   int w = aX + width() + GRAPH_MARGIN;
194   int h = aY + height() + GRAPH_MARGIN;
195   if (canvas()->width() > w) w = canvas()->width();
196   if (canvas()->height() > h) h = canvas()->height();
197   if (canvas()->width() < w || canvas()->height() < h)
198     canvas()->resize(w, h);
199
200   // save new coordinates only if node is really moving...
201   if (isMoving()) {
202     myNode->getEngine()->Coords(aX, aY);
203   }
204
205   QCanvasPolygonalItem::moveBy(dx, dy);
206
207   // update port's rectangle
208   const QObjectList* list = myNode->children();
209   if (list) {
210     QObjectListIt it(*list);
211     SUPERVGUI_CanvasPort* aPort;
212     while (QObject* obj = it.current()) {
213       ++it;
214       if (obj->inherits("SUPERVGUI_CanvasPort")) {
215         aPort = (SUPERVGUI_CanvasPort*) obj;
216         aPort->moveBy(xx, yy);
217       }
218     }
219   }
220
221   if (!myCellPrs) {
222     myPointIn->moveBy(dx, dy);
223     myPointOut->moveBy(dx, dy);
224   }
225 }
226
227 void SUPERVGUI_CanvasNodePrs::setZ(double z)
228 {
229   QCanvasItem::setZ(z);
230
231   // update port's 
232   const QObjectList* list = myNode->children();
233   if (list) {
234     QObjectListIt it(*list);
235     SUPERVGUI_CanvasPort* aPort;
236     while (QObject* obj = it.current()) {
237       ++it;
238       if (obj->inherits("SUPERVGUI_CanvasPort")) {
239         aPort = (SUPERVGUI_CanvasPort*) obj;
240         aPort->getPrs()->setZ(z);
241       }
242     }
243   }
244 }
245
246 void SUPERVGUI_CanvasNodePrs::hideAll()
247 {
248   bool aDisp = isVisible();
249   if (aDisp) hide();
250
251   setLabelVisible(false);
252   setPortVisible(false);
253
254   if (aDisp) {
255     show();
256     //    canvas()->update();
257   }
258 }
259
260 void SUPERVGUI_CanvasNodePrs::showAll()
261 {
262   bool aDisp = isVisible();
263   if (aDisp) hide();
264
265   setLabelVisible(true);
266   setPortVisible(true);
267
268   if (aDisp) {
269     show();
270     //    canvas()->update();
271   }
272 }
273
274 void SUPERVGUI_CanvasNodePrs::setLabelVisible(bool b)
275 {
276   bool aDisp = isVisible();
277   if (aDisp) hide();
278
279   myLabelVisible = b;
280   updatePorts();
281   if (!isPortVisible() && !myCellPrs) updatePoints();
282
283   if (aDisp) {
284     show();
285     canvas()->update();
286   }
287 }
288
289 void SUPERVGUI_CanvasNodePrs::setPortVisible(bool b)
290 {
291   bool aDisp = isVisible();
292   if (aDisp) hide();
293
294   myPortVisible = b;
295   if (b) {
296     if (!myCellPrs) {
297       myPointIn->hide();
298       myPointOut->hide();
299     }
300
301     updateGates();
302   }
303   else {
304     if (!myCellPrs) {
305       updatePoints();
306       
307       myPointIn->show();
308       myPointOut->show();
309     }
310   }
311
312   const QObjectList* list = myNode->children();
313   if (list) {
314     QObjectListIt it(*list);
315     SUPERVGUI_CanvasPort* aPort;
316     while (QObject* obj = it.current()) {
317       ++it;
318       if (obj->inherits("SUPERVGUI_CanvasPort")) {
319         aPort = (SUPERVGUI_CanvasPort*) obj;
320         aPort->getPrs()->setVisible(b);
321       }
322     }
323   }
324
325   if (aDisp) {
326     show();
327     canvas()->update();
328   }
329 }
330
331 void SUPERVGUI_CanvasNodePrs::setNodeColor(const QColor& theColor)
332 {
333   myColor = theColor;
334   canvas()->setChanged(getRect());
335   canvas()->update();
336 }
337
338 void SUPERVGUI_CanvasNodePrs::updateInfo()
339 {
340   canvas()->setChanged(getTitleRect());
341   canvas()->setChanged(getLabelRect()); //node's comment is saved in engine (we can see it only 
342                                         //with help of ChangeInformation dialog),
343                                         //node's label isn't change
344   canvas()->update();
345 }
346
347 void SUPERVGUI_CanvasNodePrs::updatePoints()
348 {
349   QPoint in = getInConnectionPoint();
350   myPointIn->setCoords(in.x(), in.y());
351
352   QPoint out = getOutConnectionPoint();
353   myPointOut->setCoords(out.x(), out.y());
354 }
355
356 void SUPERVGUI_CanvasNodePrs::updatePorts() 
357 {
358   bool aDisp = isVisible();
359   if (aDisp) hide();
360
361   QRect r = getBodyRect();
362   int w = (int)(r.width()/2) - PORT_MARGIN; 
363   if (w < PORT_WIDTH) w = PORT_WIDTH;
364
365   int ix = r.x() + PORT_MARGIN;
366   int ih = r.y() + PORT_MARGIN;
367   int ox = ix + w;
368   int oh = r.y() + PORT_MARGIN;
369
370   const QObjectList* list = myNode->children();
371   if (list) {
372     QObjectListIt it(*list);
373     SUPERVGUI_CanvasPort* aPort;
374     while (QObject* obj = it.current()) {
375       ++it;
376       if (obj->inherits("SUPERVGUI_CanvasPort")) {
377         aPort = (SUPERVGUI_CanvasPort*) obj;
378         if (!aPort->getEngine()->IsGate() && !aPort->isStream()) {
379           if (aPort->getEngine()->IsInput()) {
380             aPort->getPrs()->setPortRect(QRect(ix, ih, w, PORT_HEIGHT));
381             ih += PORT_HEIGHT;
382           }
383           else {
384             aPort->getPrs()->setPortRect(QRect(ox, oh, w, PORT_HEIGHT));
385             oh += PORT_HEIGHT;
386           }
387         }
388       }
389     }
390   }
391
392   myPortHeight = (ih>oh?ih:oh) - r.y() + PORT_MARGIN;
393
394   // update stream ports
395   int sy = r.y() + myPortHeight;
396   ih = sy + PORT_MARGIN;
397   oh = sy + PORT_MARGIN;
398
399   if (list) {
400     QObjectListIt it(*list);
401     SUPERVGUI_CanvasPort* aPort;
402     while (QObject* obj = it.current()) {
403       ++it;
404       if (obj->inherits("SUPERVGUI_CanvasPort")) {
405         aPort = (SUPERVGUI_CanvasPort*) obj;
406         if (!aPort->getEngine()->IsGate() && aPort->isStream()) {
407           if (aPort->getEngine()->IsInput()) {
408             aPort->getPrs()->setPortRect(QRect(ix, ih, w, PORT_HEIGHT));
409             ih += PORT_HEIGHT;
410           }
411           else {
412             aPort->getPrs()->setPortRect(QRect(ox, oh, w, PORT_HEIGHT));
413             oh += PORT_HEIGHT;
414           }
415         }
416       }
417     }
418   }
419
420   myStreamHeight = (ih>oh?ih:oh) - sy + PORT_MARGIN;
421   if (myStreamHeight == 2*PORT_MARGIN) myStreamHeight = 0;
422
423   // can update gates only after body height will be defined
424   updateGates();
425
426   if (aDisp) {
427     show();
428     canvas()->update();
429   }
430 }
431
432 void SUPERVGUI_CanvasNodePrs::updateGates() 
433 {
434   bool aDisp = isVisible();
435   if (aDisp) hide();
436
437   QRect r = getGateRect();
438   int w = (int)(r.width()/2) - PORT_MARGIN; 
439   if (w < PORT_WIDTH) w = PORT_WIDTH;
440
441   int ix = r.x() + PORT_MARGIN;
442   int ih = r.y() + PORT_MARGIN;
443   int ox = ix + w;
444   int oh = r.y() + PORT_MARGIN;
445
446   const QObjectList* list = myNode->children();
447   if (list) {
448     QObjectListIt it(*list);
449     SUPERVGUI_CanvasPort* aPort;
450     while (QObject* obj = it.current()) {
451       ++it;
452       if (obj->inherits("SUPERVGUI_CanvasPort")) {
453         aPort = (SUPERVGUI_CanvasPort*) obj;
454         if (aPort->getEngine()->IsGate()) {
455           if (aPort->getEngine()->IsInput()) {
456             aPort->getPrs()->setPortRect(QRect(ix, ih, w, PORT_HEIGHT));
457             ih += PORT_HEIGHT;
458           }
459           else {
460             aPort->getPrs()->setPortRect(QRect(ox, oh, w, PORT_HEIGHT));
461             oh += PORT_HEIGHT;
462           }
463         }
464       }
465     }
466   }
467   
468   myGateHeight = (ih>oh?ih:oh) - r.y() + PORT_MARGIN;
469
470   if (aDisp) show();
471 }
472
473 QRect SUPERVGUI_CanvasNodePrs::getRect() const
474 {
475   return QRect((int)x(), (int)y(), width(), height());
476 }
477
478 QRect SUPERVGUI_CanvasNodePrs::getTitleRect() const
479 {
480   return QRect((int)x(), (int)y(), width(), getTitleHeight());
481 }
482
483 QRect SUPERVGUI_CanvasNodePrs::getLabelRect() const
484 {
485   return QRect((int)x(), ((int)y())+getTitleHeight(), width(), getLabelHeight());
486 }
487
488 QRect SUPERVGUI_CanvasNodePrs::getStatusRect() const
489 {
490   return QRect((int)x(), ((int)y())+getTitleHeight()+getLabelHeight(),
491                width(), getStatusHeight());
492 }
493
494 QRect SUPERVGUI_CanvasNodePrs::getBodyRect() const
495 {
496   return QRect((int)x(), ((int)y())+getTitleHeight()+getLabelHeight()+getStatusHeight(), 
497                width(), getBodyHeight());
498 }
499
500 QRect SUPERVGUI_CanvasNodePrs::getGateRect() const
501 {
502   return QRect((int)x(), ((int)y())+getTitleHeight()+getLabelHeight()+
503                getStatusHeight()+getBodyHeight(), 
504                width(), getGateHeight());
505 }
506
507 QPoint SUPERVGUI_CanvasNodePrs::getInConnectionPoint() const
508 {
509   QRect r = getGateRect();
510   int h;
511   if (isPortVisible()) {
512     h = (int)((r.top()+r.bottom())/2);
513   }
514   else {
515     h = (int)(y()+height()/2);
516   }
517   return QPoint(r.left()-POINT_SIZE, h);
518 }
519
520 QPoint SUPERVGUI_CanvasNodePrs::getOutConnectionPoint() const
521 {
522   QRect r = getGateRect();
523   int h;
524   if (isPortVisible()) {
525     h = (int)((r.top()+r.bottom())/2);
526   }
527   else {
528     h = (int)y() + (int)(height()/2);
529   }
530   return QPoint(r.right()+POINT_SIZE, h);
531 }
532
533 void drawText(QPainter& thePainter, const QString& theText, 
534               const QRect& theRect, int theHAlign = Qt::AlignAuto)
535 {
536   int flags = theHAlign | Qt::AlignVCenter;
537   QRect r(theRect.x() + TEXT_MARGIN, theRect.y(), 
538           theRect.width() - 2*TEXT_MARGIN, theRect.height());
539
540   QWMatrix aMat = thePainter.worldMatrix();
541   if (aMat.m11() != 1.0) { 
542     // for scaled picture only
543     QRect r1 = aMat.mapRect(r);
544     QFont saved = thePainter.font();
545     QFont f(saved);
546     if (f.pointSize() == -1) {
547       f.setPixelSize(f.pixelSize()*aMat.m11());
548     }
549     else {
550       f.setPointSize(f.pointSize()*aMat.m11());
551     }
552     thePainter.save();
553     QWMatrix m;
554     thePainter.setWorldMatrix(m);
555     thePainter.setFont(f);
556     thePainter.drawText(r1, flags, theText);
557     thePainter.setFont(saved);
558     thePainter.restore();
559   }
560   else {
561     thePainter.drawText(r, flags, theText);
562   }
563 }
564
565 void SUPERVGUI_CanvasNodePrs::draw(QPainter& thePainter) 
566 {
567   thePainter.setPen(pen());
568   thePainter.setBrush(nodeColor());
569   drawShape(thePainter);
570 }
571
572 void SUPERVGUI_CanvasNodePrs::drawShape(QPainter& thePainter) 
573 {
574   drawTitle(thePainter);
575   if (isLabelVisible()) {
576     drawLabel(thePainter);
577   }
578   if (isPortVisible()) {
579     drawPort(thePainter);
580     drawGate(thePainter);
581   }
582   drawStatus(thePainter);
583   drawFrame(thePainter);
584 }
585
586 void SUPERVGUI_CanvasNodePrs::drawFrame(QPainter& thePainter) 
587 {
588   /* it was a good idea, but...
589      drawed polyline is out of item boundaries :-(
590   QPointArray pnts = areaPoints();
591   int n = pnts.size();
592   pnts.resize(n+1);
593   pnts[n] = pnts[0];
594   thePainter.drawPolyline(pnts);
595   */
596
597   QBrush saved = thePainter.brush();
598   thePainter.setBrush(NoBrush);
599   thePainter.drawRect(getRect());
600   thePainter.setBrush(saved);
601 }
602
603 void SUPERVGUI_CanvasNodePrs::drawTitle(QPainter& thePainter) 
604 {
605   QBrush saved = thePainter.brush();
606   QBrush br(MAIN_TITLE);
607   thePainter.setBrush(br);
608   drawTitleShape(thePainter);
609   thePainter.setBrush(saved);
610
611   drawText(thePainter, myNode->getEngine()->Name(), getTitleRect(), Qt::AlignHCenter);
612 }
613
614 void SUPERVGUI_CanvasNodePrs::drawTitleShape(QPainter& thePainter) 
615 {
616   thePainter.drawRect(getTitleRect());
617 }
618
619 void SUPERVGUI_CanvasNodePrs::drawLabel(QPainter& thePainter) 
620 {
621   QRect r = getLabelRect();
622
623   QPen saved = thePainter.pen();
624   thePainter.setPen(NoPen);
625   thePainter.drawRect(r);
626   thePainter.setPen(saved);
627
628   //  drawText(thePainter, myNode->getEngine()->Comment(), r);
629   drawText(thePainter, myNode->getLabelText(), r);
630 }
631
632 void SUPERVGUI_CanvasNodePrs::drawStatus(QPainter& thePainter) 
633 {
634   QRect r = getStatusRect();
635   if (isPortVisible())
636     r.setHeight(r.height()+1);
637
638   QBrush savedB = thePainter.brush();
639   thePainter.setBrush(myStatusColor);
640   drawStatusShape(thePainter);
641   thePainter.setBrush(savedB);
642
643   QRect r1(r.x(), r.y(), (int)r.width()/2, r.height());
644   drawText(thePainter, myStatus, r1, Qt::AlignHCenter);
645
646   QRect r2(r.x()+r.width()-r1.width(), r.y(), r1.width(), r.height());
647   drawText(thePainter, myTime, r2, Qt::AlignHCenter);
648 }
649
650 void SUPERVGUI_CanvasNodePrs::drawStatusShape(QPainter& thePainter) 
651 {
652   QRect r = getStatusRect();
653   if (isPortVisible())
654     r.setHeight(r.height()+1);
655   thePainter.drawRect(r);
656 }
657
658 void SUPERVGUI_CanvasNodePrs::drawPort(QPainter& thePainter) 
659 {
660   QRect r = getBodyRect();
661   r.setHeight(r.height()+1);
662
663   thePainter.drawRect(r);
664   int x0 = (r.left() + r.right())/2;
665   thePainter.drawLine(x0, r.top(), x0, r.bottom());
666   if (getStreamHeight() > 0) {
667     int y0 = r.top() + getPortHeight();
668     thePainter.drawLine(r.left(), y0, r.right(), y0);
669   }
670
671   const QObjectList* list = myNode->children();
672   if (list) {
673     QObjectListIt it(*list);
674     SUPERVGUI_CanvasPort* aPort;
675     while (QObject* obj = it.current()) {
676       ++it;
677       if (obj->inherits("SUPERVGUI_CanvasPort")) {
678         aPort = (SUPERVGUI_CanvasPort*) obj;
679         if (!aPort->getEngine()->IsGate()) {
680           aPort->getPrs()->draw(thePainter);
681         }
682       }
683     }
684   }
685 }
686
687 void SUPERVGUI_CanvasNodePrs::drawGate(QPainter& thePainter) 
688 {
689   QBrush saved = thePainter.brush();
690   thePainter.setBrush(green.light(170));
691
692   QRect r = getGateRect();
693   //  r.setHeight(r.height()+1);
694   thePainter.drawRect(r);
695   int x0 = (r.left() + r.right())/2;
696   //  thePainter.drawLine(x0, r.top(), x0, r.bottom());
697
698   const QObjectList* list = myNode->children();
699   if (list) {
700     QObjectListIt it(*list);
701     SUPERVGUI_CanvasPort* aPort;
702     while (QObject* obj = it.current()) {
703       ++it;
704       if (obj->inherits("SUPERVGUI_CanvasPort")) {
705         aPort = (SUPERVGUI_CanvasPort*) obj;
706         if (aPort->getEngine()->IsGate()) {
707           aPort->getPrs()->draw(thePainter);
708         }
709       }
710     }
711   }
712
713   thePainter.setBrush(saved);
714 }
715
716 void SUPERVGUI_CanvasNodePrs::setState(SUPERV::GraphState theState)
717 {
718   switch(theState) {
719   case SUPERV_Waiting:
720     myStatus = "Waiting";
721     myStatusColor = QColor(35, 192, 255);
722     break;
723
724   case SUPERV_Running:
725   case SUPERV::ReadyState:
726     myStatus = "Running";
727     myStatusColor = QColor(32,210,32);
728     break;
729
730   case SUPERV_Suspend:
731   case SUPERV::SuspendReadyState:
732     myStatus = "Suspended";
733     myStatusColor = QColor(255,180, 0);
734     break;
735
736   case SUPERV_Done:
737     myStatus = "Finished";
738     myStatusColor = QColor(255, 158, 255);
739     break;
740
741   case SUPERV_Error: 
742     myStatus = "Aborted";
743     myStatusColor = red;
744     break;
745
746   case SUPERV_Kill:
747     myStatus = "Killed";
748     myStatusColor = red;
749     break;
750
751   case SUPERV::LoadingState:
752     myStatus = "Loading";
753     myStatusColor = QColor(56,255,56);
754     break;
755
756   default:
757     myStatus = "No Status";
758     myStatusColor = MAIN_BACK;
759     break;
760   }
761
762   long sec = myNode->getEngine()->CpuUsed();
763   char hms[9];
764   long s = sec/3600;
765   hms[0]=(char)(((s/10)%10)+48);
766   hms[1]=(char)((s%10)+48);
767   hms[2]=':';
768   sec = sec%3600;
769   s = sec/60;
770   hms[3]=(char)((s/10)+48);
771   hms[4]=(char)((s%10)+48);
772   hms[5]=':';
773   sec = sec%60;
774   hms[6]=(char)((sec/10)+48);
775   hms[7]=(char)((sec%10)+48);
776   hms[8]='\0';
777   myTime = QString(hms);
778
779   canvas()->setChanged(getStatusRect());
780   canvas()->update();
781 }
782
783
784 //=====================================================================
785 // Port presentation
786 //=====================================================================
787 SUPERVGUI_CanvasPortPrs::SUPERVGUI_CanvasPortPrs(QCanvas* theCanvas, 
788                                                  SUPERVGUI_CanvasPort* thePort):
789   myCanvas(theCanvas), myPort(thePort)
790 {
791   myText = getText();
792   myVisible = true;
793   myPoint = new SUPERVGUI_CanvasHookPrs(theCanvas, this, myPort->getEngine()->IsInput());
794 }
795
796 SUPERVGUI_CanvasPortPrs::~SUPERVGUI_CanvasPortPrs()
797 {
798   if (myPoint) delete myPoint;
799 }
800
801 void SUPERVGUI_CanvasPortPrs::setVisible(bool b)
802 {
803   if (myPoint) myPoint->setVisible(b);
804   myVisible = b;
805   myPort->updateLinks();
806 }
807
808 void SUPERVGUI_CanvasPortPrs::setPortRect(const QRect& theRect)
809 {
810   myRect = theRect;
811   QPoint aPnt = getConnectionPoint();
812 //   int dx = 0;
813 //   if (myPort->getEngine()->IsInput()) 
814 //     dx = POINT_SIZE;
815 //   else
816 //     dx = - POINT_SIZE;
817 //   QPoint aPnt2(aPnt.x()+dx, aPnt.y());
818
819 //   if (myLine) {
820 //     myLine->move(0, 0);
821 //     myLine->setPoints(aPnt2.x(), aPnt2.y(), aPnt.x(), aPnt.y());
822 //     if (myVisible) myLine->show();
823 //   }
824   if (myPoint) {
825     myPoint->setCoords(aPnt.x(), aPnt.y());
826     //    myPoint->move(aPnt.x(), aPnt.y());
827     if (myVisible) myPoint->show();
828   }
829   myPort->updateLinks();
830 }
831
832 void SUPERVGUI_CanvasPortPrs::moveBy(int dx, int dy)
833 {
834   myRect.moveBy(dx, dy);
835   if (myPoint) myPoint->moveBy(dx, dy);
836   //  if (myLine) myLine->moveBy(dx, dy);
837 }
838
839 void SUPERVGUI_CanvasPortPrs::setZ(double z)
840 {
841   if (myPoint) myPoint->setZ(z);
842   //  if (myLine) myLine->setZ(z);
843 }
844
845 void SUPERVGUI_CanvasPortPrs::update(bool theForce)
846 {
847   QString aNewText = getText();
848   if (theForce || myText.compare(aNewText) != 0) {
849     myText = aNewText;
850     myCanvas->setChanged(myRect);
851   }
852 }
853
854 bool SUPERVGUI_CanvasPortPrs::isHilight() const
855 {
856   SUPERV_Port aPort = myPort->getEngine();
857   bool b = false;
858   if (!aPort->IsGate()) {
859     if (aPort->IsInput()) {
860       if (aPort->HasInput() && !aPort->IsLinked())
861         b = true;
862     }
863     else if (myPort->inherits("SUPERVGUI_CanvasPortOut")) {
864       SUPERVGUI_CanvasPortOut* aPortOut = (SUPERVGUI_CanvasPortOut*) myPort;
865       if (aPortOut->isInStudy())
866         b = true;
867     }
868   }
869   return b;
870 }
871
872 bool SUPERVGUI_CanvasPortPrs::isAlert() const
873 {
874   bool b = false;
875   SUPERV_Port aPort = myPort->getEngine();
876   if (!aPort->IsGate()) {
877     if (aPort->IsInput() && !aPort->HasInput() && !aPort->IsLinked())
878       b = true;
879   }
880   return b;
881 }
882
883 QString SUPERVGUI_CanvasPortPrs::getText() const
884 {
885   SUPERV_Port aPort = myPort->getEngine();
886   QString aText = aPort->Name();
887   if (aPort->IsParam() || aPort->IsInLine() || myPort->isStream())
888     aText = aText + "=" + aPort->ToString();
889   return aText;
890 }
891
892 int SUPERVGUI_CanvasPortPrs::getAlignment() const
893 {
894   int a = Qt::AlignAuto;
895   SUPERV_Port aPort = myPort->getEngine();
896   /*  Merge to Ecole_Ete
897   if (QString(aPort->Name()).compare(OUTVOID) == 0)
898     a = Qt::AlignRight;
899   */
900   if (aPort->IsGate()) {
901     if (aPort->IsInput())
902       a = Qt::AlignLeft;
903     else
904       a = Qt::AlignRight;
905   }
906   return a;
907 }
908
909 QPoint SUPERVGUI_CanvasPortPrs::getConnectionPoint() const
910 {
911   int x, y;
912   if (myPort->getEngine()->IsInput())
913     x = myRect.left() - PORT_MARGIN - POINT_SIZE;
914   else
915     x = myRect.right() + PORT_MARGIN + POINT_SIZE;
916   y = (int)(myRect.top() + myRect.bottom())/2;
917   return QPoint(x, y);
918 }
919
920 void SUPERVGUI_CanvasPortPrs::draw(QPainter& thePainter)
921 {
922   /*
923   QPen savedP = thePainter.pen();
924   QBrush savedB = thePainter.brush();
925
926   QPen aPen(savedP.color(), getLineWidth());
927   thePainter.setPen(aPen);
928   thePainter.setBrush(Qt::NoBrush);
929   thePainter.drawRect(myRect);
930   thePainter.setPen(savedP);
931   thePainter.setBrush(savedB);
932   */
933   QFont saved = thePainter.font();
934   QFont f(saved);
935   f.setBold(isHilight());
936   thePainter.setFont(f);
937
938   QPen savedP = thePainter.pen();
939   if (myPort->isStream())
940     thePainter.setPen(QColor(128, 64, 0));// Qt::darkCyan);
941   else if (isHilight())
942     thePainter.setPen(Qt::blue);
943   else if (isAlert())
944     thePainter.setPen(Qt::red.dark(120));
945
946   drawText(thePainter, myText, myRect, getAlignment());
947
948   thePainter.setPen(savedP);
949   thePainter.setFont(saved);
950 }
951
952
953 //=====================================================================
954 // Node presentation
955 //=====================================================================
956 SUPERVGUI_CanvasHookPrs::SUPERVGUI_CanvasHookPrs(QCanvas* theCanvas, 
957                                                  SUPERVGUI_CanvasNodePrs* theNode,
958                                                  const bool& theIn):
959   QCanvasEllipse(POINT_SIZE, POINT_SIZE, theCanvas),
960   myNodePrs(theNode), myPortPrs(0), myIn(theIn), myLine(0)
961 {
962   init(theCanvas);
963 }
964
965 SUPERVGUI_CanvasHookPrs::SUPERVGUI_CanvasHookPrs(QCanvas* theCanvas, 
966                                                  SUPERVGUI_CanvasPortPrs* thePort,
967                                                  const bool& theIn):
968   QCanvasEllipse(POINT_SIZE, POINT_SIZE, theCanvas),
969   myNodePrs(0), myPortPrs(thePort), myIn(theIn), myLine(0)
970 {
971   init(theCanvas);
972 }
973
974 void SUPERVGUI_CanvasHookPrs::init(QCanvas* theCanvas)
975 {
976   myLine = new QCanvasLine(theCanvas);
977
978   setBrush(Qt::black);
979   myLine->setPen(QPen(Qt::black, 1));
980
981   setZ(0);
982 }
983
984 SUPERVGUI_CanvasHookPrs::~SUPERVGUI_CanvasHookPrs()
985 {
986   hide();
987   if (myLine) {
988     delete myLine;
989     myLine = 0;
990   }
991 }
992
993 QObject* SUPERVGUI_CanvasHookPrs::getObject() const
994 {
995   QObject* anObj = 0;
996   if (myNodePrs)
997     anObj = myNodePrs->getNode();
998   else if (myPortPrs)
999     anObj = myPortPrs->getPort();
1000   return anObj;
1001 }
1002
1003 void SUPERVGUI_CanvasHookPrs::setCoords(int x, int y)
1004 {
1005   move(x, y);
1006   if (myLine) {
1007     myLine->move(0, 0);
1008     myLine->setPoints(x+(myIn?POINT_SIZE:-POINT_SIZE), y, x, y);
1009   }
1010 }
1011
1012 void SUPERVGUI_CanvasHookPrs::setVisible(bool b)
1013 {
1014   QCanvasEllipse::setVisible(b);
1015   if (myLine) myLine->setVisible(b);
1016 }
1017
1018 void SUPERVGUI_CanvasHookPrs::moveBy(double dx, double dy)
1019 {
1020   QCanvasEllipse::moveBy(dx, dy);
1021   if (myLine) myLine->moveBy(dx, dy);
1022 }
1023
1024 void SUPERVGUI_CanvasHookPrs::setZ(double z)
1025 {
1026   QCanvasEllipse::setZ(z);
1027   if (myLine) myLine->setZ(z);
1028 }
1029
1030 int SUPERVGUI_CanvasHookPrs::rtti() const
1031 {
1032   return SUPERVGUI_Canvas::Rtti_Hook;
1033 }