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_Main.h"
14 #include "SUPERVGUI.h"
15 #include "SUPERVGUI_Canvas.h"
17 #include "QAD_FileDlg.h"
18 #include "QAD_Application.h"
22 //=====================================================================
24 //=====================================================================
25 SUPERVGUI_CanvasComputeNode::SUPERVGUI_CanvasComputeNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
26 SUPERVGUI_CanvasNode(theParent, theMain, theNode)
28 Trace("SUPERVGUI_CanvasComputeNode::SUPERVGUI_CanvasComputeNode");
31 QPopupMenu* SUPERVGUI_CanvasComputeNode::getPopupMenu(QWidget* theParent)
33 QPopupMenu* popup = SUPERVGUI_CanvasNode::getPopupMenu(theParent);
35 QPopupMenu* aShowPopup = new QPopupMenu(theParent);
37 anItem = aShowPopup->insertItem(tr("POP_SHOWTITLES"), this, SLOT(switchLabel()));
38 aShowPopup->setItemChecked(anItem, getPrs()->isLabelVisible());
39 anItem = aShowPopup->insertItem(tr("POP_SHOWPORTS"), this, SLOT(switchPorts()));
40 aShowPopup->setItemChecked(anItem, getPrs()->isPortVisible());
42 popup->insertSeparator();
43 popup->insertItem(tr("POP_SHOW"), aShowPopup);
49 //=====================================================================
51 //=====================================================================
52 SUPERVGUI_CanvasStartNode::SUPERVGUI_CanvasStartNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
53 SUPERVGUI_CanvasNode(theParent, theMain, theNode),
56 Trace("SUPERVGUI_CanvasStartNode::SUPERVGUI_CanvasStartNode");
59 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasStartNode::createPrs() const
61 return new SUPERVGUI_CanvasStartNodePrs(getMain()->getCanvas(),
62 (SUPERVGUI_CanvasStartNode*)this);
65 bool SUPERVGUI_CanvasStartNode::setNodeName(QString aName)
67 bool result = SUPERVGUI_CanvasNode::setNodeName(aName);
68 if (result && myCoupled) {
69 myCoupled->setNodeName(QString(tr("ENDNODE_PREFIX"))+aName);
74 QPopupMenu* SUPERVGUI_CanvasStartNode::getPopupMenu(QWidget* theParent)
76 QPopupMenu* popup = SUPERVGUI_CanvasNode::getPopupMenu(theParent);
78 popup->insertSeparator();
79 int anItem = popup->insertItem(tr("POP_HIDEPORTS"), this, SLOT(switchPorts()));
80 popup->setItemChecked(anItem, !getPrs()->isPortVisible());
85 void SUPERVGUI_CanvasStartNode::remove()
87 SUPERVGUI_Canvas* aCanvas = getMain()->getCanvas();
90 if (myCoupled) myCoupled->setDestroyed();
92 getEngine()->destroy();
94 if (myCoupled) delete myCoupled;
100 void SUPERVGUI_CanvasStartNode::onDestroyed(QObject* theObject)
103 SUPERVGUI_CanvasNode::onDestroyed(theObject);
104 if (getEngine()->IsLoop()) merge();
105 if (myCoupled) myCoupled->merge();
109 void SUPERVGUI_CanvasStartNode::addInputPort()
111 SUPERVGUI_CanvasNode::addInputPort();
112 if (getEngine()->IsLoop()) merge();
113 if (myCoupled) myCoupled->merge();
116 void SUPERVGUI_CanvasStartNode::addOutputPort()
118 SUPERVGUI_CanvasNode::addOutputPort();
119 if (myCoupled) myCoupled->merge();
122 //=====================================================================
124 //=====================================================================
125 SUPERVGUI_CanvasEndNode::SUPERVGUI_CanvasEndNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode,
126 SUPERVGUI_CanvasStartNode* theStart):
127 SUPERVGUI_CanvasNode(theParent, theMain, theNode),
130 Trace("SUPERVGUI_CanvasEndNode::SUPERVGUI_CanvasEndNode");
131 myCoupled->setCoupled(this);
134 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasEndNode::createPrs() const
136 return new SUPERVGUI_CanvasEndNodePrs(getMain()->getCanvas(),
137 (SUPERVGUI_CanvasEndNode*)this);
140 QPopupMenu* SUPERVGUI_CanvasEndNode::getPopupMenu(QWidget* theParent)
142 QPopupMenu* popup = SUPERVGUI_CanvasNode::getPopupMenu(theParent);
144 popup->insertSeparator();
145 int anItem = popup->insertItem(tr("POP_HIDEPORTS"), this, SLOT(switchPorts()));
146 popup->setItemChecked(anItem, !getPrs()->isPortVisible());
151 void SUPERVGUI_CanvasEndNode::addInputPort()
153 SUPERVGUI_CanvasNode::addInputPort();
154 if (getEngine()->IsEndSwitch()) merge();
158 //=====================================================================
160 //=====================================================================
161 SUPERVGUI_CanvasGotoNode::SUPERVGUI_CanvasGotoNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
162 SUPERVGUI_CanvasNode(theParent, theMain, theNode)
164 Trace("SUPERVGUI_CanvasGotoNode::SUPERVGUI_CanvasGotoNode");
167 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasGotoNode::createPrs() const
169 return new SUPERVGUI_CanvasGotoNodePrs(getMain()->getCanvas(),
170 (SUPERVGUI_CanvasGotoNode*)this);
173 QPopupMenu* SUPERVGUI_CanvasGotoNode::getPopupMenu(QWidget* theParent)
175 QPopupMenu* popup = SUPERVGUI_CanvasNode::getPopupMenu(theParent);
177 popup->insertSeparator();
178 popup->insertItem("Link to Node...", this, SLOT(linkToNode()));
180 popup->insertSeparator();
181 int anItem = popup->insertItem(tr("POP_HIDEPORTS"), this, SLOT(switchPorts()));
182 popup->setItemChecked(anItem, !getPrs()->isPortVisible());
187 void SUPERVGUI_CanvasGotoNode::linkToNode() {
188 SUPERVGUI_SelectInlineDlg* aDlg = new SUPERVGUI_SelectInlineDlg(getMain());
190 QString aNodeName = aDlg->getName();
191 if (!aNodeName.isEmpty()) { //implement additional check from GUI side for bug PAL7007
192 getGotoNode()->SetCoupled(aNodeName.latin1());
193 getMain()->getCanvas()->sync();
199 //=====================================================================
201 //=====================================================================
202 SUPERVGUI_CanvasMacroNode::SUPERVGUI_CanvasMacroNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
203 SUPERVGUI_CanvasComputeNode(theParent, theMain, theNode)
205 Trace("SUPERVGUI_CanvasMacroNode::SUPERVGUI_CanvasMacroNode");
208 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasMacroNode::createPrs() const
210 return new SUPERVGUI_CanvasMacroNodePrs(getMain()->getCanvas(),
211 (SUPERVGUI_CanvasMacroNode*)this);
214 QPopupMenu* SUPERVGUI_CanvasMacroNode::getPopupMenu(QWidget* theParent)
216 QPopupMenu* popup = SUPERVGUI_CanvasComputeNode::getPopupMenu(theParent);
218 popup->insertSeparator(0);
219 popup->insertItem(tr("MSG_EXPORT"), this, SLOT(exportDataflow()), 0, -1, 0);
220 popup->insertItem("Open SubGraph", this, SLOT(openSubGraph()), 0, -1, 0);
225 void SUPERVGUI_CanvasMacroNode::openSubGraph()
227 getMain()->openSubGraph(getEngine());
230 void SUPERVGUI_CanvasMacroNode::exportDataflow()
233 if (getEngine()->IsMacro()) {
234 SUPERV_Graph aMacro = getMacroNode();
235 if (aMacro->IsStreamMacro())
236 aGraph = aMacro->StreamObjRef();
238 aGraph = aMacro->FlowObjRef();
240 if (SUPERV_isNull(aGraph)) {
241 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_EXPORT"));
245 QString aFileName = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
248 tr("TTL_EXPORT_DATAFLOW"),
250 if ( !aFileName.isEmpty() ) {
251 // asv : bug [VSR Bugs and Improvements in Supervisor] 1.8 : when exporting a file,
252 // a backup copy of an existing file must be created (in case Export fails..)
253 QString aBackupFile = SUPERVGUI::createBackupFile( aFileName );
255 if (!aGraph->Export(aFileName.latin1())) {
256 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_WRITING").arg(aBackupFile));
258 // remove a backup file if export was successfull
259 else if ( !aBackupFile.isNull() && !aBackupFile.isEmpty() ) {
260 QFile::remove( aBackupFile );
266 //=====================================================================
267 // Cell node: node for table view
268 //=====================================================================
269 SUPERVGUI_CanvasCellNode::SUPERVGUI_CanvasCellNode(QObject* theParent,
270 SUPERVGUI_Main* theMain,
271 SUPERV_CNode theNode):
272 SUPERVGUI_CanvasNode(theParent, theMain, theNode, true)
274 Trace("SUPERVGUI_CanvasCellNode::SUPERVGUI_CanvasCellNode");
279 //check for control nodes
280 if (getEngine()->IsLoop() || getEngine()->IsSwitch()) {
284 if (getEngine()->IsEndLoop() || getEngine()->IsEndSwitch())
288 QPopupMenu* SUPERVGUI_CanvasCellNode::getPopupMenu(QWidget* theParent)
290 QPopupMenu* popup = SUPERVGUI_CanvasNode::getPopupMenu(theParent);
291 popup->setItemEnabled(myDeleteItem, false);
295 void SUPERVGUI_CanvasCellNode::setPairCell(SUPERVGUI_CanvasCellNode* thePairCell) {
296 if (myIsControl) { //only for ControlNode
297 myPairCell = thePairCell;
303 SUPERVGUI_CanvasCellNode* SUPERVGUI_CanvasCellNode::getPairCell() {
307 void SUPERVGUI_CanvasCellNode::sync() {
308 MESSAGE("===> SUPERVGUI_CanvasCellNode::sync() " << getEngine()->Name() << ", state " << getEngine()->State());
310 const bool isExecuting = getMain()->getDataflow()->IsExecuting();
311 //if getEngine() is a MacroNode then set it state to state of its subgraph
312 if ( getEngine()->IsMacro() && isExecuting ) {
313 // get SubGraph from MacroNode
314 SUPERV_Graph aMacro = SUPERV::Graph::_narrow(getEngine());
315 if (!SUPERV_isNull(aMacro)) {
317 if (aMacro->IsStreamMacro())
318 aGraph = aMacro->StreamObjRef();
320 aGraph = aMacro->FlowObjRef();
321 if (!SUPERV_isNull(aGraph)) {
322 if (aGraph->State() != SUPERV::UndefinedState && aGraph->State() != SUPERV::NoState)
323 getPrs()->setState(aGraph->State());
325 getPrs()->setState(getEngine()->State());
330 getPrs()->setState(getEngine()->State());
334 /*bool SUPERVGUI_CanvasCellNode::setNodeName(QString aName)
336 bool result = SUPERVGUI_CanvasNode::setNodeName(aName);
337 if (result && myPairCell) {
338 result = myPairCell->getEngine()->SetName((QString(tr("ENDNODE_PREFIX"))+aName).latin1());
340 setName(myPairCell->getEngine()->Name());
341 myPairCell->getPrs()->updateInfo();
344 QMessageBox::warning( QAD_Application::getDesktop(), tr( "ERROR" ), tr( "MSG_CANT_RENAMENODE" ) );
350 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasCellNode::createPrs() const
352 MESSAGE(" -> SUPERVGUI_CanvasCellNode::createPrs()");
353 SUPERVGUI_CanvasNodePrs* aPrs =
354 new SUPERVGUI_CanvasCellNodePrs(getMain()->getCanvasArray(),
355 (SUPERVGUI_CanvasCellNode*)this);
356 MESSAGE(" -> SUPERVGUI_CanvasCellNode::createPrs() 11");
360 SUPERVGUI_CanvasCellEndNode::SUPERVGUI_CanvasCellEndNode( QObject* theParent,
361 SUPERVGUI_Main* theMain,
362 SUPERV_CNode theNode,
363 SUPERVGUI_CanvasCellNode* theStart):
364 SUPERVGUI_CanvasCellNode(theParent, theMain, theNode)
366 //set start cell for end cell as pair
367 myPairCell = theStart;
368 //set end cell for start cell as pair
369 myPairCell->setPairCell(dynamic_cast<SUPERVGUI_CanvasCellNode*>(this));
372 //-----------------------------------------------------------
373 //*************** Select Inline node dialog******************
374 // Taken from SUPERVGUI_ControlNode.cxx without change
375 //-----------------------------------------------------------
377 SUPERVGUI_SelectInlineDlg::SUPERVGUI_SelectInlineDlg(SUPERVGUI_Main* theMain)
378 :QDialog(theMain, 0, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
380 setSizeGripEnabled( true );
381 setCaption(tr("TIT_FUNC_PYTHON"));
382 QGridLayout* aMainLayout = new QGridLayout(this, 2, 2, 7, 4);
384 QLabel* aLabel = new QLabel("Connect to", this );
385 aMainLayout->addWidget(aLabel, 0, 0);
387 myCombo = new QComboBox(this);
388 myCombo->clear(); //for the additional check from GUI side for bug PAL7007
389 SUPERV_Nodes aNodesList = theMain->getDataflow()->Nodes();
391 for (i = 0; i < aNodesList->INodes.length(); i++) {
392 myCombo->insertItem(QString(aNodesList->INodes[i]->Name()));
394 for (i = 0; i < aNodesList->LNodes.length(); i++) {
395 myCombo->insertItem(QString(aNodesList->LNodes[i]->Name()));
397 for (i = 0; i < aNodesList->SNodes.length(); i++) {
398 myCombo->insertItem(QString(aNodesList->SNodes[i]->Name()));
400 aMainLayout->addWidget(myCombo, 0, 1);
402 QGroupBox* aBtnBox = new QGroupBox( this );
403 aBtnBox->setColumnLayout( 0, Qt::Vertical );
404 aBtnBox->layout()->setSpacing( 0 ); aBtnBox->layout()->setMargin( 0 );
405 QHBoxLayout* aBtnLayout = new QHBoxLayout( aBtnBox->layout() );
406 aBtnLayout->setAlignment( Qt::AlignTop );
407 aBtnLayout->setSpacing( 6 ); aBtnLayout->setMargin( 11 );
409 QPushButton* aOKBtn = new QPushButton( tr( "BUT_OK" ), aBtnBox );
410 connect( aOKBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
411 aBtnLayout->addWidget( aOKBtn );
413 aBtnLayout->addStretch();
415 QPushButton* aCancelBtn = new QPushButton( tr("BUT_CANCEL"), aBtnBox );
416 connect( aCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
417 aBtnLayout->addWidget( aCancelBtn );
419 aMainLayout->addMultiCellWidget(aBtnBox, 1, 1, 0, 1);