1 // Created on: 1993-07-08
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16 
17 #ifndef _BRepLib_MakeWire_HeaderFile
18 #define _BRepLib_MakeWire_HeaderFile
19 
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
23 
24 #include <BRepLib_WireError.hxx>
25 #include <TopoDS_Edge.hxx>
26 #include <TopoDS_Vertex.hxx>
27 #include <TopTools_DataMapOfShapeShape.hxx>
28 #include <TopTools_IndexedMapOfShape.hxx>
29 #include <BRepLib_MakeShape.hxx>
30 #include <TopTools_ListOfShape.hxx>
31 #include <Bnd_Box.hxx>
32 #include <NCollection_UBTree.hxx>
33 
34 class TopoDS_Wire;
35 
36 //! Provides methods to build wires.
37 //!
38 //! A wire may be built :
39 //!
40 //! * From a single edge.
41 //!
42 //! * From a wire and an edge.
43 //!
44 //! - A new wire  is created with the edges  of  the
45 //! wire + the edge.
46 //!
47 //! - If the edge is not connected  to the wire the
48 //! flag NotDone   is set and  the  method Wire will
49 //! raise an error.
50 //!
51 //! - The connection may be :
52 //!
53 //! . Through an existing vertex. The edge is shared.
54 //!
55 //! . Through a geometric coincidence of vertices.
56 //! The edge is  copied  and the vertices from the
57 //! edge are  replaced  by  the vertices from  the
58 //! wire.
59 //!
60 //! . The new edge and the connection vertices are
61 //! kept by the algorithm.
62 //!
63 //! * From 2, 3, 4 edges.
64 //!
65 //! - A wire is  created from  the first edge, the
66 //! following edges are added.
67 //!
68 //! * From many edges.
69 //!
70 //! - The following syntax may be used :
71 //!
72 //! BRepLib_MakeWire MW;
73 //!
74 //! // for all the edges ...
75 //! MW.Add(anEdge);
76 //!
77 //! TopoDS_Wire W = MW;
78 
79 class BRepLib_MakeWire  : public BRepLib_MakeShape
80 {
81 public:
82 
83   DEFINE_STANDARD_ALLOC
84 
85 
86   //! NotDone MakeWire.
87   Standard_EXPORT BRepLib_MakeWire();
88 
89   //! Make a Wire from an edge.
90   Standard_EXPORT BRepLib_MakeWire(const TopoDS_Edge& E);
91 
92   //! Make a Wire from two edges.
93   Standard_EXPORT BRepLib_MakeWire(const TopoDS_Edge& E1, const TopoDS_Edge& E2);
94 
95   //! Make a Wire from three edges.
96   Standard_EXPORT BRepLib_MakeWire(const TopoDS_Edge& E1, const TopoDS_Edge& E2, const TopoDS_Edge& E3);
97 
98   //! Make a Wire from four edges.
99   Standard_EXPORT BRepLib_MakeWire(const TopoDS_Edge& E1, const TopoDS_Edge& E2, const TopoDS_Edge& E3, const TopoDS_Edge& E4);
100 
101   //! Make a Wire from a Wire. Useful for adding later.
102   Standard_EXPORT BRepLib_MakeWire(const TopoDS_Wire& W);
103 
104   //! Add an edge to a wire.
105   Standard_EXPORT BRepLib_MakeWire(const TopoDS_Wire& W, const TopoDS_Edge& E);
106 
107   //! Add the edge <E> to the current wire.
108   Standard_EXPORT void Add (const TopoDS_Edge& E);
109 
110   //! Add the edges of <W> to the current wire.
111   Standard_EXPORT void Add (const TopoDS_Wire& W);
112 
113   //! Add the edges of <L> to the current wire.
114   //! The edges are not to be consecutive.  But they are
115   //! to be all connected geometrically or topologically.
116   Standard_EXPORT void Add (const TopTools_ListOfShape& L);
117 
118   Standard_EXPORT BRepLib_WireError Error() const;
119 
120   //! Returns the new wire.
121   Standard_EXPORT const TopoDS_Wire& Wire();
122   Standard_EXPORT operator TopoDS_Wire();
123 
124   //! Returns the last edge added to the wire.
125   Standard_EXPORT const TopoDS_Edge& Edge() const;
126 
127   //! Returns the last connecting vertex.
128   Standard_EXPORT const TopoDS_Vertex& Vertex() const;
129 
130 private:
131   class BRepLib_BndBoxVertexSelector : public NCollection_UBTree <Standard_Integer,Bnd_Box>::Selector
132   {
133   public:
BRepLib_BndBoxVertexSelector(const TopTools_IndexedMapOfShape & theMapOfShape)134     BRepLib_BndBoxVertexSelector(const TopTools_IndexedMapOfShape& theMapOfShape)
135     : BRepLib_BndBoxVertexSelector::Selector(),
136       myMapOfShape (theMapOfShape),
137       myTolP(0.0),
138       myVInd(0)
139     {
140     }
141 
Reject(const Bnd_Box & theBox) const142     Standard_Boolean Reject (const Bnd_Box& theBox) const
143     {
144       return theBox.IsOut(myVBox);
145     }
146 
147     Standard_Boolean Accept (const Standard_Integer& theObj);
148 
149     void SetCurrentVertex (const gp_Pnt& theP, Standard_Real theTol,
150                            Standard_Integer theVInd);
151 
GetResultInds() const152     const NCollection_List<Standard_Integer>& GetResultInds () const
153     {
154       return myResultInd;
155     }
156 
ClearResInds()157     void ClearResInds()
158     {
159       myResultInd.Clear();
160     }
161 
162   private:
163 
164     BRepLib_BndBoxVertexSelector(const BRepLib_BndBoxVertexSelector& );
165     BRepLib_BndBoxVertexSelector& operator=(const BRepLib_BndBoxVertexSelector& );
166 
167     const TopTools_IndexedMapOfShape& myMapOfShape; //vertices
168     gp_Pnt myP;
169     Standard_Real myTolP;
170     Standard_Integer myVInd;
171     Bnd_Box myVBox;
172     NCollection_List<Standard_Integer> myResultInd;
173   };
174 
175   void CollectCoincidentVertices(const TopTools_ListOfShape& theL,
176                                  NCollection_List<NCollection_List<TopoDS_Vertex>>& theGrVL);
177 
178   void CreateNewVertices(const NCollection_List<NCollection_List<TopoDS_Vertex>>& theGrVL,
179                          TopTools_DataMapOfShapeShape& theO2NV);
180 
181   void CreateNewListOfEdges(const TopTools_ListOfShape& theL,
182                             const TopTools_DataMapOfShapeShape& theO2NV,
183                             TopTools_ListOfShape& theNewEList);
184 
185   void Add(const TopoDS_Edge& E, Standard_Boolean IsCheckGeometryProximity);
186 
187 
188 
189 protected:
190 
191 
192 
193 private:
194 
195   BRepLib_WireError myError;
196   TopoDS_Edge myEdge;
197   TopoDS_Vertex myVertex;
198   TopTools_IndexedMapOfShape myVertices;
199   TopoDS_Vertex FirstVertex;
200   TopoDS_Vertex VF;
201   TopoDS_Vertex VL;
202 
203 };
204 
205 
206 
207 
208 
209 
210 
211 #endif // _BRepLib_MakeWire_HeaderFile
212