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) \
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); \
52 #define ADDCONTROLNODES(NodesName) \
53 ncols = nodes->NodesName.length(); \
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); \
71 SUPERVGUI_Array::SUPERVGUI_Array(SUPERVGUI_Main* m):
74 resizeContents(GRAPH_WIDTH, GRAPH_HEIGHT);
79 SUPERVGUI_Array::~SUPERVGUI_Array() {
80 Trace("SUPERVGUI_Array::~SUPERVGUI_Array")
83 bool SUPERVGUI_Array::create() {
84 Trace("SUPERVGUI_Array::create");
85 SUPERV_Nodes nodes = main->getDataflow()->Nodes();
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();
102 int nligs = main->getDataflow()->LevelMax();
103 int ncols = main->getDataflow()->ThreadsMax();
105 // there is no any calculations
106 if (ncols == 0) return false;
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);
118 for (int li=0; li<=nligs; li++) {
119 nodes = main->getDataflow()->LevelNodes(li);
120 y = 60 + li * (CELL_HEIGHT + CELL_SPACE);
125 ADDCONTROLNODES(LNodes);
126 ADDCONTROLNODES(SNodes);
129 nodeY = y + CELL_HEIGHT*2;
135 void SUPERVGUI_Array::destroy() {
136 Trace("SUPERVGUI_Array::destroy")
139 SUPERVGUI_Cell* cell;
140 QObjectList* ihmList = queryList("SUPERVGUI_Cell");
141 QObjectListIt i(*ihmList);
143 while ((cell=(SUPERVGUI_Cell*)i.current()) != 0) {
151 SUPERVGUI_CellEndControl* cellEC;
152 QObjectList* ihmListEC = queryList("SUPERVGUI_CellEndControl");
153 QObjectListIt iEC(*ihmListEC);
155 while ((cellEC=(SUPERVGUI_CellEndControl*)iEC.current()) != 0) {
157 cellEC->updateStudy();
165 void SUPERVGUI_Array::sync() {
166 Trace("SUPERVGUI_Array::sync")
167 if (SUPERV_isNull(main->getDataflow())) return;
169 SUPERVGUI_Cell* cell;
170 QObjectList* ihmList = queryList("SUPERVGUI_Cell");
171 QObjectListIt i(*ihmList);
172 while ((cell=(SUPERVGUI_Cell*)i.current()) != 0) {
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);
190 void SUPERVGUI_Array::contentsMousePressEvent(QMouseEvent* e) {
191 Trace("SUPERVGUI_Array::contentsMousePressEvent")
192 if (e->button() == RightButton) {
193 myPopup->exec(e->globalPos());
201 // ------------------------------------
202 // Cell widget of the table
203 // ------------------------------------
206 SUPERVGUI_Cell::SUPERVGUI_Cell(QWidget* parent, SUPERVGUI_Main* m, SUPERV_CNode n):
207 SUPERVGUI_Node(parent, m, n),
210 Trace("SUPERVGUI_Cell::SUPERVGUI_Cell");
212 setFrameStyle(QFrame::Panel | QFrame::Raised);
214 QHBoxLayout* aBox = new QHBoxLayout(this);
219 if (getNodeType() == SUPERV::FactoryNode)
220 aCommentVis = QString(myNode->Service()->ServiceName) + QString(tr("COMMENT_FROM"))
221 + QString(getFactoryNode()->GetComponentName());
223 //aCommentVis = tr("COMMENT_PYTHON");
224 aCommentVis = tr("COMMENT_CNODE");
226 component = new SUPERVGUI_Label(this, CELL_WIDTH_PART, LABEL_HEIGHT, aCommentVis, QLabel::AlignLeft);
227 connect(component, SIGNAL(MousePress(QMouseEvent*)), this, SLOT(showPopup(QMouseEvent*)));
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);
234 // aBox->addWidget(service);
235 aBox->addWidget(myTitle);
236 aBox->addWidget(component);
238 myStatus->reparent(this, pos());
239 aBox->addWidget(myStatus);
241 if(m->isEditable()) {
242 // QToolTip::add(service, myNode->Name());
243 QToolTip::add(myTitle, myTitle->text());
244 QToolTip::add(component, component->text());
247 myPopup->setItemEnabled(myDeleteItem, false);
253 //check for control nodes
254 if (n->IsLoop() || n->IsSwitch()) {
258 if (n->IsEndLoop() || n->IsEndSwitch())
262 SUPERVGUI_Cell::~SUPERVGUI_Cell() {
263 Trace("SUPERVGUI_Cell::~SUPERVGUI_Cell");
264 QToolTip::remove(myTitle);
265 if (guiNode != NULL) {
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());
276 if (guiNode != NULL) {
279 SUPERVGUI_PortIn* pi;
280 QObjectList* ihmList = guiNode->queryList("SUPERVGUI_PortIn");
281 QObjectListIt i(*ihmList);
282 while ((pi=(SUPERVGUI_PortIn*)i.current()) != 0) {
288 SUPERVGUI_PortOut* po;
289 ihmList = guiNode->queryList("SUPERVGUI_PortOut");
291 while ((po=(SUPERVGUI_PortOut*)i.current()) != 0) {
297 SUPERVGUI_Node::sync();
301 void SUPERVGUI_Cell::updateStudy()
303 Trace("SUPERVGUI_Cell::updateStudy")
306 SUPERVGUI_PortOut* po;
307 QObjectList* ihmList = guiNode->queryList("SUPERVGUI_PortOut");
308 QObjectListIt i(*ihmList);
309 while ((po=(SUPERVGUI_PortOut*)i.current()) != 0)
319 void SUPERVGUI_Cell::rename() {
320 SUPERVGUI_Node::rename();
321 if (!myIsControl) { //not ControlNode
322 myTitle->setText(myNode->Name());
325 if (myIsStart) { //StartControlNode
327 QString nm = myNode->Name();
329 myTitle->setText(nm);
330 QString aStr(tr("ENDNODE_PREFIX"));
332 myPairCell->getTitle()->setText(aStr);
333 myPairCell->setNodeName(aStr);
334 // QToolTip::remove(myPairCell->getTitle());
335 QToolTip::add(myPairCell->getTitle(), myPairCell->getTitle()->text());
342 // QToolTip::remove(myTitle);
343 QToolTip::add(myTitle, myTitle->text());
346 void SUPERVGUI_Cell::setPairCell(SUPERVGUI_Cell* thePairCell) {
347 if (myIsControl) { //only for ControlNode
348 myPairCell = thePairCell;
354 SUPERVGUI_Cell* SUPERVGUI_Cell::getPairCell() {
358 SUPERVGUI_CellEndControl::SUPERVGUI_CellEndControl(QWidget* parent, SUPERVGUI_Main* m, SUPERV_CNode n,
359 SUPERVGUI_Cell* theStart)
360 :SUPERVGUI_Cell(parent, m, n)
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
366 SUPERVGUI_CellEndControl::~SUPERVGUI_CellEndControl() {
367 Trace("SUPERVGUI_CellEndControl::~SUPERVGUI_CellEndControl");
368 QToolTip::remove(myTitle);
369 if (guiNode != NULL) {