Salome HOME
Using files from package LightApp instead of files from package SalomeApp
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_BrowseNodeDlg.cxx
index dd0939e97fdef71e409a0505fbfb0d70fc164fcc..334b7c3413510e01279c7fe68df157f9cabf7bec 100644 (file)
@@ -9,12 +9,25 @@
 //  Module : SUPERV
 
 using namespace std;
+
+#include "SALOMEDSClient.hxx"
+#include "SALOMEDS_SObject.hxx"
+#include "SALOMEDS_Study.hxx"
+#include <boost/shared_ptr.hpp>
+using namespace boost;
+
+#include "SalomeApp_Application.h"
+#include "LightApp_SelectionMgr.h"
+#include "SalomeApp_Study.h"
+#include "SUIT_Session.h"
+
+#include "SALOME_ListIO.hxx"
+
 #include "SUPERVGUI_BrowseNodeDlg.h"
-#include "SUPERVGUI_Node.h"
 #include "SUPERVGUI_CanvasNode.h"
-#include "SUPERVGUI_Port.h"
 #include "SUPERVGUI_CanvasPort.h"
 #include "SUPERVGUI.h"
+
 #include <qlayout.h>
 #include <qlabel.h>
 #include <qlineedit.h>
@@ -66,10 +79,16 @@ bool SUPERVGUI_PortField::setNewValue() {
   if ( !myIsEditable ) return false;
 
   QString aTxt = myValue->text();
-  if ( aTxt.isNull() || aTxt.isEmpty() ) return false;
+  //mkr : fix for bug IPAL9441
+  //if ( aTxt.isNull() || aTxt.isEmpty() ) return false;
   
   if ( aTxt.find( "Unknown" ) < 0 ) {
-    return myPort->Input( Supervision.getEngine()->StringValue( aTxt ) );
+    SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
+    if ( !aSupMod ) {
+      MESSAGE("NULL Supervision module!");
+      return false;
+    }
+    return myPort->Input( aSupMod->getEngine()->StringValue( aTxt ) );
   }
   return false;
 }
@@ -88,25 +107,12 @@ bool SUPERVGUI_PortField::eventFilter( QObject* o, QEvent* e )
 }
 
 
-/**
- * Constructor (SUPERVGUI_Node)
- */
-SUPERVGUI_BrowseNodeDlg::SUPERVGUI_BrowseNodeDlg( SUPERVGUI_Node* theNode )
-  : QDialog( theNode, 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
-{
-  myNode = theNode;
-  myNodeCanvas = 0;
-
-  init();
-}
-
 /**
  * Constructor (SUPERVGUI_CanvasNode)
  */
 SUPERVGUI_BrowseNodeDlg::SUPERVGUI_BrowseNodeDlg( SUPERVGUI_CanvasNode* theNode )
-  : QDialog( QAD_Application::getDesktop(), 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
+  : QDialog( SUIT_Session::session()->activeApplication()->desktop(), 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
 {
-  myNode = 0;
   myNodeCanvas = theNode;
 
   init();
@@ -118,15 +124,8 @@ void SUPERVGUI_BrowseNodeDlg::init()
   setSizeGripEnabled( true );
   myPortsList.setAutoDelete( true );
 
-  SUPERV_CNode aEngine;
-  if (myNode != 0)
-    aEngine = myNode->getEngine();
-  else
-    aEngine = myNodeCanvas->getEngine();
+  SUPERV_CNode aEngine = myNodeCanvas->getEngine();
   
-  mySelection = SALOME_Selection::Selection( Supervision.getActiveStudy()->getSelection() );
-//  mySelection->ClearIObjects();
-
   setName( "SUPERVGUI_BrowseNodeDlg" );
   setCaption( tr( "TIT_BROWSENODE" ) + aEngine->Name() );
 
@@ -151,7 +150,8 @@ void SUPERVGUI_BrowseNodeDlg::init()
     if ( ports[i]->IsInput() ) {
       if ( !ports[i]->IsGate() ) { // not a gate
        SUPERVGUI_PortField* aField = new SUPERVGUI_PortField( aInBox, ports[i] );
-       if ( aField->isEditable() ) myIsEditable = true;
+       if ( aField->isEditable() ) 
+         myIsEditable = true;
        myPortsList.append( aField );
        if ( !myActiveField )
          myActiveField = aField;
@@ -196,11 +196,12 @@ void SUPERVGUI_BrowseNodeDlg::init()
   if ( !myIsEditable )
     aBtnLayout->addStretch();
 
-  connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
-  if (myNode != 0)
-    myNode->getMain()->lockedGraph(true);
-  else
-    myNodeCanvas->getMain()->lockedGraph(true);
+  SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
+  if ( aSupMod ) connect( (( SalomeApp_Application* )(aSupMod->getActiveStudy()->application()))->selectionMgr(), 
+                         SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
+  else MESSAGE("NULL Supervision module!");
+  
+  myNodeCanvas->getMain()->lockedGraph(true);
 }
 
 /**
@@ -223,22 +224,16 @@ void SUPERVGUI_BrowseNodeDlg::setValues() {
  * Set inputed values of editable ports and then closes and destroys dialog
  */
 void SUPERVGUI_BrowseNodeDlg::accept() {
+  myNodeCanvas->getMain()->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag 
   if ( myIsEditable ) {
     SUPERVGUI_PortField* aField;
     for ( aField = myPortsList.first(); aField; aField = myPortsList.next() ) {
       aField->setNewValue();
     }
-    if (myNode != 0)
-      myNode->sync();
-    else {
-      myNodeCanvas->sync();
-      myNodeCanvas->getMain()->getCanvas()->update();
-    }
+    myNodeCanvas->sync();
+    myNodeCanvas->getMain()->getCanvas()->update();
   }
-  if (myNode != 0)
-    myNode->getMain()->lockedGraph(false);
-  else
-    myNodeCanvas->getMain()->lockedGraph(false);
+  myNodeCanvas->getMain()->lockedGraph(false);
   QDialog::accept();
   close();
 }
@@ -248,10 +243,7 @@ void SUPERVGUI_BrowseNodeDlg::accept() {
  * Closes and destroys dialog
  */
 void SUPERVGUI_BrowseNodeDlg::reject() {
-  if (myNode != 0)
-    myNode->getMain()->lockedGraph(false);
-  else
-    myNodeCanvas->getMain()->lockedGraph(false);
+  myNodeCanvas->getMain()->lockedGraph(false);
   QDialog::reject();
   close();
 }
@@ -281,22 +273,37 @@ void SUPERVGUI_BrowseNodeDlg::onFieldActivated()
 void SUPERVGUI_BrowseNodeDlg::onSelectionChanged()
 {
   if ( myActiveField ) {
-    if( mySelection->IObjectCount() == 1 ) {
-      Handle( SALOME_InteractiveObject ) anIO = mySelection->firstIObject();
+    
+    SALOME_ListIO aList;
+    aList.Clear();
+
+    SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
+    if ( !aSupMod ) {
+      MESSAGE("NULL Supervision module!");
+      return;
+    }
+
+    (( SalomeApp_Application* )(aSupMod->getActiveStudy()->application()))
+      ->selectionMgr()->selectedObjects( aList );
+    
+    if( aList.Extent() == 1 ) {
+      Handle( SALOME_InteractiveObject ) anIO = aList.First();
       if ( anIO->hasEntry() ) {
-       SALOMEDS::SObject_var aObj = Supervision.getActiveStudy()->
-       getStudyDocument()->FindObjectID( anIO->getEntry() );
+       _PTR(SObject) aObj ( dynamic_cast<SalomeApp_Study*>( aSupMod->getActiveStudy() )->
+                            studyDS()->FindObjectID( anIO->getEntry() ) );
          
-       SALOMEDS::GenericAttribute_var anAttr;
-       SALOMEDS::AttributeIOR_var     anIOR;
-       Standard_CString               ior = "";
+       _PTR(GenericAttribute) anAttr;
+       QString ior("");
          
        if (aObj->FindAttribute( anAttr, "AttributeIOR" ) ) {
-         anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
-         ior = anIOR->Value();
+         _PTR(AttributeIOR) anIOR ( anAttr );
+         ior = anIOR->Value().c_str();
        }
        else {
-         ior = aObj->GetStudy()->ConvertObjectToIOR( aObj );
+         SALOMEDS_Study* aSStudy = dynamic_cast<SALOMEDS_Study*>( aObj->GetStudy().get() );
+         SALOMEDS_SObject* aSSObj = dynamic_cast<SALOMEDS_SObject*>( aObj.get() );
+         if ( aSStudy && aSSObj )
+           ior = aSStudy->ConvertObjectToIOR( aSSObj->GetObject() ).c_str();
        }
        myActiveField->setData( ior );
       }
@@ -304,40 +311,13 @@ void SUPERVGUI_BrowseNodeDlg::onSelectionChanged()
   }
 }
 
-/**
- * Constructor (SUPERVGUI_PortIn)
- */
-SUPERVGUI_GetValueDlg::SUPERVGUI_GetValueDlg( SUPERVGUI_PortIn* thePort )
-  : QDialog( thePort, 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
-{
-  myPort = thePort;
-  myPortESNode = 0;
-  myPortCanvas = 0;
-
-  init();
-}
-
-/**
- * Constructor (SUPERVGUI_PortInESNode)
- */
-SUPERVGUI_GetValueDlg::SUPERVGUI_GetValueDlg( SUPERVGUI_PortInESNode* thePort )
-  : QDialog( thePort, 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
-{
-  myPort = 0;
-  myPortESNode = thePort;
-  myPortCanvas = 0;
-
-  init();
-}
 
 /**
  * Constructor (SUPERVGUI_CanvasPort)
  */
 SUPERVGUI_GetValueDlg::SUPERVGUI_GetValueDlg( SUPERVGUI_CanvasPort* thePort )
-  : QDialog( QAD_Application::getDesktop(), 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
+  : QDialog( SUIT_Session::session()->activeApplication()->desktop(), 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
 {
-  myPort = 0;
-  myPortESNode = 0;
   myPortCanvas = thePort;
 
   init();
@@ -348,9 +328,6 @@ void SUPERVGUI_GetValueDlg::init()
   myOKBtn = 0;
   setSizeGripEnabled( true );
 
-  mySelection = SALOME_Selection::Selection( Supervision.getActiveStudy()->getSelection() );
-//  mySelection->ClearIObjects();
-
   setName( "SUPERVGUI_GetValueDlg" );
   setCaption( tr( "TIT_SETVALUE_PORT" ) );
   
@@ -369,14 +346,8 @@ void SUPERVGUI_GetValueDlg::init()
   QLabel* aInfoLab = new QLabel( tr( "ENTER_OR_SELECT_LBL" ), aBox );
   QFont fnt = aInfoLab->font(); fnt.setBold( true ); aInfoLab->setFont( fnt );
   aBoxLayout->addMultiCellWidget( aInfoLab, 0, 0, 0, 1 );
-  SUPERV_Port aEngine;
-  if (myPort != 0)
-    aEngine = myPort->getPort();
-  else if (myPortESNode != 0)
-    aEngine = myPortESNode->getPort();
-  else {
-    aEngine = myPortCanvas->getEngine();
-  }
+  SUPERV_Port aEngine = myPortCanvas->getEngine();
+
   myField = new SUPERVGUI_PortField( aBox, aEngine );
   bool myIsEditable = myField->isEditable();
   aBoxLayout->addWidget( myField->myLabel, 1, 0 ); 
@@ -406,13 +377,13 @@ void SUPERVGUI_GetValueDlg::init()
     aBtnLayout->addStretch();
 
   myField->updateGUI();
-  connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
-  if (myPort != 0)
-    myPort->getMain()->lockedGraph(true);
-  else if (myPortESNode != 0)
-    myPortESNode->getMain()->lockedGraph(true);
-  else
-    myPortCanvas->getMain()->lockedGraph(true);
+  
+  SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
+  if ( aSupMod ) connect( (( SalomeApp_Application* )(aSupMod->getActiveStudy()->application()))->selectionMgr(), 
+                         SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
+  else MESSAGE("NULL Supervision module!");
+  myPortCanvas->getMain()->lockedGraph(true);
 }
 
 /**
@@ -425,30 +396,29 @@ SUPERVGUI_GetValueDlg::~SUPERVGUI_GetValueDlg() {
  * Set entered value into port and then closes and destroys dialog
  */
 void SUPERVGUI_GetValueDlg::accept() {
+  myPortCanvas->getMain()->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag 
   if ( myField->setNewValue() ) {
     
-    if (myPort != 0)
-      myPort->sync();
-    else if (myPortESNode != 0)
-      myPortESNode->sync();
-    else {
-      myPortCanvas->sync();
-      myPortCanvas->getMain()->getCanvas()->update();
-    }
+    myPortCanvas->sync();
+
+    // asv : 19.11.04 : fix for 6170, last comment of it about BrowsePort - update node status
+    // asv : 13.12.04 : commented out sync() of Node.  See 2.21.
+    //if ( myPortCanvas->parent() && myPortCanvas->parent()->inherits( "SUPERVGUI_CanvasNode" ) ) {
+    //  SUPERVGUI_CanvasNode* aNode = (SUPERVGUI_CanvasNode*)myPortCanvas->parent();
+    //  aNode->sync();
+    //}
+
+    myPortCanvas->getMain()->getCanvas()->update();
   }
   else {
-    if ( QMessageBox::warning( QAD_Application::getDesktop(), 
+    if ( QMessageBox::warning( SUIT_Session::session()->activeApplication()->desktop(), 
                               tr( "ERROR" ), tr( "MSG_CANT_SETVAL" ),
                               QMessageBox::Retry, QMessageBox::Abort) == QMessageBox::Retry )
       return;
   }
 
-  if (myPort != 0)
-    myPort->getMain()->lockedGraph(false);
-  else if (myPortESNode != 0)
-    myPortESNode->getMain()->lockedGraph(false);
-  else
-    myPortCanvas->getMain()->lockedGraph(false);
+  myPortCanvas->getMain()->lockedGraph(false);
+  
   QDialog::accept();
   close();
 }
@@ -457,12 +427,7 @@ void SUPERVGUI_GetValueDlg::accept() {
  * Closes and destroys dialog
  */
 void SUPERVGUI_GetValueDlg::reject() {
-  if (myPort != 0)
-    myPort->getMain()->lockedGraph(false);
-  else if (myPortESNode != 0)
-    myPortESNode->getMain()->lockedGraph(false);
-  else
-    myPortCanvas->getMain()->lockedGraph(false);
+  myPortCanvas->getMain()->lockedGraph(false);
   QDialog::reject();
   close();
 }
@@ -472,22 +437,36 @@ void SUPERVGUI_GetValueDlg::reject() {
  */
 void SUPERVGUI_GetValueDlg::onSelectionChanged()
 {
-  if( mySelection->IObjectCount() == 1 ) {
-    Handle( SALOME_InteractiveObject ) anIO = mySelection->firstIObject();
+  SALOME_ListIO aList;
+  aList.Clear();
+  
+  SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
+  if ( !aSupMod ) {
+    MESSAGE("NULL Supervision module!");
+    return;
+  }
+  
+  (( SalomeApp_Application* )(aSupMod->getActiveStudy()->application()))
+    ->selectionMgr()->selectedObjects( aList );
+  
+  if( aList.Extent() == 1 ) {
+    Handle( SALOME_InteractiveObject ) anIO = aList.First();
     if ( anIO->hasEntry() ) {
-      SALOMEDS::SObject_var aObj = Supervision.getActiveStudy()->
-      getStudyDocument()->FindObjectID( anIO->getEntry() );
+      _PTR(SObject) aObj ( dynamic_cast<SalomeApp_Study*>( aSupMod->getActiveStudy() )->
+                          studyDS()->FindObjectID( anIO->getEntry() ) );
        
-      SALOMEDS::GenericAttribute_var anAttr;
-      SALOMEDS::AttributeIOR_var     anIOR;
-      Standard_CString               ior = "";
+      _PTR(GenericAttribute) anAttr;
+      QString ior("");
        
       if (aObj->FindAttribute( anAttr, "AttributeIOR" ) ) {
-       anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
-       ior = anIOR->Value();
+       _PTR(AttributeIOR) anIOR ( anAttr );
+       ior = anIOR->Value().c_str();
       }
       else {
-       ior = aObj->GetStudy()->ConvertObjectToIOR( aObj );
+       SALOMEDS_Study* aSStudy = dynamic_cast<SALOMEDS_Study*>( aObj->GetStudy().get() );
+       SALOMEDS_SObject* aSSObj = dynamic_cast<SALOMEDS_SObject*>( aObj.get() );
+       if ( aSStudy && aSSObj )
+         ior = aSStudy->ConvertObjectToIOR( aSSObj->GetObject() ).c_str();
       }
       myField->setData( ior );
     }
@@ -500,18 +479,9 @@ void SUPERVGUI_GetValueDlg::onSelectionChanged()
 // Stream Ports
 // ----------------------------
 
-SUPERVGUI_StreamInDlg::SUPERVGUI_StreamInDlg(SUPERVGUI_StreamPortIn* thePort)
-  :QDialog( QAD_Application::getDesktop(), "", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
-{
-  myPort = thePort;
-  myPortCanvas = 0;
-  init();
-}
-
 SUPERVGUI_StreamInDlg::SUPERVGUI_StreamInDlg(SUPERVGUI_CanvasStreamPortIn* thePort)
-  :QDialog( QAD_Application::getDesktop(), "", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
+  :QDialog( SUIT_Session::session()->activeApplication()->desktop(), "", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
 {
-  myPort = 0;
   myPortCanvas = thePort;
   init();
 }
@@ -591,10 +561,7 @@ void SUPERVGUI_StreamInDlg::setData() {
   SUPERV::KindOfInterpolation aInterpolat;
   SUPERV::KindOfExtrapolation aExtrapolat;
 
-  if (myPort != 0)
-    myPort->getStreamPort()->Params(aSchema, aInterpolat, aExtrapolat);
-  else
-    myPortCanvas->getStreamEngine()->Params(aSchema, aInterpolat, aExtrapolat);
+  myPortCanvas->getStreamEngine()->Params(aSchema, aInterpolat, aExtrapolat);
 
   mySchemaCombo->setCurrentItem((int)aSchema);
   myInterCombo->setCurrentItem((int)aInterpolat);
@@ -602,30 +569,18 @@ void SUPERVGUI_StreamInDlg::setData() {
 }
 
 void SUPERVGUI_StreamInDlg::accept() {
-  if (myPort != 0)
-    myPort->getStreamPort()->SetParams((SUPERV::KindOfSchema) mySchemaCombo->currentItem(), 
-                                      (SUPERV::KindOfInterpolation) myInterCombo->currentItem(),
-                                      (SUPERV::KindOfExtrapolation) myExterCombo->currentItem());
-  else
-    myPortCanvas->getStreamEngine()->SetParams((SUPERV::KindOfSchema) mySchemaCombo->currentItem(), 
-                                              (SUPERV::KindOfInterpolation) myInterCombo->currentItem(),
-                                              (SUPERV::KindOfExtrapolation) myExterCombo->currentItem());
+  myPortCanvas->getMain()->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag 
+  myPortCanvas->getStreamEngine()->SetParams((SUPERV::KindOfSchema) mySchemaCombo->currentItem(), 
+                                            (SUPERV::KindOfInterpolation) myInterCombo->currentItem(),
+                                            (SUPERV::KindOfExtrapolation) myExterCombo->currentItem());
   QDialog::accept();
 }
 
 
 //-------------------------------------------------------------------------
-SUPERVGUI_StreamOutDlg::SUPERVGUI_StreamOutDlg(SUPERVGUI_StreamPortOut* thePort)
-  :QDialog( QAD_Application::getDesktop(), "", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
-{
-  myPort = thePort;
-  myPortCanvas = 0;
-  init();
-}
 SUPERVGUI_StreamOutDlg::SUPERVGUI_StreamOutDlg(SUPERVGUI_CanvasStreamPortOut* thePort)
-  :QDialog( QAD_Application::getDesktop(), "", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
+  :QDialog( SUIT_Session::session()->activeApplication()->desktop(), "", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
 {
-  myPort = 0;
   myPortCanvas = thePort;
   init();
 }
@@ -646,11 +601,7 @@ void SUPERVGUI_StreamOutDlg::init()
   myValEdit = new QLineEdit( aCtrlPane, "ValEdit" );
   myValEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
   myValEdit->setValidator( new QIntValidator(this) );
-  SUPERV_StreamPort aEngine;
-  if (myPort != 0)
-    aEngine = myPort->getStreamPort();
-  else
-    aEngine = myPortCanvas->getStreamEngine();
+  SUPERV_StreamPort aEngine = myPortCanvas->getStreamEngine();
   myValEdit->setText(QString("%1").arg(aEngine->NumberOfValues()));
   aCtrlLayout->addWidget(myValEdit, 0, 1);
   TopLayout->addWidget( aCtrlPane );
@@ -683,10 +634,7 @@ void SUPERVGUI_StreamOutDlg::accept() {
   QString aStr = myValEdit->text();
   if (!aStr.isEmpty())
     aRes = aStr.toLong();
-  if (myPort != 0) 
-    myPort->getStreamPort()->SetNumberOfValues(aRes);
-  else
-    myPortCanvas->getStreamEngine()->SetNumberOfValues(aRes);
+  myPortCanvas->getStreamEngine()->SetNumberOfValues(aRes);
   QDialog::accept();
 }