myPreviewViewManager( NULL ),
myShowGeomObjects( true ),
myShowLandCovers( false ),
- myShowZones( false )
+ myShowZones( false ),
+ myUpdateLandCoverZonesPrs( false )
{
setName( myIsEdit ? tr( "EDIT_CALCULATION" ) : tr( "CREATE_CALCULATION" ) );
}
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* ) ) );
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
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 )
// 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 )
{
}
}
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() )
{
anIsToUpdateOb = true;
- myEditedObject->SetToUpdate( true );
+ myUpdateLandCoverZonesPrs = true;
}
else
{
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 );
closePreview( false );
createPreview( true );
- if ( !anIsToUpdate )
+ if ( myUpdateLandCoverZonesPrs )
+ myUpdateLandCoverZonesPrs = false;
+ else
{
// Hide zones
setZonesVisible( false, false );
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 );
+}
#include "HYDROGUI_PriorityTableModel.h"
#include <HYDROData_LandCover.h>
+#include <HYDROGUI_DataObject.h>
/**
Constructor.
}
bool aRes = false;
-
+
if ( theRole == Qt::EditRole ) {
+ bool aRuleChanged = false;
+ myPrevRules = myRules;
+
int aColumn = theIndex.column();
if ( aColumn == 0 || aColumn == 2 ) {
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;
}
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;
void HYDROGUI_PriorityTableModel::setRules( const HYDROData_ListOfRules& theRules )
{
beginResetModel();
+ myPrevRules = myRules;
myRules = theRules;
endResetModel();
}
{
myObjects = theObjects;
+ myPrevRules = myRules;
+
beginResetModel();
// Remove rules which use objects which are no longer available
aNewRule.Priority = aPriorityType;
aNewRule.MergeType = HYDROData_Zone::Merge_ZMIN;
+ myPrevRules = myRules;
+
beginResetModel();
myRules << aNewRule;
endResetModel();
aLastRow = myRules.count() - 1;
}
+ myPrevRules = myRules;
+
beginRemoveRows( theParent, theRow, aLastRow );
// Remove the corresponding rules
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.