]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
refs #542: show warning, when order or priority rules are changed for geometry object...
authormkr <mkr@opencascade.com>
Thu, 25 Jun 2015 14:05:58 +0000 (17:05 +0300)
committermkr <mkr@opencascade.com>
Thu, 25 Jun 2015 14:05:58 +0000 (17:05 +0300)
src/HYDROGUI/HYDROGUI_CalculationDlg.cxx
src/HYDROGUI/HYDROGUI_CalculationDlg.h
src/HYDROGUI/HYDROGUI_CalculationOp.cxx
src/HYDROGUI/HYDROGUI_CalculationOp.h
src/HYDROGUI/HYDROGUI_PriorityTableModel.cxx
src/HYDROGUI/HYDROGUI_PriorityTableModel.h
src/HYDROGUI/HYDROGUI_PriorityWidget.cxx
src/HYDROGUI/HYDROGUI_PriorityWidget.h
src/HYDROGUI/resources/HYDROGUI_msg_en.ts

index 3103fe4a74b6aac72d7c76fb00ffb4f598ff1957..396e2c579c436b469beb17c07325d9b77c6551dc 100644 (file)
@@ -245,6 +245,8 @@ QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() {
 
   connect( myGeomObjects, SIGNAL( orderChanged() ), SLOT( onOrderChanged() ) );
 
+  connect( myPriorityWidget, SIGNAL( ruleChanged() ), SLOT( onRuleChanged() ) );
+
   return aPage;
 }
 
@@ -445,6 +447,8 @@ QWizardPage* HYDROGUI_CalculationDlg::createLandCoversPage() {
 
   connect( myLandCovers, SIGNAL( orderChanged() ), SLOT( onOrderLandCoverChanged() ) );
 
+  connect( myLandCoverPriorityWidget, SIGNAL( ruleChanged() ), SLOT( onLandCoverRuleChanged() ) );
+
   return aPage;
 }
 
@@ -1144,6 +1148,17 @@ void HYDROGUI_CalculationDlg::onOrderChanged()
     myGeomObjects->undoLastMove();
 }
 
+/**
+  Slot called when priority rule for geometry objects is changed.
+ */
+void HYDROGUI_CalculationDlg::onRuleChanged()
+{
+  bool isConfirmed = true;
+  emit ruleChanged( isConfirmed );
+  if( !isConfirmed )
+    myPriorityWidget->undoLastChange();
+}
+
 void HYDROGUI_CalculationDlg::setStricklerTable( const QString& theStricklerTableName, bool theBlockSignals )
 {
   bool isBlocked;
@@ -1230,3 +1245,14 @@ void HYDROGUI_CalculationDlg::onOrderLandCoverChanged()
   else
     myLandCovers->undoLastMove();  
 }
+
+/**
+  Slot called when priority rule for land covers is changed.
+ */
+void HYDROGUI_CalculationDlg::onLandCoverRuleChanged()
+{
+  bool isConfirmed = true;
+  emit ruleLandCoverChanged( isConfirmed );
+  if( !isConfirmed )
+    myLandCoverPriorityWidget->undoLastChange();
+}
index d6105168c3d8807675d5ba204a60bd93d406b9b0..c0e972c190c70d0c083174fa6b3e7c5ff8b87d04 100644 (file)
@@ -98,6 +98,7 @@ public slots:
   void                       refreshZonesBrowser();
   void                       onDataChanged();
   void                       onOrderChanged();
+  void                       onRuleChanged();
 
   void                       setLandCoverMode( int theMode );
   void                       setStricklerTable( const QString& theStricklerTableName, bool theBlockSignals = true );
@@ -106,6 +107,7 @@ public slots:
   void                       refreshLandCoverZonesBrowser();
   void                       onDataLandCoverChanged();
   void                       onOrderLandCoverChanged();
+  void                       onLandCoverRuleChanged();
 
   /**
    * Process items selection: hide/show bathymetry merge type selector.
@@ -142,6 +144,7 @@ signals:
   void                       removeObjects();
   void                       objectsSelected();
   void                       orderChanged( bool& isConfirmed );
+  void                       ruleChanged( bool& isConfirmed );
 
   void                       addGroups();
   void                       removeGroups();
@@ -159,6 +162,7 @@ signals:
   void                       removeLandCovers();
   void                       landCoversSelected();
   void                       orderLandCoverChanged( bool& isConfirmed );
+  void                       ruleLandCoverChanged( bool& isConfirmed );
 
   void                       createLandCoverRegion( const QList<SUIT_DataObject*>& theLandCoverZonesList );
   
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 );
+}
index 9d2dc0d1b5a91326b7b6d844b5a188750f30d134..cefe99bfddfafc1970be36fa22602abd74a1b61d 100644 (file)
@@ -150,6 +150,9 @@ protected slots:
   void onOrderChanged( bool& isConfirmed );
   void onOrderLandCoverChanged( bool& isConfirmed );
 
+  void onRuleChanged( bool& isConfirmed );
+  void onRuleLandCoverChanged( bool& isConfirmed );
+
 private:
   void                            createPreview( const bool theLandCover);
   void                            closePreview( bool theRemoveViewManager = true );
@@ -188,17 +191,20 @@ private:
   bool confirmRegionsChange() const;
   bool confirmModeChange() const;
   bool confirmOrderChange() const;
+  bool confirmRuleChange() const;
   bool confirmContinueWithWarning( const HYDROData_Warning& theWarning ) const;
 
   bool confirmLandCoverRegionsChange() const;
   bool confirmLandCoverModeChange() const;
   bool confirmLandCoverOrderChange() const;
+  bool confirmLandCoverRuleChange() const;
 
 private:
   bool                            myIsEdit;
   bool                            myShowZones;
   bool                            myShowGeomObjects;
   bool                            myShowLandCovers;
+  bool                            myUpdateLandCoverZonesPrs;
   Handle(HYDROData_CalculationCase) myEditedObject;
 
   SUIT_ViewManager*               myActiveViewManager;
index c284d7927e94e306a413d6a9b216a4003569e272..684d3a53ea8e614b9194b1008931acb0db8d8cfa 100644 (file)
@@ -19,6 +19,7 @@
 #include "HYDROGUI_PriorityTableModel.h"
 
 #include <HYDROData_LandCover.h>
+#include <HYDROGUI_DataObject.h>
 
 /**
   Constructor.
@@ -119,8 +120,11 @@ bool HYDROGUI_PriorityTableModel::setData( const QModelIndex & theIndex, const Q
   }
 
   bool aRes = false;
-
+  
   if ( theRole ==  Qt::EditRole ) {
+    bool aRuleChanged = false;
+    myPrevRules = myRules;
+
     int aColumn = theIndex.column();
 
     if ( aColumn == 0 || aColumn == 2 ) {
@@ -135,9 +139,16 @@ bool HYDROGUI_PriorityTableModel::setData( const QModelIndex & theIndex, const Q
       if ( !anObject.IsNull() ) {
         HYDROData_CustomRule anEditedRule = myRules[aRow];
         
+        QString anEntryNew = HYDROGUI_DataObject::dataObjectEntry( anObject );
         if ( aColumn == 0 ) {
+          QString anEntryOld = HYDROGUI_DataObject::dataObjectEntry( anEditedRule.Object1 );
+          if ( anEntryOld != anEntryNew )
+            aRuleChanged = true;
           anEditedRule.Object1 = anObject;
         } else {
+          QString anEntryOld = HYDROGUI_DataObject::dataObjectEntry( anEditedRule.Object2 );
+          if ( anEntryOld != anEntryNew )
+            aRuleChanged = true;
           anEditedRule.Object2 = anObject;
         }
         
@@ -145,14 +156,24 @@ bool HYDROGUI_PriorityTableModel::setData( const QModelIndex & theIndex, const Q
           myRules[aRow] = anEditedRule;
           aRes = true;
         } else {
+          aRuleChanged = false;
           emit showError( tr("ALREADY_EXISTS") );
         }
       }
     } else if ( aColumn == 1 ) {
-      myRules[aRow].Priority = (HYDROData_PriorityType)theValue.toInt();
+      HYDROData_PriorityType aNewPriority = (HYDROData_PriorityType)theValue.toInt();
+      if ( myRules[aRow].Priority != aNewPriority )
+        aRuleChanged = true;
+      myRules[aRow].Priority = aNewPriority;
     } else if ( aColumn == 3 ) {
-      myRules[aRow].MergeType = (HYDROData_Zone::MergeType)theValue.toInt();;
+      HYDROData_Zone::MergeType aNewMergeType = (HYDROData_Zone::MergeType)theValue.toInt();
+      if ( myRules[aRow].MergeType != aNewMergeType )
+        aRuleChanged = true;
+      myRules[aRow].MergeType = aNewMergeType;
     }
+
+    if ( aRuleChanged )
+      emit ruleChanged();
   }
 
   return aRes;
@@ -179,6 +200,7 @@ int HYDROGUI_PriorityTableModel::columnCount( const QModelIndex &theParent ) con
 void HYDROGUI_PriorityTableModel::setRules( const HYDROData_ListOfRules& theRules )
 {
   beginResetModel();
+  myPrevRules = myRules;
   myRules = theRules;
   endResetModel();
 }
@@ -238,6 +260,8 @@ void HYDROGUI_PriorityTableModel::setObjects( const QList<Handle(HYDROData_Entit
 {
   myObjects = theObjects;
     
+  myPrevRules = myRules;
+
   beginResetModel();
 
   // Remove rules which use objects which are no longer available
@@ -317,6 +341,8 @@ bool HYDROGUI_PriorityTableModel::createNewRule()
     aNewRule.Priority = aPriorityType;
     aNewRule.MergeType = HYDROData_Zone::Merge_ZMIN;
 
+    myPrevRules = myRules;
+
     beginResetModel();
     myRules << aNewRule;
     endResetModel();
@@ -351,6 +377,8 @@ bool HYDROGUI_PriorityTableModel::removeRows ( int theRow, int theCount, const Q
     aLastRow = myRules.count() - 1;
   }
 
+  myPrevRules = myRules;
+
   beginRemoveRows( theParent, theRow, aLastRow );
 
   // Remove the corresponding rules
@@ -495,6 +523,17 @@ void HYDROGUI_PriorityTableModel::setColumnCount( int theColumnCount )
   myColumnCount = theColumnCount;
 }
 
+/**
+ Undo last change in the list of priority rules.
+ */
+void HYDROGUI_PriorityTableModel::undoLastChange()
+{
+  beginResetModel();
+  myRules = myPrevRules;
+  endResetModel();
+  reset();
+}
+
 /**
   Get type of objects for which rules are defined assuming,
   that all objects in the list have the same type.
index 9133843769deec66b81c69263f3be4624c7aaed7..17dbd802c7809be75c66cedbf71df3d374fb1bce 100644 (file)
@@ -67,6 +67,8 @@ public:
   bool canCreateNewRule() const;
 
   void setColumnCount( int theColumnCount );
+
+  void undoLastChange();
   
 protected:
   bool isUsed( const Handle(HYDROData_Entity)& theObj1, 
@@ -80,6 +82,7 @@ protected:
 
 signals:
   void showError( const QString& theMsg );
+  void ruleChanged();
 
 private:
   const ObjectKind getObjectsKind() const;
@@ -88,7 +91,7 @@ private:
 
   HYDROGUI_Module* myModule;
 
-  HYDROData_ListOfRules myRules;
+  HYDROData_ListOfRules myRules, myPrevRules;
   QList<Handle(HYDROData_Entity)> myObjects;
 
   int myColumnCount;
index 7175941cca187d7ede319a448db90aa92afa00e5..6c85d3e0ab54c76392207576a17c5f2a088dca11 100644 (file)
@@ -185,6 +185,7 @@ HYDROGUI_PriorityWidget::HYDROGUI_PriorityWidget( QWidget* theParent )
             this, SLOT( onSelectionChanged() ) );
 
   connect( aModel, SIGNAL( showError( const QString& ) ), this, SLOT( onShowError( const QString& ) ) );
+  connect( aModel, SIGNAL( ruleChanged() ), this, SIGNAL( ruleChanged() ) );
 }
 
 /**
@@ -204,6 +205,7 @@ void HYDROGUI_PriorityWidget::onAddRule()
   if ( aModel ) {
     if (aModel->createNewRule()) {
       updateControls();
+      emit ruleChanged();
     }
   }
 }
@@ -226,6 +228,7 @@ void HYDROGUI_PriorityWidget::onRemoveRule()
     
     if ( aModel->removeRows( aRows ) ) {
       updateControls();
+      emit ruleChanged();
     }
   }
 }
@@ -239,6 +242,7 @@ void HYDROGUI_PriorityWidget::onClearRules()
     dynamic_cast<HYDROGUI_PriorityTableModel*>( myTable->model() );
   if ( aModel && aModel->removeAll() ) {
     updateControls();
+    emit ruleChanged();
   }
 }
 
@@ -325,4 +329,15 @@ void HYDROGUI_PriorityWidget::updateControls()
  */
 void HYDROGUI_PriorityWidget::onShowError( const QString& theMsg ) {
   SUIT_MessageBox::warning( this, tr( "INCORRECT_INPUT" ), theMsg );
-}
\ No newline at end of file
+}
+
+/**
+ Undo last change in priority rules table.
+ */
+void HYDROGUI_PriorityWidget::undoLastChange()
+{
+  HYDROGUI_PriorityTableModel* aModel = 
+    dynamic_cast<HYDROGUI_PriorityTableModel*>( myTable->model() );
+  if ( aModel )
+    aModel->undoLastChange();
+}
index bbc6c9edf86a43bea946d1f8f5098a50a8897e7c..ff1cfc41a9349c1788645e64a188112eebba0a47 100644 (file)
@@ -54,9 +54,14 @@ public:
 
   QTableView* getTable() const;
 
+  void undoLastChange();
+
 protected:
   void updateControls();
 
+signals:
+  void ruleChanged();
+
 protected slots:
   void onAddRule();
   void onRemoveRule();
index 381bc4c857fd855deecf5506252ccd513903d501..bd88bd54135141c0c106e17dd6f4b90dfd0ca35e 100644 (file)
@@ -401,6 +401,10 @@ All supported formats (*.brep *.iges *.igs *.step *.stp)</translation>
       <source>ORDER_CHANGED</source>
       <translation>Order of objects is changed</translation>
     </message>
+    <message>
+      <source>RULE_CHANGED</source>
+      <translation>Priority rule for objects is changed</translation>
+    </message>
     <message>
       <source>CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS</source>
       <translation>Case splitting zones already exist and will be recalculated after regions list modification. Do you confirm the recalculation?</translation>