Salome HOME
PAL7508: Development of new block functionalities. GetInPlace() now works for the...
[modules/geom.git] / src / NMTAlgo / NMTAlgo_Splitter_1.cxx
index 2c057d7f06d1ee783f89983b2977b2886780c5d5..468fb03327b13e3bc7a744d2e1df00d0f8dda33e 100644 (file)
@@ -5,34 +5,54 @@
 
 
 #include <NMTAlgo_Splitter.ixx>
-#include <TopExp_Explorer.hxx>
+
+#include <Precision.hxx>
+
+#include <gp_Pnt.hxx>
+
+#include <TopAbs_ShapeEnum.hxx>
+
+#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Face.hxx>
 #include <TopoDS_Shape.hxx>
 #include <TopoDS_Compound.hxx>
+#include <TopoDS_Solid.hxx>
+#include <TopoDS_Iterator.hxx>
+
+#include <TopExp.hxx>
+#include <TopExp_Explorer.hxx>
+
 #include <TopTools_MapOfShape.hxx>
 #include <TopTools_DataMapOfShapeListOfShape.hxx>
 #include <TopTools_MapIteratorOfMapOfShape.hxx>
 #include <TopTools_ListOfShape.hxx>
 #include <TopTools_ListIteratorOfListOfShape.hxx>
-#include <TopExp.hxx>
-#include <TopoDS_Iterator.hxx>
 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
-#include <TopoDS.hxx>
-#include <TopoDS_Edge.hxx>
-#include <TopoDS_Face.hxx>
-#include <NMTAlgo_Loop3d.hxx>
-#include <Precision.hxx>
+#include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
+#include <TopTools_IndexedMapOfShape.hxx>
+#include <TopTools_IndexedDataMapOfShapeShape.hxx>
+
 #include <BRep_Tool.hxx>
 #include <BRepClass3d_SolidClassifier.hxx>
-#include <gp_Pnt.hxx>
-#include <TopoDS_Solid.hxx>
+
 #include <NMTAlgo_Loop3d.hxx>
-#include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
+
+//
+//modified by NIZNHY-PKV Tue Feb  1 12:12:39 2005 f
+static 
+  void RefineShells(const TopoDS_Shape& ,
+                   TopTools_ListOfShape&);
+static 
+  void RefineSolids(const TopoDS_Shape& ,
+                   TopTools_ListOfShape&);
+//modified by NIZNHY-PKV Tue Feb  1 12:12:43 2005 t
 
 //=======================================================================
 //function : ShellsAndSolids
 //purpose  : 
 //=======================================================================
 void NMTAlgo_Splitter::ShellsAndSolids()
+ void NMTAlgo_Splitter::ShellsAndSolids()
 {
   Standard_Boolean bMakeSolids;
   TopAbs_ShapeEnum aType;
 //function : MakeShells
 //purpose  : split S into compound of shells
 //=======================================================================
-  void NMTAlgo_Splitter::MakeShells(const TopoDS_Shape& aS,
-                                   TopTools_ListOfShape& aLNS)
+void NMTAlgo_Splitter::MakeShells(const TopoDS_Shape& aS,
+                                 TopTools_ListOfShape& aLNS)
 {
   NMTAlgo_Loop3d aShellMaker;
   //
   }
   //
   aLNS=aShellMaker.MakeShells(myAddedFacesMap);
+  //modified by NIZNHY-PKV Tue Feb  1 14:11:11 2005 f
+  RefineShells(aS, aLNS);
+  //modified by NIZNHY-PKV Tue Feb  1 14:11:14 2005 t
   //
   // Add faces added to new shell to myAddedFacesMap:
   // avoid rebuilding twice common part of 2 solids.
 //function : MakeSolids
 //purpose  : make solids out of Shells
 //=======================================================================
-  void NMTAlgo_Splitter::MakeSolids(const TopoDS_Shape&   theSolid,
-                                   TopTools_ListOfShape& theShellList)
+void NMTAlgo_Splitter::MakeSolids(const TopoDS_Shape&   theSolid,
+                                 TopTools_ListOfShape& theShellList)
 {
   // for a solid wrapping other shells or solids without intersection,
   // it is necessary to find shells making holes in it
       TopoDS_Solid Solid;
       myBuilder.MakeSolid( Solid );
       myBuilder.Add (Solid, aShell);
-
+      
       aNewSolids.Append (Solid);
     }
   }
       myBuilder.Add (aSolid, aHole);
     }
   }
+  //
   theShellList.Clear();
-  theShellList.Append( aNewSolids );
+  //modified by NIZNHY-PKV Tue Feb  1 15:06:16 2005 f
+  RefineSolids(theSolid, aNewSolids);
+  //modified by NIZNHY-PKV Tue Feb  1 15:06:21 2005 t
+  theShellList.Append(aNewSolids);
 }
  
 //=======================================================================
 //purpose  : Return True if the first vertex of S1 inside S2.
 //           If S1.IsNull(), check infinite point against S2.
 //=======================================================================
-  Standard_Boolean NMTAlgo_Splitter::IsInside (const TopoDS_Shape& theS1,
-                                              const TopoDS_Shape& theS2)
+Standard_Boolean NMTAlgo_Splitter::IsInside (const TopoDS_Shape& theS1,
+                                            const TopoDS_Shape& theS2)
 {
   BRepClass3d_SolidClassifier aClassifier( theS2 );
   //
   //
   return ( aClassifier.State() == TopAbs_IN );
 }
-
 //=======================================================================
 //function : GetOriginalShape
 //purpose  : Return the  shape  aShape  originates from. aShape
 //           should be a face or more complex result shape
 //=======================================================================
-  TopoDS_Shape NMTAlgo_Splitter::GetOriginalShape(const TopoDS_Shape& theShape) const
+TopoDS_Shape NMTAlgo_Splitter::GetOriginalShape(const TopoDS_Shape& theShape) const
 {
   TopoDS_Shape anOrigShape;
 
   }
   return anOrigShape;
 }
+
+//modified by NIZNHY-PKV Tue Feb  1 11:56:24 2005f
+//=======================================================================
+//function :RefineShells 
+//purpose  : 
+//=======================================================================
+void RefineShells(const TopoDS_Shape& aS,
+                 TopTools_ListOfShape& aLNS)
+{
+  Standard_Boolean bFound;
+  Standard_Integer iS, jS, aNbSOrs, aNbSIms, aNbFOrs, aNbFIms, kFOrs, aNb;
+  TopTools_ListIteratorOfListOfShape aIt;
+  TopTools_IndexedMapOfShape aMSOrs, aMSIms, aMFOrs, aMFIms;
+  TopTools_IndexedDataMapOfShapeShape aMImOr;
+  TopTools_ListOfShape aLS;
+  //
+  TopExp::MapShapes(aS, TopAbs_SHELL, aMSOrs);
+  aIt.Initialize(aLNS);
+  for (;aIt.More(); aIt.Next()) {
+    const TopoDS_Shape& aSh=aIt.Value();
+    aMSIms.Add(aSh);
+  }
+  //
+  aNbSOrs=aMSOrs.Extent();
+  aNbSIms=aMSIms.Extent();
+  //
+  for (iS=1; iS<=aNbSOrs; ++iS) {
+    const TopoDS_Shape& aSOr=aMSOrs(iS);
+    aMFOrs.Clear();
+    TopExp::MapShapes(aSOr, TopAbs_FACE, aMFOrs);
+    aNbFOrs=aMFOrs.Extent();
+    //
+    for (jS=1; jS<=aNbSIms; ++jS) {
+      const TopoDS_Shape& aSIm=aMSIms(jS);
+      if (aMImOr.Contains(aSIm)) {
+       continue;
+      }
+      //
+      aMFIms.Clear();
+      TopExp::MapShapes(aSIm, TopAbs_FACE, aMFIms);
+      aNbFIms=aMFIms.Extent();
+      //
+      if (aNbFIms==aNbFOrs) {
+       bFound=Standard_True;
+       for (kFOrs=1; kFOrs<=aNbFOrs; ++kFOrs) {
+         const TopoDS_Shape& aFOr=aMFOrs(kFOrs);
+         if (!aMFIms.Contains(aFOr)) {
+           bFound=Standard_False;
+           break; //next aSIm
+         }
+       }
+       if (bFound){
+         aMImOr.Add(aSIm, aSOr);
+         break; //next aSOr
+       }
+      } //if (aNbFIms==aNbFOrs)
+    }
+  }
+  //
+  aNb=aMImOr.Extent();
+  aIt.Initialize(aLNS);
+  for (;aIt.More(); aIt.Next()) {
+    const TopoDS_Shape& aSh=aIt.Value();
+    if (aMImOr.Contains(aSh)) {
+      const TopoDS_Shape& aSOr=aMImOr.FindFromKey(aSh);
+      aLS.Append(aSOr);
+    }
+    else {
+      aLS.Append(aSh);
+    }
+  }
+  //
+  aLNS.Clear();
+  aLNS.Append(aLS);
+}
+
+//=======================================================================
+//function :RefineSolids 
+//purpose  : 
+//=======================================================================
+void RefineSolids(const TopoDS_Shape& aSolidOr,
+                 TopTools_ListOfShape& aLNS)
+{
+  Standard_Integer aNb, iS,  aNbSOrs, aNbSIms;
+  TopoDS_Shape aSolidIm;
+  TopTools_IndexedMapOfShape aMSOrs, aMSIms;
+  //
+  aNb=aLNS.Extent();
+  if (aNb!=1) {
+    return;
+  }
+  //
+  aSolidIm=aLNS.First();
+  
+  TopExp::MapShapes(aSolidOr, TopAbs_SHELL, aMSOrs);
+  TopExp::MapShapes(aSolidIm, TopAbs_SHELL, aMSIms);
+  aNbSOrs=aMSOrs.Extent();
+  aNbSIms=aMSIms.Extent();
+  if (aNbSOrs!=aNbSIms) {
+    return;
+  }
+  //
+  for (iS=1; iS<=aNbSOrs; ++iS) {
+    const TopoDS_Shape& aSOr=aMSOrs(iS);
+    if (!aMSIms.Contains(aSOr)) {
+      return;
+    }
+  }
+  //
+  aLNS.Clear();
+  aLNS.Append(aSolidOr);
+}
+//modified by NIZNHY-PKV Tue Feb  1 11:56:28 2005t