1 // Created on: 1997-01-21
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
25 #include <TestTopOpe.ixx>
28 #include <Draw_Interpretor.hxx>
29 #include <Draw_Appli.hxx>
31 #include <Draw_Marker3D.hxx>
32 #include <Draw_Segment3D.hxx>
33 #include <DrawTrSurf_Point.hxx>
34 #include <DrawTrSurf.hxx>
35 #include <BRep_Builder.hxx>
37 #include <TopoDS_Vertex.hxx>
38 #include <TopoDS_Shell.hxx>
39 #include <TopoDS_Shape.hxx>
40 #include <TopoDS_Solid.hxx>
41 #include <Bnd_Box.hxx>
44 #include <BRepBndLib.hxx>
45 #include <BRep_Tool.hxx>
46 #include <Precision.hxx>
49 Standard_IMPORT Draw_Viewer dout;
55 //=======================================================================
56 // bounds S xmin ymin zmin zmax ymax zmax
57 //=======================================================================
58 Standard_Integer BOUNDS(Draw_Interpretor& di, Standard_Integer narg, const char** a)
60 if (narg != 8) return 1;
61 TopoDS_Shape S = DBRep::Get(a[1]);
62 Standard_Real xmin,ymin,zmin,xmax,ymax,zmax;
63 Bnd_Box b; BRepBndLib::Add(S,b);
64 b.Enlarge(Precision::Confusion());
65 b.Get(xmin,ymin,zmin,xmax,ymax,zmax);
72 di<<"xmin:"<<xmin<<" ";
73 di<<"ymin:"<<ymin<<" ";
74 di<<"zmin:"<<zmin<<" ";
75 di<<"xmax:"<<xmax<<" ";
76 di<<"ymax:"<<ymax<<" ";
77 di<<"zmax:"<<zmax<<"\n";
81 //---------------------------------------------------------------------
82 static Standard_Boolean PersEyeDir(const Standard_Integer ViewId,
85 //---------------------------------------------------------------------
90 dout.GetTrsf(ViewId,T);
93 Standard_Boolean pers = Standard_False;
94 if (!strcmp("PERS",dout.GetType(ViewId))) {
96 Eye.SetXYZ(dout.Focal(ViewId)*Dirz.XYZ());
103 //=======================================================================
104 // DOTVIEW dx dy dz id ddx ddy ddz (ddx,ddy,ddz) = (dx,dy,dz)^(<id> axis)
105 //=======================================================================
106 Standard_Integer DOTVIEW(Draw_Interpretor&, Standard_Integer narg, const char** a)
108 if (narg < 8) return 1;
110 Standard_Real dx,dy,dz;
111 Draw::Get(a[1],dx); Draw::Get(a[2],dy); Draw::Get(a[3],dz);
113 Standard_Real idr; Draw::Get(a[4],idr);
114 gp_Pnt p; gp_Dir d2; PersEyeDir((Standard_Integer)idr,p,d2);
116 gp_Dir d3(d1.Crossed(d2));
117 Draw::Set(a[5],d3.X());
118 Draw::Set(a[6],d3.Y());
119 Draw::Set(a[7],d3.Z());
124 Standard_Integer VECTEUR(Draw_Interpretor& di, Standard_Integer , const char** ) {
125 di << "Pick positions with button "<<"\n";
126 Standard_Integer id,X,Y,b;
128 gp_Pnt P1,P2,PP1,PP2;
130 //-----------------------------------------------------------
131 dout.Select(id,X,Y,b); dout.GetTrsf(id,T);
133 Standard_Real z = dout.Zoom(id);
134 P1.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
137 dout.Select(id,X,Y,b); dout.GetTrsf(id,T);
138 T.Invert(); z = dout.Zoom(id);
140 P2.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
142 Standard_Real xa,ya,za;
143 if(Abs(P1.X())>Abs(P2.X())) xa = P1.X(); else xa = P2.X();
144 if(Abs(P1.Y())>Abs(P2.Y())) ya = P1.Y(); else ya = P2.Y();
145 if(Abs(P1.Z())>Abs(P2.Z())) za = P1.Z(); else za = P2.Z();
146 P1.SetCoord(xa,ya,za);
147 Handle(Draw_Marker3D) D0 = new Draw_Marker3D
148 (gp_Pnt(P1.X(),P1.Y(),P1.Z()),Draw_Square,Draw_blanc,1);
151 //-----------------------------------------------------------
152 dout.Select(id,X,Y,b);
156 PP1.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
158 dout.Select(id,X,Y,b);
162 PP2.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
164 if(Abs(PP1.X())>Abs(PP2.X())) xa = PP1.X(); else xa = PP2.X();
165 if(Abs(PP1.Y())>Abs(PP2.Y())) ya = PP1.Y(); else ya = PP2.Y();
166 if(Abs(PP1.Z())>Abs(PP2.Z())) za = PP1.Z(); else za = PP2.Z();
167 PP1.SetCoord(xa,ya,za);
168 Handle(Draw_Segment3D) d = new Draw_Segment3D(P1, PP1, Draw_blanc);
172 di<<"cdinp P1 "<<P1.X()<<" "<<P1.Y()<<" "<<P1.Z()<<"\n";
173 di<<"cdinp P2 "<<PP1.X()<<" "<<PP1.Y()<<" "<<PP1.Z()<<"\n";
174 di<<"cdinp PM "<<(PP1.X()+P1.X())/2<<" "<<(PP1.Y()+P1.Y())/2<<" "<<(PP1.Z()+P1.Z())/2<<"\n";
176 di<<"ttranslate "<<PP1.X()-P1.X()<<" "<<PP1.Y()-P1.Y()<<" "<<PP1.Z()-P1.Z()<<"\n";
181 Standard_Integer MKSOLSHE(Draw_Interpretor&, Standard_Integer narg, const char** a) {
182 // 0 = [mksol | mkshe], 1 = solide/shell a creer avec 1 = shell ou face
183 // 0 = [mksol | mkshe], 1 = solide/shell a creer avec 2...narg-1 subsshapes
184 if (narg < 2) return 1;
190 Standard_Integer i1 = (narg == 2) ? 1 : 2;
191 Standard_Integer i2 = (narg > 2) ? narg : 2;
193 // take all the FACE args, place them in the shell <she>
194 TopoDS_Shell she; BB.MakeShell(she); she.Closed(Standard_False);
195 Standard_Boolean yaface = Standard_False;
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_FACE) {
201 yaface = Standard_True;
205 // take all the SHELL args, place them in the solid <sol>
206 TopoDS_Solid sol; BB.MakeSolid(sol);
207 Standard_Boolean yashell = Standard_False;
208 for (i = i1; i < i2; i++) {
209 const TopoDS_Shape& S = DBRep::Get(a[i]);
210 if (S.IsNull()) continue;
211 if (S.ShapeType() == TopAbs_SHELL) {
213 yashell = Standard_True;
217 if (!strcmp("mksol",a[0])) {
218 if (yaface) BB.Add(sol,she);
221 else if (!strcmp("mkshe",a[0])) {
228 DBRep::Set(a[1],res);
232 //=======================================================================
233 // Grille xmin ymin zmin zmax ymax zmax nbx nby nbz
234 //=======================================================================
235 Standard_Integer GRILLE(Draw_Interpretor& di, Standard_Integer narg, const char** a)
237 if (narg != 10) return 1;
238 Standard_Real xmin,ymin,zmin,xmax,ymax,zmax,dx,dy,dz;
239 Standard_Integer nbx,nby,nbz;
249 if(xmax<xmin || ymax<ymin || zmax<zmin || nbx<0 || nby<0 || nbz<0)
251 if(nbx) dx = (xmax-xmin)/nbx; else dx=0;
252 if(nby) dy = (ymax-ymin)/nby; else dy=0;
253 if(nbz) dz = (zmax-zmin)/nbz; else dz=0;
254 di<<"compound CE"<<"\n";
255 for(Standard_Real x=xmin; x<xmax; x+=dx) {
256 for(Standard_Real y=ymin; y<ymax; y+=dx) {
257 //-- cout<<x<<" "<<y<<" "<<zmin<<" "<<x<<" "<<y<<" "<<zmax<<"\n";
258 di<<"line l "<<x<<" "<<y<<" "<<zmin<<" 0 0 1;mkedge e l 0 ";
259 di<<zmax-zmin<<" ;orient e EXTERNAL; add e CE"<<"\n";
267 Standard_Integer GETP3D(Draw_Interpretor& di, Standard_Integer narg, const char** a)
269 TopoDS_Shape V = DBRep::Get(a[1]);
271 di<<"null shape"<<"\n";
274 gp_Pnt pV = BRep_Tool::Pnt(TopoDS::Vertex(V));
275 di<<pV.X()<<" "<<pV.Y()<<" "<<pV.Z()<<"\n";
279 #include <Draw_Chronometer.hxx>
280 Standard_IMPORT Standard_Boolean Draw_Chrono;
281 Standard_Integer CHROBOOP(Draw_Interpretor& di, Standard_Integer n, const char** a)
283 Standard_Real ns = 0.;
284 Standard_Integer nm = 0;
285 Standard_Integer nh = 0;
286 Standard_Real ct = 0.;
288 if ((n == 1) || (*a[1] == '0') || (*a[1] == '1')) {
290 Draw_Chrono = !Draw_Chrono;
292 Draw_Chrono = (*a[1] == '1');
294 if (Draw_Chrono) di << "Chronometers activated."<<"\n";
295 else di << "Chronometers desactivated."<<"\n";
298 Handle(Draw_Drawable3D) D = Draw::Get(a[1]);
299 Handle(Draw_Chronometer) C;
301 C = Handle(Draw_Chronometer)::DownCast(D);
304 C = new Draw_Chronometer();
305 Draw::Set(a[1],C,Standard_False);
311 if (!strcasecmp(a[2],"reset"))
313 else if (!strcasecmp(a[2],"start"))
315 else if (!strcasecmp(a[2],"stop"))
317 else if (!strcasecmp(a[2],"show"))
320 C->Timer().Show(ns,nm,nh,ct);
321 if (!strcasecmp(a[2],"-s")) {
324 else if (!strcasecmp(a[2],"-m")) {
327 else if (!strcasecmp(a[2],"-h")) {
330 else if (!strcasecmp(a[2],"-c")) {
340 //=======================================================================
341 //function : OtherCommands
343 //=======================================================================
344 void TestTopOpe::OtherCommands(Draw_Interpretor& theCommands)
346 const char* g = "TestTopOpe OtherCommands";
347 theCommands.Add("grille","grille x0 y0 z0 x1 y1 z1 nbx nby nbz",__FILE__,GRILLE,g);
348 theCommands.Add("vecteur","4 Pick",__FILE__,VECTEUR,g);
349 theCommands.Add("bounds","bounds S x1 y1 z1 z2 y2 z2 = (box of S)",__FILE__,BOUNDS,g);
350 theCommands.Add("dotview","dotview dx dy dz id _dx1 _dx2 _dx3",__FILE__,DOTVIEW,g);
351 theCommands.Add("mksol","make a solid [1] with [2] ...",__FILE__,MKSOLSHE,g);
352 theCommands.Add("mkshe","make a shell [1] with [2] ...",__FILE__,MKSOLSHE,g);
353 theCommands.Add("getp3d","getp3d vertex",__FILE__,GETP3D,g);
355 theCommands.Add("chroboop","",__FILE__,CHROBOOP,g);