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 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.
18 #include <Bnd_Box.hxx>
19 #include <BRep_Builder.hxx>
20 #include <BRep_Tool.hxx>
21 #include <BRepBndLib.hxx>
24 #include <Draw_Appli.hxx>
25 #include <Draw_Interpretor.hxx>
26 #include <Draw_Marker3D.hxx>
27 #include <Draw_Segment3D.hxx>
28 #include <DrawTrSurf.hxx>
29 #include <DrawTrSurf_Point.hxx>
32 #include <Precision.hxx>
33 #include <TestTopOpe.hxx>
35 #include <TopoDS_Shape.hxx>
36 #include <TopoDS_Shell.hxx>
37 #include <TopoDS_Solid.hxx>
38 #include <TopoDS_Vertex.hxx>
39 #include <TopOpeBRepBuild_HBuilder.hxx>
40 #include <TopOpeBRepDS_HDataStructure.hxx>
43 Standard_IMPORT Draw_Viewer dout;
46 //=======================================================================
47 // bounds S xmin ymin zmin zmax ymax zmax
48 //=======================================================================
49 Standard_Integer BOUNDS(Draw_Interpretor& di, Standard_Integer narg, const char** a)
51 if (narg != 8) return 1;
52 TopoDS_Shape S = DBRep::Get(a[1]);
53 Standard_Real xmin,ymin,zmin,xmax,ymax,zmax;
54 Bnd_Box b; BRepBndLib::Add(S,b);
55 b.Enlarge(Precision::Confusion());
56 b.Get(xmin,ymin,zmin,xmax,ymax,zmax);
63 di<<"xmin:"<<xmin<<" ";
64 di<<"ymin:"<<ymin<<" ";
65 di<<"zmin:"<<zmin<<" ";
66 di<<"xmax:"<<xmax<<" ";
67 di<<"ymax:"<<ymax<<" ";
68 di<<"zmax:"<<zmax<<"\n";
72 //---------------------------------------------------------------------
73 static Standard_Boolean PersEyeDir(const Standard_Integer ViewId,
76 //---------------------------------------------------------------------
81 dout.GetTrsf(ViewId,T);
84 Standard_Boolean pers = Standard_False;
85 if (!strcmp("PERS",dout.GetType(ViewId))) {
87 Eye.SetXYZ(dout.Focal(ViewId)*Dirz.XYZ());
94 //=======================================================================
95 // DOTVIEW dx dy dz id ddx ddy ddz (ddx,ddy,ddz) = (dx,dy,dz)^(<id> axis)
96 //=======================================================================
97 Standard_Integer DOTVIEW(Draw_Interpretor&, Standard_Integer narg, const char** a)
99 if (narg < 8) return 1;
101 Standard_Real dx,dy,dz;
102 Draw::Get(a[1],dx); Draw::Get(a[2],dy); Draw::Get(a[3],dz);
104 Standard_Real idr; Draw::Get(a[4],idr);
105 gp_Pnt p; gp_Dir d2; PersEyeDir((Standard_Integer)idr,p,d2);
107 gp_Dir d3(d1.Crossed(d2));
108 Draw::Set(a[5],d3.X());
109 Draw::Set(a[6],d3.Y());
110 Draw::Set(a[7],d3.Z());
115 Standard_Integer VECTEUR(Draw_Interpretor& di, Standard_Integer , const char** ) {
116 di << "Pick positions with button \n";
117 Standard_Integer id,X,Y,b;
119 gp_Pnt P1,P2,PP1,PP2;
121 //-----------------------------------------------------------
122 dout.Select(id,X,Y,b); dout.GetTrsf(id,T);
124 Standard_Real z = dout.Zoom(id);
125 P1.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
128 dout.Select(id,X,Y,b); dout.GetTrsf(id,T);
129 T.Invert(); z = dout.Zoom(id);
131 P2.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
133 Standard_Real xa,ya,za;
134 if(Abs(P1.X())>Abs(P2.X())) xa = P1.X(); else xa = P2.X();
135 if(Abs(P1.Y())>Abs(P2.Y())) ya = P1.Y(); else ya = P2.Y();
136 if(Abs(P1.Z())>Abs(P2.Z())) za = P1.Z(); else za = P2.Z();
137 P1.SetCoord(xa,ya,za);
138 Handle(Draw_Marker3D) D0 = new Draw_Marker3D
139 (gp_Pnt(P1.X(),P1.Y(),P1.Z()),Draw_Square,Draw_blanc,1);
142 //-----------------------------------------------------------
143 dout.Select(id,X,Y,b);
147 PP1.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
149 dout.Select(id,X,Y,b);
153 PP2.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
155 if(Abs(PP1.X())>Abs(PP2.X())) xa = PP1.X(); else xa = PP2.X();
156 if(Abs(PP1.Y())>Abs(PP2.Y())) ya = PP1.Y(); else ya = PP2.Y();
157 if(Abs(PP1.Z())>Abs(PP2.Z())) za = PP1.Z(); else za = PP2.Z();
158 PP1.SetCoord(xa,ya,za);
159 Handle(Draw_Segment3D) d = new Draw_Segment3D(P1, PP1, Draw_blanc);
163 di<<"cdinp P1 "<<P1.X()<<" "<<P1.Y()<<" "<<P1.Z()<<"\n";
164 di<<"cdinp P2 "<<PP1.X()<<" "<<PP1.Y()<<" "<<PP1.Z()<<"\n";
165 di<<"cdinp PM "<<(PP1.X()+P1.X())/2<<" "<<(PP1.Y()+P1.Y())/2<<" "<<(PP1.Z()+P1.Z())/2<<"\n";
167 di<<"ttranslate "<<PP1.X()-P1.X()<<" "<<PP1.Y()-P1.Y()<<" "<<PP1.Z()-P1.Z()<<"\n";
172 Standard_Integer MKSOLSHE(Draw_Interpretor&, Standard_Integer narg, const char** a) {
173 // 0 = [mksol | mkshe], 1 = solide/shell a creer avec 1 = shell ou face
174 // 0 = [mksol | mkshe], 1 = solide/shell a creer avec 2...narg-1 subsshapes
175 if (narg < 2) return 1;
181 Standard_Integer i1 = (narg == 2) ? 1 : 2;
182 Standard_Integer i2 = (narg > 2) ? narg : 2;
184 // take all the FACE args, place them in the shell <she>
185 TopoDS_Shell she; BB.MakeShell(she); she.Closed(Standard_False);
186 Standard_Boolean yaface = Standard_False;
187 for (i = i1; i < i2; i++) {
188 const TopoDS_Shape& S = DBRep::Get(a[i]);
189 if (S.IsNull()) continue;
190 if (S.ShapeType() == TopAbs_FACE) {
192 she.Closed (BRep_Tool::IsClosed (she));
193 yaface = Standard_True;
197 // take all the SHELL args, place them in the solid <sol>
198 TopoDS_Solid sol; BB.MakeSolid(sol);
199 for (i = i1; i < i2; i++) {
200 const TopoDS_Shape& S = DBRep::Get(a[i]);
201 if (S.IsNull()) continue;
202 if (S.ShapeType() == TopAbs_SHELL) {
207 if (!strcmp("mksol",a[0])) {
208 if (yaface) BB.Add(sol,she);
211 else if (!strcmp("mkshe",a[0])) {
218 DBRep::Set(a[1],res);
222 //=======================================================================
223 // Grille xmin ymin zmin zmax ymax zmax nbx nby nbz
224 //=======================================================================
225 Standard_Integer GRILLE(Draw_Interpretor& di, Standard_Integer narg, const char** a)
227 if (narg != 10) return 1;
228 Standard_Real xmin,ymin,zmin,xmax,ymax,zmax,dx,dy;
229 Standard_Integer nbx,nby,nbz;
230 xmin = Draw::Atof(a[1]);
231 ymin = Draw::Atof(a[2]);
232 zmin = Draw::Atof(a[3]);
233 xmax = Draw::Atof(a[4]);
234 ymax = Draw::Atof(a[5]);
235 zmax = Draw::Atof(a[6]);
236 nbx = Draw::Atoi(a[7]);
237 nby = Draw::Atoi(a[8]);
238 nbz = Draw::Atoi(a[9]);
239 if(xmax<xmin || ymax<ymin || zmax<zmin || nbx<0 || nby<0 || nbz<0)
241 if(nbx) dx = (xmax-xmin)/nbx; else dx=0;
242 if(nby) dy = (ymax-ymin)/nby; else dy=0;
244 for(Standard_Real x=xmin; x<xmax; x+=dx) {
245 for(Standard_Real y=ymin; y<ymax; y+=dx) {
246 //-- cout<<x<<" "<<y<<" "<<zmin<<" "<<x<<" "<<y<<" "<<zmax<<"\n";
247 di<<"line l "<<x<<" "<<y<<" "<<zmin<<" 0 0 1;mkedge e l 0 ";
248 di<<zmax-zmin<<" ;orient e EXTERNAL; add e CE\n";
256 Standard_Integer GETP3D(Draw_Interpretor& di, Standard_Integer /*narg*/, const char** a)
258 TopoDS_Shape V = DBRep::Get(a[1]);
263 gp_Pnt pV = BRep_Tool::Pnt(TopoDS::Vertex(V));
264 di<<pV.X()<<" "<<pV.Y()<<" "<<pV.Z()<<"\n";
268 #include <Draw_Chronometer.hxx>
269 Standard_IMPORT Standard_Boolean Draw_Chrono;
270 Standard_Integer CHROBOOP(Draw_Interpretor& di, Standard_Integer n, const char** a)
272 Standard_Real ns = 0.;
273 Standard_Integer nm = 0;
274 Standard_Integer nh = 0;
275 Standard_Real ct = 0.;
277 if ((n == 1) || (*a[1] == '0') || (*a[1] == '1')) {
279 Draw_Chrono = !Draw_Chrono;
281 Draw_Chrono = (*a[1] == '1');
283 if (Draw_Chrono) di << "Chronometers activated.\n";
284 else di << "Chronometers desactivated.\n";
287 Handle(Draw_Drawable3D) D = Draw::Get(a[1]);
288 Handle(Draw_Chronometer) C;
290 C = Handle(Draw_Chronometer)::DownCast(D);
293 C = new Draw_Chronometer();
294 Draw::Set(a[1],C,Standard_False);
300 if (!strcasecmp(a[2],"reset"))
302 else if (!strcasecmp(a[2],"start"))
304 else if (!strcasecmp(a[2],"stop"))
306 else if (!strcasecmp(a[2],"show"))
309 C->Timer().Show(ns,nm,nh,ct);
310 if (!strcasecmp(a[2],"-s")) {
313 else if (!strcasecmp(a[2],"-m")) {
316 else if (!strcasecmp(a[2],"-h")) {
319 else if (!strcasecmp(a[2],"-c")) {
329 //=======================================================================
330 //function : OtherCommands
332 //=======================================================================
333 void TestTopOpe::OtherCommands(Draw_Interpretor& theCommands)
335 const char* g = "TestTopOpe OtherCommands";
336 theCommands.Add("grille","grille x0 y0 z0 x1 y1 z1 nbx nby nbz",__FILE__,GRILLE,g);
337 theCommands.Add("vecteur","4 Pick",__FILE__,VECTEUR,g);
338 theCommands.Add("bounds","bounds S x1 y1 z1 z2 y2 z2 = (box of S)",__FILE__,BOUNDS,g);
339 theCommands.Add("dotview","dotview dx dy dz id _dx1 _dx2 _dx3",__FILE__,DOTVIEW,g);
340 theCommands.Add("mksol","make a solid [1] with [2] ...",__FILE__,MKSOLSHE,g);
341 theCommands.Add("mkshe","make a shell [1] with [2] ...",__FILE__,MKSOLSHE,g);
342 theCommands.Add("getp3d","getp3d vertex",__FILE__,GETP3D,g);
344 theCommands.Add("chroboop","",__FILE__,CHROBOOP,g);