]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Splitting data for calculation case edges (Feature #242).
authoradv <adv@opencascade.com>
Tue, 17 Dec 2013 08:02:11 +0000 (08:02 +0000)
committeradv <adv@opencascade.com>
Tue, 17 Dec 2013 08:02:11 +0000 (08:02 +0000)
src/HYDROData/CMakeLists.txt
src/HYDROData/HYDROData_CalculationCase.cxx
src/HYDROData/HYDROData_CalculationCase.h
src/HYDROData/HYDROData_Entity.h
src/HYDROData/HYDROData_Iterator.cxx
src/HYDROData/HYDROData_SplitToZonesTool.cxx
src/HYDROData/HYDROData_SplitToZonesTool.h
src/HYDROData/HYDROData_SplittedEdgesGroup.cxx [new file with mode: 0644]
src/HYDROData/HYDROData_SplittedEdgesGroup.h [new file with mode: 0644]

index a2a0ed56c42da12e64897ca461a361d028a770ca..3aa79d5613243b3836a97a176e4aca3d4ab38d2b 100644 (file)
@@ -32,6 +32,7 @@ set(PROJECT_HEADERS
     HYDROData_Projection.h
     HYDROData_Region.h
     HYDROData_River.h
+    HYDROData_SplittedEdgesGroup.h
     HYDROData_SplitToZonesTool.h
     HYDROData_Stream.h
     HYDROData_Tool.h
@@ -70,6 +71,7 @@ set(PROJECT_SOURCES
     HYDROData_Projection.cxx
     HYDROData_Region.cxx
     HYDROData_River.cxx
+    HYDROData_SplittedEdgesGroup.cxx
     HYDROData_SplitToZonesTool.cxx
     HYDROData_Stream.cxx
     HYDROData_Tool.cxx
index 64085eb597e5cac95e001e3a0096211e3d506ad3..220790056cd917e0ab50f1075a26aa4687d75218 100644 (file)
@@ -9,20 +9,25 @@
 #include "HYDROData_NaturalObject.h"
 #include "HYDROData_PolylineXY.h"
 #include "HYDROData_SplitToZonesTool.h"
+#include "HYDROData_SplittedEdgesGroup.h"
 #include "HYDROData_Region.h"
 #include "HYDROData_Tool.h"
 #include "HYDROData_Zone.h"
 
 #include <TopoDS.hxx>
 #include <TopoDS_Shell.hxx>
+#include <TopoDS_Edge.hxx>
+
 #include <BRep_Builder.hxx>
 #include <BRepBuilderAPI_Sewing.hxx>
+#include <BRepTopAdaptor_FClass2d.hxx>
+
+#include <TopAbs.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopExp.hxx>
 #include <TopTools_ListOfShape.hxx>
 #include <TopTools_ListIteratorOfListOfShape.hxx>
-#include <BRepTopAdaptor_FClass2d.hxx>
-#include <TopAbs.hxx>
+
 
 #define CALCULATION_REGIONS_PREF GetName() + "_Reg"
 #define CALCULATION_ZONES_PREF GetName() + "_Zone"
@@ -151,8 +156,9 @@ void HYDROData_CalculationCase::Update()
 {
   HYDROData_Entity::Update();
 
-  // At first we remove previously created regions
+  // At first we remove previously created objects
   RemoveRegions();
+  RemoveSplittedGroups();
 
   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
   if ( aDocument.IsNull() )
@@ -163,45 +169,73 @@ void HYDROData_CalculationCase::Update()
   if ( aGeomObjects.IsEmpty() )
     return;
 
-  HYDROData_SplitToZonesTool::SplitDataList aSplitedZones =
-    HYDROData_SplitToZonesTool::SplitToZones( aGeomObjects, aBoundaryPolyline );
-  if ( aSplitedZones.isEmpty() )
+  HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
+
+  HYDROData_SplitToZonesTool::SplitDataList aSplitedObjects =
+    HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline );
+  if ( aSplitedObjects.isEmpty() )
     return;
 
   QString aRegsPref = CALCULATION_REGIONS_PREF;
   QString aZonesPref = CALCULATION_ZONES_PREF;
 
+  QMap<QString,Handle(HYDROData_SplittedEdgesGroup)> aSplittedEdgesGroupsMap;
+
   // Create result regions for case, by default one zone for one region
-  HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitedZones );
+  HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitedObjects );
   while( anIter.hasNext() )
   {
     const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
 
-    // Create new region
-    Handle(HYDROData_Region) aRegion = addNewRegion();
+    if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
+    {
+      // Create new region
+      Handle(HYDROData_Region) aRegion = addNewRegion();
 
-    QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
-    aRegion->SetName( aRegionName );
+      QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
+      aRegion->SetName( aRegionName );
 
-    // Add the zone for region
-    Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone();
+      // Add the zone for region
+      Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone();
 
-    QString aZoneName = HYDROData_Tool::GenerateObjectName( aDocument, aZonesPref );
-    aRegionZone->SetName( aZoneName );
+      QString aZoneName = HYDROData_Tool::GenerateObjectName( aDocument, aZonesPref );
+      aRegionZone->SetName( aZoneName );
 
-    aRegionZone->SetShape( aSplitData.Face() );
+      aRegionZone->SetShape( aSplitData.Face() );
 
-    // Add the reference object for zone
-    for ( int i = 0, n = aSplitData.ObjectNames.length(); i < n; ++i )
+      // Add the reference object for zone
+      for ( int i = 0, n = aSplitData.ObjectNames.length(); i < n; ++i )
+      {
+        const QString& anObjName = aSplitData.ObjectNames.at( i );
+        
+        Handle(HYDROData_Object) aRefObject = Handle(HYDROData_Object)::DownCast(
+          HYDROData_Tool::FindObjectByName( aDocument, anObjName ) );
+        if ( aRefObject.IsNull() )
+          continue;
+
+        aRegionZone->AddGeometryObject( aRefObject );
+      }
+    }
+    else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge )
     {
-      const QString& anObjName = aSplitData.ObjectNames.at( i );
-      
-      Handle(HYDROData_Object) aRefObject = Handle(HYDROData_Object)::DownCast(
-        HYDROData_Tool::FindObjectByName( aDocument, anObjName ) );
-      if ( aRefObject.IsNull() )
+      // Create new edges group
+      if ( aSplitData.ObjectNames.isEmpty() || 
+           aSplitData.Shape.IsNull() || aSplitData.Shape.ShapeType() != TopAbs_EDGE )
+        continue;
+
+      QString anObjName = aSplitData.ObjectNames.first();
+      if ( anObjName.isEmpty() )
         continue;
 
-      aRegionZone->AddGeometryObject( aRefObject );
+      if ( !aSplittedEdgesGroupsMap.contains( anObjName ) )
+        aSplittedEdgesGroupsMap.insert( anObjName, addNewSplittedGroup() );
+
+      Handle(HYDROData_SplittedEdgesGroup) aSplittedGroup = aSplittedEdgesGroupsMap[ anObjName ];
+      if ( aSplittedGroup.IsNull() )
+        continue;
+
+      TopoDS_Edge anEdge = TopoDS::Edge( aSplitData.Shape );
+      aSplittedGroup->AddEdge( anEdge );
     }
   }
 }
@@ -416,19 +450,17 @@ void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& th
 
 void HYDROData_CalculationCase::RemoveRegions()
 {
-  ClearReferenceObjects( DataTag_Region );
-  myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes( true );
+  myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes();
 }
 
-Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion()
+HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplittedGroups() const
 {
-  TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild();
-
-  Handle(HYDROData_Region) aNewRegion =
-    Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
-  AddRegion( aNewRegion );
+  return GetReferenceObjects( DataTag_SplittedGroups );
+}
 
-  return aNewRegion;
+void HYDROData_CalculationCase::RemoveSplittedGroups()
+{
+  myLab.FindChild( DataTag_SplittedGroups ).ForgetAllAttributes();
 }
 
 TopoDS_Shell HYDROData_CalculationCase::GetShell()
@@ -663,6 +695,7 @@ Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY&
 
   return aResZone;
 }
+
 HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
   const gp_XY&                  thePoint,
   const Handle(HYDROData_Zone)& theZone ) const
@@ -685,3 +718,28 @@ HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPoi
     aRes =  POINT_ON;    
   return aRes;
 }
+
+Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion()
+{
+  TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild();
+
+  Handle(HYDROData_Region) aNewRegion =
+    Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
+  AddRegion( aNewRegion );
+
+  return aNewRegion;
+}
+
+Handle(HYDROData_SplittedEdgesGroup) HYDROData_CalculationCase::addNewSplittedGroup()
+{
+  TDF_Label aNewLab = myLab.FindChild( DataTag_SplittedGroups ).NewChild();
+
+  Handle(HYDROData_SplittedEdgesGroup) aNewGroup =
+    Handle(HYDROData_SplittedEdgesGroup)::DownCast( 
+      HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLITTED_GROUP ) );
+  AddReferenceObject( aNewGroup, DataTag_SplittedGroups );
+
+  return aNewGroup;
+}
+
+
index d3f6bcda7dad82250078ef9e6f8067fbcde6ecdf..eef8ea0b2ad04a10119b4a03a4931bfbd72f79f6 100644 (file)
@@ -14,6 +14,7 @@ class Handle(HYDROData_Region);
 class Handle(HYDROData_Zone);
 class Handle(HYDROData_PolylineXY);
 class Handle(HYDROData_EdgesGroup);
+class Handle(HYDROData_SplittedEdgesGroup);
 
 DEFINE_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity)
 
@@ -176,6 +177,18 @@ public:
    */
   HYDRODATA_EXPORT virtual void RemoveRegions();
 
+  
+  /**
+   * Returns all reference geometry groups of calculation case.
+   */
+  HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetSplittedGroups() const;
+
+  /**
+   * Removes all reference geometry groups from calculation case.
+   */
+  HYDRODATA_EXPORT virtual void RemoveSplittedGroups();
+
+
   /**
    * Returns shell containing faces which correspond to regions.
    * \return shell as TopoDS_Shell
@@ -218,6 +231,10 @@ private:
    */
   HYDRODATA_EXPORT virtual Handle(HYDROData_Region) addNewRegion();
 
+  /**
+   * Add new one splitted edges group for calculation case.
+   */
+  HYDRODATA_EXPORT virtual Handle(HYDROData_SplittedEdgesGroup) addNewSplittedGroup();
 
 protected:
 
index 00a91985f50da3d01f97825725337a909f007390..c1a5fccc16ecbc8d5f61ad8b30ba86719a29d93b 100644 (file)
@@ -43,7 +43,8 @@ const ObjectKind KIND_ARTIFICIAL_OBJECT = 19;
 const ObjectKind KIND_NATURAL_OBJECT    = 20;
 const ObjectKind KIND_DUMMY_3D          = 21;
 const ObjectKind KIND_EDGES_GROUP       = 22;
-const ObjectKind KIND_LAST              = KIND_EDGES_GROUP;
+const ObjectKind KIND_SPLITTED_GROUP    = 23;
+const ObjectKind KIND_LAST              = KIND_SPLITTED_GROUP;
 
 DEFINE_STANDARD_HANDLE(HYDROData_Entity, MMgt_TShared)
 
index f1dde62f1b67520606ec235e12bf5fa933df22b3..f0fa49b2b29bee41f13adbd125c7e210a65e2d7e 100644 (file)
@@ -19,6 +19,7 @@
 #include "HYDROData_VisualState.h"
 #include "HYDROData_Region.h"
 #include "HYDROData_River.h"
+#include "HYDROData_SplittedEdgesGroup.h"
 #include "HYDROData_Stream.h"
 #include "HYDROData_Zone.h"
 
@@ -126,6 +127,7 @@ Handle(HYDROData_Entity) HYDROData_Iterator::Object( const TDF_Label& theLabel )
     case KIND_VISUAL_STATE:     aResult = new HYDROData_VisualState();       break;
     case KIND_DUMMY_3D:         aResult = new HYDROData_DummyObject3D();     break;
     case KIND_EDGES_GROUP:      aResult = new HYDROData_EdgesGroup();        break;
+    case KIND_SPLITTED_GROUP:   aResult = new HYDROData_SplittedEdgesGroup();break;
     default:                                                                 break;
   }
 
index 9b279724a040996e7fa09b21da7cd82861812c62..a3fe087a0a4285d7f3b2790db9e4e579734ec4f5 100644 (file)
@@ -35,8 +35,9 @@ TopoDS_Face HYDROData_SplitToZonesTool::SplitData::Face() const
 }
 
 HYDROData_SplitToZonesTool::SplitDataList
-HYDROData_SplitToZonesTool::SplitToZones( const HYDROData_SequenceOfObjects& theObjectList,
-                                          const Handle(HYDROData_PolylineXY)&  thePolyline )
+  HYDROData_SplitToZonesTool::Split( const HYDROData_SequenceOfObjects&  theObjectList,
+                                     const HYDROData_SequenceOfObjects&  theGroupsList,
+                                     const Handle(HYDROData_PolylineXY)& thePolyline )
 {
   SplitDataList anOutputSplitDataList;
 
@@ -59,12 +60,12 @@ HYDROData_SplitToZonesTool::SplitToZones( const HYDROData_SequenceOfObjects& the
       for ( ; anExp.More(); anExp.Next() ) {
         TopoDS_Face aFace = TopoDS::Face( anExp.Current() );
         if ( !aFace.IsNull() ) {
-          SplitData aSplitData( aFace, aGeomObj->GetName() );
+          SplitData aSplitData( SplitData::Data_Zone, aFace, aGeomObj->GetName() );
           anInputSplitDataList.append( aSplitData );
         }
       }
     } else {
-      SplitData aSplitData( aShape, aGeomObj->GetName() );
+      SplitData aSplitData( SplitData::Data_Zone, aShape, aGeomObj->GetName() );
       anInputSplitDataList.append( aSplitData );
     }
   }
@@ -116,7 +117,7 @@ HYDROData_SplitToZonesTool::SplitToZones( const HYDROData_SequenceOfObjects& the
       aMakeFace.Build();
       if( aMakeFace.IsDone() )
       {
-        SplitData aBoundarySplitData( aMakeFace.Face(), "" );
+        SplitData aBoundarySplitData( SplitData::Data_Zone, aMakeFace.Face(), "" );
 
         SplitDataList aCutSplitDataList;
         SplitDataListIterator anOutputIter( anOutputSplitDataList );
@@ -173,9 +174,9 @@ bool HYDROData_SplitToZonesTool::SplitTwoData( const SplitData& theData1,
   BRepAlgoAPI_Cut aCut2( aShape2, aShape1 );
   TopoDS_Shape aCut2Shape = aCut2.Shape();
 
-  theData1Subtracted = SplitData( aCut1Shape, anObjectNames1 );
-  theData2Subtracted = SplitData( aCut2Shape, anObjectNames2 );
-  theDataIntersected = SplitData( aCommonShape, anObjectNames1 + anObjectNames2 );
+  theData1Subtracted = SplitData( SplitData::Data_Zone, aCut1Shape, anObjectNames1 );
+  theData2Subtracted = SplitData( SplitData::Data_Zone, aCut2Shape, anObjectNames2 );
+  theDataIntersected = SplitData( SplitData::Data_Zone, aCommonShape, anObjectNames1 + anObjectNames2 );
 
   return true;
 }
@@ -193,7 +194,7 @@ HYDROData_SplitToZonesTool::ExtractSeparateData( const SplitData& theData )
       TopoDS_Face aFace = TopoDS::Face( aShape );
       if( !aFace.IsNull() )
       {
-        SplitData aSplitData( aFace, theData.ObjectNames );
+        SplitData aSplitData( SplitData::Data_Zone, aFace, theData.ObjectNames );
         aSplitDataList.append( aSplitData );
       }
     }
index 4d7780f3ba882fbb1858e963d519a6e8573b850f..28413ef7ca122a4c7e41129b142efbcb3a4fba9d 100644 (file)
@@ -20,18 +20,29 @@ class HYDRODATA_EXPORT HYDROData_SplitToZonesTool
 public:
   struct HYDRODATA_EXPORT SplitData
   {
-    TopoDS_Shape Shape;
-    QStringList  ObjectNames;
-
-    SplitData() {}
+    enum SplitObjectType
+    {
+      Data_None,
+      Data_Zone,
+      Data_Edge
+    };
+
+    TopoDS_Shape    Shape;
+    QStringList     ObjectNames;
+    SplitObjectType Type;
+
+    SplitData() :
+     Type( Data_None ) {}
     
-    SplitData( const TopoDS_Shape& theShape,
-               const QStringList& theObjectNames ) :
-      Shape( theShape ), ObjectNames( theObjectNames ) {}
+    SplitData( const SplitObjectType& theType,
+               const TopoDS_Shape&    theShape,
+               const QStringList&     theObjectNames ) :
+      Type( theType ), Shape( theShape ), ObjectNames( theObjectNames ) {}
 
-    SplitData( const TopoDS_Shape& theShape,
-               const QString& theObjectNames ) :
-      Shape( theShape ), ObjectNames( theObjectNames ) {}
+    SplitData( const SplitObjectType& theType,
+               const TopoDS_Shape&    theShape,
+               const QString&         theObjectName ) :
+      Type( theType ), Shape( theShape ), ObjectNames( theObjectName ) {}
 
     TopoDS_Face Face() const;
   };
@@ -41,8 +52,9 @@ public:
 
 public:
 
-  static SplitDataList       SplitToZones( const HYDROData_SequenceOfObjects& theObjectList,
-                                           const Handle(HYDROData_PolylineXY)&  thePolyline );
+  static SplitDataList       Split( const HYDROData_SequenceOfObjects&  theObjectList,
+                                    const HYDROData_SequenceOfObjects&  theGroupsList,
+                                    const Handle(HYDROData_PolylineXY)& thePolyline );
 
 private:
 
diff --git a/src/HYDROData/HYDROData_SplittedEdgesGroup.cxx b/src/HYDROData/HYDROData_SplittedEdgesGroup.cxx
new file mode 100644 (file)
index 0000000..92a54e9
--- /dev/null
@@ -0,0 +1,16 @@
+
+#include "HYDROData_SplittedEdgesGroup.h"
+
+IMPLEMENT_STANDARD_HANDLE(HYDROData_SplittedEdgesGroup,HYDROData_EdgesGroup)
+IMPLEMENT_STANDARD_RTTIEXT(HYDROData_SplittedEdgesGroup,HYDROData_EdgesGroup)
+
+HYDROData_SplittedEdgesGroup::HYDROData_SplittedEdgesGroup()
+: HYDROData_EdgesGroup()
+{
+}
+
+HYDROData_SplittedEdgesGroup::~HYDROData_SplittedEdgesGroup()
+{
+}
+
+
diff --git a/src/HYDROData/HYDROData_SplittedEdgesGroup.h b/src/HYDROData/HYDROData_SplittedEdgesGroup.h
new file mode 100644 (file)
index 0000000..e62cadb
--- /dev/null
@@ -0,0 +1,49 @@
+
+#ifndef HYDROData_SplittedEdgesGroup_HeaderFile
+#define HYDROData_SplittedEdgesGroup_HeaderFile
+
+#include <HYDROData_EdgesGroup.h>
+
+DEFINE_STANDARD_HANDLE(HYDROData_SplittedEdgesGroup, HYDROData_EdgesGroup)
+
+
+/**\class HYDROData_SplittedEdgesGroup
+ * \brief The artificial objects are objects created or planned for creation by human.
+ *
+ */
+class HYDROData_SplittedEdgesGroup : public HYDROData_EdgesGroup
+{
+protected:
+  /**
+   * Enumeration of tags corresponding to the persistent object parameters.
+   */
+  enum DataTag
+  {
+    DataTag_First = HYDROData_EdgesGroup::DataTag_First + 100 ///< first tag, to reserve
+  };
+
+public:
+  DEFINE_STANDARD_RTTI(HYDROData_SplittedEdgesGroup);
+
+  /**
+   * Returns the kind of this object. Must be redefined in all objects of known type.
+   */
+  HYDRODATA_EXPORT virtual const ObjectKind GetKind() const { return KIND_SPLITTED_GROUP; }
+
+protected:
+
+  friend class HYDROData_Iterator;
+
+  /**
+   * Creates new object in the internal data structure. Use higher level objects 
+   * to create objects with real content.
+   */
+  HYDRODATA_EXPORT HYDROData_SplittedEdgesGroup();
+
+  /**
+   * Destructs properties of the object and object itself, removes it from the document.
+   */
+  virtual HYDRODATA_EXPORT ~HYDROData_SplittedEdgesGroup();
+};
+
+#endif