1a84d306276ace4302f72044e169dd0b0eb32887
[occt.git] / src / BRepBuilderAPI / BRepBuilderAPI_MakePolygon.hxx
1 // Created on: 1993-07-29
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 _BRepBuilderAPI_MakePolygon_HeaderFile
18 #define _BRepBuilderAPI_MakePolygon_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
23
24 #include <BRepLib_MakePolygon.hxx>
25 #include <BRepBuilderAPI_MakeShape.hxx>
26 #include <Standard_Boolean.hxx>
27 class StdFail_NotDone;
28 class gp_Pnt;
29 class TopoDS_Vertex;
30 class TopoDS_Edge;
31 class TopoDS_Wire;
32
33
34 //! Describes functions to build polygonal wires. A
35 //! polygonal wire can be built from any number of points
36 //! or vertices, and consists of a sequence of connected
37 //! rectilinear edges.
38 //! When a point or vertex is added to the  polygon if
39 //! it is identic  to the previous  point no  edge  is
40 //! built. The method added can be used to test it.
41 //! Construction of a Polygonal Wire
42 //! You can construct:
43 //! -   a complete polygonal wire by defining all its points
44 //! or vertices (limited to four), or
45 //! -   an empty polygonal wire and add its points or
46 //! vertices in sequence (unlimited number).
47 //! A MakePolygon object provides a framework for:
48 //! -   initializing the construction of a polygonal wire,
49 //! -   adding points or vertices to the polygonal wire under construction, and
50 //! -   consulting the result.
51 class BRepBuilderAPI_MakePolygon  : public BRepBuilderAPI_MakeShape
52 {
53 public:
54
55   DEFINE_STANDARD_ALLOC
56
57   
58   //! Initializes an empty polygonal wire, to which points or
59   //! vertices are added using the Add function.
60   //! As soon as the polygonal wire under construction
61   //! contains vertices, it can be consulted using the Wire function.
62   Standard_EXPORT BRepBuilderAPI_MakePolygon();
63   
64   Standard_EXPORT BRepBuilderAPI_MakePolygon(const gp_Pnt& P1, const gp_Pnt& P2);
65   
66   Standard_EXPORT BRepBuilderAPI_MakePolygon(const gp_Pnt& P1, const gp_Pnt& P2, const gp_Pnt& P3, const Standard_Boolean Close = Standard_False);
67   
68   //! Constructs a polygonal wire from 2, 3 or 4 points. Vertices are
69   //! automatically created on the given points. The polygonal wire is
70   //! closed if Close is true; otherwise it is open. Further vertices can
71   //! be added using the Add function. The polygonal wire under
72   //! construction can be consulted at any time by using the Wire function.
73   //! Example
74   //! //an open polygon from four points
75   //! TopoDS_Wire W = BRepBuilderAPI_MakePolygon(P1,P2,P3,P4);
76   //! Warning: The process is equivalent to:
77   //! - initializing an empty polygonal wire,
78   //! - and adding the given points in sequence.
79   //! Consequently, be careful when using this function: if the
80   //! sequence of points p1 - p2 - p1 is found among the arguments of the
81   //! constructor, you will create a polygonal wire with two
82   //! consecutive coincident edges.
83   Standard_EXPORT BRepBuilderAPI_MakePolygon(const gp_Pnt& P1, const gp_Pnt& P2, const gp_Pnt& P3, const gp_Pnt& P4, const Standard_Boolean Close = Standard_False);
84   
85   Standard_EXPORT BRepBuilderAPI_MakePolygon(const TopoDS_Vertex& V1, const TopoDS_Vertex& V2);
86   
87   Standard_EXPORT BRepBuilderAPI_MakePolygon(const TopoDS_Vertex& V1, const TopoDS_Vertex& V2, const TopoDS_Vertex& V3, const Standard_Boolean Close = Standard_False);
88   
89   //! Constructs a polygonal wire from
90   //! 2, 3 or 4 vertices. The polygonal wire is closed if Close is true;
91   //! otherwise it is open (default value). Further vertices can be
92   //! added using the Add function. The polygonal wire under
93   //! construction can be consulted at any time by using the Wire function.
94   //! Example
95   //! //a closed triangle from three vertices
96   //! TopoDS_Wire W = BRepBuilderAPI_MakePolygon(V1,V2,V3,Standard_True);
97   //! Warning
98   //! The process is equivalent to:
99   //! -      initializing an empty polygonal wire,
100   //! -      then adding the given points in sequence.
101   //! So be careful, as when using this function, you could create a
102   //! polygonal wire with two consecutive coincident edges if
103   //! the sequence of vertices v1 - v2 - v1 is found among the
104   //! constructor's arguments.
105   Standard_EXPORT BRepBuilderAPI_MakePolygon(const TopoDS_Vertex& V1, const TopoDS_Vertex& V2, const TopoDS_Vertex& V3, const TopoDS_Vertex& V4, const Standard_Boolean Close = Standard_False);
106   
107   Standard_EXPORT void Add (const gp_Pnt& P);
108   
109
110   //! Adds the point P or the vertex V at the end of the
111   //! polygonal wire under construction. A vertex is
112   //! automatically created on the point P.
113   //! Warning
114   //! -   When P or V is coincident to the previous vertex,
115   //! no edge is built. The method Added can be used to
116   //! test for this. Neither P nor V is checked to verify
117   //! that it is coincident with another vertex than the last
118   //! one, of the polygonal wire under construction. It is
119   //! also possible to add vertices on a closed polygon
120   //! (built for example by using a constructor which
121   //! declares the polygon closed, or after the use of the Close function).
122   //! Consequently, be careful using this function: you might create:
123   //! -      a polygonal wire with two consecutive coincident edges, or
124   //! -      a non manifold polygonal wire.
125   //! -      P or V is not checked to verify if it is
126   //! coincident with another vertex but the last one, of
127   //! the polygonal wire under construction. It is also
128   //! possible to add vertices on a closed polygon (built
129   //! for example by using a constructor which declares
130   //! the polygon closed, or after the use of the Close function).
131   //! Consequently, be careful when using this function: you might create:
132   //! -   a polygonal wire with two consecutive coincident edges, or
133   //! -   a non-manifold polygonal wire.
134   Standard_EXPORT void Add (const TopoDS_Vertex& V);
135   
136   //! Returns true if the last vertex added to the constructed
137   //! polygonal wire is not coincident with the previous one.
138   Standard_EXPORT Standard_Boolean Added() const;
139   
140   //! Closes the polygonal wire under construction. Note - this
141   //! is equivalent to adding the first vertex to the polygonal
142   //! wire under construction.
143   Standard_EXPORT void Close();
144   
145   Standard_EXPORT const TopoDS_Vertex& FirstVertex() const;
146   
147   //! Returns the first or the last vertex of the polygonal wire under construction.
148   //! If the constructed polygonal wire is closed, the first and the last vertices are identical.
149   Standard_EXPORT const TopoDS_Vertex& LastVertex() const;
150   
151
152   //! Returns true if this algorithm contains a valid polygonal
153   //! wire (i.e. if there is at least one edge).
154   //! IsDone returns false if fewer than two vertices have
155   //! been chained together by this construction algorithm.
156   Standard_EXPORT virtual Standard_Boolean IsDone() const Standard_OVERRIDE;
157   
158   //! Returns the edge built between the last two points or
159   //! vertices added to the constructed polygonal wire under construction.
160   //! Warning
161   //! If there is only one vertex in the polygonal wire, the result is a null edge.
162   Standard_EXPORT const TopoDS_Edge& Edge() const;
163 Standard_EXPORT operator TopoDS_Edge() const;
164   
165
166   //! Returns the constructed polygonal wire, or the already
167   //! built part of the polygonal wire under construction.
168   //! Exceptions
169   //! StdFail_NotDone if the wire is not built, i.e. if fewer than
170   //! two vertices have been chained together by this construction algorithm.
171   Standard_EXPORT const TopoDS_Wire& Wire() const;
172 Standard_EXPORT operator TopoDS_Wire() const;
173
174
175
176
177 protected:
178
179
180
181
182
183 private:
184
185
186
187   BRepLib_MakePolygon myMakePolygon;
188
189
190 };
191
192
193
194
195
196
197
198 #endif // _BRepBuilderAPI_MakePolygon_HeaderFile