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