Salome HOME
66bf49ba35e653b345c7e5f1d360c0c3d89f450c
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_CanvasNode.cxx
1 //  SUPERV SUPERVGUI : GUI for Supervisor component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE
4 //
5 //  File   : SUPERVGUI_CanvasNode.cxx
6 //  Author : Natalia KOPNOVA
7 //  Module : SUPERV
8
9 using namespace std;
10 #include "SUPERVGUI_CanvasNode.h"
11 #include "SUPERVGUI_CanvasNodePrs.h"
12 #include "SUPERVGUI_CanvasPort.h"
13 #include "SUPERVGUI_Clipboard.h"
14 #include "SUPERVGUI_Main.h"
15 #include "SUPERVGUI.h"
16 #include "SUPERVGUI_BrowseNodeDlg.h"
17 #include "SUPERVGUI_ManagePortsDlg.h"
18 #include "SUPERVGUI_Information.h"
19 #include "SUPERVGUI_Library.h"
20
21 #include "SUIT_MessageBox.h"
22 #include "LogWindow.h"
23 #include "SUIT_Session.h"
24
25 #include <qinputdialog.h>
26
27
28 SUPERVGUI_CanvasNode::SUPERVGUI_CanvasNode( SUIT_ResourceMgr* mgr, QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode, bool theIsCell):
29     QObject(theParent),
30     myMain(theMain),
31     myNode(theNode),
32     myPrs(0),
33     myDestroyed(false),
34     warning(true),
35     step(true),
36     trace(true),
37     verbose(true),
38     myBrowseDlg(0),
39     myMgr( mgr )
40 {
41   Trace("SUPERVGUI_CanvasNode::SUPERVGUI_CanvasNode");
42
43   setName(myNode->Name());
44
45   QString aComment(myNode->Comment());
46   QString aNewComment = aComment;
47   if (getNodeType() == SUPERV::FactoryNode) {
48     aNewComment = QString(myNode->Service()->ServiceName) +
49       QString(tr("COMMENT_FROM")) +
50       QString(getFactoryNode()->GetComponentName());
51   }
52   else if (myNode->IsMacro()) {
53     aNewComment = tr("COMMENT_MNODE");
54   }
55   else {
56     aNewComment = tr("COMMENT_CNODE");
57   }
58   if (aComment.isEmpty()) {
59     myNode->SetComment(aNewComment.latin1());
60   }
61
62   myLabelText = aNewComment;
63
64   // mkr : if the SUPERVGUI_CavasCellNode created (for CANVASTABLE view), 
65   // we don't create the ports
66   if (!theIsCell) {
67     // create node ports
68     isIgnore = true;
69     SUPERV_Ports aPortList = myNode->Ports();
70     for (int i = 0; i < aPortList->length(); i++)
71       createPort(aPortList[i].in());
72     
73     SUPERV_StreamPorts aStreamPortList = myNode->StreamPorts();
74     for (int i = 0; i < aStreamPortList->length(); i++) {
75       createStreamPort(aStreamPortList[i].in());
76     }
77   }
78
79   isIgnore = false;
80 }
81
82 SUPERVGUI_CanvasNode::~SUPERVGUI_CanvasNode()
83 {
84   isIgnore = true;
85   if ( myPrs ) {
86     myPrs->hide();
87     delete myPrs;
88     myPrs = 0;
89   }
90 }
91
92 void SUPERVGUI_CanvasNode::setDestroyed()
93 {
94   myDestroyed = true;
95   getPrs()->hide();
96 }
97
98 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasNode::getPrs()
99 {
100   if ( !myPrs )
101     myPrs = createPrs();
102
103   return myPrs;
104 }
105
106 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasNode::createPrs() const
107 {
108   return new SUPERVGUI_CanvasNodePrs( myMgr, myMain->getCanvas(), (SUPERVGUI_CanvasNode*)this);
109 }
110
111 void SUPERVGUI_CanvasNode::createPort(SUPERV::Port_ptr thePort)
112 {
113   SUPERVGUI_CanvasPort* aPort = 0;
114   if (thePort->IsInput())
115     aPort = new SUPERVGUI_CanvasPortIn((SUPERVGUI_CanvasNode*)this, myMain, thePort);
116   else
117     aPort = new SUPERVGUI_CanvasPortOut((SUPERVGUI_CanvasNode*)this, myMain, thePort);
118
119   if (aPort) {
120     connect(aPort, SIGNAL(destroyed(QObject*)), this, SLOT(onDestroyed(QObject*)));
121     if (!isIgnore) getPrs()->updatePorts();
122   }
123 }
124
125 void SUPERVGUI_CanvasNode::createStreamPort(SUPERV::StreamPort_ptr thePort)
126 {
127   SUPERVGUI_CanvasPort* aPort = 0;
128   if (thePort->IsInput())
129     aPort = new SUPERVGUI_CanvasStreamPortIn((SUPERVGUI_CanvasNode*)this, myMain, thePort);
130   else
131     aPort = new SUPERVGUI_CanvasStreamPortOut((SUPERVGUI_CanvasNode*)this, myMain, thePort);
132
133   if (aPort) {
134     connect(aPort, SIGNAL(destroyed(QObject*)), this, SLOT(onDestroyed(QObject*)));
135     if (!isIgnore) getPrs()->updatePorts();
136   }
137 }
138
139 void SUPERVGUI_CanvasNode::onDestroyed(QObject* theObject)
140 {
141   if (!isIgnore) {
142     removeChild(theObject); // signal is sent before removing the object
143     getPrs()->updatePorts();
144   }
145 }
146
147 QPopupMenu* SUPERVGUI_CanvasNode::getPopupMenu(QWidget* theParent) 
148 {
149   QPopupMenu* popup = new QPopupMenu(theParent);
150
151   if (myMain->getDataflow()->IsExecuting()) { // Execution time
152     popup->insertItem((myNode->IsSuspended()?tr("MSG_RESUME"):tr("MSG_SUSPEND")), this, SLOT(suspendResume()));
153     popup->insertItem(tr("MSG_KILL"), this, SLOT(kill()));
154   }
155   else { // Edition time
156     const int type = getNodeType();
157
158     // for all nodes except EndLoop and EndSwitch : Rename, Delete, Copy
159     if ( myMain->isEditable() && type != SUPERV::EndLoopNode && type != SUPERV::EndSwitchNode &&
160         // asv 26.01.05 : don't allow nodes "edition" commands in Table view
161         myMain->getViewType() != CANVASTABLE ) { 
162       popup->insertItem(tr("MSG_RENAME"), this, SLOT(rename()));
163       popup->insertItem(tr("MSG_DELETE"), this, SLOT(remove()));
164     }
165     
166     // tmp: Copy temporary does not work for Macro nodes...
167     if ( type != SUPERV::MacroNode )
168       popup->insertItem(tr("ITM_COPY_NODE"), this, SLOT(copy())); // Copy Node functionality
169     popup->insertSeparator();
170         
171     // for all nodes : Browse
172     popup->insertItem(tr("MSG_BROWSE"), this, SLOT(browse()));
173
174     // for all nodes except EndLoop and EndSwitch : Change info
175     if (type != SUPERV::EndLoopNode && type != SUPERV::EndSwitchNode)
176       popup->insertItem(tr("MSG_CHANGE_INFO"), this, SLOT(changeInformation()));
177
178     // for all InLine nodes
179     if ( type != SUPERV::FactoryNode && type != SUPERV::ComputingNode && type != SUPERV::MacroNode ) {
180       if ( myMain->isEditable() ) { 
181         popup->insertSeparator();
182         popup->insertItem( tr( "MNU_EDIT_FUNC" ), this, SLOT(editFunction()));
183       }
184
185       // for all InLine, regardless isEditable() : Export to Library
186       popup->insertItem( tr( "MNU_EXPORT" ), this, SLOT( exportToLib()));
187
188       // for all InLine except EndLoop : Add Ports menu, Paste, Manage Ports
189       if ( myMain->isEditable() && type != SUPERV::EndLoopNode ) {
190         // mkr : IPAL9815 : commented the following code
191         /*QPopupMenu* addPortMenu = new QPopupMenu(theParent);
192         addPortMenu->insertItem( tr( "MNU_INPUT" ), this, SLOT(addInputPort()));
193         if (getNodeType() != SUPERV::LoopNode)
194           addPortMenu->insertItem( tr( "MNU_OUTPUT" ), this, SLOT(addOutputPort()));
195
196           popup->insertItem( tr( "MNU_ADD_PORT" ), addPortMenu);*/
197         popup->insertItem( tr( "MNU_MANAGE_PORTS" ), this, SLOT(managePorts()));
198
199         // Paste Port functionality
200         int aPasteItem = popup->insertItem(tr("ITM_PASTE_PORT"), this, SLOT(pastePort()));
201         SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard();
202         if ( !aCB->isCopyPort() || (type == SUPERV::LoopNode && !aCB->getCopyPort()->IsInput()) )
203           popup->setItemEnabled( aPasteItem, false );
204       }
205     }
206   }
207   return popup;
208 }
209
210 void SUPERVGUI_CanvasNode::show() 
211 {
212   getPrs()->show();
213 }
214
215 void SUPERVGUI_CanvasNode::showAll() 
216 {
217   getPrs()->showAll();
218 }
219
220 void SUPERVGUI_CanvasNode::hideAll() 
221 {
222   getPrs()->hideAll();
223 }
224
225 void SUPERVGUI_CanvasNode::switchLabel()
226 {
227   getPrs()->setLabelVisible(!getPrs()->isLabelVisible());
228 }
229
230 void SUPERVGUI_CanvasNode::switchPorts()
231 {
232   getPrs()->setPortVisible(!getPrs()->isPortVisible());
233 }
234
235 void SUPERVGUI_CanvasNode::move(int x, int y)
236 {
237   //  myNode->Coords(x, y); //  <<<- done inside Prs to reflect item movement by mouse press
238   if (x > GRAPH_MAX) x = (int) getPrs()->x();
239   if (y > GRAPH_MAX) y = (int) getPrs()->y();
240   getPrs()->move(x, y);
241 }
242
243 void SUPERVGUI_CanvasNode::merge() 
244 {
245   // synchronize port list
246   bool update = false;
247   isIgnore = true;
248   SUPERVGUI_CanvasPort* aPort;
249   QObjectList* aPortList = queryList("SUPERVGUI_CanvasPort");
250   SUPERV_Ports aPorts = myNode->Ports();
251   for (int i = 0; i < aPorts->length(); i++) {
252     aPort = (SUPERVGUI_CanvasPort*) 
253       child(myMain->getCanvas()->getPortName(aPorts[i].in()), "SUPERVGUI_CanvasPort");
254     if (aPort) {
255       aPortList->removeRef(aPort);
256       aPort->update();
257     }
258     else {
259       createPort(aPorts[i].in());
260       update = true;
261     }
262   }
263
264   SUPERV_StreamPorts aStreamPorts = myNode->StreamPorts();
265   for (int i = 0; i < aStreamPorts->length(); i++) {
266     aPort = (SUPERVGUI_CanvasPort*) 
267       child(myMain->getCanvas()->getPortName(aStreamPorts[i].in()), "SUPERVGUI_CanvasPort");
268     if (aPort) {
269       aPortList->removeRef(aPort);
270       aPort->update();
271     }
272     else {
273       createPort(aStreamPorts[i].in());
274       update = true;
275     }
276   }
277
278   QObjectListIt it(*aPortList);
279   while ((aPort=(SUPERVGUI_CanvasPort*)it.current()) != 0) {
280     ++it;
281     aPortList->removeRef(aPort);
282     delete aPort;
283     update = true;
284   }
285   delete aPortList;
286   isIgnore = false;
287   if (update) getPrs()->updatePorts();
288
289   sync(); // update node state also
290 }
291
292 void SUPERVGUI_CanvasNode::sync()  {
293   const bool isExecuting = myMain->getDataflow()->IsExecuting();
294   if ( myNode->IsMacro() && isExecuting ) {
295     // get SubGraph from MacroNode
296     SUPERV_Graph aMacro = SUPERV::Graph::_narrow(myNode);
297     if (!SUPERV_isNull(aMacro)) {
298       SUPERV_Graph aGraph;
299       if (aMacro->IsStreamMacro())
300         aGraph = aMacro->StreamObjRef();
301       else
302         aGraph = aMacro->FlowObjRef();
303       if (!SUPERV_isNull(aGraph)) {
304         if (aGraph->State() != SUPERV::UndefinedState && aGraph->State() != SUPERV::NoState)
305           getPrs()->setState(aGraph->State());
306         else 
307           getPrs()->setState(myNode->State());
308       }
309     }
310   }
311   else {
312     SUPERV::GraphState aState = myNode->State();
313
314     // asv : 18.11.04 : fix for 6170 : after execution is finished, nodes' status must be reset.
315     // asv : 13.12.04 : commented out setting EditingState.  See 2.21.
316     //if ( !isExecuting && myMain->IsGUIEventLoopFinished() && (aState == SUPERV::DoneState || 
317     //  aState == SUPERV::KillState || aState == SUPERV::StopState ) )
318     //  aState = SUPERV::EditingState;
319     getPrs()->setState(aState);
320   }
321   
322   // update child ports
323   const QObjectList* list = children();
324   if (list) {
325     QObjectListIt it(*list);
326     while (QObject* obj = it.current()) {
327       ++it;
328       if (obj->inherits("SUPERVGUI_CanvasPort")) {
329         ((SUPERVGUI_CanvasPort*)obj)->sync();
330       }
331     }
332   }
333 }
334
335 void SUPERVGUI_CanvasNode::syncOnEvent(SUPERV::GraphState theStateFromEvent) 
336 {
337   getPrs()->setState(theStateFromEvent);
338 }
339
340 bool SUPERVGUI_CanvasNode::setNodeName(QString aName)  {
341   bool result = myNode->SetName(aName.latin1());
342   if (result) {
343     setName(myNode->Name());
344     getPrs()->updateInfo();
345     // TODO: update name of all the links to this node
346   } 
347   else {
348     QMessageBox::warning( SUIT_Session::session()->activeApplication()->desktop(), tr( "ERROR" ), tr( "MSG_CANT_RENAMENODE" ) );
349   }
350   return result;
351 }
352
353 void SUPERVGUI_CanvasNode::rename()  {
354   bool ok;
355    QString aName = QInputDialog::getText( tr( "Rename" ), tr( "Enter new name:" ), QLineEdit::Normal,
356                                           myNode->Name(), &ok, SUIT_Session::session()->activeApplication()->desktop() );
357
358   //mkr : modifications for fixing bug IPAL9972
359   if( ok && !aName.isEmpty() && aName.compare( myNode->Name() ) != 0) {
360     setNodeName(aName);
361   }
362 }
363
364 void SUPERVGUI_CanvasNode::remove() {
365   Trace("SUPERVGUI_CanvasNode::remove");
366   myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag 
367
368   //set myCopyPort from Main object to empty if engine of this port is deleted
369   //check if any port of this deleted node has been copied
370   SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard();
371   if ( aCB->isCopyPort() )
372     if ( QString(myNode->Name()) == QString(aCB->getCopyPort()->Node()->Name()) )
373       aCB->setCopyPort( 0 );
374
375   //set myCopyNode from Main object to empty if engine of this node is deleted
376   //check if myCopyNode and this node engine is equal
377   if ( aCB->isCopyNode() )
378     if ( QString(myNode->Name()) == QString(aCB->getCopyNode()->Name()) ) 
379       aCB->setCopyNode( 0 );
380
381   // mkr: since the deletion of the node allow only in CANVAS view,
382   // it is necessary to remove the CanvasArray's children, which
383   // have the same CNode engine as deleting node
384   myMain->removeArrayChild(myNode);
385
386   SUPERVGUI_Canvas* aCanvas = myMain->getCanvas();
387   setDestroyed();
388   myNode->destroy();
389   delete this;
390   aCanvas->update();
391 }
392
393 void SUPERVGUI_CanvasNode::copy() {
394   Trace("SUPERVGUI_CanvasNode::copy()");
395   SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard();
396   const int aKind = getNodeType(); 
397   if ( aKind == SUPERV::EndLoopNode || aKind == SUPERV::EndSwitchNode )
398     aCB->setCopyNode( SUPERV::CNode::_duplicate(SUPERV::GNode::_narrow(getEngine())->Coupled()) );
399   else
400     aCB->setCopyNode( SUPERV::CNode::_duplicate( getEngine() ) );
401 }
402
403 void SUPERVGUI_CanvasNode::suspendResume() {
404   Trace("SUPERVGUI_CanvasNode::suspendResume");
405   int n = queryList("SUPERVGUI_CanvasNode")->count(); 
406   if (myNode->IsSuspended()) {
407     if (!((n==1)? myMain->getDataflow()->Resume() : myNode->Resume())) {
408       QMessageBox::warning( SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CANT_RESUMENODE") );
409     }
410     else {
411       sync();
412       myMain->getMyThread()->startThread(tr("MSG_NODE_RESUMED1")+myNode->Name()+tr("MSG_NODE_RESUMED2"));
413     }
414   } else {
415     if (!((n==1)? myMain->getDataflow()->Suspend() : myNode->Suspend())) {
416       QMessageBox::warning( SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CANT_SUSPENDNODE") );
417     } else {
418       syncOnEvent(SUPERV::SuspendReadyState);
419       myMain->getMessage()->putMessage(tr("MSG_NODE_SUSPENDED1")+myNode->Name()+tr("MSG_NODE_SUSPENDED2"));
420     }
421   }
422 }
423
424 void SUPERVGUI_CanvasNode::kill() {
425   Trace("SUPERVGUI_CanvasNode::kill");
426   int n = queryList("SUPERVGUI_CanvasNode")->count(); 
427   if (!((n==1)? myMain->getDataflow()->Kill() : myNode->Kill())) {
428     QMessageBox::warning( SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CANT_KILLNODE") );
429   } else {
430     syncOnEvent(SUPERV_Kill);
431     myMain->getMessage()->putMessage(tr("MSG_NODE_KILLED1")+myNode->Name()+tr("MSG_NODE_KILLED2"));
432   }
433 }
434 /* asv : 15.12.04 : commented out stopRestart() in Main and CanvasNode because it's not called from anywhere,
435    the comment from kloss (in Main.cxx) may be explaining it, but it's in French and I do not understand it..
436 void SUPERVGUI_CanvasNode::stopRestart() {
437   Trace("SUPERVGUI_CanvasNode::stopRestart");
438   
439   int n = queryList("SUPERVGUI_CanvasNode")->count(); 
440   if ((myNode->State() == SUPERV_Stop) || (myNode->State() == SUPERV_Kill)) {
441     if (!((n==1)? myMain->getDataflow()->Run() : myNode->ReStart())) {
442       QMessageBox::warning( SUIT_Session::session()->activeApplication()->desktop(),  tr("ERROR"), tr("MSG_CANT_RESTARTNODE") );
443     }
444   } else {
445     if (!((n==1)? myMain->getDataflow()->Stop() : myNode->Stop())) {
446       QMessageBox::warning( SUIT_Session::session()->activeApplication()->desktop(),  tr("ERROR"), tr("MSG_CANT_STOPNODE") );
447     }
448   }
449 }
450 */
451 void SUPERVGUI_CanvasNode::changeInformation() {
452   SUPERVGUI_Information* aDlg = new SUPERVGUI_Information(myNode, !myMain->isEditable());
453   if (aDlg->exec()) {
454
455     QString aName = myNode->Name();
456     if (!aName.isEmpty() && myMain->isEditable()) {
457       //mkr : modifications for fixing bug IPAL9972
458       //setNodeName(aName);
459
460       setName(myNode->Name());
461       getPrs()->updateInfo();
462       // TODO: update name of all the links to this node
463     }
464
465   }
466   delete aDlg;
467 }
468
469 /* asv : 13.12.04 : The functions below are not called from anywhere, so commenting them out...
470 void SUPERVGUI_CanvasNode::configure() 
471 {
472   Trace("SUPERVGUI_CanvasNode::configure");
473   QMessageBox::warning( SUIT_Session::session()->activeApplication()->desktop(),  tr("ERROR"), tr("MSG_NOT_IMPLEMENTED") ); // kloss : a faire : lancer l'ihm DATA
474 }
475
476 void SUPERVGUI_CanvasNode::showPython() 
477 {
478   Trace("SUPERVGUI_CanvasNode::showPython");
479   SUPERVGUI_Python cp(myMain->getStudy()->get_PyInterp(), !myMain->isEditable());
480   cp.exec();
481 }
482 */
483
484 bool SUPERVGUI_CanvasNode::isWarning() 
485 {
486   Trace("SUPERVGUI_CanvasNode::isWarning");
487   return(warning);
488 }
489
490 bool SUPERVGUI_CanvasNode::isStep() 
491 {
492   Trace("SUPERVGUI_CanvasNode::isStep");
493   return(step);
494 }
495
496 bool SUPERVGUI_CanvasNode::isTrace() 
497 {
498   Trace("SUPERVGUI_CanvasNode::isTrace");
499   return(trace);
500 }
501
502 bool SUPERVGUI_CanvasNode::isVerbose() 
503 {
504   Trace("SUPERVGUI_CanvasNode::isVerbose");
505   return(verbose);
506 }
507
508 void SUPERVGUI_CanvasNode::setWarning(bool b) 
509 {
510   Trace("SUPERVGUI_CanvasNode::setWarning");
511   warning = b;
512 }
513
514 void SUPERVGUI_CanvasNode::setStep(bool b) 
515 {
516   Trace("SUPERVGUI_CanvasNode::setStep");
517   step = b;
518 }
519
520 void SUPERVGUI_CanvasNode::setTrace(bool b) 
521 {
522   Trace("SUPERVGUI_CanvasNode::setTrace");
523   trace = b;
524 }
525
526 void SUPERVGUI_CanvasNode::setVerbose(bool b) 
527 {
528   Trace("SUPERVGUI_CanvasNode::setVerbose");
529   verbose = b;
530 }
531
532
533 void SUPERVGUI_CanvasNode::browse() 
534 {
535   // asv 28.01.05 : set "Editing" flag only on "OK" pressed in BrowseDlg
536   //myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag 
537   if (!myBrowseDlg) {
538     myBrowseDlg = new SUPERVGUI_BrowseNodeDlg(this);
539     myBrowseDlg->installEventFilter(this);
540   }
541   if (!myBrowseDlg->isVisible())
542     myBrowseDlg->show();
543   else {
544     myBrowseDlg->raise();
545     myBrowseDlg->setActiveWindow();
546     myBrowseDlg->setFocus();
547   }
548 }
549
550 bool SUPERVGUI_CanvasNode::eventFilter( QObject* o, QEvent* e )
551 {
552   if (o == myBrowseDlg && e->type() == QEvent::Close)
553     myBrowseDlg = 0;
554   return QObject::eventFilter(o, e);
555 }
556
557 QStringList SUPERVGUI_CanvasNode::getPortsNamesIN(SUPERV_INode theNode, bool theInputPorts)
558 {
559   QStringList aPNList;
560   if (!SUPERV_isNull(theNode)) {
561     SUPERV_Ports aPorts = theNode->Ports();
562     for (int i=0; i<aPorts->length(); i++) {
563       if (theInputPorts) {
564         if (aPorts[i]->IsInput()) aPNList.append(QString(aPorts[i]->Name()));
565       }
566       else 
567         if (!aPorts[i]->IsInput()) aPNList.append(QString(aPorts[i]->Name()));
568     }
569   }
570   return aPNList;
571 }
572
573 SUPERV_Port SUPERVGUI_CanvasNode::createInPort() 
574 {
575   SUPERV_INode aNode = getInlineNode();
576   if (SUPERV_isNull(aNode)) {
577     MESSAGE("SUPERVGUI_CanvasNode::createInPort: Node is wrong type");
578     return NULL;
579   }
580   SUPERVGUI_PortParamsDlg* aDlg = new SUPERVGUI_PortParamsDlg(getPortsNamesIN(aNode,true));
581   if (aDlg->exec()) {
582     myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag 
583     SUPERV_Port aPort = aNode->InPort(aDlg->getName().latin1(),
584                                       aDlg->getType().latin1());    
585     delete aDlg;
586     return aPort;
587   }
588   delete aDlg;
589   return NULL;
590 }
591
592 SUPERV_Port SUPERVGUI_CanvasNode::createOutPort() 
593 {
594   SUPERV_INode aNode = getInlineNode();
595   if (SUPERV_isNull(aNode)) {
596     MESSAGE("SUPERVGUI_CanvasNode::createOutPort: Node is wrong type");
597     return NULL;
598   }
599   
600   SUPERVGUI_PortParamsDlg* aDlg = new SUPERVGUI_PortParamsDlg(getPortsNamesIN(aNode,false));
601   if (aDlg->exec()) {
602     myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag 
603     SUPERV_Port aPort = aNode->OutPort(aDlg->getName().latin1(),
604                                        aDlg->getType().latin1());
605     delete aDlg;
606     return aPort;
607   }
608   delete aDlg;
609   return NULL;
610 }
611
612 // mkr : IPAL9815 : commented the following code
613 /*void SUPERVGUI_CanvasNode::addInputPort() {
614   SUPERV_Port aPort = createInPort();
615   if (aPort == NULL || CORBA::is_nil( aPort ) ) return;
616
617   createPort(aPort.in());
618 }
619
620
621 void SUPERVGUI_CanvasNode::addOutputPort() {
622   SUPERV_Port aPort = createOutPort();
623   if (aPort == NULL || CORBA::is_nil( aPort ) ) return;
624
625   createPort(aPort.in());
626 }*/
627
628
629 void SUPERVGUI_CanvasNode::editFunction()  {
630   if (getNodeType() == SUPERV::LoopNode) {
631     SUPERVGUI_EditPythonDlg* aDlg = new SUPERVGUI_EditPythonDlg(true);
632     SUPERV_LNode aLNode = getLoopNode();
633     aDlg->setInitFunction(aLNode->PyInit());
634     aDlg->setMoreFunction(aLNode->PyMore());
635     aDlg->setNextFunction(aLNode->PyNext());
636     if (aDlg->exec()) {
637       myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag 
638       aLNode->SetPyInit(aDlg->getInitFuncName().latin1(), (aDlg->getInitFunction()).in());
639       aLNode->SetPyMore(aDlg->getMoreFuncName().latin1(), (aDlg->getMoreFunction()).in());
640       aLNode->SetPyNext(aDlg->getNextFuncName().latin1(), (aDlg->getNextFunction()).in());
641     }
642     delete aDlg;
643   } 
644   else {
645     SUPERVGUI_EditPythonDlg* aDlg = new SUPERVGUI_EditPythonDlg();
646     SUPERV_INode aINode = getInlineNode();
647     aDlg->setFunction(aINode->PyFunction());
648     if (aDlg->exec()) {
649       myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag 
650       aINode->SetPyFunction(aDlg->getFuncName().latin1(), (aDlg->getFunction()).in());
651     }
652     delete aDlg;
653   }
654 }
655
656 /** 
657  * Called on "Paste port" command of popup menu
658  */
659 void SUPERVGUI_CanvasNode::pastePort() {
660   SUPERVGUI_Clipboard::getClipboard()->pastePort( this );
661 }
662
663 /** 
664  * Called on "Edit ports" popup menu command. See SUPERVGUI_ManagePortsDlg.h
665  * for detailed description of the functionality
666  */
667 void SUPERVGUI_CanvasNode::managePorts() {
668   SUPERVGUI_ManagePortsDlg* aDlg = new SUPERVGUI_ManagePortsDlg( this );
669   aDlg->exec();
670   delete aDlg;
671 }
672
673 /**
674  * Called on "Export to Library" popup menu command.  See SUPERVGUI_Library.h
675  * for details on InLine nodes library functionality
676  */
677 void SUPERVGUI_CanvasNode::exportToLib() {
678   SUPERV::INode_var anINode = SUPERV::INode::_narrow( getEngine() );
679   if ( !CORBA::is_nil( anINode ) )
680     SUPERVGUI_Library::getLibrary()->Export( anINode );
681   else
682     SUIT_MessageBox::error1( SUIT_Session::session()->activeApplication()->desktop(), tr( "ERROR" ), tr( "MSG_BAD_INODE" ), tr( "OK" ) );
683 }