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