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