1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SUPERV SUPERVGUI : GUI for Supervisor component
23 // File : SUPERVGUI_CanvasArray.cxx
27 #include "SUPERVGUI.h"
28 #include "SUPERVGUI_CanvasArray.h"
29 #include "SUPERVGUI_Main.h"
30 #include "SUPERVGUI_BrowseNodeDlg.h"
31 #include "SUPERVGUI_CanvasCellNodePrs.h"
33 #include "SUIT_ResourceMgr.h"
34 #include "SUIT_Session.h"
39 #include <iostream.h> //for debug only
41 #define ADDNODES(NodesName,LevelHasDiffNT) \
42 ncols = nodes->NodesName.length(); \
43 for (int co=0; co<ncols; co++) { \
44 SUPERV_CNode aCNode = SUPERV::CNode::_narrow(nodes->NodesName[co]); \
45 if (!LevelHasDiffNT) x = 50 + co * (CELL_WIDTH + CELL_SPACE); \
46 else x += (CELL_WIDTH + CELL_SPACE); \
47 cell = getCellNode(aCNode); \
49 SUPERVGUI_CanvasCellNode* aNode = SUPERVGUI_CanvasCellNode::Create(myMgr, this, myMain, aCNode); \
62 #define ADDCONTROLNODES(NodesName,LevelHasDiffNT) \
63 ncols = nodes->NodesName.length(); \
64 if (!LevelHasDiffNT) x = 50; \
65 else x += (CELL_WIDTH + CELL_SPACE); \
66 for (int co=0; co<ncols; co++) { \
67 SUPERV_CNode aCNode = SUPERV::CNode::_narrow(nodes->NodesName[co]); \
68 SUPERV_CNode aCNodeEnd = SUPERV::CNode::_narrow(nodes->NodesName[co]->Coupled()); \
69 cell = getCellNode(aCNode); \
71 SUPERVGUI_CanvasCellNode* aNode = SUPERVGUI_CanvasCellNode::Create(myMgr, this, myMain, aCNode); \
75 y += (CELL_HEIGHT + CELL_SPACE); \
76 SUPERVGUI_CanvasCellNode* aNodeEnd = SUPERVGUI_CanvasCellEndNode::Create(myMgr, this, myMain, aCNodeEnd, aNode); \
77 aNodeEnd->move(x, y); \
83 y += (CELL_HEIGHT + CELL_SPACE); \
84 cell = getCellNode(aCNodeEnd); \
89 if (co < (ncols-1)) x += (CELL_WIDTH + CELL_SPACE); \
93 // ----------------------------------------------------------
94 // SUPERVGUI_Array on QCanvas
95 // ----------------------------------------------------------
97 SUPERVGUI_CanvasArray::SUPERVGUI_CanvasArray(SUPERVGUI_Main* m, SUIT_ResourceMgr* mgr ):
102 Trace("SUPERVGUI_CanvasArray::SUPERVGUI_CanvasArray");
103 //resize(GRAPH_WIDTH, GRAPH_HEIGHT);
105 setDoubleBuffering(true);
107 // mkr : IPAL10825 -->
108 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
110 MESSAGE("NULL Supervision module!");
113 QColor aColor = aSupMod->getIVFBackgroundColor();
114 if ( !aColor.isValid() )
115 aColor = mgr->colorValue( "SUPERVGraph", "Background", DEF_MAIN_COLOR );
118 //aColor = QColor(SUIT_Session::session()->resourceMgr()->integerValue( "SUPERVGraph", "BackgroundColorRed" ),
119 // SUIT_Session::session()->resourceMgr()->integerValue( "SUPERVGraph", "BackgroundColorGreen" ),
120 // SUIT_Session::session()->resourceMgr()->integerValue( "SUPERVGraph", "BackgroundColorBlue" ) );
121 setBackgroundColor(aColor);
124 SUPERVGUI_CanvasArray::~SUPERVGUI_CanvasArray() {
125 Trace("SUPERVGUI_Array::~SUPERVGUI_CanvasArray");
126 //delete all cells which SUPERVGUI_CanvasArray contains
128 QObjectList* aCellList = queryList("SUPERVGUI_CanvasCellNode");
129 QObjectListIt aIt(*aCellList);
131 while ((anObj = aIt.current()) != 0) {
138 void SUPERVGUI_CanvasArray::sync() {
139 if (SUPERV_isNull(myMain->getDataflow())) return;
141 SUPERVGUI_CanvasCellNode* ihmNode;
142 QObjectList* ihmList = queryList("SUPERVGUI_CanvasCellNode");
143 QObjectListIt it(*ihmList);
144 while ((ihmNode=(SUPERVGUI_CanvasCellNode*)it.current()) != 0) {
151 bool SUPERVGUI_CanvasArray::create() {
152 Trace("SUPERVGUI_Array::create");
153 SUPERV_Nodes nodes = myMain->getDataflow()->Nodes();
155 aCount += nodes->CNodes.length();
156 aCount += nodes->FNodes.length();
157 aCount += nodes->INodes.length();
158 aCount += nodes->GNodes.length();
159 aCount += nodes->LNodes.length();
160 aCount += nodes->SNodes.length();
161 if (aCount == 0) return true;
163 SUPERVGUI_CanvasCellNode* cell;
167 int nligs = myMain->getDataflow()->LevelMax();
168 int ncols = myMain->getDataflow()->ThreadsMax();
170 // there is no any calculations
171 if (ncols == 0) return false;
173 QPen pen(Qt::SolidLine);
176 QBrush br( myMgr->colorValue( "SUPERVGraph", "Title", DEF_MAIN_TITLE ) );
178 // variables to resize canvas in table view
182 for (int co = 0; co < ncols; co++) {
183 aLabel = QString("Thread %1").arg(co);
184 QRect aRect = QRect(50 + co * (CELL_WIDTH + CELL_SPACE), 20, CELL_WIDTH, CELL_HEIGHT);
185 QCanvasRectangle* aThread = new QCanvasRectangle(aRect, this);
186 aThread->setPen(pen);
187 aThread->setBrush(br);
191 QCanvasText* aText = new QCanvasText(aLabel, this);
192 QRect aBRect = aText->boundingRect();
193 aText->setX(aRect.x() + aRect.width()/2 - aBRect.width()/2);
194 aText->setY(aRect.y() + aRect.height()/2 - aBRect.height()/2);
198 aMaxWidth = aRect.x() + aRect.width() + 50;
202 bool LevelHasDiffNT = false;
203 for (int li = 0; li <= nligs; li++) {
204 nodes = myMain->getDataflow()->LevelNodes(li);
205 int aSumNum = nodes->CNodes.length()+nodes->FNodes.length()+nodes->INodes.length()+
206 nodes->GNodes.length()+nodes->LNodes.length()+nodes->SNodes.length();
207 if (nodes->CNodes.length() != 0 ) {
208 ADDNODES(CNodes,LevelHasDiffNT);
209 if (aSumNum > nodes->CNodes.length())
210 LevelHasDiffNT = true;
212 if (nodes->FNodes.length() != 0 ) {
213 ADDNODES(FNodes,LevelHasDiffNT);
214 if (aSumNum > nodes->FNodes.length())
215 LevelHasDiffNT = true;
217 if (nodes->INodes.length() != 0 ) {
218 ADDNODES(INodes,LevelHasDiffNT);
219 if (aSumNum > nodes->INodes.length())
220 LevelHasDiffNT = true;
222 if (nodes->GNodes.length() != 0 ) {
223 ADDNODES(GNodes,LevelHasDiffNT);
224 if (aSumNum > nodes->GNodes.length())
225 LevelHasDiffNT = true;
227 if (nodes->LNodes.length() != 0 ) {
228 ADDCONTROLNODES(LNodes,LevelHasDiffNT);
229 if (aSumNum > nodes->LNodes.length())
230 LevelHasDiffNT = true;
232 if (nodes->SNodes.length() != 0 ) {
233 ADDCONTROLNODES(SNodes,LevelHasDiffNT);
234 if (aSumNum > nodes->SNodes.length())
235 LevelHasDiffNT = true;
237 y += (CELL_HEIGHT + CELL_SPACE);
239 LevelHasDiffNT = false;
242 nodeY = y + CELL_HEIGHT*2;
246 // if aMaxWidth and aMaxHeight is greater than the current size
247 // of the canvas, we resize canvas to these new width and height
248 if ( aMaxWidth > this->width() || aMaxHeight > this->height() )
249 this->resize( aMaxWidth > this->width() ? aMaxWidth : this->width(),
250 aMaxHeight > this->height() ? aMaxHeight : this->height() );
255 void SUPERVGUI_CanvasArray::destroy() {
256 Trace("SUPERVGUI_Array::destroy");
258 QObjectList* aCellList = queryList("SUPERVGUI_CanvasCellNode");
259 QObjectListIt aIt(*aCellList);
261 while ((anObj = aIt.current()) != 0) {
263 ((SUPERVGUI_CanvasCellNode*)anObj)->getPrs()->hide();
267 // mkr : delete QCanvasRectangle and QCanvasText canvas items for each Thread.
268 // Threads will be recreate when create() function is called
269 QCanvasItemList aTextList = allItems();
270 for (QCanvasItemList::Iterator aItText = aTextList.begin(); aItText != aTextList.end(); ++aItText) {
271 SUPERVGUI_CanvasCellNodePrs* aPrs = dynamic_cast<SUPERVGUI_CanvasCellNodePrs*>(*aItText);
279 SUPERVGUI_CanvasCellNode* SUPERVGUI_CanvasArray::getCellNode(SUPERV::CNode_ptr theNode) const
281 return (SUPERVGUI_CanvasCellNode*)
282 ((SUPERVGUI_CanvasArray*)this)->child(theNode->Name(), "SUPERVGUI_CanvasCellNode");
285 SUPERVGUI_CanvasCellNode* SUPERVGUI_CanvasArray::addNode(SUPERV_CNode node) {
286 Trace("SUPERVGUI_CanvasArray::addNode");
287 SUPERVGUI_CanvasCellNode* n = SUPERVGUI_CanvasCellNode::Create(myMgr, this, myMain, node);
288 n->move(nodeX, nodeY);