b311480e |
1 | // Created on: 1993-10-29 |
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 | // |
d5f74e42 |
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 |
973c2be1 |
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 | |
42cf5bc1 |
17 | |
18 | #include <HatchGen_PointOnElement.hxx> |
19 | #include <HatchGen_PointOnHatching.hxx> |
20 | #include <IntRes2d_IntersectionPoint.hxx> |
21 | #include <Standard_OutOfRange.hxx> |
7fd59977 |
22 | #include <Standard_Stream.hxx> |
7fd59977 |
23 | |
24 | #define RAISE_IF_NOSUCHOBJECT 0 |
25 | |
26 | //======================================================================= |
27 | // Function : HatchGen_PointOnHatching |
28 | // Purpose : Constructor. |
29 | //======================================================================= |
30 | |
31 | HatchGen_PointOnHatching::HatchGen_PointOnHatching () : |
32 | HatchGen_IntersectionPoint () , |
33 | myPoints () |
34 | { |
35 | } |
36 | |
37 | //======================================================================= |
38 | // Function : HatchGen_PointOnHatching |
39 | // Purpose : Constructor. |
40 | //======================================================================= |
41 | |
7fd59977 |
42 | HatchGen_PointOnHatching::HatchGen_PointOnHatching (const IntRes2d_IntersectionPoint& Point) |
43 | { |
44 | myIndex = 0 ; |
45 | myParam = Point.ParamOnFirst() ; |
46 | switch (Point.TransitionOfFirst().PositionOnCurve()) { |
47 | case IntRes2d_Head : myPosit = TopAbs_FORWARD ; break ; |
48 | case IntRes2d_Middle : myPosit = TopAbs_INTERNAL ; break ; |
49 | case IntRes2d_End : myPosit = TopAbs_REVERSED ; break ; |
50 | } |
51 | myBefore = TopAbs_UNKNOWN ; |
52 | myAfter = TopAbs_UNKNOWN ; |
53 | mySegBeg = Standard_False ; |
54 | mySegEnd = Standard_False ; |
55 | myPoints.Clear() ; |
56 | } |
57 | |
7fd59977 |
58 | //======================================================================= |
59 | // Function : AddPoint |
60 | // Purpose : Adds a point on element to the point. |
61 | //======================================================================= |
62 | |
63 | void HatchGen_PointOnHatching::AddPoint (const HatchGen_PointOnElement& Point, |
64 | const Standard_Real Confusion) |
65 | { |
66 | Standard_Integer NbPnt = myPoints.Length() ; |
67 | // for (Standard_Integer IPnt = 1 ; |
68 | Standard_Integer IPnt; |
69 | for ( IPnt = 1 ; |
70 | IPnt <= NbPnt && myPoints(IPnt).IsDifferent (Point, Confusion) ; |
71 | IPnt++) ; |
72 | if (IPnt > NbPnt) myPoints.Append (Point) ; |
73 | } |
74 | |
7fd59977 |
75 | //======================================================================= |
76 | // Function : NbPoints |
77 | // Purpose : Returns the number of elements intersecting the hatching at |
78 | // this point. |
79 | //======================================================================= |
80 | |
81 | Standard_Integer HatchGen_PointOnHatching::NbPoints () const |
82 | { |
83 | return myPoints.Length() ; |
84 | } |
85 | |
86 | //======================================================================= |
87 | // Function : Point |
88 | // Purpose : Returns the Index-th point on element of the point. |
89 | //======================================================================= |
90 | |
91 | const HatchGen_PointOnElement& HatchGen_PointOnHatching::Point (const Standard_Integer Index) const |
92 | { |
93 | #if RAISE_IF_NOSUCHOBJECT |
94 | Standard_Integer NbPnt = myPoints.Length() ; |
95 | Standard_OutOfRange_Raise_if (Index < 1 || Index > NbPnt, "") ; |
96 | #endif |
97 | const HatchGen_PointOnElement& Point = myPoints.Value (Index) ; |
98 | return Point ; |
99 | } |
100 | |
101 | //======================================================================= |
102 | // Function : RemPoint |
103 | // Purpose : Removes the Index-th point on element of the point.. |
104 | //======================================================================= |
105 | |
106 | void HatchGen_PointOnHatching::RemPoint (const Standard_Integer Index) |
107 | { |
108 | #if RAISE_IF_NOSUCHOBJECT |
109 | Standard_Integer NbPnt = myPoints.Length() ; |
110 | Standard_OutOfRange_Raise_if (Index < 1 || Index > NbPnt, "") ; |
111 | #endif |
112 | myPoints.Remove (Index) ; |
113 | } |
114 | |
115 | //======================================================================= |
116 | // Function : ClrPoints |
117 | // Purpose : Removes all the points on element of the point. |
118 | //======================================================================= |
119 | |
120 | void HatchGen_PointOnHatching::ClrPoints () |
121 | { |
122 | myPoints.Clear() ; |
123 | } |
124 | |
125 | //======================================================================= |
126 | // Function : IsLower |
127 | // Purpose : Tests if the point is lower than an other. |
128 | //======================================================================= |
129 | |
130 | Standard_Boolean HatchGen_PointOnHatching::IsLower (const HatchGen_PointOnHatching& Point, |
131 | const Standard_Real Confusion) const |
132 | { |
133 | return (Point.myParam - myParam > Confusion) ; |
134 | } |
135 | |
136 | //======================================================================= |
137 | // Function : IsEqual |
138 | // Purpose : Tests if the point is equal to an other. |
139 | //======================================================================= |
140 | |
141 | Standard_Boolean HatchGen_PointOnHatching::IsEqual (const HatchGen_PointOnHatching& Point, |
142 | const Standard_Real Confusion) const |
143 | { |
144 | return (Abs (Point.myParam - myParam) <= Confusion) ; |
145 | } |
146 | |
147 | //======================================================================= |
148 | // Function : IsGreater |
149 | // Purpose : Tests if the point is greater than an other. |
150 | //======================================================================= |
151 | |
152 | Standard_Boolean HatchGen_PointOnHatching::IsGreater (const HatchGen_PointOnHatching& Point, |
153 | const Standard_Real Confusion) const |
154 | { |
155 | return (myParam - Point.myParam > Confusion) ; |
156 | } |
157 | |
158 | //======================================================================= |
159 | // Function : Dump |
160 | // Purpose : Dump of the point. |
161 | //======================================================================= |
162 | |
163 | void HatchGen_PointOnHatching::Dump (const Standard_Integer Index) const |
164 | { |
04232180 |
165 | std::cout << "--- Point on hatching " ; |
7fd59977 |
166 | if (Index > 0) { |
04232180 |
167 | std::cout << "# " << std::setw(3) << Index << " " ; |
7fd59977 |
168 | } else { |
04232180 |
169 | std::cout << "------" ; |
7fd59977 |
170 | } |
04232180 |
171 | std::cout << "------------------" << std::endl ; |
7fd59977 |
172 | |
04232180 |
173 | std::cout << " Index of the hatching = " << myIndex << std::endl ; |
174 | std::cout << " Parameter on hatching = " << myParam << std::endl ; |
175 | std::cout << " Position on hatching = " ; |
7fd59977 |
176 | switch (myPosit) { |
04232180 |
177 | case TopAbs_FORWARD : std::cout << "FORWARD (i.e. BEGIN )" ; break ; |
178 | case TopAbs_INTERNAL : std::cout << "INTERNAL (i.e. MIDDLE )" ; break ; |
179 | case TopAbs_REVERSED : std::cout << "REVERSED (i.e. END )" ; break ; |
180 | case TopAbs_EXTERNAL : std::cout << "EXTERNAL (i.e. UNKNOWN)" ; break ; |
7fd59977 |
181 | } |
04232180 |
182 | std::cout << std::endl ; |
183 | std::cout << " State Before = " ; |
7fd59977 |
184 | switch (myBefore) { |
04232180 |
185 | case TopAbs_IN : std::cout << "IN" ; break ; |
186 | case TopAbs_OUT : std::cout << "OUT" ; break ; |
187 | case TopAbs_ON : std::cout << "ON" ; break ; |
188 | case TopAbs_UNKNOWN : std::cout << "UNKNOWN" ; break ; |
7fd59977 |
189 | } |
04232180 |
190 | std::cout << std::endl ; |
191 | std::cout << " State After = " ; |
7fd59977 |
192 | switch (myAfter) { |
04232180 |
193 | case TopAbs_IN : std::cout << "IN" ; break ; |
194 | case TopAbs_OUT : std::cout << "OUT" ; break ; |
195 | case TopAbs_ON : std::cout << "ON" ; break ; |
196 | case TopAbs_UNKNOWN : std::cout << "UNKNOWN" ; break ; |
7fd59977 |
197 | } |
04232180 |
198 | std::cout << std::endl ; |
199 | std::cout << " Beginning of segment = " << (mySegBeg ? "TRUE" : "FALSE") << std::endl ; |
200 | std::cout << " End of segment = " << (mySegEnd ? "TRUE" : "FALSE") << std::endl ; |
7fd59977 |
201 | |
202 | Standard_Integer NbPnt = myPoints.Length () ; |
203 | if (NbPnt == 0) { |
04232180 |
204 | std::cout << " No points on element" << std::endl ; |
7fd59977 |
205 | } else { |
04232180 |
206 | std::cout << " Contains " << NbPnt << " points on element" << std::endl ; |
7fd59977 |
207 | for (Standard_Integer IPnt = 1 ; IPnt <= NbPnt ; IPnt++) { |
208 | const HatchGen_PointOnElement& Point = myPoints.Value (IPnt) ; |
209 | Point.Dump (IPnt) ; |
210 | } |
211 | } |
212 | |
04232180 |
213 | std::cout << "----------------------------------------------" << std::endl ; |
7fd59977 |
214 | } |