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