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_Main.h"
13 #include "SUPERVGUI.h"
14 #include "SUPERVGUI_Canvas.h"
15 #include "SUPERVGUI_ControlNode.h" // access to SelectInlineDlg
17 #include "QAD_FileDlg.h"
18 #include "QAD_Application.h"
20 //=====================================================================
22 //=====================================================================
23 SUPERVGUI_CanvasComputeNode::SUPERVGUI_CanvasComputeNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
24 SUPERVGUI_CanvasNode(theParent, theMain, theNode)
26 Trace("SUPERVGUI_CanvasComputeNode::SUPERVGUI_CanvasComputeNode");
29 QPopupMenu* SUPERVGUI_CanvasComputeNode::getPopupMenu(QWidget* theParent)
31 QPopupMenu* popup = SUPERVGUI_CanvasNode::getPopupMenu(theParent);
33 QPopupMenu* aShowPopup = new QPopupMenu(theParent);
35 anItem = aShowPopup->insertItem(tr("POP_SHOWTITLES"), this, SLOT(switchLabel()));
36 aShowPopup->setItemChecked(anItem, getPrs()->isLabelVisible());
37 anItem = aShowPopup->insertItem(tr("POP_SHOWPORTS"), this, SLOT(switchPorts()));
38 aShowPopup->setItemChecked(anItem, getPrs()->isPortVisible());
40 popup->insertSeparator();
41 popup->insertItem(tr("POP_SHOW"), aShowPopup);
47 //=====================================================================
49 //=====================================================================
50 SUPERVGUI_CanvasStartNode::SUPERVGUI_CanvasStartNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
51 SUPERVGUI_CanvasNode(theParent, theMain, theNode),
54 Trace("SUPERVGUI_CanvasStartNode::SUPERVGUI_CanvasStartNode");
57 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasStartNode::createPrs() const
59 return new SUPERVGUI_CanvasStartNodePrs(getMain()->getCanvas(),
60 (SUPERVGUI_CanvasStartNode*)this);
63 bool SUPERVGUI_CanvasStartNode::setNodeName(QString aName)
65 bool result = SUPERVGUI_CanvasNode::setNodeName(aName);
66 if (result && myCoupled) {
67 myCoupled->setNodeName(QString(tr("ENDNODE_PREFIX"))+aName);
72 QPopupMenu* SUPERVGUI_CanvasStartNode::getPopupMenu(QWidget* theParent)
74 QPopupMenu* popup = SUPERVGUI_CanvasNode::getPopupMenu(theParent);
76 popup->insertSeparator();
77 int anItem = popup->insertItem(tr("POP_HIDEPORTS"), this, SLOT(switchPorts()));
78 popup->setItemChecked(anItem, !getPrs()->isPortVisible());
83 void SUPERVGUI_CanvasStartNode::remove()
85 SUPERVGUI_Canvas* aCanvas = getMain()->getCanvas();
88 if (myCoupled) myCoupled->setDestroyed();
90 getEngine()->destroy();
92 if (myCoupled) delete myCoupled;
98 void SUPERVGUI_CanvasStartNode::onDestroyed(QObject* theObject)
101 SUPERVGUI_CanvasNode::onDestroyed(theObject);
102 if (getEngine()->IsLoop()) merge();
103 if (myCoupled) myCoupled->merge();
107 void SUPERVGUI_CanvasStartNode::addInputPort()
109 SUPERVGUI_CanvasNode::addInputPort();
110 if (getEngine()->IsLoop()) merge();
111 if (myCoupled) myCoupled->merge();
114 void SUPERVGUI_CanvasStartNode::addOutputPort()
116 SUPERVGUI_CanvasNode::addOutputPort();
117 if (myCoupled) myCoupled->merge();
120 //=====================================================================
122 //=====================================================================
123 SUPERVGUI_CanvasEndNode::SUPERVGUI_CanvasEndNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode,
124 SUPERVGUI_CanvasStartNode* theStart):
125 SUPERVGUI_CanvasNode(theParent, theMain, theNode),
128 Trace("SUPERVGUI_CanvasEndNode::SUPERVGUI_CanvasEndNode");
129 myCoupled->setCoupled(this);
132 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasEndNode::createPrs() const
134 return new SUPERVGUI_CanvasEndNodePrs(getMain()->getCanvas(),
135 (SUPERVGUI_CanvasEndNode*)this);
138 QPopupMenu* SUPERVGUI_CanvasEndNode::getPopupMenu(QWidget* theParent)
140 QPopupMenu* popup = SUPERVGUI_CanvasNode::getPopupMenu(theParent);
142 popup->insertSeparator();
143 int anItem = popup->insertItem(tr("POP_HIDEPORTS"), this, SLOT(switchPorts()));
144 popup->setItemChecked(anItem, !getPrs()->isPortVisible());
149 void SUPERVGUI_CanvasEndNode::addInputPort()
151 SUPERVGUI_CanvasNode::addInputPort();
152 if (getEngine()->IsEndSwitch()) merge();
156 //=====================================================================
158 //=====================================================================
159 SUPERVGUI_CanvasGotoNode::SUPERVGUI_CanvasGotoNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
160 SUPERVGUI_CanvasNode(theParent, theMain, theNode)
162 Trace("SUPERVGUI_CanvasGotoNode::SUPERVGUI_CanvasGotoNode");
165 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasGotoNode::createPrs() const
167 return new SUPERVGUI_CanvasGotoNodePrs(getMain()->getCanvas(),
168 (SUPERVGUI_CanvasGotoNode*)this);
171 QPopupMenu* SUPERVGUI_CanvasGotoNode::getPopupMenu(QWidget* theParent)
173 QPopupMenu* popup = SUPERVGUI_CanvasNode::getPopupMenu(theParent);
175 popup->insertSeparator();
176 popup->insertItem("Link to Node...", this, SLOT(linkToNode()));
178 popup->insertSeparator();
179 int anItem = popup->insertItem(tr("POP_HIDEPORTS"), this, SLOT(switchPorts()));
180 popup->setItemChecked(anItem, !getPrs()->isPortVisible());
185 void SUPERVGUI_CanvasGotoNode::linkToNode() {
186 SUPERVGUI_SelectInlineDlg* aDlg = new SUPERVGUI_SelectInlineDlg(getMain());
188 QString aNodeName = aDlg->getName();
189 if (!aNodeName.isEmpty()) { //implement additional check from GUI side for bug PAL7007
190 getGotoNode()->SetCoupled(aNodeName.latin1());
191 getMain()->getCanvas()->sync();
197 //=====================================================================
199 //=====================================================================
200 SUPERVGUI_CanvasMacroNode::SUPERVGUI_CanvasMacroNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
201 SUPERVGUI_CanvasComputeNode(theParent, theMain, theNode)
203 Trace("SUPERVGUI_CanvasMacroNode::SUPERVGUI_CanvasMacroNode");
206 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasMacroNode::createPrs() const
208 return new SUPERVGUI_CanvasMacroNodePrs(getMain()->getCanvas(),
209 (SUPERVGUI_CanvasMacroNode*)this);
212 QPopupMenu* SUPERVGUI_CanvasMacroNode::getPopupMenu(QWidget* theParent)
214 QPopupMenu* popup = SUPERVGUI_CanvasComputeNode::getPopupMenu(theParent);
216 popup->insertSeparator(0);
217 popup->insertItem(tr("MSG_EXPORT"), this, SLOT(exportDataflow()), 0, -1, 0);
218 popup->insertItem("Open SubGraph", this, SLOT(openSubGraph()), 0, -1, 0);
223 void SUPERVGUI_CanvasMacroNode::openSubGraph()
225 getMain()->openSubGraph(getEngine());
228 void SUPERVGUI_CanvasMacroNode::exportDataflow()
231 if (getEngine()->IsMacro()) {
232 SUPERV_Graph aMacro = getMacroNode();
233 if (aMacro->IsStreamMacro())
234 aGraph = aMacro->StreamObjRef();
236 aGraph = aMacro->FlowObjRef();
238 if (SUPERV_isNull(aGraph)) {
239 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_EXPORT"));
243 QString aFileName = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
246 tr("TTL_EXPORT_DATAFLOW"),
248 if ( !aFileName.isEmpty() ) {
249 // asv : bug [VSR Bugs and Improvements in Supervisor] 1.8 : when exporting a file,
250 // a backup copy of an existing file must be created (in case Export fails..)
251 QString aBackupFile = SUPERVGUI::createBackupFile( aFileName );
253 if (!aGraph->Export(aFileName.latin1())) {
254 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_WRITING").arg(aBackupFile));
256 // remove a backup file if export was successfull
257 else if ( !aBackupFile.isNull() && !aBackupFile.isEmpty() ) {
258 QFile::remove( aBackupFile );