]> SALOME platform Git repositories - modules/superv.git/blob - src/SUPERVGUI/SUPERVGUI_CanvasArray.cxx
Salome HOME
Fix for bug IPAL9558 : Maintainance Mandrake porting: black rectangle in table view.
[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 using namespace std;
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(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(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(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):
80   QCanvas(),
81   myMain(m)
82 {
83   Trace("SUPERVGUI_CanvasArray::SUPERVGUI_CanvasArray");
84   //resize(GRAPH_WIDTH, GRAPH_HEIGHT);
85   resize(1000, 725);
86   setDoubleBuffering(true);
87
88   QColor aColor(MAIN_COLOR);
89   //aColor = QColor(SUIT_Session::session()->resourceMgr()->integerValue( "SUPERVGraph", "BackgroundColorRed" ), 
90   //              SUIT_Session::session()->resourceMgr()->integerValue( "SUPERVGraph", "BackgroundColorGreen" ), 
91   //              SUIT_Session::session()->resourceMgr()->integerValue( "SUPERVGraph", "BackgroundColorBlue" ) );
92   setBackgroundColor(aColor);
93 }
94
95 SUPERVGUI_CanvasArray::~SUPERVGUI_CanvasArray() {
96   Trace("SUPERVGUI_Array::~SUPERVGUI_CanvasArray");
97   //delete all cells which SUPERVGUI_CanvasArray contains
98   //destroy();
99   QObjectList* aCellList = queryList("SUPERVGUI_CanvasCellNode");
100   QObjectListIt aIt(*aCellList);
101   QObject* anObj;
102   while ((anObj = aIt.current()) != 0) {
103     ++aIt;
104     delete anObj;
105   }
106   delete aCellList;
107 }
108
109 void SUPERVGUI_CanvasArray::sync() {
110   if (SUPERV_isNull(myMain->getDataflow())) return;
111   
112   SUPERVGUI_CanvasCellNode* ihmNode;
113   QObjectList* ihmList = queryList("SUPERVGUI_CanvasCellNode");
114   QObjectListIt it(*ihmList);
115   while ((ihmNode=(SUPERVGUI_CanvasCellNode*)it.current()) != 0) {
116     ++it;
117     ihmNode->sync();
118   }
119   delete ihmList;
120 }
121
122 bool SUPERVGUI_CanvasArray::create() {
123   Trace("SUPERVGUI_Array::create");
124   SUPERV_Nodes nodes = myMain->getDataflow()->Nodes();
125   int aCount = 0;
126   aCount += nodes->CNodes.length();
127   aCount += nodes->FNodes.length();
128   aCount += nodes->INodes.length();
129   aCount += nodes->GNodes.length();
130   aCount += nodes->LNodes.length();
131   aCount += nodes->SNodes.length();
132   if (aCount == 0) return true;
133
134   SUPERVGUI_CanvasCellNode* cell;
135   QString         aLabel;
136   int             x, y;
137  
138   int             nligs = myMain->getDataflow()->LevelMax();
139   cout<<"-> myMain->getDataflow()->LevelMax() = "<<myMain->getDataflow()->LevelMax()<<endl;
140   int             ncols = myMain->getDataflow()->ThreadsMax();
141   cout<<"-> myMain->getDataflow()->ThreadsMax() = "<<myMain->getDataflow()->ThreadsMax()<<endl;
142   
143   // there is no any calculations
144   if (ncols == 0) return false;
145
146   QPen pen(Qt::SolidLine);
147   pen.setWidth(1);
148   QBrush br(MAIN_TITLE);
149   
150   // variables to resize canvas in table view
151   int aMaxWidth = 0;
152   int aMaxHeight = 0;
153   
154   for (int co = 0; co < ncols; co++) {
155     aLabel = QString("Thread %1").arg(co);
156     QRect aRect = QRect(50 + co * (CELL_WIDTH  + CELL_SPACE), 20, CELL_WIDTH, CELL_HEIGHT);
157     QCanvasRectangle* aThread = new QCanvasRectangle(aRect, this);
158     aThread->setPen(pen);
159     aThread->setBrush(br);
160     aThread->setZ(0);
161     aThread->show();
162     
163     QCanvasText* aText = new QCanvasText(aLabel, this);
164     QRect aBRect = aText->boundingRect();
165     aText->setX(aRect.x() + aRect.width()/2 - aBRect.width()/2);
166     aText->setY(aRect.y() + aRect.height()/2 - aBRect.height()/2);
167     aText->setZ(1);
168     aText->show();
169     
170     aMaxWidth = aRect.x() + aRect.width() + 50;
171   }
172   
173   y = 60;
174   bool LevelHasDiffNT = false;
175   for (int li = 0; li <= nligs; li++) {
176     nodes = myMain->getDataflow()->LevelNodes(li);
177     int aSumNum = nodes->CNodes.length()+nodes->FNodes.length()+nodes->INodes.length()+
178                   nodes->GNodes.length()+nodes->LNodes.length()+nodes->SNodes.length();
179     if (nodes->CNodes.length() != 0 ) {
180       ADDNODES(CNodes,LevelHasDiffNT);
181       if (aSumNum > nodes->CNodes.length())
182         LevelHasDiffNT = true;
183     }
184     if (nodes->FNodes.length() != 0 ) {
185       ADDNODES(FNodes,LevelHasDiffNT);
186       if (aSumNum > nodes->FNodes.length())
187         LevelHasDiffNT = true;
188     }
189     if (nodes->INodes.length() != 0 ) {
190       ADDNODES(INodes,LevelHasDiffNT);
191       if (aSumNum > nodes->INodes.length())
192         LevelHasDiffNT = true;
193     }
194     if (nodes->GNodes.length() != 0 ) {
195       ADDNODES(GNodes,LevelHasDiffNT);
196       if (aSumNum > nodes->GNodes.length())
197         LevelHasDiffNT = true;
198     }
199     if (nodes->LNodes.length() != 0 ) {
200       ADDCONTROLNODES(LNodes,LevelHasDiffNT);
201       if (aSumNum > nodes->LNodes.length())
202         LevelHasDiffNT = true;
203     }
204     if (nodes->SNodes.length() != 0 ) {
205       ADDCONTROLNODES(SNodes,LevelHasDiffNT);
206       if (aSumNum > nodes->SNodes.length())
207         LevelHasDiffNT = true;
208     }
209     y += (CELL_HEIGHT + CELL_SPACE);
210
211     LevelHasDiffNT = false;
212   }
213   nodeX = 50;
214   nodeY = y + CELL_HEIGHT*2;
215
216   aMaxHeight = nodeY;
217   
218   // if aMaxWidth and aMaxHeight is greater than the current size 
219   // of the canvas, we resize canvas to these new width and height
220   if ( aMaxWidth > this->width() || aMaxHeight > this->height() )
221     this->resize( aMaxWidth > this->width() ? aMaxWidth : this->width(), 
222                   aMaxHeight > this->height() ? aMaxHeight : this->height() );
223   return true;
224
225 }
226
227 void SUPERVGUI_CanvasArray::destroy() {
228   Trace("SUPERVGUI_Array::destroy");
229   
230   QObjectList* aCellList = queryList("SUPERVGUI_CanvasCellNode");
231   QObjectListIt aIt(*aCellList);
232   QObject* anObj;
233   while ((anObj = aIt.current()) != 0) {
234     ++aIt;
235     ((SUPERVGUI_CanvasCellNode*)anObj)->getPrs()->hide();
236   }
237   delete aCellList;
238
239   // mkr : delete QCanvasRectangle and QCanvasText canvas items for each Thread.
240   // Threads will be recreate when create() function is called
241   QCanvasItemList aTextList = allItems();
242   for (QCanvasItemList::Iterator aItText = aTextList.begin(); aItText != aTextList.end(); ++aItText) {
243     SUPERVGUI_CanvasCellNodePrs* aPrs = dynamic_cast<SUPERVGUI_CanvasCellNodePrs*>(*aItText);
244     if (!aPrs) {
245       (*aItText)->hide();
246       delete *aItText;
247     }
248   }
249 }
250
251 SUPERVGUI_CanvasCellNode* SUPERVGUI_CanvasArray::getCellNode(SUPERV::CNode_ptr theNode) const
252 {
253   return (SUPERVGUI_CanvasCellNode*) 
254     ((SUPERVGUI_CanvasArray*)this)->child(theNode->Name(), "SUPERVGUI_CanvasCellNode");
255 }
256
257 SUPERVGUI_CanvasCellNode* SUPERVGUI_CanvasArray::addNode(SUPERV_CNode node) {
258   Trace("SUPERVGUI_CanvasArray::addNode");
259   SUPERVGUI_CanvasCellNode* n = new SUPERVGUI_CanvasCellNode(this, myMain, node);
260   n->move(nodeX, nodeY);
261   n->show();
262   update();
263   nodeX += NODE_DX;
264   nodeY += NODE_DY;
265   n->sync();
266   return(n);
267 }