0024428: Implementation of LGPL license
[occt.git] / src / HatchGen / HatchGen_HatchingGen.gxx
CommitLineData
b311480e 1// Created on: 1993-11-03
2// Created by: Jean Marc LACHAUME
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 <HatchGen_PointOnElement.hxx>
18
19#define RAISE_IF_NOSUCHOBJECT 0
20
21#include <Precision.hxx>
22//=======================================================================
23// Function : HatchGen_HatchingGen
24// Purpose : Constructor.
25//=======================================================================
26
27HatchGen_HatchingGen::HatchGen_HatchingGen () {
28}
29
30//=======================================================================
31// Function : HatchGen_HatchingGen
32// Purpose : Constructor.
33//=======================================================================
34
35HatchGen_HatchingGen::HatchGen_HatchingGen (const TheHatchingCurve& Curve) :
36 myCurve (Curve),
37 myTrimDone (Standard_False),
38 myTrimFailed (Standard_False),
39 myIsDone (Standard_False),
40 myStatus (HatchGen_NoProblem)
41{
42}
43
44//=======================================================================
45// Function : Curve
46// Purpose : Returns the curve associated to the hatching.
47//=======================================================================
48
49const TheHatchingCurve& HatchGen_HatchingGen::Curve () const
50{
51 return myCurve ;
52}
53
54//=======================================================================
55// Function : ChangeCurve
56// Purpose : Returns the curve associated to the hatching.
57//=======================================================================
58
59TheHatchingCurve& HatchGen_HatchingGen::ChangeCurve ()
60{
61 return myCurve ;
62}
63
64//=======================================================================
65// Function : TrimDone
66// Purpose : Sets the flag about the trimmings computation to the given
67// value.
68//=======================================================================
69
70void HatchGen_HatchingGen::TrimDone (const Standard_Boolean Flag)
71{
72 myTrimDone = Flag ;
73}
74
75//=======================================================================
76// Function : TrimDone
77// Purpose : Returns the flag about the trimmings computation.
78//=======================================================================
79
80Standard_Boolean HatchGen_HatchingGen::TrimDone () const
81{
82 return myTrimDone ;
83}
84
85//=======================================================================
86// Function : TrimFailed
87// Purpose : Sets the flag about the trimmings failure to the given
88// value.
89//=======================================================================
90
91void HatchGen_HatchingGen::TrimFailed (const Standard_Boolean Flag)
92{
93 myTrimFailed = Flag ;
94 if (myTrimFailed) myStatus = HatchGen_TrimFailure ;
95}
96
97//=======================================================================
98// Function : TrimFailed
99// Purpose : Returns the flag about the trimmings failure.
100//=======================================================================
101
102Standard_Boolean HatchGen_HatchingGen::TrimFailed () const
103{
104 return myTrimFailed ;
105}
106
107//=======================================================================
108// Function : IsDone
109// Purpose : Sets the flag about the domains computation to the given
110// value.
111//=======================================================================
112
113void HatchGen_HatchingGen::IsDone (const Standard_Boolean Flag)
114{
115 myIsDone = Flag ;
116}
117
118//=======================================================================
119// Function : IsDone
120// Purpose : Returns the flag about the domains computation.
121//=======================================================================
122
123Standard_Boolean HatchGen_HatchingGen::IsDone () const
124{
125 return myIsDone ;
126}
127
128//=======================================================================
129// Function : SetStatus
130// Purpose : Sets the error status.
131//=======================================================================
132
133void HatchGen_HatchingGen::Status (const HatchGen_ErrorStatus Status)
134{
135 myStatus = Status ;
136}
137
138//=======================================================================
139// Function : Status
140// Purpose : Returns the error status.
141//=======================================================================
142
143HatchGen_ErrorStatus HatchGen_HatchingGen::Status () const
144{
145 return myStatus ;
146}
147
148//=======================================================================
149// Function : AddPoint
150// Purpose : Adds an intersection point to the hatching.
151//=======================================================================
152
153void HatchGen_HatchingGen::AddPoint (const HatchGen_PointOnHatching& Point,
154 const Standard_Real Confusion)
155{
156 Standard_Integer NbPoints = myPoints.Length () ;
157//for (Standard_Integer IPntH = 1 ; IPntH <= NbPoints ; IPntH++) {
158 Standard_Integer IPntH;
159 for (IPntH = 1 ; IPntH <= NbPoints ; IPntH++) {
160 const HatchGen_PointOnHatching& PntH = myPoints.Value (IPntH) ;
161 if (!PntH.IsLower (Point, Confusion)) break ;
162 }
163 if (IPntH > NbPoints) {
164 myPoints.Append (Point) ;
165 } else {
166 HatchGen_PointOnHatching& PntH = myPoints.ChangeValue (IPntH) ;
167 if (PntH.IsGreater (Point, Confusion)) {
168 myPoints.InsertBefore (IPntH, Point) ;
169 } else {
170 for (Standard_Integer IPntE = 1 ; IPntE <= Point.NbPoints() ; IPntE++) {
171 const HatchGen_PointOnElement& PntE = Point.Point (IPntE) ;
172 PntH.AddPoint (PntE, Confusion) ;
173 }
174 }
175 }
176 if (myIsDone) ClrDomains() ;
177}
178
179//=======================================================================
180// Function : NbPoints
181// Purpose : Returns the number of intersection points on the hatching.
182//=======================================================================
183
184Standard_Integer HatchGen_HatchingGen::NbPoints () const
185{
186 return myPoints.Length () ;
187}
188
189//=======================================================================
190// Function : Point
191// Purpose : Returns the Index-th intersection point on the hatching.
192//=======================================================================
193
194const HatchGen_PointOnHatching& HatchGen_HatchingGen::Point (const Standard_Integer Index) const
195{
196#if RAISE_IF_NOSUCHOBJECT
197 Standard_Integer NbPoints = myPoints.Length () ;
198 Standard_OutOfRange_Raise_if (Index < 1 || Index > NbPoints, "") ;
199#endif
200 const HatchGen_PointOnHatching& Point = myPoints.Value (Index) ;
201 return Point ;
202}
203
204//=======================================================================
205// Function : ChangePoint
206// Purpose : Returns the Index-th intersection point on the hatching.
207//=======================================================================
208
209HatchGen_PointOnHatching& HatchGen_HatchingGen::ChangePoint (const Standard_Integer Index)
210{
211#if RAISE_IF_NOSUCHOBJECT
212 Standard_Integer NbPoints = myPoints.Length () ;
213 Standard_OutOfRange_Raise_if (Index < 1 || Index > NbPoints, "") ;
214#endif
215 HatchGen_PointOnHatching& Point = myPoints.ChangeValue (Index) ;
216 return Point ;
217}
218
219//=======================================================================
220// Function : RemPoint
221// Purpose : Removes the Index-th intersection point of the hatching.
222//=======================================================================
223
224void HatchGen_HatchingGen::RemPoint (const Standard_Integer Index)
225{
226#if RAISE_IF_NOSUCHOBJECT
227 Standard_Integer NbPoints = myPoints.Length () ;
228 Standard_OutOfRange_Raise_if (Index < 1 || Index > NbPoints, "") ;
229#endif
230 if (myIsDone) ClrDomains() ;
231 myPoints.Remove (Index) ;
232}
233
234//=======================================================================
235// Function : ClrPoints
236// Purpose : Removes all the intersection points of the hatching.
237//=======================================================================
238
239void HatchGen_HatchingGen::ClrPoints ()
240{
241 if (myIsDone) ClrDomains() ;
242 for (Standard_Integer IPntH = 1 ; IPntH <= myPoints.Length() ; IPntH++) {
243 HatchGen_PointOnHatching& Point = myPoints.ChangeValue (IPntH) ;
244 Point.ClrPoints() ;
245 }
246 myPoints.Clear () ;
247 myTrimDone = Standard_False ;
248 myTrimFailed = Standard_False ;
249}
250
251//=======================================================================
252// Function : AddDomain
253// Purpose : Adds a domain to the hatching.
254//=======================================================================
255
256void HatchGen_HatchingGen::AddDomain (const HatchGen_Domain& Domain)
257{
258 myDomains.Append (Domain) ;
259}
260
261//=======================================================================
262// Function : NbDomains
263// Purpose : Returns the number of domains on the hatching.
264//=======================================================================
265
266Standard_Integer HatchGen_HatchingGen::NbDomains () const
267{
268 return myDomains.Length () ;
269}
270
271//=======================================================================
272// Function : Domain
273// Purpose : Returns the Index-th domain on the hatching.
274//=======================================================================
275
276const HatchGen_Domain& HatchGen_HatchingGen::Domain (const Standard_Integer Index) const
277{
278#if RAISE_IF_NOSUCHOBJECT
279 Standard_Integer NbDomains = myDomains.Length () ;
280 Standard_OutOfRange_Raise_if (Index < 1 || Index > NbDomains, "") ;
281#endif
282 const HatchGen_Domain& Domain = myDomains.Value (Index) ;
283 return Domain ;
284}
285
286//=======================================================================
287// Function : RemDomain
288// Purpose : Removes the Index-th domain of the hatching.
289//=======================================================================
290
291void HatchGen_HatchingGen::RemDomain (const Standard_Integer Index)
292{
293#if RAISE_IF_NOSUCHOBJECT
294 Standard_Integer NbDomains = myDomains.Length () ;
295 Standard_OutOfRange_Raise_if (Index < 1 || Index > NbDomains, "") ;
296#endif
297 myDomains.Remove (Index) ;
298}
299
300//=======================================================================
301// Function : ClrDomains
302// Purpose : Removes all the domains of the hatching.
303//=======================================================================
304
305void HatchGen_HatchingGen::ClrDomains ()
306{
307 myDomains.Clear () ;
308 myIsDone = Standard_False ;
309}
310
311//=======================================================================
312// Function : ClassificationPoint
313// Purpose : returns a 2d point on the curve
314//=======================================================================
315gp_Pnt2d HatchGen_HatchingGen::ClassificationPoint () const {
316 Standard_Real t,a,b;
317 a = myCurve.FirstParameter();
318 b = myCurve.LastParameter();
319 if(b >= Precision::Infinite()) {
320 if(a <= -Precision::Infinite()) {
321 t=0;
322 }
323 else {
324 t = a;
325 }
326 }
327 else {
328 t = b;
329 }
330 return(myCurve.Value(t));
331}
332