Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-04 09:13:55

0001 // Created on: 1993-07-08
0002 // Created by: Remi LEQUETTE
0003 // Copyright (c) 1993-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _BRepLib_MakeWire_HeaderFile
0018 #define _BRepLib_MakeWire_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_DefineAlloc.hxx>
0022 
0023 #include <BRepLib_WireError.hxx>
0024 #include <TopoDS_Edge.hxx>
0025 #include <TopoDS_Vertex.hxx>
0026 #include <TopoDS_Shape.hxx>
0027 #include <TopTools_ShapeMapHasher.hxx>
0028 #include <NCollection_DataMap.hxx>
0029 #include <NCollection_IndexedMap.hxx>
0030 #include <BRepLib_MakeShape.hxx>
0031 #include <NCollection_List.hxx>
0032 #include <Bnd_Box.hxx>
0033 #include <NCollection_UBTree.hxx>
0034 
0035 class TopoDS_Wire;
0036 
0037 //! Provides methods to build wires.
0038 //!
0039 //! A wire may be built:
0040 //!
0041 //! * From a single edge.
0042 //!
0043 //! * From a wire and an edge.
0044 //!
0045 //! - A new wire is created with the edges of the
0046 //! wire + the edge.
0047 //!
0048 //! - If the edge is not connected to the wire the
0049 //! flag NotDone is set and the method Wire will
0050 //! raise an error.
0051 //!
0052 //! - The connection may be:
0053 //!
0054 //! . Through an existing vertex. The edge is shared.
0055 //!
0056 //! . Through a geometric coincidence of vertices.
0057 //! The edge is copied and the vertices from the
0058 //! edge are replaced by the vertices from the
0059 //! wire.
0060 //!
0061 //! . The new edge and the connection vertices are
0062 //! kept by the algorithm.
0063 //!
0064 //! * From 2, 3, 4 edges.
0065 //!
0066 //! - A wire is created from the first edge, the
0067 //! following edges are added.
0068 //!
0069 //! * From many edges.
0070 //!
0071 //! - The following syntax may be used :
0072 //!
0073 //! BRepLib_MakeWire MW;
0074 //!
0075 //! // for all the edges ...
0076 //! MW.Add(anEdge);
0077 //!
0078 //! TopoDS_Wire W = MW;
0079 
0080 class BRepLib_MakeWire : public BRepLib_MakeShape
0081 {
0082 public:
0083   DEFINE_STANDARD_ALLOC
0084 
0085   //! NotDone MakeWire.
0086   Standard_EXPORT BRepLib_MakeWire();
0087 
0088   //! Make a Wire from an edge.
0089   Standard_EXPORT BRepLib_MakeWire(const TopoDS_Edge& E);
0090 
0091   //! Make a Wire from two edges.
0092   Standard_EXPORT BRepLib_MakeWire(const TopoDS_Edge& E1, const TopoDS_Edge& E2);
0093 
0094   //! Make a Wire from three edges.
0095   Standard_EXPORT BRepLib_MakeWire(const TopoDS_Edge& E1,
0096                                    const TopoDS_Edge& E2,
0097                                    const TopoDS_Edge& E3);
0098 
0099   //! Make a Wire from four edges.
0100   Standard_EXPORT BRepLib_MakeWire(const TopoDS_Edge& E1,
0101                                    const TopoDS_Edge& E2,
0102                                    const TopoDS_Edge& E3,
0103                                    const TopoDS_Edge& E4);
0104 
0105   //! Make a Wire from a Wire. Useful for adding later.
0106   Standard_EXPORT BRepLib_MakeWire(const TopoDS_Wire& W);
0107 
0108   //! Add an edge to a wire.
0109   Standard_EXPORT BRepLib_MakeWire(const TopoDS_Wire& W, const TopoDS_Edge& E);
0110 
0111   //! Add the edge <E> to the current wire.
0112   Standard_EXPORT void Add(const TopoDS_Edge& E);
0113 
0114   //! Add the edges of <W> to the current wire.
0115   Standard_EXPORT void Add(const TopoDS_Wire& W);
0116 
0117   //! Add the edges of <L> to the current wire.
0118   //! The edges are not to be consecutive. But they are
0119   //! to be all connected geometrically or topologically.
0120   Standard_EXPORT void Add(const NCollection_List<TopoDS_Shape>& L);
0121 
0122   Standard_EXPORT BRepLib_WireError Error() const;
0123 
0124   //! Returns the new wire.
0125   Standard_EXPORT const TopoDS_Wire& Wire();
0126   Standard_EXPORT                    operator TopoDS_Wire();
0127 
0128   //! Returns the last edge added to the wire.
0129   Standard_EXPORT const TopoDS_Edge& Edge() const;
0130 
0131   //! Returns the last connecting vertex.
0132   Standard_EXPORT const TopoDS_Vertex& Vertex() const;
0133 
0134 private:
0135   class BRepLib_BndBoxVertexSelector : public NCollection_UBTree<int, Bnd_Box>::Selector
0136   {
0137   public:
0138     BRepLib_BndBoxVertexSelector(
0139       const NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher>& theMapOfShape)
0140         : myMapOfShape(theMapOfShape),
0141           myTolP(0.0),
0142           myVInd(0)
0143     {
0144     }
0145 
0146     bool Reject(const Bnd_Box& theBox) const override { return theBox.IsOut(myVBox); }
0147 
0148     bool Accept(const int& theObj) override;
0149 
0150     void SetCurrentVertex(const gp_Pnt& theP, double theTol, int theVInd);
0151 
0152     const NCollection_List<int>& GetResultInds() const { return myResultInd; }
0153 
0154     void ClearResInds() { myResultInd.Clear(); }
0155 
0156   private:
0157     BRepLib_BndBoxVertexSelector(const BRepLib_BndBoxVertexSelector&)            = delete;
0158     BRepLib_BndBoxVertexSelector& operator=(const BRepLib_BndBoxVertexSelector&) = delete;
0159 
0160     const NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher>& myMapOfShape; // vertices
0161     gp_Pnt                                                               myP;
0162     double                                                               myTolP;
0163     int                                                                  myVInd;
0164     Bnd_Box                                                              myVBox;
0165     NCollection_List<int>                                                myResultInd;
0166   };
0167 
0168   void CollectCoincidentVertices(const NCollection_List<TopoDS_Shape>&              theL,
0169                                  NCollection_List<NCollection_List<TopoDS_Vertex>>& theGrVL);
0170 
0171   void CreateNewVertices(
0172     const NCollection_List<NCollection_List<TopoDS_Vertex>>&                  theGrVL,
0173     NCollection_DataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher>& theO2NV);
0174 
0175   void CreateNewListOfEdges(
0176     const NCollection_List<TopoDS_Shape>&                                           theL,
0177     const NCollection_DataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher>& theO2NV,
0178     NCollection_List<TopoDS_Shape>&                                                 theNewEList);
0179 
0180   void Add(const TopoDS_Edge& E, bool IsCheckGeometryProximity);
0181 
0182 private:
0183   BRepLib_WireError                                             myError;
0184   TopoDS_Edge                                                   myEdge;
0185   TopoDS_Vertex                                                 myVertex;
0186   NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher> myVertices;
0187   TopoDS_Vertex                                                 FirstVertex;
0188   TopoDS_Vertex                                                 VF;
0189   TopoDS_Vertex                                                 VL;
0190 };
0191 
0192 #endif // _BRepLib_MakeWire_HeaderFile