0030416: Incorrect implementation of the method Bnd_OBB::SquareExtent
[occt.git] / src / BRepTest / BRepTest_PrimitiveCommands.cxx
CommitLineData
b311480e 1// Created on: 1993-07-22
2// Created by: Remi LEQUETTE
3// Copyright (c) 1993-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <BRepTest.hxx>
18#include <DBRep.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>
33#include <gp_Pln.hxx>
34
35
36//=======================================================================
37// box
38//=======================================================================
39
40static Standard_Integer box(Draw_Interpretor& , Standard_Integer n, const char** a)
41{
42 if (n < 5) return 1;
91322f44 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]);
7fd59977 46
47 TopoDS_Solid S;
48
49 if (n > 5) {
50 if (n < 8) return 1;
91322f44 51 Standard_Real x = Draw::Atof(a[2]);
52 Standard_Real y = Draw::Atof(a[3]);
53 Standard_Real z = Draw::Atof(a[4]);
7fd59977 54 S = BRepPrimAPI_MakeBox(gp_Pnt(x,y,z),dx,dy,dz);
55 }
56 else {
57 S = BRepPrimAPI_MakeBox(dx,dy,dz);
58 }
59
60 DBRep::Set(a[1],S);
61 return 0;
62}
63
64//=======================================================================
65// wedge
66//=======================================================================
67
68static Standard_Integer wedge(Draw_Interpretor& , Standard_Integer n, const char** a)
69{
70 TopoDS_Solid S;
71
72// Standard_Integer i = 0;
73 if ( n == 15 || n == 18) {
91322f44 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]));
7fd59977 77 gp_Ax2 Axis(LocalP,LocalN,LocalVx);
91322f44 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])));
7fd59977 81 if ( n == 15) {
82 S = BRepPrimAPI_MakeWedge(Axis,
91322f44 83 Draw::Atof(a[11]),Draw::Atof(a[12]),Draw::Atof(a[13]),Draw::Atof(a[14]));
7fd59977 84 }
85 else {
86 S = BRepPrimAPI_MakeWedge(Axis,
91322f44 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]));
7fd59977 89 }
90 }
91 else if (n == 6) {
91322f44 92 S = BRepPrimAPI_MakeWedge(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]));
7fd59977 93 }
94 else if (n == 9){
91322f44 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]));
7fd59977 97 }
98 else
99 return 1;
100
101 DBRep::Set(a[1],S);
102 return 0;
103}
104
105//=======================================================================
106// cylinder
107//=======================================================================
108
109static Standard_Integer cylinder(Draw_Interpretor& , Standard_Integer n, const char** a)
110{
111 if (n < 3) return 1;
112 TopoDS_Solid S;
113 Handle(Geom_Plane) P =
114 Handle(Geom_Plane)::DownCast(DrawTrSurf::Get(a[2]));
115
116 if (n == 4) {
91322f44 117 S = BRepPrimAPI_MakeCylinder(Draw::Atof(a[2]),Draw::Atof(a[3]));
7fd59977 118 }
119 else if (n == 5) {
120 if (P.IsNull())
91322f44 121 S = BRepPrimAPI_MakeCylinder(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4]) * (M_PI / 180.0));
7fd59977 122 else
91322f44 123 S = BRepPrimAPI_MakeCylinder(P->Pln().Position().Ax2(),Draw::Atof(a[3]),Draw::Atof(a[4]));
7fd59977 124 }
125 else if (n == 6) {
126 if (P.IsNull())
127 return 1;
128 else
91322f44 129 S = BRepPrimAPI_MakeCylinder(P->Pln().Position().Ax2(),Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]) * (M_PI / 180.0));
7fd59977 130 }
131 else
132 return 1;
133
134 DBRep::Set(a[1],S);
135 return 0;
136}
137
138//=======================================================================
139// cone
140//=======================================================================
141
142static Standard_Integer cone(Draw_Interpretor& , Standard_Integer n, const char** a)
143{
144 if (n < 3) return 1;
145 TopoDS_Solid S;
146
147 Handle(Geom_Plane) P =
148 Handle(Geom_Plane)::DownCast(DrawTrSurf::Get(a[2]));
149
150 if (n == 5) {
91322f44 151 S = BRepPrimAPI_MakeCone(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4]));
7fd59977 152 }
153 else if (n == 6) {
154 if (P.IsNull())
91322f44 155 S = BRepPrimAPI_MakeCone(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]) * (M_PI / 180.0));
7fd59977 156 else
91322f44 157 S = BRepPrimAPI_MakeCone(P->Pln().Position().Ax2(),Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]));
7fd59977 158 }
159 else if (n == 7) {
91322f44 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));
7fd59977 161 }
162 else
163 return 1;
164
165 DBRep::Set(a[1],S);
166 return 0;
167}
168
169//=======================================================================
170// sphere
171//=======================================================================
172
173static Standard_Integer sphere(Draw_Interpretor& , Standard_Integer n, const char** a)
174{
175 if (n < 3) return 1;
176 TopoDS_Solid S;
177
178 Handle(Geom_Plane) P =
179 Handle(Geom_Plane)::DownCast(DrawTrSurf::Get(a[2]));
180
181 if (n == 3) {
91322f44 182 S = BRepPrimAPI_MakeSphere(Draw::Atof(a[2]));
7fd59977 183 }
184 else if (n == 4) {
185 if (P.IsNull())
91322f44 186 S = BRepPrimAPI_MakeSphere(Draw::Atof(a[2]),Draw::Atof(a[3]) * (M_PI / 180.0));
7fd59977 187 else
91322f44 188 S = BRepPrimAPI_MakeSphere(P->Pln().Position().Ax2(),Draw::Atof(a[3]));
7fd59977 189 }
190 else if (n == 5) {
191 if (P.IsNull())
91322f44 192 S = BRepPrimAPI_MakeSphere(Draw::Atof(a[2]),Draw::Atof(a[3]) * (M_PI / 180.0),Draw::Atof(a[4]) * (M_PI / 180.0));
7fd59977 193 else
91322f44 194 S = BRepPrimAPI_MakeSphere(P->Pln().Position().Ax2(),Draw::Atof(a[3]),Draw::Atof(a[4]) * (M_PI / 180.0));
7fd59977 195 }
196 else if (n == 6) {
197 if (P.IsNull())
91322f44 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));
7fd59977 199 else
91322f44 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));
7fd59977 201 }
202 else if (n == 7) {
91322f44 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));
7fd59977 204 }
205 else
206 return 1;
207
208 DBRep::Set(a[1],S);
209 return 0;
210}
211
212//=======================================================================
213// torus
214//=======================================================================
215
216static Standard_Integer torus(Draw_Interpretor& , Standard_Integer n, const char** a)
217{
218 if (n < 3) return 1;
219 TopoDS_Solid S;
220
221 Handle(Geom_Plane) P =
222 Handle(Geom_Plane)::DownCast(DrawTrSurf::Get(a[2]));
223
224 if (n == 4) {
91322f44 225 S = BRepPrimAPI_MakeTorus(Draw::Atof(a[2]),Draw::Atof(a[3]));
7fd59977 226 }
227 else if (n == 5) {
228 if (P.IsNull())
91322f44 229 S = BRepPrimAPI_MakeTorus(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4]) * (M_PI / 180.0));
7fd59977 230 else
91322f44 231 S = BRepPrimAPI_MakeTorus(P->Pln().Position().Ax2(),Draw::Atof(a[3]),Draw::Atof(a[4]));
7fd59977 232 }
233 else if (n == 6) {
234 if (P.IsNull())
91322f44 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));
7fd59977 237 else
238 S = BRepPrimAPI_MakeTorus(P->Pln().Position().Ax2(),
91322f44 239 Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]) * (M_PI / 180.0));
7fd59977 240 }
241 else if (n == 7) {
242 if (P.IsNull())
91322f44 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));
7fd59977 245 else
91322f44 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));
7fd59977 248 }
249 else if (n == 8) {
91322f44 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));
7fd59977 252 }
253 else
254 return 1;
255
256 DBRep::Set(a[1],S);
257 return 0;
258}
259
260
261
262//=======================================================================
263//function : PrimitiveCommands
264//purpose :
265//=======================================================================
266
267void BRepTest::PrimitiveCommands(Draw_Interpretor& theCommands)
268{
269 static Standard_Boolean done = Standard_False;
270 if (done) return;
271 done = Standard_True;
272
273 DBRep::BasicCommands(theCommands);
274
275 const char* g = "Primitive building commands";
276
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);
279
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);
284}
285
286