Salome HOME
Merge branch 'BR_MULTI_BATHS' into HEAD
[modules/hydro.git] / src / HYDROData / HYDROData_SplitToZonesTool.cxx
index ba3359c295842b39e27564f0de103373f189e50a..e5a1d8428aa7d3b87393a9bd3eb1f5e7eb896f5c 100644 (file)
@@ -40,6 +40,9 @@
 #include <Geom_Plane.hxx>
 #include <BRepBuilderAPI_FindPlane.hxx>
 
+#include <BOPAlgo_BOP.hxx>
+#include <BOPAlgo_Builder.hxx>
+
 //#define DEB_SPLIT_TO_ZONES 1
 //#define DEB_SPLIT_TO_ZONES_CHECK_PARTITION 1
 #if (defined (DEB_SPLIT_TO_ZONES) || defined(DEB_SPLIT_TO_ZONES_CHECK_PARTITION))
@@ -130,7 +133,8 @@ Standard_Integer HYDROData_SplitToZonesTool::SplitFaces(const TopoDS_Compound& t
 HYDROData_SplitToZonesTool::SplitDataList
   HYDROData_SplitToZonesTool::Split( const HYDROData_SequenceOfObjects&  theObjectList,
                                      const HYDROData_SequenceOfObjects&  theGroupsList,
-                                     const Handle(HYDROData_PolylineXY)& thePolyline )
+                                     const Handle(HYDROData_PolylineXY)& thePolyline,
+                                     const HYDROData_SequenceOfObjects& InterPolys)
 {
   DEBTRACE("Split");
   SplitDataList anOutputSplitDataList;
@@ -547,6 +551,9 @@ HYDROData_SplitToZonesTool::SplitDataList
       }
     }
   }
+
+  AddInternalEdges(aDM2, InterPolys);
+
   // Step 4. Fill output structure.
 #ifdef DEB_SPLIT_TO_ZONES
   TCollection_AsciiString aNam4 ("SC_");
@@ -609,6 +616,78 @@ HYDROData_SplitToZonesTool::SplitDataList
 {
   HYDROData_SequenceOfObjects aGeomGroups;
   Handle(HYDROData_PolylineXY) aPolyline;
+  HYDROData_SequenceOfObjects InterPolys;
+
+  return Split( theObjectList, aGeomGroups, aPolyline, InterPolys );
+}
+
+void HYDROData_SplitToZonesTool::AddInternalEdges(HYDROData_DataMapOfShapeListOfShape& DM,
+   const HYDROData_SequenceOfObjects& thePolylines)
+{
+
+  HYDROData_SequenceOfObjects::Iterator it(thePolylines);
+  TopTools_ListOfShape Wires;
+  for (;it.More();it.Next())
+  {
+    Handle(HYDROData_PolylineXY) P = Handle(HYDROData_PolylineXY)::DownCast(it.Value());
+    Wires.Append(P->GetShape());
+    //Handle(TopTools_HSequenceOfShape) aConnectedWires = new TopTools_HSequenceOfShape;
+    //if (P->GetNbConnectedWires(aConnectedWires) > 0)
+    //  Wires.Append(aConnectedWires->Value(1));
+  }
+
+  HYDROData_DataMapOfShapeListOfShape newDM;
+
+  for (int i = 1; i <= DM.Extent();i++)
+  {
+    const TopoDS_Shape& K = DM.FindKey(i);
+    const TopTools_ListOfShape& V = DM.FindFromIndex(i);
+    TopTools_ListOfShape out;
+    if (K.ShapeType() == TopAbs_FACE)
+    {
+      CutByEdges(K, Wires, out);
+      TopTools_ListIteratorOfListOfShape it(out);
+      for (;it.More(); it.Next())
+      {
+        const TopoDS_Shape& NF = it.Value();
+        if (!NF.IsNull())
+          newDM.Add(NF, V);
+      }
+    }
+    else
+      newDM.Add(K, V); // ignore edges, wires...
+  }
+
+  DM = newDM;
+}
+
+
+int HYDROData_SplitToZonesTool::CutByEdges(const TopoDS_Shape& InSh, const TopTools_ListOfShape& InEdges,
+  TopTools_ListOfShape& outShs)
+{
+  int anError;
+  if (InSh.IsNull())
+    return -1;
+  if (InEdges.IsEmpty())
+  {
+    outShs.Clear();
+    outShs.Append(InSh);
+    return 0;
+  }
+  TopTools_ListIteratorOfListOfShape anIt;
+  BOPAlgo_Builder anAlgo;
+  anAlgo.AddArgument(InSh);
+  anIt.Initialize( InEdges );
+  for( ; anIt.More(); anIt.Next() )
+    anAlgo.AddArgument( anIt.Value() );
+
+  anAlgo.Perform(); 
+  anError = anAlgo.ErrorStatus();
+  if (anError)
+    return anError;
 
-  return Split( theObjectList, aGeomGroups, aPolyline );
+  outShs = anAlgo.Modified( InSh );
+  if (outShs.IsEmpty())
+    outShs.Append(InSh);
+  return 0;
 }