Salome HOME
Update copyright information
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_CanvasNode.cxx
index a7469ff8a7bd4c14e49835a80e96abaa0e4446b0..9cf4132c8f246675d81b8bdfdc9ef0edc9295848 100644 (file)
@@ -1,12 +1,29 @@
-//  SUPERV SUPERVGUI : GUI for Supervisor component
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
 //
-//  Copyright (C) 2003  OPEN CASCADE
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+//  SUPERV SUPERVGUI : GUI for Supervisor component
 //  File   : SUPERVGUI_CanvasNode.cxx
 //  Author : Natalia KOPNOVA
 //  Module : SUPERV
-
-using namespace std;
+//
 #include "SUPERVGUI_CanvasNode.h"
 #include "SUPERVGUI_CanvasNodePrs.h"
 #include "SUPERVGUI_CanvasPort.h"
@@ -18,12 +35,15 @@ using namespace std;
 #include "SUPERVGUI_Information.h"
 #include "SUPERVGUI_Library.h"
 
-#include "SALOMEGUI_NameDlg.h"
-#include "QAD_MessageBox.h"
-#include "QAD_Message.h"
+#include "SUIT_MessageBox.h"
+#include "LogWindow.h"
+#include "SUIT_Session.h"
 
+#include <qinputdialog.h>
 
-SUPERVGUI_CanvasNode::SUPERVGUI_CanvasNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode, bool theIsCell):
+
+SUPERVGUI_CanvasNode::SUPERVGUI_CanvasNode( SUIT_ResourceMgr* mgr, QObject* theParent,
+                                            SUPERVGUI_Main* theMain, SUPERV_CNode theNode, bool theIsCell):
     QObject(theParent),
     myMain(theMain),
     myNode(theNode),
@@ -33,7 +53,8 @@ SUPERVGUI_CanvasNode::SUPERVGUI_CanvasNode(QObject* theParent, SUPERVGUI_Main* t
     step(true),
     trace(true),
     verbose(true),
-    myBrowseDlg(0)
+    myBrowseDlg(0),
+    myMgr( mgr )
 {
   Trace("SUPERVGUI_CanvasNode::SUPERVGUI_CanvasNode");
 
@@ -74,6 +95,9 @@ SUPERVGUI_CanvasNode::SUPERVGUI_CanvasNode(QObject* theParent, SUPERVGUI_Main* t
   }
 
   isIgnore = false;
+
+  // mkr : PAL8237
+  connect(this, SIGNAL(objectCreatedDeleted()), myMain, SLOT(onObjectCreatedDeleted()));
 }
 
 SUPERVGUI_CanvasNode::~SUPERVGUI_CanvasNode()
@@ -102,7 +126,14 @@ SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasNode::getPrs()
 
 SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasNode::createPrs() const
 {
-  return new SUPERVGUI_CanvasNodePrs(myMain->getCanvas(), (SUPERVGUI_CanvasNode*)this);
+  //
+  //SUPERVGUI_PrsNode* glNode = new SUPERVGUI_PrsNode( (SUPERVGUI_CanvasNode*)this );
+  //glNode->setFirstPoint( new GLViewer_Pnt( 10, 10 ) );
+  //glNode->compute();
+  //glNode->update();
+  //getGLContext()->insertObject( glNode, true /*false*/ );
+  //
+  return new SUPERVGUI_CanvasNodePrs( myMgr, myMain->getCanvas(), (SUPERVGUI_CanvasNode*)this);
 }
 
 void SUPERVGUI_CanvasNode::createPort(SUPERV::Port_ptr thePort)
@@ -116,6 +147,8 @@ void SUPERVGUI_CanvasNode::createPort(SUPERV::Port_ptr thePort)
   if (aPort) {
     connect(aPort, SIGNAL(destroyed(QObject*)), this, SLOT(onDestroyed(QObject*)));
     if (!isIgnore) getPrs()->updatePorts();
+    
+    emit objectCreatedDeleted(); // mkr : PAL8237
   }
 }
 
@@ -184,12 +217,13 @@ QPopupMenu* SUPERVGUI_CanvasNode::getPopupMenu(QWidget* theParent)
 
       // for all InLine except EndLoop : Add Ports menu, Paste, Manage Ports
       if ( myMain->isEditable() && type != SUPERV::EndLoopNode ) {
-       QPopupMenu* addPortMenu = new QPopupMenu(theParent);
+       // mkr : IPAL9815 : commented the following code
+       /*QPopupMenu* addPortMenu = new QPopupMenu(theParent);
        addPortMenu->insertItem( tr( "MNU_INPUT" ), this, SLOT(addInputPort()));
        if (getNodeType() != SUPERV::LoopNode)
          addPortMenu->insertItem( tr( "MNU_OUTPUT" ), this, SLOT(addOutputPort()));
 
-       popup->insertItem( tr( "MNU_ADD_PORT" ), addPortMenu);
+         popup->insertItem( tr( "MNU_ADD_PORT" ), addPortMenu);*/
        popup->insertItem( tr( "MNU_MANAGE_PORTS" ), this, SLOT(managePorts()));
 
        // Paste Port functionality
@@ -341,14 +375,18 @@ bool SUPERVGUI_CanvasNode::setNodeName(QString aName)  {
     // TODO: update name of all the links to this node
   } 
   else {
-    QMessageBox::warning( QAD_Application::getDesktop(), tr( "ERROR" ), tr( "MSG_CANT_RENAMENODE" ) );
+    QMessageBox::warning( SUIT_Session::session()->activeApplication()->desktop(), tr( "ERROR" ), tr( "MSG_CANT_RENAMENODE" ) );
   }
   return result;
 }
 
 void SUPERVGUI_CanvasNode::rename()  {
-  QString aName = SALOMEGUI_NameDlg::getName(QAD_Application::getDesktop(), myNode->Name());
-  if (!aName.isEmpty()) {
+  bool ok;
+   QString aName = QInputDialog::getText( tr( "Rename" ), tr( "Enter new name:" ), QLineEdit::Normal,
+                                          myNode->Name(), &ok, SUIT_Session::session()->activeApplication()->desktop() );
+
+  //mkr : modifications for fixing bug IPAL9972
+  if( ok && !aName.isEmpty() && aName.compare( myNode->Name() ) != 0) {
     setNodeName(aName);
   }
 }
@@ -378,6 +416,9 @@ void SUPERVGUI_CanvasNode::remove() {
   SUPERVGUI_Canvas* aCanvas = myMain->getCanvas();
   setDestroyed();
   myNode->destroy();
+
+  emit objectCreatedDeleted(); // mkr : PAL8237
+  
   delete this;
   aCanvas->update();
 }
@@ -397,7 +438,7 @@ void SUPERVGUI_CanvasNode::suspendResume() {
   int n = queryList("SUPERVGUI_CanvasNode")->count(); 
   if (myNode->IsSuspended()) {
     if (!((n==1)? myMain->getDataflow()->Resume() : myNode->Resume())) {
-      QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_RESUMENODE"));
+      QMessageBox::warning( SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CANT_RESUMENODE") );
     }
     else {
       sync();
@@ -405,10 +446,10 @@ void SUPERVGUI_CanvasNode::suspendResume() {
     }
   } else {
     if (!((n==1)? myMain->getDataflow()->Suspend() : myNode->Suspend())) {
-      QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_SUSPENDNODE"));
+      QMessageBox::warning( SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CANT_SUSPENDNODE") );
     } else {
       syncOnEvent(SUPERV::SuspendReadyState);
-      myMain->getMessage()->setMessage(tr("MSG_NODE_SUSPENDED1")+myNode->Name()+tr("MSG_NODE_SUSPENDED2"));
+      myMain->getMessage()->putMessage(tr("MSG_NODE_SUSPENDED1")+myNode->Name()+tr("MSG_NODE_SUSPENDED2"));
     }
   }
 }
@@ -417,10 +458,10 @@ void SUPERVGUI_CanvasNode::kill() {
   Trace("SUPERVGUI_CanvasNode::kill");
   int n = queryList("SUPERVGUI_CanvasNode")->count(); 
   if (!((n==1)? myMain->getDataflow()->Kill() : myNode->Kill())) {
-    QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_KILLNODE"));
+    QMessageBox::warning( SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CANT_KILLNODE") );
   } else {
     syncOnEvent(SUPERV_Kill);
-    myMain->getMessage()->setMessage(tr("MSG_NODE_KILLED1")+myNode->Name()+tr("MSG_NODE_KILLED2"));
+    myMain->getMessage()->putMessage(tr("MSG_NODE_KILLED1")+myNode->Name()+tr("MSG_NODE_KILLED2"));
   }
 }
 /* asv : 15.12.04 : commented out stopRestart() in Main and CanvasNode because it's not called from anywhere,
@@ -431,11 +472,11 @@ void SUPERVGUI_CanvasNode::stopRestart() {
   int n = queryList("SUPERVGUI_CanvasNode")->count(); 
   if ((myNode->State() == SUPERV_Stop) || (myNode->State() == SUPERV_Kill)) {
     if (!((n==1)? myMain->getDataflow()->Run() : myNode->ReStart())) {
-      QMessageBox::warning(QAD_Application::getDesktop(),  tr("ERROR"), tr("MSG_CANT_RESTARTNODE"));
+      QMessageBox::warning( SUIT_Session::session()->activeApplication()->desktop(),  tr("ERROR"), tr("MSG_CANT_RESTARTNODE") );
     }
   } else {
     if (!((n==1)? myMain->getDataflow()->Stop() : myNode->Stop())) {
-      QMessageBox::warning(QAD_Application::getDesktop(),  tr("ERROR"), tr("MSG_CANT_STOPNODE"));
+      QMessageBox::warning( SUIT_Session::session()->activeApplication()->desktop(),  tr("ERROR"), tr("MSG_CANT_STOPNODE") );
     }
   }
 }
@@ -443,9 +484,17 @@ void SUPERVGUI_CanvasNode::stopRestart() {
 void SUPERVGUI_CanvasNode::changeInformation() {
   SUPERVGUI_Information* aDlg = new SUPERVGUI_Information(myNode, !myMain->isEditable());
   if (aDlg->exec()) {
+
     QString aName = myNode->Name();
-    if (!aName.isEmpty() && myMain->isEditable())
-      setNodeName(aName);
+    if (!aName.isEmpty() && myMain->isEditable()) {
+      //mkr : modifications for fixing bug IPAL9972
+      //setNodeName(aName);
+
+      setName(myNode->Name());
+      getPrs()->updateInfo();
+      // TODO: update name of all the links to this node
+    }
+
   }
   delete aDlg;
 }
@@ -454,7 +503,7 @@ void SUPERVGUI_CanvasNode::changeInformation() {
 void SUPERVGUI_CanvasNode::configure() 
 {
   Trace("SUPERVGUI_CanvasNode::configure");
-  QMessageBox::warning(QAD_Application::getDesktop(),  tr("ERROR"), tr("MSG_NOT_IMPLEMENTED")); // kloss : a faire : lancer l'ihm DATA
+  QMessageBox::warning( SUIT_Session::session()->activeApplication()->desktop(),  tr("ERROR"), tr("MSG_NOT_IMPLEMENTED") ); // kloss : a faire : lancer l'ihm DATA
 }
 
 void SUPERVGUI_CanvasNode::showPython() 
@@ -563,6 +612,7 @@ SUPERV_Port SUPERVGUI_CanvasNode::createInPort()
   }
   SUPERVGUI_PortParamsDlg* aDlg = new SUPERVGUI_PortParamsDlg(getPortsNamesIN(aNode,true));
   if (aDlg->exec()) {
+    myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag 
     SUPERV_Port aPort = aNode->InPort(aDlg->getName().latin1(),
                                      aDlg->getType().latin1());    
     delete aDlg;
@@ -582,6 +632,7 @@ SUPERV_Port SUPERVGUI_CanvasNode::createOutPort()
   
   SUPERVGUI_PortParamsDlg* aDlg = new SUPERVGUI_PortParamsDlg(getPortsNamesIN(aNode,false));
   if (aDlg->exec()) {
+    myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag 
     SUPERV_Port aPort = aNode->OutPort(aDlg->getName().latin1(),
                                       aDlg->getType().latin1());
     delete aDlg;
@@ -591,9 +642,8 @@ SUPERV_Port SUPERVGUI_CanvasNode::createOutPort()
   return NULL;
 }
 
-void SUPERVGUI_CanvasNode::addInputPort() {
-  myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag 
-
+// mkr : IPAL9815 : commented the following code
+/*void SUPERVGUI_CanvasNode::addInputPort() {
   SUPERV_Port aPort = createInPort();
   if (aPort == NULL || CORBA::is_nil( aPort ) ) return;
 
@@ -602,18 +652,14 @@ void SUPERVGUI_CanvasNode::addInputPort() {
 
 
 void SUPERVGUI_CanvasNode::addOutputPort() {
-  myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag 
-
   SUPERV_Port aPort = createOutPort();
   if (aPort == NULL || CORBA::is_nil( aPort ) ) return;
 
   createPort(aPort.in());
-}
+}*/
 
 
 void SUPERVGUI_CanvasNode::editFunction()  {
-  myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag 
-
   if (getNodeType() == SUPERV::LoopNode) {
     SUPERVGUI_EditPythonDlg* aDlg = new SUPERVGUI_EditPythonDlg(true);
     SUPERV_LNode aLNode = getLoopNode();
@@ -621,6 +667,7 @@ void SUPERVGUI_CanvasNode::editFunction()  {
     aDlg->setMoreFunction(aLNode->PyMore());
     aDlg->setNextFunction(aLNode->PyNext());
     if (aDlg->exec()) {
+      myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag 
       aLNode->SetPyInit(aDlg->getInitFuncName().latin1(), (aDlg->getInitFunction()).in());
       aLNode->SetPyMore(aDlg->getMoreFuncName().latin1(), (aDlg->getMoreFunction()).in());
       aLNode->SetPyNext(aDlg->getNextFuncName().latin1(), (aDlg->getNextFunction()).in());
@@ -632,6 +679,7 @@ void SUPERVGUI_CanvasNode::editFunction()  {
     SUPERV_INode aINode = getInlineNode();
     aDlg->setFunction(aINode->PyFunction());
     if (aDlg->exec()) {
+      myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag 
       aINode->SetPyFunction(aDlg->getFuncName().latin1(), (aDlg->getFunction()).in());
     }
     delete aDlg;
@@ -650,8 +698,6 @@ void SUPERVGUI_CanvasNode::pastePort() {
  * for detailed description of the functionality
  */
 void SUPERVGUI_CanvasNode::managePorts() {
-  myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag 
-
   SUPERVGUI_ManagePortsDlg* aDlg = new SUPERVGUI_ManagePortsDlg( this );
   aDlg->exec();
   delete aDlg;
@@ -666,5 +712,14 @@ void SUPERVGUI_CanvasNode::exportToLib() {
   if ( !CORBA::is_nil( anINode ) )
     SUPERVGUI_Library::getLibrary()->Export( anINode );
   else
-    QAD_MessageBox::error1( QAD_Application::getDesktop(), tr( "ERROR" ), tr( "MSG_BAD_INODE" ), tr( "OK" ) );
+    SUIT_MessageBox::error1( SUIT_Session::session()->activeApplication()->desktop(), tr( "ERROR" ), tr( "MSG_BAD_INODE" ), tr( "OK" ) );
+}
+
+QString SUPERVGUI_CanvasNode::getToolTipText() const {
+  if ( myNode->IsFactory() )
+    return QString("Name : ") + SUPERV::FNode::_narrow(myNode)->Name() +
+      QString("\nContainer : ") + SUPERV::FNode::_narrow(myNode)->GetContainer() +
+      QString("\nComponentName : ") + SUPERV::FNode::_narrow(myNode)->GetComponentName() +
+      QString("\nInterfaceName : ") + SUPERV::FNode::_narrow(myNode)->GetInterfaceName();
+  return QString("Name : ") + myNode->Name() + '\n' + getLabelText();
 }