]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Restriction for types of added objects corrected.
authoradv <adv@opencascade.com>
Tue, 3 Dec 2013 07:12:13 +0000 (07:12 +0000)
committeradv <adv@opencascade.com>
Tue, 3 Dec 2013 07:12:13 +0000 (07:12 +0000)
src/HYDROGUI/HYDROGUI_CalculationOp.cxx

index 0ded37300fa1e7f28d539dc2f850508c8e586f8e..6fb6cfb4ab9b2ee538421a3440dbcfdf7886ad5f 100644 (file)
@@ -32,8 +32,8 @@
 
 #include <HYDROData_PolylineXY.h>
 #include <HYDROData_Iterator.h>
-#include <HYDROData_ImmersibleZone.h>
 #include <HYDROData_Object.h>
+#include <HYDROData_Tool.h>
 
 #include <OCCViewer_ViewManager.h>
 #include <OCCViewer_ViewModel.h>
@@ -148,25 +148,18 @@ void HYDROGUI_CalculationOp::startOperation()
 void HYDROGUI_CalculationOp::getNamesAndEntries( const HYDROData_SequenceOfObjects& theSeq, 
                                                 QStringList& theNames, QStringList& theEntries ) const
 {
-  Handle(HYDROData_Object) anObject;
-  Handle(HYDROData_Entity) anEntity;
   theNames.clear();
   theEntries.clear();
   HYDROData_SequenceOfObjects::Iterator anIter( theSeq );
   for ( ; anIter.More(); anIter.Next() )
   {
-    anEntity = anIter.Value();
-    if ( !anEntity.IsNull() )
-    {
-      // Temporary solution will be revised later
-      //anObject = Handle(HYDROData_Object)::DownCast( anEntity );
-      anObject = Handle(HYDROData_ImmersibleZone)::DownCast( anEntity );
-      if ( !anObject.IsNull() )
-      {
-        theNames.append( anObject->GetName() );
-        theEntries.append( HYDROGUI_DataObject::dataObjectEntry( anObject ) );
-      }
-    }
+    Handle(HYDROData_Entity) anEntity = anIter.Value();
+    if ( !HYDROData_Tool::IsGeometryObject( anEntity ) )
+      continue;
+
+    theNames.append( anEntity->GetName() );
+    theEntries.append( HYDROGUI_DataObject::dataObjectEntry( anEntity ) );
   }
 }
 
@@ -412,36 +405,30 @@ void HYDROGUI_CalculationOp::onAddObjects()
 {
   HYDROGUI_CalculationDlg* aPanel = 
     ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
-  if ( aPanel )
+  if ( !aPanel )
+    return;
+
+  // Add geometry objects selected in the module browser to the calculation case
+  QStringList aSelectedList = aPanel->getSelectedAvailableGeomObjects();
+  if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
+    return;
+
+  QStringList anAddedList;
+  for (int i = 0; i < aSelectedList.length(); i++)
   {
-    // Add geometry objects selected in the module browser to the calculation case
-    QStringList aSelectedList = aPanel->getSelectedAvailableGeomObjects();
-    if ( ( !aSelectedList.isEmpty() ) && ( confirmRegionsChange() ) )
-    {
-      Handle(HYDROData_Object) anObject;
-      Handle(HYDROData_Entity) anEntity;
-      QStringList aList;
-      for (int i = 0; i < aSelectedList.length(); i++)
-      {
-        anEntity = HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) );
-        if ( !anEntity.IsNull() )
-        {
-          anObject = Handle(HYDROData_Object)::DownCast( anEntity );
-          if ( !anObject.IsNull() )
-          {
-            if (myEditedObject->AddGeometryObject( anObject ))
-            {
-              aList.append( anObject->GetName() );
-            }
-          }
-        }
-      }
-      if ( !aList.isEmpty() )
-      {
-        aPanel->includeGeomObjects( aList );
-        createPreview();
-      }
-    }
+    Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast( 
+      HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
+    if ( anObject.IsNull() )
+      continue;
+
+    if ( myEditedObject->AddGeometryObject( anObject ) )
+      anAddedList.append( anObject->GetName() );
+  }
+
+  if ( !anAddedList.isEmpty() )
+  {
+    aPanel->includeGeomObjects( anAddedList );
+    createPreview();
   }
 }
 
@@ -450,32 +437,25 @@ void HYDROGUI_CalculationOp::onRemoveObjects()
   // Remove selected objects from the calculation case
   HYDROGUI_CalculationDlg* aPanel = 
     ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
-  if ( aPanel )
+  if ( !aPanel )
+    return;
+
+  QStringList aSelectedList = aPanel->getSelectedGeomObjects();
+  if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
+    return;
+
+  for (int i = 0; i < aSelectedList.length(); i++)
   {
-    QStringList aList = aPanel->getSelectedGeomObjects();
-    if ( ( !aList.isEmpty() ) && ( confirmRegionsChange() ) )
-    {
-      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() )
-          {
-            module()->removeObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anObject );
-            myEditedObject->RemoveGeometryObject( anObject );
-          }
-        }
-      }
-      if ( !aList.isEmpty() )
-      {
-        aPanel->excludeGeomObjects( aList );
-      }
-    }
+    Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast( 
+      HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
+    if ( anObject.IsNull() )
+      continue;
+
+    module()->removeObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anObject );
+    myEditedObject->RemoveGeometryObject( anObject );
   }
+
+  aPanel->excludeGeomObjects( aSelectedList );
 }
 
 bool HYDROGUI_CalculationOp::confirmRegionsChange() const