From a6ab61e5fa3141b7efac4b1b408f599666420c54 Mon Sep 17 00:00:00 2001 From: mkr Date: Wed, 24 Jun 2015 15:54:09 +0300 Subject: [PATCH] refs #573: fix regression of saving resolved conflicts on zones constructed on geometry objects, separate assignment modes for regions constructed on geometry objects and land covers, update corresponding *.sip file. --- src/HYDROData/HYDROData_CalculationCase.cxx | 41 +++++++++++-- src/HYDROData/HYDROData_CalculationCase.h | 2 + src/HYDROGUI/HYDROGUI_CalculationOp.cxx | 64 +++++++++++++++------ src/HYDROGUI/HYDROGUI_CalculationOp.h | 1 + src/HYDROPy/HYDROData_CalculationCase.sip | 4 ++ 5 files changed, 89 insertions(+), 23 deletions(-) diff --git a/src/HYDROData/HYDROData_CalculationCase.cxx b/src/HYDROData/HYDROData_CalculationCase.cxx index 00474d50..8027835c 100644 --- a/src/HYDROData/HYDROData_CalculationCase.cxx +++ b/src/HYDROData/HYDROData_CalculationCase.cxx @@ -116,10 +116,14 @@ QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTre QString aCalculName = GetObjPyName(); - AssignmentMode aMode = GetAssignmentMode(); + AssignmentMode aMode = GetAssignmentMode(); QString aModeStr = aMode==MANUAL ? "HYDROData_CalculationCase.MANUAL" : "HYDROData_CalculationCase.AUTOMATIC"; aResList << QString( "%0.SetAssignmentMode( %1 )" ).arg( aCalculName ).arg( aModeStr ); + AssignmentMode aModeLC = GetAssignmentLandCoverMode(); + QString aModeLCStr = aModeLC==MANUAL ? "HYDROData_CalculationCase.MANUAL" : "HYDROData_CalculationCase.AUTOMATIC"; + aResList << QString( "%0.SetAssignmentLandCoverMode( %1 )" ).arg( aCalculName ).arg( aModeLCStr ); + HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects(); HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects ); for ( ; anIter.More(); anIter.Next() ) @@ -158,6 +162,8 @@ QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTre if( aMode==AUTOMATIC ) DumpRulesToPython( aCalculName, aResList ); + if( aModeLC==AUTOMATIC ) + DumpLandCoverRulesToPython( aCalculName, aResList ); aResList << QString( "" ); aResList << "# Start the algorithm of the partition and assignment"; @@ -167,7 +173,12 @@ QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTre { // Now we restore the // - regions and zones order - DumpRegionsToPython( aResList, theTreatedObjects, GetRegions( false ) ); + DumpRegionsToPython( aResList, theTreatedObjects, GetRegions( false ) ); + } + + if( aModeLC==MANUAL ) + { + // Now we restore the // - land cover regions and zones order DumpRegionsToPython( aResList, theTreatedObjects, GetRegions( true ) ); } @@ -308,14 +319,23 @@ void HYDROData_CalculationCase::Update() switch( GetAssignmentMode() ) { case MANUAL: - CreateRegionsDef( aDocument, aZonesList, false ); + CreateRegionsDef( aDocument, aZonesList, false ); + break; + case AUTOMATIC: + CreateRegionsAuto( aDocument, aZonesList, false ); + break; + } + + switch( GetAssignmentLandCoverMode() ) + { + case MANUAL: CreateRegionsDef( aDocument, aLandCoverZonesList, true ); break; case AUTOMATIC: - CreateRegionsAuto( aDocument, aZonesList, false ); CreateRegionsAuto( aDocument, aLandCoverZonesList, true ); break; } + CreateEdgeGroupsDef( aDocument, anEdgesList ); } @@ -1242,6 +1262,12 @@ QString HYDROData_CalculationCase::DumpRules() const return HYDROData_PriorityQueue::DumpRules( aRulesLab ); } +QString HYDROData_CalculationCase::DumpLandCoverRules() const +{ + TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomLandCoverRules ); + return HYDROData_PriorityQueue::DumpRules( aRulesLab ); +} + void HYDROData_CalculationCase::SetAssignmentMode( AssignmentMode theMode ) { TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentMode ); @@ -1268,6 +1294,13 @@ void HYDROData_CalculationCase::DumpRulesToPython( const QString& theCalcCaseNam HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript ); } +void HYDROData_CalculationCase::DumpLandCoverRulesToPython( const QString& theCalcCaseName, + QStringList& theScript ) const +{ + TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomLandCoverRules ); + HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript ); +} + HYDROData_Warning HYDROData_CalculationCase::GetLastWarning() const { return myLastWarning; diff --git a/src/HYDROData/HYDROData_CalculationCase.h b/src/HYDROData/HYDROData_CalculationCase.h index 70e925e7..0dd025ed 100644 --- a/src/HYDROData/HYDROData_CalculationCase.h +++ b/src/HYDROData/HYDROData_CalculationCase.h @@ -402,6 +402,7 @@ public: HYDRODATA_EXPORT AssignmentMode GetAssignmentLandCoverMode() const; HYDRODATA_EXPORT QString DumpRules() const; + HYDRODATA_EXPORT QString DumpLandCoverRules() const; HYDRODATA_EXPORT HYDROData_Warning GetLastWarning() const; @@ -446,6 +447,7 @@ private: const HYDROData_SplitToZonesTool::SplitDataList& theEdges ); void DumpRulesToPython( const QString& theCalcCaseName, QStringList& theScript ) const; + void DumpLandCoverRulesToPython( const QString& theCalcCaseName, QStringList& theScript ) const; void SetWarning( HYDROData_WarningType theType = WARN_OK, const QString& theData = "" ); diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx index 93528ff5..ef991cab 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx @@ -726,28 +726,52 @@ bool HYDROGUI_CalculationOp::confirmContinueWithWarning( const HYDROData_Warning return ( anAnswer == QMessageBox::Yes ); } +bool HYDROGUI_CalculationOp::confirmLandCoverRegionsChange() 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( "REGIONS_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::confirmLandCoverModeChange() 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 - // TODO: adapt HYDROData_CalculationCase class to process regions constructed for land covers - /*HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCoverRegions(); + // 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 zones then ask a user to confirm zones recalculation + { + // 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( "MODE_CHANGED" ), tr( "CONFIRM_LAND_COVER_PARTITION_RECALCULATION_MODE" ), QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) == QMessageBox::Yes ); - /*} + } else { - isConfirmed = true; // No regions - no zones - nothing to recalculate - }*/ + isConfirmed = true; // No regions - no land cover zones - nothing to recalculate + } } return isConfirmed; } @@ -758,22 +782,21 @@ bool HYDROGUI_CalculationOp::confirmLandCoverOrderChange() const bool isConfirmed = myEditedObject->IsMustBeUpdated(); if ( !isConfirmed ) { - // If not modified check if the case has already defined regions with zones - // TODO: adapt HYDROData_CalculationCase class to process regions constructed for land covers - /*HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCoverRegions(); + // 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 zones then ask a user to confirm zones recalculation + { + // 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( "ORDER_CHANGED" ), tr( "CONFIRM_LAND_COVER_PARTITION_RECALCULATION_REGIONS" ), QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) == QMessageBox::Yes ); - /*} + } else { - isConfirmed = true; // No regions - no zones - nothing to recalculate - }*/ + isConfirmed = true; // No regions - no land cover zones - nothing to recalculate + } } return isConfirmed; } @@ -907,8 +930,10 @@ void HYDROGUI_CalculationOp::onNext( const int theIndex ) } } aPanel->setStricklerTableNames( aList, anEntryList ); + bool anUpdateState = myEditedObject->IsMustBeUpdated(); if ( !aList.isEmpty() ) aPanel->setStricklerTable( aList.at( 0 ), false ); + myEditedObject->SetToUpdate( anUpdateState ); // Fill in list widget with all available land covers aSeq = HYDROGUI_Tool::GetLandCovers( module() ); @@ -1081,7 +1106,8 @@ void HYDROGUI_CalculationOp::onNext( const int theIndex ) if ( anIsToUpdate ) { myShowZones = true; - myEditedObject->Update(); + //myEditedObject->Update(); + myEditedObject->SetToUpdate( false ); AssignDefaultZonesColors( true ); @@ -1607,7 +1633,7 @@ void HYDROGUI_CalculationOp::onAddLandCovers() // Add land covers selected in the module browser to the calculation case QStringList aSelectedList = aPanel->getSelectedAvailableLandCovers(); - if ( aSelectedList.isEmpty() || !confirmRegionsChange() ) + if ( aSelectedList.isEmpty() || !confirmLandCoverRegionsChange() ) return; QStringList anAddedList; @@ -1638,7 +1664,7 @@ void HYDROGUI_CalculationOp::onRemoveLandCovers() return; QStringList aSelectedList = aPanel->getSelectedLandCovers(); - if ( aSelectedList.isEmpty() || !confirmRegionsChange() ) + if ( aSelectedList.isEmpty() || !confirmLandCoverRegionsChange() ) return; for (int i = 0; i < aSelectedList.length(); i++) diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.h b/src/HYDROGUI/HYDROGUI_CalculationOp.h index 4aa6485b..9d2dc0d1 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.h +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.h @@ -190,6 +190,7 @@ private: bool confirmOrderChange() const; bool confirmContinueWithWarning( const HYDROData_Warning& theWarning ) const; + bool confirmLandCoverRegionsChange() const; bool confirmLandCoverModeChange() const; bool confirmLandCoverOrderChange() const; diff --git a/src/HYDROPy/HYDROData_CalculationCase.sip b/src/HYDROPy/HYDROData_CalculationCase.sip index df0279af..d925944a 100644 --- a/src/HYDROPy/HYDROData_CalculationCase.sip +++ b/src/HYDROPy/HYDROData_CalculationCase.sip @@ -528,10 +528,14 @@ public: %End QString DumpRules(); + QString DumpLandCoverRules(); void SetAssignmentMode( AssignmentMode theMode ); AssignmentMode GetAssignmentMode() const; + void SetAssignmentLandCoverMode( AssignmentMode theMode ); + AssignmentMode GetAssignmentLandCoverMode() const; + protected: /** -- 2.39.2