]> SALOME platform Git repositories - modules/superv.git/blob - src/SUPERVGUI/SUPERVGUI_Array.cxx
Salome HOME
SALOME PAL V1_4_1
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_Array.cxx
1 //  SUPERV SUPERVGUI : GUI for Supervisor component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SUPERVGUI_Array.cxx
25 //  Author : Francis KLOSS
26 //  Module : SUPERV
27
28 using namespace std;
29 #include "SUPERVGUI_Def.h"
30 #include "SUPERVGUI_Array.h"
31 #include "SUPERVGUI_Main.h"
32 #include "SUPERVGUI_ComputeNode.h"
33 #include "SUPERVGUI_BrowseNodeDlg.h"
34 #include "SUPERVGUI_Node.h"
35 #include "SUPERVGUI_GraphNode.h"
36 #include "SUPERVGUI_ControlNode.h"
37 #include <qtooltip.h>
38 #include <qlayout.h>
39
40 #define ADDNODES(NodesName) \
41     ncols = nodes->NodesName.length(); \
42     for (int co=0; co<ncols; co++) {  \
43       SUPERV_CNode aCNode = SUPERV::CNode::_narrow(nodes->NodesName[co]); \
44       x = 50 + co * (CELL_WIDTH  + CELL_SPACE);\
45       SUPERVGUI_Node* aNode = new SUPERVGUI_Cell(viewport(), main, aCNode); \
46       ResizeGraph(aNode, x, y); \
47       addChild(aNode, x, y);  \
48     }
49
50
51
52 #define ADDCONTROLNODES(NodesName) \
53     ncols = nodes->NodesName.length(); \
54     x = 50; \
55     for (int co=0; co<ncols; co++) {  \
56       SUPERV_CNode aCNode = SUPERV::CNode::_narrow(nodes->NodesName[co]); \
57       SUPERVGUI_Node* aNode = new SUPERVGUI_Cell(viewport(), main, aCNode); \
58       ResizeGraph(aNode, x, y); \
59       addChild(aNode, x, y);  \
60       x += (CELL_WIDTH + CELL_SPACE); \
61       SUPERV_CNode aCNodeEnd = SUPERV::CNode::_narrow(nodes->NodesName[co]->Coupled()); \
62       SUPERVGUI_Node* aNodeEnd = new SUPERVGUI_CellEndControl(viewport(), main, aCNodeEnd, dynamic_cast<SUPERVGUI_Cell*>(aNode)); \
63       ResizeGraph(aNodeEnd, x, y); \
64       addChild(aNodeEnd, x, y);  \
65       x += (CELL_WIDTH + CELL_SPACE); \
66      }
67
68
69
70
71 SUPERVGUI_Array::SUPERVGUI_Array(SUPERVGUI_Main* m):
72     SUPERVGUI_View(m)
73 {
74   resizeContents(GRAPH_WIDTH, GRAPH_HEIGHT);
75   setName("TableView");
76   hide();
77 }
78
79 SUPERVGUI_Array::~SUPERVGUI_Array() {
80     Trace("SUPERVGUI_Array::~SUPERVGUI_Array")
81 }
82
83 bool SUPERVGUI_Array::create() {
84   Trace("SUPERVGUI_Array::create");
85   SUPERV_Nodes nodes = main->getDataflow()->Nodes();
86   int aCount = 0;
87   aCount += nodes->CNodes.length();
88   aCount += nodes->FNodes.length();
89   aCount += nodes->INodes.length();
90   aCount += nodes->GNodes.length();
91   aCount += nodes->LNodes.length();
92   aCount += nodes->SNodes.length();
93   if (aCount == 0) {
94     show();
95     return true;
96   }
97
98   //SUPERV_Nodes    nodes;
99   SUPERVGUI_Cell* cell;
100   QString         aLabel;
101   int             x, y;
102   int             nligs = main->getDataflow()->LevelMax();
103   int             ncols = main->getDataflow()->ThreadsMax();
104   
105   // there is no any calculations
106   if (ncols == 0) return false;
107   
108   for (int co=0; co<ncols; co++) {
109     aLabel = QString("Thread %1").arg(co);
110     QLabel* aTitle = new QLabel(aLabel, viewport());
111     aTitle->setAlignment(QLabel::AlignCenter | QLabel::AlignVCenter);
112     aTitle->setLineWidth(1);
113     aTitle->setPaletteBackgroundColor(MAIN_TITLE);
114     aTitle->setMinimumSize(CELL_WIDTH, CELL_HEIGHT);
115     aTitle->setFrameStyle(QFrame::Panel | QFrame::Plain);
116     addChild(aTitle, 50 + co * (CELL_WIDTH  + CELL_SPACE), 20);
117   }
118   for (int li=0; li<=nligs; li++) {
119     nodes = main->getDataflow()->LevelNodes(li);
120     y = 60 + li * (CELL_HEIGHT + CELL_SPACE);
121     ADDNODES(CNodes);
122     ADDNODES(FNodes);
123     ADDNODES(INodes);
124     ADDNODES(GNodes);
125     ADDCONTROLNODES(LNodes);
126     ADDCONTROLNODES(SNodes);
127   }
128   nodeX = 50;
129   nodeY = y + CELL_HEIGHT*2;
130   
131   show();
132   return true;
133 }
134
135 void SUPERVGUI_Array::destroy() {
136     Trace("SUPERVGUI_Array::destroy")
137     hide();
138
139     SUPERVGUI_Cell* cell;
140     QObjectList* ihmList = queryList("SUPERVGUI_Cell");
141     QObjectListIt i(*ihmList);
142
143     while ((cell=(SUPERVGUI_Cell*)i.current()) != 0) {
144         ++i;
145         cell->updateStudy();
146         cell->close(true);
147     };
148
149     delete ihmList;
150
151     SUPERVGUI_CellEndControl* cellEC;
152     QObjectList* ihmListEC = queryList("SUPERVGUI_CellEndControl");
153     QObjectListIt iEC(*ihmListEC);
154
155     while ((cellEC=(SUPERVGUI_CellEndControl*)iEC.current()) != 0) {
156         ++iEC;
157         cellEC->updateStudy();
158         cellEC->close(true);
159     };
160
161     delete ihmListEC;
162
163 }
164
165 void SUPERVGUI_Array::sync() {
166     Trace("SUPERVGUI_Array::sync")
167     if (SUPERV_isNull(main->getDataflow())) return;
168
169     SUPERVGUI_Cell* cell;
170     QObjectList* ihmList = queryList("SUPERVGUI_Cell");
171     QObjectListIt i(*ihmList);
172     while ((cell=(SUPERVGUI_Cell*)i.current()) != 0) {
173       ++i;
174       cell->sync();
175     }
176     delete ihmList;
177 }
178
179 SUPERVGUI_Node* SUPERVGUI_Array::addNode(SUPERV_CNode node) {
180     Trace("SUPERVGUI_Array::Array")
181     SUPERVGUI_Node* n = new SUPERVGUI_ComputeNode(viewport(), main, node);
182     ResizeGraph(n, nodeX, nodeY);
183     addChild(n, nodeX, nodeY);
184     nodeX += NODE_DX;
185     nodeY += NODE_DY;
186     n->sync();
187     return(n);
188 }
189
190 void SUPERVGUI_Array::contentsMousePressEvent(QMouseEvent* e) {
191     Trace("SUPERVGUI_Array::contentsMousePressEvent")
192     if (e->button() == RightButton) {
193         myPopup->exec(e->globalPos());
194     };
195 }
196
197
198
199
200
201 // ------------------------------------
202 // Cell widget of the table
203 // ------------------------------------
204
205
206 SUPERVGUI_Cell::SUPERVGUI_Cell(QWidget* parent, SUPERVGUI_Main* m, SUPERV_CNode n):
207     SUPERVGUI_Node(parent, m, n),
208     guiNode(NULL)
209 {
210   Trace("SUPERVGUI_Cell::SUPERVGUI_Cell");
211   setLineWidth(2);
212   setFrameStyle(QFrame::Panel | QFrame::Raised);
213   
214   QHBoxLayout* aBox = new QHBoxLayout(this);
215   aBox->setMargin(3);
216   aBox->setSpacing(3);
217
218   QString aCommentVis;
219   if (getNodeType() == SUPERV::FactoryNode)
220     aCommentVis = QString(myNode->Service()->ServiceName) + QString(tr("COMMENT_FROM"))
221       + QString(getFactoryNode()->GetComponentName());
222   else 
223     //aCommentVis = tr("COMMENT_PYTHON");
224     aCommentVis = tr("COMMENT_CNODE");
225
226   component = new SUPERVGUI_Label(this, CELL_WIDTH_PART, LABEL_HEIGHT, aCommentVis, QLabel::AlignLeft);
227   connect(component, SIGNAL(MousePress(QMouseEvent*)), this, SLOT(showPopup(QMouseEvent*)));
228
229   myTitle = new SUPERVGUI_Label(this, CELL_WIDTH_PART, LABEL_HEIGHT, name(), QLabel::AlignLeft);
230   connect(myTitle, SIGNAL(MousePress(QMouseEvent*)), this, SLOT(showPopup(QMouseEvent*)));
231   myTitle->setMinimumSize(CELL_WIDTH_PART, LABEL_HEIGHT);
232   myTitle->setMaximumSize(CELL_WIDTH_PART, LABEL_HEIGHT);
233
234   //  aBox->addWidget(service);
235   aBox->addWidget(myTitle);
236   aBox->addWidget(component);
237
238   myStatus->reparent(this, pos());
239   aBox->addWidget(myStatus);
240
241   if(m->isEditable()) {
242     //  QToolTip::add(service, myNode->Name());
243     QToolTip::add(myTitle, myTitle->text());
244     QToolTip::add(component, component->text());
245   }
246
247   myPopup->setItemEnabled(myDeleteItem, false);
248   adjustSize();
249
250   myIsControl = false;
251   myIsStart = false;
252
253   //check for control nodes
254   if (n->IsLoop() || n->IsSwitch()) {
255     myIsControl = true;  
256     myIsStart = true;
257   }
258   if (n->IsEndLoop() || n->IsEndSwitch())
259     myIsControl = true;
260 }
261
262 SUPERVGUI_Cell::~SUPERVGUI_Cell() {
263   Trace("SUPERVGUI_Cell::~SUPERVGUI_Cell");
264   QToolTip::remove(myTitle);
265   if (guiNode != NULL) {
266     guiNode->close();
267   }
268 }
269
270 void SUPERVGUI_Cell::sync() {
271   Trace("SUPERVGUI_Cell::sync");
272   if (myMain == NULL) return;
273   myTitle->setText(myNode->Name());
274   //component->setText(myNode->Comment());
275   
276   if (guiNode != NULL) {
277     guiNode->sync();
278     
279     SUPERVGUI_PortIn* pi;
280     QObjectList* ihmList = guiNode->queryList("SUPERVGUI_PortIn");
281     QObjectListIt i(*ihmList);
282     while ((pi=(SUPERVGUI_PortIn*)i.current()) != 0) {
283       ++i;
284       pi->sync();
285     }
286     delete ihmList;
287     
288     SUPERVGUI_PortOut* po;
289     ihmList = guiNode->queryList("SUPERVGUI_PortOut");
290     i = *ihmList;
291     while ((po=(SUPERVGUI_PortOut*)i.current()) != 0) {
292       ++i;
293       po->sync();
294     }
295     delete ihmList;
296   }
297   SUPERVGUI_Node::sync();
298 }
299
300
301 void SUPERVGUI_Cell::updateStudy()
302 {
303   Trace("SUPERVGUI_Cell::updateStudy")
304   if (guiNode != NULL)
305     {
306       SUPERVGUI_PortOut* po;
307       QObjectList* ihmList = guiNode->queryList("SUPERVGUI_PortOut");
308       QObjectListIt i(*ihmList);
309       while ((po=(SUPERVGUI_PortOut*)i.current()) != 0)
310         {
311           ++i;
312           po->updateStudy();
313         }
314       delete ihmList;
315     }
316 }
317
318
319 void SUPERVGUI_Cell::rename() {
320   SUPERVGUI_Node::rename();
321   if (!myIsControl) { //not ControlNode
322     myTitle->setText(myNode->Name());  
323   }
324   else {
325     if (myIsStart) { //StartControlNode
326       if (myPairCell) {
327         QString nm = myNode->Name();
328         if (!nm.isEmpty()) {
329           myTitle->setText(nm);  
330           QString aStr(tr("ENDNODE_PREFIX"));
331           aStr += nm;
332           myPairCell->getTitle()->setText(aStr);
333           myPairCell->setNodeName(aStr);
334           // QToolTip::remove(myPairCell->getTitle());
335           QToolTip::add(myPairCell->getTitle(), myPairCell->getTitle()->text());  
336
337         }
338       }
339     }
340   }
341
342   // QToolTip::remove(myTitle);
343   QToolTip::add(myTitle, myTitle->text());  
344 }
345
346 void SUPERVGUI_Cell::setPairCell(SUPERVGUI_Cell* thePairCell) {
347   if (myIsControl) { //only for ControlNode
348     myPairCell = thePairCell;
349   }
350   else 
351     myPairCell = 0;
352 }
353
354 SUPERVGUI_Cell* SUPERVGUI_Cell::getPairCell() {
355   return myPairCell;
356 }
357
358 SUPERVGUI_CellEndControl::SUPERVGUI_CellEndControl(QWidget* parent, SUPERVGUI_Main* m, SUPERV_CNode n,
359                                                    SUPERVGUI_Cell* theStart)
360      :SUPERVGUI_Cell(parent, m, n)
361 {
362   myPairCell = theStart;  //set start cell for end cell as pair 
363   myPairCell->setPairCell(dynamic_cast<SUPERVGUI_Cell*>(this));  //set end cell for start cell as pair
364 }
365
366 SUPERVGUI_CellEndControl::~SUPERVGUI_CellEndControl() {
367   Trace("SUPERVGUI_CellEndControl::~SUPERVGUI_CellEndControl");
368   QToolTip::remove(myTitle);
369   if (guiNode != NULL) {
370     guiNode->close();
371   }
372 }