Salome HOME
A new dialog class for edition of Ports of an InLine nodes is introduced. This funct...
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_BrowseNodeDlg.cxx
index a3e187ad65a3e0bb64d6fabd3ddcac4e2881e825..dd0939e97fdef71e409a0505fbfb0d70fc164fcc 100644 (file)
@@ -11,6 +11,9 @@
 using namespace std;
 #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>
@@ -18,6 +21,7 @@ using namespace std;
 #include <qpushbutton.h>
 #include <qhbox.h>
 #include <qgroupbox.h>
+#include <qvalidator.h>
 
 /**
  * Constructor
@@ -65,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;
 }
@@ -85,17 +89,41 @@ bool SUPERVGUI_PortField::eventFilter( QObject* o, QEvent* e )
 
 
 /**
- * Constructor
+ * 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 )
+{
+  myNode = 0;
+  myNodeCanvas = theNode;
+
+  init();
+}
+
+void SUPERVGUI_BrowseNodeDlg::init()
 {
   myActiveField = 0;
   setSizeGripEnabled( true );
-  myNode = theNode;
   myPortsList.setAutoDelete( true );
 
-  SUPERV_CNode aEngine = myNode->getEngine();
+  SUPERV_CNode aEngine;
+  if (myNode != 0)
+    aEngine = myNode->getEngine();
+  else
+    aEngine = myNodeCanvas->getEngine();
+  
   mySelection = SALOME_Selection::Selection( Supervision.getActiveStudy()->getSelection() );
 //  mySelection->ClearIObjects();
 
@@ -169,7 +197,10 @@ SUPERVGUI_BrowseNodeDlg::SUPERVGUI_BrowseNodeDlg( SUPERVGUI_Node* theNode )
     aBtnLayout->addStretch();
 
   connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
-  myNode->getMain()->lockedGraph(true);
+  if (myNode != 0)
+    myNode->getMain()->lockedGraph(true);
+  else
+    myNodeCanvas->getMain()->lockedGraph(true);
 }
 
 /**
@@ -197,9 +228,17 @@ void SUPERVGUI_BrowseNodeDlg::accept() {
     for ( aField = myPortsList.first(); aField; aField = myPortsList.next() ) {
       aField->setNewValue();
     }
-    myNode->sync();
+    if (myNode != 0)
+      myNode->sync();
+    else {
+      myNodeCanvas->sync();
+      myNodeCanvas->getMain()->getCanvas()->update();
+    }
   }
-  myNode->getMain()->lockedGraph(false);
+  if (myNode != 0)
+    myNode->getMain()->lockedGraph(false);
+  else
+    myNodeCanvas->getMain()->lockedGraph(false);
   QDialog::accept();
   close();
 }
@@ -209,7 +248,10 @@ void SUPERVGUI_BrowseNodeDlg::accept() {
  * Closes and destroys dialog
  */
 void SUPERVGUI_BrowseNodeDlg::reject() {
-  myNode->getMain()->lockedGraph(false);
+  if (myNode != 0)
+    myNode->getMain()->lockedGraph(false);
+  else
+    myNodeCanvas->getMain()->lockedGraph(false);
   QDialog::reject();
   close();
 }
@@ -263,80 +305,48 @@ void SUPERVGUI_BrowseNodeDlg::onSelectionChanged()
 }
 
 /**
- * Constructor
+ * Constructor (SUPERVGUI_PortIn)
  */
 SUPERVGUI_GetValueDlg::SUPERVGUI_GetValueDlg( SUPERVGUI_PortIn* thePort )
   : QDialog( thePort, 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
 {
-  myOKBtn = 0;
-  setSizeGripEnabled( true );
   myPort = thePort;
   myPortESNode = 0;
+  myPortCanvas = 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();
-
-  myField->updateGUI();
-  connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
-  myPort->getMain()->lockedGraph(true);
+  init();
 }
 
 /**
- * Constructor
+ * Constructor (SUPERVGUI_PortInESNode)
  */
 SUPERVGUI_GetValueDlg::SUPERVGUI_GetValueDlg( SUPERVGUI_PortInESNode* thePort )
   : QDialog( thePort, 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
 {
-  myOKBtn = 0;
-  setSizeGripEnabled( true );
   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 )
+{
+  myPort = 0;
+  myPortESNode = 0;
+  myPortCanvas = thePort;
+
+  init();
+}
+
+void SUPERVGUI_GetValueDlg::init()
+{
+  myOKBtn = 0;
+  setSizeGripEnabled( true );
 
   mySelection = SALOME_Selection::Selection( Supervision.getActiveStudy()->getSelection() );
 //  mySelection->ClearIObjects();
@@ -359,7 +369,15 @@ 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;
+  if (myPort != 0)
+    aEngine = myPort->getPort();
+  else if (myPortESNode != 0)
+    aEngine = myPortESNode->getPort();
+  else {
+    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 );
@@ -389,7 +407,12 @@ SUPERVGUI_GetValueDlg::SUPERVGUI_GetValueDlg( SUPERVGUI_PortInESNode* thePort )
 
   myField->updateGUI();
   connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
-  myPortESNode->getMain()->lockedGraph(true);
+  if (myPort != 0)
+    myPort->getMain()->lockedGraph(true);
+  else if (myPortESNode != 0)
+    myPortESNode->getMain()->lockedGraph(true);
+  else
+    myPortCanvas->getMain()->lockedGraph(true);
 }
 
 /**
@@ -406,8 +429,12 @@ void SUPERVGUI_GetValueDlg::accept() {
     
     if (myPort != 0)
       myPort->sync();
-    else
+    else if (myPortESNode != 0)
       myPortESNode->sync();
+    else {
+      myPortCanvas->sync();
+      myPortCanvas->getMain()->getCanvas()->update();
+    }
   }
   else {
     if ( QMessageBox::warning( QAD_Application::getDesktop(), 
@@ -418,8 +445,10 @@ void SUPERVGUI_GetValueDlg::accept() {
 
   if (myPort != 0)
     myPort->getMain()->lockedGraph(false);
-  else
+  else if (myPortESNode != 0)
     myPortESNode->getMain()->lockedGraph(false);
+  else
+    myPortCanvas->getMain()->lockedGraph(false);
   QDialog::accept();
   close();
 }
@@ -430,8 +459,10 @@ void SUPERVGUI_GetValueDlg::accept() {
 void SUPERVGUI_GetValueDlg::reject() {
   if (myPort != 0)
     myPort->getMain()->lockedGraph(false);
-  else
+  else if (myPortESNode != 0)
     myPortESNode->getMain()->lockedGraph(false);
+  else
+    myPortCanvas->getMain()->lockedGraph(false);
   QDialog::reject();
   close();
 }
@@ -463,3 +494,199 @@ 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 )
+{
+  myPort = 0;
+  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;
+
+  if (myPort != 0)
+    myPort->getStreamPort()->Params(aSchema, aInterpolat, aExtrapolat);
+  else
+    myPortCanvas->getStreamEngine()->Params(aSchema, aInterpolat, aExtrapolat);
+
+  mySchemaCombo->setCurrentItem((int)aSchema);
+  myInterCombo->setCurrentItem((int)aInterpolat);
+  myExterCombo->setCurrentItem((int)aExtrapolat);
+}
+
+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());
+  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 )
+{
+  myPort = 0;
+  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;
+  if (myPort != 0)
+    aEngine = myPort->getStreamPort();
+  else
+    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();
+  if (myPort != 0) 
+    myPort->getStreamPort()->SetNumberOfValues(aRes);
+  else
+    myPortCanvas->getStreamEngine()->SetNumberOfValues(aRes);
+  QDialog::accept();
+}
+