]> SALOME platform Git repositories - modules/superv.git/blob - src/SUPERVGUI/SUPERVGUI_CanvasControlNodePrs.cxx
Salome HOME
Merge from OCC_development_generic_2006
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_CanvasControlNodePrs.cxx
1 //  SUPERV SUPERVGUI : GUI for Supervisor component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE
4 //
5 //  File   : SUPERVGUI_CanvasControlNodePrs.cxx
6 //  Author : Natalia KOPNOVA
7 //  Module : SUPERV
8
9 #include "SUPERVGUI_CanvasControlNodePrs.h"
10 #include "SUPERVGUI_CanvasControlNode.h"
11 #include "SUPERVGUI_Canvas.h"
12
13 #define SHIFT LABEL_HEIGHT/2
14
15 //=====================================================================
16 // Control node presentation
17 //=====================================================================
18 SUPERVGUI_CanvasControlNodePrs::SUPERVGUI_CanvasControlNodePrs( SUIT_ResourceMgr* mgr, QCanvas* theCanvas, SUPERVGUI_CanvasNode* theNode):
19   SUPERVGUI_CanvasNodePrs( mgr, theCanvas, theNode)
20 {
21   Trace("SUPERVGUI_CanvasControlNodePrs::SUPERVGUI_CanvasControlNodePrs");
22   setLabelVisible(false);
23   setNodeColor(Qt::cyan.light());
24 }
25
26 void SUPERVGUI_CanvasControlNodePrs::hideAll()
27 {
28   bool aDisp = isVisible();
29   if (aDisp) hide();
30
31   setPortVisible(false);
32
33   if (aDisp) {
34     show();
35     canvas()->update();
36   }
37 }
38
39 void SUPERVGUI_CanvasControlNodePrs::showAll()
40 {
41   bool aDisp = isVisible();
42   if (aDisp) hide();
43
44   setPortVisible(true);
45
46   if (aDisp) {
47     show();
48     canvas()->update();
49   }
50 }
51
52 QRect SUPERVGUI_CanvasControlNodePrs::getStatusRect() const
53 {
54   return QRect((int)x(), ((int)y())+getTitleHeight()+getLabelHeight()+
55                getBodyHeight()+getGateHeight(),
56                width(), getStatusHeight());
57 }
58
59 QRect SUPERVGUI_CanvasControlNodePrs::getBodyRect() const
60 {
61   return QRect((int)x(), ((int)y())+getTitleHeight()+getLabelHeight(), 
62                width(), getBodyHeight());
63 }
64
65 QRect SUPERVGUI_CanvasControlNodePrs::getGateRect() const
66 {
67   return QRect((int)x(), ((int)y())+getTitleHeight()+getLabelHeight()+getBodyHeight(), 
68                width(), getGateHeight());
69 }
70
71 //=====================================================================
72 // Start control node presentation
73 //=====================================================================
74 SUPERVGUI_CanvasStartNodePrs::SUPERVGUI_CanvasStartNodePrs( SUIT_ResourceMgr* mgr, QCanvas* theCanvas, SUPERVGUI_CanvasStartNode* theNode):
75   SUPERVGUI_CanvasControlNodePrs( mgr, theCanvas, theNode)
76 {
77   Trace("SUPERVGUI_CanvasStartNodePrs::SUPERVGUI_CanvasStartNodePrs");
78 }
79
80 QPointArray SUPERVGUI_CanvasStartNodePrs::areaPoints() const
81 {
82   int w = width();
83   int h = height()+2; // add width of pen 
84
85   int h1 = getTitleHeight()+1;
86   int h2 = getStatusHeight()+1;
87
88   QPointArray aPnts(8);
89   QPoint p((int)x(), (int)y()-1);
90   aPnts[0] = p + QPoint(0, h1);
91   aPnts[1] = p + QPoint(SHIFT, 0);
92   aPnts[2] = aPnts[1] + QPoint(w, 0);
93   aPnts[3] = aPnts[0] + QPoint(w, 0);
94   aPnts[4] = aPnts[3] + QPoint(0, h-h1-h2);
95   aPnts[5] = aPnts[2] + QPoint(0, h);
96   aPnts[6] = aPnts[1] + QPoint(0, h);
97   aPnts[7] = aPnts[0] + QPoint(0, h-h1-h2);
98   return aPnts;
99 }
100
101 void SUPERVGUI_CanvasStartNodePrs::drawFrame(QPainter& thePainter) 
102 {
103   QRect r = getRect();
104
105   int h1 = getTitleHeight();
106   int h2 = getStatusHeight();
107
108   QRect r0(r.x(), r.y()+h1, r.width(), r.height()-h1-h2);
109
110   QBrush saved = thePainter.brush();
111   thePainter.setBrush(NoBrush);
112   thePainter.drawRect(r0);
113   thePainter.setBrush(saved);
114 }
115
116 void SUPERVGUI_CanvasStartNodePrs::drawTitleShape(QPainter& thePainter) 
117 {
118   QRect r = getTitleRect();
119   int w = width()-1;
120
121   QPointArray aPnts(4);
122   aPnts[0] = r.topLeft() + QPoint(0, r.height());
123   aPnts[1] = r.topLeft() + QPoint(SHIFT, 0);
124   aPnts[2] = aPnts[1] + QPoint(w, 0);
125   aPnts[3] = aPnts[0] + QPoint(w, 0);
126
127   thePainter.setBrush(Qt::red.light());
128   thePainter.drawPolygon(aPnts);
129 }
130
131 void SUPERVGUI_CanvasStartNodePrs::drawStatusShape(QPainter& thePainter) 
132 {
133   QRect r = getStatusRect();
134   int w = width()-1;
135
136   QPointArray aPnts(4);
137   aPnts[0] = r.topLeft() + QPoint(SHIFT, r.height());
138   aPnts[1] = r.topLeft();
139   aPnts[2] = aPnts[1] + QPoint(w, 0);
140   aPnts[3] = aPnts[0] + QPoint(w, 0);
141
142   thePainter.drawPolygon(aPnts);
143 }
144
145
146 void SUPERVGUI_CanvasStartNodePrs::setState(SUPERV::GraphState theState) 
147 {
148   QRect r = getStatusRect();
149   canvas()->setChanged(QRect(r.x(), r.y(), r.width()+SHIFT, r.height()));
150   SUPERVGUI_CanvasNodePrs::setState(theState);
151 }
152
153
154 //=====================================================================
155 // End control node presentation
156 //=====================================================================
157 SUPERVGUI_CanvasEndNodePrs::SUPERVGUI_CanvasEndNodePrs( SUIT_ResourceMgr* mgr, QCanvas* theCanvas, SUPERVGUI_CanvasEndNode* theNode):
158   SUPERVGUI_CanvasControlNodePrs(mgr,theCanvas, theNode)
159 {
160   Trace("SUPERVGUI_CanvasEndNodePrs::SUPERVGUI_CanvasEndNodePrs");
161 }
162
163 QPointArray SUPERVGUI_CanvasEndNodePrs::areaPoints() const
164 {
165   int w = width();
166   int h = height()+2;
167
168   int h1 = getTitleHeight()+1;
169   int h2 = getStatusHeight()+1;
170
171   QPointArray aPnts(8);
172   QPoint p((int)x(), (int)y()-1);
173   aPnts[0] = p + QPoint(0, h1);
174   aPnts[1] = p + QPoint(-SHIFT, 0);
175   aPnts[2] = aPnts[1] + QPoint(w, 0);
176   aPnts[3] = aPnts[0] + QPoint(w, 0);
177   aPnts[4] = aPnts[3] + QPoint(0, h-h1-h2);
178   aPnts[5] = aPnts[2] + QPoint(0, h);
179   aPnts[6] = aPnts[1] + QPoint(0, h);
180   aPnts[7] = aPnts[0] + QPoint(0, h-h1-h2);
181   return aPnts;
182 }
183
184 void SUPERVGUI_CanvasEndNodePrs::drawFrame(QPainter& thePainter) 
185 {
186   QRect r = getRect();
187
188   int h1 = getTitleHeight();
189   int h2 = getStatusHeight();
190
191   QRect r0(r.x(), r.y()+h1, r.width(), r.height()-h1-h2);
192
193   QBrush saved = thePainter.brush();
194   thePainter.setBrush(NoBrush);
195   thePainter.drawRect(r0);
196   thePainter.setBrush(saved);
197 }
198
199 void SUPERVGUI_CanvasEndNodePrs::drawTitleShape(QPainter& thePainter) 
200 {
201   QRect r = getTitleRect();
202   int w = width()-1;
203
204   QPointArray aPnts(4);
205   aPnts[0] = r.topLeft() + QPoint(0, r.height());
206   aPnts[1] = r.topLeft() + QPoint(-SHIFT, 0);
207   aPnts[2] = aPnts[1] + QPoint(w, 0);
208   aPnts[3] = aPnts[0] + QPoint(w, 0);
209
210   thePainter.setBrush(Qt::red.light());
211   thePainter.drawPolygon(aPnts);
212 }
213
214 void SUPERVGUI_CanvasEndNodePrs::drawStatusShape(QPainter& thePainter) 
215 {
216   QRect r = getStatusRect();
217   int w = width()-1;
218
219   QPointArray aPnts(4);
220   aPnts[0] = r.topLeft() + QPoint(-SHIFT, r.height());
221   aPnts[1] = r.topLeft();
222   aPnts[2] = aPnts[1] + QPoint(w, 0);
223   aPnts[3] = aPnts[0] + QPoint(w, 0);
224
225   thePainter.drawPolygon(aPnts);
226 }
227
228 void SUPERVGUI_CanvasEndNodePrs::setState(SUPERV::GraphState theState)
229 {
230   QRect r = getStatusRect();
231   canvas()->setChanged(QRect(r.x()-SHIFT, r.y(), r.width()+SHIFT, r.height()));
232   SUPERVGUI_CanvasNodePrs::setState(theState);
233 }
234
235 //=====================================================================
236 // Goto control node presentation
237 //=====================================================================
238 SUPERVGUI_CanvasGotoNodePrs::SUPERVGUI_CanvasGotoNodePrs( SUIT_ResourceMgr* mgr, QCanvas* theCanvas, SUPERVGUI_CanvasGotoNode* theNode):
239   SUPERVGUI_CanvasControlNodePrs(mgr, theCanvas, theNode)
240 {
241   Trace("SUPERVGUI_CanvasGotoNodePrs::SUPERVGUI_CanvasGotoNodePrs");
242 }
243
244 QPointArray SUPERVGUI_CanvasGotoNodePrs::areaPoints() const
245 {
246   int w = width();
247   int h = height()+2;
248
249   int h1 = getTitleHeight()+1;
250   int h2 = getStatusHeight()+1;
251
252   QPointArray aPnts(8);
253   QPoint p((int)x(), (int)y()-1);
254   aPnts[0] = p + QPoint(0, h1);
255   aPnts[1] = p + QPoint(SHIFT, 0);
256   aPnts[2] = aPnts[1] + QPoint(w-2*SHIFT, 0);
257   aPnts[3] = aPnts[0] + QPoint(w, 0);
258   aPnts[4] = aPnts[3] + QPoint(0, h-h1-h2);
259   aPnts[5] = aPnts[2] + QPoint(0, h);
260   aPnts[6] = aPnts[1] + QPoint(0, h);
261   aPnts[7] = aPnts[0] + QPoint(0, h-h1-h2);
262   return aPnts;
263 }
264
265 void SUPERVGUI_CanvasGotoNodePrs::drawFrame(QPainter& thePainter) 
266 {
267   QRect r = getRect();
268
269   int h1 = getTitleHeight();
270   int h2 = getStatusHeight();
271
272   QRect r0(r.x(), r.y()+h1, r.width(), r.height()-h1-h2);
273
274   QBrush saved = thePainter.brush();
275   thePainter.setBrush(NoBrush);
276   thePainter.drawRect(r0);
277   thePainter.setBrush(saved);
278 }
279
280 void SUPERVGUI_CanvasGotoNodePrs::drawTitleShape(QPainter& thePainter) 
281 {
282   QRect r = getTitleRect();
283   int w = width()-1;
284
285   QPointArray aPnts(4);
286   aPnts[0] = r.topLeft() + QPoint(0, r.height());
287   aPnts[1] = r.topLeft() + QPoint(SHIFT, 0);
288   aPnts[2] = aPnts[1] + QPoint(w-2*SHIFT, 0);
289   aPnts[3] = aPnts[0] + QPoint(w, 0);
290
291   thePainter.setBrush(Qt::green.light());
292   thePainter.drawPolygon(aPnts);
293 }
294
295 void SUPERVGUI_CanvasGotoNodePrs::drawStatusShape(QPainter& thePainter) 
296 {
297   QRect r = getStatusRect();
298   int w = width()-1;
299
300   QPointArray aPnts(4);
301   aPnts[0] = r.topLeft() + QPoint(SHIFT, r.height());
302   aPnts[1] = r.topLeft();
303   aPnts[2] = aPnts[1] + QPoint(w, 0);
304   aPnts[3] = aPnts[0] + QPoint(w-2*SHIFT, 0);
305
306   thePainter.drawPolygon(aPnts);
307 }
308
309
310 //=====================================================================
311 // Macro node presentation
312 //=====================================================================
313 SUPERVGUI_CanvasMacroNodePrs::SUPERVGUI_CanvasMacroNodePrs( SUIT_ResourceMgr* mgr, QCanvas* theCanvas, SUPERVGUI_CanvasMacroNode* theNode):
314   SUPERVGUI_CanvasNodePrs( mgr, theCanvas, theNode)
315 {
316   Trace("SUPERVGUI_CanvasControlNodePrs::SUPERVGUI_CanvasControlNodePrs");
317   setNodeColor(QColor(255, 186, 149)); //QColor(255, 200, 170));
318 }
319
320 void SUPERVGUI_CanvasMacroNodePrs::drawFrame(QPainter& thePainter) 
321 {
322   SUPERVGUI_CanvasNodePrs::drawFrame(thePainter);
323
324   QPen saved = thePainter.pen();
325   thePainter.setPen(QPen(saved.color(), 2));
326
327   QRect r = getRect();
328   thePainter.drawLine(r.left(), r.top(), r.left(), r.bottom());
329   thePainter.drawLine(r.left()+3, r.top(), r.left()+3, r.bottom());
330   thePainter.drawLine(r.right()-3, r.top(), r.right()-3, r.bottom());
331   thePainter.drawLine(r.right(), r.top(), r.right(), r.bottom());
332   thePainter.setPen(saved);
333 }
334
335 QPointArray SUPERVGUI_CanvasMacroNodePrs::areaPoints() const
336 {
337   int w = width()+2; // add width of pen
338   int h = height()+1;
339
340   QPointArray aPnts(4);
341   aPnts[0] = QPoint((int)x()-1, (int)y());
342   aPnts[1] = aPnts[0] + QPoint(w, 0);
343   aPnts[2] = aPnts[1] + QPoint(0, h);
344   aPnts[3] = aPnts[0] + QPoint(0, h);
345   return aPnts;
346 }