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(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
28 SUPERVGUI_CanvasNode(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(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
55 SUPERVGUI_CanvasNode(theParent, theMain, theNode),
58 Trace("SUPERVGUI_CanvasStartNode::SUPERVGUI_CanvasStartNode");
61 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasStartNode::createPrs() const
63 return new SUPERVGUI_CanvasStartNodePrs(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 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(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode,
163 SUPERVGUI_CanvasStartNode* theStart):
164 SUPERVGUI_CanvasNode(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(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 void SUPERVGUI_CanvasEndNode::addInputPort()
190 SUPERVGUI_CanvasNode::addInputPort();
191 if (getEngine()->IsEndSwitch()) merge();
195 //=====================================================================
197 //=====================================================================
198 SUPERVGUI_CanvasGotoNode::SUPERVGUI_CanvasGotoNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
199 SUPERVGUI_CanvasNode(theParent, theMain, theNode)
201 Trace("SUPERVGUI_CanvasGotoNode::SUPERVGUI_CanvasGotoNode");
204 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasGotoNode::createPrs() const
206 return new SUPERVGUI_CanvasGotoNodePrs(getMain()->getCanvas(),
207 (SUPERVGUI_CanvasGotoNode*)this);
210 QPopupMenu* SUPERVGUI_CanvasGotoNode::getPopupMenu(QWidget* theParent)
212 QPopupMenu* popup = SUPERVGUI_CanvasNode::getPopupMenu(theParent);
214 popup->insertSeparator();
215 popup->insertItem("Link to Node...", this, SLOT(linkToNode()));
217 popup->insertSeparator();
218 int anItem = popup->insertItem(tr("POP_HIDEPORTS"), this, SLOT(switchPorts()));
219 popup->setItemChecked(anItem, !getPrs()->isPortVisible());
224 void SUPERVGUI_CanvasGotoNode::linkToNode() {
225 SUPERVGUI_SelectInlineDlg* aDlg = new SUPERVGUI_SelectInlineDlg(getMain());
227 QString aNodeName = aDlg->getName();
228 if (!aNodeName.isEmpty()) { //implement additional check from GUI side for bug PAL7007
229 getGotoNode()->SetCoupled(aNodeName.latin1());
230 getMain()->getCanvas()->sync();
236 //=====================================================================
238 //=====================================================================
239 SUPERVGUI_CanvasMacroNode::SUPERVGUI_CanvasMacroNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
240 SUPERVGUI_CanvasComputeNode(theParent, theMain, theNode)
242 Trace("SUPERVGUI_CanvasMacroNode::SUPERVGUI_CanvasMacroNode");
245 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasMacroNode::createPrs() const
247 return new SUPERVGUI_CanvasMacroNodePrs(getMain()->getCanvas(),
248 (SUPERVGUI_CanvasMacroNode*)this);
251 QPopupMenu* SUPERVGUI_CanvasMacroNode::getPopupMenu(QWidget* theParent)
253 QPopupMenu* popup = SUPERVGUI_CanvasComputeNode::getPopupMenu(theParent);
255 popup->insertSeparator(0);
256 popup->insertItem(tr("MSG_EXPORT"), this, SLOT(exportDataflow()), 0, -1, 0);
257 popup->insertItem("Open SubGraph", this, SLOT(openSubGraph()), 0, -1, 0);
262 void SUPERVGUI_CanvasMacroNode::openSubGraph()
264 getMain()->openSubGraph(getEngine());
267 void SUPERVGUI_CanvasMacroNode::exportDataflow()
270 if (getEngine()->IsMacro()) {
271 SUPERV_Graph aMacro = getMacroNode();
272 if (aMacro->IsStreamMacro())
273 aGraph = aMacro->StreamObjRef();
275 aGraph = aMacro->FlowObjRef();
277 if (SUPERV_isNull(aGraph)) {
278 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_EXPORT"));
282 QString aFileName = SUIT_FileDlg::getFileName(SUIT_Session::session()->activeApplication()->desktop(),
285 tr("TTL_EXPORT_DATAFLOW"),
287 if ( !aFileName.isEmpty() ) {
288 // asv : bug [VSR Bugs and Improvements in Supervisor] 1.8 : when exporting a file,
289 // a backup copy of an existing file must be created (in case Export fails..)
290 QString aBackupFile = SUPERVGUI::createBackupFile( aFileName );
292 if (!aGraph->Export(aFileName.latin1())) {
293 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_BAD_WRITING").arg(aBackupFile));
295 // remove a backup file if export was successfull
296 else if ( !aBackupFile.isNull() && !aBackupFile.isEmpty() ) {
297 QFile::remove( aBackupFile );
303 //=====================================================================
304 // Cell node: node for table view
305 //=====================================================================
306 SUPERVGUI_CanvasCellNode::SUPERVGUI_CanvasCellNode(QObject* theParent,
307 SUPERVGUI_Main* theMain,
308 SUPERV_CNode theNode):
309 SUPERVGUI_CanvasNode(theParent, theMain, theNode, true)
311 Trace("SUPERVGUI_CanvasCellNode::SUPERVGUI_CanvasCellNode");
316 //check for control nodes
317 if (getEngine()->IsLoop() || getEngine()->IsSwitch()) {
321 if (getEngine()->IsEndLoop() || getEngine()->IsEndSwitch())
325 SUPERVGUI_CanvasCellNode::~SUPERVGUI_CanvasCellNode()
329 QPopupMenu* SUPERVGUI_CanvasCellNode::getPopupMenu(QWidget* theParent)
331 QPopupMenu* popup = SUPERVGUI_CanvasNode::getPopupMenu(theParent);
332 popup->setItemEnabled(myDeleteItem, false);
336 void SUPERVGUI_CanvasCellNode::setPairCell(SUPERVGUI_CanvasCellNode* thePairCell) {
337 if (myIsControl) { //only for ControlNode
338 myPairCell = thePairCell;
344 SUPERVGUI_CanvasCellNode* SUPERVGUI_CanvasCellNode::getPairCell() {
348 void SUPERVGUI_CanvasCellNode::sync() {
349 const bool isExecuting = getMain()->getDataflow()->IsExecuting();
350 //if getEngine() is a MacroNode then set it state to state of its subgraph
351 if ( getEngine()->IsMacro() && isExecuting ) {
352 // get SubGraph from MacroNode
353 SUPERV_Graph aMacro = SUPERV::Graph::_narrow(getEngine());
354 if (!SUPERV_isNull(aMacro)) {
356 if (aMacro->IsStreamMacro())
357 aGraph = aMacro->StreamObjRef();
359 aGraph = aMacro->FlowObjRef();
360 if (!SUPERV_isNull(aGraph)) {
361 if (aGraph->State() != SUPERV::UndefinedState && aGraph->State() != SUPERV::NoState)
362 getPrs()->setState(aGraph->State());
364 getPrs()->setState(getEngine()->State());
369 getPrs()->setState(getEngine()->State());
373 bool SUPERVGUI_CanvasCellNode::setNodeName(QString aName)
375 bool result = SUPERVGUI_CanvasNode::setNodeName(aName);
376 if (result && myPairCell) {
377 result = myPairCell->setNodeName(QString(tr("ENDNODE_PREFIX"))+aName);
382 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasCellNode::createPrs() const
384 SUPERVGUI_CanvasNodePrs* aPrs =
385 new SUPERVGUI_CanvasCellNodePrs(getMain()->getCanvasArray(),
386 (SUPERVGUI_CanvasCellNode*)this);
390 SUPERVGUI_CanvasCellEndNode::SUPERVGUI_CanvasCellEndNode( QObject* theParent,
391 SUPERVGUI_Main* theMain,
392 SUPERV_CNode theNode,
393 SUPERVGUI_CanvasCellNode* theStart):
394 SUPERVGUI_CanvasCellNode(theParent, theMain, theNode)
396 //set start cell for end cell as pair
397 myPairCell = theStart;
398 //set end cell for start cell as pair
399 myPairCell->setPairCell(dynamic_cast<SUPERVGUI_CanvasCellNode*>(this));
402 bool SUPERVGUI_CanvasCellEndNode::setNodeName(QString theName)
404 return SUPERVGUI_CanvasNode::setNodeName(theName);
407 //-----------------------------------------------------------
408 //*************** Select Inline node dialog******************
409 // Taken from SUPERVGUI_ControlNode.cxx without change
410 //-----------------------------------------------------------
412 SUPERVGUI_SelectInlineDlg::SUPERVGUI_SelectInlineDlg(SUPERVGUI_Main* theMain)
413 :QDialog(theMain, 0, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
415 setSizeGripEnabled( true );
416 setCaption(tr("TIT_FUNC_PYTHON"));
417 QGridLayout* aMainLayout = new QGridLayout(this, 2, 2, 7, 4);
419 QLabel* aLabel = new QLabel("Connect to", this );
420 aMainLayout->addWidget(aLabel, 0, 0);
422 myCombo = new QComboBox(this);
423 myCombo->clear(); //for the additional check from GUI side for bug PAL7007
424 SUPERV_Nodes aNodesList = theMain->getDataflow()->Nodes();
426 for (i = 0; i < aNodesList->INodes.length(); i++) {
427 myCombo->insertItem(QString(aNodesList->INodes[i]->Name()));
429 for (i = 0; i < aNodesList->LNodes.length(); i++) {
430 myCombo->insertItem(QString(aNodesList->LNodes[i]->Name()));
432 for (i = 0; i < aNodesList->SNodes.length(); i++) {
433 myCombo->insertItem(QString(aNodesList->SNodes[i]->Name()));
435 aMainLayout->addWidget(myCombo, 0, 1);
437 QGroupBox* aBtnBox = new QGroupBox( this );
438 aBtnBox->setColumnLayout( 0, Qt::Vertical );
439 aBtnBox->layout()->setSpacing( 0 ); aBtnBox->layout()->setMargin( 0 );
440 QHBoxLayout* aBtnLayout = new QHBoxLayout( aBtnBox->layout() );
441 aBtnLayout->setAlignment( Qt::AlignTop );
442 aBtnLayout->setSpacing( 6 ); aBtnLayout->setMargin( 11 );
444 QPushButton* aOKBtn = new QPushButton( tr( "BUT_OK" ), aBtnBox );
445 connect( aOKBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
446 aBtnLayout->addWidget( aOKBtn );
448 aBtnLayout->addStretch();
450 QPushButton* aCancelBtn = new QPushButton( tr("BUT_CANCEL"), aBtnBox );
451 connect( aCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
452 aBtnLayout->addWidget( aCancelBtn );
454 aMainLayout->addMultiCellWidget(aBtnBox, 1, 1, 0, 1);