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