Salome HOME
d82abd2a81bec413dc67b51a4faebf7120ff500c
[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 #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   drawShape(thePainter);
565 }
566
567 void SUPERVGUI_CanvasNodePrs::drawShape(QPainter& thePainter) 
568 {
569   drawTitle(thePainter);
570   if (isLabelVisible()) {
571     drawLabel(thePainter);
572   }
573   if (isPortVisible()) {
574     drawPort(thePainter);
575     drawGate(thePainter);
576   }
577   drawStatus(thePainter);
578   drawFrame(thePainter);
579 }
580
581 void SUPERVGUI_CanvasNodePrs::drawFrame(QPainter& thePainter) 
582 {
583   /* it was a good idea, but...
584      drawed polyline is out of item boundaries :-(
585   QPointArray pnts = areaPoints();
586   int n = pnts.size();
587   pnts.resize(n+1);
588   pnts[n] = pnts[0];
589   thePainter.drawPolyline(pnts);
590   */
591
592   QBrush saved = thePainter.brush();
593   thePainter.setBrush(NoBrush);
594   thePainter.drawRect(getRect());
595   thePainter.setBrush(saved);
596 }
597
598 void SUPERVGUI_CanvasNodePrs::drawTitle(QPainter& thePainter) 
599 {
600   QBrush saved = thePainter.brush();
601   QBrush br( myMgr->colorValue( "SUPERVGraph", "Title", DEF_MAIN_TITLE ) );
602   thePainter.setBrush(br);
603   drawTitleShape(thePainter);
604   thePainter.setBrush(saved);
605
606   drawText(thePainter, myNode->getEngine()->Name(), getTitleRect(), Qt::AlignHCenter);
607 }
608
609 void SUPERVGUI_CanvasNodePrs::drawTitleShape(QPainter& thePainter) 
610 {
611   thePainter.drawRect(getTitleRect());
612 }
613
614 void SUPERVGUI_CanvasNodePrs::drawLabel(QPainter& thePainter) 
615 {
616   QRect r = getLabelRect();
617
618   QPen saved = thePainter.pen();
619   thePainter.setPen(NoPen);
620   thePainter.drawRect(r);
621   thePainter.setPen(saved);
622
623   //  drawText(thePainter, myNode->getEngine()->Comment(), r);
624   drawText(thePainter, myNode->getLabelText(), r);
625 }
626
627 void SUPERVGUI_CanvasNodePrs::drawStatus(QPainter& thePainter) 
628 {
629   QRect r = getStatusRect();
630   if (isPortVisible())
631     r.setHeight(r.height()+1);
632
633   QBrush savedB = thePainter.brush();
634   thePainter.setBrush(myStatusColor);
635   drawStatusShape(thePainter);
636   thePainter.setBrush(savedB);
637
638   QRect r1(r.x(), r.y(), (int)r.width()/2, r.height());
639   drawText(thePainter, myStatus, r1, Qt::AlignHCenter);
640
641   QRect r2(r.x()+r.width()-r1.width(), r.y(), r1.width(), r.height());
642   drawText(thePainter, myTime, r2, Qt::AlignHCenter);
643 }
644
645 void SUPERVGUI_CanvasNodePrs::drawStatusShape(QPainter& thePainter) 
646 {
647   QRect r = getStatusRect();
648   if (isPortVisible())
649     r.setHeight(r.height()+1);
650   thePainter.drawRect(r);
651 }
652
653 void SUPERVGUI_CanvasNodePrs::drawPort(QPainter& thePainter) 
654 {
655   QRect r = getBodyRect();
656   r.setHeight(r.height()+1);
657
658   thePainter.drawRect(r);
659   int x0 = (r.left() + r.right())/2;
660   thePainter.drawLine(x0, r.top(), x0, r.bottom());
661   if (getStreamHeight() > 0) {
662     int y0 = r.top() + getPortHeight();
663     thePainter.drawLine(r.left(), y0, r.right(), y0);
664   }
665
666   const QObjectList* list = myNode->children();
667   if (list) {
668     QObjectListIt it(*list);
669     SUPERVGUI_CanvasPort* aPort;
670     while (QObject* obj = it.current()) {
671       ++it;
672       if (obj->inherits("SUPERVGUI_CanvasPort")) {
673         aPort = (SUPERVGUI_CanvasPort*) obj;
674         if (!aPort->getEngine()->IsGate()) {
675           aPort->getPrs()->draw(thePainter);
676         }
677       }
678     }
679   }
680 }
681
682 void SUPERVGUI_CanvasNodePrs::drawGate(QPainter& thePainter) 
683 {
684   QBrush saved = thePainter.brush();
685   thePainter.setBrush(green.light(170));
686
687   QRect r = getGateRect();
688   //  r.setHeight(r.height()+1);
689   thePainter.drawRect(r);
690   //int x0 = (r.left() + r.right())/2;
691   //  thePainter.drawLine(x0, r.top(), x0, r.bottom());
692
693   const QObjectList* list = myNode->children();
694   if (list) {
695     QObjectListIt it(*list);
696     SUPERVGUI_CanvasPort* aPort;
697     while (QObject* obj = it.current()) {
698       ++it;
699       if (obj->inherits("SUPERVGUI_CanvasPort")) {
700         aPort = (SUPERVGUI_CanvasPort*) obj;
701         if (aPort->getEngine()->IsGate()) {
702           aPort->getPrs()->draw(thePainter);
703         }
704       }
705     }
706   }
707
708   thePainter.setBrush(saved);
709 }
710
711 void SUPERVGUI_CanvasNodePrs::setState(SUPERV::GraphState theState)
712 {
713   switch(theState) {
714   case SUPERV_Waiting:
715     myStatus = "Waiting";
716     myStatusColor = QColor(35, 192, 255);
717     break;
718
719   case SUPERV_Running:
720   case SUPERV::ReadyState:
721     myStatus = "Running";
722     myStatusColor = QColor(32,210,32);
723     break;
724
725   case SUPERV_Suspend:
726   case SUPERV::SuspendReadyState:
727     myStatus = "Suspended";
728     myStatusColor = QColor(255,180, 0);
729     break;
730
731   case SUPERV_Done:
732     myStatus = "Finished";
733     myStatusColor = QColor(255, 158, 255);
734     break;
735
736   case SUPERV_Error: 
737     myStatus = "Aborted";
738     myStatusColor = red;
739     break;
740
741   case SUPERV_Kill:
742     myStatus = "Killed";
743     myStatusColor = red;
744     break;
745
746   case SUPERV::LoadingState:
747     myStatus = "Loading";
748     myStatusColor = QColor(56,255,56);
749     break;
750
751   default:
752     myStatus = "No Status";
753     myStatusColor = myMgr->colorValue( "SUPERVGraph", "NodeBody", DEF_MAIN_BACK );
754     break;
755   }
756
757   long sec = myNode->getEngine()->CpuUsed();
758   char hms[9];
759   long s = sec/3600;
760   hms[0]=(char)(((s/10)%10)+48);
761   hms[1]=(char)((s%10)+48);
762   hms[2]=':';
763   sec = sec%3600;
764   s = sec/60;
765   hms[3]=(char)((s/10)+48);
766   hms[4]=(char)((s%10)+48);
767   hms[5]=':';
768   sec = sec%60;
769   hms[6]=(char)((sec/10)+48);
770   hms[7]=(char)((sec%10)+48);
771   hms[8]='\0';
772   myTime = QString(hms);
773
774   canvas()->setChanged(getStatusRect());
775   canvas()->update();
776 }
777
778
779 //=====================================================================
780 // Port presentation
781 //=====================================================================
782 SUPERVGUI_CanvasPortPrs::SUPERVGUI_CanvasPortPrs(QCanvas* theCanvas, 
783                                                  SUPERVGUI_CanvasPort* thePort):
784   myCanvas(theCanvas), myPort(thePort)
785 {
786   myText = getText();
787   myVisible = true;
788   myPoint = new SUPERVGUI_CanvasHookPrs(theCanvas, this, myPort->getEngine()->IsInput());
789 }
790
791 SUPERVGUI_CanvasPortPrs::~SUPERVGUI_CanvasPortPrs()
792 {
793   if (myPoint) delete myPoint;
794 }
795
796 void SUPERVGUI_CanvasPortPrs::setVisible(bool b)
797 {
798   if (myPoint) myPoint->setVisible(b);
799   myVisible = b;
800   myPort->updateLinks();
801 }
802
803 void SUPERVGUI_CanvasPortPrs::setPortRect(const QRect& theRect)
804 {
805   myRect = theRect;
806   QPoint aPnt = getConnectionPoint();
807 //   int dx = 0;
808 //   if (myPort->getEngine()->IsInput()) 
809 //     dx = POINT_SIZE;
810 //   else
811 //     dx = - POINT_SIZE;
812 //   QPoint aPnt2(aPnt.x()+dx, aPnt.y());
813
814 //   if (myLine) {
815 //     myLine->move(0, 0);
816 //     myLine->setPoints(aPnt2.x(), aPnt2.y(), aPnt.x(), aPnt.y());
817 //     if (myVisible) myLine->show();
818 //   }
819   if (myPoint) {
820     myPoint->setCoords(aPnt.x(), aPnt.y());
821     //    myPoint->move(aPnt.x(), aPnt.y());
822     if (myVisible) myPoint->show();
823   }
824   myPort->updateLinks();
825 }
826
827 void SUPERVGUI_CanvasPortPrs::moveBy(int dx, int dy)
828 {
829   myRect.moveBy(dx, dy);
830   if (myPoint) myPoint->moveBy(dx, dy);
831   //  if (myLine) myLine->moveBy(dx, dy);
832 }
833
834 void SUPERVGUI_CanvasPortPrs::setZ(double z)
835 {
836   if (myPoint) myPoint->setZ(z);
837   //  if (myLine) myLine->setZ(z);
838 }
839
840 void SUPERVGUI_CanvasPortPrs::update(bool theForce)
841 {
842   QString aNewText = getText();
843   if (theForce || myText.compare(aNewText) != 0) {
844     myText = aNewText;
845     myCanvas->setChanged(myRect);
846   }
847 }
848
849 bool SUPERVGUI_CanvasPortPrs::isHilight() const
850 {
851   SUPERV_Port aPort = myPort->getEngine();
852   bool b = false;
853   if (!aPort->IsGate()) {
854     if (aPort->IsInput()) {
855       if (aPort->HasInput() && !aPort->IsLinked())
856         b = true;
857     }
858     else if (myPort->inherits("SUPERVGUI_CanvasPortOut")) {
859       SUPERVGUI_CanvasPortOut* aPortOut = (SUPERVGUI_CanvasPortOut*) myPort;
860       if (aPortOut->isInStudy())
861         b = true;
862     }
863   }
864   return b;
865 }
866
867 bool SUPERVGUI_CanvasPortPrs::isAlert() const
868 {
869   bool b = false;
870   SUPERV_Port aPort = myPort->getEngine();
871   if (!aPort->IsGate()) {
872     if (aPort->IsInput() && !aPort->HasInput() && !aPort->IsLinked())
873       b = true;
874   }
875   return b;
876 }
877
878 QString SUPERVGUI_CanvasPortPrs::getText() const
879 {
880   SUPERV_Port aPort = myPort->getEngine();
881   QString aText = aPort->Name();
882   if (aPort->IsParam() || aPort->IsInLine() || myPort->isStream())
883     aText = aText + "=" + aPort->ToString();
884   return aText;
885 }
886
887 int SUPERVGUI_CanvasPortPrs::getAlignment() const
888 {
889   int a = Qt::AlignAuto;
890   SUPERV_Port aPort = myPort->getEngine();
891   /*  Merge to Ecole_Ete
892   if (QString(aPort->Name()).compare(OUTVOID) == 0)
893     a = Qt::AlignRight;
894   */
895   if (aPort->IsGate()) {
896     if (aPort->IsInput())
897       a = Qt::AlignLeft;
898     else
899       a = Qt::AlignRight;
900   }
901   return a;
902 }
903
904 QPoint SUPERVGUI_CanvasPortPrs::getConnectionPoint() const
905 {
906   int x, y;
907   if (myPort->getEngine()->IsInput())
908     x = myRect.left() - PORT_MARGIN - POINT_SIZE;
909   else
910     x = myRect.right() + PORT_MARGIN + POINT_SIZE;
911   y = (int)(myRect.top() + myRect.bottom())/2;
912   return QPoint(x, y);
913 }
914
915 void SUPERVGUI_CanvasPortPrs::draw(QPainter& thePainter)
916 {
917   /*
918   QPen savedP = thePainter.pen();
919   QBrush savedB = thePainter.brush();
920
921   QPen aPen(savedP.color(), getLineWidth());
922   thePainter.setPen(aPen);
923   thePainter.setBrush(Qt::NoBrush);
924   thePainter.drawRect(myRect);
925   thePainter.setPen(savedP);
926   thePainter.setBrush(savedB);
927   */
928   QFont saved = thePainter.font();
929   QFont f(saved);
930   f.setBold(isHilight());
931   thePainter.setFont(f);
932
933   QPen savedP = thePainter.pen();
934   if (myPort->isStream())
935     thePainter.setPen(QColor(128, 64, 0));// Qt::darkCyan);
936   else if (isHilight())
937     thePainter.setPen(Qt::blue);
938   else if (isAlert())
939     thePainter.setPen(Qt::red.dark(120));
940
941   drawText(thePainter, myText, myRect, getAlignment());
942
943   thePainter.setPen(savedP);
944   thePainter.setFont(saved);
945 }
946
947
948 //=====================================================================
949 // Node presentation
950 //=====================================================================
951 SUPERVGUI_CanvasHookPrs::SUPERVGUI_CanvasHookPrs(QCanvas* theCanvas, 
952                                                  SUPERVGUI_CanvasNodePrs* theNode,
953                                                  const bool& theIn):
954   QCanvasEllipse(POINT_SIZE, POINT_SIZE, theCanvas),
955   myNodePrs(theNode), myPortPrs(0), myIn(theIn), myLine(0)
956 {
957   init(theCanvas);
958 }
959
960 SUPERVGUI_CanvasHookPrs::SUPERVGUI_CanvasHookPrs(QCanvas* theCanvas, 
961                                                  SUPERVGUI_CanvasPortPrs* thePort,
962                                                  const bool& theIn):
963   QCanvasEllipse(POINT_SIZE, POINT_SIZE, theCanvas),
964   myNodePrs(0), myPortPrs(thePort), myIn(theIn), myLine(0)
965 {
966   init(theCanvas);
967 }
968
969 void SUPERVGUI_CanvasHookPrs::init(QCanvas* theCanvas)
970 {
971   myLine = new QCanvasLine(theCanvas);
972
973   setBrush(Qt::black);
974   myLine->setPen(QPen(Qt::black, 1));
975
976   setZ(0);
977 }
978
979 SUPERVGUI_CanvasHookPrs::~SUPERVGUI_CanvasHookPrs()
980 {
981   hide();
982   if ( myLine ) {
983     delete myLine;
984     myLine = 0;
985   }
986 }
987
988 QObject* SUPERVGUI_CanvasHookPrs::getObject() const
989 {
990   QObject* anObj = 0;
991   if ( myNodePrs )
992     anObj = myNodePrs->getNode();
993   else if ( myPortPrs )
994     anObj = myPortPrs->getPort();
995   return anObj;
996 }
997
998 void SUPERVGUI_CanvasHookPrs::setCoords(int x, int y)
999 {
1000   move(x, y);
1001   if (myLine) {
1002     myLine->move(0, 0);
1003     myLine->setPoints(x+(myIn?POINT_SIZE:-POINT_SIZE), y, x, y);
1004   }
1005 }
1006
1007 void SUPERVGUI_CanvasHookPrs::setVisible(bool b)
1008 {
1009   QCanvasEllipse::setVisible(b);
1010   if (myLine) myLine->setVisible(b);
1011 }
1012
1013 void SUPERVGUI_CanvasHookPrs::moveBy(double dx, double dy)
1014 {
1015   QCanvasEllipse::moveBy(dx, dy);
1016   if (myLine) myLine->moveBy(dx, dy);
1017 }
1018
1019 void SUPERVGUI_CanvasHookPrs::setZ(double z)
1020 {
1021   QCanvasEllipse::setZ(z);
1022   if (myLine) myLine->setZ(z);
1023 }
1024
1025 int SUPERVGUI_CanvasHookPrs::rtti() const
1026 {
1027   return SUPERVGUI_Canvas::Rtti_Hook;
1028 }