0026377: Passing Handle objects as arguments to functions as non-const reference...
[occt.git] / src / HatchGen / HatchGen_PointOnHatching.cxx
CommitLineData
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
31HatchGen_PointOnHatching::HatchGen_PointOnHatching () :
32 HatchGen_IntersectionPoint () ,
33 myPoints ()
34{
35}
36
37//=======================================================================
38// Function : HatchGen_PointOnHatching
39// Purpose : Constructor.
40//=======================================================================
41
42HatchGen_PointOnHatching::HatchGen_PointOnHatching (const HatchGen_PointOnHatching& Point)
43{
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 ;
52}
53
54//=======================================================================
55// Function : HatchGen_PointOnHatching
56// Purpose : Constructor.
57//=======================================================================
58
59HatchGen_PointOnHatching::HatchGen_PointOnHatching (const IntRes2d_IntersectionPoint& Point)
60{
61 myIndex = 0 ;
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 ;
67 }
68 myBefore = TopAbs_UNKNOWN ;
69 myAfter = TopAbs_UNKNOWN ;
70 mySegBeg = Standard_False ;
71 mySegEnd = Standard_False ;
72 myPoints.Clear() ;
73}
74
7fd59977 75//=======================================================================
76// Function : AddPoint
77// Purpose : Adds a point on element to the point.
78//=======================================================================
79
80void HatchGen_PointOnHatching::AddPoint (const HatchGen_PointOnElement& Point,
81 const Standard_Real Confusion)
82{
83 Standard_Integer NbPnt = myPoints.Length() ;
84 // for (Standard_Integer IPnt = 1 ;
85 Standard_Integer IPnt;
86 for ( IPnt = 1 ;
87 IPnt <= NbPnt && myPoints(IPnt).IsDifferent (Point, Confusion) ;
88 IPnt++) ;
89 if (IPnt > NbPnt) myPoints.Append (Point) ;
90}
91
7fd59977 92//=======================================================================
93// Function : NbPoints
94// Purpose : Returns the number of elements intersecting the hatching at
95// this point.
96//=======================================================================
97
98Standard_Integer HatchGen_PointOnHatching::NbPoints () const
99{
100 return myPoints.Length() ;
101}
102
103//=======================================================================
104// Function : Point
105// Purpose : Returns the Index-th point on element of the point.
106//=======================================================================
107
108const HatchGen_PointOnElement& HatchGen_PointOnHatching::Point (const Standard_Integer Index) const
109{
110#if RAISE_IF_NOSUCHOBJECT
111 Standard_Integer NbPnt = myPoints.Length() ;
112 Standard_OutOfRange_Raise_if (Index < 1 || Index > NbPnt, "") ;
113#endif
114 const HatchGen_PointOnElement& Point = myPoints.Value (Index) ;
115 return Point ;
116}
117
118//=======================================================================
119// Function : RemPoint
120// Purpose : Removes the Index-th point on element of the point..
121//=======================================================================
122
123void HatchGen_PointOnHatching::RemPoint (const Standard_Integer Index)
124{
125#if RAISE_IF_NOSUCHOBJECT
126 Standard_Integer NbPnt = myPoints.Length() ;
127 Standard_OutOfRange_Raise_if (Index < 1 || Index > NbPnt, "") ;
128#endif
129 myPoints.Remove (Index) ;
130}
131
132//=======================================================================
133// Function : ClrPoints
134// Purpose : Removes all the points on element of the point.
135//=======================================================================
136
137void HatchGen_PointOnHatching::ClrPoints ()
138{
139 myPoints.Clear() ;
140}
141
142//=======================================================================
143// Function : IsLower
144// Purpose : Tests if the point is lower than an other.
145//=======================================================================
146
147Standard_Boolean HatchGen_PointOnHatching::IsLower (const HatchGen_PointOnHatching& Point,
148 const Standard_Real Confusion) const
149{
150 return (Point.myParam - myParam > Confusion) ;
151}
152
153//=======================================================================
154// Function : IsEqual
155// Purpose : Tests if the point is equal to an other.
156//=======================================================================
157
158Standard_Boolean HatchGen_PointOnHatching::IsEqual (const HatchGen_PointOnHatching& Point,
159 const Standard_Real Confusion) const
160{
161 return (Abs (Point.myParam - myParam) <= Confusion) ;
162}
163
164//=======================================================================
165// Function : IsGreater
166// Purpose : Tests if the point is greater than an other.
167//=======================================================================
168
169Standard_Boolean HatchGen_PointOnHatching::IsGreater (const HatchGen_PointOnHatching& Point,
170 const Standard_Real Confusion) const
171{
172 return (myParam - Point.myParam > Confusion) ;
173}
174
175//=======================================================================
176// Function : Dump
177// Purpose : Dump of the point.
178//=======================================================================
179
180void HatchGen_PointOnHatching::Dump (const Standard_Integer Index) const
181{
182 cout << "--- Point on hatching " ;
183 if (Index > 0) {
184 cout << "# " << setw(3) << Index << " " ;
185 } else {
186 cout << "------" ;
187 }
188 cout << "------------------" << endl ;
189
190 cout << " Index of the hatching = " << myIndex << endl ;
191 cout << " Parameter on hatching = " << myParam << endl ;
192 cout << " Position on hatching = " ;
193 switch (myPosit) {
194 case TopAbs_FORWARD : cout << "FORWARD (i.e. BEGIN )" ; break ;
195 case TopAbs_INTERNAL : cout << "INTERNAL (i.e. MIDDLE )" ; break ;
196 case TopAbs_REVERSED : cout << "REVERSED (i.e. END )" ; break ;
197 case TopAbs_EXTERNAL : cout << "EXTERNAL (i.e. UNKNOWN)" ; break ;
198 }
199 cout << endl ;
200 cout << " State Before = " ;
201 switch (myBefore) {
202 case TopAbs_IN : cout << "IN" ; break ;
203 case TopAbs_OUT : cout << "OUT" ; break ;
204 case TopAbs_ON : cout << "ON" ; break ;
205 case TopAbs_UNKNOWN : cout << "UNKNOWN" ; break ;
206 }
207 cout << endl ;
208 cout << " State After = " ;
209 switch (myAfter) {
210 case TopAbs_IN : cout << "IN" ; break ;
211 case TopAbs_OUT : cout << "OUT" ; break ;
212 case TopAbs_ON : cout << "ON" ; break ;
213 case TopAbs_UNKNOWN : cout << "UNKNOWN" ; break ;
214 }
215 cout << endl ;
216 cout << " Beginning of segment = " << (mySegBeg ? "TRUE" : "FALSE") << endl ;
217 cout << " End of segment = " << (mySegEnd ? "TRUE" : "FALSE") << endl ;
218
219 Standard_Integer NbPnt = myPoints.Length () ;
220 if (NbPnt == 0) {
221 cout << " No points on element" << endl ;
222 } else {
223 cout << " Contains " << NbPnt << " points on element" << endl ;
224 for (Standard_Integer IPnt = 1 ; IPnt <= NbPnt ; IPnt++) {
225 const HatchGen_PointOnElement& Point = myPoints.Value (IPnt) ;
226 Point.Dump (IPnt) ;
227 }
228 }
229
230 cout << "----------------------------------------------" << endl ;
231}