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 "SUIT_FileDlg.h"
19 #include "SUIT_Session.h"
24 //=====================================================================
26 //=====================================================================
27 SUPERVGUI_CanvasComputeNode::SUPERVGUI_CanvasComputeNode( SUIT_ResourceMgr* mgr, QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
28 SUPERVGUI_CanvasNode( mgr, theParent, theMain, theNode)
30 Trace("SUPERVGUI_CanvasComputeNode::SUPERVGUI_CanvasComputeNode");
33 QPopupMenu* SUPERVGUI_CanvasComputeNode::getPopupMenu(QWidget* theParent)
35 QPopupMenu* popup = SUPERVGUI_CanvasNode::getPopupMenu(theParent);
37 QPopupMenu* aShowPopup = new QPopupMenu(theParent);
39 anItem = aShowPopup->insertItem(tr("POP_SHOWTITLES"), this, SLOT(switchLabel()));
40 aShowPopup->setItemChecked(anItem, getPrs()->isLabelVisible());
41 anItem = aShowPopup->insertItem(tr("POP_SHOWPORTS"), this, SLOT(switchPorts()));
42 aShowPopup->setItemChecked(anItem, getPrs()->isPortVisible());
44 popup->insertSeparator();
45 popup->insertItem(tr("POP_SHOW"), aShowPopup);
51 //=====================================================================
53 //=====================================================================
54 SUPERVGUI_CanvasStartNode::SUPERVGUI_CanvasStartNode(SUIT_ResourceMgr* mgr, QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
55 SUPERVGUI_CanvasNode( mgr, theParent, theMain, theNode),
58 Trace("SUPERVGUI_CanvasStartNode::SUPERVGUI_CanvasStartNode");
61 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasStartNode::createPrs() const
63 return new SUPERVGUI_CanvasStartNodePrs( resMgr(), getMain()->getCanvas(),
64 (SUPERVGUI_CanvasStartNode*)this);
67 bool SUPERVGUI_CanvasStartNode::setNodeName(QString aName)
69 bool result = SUPERVGUI_CanvasNode::setNodeName(aName);
70 if (result && myCoupled) {
71 myCoupled->setNodeName(QString(tr("ENDNODE_PREFIX"))+aName);
76 QPopupMenu* SUPERVGUI_CanvasStartNode::getPopupMenu(QWidget* theParent)
78 QPopupMenu* popup = SUPERVGUI_CanvasNode::getPopupMenu(theParent);
80 popup->insertSeparator();
81 int anItem = popup->insertItem(tr("POP_HIDEPORTS"), this, SLOT(switchPorts()));
82 popup->setItemChecked(anItem, !getPrs()->isPortVisible());
87 void SUPERVGUI_CanvasStartNode::remove()
89 SUPERVGUI_Canvas* aCanvas = getMain()->getCanvas();
92 SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard();
95 //set myCopyPort from Main object to empty if engine of this port is deleted
96 //check if any port of this deleted node has been copied
97 if ( aCB->isCopyPort() )
98 if ( QString(getEngine()->Name()) == QString(aCB->getCopyPort()->Node()->Name()) ||
99 QString(myCoupled->getEngine()->Name()) == QString(aCB->getCopyPort()->Node()->Name()) )
100 aCB->setCopyPort( 0 );
102 myCoupled->setDestroyed();
105 //set myCopyNode from Main object to empty if engine of this node is deleted
106 //check if myCopyNode and this node engine is equal
107 if ( aCB->isCopyNode() )
108 if ( QString(getEngine()->Name()) == QString(aCB->getCopyNode()->Name()) )
109 aCB->setCopyNode( 0 );
111 // mkr: since the deletion of the node allow only in CANVAS view,
112 // it is necessary to remove the CanvasArray's children, which
113 // have the same CNode engine as deleting node
114 getMain()->removeArrayChild(getEngine());
115 getMain()->removeArrayChild(myCoupled->getEngine());
117 getEngine()->destroy();
127 void SUPERVGUI_CanvasStartNode::onDestroyed(QObject* theObject)
130 SUPERVGUI_CanvasNode::onDestroyed(theObject);
131 if (getEngine()->IsLoop()) merge();
132 if (myCoupled) myCoupled->merge();
136 // mkr : IPAL9815 : commented the following code
137 /*void SUPERVGUI_CanvasStartNode::addInputPort()
139 SUPERVGUI_CanvasNode::addInputPort();
140 if (getEngine()->IsLoop()) merge();
141 if (myCoupled) myCoupled->merge();
144 void SUPERVGUI_CanvasStartNode::addOutputPort()
146 SUPERVGUI_CanvasNode::addOutputPort();
147 if (myCoupled) myCoupled->merge();
150 void SUPERVGUI_CanvasStartNode::pastePort()
152 SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard();
153 SUPERVGUI_CanvasNode::pastePort();
154 if ( aCB->getCopyPort()->IsInput() && getEngine()->IsLoop() )
160 //=====================================================================
162 //=====================================================================
163 SUPERVGUI_CanvasEndNode::SUPERVGUI_CanvasEndNode(SUIT_ResourceMgr* mgr, QObject* theParent, SUPERVGUI_Main* theMain,
164 SUPERV_CNode theNode, SUPERVGUI_CanvasStartNode* theStart):
165 SUPERVGUI_CanvasNode(mgr, theParent, theMain, theNode),
168 Trace("SUPERVGUI_CanvasEndNode::SUPERVGUI_CanvasEndNode");
169 myCoupled->setCoupled(this);
172 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasEndNode::createPrs() const
174 return new SUPERVGUI_CanvasEndNodePrs( resMgr(), getMain()->getCanvas(),
175 (SUPERVGUI_CanvasEndNode*)this);
178 QPopupMenu* SUPERVGUI_CanvasEndNode::getPopupMenu(QWidget* theParent)
180 QPopupMenu* popup = SUPERVGUI_CanvasNode::getPopupMenu(theParent);
182 popup->insertSeparator();
183 int anItem = popup->insertItem(tr("POP_HIDEPORTS"), this, SLOT(switchPorts()));
184 popup->setItemChecked(anItem, !getPrs()->isPortVisible());
189 // mkr : IPAL9815 : commented the following code
190 /*void SUPERVGUI_CanvasEndNode::addInputPort()
192 SUPERVGUI_CanvasNode::addInputPort();
193 if (getEngine()->IsEndSwitch()) merge();
197 //=====================================================================
199 //=====================================================================
200 SUPERVGUI_CanvasGotoNode::SUPERVGUI_CanvasGotoNode(SUIT_ResourceMgr* mgr, QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
201 SUPERVGUI_CanvasNode(mgr, theParent, theMain, theNode)
203 Trace("SUPERVGUI_CanvasGotoNode::SUPERVGUI_CanvasGotoNode");
206 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasGotoNode::createPrs() const
208 return new SUPERVGUI_CanvasGotoNodePrs( resMgr(), getMain()->getCanvas(),
209 (SUPERVGUI_CanvasGotoNode*)this);
212 QPopupMenu* SUPERVGUI_CanvasGotoNode::getPopupMenu(QWidget* theParent)
214 QPopupMenu* popup = SUPERVGUI_CanvasNode::getPopupMenu(theParent);
216 popup->insertSeparator();
217 popup->insertItem("Link to Node...", this, SLOT(linkToNode()));
219 popup->insertSeparator();
220 int anItem = popup->insertItem(tr("POP_HIDEPORTS"), this, SLOT(switchPorts()));
221 popup->setItemChecked(anItem, !getPrs()->isPortVisible());
226 void SUPERVGUI_CanvasGotoNode::linkToNode() {
227 SUPERVGUI_SelectInlineDlg* aDlg = new SUPERVGUI_SelectInlineDlg(getMain());
229 QString aNodeName = aDlg->getName();
230 if (!aNodeName.isEmpty()) { //implement additional check from GUI side for bug PAL7007
231 getGotoNode()->SetCoupled(aNodeName.latin1());
232 getMain()->getCanvas()->sync();
238 //=====================================================================
240 //=====================================================================
241 SUPERVGUI_CanvasMacroNode::SUPERVGUI_CanvasMacroNode(SUIT_ResourceMgr* mgr, QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
242 SUPERVGUI_CanvasComputeNode(mgr, theParent, theMain, theNode)
244 Trace("SUPERVGUI_CanvasMacroNode::SUPERVGUI_CanvasMacroNode");
247 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasMacroNode::createPrs() const
249 return new SUPERVGUI_CanvasMacroNodePrs( resMgr(), getMain()->getCanvas(),
250 (SUPERVGUI_CanvasMacroNode*)this);
253 QPopupMenu* SUPERVGUI_CanvasMacroNode::getPopupMenu(QWidget* theParent)
255 QPopupMenu* popup = SUPERVGUI_CanvasComputeNode::getPopupMenu(theParent);
257 popup->insertSeparator(0);
258 popup->insertItem(tr("MSG_EXPORT"), this, SLOT(exportDataflow()), 0, -1, 0);
259 popup->insertItem("Open SubGraph", this, SLOT(openSubGraph()), 0, -1, 0);
264 void SUPERVGUI_CanvasMacroNode::openSubGraph()
266 getMain()->openSubGraph(getEngine());
269 void SUPERVGUI_CanvasMacroNode::exportDataflow()
272 if (getEngine()->IsMacro()) {
273 SUPERV_Graph aMacro = getMacroNode();
274 if (aMacro->IsStreamMacro())
275 aGraph = aMacro->StreamObjRef();
277 aGraph = aMacro->FlowObjRef();
279 if (SUPERV_isNull(aGraph)) {
280 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_EXPORT"));
284 QString aFileName = SUIT_FileDlg::getFileName(SUIT_Session::session()->activeApplication()->desktop(),
287 tr("TTL_EXPORT_DATAFLOW"),
289 if ( !aFileName.isEmpty() ) {
290 // asv : bug [VSR Bugs and Improvements in Supervisor] 1.8 : when exporting a file,
291 // a backup copy of an existing file must be created (in case Export fails..)
292 QString aBackupFile = SUPERVGUI::createBackupFile( aFileName );
294 if (!aGraph->Export(aFileName.latin1())) {
295 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_BAD_WRITING").arg(aBackupFile));
297 // remove a backup file if export was successfull
298 else if ( !aBackupFile.isNull() && !aBackupFile.isEmpty() ) {
299 QFile::remove( aBackupFile );
305 //=====================================================================
306 // Cell node: node for table view
307 //=====================================================================
308 SUPERVGUI_CanvasCellNode::SUPERVGUI_CanvasCellNode(SUIT_ResourceMgr* mgr, QObject* theParent,
309 SUPERVGUI_Main* theMain,
310 SUPERV_CNode theNode):
311 SUPERVGUI_CanvasNode(mgr, theParent, theMain, theNode, true)
313 Trace("SUPERVGUI_CanvasCellNode::SUPERVGUI_CanvasCellNode");
318 //check for control nodes
319 if (getEngine()->IsLoop() || getEngine()->IsSwitch()) {
323 if (getEngine()->IsEndLoop() || getEngine()->IsEndSwitch())
327 SUPERVGUI_CanvasCellNode::~SUPERVGUI_CanvasCellNode()
331 QPopupMenu* SUPERVGUI_CanvasCellNode::getPopupMenu(QWidget* theParent)
333 QPopupMenu* popup = SUPERVGUI_CanvasNode::getPopupMenu(theParent);
334 popup->setItemEnabled(myDeleteItem, false);
338 void SUPERVGUI_CanvasCellNode::setPairCell(SUPERVGUI_CanvasCellNode* thePairCell) {
339 if (myIsControl) { //only for ControlNode
340 myPairCell = thePairCell;
346 SUPERVGUI_CanvasCellNode* SUPERVGUI_CanvasCellNode::getPairCell() {
350 void SUPERVGUI_CanvasCellNode::sync() {
351 const bool isExecuting = getMain()->getDataflow()->IsExecuting();
352 //if getEngine() is a MacroNode then set it state to state of its subgraph
353 if ( getEngine()->IsMacro() && isExecuting ) {
354 // get SubGraph from MacroNode
355 SUPERV_Graph aMacro = SUPERV::Graph::_narrow(getEngine());
356 if (!SUPERV_isNull(aMacro)) {
358 if (aMacro->IsStreamMacro())
359 aGraph = aMacro->StreamObjRef();
361 aGraph = aMacro->FlowObjRef();
362 if (!SUPERV_isNull(aGraph)) {
363 if (aGraph->State() != SUPERV::UndefinedState && aGraph->State() != SUPERV::NoState)
364 getPrs()->setState(aGraph->State());
366 getPrs()->setState(getEngine()->State());
371 getPrs()->setState(getEngine()->State());
375 bool SUPERVGUI_CanvasCellNode::setNodeName(QString aName)
377 bool result = SUPERVGUI_CanvasNode::setNodeName(aName);
378 if (result && myPairCell) {
379 result = myPairCell->setNodeName(QString(tr("ENDNODE_PREFIX"))+aName);
384 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasCellNode::createPrs() const
386 SUPERVGUI_CanvasNodePrs* aPrs =
387 new SUPERVGUI_CanvasCellNodePrs( resMgr(), getMain()->getCanvasArray(),
388 (SUPERVGUI_CanvasCellNode*)this);
392 SUPERVGUI_CanvasCellEndNode::SUPERVGUI_CanvasCellEndNode( SUIT_ResourceMgr* mgr, QObject* theParent,
393 SUPERVGUI_Main* theMain,
394 SUPERV_CNode theNode,
395 SUPERVGUI_CanvasCellNode* theStart):
396 SUPERVGUI_CanvasCellNode(mgr, theParent, theMain, theNode)
398 //set start cell for end cell as pair
399 myPairCell = theStart;
400 //set end cell for start cell as pair
401 myPairCell->setPairCell(dynamic_cast<SUPERVGUI_CanvasCellNode*>(this));
404 bool SUPERVGUI_CanvasCellEndNode::setNodeName(QString theName)
406 return SUPERVGUI_CanvasNode::setNodeName(theName);
409 //-----------------------------------------------------------
410 //*************** Select Inline node dialog******************
411 // Taken from SUPERVGUI_ControlNode.cxx without change
412 //-----------------------------------------------------------
414 SUPERVGUI_SelectInlineDlg::SUPERVGUI_SelectInlineDlg(SUPERVGUI_Main* theMain)
415 :QDialog(theMain, 0, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
417 setSizeGripEnabled( true );
418 setCaption(tr("TIT_FUNC_PYTHON"));
419 QGridLayout* aMainLayout = new QGridLayout(this, 2, 2, 7, 4);
421 QLabel* aLabel = new QLabel("Connect to", this );
422 aMainLayout->addWidget(aLabel, 0, 0);
424 myCombo = new QComboBox(this);
425 myCombo->clear(); //for the additional check from GUI side for bug PAL7007
426 SUPERV_Nodes aNodesList = theMain->getDataflow()->Nodes();
428 for (i = 0; i < aNodesList->INodes.length(); i++) {
429 myCombo->insertItem(QString(aNodesList->INodes[i]->Name()));
431 for (i = 0; i < aNodesList->LNodes.length(); i++) {
432 myCombo->insertItem(QString(aNodesList->LNodes[i]->Name()));
434 for (i = 0; i < aNodesList->SNodes.length(); i++) {
435 myCombo->insertItem(QString(aNodesList->SNodes[i]->Name()));
437 aMainLayout->addWidget(myCombo, 0, 1);
439 QGroupBox* aBtnBox = new QGroupBox( this );
440 aBtnBox->setColumnLayout( 0, Qt::Vertical );
441 aBtnBox->layout()->setSpacing( 0 ); aBtnBox->layout()->setMargin( 0 );
442 QHBoxLayout* aBtnLayout = new QHBoxLayout( aBtnBox->layout() );
443 aBtnLayout->setAlignment( Qt::AlignTop );
444 aBtnLayout->setSpacing( 6 ); aBtnLayout->setMargin( 11 );
446 QPushButton* aOKBtn = new QPushButton( tr( "BUT_OK" ), aBtnBox );
447 connect( aOKBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
448 aBtnLayout->addWidget( aOKBtn );
450 aBtnLayout->addStretch();
452 QPushButton* aCancelBtn = new QPushButton( tr("BUT_CANCEL"), aBtnBox );
453 connect( aCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
454 aBtnLayout->addWidget( aCancelBtn );
456 aMainLayout->addMultiCellWidget(aBtnBox, 1, 1, 0, 1);