]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Add/remove objects is implemented on the first page of the Calculation Case operation...
authorrkv <rkv@opencascade.com>
Wed, 30 Oct 2013 09:55:23 +0000 (09:55 +0000)
committerrkv <rkv@opencascade.com>
Wed, 30 Oct 2013 09:55:23 +0000 (09:55 +0000)
src/HYDROGUI/HYDROGUI_CalculationDlg.cxx
src/HYDROGUI/HYDROGUI_CalculationDlg.h
src/HYDROGUI/HYDROGUI_CalculationOp.cxx
src/HYDROGUI/HYDROGUI_CalculationOp.h

index 1713e060600131042317f98638f32c8998e9f567..302efd74631a5126b00fed7cd9b0e699d2695de4 100644 (file)
@@ -129,16 +129,11 @@ QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() {
   aZonesLayout->addWidget( myGeomObjects,  1, 1, 2, 1 );
   aZonesLayout->addWidget( aBtnsFrame,     2, 0, Qt::AlignHCenter );
 
-  //QBoxLayout* aMainLayout = new QVBoxLayout( aFrame );
-  //aMainLayout->setMargin( 0 );
-  //aMainLayout->setSpacing( 5 );
-  //aMainLayout->addWidget( myObjectNameGroup );
-  //aMainLayout->addWidget( anObjectsFrame );
-  //aMainLayout->addStretch();
-
-  //aPage->setLayout( aMainLayout );
   aPage->setLayout( aZonesLayout );
 
+  connect( anAddBtn, SIGNAL( clicked() ), this, SIGNAL( addObjects() ) );
+  connect( aRemoveBtn, SIGNAL( clicked() ), this, SIGNAL( removeObjects() ) );
+
   return aPage;
 }
 
@@ -213,17 +208,11 @@ void HYDROGUI_CalculationDlg::setSelectedGeomObjects( const QStringList& theObje
 QStringList HYDROGUI_CalculationDlg::getSelectedGeomObjects() const
 {
   QStringList aResList;
-
-  for ( int i = 0, n = myGeomObjects->count(); i < n; ++i )
+  QList<QListWidgetItem*> aList = myGeomObjects->selectedItems();
+  for ( int i = 0, n = aList.length(); i < n; ++i )
   {
-    QListWidgetItem* aListItem = myGeomObjects->item( i );
-    if ( !aListItem )
-      continue;
-
-    QString aSelObjName = aListItem->text();
-    aResList.append( aSelObjName );
+    aResList.append( aList.at( i )->text() );
   }
-
   return aResList;
 }
 
index 37206ede90ca26759bd3511c617c2a76407e077d..aa3dbe5381322fa97a98d25e663831887208445d 100644 (file)
@@ -31,6 +31,7 @@ class QGroupBox;
 class QLineEdit;
 class QListWidget;
 class QComboBox;
+class QStringList;
 class HYDROGUI_DataBrowser;
 class HYDROGUI_NameValidator;
 
@@ -53,9 +54,14 @@ public:
   void                       setSelectedGeomObjects( const QStringList& theObjects );
   QStringList                getSelectedGeomObjects() const;
 
-  public slots:
+public slots:
     void                     onEmptyName();
     void                     onAlreadyExists( QString theName );
+
+signals:
+    void                     addObjects();
+    void                     removeObjects();
+
 private:
 
   QWizardPage*               createObjectsPage();
index 621d9d755a6badbc11402614253e9f0ca8b6e174..977b440bb0bdedf396b13cc9332064ef0300d857 100644 (file)
@@ -31,6 +31,7 @@
 #include <HYDROData_Polyline.h>
 #include <HYDROData_Iterator.h>
 #include <HYDROData_ImmersibleZone.h>
+#include <HYDROData_Object.h>
 
 #include <OCCViewer_ViewManager.h>
 #include <OCCViewer_ViewModel.h>
@@ -84,22 +85,7 @@ void HYDROGUI_CalculationOp::startOperation()
     if ( !myEditedObject.IsNull() )
     {
       anObjectName = myEditedObject->GetName();
-
-      HYDROData_SequenceOfObjects aRefObjects = myEditedObject->GetGeometryObjects();
-      HYDROData_SequenceOfObjects::Iterator anIter( aRefObjects );
-      for ( ; anIter.More(); anIter.Next() )
-      {
-        Handle(HYDROData_Object) aRefbject = 
-          Handle(HYDROData_Object)::DownCast( anIter.Value() );
-        if ( aRefbject.IsNull() )
-          continue;
-
-        QString aRefObjectName = aRefbject->GetName();
-        if ( aRefObjectName.isEmpty() )
-          continue;
-
-        aSelectedObjects.append( aRefObjectName );
-      }
+      updateGeomObjectsList(aPanel);
     }
   }
   else
@@ -111,11 +97,34 @@ void HYDROGUI_CalculationOp::startOperation()
 
   aPanel->setObjectName( anObjectName );
   aPanel->setEditedObject( myEditedObject );
-  aPanel->setSelectedGeomObjects( aSelectedObjects );
+//  aPanel->setSelectedGeomObjects( aSelectedObjects );
 
   createPreview();
 }
 
+void HYDROGUI_CalculationOp::updateGeomObjectsList( HYDROGUI_CalculationDlg* thePanel ) const
+{
+  Handle(HYDROData_Object) anObject;
+  Handle(HYDROData_Entity) anEntity;
+  QStringList aList;
+  // Update the list in the dialog
+  HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
+  HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
+  for ( ; anIter.More(); anIter.Next() )
+  {
+    anEntity = anIter.Value();
+    if ( !anEntity.IsNull() )
+    {
+      anObject = Handle(HYDROData_Object)::DownCast( anEntity );
+      if ( !anObject.IsNull() )
+      {
+        aList.append( anObject->GetName() );
+      }
+    }
+  }
+  thePanel->setSelectedGeomObjects( aList );
+}
+
 void HYDROGUI_CalculationOp::abortOperation()
 {
   closePreview();
@@ -137,10 +146,68 @@ HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
   HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() );
 
   // Connect signals and slots
+  connect( aPanel, SIGNAL( addObjects() ), this, SLOT( onAddObjects() ) );
+  connect( aPanel, SIGNAL( removeObjects() ), this, SLOT( onRemoveObjects() ) );
 
   return aPanel;
 }
 
+void HYDROGUI_CalculationOp::onAddObjects()
+{
+  // Add geometry objects selected in the module browser to the calculation case
+  Handle(HYDROData_Object) anObject;
+  Handle(HYDROData_Entity) anEntity;
+  QStringList aList;
+  HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( module() );
+  for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
+  {
+    anEntity = aSeq.Value( anIndex );
+    if ( !anEntity.IsNull() )
+    {
+      anObject = Handle(HYDROData_Object)::DownCast( anEntity );
+      if( !anObject.IsNull() )
+      {
+        if (myEditedObject->AddGeometryObject( anObject ))
+        {
+          aList.append( anObject->GetName() );
+        }
+      }
+    }
+  }
+  HYDROGUI_CalculationDlg* aPanel = 
+    ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
+  if ( aPanel )
+  {
+    updateGeomObjectsList( aPanel );
+  }
+}
+
+void HYDROGUI_CalculationOp::onRemoveObjects()
+{
+  // Remove selected objects from the calculation case
+  HYDROGUI_CalculationDlg* aPanel = 
+    ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
+  if ( aPanel )
+  {
+    QStringList aList = aPanel->getSelectedGeomObjects();
+    Handle(HYDROData_Object) anObject;
+    Handle(HYDROData_Entity) anEntity;
+    for (int i = 0; i < aList.length(); i++)
+    {
+      anEntity = HYDROGUI_Tool::FindObjectByName( module(), aList.at(i) );
+      if ( !anEntity.IsNull() )
+      {
+        anObject = Handle(HYDROData_Object)::DownCast( anEntity );
+        if ( !anObject.IsNull() )
+        {
+          myEditedObject->RemoveGeometryObject( anObject );
+        }
+      }
+    }
+    updateGeomObjectsList( aPanel );
+  }
+}
+
 bool HYDROGUI_CalculationOp::processApply( int&     theUpdateFlags,
                                            QString& theErrorMsg )
 {
index ecdd145d1c62a19f140ef6caa4c47dbba72690f7..9735e436e2fbdcac87783f9b81a9e8a88ec051d8 100644 (file)
@@ -33,6 +33,7 @@
 
 class SUIT_ViewManager;
 class OCCViewer_ViewManager;
+class HYDROGUI_CalculationDlg;
 
 class HYDROGUI_CalculationOp : public HYDROGUI_Operation
 {
@@ -80,12 +81,21 @@ protected:
   virtual bool                    processApply( int& theUpdateFlags, QString& theErrorMsg );
 
 protected slots:
+  /**
+   * Add geometry objects selected in the module browser to the calculation case.
+   */
+  void                            onAddObjects();
+  /**
+   * Remove selected objects from the calculation case.
+   */
+  void                            onRemoveObjects();
   void                            onSplitZones();
   void                            onLastViewClosed( SUIT_ViewManager* );
 
 private:
   void                            createPreview();
   void                            closePreview();
+  void                            updateGeomObjectsList( HYDROGUI_CalculationDlg* thePanel ) const;
 
 private:
   bool                            myIsEdit;