diff --git a/src/BRepOffsetAPI/BRepOffsetAPI_PatchFaces.cxx b/src/BRepOffsetAPI/BRepOffsetAPI_PatchFaces.cxx index f382c1d338..ea203a2fad 100644 --- a/src/BRepOffsetAPI/BRepOffsetAPI_PatchFaces.cxx +++ b/src/BRepOffsetAPI/BRepOffsetAPI_PatchFaces.cxx @@ -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 : diff --git a/src/BRepOffsetAPI/BRepOffsetAPI_PatchFaces.hxx b/src/BRepOffsetAPI/BRepOffsetAPI_PatchFaces.hxx index bcc23c87cb..5fe3dd39b8 100644 --- a/src/BRepOffsetAPI/BRepOffsetAPI_PatchFaces.hxx +++ b/src/BRepOffsetAPI/BRepOffsetAPI_PatchFaces.hxx @@ -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 . + //! 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: diff --git a/src/BRepTest/BRepTest_FeatureCommands.cxx b/src/BRepTest/BRepTest_FeatureCommands.cxx index d27354fe39..62a6663ddb 100644 --- a/src/BRepTest/BRepTest_FeatureCommands.cxx +++ b/src/BRepTest/BRepTest_FeatureCommands.cxx @@ -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); }