0024157: Parallelization of assembly part of BO
[occt.git] / src / gce / gce_MakeCylinder.cxx
1 // Created on: 1992-09-02
2 // Created by: Remi GILET
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22 #include <gce_MakeCylinder.ixx>
23 #include <StdFail_NotDone.hxx>
24 #include <gp.hxx>
25 #include <gp_Lin.hxx>
26
27 //=========================================================================
28 //  Constructions d un cylindre de gp par son Ax2 A2 et son rayon         +
29 //  Radius.                                                               +
30 //=========================================================================
31
32 gce_MakeCylinder::gce_MakeCylinder(const gp_Ax2&       A2     ,
33                                    const Standard_Real Radius ) 
34 {
35   if (Radius < 0.0) { TheError = gce_NegativeRadius; }
36   else {
37     TheCylinder = gp_Cylinder(A2,Radius);
38     TheError = gce_Done;
39   }
40 }
41
42 //=========================================================================
43 //  Constructions d un cylindre de gp par son axe Axis et son rayon       +
44 //  Radius.                                                               +
45 //=========================================================================
46
47 gce_MakeCylinder::gce_MakeCylinder(const gp_Ax1&       Axis   ,
48                                    const Standard_Real Radius ) 
49 {
50   if (Radius < 0.0) { TheError = gce_NegativeRadius; }
51   else {
52     gp_Dir D(Axis.Direction());
53     gp_Dir Direc;
54     Standard_Real x = D.X();
55     Standard_Real y = D.Y();
56     Standard_Real z = D.Z();
57     if (Abs(x) > gp::Resolution()) { Direc = gp_Dir(-y,x,0.0); }
58     else if (Abs(y) > gp::Resolution()) { Direc = gp_Dir(-y,x,0.0); }
59     else if (Abs(z) > gp::Resolution()) { Direc = gp_Dir(0.0,-z,y); }
60     TheCylinder = gp_Cylinder(gp_Ax2(Axis.Location(),D,Direc),Radius);
61     TheError = gce_Done;
62   }
63 }
64
65 //=========================================================================
66 //  Constructions d un cylindre de gp par un cercle.                      +
67 //=========================================================================
68
69 gce_MakeCylinder::gce_MakeCylinder(const gp_Circ& Circ ) 
70 {
71   TheCylinder = gp_Cylinder(Circ.Position(),Circ.Radius());
72   TheError = gce_Done;
73 }
74
75 //=========================================================================
76 //  Constructions d un cylindre de gp par trois points P1, P2, P3.        +
77 //  P1 et P2 donnent l axe du cylindre, la distance de P3 a l axe donne   +
78 //  le rayon du cylindre.                                                 +
79 //=========================================================================
80
81 gce_MakeCylinder::gce_MakeCylinder(const gp_Pnt& P1 ,
82                                    const gp_Pnt& P2 ,
83                                    const gp_Pnt& P3 ) 
84 {
85   if (P1.Distance(P2) < gp::Resolution()) { TheError = gce_ConfusedPoints; }
86   else {
87     gp_Dir D1(P2.XYZ()-P1.XYZ());
88     gp_Dir D2;
89     Standard_Real x = D1.X();
90     Standard_Real y = D1.Y();
91     Standard_Real z = D1.Z();
92     if (Abs(x) > gp::Resolution()) { D2 = gp_Dir(-y,x,0.0); }
93     else if (Abs(y) > gp::Resolution()) { D2 = gp_Dir(-y,x,0.0); }
94     else if (Abs(z) > gp::Resolution()) { D2 = gp_Dir(0.0,-z,y); }
95     TheCylinder = gp_Cylinder(gp_Ax2(P1,D1,D2 ),gp_Lin(P1,D1).Distance(P3));
96     TheError = gce_Done;
97   }
98 }
99
100 //=========================================================================
101 //  Constructions d un cylindre de gp concentrique a un autre cylindre de +
102 //  gp a une distance Dist.                                               +
103 //=========================================================================
104
105 gce_MakeCylinder::gce_MakeCylinder(const gp_Cylinder&  Cyl  ,
106                                    const Standard_Real Dist ) 
107 {
108   Standard_Real Rad = Cyl.Radius()+Dist;
109   if (Rad < 0.) { TheError = gce_NegativeRadius; }
110   else {
111     TheCylinder = gp_Cylinder(Cyl);
112     TheCylinder.SetRadius(Rad);
113     TheError = gce_Done;
114   }
115 }
116
117 //=========================================================================
118 //  Constructions d un cylindre de gp concentrique a un autre cylindre de +
119 //  gp passant par le point P.                                            +
120 //=========================================================================
121
122 gce_MakeCylinder::gce_MakeCylinder(const gp_Cylinder& Cyl ,
123                                    const gp_Pnt&      P   ) 
124 {
125   gp_Lin L(Cyl.Axis());
126   Standard_Real Rad = L.Distance(P);
127   TheCylinder = gp_Cylinder(Cyl);
128   TheCylinder.SetRadius(Rad);
129   TheError = gce_Done;
130 }
131
132 const gp_Cylinder& gce_MakeCylinder::Value() const
133
134   StdFail_NotDone_Raise_if(!TheError == gce_Done,"");
135   return TheCylinder;
136 }
137
138 const gp_Cylinder& gce_MakeCylinder::Operator() const 
139 {
140   return Value();
141 }
142
143 gce_MakeCylinder::operator gp_Cylinder() const
144 {
145   return Value();
146 }
147
148
149
150
151