0024428: Implementation of LGPL license
[occt.git] / src / BRepLib / BRepLib_MakePolygon.cxx
CommitLineData
b311480e 1// Created on: 1993-07-29
2// Created by: Remi LEQUETTE
3// Copyright (c) 1993-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
973c2be1 8// This library is free software; you can redistribute it and / or modify it
9// under the terms of the GNU Lesser General Public 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <BRepLib_MakePolygon.ixx>
18#include <BRepLib.hxx>
19#include <BRepLib_MakeEdge.hxx>
20#include <BRepTools.hxx>
21#include <BRep_Tool.hxx>
22#include <BRep_Builder.hxx>
23#include <TopoDS.hxx>
24#include <Precision.hxx>
25
26//=======================================================================
27//function : BRepLib_MakePolygon
28//purpose :
29//=======================================================================
30
31BRepLib_MakePolygon::BRepLib_MakePolygon()
32{
33}
34
35
36//=======================================================================
37//function : BRepLib_MakePolygon
38//purpose :
39//=======================================================================
40
41BRepLib_MakePolygon::BRepLib_MakePolygon(const gp_Pnt& P1, const gp_Pnt& P2)
42{
43 Add(P1);
44 Add(P2);
45}
46
47
48//=======================================================================
49//function : BRepLib_MakePolygon
50//purpose :
51//=======================================================================
52
53BRepLib_MakePolygon::BRepLib_MakePolygon(const gp_Pnt& P1,
54 const gp_Pnt& P2,
55 const gp_Pnt& P3,
56 const Standard_Boolean Cl)
57{
58 Add(P1);
59 Add(P2);
60 Add(P3);
61 if (Cl) Close();
62}
63
64
65//=======================================================================
66//function : BRepLib_MakePolygon
67//purpose :
68//=======================================================================
69
70BRepLib_MakePolygon::BRepLib_MakePolygon(const gp_Pnt& P1,
71 const gp_Pnt& P2,
72 const gp_Pnt& P3,
73 const gp_Pnt& P4,
74 const Standard_Boolean Cl)
75{
76 Add(P1);
77 Add(P2);
78 Add(P3);
79 Add(P4);
80 if (Cl) Close();
81}
82
83
84//=======================================================================
85//function : BRepLib_MakePolygon
86//purpose :
87//=======================================================================
88
89BRepLib_MakePolygon::BRepLib_MakePolygon(const TopoDS_Vertex& V1,
90 const TopoDS_Vertex& V2)
91{
92 Add(V1);
93 Add(V2);
94}
95
96
97//=======================================================================
98//function : BRepLib_MakePolygon
99//purpose :
100//=======================================================================
101
102BRepLib_MakePolygon::BRepLib_MakePolygon(const TopoDS_Vertex& V1,
103 const TopoDS_Vertex& V2,
104 const TopoDS_Vertex& V3,
105 const Standard_Boolean Cl)
106{
107 Add(V1);
108 Add(V2);
109 Add(V3);
110 if (Cl) Close();
111}
112
113
114//=======================================================================
115//function : BRepLib_MakePolygon
116//purpose :
117//=======================================================================
118
119BRepLib_MakePolygon::BRepLib_MakePolygon(const TopoDS_Vertex& V1,
120 const TopoDS_Vertex& V2,
121 const TopoDS_Vertex& V3,
122 const TopoDS_Vertex& V4,
123 const Standard_Boolean Cl)
124{
125 Add(V1);
126 Add(V2);
127 Add(V3);
128 Add(V4);
129 if (Cl) Close();
130}
131
132
133//=======================================================================
134//function : Add
135//purpose :
136//=======================================================================
137
138void BRepLib_MakePolygon::Add(const gp_Pnt& P)
139{
140 BRep_Builder B;
141 TopoDS_Vertex V;
142 B.MakeVertex(V,P,Precision::Confusion());
143 Add(V);
144}
145
146
147//=======================================================================
148//function : Add
149//purpose :
150//=======================================================================
151
152void BRepLib_MakePolygon::Add(const TopoDS_Vertex& V)
153{
154 if (myFirstVertex.IsNull()) {
155 myFirstVertex = V;
156 }
157 else {
158 myEdge.Nullify();
159 BRep_Builder B;
160 TopoDS_Vertex last;
161
162 Standard_Boolean second = myLastVertex.IsNull();
163 if (second) {
164 last = myFirstVertex;
165 myLastVertex = V;
166 B.MakeWire(TopoDS::Wire(myShape));
167 myShape.Closed(Standard_False);
168 myShape.Orientable(Standard_True);
169 }
170 else {
171 last = myLastVertex;
172 if (BRepTools::Compare(V,myFirstVertex)) {
173 myLastVertex = myFirstVertex;
174 myShape.Closed(Standard_True);
175 }
176 else
177 myLastVertex = V;
178 }
179
180 BRepLib_MakeEdge ME(last,myLastVertex);
181 if (ME.IsDone()) {
182 myEdge = ME;
183 B.Add(myShape,myEdge);
184 Done();
185 }
186 else {
187 // restore the previous last vertex
188 if (second)
189 myLastVertex.Nullify();
190 else
191 myLastVertex = last;
192 }
193 }
194}
195
196//=======================================================================
197//function : Added
198//purpose :
199//=======================================================================
200
201Standard_Boolean BRepLib_MakePolygon::Added()const
202{
203 return !myEdge.IsNull();
204}
205
206
207//=======================================================================
208//function : Close
209//purpose :
210//=======================================================================
211
212void BRepLib_MakePolygon::Close()
213{
214 if (myFirstVertex.IsNull() || myLastVertex.IsNull())
215 return;
216
217 // check not already closed
218 if (myShape.Closed())
219 return;
220
221 // build the last edge
222 BRep_Builder B;
223 myEdge.Nullify();
224 BRepLib_MakeEdge ME(myLastVertex,myFirstVertex);
225 if (ME.IsDone()) {
226 myEdge = ME;
227 B.Add(myShape,myEdge);
228 myShape.Closed(Standard_True);
229 }
230}
231
232
233//=======================================================================
234//function : FirstVertex
235//purpose :
236//=======================================================================
237
238const TopoDS_Vertex& BRepLib_MakePolygon::FirstVertex()const
239{
240 return myFirstVertex;
241}
242
243
244//=======================================================================
245//function : LastVertex
246//purpose :
247//=======================================================================
248
249const TopoDS_Vertex& BRepLib_MakePolygon::LastVertex()const
250{
251 return myLastVertex;
252}
253
254//=======================================================================
255//function : Edge
256//purpose :
257//=======================================================================
258
259const TopoDS_Edge& BRepLib_MakePolygon::Edge()const
260{
261 return myEdge;
262}
263
264//=======================================================================
265//function : Wire
266//purpose :
267//=======================================================================
268
269const TopoDS_Wire& BRepLib_MakePolygon::Wire()const
270{
271 return TopoDS::Wire(Shape());
272}
273
274//=======================================================================
275//function : operator
276//purpose :
277//=======================================================================
278
279BRepLib_MakePolygon::operator TopoDS_Edge() const
280{
281 return Edge();
282}
283
284//=======================================================================
285//function : operator
286//purpose :
287//=======================================================================
288
289BRepLib_MakePolygon::operator TopoDS_Wire() const
290{
291 return Wire();
292}
293
294
295