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); \
55 ihmList->removeRef(ihmNode); \
60 #define UPDATENODES(NodesName, FuncName) \
61 n = nodes->NodesName.length(); \
62 for (int i=0; i<n; i++) { \
63 SUPERV_CNode aCNode = SUPERV::CNode::_narrow(nodes->NodesName[i]); \
64 ihmNode = getNode(aCNode); \
65 if (ihmNode == NULL) { \
66 myMain->FuncName(aCNode); \
68 ihmNode->move(aCNode->X(), aCNode->Y()); \
69 ihmList->removeRef(ihmNode); \
74 #define UPDATELINK(Link) \
75 ihmLink = getLink(Link.in()); \
76 if (ihmLink == NULL) { \
77 ihmLink = new SUPERVGUI_CanvasLink(this, myMain, Link.in()); \
81 ihmList->removeRef(ihmLink); \
86 #define UPDATESTREAMLINK(Link) \
87 ihmLink = getLink(Link.in()); \
88 if (ihmLink == NULL) { \
89 ihmLink = new SUPERVGUI_CanvasStreamLink(this, myMain, Link.in()); \
93 ihmList->removeRef(ihmLink); \
99 SUPERVGUI_Canvas::SUPERVGUI_Canvas( SUPERVGUI_Main* m, SUIT_ResourceMgr* mgr ):
103 Trace("SUPERVGUI_Canvas::SUPERVGUI_Canvas");
104 myIsControlView = false;
105 // resize(GRAPH_WIDTH, GRAPH_HEIGHT);
107 setDoubleBuffering(true);
109 // mkr : IPAL10825 -->
110 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
112 MESSAGE("NULL Supervision module!");
115 QColor aColor = aSupMod->getIVFBackgroundColor();
116 if ( !aColor.isValid() )
117 aColor = mgr->colorValue( "SUPERVGraph", "Background", DEF_MAIN_COLOR );
120 //aColor = QColor(SUIT_Session::session()->resourceMgr()->integerValue( "SUPERVGraph", "BackgroundColorRed" ),
121 // SUIT_Session::session()->resourceMgr()->integerValue( "SUPERVGraph", "BackgroundColorGreen" ),
122 // SUIT_Session::session()->resourceMgr()->integerValue( "SUPERVGraph", "BackgroundColorBlue" ) );
123 setBackgroundColor(aColor);
127 SUPERVGUI_Canvas::~SUPERVGUI_Canvas() {
128 // asv : 17.01.05 : why delete its own children (CanvasNode-s)?
129 // they must be destroyed automatically.
130 QObjectList* aNodeList = queryList("SUPERVGUI_CanvasNode");
131 QObjectListIt aIt(*aNodeList);
133 while ( (anObj = aIt.current()) != 0 ) {
135 aNodeList->removeRef(anObj);
138 // asv : list returned by queryList() must be removed
142 void SUPERVGUI_Canvas::addView(QCanvasView* theView)
144 QCanvas::addView(theView);
145 theView->setPaletteBackgroundColor(backgroundColor().light(120));
148 void SUPERVGUI_Canvas::setFullView()
150 myIsControlView = false;
156 void SUPERVGUI_Canvas::setControlView()
158 myIsControlView = true;
164 void SUPERVGUI_Canvas::updateNodes(bool withPorts)
166 QObjectList* aNodeList = queryList("SUPERVGUI_CanvasNode");
167 QObjectListIt aIt(*aNodeList);
168 SUPERVGUI_CanvasNode* aNode;
169 while ((aNode=(SUPERVGUI_CanvasNode*)aIt.current()) != 0) {
179 void SUPERVGUI_Canvas::updateLinks()
181 QObjectList* aLinkList = queryList("SUPERVGUI_CanvasLink");
182 QObjectListIt aIt(*aLinkList);
183 SUPERVGUI_CanvasLink* aLink;
184 while ((aLink=(SUPERVGUI_CanvasLink*)aIt.current()) != 0) {
191 void SUPERVGUI_Canvas::sync() {
192 if (SUPERV_isNull(myMain->getDataflow())) return;
194 SUPERVGUI_CanvasNode* ihmNode;
195 QObjectList* ihmList = queryList("SUPERVGUI_CanvasNode");
196 QObjectListIt it(*ihmList);
197 while ((ihmNode=(SUPERVGUI_CanvasNode*)it.current()) != 0) {
205 * Synchronizes Graph presentation with internal graph structure
207 void SUPERVGUI_Canvas::merge() {
208 if (SUPERV_isNull(myMain->getDataflow())) return;
210 SUPERVGUI_CanvasNode* ihmNode;
211 QObjectList* ihmList = queryList("SUPERVGUI_CanvasNode");
212 SUPERV_Nodes nodes = myMain->getDataflow()->Nodes();
214 MESSAGE("CNodes="<<nodes->CNodes.length());
215 MESSAGE("FNodes="<<nodes->FNodes.length());
216 MESSAGE("INodes="<<nodes->INodes.length());
217 MESSAGE("GNodes="<<nodes->GNodes.length());
218 MESSAGE("LNodes="<<nodes->LNodes.length());
219 MESSAGE("SNodes="<<nodes->SNodes.length());
220 MESSAGE("Graphs="<<nodes->Graphs.length());
223 UPDATENODES(CNodes, addComputeNode);
224 UPDATENODES(FNodes, addComputeNode);
225 UPDATENODES(INodes, addComputeNode);
226 UPDATENODES(Graphs, addMacroNode);
227 UPDATENODES(GNodes, addGOTONode);
229 UPDATECONTROLNODES(LNodes);
230 UPDATECONTROLNODES(SNodes);
232 QObjectListIt it(*ihmList);
233 while ((ihmNode=(SUPERVGUI_CanvasNode*)it.current()) != 0) {
235 ihmList->removeRef(ihmNode);
241 SUPERVGUI_CanvasLink* ihmLink;
242 ihmList = queryList("SUPERVGUI_CanvasLink");
244 don't work... that's a pity!
246 //SUPERV_Links links = myMain->getDataflow()->Links();
247 SUPERV_Links links = myMain->getDataflow()->GLinks();
248 for (int i = 0; i < links->length(); i++) {
249 UPDATELINK(links[i]);
253 SUPERV_StreamLinks slinks = myMain->getDataflow()->StreamLinks();
254 for (int i = 0; i < slinks->length(); i++) {
255 UPDATELINK(slinks[i]);
259 if (myMain->getDataflow()->IsStreamGraph()) {
260 SUPERV_StreamGraph aSGraph = myMain->getDataflow()->ToStreamGraph();
261 if (!SUPERV_isNull(aSGraph)) {
262 SUPERV_StreamLinks slinks = aSGraph->StreamLinks(); // <<- doesn't work!!!
263 for (int i = 0; i < slinks->length(); i++) {
264 UPDATELINK(slinks[i]);
270 // update stream links by old method until StreamLinks() fuction works
271 SUPERVGUI_CanvasPort* aPort;
272 QObjectList* aPortList = queryList("SUPERVGUI_CanvasPort");
273 QObjectListIt aPortIt(*aPortList);
274 while ((aPort=(SUPERVGUI_CanvasPort*)aPortIt.current()) != 0) {
276 if (aPort->getEngine()->IsInput() && aPort->getEngine()->IsLinked()
277 && aPort->getEngine()->Kind() == SUPERV::DataStreamParameter) {
278 if (aPort->getEngine()->Node()->Kind() == SUPERV::EndSwitchNode) {
279 SUPERV_Links aLinks = aPort->getEngine()->Links();
280 for (int i = 0; i < aLinks->length(); i++) {
281 UPDATELINK(aLinks[i]);
284 // else if (aPort->isStream()) {
285 // SUPERV_StreamLink aStreamLink = ((SUPERVGUI_CanvasStreamPortIn*)aPort)->getStreamEngine()->StreamLink();
286 // UPDATESTREAMLINK(aStreamLink);
289 SUPERV_Link aLink = aPort->getEngine()->Link();
296 it = QObjectListIt(*ihmList);
297 while ((ihmLink=(SUPERVGUI_CanvasLink*)it.current()) != 0) {
299 ihmList->removeRef(ihmLink);
305 SUPERVGUI_CanvasNode* SUPERVGUI_Canvas::getNode(SUPERV::CNode_ptr theNode) const
307 return (SUPERVGUI_CanvasNode*)
308 ((SUPERVGUI_Canvas*)this)->child(theNode->Name(), "SUPERVGUI_CanvasNode");
311 SUPERVGUI_CanvasPort* SUPERVGUI_Canvas::getPort(SUPERV::Port_ptr thePort) const
313 SUPERVGUI_CanvasNode* aNode = getNode(thePort->Node());
314 if (aNode == NULL) return NULL;
316 return (SUPERVGUI_CanvasPort*)
317 aNode->child(getPortName(thePort), "SUPERVGUI_CanvasPort");
320 SUPERVGUI_CanvasLink* SUPERVGUI_Canvas::getLink(SUPERV::Link_ptr theLink) const
322 return (SUPERVGUI_CanvasLink*)
323 ((SUPERVGUI_Canvas*)this)->child(getLinkName(theLink), "SUPERVGUI_CanvasLink");
326 QString SUPERVGUI_Canvas::getPortName(SUPERV::Port_ptr thePort) const
328 QString aName(thePort->Name());
329 if (thePort->IsInput()) aName = aName + ".In";
330 else aName = aName + ".Out";
334 QString SUPERVGUI_Canvas::getLinkName(SUPERV::Link_ptr theLink) const
336 SUPERV_Port aInPort = theLink->InPort();
337 SUPERV_Port aOutPort = theLink->OutPort();
339 QString(aOutPort->Node()->Name()) + "." +
340 QString(aOutPort->Name()) + "-" +
341 QString(aInPort->Node()->Name()) + "." +
342 QString(aInPort->Name());