1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // SUPERV SUPERVGUI : GUI for Supervisor component
22 // File : SUPERVGUI_CanvasArray.cxx
26 #include "SUPERVGUI.h"
27 #include "SUPERVGUI_CanvasArray.h"
28 #include "SUPERVGUI_Main.h"
29 #include "SUPERVGUI_BrowseNodeDlg.h"
30 #include "SUPERVGUI_CanvasCellNodePrs.h"
32 #include "SUIT_ResourceMgr.h"
33 #include "SUIT_Session.h"
38 #include <iostream.h> //for debug only
40 #define ADDNODES(NodesName,LevelHasDiffNT) \
41 ncols = nodes->NodesName.length(); \
42 for (int co=0; co<ncols; co++) { \
43 SUPERV_CNode aCNode = SUPERV::CNode::_narrow(nodes->NodesName[co]); \
44 if (!LevelHasDiffNT) x = 50 + co * (CELL_WIDTH + CELL_SPACE); \
45 else x += (CELL_WIDTH + CELL_SPACE); \
46 cell = getCellNode(aCNode); \
48 SUPERVGUI_CanvasCellNode* aNode = SUPERVGUI_CanvasCellNode::Create(myMgr, this, myMain, aCNode); \
61 #define ADDCONTROLNODES(NodesName,LevelHasDiffNT) \
62 ncols = nodes->NodesName.length(); \
63 if (!LevelHasDiffNT) x = 50; \
64 else x += (CELL_WIDTH + CELL_SPACE); \
65 for (int co=0; co<ncols; co++) { \
66 SUPERV_CNode aCNode = SUPERV::CNode::_narrow(nodes->NodesName[co]); \
67 SUPERV_CNode aCNodeEnd = SUPERV::CNode::_narrow(nodes->NodesName[co]->Coupled()); \
68 cell = getCellNode(aCNode); \
70 SUPERVGUI_CanvasCellNode* aNode = SUPERVGUI_CanvasCellNode::Create(myMgr, this, myMain, aCNode); \
74 y += (CELL_HEIGHT + CELL_SPACE); \
75 SUPERVGUI_CanvasCellNode* aNodeEnd = SUPERVGUI_CanvasCellEndNode::Create(myMgr, this, myMain, aCNodeEnd, aNode); \
76 aNodeEnd->move(x, y); \
82 y += (CELL_HEIGHT + CELL_SPACE); \
83 cell = getCellNode(aCNodeEnd); \
88 if (co < (ncols-1)) x += (CELL_WIDTH + CELL_SPACE); \
92 // ----------------------------------------------------------
93 // SUPERVGUI_Array on QCanvas
94 // ----------------------------------------------------------
96 SUPERVGUI_CanvasArray::SUPERVGUI_CanvasArray(SUPERVGUI_Main* m, SUIT_ResourceMgr* mgr ):
101 Trace("SUPERVGUI_CanvasArray::SUPERVGUI_CanvasArray");
102 //resize(GRAPH_WIDTH, GRAPH_HEIGHT);
104 setDoubleBuffering(true);
106 // mkr : IPAL10825 -->
107 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
109 MESSAGE("NULL Supervision module!");
112 QColor aColor = aSupMod->getIVFBackgroundColor();
113 if ( !aColor.isValid() )
114 aColor = mgr->colorValue( "SUPERVGraph", "Background", DEF_MAIN_COLOR );
117 //aColor = QColor(SUIT_Session::session()->resourceMgr()->integerValue( "SUPERVGraph", "BackgroundColorRed" ),
118 // SUIT_Session::session()->resourceMgr()->integerValue( "SUPERVGraph", "BackgroundColorGreen" ),
119 // SUIT_Session::session()->resourceMgr()->integerValue( "SUPERVGraph", "BackgroundColorBlue" ) );
120 setBackgroundColor(aColor);
123 SUPERVGUI_CanvasArray::~SUPERVGUI_CanvasArray() {
124 Trace("SUPERVGUI_Array::~SUPERVGUI_CanvasArray");
125 //delete all cells which SUPERVGUI_CanvasArray contains
127 QObjectList* aCellList = queryList("SUPERVGUI_CanvasCellNode");
128 QObjectListIt aIt(*aCellList);
130 while ((anObj = aIt.current()) != 0) {
137 void SUPERVGUI_CanvasArray::sync() {
138 if (SUPERV_isNull(myMain->getDataflow())) return;
140 SUPERVGUI_CanvasCellNode* ihmNode;
141 QObjectList* ihmList = queryList("SUPERVGUI_CanvasCellNode");
142 QObjectListIt it(*ihmList);
143 while ((ihmNode=(SUPERVGUI_CanvasCellNode*)it.current()) != 0) {
150 bool SUPERVGUI_CanvasArray::create() {
151 Trace("SUPERVGUI_Array::create");
152 SUPERV_Nodes nodes = myMain->getDataflow()->Nodes();
154 aCount += nodes->CNodes.length();
155 aCount += nodes->FNodes.length();
156 aCount += nodes->INodes.length();
157 aCount += nodes->GNodes.length();
158 aCount += nodes->LNodes.length();
159 aCount += nodes->SNodes.length();
160 if (aCount == 0) return true;
162 SUPERVGUI_CanvasCellNode* cell;
166 int nligs = myMain->getDataflow()->LevelMax();
167 int ncols = myMain->getDataflow()->ThreadsMax();
169 // there is no any calculations
170 if (ncols == 0) return false;
172 QPen pen(Qt::SolidLine);
175 QBrush br( myMgr->colorValue( "SUPERVGraph", "Title", DEF_MAIN_TITLE ) );
177 // variables to resize canvas in table view
181 for (int co = 0; co < ncols; co++) {
182 aLabel = QString("Thread %1").arg(co);
183 QRect aRect = QRect(50 + co * (CELL_WIDTH + CELL_SPACE), 20, CELL_WIDTH, CELL_HEIGHT);
184 QCanvasRectangle* aThread = new QCanvasRectangle(aRect, this);
185 aThread->setPen(pen);
186 aThread->setBrush(br);
190 QCanvasText* aText = new QCanvasText(aLabel, this);
191 QRect aBRect = aText->boundingRect();
192 aText->setX(aRect.x() + aRect.width()/2 - aBRect.width()/2);
193 aText->setY(aRect.y() + aRect.height()/2 - aBRect.height()/2);
197 aMaxWidth = aRect.x() + aRect.width() + 50;
201 bool LevelHasDiffNT = false;
202 for (int li = 0; li <= nligs; li++) {
203 nodes = myMain->getDataflow()->LevelNodes(li);
204 int aSumNum = nodes->CNodes.length()+nodes->FNodes.length()+nodes->INodes.length()+
205 nodes->GNodes.length()+nodes->LNodes.length()+nodes->SNodes.length();
206 if (nodes->CNodes.length() != 0 ) {
207 ADDNODES(CNodes,LevelHasDiffNT);
208 if (aSumNum > nodes->CNodes.length())
209 LevelHasDiffNT = true;
211 if (nodes->FNodes.length() != 0 ) {
212 ADDNODES(FNodes,LevelHasDiffNT);
213 if (aSumNum > nodes->FNodes.length())
214 LevelHasDiffNT = true;
216 if (nodes->INodes.length() != 0 ) {
217 ADDNODES(INodes,LevelHasDiffNT);
218 if (aSumNum > nodes->INodes.length())
219 LevelHasDiffNT = true;
221 if (nodes->GNodes.length() != 0 ) {
222 ADDNODES(GNodes,LevelHasDiffNT);
223 if (aSumNum > nodes->GNodes.length())
224 LevelHasDiffNT = true;
226 if (nodes->LNodes.length() != 0 ) {
227 ADDCONTROLNODES(LNodes,LevelHasDiffNT);
228 if (aSumNum > nodes->LNodes.length())
229 LevelHasDiffNT = true;
231 if (nodes->SNodes.length() != 0 ) {
232 ADDCONTROLNODES(SNodes,LevelHasDiffNT);
233 if (aSumNum > nodes->SNodes.length())
234 LevelHasDiffNT = true;
236 y += (CELL_HEIGHT + CELL_SPACE);
238 LevelHasDiffNT = false;
241 nodeY = y + CELL_HEIGHT*2;
245 // if aMaxWidth and aMaxHeight is greater than the current size
246 // of the canvas, we resize canvas to these new width and height
247 if ( aMaxWidth > this->width() || aMaxHeight > this->height() )
248 this->resize( aMaxWidth > this->width() ? aMaxWidth : this->width(),
249 aMaxHeight > this->height() ? aMaxHeight : this->height() );
254 void SUPERVGUI_CanvasArray::destroy() {
255 Trace("SUPERVGUI_Array::destroy");
257 QObjectList* aCellList = queryList("SUPERVGUI_CanvasCellNode");
258 QObjectListIt aIt(*aCellList);
260 while ((anObj = aIt.current()) != 0) {
262 ((SUPERVGUI_CanvasCellNode*)anObj)->getPrs()->hide();
266 // mkr : delete QCanvasRectangle and QCanvasText canvas items for each Thread.
267 // Threads will be recreate when create() function is called
268 QCanvasItemList aTextList = allItems();
269 for (QCanvasItemList::Iterator aItText = aTextList.begin(); aItText != aTextList.end(); ++aItText) {
270 SUPERVGUI_CanvasCellNodePrs* aPrs = dynamic_cast<SUPERVGUI_CanvasCellNodePrs*>(*aItText);
278 SUPERVGUI_CanvasCellNode* SUPERVGUI_CanvasArray::getCellNode(SUPERV::CNode_ptr theNode) const
280 return (SUPERVGUI_CanvasCellNode*)
281 ((SUPERVGUI_CanvasArray*)this)->child(theNode->Name(), "SUPERVGUI_CanvasCellNode");
284 SUPERVGUI_CanvasCellNode* SUPERVGUI_CanvasArray::addNode(SUPERV_CNode node) {
285 Trace("SUPERVGUI_CanvasArray::addNode");
286 SUPERVGUI_CanvasCellNode* n = SUPERVGUI_CanvasCellNode::Create(myMgr, this, myMain, node);
287 n->move(nodeX, nodeY);