0027772: Foundation Classes - define Standard_Boolean using C++ type "bool" instead...
[occt.git] / src / TopOpeBRep / TopOpeBRep_FFTransitionTool.cxx
CommitLineData
b311480e 1// Created on: 1994-10-27
2// Created by: Jean Yves LEBEY
3// Copyright (c) 1994-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
7fd59977 18#include <BRep_Tool.hxx>
7fd59977 19#include <Geom_Curve.hxx>
42cf5bc1 20#include <Geom_Surface.hxx>
7fd59977 21#include <GeomAPI_ProjectPointOnCurve.hxx>
22#include <gp_Vec.hxx>
42cf5bc1 23#include <IntSurf_Situation.hxx>
24#include <IntSurf_Transition.hxx>
25#include <IntSurf_TypeTrans.hxx>
26#include <TopAbs.hxx>
27#include <TopoDS.hxx>
28#include <TopoDS_Edge.hxx>
29#include <TopoDS_Face.hxx>
30#include <TopoDS_Shape.hxx>
31#include <TopOpeBRep_FFTransitionTool.hxx>
32#include <TopOpeBRep_LineInter.hxx>
33#include <TopOpeBRep_VPointInter.hxx>
34#include <TopOpeBRepDS_CurvePointInterference.hxx>
35#include <TopOpeBRepDS_SolidSurfaceInterference.hxx>
36#include <TopOpeBRepDS_SurfaceCurveInterference.hxx>
37#include <TopOpeBRepDS_Transition.hxx>
7fd59977 38
7fd59977 39//-----------------------------------------------------------------------
40//function : TransitionToOrientation
41//purpose : static
42//-----------------------------------------------------------------------
43
44static Standard_Boolean TransitionToOrientation
45(const IntSurf_Transition& T,
46 TopAbs_Orientation& O)
47{
48 Standard_Boolean Odefined = Standard_True;
49 TopAbs_Orientation result = TopAbs_FORWARD;
50 IntSurf_TypeTrans trans;
51 IntSurf_Situation situa;
52
53 trans = T.TransitionType();
54
55 switch (trans) {
56
57 case IntSurf_In : result = TopAbs_FORWARD; break;
58 case IntSurf_Out : result = TopAbs_REVERSED; break;
59
60 case IntSurf_Touch :
61 situa = T.Situation();
62 switch (situa) {
63 case IntSurf_Inside : result = TopAbs_INTERNAL; break;
64 case IntSurf_Outside : result = TopAbs_EXTERNAL; break;
65 case IntSurf_Unknown :
66 Odefined = Standard_False;
7fd59977 67 break;
68 }
69 break;
70
71 case IntSurf_Undecided :
72 Odefined = Standard_False;
7fd59977 73 break;
74 }
75
76 O = result;
77 return Odefined;
78}
79
80
81//=======================================================================
82//function : ProcessLineTransition
83//purpose : compute the transition of the intersection
84// : point <P> on the intersected shape of index <Index> (1 or 2)
85// : for a line crossing an edge
86//=======================================================================
87
88TopOpeBRepDS_Transition TopOpeBRep_FFTransitionTool::ProcessLineTransition
89 (const TopOpeBRep_VPointInter &P,
90 const Standard_Integer Index,
91 const TopAbs_Orientation EdgeOrientation)
92{
93 TopOpeBRepDS_Transition TT;
94
95 if ((EdgeOrientation==TopAbs_INTERNAL)||(EdgeOrientation==TopAbs_EXTERNAL)) {
96 TT.Set(EdgeOrientation);
97 }
98 else {
99 TopAbs_Orientation O;
100
101 IntSurf_Transition T; {
102 switch (Index) {
103 case 1 : T = P.TransitionLineArc1(); break;
104 case 2 : T = P.TransitionLineArc2(); break;
105 }
106 Standard_Boolean Odefined = ::TransitionToOrientation(T,O);
107 if (Odefined) {
108 if (EdgeOrientation == TopAbs_REVERSED) O = TopAbs::Complement(O);
109 TT.Set(O);
110 }
111 else {
112 TT.Set(TopAbs_UNKNOWN,TopAbs_UNKNOWN);
113 }
114 }
115 }
116 return TT;
117}
118
119//=======================================================================
120//function : ProcessLineTransition
121//purpose : compute the transition of point P on line L, P lying on
122// neither of the intersecting shapes
123//=======================================================================
124
125TopOpeBRepDS_Transition TopOpeBRep_FFTransitionTool::ProcessLineTransition
126(const TopOpeBRep_VPointInter &P, const TopOpeBRep_LineInter& LI)
127{
128 TopOpeBRepDS_Transition TT;
129 TopAbs_Orientation result;
130
131 // P.IsOnDomS1() and P.IsOnDomS2() are both false
132
133 Standard_Integer nbv = LI.NbVPoint();
134 TopOpeBRep_VPointInter P1 = LI.VPoint(1);
135 Standard_Real par1 = P1.ParameterOnLine();
136 TopOpeBRep_VPointInter Pn = LI.VPoint(nbv);
137 Standard_Real parn = Pn.ParameterOnLine();
138
139 Standard_Real par = P.ParameterOnLine();
140 if ( par == par1 ) result = TopAbs_FORWARD;
141 else if ( par == parn ) result = TopAbs_REVERSED;
142 else result = TopAbs_INTERNAL;
143
144 TT.Set(result);
145 return TT;
146}
147
148
149//=======================================================================
150//function : ProcessEdgeTransition
151//purpose : compute the transition from the transition of the intersection
152// : point <P> on the intersected shape of index <Index> (1 or 2)
153// : for an edge on a line on a Face
154//=======================================================================
155
156TopOpeBRepDS_Transition TopOpeBRep_FFTransitionTool::ProcessEdgeTransition
157 (const TopOpeBRep_VPointInter &P,
158 const Standard_Integer Index,
159 const TopAbs_Orientation FaceTransition)
160{
161 TopOpeBRepDS_Transition TT;
162
163 if ((FaceTransition == TopAbs_INTERNAL) ||
164 (FaceTransition == TopAbs_EXTERNAL)) {
165 TT.Set(FaceTransition);
166 }
167 else {
168 IntSurf_Transition T;
169 if ( Index == 1 ) T = P.TransitionOnS1();
170 else if ( Index == 2 ) T = P.TransitionOnS2();
171
172 TopAbs_Orientation O;
173 Standard_Boolean defined = ::TransitionToOrientation(T,O);
174 if (defined) {
175 if (FaceTransition == TopAbs_REVERSED) O = TopAbs::Complement(O);
176 TT.Set(O);
177 }
178 else {
179 TT.Set(TopAbs_UNKNOWN,TopAbs_UNKNOWN);
180 }
181 }
182
183 return TT;
184}
185
186
187//=======================================================================
188//function : ProcessFaceTransition
189//purpose : compute the transition from a Line
190//=======================================================================
191
192TopOpeBRepDS_Transition TopOpeBRep_FFTransitionTool::ProcessFaceTransition
193 (const TopOpeBRep_LineInter& L,
194 const Standard_Integer Index,
195 const TopAbs_Orientation FaceOrientation)
196{
197 // If Index == 1, on first shape
198 // If Index == 2, on second shape
199 TopOpeBRepDS_Transition TT;
200
201 if ((FaceOrientation == TopAbs_INTERNAL) ||
202 (FaceOrientation == TopAbs_EXTERNAL)) {
203 TT.Set(FaceOrientation);
204 }
205 else {
206 Standard_Boolean Odefined = Standard_True;
1d47d8d0 207
7fd59977 208 TopAbs_Orientation O = TopAbs_FORWARD;
7fd59977 209
210 IntSurf_TypeTrans trans;
211 trans = (Index == 1) ? L.TransitionOnS1() : L.TransitionOnS2();
212
213 switch (trans) {
214
215 case IntSurf_In : O = TopAbs_FORWARD; break;
216
217 case IntSurf_Out : O = TopAbs_REVERSED; break;
218
219 case IntSurf_Touch : {
220
221 IntSurf_Situation situa;
222 situa = (Index == 1 ) ? L.SituationS1() : L.SituationS2();
223
224 switch (situa) {
225
226 case IntSurf_Inside : O = TopAbs_INTERNAL; break;
227
228 case IntSurf_Outside : O = TopAbs_EXTERNAL; break;
229
230 case IntSurf_Unknown :
231
232 Odefined = Standard_False;
7fd59977 233 break;
234 }
235 break;
236 } // case Touch
237
238 case IntSurf_Undecided :
536a3cb8 239 Odefined = Standard_False;
240 break;
7fd59977 241
242 } // trans
243
244 if (Odefined) {
245 if (FaceOrientation == TopAbs_REVERSED) O = TopAbs::Complement(O);
246 TT.Set(O);
247 }
248 else {
249 TT.Set(TopAbs_UNKNOWN,TopAbs_UNKNOWN);
250 }
251 }
252
253 return TT;
254}
255
256
257// -------------------------------------------------
258// input : P1 : point
259// input : C2 : courbe, FC2,LC2 : bornes de C2
260// output : T2 = parametre de P1 sur C2
261// -------------------------------------------------
262static Standard_Boolean FUN_ProjectPoint(const gp_Pnt& P1,
263 const Handle(Geom_Curve)& C2,
264 const Standard_Real FC2,
265 const Standard_Real LC2,
266 Standard_Real& T2)
267{
268 if ( C2.IsNull() ) {
269 return Standard_False;
270 }
dde68833 271
7fd59977 272 GeomAPI_ProjectPointOnCurve mydist(P1,C2,FC2,LC2);
273 if ( mydist.Extrema().IsDone() ) {
274 if ( mydist.NbPoints() ) {
275 T2 = mydist.LowerDistanceParameter();
dde68833 276 return Standard_True;
7fd59977 277 }
278 }
7fd59977 279
dde68833 280 return Standard_False;
7fd59977 281}
282
283// -------------------------------------------------
284// input : S1,U1,V1,C1,T1 avec D0(S1(U1,V1)) = D0(C1(T1))
285// input : C2,FC2,LC2 : courbe, bornes de C2
286// output : Trans : transition sur C1 en T1 en croisant C2
287// -------------------------------------------------
288static Standard_Boolean FUN_GeomTrans(const Handle(Geom_Surface)& S1,
289 const Standard_Real U1,
290 const Standard_Real V1,
291 const Handle(Geom_Curve)& C1,
292 const Standard_Real T1,
293 const Handle(Geom_Curve)& C2,
294 const Standard_Real FC2,
295 const Standard_Real LC2,
296 TopOpeBRepDS_Transition& Trans)
297{
298 if ( C1.IsNull() || C2.IsNull() ) {
299 return Standard_False;
300 }
301
302 // P1 : D0(C1(T1), D1_C1 : D1(C1(T1))
303 gp_Pnt P1; gp_Vec D1_C1; C1->D1(T1,P1,D1_C1);
304
305 // D1_C2 : D1(C2(P1))
d20d815b 306 Standard_Real T2 = 0.0;
7fd59977 307 Standard_Boolean projok = ::FUN_ProjectPoint(P1,C2,FC2,LC2,T2);
308 if ( !projok ) {
309 return Standard_False;
310 }
311 gp_Pnt P2; gp_Vec D1_C2; C2->D1(T2,P2,D1_C2);
312
313 // N1 : D1(S1(U1,V1))
314 gp_Vec N1,D1U,D1V;
315 gp_Pnt PS;
316 S1->D1(U1,V1,PS,D1U,D1V);
317 D1U.Normalize();
318 D1V.Normalize();
319 N1 = D1U.Crossed(D1V);
320 N1.Normalize();
321
322 gp_Vec N1D1_C1 = N1.Crossed(D1_C1);
323 Standard_Real dot = N1D1_C1.Dot(D1_C2);
324 if ( dot > 0 ) {
325 Trans.Before(TopAbs_OUT);
326 Trans.After(TopAbs_IN);
327 }
328 else {
329 Trans.Before(TopAbs_IN);
330 Trans.After(TopAbs_OUT);
331 }
332
333 return Standard_True;
334}
335
336//=======================================================================
337//function : ProcessEdgeONTransition
338//purpose :
339//=======================================================================
340
341TopOpeBRepDS_Transition TopOpeBRep_FFTransitionTool::ProcessEdgeONTransition
342(const TopOpeBRep_VPointInter& VP,
343 const Standard_Integer ShapeIndex,
344 const TopoDS_Shape& RR,
345 const TopoDS_Shape& EE,
346 const TopoDS_Shape& FF)
347{
348 const TopoDS_Edge& R = TopoDS::Edge(RR);
349 const TopoDS_Edge& E = TopoDS::Edge(EE);
350 const TopoDS_Face& F = TopoDS::Face(FF);
351
352 TopAbs_Orientation oriE = E.Orientation();
353
354 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F);
1d47d8d0 355 Standard_Real U = 0.,V = 0.;
7fd59977 356 if (ShapeIndex == 1) VP.ParametersOnS1(U,V);
357 else if (ShapeIndex == 2) VP.ParametersOnS2(U,V);
358
359 Standard_Real fE,lE;
360 const Handle(Geom_Curve)& CE = BRep_Tool::Curve(E,fE,lE);
361 Standard_Real TE = VP.EdgeParameter(ShapeIndex);
362
363 Standard_Real fR,lR;
364 const Handle(Geom_Curve)& CR = BRep_Tool::Curve(R,fR,lR);
365
366 TopOpeBRepDS_Transition Trans;
367 Standard_Boolean transok = ::FUN_GeomTrans(S,U,V,CE,TE,CR,fR,lR,Trans);
368 if ( transok ) {
369 // Trans : transition sur R en croisant l'arete E orientee dans la face F
370 if (oriE == TopAbs_REVERSED) Trans = Trans.Complement();
371 }
372
373 return Trans;
374}