0026377: Passing Handle objects as arguments to functions as non-const reference...
[occt.git] / src / ChFiKPart / ChFiKPart_ComputeData_Rotule.cxx
1 // Created on: 1994-06-27
2 // Created by: Laurent BOURESCHE
3 // Copyright (c) 1994-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 <ChFiDS_Spine.hxx>
20 #include <ChFiDS_SurfData.hxx>
21 #include <ChFiKPart_ComputeData.hxx>
22 #include <ChFiKPart_ComputeData_Fcts.hxx>
23 #include <ElCLib.hxx>
24 #include <ElSLib.hxx>
25 #include <Geom2d_Circle.hxx>
26 #include <Geom2d_Line.hxx>
27 #include <Geom_Circle.hxx>
28 #include <Geom_Line.hxx>
29 #include <Geom_ToroidalSurface.hxx>
30 #include <gp.hxx>
31 #include <gp_Ax2.hxx>
32 #include <gp_Ax3.hxx>
33 #include <gp_Ax22d.hxx>
34 #include <gp_Dir.hxx>
35 #include <gp_Dir2d.hxx>
36 #include <gp_Lin.hxx>
37 #include <gp_Lin2d.hxx>
38 #include <gp_Pln.hxx>
39 #include <gp_Pnt.hxx>
40 #include <gp_Pnt2d.hxx>
41 #include <gp_Vec.hxx>
42 #include <IntAna_QuadQuadGeo.hxx>
43 #include <Precision.hxx>
44 #include <TopOpeBRepDS_DataStructure.hxx>
45
46 //=======================================================================
47 //function : MakeRotule
48 //Purpose  : cas plan/plan.
49 //=======================================================================
50 Standard_Boolean ChFiKPart_MakeRotule(TopOpeBRepDS_DataStructure& DStr,
51                                       const Handle(ChFiDS_SurfData)& Data, 
52                                       const gp_Pln& pl, 
53                                       const gp_Pln& pl1, 
54                                       const gp_Pln& pl2, 
55                                       const TopAbs_Orientation opl,
56                                       const TopAbs_Orientation opl1,
57                                       const TopAbs_Orientation opl2,
58                                       const Standard_Real r, 
59                                       const TopAbs_Orientation ofpl)
60 {
61
62   //calcul du tore.
63   //---------------
64   gp_Ax3 pos = pl.Position();
65   gp_Dir dpl = pos.XDirection().Crossed(pos.YDirection());
66   gp_Dir dfpl = dpl;
67   gp_Dir dplnat = dpl;
68   if (opl == TopAbs_REVERSED) { dpl.Reverse(); }
69   if (ofpl == TopAbs_REVERSED) { dfpl.Reverse(); }
70   pos = pl1.Position();
71   gp_Dir dpl1 = pos.XDirection().Crossed(pos.YDirection());
72   if (opl1 == TopAbs_REVERSED) { dpl1.Reverse(); }
73   pos = pl2.Position();
74   gp_Dir dpl2 = pos.XDirection().Crossed(pos.YDirection());
75   if (opl2 == TopAbs_REVERSED) { dpl2.Reverse(); }
76
77   Standard_Real alpha = dpl1.Angle(dpl2);
78
79   IntAna_QuadQuadGeo LInt (pl1,pl2,Precision::Angular(),
80                            Precision::Confusion());
81   gp_Pnt ptor,pcirc;
82   if (LInt.IsDone()) {
83
84     pcirc = ElCLib::Value(ElCLib::Parameter(LInt.Line(1),pl.Location()),
85                          LInt.Line(1));
86     ptor.SetCoord(pcirc.X()+r*dpl.X(),
87                   pcirc.Y()+r*dpl.Y(),
88                   pcirc.Z()+r*dpl.Z());
89   }
90   else { return Standard_False; }
91
92   gp_Ax3 ppos(ptor,dpl.Reversed(),dpl1);
93   if(ppos.YDirection().Dot(dpl2) < 0.) ppos.YReverse();
94   Handle(Geom_ToroidalSurface) 
95     gtor = new Geom_ToroidalSurface(ppos,r,r);
96   Data->ChangeSurf(ChFiKPart_IndexSurfaceInDS(gtor,DStr));
97
98   //on compare l orientation du tore a celle de la face en bout.
99   //------------------------------------------------------------
100   gp_Pnt pp;
101   gp_Vec du,dv;
102   ElSLib::TorusD1(0.,M_PI/2,ppos,r,r,pp,du,dv);
103   gp_Dir drot(du.Crossed(dv));
104   Standard_Boolean reversecur = ( drot.Dot(dplnat) <= 0. );
105   Standard_Boolean reversefil = ( drot.Dot(dfpl) <= 0. );
106   if (reversefil) { Data->ChangeOrientation() = TopAbs_REVERSED; }
107   else { Data->ChangeOrientation() = TopAbs_FORWARD; }
108
109   //on charge les FaceInterferences avec les pcurves et courbes 3d.
110   //-----------------------------------------------------------------
111   
112   //du cote du plan
113   //---------------
114   gp_Ax2 circAx2 = ppos.Ax2();
115   circAx2.SetLocation(pcirc);
116   Handle(Geom_Circle) GC = new Geom_Circle(circAx2,r);
117   Standard_Real u,v;
118   ElSLib::Parameters(pl,pcirc,u,v);
119   gp_Pnt2d p2dcirc(u,v);
120   gp_Dir2d dx2d(dpl1.Dot(pl.Position().XDirection()),
121                 dpl1.Dot(pl.Position().YDirection()));
122   gp_Dir2d dy2d(ppos.YDirection().Dot(pl.Position().XDirection()),
123                 ppos.YDirection().Dot(pl.Position().YDirection()));
124   gp_Ax22d circ2dax(p2dcirc,dx2d,dy2d);
125   Handle(Geom2d_Circle) GC2d = new Geom2d_Circle(circ2dax,r);
126   gp_Pnt2d p2dlin(0.,M_PI/2);
127   Handle(Geom2d_Line) GL2d = new Geom2d_Line(p2dlin,gp::DX2d());
128   TopAbs_Orientation trans = TopAbs_REVERSED; 
129   if (reversecur) trans = TopAbs_FORWARD; 
130   Data->ChangeInterferenceOnS1().
131     SetInterference(ChFiKPart_IndexCurveInDS(GC,DStr),trans,GC2d,GL2d);
132   
133   //du cote pointu
134   //--------------
135   Handle(Geom_Curve) bid;
136   Handle(Geom2d_Curve) bid2d;
137   p2dlin.SetCoord(0.,M_PI);
138   Handle(Geom2d_Line) GL2dcoin = new Geom2d_Line(p2dlin,gp::DX2d());
139   Data->ChangeInterferenceOnS2().
140     SetInterference(ChFiKPart_IndexCurveInDS(bid,DStr),trans,bid2d,GL2dcoin);
141
142   //et les points
143   //-------------
144   Data->ChangeVertexFirstOnS1().SetPoint(pp);
145   ElSLib::TorusD0(alpha,M_PI/2,ppos,r,r,pp);
146   Data->ChangeVertexLastOnS1().SetPoint(pp);
147   Data->ChangeInterferenceOnS1().SetFirstParameter(0.);
148   Data->ChangeInterferenceOnS1().SetLastParameter(alpha);
149   Data->ChangeInterferenceOnS2().SetFirstParameter(0.);
150   Data->ChangeInterferenceOnS2().SetLastParameter(alpha);
151
152   return Standard_True;
153 }