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