1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SUPERV SUPERVGUI : GUI for Supervisor component
23 // File : SUPERVGUI_Ganvas.cxx
24 // Author : Natalia KOPNOVA
27 #include "SUPERVGUI.h"
28 #include "SUPERVGUI_Def.h"
29 #include "SUPERVGUI_Main.h"
30 #include "SUPERVGUI_CanvasNode.h"
31 #include "SUPERVGUI_CanvasPort.h"
32 #include "SUPERVGUI_CanvasLink.h"
34 #include "SUIT_ResourceMgr.h"
35 #include "SUIT_Session.h"
40 #include <sys/timeb.h>
43 #define UPDATECONTROLNODES(NodesName) \
44 n = nodes->NodesName.length(); \
45 for (int i=0; i<n; i++) { \
46 SUPERV_CNode aCNode = SUPERV::CNode::_narrow(nodes->NodesName[i]); \
47 SUPERV_CNode aCNodeEnd = SUPERV::CNode::_narrow(nodes->NodesName[i]->Coupled()); \
48 ihmNode = getNode(aCNode); \
49 if (ihmNode == NULL) { \
50 myMain->addControlNode(aCNode, aCNodeEnd, false); \
52 ihmNode->move(aCNode->X(), aCNode->Y()); \
53 ihmList->removeRef(ihmNode); \
55 ihmNode = getNode(aCNodeEnd); \
57 ihmList->removeRef(ihmNode); \
63 #define UPDATENODES(NodesName, FuncName) \
64 n = nodes->NodesName.length(); \
65 for (int i=0; i<n; i++) { \
66 SUPERV_CNode aCNode = SUPERV::CNode::_narrow(nodes->NodesName[i]); \
67 ihmNode = getNode(aCNode); \
68 if (ihmNode == NULL) { \
69 myMain->FuncName(aCNode); \
71 ihmNode->move(aCNode->X(), aCNode->Y()); \
72 ihmList->removeRef(ihmNode); \
77 #define UPDATELINK(Link) \
78 ihmLink = getLink(Link.in()); \
79 if (ihmLink == NULL) { \
80 ihmLink = new SUPERVGUI_CanvasLink(this, myMain, Link.in()); \
84 ihmList->removeRef(ihmLink); \
89 #define UPDATESTREAMLINK(Link) \
90 ihmLink = getLink(Link.in()); \
91 if (ihmLink == NULL) { \
92 ihmLink = new SUPERVGUI_CanvasStreamLink(this, myMain, Link.in()); \
96 ihmList->removeRef(ihmLink); \
102 SUPERVGUI_Canvas::SUPERVGUI_Canvas( SUPERVGUI_Main* m, SUIT_ResourceMgr* mgr ):
106 Trace("SUPERVGUI_Canvas::SUPERVGUI_Canvas");
107 myIsControlView = false;
108 // resize(GRAPH_WIDTH, GRAPH_HEIGHT);
110 setDoubleBuffering(true);
112 // mkr : IPAL10825 -->
113 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
115 MESSAGE("NULL Supervision module!");
118 QColor aColor = aSupMod->getIVFBackgroundColor();
119 if ( !aColor.isValid() )
120 aColor = mgr->colorValue( "SUPERVGraph", "Background", DEF_MAIN_COLOR );
123 //aColor = QColor(SUIT_Session::session()->resourceMgr()->integerValue( "SUPERVGraph", "BackgroundColorRed" ),
124 // SUIT_Session::session()->resourceMgr()->integerValue( "SUPERVGraph", "BackgroundColorGreen" ),
125 // SUIT_Session::session()->resourceMgr()->integerValue( "SUPERVGraph", "BackgroundColorBlue" ) );
126 setBackgroundColor(aColor);
130 SUPERVGUI_Canvas::~SUPERVGUI_Canvas() {
131 // asv : 17.01.05 : why delete its own children (CanvasNode-s)?
132 // they must be destroyed automatically.
133 QObjectList* aNodeList = queryList("SUPERVGUI_CanvasNode");
134 QObjectListIt aIt(*aNodeList);
136 while ( (anObj = aIt.current()) != 0 ) {
138 aNodeList->removeRef(anObj);
141 // asv : list returned by queryList() must be removed
145 void SUPERVGUI_Canvas::addView(QCanvasView* theView)
147 QCanvas::addView(theView);
148 theView->setPaletteBackgroundColor(backgroundColor().light(120));
151 void SUPERVGUI_Canvas::setFullView()
153 myIsControlView = false;
159 void SUPERVGUI_Canvas::setControlView()
161 myIsControlView = true;
167 void SUPERVGUI_Canvas::updateNodes(bool withPorts)
169 QObjectList* aNodeList = queryList("SUPERVGUI_CanvasNode");
170 QObjectListIt aIt(*aNodeList);
171 SUPERVGUI_CanvasNode* aNode;
172 while ((aNode=(SUPERVGUI_CanvasNode*)aIt.current()) != 0) {
182 void SUPERVGUI_Canvas::updateLinks()
184 QObjectList* aLinkList = queryList("SUPERVGUI_CanvasLink");
185 QObjectListIt aIt(*aLinkList);
186 SUPERVGUI_CanvasLink* aLink;
187 while ((aLink=(SUPERVGUI_CanvasLink*)aIt.current()) != 0) {
194 void SUPERVGUI_Canvas::sync() {
195 if (SUPERV_isNull(myMain->getDataflow())) return;
197 SUPERVGUI_CanvasNode* ihmNode;
198 QObjectList* ihmList = queryList("SUPERVGUI_CanvasNode");
199 QObjectListIt it(*ihmList);
200 while ((ihmNode=(SUPERVGUI_CanvasNode*)it.current()) != 0) {
208 * Synchronizes Graph presentation with internal graph structure
210 void SUPERVGUI_Canvas::merge() {
211 if (SUPERV_isNull(myMain->getDataflow())) return;
213 SUPERVGUI_CanvasNode* ihmNode;
214 QObjectList* ihmList = queryList("SUPERVGUI_CanvasNode");
215 SUPERV_Nodes nodes = myMain->getDataflow()->Nodes();
217 MESSAGE("CNodes="<<nodes->CNodes.length());
218 MESSAGE("FNodes="<<nodes->FNodes.length());
219 MESSAGE("INodes="<<nodes->INodes.length());
220 MESSAGE("GNodes="<<nodes->GNodes.length());
221 MESSAGE("LNodes="<<nodes->LNodes.length());
222 MESSAGE("SNodes="<<nodes->SNodes.length());
223 MESSAGE("Graphs="<<nodes->Graphs.length());
226 UPDATENODES(CNodes, addComputeNode);
227 UPDATENODES(FNodes, addComputeNode);
228 UPDATENODES(INodes, addComputeNode);
229 UPDATENODES(Graphs, addMacroNode);
230 UPDATENODES(GNodes, addGOTONode);
232 UPDATECONTROLNODES(LNodes);
233 UPDATECONTROLNODES(SNodes);
235 n = nodes->LNodes.length();
236 for (int i=0; i<n; i++) {
237 SUPERV_CNode aCNode = SUPERV::CNode::_narrow(nodes->LNodes[i]);
238 SUPERV_CNode aCNodeEnd = SUPERV::CNode::_narrow(nodes->LNodes[i]->Coupled());
239 ihmNode = getNode(aCNode);
240 SUPERVGUI_CanvasNode* ihmNodeEnd = getNode(aCNodeEnd);
241 if (ihmNode == NULL) {
242 myMain->addControlNode(aCNode, aCNodeEnd, false);
245 ihmNode->move(aCNode->X(), aCNode->Y());
246 ihmList->removeRef(ihmNode);
248 ihmNode = getNode(aCNodeEnd);
249 ihmList->removeRef(ihmNode);
254 n = nodes->SNodes.length();
255 for (int i=0; i<n; i++) {
256 SUPERV_CNode aCNode = SUPERV::CNode::_narrow(nodes->SNodes[i]);
257 SUPERV_CNode aCNodeEnd = SUPERV::CNode::_narrow(nodes->SNodes[i]->Coupled());
258 ihmNode = getNode(aCNode);
259 if (ihmNode == NULL) {
260 myMain->addControlNode(aCNode, aCNodeEnd, false);
262 ihmNode->move(aCNode->X(), aCNode->Y());
263 ihmList->removeRef(ihmNode);
265 ihmNode = getNode(aCNodeEnd);
266 ihmList->removeRef(ihmNode);
272 QObjectListIt it(*ihmList);
273 while ((ihmNode=(SUPERVGUI_CanvasNode*)it.current()) != 0) {
275 ihmList->removeRef(ihmNode);
281 SUPERVGUI_CanvasLink* ihmLink;
282 ihmList = queryList("SUPERVGUI_CanvasLink");
284 don't work... that's a pity!
286 //SUPERV_Links links = myMain->getDataflow()->Links();
287 SUPERV_Links links = myMain->getDataflow()->GLinks();
288 for (int i = 0; i < links->length(); i++) {
289 UPDATELINK(links[i]);
293 SUPERV_StreamLinks slinks = myMain->getDataflow()->StreamLinks();
294 for (int i = 0; i < slinks->length(); i++) {
295 UPDATELINK(slinks[i]);
299 if (myMain->getDataflow()->IsStreamGraph()) {
300 SUPERV_StreamGraph aSGraph = myMain->getDataflow()->ToStreamGraph();
301 if (!SUPERV_isNull(aSGraph)) {
302 SUPERV_StreamLinks slinks = aSGraph->StreamLinks(); // <<- doesn't work!!!
303 for (int i = 0; i < slinks->length(); i++) {
304 UPDATELINK(slinks[i]);
310 // update stream links by old method until StreamLinks() fuction works
311 SUPERVGUI_CanvasPort* aPort;
312 QObjectList* aPortList = queryList("SUPERVGUI_CanvasPort");
313 QObjectListIt aPortIt(*aPortList);
314 while ((aPort=(SUPERVGUI_CanvasPort*)aPortIt.current()) != 0) {
316 if (aPort->getEngine()->IsInput() && aPort->getEngine()->IsLinked()
317 && aPort->getEngine()->Kind() == SUPERV::DataStreamParameter) {
318 if (aPort->getEngine()->Node()->Kind() == SUPERV::EndSwitchNode) {
319 SUPERV_Links aLinks = aPort->getEngine()->Links();
320 for (int i = 0; i < aLinks->length(); i++) {
321 UPDATELINK(aLinks[i]);
324 // else if (aPort->isStream()) {
325 // SUPERV_StreamLink aStreamLink = ((SUPERVGUI_CanvasStreamPortIn*)aPort)->getStreamEngine()->StreamLink();
326 // UPDATESTREAMLINK(aStreamLink);
329 SUPERV_Link aLink = aPort->getEngine()->Link();
336 it = QObjectListIt(*ihmList);
337 while ((ihmLink=(SUPERVGUI_CanvasLink*)it.current()) != 0) {
339 ihmList->removeRef(ihmLink);
345 SUPERVGUI_CanvasNode* SUPERVGUI_Canvas::getNode(SUPERV::CNode_ptr theNode) const
347 return (SUPERVGUI_CanvasNode*)
348 ((SUPERVGUI_Canvas*)this)->child(theNode->Name(), "SUPERVGUI_CanvasNode");
351 SUPERVGUI_CanvasPort* SUPERVGUI_Canvas::getPort(SUPERV::Port_ptr thePort) const
353 SUPERVGUI_CanvasNode* aNode = getNode(thePort->Node());
354 if (aNode == NULL) return NULL;
356 return (SUPERVGUI_CanvasPort*)
357 aNode->child(getPortName(thePort), "SUPERVGUI_CanvasPort");
360 SUPERVGUI_CanvasLink* SUPERVGUI_Canvas::getLink(SUPERV::Link_ptr theLink) const
362 return (SUPERVGUI_CanvasLink*)
363 ((SUPERVGUI_Canvas*)this)->child(getLinkName(theLink), "SUPERVGUI_CanvasLink");
366 QString SUPERVGUI_Canvas::getPortName(SUPERV::Port_ptr thePort) const
368 QString aName(thePort->Name());
369 if (thePort->IsInput()) aName = aName + ".In";
370 else aName = aName + ".Out";
374 QString SUPERVGUI_Canvas::getLinkName(SUPERV::Link_ptr theLink) const
376 SUPERV_Port aInPort = theLink->InPort();
377 SUPERV_Port aOutPort = theLink->OutPort();
379 QString(aOutPort->Node()->Name()) + "." +
380 QString(aOutPort->Name()) + "-" +
381 QString(aInPort->Node()->Name()) + "." +
382 QString(aInPort->Name());