summaryrefslogtreecommitdiff
path: root/src/gce/gce_MakeCylinder.cxx
blob: 69623c3452b293f02d48152f070f8a2f12fae36e (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
// File:	gce_MakeCylinder.cxx
// Created:	Wed Sep  2 10:34:28 1992
// Author:	Remi GILET
//		<reg@sdsun1>

#include <gce_MakeCylinder.ixx>
#include <StdFail_NotDone.hxx>
#include <gp.hxx>
#include <gp_Lin.hxx>

//=========================================================================
//  Constructions d un cylindre de gp par son Ax2 A2 et son rayon         +
//  Radius.                                                               +
//=========================================================================

gce_MakeCylinder::gce_MakeCylinder(const gp_Ax2&       A2     ,
				   const Standard_Real Radius ) 
{
  if (Radius < 0.0) { TheError = gce_NegativeRadius; }
  else {
    TheCylinder = gp_Cylinder(A2,Radius);
    TheError = gce_Done;
  }
}

//=========================================================================
//  Constructions d un cylindre de gp par son axe Axis et son rayon       +
//  Radius.                                                               +
//=========================================================================

gce_MakeCylinder::gce_MakeCylinder(const gp_Ax1&       Axis   ,
				   const Standard_Real Radius ) 
{
  if (Radius < 0.0) { TheError = gce_NegativeRadius; }
  else {
    gp_Dir D(Axis.Direction());
    gp_Dir Direc;
    Standard_Real x = D.X();
    Standard_Real y = D.Y();
    Standard_Real z = D.Z();
    if (Abs(x) > gp::Resolution()) { Direc = gp_Dir(-y,x,0.0); }
    else if (Abs(y) > gp::Resolution()) { Direc = gp_Dir(-y,x,0.0); }
    else if (Abs(z) > gp::Resolution()) { Direc = gp_Dir(0.0,-z,y); }
    TheCylinder = gp_Cylinder(gp_Ax2(Axis.Location(),D,Direc),Radius);
    TheError = gce_Done;
  }
}

//=========================================================================
//  Constructions d un cylindre de gp par un cercle.                      +
//=========================================================================

gce_MakeCylinder::gce_MakeCylinder(const gp_Circ& Circ ) 
{
  TheCylinder = gp_Cylinder(Circ.Position(),Circ.Radius());
  TheError = gce_Done;
}

//=========================================================================
//  Constructions d un cylindre de gp par trois points P1, P2, P3.        +
//  P1 et P2 donnent l axe du cylindre, la distance de P3 a l axe donne   +
//  le rayon du cylindre.                                                 +
//=========================================================================

gce_MakeCylinder::gce_MakeCylinder(const gp_Pnt& P1 ,
				   const gp_Pnt& P2 ,
				   const gp_Pnt& P3 ) 
{
  if (P1.Distance(P2) < gp::Resolution()) { TheError = gce_ConfusedPoints; }
  else {
    gp_Dir D1(P2.XYZ()-P1.XYZ());
    gp_Dir D2;
    Standard_Real x = D1.X();
    Standard_Real y = D1.Y();
    Standard_Real z = D1.Z();
    if (Abs(x) > gp::Resolution()) { D2 = gp_Dir(-y,x,0.0); }
    else if (Abs(y) > gp::Resolution()) { D2 = gp_Dir(-y,x,0.0); }
    else if (Abs(z) > gp::Resolution()) { D2 = gp_Dir(0.0,-z,y); }
    TheCylinder = gp_Cylinder(gp_Ax2(P1,D1,D2 ),gp_Lin(P1,D1).Distance(P3));
    TheError = gce_Done;
  }
}

//=========================================================================
//  Constructions d un cylindre de gp concentrique a un autre cylindre de +
//  gp a une distance Dist.                                               +
//=========================================================================

gce_MakeCylinder::gce_MakeCylinder(const gp_Cylinder&  Cyl  ,
				   const Standard_Real Dist ) 
{
  Standard_Real Rad = Cyl.Radius()+Dist;
  if (Rad < 0.) { TheError = gce_NegativeRadius; }
  else {
    TheCylinder = gp_Cylinder(Cyl);
    TheCylinder.SetRadius(Rad);
    TheError = gce_Done;
  }
}

//=========================================================================
//  Constructions d un cylindre de gp concentrique a un autre cylindre de +
//  gp passant par le point P.                                            +
//=========================================================================

gce_MakeCylinder::gce_MakeCylinder(const gp_Cylinder& Cyl ,
				   const gp_Pnt&      P   ) 
{
  gp_Lin L(Cyl.Axis());
  Standard_Real Rad = L.Distance(P);
  TheCylinder = gp_Cylinder(Cyl);
  TheCylinder.SetRadius(Rad);
  TheError = gce_Done;
}

const gp_Cylinder& gce_MakeCylinder::Value() const
{ 
  StdFail_NotDone_Raise_if(!TheError == gce_Done,"");
  return TheCylinder;
}

const gp_Cylinder& gce_MakeCylinder::Operator() const 
{
  return Value();
}

gce_MakeCylinder::operator gp_Cylinder() const
{
  return Value();
}