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