0024157: Parallelization of assembly part of BO
[occt.git] / src / gce / gce_MakeCone.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_MakeCone.ixx>
23 #include <StdFail_NotDone.hxx>
24 #include <gp.hxx>
25
26 //=========================================================================
27 //  Construction d un cone par son axe , le rayon de sa base et le demi   +
28 //  angle d ouverture.                                                    +
29 //=========================================================================
30
31 gce_MakeCone::gce_MakeCone(const gp_Ax2&       A2    ,
32                            const Standard_Real Ang   ,
33                            const Standard_Real Radius)
34 {
35   if (Radius < 0.0) { TheError = gce_NegativeRadius; }
36   else {
37     if (Ang <= gp::Resolution() || M_PI/2-Ang <= gp::Resolution()) {
38       TheError = gce_BadAngle;
39     }
40     else {
41       TheError = gce_Done;
42       TheCone = gp_Cone(A2,Ang,Radius);
43     }
44   }
45 }
46
47 //=========================================================================
48 //  Constructions d un cone de gp par quatre points P1, P2, P3 et P4.     +
49 //  P1 et P2 donnent l axe du cone, la distance de P3 a l axe donne       +
50 //  le rayon de la base du cone et la distance de P4 a l axe donne le     +
51 //  rayon du cone pour la section passant par P4.                         +
52 //=========================================================================
53
54 gce_MakeCone::gce_MakeCone(const gp_Pnt& P1 ,
55                            const gp_Pnt& P2 ,
56                            const gp_Pnt& P3 ,
57                            const gp_Pnt& P4 ) 
58 {
59   if (P1.Distance(P2)<RealEpsilon() || P3.Distance(P4)<RealEpsilon()) { TheError = gce_ConfusedPoints; return;  }
60
61   gp_Dir D1(P2.XYZ()-P1.XYZ());
62   Standard_Real cos = D1.Dot(gp_Dir(P4.XYZ()-P1.XYZ()));
63   Standard_Real dist = P1.Distance(P4);
64   gp_Pnt PP4(P1.XYZ()+cos*dist*D1.XYZ());
65   cos = D1.Dot(gp_Dir(P3.XYZ()-P1.XYZ()));
66   dist = P1.Distance(P3);
67   gp_Pnt PP3(P1.XYZ()+cos*dist*D1.XYZ());
68   
69   Standard_Real Dist13 = PP3.Distance(P1);
70   Standard_Real Dist14 = PP4.Distance(P1);
71   if(Abs(Dist13-Dist14)<RealEpsilon()) { TheError = gce_NullAngle;  return; }
72   gp_Lin L1(P1,D1);
73   Standard_Real Dist3 = L1.Distance(P3);
74   Standard_Real Dist4 = L1.Distance(P4);
75   Standard_Real DifRad = Dist3-Dist4;
76   Standard_Real angle = Abs(ATan(DifRad/(Dist13-Dist14)));
77   if(Abs(M_PI/2.-angle) < RealEpsilon() || Abs(angle) < RealEpsilon()) { TheError = gce_NullRadius; return; }
78   Standard_Real R1 = PP3.Distance(P3);
79   Standard_Real R2 = PP4.Distance(P4);
80   if (R1 < 0.0 || R2 < 0.0) { TheError = gce_NegativeRadius; return; }
81   gp_Dir DD1(PP4.XYZ()-PP3.XYZ());
82   gp_Dir D2;
83   Standard_Real x = DD1.X();
84   Standard_Real y = DD1.Y();
85   Standard_Real z = DD1.Z();
86   if (Abs(x) > gp::Resolution()) { D2 = gp_Dir(-y,x,0.0); }
87   else if (Abs(y) > gp::Resolution()) { D2 = gp_Dir(-y,x,0.0); }
88   else if (Abs(z) > gp::Resolution()) { D2 = gp_Dir(0.0,-z,y); }
89   if (R1 > R2) { angle *= -1; }
90   TheCone = gp_Cone(gp_Ax2(PP3,DD1,D2),angle,R1);
91   TheError = gce_Done;
92 }
93  
94  
95
96 //=========================================================================
97 //  Constructions d un cone de gp par son axe et deux points P1, P2.      +
98 //  La distance de P1 a l axe donne le rayon de la base du cone et la     +
99 //  distance de P2 a l axe donne le rayon du cone pour la section passant +
100 //  par P2.                                                               +
101 //=========================================================================
102
103 gce_MakeCone::gce_MakeCone(const gp_Ax1&   Axis  ,
104                            const gp_Pnt&   P1    ,
105                            const gp_Pnt&   P2    ) 
106 {
107   gp_Pnt P3(Axis.Location());
108   gp_Pnt P4(P3.XYZ()+Axis.Direction().XYZ());
109   gce_MakeCone Cone(P3,P4,P1,P2);
110   if (Cone.IsDone()) {
111     TheCone = Cone.Value();
112     TheError = gce_Done;
113   }
114   else { 
115     TheError = Cone.Status();
116   }
117 }
118
119 //=========================================================================
120 //  Constructions d un cone parallele a un autre cone passant par un      +
121 //  donne.                                                                +
122 //=========================================================================
123
124 //gce_MakeCone::gce_MakeCone(const gp_Cone&  cone ,
125 //                         const gp_Pnt&   P    ) 
126 gce_MakeCone::gce_MakeCone(const gp_Cone&   ,
127                            const gp_Pnt&       ) 
128 {
129   TheError = gce_ConfusedPoints;
130 }
131
132 //=========================================================================
133 //  Constructions d un cone parallele a un autre cone a une distance      +
134 //  donnee.                                                               +
135 //=========================================================================
136
137 //gce_MakeCone::gce_MakeCone(const gp_Cone&      cone ,
138 //                         const Standard_Real Dist ) 
139 gce_MakeCone::gce_MakeCone(const gp_Cone&       ,
140                            const Standard_Real  ) 
141 {
142   TheError = gce_Done;
143 }
144
145 //=========================================================================
146 //  Constructions d un cone de gp par son axe et deux points P1, P2.      +
147 //  La distance de P1 a l axe donne le rayon de la base du cone et la     +
148 //  distance de P2 a l axe donne le rayon du cone pour la section passant +
149 //  par P2.                                                               +
150 //=========================================================================
151
152 gce_MakeCone::gce_MakeCone(const gp_Lin&   Axis  ,
153                            const gp_Pnt&   P1    ,
154                            const gp_Pnt&   P2    ) 
155 {
156   gp_Pnt P3(Axis.Location());
157   gp_Pnt P4(P3.XYZ()+Axis.Direction().XYZ());
158   gce_MakeCone Cone(P3,P4,P1,P2);
159   if (Cone.IsDone()) {
160     TheCone = Cone.Value();
161     TheError = gce_Done;
162   }
163   else { TheError = Cone.Status(); }
164 }
165
166 //=========================================================================
167 //  cone par deux points (axe du cone.) et deux rayons (rayon des         +
168 //  sections passant par chacun de ces points).                           +
169 //=========================================================================
170
171 gce_MakeCone::gce_MakeCone(const gp_Pnt&       P1   ,
172                            const gp_Pnt&       P2   ,
173                            const Standard_Real R1   ,
174                            const Standard_Real R2   ) 
175 {
176   Standard_Real dist = P1.Distance(P2);
177   if (dist < RealEpsilon()) { TheError = gce_NullAxis; }
178   else {
179     if (R1 < 0.0 || R2 < 0.0) {
180       TheError = gce_NegativeRadius;
181     }
182     else {
183       Standard_Real Angle = Abs(atan((R1-R2)/dist));
184       if (Abs(M_PI/2.-Angle)<RealEpsilon() || Abs(Angle)<RealEpsilon()) {
185         TheError = gce_NullAngle;
186       }
187       else {
188         gp_Dir D1(P2.XYZ()-P1.XYZ());
189         gp_Dir D2;
190         Standard_Real x = D1.X();
191         Standard_Real y = D1.Y();
192         Standard_Real z = D1.Z();
193         if (Abs(x) > gp::Resolution()) { D2 = gp_Dir(-y,x,0.0); }
194         else if (Abs(y) > gp::Resolution()) { D2 = gp_Dir(-y,x,0.0); }
195         else if (Abs(z) > gp::Resolution()) { D2 = gp_Dir(0.0,-z,y); }
196         if (R1 > R2) { Angle *= -1; }
197         TheCone = gp_Cone(gp_Ax2(P1,D1,D2),Angle,R1);
198         TheError = gce_Done;
199       }
200     }
201   }
202 }
203
204 const gp_Cone& gce_MakeCone::Value() const
205
206   StdFail_NotDone_Raise_if(!TheError == gce_Done,"");
207   return TheCone;
208 }
209
210 const gp_Cone& gce_MakeCone::Operator() const 
211 {
212   return Value();
213 }
214
215 gce_MakeCone::operator gp_Cone() const
216 {
217   return Value();
218 }
219