+void HYDROGUI_CalculationOp::onNext( const int theIndex )
+{
+ if( theIndex==1 )
+ {
+ setAvailableGroups();
+ }
+ else if( theIndex==2 )
+ {
+ // Land cover map panel
+ HYDROGUI_CalculationDlg* aPanel =
+ ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
+ if ( !aPanel )
+ return;
+
+ setLandCoverMapVisible( true );
+
+ QStringList aList;
+ QStringList anEntryList;
+
+ // Get all land cover map objects to fill in combo-box
+ Handle(HYDROData_LandCoverMap) aLandCoverMapObj;
+ QString aLandCoverMapName;
+
+ aList.clear();
+ anEntryList.clear();
+ HYDROData_Iterator anIter( doc(), KIND_LAND_COVER_MAP );
+ for ( ; anIter.More(); anIter.Next() )
+ {
+ aLandCoverMapObj = Handle(HYDROData_LandCoverMap)::DownCast( anIter.Current() );
+
+ if ( !aLandCoverMapObj.IsNull() )
+ {
+ aLandCoverMapName = aLandCoverMapObj->GetName();
+ if ( !aLandCoverMapName.isEmpty() )
+ {
+ aList.append( aLandCoverMapName );
+ anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aLandCoverMapObj ) );
+ }
+ }
+ }
+ aPanel->setLandCoverMapsNames( aList, anEntryList );
+ aLandCoverMapObj = myEditedObject->GetLandCoverMap();
+ if ( !aList.isEmpty() )
+ {
+ if ( aLandCoverMapObj.IsNull() )
+ aPanel->setLandCoverMap( aList.at( 0 ), false );
+ else if ( myIsEdit )
+ aPanel->setLandCoverMap( aList.at( 0 ), true );
+ else
+ aPanel->setLandCoverMap( aList.at( aList.indexOf( aLandCoverMapObj->GetName() ) ), true );
+ }
+
+ // Get all Strickler table objects to fill in combo-box
+ Handle(HYDROData_StricklerTable) aStricklerTableObj;
+ QString aStricklerTableName;
+
+ aList.clear();
+ anEntryList.clear();
+ anIter = HYDROData_Iterator( doc(), KIND_STRICKLER_TABLE );
+ for ( ; anIter.More(); anIter.Next() )
+ {
+ aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( anIter.Current() );
+
+ if ( !aStricklerTableObj.IsNull() )
+ {
+ aStricklerTableName = aStricklerTableObj->GetName();
+ if ( !aStricklerTableName.isEmpty() )
+ {
+ aList.append( aStricklerTableName );
+ anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aStricklerTableObj ) );
+ }
+ }
+ }
+ aPanel->setStricklerTableNames( aList, anEntryList );
+ //@ASL: bool anUpdateState = myEditedObject->IsMustBeUpdated();
+ if ( !aList.isEmpty() )
+ aPanel->setStricklerTable( aList.at( 0 ), false );
+ //@ASL: myEditedObject->SetToUpdate( anUpdateState );
+
+ if ( !myEditedObject.IsNull() )
+ {
+ if ( myIsEdit )
+ {
+ // Select the certain Strickler table object in combo-box
+ aStricklerTableObj = myEditedObject->GetStricklerTable();
+ if ( aStricklerTableObj.IsNull() )
+ {
+ aPanel->setStricklerTable( QString() );
+ }
+ else
+ {
+ aStricklerTableName = aStricklerTableObj->GetName();
+ aPanel->setStricklerTable( aStricklerTableName );
+ }
+
+ // Select the certain land cover map object in combo-box
+ if ( aLandCoverMapObj.IsNull() )
+ {
+ aPanel->setLandCoverMap( QString() );
+ }
+ else
+ {
+ aLandCoverMapName = aLandCoverMapObj->GetName();
+ aPanel->setLandCoverMap( aLandCoverMapName );
+ }
+ }
+ }
+
+ closePreview( false );
+ createPreview( true );
+ }
+ else if( theIndex==3 )
+ {
+ HYDROGUI_CalculationDlg* aPanel =
+ ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
+ if ( !aPanel )
+ return;
+
+ QApplication::setOverrideCursor( Qt::WaitCursor );
+
+ setGeomObjectsVisible( false );
+ setLandCoverMapVisible( false );
+
+ QString aNewCaseName = aPanel->getObjectName();
+ QString anOldCaseName = myEditedObject->GetName();
+ bool isNameChanged = anOldCaseName != aNewCaseName;
+
+ bool anIsToUpdateOb = isNameChanged;
+
+ // At first we must to update the case name because of
+ // automatic names generation for regions and zones
+ myEditedObject->SetName( aNewCaseName );
+
+ // Zones: set parameters for automatic mode
+ int aMode = aPanel->getMode();
+ if ( aMode == HYDROData_CalculationCase::AUTOMATIC )
+ {
+ // Set objects in the specified order
+ if( myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d ) )
+ {
+ myEditedObject->RemoveGeometryObjects();
+ foreach ( const QString& aName, aPanel->getAllGeomObjects() )
+ {
+ Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
+ HYDROGUI_Tool::FindObjectByName( module(), aName ) );
+ if ( anObject.IsNull() )
+ {
+ continue;
+ }
+ myEditedObject->AddGeometryObject( anObject );
+ }
+
+ // Clear priority rules
+ //@ASL if ( myEditedObject->GetRulesCount() > 0 ) {
+ myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, true );
+ //@ASL }
+ // Set priority rules
+ foreach ( const HYDROData_CustomRule& aRule, aPanel->getRules() ) {
+ myEditedObject->AddRule( aRule.Object1, aRule.Priority,
+ aRule.Object2, aRule.MergeType,
+ HYDROData_CalculationCase::DataTag_CustomRules );
+ }
+ }
+ }
+ aPanel->setEditZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
+
+ if ( myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_All ) )
+ {
+ myShowZones = true;
+ myEditedObject->Update();
+
+ AssignDefaultZonesColors();
+
+ //aPanel->setEditedObject( myEditedObject );
+ aPanel->refreshZonesBrowser();
+
+ closePreview( false );
+ createPreview( false );
+
+ anIsToUpdateOb = true;
+ }
+ else
+ {
+ // Show zones
+ setZonesVisible( true );
+
+ if ( isNameChanged ) {
+ module()->getDataModel()->updateObjectTree( myEditedObject );
+ }
+ }
+
+ QApplication::restoreOverrideCursor();
+ }
+}
+
+void HYDROGUI_CalculationOp::onHideZones( const int theIndex )
+{
+ if( theIndex==1 )
+ {
+ setGeomObjectsVisible( true );
+
+ closePreview( false );
+ createPreview( false );
+ }
+ if( theIndex==2 )
+ {
+ setLandCoverMapVisible( true );
+
+ closePreview( false );
+ createPreview( true );
+
+ // Hide zones
+ setZonesVisible( false );
+ }
+ else if( theIndex==3 )
+ {
+ AssignDefaultZonesColors();
+
+ closePreview( false );
+ createPreview( false );
+
+ // Show zones
+ setZonesVisible( true );
+ }
+}
+
+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::setGeomObjectsVisible( bool theIsVisible )
+{
+ myShowGeomObjects = theIsVisible;
+
+ HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
+
+ HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
+ for ( ; anIter.More(); anIter.Next() ) {
+ setObjectVisibility( anIter.Value(), theIsVisible );
+ }
+}
+
+void HYDROGUI_CalculationOp::setLandCoverMapVisible( bool theIsVisible )
+{
+ myShowLandCoverMap = theIsVisible;
+ setObjectVisibility( myEditedObject->GetLandCoverMap(), theIsVisible );
+}
+
+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 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 : Qt::darkBlue );
+}
+
+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::MergeType 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 );
+}
+
+bool HYDROGUI_CalculationOp::createRegion( const QList<SUIT_DataObject*>& theZonesList )
+{
+ bool aRetValue = false;
+
+ QList<HYDROGUI_Zone*> aZonesList;
+ HYDROGUI_Zone* aZone;
+ // Get a list of dropped zones
+ for ( int i = 0; i < theZonesList.length(); i++ )
+ {
+ aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
+ if ( aZone )
+ {
+ aZonesList.append( aZone );
+ }
+ }
+ if ( aZonesList.length() > 0 )
+ {
+ module()->getDataModel()->createNewRegion( myEditedObject, aZonesList );
+ aRetValue = true;
+ }
+
+ return aRetValue;
+}
+
+void HYDROGUI_CalculationOp::createPreview( const bool theLandCoverMap )