Salome HOME
refs #1501 p.2
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_StreamDlg.cxx
index 8b4f7050fada1831bd6eaeec0962f11f574f2cbc..a07c5fe7e79b5e5a178bfead856e8a6a2bf7e62c 100644 (file)
 //
 
 #include "HYDROGUI_StreamDlg.h"
+#include "HYDROGUI_ListSelector.h"
+#include "HYDROGUI_OrderedListWidget.h"
+#include <HYDROData_Profile.h>
 
-#include "HYDROGUI_Tool.h"
+#ifndef LIGHT_MODE
+  #include "HYDROGUI_Module.h"
+  #include "HYDROGUI_Tool2.h"
+  #include <LightApp_Application.h>
+  #include <LightApp_SelectionMgr.h>
+#endif
 
 #include <QComboBox>
 #include <QGroupBox>
@@ -27,6 +35,8 @@
 #include <QLineEdit>
 #include <QListWidget>
 #include <QPushButton>
+#include <QDoubleSpinBox>
+#include <QTextEdit>
 
 HYDROGUI_StreamDlg::HYDROGUI_StreamDlg( HYDROGUI_Module* theModule, const QString& theTitle )
 : HYDROGUI_InputPanel( theModule, theTitle )
@@ -47,16 +57,32 @@ HYDROGUI_StreamDlg::HYDROGUI_StreamDlg( HYDROGUI_Module* theModule, const QStrin
 
   myAxes = new QComboBox( aParamGroup );
   myAxes->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
-  QBoxLayout* anAxisLayout = new QHBoxLayout();
-  anAxisLayout->addWidget( new QLabel( tr( "STREAM_HYDRAULIC_AXIS" ) ) );
-  anAxisLayout->addWidget( myAxes );
-
-  myProfiles = new QListWidget( aParamGroup );
-  myProfiles->setSelectionMode( QListWidget::ExtendedSelection );
-  myProfiles->setEditTriggers( QListWidget::NoEditTriggers );
-  myProfiles->setViewMode( QListWidget::ListMode );
-  myProfiles->setSortingEnabled( false );
-
+  myDDZ = new QDoubleSpinBox( aParamGroup );
+  myDDZ->setRange( 0.01, 100 );
+  myDDZ->setSingleStep( 0.1 );
+  myDDZ->setValue( 0.1 );
+  myDDZ->setDecimals( 2 );
+  mySpatialStep = new QDoubleSpinBox( aParamGroup );
+  mySpatialStep->setRange( 0.1, 100 );
+  mySpatialStep->setSingleStep( 0.1 );
+  mySpatialStep->setValue( 1 );
+  mySpatialStep->setDecimals( 2 );
+
+  QGridLayout* aParam1Layout = new QGridLayout();
+  aParam1Layout->setMargin( 0 );
+  aParam1Layout->addWidget( new QLabel( tr( "STREAM_HYDRAULIC_AXIS" ) ), 0, 0 );
+  aParam1Layout->addWidget( myAxes, 0, 1 );
+  aParam1Layout->addWidget( new QLabel( tr( "STREAM_DDZ" ) ), 1, 0 );
+  aParam1Layout->addWidget( myDDZ, 1, 1 );
+  aParam1Layout->addWidget( new QLabel( tr( "STREAM_SPATIAL_STEP" ) ), 2, 0 );
+  aParam1Layout->addWidget( mySpatialStep, 2, 1 );
+
+  myProfiles = new HYDROGUI_OrderedListWidget( aParamGroup, 0 );
+  myProfiles->setHiddenObjectsShown(true);
+  myProfiles->setVisibilityIconShown(false);
+  myProfiles->setContentsMargins(QMargins());
+  myProfiles->setOrderingEnabled( false );
   myAddButton = new QPushButton( aParamGroup );
   myAddButton->setText( tr("ADD") );
   myRemoveButton = new QPushButton( aParamGroup );
@@ -69,22 +95,43 @@ HYDROGUI_StreamDlg::HYDROGUI_StreamDlg( HYDROGUI_Module* theModule, const QStrin
   QBoxLayout* aParamLayout = new QVBoxLayout();
   aParamLayout->setMargin( 5 );
   aParamLayout->setSpacing( 5 );
-  aParamLayout->addLayout( anAxisLayout );
+  aParamLayout->addLayout( aParam1Layout );
   aParamLayout->addWidget( myProfiles );
   aParamLayout->addLayout( aButtonsLayout );
-
+  
   aParamGroup->setLayout( aParamLayout );
 
+  // Warnings
+  QGroupBox* aWarnGroup = new QGroupBox( tr( "STREAM_WARNINGS" ), mainFrame() );
+  myWarnText = new QTextEdit(); 
+  myWarnText->setReadOnly(true);
+  QBoxLayout* aWarnLayout = new QVBoxLayout();
+  aWarnLayout->addWidget( myWarnText );  
+  aWarnGroup->setLayout( aWarnLayout );
+
   // Common
   addWidget( myObjectNameGroup );
   addWidget( aParamGroup );
+  addWidget( aWarnGroup );
   addStretch();
 
+  // Create selector
+  if ( module() ) {
+    HYDROGUI_ListSelector* aListSelector = 
+#ifdef LIGHT_MODE
+      new HYDROGUI_ListSelector( myProfiles, 0 );
+#else
+      new HYDROGUI_ListSelector( myProfiles, module()->getApp()->selectionMgr() );
+#endif
+    aListSelector->setAutoBlock( true );
+  }
+
   // Connect signals and slots
-  connect( myAxes, SIGNAL( currentIndexChanged( const QString & ) ), 
-           this, SIGNAL( AxisChanged( const QString& ) ) );
+  connect( myAxes, SIGNAL( currentIndexChanged( const QString & ) ), this, SIGNAL( AxisChanged( const QString& ) ) );
   connect( myAddButton, SIGNAL( clicked() ), this, SIGNAL( AddProfiles() ) );
   connect( myRemoveButton, SIGNAL( clicked() ), this, SLOT( onRemoveProfiles() ) );
+  connect( myDDZ, SIGNAL( valueChanged (double) ), this, SLOT (onDDZValueChanged(double)));
+  connect( mySpatialStep, SIGNAL( valueChanged (double) ), this, SLOT (onSSValueChanged(double)));
 }
 
 HYDROGUI_StreamDlg::~HYDROGUI_StreamDlg()
@@ -98,9 +145,9 @@ void HYDROGUI_StreamDlg::reset()
   myObjectName->clear();
 
   myAxes->clear();
-  myProfiles->clear();
-  myAddButton->setEnabled( false );
-  myRemoveButton->setEnabled( false );
+  myProfiles->setObjects( HYDROGUI_ListModel::Object2VisibleList() );
+  myAddButton->setEnabled( true );
+  myRemoveButton->setEnabled( true );
 
   blockSignals( isBlocked );
 }
@@ -133,7 +180,7 @@ void HYDROGUI_StreamDlg::setAxisName( const QString& theName )
   if ( aNewId != myAxes->currentIndex() ) {
     myAxes->setCurrentIndex( aNewId );
   }
-  myAddButton->setEnabled( myAxes->currentIndex() > -1 );
+  //myAddButton->setEnabled( myAxes->currentIndex() > -1 );
 
   blockSignals( isBlocked );
 }
@@ -149,13 +196,23 @@ void HYDROGUI_StreamDlg::setProfiles( const QStringList& theProfiles )
 
   myProfiles->setUpdatesEnabled( false );
   
-  myProfiles->clear();
-  foreach ( const QString& aProfileName, theProfiles ) {
-    QListWidgetItem* aListItem = new QListWidgetItem( aProfileName, myProfiles );
-    aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
+  HYDROGUI_ListModel::Object2VisibleList aProfiles;
+#ifndef LIGHT_MODE
+  foreach ( const QString& aProfileName, theProfiles )
+  {
+    Handle(HYDROData_Profile) anObject = Handle(HYDROData_Profile)::DownCast( 
+      HYDROGUI_Tool::FindObjectByName( module(), aProfileName ) );
+    if ( !anObject.IsNull() )
+    {
+      aProfiles.append( HYDROGUI_ListModel::Object2Visible( anObject, true ) );
+    }
   }
+#endif
+
+  myProfiles->setObjects( aProfiles );
 
-  myRemoveButton->setEnabled( myProfiles->count() > 0 );
+
+  myRemoveButton->setEnabled( myProfiles->getObjects().count() > 0 );
 
   myProfiles->setUpdatesEnabled( true );
 
@@ -164,15 +221,64 @@ void HYDROGUI_StreamDlg::setProfiles( const QStringList& theProfiles )
 
 void HYDROGUI_StreamDlg::onRemoveProfiles()
 {
-  QStringList aSelectedProfiles;
-
-  QList<QListWidgetItem*> aSelectedItems = myProfiles->selectedItems();
-  foreach( const QListWidgetItem* anItem, aSelectedItems ) {
-    QString aProfileName = anItem->text();
-    if ( !aProfileName.isEmpty() ) {
-      aSelectedProfiles << aProfileName;
-    }
-  }
+  QStringList aSelectedProfiles = myProfiles->getSelectedNames();
 
   emit RemoveProfiles( aSelectedProfiles );
 }
+
+void HYDROGUI_StreamDlg::onDDZValueChanged(double d)
+{
+  emit DDZValueChanged( d );
+}
+
+void HYDROGUI_StreamDlg::onSSValueChanged(double d)
+{
+  emit SSValueChanged( d );
+}
+
+
+void HYDROGUI_StreamDlg::setDDZ( const double theDDZ )
+{
+  myDDZ->setValue( theDDZ );
+}
+
+double HYDROGUI_StreamDlg::getDDZ() const
+{
+  return myDDZ->value();
+}
+
+void HYDROGUI_StreamDlg::setSpatialStep( const double theSpatialStep )
+{
+  mySpatialStep->setValue( theSpatialStep );
+}
+
+double HYDROGUI_StreamDlg::getSpatialStep() const
+{
+  return mySpatialStep->value();
+}
+
+void HYDROGUI_StreamDlg::setBackgroundColorForProfileList (int theInd, QColor theColor)
+{
+  myProfiles->setBackgroundColor(theInd, theColor);
+}
+
+QColor HYDROGUI_StreamDlg::getBackgroundColorForProfileList (int theInd) const
+{
+  return myProfiles->getBackgroundColor(theInd);
+}
+
+void HYDROGUI_StreamDlg::clearAllBackgroundColorsForProfileList ()
+{
+  myProfiles->clearAllBackgroundColors();
+}
+
+void HYDROGUI_StreamDlg::addWarning( const QString& theWarnMess )
+{
+  myWarnText->append( theWarnMess );
+}
+
+void HYDROGUI_StreamDlg::clearWarnings()
+{
+  myWarnText->clear();
+}
+