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 | // |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
17 | #ifdef HAVE_CONFIG_H |
18 | # include <config.h> |
19 | #endif |
20 | #include <TestTopOpe.ixx> |
21 | |
22 | #include <DBRep.hxx> |
23 | #include <Draw_Interpretor.hxx> |
24 | #include <Draw_Appli.hxx> |
25 | #include <Draw.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> |
31 | #include <TopoDS.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> |
37 | #include <gp.hxx> |
38 | #include <gp_Pnt.hxx> |
39 | #include <BRepBndLib.hxx> |
40 | #include <BRep_Tool.hxx> |
41 | #include <Precision.hxx> |
42 | |
43 | #ifdef WNT |
44 | Standard_IMPORT Draw_Viewer dout; |
45 | #endif |
46 | #ifdef HAVE_STRINGS_H |
47 | # include <strings.h> |
48 | #endif |
49 | |
50 | //======================================================================= |
51 | // bounds S xmin ymin zmin zmax ymax zmax |
52 | //======================================================================= |
53 | Standard_Integer BOUNDS(Draw_Interpretor& di, Standard_Integer narg, const char** a) |
54 | { |
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); |
61 | Draw::Set(a[2],xmin); |
62 | Draw::Set(a[3],ymin); |
63 | Draw::Set(a[4],zmin); |
64 | Draw::Set(a[5],xmax); |
65 | Draw::Set(a[6],ymax); |
66 | Draw::Set(a[7],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"; |
73 | return 0 ; |
74 | } |
75 | |
76 | //--------------------------------------------------------------------- |
77 | static Standard_Boolean PersEyeDir(const Standard_Integer ViewId, |
78 | gp_Pnt& E, |
79 | gp_Dir& D) |
80 | //--------------------------------------------------------------------- |
81 | { |
82 | gp_Trsf T; |
83 | gp_Pnt Eye; |
84 | gp_Dir Dirz(0,0,1); |
85 | dout.GetTrsf(ViewId,T); |
86 | T.Invert(); |
87 | Dirz.Transform(T); |
88 | Standard_Boolean pers = Standard_False; |
89 | if (!strcmp("PERS",dout.GetType(ViewId))) { |
90 | pers = Standard_True; |
91 | Eye.SetXYZ(dout.Focal(ViewId)*Dirz.XYZ()); |
92 | } |
93 | E = Eye; |
94 | D = Dirz; |
95 | return pers; |
96 | } |
97 | |
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) |
102 | { |
103 | if (narg < 8) return 1; |
104 | |
105 | Standard_Real dx,dy,dz; |
106 | Draw::Get(a[1],dx); Draw::Get(a[2],dy); Draw::Get(a[3],dz); |
107 | gp_Dir d1(dx,dy,dz); |
108 | Standard_Real idr; Draw::Get(a[4],idr); |
109 | gp_Pnt p; gp_Dir d2; PersEyeDir((Standard_Integer)idr,p,d2); |
110 | |
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()); |
115 | |
116 | return 0; |
117 | } |
118 | |
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; |
122 | gp_Trsf T; |
123 | gp_Pnt P1,P2,PP1,PP2; |
124 | |
125 | //----------------------------------------------------------- |
126 | dout.Select(id,X,Y,b); dout.GetTrsf(id,T); |
127 | T.Invert(); |
128 | Standard_Real z = dout.Zoom(id); |
129 | P1.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0); |
130 | P1.Transform(T); |
131 | |
132 | dout.Select(id,X,Y,b); dout.GetTrsf(id,T); |
133 | T.Invert(); z = dout.Zoom(id); |
134 | |
135 | P2.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0); |
136 | P2.Transform(T); |
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); |
144 | dout << D0; |
145 | dout.Flush(); |
146 | //----------------------------------------------------------- |
147 | dout.Select(id,X,Y,b); |
148 | dout.GetTrsf(id,T); |
149 | T.Invert(); |
150 | z = dout.Zoom(id); |
151 | PP1.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0); |
152 | PP1.Transform(T); |
153 | dout.Select(id,X,Y,b); |
154 | dout.GetTrsf(id,T); |
155 | T.Invert(); |
156 | z = dout.Zoom(id); |
157 | PP2.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0); |
158 | PP2.Transform(T); |
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); |
164 | dout << d; |
165 | dout.Flush(); |
166 | di<<"\n"; |
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"; |
170 | di<<"\n"; |
171 | di<<"ttranslate "<<PP1.X()-P1.X()<<" "<<PP1.Y()-P1.Y()<<" "<<PP1.Z()-P1.Z()<<"\n"; |
172 | |
173 | return 0; |
174 | } |
175 | |
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; |
180 | |
181 | Standard_Integer i; |
182 | BRep_Builder BB; |
183 | TopoDS_Shape res; |
184 | |
185 | Standard_Integer i1 = (narg == 2) ? 1 : 2; |
186 | Standard_Integer i2 = (narg > 2) ? narg : 2; |
187 | |
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) { |
195 | BB.Add(she,S); |
196 | yaface = Standard_True; |
197 | } |
198 | } |
199 | |
200 | // take all the SHELL args, place them in the solid <sol> |
201 | TopoDS_Solid sol; BB.MakeSolid(sol); |
7fd59977 |
202 | for (i = i1; i < i2; i++) { |
203 | const TopoDS_Shape& S = DBRep::Get(a[i]); |
204 | if (S.IsNull()) continue; |
205 | if (S.ShapeType() == TopAbs_SHELL) { |
206 | BB.Add(sol,S); |
7fd59977 |
207 | } |
208 | } |
209 | |
210 | if (!strcmp("mksol",a[0])) { |
211 | if (yaface) BB.Add(sol,she); |
212 | res = sol; |
213 | } |
214 | else if (!strcmp("mkshe",a[0])) { |
215 | res = she; |
216 | } |
217 | else { |
218 | return 1; |
219 | } |
220 | |
221 | DBRep::Set(a[1],res); |
222 | return 0; |
223 | } |
224 | |
225 | //======================================================================= |
226 | // Grille xmin ymin zmin zmax ymax zmax nbx nby nbz |
227 | //======================================================================= |
228 | Standard_Integer GRILLE(Draw_Interpretor& di, Standard_Integer narg, const char** a) |
229 | { |
230 | if (narg != 10) return 1; |
96a95605 |
231 | Standard_Real xmin,ymin,zmin,xmax,ymax,zmax,dx,dy; |
7fd59977 |
232 | Standard_Integer nbx,nby,nbz; |
91322f44 |
233 | xmin = Draw::Atof(a[1]); |
234 | ymin = Draw::Atof(a[2]); |
235 | zmin = Draw::Atof(a[3]); |
236 | xmax = Draw::Atof(a[4]); |
237 | ymax = Draw::Atof(a[5]); |
238 | zmax = Draw::Atof(a[6]); |
239 | nbx = Draw::Atoi(a[7]); |
240 | nby = Draw::Atoi(a[8]); |
241 | nbz = Draw::Atoi(a[9]); |
7fd59977 |
242 | if(xmax<xmin || ymax<ymin || zmax<zmin || nbx<0 || nby<0 || nbz<0) |
243 | return 1; |
244 | if(nbx) dx = (xmax-xmin)/nbx; else dx=0; |
245 | if(nby) dy = (ymax-ymin)/nby; else dy=0; |
7fd59977 |
246 | di<<"compound CE"<<"\n"; |
247 | for(Standard_Real x=xmin; x<xmax; x+=dx) { |
248 | for(Standard_Real y=ymin; y<ymax; y+=dx) { |
249 | //-- cout<<x<<" "<<y<<" "<<zmin<<" "<<x<<" "<<y<<" "<<zmax<<"\n"; |
250 | di<<"line l "<<x<<" "<<y<<" "<<zmin<<" 0 0 1;mkedge e l 0 "; |
251 | di<<zmax-zmin<<" ;orient e EXTERNAL; add e CE"<<"\n"; |
252 | if(dy==0) y=ymax; |
253 | } |
254 | if(dx==0) x=xmax; |
255 | } |
256 | return 0 ; |
257 | } |
258 | |
35e08fe8 |
259 | Standard_Integer GETP3D(Draw_Interpretor& di, Standard_Integer /*narg*/, const char** a) |
7fd59977 |
260 | { |
261 | TopoDS_Shape V = DBRep::Get(a[1]); |
262 | if (V.IsNull()) { |
263 | di<<"null shape"<<"\n"; |
264 | return 1; |
265 | } |
266 | gp_Pnt pV = BRep_Tool::Pnt(TopoDS::Vertex(V)); |
267 | di<<pV.X()<<" "<<pV.Y()<<" "<<pV.Z()<<"\n"; |
268 | return 0; |
269 | } |
270 | #ifdef DEB |
271 | #include <Draw_Chronometer.hxx> |
272 | Standard_IMPORT Standard_Boolean Draw_Chrono; |
273 | Standard_Integer CHROBOOP(Draw_Interpretor& di, Standard_Integer n, const char** a) |
274 | { |
275 | Standard_Real ns = 0.; |
276 | Standard_Integer nm = 0; |
277 | Standard_Integer nh = 0; |
278 | Standard_Real ct = 0.; |
279 | |
280 | if ((n == 1) || (*a[1] == '0') || (*a[1] == '1')) { |
281 | if (n == 1) |
282 | Draw_Chrono = !Draw_Chrono; |
283 | else |
284 | Draw_Chrono = (*a[1] == '1'); |
285 | |
286 | if (Draw_Chrono) di << "Chronometers activated."<<"\n"; |
287 | else di << "Chronometers desactivated."<<"\n"; |
288 | } |
289 | else { |
290 | Handle(Draw_Drawable3D) D = Draw::Get(a[1]); |
291 | Handle(Draw_Chronometer) C; |
292 | if (!D.IsNull()) { |
293 | C = Handle(Draw_Chronometer)::DownCast(D); |
294 | } |
295 | if (C.IsNull()) { |
296 | C = new Draw_Chronometer(); |
297 | Draw::Set(a[1],C,Standard_False); |
298 | } |
299 | if (n <= 2) { |
300 | C->Timer().Reset(); |
301 | } |
302 | else if (n <= 3) { |
303 | if (!strcasecmp(a[2],"reset")) |
304 | C->Timer().Reset(); |
305 | else if (!strcasecmp(a[2],"start")) |
306 | C->Timer().Start(); |
307 | else if (!strcasecmp(a[2],"stop")) |
308 | C->Timer().Stop(); |
309 | else if (!strcasecmp(a[2],"show")) |
310 | C->Timer().Show(); |
311 | else { |
312 | C->Timer().Show(ns,nm,nh,ct); |
313 | if (!strcasecmp(a[2],"-s")) { |
314 | di<<ns; |
315 | } |
316 | else if (!strcasecmp(a[2],"-m")) { |
317 | di<<nm; |
318 | } |
319 | else if (!strcasecmp(a[2],"-h")) { |
320 | di<<nh; |
321 | } |
322 | else if (!strcasecmp(a[2],"-c")) { |
323 | di<<ct; |
324 | } |
325 | } |
326 | } |
327 | } |
328 | return 0; |
329 | } |
330 | #endif |
331 | |
332 | //======================================================================= |
333 | //function : OtherCommands |
334 | //purpose : |
335 | //======================================================================= |
336 | void TestTopOpe::OtherCommands(Draw_Interpretor& theCommands) |
337 | { |
338 | const char* g = "TestTopOpe OtherCommands"; |
339 | theCommands.Add("grille","grille x0 y0 z0 x1 y1 z1 nbx nby nbz",__FILE__,GRILLE,g); |
340 | theCommands.Add("vecteur","4 Pick",__FILE__,VECTEUR,g); |
341 | theCommands.Add("bounds","bounds S x1 y1 z1 z2 y2 z2 = (box of S)",__FILE__,BOUNDS,g); |
342 | theCommands.Add("dotview","dotview dx dy dz id _dx1 _dx2 _dx3",__FILE__,DOTVIEW,g); |
343 | theCommands.Add("mksol","make a solid [1] with [2] ...",__FILE__,MKSOLSHE,g); |
344 | theCommands.Add("mkshe","make a shell [1] with [2] ...",__FILE__,MKSOLSHE,g); |
345 | theCommands.Add("getp3d","getp3d vertex",__FILE__,GETP3D,g); |
346 | #ifdef DEB |
347 | theCommands.Add("chroboop","",__FILE__,CHROBOOP,g); |
348 | #endif |
349 | } |