From: mkr Date: Thu, 25 Jun 2015 14:05:58 +0000 (+0300) Subject: refs #542: show warning, when order or priority rules are changed for geometry object... X-Git-Tag: v1.4.2~29^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b7f29417b3f18f4a2719c68bc7863f081ab2c4e1;p=modules%2Fhydro.git refs #542: show warning, when order or priority rules are changed for geometry objects or land covers. --- diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx index 3103fe4a..396e2c57 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx @@ -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(); +} diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.h b/src/HYDROGUI/HYDROGUI_CalculationDlg.h index d6105168..c0e972c1 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.h +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.h @@ -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& theLandCoverZonesList ); diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx index 6c6aa8e8..2951e583 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx @@ -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( inputPanel() ); + if ( !aPanel ) + return; + + isConfirmed = confirmRuleChange(); + if( isConfirmed ) + myEditedObject->SetToUpdate( true ); +} + +void HYDROGUI_CalculationOp::onRuleLandCoverChanged( bool& isConfirmed ) +{ + HYDROGUI_CalculationDlg* aPanel = + ::qobject_cast( inputPanel() ); + if ( !aPanel ) + return; + + isConfirmed = confirmLandCoverRuleChange(); + if( isConfirmed ) + myEditedObject->SetToUpdate( true ); +} diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.h b/src/HYDROGUI/HYDROGUI_CalculationOp.h index 9d2dc0d1..cefe99bf 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.h +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.h @@ -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; diff --git a/src/HYDROGUI/HYDROGUI_PriorityTableModel.cxx b/src/HYDROGUI/HYDROGUI_PriorityTableModel.cxx index c284d792..684d3a53 100644 --- a/src/HYDROGUI/HYDROGUI_PriorityTableModel.cxx +++ b/src/HYDROGUI/HYDROGUI_PriorityTableModel.cxx @@ -19,6 +19,7 @@ #include "HYDROGUI_PriorityTableModel.h" #include +#include /** 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 myObjects; int myColumnCount; diff --git a/src/HYDROGUI/HYDROGUI_PriorityWidget.cxx b/src/HYDROGUI/HYDROGUI_PriorityWidget.cxx index 7175941c..6c85d3e0 100644 --- a/src/HYDROGUI/HYDROGUI_PriorityWidget.cxx +++ b/src/HYDROGUI/HYDROGUI_PriorityWidget.cxx @@ -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( 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( myTable->model() ); + if ( aModel ) + aModel->undoLastChange(); +} diff --git a/src/HYDROGUI/HYDROGUI_PriorityWidget.h b/src/HYDROGUI/HYDROGUI_PriorityWidget.h index bbc6c9ed..ff1cfc41 100644 --- a/src/HYDROGUI/HYDROGUI_PriorityWidget.h +++ b/src/HYDROGUI/HYDROGUI_PriorityWidget.h @@ -54,9 +54,14 @@ public: QTableView* getTable() const; + void undoLastChange(); + protected: void updateControls(); +signals: + void ruleChanged(); + protected slots: void onAddRule(); void onRemoveRule(); diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 381bc4c8..bd88bd54 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -401,6 +401,10 @@ All supported formats (*.brep *.iges *.igs *.step *.stp) ORDER_CHANGED Order of objects is changed + + RULE_CHANGED + Priority rule for objects is changed + CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS Case splitting zones already exist and will be recalculated after regions list modification. Do you confirm the recalculation?