0024428: Implementation of LGPL license
[occt.git] / src / BRepPrim / BRepPrim_Sphere.cxx
1 // Created on: 1992-11-06
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and / or modify it
9 // under the terms of the GNU Lesser General Public 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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <BRepPrim_Sphere.ixx>
18
19 #include <gp.hxx>
20 #include <gp_Ax2d.hxx>
21 #include <Precision.hxx>
22
23 #include <Geom_SphericalSurface.hxx>
24 #include <Geom_Circle.hxx>
25 #include <Geom2d_Circle.hxx>
26
27 // parameters on the meridian
28
29 #define PMIN (-0.5*M_PI)
30 #define PMAX (0.5*M_PI)
31
32 //=======================================================================
33 //function : BRepPrim_Sphere
34 //purpose  : 
35 //=======================================================================
36
37 BRepPrim_Sphere::BRepPrim_Sphere(const Standard_Real Radius) :
38        BRepPrim_Revolution(gp::XOY(),PMIN,PMAX),
39        myRadius(Radius)
40 {
41   SetMeridian();
42 }
43
44 //=======================================================================
45 //function : BRepPrim_Sphere
46 //purpose  : 
47 //=======================================================================
48
49 BRepPrim_Sphere::BRepPrim_Sphere(const gp_Pnt& Center, 
50                                  const Standard_Real Radius) :
51        BRepPrim_Revolution(gp_Ax2(Center,gp_Dir(0,0,1),gp_Dir(1,0,0)),
52                            PMIN,PMAX),
53        myRadius(Radius)
54 {
55   SetMeridian();
56 }
57
58 //=======================================================================
59 //function : BRepPrim_Sphere
60 //purpose  : 
61 //=======================================================================
62
63 BRepPrim_Sphere::BRepPrim_Sphere(const gp_Ax2& Axes, 
64                                  const Standard_Real Radius) :
65        BRepPrim_Revolution(Axes,PMIN,PMAX),
66        myRadius(Radius)
67 {
68   SetMeridian();
69 }
70
71 //=======================================================================
72 //function : MakeEmptyLateralFace
73 //purpose  : 
74 //=======================================================================
75
76 TopoDS_Face  BRepPrim_Sphere::MakeEmptyLateralFace()const
77 {
78   Handle(Geom_SphericalSurface) S =
79     new Geom_SphericalSurface(Axes(),myRadius);
80   TopoDS_Face F;
81   myBuilder.Builder().MakeFace(F,S,Precision::Confusion());
82   return F;
83 }
84
85 //=======================================================================
86 //function : SetMeridian
87 //purpose  : 
88 //=======================================================================
89
90 void BRepPrim_Sphere::SetMeridian()
91 {
92   // Offset the parameters on the meridian
93   // to trim the edge in 3pi/2, 5pi/2
94
95   SetMeridianOffset(2*M_PI);
96
97   gp_Dir D = Axes().YDirection();
98   D.Reverse();
99   gp_Ax2 A(Axes().Location(),D,Axes().XDirection());
100   Handle(Geom_Circle) C = new Geom_Circle(A,myRadius);
101   Handle(Geom2d_Circle) C2d = 
102     new Geom2d_Circle(gp_Ax2d(gp_Pnt2d(0,0),gp_Dir2d(1,0)),
103                       myRadius);
104   Meridian(C,C2d);
105 }
106
107