1 // SUPERV SUPERVGUI : GUI for Supervisor component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SUPERVGUI_CanvasControlNodePrs.cxx
23 // Author : Natalia KOPNOVA
26 #include "SUPERVGUI_CanvasControlNodePrs.h"
27 #include "SUPERVGUI_CanvasControlNode.h"
28 #include "SUPERVGUI_Canvas.h"
30 #define SHIFT LABEL_HEIGHT/2
32 //=====================================================================
33 // Control node presentation
34 //=====================================================================
35 SUPERVGUI_CanvasControlNodePrs::SUPERVGUI_CanvasControlNodePrs( SUIT_ResourceMgr* mgr, QCanvas* theCanvas, SUPERVGUI_CanvasNode* theNode):
36 SUPERVGUI_CanvasNodePrs( mgr, theCanvas, theNode)
38 Trace("SUPERVGUI_CanvasControlNodePrs::SUPERVGUI_CanvasControlNodePrs");
39 setLabelVisible(false);
40 setNodeColor(Qt::cyan.light());
43 void SUPERVGUI_CanvasControlNodePrs::hideAll()
45 bool aDisp = isVisible();
48 setPortVisible(false);
56 void SUPERVGUI_CanvasControlNodePrs::showAll()
58 bool aDisp = isVisible();
69 QRect SUPERVGUI_CanvasControlNodePrs::getStatusRect() const
71 return QRect((int)x(), ((int)y())+getTitleHeight()+getLabelHeight()+
72 getBodyHeight()+getGateHeight(),
73 width(), getStatusHeight());
76 QRect SUPERVGUI_CanvasControlNodePrs::getBodyRect() const
78 return QRect((int)x(), ((int)y())+getTitleHeight()+getLabelHeight(),
79 width(), getBodyHeight());
82 QRect SUPERVGUI_CanvasControlNodePrs::getGateRect() const
84 return QRect((int)x(), ((int)y())+getTitleHeight()+getLabelHeight()+getBodyHeight(),
85 width(), getGateHeight());
88 //=====================================================================
89 // Start control node presentation
90 //=====================================================================
91 SUPERVGUI_CanvasStartNodePrs::SUPERVGUI_CanvasStartNodePrs( SUIT_ResourceMgr* mgr, QCanvas* theCanvas, SUPERVGUI_CanvasStartNode* theNode):
92 SUPERVGUI_CanvasControlNodePrs( mgr, theCanvas, theNode)
94 Trace("SUPERVGUI_CanvasStartNodePrs::SUPERVGUI_CanvasStartNodePrs");
97 QPointArray SUPERVGUI_CanvasStartNodePrs::areaPoints() const
100 int h = height()+2; // add width of pen
102 int h1 = getTitleHeight()+1;
103 int h2 = getStatusHeight()+1;
105 QPointArray aPnts(8);
106 QPoint p((int)x(), (int)y()-1);
107 aPnts[0] = p + QPoint(0, h1);
108 aPnts[1] = p + QPoint(SHIFT, 0);
109 aPnts[2] = aPnts[1] + QPoint(w, 0);
110 aPnts[3] = aPnts[0] + QPoint(w, 0);
111 aPnts[4] = aPnts[3] + QPoint(0, h-h1-h2);
112 aPnts[5] = aPnts[2] + QPoint(0, h);
113 aPnts[6] = aPnts[1] + QPoint(0, h);
114 aPnts[7] = aPnts[0] + QPoint(0, h-h1-h2);
118 void SUPERVGUI_CanvasStartNodePrs::drawFrame(QPainter& thePainter)
122 int h1 = getTitleHeight();
123 int h2 = getStatusHeight();
125 QRect r0(r.x(), r.y()+h1, r.width(), r.height()-h1-h2);
127 QBrush saved = thePainter.brush();
128 thePainter.setBrush(NoBrush);
129 thePainter.drawRect(r0);
130 thePainter.setBrush(saved);
133 void SUPERVGUI_CanvasStartNodePrs::drawTitleShape(QPainter& thePainter)
135 QRect r = getTitleRect();
138 QPointArray aPnts(4);
139 aPnts[0] = r.topLeft() + QPoint(0, r.height());
140 aPnts[1] = r.topLeft() + QPoint(SHIFT, 0);
141 aPnts[2] = aPnts[1] + QPoint(w, 0);
142 aPnts[3] = aPnts[0] + QPoint(w, 0);
144 thePainter.setBrush(Qt::red.light());
145 thePainter.drawPolygon(aPnts);
148 void SUPERVGUI_CanvasStartNodePrs::drawStatusShape(QPainter& thePainter)
150 QRect r = getStatusRect();
153 QPointArray aPnts(4);
154 aPnts[0] = r.topLeft() + QPoint(SHIFT, r.height());
155 aPnts[1] = r.topLeft();
156 aPnts[2] = aPnts[1] + QPoint(w, 0);
157 aPnts[3] = aPnts[0] + QPoint(w, 0);
159 thePainter.drawPolygon(aPnts);
163 void SUPERVGUI_CanvasStartNodePrs::setState(SUPERV::GraphState theState)
165 QRect r = getStatusRect();
166 canvas()->setChanged(QRect(r.x(), r.y(), r.width()+SHIFT, r.height()));
167 SUPERVGUI_CanvasNodePrs::setState(theState);
171 //=====================================================================
172 // End control node presentation
173 //=====================================================================
174 SUPERVGUI_CanvasEndNodePrs::SUPERVGUI_CanvasEndNodePrs( SUIT_ResourceMgr* mgr, QCanvas* theCanvas, SUPERVGUI_CanvasEndNode* theNode):
175 SUPERVGUI_CanvasControlNodePrs(mgr,theCanvas, theNode)
177 Trace("SUPERVGUI_CanvasEndNodePrs::SUPERVGUI_CanvasEndNodePrs");
180 QPointArray SUPERVGUI_CanvasEndNodePrs::areaPoints() const
185 int h1 = getTitleHeight()+1;
186 int h2 = getStatusHeight()+1;
188 QPointArray aPnts(8);
189 QPoint p((int)x(), (int)y()-1);
190 aPnts[0] = p + QPoint(0, h1);
191 aPnts[1] = p + QPoint(-SHIFT, 0);
192 aPnts[2] = aPnts[1] + QPoint(w, 0);
193 aPnts[3] = aPnts[0] + QPoint(w, 0);
194 aPnts[4] = aPnts[3] + QPoint(0, h-h1-h2);
195 aPnts[5] = aPnts[2] + QPoint(0, h);
196 aPnts[6] = aPnts[1] + QPoint(0, h);
197 aPnts[7] = aPnts[0] + QPoint(0, h-h1-h2);
201 void SUPERVGUI_CanvasEndNodePrs::drawFrame(QPainter& thePainter)
205 int h1 = getTitleHeight();
206 int h2 = getStatusHeight();
208 QRect r0(r.x(), r.y()+h1, r.width(), r.height()-h1-h2);
210 QBrush saved = thePainter.brush();
211 thePainter.setBrush(NoBrush);
212 thePainter.drawRect(r0);
213 thePainter.setBrush(saved);
216 void SUPERVGUI_CanvasEndNodePrs::drawTitleShape(QPainter& thePainter)
218 QRect r = getTitleRect();
221 QPointArray aPnts(4);
222 aPnts[0] = r.topLeft() + QPoint(0, r.height());
223 aPnts[1] = r.topLeft() + QPoint(-SHIFT, 0);
224 aPnts[2] = aPnts[1] + QPoint(w, 0);
225 aPnts[3] = aPnts[0] + QPoint(w, 0);
227 thePainter.setBrush(Qt::red.light());
228 thePainter.drawPolygon(aPnts);
231 void SUPERVGUI_CanvasEndNodePrs::drawStatusShape(QPainter& thePainter)
233 QRect r = getStatusRect();
236 QPointArray aPnts(4);
237 aPnts[0] = r.topLeft() + QPoint(-SHIFT, r.height());
238 aPnts[1] = r.topLeft();
239 aPnts[2] = aPnts[1] + QPoint(w, 0);
240 aPnts[3] = aPnts[0] + QPoint(w, 0);
242 thePainter.drawPolygon(aPnts);
245 void SUPERVGUI_CanvasEndNodePrs::setState(SUPERV::GraphState theState)
247 QRect r = getStatusRect();
248 canvas()->setChanged(QRect(r.x()-SHIFT, r.y(), r.width()+SHIFT, r.height()));
249 SUPERVGUI_CanvasNodePrs::setState(theState);
252 //=====================================================================
253 // Goto control node presentation
254 //=====================================================================
255 SUPERVGUI_CanvasGotoNodePrs::SUPERVGUI_CanvasGotoNodePrs( SUIT_ResourceMgr* mgr, QCanvas* theCanvas, SUPERVGUI_CanvasGotoNode* theNode):
256 SUPERVGUI_CanvasControlNodePrs(mgr, theCanvas, theNode)
258 Trace("SUPERVGUI_CanvasGotoNodePrs::SUPERVGUI_CanvasGotoNodePrs");
261 QPointArray SUPERVGUI_CanvasGotoNodePrs::areaPoints() const
266 int h1 = getTitleHeight()+1;
267 int h2 = getStatusHeight()+1;
269 QPointArray aPnts(8);
270 QPoint p((int)x(), (int)y()-1);
271 aPnts[0] = p + QPoint(0, h1);
272 aPnts[1] = p + QPoint(SHIFT, 0);
273 aPnts[2] = aPnts[1] + QPoint(w-2*SHIFT, 0);
274 aPnts[3] = aPnts[0] + QPoint(w, 0);
275 aPnts[4] = aPnts[3] + QPoint(0, h-h1-h2);
276 aPnts[5] = aPnts[2] + QPoint(0, h);
277 aPnts[6] = aPnts[1] + QPoint(0, h);
278 aPnts[7] = aPnts[0] + QPoint(0, h-h1-h2);
282 void SUPERVGUI_CanvasGotoNodePrs::drawFrame(QPainter& thePainter)
286 int h1 = getTitleHeight();
287 int h2 = getStatusHeight();
289 QRect r0(r.x(), r.y()+h1, r.width(), r.height()-h1-h2);
291 QBrush saved = thePainter.brush();
292 thePainter.setBrush(NoBrush);
293 thePainter.drawRect(r0);
294 thePainter.setBrush(saved);
297 void SUPERVGUI_CanvasGotoNodePrs::drawTitleShape(QPainter& thePainter)
299 QRect r = getTitleRect();
302 QPointArray aPnts(4);
303 aPnts[0] = r.topLeft() + QPoint(0, r.height());
304 aPnts[1] = r.topLeft() + QPoint(SHIFT, 0);
305 aPnts[2] = aPnts[1] + QPoint(w-2*SHIFT, 0);
306 aPnts[3] = aPnts[0] + QPoint(w, 0);
308 thePainter.setBrush(Qt::green.light());
309 thePainter.drawPolygon(aPnts);
312 void SUPERVGUI_CanvasGotoNodePrs::drawStatusShape(QPainter& thePainter)
314 QRect r = getStatusRect();
317 QPointArray aPnts(4);
318 aPnts[0] = r.topLeft() + QPoint(SHIFT, r.height());
319 aPnts[1] = r.topLeft();
320 aPnts[2] = aPnts[1] + QPoint(w, 0);
321 aPnts[3] = aPnts[0] + QPoint(w-2*SHIFT, 0);
323 thePainter.drawPolygon(aPnts);
327 //=====================================================================
328 // Macro node presentation
329 //=====================================================================
330 SUPERVGUI_CanvasMacroNodePrs::SUPERVGUI_CanvasMacroNodePrs( SUIT_ResourceMgr* mgr, QCanvas* theCanvas, SUPERVGUI_CanvasMacroNode* theNode):
331 SUPERVGUI_CanvasNodePrs( mgr, theCanvas, theNode)
333 Trace("SUPERVGUI_CanvasControlNodePrs::SUPERVGUI_CanvasControlNodePrs");
334 setNodeColor(QColor(255, 186, 149)); //QColor(255, 200, 170));
337 void SUPERVGUI_CanvasMacroNodePrs::drawFrame(QPainter& thePainter)
339 SUPERVGUI_CanvasNodePrs::drawFrame(thePainter);
341 QPen saved = thePainter.pen();
342 thePainter.setPen(QPen(saved.color(), 2));
345 thePainter.drawLine(r.left(), r.top(), r.left(), r.bottom());
346 thePainter.drawLine(r.left()+3, r.top(), r.left()+3, r.bottom());
347 thePainter.drawLine(r.right()-3, r.top(), r.right()-3, r.bottom());
348 thePainter.drawLine(r.right(), r.top(), r.right(), r.bottom());
349 thePainter.setPen(saved);
352 QPointArray SUPERVGUI_CanvasMacroNodePrs::areaPoints() const
354 int w = width()+2; // add width of pen
357 QPointArray aPnts(4);
358 aPnts[0] = QPoint((int)x()-1, (int)y());
359 aPnts[1] = aPnts[0] + QPoint(w, 0);
360 aPnts[2] = aPnts[1] + QPoint(0, h);
361 aPnts[3] = aPnts[0] + QPoint(0, h);