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* ) ) );
connect( aPanel, SIGNAL( StricklerTableSelected( const QString & ) ),
SLOT( onStricklerTableSelected( const QString & ) ) );
+ connect( aPanel, SIGNAL( regenerateColors() ), this,
+ SLOT( onRegenerateColors() ) );
+
return aPanel;
}
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 );
float theSaturation/* = 0.5*/,
float theValue/* = 0.95*/ ) const
{
- float aGoldenRatioConjugate = (float)(360./582.);
- float aHue = (float)(rand()%100);
- aHue += aGoldenRatioConjugate*theIndex;
- aHue -= floor(aHue);
-
- float aR = 0., aG = 0., aB = 0.;
- int aHueInt = (int)(aHue*6.);
- float aF = aHue*6. - aHueInt;
- float aP = theValue * (1. - theSaturation);
- float aQ = theValue * (1. - aF*theSaturation);
- float aT = theValue * (1. - (1. - aF) * theSaturation);
- switch (aHueInt)
- {
- case 0: { aR = theValue; aG = aT; aB = aP; break; }
- case 1: { aR = aQ; aG = theValue; aB = aP; break; }
- case 2: { aR = aP; aG = theValue; aB = aT; break; }
- case 3: { aR = aP; aG = aQ; aB = theValue; break; }
- case 4: { aR = aT; aG = aP; aB = theValue; break; }
- case 5: { aR = theValue; aG = aP; aB = aQ; break; }
- default: break;
- }
-
- QColor aColor = QColor( (int)(aR*256.), (int)(aG*256.), (int)(aB*256.) );
+ float aHue = ( rand()%1000 ) * 0.001f;
+
+ QColor aColor;
+ aColor.setHsl( (int)(aHue*255.), 128, 128 );
+ int r = aColor.red();
+ int g = aColor.green();
+ int b = aColor.blue();
return ( aColor.isValid() ? aColor : HYDROData_ImmersibleZone::DefaultFillingColor() );
}
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 );
+}
+
+void HYDROGUI_CalculationOp::onRegenerateColors()
+{
+ // For geometry zones
+ AssignDefaultZonesColors( false );
+ setZonesVisible( false, false );
+ setZonesVisible( true, false );
+}