0026937: Eliminate NO_CXX_EXCEPTION macro support
[occt.git] / src / ChFiKPart / ChFiKPart_ComputeData.cxx
1 // Created on: 1993-12-23
2 // Created by: Isabelle GRIGNON
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
18 #include <Adaptor3d_HSurface.hxx>
19 #include <BRepAdaptor_HSurface.hxx>
20 #include <ChFiDS_ChamfSpine.hxx>
21 #include <ChFiDS_FilSpine.hxx>
22 #include <ChFiDS_Spine.hxx>
23 #include <ChFiDS_SurfData.hxx>
24 #include <ChFiKPart_ComputeData.hxx>
25 #include <ChFiKPart_ComputeData_ChAsymPlnCon.hxx>
26 #include <ChFiKPart_ComputeData_ChAsymPlnCyl.hxx>
27 #include <ChFiKPart_ComputeData_ChAsymPlnPln.hxx>
28 #include <ChFiKPart_ComputeData_ChPlnCon.hxx>
29 #include <ChFiKPart_ComputeData_ChPlnCyl.hxx>
30 #include <ChFiKPart_ComputeData_ChPlnPln.hxx>
31 #include <ChFiKPart_ComputeData_CS.hxx>
32 #include <ChFiKPart_ComputeData_Fcts.hxx>
33 #include <ChFiKPart_ComputeData_FilPlnCon.hxx>
34 #include <ChFiKPart_ComputeData_FilPlnCyl.hxx>
35 #include <ChFiKPart_ComputeData_FilPlnPln.hxx>
36 #include <ChFiKPart_ComputeData_Rotule.hxx>
37 #include <ChFiKPart_ComputeData_Sphere.hxx>
38 #include <ElCLib.hxx>
39 #include <ElSLib.hxx>
40 #include <Geom2d_BSplineCurve.hxx>
41 #include <Geom2d_Circle.hxx>
42 #include <Geom2d_Curve.hxx>
43 #include <Geom2d_Line.hxx>
44 #include <Geom2dAdaptor_Curve.hxx>
45 #include <Geom2dInt_GInter.hxx>
46 #include <Geom_Circle.hxx>
47 #include <Geom_ConicalSurface.hxx>
48 #include <Geom_Curve.hxx>
49 #include <Geom_CylindricalSurface.hxx>
50 #include <Geom_Line.hxx>
51 #include <Geom_Plane.hxx>
52 #include <Geom_SphericalSurface.hxx>
53 #include <Geom_Surface.hxx>
54 #include <Geom_ToroidalSurface.hxx>
55 #include <GeomAbs_CurveType.hxx>
56 #include <GeomAbs_SurfaceType.hxx>
57 #include <GeomAdaptor_Curve.hxx>
58 #include <gp.hxx>
59 #include <gp_Ax2.hxx>
60 #include <gp_Ax3.hxx>
61 #include <gp_Circ.hxx>
62 #include <gp_Cylinder.hxx>
63 #include <gp_Dir.hxx>
64 #include <gp_Dir2d.hxx>
65 #include <gp_Lin.hxx>
66 #include <gp_Lin2d.hxx>
67 #include <gp_Pln.hxx>
68 #include <gp_Pnt.hxx>
69 #include <gp_Pnt2d.hxx>
70 #include <gp_Vec.hxx>
71 #include <IntAna_QuadQuadGeo.hxx>
72 #include <IntRes2d_IntersectionPoint.hxx>
73 #include <IntRes2d_Position.hxx>
74 #include <IntRes2d_Transition.hxx>
75 #include <IntRes2d_TypeTrans.hxx>
76 #include <IntSurf_Transition.hxx>
77 #include <IntSurf_TypeTrans.hxx>
78 #include <Precision.hxx>
79 #include <Standard_ConstructionError.hxx>
80 #include <Standard_NotImplemented.hxx>
81 #include <TopExp.hxx>
82 #include <TopOpeBRepDS_Curve.hxx>
83 #include <TopOpeBRepDS_DataStructure.hxx>
84 #include <TopOpeBRepDS_Surface.hxx>
85
86 //#include <BRepAdaptor_Curve2d.hxx>
87 //#include <BRepAdaptor_HCurve2d.hxx>
88 //=======================================================================
89 //function : Compute
90 //purpose  : 
91 //=======================================================================
92  Standard_Boolean ChFiKPart_ComputeData::Compute
93  (TopOpeBRepDS_DataStructure&    DStr, 
94   Handle(ChFiDS_SurfData)&       Data, 
95   const Handle(Adaptor3d_HSurface)& S1, 
96   const Handle(Adaptor3d_HSurface)& S2, 
97   const TopAbs_Orientation       Or1, 
98   const TopAbs_Orientation       Or2, 
99   const Handle(ChFiDS_Spine)&    Sp, 
100   const Standard_Integer         Iedge)
101 {
102   Standard_Real Wref = 0.;
103
104   Handle(ChFiDS_FilSpine)   Spine  = Handle(ChFiDS_FilSpine)::DownCast(Sp);
105   Handle(ChFiDS_ChamfSpine) CSpine = Handle(ChFiDS_ChamfSpine)::DownCast(Sp);
106   Standard_Boolean surfok = Standard_False;
107   GeomAbs_SurfaceType typ1 = S1->GetType();
108   GeomAbs_SurfaceType typ2 = S2->GetType();
109   GeomAbs_CurveType   ctyp;
110
111   if (!Spine.IsNull())
112     ctyp = Spine->CurrentElementarySpine(Iedge).GetType();
113   else 
114     ctyp = CSpine->CurrentElementarySpine(Iedge).GetType();
115
116   // Return orientations.
117   TopAbs_Orientation OrFace1 = TopAbs_FORWARD, OrFace2 = TopAbs_FORWARD;
118   Handle(BRepAdaptor_HSurface) HS = Handle(BRepAdaptor_HSurface)::DownCast(S1);
119   if (!HS.IsNull()) OrFace1 = HS->ChangeSurface().Face().Orientation();
120   HS = Handle(BRepAdaptor_HSurface)::DownCast(S2);
121   if (!HS.IsNull()) OrFace2 = HS->ChangeSurface().Face().Orientation();
122   
123   if(!Spine.IsNull()){
124     Standard_Real Radius = Spine->Radius(Iedge);
125     if ( typ1 == GeomAbs_Plane && typ2 == GeomAbs_Plane ){
126       surfok = ChFiKPart_MakeFillet(DStr,Data,S1->Plane(),S2->Plane(), 
127                                     Or1,Or2,Radius,Spine->Line(),
128                                     Wref,OrFace1);
129     }
130     else if ( typ1 == GeomAbs_Plane && typ2 == GeomAbs_Cylinder ){
131       if (ctyp == GeomAbs_Line) 
132         surfok = ChFiKPart_MakeFillet(DStr,Data,S1->Plane(),S2->Cylinder(),
133                                       S2->FirstUParameter(),S2->LastUParameter(),
134                                       Or1,Or2,Radius,Spine->Line(),
135                                       Wref,OrFace1,Standard_True);
136         else
137           surfok = ChFiKPart_MakeFillet(DStr,Data,S1->Plane(),S2->Cylinder(),
138                                         S2->FirstUParameter(),S2->LastUParameter(),
139                                         Or1,Or2,Radius,Spine->Circle(),
140                                         Wref,OrFace1,Standard_True);
141     }
142     else if ( typ1 == GeomAbs_Cylinder && typ2 == GeomAbs_Plane ){
143       if (ctyp == GeomAbs_Line) 
144         surfok = ChFiKPart_MakeFillet(DStr,Data,S2->Plane(),S1->Cylinder(), 
145                                       S1->FirstUParameter(),S1->LastUParameter(),
146                                       Or2,Or1,Radius,Spine->Line(),
147                                       Wref,OrFace2,Standard_False);
148       else 
149         surfok = ChFiKPart_MakeFillet(DStr,Data,S2->Plane(),S1->Cylinder(), 
150                                       S1->FirstUParameter(),S1->LastUParameter(),
151                                       Or2,Or1,Radius,Spine->Circle(),
152                                       Wref,OrFace2,Standard_False);
153     }
154     else if ( typ1 == GeomAbs_Plane && typ2 == GeomAbs_Cone ){
155       surfok =  ChFiKPart_MakeFillet(DStr,Data,S1->Plane(),S2->Cone(), 
156                                      S2->FirstUParameter(),S2->LastUParameter(),
157                                      Or1,Or2,Radius,Spine->Circle(),
158                                      Wref,OrFace1,Standard_True);
159     }
160     else if ( typ1 == GeomAbs_Cone && typ2 == GeomAbs_Plane ){
161       surfok = ChFiKPart_MakeFillet(DStr,Data,S2->Plane(),S1->Cone(), 
162                                     S1->FirstUParameter(),S1->LastUParameter(),
163                                     Or2,Or1,Radius,Spine->Circle(),
164                                     Wref,OrFace2,Standard_False);
165     }
166     else{
167       throw Standard_NotImplemented("particular case not written");
168     }
169   }
170   else if(!CSpine.IsNull()){
171     if (CSpine->IsChamfer() == ChFiDS_Sym) {
172       Standard_Real dis;
173       CSpine->GetDist(dis);
174       if ( typ1 == GeomAbs_Plane && typ2 == GeomAbs_Plane ){
175         surfok = ChFiKPart_MakeChamfer(DStr,Data,S1->Plane(),S2->Plane(), 
176                                       Or1,Or2,dis, dis,CSpine->Line(),
177                                       Wref,OrFace1);
178       }
179       else if ( typ1 == GeomAbs_Plane && typ2 == GeomAbs_Cylinder ){
180         if (ctyp == GeomAbs_Circle)
181           surfok = ChFiKPart_MakeChamfer(DStr,Data,S1->Plane(),S2->Cylinder(),
182                                          S2->FirstUParameter(),S2->LastUParameter(),
183                                          Or1,Or2,dis,dis ,CSpine->Circle(),
184                                          Wref,OrFace1,Standard_True);
185         else
186           surfok = ChFiKPart_MakeChamfer(DStr,Data,S1->Plane(),S2->Cylinder(),
187                                          S2->FirstUParameter(),S2->LastUParameter(),
188                                          Or1,Or2,dis,dis,CSpine->Line(),
189                                          Wref,OrFace1,Standard_True);
190       }
191       else if ( typ1 == GeomAbs_Cylinder && typ2 == GeomAbs_Plane ){
192         if (ctyp == GeomAbs_Circle)
193           surfok = ChFiKPart_MakeChamfer(DStr,Data,S2->Plane(),S1->Cylinder(), 
194                                          S1->FirstUParameter(),S1->LastUParameter(),
195                                          Or2,Or1,dis,dis,CSpine->Circle(),
196                                          Wref,OrFace2,Standard_False);
197         else
198           surfok = ChFiKPart_MakeChamfer(DStr,Data,S2->Plane(),S1->Cylinder(), 
199                                          S1->FirstUParameter(),S1->LastUParameter(),
200                                          Or2,Or1,dis,dis,CSpine->Line(),
201                                          Wref,OrFace2,Standard_False);
202       }
203       else if ( typ1 == GeomAbs_Plane && typ2 == GeomAbs_Cone ){
204         surfok = ChFiKPart_MakeChamfer(DStr,Data,S1->Plane(),S2->Cone(), 
205                                        S2->FirstUParameter(),S2->LastUParameter(),
206                                        Or1,Or2,dis,dis,CSpine->Circle(),
207                                        Wref,OrFace1,Standard_True);
208       }
209       else if ( typ1 == GeomAbs_Cone && typ2 == GeomAbs_Plane ){
210         surfok = ChFiKPart_MakeChamfer(DStr,Data,S2->Plane(),S1->Cone(), 
211                                        S1->FirstUParameter(),S1->LastUParameter(),
212                                        Or2,Or1,dis,dis,CSpine->Circle(),
213                                        Wref,OrFace2,Standard_False); 
214       }
215       else{
216         throw Standard_NotImplemented("particular case not written");
217       }
218     }
219     else if (CSpine->IsChamfer() == ChFiDS_TwoDist) {    
220       Standard_Real dis1,dis2;
221       CSpine->Dists(dis1,dis2);
222       if ( typ1 == GeomAbs_Plane && typ2 == GeomAbs_Plane ){
223         surfok = ChFiKPart_MakeChamfer(DStr,Data,S1->Plane(),S2->Plane(), 
224                                       Or1,Or2,dis1,dis2,CSpine->Line(),
225                                       Wref,OrFace1);
226       }
227       else if ( typ1 == GeomAbs_Plane && typ2 == GeomAbs_Cylinder ){
228         if (ctyp == GeomAbs_Circle)
229           surfok = ChFiKPart_MakeChamfer(DStr,Data,S1->Plane(),S2->Cylinder(),
230                                          S2->FirstUParameter(),S2->LastUParameter(),
231                                          Or1,Or2,dis1,dis2,CSpine->Circle(),
232                                          Wref,OrFace1,Standard_True);
233         else
234           surfok = ChFiKPart_MakeChamfer(DStr,Data,S1->Plane(),S2->Cylinder(),
235                                          S2->FirstUParameter(),S2->LastUParameter(),
236                                          Or1,Or2,dis1,dis2,CSpine->Line(),
237                                          Wref,OrFace1,Standard_True);
238       }
239       else if ( typ1 == GeomAbs_Cylinder && typ2 == GeomAbs_Plane ){
240         if (ctyp == GeomAbs_Circle)
241           surfok = ChFiKPart_MakeChamfer(DStr,Data,S2->Plane(),S1->Cylinder(), 
242                                          S1->FirstUParameter(),S1->LastUParameter(),
243                                          Or2,Or1,dis2,dis1,CSpine->Circle(),
244                                          Wref,OrFace2,Standard_False);
245         else
246           surfok = ChFiKPart_MakeChamfer(DStr,Data,S2->Plane(),S1->Cylinder(), 
247                                          S1->FirstUParameter(),S1->LastUParameter(),
248                                          Or2,Or1,dis2,dis1,CSpine->Line(),
249                                          Wref,OrFace2,Standard_False);
250       }
251       else if ( typ1 == GeomAbs_Plane && typ2 == GeomAbs_Cone ){
252         surfok = ChFiKPart_MakeChamfer(DStr,Data,S1->Plane(),S2->Cone(), 
253                                        S2->FirstUParameter(),S2->LastUParameter(),
254                                        Or1,Or2,dis1,dis2,CSpine->Circle(),
255                                        Wref,OrFace1,Standard_True);
256       }
257       else if ( typ1 == GeomAbs_Cone && typ2 == GeomAbs_Plane ){
258         surfok = ChFiKPart_MakeChamfer(DStr,Data,S2->Plane(),S1->Cone(), 
259                                        S1->FirstUParameter(),S1->LastUParameter(),
260                                        Or2,Or1,dis2,dis1,CSpine->Circle(),
261                                        Wref,OrFace2,Standard_False); 
262       }
263       else{
264         throw Standard_NotImplemented("particular case not written");
265       }
266     }
267     else {
268       Standard_Real dis, Angle;
269       Standard_Boolean DisOnP;
270       CSpine->GetDistAngle(dis, Angle, DisOnP);
271       if ( typ1 == GeomAbs_Plane && typ2 == GeomAbs_Plane ){
272         surfok = ChFiKPart_MakeChAsym(DStr,Data,S1->Plane(),S2->Plane(), 
273                                       Or1,Or2, dis, Angle, CSpine->Line(),
274                                       Wref,OrFace1, DisOnP);
275       }
276       else if ( typ1 == GeomAbs_Plane && typ2 == GeomAbs_Cylinder ){
277         if (ctyp == GeomAbs_Circle)
278           surfok = ChFiKPart_MakeChAsym(DStr,Data,S1->Plane(),S2->Cylinder(),
279                                         S2->FirstUParameter(),S2->LastUParameter(),
280                                         Or1,Or2,dis, Angle, CSpine->Circle(),
281                                         Wref,OrFace1,Standard_True, DisOnP);
282         else
283           surfok = ChFiKPart_MakeChAsym(DStr,Data,S1->Plane(),S2->Cylinder(),
284                                         S2->FirstUParameter(),S2->LastUParameter(),
285                                         Or1,Or2, dis, Angle, CSpine->Line(),
286                                         Wref,OrFace1,Standard_True, DisOnP);
287       }
288       else if ( typ1 == GeomAbs_Cylinder && typ2 == GeomAbs_Plane ){
289         if (ctyp == GeomAbs_Circle)
290           surfok = ChFiKPart_MakeChAsym(DStr,Data,S2->Plane(),S1->Cylinder(), 
291                                         S1->FirstUParameter(),S1->LastUParameter(),
292                                         Or2,Or1,dis, Angle, CSpine->Circle(),
293                                         Wref,OrFace2,Standard_False, DisOnP);
294         else
295           surfok = ChFiKPart_MakeChAsym(DStr,Data,S2->Plane(),S1->Cylinder(), 
296                                         S1->FirstUParameter(),S1->LastUParameter(),
297                                         Or2,Or1,dis, Angle, CSpine->Line(),
298                                         Wref,OrFace2,Standard_False, DisOnP);
299       }
300       else if ( typ1 == GeomAbs_Plane && typ2 == GeomAbs_Cone ){
301         surfok = ChFiKPart_MakeChAsym(DStr,Data,S1->Plane(),S2->Cone(), 
302                                       S2->FirstUParameter(),S2->LastUParameter(),
303                                       Or1,Or2, dis, Angle, CSpine->Circle(),
304                                       Wref,OrFace1,Standard_True, DisOnP);
305       }
306       else if ( typ1 == GeomAbs_Cone && typ2 == GeomAbs_Plane ){
307         surfok = ChFiKPart_MakeChAsym(DStr,Data,S2->Plane(),S1->Cone(), 
308                                       S1->FirstUParameter(),S1->LastUParameter(),
309                                       Or2,Or1, dis, Angle, CSpine->Circle(),
310                                       Wref,OrFace2,Standard_False, DisOnP); 
311       }
312       else{
313         throw Standard_NotImplemented("particular case not written");
314       }
315     }
316   }
317   return surfok; 
318 }
319
320 //=======================================================================
321 //function : ComputeCorner
322 //purpose  : 
323 //=======================================================================
324
325 Standard_Boolean ChFiKPart_ComputeData::ComputeCorner
326   (TopOpeBRepDS_DataStructure& DStr,
327    const Handle(ChFiDS_SurfData)& Data, 
328    const Handle(Adaptor3d_HSurface)& S1, 
329    const Handle(Adaptor3d_HSurface)& S2,
330    const TopAbs_Orientation OrFace1,
331    const TopAbs_Orientation,
332    const TopAbs_Orientation Or1,
333    const TopAbs_Orientation Or2,
334    const Standard_Real minRad, 
335    const Standard_Real majRad, 
336    const gp_Pnt2d& P1S1,
337    const gp_Pnt2d& P2S1,
338    const gp_Pnt2d& P1S2,
339    const gp_Pnt2d& P2S2)
340 {
341   Standard_Boolean surfok;
342   GeomAbs_SurfaceType typ1 = S1->GetType();
343   GeomAbs_SurfaceType typ2 = S2->GetType();
344   if ( typ1 != GeomAbs_Plane ){
345     throw Standard_ConstructionError("la face du conge torique doit etre plane");
346   }
347   // The guideline is the circle corresponding 
348   // to the section of S2, and other construction elements.
349
350   gp_Cylinder cyl;
351   gp_Circ circ;
352   Standard_Real First,Last,fu,lu;
353   ChFiKPart_CornerSpine(S1,S2,P1S1,P2S1,P1S2,P2S2,majRad,cyl,circ,First,Last);
354   if ( typ2 == GeomAbs_Cylinder ){
355     cyl = S2->Cylinder();
356     fu = P1S2.X();
357     lu = P2S2.X();
358   }
359   else{
360     fu = First;
361     lu = Last;
362   }
363   surfok = ChFiKPart_MakeFillet(DStr,Data,S1->Plane(),cyl, 
364                                fu,lu,Or1,Or2,minRad,circ,
365                                First,OrFace1,Standard_True);
366   if(surfok){
367     if ( typ2 != GeomAbs_Cylinder ){
368       Data->ChangeInterferenceOnS2().ChangePCurveOnFace() = 
369         ChFiKPart_PCurve(P1S2,P2S2,First,Last);
370     }
371     Data->ChangeVertexFirstOnS1().SetPoint(S1->Value(P1S1.X(),P1S1.Y()));
372     Data->ChangeVertexLastOnS1().SetPoint(S1->Value(P2S1.X(),P2S1.Y()));
373     Data->ChangeVertexFirstOnS2().SetPoint(S2->Value(P1S2.X(),P1S2.Y()));
374     Data->ChangeVertexLastOnS2().SetPoint(S2->Value(P2S2.X(),P2S2.Y()));
375     Data->ChangeInterferenceOnS1().SetFirstParameter(First);
376     Data->ChangeInterferenceOnS1().SetLastParameter(Last);
377     Data->ChangeInterferenceOnS2().SetFirstParameter(First);
378     Data->ChangeInterferenceOnS2().SetLastParameter(Last);
379     return Standard_True;
380   }
381   return Standard_False;
382 }
383
384
385 //=======================================================================
386 //function : ComputeCorner
387 //purpose  : 
388 //=======================================================================
389
390 Standard_Boolean ChFiKPart_ComputeData::ComputeCorner
391   (TopOpeBRepDS_DataStructure& DStr,
392    const Handle(ChFiDS_SurfData)& Data, 
393    const Handle(Adaptor3d_HSurface)& S1, 
394    const Handle(Adaptor3d_HSurface)& S2,
395    const TopAbs_Orientation OrFace1,
396    const TopAbs_Orientation OrFace2,
397    const TopAbs_Orientation Or1,
398    const TopAbs_Orientation Or2,
399    const Standard_Real Rad, 
400    const gp_Pnt2d& PS1,
401    const gp_Pnt2d& P1S2,
402    const gp_Pnt2d& P2S2)
403 {
404   return ChFiKPart_Sphere(DStr,Data,S1,S2,OrFace1,OrFace2,Or1,Or2,Rad,PS1,P1S2,P2S2);
405 }
406
407 //=======================================================================
408 //function : ComputeCorner
409 //purpose  : 
410 //=======================================================================
411
412 Standard_Boolean ChFiKPart_ComputeData::ComputeCorner
413   (TopOpeBRepDS_DataStructure& DStr,
414    const Handle(ChFiDS_SurfData)& Data, 
415    const Handle(Adaptor3d_HSurface)& S, 
416    const Handle(Adaptor3d_HSurface)& S1, 
417    const Handle(Adaptor3d_HSurface)& S2,
418    const TopAbs_Orientation OfS,
419    const TopAbs_Orientation OS,
420    const TopAbs_Orientation OS1,
421    const TopAbs_Orientation OS2,
422    const Standard_Real Radius)
423 {
424   GeomAbs_SurfaceType typ = S->GetType();
425   GeomAbs_SurfaceType typ1 = S1->GetType();
426   GeomAbs_SurfaceType typ2 = S2->GetType();
427   if (typ != GeomAbs_Plane ||
428       typ1 != GeomAbs_Plane ||
429       typ2 != GeomAbs_Plane){
430     throw Standard_ConstructionError("torus joint only between the planes");
431   }
432   return ChFiKPart_MakeRotule(DStr,Data,S->Plane(),S1->Plane(),
433                               S2->Plane(),OS,OS1,OS2,Radius,OfS);
434 }