0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / gce / gce_MakeCone.cxx
CommitLineData
b311480e 1// Created on: 1992-09-02
2// Created by: Remi GILET
3// Copyright (c) 1992-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
42cf5bc1 17
18#include <gce_MakeCone.hxx>
7fd59977 19#include <gp.hxx>
42cf5bc1 20#include <gp_Ax1.hxx>
21#include <gp_Ax2.hxx>
22#include <gp_Cone.hxx>
23#include <gp_Lin.hxx>
24#include <gp_Pnt.hxx>
25#include <StdFail_NotDone.hxx>
7fd59977 26
27//=========================================================================
28// Construction d un cone par son axe , le rayon de sa base et le demi +
29// angle d ouverture. +
30//=========================================================================
7fd59977 31gce_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 {
c6541a0c 37 if (Ang <= gp::Resolution() || M_PI/2-Ang <= gp::Resolution()) {
7fd59977 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
54gce_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)));
c6541a0c 77 if(Abs(M_PI/2.-angle) < RealEpsilon() || Abs(angle) < RealEpsilon()) { TheError = gce_NullRadius; return; }
7fd59977 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
103gce_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 )
126gce_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 )
139gce_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
152gce_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
171gce_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));
c6541a0c 184 if (Abs(M_PI/2.-Angle)<RealEpsilon() || Abs(Angle)<RealEpsilon()) {
7fd59977 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
204const gp_Cone& gce_MakeCone::Value() const
205{
2d2b3d53 206 StdFail_NotDone_Raise_if (TheError != gce_Done,
207 "gce_MakeCone::Value() - no result");
7fd59977 208 return TheCone;
209}
210
211const gp_Cone& gce_MakeCone::Operator() const
212{
213 return Value();
214}
215
216gce_MakeCone::operator gp_Cone() const
217{
218 return Value();
219}
220