0020716: Eliminate usage of "config.h" header file
[occt.git] / src / TestTopOpe / TestTopOpe_OtherCommands.cxx
CommitLineData
b311480e 1// Created on: 1997-01-21
2// Created by: Jean Yves LEBEY
3// Copyright (c) 1997-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
7fd59977 17#include <TestTopOpe.ixx>
18
19#include <DBRep.hxx>
20#include <Draw_Interpretor.hxx>
21#include <Draw_Appli.hxx>
22#include <Draw.hxx>
23#include <Draw_Marker3D.hxx>
24#include <Draw_Segment3D.hxx>
25#include <DrawTrSurf_Point.hxx>
26#include <DrawTrSurf.hxx>
27#include <BRep_Builder.hxx>
28#include <TopoDS.hxx>
29#include <TopoDS_Vertex.hxx>
30#include <TopoDS_Shell.hxx>
31#include <TopoDS_Shape.hxx>
32#include <TopoDS_Solid.hxx>
33#include <Bnd_Box.hxx>
34#include <gp.hxx>
35#include <gp_Pnt.hxx>
36#include <BRepBndLib.hxx>
37#include <BRep_Tool.hxx>
38#include <Precision.hxx>
39
03155c18 40#ifdef _WIN32
7fd59977 41Standard_IMPORT Draw_Viewer dout;
42#endif
7fd59977 43
44//=======================================================================
45// bounds S xmin ymin zmin zmax ymax zmax
46//=======================================================================
47Standard_Integer BOUNDS(Draw_Interpretor& di, Standard_Integer narg, const char** a)
48{
49 if (narg != 8) return 1;
50 TopoDS_Shape S = DBRep::Get(a[1]);
51 Standard_Real xmin,ymin,zmin,xmax,ymax,zmax;
52 Bnd_Box b; BRepBndLib::Add(S,b);
53 b.Enlarge(Precision::Confusion());
54 b.Get(xmin,ymin,zmin,xmax,ymax,zmax);
55 Draw::Set(a[2],xmin);
56 Draw::Set(a[3],ymin);
57 Draw::Set(a[4],zmin);
58 Draw::Set(a[5],xmax);
59 Draw::Set(a[6],ymax);
60 Draw::Set(a[7],zmax);
61 di<<"xmin:"<<xmin<<" ";
62 di<<"ymin:"<<ymin<<" ";
63 di<<"zmin:"<<zmin<<" ";
64 di<<"xmax:"<<xmax<<" ";
65 di<<"ymax:"<<ymax<<" ";
66 di<<"zmax:"<<zmax<<"\n";
67 return 0 ;
68}
69
70//---------------------------------------------------------------------
71static Standard_Boolean PersEyeDir(const Standard_Integer ViewId,
72 gp_Pnt& E,
73 gp_Dir& D)
74//---------------------------------------------------------------------
75{
76 gp_Trsf T;
77 gp_Pnt Eye;
78 gp_Dir Dirz(0,0,1);
79 dout.GetTrsf(ViewId,T);
80 T.Invert();
81 Dirz.Transform(T);
82 Standard_Boolean pers = Standard_False;
83 if (!strcmp("PERS",dout.GetType(ViewId))) {
84 pers = Standard_True;
85 Eye.SetXYZ(dout.Focal(ViewId)*Dirz.XYZ());
86 }
87 E = Eye;
88 D = Dirz;
89 return pers;
90}
91
92//=======================================================================
93// DOTVIEW dx dy dz id ddx ddy ddz (ddx,ddy,ddz) = (dx,dy,dz)^(<id> axis)
94//=======================================================================
95Standard_Integer DOTVIEW(Draw_Interpretor&, Standard_Integer narg, const char** a)
96{
97 if (narg < 8) return 1;
98
99 Standard_Real dx,dy,dz;
100 Draw::Get(a[1],dx); Draw::Get(a[2],dy); Draw::Get(a[3],dz);
101 gp_Dir d1(dx,dy,dz);
102 Standard_Real idr; Draw::Get(a[4],idr);
103 gp_Pnt p; gp_Dir d2; PersEyeDir((Standard_Integer)idr,p,d2);
104
105 gp_Dir d3(d1.Crossed(d2));
106 Draw::Set(a[5],d3.X());
107 Draw::Set(a[6],d3.Y());
108 Draw::Set(a[7],d3.Z());
109
110 return 0;
111}
112
113Standard_Integer VECTEUR(Draw_Interpretor& di, Standard_Integer , const char** ) {
114 di << "Pick positions with button "<<"\n";
115 Standard_Integer id,X,Y,b;
116 gp_Trsf T;
117 gp_Pnt P1,P2,PP1,PP2;
118
119 //-----------------------------------------------------------
120 dout.Select(id,X,Y,b); dout.GetTrsf(id,T);
121 T.Invert();
122 Standard_Real z = dout.Zoom(id);
123 P1.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
124 P1.Transform(T);
125
126 dout.Select(id,X,Y,b); dout.GetTrsf(id,T);
127 T.Invert(); z = dout.Zoom(id);
128
129 P2.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
130 P2.Transform(T);
131 Standard_Real xa,ya,za;
132 if(Abs(P1.X())>Abs(P2.X())) xa = P1.X(); else xa = P2.X();
133 if(Abs(P1.Y())>Abs(P2.Y())) ya = P1.Y(); else ya = P2.Y();
134 if(Abs(P1.Z())>Abs(P2.Z())) za = P1.Z(); else za = P2.Z();
135 P1.SetCoord(xa,ya,za);
136 Handle(Draw_Marker3D) D0 = new Draw_Marker3D
137 (gp_Pnt(P1.X(),P1.Y(),P1.Z()),Draw_Square,Draw_blanc,1);
138 dout << D0;
139 dout.Flush();
140 //-----------------------------------------------------------
141 dout.Select(id,X,Y,b);
142 dout.GetTrsf(id,T);
143 T.Invert();
144 z = dout.Zoom(id);
145 PP1.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
146 PP1.Transform(T);
147 dout.Select(id,X,Y,b);
148 dout.GetTrsf(id,T);
149 T.Invert();
150 z = dout.Zoom(id);
151 PP2.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
152 PP2.Transform(T);
153 if(Abs(PP1.X())>Abs(PP2.X())) xa = PP1.X(); else xa = PP2.X();
154 if(Abs(PP1.Y())>Abs(PP2.Y())) ya = PP1.Y(); else ya = PP2.Y();
155 if(Abs(PP1.Z())>Abs(PP2.Z())) za = PP1.Z(); else za = PP2.Z();
156 PP1.SetCoord(xa,ya,za);
157 Handle(Draw_Segment3D) d = new Draw_Segment3D(P1, PP1, Draw_blanc);
158 dout << d;
159 dout.Flush();
160 di<<"\n";
161 di<<"cdinp P1 "<<P1.X()<<" "<<P1.Y()<<" "<<P1.Z()<<"\n";
162 di<<"cdinp P2 "<<PP1.X()<<" "<<PP1.Y()<<" "<<PP1.Z()<<"\n";
163 di<<"cdinp PM "<<(PP1.X()+P1.X())/2<<" "<<(PP1.Y()+P1.Y())/2<<" "<<(PP1.Z()+P1.Z())/2<<"\n";
164 di<<"\n";
165 di<<"ttranslate "<<PP1.X()-P1.X()<<" "<<PP1.Y()-P1.Y()<<" "<<PP1.Z()-P1.Z()<<"\n";
166
167 return 0;
168}
169
170Standard_Integer MKSOLSHE(Draw_Interpretor&, Standard_Integer narg, const char** a) {
171 // 0 = [mksol | mkshe], 1 = solide/shell a creer avec 1 = shell ou face
172 // 0 = [mksol | mkshe], 1 = solide/shell a creer avec 2...narg-1 subsshapes
173 if (narg < 2) return 1;
174
175 Standard_Integer i;
176 BRep_Builder BB;
177 TopoDS_Shape res;
178
179 Standard_Integer i1 = (narg == 2) ? 1 : 2;
180 Standard_Integer i2 = (narg > 2) ? narg : 2;
181
182 // take all the FACE args, place them in the shell <she>
183 TopoDS_Shell she; BB.MakeShell(she); she.Closed(Standard_False);
184 Standard_Boolean yaface = Standard_False;
185 for (i = i1; i < i2; i++) {
186 const TopoDS_Shape& S = DBRep::Get(a[i]);
187 if (S.IsNull()) continue;
188 if (S.ShapeType() == TopAbs_FACE) {
189 BB.Add(she,S);
190 yaface = Standard_True;
191 }
192 }
193
194 // take all the SHELL args, place them in the solid <sol>
195 TopoDS_Solid sol; BB.MakeSolid(sol);
7fd59977 196 for (i = i1; i < i2; i++) {
197 const TopoDS_Shape& S = DBRep::Get(a[i]);
198 if (S.IsNull()) continue;
199 if (S.ShapeType() == TopAbs_SHELL) {
200 BB.Add(sol,S);
7fd59977 201 }
202 }
203
204 if (!strcmp("mksol",a[0])) {
205 if (yaface) BB.Add(sol,she);
206 res = sol;
207 }
208 else if (!strcmp("mkshe",a[0])) {
209 res = she;
210 }
211 else {
212 return 1;
213 }
214
215 DBRep::Set(a[1],res);
216 return 0;
217}
218
219//=======================================================================
220// Grille xmin ymin zmin zmax ymax zmax nbx nby nbz
221//=======================================================================
222Standard_Integer GRILLE(Draw_Interpretor& di, Standard_Integer narg, const char** a)
223{
224 if (narg != 10) return 1;
96a95605 225 Standard_Real xmin,ymin,zmin,xmax,ymax,zmax,dx,dy;
7fd59977 226 Standard_Integer nbx,nby,nbz;
91322f44 227 xmin = Draw::Atof(a[1]);
228 ymin = Draw::Atof(a[2]);
229 zmin = Draw::Atof(a[3]);
230 xmax = Draw::Atof(a[4]);
231 ymax = Draw::Atof(a[5]);
232 zmax = Draw::Atof(a[6]);
233 nbx = Draw::Atoi(a[7]);
234 nby = Draw::Atoi(a[8]);
235 nbz = Draw::Atoi(a[9]);
7fd59977 236 if(xmax<xmin || ymax<ymin || zmax<zmin || nbx<0 || nby<0 || nbz<0)
237 return 1;
238 if(nbx) dx = (xmax-xmin)/nbx; else dx=0;
239 if(nby) dy = (ymax-ymin)/nby; else dy=0;
7fd59977 240 di<<"compound CE"<<"\n";
241 for(Standard_Real x=xmin; x<xmax; x+=dx) {
242 for(Standard_Real y=ymin; y<ymax; y+=dx) {
243 //-- cout<<x<<" "<<y<<" "<<zmin<<" "<<x<<" "<<y<<" "<<zmax<<"\n";
244 di<<"line l "<<x<<" "<<y<<" "<<zmin<<" 0 0 1;mkedge e l 0 ";
245 di<<zmax-zmin<<" ;orient e EXTERNAL; add e CE"<<"\n";
246 if(dy==0) y=ymax;
247 }
248 if(dx==0) x=xmax;
249 }
250 return 0 ;
251}
252
35e08fe8 253Standard_Integer GETP3D(Draw_Interpretor& di, Standard_Integer /*narg*/, const char** a)
7fd59977 254{
255 TopoDS_Shape V = DBRep::Get(a[1]);
256 if (V.IsNull()) {
257 di<<"null shape"<<"\n";
258 return 1;
259 }
260 gp_Pnt pV = BRep_Tool::Pnt(TopoDS::Vertex(V));
261 di<<pV.X()<<" "<<pV.Y()<<" "<<pV.Z()<<"\n";
262 return 0;
263}
264#ifdef DEB
265#include <Draw_Chronometer.hxx>
266Standard_IMPORT Standard_Boolean Draw_Chrono;
267Standard_Integer CHROBOOP(Draw_Interpretor& di, Standard_Integer n, const char** a)
268{
269 Standard_Real ns = 0.;
270 Standard_Integer nm = 0;
271 Standard_Integer nh = 0;
272 Standard_Real ct = 0.;
273
274 if ((n == 1) || (*a[1] == '0') || (*a[1] == '1')) {
275 if (n == 1)
276 Draw_Chrono = !Draw_Chrono;
277 else
278 Draw_Chrono = (*a[1] == '1');
279
280 if (Draw_Chrono) di << "Chronometers activated."<<"\n";
281 else di << "Chronometers desactivated."<<"\n";
282 }
283 else {
284 Handle(Draw_Drawable3D) D = Draw::Get(a[1]);
285 Handle(Draw_Chronometer) C;
286 if (!D.IsNull()) {
287 C = Handle(Draw_Chronometer)::DownCast(D);
288 }
289 if (C.IsNull()) {
290 C = new Draw_Chronometer();
291 Draw::Set(a[1],C,Standard_False);
292 }
293 if (n <= 2) {
294 C->Timer().Reset();
295 }
296 else if (n <= 3) {
297 if (!strcasecmp(a[2],"reset"))
298 C->Timer().Reset();
299 else if (!strcasecmp(a[2],"start"))
300 C->Timer().Start();
301 else if (!strcasecmp(a[2],"stop"))
302 C->Timer().Stop();
303 else if (!strcasecmp(a[2],"show"))
304 C->Timer().Show();
305 else {
306 C->Timer().Show(ns,nm,nh,ct);
307 if (!strcasecmp(a[2],"-s")) {
308 di<<ns;
309 }
310 else if (!strcasecmp(a[2],"-m")) {
311 di<<nm;
312 }
313 else if (!strcasecmp(a[2],"-h")) {
314 di<<nh;
315 }
316 else if (!strcasecmp(a[2],"-c")) {
317 di<<ct;
318 }
319 }
320 }
321 }
322 return 0;
323}
324#endif
325
326//=======================================================================
327//function : OtherCommands
328//purpose :
329//=======================================================================
330void TestTopOpe::OtherCommands(Draw_Interpretor& theCommands)
331{
332 const char* g = "TestTopOpe OtherCommands";
333 theCommands.Add("grille","grille x0 y0 z0 x1 y1 z1 nbx nby nbz",__FILE__,GRILLE,g);
334 theCommands.Add("vecteur","4 Pick",__FILE__,VECTEUR,g);
335 theCommands.Add("bounds","bounds S x1 y1 z1 z2 y2 z2 = (box of S)",__FILE__,BOUNDS,g);
336 theCommands.Add("dotview","dotview dx dy dz id _dx1 _dx2 _dx3",__FILE__,DOTVIEW,g);
337 theCommands.Add("mksol","make a solid [1] with [2] ...",__FILE__,MKSOLSHE,g);
338 theCommands.Add("mkshe","make a shell [1] with [2] ...",__FILE__,MKSOLSHE,g);
339 theCommands.Add("getp3d","getp3d vertex",__FILE__,GETP3D,g);
340#ifdef DEB
341 theCommands.Add("chroboop","",__FILE__,CHROBOOP,g);
342#endif
343}