1 // Created on: 1992-09-02
2 // Created by: Remi GILET
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <gce_MakeCylinder.hxx>
22 #include <gp_Circ.hxx>
23 #include <gp_Cylinder.hxx>
26 #include <StdFail_NotDone.hxx>
28 //=========================================================================
29 // Constructions d un cylindre de gp par son Ax2 A2 et son rayon +
31 //=========================================================================
32 gce_MakeCylinder::gce_MakeCylinder(const gp_Ax2& A2 ,
33 const Standard_Real Radius )
35 if (Radius < 0.0) { TheError = gce_NegativeRadius; }
37 TheCylinder = gp_Cylinder(A2,Radius);
42 //=========================================================================
43 // Constructions d un cylindre de gp par son axe Axis et son rayon +
45 //=========================================================================
47 gce_MakeCylinder::gce_MakeCylinder(const gp_Ax1& Axis ,
48 const Standard_Real Radius )
50 if (Radius < 0.0) { TheError = gce_NegativeRadius; }
52 gp_Dir D(Axis.Direction());
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);
65 //=========================================================================
66 // Constructions d un cylindre de gp par un cercle. +
67 //=========================================================================
69 gce_MakeCylinder::gce_MakeCylinder(const gp_Circ& Circ )
71 TheCylinder = gp_Cylinder(Circ.Position(),Circ.Radius());
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 //=========================================================================
81 gce_MakeCylinder::gce_MakeCylinder(const gp_Pnt& P1 ,
85 if (P1.Distance(P2) < gp::Resolution()) { TheError = gce_ConfusedPoints; }
87 gp_Dir D1(P2.XYZ()-P1.XYZ());
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));
100 //=========================================================================
101 // Constructions d un cylindre de gp concentrique a un autre cylindre de +
102 // gp a une distance Dist. +
103 //=========================================================================
105 gce_MakeCylinder::gce_MakeCylinder(const gp_Cylinder& Cyl ,
106 const Standard_Real Dist )
108 Standard_Real Rad = Cyl.Radius()+Dist;
109 if (Rad < 0.) { TheError = gce_NegativeRadius; }
111 TheCylinder = gp_Cylinder(Cyl);
112 TheCylinder.SetRadius(Rad);
117 //=========================================================================
118 // Constructions d un cylindre de gp concentrique a un autre cylindre de +
119 // gp passant par le point P. +
120 //=========================================================================
122 gce_MakeCylinder::gce_MakeCylinder(const gp_Cylinder& Cyl ,
125 gp_Lin L(Cyl.Axis());
126 Standard_Real Rad = L.Distance(P);
127 TheCylinder = gp_Cylinder(Cyl);
128 TheCylinder.SetRadius(Rad);
132 const gp_Cylinder& gce_MakeCylinder::Value() const
134 StdFail_NotDone_Raise_if(TheError != gce_Done,"");
138 const gp_Cylinder& gce_MakeCylinder::Operator() const
143 gce_MakeCylinder::operator gp_Cylinder() const