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 #define ADDNODES(NodesName,LevelHasDiffNT) \
22 ncols = nodes->NodesName.length(); \
23 for (int co=0; co<ncols; co++) { \
24 SUPERV_CNode aCNode = SUPERV::CNode::_narrow(nodes->NodesName[co]); \
25 if (!LevelHasDiffNT) x = 50 + co * (CELL_WIDTH + CELL_SPACE); \
26 else x += (CELL_WIDTH + CELL_SPACE); \
27 cell = getCellNode(aCNode); \
29 SUPERVGUI_CanvasCellNode* aNode = new SUPERVGUI_CanvasCellNode(this, myMain, aCNode); \
42 #define ADDCONTROLNODES(NodesName,LevelHasDiffNT) \
43 ncols = nodes->NodesName.length(); \
44 if (!LevelHasDiffNT) x = 50; \
45 else x += (CELL_WIDTH + CELL_SPACE); \
46 for (int co=0; co<ncols; co++) { \
47 SUPERV_CNode aCNode = SUPERV::CNode::_narrow(nodes->NodesName[co]); \
48 SUPERV_CNode aCNodeEnd = SUPERV::CNode::_narrow(nodes->NodesName[co]->Coupled()); \
49 cell = getCellNode(aCNode); \
51 SUPERVGUI_CanvasCellNode* aNode = new SUPERVGUI_CanvasCellNode(this, myMain, aCNode); \
55 y += (CELL_HEIGHT + CELL_SPACE); \
56 SUPERVGUI_CanvasCellNode* aNodeEnd = new SUPERVGUI_CanvasCellEndNode(this, myMain, aCNodeEnd, aNode); \
57 aNodeEnd->move(x, y); \
63 y += (CELL_HEIGHT + CELL_SPACE); \
64 cell = getCellNode(aCNodeEnd); \
69 if (co < (ncols-1)) x += (CELL_WIDTH + CELL_SPACE); \
73 // ----------------------------------------------------------
74 // SUPERVGUI_Array on QCanvas
75 // ----------------------------------------------------------
77 SUPERVGUI_CanvasArray::SUPERVGUI_CanvasArray(SUPERVGUI_Main* m):
81 Trace("SUPERVGUI_CanvasArray::SUPERVGUI_CanvasArray");
82 //resize(GRAPH_WIDTH, GRAPH_HEIGHT);
84 setDoubleBuffering(true);
86 QColor aColor(MAIN_COLOR);
87 //aColor = QColor(SUIT_Session::session()->resourceMgr()->integerValue( "SUPERVGraph", "BackgroundColorRed" ),
88 // SUIT_Session::session()->resourceMgr()->integerValue( "SUPERVGraph", "BackgroundColorGreen" ),
89 // SUIT_Session::session()->resourceMgr()->integerValue( "SUPERVGraph", "BackgroundColorBlue" ) );
90 setBackgroundColor(aColor);
93 SUPERVGUI_CanvasArray::~SUPERVGUI_CanvasArray() {
94 Trace("SUPERVGUI_Array::~SUPERVGUI_CanvasArray");
95 //delete all cells which SUPERVGUI_CanvasArray contains
97 QObjectList* aCellList = queryList("SUPERVGUI_CanvasCellNode");
98 QObjectListIt aIt(*aCellList);
100 while ((anObj = aIt.current()) != 0) {
107 void SUPERVGUI_CanvasArray::sync() {
108 if (SUPERV_isNull(myMain->getDataflow())) return;
110 SUPERVGUI_CanvasCellNode* ihmNode;
111 QObjectList* ihmList = queryList("SUPERVGUI_CanvasCellNode");
112 QObjectListIt it(*ihmList);
113 while ((ihmNode=(SUPERVGUI_CanvasCellNode*)it.current()) != 0) {
120 bool SUPERVGUI_CanvasArray::create() {
121 Trace("SUPERVGUI_Array::create");
122 SUPERV_Nodes nodes = myMain->getDataflow()->Nodes();
124 aCount += nodes->CNodes.length();
125 aCount += nodes->FNodes.length();
126 aCount += nodes->INodes.length();
127 aCount += nodes->GNodes.length();
128 aCount += nodes->LNodes.length();
129 aCount += nodes->SNodes.length();
130 if (aCount == 0) return true;
132 SUPERVGUI_CanvasCellNode* cell;
135 int nligs = myMain->getDataflow()->LevelMax();
136 int ncols = myMain->getDataflow()->ThreadsMax();
138 // there is no any calculations
139 if (ncols == 0) return false;
141 QPen pen(Qt::SolidLine);
143 QBrush br(MAIN_TITLE);
145 for (int co = 0; co < ncols; co++) {
146 aLabel = QString("Thread %1").arg(co);
147 QRect aRect = QRect(50 + co * (CELL_WIDTH + CELL_SPACE), 20, CELL_WIDTH, CELL_HEIGHT);
148 QCanvasRectangle* aThread = new QCanvasRectangle(aRect, this);
149 aThread->setPen(pen);
150 aThread->setBrush(br);
154 QCanvasText* aText = new QCanvasText(aLabel, this);
155 QRect aBRect = aText->boundingRect();
156 aText->setX(aRect.x() + aRect.width()/2 - aBRect.width()/2);
157 aText->setY(aRect.y() + aRect.height()/2 - aBRect.height()/2);
163 bool LevelHasDiffNT = false;
164 for (int li = 0; li <= nligs; li++) {
165 nodes = myMain->getDataflow()->LevelNodes(li);
166 int aSumNum = nodes->CNodes.length()+nodes->FNodes.length()+nodes->INodes.length()+
167 nodes->GNodes.length()+nodes->LNodes.length()+nodes->SNodes.length();
168 if (nodes->CNodes.length() != 0 ) {
169 ADDNODES(CNodes,LevelHasDiffNT);
170 if (aSumNum > nodes->CNodes.length())
171 LevelHasDiffNT = true;
173 if (nodes->FNodes.length() != 0 ) {
174 ADDNODES(FNodes,LevelHasDiffNT);
175 if (aSumNum > nodes->FNodes.length())
176 LevelHasDiffNT = true;
178 if (nodes->INodes.length() != 0 ) {
179 ADDNODES(INodes,LevelHasDiffNT);
180 if (aSumNum > nodes->INodes.length())
181 LevelHasDiffNT = true;
183 if (nodes->GNodes.length() != 0 ) {
184 ADDNODES(GNodes,LevelHasDiffNT);
185 if (aSumNum > nodes->GNodes.length())
186 LevelHasDiffNT = true;
188 if (nodes->LNodes.length() != 0 ) {
189 ADDCONTROLNODES(LNodes,LevelHasDiffNT);
190 if (aSumNum > nodes->LNodes.length())
191 LevelHasDiffNT = true;
193 if (nodes->SNodes.length() != 0 ) {
194 ADDCONTROLNODES(SNodes,LevelHasDiffNT);
195 if (aSumNum > nodes->SNodes.length())
196 LevelHasDiffNT = true;
198 y += (CELL_HEIGHT + CELL_SPACE);
200 LevelHasDiffNT = false;
203 nodeY = y + CELL_HEIGHT*2;
209 void SUPERVGUI_CanvasArray::destroy() {
210 Trace("SUPERVGUI_Array::destroy");
212 QObjectList* aCellList = queryList("SUPERVGUI_CanvasCellNode");
213 QObjectListIt aIt(*aCellList);
215 while ((anObj = aIt.current()) != 0) {
217 ((SUPERVGUI_CanvasCellNode*)anObj)->getPrs()->hide();
221 // mkr : delete QCanvasRectangle and QCanvasText canvas items for each Thread.
222 // Threads will be recreate when create() function is called
223 QCanvasItemList aTextList = allItems();
224 for (QCanvasItemList::Iterator aItText = aTextList.begin(); aItText != aTextList.end(); ++aItText) {
225 SUPERVGUI_CanvasCellNodePrs* aPrs = dynamic_cast<SUPERVGUI_CanvasCellNodePrs*>(*aItText);
233 SUPERVGUI_CanvasCellNode* SUPERVGUI_CanvasArray::getCellNode(SUPERV::CNode_ptr theNode) const
235 return (SUPERVGUI_CanvasCellNode*)
236 ((SUPERVGUI_CanvasArray*)this)->child(theNode->Name(), "SUPERVGUI_CanvasCellNode");
239 SUPERVGUI_CanvasCellNode* SUPERVGUI_CanvasArray::addNode(SUPERV_CNode node) {
240 Trace("SUPERVGUI_CanvasArray::addNode");
241 SUPERVGUI_CanvasCellNode* n = new SUPERVGUI_CanvasCellNode(this, myMain, node);
242 n->move(nodeX, nodeY);