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 getEngine()->destroy();
120 void SUPERVGUI_CanvasStartNode::onDestroyed(QObject* theObject)
123 SUPERVGUI_CanvasNode::onDestroyed(theObject);
124 if (getEngine()->IsLoop()) merge();
125 if (myCoupled) myCoupled->merge();
129 void SUPERVGUI_CanvasStartNode::addInputPort()
131 SUPERVGUI_CanvasNode::addInputPort();
132 if (getEngine()->IsLoop()) merge();
133 if (myCoupled) myCoupled->merge();
136 void SUPERVGUI_CanvasStartNode::addOutputPort()
138 SUPERVGUI_CanvasNode::addOutputPort();
139 if (myCoupled) myCoupled->merge();
142 void SUPERVGUI_CanvasStartNode::pastePort()
144 SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard();
145 SUPERVGUI_CanvasNode::pastePort();
146 if ( aCB->getCopyPort()->IsInput() && getEngine()->IsLoop() )
152 //=====================================================================
154 //=====================================================================
155 SUPERVGUI_CanvasEndNode::SUPERVGUI_CanvasEndNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode,
156 SUPERVGUI_CanvasStartNode* theStart):
157 SUPERVGUI_CanvasNode(theParent, theMain, theNode),
160 Trace("SUPERVGUI_CanvasEndNode::SUPERVGUI_CanvasEndNode");
161 myCoupled->setCoupled(this);
164 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasEndNode::createPrs() const
166 return new SUPERVGUI_CanvasEndNodePrs(getMain()->getCanvas(),
167 (SUPERVGUI_CanvasEndNode*)this);
170 QPopupMenu* SUPERVGUI_CanvasEndNode::getPopupMenu(QWidget* theParent)
172 QPopupMenu* popup = SUPERVGUI_CanvasNode::getPopupMenu(theParent);
174 popup->insertSeparator();
175 int anItem = popup->insertItem(tr("POP_HIDEPORTS"), this, SLOT(switchPorts()));
176 popup->setItemChecked(anItem, !getPrs()->isPortVisible());
181 void SUPERVGUI_CanvasEndNode::addInputPort()
183 SUPERVGUI_CanvasNode::addInputPort();
184 if (getEngine()->IsEndSwitch()) merge();
188 //=====================================================================
190 //=====================================================================
191 SUPERVGUI_CanvasGotoNode::SUPERVGUI_CanvasGotoNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
192 SUPERVGUI_CanvasNode(theParent, theMain, theNode)
194 Trace("SUPERVGUI_CanvasGotoNode::SUPERVGUI_CanvasGotoNode");
197 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasGotoNode::createPrs() const
199 return new SUPERVGUI_CanvasGotoNodePrs(getMain()->getCanvas(),
200 (SUPERVGUI_CanvasGotoNode*)this);
203 QPopupMenu* SUPERVGUI_CanvasGotoNode::getPopupMenu(QWidget* theParent)
205 QPopupMenu* popup = SUPERVGUI_CanvasNode::getPopupMenu(theParent);
207 popup->insertSeparator();
208 popup->insertItem("Link to Node...", this, SLOT(linkToNode()));
210 popup->insertSeparator();
211 int anItem = popup->insertItem(tr("POP_HIDEPORTS"), this, SLOT(switchPorts()));
212 popup->setItemChecked(anItem, !getPrs()->isPortVisible());
217 void SUPERVGUI_CanvasGotoNode::linkToNode() {
218 SUPERVGUI_SelectInlineDlg* aDlg = new SUPERVGUI_SelectInlineDlg(getMain());
220 QString aNodeName = aDlg->getName();
221 if (!aNodeName.isEmpty()) { //implement additional check from GUI side for bug PAL7007
222 getGotoNode()->SetCoupled(aNodeName.latin1());
223 getMain()->getCanvas()->sync();
229 //=====================================================================
231 //=====================================================================
232 SUPERVGUI_CanvasMacroNode::SUPERVGUI_CanvasMacroNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
233 SUPERVGUI_CanvasComputeNode(theParent, theMain, theNode)
235 Trace("SUPERVGUI_CanvasMacroNode::SUPERVGUI_CanvasMacroNode");
238 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasMacroNode::createPrs() const
240 return new SUPERVGUI_CanvasMacroNodePrs(getMain()->getCanvas(),
241 (SUPERVGUI_CanvasMacroNode*)this);
244 QPopupMenu* SUPERVGUI_CanvasMacroNode::getPopupMenu(QWidget* theParent)
246 QPopupMenu* popup = SUPERVGUI_CanvasComputeNode::getPopupMenu(theParent);
248 popup->insertSeparator(0);
249 popup->insertItem(tr("MSG_EXPORT"), this, SLOT(exportDataflow()), 0, -1, 0);
250 popup->insertItem("Open SubGraph", this, SLOT(openSubGraph()), 0, -1, 0);
255 void SUPERVGUI_CanvasMacroNode::openSubGraph()
257 getMain()->openSubGraph(getEngine());
260 void SUPERVGUI_CanvasMacroNode::exportDataflow()
263 if (getEngine()->IsMacro()) {
264 SUPERV_Graph aMacro = getMacroNode();
265 if (aMacro->IsStreamMacro())
266 aGraph = aMacro->StreamObjRef();
268 aGraph = aMacro->FlowObjRef();
270 if (SUPERV_isNull(aGraph)) {
271 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_EXPORT"));
275 QString aFileName = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
278 tr("TTL_EXPORT_DATAFLOW"),
280 if ( !aFileName.isEmpty() ) {
281 // asv : bug [VSR Bugs and Improvements in Supervisor] 1.8 : when exporting a file,
282 // a backup copy of an existing file must be created (in case Export fails..)
283 QString aBackupFile = SUPERVGUI::createBackupFile( aFileName );
285 if (!aGraph->Export(aFileName.latin1())) {
286 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_WRITING").arg(aBackupFile));
288 // remove a backup file if export was successfull
289 else if ( !aBackupFile.isNull() && !aBackupFile.isEmpty() ) {
290 QFile::remove( aBackupFile );
296 //=====================================================================
297 // Cell node: node for table view
298 //=====================================================================
299 SUPERVGUI_CanvasCellNode::SUPERVGUI_CanvasCellNode(QObject* theParent,
300 SUPERVGUI_Main* theMain,
301 SUPERV_CNode theNode):
302 SUPERVGUI_CanvasNode(theParent, theMain, theNode, true)
304 Trace("SUPERVGUI_CanvasCellNode::SUPERVGUI_CanvasCellNode");
309 //check for control nodes
310 if (getEngine()->IsLoop() || getEngine()->IsSwitch()) {
314 if (getEngine()->IsEndLoop() || getEngine()->IsEndSwitch())
318 QPopupMenu* SUPERVGUI_CanvasCellNode::getPopupMenu(QWidget* theParent)
320 QPopupMenu* popup = SUPERVGUI_CanvasNode::getPopupMenu(theParent);
321 popup->setItemEnabled(myDeleteItem, false);
325 void SUPERVGUI_CanvasCellNode::setPairCell(SUPERVGUI_CanvasCellNode* thePairCell) {
326 if (myIsControl) { //only for ControlNode
327 myPairCell = thePairCell;
333 SUPERVGUI_CanvasCellNode* SUPERVGUI_CanvasCellNode::getPairCell() {
337 void SUPERVGUI_CanvasCellNode::sync() {
338 MESSAGE("===> SUPERVGUI_CanvasCellNode::sync() " << getEngine()->Name() << ", state " << getEngine()->State());
340 const bool isExecuting = getMain()->getDataflow()->IsExecuting();
341 //if getEngine() is a MacroNode then set it state to state of its subgraph
342 if ( getEngine()->IsMacro() && isExecuting ) {
343 // get SubGraph from MacroNode
344 SUPERV_Graph aMacro = SUPERV::Graph::_narrow(getEngine());
345 if (!SUPERV_isNull(aMacro)) {
347 if (aMacro->IsStreamMacro())
348 aGraph = aMacro->StreamObjRef();
350 aGraph = aMacro->FlowObjRef();
351 if (!SUPERV_isNull(aGraph)) {
352 if (aGraph->State() != SUPERV::UndefinedState && aGraph->State() != SUPERV::NoState)
353 getPrs()->setState(aGraph->State());
355 getPrs()->setState(getEngine()->State());
360 getPrs()->setState(getEngine()->State());
364 bool SUPERVGUI_CanvasCellNode::setNodeName(QString aName)
366 bool result = SUPERVGUI_CanvasNode::setNodeName(aName);
367 if (result && myPairCell) {
368 result = myPairCell->setNodeName(QString(tr("ENDNODE_PREFIX"))+aName);
373 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasCellNode::createPrs() const
375 MESSAGE(" -> SUPERVGUI_CanvasCellNode::createPrs()");
376 SUPERVGUI_CanvasNodePrs* aPrs =
377 new SUPERVGUI_CanvasCellNodePrs(getMain()->getCanvasArray(),
378 (SUPERVGUI_CanvasCellNode*)this);
379 MESSAGE(" -> SUPERVGUI_CanvasCellNode::createPrs() 11");
383 SUPERVGUI_CanvasCellEndNode::SUPERVGUI_CanvasCellEndNode( QObject* theParent,
384 SUPERVGUI_Main* theMain,
385 SUPERV_CNode theNode,
386 SUPERVGUI_CanvasCellNode* theStart):
387 SUPERVGUI_CanvasCellNode(theParent, theMain, theNode)
389 //set start cell for end cell as pair
390 myPairCell = theStart;
391 //set end cell for start cell as pair
392 myPairCell->setPairCell(dynamic_cast<SUPERVGUI_CanvasCellNode*>(this));
395 bool SUPERVGUI_CanvasCellEndNode::setNodeName(QString theName)
397 return SUPERVGUI_CanvasNode::setNodeName(theName);
400 //-----------------------------------------------------------
401 //*************** Select Inline node dialog******************
402 // Taken from SUPERVGUI_ControlNode.cxx without change
403 //-----------------------------------------------------------
405 SUPERVGUI_SelectInlineDlg::SUPERVGUI_SelectInlineDlg(SUPERVGUI_Main* theMain)
406 :QDialog(theMain, 0, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
408 setSizeGripEnabled( true );
409 setCaption(tr("TIT_FUNC_PYTHON"));
410 QGridLayout* aMainLayout = new QGridLayout(this, 2, 2, 7, 4);
412 QLabel* aLabel = new QLabel("Connect to", this );
413 aMainLayout->addWidget(aLabel, 0, 0);
415 myCombo = new QComboBox(this);
416 myCombo->clear(); //for the additional check from GUI side for bug PAL7007
417 SUPERV_Nodes aNodesList = theMain->getDataflow()->Nodes();
419 for (i = 0; i < aNodesList->INodes.length(); i++) {
420 myCombo->insertItem(QString(aNodesList->INodes[i]->Name()));
422 for (i = 0; i < aNodesList->LNodes.length(); i++) {
423 myCombo->insertItem(QString(aNodesList->LNodes[i]->Name()));
425 for (i = 0; i < aNodesList->SNodes.length(); i++) {
426 myCombo->insertItem(QString(aNodesList->SNodes[i]->Name()));
428 aMainLayout->addWidget(myCombo, 0, 1);
430 QGroupBox* aBtnBox = new QGroupBox( this );
431 aBtnBox->setColumnLayout( 0, Qt::Vertical );
432 aBtnBox->layout()->setSpacing( 0 ); aBtnBox->layout()->setMargin( 0 );
433 QHBoxLayout* aBtnLayout = new QHBoxLayout( aBtnBox->layout() );
434 aBtnLayout->setAlignment( Qt::AlignTop );
435 aBtnLayout->setSpacing( 6 ); aBtnLayout->setMargin( 11 );
437 QPushButton* aOKBtn = new QPushButton( tr( "BUT_OK" ), aBtnBox );
438 connect( aOKBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
439 aBtnLayout->addWidget( aOKBtn );
441 aBtnLayout->addStretch();
443 QPushButton* aCancelBtn = new QPushButton( tr("BUT_CANCEL"), aBtnBox );
444 connect( aCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
445 aBtnLayout->addWidget( aCancelBtn );
447 aMainLayout->addMultiCellWidget(aBtnBox, 1, 1, 0, 1);