| // Created on: 1992-09-02 | |
| // Created by: Remi GILET | |
| // Copyright (c) 1992-1999 Matra Datavision | |
| // Copyright (c) 1999-2014 OPEN CASCADE SAS | |
| // | |
| // This file is part of Open CASCADE Technology software library. | |
| // | |
| // This library is free software; you can redistribute it and/or modify it under | |
| // the terms of the GNU Lesser General Public License version 2.1 as published | |
| // by the Free Software Foundation, with special exception defined in the file | |
| // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
| // distribution for complete text of the license and disclaimer of any warranty. | |
| // | |
| // Alternatively, this file may be used under the terms of Open CASCADE | |
| // commercial license or contractual agreement. | |
| #include <gce_MakeCylinder.hxx> | |
| #include <gp.hxx> | |
| #include <gp_Ax1.hxx> | |
| #include <gp_Ax2.hxx> | |
| #include <gp_Circ.hxx> | |
| #include <gp_Cylinder.hxx> | |
| #include <gp_Lin.hxx> | |
| #include <gp_Pnt.hxx> | |
| #include <StdFail_NotDone.hxx> | |
| //================================================================================================= | |
| gce_MakeCylinder::gce_MakeCylinder(const gp_Ax2& A2, const double Radius) | |
| { | |
| if (Radius < 0.0) | |
| { | |
| TheError = gce_NegativeRadius; | |
| } | |
| else | |
| { | |
| TheCylinder = gp_Cylinder(A2, Radius); | |
| TheError = gce_Done; | |
| } | |
| } | |
| //================================================================================================= | |
| gce_MakeCylinder::gce_MakeCylinder(const gp_Ax1& Axis, const double Radius) | |
| { | |
| if (Radius < 0.0) | |
| { | |
| TheError = gce_NegativeRadius; | |
| } | |
| else | |
| { | |
| gp_Dir D(Axis.Direction()); | |
| gp_Dir Direc; | |
| double x = D.X(); | |
| double y = D.Y(); | |
| double z = D.Z(); | |
| if (std::abs(x) > gp::Resolution()) | |
| { | |
| Direc = gp_Dir(-y, x, 0.0); | |
| } | |
| else if (std::abs(y) > gp::Resolution()) | |
| { | |
| Direc = gp_Dir(0.0, -z, y); | |
| } | |
| else if (std::abs(z) > gp::Resolution()) | |
| { | |
| Direc = gp_Dir(z, 0.0, -x); | |
| } | |
| TheCylinder = gp_Cylinder(gp_Ax2(Axis.Location(), D, Direc), Radius); | |
| TheError = gce_Done; | |
| } | |
| } | |
| //================================================================================================= | |
| gce_MakeCylinder::gce_MakeCylinder(const gp_Circ& Circ) | |
| { | |
| TheCylinder = gp_Cylinder(Circ.Position(), Circ.Radius()); | |
| TheError = gce_Done; | |
| } | |
| //================================================================================================= | |
| gce_MakeCylinder::gce_MakeCylinder(const gp_Pnt& P1, const gp_Pnt& P2, const gp_Pnt& P3) | |
| { | |
| // P1 and P2 define the cylinder axis, the distance from P3 to the axis | |
| // gives the cylinder radius. | |
| if (P1.Distance(P2) < gp::Resolution()) | |
| { | |
| TheError = gce_ConfusedPoints; | |
| } | |
| else | |
| { | |
| gp_Dir D1(P2.XYZ() - P1.XYZ()); | |
| gp_Dir D2; | |
| double x = D1.X(); | |
| double y = D1.Y(); | |
| double z = D1.Z(); | |
| if (std::abs(x) > gp::Resolution()) | |
| { | |
| D2 = gp_Dir(-y, x, 0.0); | |
| } | |
| else if (std::abs(y) > gp::Resolution()) | |
| { | |
| D2 = gp_Dir(0.0, -z, y); | |
| } | |
| else if (std::abs(z) > gp::Resolution()) | |
| { | |
| D2 = gp_Dir(z, 0.0, -x); | |
| } | |
| TheCylinder = gp_Cylinder(gp_Ax2(P1, D1, D2), gp_Lin(P1, D1).Distance(P3)); | |
| TheError = gce_Done; | |
| } | |
| } | |
| //================================================================================================= | |
| gce_MakeCylinder::gce_MakeCylinder(const gp_Cylinder& Cyl, const double Dist) | |
| { | |
| double Rad = Cyl.Radius() + Dist; | |
| if (Rad < 0.) | |
| { | |
| TheError = gce_NegativeRadius; | |
| } | |
| else | |
| { | |
| TheCylinder = gp_Cylinder(Cyl); | |
| TheCylinder.SetRadius(Rad); | |
| TheError = gce_Done; | |
| } | |
| } | |
| //================================================================================================= | |
| gce_MakeCylinder::gce_MakeCylinder(const gp_Cylinder& Cyl, const gp_Pnt& P) | |
| { | |
| gp_Lin L(Cyl.Axis()); | |
| double Rad = L.Distance(P); | |
| TheCylinder = gp_Cylinder(Cyl); | |
| TheCylinder.SetRadius(Rad); | |
| TheError = gce_Done; | |
| } | |
| //================================================================================================= | |
| const gp_Cylinder& gce_MakeCylinder::Value() const | |
| { | |
| StdFail_NotDone_Raise_if(TheError != gce_Done, "gce_MakeCylinder::Value() - no result"); | |
| return TheCylinder; | |
| } |