+ //aPanel->setEditedObject( myEditedObject );
+ aPanel->refreshZonesBrowser();
+
+ closePreview();
+ createPreview();
+
+ anIsToUpdateOb = true;
+
+ myEditedObject->SetToUpdate( true );
+ }
+ else
+ {
+ setZonesVisible( true );
+
+ if ( isNameChanged ) {
+ module()->getDataModel()->updateObjectTree( myEditedObject );
+ }
+ }
+
+ // Move this code to processing od the last panel (see below)
+ if ( anIsToUpdateOb ) {
+ SUIT_DataBrowser* anObjBrowser = ((LightApp_Application*)module()->application())->objectBrowser();
+ if ( anObjBrowser ) {
+ anObjBrowser->updateTree( module()->getDataModel()->getDataObject( myEditedObject ), false );
+ }
+ }
+
+ QApplication::restoreOverrideCursor();
+ }
+ else if( theIndex==4 )
+ {
+ // Partition of Land covers panel
+ HYDROGUI_CalculationDlg* aPanel =
+ ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
+ if ( !aPanel )
+ return;
+
+ 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->setEditLandCoversEnabled( aMode == HYDROData_CalculationCase::MANUAL );
+
+ QApplication::restoreOverrideCursor();
+ }
+}
+
+void HYDROGUI_CalculationOp::onHideZones()
+{
+ setZonesVisible( false );
+}
+
+void HYDROGUI_CalculationOp::setZonesVisible( bool theIsVisible )
+{
+ myShowZones = theIsVisible;
+ HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
+ HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
+ HYDROData_SequenceOfObjects aZones;
+ Handle(HYDROData_Region) aRegion;
+ if ( myPreviewViewManager )
+ {
+ if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
+ {
+ Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
+ if ( !aCtx.IsNull() )
+ {
+ for ( ; aRegionsIter.More(); aRegionsIter.Next() )
+ {
+ aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
+ if ( !aRegion.IsNull() )
+ {
+ aZones = aRegion->GetZones();
+ HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
+ for ( ; aZonesIter.More(); aZonesIter.Next() )
+ {
+ setObjectVisibility( aZonesIter.Value(), theIsVisible );
+ }
+ }
+ }
+ }
+
+ module()->update( UF_OCCViewer );
+ }
+ }
+}
+
+void HYDROGUI_CalculationOp::AssignDefaultZonesColors()
+{
+ HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
+ HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
+ HYDROData_SequenceOfObjects aZones;
+ Handle(HYDROData_Region) aRegion;
+ if ( myPreviewViewManager )
+ {
+ if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
+ {
+ Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
+ if ( !aCtx.IsNull() )
+ {
+ int aCounter = 0;
+ for ( ; aRegionsIter.More(); aRegionsIter.Next() )
+ {
+ aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
+ if ( !aRegion.IsNull() )
+ {
+ aZones = aRegion->GetZones();
+ HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
+ for ( ; aZonesIter.More(); aZonesIter.Next() )
+ {
+ // Zone
+ Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
+ if ( !aZone.IsNull() )
+ {
+ QColor aFillingColor = GenerateDefaultZonesColor(++aCounter);
+ while (aFillingColor == Qt::red)
+ aFillingColor = GenerateDefaultZonesColor(++aCounter);
+
+ aZone->SetColor(aFillingColor);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+QColor HYDROGUI_CalculationOp::GenerateDefaultZonesColor( int theIndex,
+ float theSaturation/* = 0.5*/,
+ float theValue/* = 0.95*/ ) const
+{
+ float aGoldenRatioConjugate = (float)(360./582.);
+ float aHue = (float)rand();
+ 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.) );
+ return ( aColor.isValid() ? aColor : HYDROData_ImmersibleZone::DefaultFillingColor() );
+}
+
+void HYDROGUI_CalculationOp::setRules( HYDROData_CalculationCase::DataTag theDataTag )
+{
+ HYDROGUI_CalculationDlg* aPanel =
+ ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
+ if ( !aPanel )
+ return;
+
+ HYDROData_ListOfRules aRules;
+ Handle(HYDROData_Entity) anObject1, anObject2;
+ HYDROData_PriorityType aPriority;
+ HYDROData_Zone::MergeAltitudesType aMergeType;
+ HYDROData_CalculationCase::DataTag aDataTag = HYDROData_CalculationCase::DataTag_CustomRules;
+ for ( int anIndex = 0; ; anIndex++ )
+ {
+ if ( myEditedObject->GetRule( anIndex, anObject1, aPriority, anObject2, aMergeType, theDataTag ) ) {
+ HYDROData_CustomRule aRule;
+ aRule.Object1 = anObject1;
+ aRule.Object2 = anObject2;
+ aRule.Priority = aPriority;
+ aRule.MergeType = aMergeType;
+
+ aRules << aRule;
+ }
+ else
+ break;
+ }
+
+ if ( theDataTag == HYDROData_CalculationCase::DataTag_CustomRules )
+ aPanel->setRules( aRules );
+ else if ( theDataTag == HYDROData_CalculationCase::DataTag_CustomLandCoverRules )
+ aPanel->setLandCoverRules( aRules );