1 // SUPERV SUPERVGUI : GUI for Supervisor component
3 // Copyright (C) 2003 OPEN CASCADE
5 // File : SUPERVGUI_CanvasControlNode.cxx
6 // Author : Natalia KOPNOVA
10 #include "SUPERVGUI_CanvasControlNode.h"
11 #include "SUPERVGUI_CanvasControlNodePrs.h"
12 #include "SUPERVGUI_CanvasCellNodePrs.h"
13 #include "SUPERVGUI_Main.h"
14 #include "SUPERVGUI.h"
15 #include "SUPERVGUI_Canvas.h"
16 #include "SUPERVGUI_ControlNode.h" // access to SelectInlineDlg
18 #include "QAD_FileDlg.h"
19 #include "QAD_Application.h"
21 //=====================================================================
23 //=====================================================================
24 SUPERVGUI_CanvasComputeNode::SUPERVGUI_CanvasComputeNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
25 SUPERVGUI_CanvasNode(theParent, theMain, theNode)
27 Trace("SUPERVGUI_CanvasComputeNode::SUPERVGUI_CanvasComputeNode");
30 QPopupMenu* SUPERVGUI_CanvasComputeNode::getPopupMenu(QWidget* theParent)
32 QPopupMenu* popup = SUPERVGUI_CanvasNode::getPopupMenu(theParent);
34 QPopupMenu* aShowPopup = new QPopupMenu(theParent);
36 anItem = aShowPopup->insertItem(tr("POP_SHOWTITLES"), this, SLOT(switchLabel()));
37 aShowPopup->setItemChecked(anItem, getPrs()->isLabelVisible());
38 anItem = aShowPopup->insertItem(tr("POP_SHOWPORTS"), this, SLOT(switchPorts()));
39 aShowPopup->setItemChecked(anItem, getPrs()->isPortVisible());
41 popup->insertSeparator();
42 popup->insertItem(tr("POP_SHOW"), aShowPopup);
48 //=====================================================================
50 //=====================================================================
51 SUPERVGUI_CanvasStartNode::SUPERVGUI_CanvasStartNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
52 SUPERVGUI_CanvasNode(theParent, theMain, theNode),
55 Trace("SUPERVGUI_CanvasStartNode::SUPERVGUI_CanvasStartNode");
58 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasStartNode::createPrs() const
60 return new SUPERVGUI_CanvasStartNodePrs(getMain()->getCanvas(),
61 (SUPERVGUI_CanvasStartNode*)this);
64 bool SUPERVGUI_CanvasStartNode::setNodeName(QString aName)
66 bool result = SUPERVGUI_CanvasNode::setNodeName(aName);
67 if (result && myCoupled) {
68 myCoupled->setNodeName(QString(tr("ENDNODE_PREFIX"))+aName);
73 QPopupMenu* SUPERVGUI_CanvasStartNode::getPopupMenu(QWidget* theParent)
75 QPopupMenu* popup = SUPERVGUI_CanvasNode::getPopupMenu(theParent);
77 popup->insertSeparator();
78 int anItem = popup->insertItem(tr("POP_HIDEPORTS"), this, SLOT(switchPorts()));
79 popup->setItemChecked(anItem, !getPrs()->isPortVisible());
84 void SUPERVGUI_CanvasStartNode::remove()
86 SUPERVGUI_Canvas* aCanvas = getMain()->getCanvas();
89 if (myCoupled) myCoupled->setDestroyed();
91 getEngine()->destroy();
93 if (myCoupled) delete myCoupled;
99 void SUPERVGUI_CanvasStartNode::onDestroyed(QObject* theObject)
102 SUPERVGUI_CanvasNode::onDestroyed(theObject);
103 if (getEngine()->IsLoop()) merge();
104 if (myCoupled) myCoupled->merge();
108 void SUPERVGUI_CanvasStartNode::addInputPort()
110 SUPERVGUI_CanvasNode::addInputPort();
111 if (getEngine()->IsLoop()) merge();
112 if (myCoupled) myCoupled->merge();
115 void SUPERVGUI_CanvasStartNode::addOutputPort()
117 SUPERVGUI_CanvasNode::addOutputPort();
118 if (myCoupled) myCoupled->merge();
121 //=====================================================================
123 //=====================================================================
124 SUPERVGUI_CanvasEndNode::SUPERVGUI_CanvasEndNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode,
125 SUPERVGUI_CanvasStartNode* theStart):
126 SUPERVGUI_CanvasNode(theParent, theMain, theNode),
129 Trace("SUPERVGUI_CanvasEndNode::SUPERVGUI_CanvasEndNode");
130 myCoupled->setCoupled(this);
133 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasEndNode::createPrs() const
135 return new SUPERVGUI_CanvasEndNodePrs(getMain()->getCanvas(),
136 (SUPERVGUI_CanvasEndNode*)this);
139 QPopupMenu* SUPERVGUI_CanvasEndNode::getPopupMenu(QWidget* theParent)
141 QPopupMenu* popup = SUPERVGUI_CanvasNode::getPopupMenu(theParent);
143 popup->insertSeparator();
144 int anItem = popup->insertItem(tr("POP_HIDEPORTS"), this, SLOT(switchPorts()));
145 popup->setItemChecked(anItem, !getPrs()->isPortVisible());
150 void SUPERVGUI_CanvasEndNode::addInputPort()
152 SUPERVGUI_CanvasNode::addInputPort();
153 if (getEngine()->IsEndSwitch()) merge();
157 //=====================================================================
159 //=====================================================================
160 SUPERVGUI_CanvasGotoNode::SUPERVGUI_CanvasGotoNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
161 SUPERVGUI_CanvasNode(theParent, theMain, theNode)
163 Trace("SUPERVGUI_CanvasGotoNode::SUPERVGUI_CanvasGotoNode");
166 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasGotoNode::createPrs() const
168 return new SUPERVGUI_CanvasGotoNodePrs(getMain()->getCanvas(),
169 (SUPERVGUI_CanvasGotoNode*)this);
172 QPopupMenu* SUPERVGUI_CanvasGotoNode::getPopupMenu(QWidget* theParent)
174 QPopupMenu* popup = SUPERVGUI_CanvasNode::getPopupMenu(theParent);
176 popup->insertSeparator();
177 popup->insertItem("Link to Node...", this, SLOT(linkToNode()));
179 popup->insertSeparator();
180 int anItem = popup->insertItem(tr("POP_HIDEPORTS"), this, SLOT(switchPorts()));
181 popup->setItemChecked(anItem, !getPrs()->isPortVisible());
186 void SUPERVGUI_CanvasGotoNode::linkToNode() {
187 SUPERVGUI_SelectInlineDlg* aDlg = new SUPERVGUI_SelectInlineDlg(getMain());
189 QString aNodeName = aDlg->getName();
190 if (!aNodeName.isEmpty()) { //implement additional check from GUI side for bug PAL7007
191 getGotoNode()->SetCoupled(aNodeName.latin1());
192 getMain()->getCanvas()->sync();
198 //=====================================================================
200 //=====================================================================
201 SUPERVGUI_CanvasMacroNode::SUPERVGUI_CanvasMacroNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
202 SUPERVGUI_CanvasComputeNode(theParent, theMain, theNode)
204 Trace("SUPERVGUI_CanvasMacroNode::SUPERVGUI_CanvasMacroNode");
207 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasMacroNode::createPrs() const
209 return new SUPERVGUI_CanvasMacroNodePrs(getMain()->getCanvas(),
210 (SUPERVGUI_CanvasMacroNode*)this);
213 QPopupMenu* SUPERVGUI_CanvasMacroNode::getPopupMenu(QWidget* theParent)
215 QPopupMenu* popup = SUPERVGUI_CanvasComputeNode::getPopupMenu(theParent);
217 popup->insertSeparator(0);
218 popup->insertItem(tr("MSG_EXPORT"), this, SLOT(exportDataflow()), 0, -1, 0);
219 popup->insertItem("Open SubGraph", this, SLOT(openSubGraph()), 0, -1, 0);
224 void SUPERVGUI_CanvasMacroNode::openSubGraph()
226 getMain()->openSubGraph(getEngine());
229 void SUPERVGUI_CanvasMacroNode::exportDataflow()
232 if (getEngine()->IsMacro()) {
233 SUPERV_Graph aMacro = getMacroNode();
234 if (aMacro->IsStreamMacro())
235 aGraph = aMacro->StreamObjRef();
237 aGraph = aMacro->FlowObjRef();
239 if (SUPERV_isNull(aGraph)) {
240 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_EXPORT"));
244 QString aFileName = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
247 tr("TTL_EXPORT_DATAFLOW"),
249 if ( !aFileName.isEmpty() ) {
250 // asv : bug [VSR Bugs and Improvements in Supervisor] 1.8 : when exporting a file,
251 // a backup copy of an existing file must be created (in case Export fails..)
252 QString aBackupFile = SUPERVGUI::createBackupFile( aFileName );
254 if (!aGraph->Export(aFileName.latin1())) {
255 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_WRITING").arg(aBackupFile));
257 // remove a backup file if export was successfull
258 else if ( !aBackupFile.isNull() && !aBackupFile.isEmpty() ) {
259 QFile::remove( aBackupFile );
265 //=====================================================================
266 // Cell node: node for table view
267 //=====================================================================
268 SUPERVGUI_CanvasCellNode::SUPERVGUI_CanvasCellNode(QObject* theParent,
269 SUPERVGUI_Main* theMain,
270 SUPERV_CNode theNode):
271 SUPERVGUI_CanvasNode(theParent, theMain, theNode, true)
273 Trace("SUPERVGUI_CanvasCellNode::SUPERVGUI_CanvasCellNode");
278 //check for control nodes
279 if (getEngine()->IsLoop() || getEngine()->IsSwitch()) {
283 if (getEngine()->IsEndLoop() || getEngine()->IsEndSwitch())
287 QPopupMenu* SUPERVGUI_CanvasCellNode::getPopupMenu(QWidget* theParent)
289 QPopupMenu* popup = SUPERVGUI_CanvasNode::getPopupMenu(theParent);
290 popup->setItemEnabled(myDeleteItem, false);
294 void SUPERVGUI_CanvasCellNode::setPairCell(SUPERVGUI_CanvasCellNode* thePairCell) {
295 if (myIsControl) { //only for ControlNode
296 myPairCell = thePairCell;
302 SUPERVGUI_CanvasCellNode* SUPERVGUI_CanvasCellNode::getPairCell() {
306 void SUPERVGUI_CanvasCellNode::sync() {
307 MESSAGE("===> SUPERVGUI_CanvasCellNode::sync() " << getEngine()->Name() << ", state " << getEngine()->State());
309 const bool isExecuting = getMain()->getDataflow()->IsExecuting();
310 //if getEngine() is a MacroNode then set it state to state of its subgraph
311 if ( getEngine()->IsMacro() && isExecuting ) {
312 // get SubGraph from MacroNode
313 SUPERV_Graph aMacro = SUPERV::Graph::_narrow(getEngine());
314 if (!SUPERV_isNull(aMacro)) {
316 if (aMacro->IsStreamMacro())
317 aGraph = aMacro->StreamObjRef();
319 aGraph = aMacro->FlowObjRef();
320 if (!SUPERV_isNull(aGraph)) {
321 if (aGraph->State() != SUPERV::UndefinedState && aGraph->State() != SUPERV::NoState)
322 getPrs()->setState(aGraph->State());
324 getPrs()->setState(getEngine()->State());
329 getPrs()->setState(getEngine()->State());
333 /*bool SUPERVGUI_CanvasCellNode::setNodeName(QString aName)
335 bool result = SUPERVGUI_CanvasNode::setNodeName(aName);
336 if (result && myPairCell) {
337 result = myPairCell->getEngine()->SetName((QString(tr("ENDNODE_PREFIX"))+aName).latin1());
339 setName(myPairCell->getEngine()->Name());
340 myPairCell->getPrs()->updateInfo();
343 QMessageBox::warning( QAD_Application::getDesktop(), tr( "ERROR" ), tr( "MSG_CANT_RENAMENODE" ) );
349 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasCellNode::createPrs() const
351 MESSAGE(" -> SUPERVGUI_CanvasCellNode::createPrs()");
352 SUPERVGUI_CanvasNodePrs* aPrs =
353 new SUPERVGUI_CanvasCellNodePrs(getMain()->getCanvasArray(),
354 (SUPERVGUI_CanvasCellNode*)this);
355 MESSAGE(" -> SUPERVGUI_CanvasCellNode::createPrs() 11");
359 SUPERVGUI_CanvasCellEndNode::SUPERVGUI_CanvasCellEndNode( QObject* theParent,
360 SUPERVGUI_Main* theMain,
361 SUPERV_CNode theNode,
362 SUPERVGUI_CanvasCellNode* theStart):
363 SUPERVGUI_CanvasCellNode(theParent, theMain, theNode)
365 //set start cell for end cell as pair
366 myPairCell = theStart;
367 //set end cell for start cell as pair
368 myPairCell->setPairCell(dynamic_cast<SUPERVGUI_CanvasCellNode*>(this));