Salome HOME
refs #618
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_CalculationOp.cxx
index 6c6aa8e8afcce538cf5b01b22ff2c96810ad2530..2951e5838d5dd4003cb4ab77bac4bb40f461a312 100644 (file)
@@ -58,7 +58,8 @@ HYDROGUI_CalculationOp::HYDROGUI_CalculationOp( HYDROGUI_Module* theModule, bool
   myPreviewViewManager( NULL ),
   myShowGeomObjects( true ),
   myShowLandCovers( false ),
-  myShowZones( false )
+  myShowZones( false ),
+  myUpdateLandCoverZonesPrs( false )
 {
   setName( myIsEdit ? tr( "EDIT_CALCULATION" ) : tr( "CREATE_CALCULATION" ) );
 }
@@ -221,7 +222,10 @@ HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
   
   connect( aPanel, SIGNAL( orderChanged( bool& ) ), SLOT( onOrderChanged( bool& ) ) );
   connect( aPanel, SIGNAL( orderLandCoverChanged( bool& ) ), SLOT( onOrderLandCoverChanged( bool& ) ) );
-    
+
+  connect( aPanel, SIGNAL( ruleChanged( bool& ) ), SLOT( onRuleChanged( bool& ) ) );
+  connect( aPanel, SIGNAL( ruleLandCoverChanged( bool& ) ), SLOT( onRuleLandCoverChanged( bool& ) ) );
+
   connect( aPanel, SIGNAL( Next( const int ) ), SLOT( onNext( const int ) ) );
   connect( aPanel, SIGNAL( Back( const int ) ), SLOT( onHideZones( const int ) ) );
   //connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
@@ -672,6 +676,31 @@ bool HYDROGUI_CalculationOp::confirmOrderChange() const
   return isConfirmed;
 }
 
+bool HYDROGUI_CalculationOp::confirmRuleChange() 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( false );
+    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( "RULE_CHANGED" ),
+                               tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
+                               QMessageBox::Yes | QMessageBox::No,
+                               QMessageBox::No ) == QMessageBox::Yes );
+    }
+    else
+    {
+      isConfirmed = true; // No regions - no zones - nothing to recalculate
+    }
+  }
+  return isConfirmed;
+}
+
 bool HYDROGUI_CalculationOp::confirmModeChange() const
 {
   // Check if the case is already modified or not
@@ -801,6 +830,31 @@ bool HYDROGUI_CalculationOp::confirmLandCoverOrderChange() const
   return isConfirmed;
 }
 
+bool HYDROGUI_CalculationOp::confirmLandCoverRuleChange() 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 land cover zones
+    HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( true );
+    if ( aSeq.Length() > 0 )
+    {
+      // If there are already defined land cover zones then ask a user to confirm land cover zones recalculation
+      isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
+                               tr( "RULE_CHANGED" ),
+                               tr( "CONFIRM_LAND_COVER_PARTITION_RECALCULATION_REGIONS" ),
+                               QMessageBox::Yes | QMessageBox::No,
+                               QMessageBox::No ) == QMessageBox::Yes );
+    }
+    else
+    {
+      isConfirmed = true; // No regions - no land cover zones - nothing to recalculate
+    }
+  }
+  return isConfirmed;
+}
+
 bool HYDROGUI_CalculationOp::processApply( int&     theUpdateFlags,
                                            QString& theErrorMsg,
                                            QStringList& theBrowseObjectsEntries )
@@ -998,7 +1052,7 @@ void HYDROGUI_CalculationOp::onNext( const int theIndex )
     // automatic names generation for regions and zones
     myEditedObject->SetName( aNewCaseName );
     
-    // Set parameters for automatic mode
+    // Zones: set parameters for automatic mode
     int aMode = aPanel->getMode();
     if ( aMode == HYDROData_CalculationCase::AUTOMATIC )
     {
@@ -1030,6 +1084,37 @@ void HYDROGUI_CalculationOp::onNext( const int theIndex )
       }
     }
     aPanel->setEditZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
+
+    // Land cover zones: set parameters for automatic mode
+    aMode = aPanel->getLandCoverMode();
+    if ( aMode == HYDROData_CalculationCase::AUTOMATIC )
+    {
+      // Set objects in the specified order
+      if( myEditedObject->IsMustBeUpdated() )
+      {
+        myEditedObject->RemoveLandCovers();
+        foreach ( const QString& aName, aPanel->getAllLandCovers() )
+        {
+          Handle(HYDROData_LandCover) aLandCover = Handle(HYDROData_LandCover)::DownCast( 
+            HYDROGUI_Tool::FindObjectByName( module(), aName ) );
+          if ( aLandCover.IsNull() )
+          {
+            continue;
+          }
+          myEditedObject->AddLandCover( aLandCover );
+        }
+
+        // Clear priority rules
+        myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules, true );
+        // Set priority rules
+        foreach ( const HYDROData_CustomRule& aRule, aPanel->getLandCoverRules() ) {
+          myEditedObject->AddRule( aRule.Object1, aRule.Priority,
+                                   aRule.Object2, HYDROData_Zone::Merge_Object,
+                                   HYDROData_CalculationCase::DataTag_CustomLandCoverRules );
+        }
+      }
+    }
+    aPanel->setEditLandCoverZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
          
     if ( myEditedObject->IsMustBeUpdated() )
     {
@@ -1046,7 +1131,7 @@ void HYDROGUI_CalculationOp::onNext( const int theIndex )
 
       anIsToUpdateOb = true;
 
-      myEditedObject->SetToUpdate( true );
+      myUpdateLandCoverZonesPrs = true;
     }
     else
     {
@@ -1070,43 +1155,10 @@ void HYDROGUI_CalculationOp::onNext( const int theIndex )
 
     QApplication::setOverrideCursor( Qt::WaitCursor );
 
-    // Set parameters for automatic mode
-    int aMode = aPanel->getLandCoverMode();
-    if ( aMode == HYDROData_CalculationCase::AUTOMATIC )
-    {
-      // Set objects in the specified order
-      if( myEditedObject->IsMustBeUpdated() )
-      {
-        myEditedObject->RemoveLandCovers();
-        foreach ( const QString& aName, aPanel->getAllLandCovers() )
-        {
-          Handle(HYDROData_LandCover) aLandCover = Handle(HYDROData_LandCover)::DownCast( 
-            HYDROGUI_Tool::FindObjectByName( module(), aName ) );
-          if ( aLandCover.IsNull() )
-          {
-            continue;
-          }
-          myEditedObject->AddLandCover( aLandCover );
-        }
-
-        // Clear priority rules
-        myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules, true );
-        // Set priority rules
-        foreach ( const HYDROData_CustomRule& aRule, aPanel->getLandCoverRules() ) {
-          myEditedObject->AddRule( aRule.Object1, aRule.Priority,
-                                   aRule.Object2, HYDROData_Zone::Merge_Object,
-                                   HYDROData_CalculationCase::DataTag_CustomLandCoverRules );
-        }
-      }
-    }
-    aPanel->setEditLandCoverZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
-
     bool anIsToUpdateOb = false;
-    bool anIsToUpdate = myEditedObject->IsMustBeUpdated();
-    if ( anIsToUpdate )
+    if ( myUpdateLandCoverZonesPrs )
     {
       myShowZones = true;
-      myEditedObject->SetToUpdate( false );
       
       AssignDefaultZonesColors( true );
 
@@ -1118,7 +1170,9 @@ void HYDROGUI_CalculationOp::onNext( const int theIndex )
     closePreview( false );
     createPreview( true );
     
-    if ( !anIsToUpdate )
+    if ( myUpdateLandCoverZonesPrs )
+      myUpdateLandCoverZonesPrs = false;
+    else
     {
       // Hide zones
       setZonesVisible( false, false );
@@ -1720,3 +1774,27 @@ void HYDROGUI_CalculationOp::onOrderLandCoverChanged( bool& isConfirmed )
   if( isConfirmed )
     myEditedObject->SetToUpdate( true );
 }
+
+void HYDROGUI_CalculationOp::onRuleChanged( bool& isConfirmed )
+{
+  HYDROGUI_CalculationDlg* aPanel = 
+    ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
+  if ( !aPanel )
+    return;
+
+  isConfirmed = confirmRuleChange();
+  if( isConfirmed )
+    myEditedObject->SetToUpdate( true );
+}
+
+void HYDROGUI_CalculationOp::onRuleLandCoverChanged( bool& isConfirmed )
+{
+  HYDROGUI_CalculationDlg* aPanel = 
+    ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
+  if ( !aPanel )
+    return;
+
+  isConfirmed = confirmLandCoverRuleChange();
+  if( isConfirmed )
+    myEditedObject->SetToUpdate( true );
+}