1 // SUPERV SUPERVGUI : GUI for Supervisor component
3 // Copyright (C) 2003 OPEN CASCADE
5 // File : SUPERVGUI_CanvasArray.cxx
10 #include "SUPERVGUI_CanvasArray.h"
11 #include "SUPERVGUI_Main.h"
12 #include "SUPERVGUI_BrowseNodeDlg.h"
13 #include "QAD_Config.h"
14 #include "SUPERVGUI_CanvasCellNodePrs.h"
17 //#include <qpointarray.h>
20 #define ADDNODES(NodesName,LevelHasDiffNT) \
21 ncols = nodes->NodesName.length(); \
22 for (int co=0; co<ncols; co++) { \
23 SUPERV_CNode aCNode = SUPERV::CNode::_narrow(nodes->NodesName[co]); \
24 if (!LevelHasDiffNT) x = 50 + co * (CELL_WIDTH + CELL_SPACE); \
25 else x += (CELL_WIDTH + CELL_SPACE); \
26 cell = getCellNode(aCNode); \
28 cout<<" ***> cell is NULL => create a new one"<<endl; \
29 SUPERVGUI_CanvasCellNode* aNode = new SUPERVGUI_CanvasCellNode(this, myMain, aCNode); \
34 cout<<" ***> cell is NOT NULL => not create"<<endl; \
43 #define ADDCONTROLNODES(NodesName,LevelHasDiffNT) \
44 ncols = nodes->NodesName.length(); \
45 if (!LevelHasDiffNT) x = 50; \
46 else x += (CELL_WIDTH + CELL_SPACE); \
47 for (int co=0; co<ncols; co++) { \
48 SUPERV_CNode aCNode = SUPERV::CNode::_narrow(nodes->NodesName[co]); \
49 SUPERV_CNode aCNodeEnd = SUPERV::CNode::_narrow(nodes->NodesName[co]->Coupled()); \
50 cell = getCellNode(aCNode); \
52 cout<<" ***> cell control is NULL => create a new one"<<endl; \
53 SUPERVGUI_CanvasCellNode* aNode = new SUPERVGUI_CanvasCellNode(this, myMain, aCNode); \
57 y += (CELL_HEIGHT + CELL_SPACE); \
58 SUPERVGUI_CanvasCellNode* aNodeEnd = new SUPERVGUI_CanvasCellEndNode(this, myMain, aCNodeEnd, aNode); \
59 aNodeEnd->move(x, y); \
63 cout<<" ***> cell control is NOT NULL => not create"<<endl; \
66 y += (CELL_HEIGHT + CELL_SPACE); \
67 cell = getCellNode(aCNodeEnd); \
72 x += (CELL_WIDTH + CELL_SPACE); \
76 // ----------------------------------------------------------
77 // SUPERVGUI_Array on QCanvas
78 // ----------------------------------------------------------
80 SUPERVGUI_CanvasArray::SUPERVGUI_CanvasArray(SUPERVGUI_Main* m):
84 Trace("SUPERVGUI_CanvasArray::SUPERVGUI_CanvasArray");
85 //resize(GRAPH_WIDTH, GRAPH_HEIGHT);
87 setDoubleBuffering(true);
89 QColor aColor(MAIN_COLOR);
90 QString aRed = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorRed");
91 QString aGreen = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorGreen");
92 QString aBlue = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorBlue");
93 if( (!aRed.isEmpty()) && (!aGreen.isEmpty()) && (!aBlue.isEmpty()) )
94 aColor = QColor(aRed.toInt(), aGreen.toInt(), aBlue.toInt());
95 setBackgroundColor(aColor);
99 SUPERVGUI_CanvasArray::~SUPERVGUI_CanvasArray() {
100 Trace("SUPERVGUI_Array::~SUPERVGUI_CanvasArray");
101 //delete all cells which SUPERVGUI_CanvasArray contains
103 QObjectList* aCellList = queryList("SUPERVGUI_CanvasCellNode");
104 QObjectListIt aIt(*aCellList);
106 while ((anObj = aIt.current()) != 0) {
113 QObjectList* aCellEndList = queryList("SUPERVGUI_CanvasCellEndNode");
114 QObjectListIt aItEnd(*aCellEndList);
116 while ((anObjEnd = aItEnd.current()) != 0) {
124 void SUPERVGUI_CanvasArray::sync() {
125 MESSAGE("===> SUPERVGUI_CanvasArray::sync()");
126 if (SUPERV_isNull(myMain->getDataflow())) return;
128 SUPERVGUI_CanvasCellNode* ihmNode;
129 QObjectList* ihmList = queryList("SUPERVGUI_CanvasCellNode");
130 QObjectListIt it(*ihmList);
131 while ((ihmNode=(SUPERVGUI_CanvasCellNode*)it.current()) != 0) {
137 SUPERVGUI_CanvasCellEndNode* ihmNodeEnd;
138 QObjectList* ihmListEnd = queryList("SUPERVGUI_CanvasCellEndNode");
139 QObjectListIt itEnd(*ihmListEnd);
140 while ((ihmNodeEnd=(SUPERVGUI_CanvasCellEndNode*)itEnd.current()) != 0) {
147 bool SUPERVGUI_CanvasArray::create() {
148 Trace("SUPERVGUI_Array::create");
149 SUPERV_Nodes nodes = myMain->getDataflow()->Nodes();
151 aCount += nodes->CNodes.length();
152 aCount += nodes->FNodes.length();
153 aCount += nodes->INodes.length();
154 aCount += nodes->GNodes.length();
155 aCount += nodes->LNodes.length();
156 aCount += nodes->SNodes.length();
157 if (aCount == 0) return true;
159 SUPERVGUI_CanvasCellNode* cell;
162 int nligs = myMain->getDataflow()->LevelMax();
163 int ncols = myMain->getDataflow()->ThreadsMax();
165 // there is no any calculations
166 if (ncols == 0) return false;
168 QCanvasItemList anIL1 = this->allItems();
169 cout<<" ===> begin create() : CanvasArray has "<<anIL1.count()<<" items!"<<endl;
171 QPen pen(Qt::SolidLine);
173 QBrush br(MAIN_TITLE);
175 if (myOldThreadNum) { //some of threads allready exist on canvas array
176 cout<<" ===> second ... creation !"<<endl;
177 QObjectList* aThreadList = queryList("QCanvasRectangle");
178 QObjectListIt aItThread(*aThreadList);
179 QCanvasRectangle* anObjThread;
180 while ((anObjThread = (QCanvasRectangle*)aItThread.current()) != 0) {
182 if (!anObjThread->isVisible())
187 QObjectList* aTextList = queryList("QCanvasText");
188 QObjectListIt aItText(*aTextList);
189 QCanvasText* anObjText;
190 while ((anObjText = (QCanvasText*)aItText.current()) != 0) {
192 if (!anObjText->isVisible())
198 for (int co = myOldThreadNum; co < ncols; co++) {
199 aLabel = QString("Thread %1").arg(co);
200 QRect aRect = QRect(50 + co * (CELL_WIDTH + CELL_SPACE), 20, CELL_WIDTH, CELL_HEIGHT);
201 QCanvasRectangle* aThread = new QCanvasRectangle(aRect, this);
202 aThread->setPen(pen);
203 aThread->setBrush(br);
207 QCanvasText* aText = new QCanvasText(aLabel, this);
208 QRect aBRect = aText->boundingRect();
209 aText->setX(aRect.x() + aRect.width()/2 - aBRect.width()/2);
210 aText->setY(aRect.y() + aRect.height()/2 - aBRect.height()/2);
215 myOldThreadNum = ncols;
217 QCanvasItemList anIL2 = this->allItems();
218 cout<<" ===> 1 create() : CanvasArray has "<<anIL2.count()<<" items!"<<endl;
221 bool LevelHasDiffNT = false;
222 for (int li = 0; li <= nligs; li++) {
223 nodes = myMain->getDataflow()->LevelNodes(li);
224 int aSumNum = nodes->CNodes.length()+nodes->FNodes.length()+nodes->INodes.length()+
225 nodes->GNodes.length()+nodes->LNodes.length()+nodes->SNodes.length();
226 if (nodes->CNodes.length() != 0 ) {
227 ADDNODES(CNodes,LevelHasDiffNT);
228 if (aSumNum > nodes->CNodes.length())
229 LevelHasDiffNT = true;
231 if (nodes->FNodes.length() != 0 ) {
232 ADDNODES(FNodes,LevelHasDiffNT);
234 QCanvasItemList anIL3 = this->allItems();
235 cout<<" ===> 2 create() : CanvasArray has "<<anIL3.count()<<" items!"<<endl;
237 if (aSumNum > nodes->FNodes.length())
238 LevelHasDiffNT = true;
240 if (nodes->INodes.length() != 0 ) {
241 ADDNODES(INodes,LevelHasDiffNT);
242 if (aSumNum > nodes->INodes.length())
243 LevelHasDiffNT = true;
245 if (nodes->GNodes.length() != 0 ) {
246 ADDNODES(GNodes,LevelHasDiffNT);
247 if (aSumNum > nodes->GNodes.length())
248 LevelHasDiffNT = true;
250 if (nodes->LNodes.length() != 0 ) {
251 ADDCONTROLNODES(LNodes,LevelHasDiffNT);
252 if (aSumNum > nodes->LNodes.length())
253 LevelHasDiffNT = true;
255 if (nodes->SNodes.length() != 0 ) {
256 ADDCONTROLNODES(SNodes,LevelHasDiffNT);
257 if (aSumNum > nodes->SNodes.length())
258 LevelHasDiffNT = true;
260 y += (CELL_HEIGHT + CELL_SPACE);
262 LevelHasDiffNT = false;
265 nodeY = y + CELL_HEIGHT*2;
267 QCanvasItemList anIL4 = this->allItems();
268 cout<<" ===> end create() : CanvasArray has "<<anIL4.count()<<" items!"<<endl;
274 void SUPERVGUI_CanvasArray::destroy() {
275 Trace("SUPERVGUI_Array::destroy");
277 QCanvasItemList anIL1 = this->allItems();
278 cout<<" ===> begin destroy() : CanvasArray has "<<anIL1.count()<<" items!"<<endl;
279 const QObjectList* anCL1 = this->children();
280 cout<<" ===> begin destroy() : CanvasArray has "<<anCL1->count()<<" children!"<<endl;
282 QObjectList* aCellList = queryList("SUPERVGUI_CanvasCellNode");
283 QObjectListIt aIt(*aCellList);
285 while ((anObj = aIt.current()) != 0) {
287 ((SUPERVGUI_CanvasCellNode*)anObj)->getPrs()->hide();
292 QObjectList* aCellEndList = queryList("SUPERVGUI_CanvasCellEndNode");
293 QObjectListIt aItEnd(*aCellEndList);
295 while ((anObjEnd = aItEnd.current()) != 0) {
297 ((SUPERVGUI_CanvasCellEndNode*)anObjEnd)->getPrs()->hide();
302 QObjectList* aThreadList = queryList("QCanvasRectangle");
303 QObjectListIt aItThread(*aThreadList);
304 QCanvasRectangle* anObjThread;
305 while ((anObjThread = (QCanvasRectangle*)aItThread.current()) != 0) {
312 QObjectList* aTextList = queryList("QCanvasText");
313 QObjectListIt aItText(*aTextList);
314 QCanvasText* anObjText;
315 while ((anObjText = (QCanvasText*)aItText.current()) != 0) {
322 QCanvasItemList anIL2 = this->allItems();
323 cout<<" ===> end destroy() : CanvasArray has "<<anIL2.count()<<" items!"<<endl;
326 SUPERVGUI_CanvasCellNode* SUPERVGUI_CanvasArray::getCellNode(SUPERV::CNode_ptr theNode) const
328 return (SUPERVGUI_CanvasCellNode*)
329 ((SUPERVGUI_CanvasArray*)this)->child(theNode->Name(), "SUPERVGUI_CanvasCellNode");
332 SUPERVGUI_CanvasCellNode* SUPERVGUI_CanvasArray::addNode(SUPERV_CNode node) {
333 Trace("SUPERVGUI_CanvasArray::addNode");
334 SUPERVGUI_CanvasCellNode* n = new SUPERVGUI_CanvasCellNode(this, myMain, node);
335 n->move(nodeX, nodeY);