]> OCCT Git - occt-copy.git/commitdiff
Provide possibility to get the modified faces from the BRepOffsetAPI_PatchFaces algor...
authoremv <emv@opencascade.com>
Thu, 26 Oct 2017 11:51:13 +0000 (14:51 +0300)
committeremv <emv@opencascade.com>
Thu, 26 Oct 2017 11:51:13 +0000 (14:51 +0300)
Two new methods have been added:
- to get the new replaced face - TopoDS_Face GetPatchFace(const TopoDS_Face& theFace) const
- to get the neighboring faces of the replacing face - void GetAdjacentFaces(const TopoDS_Face& theFace, TopTools_ListOfShape& theNeighbors) const

Both methods take as an IN parameter the original face which was intended to be replaced.
First method returns the new face, on which the original one was replaced, updated to fit the resulting model.
Second method returns the faces adjacent to the original one also updated to fit the resulting model.

The new draw commands have been implemented to test these new methods:
- pfgetpatchface
- pfgetadjacentfaces

src/BRepOffsetAPI/BRepOffsetAPI_PatchFaces.cxx
src/BRepOffsetAPI/BRepOffsetAPI_PatchFaces.hxx
src/BRepTest/BRepTest_FeatureCommands.cxx

index f382c1d338fcefdf2ae254aa8556e8eb0af259fb..ea203a2fadcc4dfdf7f0ea9f95a00b9d2c68a06c 100644 (file)
@@ -818,6 +818,31 @@ BRepOffsetAPI_PatchFaces::BRepOffsetAPI_PatchFaces(const TopoDS_Shape& theShape)
   myInitialShape = theShape;
 }
 
+//=======================================================================
+//function : BRepOffsetAPI_PatchFaces
+//purpose  : Empty constructor
+//=======================================================================
+BRepOffsetAPI_PatchFaces::BRepOffsetAPI_PatchFaces()
+{}
+
+//=======================================================================
+//function : Clear
+//purpose  : 
+//=======================================================================
+void BRepOffsetAPI_PatchFaces::Clear()
+{
+  myFacePatchFace.Clear();
+  myFaceNewFace.Clear();
+  myNewFaceBoundedFace.Clear();
+  myEdgeNewEdge.Clear();
+  myVertexNewVertex.Clear();
+  myTangentEdges.Clear();
+  mySmoothEdges.Clear();
+  myEFmap.Clear();
+  myVEmap.Clear();
+  myVFmap.Clear();
+}
+
 //=======================================================================
 //function : SetOffsetFace
 //purpose  : 
@@ -836,6 +861,60 @@ void BRepOffsetAPI_PatchFaces::AddPatchFace(const TopoDS_Face& theFace,
   myFacePatchFace.Add(aFace, anOrientedPatchFace);
 }
 
+//=======================================================================
+//function : GetPatchFace
+//purpose  : 
+//=======================================================================
+TopoDS_Face BRepOffsetAPI_PatchFaces::GetPatchFace(const TopoDS_Face& theFace) const
+{
+  const TopoDS_Shape* anInitialPatchFace = myFacePatchFace.Seek(theFace);
+  if (!anInitialPatchFace)
+  {
+    TopoDS_Face aNullFace;
+    return aNullFace;
+  }
+
+  const TopoDS_Face& aPatch = TopoDS::Face(myNewFaceBoundedFace(*anInitialPatchFace));
+  return aPatch;
+}
+
+//=======================================================================
+//function : Get
+//purpose  : 
+//=======================================================================
+void BRepOffsetAPI_PatchFaces::GetAdjacentFaces(const TopoDS_Face& theFace,
+                                                TopTools_ListOfShape& theNeighbors) const
+{
+  const TopoDS_Shape* anInitialPatchFace = myFacePatchFace.Seek(theFace);
+  if (!anInitialPatchFace)
+    return;
+
+  // Fence map to avoid duplicates in the list
+  TopTools_MapOfShape aMFence;
+  // Find all adjacent faces in the initial solid
+  TopExp_Explorer anExpV(theFace, TopAbs_VERTEX);
+  for (; anExpV.More(); anExpV.Next())
+  {
+    const TopoDS_Shape& aVertex = anExpV.Current();
+    const TopTools_ListOfShape& aLFaces = myVFmap.Find(aVertex);
+
+    TopTools_ListIteratorOfListOfShape aItLF(aLFaces);
+    for (; aItLF.More(); aItLF.Next())
+    {
+      const TopoDS_Shape& aFace = aItLF.Value();
+      if (aFace.IsSame(theFace) || !aMFence.Add(aFace))
+        continue;
+
+      // Get face from the result solid
+      const TopoDS_Shape* pNewFace = myFaceNewFace.Seek(aFace);
+      if (pNewFace)
+        theNeighbors.Append(myNewFaceBoundedFace(*pNewFace));
+      else
+        theNeighbors.Append(aFace);
+    }
+  }
+}
+
 //=======================================================================
 //function : Build
 //purpose  : 
index bcc23c87cbf9fe9072205b478cb7fe113021647f..5fe3dd39b8466ba136a15acb218c5452df0b590e 100644 (file)
@@ -47,13 +47,31 @@ public:
   
   //! General constructor.
   Standard_EXPORT BRepOffsetAPI_PatchFaces(const TopoDS_Shape& aShape);
-  
+
+  //! Empty constructor.
+  Standard_EXPORT BRepOffsetAPI_PatchFaces();
+
+  //! Sets the model
+  void SetShape(const TopoDS_Shape& theShape)
+  {
+    myInitialShape = theShape;
+  }
+
+  //! Clears the contents from the previous runs
+  Standard_EXPORT void Clear();
+
   //! Adds the patch face for the face in the shape.
   Standard_EXPORT void AddPatchFace (const TopoDS_Face& theFace, const TopoDS_Face& thePatchFace);
   
   Standard_EXPORT virtual void Build() Standard_OVERRIDE;
 
+  //! Returns the patched face, updated to fit the model, for the given face <theFace>.
+  //! If there is no patched faces for the given face, the returned face will be null.
+  Standard_EXPORT TopoDS_Face GetPatchFace(const TopoDS_Face& theFace) const;
 
+  //! Returns the list of the faces, updated to fit the model, adjacent to the given replaced face.
+  //! If the given face has not been replaced, the list will be empty.
+  Standard_EXPORT void GetAdjacentFaces(const TopoDS_Face& theFace, TopTools_ListOfShape& theNeighbors) const;
 
 
 protected:
index d27354fe3908a8eca27a5ad1c0ef265a7efc6e49..62a6663ddb749f82f06273aa55f9eb9609a8e1c7 100644 (file)
@@ -2251,6 +2251,7 @@ static Standard_Integer BOSS(Draw_Interpretor& theCommands,
   return 1;
 }
 
+static BRepOffsetAPI_PatchFaces aPFBuilder;
 //=======================================================================
 //function : patchfaces
 //purpose  :
@@ -2271,16 +2272,94 @@ static Standard_Integer patchfaces(Draw_Interpretor& /*di*/,
   if (aLocalNewFace.IsNull()) return 1;
   TopoDS_Face aNewFace = TopoDS::Face(aLocalNewFace);
 
-  BRepOffsetAPI_PatchFaces Builder(aShape);
-  Builder.AddPatchFace(aFace, aNewFace);
-  Builder.Build();
+  aPFBuilder.Clear();
+  aPFBuilder.SetShape(aShape);
+  aPFBuilder.AddPatchFace(aFace, aNewFace);
+  aPFBuilder.Build();
 
-  TopoDS_Shape Result = Builder.Shape();
+  const TopoDS_Shape& Result = aPFBuilder.Shape();
   DBRep::Set(a[1], Result);
 
   return 0;
 }
 
+//=======================================================================
+//function : pfgetpatchface
+//purpose  :
+//=======================================================================
+static Standard_Integer pfgetpatchface(Draw_Interpretor& di,
+                                       Standard_Integer n,
+                                       const char** a)
+{
+  if (n != 3)
+  {
+    di << di.PrintHelp(a[0]);
+    return 1;
+  }
+
+  if (!aPFBuilder.IsDone())
+  {
+    di << "perform PatchFace operation first\n";
+    return 1;
+  }
+
+  TopoDS_Shape anInitialFace = DBRep::Get(a[2]);
+  if (anInitialFace.IsNull())
+  {
+    di << "The shape " << a[2] << " is a null shape\n";
+    return 1;
+  }
+
+  TopoDS_Shape aPatch = aPFBuilder.GetPatchFace(TopoDS::Face(anInitialFace));
+
+  DBRep::Set(a[1], aPatch);
+
+  return 0;
+}
+
+//=======================================================================
+//function : pfgetadjacentfaces
+//purpose  :
+//=======================================================================
+static Standard_Integer pfgetadjacentfaces(Draw_Interpretor& di,
+                                           Standard_Integer n,
+                                           const char** a)
+{
+  if (n != 3)
+  {
+    di << di.PrintHelp(a[0]);
+    return 1;
+  }
+
+  if (!aPFBuilder.IsDone())
+  {
+    di << "perform PatchFace operation first\n";
+    return 1;
+  }
+
+  TopoDS_Shape anInitialFace = DBRep::Get(a[2]);
+  if (anInitialFace.IsNull())
+  {
+    di << "The shape " << a[2] << " is a null shape\n";
+    return 1;
+  }
+
+  TopTools_ListOfShape aLF;
+  aPFBuilder.GetAdjacentFaces(TopoDS::Face(anInitialFace), aLF);
+
+  BRep_Builder aBB;
+  TopoDS_Compound aCFN;
+  aBB.MakeCompound(aCFN);
+
+  TopTools_ListIteratorOfListOfShape aIt(aLF);
+  for (; aIt.More(); aIt.Next())
+    aBB.Add(aCFN, aIt.Value());
+
+  DBRep::Set(a[1], aCFN);
+
+  return 0;
+}
+
 //=======================================================================
 //function : FeatureCommands
 //purpose  : 
@@ -2428,4 +2507,10 @@ void BRepTest::FeatureCommands (Draw_Interpretor& theCommands)
 
   theCommands.Add("patchfaces", "patchfaces res shape face newface",
                  __FILE__,patchfaces,g);
+
+  theCommands.Add("pfgetpatchface", "Get the patched face, updated to fit the model, for the given face.\n"
+                                    "Usage: pfgetpatchface res face", __FILE__, pfgetpatchface, g);
+
+  theCommands.Add("pfgetadjacentfaces", "Returns the list of the faces, updated to fit the model, adjacent to the given replaced face.\n"
+                                        "Usage: pfgetadjacentfaces res face", __FILE__, pfgetadjacentfaces, g);
 }