1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // SUPERV SUPERVGUI : GUI for Supervisor component
22 // File : SUPERVGUI_Ganvas.cxx
23 // Author : Natalia KOPNOVA
26 #include "SUPERVGUI.h"
27 #include "SUPERVGUI_Def.h"
28 #include "SUPERVGUI_Main.h"
29 #include "SUPERVGUI_CanvasNode.h"
30 #include "SUPERVGUI_CanvasPort.h"
31 #include "SUPERVGUI_CanvasLink.h"
33 #include "SUIT_ResourceMgr.h"
34 #include "SUIT_Session.h"
39 #include <sys/timeb.h>
42 #define UPDATECONTROLNODES(NodesName) \
43 n = nodes->NodesName.length(); \
44 for (int i=0; i<n; i++) { \
45 SUPERV_CNode aCNode = SUPERV::CNode::_narrow(nodes->NodesName[i]); \
46 SUPERV_CNode aCNodeEnd = SUPERV::CNode::_narrow(nodes->NodesName[i]->Coupled()); \
47 ihmNode = getNode(aCNode); \
48 if (ihmNode == NULL) { \
49 myMain->addControlNode(aCNode, aCNodeEnd, false); \
51 ihmNode->move(aCNode->X(), aCNode->Y()); \
52 ihmList->removeRef(ihmNode); \
54 ihmNode = getNode(aCNodeEnd); \
56 ihmList->removeRef(ihmNode); \
62 #define UPDATENODES(NodesName, FuncName) \
63 n = nodes->NodesName.length(); \
64 for (int i=0; i<n; i++) { \
65 SUPERV_CNode aCNode = SUPERV::CNode::_narrow(nodes->NodesName[i]); \
66 ihmNode = getNode(aCNode); \
67 if (ihmNode == NULL) { \
68 myMain->FuncName(aCNode); \
70 ihmNode->move(aCNode->X(), aCNode->Y()); \
71 ihmList->removeRef(ihmNode); \
76 #define UPDATELINK(Link) \
77 ihmLink = getLink(Link.in()); \
78 if (ihmLink == NULL) { \
79 ihmLink = new SUPERVGUI_CanvasLink(this, myMain, Link.in()); \
83 ihmList->removeRef(ihmLink); \
88 #define UPDATESTREAMLINK(Link) \
89 ihmLink = getLink(Link.in()); \
90 if (ihmLink == NULL) { \
91 ihmLink = new SUPERVGUI_CanvasStreamLink(this, myMain, Link.in()); \
95 ihmList->removeRef(ihmLink); \
101 SUPERVGUI_Canvas::SUPERVGUI_Canvas( SUPERVGUI_Main* m, SUIT_ResourceMgr* mgr ):
105 Trace("SUPERVGUI_Canvas::SUPERVGUI_Canvas");
106 myIsControlView = false;
107 // resize(GRAPH_WIDTH, GRAPH_HEIGHT);
109 setDoubleBuffering(true);
111 // mkr : IPAL10825 -->
112 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
114 MESSAGE("NULL Supervision module!");
117 QColor aColor = aSupMod->getIVFBackgroundColor();
118 if ( !aColor.isValid() )
119 aColor = mgr->colorValue( "SUPERVGraph", "Background", DEF_MAIN_COLOR );
122 //aColor = QColor(SUIT_Session::session()->resourceMgr()->integerValue( "SUPERVGraph", "BackgroundColorRed" ),
123 // SUIT_Session::session()->resourceMgr()->integerValue( "SUPERVGraph", "BackgroundColorGreen" ),
124 // SUIT_Session::session()->resourceMgr()->integerValue( "SUPERVGraph", "BackgroundColorBlue" ) );
125 setBackgroundColor(aColor);
129 SUPERVGUI_Canvas::~SUPERVGUI_Canvas() {
130 // asv : 17.01.05 : why delete its own children (CanvasNode-s)?
131 // they must be destroyed automatically.
132 QObjectList* aNodeList = queryList("SUPERVGUI_CanvasNode");
133 QObjectListIt aIt(*aNodeList);
135 while ( (anObj = aIt.current()) != 0 ) {
137 aNodeList->removeRef(anObj);
140 // asv : list returned by queryList() must be removed
144 void SUPERVGUI_Canvas::addView(QCanvasView* theView)
146 QCanvas::addView(theView);
147 theView->setPaletteBackgroundColor(backgroundColor().light(120));
150 void SUPERVGUI_Canvas::setFullView()
152 myIsControlView = false;
158 void SUPERVGUI_Canvas::setControlView()
160 myIsControlView = true;
166 void SUPERVGUI_Canvas::updateNodes(bool withPorts)
168 QObjectList* aNodeList = queryList("SUPERVGUI_CanvasNode");
169 QObjectListIt aIt(*aNodeList);
170 SUPERVGUI_CanvasNode* aNode;
171 while ((aNode=(SUPERVGUI_CanvasNode*)aIt.current()) != 0) {
181 void SUPERVGUI_Canvas::updateLinks()
183 QObjectList* aLinkList = queryList("SUPERVGUI_CanvasLink");
184 QObjectListIt aIt(*aLinkList);
185 SUPERVGUI_CanvasLink* aLink;
186 while ((aLink=(SUPERVGUI_CanvasLink*)aIt.current()) != 0) {
193 void SUPERVGUI_Canvas::sync() {
194 if (SUPERV_isNull(myMain->getDataflow())) return;
196 SUPERVGUI_CanvasNode* ihmNode;
197 QObjectList* ihmList = queryList("SUPERVGUI_CanvasNode");
198 QObjectListIt it(*ihmList);
199 while ((ihmNode=(SUPERVGUI_CanvasNode*)it.current()) != 0) {
207 * Synchronizes Graph presentation with internal graph structure
209 void SUPERVGUI_Canvas::merge() {
210 if (SUPERV_isNull(myMain->getDataflow())) return;
212 SUPERVGUI_CanvasNode* ihmNode;
213 QObjectList* ihmList = queryList("SUPERVGUI_CanvasNode");
214 SUPERV_Nodes nodes = myMain->getDataflow()->Nodes();
216 MESSAGE("CNodes="<<nodes->CNodes.length());
217 MESSAGE("FNodes="<<nodes->FNodes.length());
218 MESSAGE("INodes="<<nodes->INodes.length());
219 MESSAGE("GNodes="<<nodes->GNodes.length());
220 MESSAGE("LNodes="<<nodes->LNodes.length());
221 MESSAGE("SNodes="<<nodes->SNodes.length());
222 MESSAGE("Graphs="<<nodes->Graphs.length());
225 UPDATENODES(CNodes, addComputeNode);
226 UPDATENODES(FNodes, addComputeNode);
227 UPDATENODES(INodes, addComputeNode);
228 UPDATENODES(Graphs, addMacroNode);
229 UPDATENODES(GNodes, addGOTONode);
231 UPDATECONTROLNODES(LNodes);
232 UPDATECONTROLNODES(SNodes);
234 n = nodes->LNodes.length();
235 for (int i=0; i<n; i++) {
236 SUPERV_CNode aCNode = SUPERV::CNode::_narrow(nodes->LNodes[i]);
237 SUPERV_CNode aCNodeEnd = SUPERV::CNode::_narrow(nodes->LNodes[i]->Coupled());
238 ihmNode = getNode(aCNode);
239 SUPERVGUI_CanvasNode* ihmNodeEnd = getNode(aCNodeEnd);
240 if (ihmNode == NULL) {
241 myMain->addControlNode(aCNode, aCNodeEnd, false);
244 ihmNode->move(aCNode->X(), aCNode->Y());
245 ihmList->removeRef(ihmNode);
247 ihmNode = getNode(aCNodeEnd);
248 ihmList->removeRef(ihmNode);
253 n = nodes->SNodes.length();
254 for (int i=0; i<n; i++) {
255 SUPERV_CNode aCNode = SUPERV::CNode::_narrow(nodes->SNodes[i]);
256 SUPERV_CNode aCNodeEnd = SUPERV::CNode::_narrow(nodes->SNodes[i]->Coupled());
257 ihmNode = getNode(aCNode);
258 if (ihmNode == NULL) {
259 myMain->addControlNode(aCNode, aCNodeEnd, false);
261 ihmNode->move(aCNode->X(), aCNode->Y());
262 ihmList->removeRef(ihmNode);
264 ihmNode = getNode(aCNodeEnd);
265 ihmList->removeRef(ihmNode);
271 QObjectListIt it(*ihmList);
272 while ((ihmNode=(SUPERVGUI_CanvasNode*)it.current()) != 0) {
274 ihmList->removeRef(ihmNode);
280 SUPERVGUI_CanvasLink* ihmLink;
281 ihmList = queryList("SUPERVGUI_CanvasLink");
283 don't work... that's a pity!
285 //SUPERV_Links links = myMain->getDataflow()->Links();
286 SUPERV_Links links = myMain->getDataflow()->GLinks();
287 for (int i = 0; i < links->length(); i++) {
288 UPDATELINK(links[i]);
292 SUPERV_StreamLinks slinks = myMain->getDataflow()->StreamLinks();
293 for (int i = 0; i < slinks->length(); i++) {
294 UPDATELINK(slinks[i]);
298 if (myMain->getDataflow()->IsStreamGraph()) {
299 SUPERV_StreamGraph aSGraph = myMain->getDataflow()->ToStreamGraph();
300 if (!SUPERV_isNull(aSGraph)) {
301 SUPERV_StreamLinks slinks = aSGraph->StreamLinks(); // <<- doesn't work!!!
302 for (int i = 0; i < slinks->length(); i++) {
303 UPDATELINK(slinks[i]);
309 // update stream links by old method until StreamLinks() fuction works
310 SUPERVGUI_CanvasPort* aPort;
311 QObjectList* aPortList = queryList("SUPERVGUI_CanvasPort");
312 QObjectListIt aPortIt(*aPortList);
313 while ((aPort=(SUPERVGUI_CanvasPort*)aPortIt.current()) != 0) {
315 if (aPort->getEngine()->IsInput() && aPort->getEngine()->IsLinked()
316 && aPort->getEngine()->Kind() == SUPERV::DataStreamParameter) {
317 if (aPort->getEngine()->Node()->Kind() == SUPERV::EndSwitchNode) {
318 SUPERV_Links aLinks = aPort->getEngine()->Links();
319 for (int i = 0; i < aLinks->length(); i++) {
320 UPDATELINK(aLinks[i]);
323 // else if (aPort->isStream()) {
324 // SUPERV_StreamLink aStreamLink = ((SUPERVGUI_CanvasStreamPortIn*)aPort)->getStreamEngine()->StreamLink();
325 // UPDATESTREAMLINK(aStreamLink);
328 SUPERV_Link aLink = aPort->getEngine()->Link();
335 it = QObjectListIt(*ihmList);
336 while ((ihmLink=(SUPERVGUI_CanvasLink*)it.current()) != 0) {
338 ihmList->removeRef(ihmLink);
344 SUPERVGUI_CanvasNode* SUPERVGUI_Canvas::getNode(SUPERV::CNode_ptr theNode) const
346 return (SUPERVGUI_CanvasNode*)
347 ((SUPERVGUI_Canvas*)this)->child(theNode->Name(), "SUPERVGUI_CanvasNode");
350 SUPERVGUI_CanvasPort* SUPERVGUI_Canvas::getPort(SUPERV::Port_ptr thePort) const
352 SUPERVGUI_CanvasNode* aNode = getNode(thePort->Node());
353 if (aNode == NULL) return NULL;
355 return (SUPERVGUI_CanvasPort*)
356 aNode->child(getPortName(thePort), "SUPERVGUI_CanvasPort");
359 SUPERVGUI_CanvasLink* SUPERVGUI_Canvas::getLink(SUPERV::Link_ptr theLink) const
361 return (SUPERVGUI_CanvasLink*)
362 ((SUPERVGUI_Canvas*)this)->child(getLinkName(theLink), "SUPERVGUI_CanvasLink");
365 QString SUPERVGUI_Canvas::getPortName(SUPERV::Port_ptr thePort) const
367 QString aName(thePort->Name());
368 if (thePort->IsInput()) aName = aName + ".In";
369 else aName = aName + ".Out";
373 QString SUPERVGUI_Canvas::getLinkName(SUPERV::Link_ptr theLink) const
375 SUPERV_Port aInPort = theLink->InPort();
376 SUPERV_Port aOutPort = theLink->OutPort();
378 QString(aOutPort->Node()->Name()) + "." +
379 QString(aOutPort->Name()) + "-" +
380 QString(aInPort->Node()->Name()) + "." +
381 QString(aInPort->Name());