1 // Created on: 1992-01-23
2 // Created by: Didier PIFFAULT
3 // Copyright (c) 1992-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.
20 #include <TopTrans_CurveTransition.hxx>
26 //=======================================================================
27 //function : TopTrans_CurveTransition
28 //purpose : Empty Constructor.
29 //=======================================================================
31 TopTrans_CurveTransition::TopTrans_CurveTransition ()
35 //=======================================================================
37 //purpose : Initializer for a complex curve transition with the elements
38 // of the intersecting curve.
39 //=======================================================================
41 void TopTrans_CurveTransition::Reset (const gp_Dir& Tgt,
43 const Standard_Real Curv)
45 myTgt=Tgt; myNorm=Norm; myCurv=Curv; Init=Standard_True;
48 //=======================================================================
50 //purpose : Initializer for a complex curve transition with the elements
51 // of the intersecting straight line.
52 //=======================================================================
54 void TopTrans_CurveTransition::Reset (const gp_Dir& Tgt)
56 myTgt=Tgt; myCurv=0.; Init=Standard_True;
59 //=======================================================================
61 //purpose : Compare the elements of an interference on an intersected
62 // curve with the interference stored in the complex Transition.
63 //=======================================================================
65 void TopTrans_CurveTransition::Compare (const Standard_Real Tole,
68 const Standard_Real C,
69 const TopAbs_Orientation St,
70 const TopAbs_Orientation Or)
72 // S is the transition, how the curve cross the boundary
73 // O is the orientation, how the intersection is set on the boundary
74 TopAbs_Orientation S = St;
75 TopAbs_Orientation O = Or;
77 // adjustment for INTERNAL transition
78 if (S == TopAbs_INTERNAL) {
80 S = TopAbs::Reverse(O);
85 // It is the first comparaison for this complex transition
97 // Interference en fin d'arete il faut inverser la tangente
98 case TopAbs_REVERSED :
102 case TopAbs_INTERNAL :
103 // Interference en milieu d'arete il faut inverser en fonction de la
104 // position de la tangente de reference
105 if (myTgt*T>0) TgtFirst.Reverse();
106 else TgtLast.Reverse();
108 case TopAbs_FORWARD :
109 case TopAbs_EXTERNAL :
114 // Compare with the existent first and last transition :
116 Standard_Boolean FirstSet=Standard_False;
117 Standard_Real cosAngWithT=myTgt*T;
119 case TopAbs_REVERSED :
120 cosAngWithT= -cosAngWithT;
122 case TopAbs_INTERNAL :
123 if (cosAngWithT>0) cosAngWithT=-cosAngWithT;
125 case TopAbs_FORWARD :
126 case TopAbs_EXTERNAL :
129 Standard_Real cosAngWith1=myTgt*TgtFirst;
131 switch (Compare(cosAngWithT, cosAngWith1, Tole)) {
134 // If the angle is greater than the first the new become the first
135 FirstSet=Standard_True;
138 case TopAbs_REVERSED :
141 case TopAbs_INTERNAL :
142 if (myTgt*T>0) TgtFirst.Reverse();
144 case TopAbs_FORWARD :
145 case TopAbs_EXTERNAL :
154 // If same angles we look at the Curvature
155 if (IsBefore(Tole, cosAngWithT, N, C, NormFirst, CurvFirst)) {
156 FirstSet=Standard_True;
159 case TopAbs_REVERSED :
162 case TopAbs_INTERNAL :
163 if (myTgt*T>0) TgtFirst.Reverse();
165 case TopAbs_FORWARD :
166 case TopAbs_EXTERNAL :
179 if (!FirstSet || O==TopAbs_INTERNAL) {
180 // Dans les cas de tangence le premier peut etre aussi le dernier
181 if (O==TopAbs_INTERNAL) cosAngWithT=-cosAngWithT;
182 Standard_Real cosAngWith2=myTgt*TgtLast;
184 switch (Compare(cosAngWithT, cosAngWith2, Tole)) {
187 // If the angle is lower than the last the new become the last
190 case TopAbs_REVERSED :
193 case TopAbs_INTERNAL :
194 if (myTgt*T<0) TgtLast.Reverse();
196 case TopAbs_FORWARD :
197 case TopAbs_EXTERNAL :
206 // If the angle is the same we look at the curvature
207 if (IsBefore(Tole, cosAngWithT, NormLast, CurvLast, N, C)) {
210 case TopAbs_REVERSED :
213 case TopAbs_INTERNAL :
214 if (myTgt*T<0) TgtLast.Reverse();
216 case TopAbs_FORWARD :
217 case TopAbs_EXTERNAL :
229 //=======================================================================
230 //function : StateBefore
231 //purpose : Give the state of the curv before the interference.
232 //=======================================================================
234 TopAbs_State TopTrans_CurveTransition::StateBefore () const
236 if (Init) return TopAbs_UNKNOWN;
239 case TopAbs_FORWARD :
240 case TopAbs_EXTERNAL :
242 case TopAbs_REVERSED :
243 case TopAbs_INTERNAL :
249 //=======================================================================
250 //function : StateAfter
251 //purpose : give the state of the curve after the interference.
252 //=======================================================================
254 TopAbs_State TopTrans_CurveTransition::StateAfter () const
256 if (Init) return TopAbs_UNKNOWN;
259 case TopAbs_FORWARD :
260 case TopAbs_INTERNAL :
262 case TopAbs_REVERSED :
263 case TopAbs_EXTERNAL :
270 //=======================================================================
271 //function : IsBefore
272 //purpose : Compare the curvature of the two transition and return true
273 // if T1 is before T2
274 //=======================================================================
276 Standard_Boolean TopTrans_CurveTransition::IsBefore
277 (const Standard_Real Tole,
278 const Standard_Real CosAngl,
280 const Standard_Real C1,
282 const Standard_Real C2) const
284 Standard_Real TN1=myTgt*N1;
285 Standard_Real TN2=myTgt*N2;
286 Standard_Boolean OneBefore=Standard_False;
288 if (Abs(TN1)<=Tole || Abs(TN2)<=Tole) {
289 // Tangent : The first is the interference which have the nearest curvature
290 // from the reference.
292 // The reference is straight
293 // The first is the interference which have the lowest curvature.
294 if (C1<C2) OneBefore=Standard_True;
295 // Modified by Sergey KHROMOV - Wed Dec 27 17:08:49 2000 Begin
297 OneBefore=!OneBefore;
298 // Modified by Sergey KHROMOV - Wed Dec 27 17:08:50 2000 End
301 // The reference is curv
302 // The first is the interference which have the nearest curvature
304 Standard_Real deltaC1, deltaC2;
305 if (C1==0. || myCurv==0.) {
309 deltaC1=(C1-myCurv)*(N1*myNorm);
311 if (C2==0. || myCurv==0.) {
315 deltaC2=(C2-myCurv)*(N2*myNorm);
317 if (deltaC1 < deltaC2) OneBefore=Standard_True;
318 if (CosAngl>0) OneBefore=!OneBefore;
322 // Before the first interference we are in the curvature
324 // Before the second interference we are out the curvature
325 // The first interference is before /* ->)( */
326 OneBefore=Standard_True;
329 // Before the second interference we are in the curvature
331 // We choice the greater curvature
332 // The first interference is before /* ->)) */
333 OneBefore=Standard_True;
338 // Before the first interference we are out the curvature
340 // Before the second interference we are out the curvature /* ->(( */
342 // We choice the lower curvature
343 // The first interference is before
344 OneBefore=Standard_True;
352 //=======================================================================
354 //purpose : Compare two angles
355 //=======================================================================
357 Standard_Integer TopTrans_CurveTransition::Compare(const Standard_Real Ang1,
358 const Standard_Real Ang2,
359 const Standard_Real Tole) const
361 Standard_Integer res=SAME;
362 if (Ang1 - Ang2 > Tole) res=GREATER;
363 else if (Ang2 - Ang1 > Tole) res=LOWER;