From f17efc89ee19de46802d511d84cce537fcfa71a1 Mon Sep 17 00:00:00 2001 From: asl Date: Tue, 14 Oct 2014 05:17:09 +0000 Subject: [PATCH] assignment mode + dump rules to Python --- src/HYDROData/HYDROData_CalculationCase.cxx | 84 +++++++++++++++------ src/HYDROData/HYDROData_CalculationCase.h | 12 +++ src/HYDROData/HYDROData_PriorityQueue.cxx | 36 +++++++++ src/HYDROData/HYDROData_PriorityQueue.h | 3 + src/HYDROPy/HYDROData_CalculationCase.sip | 9 +++ 5 files changed, 123 insertions(+), 21 deletions(-) diff --git a/src/HYDROData/HYDROData_CalculationCase.cxx b/src/HYDROData/HYDROData_CalculationCase.cxx index d878012a..1cfa75e3 100644 --- a/src/HYDROData/HYDROData_CalculationCase.cxx +++ b/src/HYDROData/HYDROData_CalculationCase.cxx @@ -31,6 +31,7 @@ #include #include #include +#include //#define DEB_CALCULATION 1 #ifdef DEB_CALCULATION @@ -112,6 +113,10 @@ QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTre QString aCalculName = GetObjPyName(); + AssignmentMode aMode = GetAssignmentMode(); + QString aModeStr = aMode==MANUAL ? "MANUAL" : "AUTOMATIC"; + aResList << QString( "%0.SetAssignmentMode( %1 )" ).arg( aCalculName ).arg( aModeStr ); + HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects(); HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects ); for ( ; anIter.More(); anIter.Next() ) @@ -150,35 +155,42 @@ QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTre setPythonReferenceObject( theTreatedObjects, aResList, aBoundaryPolyline, "SetBoundaryPolyline" ); aResList << QString( "" ); + if( aMode==AUTOMATIC ) + DumpRulesToPython( aCalculName, aResList ); + + aResList << QString( "" ); aResList << QString( "%1.Update();" ).arg( aCalculName ); aResList << QString( "" ); - // Now we restore the regions and zones order - HYDROData_SequenceOfObjects aRegions = GetRegions(); - anIter.Init( aRegions ); - for ( ; anIter.More(); anIter.Next() ) + if( aMode==MANUAL ) { - Handle(HYDROData_Region) aRegion = - Handle(HYDROData_Region)::DownCast( anIter.Value() ); - if ( aRegion.IsNull() ) - continue; - - QString aRegionName = aRegion->GetName(); - - HYDROData_SequenceOfObjects aZones = aRegion->GetZones(); - HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones ); - for ( ; aZonesIter.More(); aZonesIter.Next() ) + // Now we restore the regions and zones order + HYDROData_SequenceOfObjects aRegions = GetRegions(); + anIter.Init( aRegions ); + for ( ; anIter.More(); anIter.Next() ) { - Handle(HYDROData_Zone) aRegZone = - Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() ); - if ( aRegZone.IsNull() ) + Handle(HYDROData_Region) aRegion = + Handle(HYDROData_Region)::DownCast( anIter.Value() ); + if ( aRegion.IsNull() ) continue; - // TODO + QString aRegionName = aRegion->GetName(); + + HYDROData_SequenceOfObjects aZones = aRegion->GetZones(); + HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones ); + for ( ; aZonesIter.More(); aZonesIter.Next() ) + { + Handle(HYDROData_Zone) aRegZone = + Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() ); + if ( aRegZone.IsNull() ) + continue; + + // TODO + } } } - aResList << QString( "" ); + aResList << QString( "" ); return aResList; } @@ -232,8 +244,15 @@ void HYDROData_CalculationCase::Update() anEdgesList.append( aSplitData ); } - //CreateRegionsDef( aDocument, aZonesList ); - CreateRegionsAuto( aDocument, aZonesList ); + switch( GetAssignmentMode() ) + { + case MANUAL: + CreateRegionsDef( aDocument, aZonesList ); + break; + case AUTOMATIC: + CreateRegionsAuto( aDocument, aZonesList ); + break; + } CreateEdgeGroupsDef( aDocument, anEdgesList ); } @@ -1065,3 +1084,26 @@ QString HYDROData_CalculationCase::DumpRules() TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules ); return HYDROData_PriorityQueue::DumpRules( aRulesLab ); } + +void HYDROData_CalculationCase::SetAssignmentMode( AssignmentMode theMode ) +{ + TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentMode ); + TDataStd_Integer::Set( aModeLab, ( int ) theMode ); +} + +HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentMode() const +{ + Handle(TDataStd_Integer) aModeAttr; + bool isOK = myLab.FindChild( DataTag_AssignmentMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr ); + if( isOK ) + return ( AssignmentMode ) aModeAttr->Get(); + else + return MANUAL; +} + +void HYDROData_CalculationCase::DumpRulesToPython( const QString& theCalcCaseName, + QStringList& theScript ) const +{ + TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules ); + HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript ); +} diff --git a/src/HYDROData/HYDROData_CalculationCase.h b/src/HYDROData/HYDROData_CalculationCase.h index 4eb2ee1d..e851eaa3 100644 --- a/src/HYDROData/HYDROData_CalculationCase.h +++ b/src/HYDROData/HYDROData_CalculationCase.h @@ -44,6 +44,12 @@ public: POINT_ON ///< point is on the edge of zone face }; + enum AssignmentMode + { + MANUAL = 0, + AUTOMATIC, + }; + public: /** @@ -59,6 +65,7 @@ public: DataTag_GeometryGroup, ///< reference geometry groups DataTag_SplittedGroups, ///< reference splitted groups DataTag_CustomRules, ///< custom rules + DataTag_AssignmentMode, ///< assignment mode }; public: @@ -281,6 +288,9 @@ public: const gp_XY& thePoint, const Handle(HYDROData_Zone)& theZone ) const; + HYDRODATA_EXPORT void SetAssignmentMode( AssignmentMode theMode ); + HYDRODATA_EXPORT AssignmentMode GetAssignmentMode() const; + HYDRODATA_EXPORT void ClearRules(); HYDRODATA_EXPORT void AddRule( const Handle(HYDROData_Object)& theObject1, HYDROData_PriorityType thePriority, @@ -338,6 +348,8 @@ private: void CreateEdgeGroupsDef( const Handle(HYDROData_Document)& theDoc, const HYDROData_SplitToZonesTool::SplitDataList& theEdges ); + void DumpRulesToPython( const QString& theCalcCaseName, QStringList& theScript ) const; + protected: friend class HYDROData_Iterator; diff --git a/src/HYDROData/HYDROData_PriorityQueue.cxx b/src/HYDROData/HYDROData_PriorityQueue.cxx index fd72c219..e3c5a133 100644 --- a/src/HYDROData/HYDROData_PriorityQueue.cxx +++ b/src/HYDROData/HYDROData_PriorityQueue.cxx @@ -180,3 +180,39 @@ QString HYDROData_PriorityQueue::DumpRules( const TDF_Label& theRulesLab ) } return aDump; } + +void HYDROData_PriorityQueue::DumpRulesToPython( const TDF_Label& theRulesLab, + const QString& theCalcCaseName, + QStringList& theScript ) +{ + HYDROData_ListOfRules aRules = GetRules( theRulesLab ); + HYDROData_ListOfRules::const_iterator anIt = aRules.begin(), aLast = aRules.end(); + for( ; anIt!=aLast; anIt++ ) + { + QString anObj1 = anIt->Object1->GetObjPyName(); + QString anObj2 = anIt->Object2->GetObjPyName(); + QString aPriority = anIt->Priority == LESS ? "LESS" : "GREATER"; + QString aMergeType; + + switch( anIt->MergeType ) + { + case HYDROData_Zone::Merge_UNKNOWN: + aMergeType = "Merge_UNKNOWN"; + break; + case HYDROData_Zone::Merge_ZMIN: + aMergeType = "Merge_ZMIN"; + break; + case HYDROData_Zone::Merge_ZMAX: + aMergeType = "Merge_ZMAX"; + break; + case HYDROData_Zone::Merge_Object: + aMergeType = "Merge_Object"; + break; + } + + QString aRule = QString( "%0.AddRule( %1, %2, %3, %4 )" ). + arg( theCalcCaseName ).arg( anObj1 ).arg( aPriority ).arg( anObj2 ).arg( aMergeType ); + + theScript << aRule; + } +} diff --git a/src/HYDROData/HYDROData_PriorityQueue.h b/src/HYDROData/HYDROData_PriorityQueue.h index 314f455b..bb11ef63 100644 --- a/src/HYDROData/HYDROData_PriorityQueue.h +++ b/src/HYDROData/HYDROData_PriorityQueue.h @@ -45,6 +45,9 @@ public: HYDROData_Zone::MergeAltitudesType theMergeType ); static HYDROData_ListOfRules GetRules( const TDF_Label& theRulesLabel ); static QString DumpRules( const TDF_Label& theRulesLab ); + static void DumpRulesToPython( const TDF_Label& theRulesLab, + const QString& theCalcCaseName, + QStringList& theScript ); private: typedef QMap MapNameToObject; diff --git a/src/HYDROPy/HYDROData_CalculationCase.sip b/src/HYDROPy/HYDROData_CalculationCase.sip index 5b7c7f2c..fc09eeb1 100644 --- a/src/HYDROPy/HYDROData_CalculationCase.sip +++ b/src/HYDROPy/HYDROData_CalculationCase.sip @@ -60,6 +60,12 @@ public: POINT_ON ///< point is on the edge of zone face }; + enum AssignmentMode + { + MANUAL = 0, + AUTOMATIC, + }; + public: /** * Add new one reference geometry object for calculation case. @@ -501,6 +507,9 @@ public: QString DumpRules(); + void SetAssignmentMode( AssignmentMode theMode ); + AssignmentMode GetAssignmentMode() const; + protected: /** -- 2.39.2