1 // Created on: 1993-11-03
2 // Created by: Jean Marc LACHAUME
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Geom2dAdaptor_Curve.hxx>
19 #include <Geom2dHatch_Hatching.hxx>
20 #include <gp_Pnt2d.hxx>
21 #include <HatchGen_Domain.hxx>
22 #include <HatchGen_PointOnElement.hxx>
23 #include <HatchGen_PointOnHatching.hxx>
24 #include <Standard_OutOfRange.hxx>
26 #define RAISE_IF_NOSUCHOBJECT 0
28 #include <Precision.hxx>
29 //=======================================================================
30 // Function : Geom2dHatch_Hatching
31 // Purpose : Constructor.
32 //=======================================================================
34 Geom2dHatch_Hatching::Geom2dHatch_Hatching () {
37 //=======================================================================
38 // Function : Geom2dHatch_Hatching
39 // Purpose : Constructor.
40 //=======================================================================
42 Geom2dHatch_Hatching::Geom2dHatch_Hatching (const Geom2dAdaptor_Curve& Curve) :
44 myTrimDone (Standard_False),
45 myTrimFailed (Standard_False),
46 myIsDone (Standard_False),
47 myStatus (HatchGen_NoProblem)
51 //=======================================================================
53 // Purpose : Returns the curve associated to the hatching.
54 //=======================================================================
56 const Geom2dAdaptor_Curve& Geom2dHatch_Hatching::Curve () const
61 //=======================================================================
62 // Function : ChangeCurve
63 // Purpose : Returns the curve associated to the hatching.
64 //=======================================================================
66 Geom2dAdaptor_Curve& Geom2dHatch_Hatching::ChangeCurve ()
71 //=======================================================================
72 // Function : TrimDone
73 // Purpose : Sets the flag about the trimmings computation to the given
75 //=======================================================================
77 void Geom2dHatch_Hatching::TrimDone (const Standard_Boolean Flag)
82 //=======================================================================
83 // Function : TrimDone
84 // Purpose : Returns the flag about the trimmings computation.
85 //=======================================================================
87 Standard_Boolean Geom2dHatch_Hatching::TrimDone () const
92 //=======================================================================
93 // Function : TrimFailed
94 // Purpose : Sets the flag about the trimmings failure to the given
96 //=======================================================================
98 void Geom2dHatch_Hatching::TrimFailed (const Standard_Boolean Flag)
100 myTrimFailed = Flag ;
101 if (myTrimFailed) myStatus = HatchGen_TrimFailure ;
104 //=======================================================================
105 // Function : TrimFailed
106 // Purpose : Returns the flag about the trimmings failure.
107 //=======================================================================
109 Standard_Boolean Geom2dHatch_Hatching::TrimFailed () const
111 return myTrimFailed ;
114 //=======================================================================
116 // Purpose : Sets the flag about the domains computation to the given
118 //=======================================================================
120 void Geom2dHatch_Hatching::IsDone (const Standard_Boolean Flag)
125 //=======================================================================
127 // Purpose : Returns the flag about the domains computation.
128 //=======================================================================
130 Standard_Boolean Geom2dHatch_Hatching::IsDone () const
135 //=======================================================================
136 // Function : SetStatus
137 // Purpose : Sets the error status.
138 //=======================================================================
140 void Geom2dHatch_Hatching::Status (const HatchGen_ErrorStatus Status)
145 //=======================================================================
147 // Purpose : Returns the error status.
148 //=======================================================================
150 HatchGen_ErrorStatus Geom2dHatch_Hatching::Status () const
155 //=======================================================================
156 // Function : AddPoint
157 // Purpose : Adds an intersection point to the hatching.
158 //=======================================================================
160 void Geom2dHatch_Hatching::AddPoint (const HatchGen_PointOnHatching& Point,
161 const Standard_Real Confusion)
163 Standard_Integer NbPoints = myPoints.Length () ;
164 //for (Standard_Integer IPntH = 1 ; IPntH <= NbPoints ; IPntH++) {
165 Standard_Integer IPntH;
166 for (IPntH = 1 ; IPntH <= NbPoints ; IPntH++) {
167 const HatchGen_PointOnHatching& PntH = myPoints.Value (IPntH) ;
168 if (!PntH.IsLower (Point, Confusion)) break ;
170 if (IPntH > NbPoints) {
171 myPoints.Append (Point) ;
173 HatchGen_PointOnHatching& PntH = myPoints.ChangeValue (IPntH) ;
174 if (PntH.IsGreater (Point, Confusion)) {
175 myPoints.InsertBefore (IPntH, Point) ;
177 for (Standard_Integer IPntE = 1 ; IPntE <= Point.NbPoints() ; IPntE++) {
178 const HatchGen_PointOnElement& PntE = Point.Point (IPntE) ;
179 PntH.AddPoint (PntE, Confusion) ;
183 if (myIsDone) ClrDomains() ;
186 //=======================================================================
187 // Function : NbPoints
188 // Purpose : Returns the number of intersection points on the hatching.
189 //=======================================================================
191 Standard_Integer Geom2dHatch_Hatching::NbPoints () const
193 return myPoints.Length () ;
196 //=======================================================================
198 // Purpose : Returns the Index-th intersection point on the hatching.
199 //=======================================================================
201 const HatchGen_PointOnHatching& Geom2dHatch_Hatching::Point (const Standard_Integer Index) const
203 #if RAISE_IF_NOSUCHOBJECT
204 Standard_Integer NbPoints = myPoints.Length () ;
205 Standard_OutOfRange_Raise_if (Index < 1 || Index > NbPoints, "") ;
207 const HatchGen_PointOnHatching& Point = myPoints.Value (Index) ;
211 //=======================================================================
212 // Function : ChangePoint
213 // Purpose : Returns the Index-th intersection point on the hatching.
214 //=======================================================================
216 HatchGen_PointOnHatching& Geom2dHatch_Hatching::ChangePoint (const Standard_Integer Index)
218 #if RAISE_IF_NOSUCHOBJECT
219 Standard_Integer NbPoints = myPoints.Length () ;
220 Standard_OutOfRange_Raise_if (Index < 1 || Index > NbPoints, "") ;
222 HatchGen_PointOnHatching& Point = myPoints.ChangeValue (Index) ;
226 //=======================================================================
227 // Function : RemPoint
228 // Purpose : Removes the Index-th intersection point of the hatching.
229 //=======================================================================
231 void Geom2dHatch_Hatching::RemPoint (const Standard_Integer Index)
233 #if RAISE_IF_NOSUCHOBJECT
234 Standard_Integer NbPoints = myPoints.Length () ;
235 Standard_OutOfRange_Raise_if (Index < 1 || Index > NbPoints, "") ;
237 if (myIsDone) ClrDomains() ;
238 myPoints.Remove (Index) ;
241 //=======================================================================
242 // Function : ClrPoints
243 // Purpose : Removes all the intersection points of the hatching.
244 //=======================================================================
246 void Geom2dHatch_Hatching::ClrPoints ()
248 if (myIsDone) ClrDomains() ;
249 for (Standard_Integer IPntH = 1 ; IPntH <= myPoints.Length() ; IPntH++) {
250 HatchGen_PointOnHatching& Point = myPoints.ChangeValue (IPntH) ;
254 myTrimDone = Standard_False ;
255 myTrimFailed = Standard_False ;
258 //=======================================================================
259 // Function : AddDomain
260 // Purpose : Adds a domain to the hatching.
261 //=======================================================================
263 void Geom2dHatch_Hatching::AddDomain (const HatchGen_Domain& Domain)
265 myDomains.Append (Domain) ;
268 //=======================================================================
269 // Function : NbDomains
270 // Purpose : Returns the number of domains on the hatching.
271 //=======================================================================
273 Standard_Integer Geom2dHatch_Hatching::NbDomains () const
275 return myDomains.Length () ;
278 //=======================================================================
280 // Purpose : Returns the Index-th domain on the hatching.
281 //=======================================================================
283 const HatchGen_Domain& Geom2dHatch_Hatching::Domain (const Standard_Integer Index) const
285 #if RAISE_IF_NOSUCHOBJECT
286 Standard_Integer NbDomains = myDomains.Length () ;
287 Standard_OutOfRange_Raise_if (Index < 1 || Index > NbDomains, "") ;
289 const HatchGen_Domain& Domain = myDomains.Value (Index) ;
293 //=======================================================================
294 // Function : RemDomain
295 // Purpose : Removes the Index-th domain of the hatching.
296 //=======================================================================
298 void Geom2dHatch_Hatching::RemDomain (const Standard_Integer Index)
300 #if RAISE_IF_NOSUCHOBJECT
301 Standard_Integer NbDomains = myDomains.Length () ;
302 Standard_OutOfRange_Raise_if (Index < 1 || Index > NbDomains, "") ;
304 myDomains.Remove (Index) ;
307 //=======================================================================
308 // Function : ClrDomains
309 // Purpose : Removes all the domains of the hatching.
310 //=======================================================================
312 void Geom2dHatch_Hatching::ClrDomains ()
315 myIsDone = Standard_False ;
318 //=======================================================================
319 // Function : ClassificationPoint
320 // Purpose : returns a 2d point on the curve
321 //=======================================================================
322 gp_Pnt2d Geom2dHatch_Hatching::ClassificationPoint () const {
324 a = myCurve.FirstParameter();
325 b = myCurve.LastParameter();
326 if(b >= Precision::Infinite()) {
327 if(a <= -Precision::Infinite()) {
337 return(myCurve.Value(t));