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 IntRes2d_IntersectionPoint& Point)
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 ;
51 myBefore = TopAbs_UNKNOWN ;
52 myAfter = TopAbs_UNKNOWN ;
53 mySegBeg = Standard_False ;
54 mySegEnd = Standard_False ;
58 //=======================================================================
59 // Function : AddPoint
60 // Purpose : Adds a point on element to the point.
61 //=======================================================================
63 void HatchGen_PointOnHatching::AddPoint (const HatchGen_PointOnElement& Point,
64 const Standard_Real Confusion)
66 Standard_Integer NbPnt = myPoints.Length() ;
67 // for (Standard_Integer IPnt = 1 ;
68 Standard_Integer IPnt;
70 IPnt <= NbPnt && myPoints(IPnt).IsDifferent (Point, Confusion) ;
72 if (IPnt > NbPnt) myPoints.Append (Point) ;
75 //=======================================================================
76 // Function : NbPoints
77 // Purpose : Returns the number of elements intersecting the hatching at
79 //=======================================================================
81 Standard_Integer HatchGen_PointOnHatching::NbPoints () const
83 return myPoints.Length() ;
86 //=======================================================================
88 // Purpose : Returns the Index-th point on element of the point.
89 //=======================================================================
91 const HatchGen_PointOnElement& HatchGen_PointOnHatching::Point (const Standard_Integer Index) const
93 #if RAISE_IF_NOSUCHOBJECT
94 Standard_Integer NbPnt = myPoints.Length() ;
95 Standard_OutOfRange_Raise_if (Index < 1 || Index > NbPnt, "") ;
97 const HatchGen_PointOnElement& Point = myPoints.Value (Index) ;
101 //=======================================================================
102 // Function : RemPoint
103 // Purpose : Removes the Index-th point on element of the point..
104 //=======================================================================
106 void HatchGen_PointOnHatching::RemPoint (const Standard_Integer Index)
108 #if RAISE_IF_NOSUCHOBJECT
109 Standard_Integer NbPnt = myPoints.Length() ;
110 Standard_OutOfRange_Raise_if (Index < 1 || Index > NbPnt, "") ;
112 myPoints.Remove (Index) ;
115 //=======================================================================
116 // Function : ClrPoints
117 // Purpose : Removes all the points on element of the point.
118 //=======================================================================
120 void HatchGen_PointOnHatching::ClrPoints ()
125 //=======================================================================
126 // Function : IsLower
127 // Purpose : Tests if the point is lower than an other.
128 //=======================================================================
130 Standard_Boolean HatchGen_PointOnHatching::IsLower (const HatchGen_PointOnHatching& Point,
131 const Standard_Real Confusion) const
133 return (Point.myParam - myParam > Confusion) ;
136 //=======================================================================
137 // Function : IsEqual
138 // Purpose : Tests if the point is equal to an other.
139 //=======================================================================
141 Standard_Boolean HatchGen_PointOnHatching::IsEqual (const HatchGen_PointOnHatching& Point,
142 const Standard_Real Confusion) const
144 return (Abs (Point.myParam - myParam) <= Confusion) ;
147 //=======================================================================
148 // Function : IsGreater
149 // Purpose : Tests if the point is greater than an other.
150 //=======================================================================
152 Standard_Boolean HatchGen_PointOnHatching::IsGreater (const HatchGen_PointOnHatching& Point,
153 const Standard_Real Confusion) const
155 return (myParam - Point.myParam > Confusion) ;
158 //=======================================================================
160 // Purpose : Dump of the point.
161 //=======================================================================
163 void HatchGen_PointOnHatching::Dump (const Standard_Integer Index) const
165 std::cout << "--- Point on hatching " ;
167 std::cout << "# " << std::setw(3) << Index << " " ;
169 std::cout << "------" ;
171 std::cout << "------------------" << std::endl ;
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 = " ;
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 ;
182 std::cout << std::endl ;
183 std::cout << " State Before = " ;
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 ;
190 std::cout << std::endl ;
191 std::cout << " State After = " ;
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 ;
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 ;
202 Standard_Integer NbPnt = myPoints.Length () ;
204 std::cout << " No points on element" << std::endl ;
206 std::cout << " Contains " << NbPnt << " points on element" << std::endl ;
207 for (Standard_Integer IPnt = 1 ; IPnt <= NbPnt ; IPnt++) {
208 const HatchGen_PointOnElement& Point = myPoints.Value (IPnt) ;
213 std::cout << "----------------------------------------------" << std::endl ;