]> SALOME platform Git repositories - modules/superv.git/blob - src/SUPERVGUI/SUPERVGUI_CanvasCellNodePrs.cxx
Salome HOME
Update copyright information
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_CanvasCellNodePrs.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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 //  SUPERV SUPERVGUI : GUI for Supervisor component
23 //  File   : SUPERVGUI_CanvasCellNodePrs.cxx
24 //  Author : 
25 //  Module : SUPERV
26 //
27 #include "SUPERVGUI_CanvasCellNodePrs.h"
28 #include "SUPERVGUI_Canvas.h"
29
30 #include "SUIT_ResourceMgr.h"
31
32 #define TEXT_MARGIN 5
33
34 // ----------------------------------------------------------
35 // Cell widget of the table on QCanvas
36 // ----------------------------------------------------------
37 SUPERVGUI_CanvasCellNodePrs::SUPERVGUI_CanvasCellNodePrs( SUIT_ResourceMgr* mgr, QCanvas* theCanvas, SUPERVGUI_CanvasCellNode* theNode):
38   myTitleWidth(CELL_WIDTH_PART),
39   myLabelWidth(CELL_WIDTH_PART),
40   myStatusWidth(CELL_WIDTH_PART), 
41   SUPERVGUI_CanvasNodePrs( mgr, theCanvas, theNode, true)
42 {
43   myPortVisible = false;
44 }
45
46 SUPERVGUI_CanvasCellNodePrs::~SUPERVGUI_CanvasCellNodePrs()
47 {
48 }
49
50 void SUPERVGUI_CanvasCellNodePrs::moveBy(double dx, double dy) {
51 //Trace("SUPERVGUI_CanvasCellNodePrs::moveBy");
52   int aX = (int) (x()+dx);
53   int aY = (int) (y()+dy);
54
55   int w = aX + width() + GRAPH_MARGIN;
56   int h = aY + height() + GRAPH_MARGIN;
57   if (canvas()->width() > w) w = canvas()->width();
58   if (canvas()->height() > h) h = canvas()->height();
59   if (canvas()->width() < w || canvas()->height() < h)
60     canvas()->resize(w, h);
61   QCanvasPolygonalItem::moveBy(dx, dy);
62 }
63
64 void SUPERVGUI_CanvasCellNodePrs::drawShape(QPainter& thePainter) {
65   drawTitle(thePainter);
66   drawLabel(thePainter);
67   drawStatus(thePainter);
68   drawFrame(thePainter);
69 }
70
71 void drawCellText(QPainter& thePainter, const QString& theText, 
72                   const QRect& theRect, int theHAlign = Qt::AlignAuto)
73 {
74   int flags = theHAlign | Qt::AlignVCenter;
75   QRect r(theRect.x() + TEXT_MARGIN, theRect.y(), 
76           theRect.width() - 2*TEXT_MARGIN, theRect.height());
77
78   QWMatrix aMat = thePainter.worldMatrix();
79   if (aMat.m11() != 1.0) { 
80     // for scaled picture only
81     QRect r1 = aMat.mapRect(r);
82     QFont saved = thePainter.font();
83     QFont f(saved);
84     if (f.pointSize() == -1) {
85       f.setPixelSize((int)(f.pixelSize()*aMat.m11()));
86     }
87     else {
88       f.setPointSize((int)(f.pointSize()*aMat.m11()));
89     }
90     thePainter.save();
91     QWMatrix m;
92     thePainter.setWorldMatrix(m);
93     thePainter.setFont(f);
94     thePainter.drawText(r1, flags, theText);
95     thePainter.setFont(saved);
96     thePainter.restore();
97   }
98   else {
99     thePainter.drawText(r, flags, theText);
100   }
101 }
102
103 void SUPERVGUI_CanvasCellNodePrs::drawTitle(QPainter& thePainter) {
104   QBrush saved = thePainter.brush();
105   if (getNode()->getEngine()->IsLoop() || getNode()->getEngine()->IsEndLoop()
106       ||
107       getNode()->getEngine()->IsSwitch() || getNode()->getEngine()->IsEndSwitch())
108     thePainter.setBrush(Qt::red.light());
109   else if (getNode()->getEngine()->IsGOTO())
110     thePainter.setBrush(Qt::green.light());
111   else {
112     QBrush br( resMgr()->colorValue( "SUPERVGraph", "Title", DEF_MAIN_TITLE ) );
113     thePainter.setBrush(br);
114   }
115   drawTitleShape(thePainter);
116   thePainter.setBrush(saved);
117
118   drawCellText(thePainter, getNode()->getEngine()->Name(), getTitleRect(), Qt::AlignLeft);
119 }
120
121 void SUPERVGUI_CanvasCellNodePrs::drawLabel(QPainter& thePainter) 
122 {
123   QRect r = getLabelRect();
124
125   QPen saved = thePainter.pen();
126   thePainter.setPen(NoPen);
127   thePainter.drawRect(r);
128   thePainter.setPen(saved);
129
130   drawCellText(thePainter, getNode()->getLabelText(), r, Qt::AlignLeft);
131 }
132
133 void SUPERVGUI_CanvasCellNodePrs::drawStatus(QPainter& thePainter) 
134 {
135   QRect r = getStatusRect();
136
137   QBrush savedB = thePainter.brush();
138   thePainter.setBrush(getStatusColor());
139   drawStatusShape(thePainter);
140   thePainter.setBrush(savedB);
141
142   drawCellText(thePainter, getStatus(), r, Qt::AlignHCenter);
143 }
144
145 QRect SUPERVGUI_CanvasCellNodePrs::getTitleRect() const
146 {
147   return QRect((int)x(), (int)y(), getTitleWidth(), getTitleHeight());
148 }
149
150 QRect SUPERVGUI_CanvasCellNodePrs::getLabelRect() const
151 {
152   return QRect(((int)x())+getTitleWidth(), (int)y(), getLabelWidth(), getLabelHeight());
153 }
154
155 QRect SUPERVGUI_CanvasCellNodePrs::getStatusRect() const
156 {
157   return QRect(((int)x())+getTitleWidth()+getLabelWidth(), (int)y(),
158                getStatusWidth(), getStatusHeight());
159 }
160
161 int SUPERVGUI_CanvasCellNodePrs::getTitleWidth() const {
162   return myTitleWidth;
163 }
164
165 int SUPERVGUI_CanvasCellNodePrs::getLabelWidth() const {
166   return myLabelWidth;
167 }
168
169 int SUPERVGUI_CanvasCellNodePrs::getStatusWidth() const {
170   return myStatusWidth;
171 }
172
173 int SUPERVGUI_CanvasCellNodePrs::width() const
174 {
175   return myTitleWidth + myLabelWidth + myStatusWidth;
176 }
177
178 int SUPERVGUI_CanvasCellNodePrs::height() const
179 {
180   return getTitleHeight();
181 }
182
183 void SUPERVGUI_CanvasCellNodePrs::setState(SUPERV::GraphState theState)
184 {
185   switch(theState) {
186   case SUPERV_Waiting:
187     setStatus("Waiting");
188     setStatusColor(QColor(35, 192, 255));
189     break;
190
191   case SUPERV_Running:
192   case SUPERV::ReadyState:
193     setStatus("Running");
194     setStatusColor(QColor(32,210,32));
195     break;
196
197   case SUPERV_Suspend:
198   case SUPERV::SuspendReadyState:
199     setStatus("Suspended");
200     setStatusColor(QColor(255,180, 0));
201     break;
202
203   case SUPERV_Done:
204     setStatus("Finished");
205     setStatusColor(QColor(255, 158, 255));
206     break;
207
208   case SUPERV_Error: 
209     setStatus("Aborted");
210     setStatusColor(Qt::red);
211     break;
212
213   case SUPERV_Kill:
214     setStatus("Killed");
215     setStatusColor(Qt::red);
216     break;
217
218   case SUPERV::LoadingState:
219     setStatus("Loading");
220     setStatusColor(QColor(56,255,56));
221     break;
222
223   default:
224     setStatus("No Status");
225     setStatusColor( resMgr()->colorValue( "SUPERVGraph", "NodeBody", DEF_MAIN_BACK ) ); // mkr : IPAL10829
226     break;
227   }
228
229   canvas()->setChanged(getStatusRect());
230   canvas()->update();
231 }