1 // SUPERV SUPERVGUI : GUI for Supervisor component
3 // Copyright (C) 2003 OPEN CASCADE
5 // File : SUPERVGUI_CanvasControlNode.cxx
6 // Author : Natalia KOPNOVA
9 #include "SUPERVGUI_CanvasControlNode.h"
10 #include "SUPERVGUI_CanvasControlNodePrs.h"
11 #include "SUPERVGUI_CanvasCellNodePrs.h"
12 #include "SUPERVGUI_Clipboard.h"
13 #include "SUPERVGUI_Main.h"
14 #include "SUPERVGUI.h"
15 #include "SUPERVGUI_Canvas.h"
17 #include "SUIT_FileDlg.h"
18 #include "SUIT_Session.h"
23 //=====================================================================
25 //=====================================================================
26 SUPERVGUI_CanvasComputeNode::SUPERVGUI_CanvasComputeNode( SUIT_ResourceMgr* mgr, QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
27 SUPERVGUI_CanvasNode( mgr, 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(SUIT_ResourceMgr* mgr, QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
54 SUPERVGUI_CanvasNode( mgr, theParent, theMain, theNode),
57 Trace("SUPERVGUI_CanvasStartNode::SUPERVGUI_CanvasStartNode");
60 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasStartNode::createPrs() const
62 return new SUPERVGUI_CanvasStartNodePrs( resMgr(), 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 // mkr : IPAL9815 : commented the following code
136 /*void SUPERVGUI_CanvasStartNode::addInputPort()
138 SUPERVGUI_CanvasNode::addInputPort();
139 if (getEngine()->IsLoop()) merge();
140 if (myCoupled) myCoupled->merge();
143 void SUPERVGUI_CanvasStartNode::addOutputPort()
145 SUPERVGUI_CanvasNode::addOutputPort();
146 if (myCoupled) myCoupled->merge();
149 void SUPERVGUI_CanvasStartNode::pastePort()
151 SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard();
152 SUPERVGUI_CanvasNode::pastePort();
153 if ( aCB->getCopyPort()->IsInput() && getEngine()->IsLoop() )
159 //=====================================================================
161 //=====================================================================
162 SUPERVGUI_CanvasEndNode::SUPERVGUI_CanvasEndNode(SUIT_ResourceMgr* mgr, QObject* theParent, SUPERVGUI_Main* theMain,
163 SUPERV_CNode theNode, SUPERVGUI_CanvasStartNode* theStart):
164 SUPERVGUI_CanvasNode(mgr, theParent, theMain, theNode),
167 Trace("SUPERVGUI_CanvasEndNode::SUPERVGUI_CanvasEndNode");
168 myCoupled->setCoupled(this);
171 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasEndNode::createPrs() const
173 return new SUPERVGUI_CanvasEndNodePrs( resMgr(), getMain()->getCanvas(),
174 (SUPERVGUI_CanvasEndNode*)this);
177 QPopupMenu* SUPERVGUI_CanvasEndNode::getPopupMenu(QWidget* theParent)
179 QPopupMenu* popup = SUPERVGUI_CanvasNode::getPopupMenu(theParent);
181 popup->insertSeparator();
182 int anItem = popup->insertItem(tr("POP_HIDEPORTS"), this, SLOT(switchPorts()));
183 popup->setItemChecked(anItem, !getPrs()->isPortVisible());
188 // mkr : IPAL9815 : commented the following code
189 /*void SUPERVGUI_CanvasEndNode::addInputPort()
191 SUPERVGUI_CanvasNode::addInputPort();
192 if (getEngine()->IsEndSwitch()) merge();
196 //=====================================================================
198 //=====================================================================
199 SUPERVGUI_CanvasGotoNode::SUPERVGUI_CanvasGotoNode(SUIT_ResourceMgr* mgr, QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
200 SUPERVGUI_CanvasNode(mgr, theParent, theMain, theNode)
202 Trace("SUPERVGUI_CanvasGotoNode::SUPERVGUI_CanvasGotoNode");
205 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasGotoNode::createPrs() const
207 return new SUPERVGUI_CanvasGotoNodePrs( resMgr(), getMain()->getCanvas(),
208 (SUPERVGUI_CanvasGotoNode*)this);
211 QPopupMenu* SUPERVGUI_CanvasGotoNode::getPopupMenu(QWidget* theParent)
213 QPopupMenu* popup = SUPERVGUI_CanvasNode::getPopupMenu(theParent);
215 popup->insertSeparator();
216 popup->insertItem("Link to Node...", this, SLOT(linkToNode()));
218 popup->insertSeparator();
219 int anItem = popup->insertItem(tr("POP_HIDEPORTS"), this, SLOT(switchPorts()));
220 popup->setItemChecked(anItem, !getPrs()->isPortVisible());
225 void SUPERVGUI_CanvasGotoNode::linkToNode() {
226 SUPERVGUI_SelectInlineDlg* aDlg = new SUPERVGUI_SelectInlineDlg(getMain());
228 QString aNodeName = aDlg->getName();
229 if (!aNodeName.isEmpty()) { //implement additional check from GUI side for bug PAL7007
230 getGotoNode()->SetCoupled(aNodeName.latin1());
231 getMain()->getCanvas()->sync();
237 //=====================================================================
239 //=====================================================================
240 SUPERVGUI_CanvasMacroNode::SUPERVGUI_CanvasMacroNode(SUIT_ResourceMgr* mgr, QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
241 SUPERVGUI_CanvasComputeNode(mgr, theParent, theMain, theNode)
243 Trace("SUPERVGUI_CanvasMacroNode::SUPERVGUI_CanvasMacroNode");
246 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasMacroNode::createPrs() const
248 return new SUPERVGUI_CanvasMacroNodePrs( resMgr(), getMain()->getCanvas(),
249 (SUPERVGUI_CanvasMacroNode*)this);
252 QPopupMenu* SUPERVGUI_CanvasMacroNode::getPopupMenu(QWidget* theParent)
254 QPopupMenu* popup = SUPERVGUI_CanvasComputeNode::getPopupMenu(theParent);
256 popup->insertSeparator(0);
257 popup->insertItem(tr("MSG_EXPORT"), this, SLOT(exportDataflow()), 0, -1, 0);
258 popup->insertItem("Open SubGraph", this, SLOT(openSubGraph()), 0, -1, 0);
263 void SUPERVGUI_CanvasMacroNode::openSubGraph()
265 getMain()->openSubGraph(getEngine());
268 void SUPERVGUI_CanvasMacroNode::exportDataflow()
271 if (getEngine()->IsMacro()) {
272 SUPERV_Graph aMacro = getMacroNode();
273 if (aMacro->IsStreamMacro())
274 aGraph = aMacro->StreamObjRef();
276 aGraph = aMacro->FlowObjRef();
278 if (SUPERV_isNull(aGraph)) {
279 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_EXPORT"));
283 QString aFileName = SUIT_FileDlg::getFileName(SUIT_Session::session()->activeApplication()->desktop(),
286 tr("TTL_EXPORT_DATAFLOW"),
288 if ( !aFileName.isEmpty() ) {
289 // asv : bug [VSR Bugs and Improvements in Supervisor] 1.8 : when exporting a file,
290 // a backup copy of an existing file must be created (in case Export fails..)
291 QString aBackupFile = SUPERVGUI::createBackupFile( aFileName );
293 if (!aGraph->Export(aFileName.latin1())) {
294 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_BAD_WRITING").arg(aBackupFile));
296 // remove a backup file if export was successfull
297 else if ( !aBackupFile.isNull() && !aBackupFile.isEmpty() ) {
298 QFile::remove( aBackupFile );
304 //=====================================================================
305 // Cell node: node for table view
306 //=====================================================================
307 SUPERVGUI_CanvasCellNode::SUPERVGUI_CanvasCellNode(SUIT_ResourceMgr* mgr, QObject* theParent,
308 SUPERVGUI_Main* theMain,
309 SUPERV_CNode theNode):
310 SUPERVGUI_CanvasNode(mgr, theParent, theMain, theNode, true)
312 Trace("SUPERVGUI_CanvasCellNode::SUPERVGUI_CanvasCellNode");
317 //check for control nodes
318 if (getEngine()->IsLoop() || getEngine()->IsSwitch()) {
322 if (getEngine()->IsEndLoop() || getEngine()->IsEndSwitch())
326 SUPERVGUI_CanvasCellNode::~SUPERVGUI_CanvasCellNode()
330 QPopupMenu* SUPERVGUI_CanvasCellNode::getPopupMenu(QWidget* theParent)
332 QPopupMenu* popup = SUPERVGUI_CanvasNode::getPopupMenu(theParent);
333 popup->setItemEnabled(myDeleteItem, false);
337 void SUPERVGUI_CanvasCellNode::setPairCell(SUPERVGUI_CanvasCellNode* thePairCell) {
338 if (myIsControl) { //only for ControlNode
339 myPairCell = thePairCell;
345 SUPERVGUI_CanvasCellNode* SUPERVGUI_CanvasCellNode::getPairCell() {
349 void SUPERVGUI_CanvasCellNode::sync() {
350 const bool isExecuting = getMain()->getDataflow()->IsExecuting();
351 //if getEngine() is a MacroNode then set it state to state of its subgraph
352 if ( getEngine()->IsMacro() && isExecuting ) {
353 // get SubGraph from MacroNode
354 SUPERV_Graph aMacro = SUPERV::Graph::_narrow(getEngine());
355 if (!SUPERV_isNull(aMacro)) {
357 if (aMacro->IsStreamMacro())
358 aGraph = aMacro->StreamObjRef();
360 aGraph = aMacro->FlowObjRef();
361 if (!SUPERV_isNull(aGraph)) {
362 if (aGraph->State() != SUPERV::UndefinedState && aGraph->State() != SUPERV::NoState)
363 getPrs()->setState(aGraph->State());
365 getPrs()->setState(getEngine()->State());
370 getPrs()->setState(getEngine()->State());
374 bool SUPERVGUI_CanvasCellNode::setNodeName(QString aName)
376 bool result = SUPERVGUI_CanvasNode::setNodeName(aName);
377 if (result && myPairCell) {
378 result = myPairCell->setNodeName(QString(tr("ENDNODE_PREFIX"))+aName);
383 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasCellNode::createPrs() const
385 SUPERVGUI_CanvasNodePrs* aPrs =
386 new SUPERVGUI_CanvasCellNodePrs( resMgr(), getMain()->getCanvasArray(),
387 (SUPERVGUI_CanvasCellNode*)this);
391 SUPERVGUI_CanvasCellEndNode::SUPERVGUI_CanvasCellEndNode( SUIT_ResourceMgr* mgr, QObject* theParent,
392 SUPERVGUI_Main* theMain,
393 SUPERV_CNode theNode,
394 SUPERVGUI_CanvasCellNode* theStart):
395 SUPERVGUI_CanvasCellNode(mgr, theParent, theMain, theNode)
397 //set start cell for end cell as pair
398 myPairCell = theStart;
399 //set end cell for start cell as pair
400 myPairCell->setPairCell(dynamic_cast<SUPERVGUI_CanvasCellNode*>(this));
403 bool SUPERVGUI_CanvasCellEndNode::setNodeName(QString theName)
405 return SUPERVGUI_CanvasNode::setNodeName(theName);
408 //-----------------------------------------------------------
409 //*************** Select Inline node dialog******************
410 // Taken from SUPERVGUI_ControlNode.cxx without change
411 //-----------------------------------------------------------
413 SUPERVGUI_SelectInlineDlg::SUPERVGUI_SelectInlineDlg(SUPERVGUI_Main* theMain)
414 :QDialog(theMain, 0, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
416 setSizeGripEnabled( true );
417 setCaption(tr("TIT_FUNC_PYTHON"));
418 QGridLayout* aMainLayout = new QGridLayout(this, 2, 2, 7, 4);
420 QLabel* aLabel = new QLabel("Connect to", this );
421 aMainLayout->addWidget(aLabel, 0, 0);
423 myCombo = new QComboBox(this);
424 myCombo->clear(); //for the additional check from GUI side for bug PAL7007
425 SUPERV_Nodes aNodesList = theMain->getDataflow()->Nodes();
427 for (i = 0; i < aNodesList->INodes.length(); i++) {
428 myCombo->insertItem(QString(aNodesList->INodes[i]->Name()));
430 for (i = 0; i < aNodesList->LNodes.length(); i++) {
431 myCombo->insertItem(QString(aNodesList->LNodes[i]->Name()));
433 for (i = 0; i < aNodesList->SNodes.length(); i++) {
434 myCombo->insertItem(QString(aNodesList->SNodes[i]->Name()));
436 aMainLayout->addWidget(myCombo, 0, 1);
438 QGroupBox* aBtnBox = new QGroupBox( this );
439 aBtnBox->setColumnLayout( 0, Qt::Vertical );
440 aBtnBox->layout()->setSpacing( 0 ); aBtnBox->layout()->setMargin( 0 );
441 QHBoxLayout* aBtnLayout = new QHBoxLayout( aBtnBox->layout() );
442 aBtnLayout->setAlignment( Qt::AlignTop );
443 aBtnLayout->setSpacing( 6 ); aBtnLayout->setMargin( 11 );
445 QPushButton* aOKBtn = new QPushButton( tr( "BUT_OK" ), aBtnBox );
446 connect( aOKBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
447 aBtnLayout->addWidget( aOKBtn );
449 aBtnLayout->addStretch();
451 QPushButton* aCancelBtn = new QPushButton( tr("BUT_CANCEL"), aBtnBox );
452 connect( aCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
453 aBtnLayout->addWidget( aCancelBtn );
455 aMainLayout->addMultiCellWidget(aBtnBox, 1, 1, 0, 1);