1 // Created on: 1993-07-22
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1993-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.
17 #include <BRepTest.hxx>
19 #include <Draw_Interpretor.hxx>
20 #include <Draw_Appli.hxx>
21 #include <DrawTrSurf.hxx>
22 #include <TopoDS_Solid.hxx>
23 #include <BRep_Builder.hxx>
24 #include <BRepBuilderAPI.hxx>
25 #include <BRepPrimAPI_MakeBox.hxx>
26 #include <BRepPrimAPI_MakeWedge.hxx>
27 #include <BRepPrimAPI_MakeCylinder.hxx>
28 #include <BRepPrimAPI_MakeCone.hxx>
29 #include <BRepPrimAPI_MakeSphere.hxx>
30 #include <BRepPrimAPI_MakeTorus.hxx>
31 #include <BRepPrimAPI_MakeSphere.hxx>
32 #include <Geom_Plane.hxx>
36 //=======================================================================
38 //=======================================================================
40 static Standard_Integer box(Draw_Interpretor& , Standard_Integer n, const char** a)
43 Standard_Real dx = Draw::Atof(a[n-3]);
44 Standard_Real dy = Draw::Atof(a[n-2]);
45 Standard_Real dz = Draw::Atof(a[n-1]);
51 Standard_Real x = Draw::Atof(a[2]);
52 Standard_Real y = Draw::Atof(a[3]);
53 Standard_Real z = Draw::Atof(a[4]);
54 S = BRepPrimAPI_MakeBox(gp_Pnt(x,y,z),dx,dy,dz);
57 S = BRepPrimAPI_MakeBox(dx,dy,dz);
64 //=======================================================================
66 //=======================================================================
68 static Standard_Integer wedge(Draw_Interpretor& , Standard_Integer n, const char** a)
72 // Standard_Integer i = 0;
73 if ( n == 15 || n == 18) {
74 gp_Pnt LocalP(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4]));
75 gp_Dir LocalN(Draw::Atof(a[5]),Draw::Atof(a[6]),Draw::Atof(a[7]));
76 gp_Dir LocalVx(Draw::Atof(a[8]),Draw::Atof(a[9]),Draw::Atof(a[10]));
77 gp_Ax2 Axis(LocalP,LocalN,LocalVx);
78 // gp_Ax2 Axis(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])),
79 // gp_Dir(Draw::Atof(a[5]),Draw::Atof(a[6]),Draw::Atof(a[7])),
80 // gp_Dir(Draw::Atof(a[8]),Draw::Atof(a[9]),Draw::Atof(a[10])));
82 S = BRepPrimAPI_MakeWedge(Axis,
83 Draw::Atof(a[11]),Draw::Atof(a[12]),Draw::Atof(a[13]),Draw::Atof(a[14]));
86 S = BRepPrimAPI_MakeWedge(Axis,
87 Draw::Atof(a[11]),Draw::Atof(a[12]),Draw::Atof(a[13]),
88 Draw::Atof(a[14]),Draw::Atof(a[15]),Draw::Atof(a[16]),Draw::Atof(a[17]));
92 S = BRepPrimAPI_MakeWedge(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]));
95 S = BRepPrimAPI_MakeWedge(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4]),
96 Draw::Atof(a[5]),Draw::Atof(a[6]),Draw::Atof(a[7]),Draw::Atof(a[8]));
105 //=======================================================================
107 //=======================================================================
109 static Standard_Integer cylinder(Draw_Interpretor& , Standard_Integer n, const char** a)
113 Handle(Geom_Plane) P =
114 Handle(Geom_Plane)::DownCast(DrawTrSurf::Get(a[2]));
117 S = BRepPrimAPI_MakeCylinder(Draw::Atof(a[2]),Draw::Atof(a[3]));
121 S = BRepPrimAPI_MakeCylinder(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4]) * (M_PI / 180.0));
123 S = BRepPrimAPI_MakeCylinder(P->Pln().Position().Ax2(),Draw::Atof(a[3]),Draw::Atof(a[4]));
129 S = BRepPrimAPI_MakeCylinder(P->Pln().Position().Ax2(),Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]) * (M_PI / 180.0));
138 //=======================================================================
140 //=======================================================================
142 static Standard_Integer cone(Draw_Interpretor& , Standard_Integer n, const char** a)
147 Handle(Geom_Plane) P =
148 Handle(Geom_Plane)::DownCast(DrawTrSurf::Get(a[2]));
151 S = BRepPrimAPI_MakeCone(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4]));
155 S = BRepPrimAPI_MakeCone(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]) * (M_PI / 180.0));
157 S = BRepPrimAPI_MakeCone(P->Pln().Position().Ax2(),Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]));
160 S = BRepPrimAPI_MakeCone(P->Pln().Position().Ax2(),Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]),Draw::Atof(a[6]) * (M_PI / 180.0));
169 //=======================================================================
171 //=======================================================================
173 static Standard_Integer sphere(Draw_Interpretor& , Standard_Integer n, const char** a)
178 Handle(Geom_Plane) P =
179 Handle(Geom_Plane)::DownCast(DrawTrSurf::Get(a[2]));
182 S = BRepPrimAPI_MakeSphere(Draw::Atof(a[2]));
186 S = BRepPrimAPI_MakeSphere(Draw::Atof(a[2]),Draw::Atof(a[3]) * (M_PI / 180.0));
188 S = BRepPrimAPI_MakeSphere(P->Pln().Position().Ax2(),Draw::Atof(a[3]));
192 S = BRepPrimAPI_MakeSphere(Draw::Atof(a[2]),Draw::Atof(a[3]) * (M_PI / 180.0),Draw::Atof(a[4]) * (M_PI / 180.0));
194 S = BRepPrimAPI_MakeSphere(P->Pln().Position().Ax2(),Draw::Atof(a[3]),Draw::Atof(a[4]) * (M_PI / 180.0));
198 S = BRepPrimAPI_MakeSphere(Draw::Atof(a[2]),Draw::Atof(a[3]) * (M_PI / 180.0),Draw::Atof(a[4]) * (M_PI / 180.0),Draw::Atof(a[5]) * (M_PI / 180.0));
200 S = BRepPrimAPI_MakeSphere(P->Pln().Position().Ax2(),Draw::Atof(a[3]),Draw::Atof(a[4]) * (M_PI / 180.0),Draw::Atof(a[5]) * (M_PI / 180.0));
203 S = BRepPrimAPI_MakeSphere(P->Pln().Position().Ax2(),Draw::Atof(a[3]),Draw::Atof(a[4]) * (M_PI / 180.0),Draw::Atof(a[5]) * (M_PI / 180.0),Draw::Atof(a[6]) * (M_PI / 180.0));
212 //=======================================================================
214 //=======================================================================
216 static Standard_Integer torus(Draw_Interpretor& , Standard_Integer n, const char** a)
221 Handle(Geom_Plane) P =
222 Handle(Geom_Plane)::DownCast(DrawTrSurf::Get(a[2]));
225 S = BRepPrimAPI_MakeTorus(Draw::Atof(a[2]),Draw::Atof(a[3]));
229 S = BRepPrimAPI_MakeTorus(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4]) * (M_PI / 180.0));
231 S = BRepPrimAPI_MakeTorus(P->Pln().Position().Ax2(),Draw::Atof(a[3]),Draw::Atof(a[4]));
235 S = BRepPrimAPI_MakeTorus(Draw::Atof(a[2]),Draw::Atof(a[3]),
236 Draw::Atof(a[4]) * (M_PI / 180.0),Draw::Atof(a[5]) * (M_PI / 180.0));
238 S = BRepPrimAPI_MakeTorus(P->Pln().Position().Ax2(),
239 Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]) * (M_PI / 180.0));
243 S = BRepPrimAPI_MakeTorus(Draw::Atof(a[2]),Draw::Atof(a[3]),
244 Draw::Atof(a[4]) * (M_PI / 180.0),Draw::Atof(a[5]) * (M_PI / 180.0),Draw::Atof(a[6]) * (M_PI / 180.0));
246 S = BRepPrimAPI_MakeTorus(P->Pln().Position().Ax2(),Draw::Atof(a[3]),
247 Draw::Atof(a[4]),Draw::Atof(a[5]) * (M_PI / 180.0),Draw::Atof(a[6]) * (M_PI / 180.0));
250 S = BRepPrimAPI_MakeTorus(P->Pln().Position().Ax2(),Draw::Atof(a[3]),Draw::Atof(a[4]),
251 Draw::Atof(a[5]) * (M_PI / 180.0),Draw::Atof(a[6]) * (M_PI / 180.0),Draw::Atof(a[7]) * (M_PI / 180.0));
262 //=======================================================================
263 //function : PrimitiveCommands
265 //=======================================================================
267 void BRepTest::PrimitiveCommands(Draw_Interpretor& theCommands)
269 static Standard_Boolean done = Standard_False;
271 done = Standard_True;
273 DBRep::BasicCommands(theCommands);
275 const char* g = "Primitive building commands";
277 theCommands.Add("box","box name [x1 y1 z1] dx dy dz",__FILE__,box,g);
278 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);
280 theCommands.Add("pcylinder","pcylinder name [plane(ax2)] R H [angle]",__FILE__,cylinder,g);
281 theCommands.Add("pcone", "pcone name [plane(ax2)] R1 R2 H [angle]",__FILE__,cone,g);
282 theCommands.Add("psphere", "psphere name [plane(ax2)] R [angle1 angle2] [angle]",__FILE__,sphere,g);
283 theCommands.Add("ptorus", "ptorus name [plane(ax2)] R1 R2 [angle1 angle2] [angle]",__FILE__,torus,g);