1 // SUPERV SUPERVGUI : GUI for Supervisor component
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SUPERVGUI_Array.cxx
25 // Author : Francis KLOSS
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"
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 SUPERVGUI_Node* aNode = new SUPERVGUI_Cell(viewport(), main, aCNode); \
47 ResizeGraph(aNode, x, y); \
48 addChild(aNode, x, y); \
53 #define ADDCONTROLNODES(NodesName,LevelHasDiffNT) \
54 ncols = nodes->NodesName.length(); \
55 if (!LevelHasDiffNT) x = 50; \
56 else x += (CELL_WIDTH + CELL_SPACE); \
57 for (int co=0; co<ncols; co++) { \
58 SUPERV_CNode aCNode = SUPERV::CNode::_narrow(nodes->NodesName[co]); \
59 SUPERVGUI_Node* aNode = new SUPERVGUI_Cell(viewport(), main, aCNode); \
60 ResizeGraph(aNode, x, y); \
61 addChild(aNode, x, y); \
62 y += (CELL_HEIGHT + CELL_SPACE); \
63 SUPERV_CNode aCNodeEnd = SUPERV::CNode::_narrow(nodes->NodesName[co]->Coupled()); \
64 SUPERVGUI_Node* aNodeEnd = new SUPERVGUI_CellEndControl(viewport(), main, aCNodeEnd, dynamic_cast<SUPERVGUI_Cell*>(aNode)); \
65 ResizeGraph(aNodeEnd, x, y); \
66 addChild(aNodeEnd, x, y); \
67 x += (CELL_WIDTH + CELL_SPACE); \
73 SUPERVGUI_Array::SUPERVGUI_Array(SUPERVGUI_Main* m):
76 resizeContents(GRAPH_WIDTH, GRAPH_HEIGHT);
81 SUPERVGUI_Array::~SUPERVGUI_Array() {
82 Trace("SUPERVGUI_Array::~SUPERVGUI_Array")
85 bool SUPERVGUI_Array::create() {
86 Trace("SUPERVGUI_Array::create");
87 SUPERV_Nodes nodes = main->getDataflow()->Nodes();
89 aCount += nodes->CNodes.length();
90 aCount += nodes->FNodes.length();
91 aCount += nodes->INodes.length();
92 aCount += nodes->GNodes.length();
93 aCount += nodes->LNodes.length();
94 aCount += nodes->SNodes.length();
100 //SUPERV_Nodes nodes;
101 SUPERVGUI_Cell* cell;
104 int nligs = main->getDataflow()->LevelMax();
105 int ncols = main->getDataflow()->ThreadsMax();
107 // there is no any calculations
108 if (ncols == 0) return false;
110 for (int co=0; co<ncols; co++) {
111 aLabel = QString("Thread %1").arg(co);
112 QLabel* aTitle = new QLabel(aLabel, viewport());
113 aTitle->setAlignment(QLabel::AlignCenter | QLabel::AlignVCenter);
114 aTitle->setLineWidth(1);
115 aTitle->setPaletteBackgroundColor(MAIN_TITLE);
116 aTitle->setMinimumSize(CELL_WIDTH, CELL_HEIGHT);
117 aTitle->setFrameStyle(QFrame::Panel | QFrame::Plain);
118 addChild(aTitle, 50 + co * (CELL_WIDTH + CELL_SPACE), 20);
121 bool LevelHasDiffNT = false;
122 for (int li=0; li<=nligs; li++) {
123 nodes = main->getDataflow()->LevelNodes(li);
124 int aSumNum = nodes->CNodes.length()+nodes->FNodes.length()+nodes->INodes.length()+
125 nodes->GNodes.length()+nodes->LNodes.length()+nodes->SNodes.length();
126 if (nodes->CNodes.length() != 0 ) {
127 ADDNODES(CNodes,LevelHasDiffNT);
128 if (aSumNum > nodes->CNodes.length())
129 LevelHasDiffNT = true;
131 if (nodes->FNodes.length() != 0 ) {
132 ADDNODES(FNodes,LevelHasDiffNT);
133 if (aSumNum > nodes->FNodes.length())
134 LevelHasDiffNT = true;
136 if (nodes->INodes.length() != 0 ) {
137 ADDNODES(INodes,LevelHasDiffNT);
138 if (aSumNum > nodes->INodes.length())
139 LevelHasDiffNT = true;
141 if (nodes->GNodes.length() != 0 ) {
142 ADDNODES(GNodes,LevelHasDiffNT);
143 if (aSumNum > nodes->GNodes.length())
144 LevelHasDiffNT = true;
146 if (nodes->LNodes.length() != 0 ) {
147 ADDCONTROLNODES(LNodes,LevelHasDiffNT);
148 if (aSumNum > nodes->LNodes.length())
149 LevelHasDiffNT = true;
151 if (nodes->SNodes.length() != 0 ) {
152 ADDCONTROLNODES(SNodes,LevelHasDiffNT);
153 if (aSumNum > nodes->SNodes.length())
154 LevelHasDiffNT = true;
156 y += (CELL_HEIGHT + CELL_SPACE);
158 LevelHasDiffNT = false;
161 nodeY = y + CELL_HEIGHT*2;
167 void SUPERVGUI_Array::destroy() {
168 Trace("SUPERVGUI_Array::destroy")
171 SUPERVGUI_Cell* cell;
172 QObjectList* ihmList = queryList("SUPERVGUI_Cell");
173 QObjectListIt i(*ihmList);
175 while ((cell=(SUPERVGUI_Cell*)i.current()) != 0) {
183 SUPERVGUI_CellEndControl* cellEC;
184 QObjectList* ihmListEC = queryList("SUPERVGUI_CellEndControl");
185 QObjectListIt iEC(*ihmListEC);
187 while ((cellEC=(SUPERVGUI_CellEndControl*)iEC.current()) != 0) {
189 cellEC->updateStudy();
197 void SUPERVGUI_Array::sync() {
198 Trace("SUPERVGUI_Array::sync")
199 if (SUPERV_isNull(main->getDataflow())) return;
201 SUPERVGUI_Cell* cell;
202 QObjectList* ihmList = queryList("SUPERVGUI_Cell");
203 QObjectListIt i(*ihmList);
204 while ((cell=(SUPERVGUI_Cell*)i.current()) != 0) {
211 SUPERVGUI_Node* SUPERVGUI_Array::addNode(SUPERV_CNode node) {
212 Trace("SUPERVGUI_Array::Array")
213 SUPERVGUI_Node* n = new SUPERVGUI_ComputeNode(viewport(), main, node);
214 ResizeGraph(n, nodeX, nodeY);
215 addChild(n, nodeX, nodeY);
222 void SUPERVGUI_Array::contentsMousePressEvent(QMouseEvent* e) {
223 Trace("SUPERVGUI_Array::contentsMousePressEvent")
224 if (e->button() == RightButton) {
225 myPopup->exec(e->globalPos());
233 // ------------------------------------
234 // Cell widget of the table
235 // ------------------------------------
238 SUPERVGUI_Cell::SUPERVGUI_Cell(QWidget* parent, SUPERVGUI_Main* m, SUPERV_CNode n):
239 SUPERVGUI_Node(parent, m, n),
242 Trace("SUPERVGUI_Cell::SUPERVGUI_Cell");
244 setFrameStyle(QFrame::Panel | QFrame::Raised);
246 QHBoxLayout* aBox = new QHBoxLayout(this);
251 if (getNodeType() == SUPERV::FactoryNode)
252 aCommentVis = QString(myNode->Service()->ServiceName) + QString(tr("COMMENT_FROM"))
253 + QString(getFactoryNode()->GetComponentName());
255 //aCommentVis = tr("COMMENT_PYTHON");
256 aCommentVis = tr("COMMENT_CNODE");
258 component = new SUPERVGUI_Label(this, CELL_WIDTH_PART, LABEL_HEIGHT, aCommentVis, QLabel::AlignLeft);
259 connect(component, SIGNAL(MousePress(QMouseEvent*)), this, SLOT(showPopup(QMouseEvent*)));
261 myTitle = new SUPERVGUI_Label(this, CELL_WIDTH_PART, LABEL_HEIGHT, name(), QLabel::AlignLeft);
262 connect(myTitle, SIGNAL(MousePress(QMouseEvent*)), this, SLOT(showPopup(QMouseEvent*)));
263 myTitle->setMinimumSize(CELL_WIDTH_PART, LABEL_HEIGHT);
264 myTitle->setMaximumSize(CELL_WIDTH_PART, LABEL_HEIGHT);
266 // aBox->addWidget(service);
267 aBox->addWidget(myTitle);
268 aBox->addWidget(component);
270 myStatus->reparent(this, pos());
271 aBox->addWidget(myStatus);
273 if(m->isEditable()) {
274 // QToolTip::add(service, myNode->Name());
275 QToolTip::add(myTitle, myTitle->text());
276 QToolTip::add(component, component->text());
279 myPopup->setItemEnabled(myDeleteItem, false);
285 //check for control nodes
286 if (n->IsLoop() || n->IsSwitch()) {
290 if (n->IsEndLoop() || n->IsEndSwitch())
294 SUPERVGUI_Cell::~SUPERVGUI_Cell() {
295 Trace("SUPERVGUI_Cell::~SUPERVGUI_Cell");
296 QToolTip::remove(myTitle);
297 if (guiNode != NULL) {
302 void SUPERVGUI_Cell::sync() {
303 Trace("SUPERVGUI_Cell::sync");
304 if (myMain == NULL) return;
305 myTitle->setText(myNode->Name());
306 //component->setText(myNode->Comment());
308 if (guiNode != NULL) {
311 SUPERVGUI_PortIn* pi;
312 QObjectList* ihmList = guiNode->queryList("SUPERVGUI_PortIn");
313 QObjectListIt i(*ihmList);
314 while ((pi=(SUPERVGUI_PortIn*)i.current()) != 0) {
320 SUPERVGUI_PortOut* po;
321 ihmList = guiNode->queryList("SUPERVGUI_PortOut");
323 while ((po=(SUPERVGUI_PortOut*)i.current()) != 0) {
329 SUPERVGUI_Node::sync();
333 void SUPERVGUI_Cell::updateStudy()
335 Trace("SUPERVGUI_Cell::updateStudy")
338 SUPERVGUI_PortOut* po;
339 QObjectList* ihmList = guiNode->queryList("SUPERVGUI_PortOut");
340 QObjectListIt i(*ihmList);
341 while ((po=(SUPERVGUI_PortOut*)i.current()) != 0)
351 void SUPERVGUI_Cell::rename() {
352 SUPERVGUI_Node::rename();
353 if (!myIsControl) { //not ControlNode
354 myTitle->setText(myNode->Name());
357 if (myIsStart) { //StartControlNode
359 QString nm = myNode->Name();
361 myTitle->setText(nm);
362 QString aStr(tr("ENDNODE_PREFIX"));
364 myPairCell->getTitle()->setText(aStr);
365 myPairCell->setNodeName(aStr);
366 // QToolTip::remove(myPairCell->getTitle());
367 QToolTip::add(myPairCell->getTitle(), myPairCell->getTitle()->text());
374 // QToolTip::remove(myTitle);
375 QToolTip::add(myTitle, myTitle->text());
378 void SUPERVGUI_Cell::setPairCell(SUPERVGUI_Cell* thePairCell) {
379 if (myIsControl) { //only for ControlNode
380 myPairCell = thePairCell;
386 SUPERVGUI_Cell* SUPERVGUI_Cell::getPairCell() {
390 SUPERVGUI_CellEndControl::SUPERVGUI_CellEndControl(QWidget* parent, SUPERVGUI_Main* m, SUPERV_CNode n,
391 SUPERVGUI_Cell* theStart)
392 :SUPERVGUI_Cell(parent, m, n)
394 myPairCell = theStart; //set start cell for end cell as pair
395 myPairCell->setPairCell(dynamic_cast<SUPERVGUI_Cell*>(this)); //set end cell for start cell as pair
398 SUPERVGUI_CellEndControl::~SUPERVGUI_CellEndControl() {
399 Trace("SUPERVGUI_CellEndControl::~SUPERVGUI_CellEndControl");
400 QToolTip::remove(myTitle);
401 if (guiNode != NULL) {