Salome HOME
Bug fix: don't set "Loading" state for MacroNodes in InitialState() function (called...
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_BrowseNodeDlg.cxx
index 5ec6fac860dae78364ccfde42e512e76624557d1..655c710ecf877bcc68c48459629339938a208e44 100644 (file)
@@ -1,21 +1,27 @@
-using namespace std;
-//  File      : SUPERVGUI_BrowseNodeDlg.cxx
-//  Created   : 10 / 01 / 2003
-//  Author    : Vitaly SMETANNIKOV
-//  Project   : SALOME 
-//  Module    : SUPERVGUI
-//  Copyright : Open CASCADE 
+//  SUPERV SUPERVGUI : GUI for Supervisor component
+//
+//  Copyright (C) 2003  CEA/DEN, EDF R&D
+//
+//
+//
+//  File   : SUPERVGUI_BrowseNodeDlg.cxx
+//  Author : Vitaly SMETANNIKOV
+//  Module : SUPERV
 
+using namespace std;
 
 #include "SUPERVGUI_BrowseNodeDlg.h"
-#include "SUPERVGUI_Node.h"
+#include "SUPERVGUI_CanvasNode.h"
+#include "SUPERVGUI_CanvasPort.h"
 #include "SUPERVGUI.h"
+
 #include <qlayout.h>
 #include <qlabel.h>
 #include <qlineedit.h>
 #include <qpushbutton.h>
 #include <qhbox.h>
 #include <qgroupbox.h>
+#include <qvalidator.h>
 
 /**
  * Constructor
@@ -63,7 +69,7 @@ bool SUPERVGUI_PortField::setNewValue() {
   if ( aTxt.isNull() || aTxt.isEmpty() ) return false;
   
   if ( aTxt.find( "Unknown" ) < 0 ) {
-    return myPort->Input( ( *Supervision.getEngine() )->StringValue( aTxt ) );
+    return myPort->Input( Supervision.getEngine()->StringValue( aTxt ) );
   }
   return false;
 }
@@ -83,17 +89,24 @@ bool SUPERVGUI_PortField::eventFilter( QObject* o, QEvent* e )
 
 
 /**
- * Constructor
+ * Constructor (SUPERVGUI_CanvasNode)
  */
-SUPERVGUI_BrowseNodeDlg::SUPERVGUI_BrowseNodeDlg( SUPERVGUI_Node* theNode )
-  : QDialog( theNode, 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
+SUPERVGUI_BrowseNodeDlg::SUPERVGUI_BrowseNodeDlg( SUPERVGUI_CanvasNode* theNode )
+  : QDialog( QAD_Application::getDesktop(), 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
+{
+  myNodeCanvas = theNode;
+
+  init();
+}
+
+void SUPERVGUI_BrowseNodeDlg::init()
 {
   myActiveField = 0;
   setSizeGripEnabled( true );
-  myNode = theNode;
   myPortsList.setAutoDelete( true );
 
-  SUPERV_CNode aEngine = myNode->getEngine();
+  SUPERV_CNode aEngine = myNodeCanvas->getEngine();
+  
   mySelection = SALOME_Selection::Selection( Supervision.getActiveStudy()->getSelection() );
 //  mySelection->ClearIObjects();
 
@@ -121,7 +134,8 @@ SUPERVGUI_BrowseNodeDlg::SUPERVGUI_BrowseNodeDlg( SUPERVGUI_Node* theNode )
     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;
@@ -167,7 +181,7 @@ SUPERVGUI_BrowseNodeDlg::SUPERVGUI_BrowseNodeDlg( SUPERVGUI_Node* theNode )
     aBtnLayout->addStretch();
 
   connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
-  myNode->getMain()->lockedGraph(true);
+  myNodeCanvas->getMain()->lockedGraph(true);
 }
 
 /**
@@ -195,9 +209,10 @@ void SUPERVGUI_BrowseNodeDlg::accept() {
     for ( aField = myPortsList.first(); aField; aField = myPortsList.next() ) {
       aField->setNewValue();
     }
-    myNode->sync();
+    myNodeCanvas->sync();
+    myNodeCanvas->getMain()->getCanvas()->update();
   }
-  myNode->getMain()->lockedGraph(false);
+  myNodeCanvas->getMain()->lockedGraph(false);
   QDialog::accept();
   close();
 }
@@ -207,7 +222,7 @@ void SUPERVGUI_BrowseNodeDlg::accept() {
  * Closes and destroys dialog
  */
 void SUPERVGUI_BrowseNodeDlg::reject() {
-  myNode->getMain()->lockedGraph(false);
+  myNodeCanvas->getMain()->lockedGraph(false);
   QDialog::reject();
   close();
 }
@@ -250,88 +265,32 @@ void SUPERVGUI_BrowseNodeDlg::onSelectionChanged()
        if (aObj->FindAttribute( anAttr, "AttributeIOR" ) ) {
          anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
          ior = anIOR->Value();
-         myActiveField->setData( ior );
        }
+       else {
+         ior = aObj->GetStudy()->ConvertObjectToIOR( aObj );
+       }
+       myActiveField->setData( ior );
       }
     }
   }
 }
 
+
 /**
- * Constructor
+ * Constructor (SUPERVGUI_CanvasPort)
  */
-SUPERVGUI_GetValueDlg::SUPERVGUI_GetValueDlg( SUPERVGUI_PortIn* thePort )
-  : QDialog( thePort, 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
+SUPERVGUI_GetValueDlg::SUPERVGUI_GetValueDlg( SUPERVGUI_CanvasPort* thePort )
+  : QDialog( QAD_Application::getDesktop(), 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
 {
-  myOKBtn = 0;
-  setSizeGripEnabled( true );
-  myPort = thePort;
-  myPortESNode = 0;
-
-  mySelection = SALOME_Selection::Selection( Supervision.getActiveStudy()->getSelection() );
-//  mySelection->ClearIObjects();
-
-  setName( "SUPERVGUI_GetValueDlg" );
-  setCaption( tr( "TIT_SETVALUE_PORT" ) );
-  
-  QGridLayout* aBaseLayout = new QGridLayout( this );
-  aBaseLayout->setMargin( 11 ); aBaseLayout->setSpacing( 6 );
-  
-  QGroupBox* aBox = new QGroupBox( this );
-  aBox->setColumnLayout( 0, Qt::Vertical );
-  aBox->layout()->setSpacing( 0 ); aBox->layout()->setMargin( 0 );
-  QGridLayout* aBoxLayout = new QGridLayout( aBox->layout() );
-  aBoxLayout->setAlignment( Qt::AlignTop );
-  aBoxLayout->setSpacing( 6 ); aBoxLayout->setMargin( 11 );
-  aBaseLayout->addWidget( aBox, 0, 0 );
-  aBox->setMinimumWidth( 200 );
-  
-  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 );
-  myField = new SUPERVGUI_PortField( aBox, myPort->getPort() );
-  bool myIsEditable = myField->isEditable();
-  aBoxLayout->addWidget( myField->myLabel, 1, 0 ); 
-  aBoxLayout->addWidget( myField->myValue, 1, 1 );
-  
-  QGroupBox* aBtnBox = new QGroupBox( this );
-  aBtnBox->setColumnLayout( 0, Qt::Vertical );
-  aBtnBox->layout()->setSpacing( 0 ); aBtnBox->layout()->setMargin( 0 );
-  QHBoxLayout* aBtnLayout = new QHBoxLayout( aBtnBox->layout() );
-  aBtnLayout->setAlignment( Qt::AlignTop );
-  aBtnLayout->setSpacing( 6 ); aBtnLayout->setMargin( 11 );
-
-  aBaseLayout->addWidget( aBtnBox, 1, 0 );
-
-  if ( myIsEditable ) {
-    myOKBtn = new QPushButton( tr( "BUT_OK" ), aBtnBox );
-    connect( myOKBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
-    aBtnLayout->addWidget( myOKBtn );
-  }
-
-  aBtnLayout->addStretch();
-  myCancelBtn = new QPushButton( myIsEditable ? tr( "BUT_CANCEL" ) : tr( "BUT_CLOSE" ), aBtnBox );
-  aBtnLayout->addWidget( myCancelBtn );
-  connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
-  
-  if ( !myIsEditable )
-    aBtnLayout->addStretch();
+  myPortCanvas = thePort;
 
-  myField->updateGUI();
-  connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
-  myPort->getMain()->lockedGraph(true);
+  init();
 }
 
-/**
- * Constructor
- */
-SUPERVGUI_GetValueDlg::SUPERVGUI_GetValueDlg( SUPERVGUI_PortInESNode* thePort )
-  : QDialog( thePort, 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
+void SUPERVGUI_GetValueDlg::init()
 {
   myOKBtn = 0;
   setSizeGripEnabled( true );
-  myPort = 0;
-  myPortESNode = thePort;
 
   mySelection = SALOME_Selection::Selection( Supervision.getActiveStudy()->getSelection() );
 //  mySelection->ClearIObjects();
@@ -354,7 +313,9 @@ SUPERVGUI_GetValueDlg::SUPERVGUI_GetValueDlg( SUPERVGUI_PortInESNode* thePort )
   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 );
-  myField = new SUPERVGUI_PortField( aBox, myPortESNode->getPort() );
+  SUPERV_Port aEngine = myPortCanvas->getEngine();
+
+  myField = new SUPERVGUI_PortField( aBox, aEngine );
   bool myIsEditable = myField->isEditable();
   aBoxLayout->addWidget( myField->myLabel, 1, 0 ); 
   aBoxLayout->addWidget( myField->myValue, 1, 1 );
@@ -384,7 +345,8 @@ SUPERVGUI_GetValueDlg::SUPERVGUI_GetValueDlg( SUPERVGUI_PortInESNode* thePort )
 
   myField->updateGUI();
   connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
-  myPortESNode->getMain()->lockedGraph(true);
+  
+  myPortCanvas->getMain()->lockedGraph(true);
 }
 
 /**
@@ -399,10 +361,16 @@ SUPERVGUI_GetValueDlg::~SUPERVGUI_GetValueDlg() {
 void SUPERVGUI_GetValueDlg::accept() {
   if ( myField->setNewValue() ) {
     
-    if (myPort != 0)
-      myPort->sync();
-    else
-      myPortESNode->sync();
+    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(), 
@@ -411,10 +379,8 @@ void SUPERVGUI_GetValueDlg::accept() {
       return;
   }
 
-  if (myPort != 0)
-    myPort->getMain()->lockedGraph(false);
-  else
-    myPortESNode->getMain()->lockedGraph(false);
+  myPortCanvas->getMain()->lockedGraph(false);
+  
   QDialog::accept();
   close();
 }
@@ -423,10 +389,7 @@ void SUPERVGUI_GetValueDlg::accept() {
  * Closes and destroys dialog
  */
 void SUPERVGUI_GetValueDlg::reject() {
-  if (myPort != 0)
-    myPort->getMain()->lockedGraph(false);
-  else
-    myPortESNode->getMain()->lockedGraph(false);
+  myPortCanvas->getMain()->lockedGraph(false);
   QDialog::reject();
   close();
 }
@@ -449,9 +412,176 @@ void SUPERVGUI_GetValueDlg::onSelectionChanged()
       if (aObj->FindAttribute( anAttr, "AttributeIOR" ) ) {
        anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
        ior = anIOR->Value();
-       myField->setData( ior );
       }
+      else {
+       ior = aObj->GetStudy()->ConvertObjectToIOR( aObj );
+      }
+      myField->setData( ior );
     }
   }
 }
 
+
+
+// ----------------------------
+// Stream Ports
+// ----------------------------
+
+SUPERVGUI_StreamInDlg::SUPERVGUI_StreamInDlg(SUPERVGUI_CanvasStreamPortIn* thePort)
+  :QDialog( QAD_Application::getDesktop(), "", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
+{
+  myPortCanvas = thePort;
+  init();
+}
+
+void SUPERVGUI_StreamInDlg::init()
+{
+  setSizeGripEnabled( true );
+  setCaption( tr( "MSG_STREAM_DLG_TIT" ) );
+
+  QVBoxLayout* TopLayout = new QVBoxLayout( this, 11, 6 );
+
+  QFrame* aCtrlPane = new QFrame(this);
+  QGridLayout* aCtrlLayout = new QGridLayout( aCtrlPane, 4, 10 );
+
+  // Schema
+  QLabel* aSchemaLbl = new QLabel(tr("MSG_STREAM_SCHEMA"),aCtrlPane);
+  aCtrlLayout->addWidget(aSchemaLbl, 0, 0);
+
+  mySchemaCombo = new QComboBox(aCtrlPane, "SchemaBox" );
+  mySchemaCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
+  mySchemaCombo->insertItem("SCHENULL"); 
+  mySchemaCombo->insertItem("TI");  
+  mySchemaCombo->insertItem("TF");
+  mySchemaCombo->insertItem("DELTA");
+  aCtrlLayout->addWidget(mySchemaCombo, 0, 1);
+
+  // Interpolation
+  QLabel* aInterLbl = new QLabel(tr("MSG_STREAM_INTER"),aCtrlPane);
+  aCtrlLayout->addWidget(aInterLbl, 1, 0);
+
+  myInterCombo = new QComboBox(aCtrlPane, "InterBox" );
+  myInterCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
+  myInterCombo->insertItem("INTERNULL"); 
+  myInterCombo->insertItem("L0"); 
+  myInterCombo->insertItem("L1");
+  aCtrlLayout->addWidget(myInterCombo, 1, 1);
+
+  // Extrapolation
+  QLabel* aExtraLbl = new QLabel(tr("MSG_STREAM_EXTRA"),aCtrlPane);
+  aCtrlLayout->addWidget(aExtraLbl, 2, 0);
+
+  myExterCombo = new QComboBox(aCtrlPane, "ExtraBox" );
+  myExterCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
+  myExterCombo->insertItem("EXTRANULL");  
+  myExterCombo->insertItem("E0");
+  myExterCombo->insertItem("E1");
+  aCtrlLayout->addWidget(myExterCombo, 2, 1);
+  
+  TopLayout->addWidget( aCtrlPane );
+
+  // Buttons
+  QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
+  GroupButtons->setColumnLayout(0, Qt::Vertical );
+  GroupButtons->layout()->setSpacing( 0 );
+  GroupButtons->layout()->setMargin( 0 );
+  QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
+  GroupButtonsLayout->setAlignment( Qt::AlignTop );
+  GroupButtonsLayout->setSpacing( 5 );
+  GroupButtonsLayout->setMargin( 8 );
+  
+  QPushButton* okB     = new QPushButton( tr( "BUT_OK" ),     GroupButtons );
+  QPushButton* cancelB = new QPushButton( tr( "BUT_CANCEL" ), GroupButtons );
+
+  GroupButtonsLayout->addWidget( okB, 0, 0 );
+  GroupButtonsLayout->addItem  ( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
+  GroupButtonsLayout->addWidget( cancelB, 0, 2 );
+
+  TopLayout->addWidget( GroupButtons );
+
+  connect( okB,     SIGNAL( clicked() ), this, SLOT( accept() ) );
+  connect( cancelB, SIGNAL( clicked() ), this, SLOT( reject() ) );
+  setData();
+}
+
+void SUPERVGUI_StreamInDlg::setData() {
+  SUPERV::KindOfSchema aSchema;
+  SUPERV::KindOfInterpolation aInterpolat;
+  SUPERV::KindOfExtrapolation aExtrapolat;
+
+  myPortCanvas->getStreamEngine()->Params(aSchema, aInterpolat, aExtrapolat);
+
+  mySchemaCombo->setCurrentItem((int)aSchema);
+  myInterCombo->setCurrentItem((int)aInterpolat);
+  myExterCombo->setCurrentItem((int)aExtrapolat);
+}
+
+void SUPERVGUI_StreamInDlg::accept() {
+  myPortCanvas->getStreamEngine()->SetParams((SUPERV::KindOfSchema) mySchemaCombo->currentItem(), 
+                                            (SUPERV::KindOfInterpolation) myInterCombo->currentItem(),
+                                            (SUPERV::KindOfExtrapolation) myExterCombo->currentItem());
+  QDialog::accept();
+}
+
+
+//-------------------------------------------------------------------------
+SUPERVGUI_StreamOutDlg::SUPERVGUI_StreamOutDlg(SUPERVGUI_CanvasStreamPortOut* thePort)
+  :QDialog( QAD_Application::getDesktop(), "", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
+{
+  myPortCanvas = thePort;
+  init();
+}
+
+void SUPERVGUI_StreamOutDlg::init()
+{
+  setSizeGripEnabled( true );
+  setCaption( tr( "MSG_STREAM_DLG_TIT" ) );
+
+  QVBoxLayout* TopLayout = new QVBoxLayout( this, 11, 6 );
+
+  QFrame* aCtrlPane = new QFrame(this);
+  QGridLayout* aCtrlLayout = new QGridLayout( aCtrlPane, 4, 10 );
+
+  QLabel* aLbl = new QLabel(tr("MSG_STREAM_LEVEL"),aCtrlPane);
+  aCtrlLayout->addWidget(aLbl, 0, 0);
+
+  myValEdit = new QLineEdit( aCtrlPane, "ValEdit" );
+  myValEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
+  myValEdit->setValidator( new QIntValidator(this) );
+  SUPERV_StreamPort aEngine = myPortCanvas->getStreamEngine();
+  myValEdit->setText(QString("%1").arg(aEngine->NumberOfValues()));
+  aCtrlLayout->addWidget(myValEdit, 0, 1);
+  TopLayout->addWidget( aCtrlPane );
+  
+  // Buttons
+  QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
+  GroupButtons->setColumnLayout(0, Qt::Vertical );
+  GroupButtons->layout()->setSpacing( 0 );
+  GroupButtons->layout()->setMargin( 0 );
+  QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
+  GroupButtonsLayout->setAlignment( Qt::AlignTop );
+  GroupButtonsLayout->setSpacing( 5 );
+  GroupButtonsLayout->setMargin( 8 );
+  
+  QPushButton* okB     = new QPushButton( tr( "BUT_OK" ),     GroupButtons );
+  QPushButton* cancelB = new QPushButton( tr( "BUT_CANCEL" ), GroupButtons );
+
+  GroupButtonsLayout->addWidget( okB, 0, 0 );
+  GroupButtonsLayout->addItem  ( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
+  GroupButtonsLayout->addWidget( cancelB, 0, 2 );
+
+  TopLayout->addWidget( GroupButtons );
+
+  connect( okB,     SIGNAL( clicked() ), this, SLOT( accept() ) );
+  connect( cancelB, SIGNAL( clicked() ), this, SLOT( reject() ) );
+}
+
+void SUPERVGUI_StreamOutDlg::accept() {
+  int aRes = 0;
+  QString aStr = myValEdit->text();
+  if (!aStr.isEmpty())
+    aRes = aStr.toLong();
+  myPortCanvas->getStreamEngine()->SetNumberOfValues(aRes);
+  QDialog::accept();
+}
+