1 // Created on: 1997-01-21
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1997-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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
20 #include <TestTopOpe.ixx>
23 #include <Draw_Interpretor.hxx>
24 #include <Draw_Appli.hxx>
26 #include <Draw_Marker3D.hxx>
27 #include <Draw_Segment3D.hxx>
28 #include <DrawTrSurf_Point.hxx>
29 #include <DrawTrSurf.hxx>
30 #include <BRep_Builder.hxx>
32 #include <TopoDS_Vertex.hxx>
33 #include <TopoDS_Shell.hxx>
34 #include <TopoDS_Shape.hxx>
35 #include <TopoDS_Solid.hxx>
36 #include <Bnd_Box.hxx>
39 #include <BRepBndLib.hxx>
40 #include <BRep_Tool.hxx>
41 #include <Precision.hxx>
44 Standard_IMPORT Draw_Viewer dout;
50 //=======================================================================
51 // bounds S xmin ymin zmin zmax ymax zmax
52 //=======================================================================
53 Standard_Integer BOUNDS(Draw_Interpretor& di, Standard_Integer narg, const char** a)
55 if (narg != 8) return 1;
56 TopoDS_Shape S = DBRep::Get(a[1]);
57 Standard_Real xmin,ymin,zmin,xmax,ymax,zmax;
58 Bnd_Box b; BRepBndLib::Add(S,b);
59 b.Enlarge(Precision::Confusion());
60 b.Get(xmin,ymin,zmin,xmax,ymax,zmax);
67 di<<"xmin:"<<xmin<<" ";
68 di<<"ymin:"<<ymin<<" ";
69 di<<"zmin:"<<zmin<<" ";
70 di<<"xmax:"<<xmax<<" ";
71 di<<"ymax:"<<ymax<<" ";
72 di<<"zmax:"<<zmax<<"\n";
76 //---------------------------------------------------------------------
77 static Standard_Boolean PersEyeDir(const Standard_Integer ViewId,
80 //---------------------------------------------------------------------
85 dout.GetTrsf(ViewId,T);
88 Standard_Boolean pers = Standard_False;
89 if (!strcmp("PERS",dout.GetType(ViewId))) {
91 Eye.SetXYZ(dout.Focal(ViewId)*Dirz.XYZ());
98 //=======================================================================
99 // DOTVIEW dx dy dz id ddx ddy ddz (ddx,ddy,ddz) = (dx,dy,dz)^(<id> axis)
100 //=======================================================================
101 Standard_Integer DOTVIEW(Draw_Interpretor&, Standard_Integer narg, const char** a)
103 if (narg < 8) return 1;
105 Standard_Real dx,dy,dz;
106 Draw::Get(a[1],dx); Draw::Get(a[2],dy); Draw::Get(a[3],dz);
108 Standard_Real idr; Draw::Get(a[4],idr);
109 gp_Pnt p; gp_Dir d2; PersEyeDir((Standard_Integer)idr,p,d2);
111 gp_Dir d3(d1.Crossed(d2));
112 Draw::Set(a[5],d3.X());
113 Draw::Set(a[6],d3.Y());
114 Draw::Set(a[7],d3.Z());
119 Standard_Integer VECTEUR(Draw_Interpretor& di, Standard_Integer , const char** ) {
120 di << "Pick positions with button "<<"\n";
121 Standard_Integer id,X,Y,b;
123 gp_Pnt P1,P2,PP1,PP2;
125 //-----------------------------------------------------------
126 dout.Select(id,X,Y,b); dout.GetTrsf(id,T);
128 Standard_Real z = dout.Zoom(id);
129 P1.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
132 dout.Select(id,X,Y,b); dout.GetTrsf(id,T);
133 T.Invert(); z = dout.Zoom(id);
135 P2.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
137 Standard_Real xa,ya,za;
138 if(Abs(P1.X())>Abs(P2.X())) xa = P1.X(); else xa = P2.X();
139 if(Abs(P1.Y())>Abs(P2.Y())) ya = P1.Y(); else ya = P2.Y();
140 if(Abs(P1.Z())>Abs(P2.Z())) za = P1.Z(); else za = P2.Z();
141 P1.SetCoord(xa,ya,za);
142 Handle(Draw_Marker3D) D0 = new Draw_Marker3D
143 (gp_Pnt(P1.X(),P1.Y(),P1.Z()),Draw_Square,Draw_blanc,1);
146 //-----------------------------------------------------------
147 dout.Select(id,X,Y,b);
151 PP1.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
153 dout.Select(id,X,Y,b);
157 PP2.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
159 if(Abs(PP1.X())>Abs(PP2.X())) xa = PP1.X(); else xa = PP2.X();
160 if(Abs(PP1.Y())>Abs(PP2.Y())) ya = PP1.Y(); else ya = PP2.Y();
161 if(Abs(PP1.Z())>Abs(PP2.Z())) za = PP1.Z(); else za = PP2.Z();
162 PP1.SetCoord(xa,ya,za);
163 Handle(Draw_Segment3D) d = new Draw_Segment3D(P1, PP1, Draw_blanc);
167 di<<"cdinp P1 "<<P1.X()<<" "<<P1.Y()<<" "<<P1.Z()<<"\n";
168 di<<"cdinp P2 "<<PP1.X()<<" "<<PP1.Y()<<" "<<PP1.Z()<<"\n";
169 di<<"cdinp PM "<<(PP1.X()+P1.X())/2<<" "<<(PP1.Y()+P1.Y())/2<<" "<<(PP1.Z()+P1.Z())/2<<"\n";
171 di<<"ttranslate "<<PP1.X()-P1.X()<<" "<<PP1.Y()-P1.Y()<<" "<<PP1.Z()-P1.Z()<<"\n";
176 Standard_Integer MKSOLSHE(Draw_Interpretor&, Standard_Integer narg, const char** a) {
177 // 0 = [mksol | mkshe], 1 = solide/shell a creer avec 1 = shell ou face
178 // 0 = [mksol | mkshe], 1 = solide/shell a creer avec 2...narg-1 subsshapes
179 if (narg < 2) return 1;
185 Standard_Integer i1 = (narg == 2) ? 1 : 2;
186 Standard_Integer i2 = (narg > 2) ? narg : 2;
188 // take all the FACE args, place them in the shell <she>
189 TopoDS_Shell she; BB.MakeShell(she); she.Closed(Standard_False);
190 Standard_Boolean yaface = Standard_False;
191 for (i = i1; i < i2; i++) {
192 const TopoDS_Shape& S = DBRep::Get(a[i]);
193 if (S.IsNull()) continue;
194 if (S.ShapeType() == TopAbs_FACE) {
196 yaface = Standard_True;
200 // take all the SHELL args, place them in the solid <sol>
201 TopoDS_Solid sol; BB.MakeSolid(sol);
202 Standard_Boolean yashell = Standard_False;
203 for (i = i1; i < i2; i++) {
204 const TopoDS_Shape& S = DBRep::Get(a[i]);
205 if (S.IsNull()) continue;
206 if (S.ShapeType() == TopAbs_SHELL) {
208 yashell = Standard_True;
212 if (!strcmp("mksol",a[0])) {
213 if (yaface) BB.Add(sol,she);
216 else if (!strcmp("mkshe",a[0])) {
223 DBRep::Set(a[1],res);
227 //=======================================================================
228 // Grille xmin ymin zmin zmax ymax zmax nbx nby nbz
229 //=======================================================================
230 Standard_Integer GRILLE(Draw_Interpretor& di, Standard_Integer narg, const char** a)
232 if (narg != 10) return 1;
233 Standard_Real xmin,ymin,zmin,xmax,ymax,zmax,dx,dy,dz;
234 Standard_Integer nbx,nby,nbz;
235 xmin = Draw::Atof(a[1]);
236 ymin = Draw::Atof(a[2]);
237 zmin = Draw::Atof(a[3]);
238 xmax = Draw::Atof(a[4]);
239 ymax = Draw::Atof(a[5]);
240 zmax = Draw::Atof(a[6]);
241 nbx = Draw::Atoi(a[7]);
242 nby = Draw::Atoi(a[8]);
243 nbz = Draw::Atoi(a[9]);
244 if(xmax<xmin || ymax<ymin || zmax<zmin || nbx<0 || nby<0 || nbz<0)
246 if(nbx) dx = (xmax-xmin)/nbx; else dx=0;
247 if(nby) dy = (ymax-ymin)/nby; else dy=0;
248 if(nbz) dz = (zmax-zmin)/nbz; else dz=0;
249 di<<"compound CE"<<"\n";
250 for(Standard_Real x=xmin; x<xmax; x+=dx) {
251 for(Standard_Real y=ymin; y<ymax; y+=dx) {
252 //-- cout<<x<<" "<<y<<" "<<zmin<<" "<<x<<" "<<y<<" "<<zmax<<"\n";
253 di<<"line l "<<x<<" "<<y<<" "<<zmin<<" 0 0 1;mkedge e l 0 ";
254 di<<zmax-zmin<<" ;orient e EXTERNAL; add e CE"<<"\n";
262 Standard_Integer GETP3D(Draw_Interpretor& di, Standard_Integer /*narg*/, const char** a)
264 TopoDS_Shape V = DBRep::Get(a[1]);
266 di<<"null shape"<<"\n";
269 gp_Pnt pV = BRep_Tool::Pnt(TopoDS::Vertex(V));
270 di<<pV.X()<<" "<<pV.Y()<<" "<<pV.Z()<<"\n";
274 #include <Draw_Chronometer.hxx>
275 Standard_IMPORT Standard_Boolean Draw_Chrono;
276 Standard_Integer CHROBOOP(Draw_Interpretor& di, Standard_Integer n, const char** a)
278 Standard_Real ns = 0.;
279 Standard_Integer nm = 0;
280 Standard_Integer nh = 0;
281 Standard_Real ct = 0.;
283 if ((n == 1) || (*a[1] == '0') || (*a[1] == '1')) {
285 Draw_Chrono = !Draw_Chrono;
287 Draw_Chrono = (*a[1] == '1');
289 if (Draw_Chrono) di << "Chronometers activated."<<"\n";
290 else di << "Chronometers desactivated."<<"\n";
293 Handle(Draw_Drawable3D) D = Draw::Get(a[1]);
294 Handle(Draw_Chronometer) C;
296 C = Handle(Draw_Chronometer)::DownCast(D);
299 C = new Draw_Chronometer();
300 Draw::Set(a[1],C,Standard_False);
306 if (!strcasecmp(a[2],"reset"))
308 else if (!strcasecmp(a[2],"start"))
310 else if (!strcasecmp(a[2],"stop"))
312 else if (!strcasecmp(a[2],"show"))
315 C->Timer().Show(ns,nm,nh,ct);
316 if (!strcasecmp(a[2],"-s")) {
319 else if (!strcasecmp(a[2],"-m")) {
322 else if (!strcasecmp(a[2],"-h")) {
325 else if (!strcasecmp(a[2],"-c")) {
335 //=======================================================================
336 //function : OtherCommands
338 //=======================================================================
339 void TestTopOpe::OtherCommands(Draw_Interpretor& theCommands)
341 const char* g = "TestTopOpe OtherCommands";
342 theCommands.Add("grille","grille x0 y0 z0 x1 y1 z1 nbx nby nbz",__FILE__,GRILLE,g);
343 theCommands.Add("vecteur","4 Pick",__FILE__,VECTEUR,g);
344 theCommands.Add("bounds","bounds S x1 y1 z1 z2 y2 z2 = (box of S)",__FILE__,BOUNDS,g);
345 theCommands.Add("dotview","dotview dx dy dz id _dx1 _dx2 _dx3",__FILE__,DOTVIEW,g);
346 theCommands.Add("mksol","make a solid [1] with [2] ...",__FILE__,MKSOLSHE,g);
347 theCommands.Add("mkshe","make a shell [1] with [2] ...",__FILE__,MKSOLSHE,g);
348 theCommands.Add("getp3d","getp3d vertex",__FILE__,GETP3D,g);
350 theCommands.Add("chroboop","",__FILE__,CHROBOOP,g);