7fd59977 |
1 | // File: gce_MakeCylinder.cxx |
2 | // Created: Wed Sep 2 10:34:28 1992 |
3 | // Author: Remi GILET |
4 | // <reg@sdsun1> |
5 | |
6 | #include <gce_MakeCylinder.ixx> |
7 | #include <StdFail_NotDone.hxx> |
8 | #include <gp.hxx> |
9 | #include <gp_Lin.hxx> |
10 | |
11 | //========================================================================= |
12 | // Constructions d un cylindre de gp par son Ax2 A2 et son rayon + |
13 | // Radius. + |
14 | //========================================================================= |
15 | |
16 | gce_MakeCylinder::gce_MakeCylinder(const gp_Ax2& A2 , |
17 | const Standard_Real Radius ) |
18 | { |
19 | if (Radius < 0.0) { TheError = gce_NegativeRadius; } |
20 | else { |
21 | TheCylinder = gp_Cylinder(A2,Radius); |
22 | TheError = gce_Done; |
23 | } |
24 | } |
25 | |
26 | //========================================================================= |
27 | // Constructions d un cylindre de gp par son axe Axis et son rayon + |
28 | // Radius. + |
29 | //========================================================================= |
30 | |
31 | gce_MakeCylinder::gce_MakeCylinder(const gp_Ax1& Axis , |
32 | const Standard_Real Radius ) |
33 | { |
34 | if (Radius < 0.0) { TheError = gce_NegativeRadius; } |
35 | else { |
36 | gp_Dir D(Axis.Direction()); |
37 | gp_Dir Direc; |
38 | Standard_Real x = D.X(); |
39 | Standard_Real y = D.Y(); |
40 | Standard_Real z = D.Z(); |
41 | if (Abs(x) > gp::Resolution()) { Direc = gp_Dir(-y,x,0.0); } |
42 | else if (Abs(y) > gp::Resolution()) { Direc = gp_Dir(-y,x,0.0); } |
43 | else if (Abs(z) > gp::Resolution()) { Direc = gp_Dir(0.0,-z,y); } |
44 | TheCylinder = gp_Cylinder(gp_Ax2(Axis.Location(),D,Direc),Radius); |
45 | TheError = gce_Done; |
46 | } |
47 | } |
48 | |
49 | //========================================================================= |
50 | // Constructions d un cylindre de gp par un cercle. + |
51 | //========================================================================= |
52 | |
53 | gce_MakeCylinder::gce_MakeCylinder(const gp_Circ& Circ ) |
54 | { |
55 | TheCylinder = gp_Cylinder(Circ.Position(),Circ.Radius()); |
56 | TheError = gce_Done; |
57 | } |
58 | |
59 | //========================================================================= |
60 | // Constructions d un cylindre de gp par trois points P1, P2, P3. + |
61 | // P1 et P2 donnent l axe du cylindre, la distance de P3 a l axe donne + |
62 | // le rayon du cylindre. + |
63 | //========================================================================= |
64 | |
65 | gce_MakeCylinder::gce_MakeCylinder(const gp_Pnt& P1 , |
66 | const gp_Pnt& P2 , |
67 | const gp_Pnt& P3 ) |
68 | { |
69 | if (P1.Distance(P2) < gp::Resolution()) { TheError = gce_ConfusedPoints; } |
70 | else { |
71 | gp_Dir D1(P2.XYZ()-P1.XYZ()); |
72 | gp_Dir D2; |
73 | Standard_Real x = D1.X(); |
74 | Standard_Real y = D1.Y(); |
75 | Standard_Real z = D1.Z(); |
76 | if (Abs(x) > gp::Resolution()) { D2 = gp_Dir(-y,x,0.0); } |
77 | else if (Abs(y) > gp::Resolution()) { D2 = gp_Dir(-y,x,0.0); } |
78 | else if (Abs(z) > gp::Resolution()) { D2 = gp_Dir(0.0,-z,y); } |
79 | TheCylinder = gp_Cylinder(gp_Ax2(P1,D1,D2 ),gp_Lin(P1,D1).Distance(P3)); |
80 | TheError = gce_Done; |
81 | } |
82 | } |
83 | |
84 | //========================================================================= |
85 | // Constructions d un cylindre de gp concentrique a un autre cylindre de + |
86 | // gp a une distance Dist. + |
87 | //========================================================================= |
88 | |
89 | gce_MakeCylinder::gce_MakeCylinder(const gp_Cylinder& Cyl , |
90 | const Standard_Real Dist ) |
91 | { |
92 | Standard_Real Rad = Cyl.Radius()+Dist; |
93 | if (Rad < 0.) { TheError = gce_NegativeRadius; } |
94 | else { |
95 | TheCylinder = gp_Cylinder(Cyl); |
96 | TheCylinder.SetRadius(Rad); |
97 | TheError = gce_Done; |
98 | } |
99 | } |
100 | |
101 | //========================================================================= |
102 | // Constructions d un cylindre de gp concentrique a un autre cylindre de + |
103 | // gp passant par le point P. + |
104 | //========================================================================= |
105 | |
106 | gce_MakeCylinder::gce_MakeCylinder(const gp_Cylinder& Cyl , |
107 | const gp_Pnt& P ) |
108 | { |
109 | gp_Lin L(Cyl.Axis()); |
110 | Standard_Real Rad = L.Distance(P); |
111 | TheCylinder = gp_Cylinder(Cyl); |
112 | TheCylinder.SetRadius(Rad); |
113 | TheError = gce_Done; |
114 | } |
115 | |
116 | const gp_Cylinder& gce_MakeCylinder::Value() const |
117 | { |
118 | StdFail_NotDone_Raise_if(!TheError == gce_Done,""); |
119 | return TheCylinder; |
120 | } |
121 | |
122 | const gp_Cylinder& gce_MakeCylinder::Operator() const |
123 | { |
124 | return Value(); |
125 | } |
126 | |
127 | gce_MakeCylinder::operator gp_Cylinder() const |
128 | { |
129 | return Value(); |
130 | } |
131 | |
132 | |
133 | |
134 | |
135 | |