0022792: Globally defined symbol PI conflicts with VTK definition (Intel compiler)
[occt.git] / src / BRepTest / BRepTest_PrimitiveCommands.cxx
1 // File:        DBRep_1.cxx
2 // Created:     Thu Jul 22 11:46:12 1993
3 // Author:      Remi LEQUETTE
4 //              <rle@nonox>
5
6
7 #include <BRepTest.hxx>
8 #include <DBRep.hxx>
9 #include <Draw_Interpretor.hxx>
10 #include <Draw_Appli.hxx>
11 #include <DrawTrSurf.hxx>
12 #include <TopoDS_Solid.hxx>
13 #include <BRep_Builder.hxx>
14 #include <BRepBuilderAPI.hxx>
15 #include <BRepPrimAPI_MakeBox.hxx>
16 #include <BRepPrimAPI_MakeWedge.hxx>
17 #include <BRepPrimAPI_MakeCylinder.hxx>
18 #include <BRepPrimAPI_MakeCone.hxx>
19 #include <BRepPrimAPI_MakeSphere.hxx>
20 #include <BRepPrimAPI_MakeTorus.hxx>
21 #include <BRepPrimAPI_MakeSphere.hxx>
22 #include <Geom_Plane.hxx>
23 #include <gp_Pln.hxx>
24
25
26 //=======================================================================
27 // box
28 //=======================================================================
29
30 static Standard_Integer box(Draw_Interpretor& , Standard_Integer n, const char** a)
31 {
32   if (n < 5) return 1;
33   Standard_Real dx = atof(a[n-3]);
34   Standard_Real dy = atof(a[n-2]);
35   Standard_Real dz = atof(a[n-1]);
36
37   TopoDS_Solid S;
38
39   if (n > 5) {
40     if (n < 8) return 1;
41     Standard_Real x = atof(a[2]);
42     Standard_Real y = atof(a[3]);
43     Standard_Real z = atof(a[4]);
44     S = BRepPrimAPI_MakeBox(gp_Pnt(x,y,z),dx,dy,dz);
45   }
46   else {
47     S = BRepPrimAPI_MakeBox(dx,dy,dz);
48   }
49
50   DBRep::Set(a[1],S);
51   return 0;
52 }
53
54 //=======================================================================
55 // wedge
56 //=======================================================================
57
58 static Standard_Integer wedge(Draw_Interpretor& , Standard_Integer n, const char** a)
59 {
60   TopoDS_Solid S;
61
62 //  Standard_Integer i = 0;
63   if ( n == 15 || n == 18) {
64     gp_Pnt LocalP(atof(a[2]),atof(a[3]),atof(a[4]));
65     gp_Dir LocalN(atof(a[5]),atof(a[6]),atof(a[7]));
66     gp_Dir LocalVx(atof(a[8]),atof(a[9]),atof(a[10]));
67     gp_Ax2 Axis(LocalP,LocalN,LocalVx);
68 //    gp_Ax2 Axis(gp_Pnt(atof(a[2]),atof(a[3]),atof(a[4])),
69 //              gp_Dir(atof(a[5]),atof(a[6]),atof(a[7])),
70 //              gp_Dir(atof(a[8]),atof(a[9]),atof(a[10])));
71     if ( n == 15) {
72       S = BRepPrimAPI_MakeWedge(Axis,
73                             atof(a[11]),atof(a[12]),atof(a[13]),atof(a[14]));
74     }
75     else {
76       S = BRepPrimAPI_MakeWedge(Axis,
77                             atof(a[11]),atof(a[12]),atof(a[13]),
78                             atof(a[14]),atof(a[15]),atof(a[16]),atof(a[17]));
79     }
80   }
81   else if (n == 6) {
82     S = BRepPrimAPI_MakeWedge(atof(a[2]),atof(a[3]),atof(a[4]),atof(a[5]));
83   }
84   else if (n == 9){
85     S = BRepPrimAPI_MakeWedge(atof(a[2]),atof(a[3]),atof(a[4]),
86                           atof(a[5]),atof(a[6]),atof(a[7]),atof(a[8]));
87   }
88   else
89     return 1;
90
91   DBRep::Set(a[1],S);
92   return 0;
93 }
94
95 //=======================================================================
96 // cylinder
97 //=======================================================================
98
99 static Standard_Integer cylinder(Draw_Interpretor& , Standard_Integer n, const char** a)
100 {
101   if (n < 3) return 1;
102   TopoDS_Solid S;
103   Handle(Geom_Plane) P =
104     Handle(Geom_Plane)::DownCast(DrawTrSurf::Get(a[2]));
105
106   if (n == 4) {
107       S = BRepPrimAPI_MakeCylinder(atof(a[2]),atof(a[3]));
108   }
109   else if (n == 5) {
110     if (P.IsNull())
111       S = BRepPrimAPI_MakeCylinder(atof(a[2]),atof(a[3]),atof(a[4]) * (M_PI / 180.0));
112     else
113       S = BRepPrimAPI_MakeCylinder(P->Pln().Position().Ax2(),atof(a[3]),atof(a[4]));
114   }
115   else if (n == 6) {
116     if (P.IsNull())
117       return 1;
118     else
119       S = BRepPrimAPI_MakeCylinder(P->Pln().Position().Ax2(),atof(a[3]),atof(a[4]),atof(a[5]) * (M_PI / 180.0));
120   }
121   else
122     return 1;
123
124   DBRep::Set(a[1],S);
125   return 0;
126 }
127
128 //=======================================================================
129 // cone
130 //=======================================================================
131
132 static Standard_Integer cone(Draw_Interpretor& , Standard_Integer n, const char** a)
133 {
134   if (n < 3) return 1;
135   TopoDS_Solid S;
136
137   Handle(Geom_Plane) P =
138     Handle(Geom_Plane)::DownCast(DrawTrSurf::Get(a[2]));
139
140   if (n == 5) {
141     S = BRepPrimAPI_MakeCone(atof(a[2]),atof(a[3]),atof(a[4]));
142   }
143   else if (n == 6) {
144     if (P.IsNull())
145       S = BRepPrimAPI_MakeCone(atof(a[2]),atof(a[3]),atof(a[4]),atof(a[5]) * (M_PI / 180.0));
146     else
147       S = BRepPrimAPI_MakeCone(P->Pln().Position().Ax2(),atof(a[3]),atof(a[4]),atof(a[5]));
148   }
149   else if (n == 7) {
150     S = BRepPrimAPI_MakeCone(P->Pln().Position().Ax2(),atof(a[3]),atof(a[4]),atof(a[5]),atof(a[6]) * (M_PI / 180.0));
151   }
152   else
153     return 1;
154
155   DBRep::Set(a[1],S);
156   return 0;
157 }
158
159 //=======================================================================
160 // sphere
161 //=======================================================================
162
163 static Standard_Integer sphere(Draw_Interpretor& , Standard_Integer n, const char** a)
164 {
165   if (n < 3) return 1;
166   TopoDS_Solid S;
167
168   Handle(Geom_Plane) P =
169     Handle(Geom_Plane)::DownCast(DrawTrSurf::Get(a[2]));
170
171   if (n == 3) {
172     S = BRepPrimAPI_MakeSphere(atof(a[2]));
173   }
174   else if (n == 4) {
175     if (P.IsNull())
176       S = BRepPrimAPI_MakeSphere(atof(a[2]),atof(a[3]) * (M_PI / 180.0));
177     else
178       S = BRepPrimAPI_MakeSphere(P->Pln().Position().Ax2(),atof(a[3]));
179   }
180   else if (n == 5) {
181     if (P.IsNull())
182       S = BRepPrimAPI_MakeSphere(atof(a[2]),atof(a[3]) * (M_PI / 180.0),atof(a[4]) * (M_PI / 180.0));
183     else
184       S = BRepPrimAPI_MakeSphere(P->Pln().Position().Ax2(),atof(a[3]),atof(a[4]) * (M_PI / 180.0));
185   }
186   else if (n == 6) {
187     if (P.IsNull())
188       S = BRepPrimAPI_MakeSphere(atof(a[2]),atof(a[3]) * (M_PI / 180.0),atof(a[4]) * (M_PI / 180.0),atof(a[5]) * (M_PI / 180.0));
189     else
190       S = BRepPrimAPI_MakeSphere(P->Pln().Position().Ax2(),atof(a[3]),atof(a[4]) * (M_PI / 180.0),atof(a[5]) * (M_PI / 180.0));
191   }
192   else if (n == 7) {
193     S = BRepPrimAPI_MakeSphere(P->Pln().Position().Ax2(),atof(a[3]),atof(a[4]) * (M_PI / 180.0),atof(a[5]) * (M_PI / 180.0),atof(a[6]) * (M_PI / 180.0));
194   }
195   else
196     return 1;
197
198   DBRep::Set(a[1],S);
199   return 0;
200 }
201
202 //=======================================================================
203 // torus
204 //=======================================================================
205
206 static Standard_Integer torus(Draw_Interpretor& , Standard_Integer n, const char** a)
207 {
208   if (n < 3) return 1;
209   TopoDS_Solid S;
210
211   Handle(Geom_Plane) P =
212     Handle(Geom_Plane)::DownCast(DrawTrSurf::Get(a[2]));
213
214   if (n == 4) {
215     S = BRepPrimAPI_MakeTorus(atof(a[2]),atof(a[3]));
216   }
217   else if (n == 5) {
218     if (P.IsNull())
219       S = BRepPrimAPI_MakeTorus(atof(a[2]),atof(a[3]),atof(a[4]) * (M_PI / 180.0));
220     else
221       S = BRepPrimAPI_MakeTorus(P->Pln().Position().Ax2(),atof(a[3]),atof(a[4]));
222   }
223   else if (n == 6) {
224     if (P.IsNull())
225       S = BRepPrimAPI_MakeTorus(atof(a[2]),atof(a[3]),
226                             atof(a[4]) * (M_PI / 180.0),atof(a[5]) * (M_PI / 180.0));
227     else
228       S = BRepPrimAPI_MakeTorus(P->Pln().Position().Ax2(),
229                             atof(a[3]),atof(a[4]),atof(a[5]) * (M_PI / 180.0));
230   }
231   else if (n == 7) {
232     if (P.IsNull())
233       S = BRepPrimAPI_MakeTorus(atof(a[2]),atof(a[3]),
234                             atof(a[4]) * (M_PI / 180.0),atof(a[5]) * (M_PI / 180.0),atof(a[6]) * (M_PI / 180.0));
235     else
236       S = BRepPrimAPI_MakeTorus(P->Pln().Position().Ax2(),atof(a[3]),
237                             atof(a[4]),atof(a[5]) * (M_PI / 180.0),atof(a[6]) * (M_PI / 180.0));
238   }
239   else if (n == 8) {
240     S = BRepPrimAPI_MakeTorus(P->Pln().Position().Ax2(),atof(a[3]),atof(a[4]),
241                           atof(a[5]) * (M_PI / 180.0),atof(a[6]) * (M_PI / 180.0),atof(a[7]) * (M_PI / 180.0));
242   }
243   else
244     return 1;
245
246   DBRep::Set(a[1],S);
247   return 0;
248 }
249
250
251
252 //=======================================================================
253 //function : PrimitiveCommands
254 //purpose  : 
255 //=======================================================================
256
257 void  BRepTest::PrimitiveCommands(Draw_Interpretor& theCommands)
258 {
259   static Standard_Boolean done = Standard_False;
260   if (done) return;
261   done = Standard_True;
262
263   DBRep::BasicCommands(theCommands);
264
265   const char* g = "Primitive building commands";
266     
267   theCommands.Add("box","box name [x1 y1 z1] dx dy dz",__FILE__,box,g);
268   theCommands.Add("wedge","wedge name [Ox Oy Oz Zx Zy Zz Xx Xy Xz] dx dy dz ltx / xmin zmin xmax zmax",__FILE__,wedge,g);
269   
270   theCommands.Add("pcylinder","pcylinder name [plane(ax2)] R H [angle]",__FILE__,cylinder,g);
271   theCommands.Add("pcone",    "pcone name [plane(ax2)] R1 R2 H [angle]",__FILE__,cone,g);
272   theCommands.Add("psphere",  "psphere name [plane(ax2)] R [angle1 angle2] [angle]",__FILE__,sphere,g);
273   theCommands.Add("ptorus",   "ptorus name [plane(ax2)] R1 R2 [angle1 angle2] [angle]",__FILE__,torus,g);
274 }
275
276