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