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(myMgr, 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( myMgr, this, myMain, aCNode); \
57 y += (CELL_HEIGHT + CELL_SPACE); \
58 SUPERVGUI_CanvasCellNode* aNodeEnd = new SUPERVGUI_CanvasCellEndNode( myMgr, 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, SUIT_ResourceMgr* mgr ):
84 Trace("SUPERVGUI_CanvasArray::SUPERVGUI_CanvasArray");
85 //resize(GRAPH_WIDTH, GRAPH_HEIGHT);
87 setDoubleBuffering(true);
89 // mkr : IPAL10825 -->
90 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
92 MESSAGE("NULL Supervision module!");
95 QColor aColor = aSupMod->getIVFBackgroundColor();
96 if ( !aColor.isValid() )
97 aColor = mgr->colorValue( "SUPERVGraph", "Background", DEF_MAIN_COLOR );
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);
106 SUPERVGUI_CanvasArray::~SUPERVGUI_CanvasArray() {
107 Trace("SUPERVGUI_Array::~SUPERVGUI_CanvasArray");
108 //delete all cells which SUPERVGUI_CanvasArray contains
110 QObjectList* aCellList = queryList("SUPERVGUI_CanvasCellNode");
111 QObjectListIt aIt(*aCellList);
113 while ((anObj = aIt.current()) != 0) {
120 void SUPERVGUI_CanvasArray::sync() {
121 if (SUPERV_isNull(myMain->getDataflow())) return;
123 SUPERVGUI_CanvasCellNode* ihmNode;
124 QObjectList* ihmList = queryList("SUPERVGUI_CanvasCellNode");
125 QObjectListIt it(*ihmList);
126 while ((ihmNode=(SUPERVGUI_CanvasCellNode*)it.current()) != 0) {
133 bool SUPERVGUI_CanvasArray::create() {
134 Trace("SUPERVGUI_Array::create");
135 SUPERV_Nodes nodes = myMain->getDataflow()->Nodes();
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;
145 SUPERVGUI_CanvasCellNode* cell;
149 int nligs = myMain->getDataflow()->LevelMax();
150 int ncols = myMain->getDataflow()->ThreadsMax();
152 // there is no any calculations
153 if (ncols == 0) return false;
155 QPen pen(Qt::SolidLine);
158 QBrush br( myMgr->colorValue( "SUPERVGraph", "Title", DEF_MAIN_TITLE ) );
160 // variables to resize canvas in table view
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);
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);
180 aMaxWidth = aRect.x() + aRect.width() + 50;
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;
194 if (nodes->FNodes.length() != 0 ) {
195 ADDNODES(FNodes,LevelHasDiffNT);
196 if (aSumNum > nodes->FNodes.length())
197 LevelHasDiffNT = true;
199 if (nodes->INodes.length() != 0 ) {
200 ADDNODES(INodes,LevelHasDiffNT);
201 if (aSumNum > nodes->INodes.length())
202 LevelHasDiffNT = true;
204 if (nodes->GNodes.length() != 0 ) {
205 ADDNODES(GNodes,LevelHasDiffNT);
206 if (aSumNum > nodes->GNodes.length())
207 LevelHasDiffNT = true;
209 if (nodes->LNodes.length() != 0 ) {
210 ADDCONTROLNODES(LNodes,LevelHasDiffNT);
211 if (aSumNum > nodes->LNodes.length())
212 LevelHasDiffNT = true;
214 if (nodes->SNodes.length() != 0 ) {
215 ADDCONTROLNODES(SNodes,LevelHasDiffNT);
216 if (aSumNum > nodes->SNodes.length())
217 LevelHasDiffNT = true;
219 y += (CELL_HEIGHT + CELL_SPACE);
221 LevelHasDiffNT = false;
224 nodeY = y + CELL_HEIGHT*2;
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() );
237 void SUPERVGUI_CanvasArray::destroy() {
238 Trace("SUPERVGUI_Array::destroy");
240 QObjectList* aCellList = queryList("SUPERVGUI_CanvasCellNode");
241 QObjectListIt aIt(*aCellList);
243 while ((anObj = aIt.current()) != 0) {
245 ((SUPERVGUI_CanvasCellNode*)anObj)->getPrs()->hide();
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);
261 SUPERVGUI_CanvasCellNode* SUPERVGUI_CanvasArray::getCellNode(SUPERV::CNode_ptr theNode) const
263 return (SUPERVGUI_CanvasCellNode*)
264 ((SUPERVGUI_CanvasArray*)this)->child(theNode->Name(), "SUPERVGUI_CanvasCellNode");
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);