]> SALOME platform Git repositories - modules/superv.git/blob - src/SUPERVGUI/SUPERVGUI_CanvasArray.cxx
Salome HOME
Join modifications from branch OCC_development_for_3_2_0a2
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_CanvasArray.cxx
1 //  SUPERV SUPERVGUI : GUI for Supervisor component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE
4 //
5 //  File   : SUPERVGUI_CanvasArray.cxx
6 //  Author : 
7 //  Module : SUPERV
8
9 #include "SUPERVGUI.h"
10 #include "SUPERVGUI_CanvasArray.h"
11 #include "SUPERVGUI_Main.h"
12 #include "SUPERVGUI_BrowseNodeDlg.h"
13 #include "SUPERVGUI_CanvasCellNodePrs.h"
14
15 #include "SUIT_ResourceMgr.h"
16 #include "SUIT_Session.h"
17
18 #include <qtooltip.h>
19 #define TEXT_MARGIN 5
20
21 #include <iostream.h> //for debug only
22
23 #define ADDNODES(NodesName,LevelHasDiffNT) \
24     ncols = nodes->NodesName.length(); \
25     for (int co=0; co<ncols; co++) {  \
26       SUPERV_CNode aCNode = SUPERV::CNode::_narrow(nodes->NodesName[co]); \
27       if (!LevelHasDiffNT) x = 50 + co * (CELL_WIDTH  + CELL_SPACE); \
28       else x += (CELL_WIDTH  + CELL_SPACE); \
29       cell = getCellNode(aCNode); \
30       if (cell == NULL) { \
31         SUPERVGUI_CanvasCellNode* aNode = new SUPERVGUI_CanvasCellNode(myMgr, this, myMain, aCNode); \
32         aNode->move(x, y); \
33         aNode->show(); \
34         aNode->sync(); \
35       } else { \
36         cell->move(x, y); \
37         cell->show(); \
38       } \
39       update(); \
40     }
41
42
43
44 #define ADDCONTROLNODES(NodesName,LevelHasDiffNT) \
45     ncols = nodes->NodesName.length(); \
46     if (!LevelHasDiffNT) x = 50; \
47     else x += (CELL_WIDTH  + CELL_SPACE); \
48     for (int co=0; co<ncols; co++) {  \
49       SUPERV_CNode aCNode = SUPERV::CNode::_narrow(nodes->NodesName[co]); \
50       SUPERV_CNode aCNodeEnd = SUPERV::CNode::_narrow(nodes->NodesName[co]->Coupled()); \
51       cell = getCellNode(aCNode); \
52       if (cell == NULL) { \
53         SUPERVGUI_CanvasCellNode* aNode = new SUPERVGUI_CanvasCellNode( myMgr, this, myMain, aCNode); \
54         aNode->move(x, y); \
55         aNode->show(); \
56         aNode->sync(); \
57         y += (CELL_HEIGHT + CELL_SPACE); \
58         SUPERVGUI_CanvasCellNode* aNodeEnd = new SUPERVGUI_CanvasCellEndNode( myMgr, this, myMain, aCNodeEnd, aNode); \
59         aNodeEnd->move(x, y); \
60         aNodeEnd->show(); \
61         aNodeEnd->sync(); \
62       } else { \
63         cell->move(x, y); \
64         cell->show(); \
65         y += (CELL_HEIGHT + CELL_SPACE); \
66         cell = getCellNode(aCNodeEnd); \
67         cell->move(x, y); \
68         cell->show(); \
69       } \
70       update(); \
71       if (co < (ncols-1)) x += (CELL_WIDTH + CELL_SPACE); \
72     }
73
74
75 // ----------------------------------------------------------
76 // SUPERVGUI_Array on QCanvas
77 // ----------------------------------------------------------
78
79 SUPERVGUI_CanvasArray::SUPERVGUI_CanvasArray(SUPERVGUI_Main* m, SUIT_ResourceMgr* mgr ):
80   QCanvas(),
81   myMain(m),
82   myMgr( mgr )
83 {
84   Trace("SUPERVGUI_CanvasArray::SUPERVGUI_CanvasArray");
85   //resize(GRAPH_WIDTH, GRAPH_HEIGHT);
86   resize(1000, 725);
87   setDoubleBuffering(true);
88
89   // mkr : IPAL10825 -->
90   SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
91   if ( !aSupMod ) {
92     MESSAGE("NULL Supervision module!");
93     return;
94   }
95   QColor aColor =  aSupMod->getIVFBackgroundColor();
96   if ( !aColor.isValid() )
97     aColor = mgr->colorValue( "SUPERVGraph", "Background", DEF_MAIN_COLOR );
98   // <--
99   
100   //aColor = QColor(SUIT_Session::session()->resourceMgr()->integerValue( "SUPERVGraph", "BackgroundColorRed" ), 
101   //              SUIT_Session::session()->resourceMgr()->integerValue( "SUPERVGraph", "BackgroundColorGreen" ), 
102   //              SUIT_Session::session()->resourceMgr()->integerValue( "SUPERVGraph", "BackgroundColorBlue" ) );
103   setBackgroundColor(aColor);
104 }
105
106 SUPERVGUI_CanvasArray::~SUPERVGUI_CanvasArray() {
107   Trace("SUPERVGUI_Array::~SUPERVGUI_CanvasArray");
108   //delete all cells which SUPERVGUI_CanvasArray contains
109   //destroy();
110   QObjectList* aCellList = queryList("SUPERVGUI_CanvasCellNode");
111   QObjectListIt aIt(*aCellList);
112   QObject* anObj;
113   while ((anObj = aIt.current()) != 0) {
114     ++aIt;
115     delete anObj;
116   }
117   delete aCellList;
118 }
119
120 void SUPERVGUI_CanvasArray::sync() {
121   if (SUPERV_isNull(myMain->getDataflow())) return;
122   
123   SUPERVGUI_CanvasCellNode* ihmNode;
124   QObjectList* ihmList = queryList("SUPERVGUI_CanvasCellNode");
125   QObjectListIt it(*ihmList);
126   while ((ihmNode=(SUPERVGUI_CanvasCellNode*)it.current()) != 0) {
127     ++it;
128     ihmNode->sync();
129   }
130   delete ihmList;
131 }
132
133 bool SUPERVGUI_CanvasArray::create() {
134   Trace("SUPERVGUI_Array::create");
135   SUPERV_Nodes nodes = myMain->getDataflow()->Nodes();
136   int aCount = 0;
137   aCount += nodes->CNodes.length();
138   aCount += nodes->FNodes.length();
139   aCount += nodes->INodes.length();
140   aCount += nodes->GNodes.length();
141   aCount += nodes->LNodes.length();
142   aCount += nodes->SNodes.length();
143   if (aCount == 0) return true;
144
145   SUPERVGUI_CanvasCellNode* cell;
146   QString         aLabel;
147   int             x, y;
148  
149   int             nligs = myMain->getDataflow()->LevelMax();
150   int             ncols = myMain->getDataflow()->ThreadsMax();
151   
152   // there is no any calculations
153   if (ncols == 0) return false;
154
155   QPen pen(Qt::SolidLine);
156   pen.setWidth(1);
157
158   QBrush br( myMgr->colorValue( "SUPERVGraph", "Title", DEF_MAIN_TITLE ) );
159   
160   // variables to resize canvas in table view
161   int aMaxWidth = 0;
162   int aMaxHeight = 0;
163   
164   for (int co = 0; co < ncols; co++) {
165     aLabel = QString("Thread %1").arg(co);
166     QRect aRect = QRect(50 + co * (CELL_WIDTH  + CELL_SPACE), 20, CELL_WIDTH, CELL_HEIGHT);
167     QCanvasRectangle* aThread = new QCanvasRectangle(aRect, this);
168     aThread->setPen(pen);
169     aThread->setBrush(br);
170     aThread->setZ(0);
171     aThread->show();
172     
173     QCanvasText* aText = new QCanvasText(aLabel, this);
174     QRect aBRect = aText->boundingRect();
175     aText->setX(aRect.x() + aRect.width()/2 - aBRect.width()/2);
176     aText->setY(aRect.y() + aRect.height()/2 - aBRect.height()/2);
177     aText->setZ(1);
178     aText->show();
179     
180     aMaxWidth = aRect.x() + aRect.width() + 50;
181   }
182   
183   y = 60;
184   bool LevelHasDiffNT = false;
185   for (int li = 0; li <= nligs; li++) {
186     nodes = myMain->getDataflow()->LevelNodes(li);
187     int aSumNum = nodes->CNodes.length()+nodes->FNodes.length()+nodes->INodes.length()+
188                   nodes->GNodes.length()+nodes->LNodes.length()+nodes->SNodes.length();
189     if (nodes->CNodes.length() != 0 ) {
190       ADDNODES(CNodes,LevelHasDiffNT);
191       if (aSumNum > nodes->CNodes.length())
192         LevelHasDiffNT = true;
193     }
194     if (nodes->FNodes.length() != 0 ) {
195       ADDNODES(FNodes,LevelHasDiffNT);
196       if (aSumNum > nodes->FNodes.length())
197         LevelHasDiffNT = true;
198     }
199     if (nodes->INodes.length() != 0 ) {
200       ADDNODES(INodes,LevelHasDiffNT);
201       if (aSumNum > nodes->INodes.length())
202         LevelHasDiffNT = true;
203     }
204     if (nodes->GNodes.length() != 0 ) {
205       ADDNODES(GNodes,LevelHasDiffNT);
206       if (aSumNum > nodes->GNodes.length())
207         LevelHasDiffNT = true;
208     }
209     if (nodes->LNodes.length() != 0 ) {
210       ADDCONTROLNODES(LNodes,LevelHasDiffNT);
211       if (aSumNum > nodes->LNodes.length())
212         LevelHasDiffNT = true;
213     }
214     if (nodes->SNodes.length() != 0 ) {
215       ADDCONTROLNODES(SNodes,LevelHasDiffNT);
216       if (aSumNum > nodes->SNodes.length())
217         LevelHasDiffNT = true;
218     }
219     y += (CELL_HEIGHT + CELL_SPACE);
220
221     LevelHasDiffNT = false;
222   }
223   nodeX = 50;
224   nodeY = y + CELL_HEIGHT*2;
225
226   aMaxHeight = nodeY;
227   
228   // if aMaxWidth and aMaxHeight is greater than the current size 
229   // of the canvas, we resize canvas to these new width and height
230   if ( aMaxWidth > this->width() || aMaxHeight > this->height() )
231     this->resize( aMaxWidth > this->width() ? aMaxWidth : this->width(), 
232                   aMaxHeight > this->height() ? aMaxHeight : this->height() );
233   return true;
234
235 }
236
237 void SUPERVGUI_CanvasArray::destroy() {
238   Trace("SUPERVGUI_Array::destroy");
239   
240   QObjectList* aCellList = queryList("SUPERVGUI_CanvasCellNode");
241   QObjectListIt aIt(*aCellList);
242   QObject* anObj;
243   while ((anObj = aIt.current()) != 0) {
244     ++aIt;
245     ((SUPERVGUI_CanvasCellNode*)anObj)->getPrs()->hide();
246   }
247   delete aCellList;
248
249   // mkr : delete QCanvasRectangle and QCanvasText canvas items for each Thread.
250   // Threads will be recreate when create() function is called
251   QCanvasItemList aTextList = allItems();
252   for (QCanvasItemList::Iterator aItText = aTextList.begin(); aItText != aTextList.end(); ++aItText) {
253     SUPERVGUI_CanvasCellNodePrs* aPrs = dynamic_cast<SUPERVGUI_CanvasCellNodePrs*>(*aItText);
254     if (!aPrs) {
255       (*aItText)->hide();
256       delete *aItText;
257     }
258   }
259 }
260
261 SUPERVGUI_CanvasCellNode* SUPERVGUI_CanvasArray::getCellNode(SUPERV::CNode_ptr theNode) const
262 {
263   return (SUPERVGUI_CanvasCellNode*) 
264     ((SUPERVGUI_CanvasArray*)this)->child(theNode->Name(), "SUPERVGUI_CanvasCellNode");
265 }
266
267 SUPERVGUI_CanvasCellNode* SUPERVGUI_CanvasArray::addNode(SUPERV_CNode node) {
268   Trace("SUPERVGUI_CanvasArray::addNode");
269   SUPERVGUI_CanvasCellNode* n = new SUPERVGUI_CanvasCellNode( myMgr, this, myMain, node);
270   n->move(nodeX, nodeY);
271   n->show();
272   update();
273   nodeX += NODE_DX;
274   nodeY += NODE_DY;
275   n->sync();
276   return(n);
277 }