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_Clipboard.h"
14 #include "SUPERVGUI_Main.h"
15 #include "SUPERVGUI.h"
16 #include "SUPERVGUI_Canvas.h"
18 #include "QAD_FileDlg.h"
19 #include "QAD_Application.h"
23 //=====================================================================
25 //=====================================================================
26 SUPERVGUI_CanvasComputeNode::SUPERVGUI_CanvasComputeNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
27 SUPERVGUI_CanvasNode(theParent, theMain, theNode)
29 Trace("SUPERVGUI_CanvasComputeNode::SUPERVGUI_CanvasComputeNode");
32 QPopupMenu* SUPERVGUI_CanvasComputeNode::getPopupMenu(QWidget* theParent)
34 QPopupMenu* popup = SUPERVGUI_CanvasNode::getPopupMenu(theParent);
36 QPopupMenu* aShowPopup = new QPopupMenu(theParent);
38 anItem = aShowPopup->insertItem(tr("POP_SHOWTITLES"), this, SLOT(switchLabel()));
39 aShowPopup->setItemChecked(anItem, getPrs()->isLabelVisible());
40 anItem = aShowPopup->insertItem(tr("POP_SHOWPORTS"), this, SLOT(switchPorts()));
41 aShowPopup->setItemChecked(anItem, getPrs()->isPortVisible());
43 popup->insertSeparator();
44 popup->insertItem(tr("POP_SHOW"), aShowPopup);
50 //=====================================================================
52 //=====================================================================
53 SUPERVGUI_CanvasStartNode::SUPERVGUI_CanvasStartNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
54 SUPERVGUI_CanvasNode(theParent, theMain, theNode),
57 Trace("SUPERVGUI_CanvasStartNode::SUPERVGUI_CanvasStartNode");
60 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasStartNode::createPrs() const
62 return new SUPERVGUI_CanvasStartNodePrs(getMain()->getCanvas(),
63 (SUPERVGUI_CanvasStartNode*)this);
66 bool SUPERVGUI_CanvasStartNode::setNodeName(QString aName)
68 bool result = SUPERVGUI_CanvasNode::setNodeName(aName);
69 if (result && myCoupled) {
70 myCoupled->setNodeName(QString(tr("ENDNODE_PREFIX"))+aName);
75 QPopupMenu* SUPERVGUI_CanvasStartNode::getPopupMenu(QWidget* theParent)
77 QPopupMenu* popup = SUPERVGUI_CanvasNode::getPopupMenu(theParent);
79 popup->insertSeparator();
80 int anItem = popup->insertItem(tr("POP_HIDEPORTS"), this, SLOT(switchPorts()));
81 popup->setItemChecked(anItem, !getPrs()->isPortVisible());
86 void SUPERVGUI_CanvasStartNode::remove()
88 SUPERVGUI_Canvas* aCanvas = getMain()->getCanvas();
91 SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard();
94 //set myCopyPort from Main object to empty if engine of this port is deleted
95 //check if any port of this deleted node has been copied
96 if ( aCB->isCopyPort() )
97 if ( QString(getEngine()->Name()) == QString(aCB->getCopyPort()->Node()->Name()) ||
98 QString(myCoupled->getEngine()->Name()) == QString(aCB->getCopyPort()->Node()->Name()) )
99 aCB->setCopyPort( 0 );
101 myCoupled->setDestroyed();
104 //set myCopyNode from Main object to empty if engine of this node is deleted
105 //check if myCopyNode and this node engine is equal
106 if ( aCB->isCopyNode() )
107 if ( QString(getEngine()->Name()) == QString(aCB->getCopyNode()->Name()) )
108 aCB->setCopyNode( 0 );
110 // mkr: since the deletion of the node allow only in CANVAS view,
111 // it is necessary to remove the CanvasArray's children, which
112 // have the same CNode engine as deleting node
113 getMain()->removeArrayChild(getEngine());
114 getMain()->removeArrayChild(myCoupled->getEngine());
116 getEngine()->destroy();
126 void SUPERVGUI_CanvasStartNode::onDestroyed(QObject* theObject)
129 SUPERVGUI_CanvasNode::onDestroyed(theObject);
130 if (getEngine()->IsLoop()) merge();
131 if (myCoupled) myCoupled->merge();
135 void SUPERVGUI_CanvasStartNode::addInputPort()
137 SUPERVGUI_CanvasNode::addInputPort();
138 if (getEngine()->IsLoop()) merge();
139 if (myCoupled) myCoupled->merge();
142 void SUPERVGUI_CanvasStartNode::addOutputPort()
144 SUPERVGUI_CanvasNode::addOutputPort();
145 if (myCoupled) myCoupled->merge();
148 void SUPERVGUI_CanvasStartNode::pastePort()
150 SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard();
151 SUPERVGUI_CanvasNode::pastePort();
152 if ( aCB->getCopyPort()->IsInput() && getEngine()->IsLoop() )
158 //=====================================================================
160 //=====================================================================
161 SUPERVGUI_CanvasEndNode::SUPERVGUI_CanvasEndNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode,
162 SUPERVGUI_CanvasStartNode* theStart):
163 SUPERVGUI_CanvasNode(theParent, theMain, theNode),
166 Trace("SUPERVGUI_CanvasEndNode::SUPERVGUI_CanvasEndNode");
167 myCoupled->setCoupled(this);
170 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasEndNode::createPrs() const
172 return new SUPERVGUI_CanvasEndNodePrs(getMain()->getCanvas(),
173 (SUPERVGUI_CanvasEndNode*)this);
176 QPopupMenu* SUPERVGUI_CanvasEndNode::getPopupMenu(QWidget* theParent)
178 QPopupMenu* popup = SUPERVGUI_CanvasNode::getPopupMenu(theParent);
180 popup->insertSeparator();
181 int anItem = popup->insertItem(tr("POP_HIDEPORTS"), this, SLOT(switchPorts()));
182 popup->setItemChecked(anItem, !getPrs()->isPortVisible());
187 void SUPERVGUI_CanvasEndNode::addInputPort()
189 SUPERVGUI_CanvasNode::addInputPort();
190 if (getEngine()->IsEndSwitch()) merge();
194 //=====================================================================
196 //=====================================================================
197 SUPERVGUI_CanvasGotoNode::SUPERVGUI_CanvasGotoNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
198 SUPERVGUI_CanvasNode(theParent, theMain, theNode)
200 Trace("SUPERVGUI_CanvasGotoNode::SUPERVGUI_CanvasGotoNode");
203 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasGotoNode::createPrs() const
205 return new SUPERVGUI_CanvasGotoNodePrs(getMain()->getCanvas(),
206 (SUPERVGUI_CanvasGotoNode*)this);
209 QPopupMenu* SUPERVGUI_CanvasGotoNode::getPopupMenu(QWidget* theParent)
211 QPopupMenu* popup = SUPERVGUI_CanvasNode::getPopupMenu(theParent);
213 popup->insertSeparator();
214 popup->insertItem("Link to Node...", this, SLOT(linkToNode()));
216 popup->insertSeparator();
217 int anItem = popup->insertItem(tr("POP_HIDEPORTS"), this, SLOT(switchPorts()));
218 popup->setItemChecked(anItem, !getPrs()->isPortVisible());
223 void SUPERVGUI_CanvasGotoNode::linkToNode() {
224 SUPERVGUI_SelectInlineDlg* aDlg = new SUPERVGUI_SelectInlineDlg(getMain());
226 QString aNodeName = aDlg->getName();
227 if (!aNodeName.isEmpty()) { //implement additional check from GUI side for bug PAL7007
228 getGotoNode()->SetCoupled(aNodeName.latin1());
229 getMain()->getCanvas()->sync();
235 //=====================================================================
237 //=====================================================================
238 SUPERVGUI_CanvasMacroNode::SUPERVGUI_CanvasMacroNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
239 SUPERVGUI_CanvasComputeNode(theParent, theMain, theNode)
241 Trace("SUPERVGUI_CanvasMacroNode::SUPERVGUI_CanvasMacroNode");
244 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasMacroNode::createPrs() const
246 return new SUPERVGUI_CanvasMacroNodePrs(getMain()->getCanvas(),
247 (SUPERVGUI_CanvasMacroNode*)this);
250 QPopupMenu* SUPERVGUI_CanvasMacroNode::getPopupMenu(QWidget* theParent)
252 QPopupMenu* popup = SUPERVGUI_CanvasComputeNode::getPopupMenu(theParent);
254 popup->insertSeparator(0);
255 popup->insertItem(tr("MSG_EXPORT"), this, SLOT(exportDataflow()), 0, -1, 0);
256 popup->insertItem("Open SubGraph", this, SLOT(openSubGraph()), 0, -1, 0);
261 void SUPERVGUI_CanvasMacroNode::openSubGraph()
263 getMain()->openSubGraph(getEngine());
266 void SUPERVGUI_CanvasMacroNode::exportDataflow()
269 if (getEngine()->IsMacro()) {
270 SUPERV_Graph aMacro = getMacroNode();
271 if (aMacro->IsStreamMacro())
272 aGraph = aMacro->StreamObjRef();
274 aGraph = aMacro->FlowObjRef();
276 if (SUPERV_isNull(aGraph)) {
277 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_EXPORT"));
281 QString aFileName = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
284 tr("TTL_EXPORT_DATAFLOW"),
286 if ( !aFileName.isEmpty() ) {
287 // asv : bug [VSR Bugs and Improvements in Supervisor] 1.8 : when exporting a file,
288 // a backup copy of an existing file must be created (in case Export fails..)
289 QString aBackupFile = SUPERVGUI::createBackupFile( aFileName );
291 if (!aGraph->Export(aFileName.latin1())) {
292 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_WRITING").arg(aBackupFile));
294 // remove a backup file if export was successfull
295 else if ( !aBackupFile.isNull() && !aBackupFile.isEmpty() ) {
296 QFile::remove( aBackupFile );
302 //=====================================================================
303 // Cell node: node for table view
304 //=====================================================================
305 SUPERVGUI_CanvasCellNode::SUPERVGUI_CanvasCellNode(QObject* theParent,
306 SUPERVGUI_Main* theMain,
307 SUPERV_CNode theNode):
308 SUPERVGUI_CanvasNode(theParent, theMain, theNode, true)
310 Trace("SUPERVGUI_CanvasCellNode::SUPERVGUI_CanvasCellNode");
315 //check for control nodes
316 if (getEngine()->IsLoop() || getEngine()->IsSwitch()) {
320 if (getEngine()->IsEndLoop() || getEngine()->IsEndSwitch())
324 SUPERVGUI_CanvasCellNode::~SUPERVGUI_CanvasCellNode()
328 QPopupMenu* SUPERVGUI_CanvasCellNode::getPopupMenu(QWidget* theParent)
330 QPopupMenu* popup = SUPERVGUI_CanvasNode::getPopupMenu(theParent);
331 popup->setItemEnabled(myDeleteItem, false);
335 void SUPERVGUI_CanvasCellNode::setPairCell(SUPERVGUI_CanvasCellNode* thePairCell) {
336 if (myIsControl) { //only for ControlNode
337 myPairCell = thePairCell;
343 SUPERVGUI_CanvasCellNode* SUPERVGUI_CanvasCellNode::getPairCell() {
347 void SUPERVGUI_CanvasCellNode::sync() {
348 const bool isExecuting = getMain()->getDataflow()->IsExecuting();
349 //if getEngine() is a MacroNode then set it state to state of its subgraph
350 if ( getEngine()->IsMacro() && isExecuting ) {
351 // get SubGraph from MacroNode
352 SUPERV_Graph aMacro = SUPERV::Graph::_narrow(getEngine());
353 if (!SUPERV_isNull(aMacro)) {
355 if (aMacro->IsStreamMacro())
356 aGraph = aMacro->StreamObjRef();
358 aGraph = aMacro->FlowObjRef();
359 if (!SUPERV_isNull(aGraph)) {
360 if (aGraph->State() != SUPERV::UndefinedState && aGraph->State() != SUPERV::NoState)
361 getPrs()->setState(aGraph->State());
363 getPrs()->setState(getEngine()->State());
368 getPrs()->setState(getEngine()->State());
372 bool SUPERVGUI_CanvasCellNode::setNodeName(QString aName)
374 bool result = SUPERVGUI_CanvasNode::setNodeName(aName);
375 if (result && myPairCell) {
376 result = myPairCell->setNodeName(QString(tr("ENDNODE_PREFIX"))+aName);
381 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasCellNode::createPrs() const
383 SUPERVGUI_CanvasNodePrs* aPrs =
384 new SUPERVGUI_CanvasCellNodePrs(getMain()->getCanvasArray(),
385 (SUPERVGUI_CanvasCellNode*)this);
389 SUPERVGUI_CanvasCellEndNode::SUPERVGUI_CanvasCellEndNode( QObject* theParent,
390 SUPERVGUI_Main* theMain,
391 SUPERV_CNode theNode,
392 SUPERVGUI_CanvasCellNode* theStart):
393 SUPERVGUI_CanvasCellNode(theParent, theMain, theNode)
395 //set start cell for end cell as pair
396 myPairCell = theStart;
397 //set end cell for start cell as pair
398 myPairCell->setPairCell(dynamic_cast<SUPERVGUI_CanvasCellNode*>(this));
401 bool SUPERVGUI_CanvasCellEndNode::setNodeName(QString theName)
403 return SUPERVGUI_CanvasNode::setNodeName(theName);
406 //-----------------------------------------------------------
407 //*************** Select Inline node dialog******************
408 // Taken from SUPERVGUI_ControlNode.cxx without change
409 //-----------------------------------------------------------
411 SUPERVGUI_SelectInlineDlg::SUPERVGUI_SelectInlineDlg(SUPERVGUI_Main* theMain)
412 :QDialog(theMain, 0, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
414 setSizeGripEnabled( true );
415 setCaption(tr("TIT_FUNC_PYTHON"));
416 QGridLayout* aMainLayout = new QGridLayout(this, 2, 2, 7, 4);
418 QLabel* aLabel = new QLabel("Connect to", this );
419 aMainLayout->addWidget(aLabel, 0, 0);
421 myCombo = new QComboBox(this);
422 myCombo->clear(); //for the additional check from GUI side for bug PAL7007
423 SUPERV_Nodes aNodesList = theMain->getDataflow()->Nodes();
425 for (i = 0; i < aNodesList->INodes.length(); i++) {
426 myCombo->insertItem(QString(aNodesList->INodes[i]->Name()));
428 for (i = 0; i < aNodesList->LNodes.length(); i++) {
429 myCombo->insertItem(QString(aNodesList->LNodes[i]->Name()));
431 for (i = 0; i < aNodesList->SNodes.length(); i++) {
432 myCombo->insertItem(QString(aNodesList->SNodes[i]->Name()));
434 aMainLayout->addWidget(myCombo, 0, 1);
436 QGroupBox* aBtnBox = new QGroupBox( this );
437 aBtnBox->setColumnLayout( 0, Qt::Vertical );
438 aBtnBox->layout()->setSpacing( 0 ); aBtnBox->layout()->setMargin( 0 );
439 QHBoxLayout* aBtnLayout = new QHBoxLayout( aBtnBox->layout() );
440 aBtnLayout->setAlignment( Qt::AlignTop );
441 aBtnLayout->setSpacing( 6 ); aBtnLayout->setMargin( 11 );
443 QPushButton* aOKBtn = new QPushButton( tr( "BUT_OK" ), aBtnBox );
444 connect( aOKBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
445 aBtnLayout->addWidget( aOKBtn );
447 aBtnLayout->addStretch();
449 QPushButton* aCancelBtn = new QPushButton( tr("BUT_CANCEL"), aBtnBox );
450 connect( aCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
451 aBtnLayout->addWidget( aCancelBtn );
453 aMainLayout->addMultiCellWidget(aBtnBox, 1, 1, 0, 1);