]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
assignment mode + dump rules to Python
authorasl <asl@opencascade.com>
Tue, 14 Oct 2014 05:17:09 +0000 (05:17 +0000)
committerasl <asl@opencascade.com>
Tue, 14 Oct 2014 05:17:09 +0000 (05:17 +0000)
src/HYDROData/HYDROData_CalculationCase.cxx
src/HYDROData/HYDROData_CalculationCase.h
src/HYDROData/HYDROData_PriorityQueue.cxx
src/HYDROData/HYDROData_PriorityQueue.h
src/HYDROPy/HYDROData_CalculationCase.sip

index d878012a0648cbfb234971188654c6db0cf66a92..1cfa75e3e70dea8a318d21fa55dc8d3202b0c64f 100644 (file)
@@ -31,6 +31,7 @@
 #include <TopExp.hxx>
 #include <TopTools_ListOfShape.hxx>
 #include <TopTools_ListIteratorOfListOfShape.hxx>
+#include <TDataStd_Integer.hxx>
 
 //#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 );
+}
index 4eb2ee1d804f51ab9e65b58154d132ffa8b22095..e851eaa3685355efc22da818014e510e6ce28303 100644 (file)
@@ -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;
 
index fd72c219ea6de35d279920a5a8685f387f77e63e..e3c5a133a680af460763d85a3f537ea4094c1a6e 100644 (file)
@@ -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;
+  }
+}
index 314f455b6a58b7492f37774ca7de1c072ddcd95e..bb11ef63a1b02a5a7e86c640e78f67c47e9c1f9c 100644 (file)
@@ -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<QString, Handle(HYDROData_Object)> MapNameToObject;
index 5b7c7f2ce97297644332904975566cd1a804c811..fc09eeb1b535a23e9cb92729c517e58e7fa46fbc 100644 (file)
@@ -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:
 
   /**