]> SALOME platform Git repositories - modules/superv.git/blob - src/SUPERVGUI/SUPERVGUI_CanvasControlNodePrs.cxx
Salome HOME
Fix problem with table of contents resizing
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_CanvasControlNodePrs.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_CanvasControlNodePrs.cxx
23 //  Author : Natalia KOPNOVA
24 //  Module : SUPERV
25
26 #include "SUPERVGUI_CanvasControlNodePrs.h"
27 #include "SUPERVGUI_CanvasControlNode.h"
28 #include "SUPERVGUI_Canvas.h"
29
30 #define SHIFT LABEL_HEIGHT/2
31
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)
37 {
38   Trace("SUPERVGUI_CanvasControlNodePrs::SUPERVGUI_CanvasControlNodePrs");
39   setLabelVisible(false);
40   setNodeColor(Qt::cyan.light());
41 }
42
43 void SUPERVGUI_CanvasControlNodePrs::hideAll()
44 {
45   bool aDisp = isVisible();
46   if (aDisp) hide();
47
48   setPortVisible(false);
49
50   if (aDisp) {
51     show();
52     canvas()->update();
53   }
54 }
55
56 void SUPERVGUI_CanvasControlNodePrs::showAll()
57 {
58   bool aDisp = isVisible();
59   if (aDisp) hide();
60
61   setPortVisible(true);
62
63   if (aDisp) {
64     show();
65     canvas()->update();
66   }
67 }
68
69 QRect SUPERVGUI_CanvasControlNodePrs::getStatusRect() const
70 {
71   return QRect((int)x(), ((int)y())+getTitleHeight()+getLabelHeight()+
72                getBodyHeight()+getGateHeight(),
73                width(), getStatusHeight());
74 }
75
76 QRect SUPERVGUI_CanvasControlNodePrs::getBodyRect() const
77 {
78   return QRect((int)x(), ((int)y())+getTitleHeight()+getLabelHeight(), 
79                width(), getBodyHeight());
80 }
81
82 QRect SUPERVGUI_CanvasControlNodePrs::getGateRect() const
83 {
84   return QRect((int)x(), ((int)y())+getTitleHeight()+getLabelHeight()+getBodyHeight(), 
85                width(), getGateHeight());
86 }
87
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)
93 {
94   Trace("SUPERVGUI_CanvasStartNodePrs::SUPERVGUI_CanvasStartNodePrs");
95 }
96
97 QPointArray SUPERVGUI_CanvasStartNodePrs::areaPoints() const
98 {
99   int w = width();
100   int h = height()+2; // add width of pen 
101
102   int h1 = getTitleHeight()+1;
103   int h2 = getStatusHeight()+1;
104
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);
115   return aPnts;
116 }
117
118 void SUPERVGUI_CanvasStartNodePrs::drawFrame(QPainter& thePainter) 
119 {
120   QRect r = getRect();
121
122   int h1 = getTitleHeight();
123   int h2 = getStatusHeight();
124
125   QRect r0(r.x(), r.y()+h1, r.width(), r.height()-h1-h2);
126
127   QBrush saved = thePainter.brush();
128   thePainter.setBrush(NoBrush);
129   thePainter.drawRect(r0);
130   thePainter.setBrush(saved);
131 }
132
133 void SUPERVGUI_CanvasStartNodePrs::drawTitleShape(QPainter& thePainter) 
134 {
135   QRect r = getTitleRect();
136   int w = width()-1;
137
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);
143
144   thePainter.setBrush(Qt::red.light());
145   thePainter.drawPolygon(aPnts);
146 }
147
148 void SUPERVGUI_CanvasStartNodePrs::drawStatusShape(QPainter& thePainter) 
149 {
150   QRect r = getStatusRect();
151   int w = width()-1;
152
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);
158
159   thePainter.drawPolygon(aPnts);
160 }
161
162
163 void SUPERVGUI_CanvasStartNodePrs::setState(SUPERV::GraphState theState) 
164 {
165   QRect r = getStatusRect();
166   canvas()->setChanged(QRect(r.x(), r.y(), r.width()+SHIFT, r.height()));
167   SUPERVGUI_CanvasNodePrs::setState(theState);
168 }
169
170
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)
176 {
177   Trace("SUPERVGUI_CanvasEndNodePrs::SUPERVGUI_CanvasEndNodePrs");
178 }
179
180 QPointArray SUPERVGUI_CanvasEndNodePrs::areaPoints() const
181 {
182   int w = width();
183   int h = height()+2;
184
185   int h1 = getTitleHeight()+1;
186   int h2 = getStatusHeight()+1;
187
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);
198   return aPnts;
199 }
200
201 void SUPERVGUI_CanvasEndNodePrs::drawFrame(QPainter& thePainter) 
202 {
203   QRect r = getRect();
204
205   int h1 = getTitleHeight();
206   int h2 = getStatusHeight();
207
208   QRect r0(r.x(), r.y()+h1, r.width(), r.height()-h1-h2);
209
210   QBrush saved = thePainter.brush();
211   thePainter.setBrush(NoBrush);
212   thePainter.drawRect(r0);
213   thePainter.setBrush(saved);
214 }
215
216 void SUPERVGUI_CanvasEndNodePrs::drawTitleShape(QPainter& thePainter) 
217 {
218   QRect r = getTitleRect();
219   int w = width()-1;
220
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);
226
227   thePainter.setBrush(Qt::red.light());
228   thePainter.drawPolygon(aPnts);
229 }
230
231 void SUPERVGUI_CanvasEndNodePrs::drawStatusShape(QPainter& thePainter) 
232 {
233   QRect r = getStatusRect();
234   int w = width()-1;
235
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);
241
242   thePainter.drawPolygon(aPnts);
243 }
244
245 void SUPERVGUI_CanvasEndNodePrs::setState(SUPERV::GraphState theState)
246 {
247   QRect r = getStatusRect();
248   canvas()->setChanged(QRect(r.x()-SHIFT, r.y(), r.width()+SHIFT, r.height()));
249   SUPERVGUI_CanvasNodePrs::setState(theState);
250 }
251
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)
257 {
258   Trace("SUPERVGUI_CanvasGotoNodePrs::SUPERVGUI_CanvasGotoNodePrs");
259 }
260
261 QPointArray SUPERVGUI_CanvasGotoNodePrs::areaPoints() const
262 {
263   int w = width();
264   int h = height()+2;
265
266   int h1 = getTitleHeight()+1;
267   int h2 = getStatusHeight()+1;
268
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);
279   return aPnts;
280 }
281
282 void SUPERVGUI_CanvasGotoNodePrs::drawFrame(QPainter& thePainter) 
283 {
284   QRect r = getRect();
285
286   int h1 = getTitleHeight();
287   int h2 = getStatusHeight();
288
289   QRect r0(r.x(), r.y()+h1, r.width(), r.height()-h1-h2);
290
291   QBrush saved = thePainter.brush();
292   thePainter.setBrush(NoBrush);
293   thePainter.drawRect(r0);
294   thePainter.setBrush(saved);
295 }
296
297 void SUPERVGUI_CanvasGotoNodePrs::drawTitleShape(QPainter& thePainter) 
298 {
299   QRect r = getTitleRect();
300   int w = width()-1;
301
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);
307
308   thePainter.setBrush(Qt::green.light());
309   thePainter.drawPolygon(aPnts);
310 }
311
312 void SUPERVGUI_CanvasGotoNodePrs::drawStatusShape(QPainter& thePainter) 
313 {
314   QRect r = getStatusRect();
315   int w = width()-1;
316
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);
322
323   thePainter.drawPolygon(aPnts);
324 }
325
326
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)
332 {
333   Trace("SUPERVGUI_CanvasControlNodePrs::SUPERVGUI_CanvasControlNodePrs");
334   setNodeColor(QColor(255, 186, 149)); //QColor(255, 200, 170));
335 }
336
337 void SUPERVGUI_CanvasMacroNodePrs::drawFrame(QPainter& thePainter) 
338 {
339   SUPERVGUI_CanvasNodePrs::drawFrame(thePainter);
340
341   QPen saved = thePainter.pen();
342   thePainter.setPen(QPen(saved.color(), 2));
343
344   QRect r = getRect();
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);
350 }
351
352 QPointArray SUPERVGUI_CanvasMacroNodePrs::areaPoints() const
353 {
354   int w = width()+2; // add width of pen
355   int h = height()+1;
356
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);
362   return aPnts;
363 }