Salome HOME
Icons are shown in the object browser tree.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_CalculationOp.cxx
index 54241112d3d13930ca893eb7a8571d82a23b0ed2..0ded37300fa1e7f28d539dc2f850508c8e586f8e 100644 (file)
@@ -30,7 +30,7 @@
 #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>
@@ -85,26 +85,30 @@ 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() )
-    {
-      aPolylineName = aPolylineObj->GetName();
-      if ( !aPolylineName.isEmpty() )
-      {
-        aList.append( aPolylineName );
-        anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aPolylineObj ) );
+    { 
+      // Check the polyline shape
+      TopoDS_Shape aPolylineShape = aPolylineObj->GetShape();
+      if ( !aPolylineShape.IsNull() && aPolylineShape.ShapeType() == TopAbs_WIRE ) {
+        aPolylineName = aPolylineObj->GetName();
+        if ( !aPolylineName.isEmpty() )
+        {
+          aList.append( aPolylineName );
+          anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aPolylineObj ) );
+        }
       }
     }
   }
   aPanel->setPolylineNames( aList, anEntryList );
 
-  QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), "Case" );
+  QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_CALCULATION_CASE_NAME" ) );
 
   myEditedObject.Nullify();
   if ( myIsEdit )
@@ -154,7 +158,9 @@ void HYDROGUI_CalculationOp::getNamesAndEntries( const HYDROData_SequenceOfObjec
     anEntity = anIter.Value();
     if ( !anEntity.IsNull() )
     {
-      anObject = Handle(HYDROData_Object)::DownCast( anEntity );
+      // 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() );
@@ -208,8 +214,7 @@ 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;
-  HYDROGUI_Shape* aShape;
+  Handle(HYDROData_PolylineXY) anObject;
   Handle(AIS_InteractiveContext) aCtx;
   if ( myPreviewViewManager ) 
   {
@@ -233,10 +238,10 @@ void HYDROGUI_CalculationOp::onBoundarySelected ( const QString & theObjName )
   else
   {
     Handle(HYDROData_Entity) anEntity = 
-      HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_POLYLINE );
+      HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_POLYLINEXY );
     if ( !anEntity.IsNull() )
     {
-      anObject = Handle(HYDROData_Polyline)::DownCast( anEntity );
+      anObject = Handle(HYDROData_PolylineXY)::DownCast( anEntity );
       if ( !anObject.IsNull() )
       {
         myEditedObject->SetBoundaryPolyline( anObject );
@@ -410,29 +415,32 @@ void HYDROGUI_CalculationOp::onAddObjects()
   if ( aPanel )
   {
     // Add geometry objects selected in the module browser to the calculation case
-    Handle(HYDROData_Object) anObject;
-    Handle(HYDROData_Entity) anEntity;
-    QStringList aList;
     QStringList aSelectedList = aPanel->getSelectedAvailableGeomObjects();
-    for (int i = 0; i < aSelectedList.length(); i++)
+    if ( ( !aSelectedList.isEmpty() ) && ( confirmRegionsChange() ) )
     {
-      anEntity = HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) );
-      if ( !anEntity.IsNull() )
+      Handle(HYDROData_Object) anObject;
+      Handle(HYDROData_Entity) anEntity;
+      QStringList aList;
+      for (int i = 0; i < aSelectedList.length(); i++)
       {
-        anObject = Handle(HYDROData_Object)::DownCast( anEntity );
-        if ( !anObject.IsNull() )
+        anEntity = HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) );
+        if ( !anEntity.IsNull() )
         {
-          if (myEditedObject->AddGeometryObject( anObject ))
+          anObject = Handle(HYDROData_Object)::DownCast( anEntity );
+          if ( !anObject.IsNull() )
           {
-            aList.append( anObject->GetName() );
+            if (myEditedObject->AddGeometryObject( anObject ))
+            {
+              aList.append( anObject->GetName() );
+            }
           }
         }
       }
-    }
-    if ( !aList.isEmpty() )
-    {
-      aPanel->includeGeomObjects( aList );
-      createPreview();
+      if ( !aList.isEmpty() )
+      {
+        aPanel->includeGeomObjects( aList );
+        createPreview();
+      }
     }
   }
 }
@@ -445,26 +453,54 @@ void HYDROGUI_CalculationOp::onRemoveObjects()
   if ( aPanel )
   {
     QStringList aList = aPanel->getSelectedGeomObjects();
-    Handle(HYDROData_Object) anObject;
-    Handle(HYDROData_Entity) anEntity;
-    for (int i = 0; i < aList.length(); i++)
+    if ( ( !aList.isEmpty() ) && ( confirmRegionsChange() ) )
     {
-      anEntity = HYDROGUI_Tool::FindObjectByName( module(), aList.at(i) );
-      if ( !anEntity.IsNull() )
+      Handle(HYDROData_Object) anObject;
+      Handle(HYDROData_Entity) anEntity;
+      for (int i = 0; i < aList.length(); i++)
       {
-        anObject = Handle(HYDROData_Object)::DownCast( anEntity );
-        if ( !anObject.IsNull() )
+        anEntity = HYDROGUI_Tool::FindObjectByName( module(), aList.at(i) );
+        if ( !anEntity.IsNull() )
         {
-          module()->removeObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anObject );
-          myEditedObject->RemoveGeometryObject( anObject );
+          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 );
+      }
     }
-    if ( !aList.isEmpty() )
+  }
+}
+
+bool HYDROGUI_CalculationOp::confirmRegionsChange() const
+{
+  // Check if the case is already modified or not
+  bool isConfirmed = myEditedObject->IsMustBeUpdated();
+  if ( !isConfirmed )
+  {
+    // If not modified check if the case has already defined regions with zones
+    HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
+    if ( aSeq.Length() > 0 )
+    {
+      // If there are already defined zones then ask a user to confirm zones recalculation
+      isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
+                               tr( "REGIONS_CHANGED" ),
+                               tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION" ),
+                               QMessageBox::Yes | QMessageBox::No,
+                               QMessageBox::No ) == QMessageBox::Yes );
+    }
+    else
     {
-      aPanel->excludeGeomObjects( aList );
+      isConfirmed = true; // No regions - no zones - nothing to recalculate
     }
   }
+  return isConfirmed;
 }
 
 bool HYDROGUI_CalculationOp::processApply( int&     theUpdateFlags,
@@ -475,7 +511,7 @@ bool HYDROGUI_CalculationOp::processApply( int&     theUpdateFlags,
   if ( !aPanel )
     return false;
 
-  theUpdateFlags = UF_Model;
+  theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced;
 
   return true;
 }
@@ -525,19 +561,28 @@ void HYDROGUI_CalculationOp::onApply()
 
 void HYDROGUI_CalculationOp::onSplitZones()
 {
+  HYDROGUI_CalculationDlg* aPanel = 
+    ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
+  if ( !aPanel )
+    return;
+
   QApplication::setOverrideCursor( Qt::WaitCursor );
 
+  QString aNewCaseName = aPanel->getObjectName();
+  QString anOldCaseName = myEditedObject->GetName();
+
+  bool anIsToUpdateOb = myIsEdit && anOldCaseName != aNewCaseName;
+  
+  // At first we must to update the case name because of 
+  // automatic names generation for regions and zones
+  myEditedObject->SetName( aNewCaseName );
+  
   if ( myEditedObject->IsMustBeUpdated() )
   {
     myShowZones = true;
     myEditedObject->SplitGeometryObjects();
 
-    HYDROGUI_CalculationDlg* aPanel = 
-      ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
-    if ( aPanel )
-    {
-      aPanel->setEditedObject( myEditedObject );
-    }
+    aPanel->setEditedObject( myEditedObject );
 
     createPreview();
   }
@@ -546,6 +591,9 @@ void HYDROGUI_CalculationOp::onSplitZones()
     setZonesVisible( true );
   }
 
+  if ( anIsToUpdateOb )
+    module()->getApp()->updateObjectBrowser( false );
+
   QApplication::restoreOverrideCursor();
 }