]> SALOME platform Git repositories - modules/superv.git/blob - src/SUPERVGUI/SUPERVGUI_CanvasCellNodePrs.cxx
Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_CanvasCellNodePrs.cxx
1 //  SUPERV SUPERVGUI : GUI for Supervisor component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  File   : SUPERVGUI_CanvasCellNodePrs.cxx
23 //  Author : 
24 //  Module : SUPERV
25
26 #include "SUPERVGUI_CanvasCellNodePrs.h"
27 #include "SUPERVGUI_Canvas.h"
28
29 #include "SUIT_ResourceMgr.h"
30
31 #define TEXT_MARGIN 5
32
33 // ----------------------------------------------------------
34 // Cell widget of the table on QCanvas
35 // ----------------------------------------------------------
36 SUPERVGUI_CanvasCellNodePrs::SUPERVGUI_CanvasCellNodePrs( SUIT_ResourceMgr* mgr, QCanvas* theCanvas, SUPERVGUI_CanvasCellNode* theNode):
37   myTitleWidth(CELL_WIDTH_PART),
38   myLabelWidth(CELL_WIDTH_PART),
39   myStatusWidth(CELL_WIDTH_PART), 
40   SUPERVGUI_CanvasNodePrs( mgr, theCanvas, theNode, true)
41 {
42   myPortVisible = false;
43 }
44
45 SUPERVGUI_CanvasCellNodePrs::~SUPERVGUI_CanvasCellNodePrs()
46 {
47 }
48
49 void SUPERVGUI_CanvasCellNodePrs::moveBy(double dx, double dy) {
50 //Trace("SUPERVGUI_CanvasCellNodePrs::moveBy");
51   int aX = (int) (x()+dx);
52   int aY = (int) (y()+dy);
53
54   int w = aX + width() + GRAPH_MARGIN;
55   int h = aY + height() + GRAPH_MARGIN;
56   if (canvas()->width() > w) w = canvas()->width();
57   if (canvas()->height() > h) h = canvas()->height();
58   if (canvas()->width() < w || canvas()->height() < h)
59     canvas()->resize(w, h);
60   QCanvasPolygonalItem::moveBy(dx, dy);
61 }
62
63 void SUPERVGUI_CanvasCellNodePrs::drawShape(QPainter& thePainter) {
64   drawTitle(thePainter);
65   drawLabel(thePainter);
66   drawStatus(thePainter);
67   drawFrame(thePainter);
68 }
69
70 void drawCellText(QPainter& thePainter, const QString& theText, 
71                   const QRect& theRect, int theHAlign = Qt::AlignAuto)
72 {
73   int flags = theHAlign | Qt::AlignVCenter;
74   QRect r(theRect.x() + TEXT_MARGIN, theRect.y(), 
75           theRect.width() - 2*TEXT_MARGIN, theRect.height());
76
77   QWMatrix aMat = thePainter.worldMatrix();
78   if (aMat.m11() != 1.0) { 
79     // for scaled picture only
80     QRect r1 = aMat.mapRect(r);
81     QFont saved = thePainter.font();
82     QFont f(saved);
83     if (f.pointSize() == -1) {
84       f.setPixelSize((int)(f.pixelSize()*aMat.m11()));
85     }
86     else {
87       f.setPointSize((int)(f.pointSize()*aMat.m11()));
88     }
89     thePainter.save();
90     QWMatrix m;
91     thePainter.setWorldMatrix(m);
92     thePainter.setFont(f);
93     thePainter.drawText(r1, flags, theText);
94     thePainter.setFont(saved);
95     thePainter.restore();
96   }
97   else {
98     thePainter.drawText(r, flags, theText);
99   }
100 }
101
102 void SUPERVGUI_CanvasCellNodePrs::drawTitle(QPainter& thePainter) {
103   QBrush saved = thePainter.brush();
104   if (getNode()->getEngine()->IsLoop() || getNode()->getEngine()->IsEndLoop()
105       ||
106       getNode()->getEngine()->IsSwitch() || getNode()->getEngine()->IsEndSwitch())
107     thePainter.setBrush(Qt::red.light());
108   else if (getNode()->getEngine()->IsGOTO())
109     thePainter.setBrush(Qt::green.light());
110   else {
111     QBrush br( resMgr()->colorValue( "SUPERVGraph", "Title", DEF_MAIN_TITLE ) );
112     thePainter.setBrush(br);
113   }
114   drawTitleShape(thePainter);
115   thePainter.setBrush(saved);
116
117   drawCellText(thePainter, getNode()->getEngine()->Name(), getTitleRect(), Qt::AlignLeft);
118 }
119
120 void SUPERVGUI_CanvasCellNodePrs::drawLabel(QPainter& thePainter) 
121 {
122   QRect r = getLabelRect();
123
124   QPen saved = thePainter.pen();
125   thePainter.setPen(NoPen);
126   thePainter.drawRect(r);
127   thePainter.setPen(saved);
128
129   drawCellText(thePainter, getNode()->getLabelText(), r, Qt::AlignLeft);
130 }
131
132 void SUPERVGUI_CanvasCellNodePrs::drawStatus(QPainter& thePainter) 
133 {
134   QRect r = getStatusRect();
135
136   QBrush savedB = thePainter.brush();
137   thePainter.setBrush(getStatusColor());
138   drawStatusShape(thePainter);
139   thePainter.setBrush(savedB);
140
141   drawCellText(thePainter, getStatus(), r, Qt::AlignHCenter);
142 }
143
144 QRect SUPERVGUI_CanvasCellNodePrs::getTitleRect() const
145 {
146   return QRect((int)x(), (int)y(), getTitleWidth(), getTitleHeight());
147 }
148
149 QRect SUPERVGUI_CanvasCellNodePrs::getLabelRect() const
150 {
151   return QRect(((int)x())+getTitleWidth(), (int)y(), getLabelWidth(), getLabelHeight());
152 }
153
154 QRect SUPERVGUI_CanvasCellNodePrs::getStatusRect() const
155 {
156   return QRect(((int)x())+getTitleWidth()+getLabelWidth(), (int)y(),
157                getStatusWidth(), getStatusHeight());
158 }
159
160 int SUPERVGUI_CanvasCellNodePrs::getTitleWidth() const {
161   return myTitleWidth;
162 }
163
164 int SUPERVGUI_CanvasCellNodePrs::getLabelWidth() const {
165   return myLabelWidth;
166 }
167
168 int SUPERVGUI_CanvasCellNodePrs::getStatusWidth() const {
169   return myStatusWidth;
170 }
171
172 int SUPERVGUI_CanvasCellNodePrs::width() const
173 {
174   return myTitleWidth + myLabelWidth + myStatusWidth;
175 }
176
177 int SUPERVGUI_CanvasCellNodePrs::height() const
178 {
179   return getTitleHeight();
180 }
181
182 void SUPERVGUI_CanvasCellNodePrs::setState(SUPERV::GraphState theState)
183 {
184   switch(theState) {
185   case SUPERV_Waiting:
186     setStatus("Waiting");
187     setStatusColor(QColor(35, 192, 255));
188     break;
189
190   case SUPERV_Running:
191   case SUPERV::ReadyState:
192     setStatus("Running");
193     setStatusColor(QColor(32,210,32));
194     break;
195
196   case SUPERV_Suspend:
197   case SUPERV::SuspendReadyState:
198     setStatus("Suspended");
199     setStatusColor(QColor(255,180, 0));
200     break;
201
202   case SUPERV_Done:
203     setStatus("Finished");
204     setStatusColor(QColor(255, 158, 255));
205     break;
206
207   case SUPERV_Error: 
208     setStatus("Aborted");
209     setStatusColor(Qt::red);
210     break;
211
212   case SUPERV_Kill:
213     setStatus("Killed");
214     setStatusColor(Qt::red);
215     break;
216
217   case SUPERV::LoadingState:
218     setStatus("Loading");
219     setStatusColor(QColor(56,255,56));
220     break;
221
222   default:
223     setStatus("No Status");
224     setStatusColor( resMgr()->colorValue( "SUPERVGraph", "NodeBody", DEF_MAIN_BACK ) ); // mkr : IPAL10829
225     break;
226   }
227
228   canvas()->setChanged(getStatusRect());
229   canvas()->update();
230 }