1 // Created on: 1993-10-29
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 <HatchGen_PointOnElement.hxx>
19 #include <HatchGen_PointOnHatching.hxx>
20 #include <IntRes2d_IntersectionPoint.hxx>
21 #include <Standard_OutOfRange.hxx>
22 #include <Standard_Stream.hxx>
24 #define RAISE_IF_NOSUCHOBJECT 0
26 //=======================================================================
27 // Function : HatchGen_PointOnHatching
28 // Purpose : Constructor.
29 //=======================================================================
31 HatchGen_PointOnHatching::HatchGen_PointOnHatching () :
32 HatchGen_IntersectionPoint () ,
37 //=======================================================================
38 // Function : HatchGen_PointOnHatching
39 // Purpose : Constructor.
40 //=======================================================================
42 HatchGen_PointOnHatching::HatchGen_PointOnHatching (const HatchGen_PointOnHatching& Point)
44 myIndex = Point.myIndex ;
45 myParam = Point.myParam ;
46 myPosit = Point.myPosit ;
47 myBefore = Point.myBefore ;
48 myAfter = Point.myAfter ;
49 mySegBeg = Point.mySegBeg ;
50 mySegEnd = Point.mySegEnd ;
51 myPoints = Point.myPoints ;
54 //=======================================================================
55 // Function : HatchGen_PointOnHatching
56 // Purpose : Constructor.
57 //=======================================================================
59 HatchGen_PointOnHatching::HatchGen_PointOnHatching (const IntRes2d_IntersectionPoint& Point)
62 myParam = Point.ParamOnFirst() ;
63 switch (Point.TransitionOfFirst().PositionOnCurve()) {
64 case IntRes2d_Head : myPosit = TopAbs_FORWARD ; break ;
65 case IntRes2d_Middle : myPosit = TopAbs_INTERNAL ; break ;
66 case IntRes2d_End : myPosit = TopAbs_REVERSED ; break ;
68 myBefore = TopAbs_UNKNOWN ;
69 myAfter = TopAbs_UNKNOWN ;
70 mySegBeg = Standard_False ;
71 mySegEnd = Standard_False ;
75 //=======================================================================
76 // Function : AddPoint
77 // Purpose : Adds a point on element to the point.
78 //=======================================================================
80 void HatchGen_PointOnHatching::AddPoint (const HatchGen_PointOnElement& Point,
81 const Standard_Real Confusion)
83 Standard_Integer NbPnt = myPoints.Length() ;
84 // for (Standard_Integer IPnt = 1 ;
85 Standard_Integer IPnt;
87 IPnt <= NbPnt && myPoints(IPnt).IsDifferent (Point, Confusion) ;
89 if (IPnt > NbPnt) myPoints.Append (Point) ;
92 //=======================================================================
93 // Function : NbPoints
94 // Purpose : Returns the number of elements intersecting the hatching at
96 //=======================================================================
98 Standard_Integer HatchGen_PointOnHatching::NbPoints () const
100 return myPoints.Length() ;
103 //=======================================================================
105 // Purpose : Returns the Index-th point on element of the point.
106 //=======================================================================
108 const HatchGen_PointOnElement& HatchGen_PointOnHatching::Point (const Standard_Integer Index) const
110 #if RAISE_IF_NOSUCHOBJECT
111 Standard_Integer NbPnt = myPoints.Length() ;
112 Standard_OutOfRange_Raise_if (Index < 1 || Index > NbPnt, "") ;
114 const HatchGen_PointOnElement& Point = myPoints.Value (Index) ;
118 //=======================================================================
119 // Function : RemPoint
120 // Purpose : Removes the Index-th point on element of the point..
121 //=======================================================================
123 void HatchGen_PointOnHatching::RemPoint (const Standard_Integer Index)
125 #if RAISE_IF_NOSUCHOBJECT
126 Standard_Integer NbPnt = myPoints.Length() ;
127 Standard_OutOfRange_Raise_if (Index < 1 || Index > NbPnt, "") ;
129 myPoints.Remove (Index) ;
132 //=======================================================================
133 // Function : ClrPoints
134 // Purpose : Removes all the points on element of the point.
135 //=======================================================================
137 void HatchGen_PointOnHatching::ClrPoints ()
142 //=======================================================================
143 // Function : IsLower
144 // Purpose : Tests if the point is lower than an other.
145 //=======================================================================
147 Standard_Boolean HatchGen_PointOnHatching::IsLower (const HatchGen_PointOnHatching& Point,
148 const Standard_Real Confusion) const
150 return (Point.myParam - myParam > Confusion) ;
153 //=======================================================================
154 // Function : IsEqual
155 // Purpose : Tests if the point is equal to an other.
156 //=======================================================================
158 Standard_Boolean HatchGen_PointOnHatching::IsEqual (const HatchGen_PointOnHatching& Point,
159 const Standard_Real Confusion) const
161 return (Abs (Point.myParam - myParam) <= Confusion) ;
164 //=======================================================================
165 // Function : IsGreater
166 // Purpose : Tests if the point is greater than an other.
167 //=======================================================================
169 Standard_Boolean HatchGen_PointOnHatching::IsGreater (const HatchGen_PointOnHatching& Point,
170 const Standard_Real Confusion) const
172 return (myParam - Point.myParam > Confusion) ;
175 //=======================================================================
177 // Purpose : Dump of the point.
178 //=======================================================================
180 void HatchGen_PointOnHatching::Dump (const Standard_Integer Index) const
182 std::cout << "--- Point on hatching " ;
184 std::cout << "# " << std::setw(3) << Index << " " ;
186 std::cout << "------" ;
188 std::cout << "------------------" << std::endl ;
190 std::cout << " Index of the hatching = " << myIndex << std::endl ;
191 std::cout << " Parameter on hatching = " << myParam << std::endl ;
192 std::cout << " Position on hatching = " ;
194 case TopAbs_FORWARD : std::cout << "FORWARD (i.e. BEGIN )" ; break ;
195 case TopAbs_INTERNAL : std::cout << "INTERNAL (i.e. MIDDLE )" ; break ;
196 case TopAbs_REVERSED : std::cout << "REVERSED (i.e. END )" ; break ;
197 case TopAbs_EXTERNAL : std::cout << "EXTERNAL (i.e. UNKNOWN)" ; break ;
199 std::cout << std::endl ;
200 std::cout << " State Before = " ;
202 case TopAbs_IN : std::cout << "IN" ; break ;
203 case TopAbs_OUT : std::cout << "OUT" ; break ;
204 case TopAbs_ON : std::cout << "ON" ; break ;
205 case TopAbs_UNKNOWN : std::cout << "UNKNOWN" ; break ;
207 std::cout << std::endl ;
208 std::cout << " State After = " ;
210 case TopAbs_IN : std::cout << "IN" ; break ;
211 case TopAbs_OUT : std::cout << "OUT" ; break ;
212 case TopAbs_ON : std::cout << "ON" ; break ;
213 case TopAbs_UNKNOWN : std::cout << "UNKNOWN" ; break ;
215 std::cout << std::endl ;
216 std::cout << " Beginning of segment = " << (mySegBeg ? "TRUE" : "FALSE") << std::endl ;
217 std::cout << " End of segment = " << (mySegEnd ? "TRUE" : "FALSE") << std::endl ;
219 Standard_Integer NbPnt = myPoints.Length () ;
221 std::cout << " No points on element" << std::endl ;
223 std::cout << " Contains " << NbPnt << " points on element" << std::endl ;
224 for (Standard_Integer IPnt = 1 ; IPnt <= NbPnt ; IPnt++) {
225 const HatchGen_PointOnElement& Point = myPoints.Value (IPnt) ;
230 std::cout << "----------------------------------------------" << std::endl ;