Salome HOME
Fix for the bug #45: check and warning when the same image is used in 2 arguments.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_CalculationOp.cxx
index 707a308655bc1726839d9f5aa9a70db953a4e33b..ad69b40c86fe7ae1690bb09178491878e8bc245a 100644 (file)
 #include "HYDROGUI_Zone.h"
 #include "HYDROGUI_Region.h"
 
-#include <HYDROData_Polyline.h>
+#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>
@@ -85,17 +85,17 @@ void HYDROGUI_CalculationOp::startOperation()
   // Get all polylines
   aList.clear();
   anEntryList.clear();
-  HYDROData_Iterator anIter( doc(), KIND_POLYLINE );
-  Handle(HYDROData_Polyline) aPolylineObj;
+  HYDROData_Iterator anIter( doc(), KIND_POLYLINEXY );
+  Handle(HYDROData_PolylineXY) aPolylineObj;
   QString aPolylineName;
   for ( ; anIter.More(); anIter.Next() )
   {
-    aPolylineObj = Handle(HYDROData_Polyline)::DownCast( anIter.Current() );
+    aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( anIter.Current() );
 
     if ( !aPolylineObj.IsNull() && aPolylineObj->IsClosed() )
     { 
       // Check the polyline shape
-      TopoDS_Shape aPolylineShape = aPolylineObj->GetTopShape();
+      TopoDS_Shape aPolylineShape = aPolylineObj->GetShape();
       if ( !aPolylineShape.IsNull() && aPolylineShape.ShapeType() == TopAbs_WIRE ) {
         aPolylineName = aPolylineObj->GetName();
         if ( !aPolylineName.isEmpty() )
@@ -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 ) );
   }
 }
 
@@ -193,8 +186,8 @@ HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
   // Connect signals and slots
   connect( aPanel, SIGNAL( addObjects() ), SLOT( onAddObjects() ) );
   connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) );
-  connect( aPanel, SIGNAL( splitZones() ), SLOT( onSplitZones() ) );
-  connect( aPanel, SIGNAL( hideZones() ), SLOT( onHideZones() ) );
+  connect( aPanel, SIGNAL( Next( const int ) ), SLOT( onSplitZones() ) );
+  connect( aPanel, SIGNAL( Back( const int ) ), SLOT( onHideZones() ) );
   connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
   connect( aPanel, SIGNAL( setMergeType( int, QString& ) ), SLOT( onSetMergeType( int, QString& ) ) );
   connect( aPanel, SIGNAL( moveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ),
@@ -213,43 +206,39 @@ HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
 
 void HYDROGUI_CalculationOp::onBoundarySelected ( const QString & theObjName )
 {
-  // Set the selected boundary polyline to the calculation case
-  Handle(HYDROData_Polyline) anObject;
-  Handle(AIS_InteractiveContext) aCtx;
-  if ( myPreviewViewManager ) 
-  {
-    if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
-    {
-      aCtx = aViewer->getAISContext();
-    }
-  }
+  bool anIsToUpdateViewer = false;
+
   // Remove the old boundary from the operation viewer
-  anObject = myEditedObject->GetBoundaryPolyline();
-  if ( !anObject.IsNull() )
+  Handle(HYDROData_PolylineXY) aPrevPolyline = 
+    myEditedObject->GetBoundaryPolyline();
+  if ( !aPrevPolyline.IsNull() )
   {
-    module()->removeObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anObject );
+    module()->removeObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aPrevPolyline );
+    anIsToUpdateViewer = true;
   }
 
-  if ( theObjName.trimmed().isEmpty() )
-  {
-    // No polyline is selected
-    myEditedObject->RemoveBoundaryPolyline();
-  }
-  else
+  // Set the selected boundary polyline to the calculation case
+  Handle(HYDROData_PolylineXY) aNewPolyline = Handle(HYDROData_PolylineXY)::DownCast(
+    HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_POLYLINEXY ) );
+  myEditedObject->SetBoundaryPolyline( aNewPolyline );
+
+  if ( myPreviewViewManager )
   {
-    Handle(HYDROData_Entity) anEntity = 
-      HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_POLYLINE );
-    if ( !anEntity.IsNull() )
+    OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
+    if ( aViewer )
     {
-      anObject = Handle(HYDROData_Polyline)::DownCast( anEntity );
-      if ( !anObject.IsNull() )
+      if ( !aNewPolyline.IsNull() )
       {
-        myEditedObject->SetBoundaryPolyline( anObject );
+        Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
         if ( !aCtx.IsNull() )
         {
-          showObject( anEntity, aCtx );
+          showObject( aNewPolyline, aCtx );
+          anIsToUpdateViewer = true;
         }
       }
+
+      if ( anIsToUpdateViewer )
+        aViewer->update();
     }
   }
 }
@@ -412,36 +401,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 +433,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
@@ -580,7 +556,7 @@ void HYDROGUI_CalculationOp::onSplitZones()
   if ( myEditedObject->IsMustBeUpdated() )
   {
     myShowZones = true;
-    myEditedObject->SplitGeometryObjects();
+    myEditedObject->Update();
 
     aPanel->setEditedObject( myEditedObject );
 
@@ -637,6 +613,8 @@ void HYDROGUI_CalculationOp::setZonesVisible( bool theIsVisible )
           }
         }
       }
+
+      aViewer->update();
     }
   }
 }
@@ -715,6 +693,8 @@ void HYDROGUI_CalculationOp::createPreview()
       if ( OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView() )
         vw->onTopView();
     }
+
+    aViewer->update();
   }
 }
 
@@ -728,7 +708,7 @@ void HYDROGUI_CalculationOp::showObject( Handle(HYDROData_Entity) theEntity, Han
       aShape = new HYDROGUI_Shape( theCtx, theEntity );
       module()->setObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, theEntity, aShape );
     }
-    aShape->update();
+    aShape->update( false );
   }
 }