]> SALOME platform Git repositories - modules/superv.git/blob - src/SUPERVGUI/SUPERVGUI_Array.cxx
Salome HOME
This commit was generated by cvs2git to create branch 'IMPORT'.
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_Array.cxx
1 using namespace std;
2 //  File      : SUPERVGUI_Array.cxx
3 //  Created   : 08 / 02 / 2002
4 //  Author    : Francis KLOSS
5 //  Project   : SALOME
6 //  Module    : SUPERVGUI
7 //  Copyright : CEA
8
9 #include "SUPERVGUI_Def.h"
10 #include "SUPERVGUI_Array.h"
11 #include "SUPERVGUI_Main.h"
12 #include "SUPERVGUI_ComputeNode.h"
13 #include "SUPERVGUI_BrowseNodeDlg.h"
14 #include <qtooltip.h>
15 #include <qlayout.h>
16
17 #define ADDNODES(NodesName) \
18     ncols = nodes->NodesName.length(); \
19     for (int co=0; co<ncols; co++) {  \
20       SUPERV_CNode aCNode = SUPERV::CNode::_narrow(nodes->NodesName[co]); \
21       x = 50 + co * (CELL_WIDTH  + CELL_SPACE);\
22       SUPERVGUI_Node* aNode = new SUPERVGUI_Cell(viewport(), main, aCNode); \
23       ResizeGraph(aNode, x, y); \
24       addChild(aNode, x, y);  \
25     }
26
27
28
29 #define ADDCONTROLNODES(NodesName) \
30     ncols = nodes->NodesName.length(); \
31     x = 50; \
32     for (int co=0; co<ncols; co++) {  \
33       SUPERV_CNode aCNode = SUPERV::CNode::_narrow(nodes->NodesName[co]); \
34       SUPERVGUI_Node* aNode = new SUPERVGUI_Cell(viewport(), main, aCNode); \
35       ResizeGraph(aNode, x, y); \
36       addChild(aNode, x, y);  \
37       x += (CELL_WIDTH + CELL_SPACE); \
38       SUPERV_CNode aCNodeEnd = SUPERV::CNode::_narrow(nodes->NodesName[co]->Coupled()); \
39       SUPERVGUI_Node* aNodeEnd = new SUPERVGUI_Cell(viewport(), main, aCNodeEnd); \
40       ResizeGraph(aNodeEnd, x, y); \
41       addChild(aNodeEnd, x, y);  \
42       x += (CELL_WIDTH + CELL_SPACE); \
43      }
44
45
46
47
48 SUPERVGUI_Array::SUPERVGUI_Array(SUPERVGUI_Main* m):
49     SUPERVGUI_View(m)
50 {
51   resizeContents(GRAPH_WIDTH, GRAPH_HEIGHT);
52   setName("TableView");
53   hide();
54 }
55
56 SUPERVGUI_Array::~SUPERVGUI_Array() {
57     Trace("SUPERVGUI_Array::~SUPERVGUI_Array")
58 }
59
60 bool SUPERVGUI_Array::create() {
61   Trace("SUPERVGUI_Array::create");
62   SUPERV_Nodes nodes = main->getDataflow()->Nodes();
63   int aCount = 0;
64   aCount += nodes->CNodes.length();
65   aCount += nodes->FNodes.length();
66   aCount += nodes->INodes.length();
67   aCount += nodes->GNodes.length();
68   aCount += nodes->LNodes.length();
69   aCount += nodes->SNodes.length();
70   if (aCount == 0) {
71     show();
72     return true;
73   }
74
75   //SUPERV_Nodes    nodes;
76   SUPERVGUI_Cell* cell;
77   QString         aLabel;
78   int             x, y;
79   int             nligs = main->getDataflow()->LevelMax();
80   int             ncols = main->getDataflow()->ThreadsMax();
81   
82   // there is no any calculations
83   if (ncols == 0) return false;
84   
85   for (int co=0; co<ncols; co++) {
86     aLabel = QString("Thread %1").arg(co);
87     QLabel* aTitle = new QLabel(aLabel, viewport());
88     aTitle->setAlignment(QLabel::AlignCenter | QLabel::AlignVCenter);
89     aTitle->setLineWidth(1);
90     aTitle->setPaletteBackgroundColor(MAIN_TITLE);
91     aTitle->setMinimumSize(CELL_WIDTH, CELL_HEIGHT);
92     aTitle->setFrameStyle(QFrame::Panel | QFrame::Plain);
93     addChild(aTitle, 50 + co * (CELL_WIDTH  + CELL_SPACE), 20);
94   }
95   for (int li=0; li<=nligs; li++) {
96     nodes = main->getDataflow()->LevelNodes(li);
97     y = 60 + li * (CELL_HEIGHT + CELL_SPACE);
98     ADDNODES(CNodes);
99     ADDNODES(FNodes);
100     ADDNODES(INodes);
101     ADDNODES(GNodes);
102     ADDCONTROLNODES(LNodes);
103     ADDCONTROLNODES(SNodes);
104   }
105   nodeX = 50;
106   nodeY = y + CELL_HEIGHT*2;
107   
108   show();
109   return true;
110 }
111
112 void SUPERVGUI_Array::destroy() {
113     Trace("SUPERVGUI_Array::destroy")
114     hide();
115
116     SUPERVGUI_Cell* cell;
117     QObjectList* ihmList = queryList("SUPERVGUI_Cell");
118     QObjectListIt i(*ihmList);
119
120     while ((cell=(SUPERVGUI_Cell*)i.current()) != 0) {
121         ++i;
122         cell->updateStudy();
123         cell->close(true);
124     };
125
126     delete ihmList;
127 }
128
129 void SUPERVGUI_Array::sync() {
130     Trace("SUPERVGUI_Array::sync")
131     if (SUPERV_isNull(main->getDataflow())) return;
132
133     SUPERVGUI_Cell* cell;
134     QObjectList* ihmList = queryList("SUPERVGUI_Cell");
135     QObjectListIt i(*ihmList);
136     while ((cell=(SUPERVGUI_Cell*)i.current()) != 0) {
137       ++i;
138       cell->sync();
139     }
140     delete ihmList;
141 }
142
143 SUPERVGUI_Node* SUPERVGUI_Array::addNode(SUPERV_CNode node) {
144     Trace("SUPERVGUI_Array::Array")
145     SUPERVGUI_Node* n = new SUPERVGUI_ComputeNode(viewport(), main, node);
146     ResizeGraph(n, nodeX, nodeY);
147     addChild(n, nodeX, nodeY);
148     nodeX += NODE_DX;
149     nodeY += NODE_DY;
150     n->sync();
151     return(n);
152 }
153
154 void SUPERVGUI_Array::contentsMousePressEvent(QMouseEvent* e) {
155     Trace("SUPERVGUI_Array::contentsMousePressEvent")
156     if (e->button() == RightButton) {
157         myPopup->exec(e->globalPos());
158     };
159 }
160
161
162
163
164
165 // ------------------------------------
166 // Cell widget of the table
167 // ------------------------------------
168
169
170 SUPERVGUI_Cell::SUPERVGUI_Cell(QWidget* parent, SUPERVGUI_Main* m, SUPERV_CNode n):
171     SUPERVGUI_Node(parent, m, n),
172     guiNode(NULL)
173 {
174   Trace("SUPERVGUI_Cell::SUPERVGUI_Cell");
175   setLineWidth(2);
176   setFrameStyle(QFrame::Panel | QFrame::Raised);
177   
178   QHBoxLayout* aBox = new QHBoxLayout(this);
179   aBox->setMargin(3);
180   aBox->setSpacing(3);
181   component = new SUPERVGUI_Label(this, CELL_WIDTH_PART, LABEL_HEIGHT, myNode->Comment(), QLabel::AlignLeft);
182   connect(component, SIGNAL(MousePress(QMouseEvent*)), this, SLOT(showPopup(QMouseEvent*)));
183
184   myTitle = new SUPERVGUI_Label(this, CELL_WIDTH_PART, LABEL_HEIGHT, name(), QLabel::AlignLeft);
185   connect(myTitle, SIGNAL(MousePress(QMouseEvent*)), this, SLOT(showPopup(QMouseEvent*)));
186   myTitle->setMinimumSize(CELL_WIDTH_PART, LABEL_HEIGHT);
187   myTitle->setMaximumSize(CELL_WIDTH_PART, LABEL_HEIGHT);
188
189   //  aBox->addWidget(service);
190   aBox->addWidget(myTitle);
191   aBox->addWidget(component);
192
193   myStatus->reparent(this, pos());
194   aBox->addWidget(myStatus);
195
196   //  QToolTip::add(service, myNode->Name());
197   QToolTip::add(myTitle, myTitle->text());
198
199   myPopup->setItemEnabled(myDeleteItem, false);
200   adjustSize();
201 }
202
203 SUPERVGUI_Cell::~SUPERVGUI_Cell() {
204   Trace("SUPERVGUI_Cell::~SUPERVGUI_Cell");
205   QToolTip::remove(myTitle);
206   if (guiNode != NULL) {
207     guiNode->close();
208   }
209 }
210
211 void SUPERVGUI_Cell::sync() {
212   Trace("SUPERVGUI_Cell::sync");
213   if (myMain == NULL) return;
214   myTitle->setText(myNode->Name());
215   component->setText(myNode->Comment());
216   
217   if (guiNode != NULL) {
218     guiNode->sync();
219     
220     SUPERVGUI_PortIn* pi;
221     QObjectList* ihmList = guiNode->queryList("SUPERVGUI_PortIn");
222     QObjectListIt i(*ihmList);
223     while ((pi=(SUPERVGUI_PortIn*)i.current()) != 0) {
224       ++i;
225       pi->sync();
226     }
227     delete ihmList;
228     
229     SUPERVGUI_PortOut* po;
230     ihmList = guiNode->queryList("SUPERVGUI_PortOut");
231     i = *ihmList;
232     while ((po=(SUPERVGUI_PortOut*)i.current()) != 0) {
233       ++i;
234       po->sync();
235     }
236     delete ihmList;
237   }
238   SUPERVGUI_Node::sync();
239 }
240
241
242 void SUPERVGUI_Cell::updateStudy()
243 {
244   Trace("SUPERVGUI_Cell::updateStudy")
245   if (guiNode != NULL)
246     {
247       SUPERVGUI_PortOut* po;
248       QObjectList* ihmList = guiNode->queryList("SUPERVGUI_PortOut");
249       QObjectListIt i(*ihmList);
250       while ((po=(SUPERVGUI_PortOut*)i.current()) != 0)
251         {
252           ++i;
253           po->updateStudy();
254         }
255       delete ihmList;
256     }
257 }
258
259
260 void SUPERVGUI_Cell::rename() {
261   SUPERVGUI_Node::rename();
262   myTitle->setText(myNode->Name());  
263   // QToolTip::remove(myTitle);
264   //QToolTip::add(myTitle, myTitle->text());  
265 }