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 "SUPERVGUI_CanvasCellNodePrs.h"
15 #include "SUIT_ResourceMgr.h"
16 #include "SUIT_Session.h"
21 #include <iostream.h> //for debug only
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); \
31 SUPERVGUI_CanvasCellNode* aNode = new SUPERVGUI_CanvasCellNode(this, myMain, aCNode); \
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); \
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); \
65 y += (CELL_HEIGHT + CELL_SPACE); \
66 cell = getCellNode(aCNodeEnd); \
71 if (co < (ncols-1)) x += (CELL_WIDTH + CELL_SPACE); \
75 // ----------------------------------------------------------
76 // SUPERVGUI_Array on QCanvas
77 // ----------------------------------------------------------
79 SUPERVGUI_CanvasArray::SUPERVGUI_CanvasArray(SUPERVGUI_Main* m):
83 Trace("SUPERVGUI_CanvasArray::SUPERVGUI_CanvasArray");
84 //resize(GRAPH_WIDTH, GRAPH_HEIGHT);
86 setDoubleBuffering(true);
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);
95 SUPERVGUI_CanvasArray::~SUPERVGUI_CanvasArray() {
96 Trace("SUPERVGUI_Array::~SUPERVGUI_CanvasArray");
97 //delete all cells which SUPERVGUI_CanvasArray contains
99 QObjectList* aCellList = queryList("SUPERVGUI_CanvasCellNode");
100 QObjectListIt aIt(*aCellList);
102 while ((anObj = aIt.current()) != 0) {
109 void SUPERVGUI_CanvasArray::sync() {
110 if (SUPERV_isNull(myMain->getDataflow())) return;
112 SUPERVGUI_CanvasCellNode* ihmNode;
113 QObjectList* ihmList = queryList("SUPERVGUI_CanvasCellNode");
114 QObjectListIt it(*ihmList);
115 while ((ihmNode=(SUPERVGUI_CanvasCellNode*)it.current()) != 0) {
122 bool SUPERVGUI_CanvasArray::create() {
123 Trace("SUPERVGUI_Array::create");
124 SUPERV_Nodes nodes = myMain->getDataflow()->Nodes();
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;
134 SUPERVGUI_CanvasCellNode* cell;
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;
143 // there is no any calculations
144 if (ncols == 0) return false;
146 QPen pen(Qt::SolidLine);
148 QBrush br(MAIN_TITLE);
150 // variables to resize canvas in table view
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);
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);
170 aMaxWidth = aRect.x() + aRect.width() + 50;
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;
184 if (nodes->FNodes.length() != 0 ) {
185 ADDNODES(FNodes,LevelHasDiffNT);
186 if (aSumNum > nodes->FNodes.length())
187 LevelHasDiffNT = true;
189 if (nodes->INodes.length() != 0 ) {
190 ADDNODES(INodes,LevelHasDiffNT);
191 if (aSumNum > nodes->INodes.length())
192 LevelHasDiffNT = true;
194 if (nodes->GNodes.length() != 0 ) {
195 ADDNODES(GNodes,LevelHasDiffNT);
196 if (aSumNum > nodes->GNodes.length())
197 LevelHasDiffNT = true;
199 if (nodes->LNodes.length() != 0 ) {
200 ADDCONTROLNODES(LNodes,LevelHasDiffNT);
201 if (aSumNum > nodes->LNodes.length())
202 LevelHasDiffNT = true;
204 if (nodes->SNodes.length() != 0 ) {
205 ADDCONTROLNODES(SNodes,LevelHasDiffNT);
206 if (aSumNum > nodes->SNodes.length())
207 LevelHasDiffNT = true;
209 y += (CELL_HEIGHT + CELL_SPACE);
211 LevelHasDiffNT = false;
214 nodeY = y + CELL_HEIGHT*2;
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() );
227 void SUPERVGUI_CanvasArray::destroy() {
228 Trace("SUPERVGUI_Array::destroy");
230 QObjectList* aCellList = queryList("SUPERVGUI_CanvasCellNode");
231 QObjectListIt aIt(*aCellList);
233 while ((anObj = aIt.current()) != 0) {
235 ((SUPERVGUI_CanvasCellNode*)anObj)->getPrs()->hide();
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);
251 SUPERVGUI_CanvasCellNode* SUPERVGUI_CanvasArray::getCellNode(SUPERV::CNode_ptr theNode) const
253 return (SUPERVGUI_CanvasCellNode*)
254 ((SUPERVGUI_CanvasArray*)this)->child(theNode->Name(), "SUPERVGUI_CanvasCellNode");
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);