summaryrefslogtreecommitdiff
path: root/src/ChFiKPart/ChFiKPart_ComputeData_Rotule.cxx
blob: 078eb13ab5e575b3f8be590ba9ce0c16681e6049 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// File:	ChFiKPart_ComputeData_Rotule.cxx
// Created:	Mon Jun 27 15:22:06 1994
// Author:	Laurent BOURESCHE
//		<lbo@phylox>


#include <ChFiKPart_ComputeData.jxx>
#include <ChFiKPart_ComputeData_Fcts.hxx>

#include <Precision.hxx>
#include <gp.hxx>
#include <gp_Pnt2d.hxx>
#include <gp_Dir2d.hxx>
#include <gp_Ax22d.hxx>
#include <gp_Lin2d.hxx>
#include <gp_Pnt.hxx>
#include <gp_Dir.hxx>
#include <gp_Vec.hxx>
#include <gp_Lin.hxx>
#include <gp_Ax2.hxx>
#include <gp_Ax3.hxx>
#include <gp_Pln.hxx>

#include <ElCLib.hxx>
#include <ElSLib.hxx>

#include <Geom2d_Line.hxx>
#include <Geom_Line.hxx>
#include <Geom2d_Circle.hxx>
#include <Geom_Circle.hxx>
#include <Geom_ToroidalSurface.hxx>

#include <IntAna_QuadQuadGeo.hxx>

//=======================================================================
//function : MakeRotule
//Purpose  : cas plan/plan.
//=======================================================================

Standard_Boolean ChFiKPart_MakeRotule(TopOpeBRepDS_DataStructure& DStr,
				      const Handle(ChFiDS_SurfData)& Data, 
				      const gp_Pln& pl, 
				      const gp_Pln& pl1, 
				      const gp_Pln& pl2, 
				      const TopAbs_Orientation opl,
				      const TopAbs_Orientation opl1,
				      const TopAbs_Orientation opl2,
				      const Standard_Real r, 
				      const TopAbs_Orientation ofpl)
{

  //calcul du tore.
  //---------------
  gp_Ax3 pos = pl.Position();
  gp_Dir dpl = pos.XDirection().Crossed(pos.YDirection());
  gp_Dir dfpl = dpl;
  gp_Dir dplnat = dpl;
  if (opl == TopAbs_REVERSED) { dpl.Reverse(); }
  if (ofpl == TopAbs_REVERSED) { dfpl.Reverse(); }
  pos = pl1.Position();
  gp_Dir dpl1 = pos.XDirection().Crossed(pos.YDirection());
  if (opl1 == TopAbs_REVERSED) { dpl1.Reverse(); }
  pos = pl2.Position();
  gp_Dir dpl2 = pos.XDirection().Crossed(pos.YDirection());
  if (opl2 == TopAbs_REVERSED) { dpl2.Reverse(); }

  Standard_Real alpha = dpl1.Angle(dpl2);

  IntAna_QuadQuadGeo LInt (pl1,pl2,Precision::Angular(),
			   Precision::Confusion());
  gp_Pnt ptor,pcirc;
  if (LInt.IsDone()) {

    pcirc = ElCLib::Value(ElCLib::Parameter(LInt.Line(1),pl.Location()),
			 LInt.Line(1));
    ptor.SetCoord(pcirc.X()+r*dpl.X(),
		  pcirc.Y()+r*dpl.Y(),
		  pcirc.Z()+r*dpl.Z());
  }
  else { return Standard_False; }

  gp_Ax3 ppos(ptor,dpl.Reversed(),dpl1);
  if(ppos.YDirection().Dot(dpl2) < 0.) ppos.YReverse();
  Handle(Geom_ToroidalSurface) 
    gtor = new Geom_ToroidalSurface(ppos,r,r);
  Data->ChangeSurf(ChFiKPart_IndexSurfaceInDS(gtor,DStr));

  //on compare l orientation du tore a celle de la face en bout.
  //------------------------------------------------------------
  gp_Pnt pp;
  gp_Vec du,dv;
  ElSLib::TorusD1(0.,PI/2,ppos,r,r,pp,du,dv);
  gp_Dir drot(du.Crossed(dv));
  Standard_Boolean reversecur = ( drot.Dot(dplnat) <= 0. );
  Standard_Boolean reversefil = ( drot.Dot(dfpl) <= 0. );
  if (reversefil) { Data->ChangeOrientation() = TopAbs_REVERSED; }
  else { Data->ChangeOrientation() = TopAbs_FORWARD; }

  //on charge les FaceInterferences avec les pcurves et courbes 3d.
  //-----------------------------------------------------------------
  
  //du cote du plan
  //---------------
  gp_Ax2 circAx2 = ppos.Ax2();
  circAx2.SetLocation(pcirc);
  Handle(Geom_Circle) GC = new Geom_Circle(circAx2,r);
  Standard_Real u,v;
  ElSLib::Parameters(pl,pcirc,u,v);
  gp_Pnt2d p2dcirc(u,v);
  gp_Dir2d dx2d(dpl1.Dot(pl.Position().XDirection()),
		dpl1.Dot(pl.Position().YDirection()));
  gp_Dir2d dy2d(ppos.YDirection().Dot(pl.Position().XDirection()),
		ppos.YDirection().Dot(pl.Position().YDirection()));
  gp_Ax22d circ2dax(p2dcirc,dx2d,dy2d);
  Handle(Geom2d_Circle) GC2d = new Geom2d_Circle(circ2dax,r);
  gp_Pnt2d p2dlin(0.,PI/2);
  Handle(Geom2d_Line) GL2d = new Geom2d_Line(p2dlin,gp::DX2d());
  TopAbs_Orientation trans = TopAbs_REVERSED; 
  if (reversecur) trans = TopAbs_FORWARD; 
  Data->ChangeInterferenceOnS1().
    SetInterference(ChFiKPart_IndexCurveInDS(GC,DStr),trans,GC2d,GL2d);
  
  //du cote pointu
  //--------------
  Handle(Geom_Curve) bid;
  Handle(Geom2d_Curve) bid2d;
  p2dlin.SetCoord(0.,PI);
  Handle(Geom2d_Line) GL2dcoin = new Geom2d_Line(p2dlin,gp::DX2d());
  Data->ChangeInterferenceOnS2().
    SetInterference(ChFiKPart_IndexCurveInDS(bid,DStr),trans,bid2d,GL2dcoin);

  //et les points
  //-------------
  Data->ChangeVertexFirstOnS1().SetPoint(pp);
  ElSLib::TorusD0(alpha,PI/2,ppos,r,r,pp);
  Data->ChangeVertexLastOnS1().SetPoint(pp);
  Data->ChangeInterferenceOnS1().SetFirstParameter(0.);
  Data->ChangeInterferenceOnS1().SetLastParameter(alpha);
  Data->ChangeInterferenceOnS2().SetFirstParameter(0.);
  Data->ChangeInterferenceOnS2().SetLastParameter(alpha);

  return Standard_True;
}