Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1994-12-13 |
2 | // Created by: Jacques GOUSSARD | |
3 | // Copyright (c) 1994-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 | // |
d5f74e42 | 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 | |
973c2be1 | 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 | #include <Standard_Stream.hxx> | |
18 | #include <Standard_Macro.hxx> | |
19 | ||
20 | #include <BRepTest.hxx> | |
21 | ||
22 | #include <DBRep.hxx> | |
23 | #include <Draw_Appli.hxx> | |
24 | #include <Draw_Interpretor.hxx> | |
25 | #include <Draw_Box.hxx> | |
26 | ||
27 | #include <BRepBuilderAPI.hxx> | |
28 | #include <BRepBuilderAPI_FindPlane.hxx> | |
29 | #include <BRepBuilderAPI_Copy.hxx> | |
30 | #include <BRepBuilderAPI_Transform.hxx> | |
31 | #include <BRepBuilderAPI_GTransform.hxx> | |
32 | #include <BRepBuilderAPI_NurbsConvert.hxx> | |
33 | #include <gp_Ax2.hxx> | |
34 | #include <gp_Mat.hxx> | |
35 | #include <gp_GTrsf.hxx> | |
36 | #include <BRepOffsetAPI_NormalProjection.hxx> | |
37 | #include <BRepLib.hxx> | |
38 | #include <BRep_Builder.hxx> | |
39 | #include <BRepBndLib.hxx> | |
40 | #include <Bnd_Box.hxx> | |
41 | #include <TopExp_Explorer.hxx> | |
42 | #include <TopoDS.hxx> | |
43 | #include <BRepTools_WireExplorer.hxx> | |
44 | ||
45 | #include <GCPnts_QuasiUniformAbscissa.hxx> | |
46 | #include <Geom2dAdaptor_Curve.hxx> | |
47 | #include <GeomAdaptor_Curve.hxx> | |
48 | #include <ProjLib_ComputeApproxOnPolarSurface.hxx> | |
49 | #include <DrawTrSurf.hxx> | |
50 | ||
51 | ||
52 | #include <Draw_Segment3D.hxx> | |
53 | #include <Draw_Marker3D.hxx> | |
54 | #include <Draw_MarkerShape.hxx> | |
55 | ||
7fd59977 | 56 | #include <stdio.h> |
57 | ||
58 | Standard_IMPORT Draw_Viewer dout; | |
59 | ||
60 | ||
61 | ||
62 | //======================================================================= | |
63 | // addpcurve | |
64 | //======================================================================= | |
65 | ||
66 | static Standard_Integer addpcurve(Draw_Interpretor& , Standard_Integer n, const char** a) | |
67 | { | |
68 | if(n < 4) return 1; | |
69 | TopoDS_Shape E = DBRep::Get(a[1]); | |
70 | if (E.IsNull()) return 1; | |
71 | Handle(Geom2d_Curve) PC = DrawTrSurf::GetCurve2d(a[2]); | |
72 | TopoDS_Shape F = DBRep::Get(a[3]); | |
73 | Standard_Real tol = 1.e-7; | |
74 | if (n > 4) { | |
91322f44 | 75 | tol = Draw::Atof(a[4]); |
7fd59977 | 76 | } |
77 | BRep_Builder BB; | |
78 | BB.UpdateEdge(TopoDS::Edge(E), PC, TopoDS::Face(F),tol); | |
79 | DBRep::Set(a[1], E); | |
80 | return 0; | |
81 | } | |
82 | ||
83 | ||
84 | //======================================================================= | |
85 | // transform | |
86 | //======================================================================= | |
87 | ||
88 | static Standard_Integer transform(Draw_Interpretor& di,Standard_Integer n,const char** a) | |
89 | { | |
90 | if (n <= 1) return 1; | |
91 | ||
92 | gp_Trsf T; | |
93 | Standard_Integer last = n; | |
513d3443 | 94 | const char* aName = a[0]; |
7fd59977 | 95 | |
513d3443 | 96 | Standard_Boolean isBasic = Standard_False; |
7fd59977 | 97 | |
513d3443 | 98 | if (!strcmp(aName,"reset")) { |
99 | } | |
100 | else { | |
101 | isBasic = (aName[0] == 'b'); | |
102 | aName++; | |
103 | ||
104 | if (!strcmp(aName,"move")) { | |
105 | if (n < 3) return 1; | |
106 | TopoDS_Shape SL = DBRep::Get(a[n-1]); | |
107 | if (SL.IsNull()) return 0; | |
108 | T = SL.Location().Transformation(); | |
109 | last = n-1; | |
110 | } | |
111 | else if (!strcmp(aName,"translate")) { | |
112 | if (n < 5) return 1; | |
113 | T.SetTranslation(gp_Vec(Draw::Atof(a[n-3]),Draw::Atof(a[n-2]),Draw::Atof(a[n-1]))); | |
114 | last = n-3; | |
115 | } | |
116 | else if (!strcmp(aName,"rotate")) { | |
117 | if (n < 9) return 1; | |
118 | T.SetRotation(gp_Ax1(gp_Pnt(Draw::Atof(a[n-7]),Draw::Atof(a[n-6]),Draw::Atof(a[n-5])), | |
119 | gp_Vec(Draw::Atof(a[n-4]),Draw::Atof(a[n-3]),Draw::Atof(a[n-2]))), | |
120 | Draw::Atof(a[n-1])* (M_PI / 180.0)); | |
121 | last = n-7; | |
122 | } | |
123 | else if (!strcmp(aName,"mirror")) { | |
124 | if (n < 8) return 1; | |
125 | T.SetMirror(gp_Ax2(gp_Pnt(Draw::Atof(a[n-6]),Draw::Atof(a[n-5]),Draw::Atof(a[n-4])), | |
126 | gp_Vec(Draw::Atof(a[n-3]),Draw::Atof(a[n-2]),Draw::Atof(a[n-1])))); | |
127 | last = n-6; | |
128 | } | |
129 | else if (!strcmp(aName,"scale")) { | |
130 | if (n < 6) return 1; | |
131 | T.SetScale(gp_Pnt(Draw::Atof(a[n-4]),Draw::Atof(a[n-3]),Draw::Atof(a[n-2])),Draw::Atof(a[n-1])); | |
132 | last = n-4; | |
133 | } | |
7fd59977 | 134 | } |
135 | ||
513d3443 | 136 | if (T.Form() == gp_Identity || isBasic) { |
137 | TopLoc_Location L(T); | |
7fd59977 | 138 | for (Standard_Integer i = 1; i < last; i++) { |
139 | TopoDS_Shape S = DBRep::Get(a[i]); | |
513d3443 | 140 | if (S.IsNull()) |
141 | di << a[i] << " is not a valid shape\n"; | |
142 | else | |
143 | DBRep::Set(a[i],S.Located(L)); | |
7fd59977 | 144 | } |
145 | } | |
146 | else { | |
147 | BRepBuilderAPI_Transform trf(T); | |
148 | for (Standard_Integer i = 1; i < last; i++) { | |
149 | TopoDS_Shape S = DBRep::Get(a[i]); | |
150 | if (S.IsNull()) { | |
513d3443 | 151 | di << a[i] << " is not a valid shape\n"; |
7fd59977 | 152 | } |
153 | else { | |
513d3443 | 154 | trf.Perform(S); |
155 | if (!trf.IsDone()) | |
156 | return 1; | |
157 | DBRep::Set(a[i],trf.Shape()); | |
7fd59977 | 158 | } |
159 | } | |
160 | } | |
161 | return 0; | |
162 | } | |
163 | ||
7fd59977 | 164 | ///======================================================================= |
165 | // gtransform | |
166 | //======================================================================= | |
167 | ||
168 | static Standard_Integer deform(Draw_Interpretor& di,Standard_Integer n,const char** a) | |
169 | { | |
170 | if (n <= 1) return 1; | |
171 | ||
172 | Standard_Integer last = n; | |
173 | ||
174 | gp_Trsf T; | |
175 | gp_GTrsf GT(T); | |
176 | ||
91322f44 | 177 | // gp_Mat rot(Draw::Atof(a[last-3]),0,0,0,Draw::Atof(a[last-2]),0,0,0,Draw::Atof(a[last-1])); |
178 | gp_Mat rot(Draw::Atof(a[3]),0,0,0,Draw::Atof(a[4]),0,0,0,Draw::Atof(a[5])); | |
7fd59977 | 179 | GT.SetVectorialPart(rot); |
180 | last -= 3; | |
181 | BRepBuilderAPI_GTransform gtrf(GT); | |
182 | BRepBuilderAPI_NurbsConvert nbscv; | |
183 | // for (Standard_Integer i = 1; i < last; i++) { | |
184 | // TopoDS_Shape S = DBRep::Get(a[i]); | |
185 | TopoDS_Shape S = DBRep::Get(a[2]); | |
186 | if (S.IsNull()) { | |
187 | //cout << a[2] << " is not a valid shape" << endl; | |
188 | di << a[2] << " is not a valid shape" << "\n"; | |
189 | } | |
190 | else { | |
191 | gtrf.Perform(S); | |
192 | if (gtrf.IsDone()){ | |
193 | DBRep::Set(a[1],gtrf.Shape()); | |
194 | } | |
195 | else { | |
196 | return 1; | |
197 | } | |
198 | } | |
199 | ||
200 | return 0; | |
201 | } | |
202 | ||
203 | //======================================================================= | |
204 | // tcopy | |
205 | //======================================================================= | |
206 | ||
207 | static Standard_Integer tcopy(Draw_Interpretor& di,Standard_Integer n,const char** a) | |
208 | { | |
209 | Standard_Boolean copyGeom = Standard_True; | |
210 | Standard_Integer iFirst = 1; // index of first shape argument | |
211 | ||
212 | if (n > 1 && a[1][0] == '-' && a[1][1] == 'n' ) | |
213 | { | |
214 | copyGeom = Standard_False; | |
215 | iFirst = 2; | |
216 | } | |
217 | ||
218 | if (n < 3 || (n - iFirst) % 2) { | |
219 | cout << "Use: " << a[0] << " [-n(ogeom)] shape1 copy1 [shape2 copy2 [...]]" << endl; | |
220 | cout << "Option -n forbids copying of geometry (it will be shared)" << endl; | |
221 | return 1; | |
222 | } | |
223 | ||
224 | BRepBuilderAPI_Copy cop; | |
225 | Standard_Integer nbPairs = (n - iFirst) / 2; | |
226 | for (Standard_Integer i=0; i < nbPairs; i++) { | |
227 | cop.Perform(DBRep::Get(a[i+iFirst]), copyGeom); | |
228 | DBRep::Set(a[i+iFirst+1],cop.Shape()); | |
229 | di << a[i+iFirst+1] << " "; | |
230 | } | |
231 | return 0; | |
232 | } | |
233 | ||
234 | ||
235 | //======================================================================= | |
236 | // NurbsConvert | |
237 | //======================================================================= | |
238 | ||
239 | static Standard_Integer nurbsconvert(Draw_Interpretor& di,Standard_Integer n,const char** a) | |
240 | { | |
241 | if (n < 3) return 1; | |
242 | if ((n-1)%2 != 0) return 1; | |
243 | BRepBuilderAPI_NurbsConvert nbscv; | |
244 | for (Standard_Integer i=0; i<(n-1)/2; i++) { | |
245 | TopoDS_Shape S = DBRep::Get(a[2*i+2]); | |
246 | if (S.IsNull()) { | |
247 | //cout << a[2*i+2] << " is not a valid shape" << endl; | |
248 | di << a[2*i+2] << " is not a valid shape" << "\n"; | |
249 | } | |
250 | else { | |
251 | nbscv.Perform(S); | |
252 | if (nbscv.IsDone()){ | |
253 | DBRep::Set(a[2*i+1],nbscv.Shape()); | |
254 | } | |
255 | else { | |
256 | return 1; | |
257 | } | |
258 | } | |
259 | } | |
260 | ||
261 | return 0; | |
262 | ||
263 | } | |
264 | ||
265 | //======================================================================= | |
266 | // make a 3D edge curve | |
267 | //======================================================================= | |
268 | ||
269 | static Standard_Integer mkedgecurve (Draw_Interpretor& ,Standard_Integer n,const char** a) | |
270 | { | |
271 | ||
7fd59977 | 272 | if (n < 3) return 1; |
91322f44 | 273 | Standard_Real Tolerance = Draw::Atof(a[2]) ; |
7fd59977 | 274 | |
275 | TopoDS_Shape S = DBRep::Get(a[1]); | |
276 | ||
277 | if (S.IsNull()) return 1; | |
278 | ||
7fd59977 | 279 | BRepLib::BuildCurves3d(S, |
280 | Tolerance) ; | |
281 | return 0 ; | |
282 | } | |
283 | ||
284 | //======================================================================= | |
285 | // sameparameter | |
286 | //======================================================================= | |
287 | ||
288 | static Standard_Integer sameparameter(Draw_Interpretor& ,Standard_Integer n,const char** a) | |
289 | { | |
290 | if (n < 2) return 1; | |
291 | Standard_Real tol = 1.e-7; | |
292 | TopoDS_Shape S = DBRep::Get(a[1]); | |
293 | if (S.IsNull()) return 1; | |
294 | Standard_Boolean force = !strcmp(a[0],"fsameparameter"); | |
91322f44 | 295 | if (n == 3) tol = Draw::Atof(a[2]); |
7fd59977 | 296 | |
297 | BRepLib::SameParameter(S,tol,force); | |
298 | ||
299 | DBRep::Set(a[1],S); | |
300 | return 0; | |
301 | } | |
302 | //======================================================================= | |
303 | //function : updatetol | |
304 | //purpose : | |
305 | //======================================================================= | |
306 | static Standard_Integer updatetol(Draw_Interpretor& ,Standard_Integer n,const char** a) | |
307 | { | |
308 | if (n < 2) return 1; | |
309 | ||
310 | TopoDS_Shape S = DBRep::Get(a[1]); | |
311 | if (S.IsNull()) return 1; | |
312 | ||
313 | if (n==2) BRepLib::UpdateTolerances(S); | |
314 | else BRepLib::UpdateTolerances(S,Standard_True); | |
315 | DBRep::Set(a[1],S); | |
316 | return 0; | |
317 | ||
318 | } | |
319 | ||
320 | //======================================================================= | |
321 | //function : OrienSolid | |
322 | //purpose : | |
323 | //======================================================================= | |
324 | static Standard_Integer orientsolid(Draw_Interpretor& ,Standard_Integer n,const char** a) | |
325 | { | |
326 | if (n < 2) return 1; | |
327 | ||
328 | TopoDS_Shape S = DBRep::Get(a[1]); | |
329 | if (S.IsNull()) return 1; | |
330 | if (S.ShapeType()!=TopAbs_SOLID) return 1; | |
331 | ||
332 | BRepLib::OrientClosedSolid(TopoDS::Solid(S)); | |
333 | ||
334 | DBRep::Set(a[1],S); | |
335 | return 0; | |
336 | ||
337 | } | |
338 | ||
339 | //======================================================================= | |
340 | //function : boundingstr | |
341 | //purpose : | |
342 | //======================================================================= | |
343 | static Standard_Integer boundingstr(Draw_Interpretor& di,Standard_Integer n,const char** a) | |
344 | { | |
345 | if (n < 2) return 1; | |
346 | TopoDS_Shape S = DBRep::Get(a[1]); | |
347 | if (S.IsNull()) return 1; | |
348 | Bnd_Box B; | |
349 | BRepBndLib::Add(S,B); | |
350 | Standard_Real axmin,aymin,azmin,axmax,aymax,azmax; | |
351 | B.Get(axmin,aymin,azmin,axmax,aymax,azmax); | |
352 | di << axmin<<" "<< aymin<<" "<< azmin<<" "<< axmax<<" "<< aymax<<" "<< azmax; | |
353 | if (n >= 8) { | |
354 | Draw::Set(a[2],axmin) ; | |
355 | Draw::Set(a[3],aymin) ; | |
356 | Draw::Set(a[4],azmin) ; | |
357 | Draw::Set(a[5],axmax) ; | |
358 | Draw::Set(a[6],aymax) ; | |
359 | Draw::Set(a[7],azmax) ; | |
360 | } | |
361 | return 0; | |
362 | } | |
363 | ||
9f6931fb | 364 | //======================================================================= |
365 | //function : getcoords | |
366 | //purpose : | |
367 | //======================================================================= | |
368 | static Standard_Integer getcoords(Draw_Interpretor& di,Standard_Integer n,const char** a) | |
369 | { | |
370 | if(n < 2) | |
371 | return 1; | |
372 | ||
373 | for (Standard_Integer i = 1; i < n; i++) | |
374 | { | |
375 | const TopoDS_Shape aShape = DBRep::Get (a[i]); | |
376 | ||
377 | if (aShape.IsNull()) | |
378 | continue; | |
379 | ||
380 | if (aShape.ShapeType() == TopAbs_VERTEX) | |
381 | { | |
382 | const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape); | |
383 | gp_Pnt aPnt = BRep_Tool::Pnt(aVertex); | |
384 | ||
385 | di << a[i] << " (x,y,z) : " << aPnt.X() << " " << aPnt.Y() << " " << aPnt.Z() << "\n"; | |
386 | } | |
387 | } | |
388 | ||
389 | return 0; | |
390 | } | |
391 | ||
7fd59977 | 392 | //======================================================================= |
393 | //function : bounding | |
394 | //purpose : | |
395 | //======================================================================= | |
396 | static Standard_Integer bounding(Draw_Interpretor& di,Standard_Integer n,const char** a) | |
397 | { | |
398 | if (n < 2) return 1; | |
399 | Standard_Real axmin,aymin,azmin,axmax,aymax,azmax; | |
400 | Bnd_Box B; Handle(Draw_Box) DB; | |
401 | ||
402 | if (n == 2) { | |
403 | TopoDS_Shape S = DBRep::Get(a[1]); | |
404 | if (S.IsNull()) return 1; | |
405 | BRepBndLib::Add(S,B); | |
406 | B.Get(axmin,aymin,azmin,axmax,aymax,azmax); | |
407 | DB = new Draw_Box(gp_Pnt(axmin,aymin,azmin),gp_Pnt(axmax,aymax,azmax),Draw_orange); | |
408 | dout<<DB; | |
409 | di << axmin<<" "<< aymin<<" "<< azmin<<" "<< axmax<<" "<< aymax<<" "<< azmax; | |
410 | } | |
411 | else if (n == 7) { | |
91322f44 | 412 | axmin=Draw::Atof(a[1]); |
413 | aymin=Draw::Atof(a[2]); | |
414 | azmin=Draw::Atof(a[3]); | |
415 | axmax=Draw::Atof(a[4]); | |
416 | aymax=Draw::Atof(a[5]); | |
417 | azmax=Draw::Atof(a[6]); | |
7fd59977 | 418 | DB = new Draw_Box(gp_Pnt(axmin,aymin,azmin),gp_Pnt(axmax,aymax,azmax),Draw_orange); |
419 | dout<<DB; | |
420 | } | |
421 | return 0; | |
422 | } | |
423 | //======================================================================= | |
424 | //function : findplane | |
425 | //purpose : | |
426 | //======================================================================= | |
427 | static Standard_Integer findplane(Draw_Interpretor& di,Standard_Integer n,const char** a) | |
428 | { | |
429 | if (n < 3) return 1; | |
430 | TopoDS_Shape S = DBRep::Get(a[1]); | |
431 | if (S.IsNull()) return 1; | |
432 | Standard_Real tolerance = 1.0e-5 ; | |
433 | BRepBuilderAPI_FindPlane a_plane_finder(S, | |
434 | tolerance) ; | |
435 | if (a_plane_finder.Found()) { | |
436 | //cout << " a plane is found " ; | |
437 | di << " a plane is found \n"; | |
438 | DrawTrSurf::Set(a[2],a_plane_finder.Plane()) ; | |
439 | } | |
440 | return 0 ; | |
441 | } | |
442 | //======================================================================= | |
443 | //function : precision | |
444 | //purpose : | |
445 | //======================================================================= | |
446 | ||
447 | static Standard_Integer precision(Draw_Interpretor& di,Standard_Integer n,const char** a) | |
448 | { | |
449 | n--; | |
450 | ||
451 | if ( n == 0) { | |
452 | //cout << " Current Precision = " << BRepBuilderAPI::Precision() << endl; | |
453 | di << " Current Precision = " << BRepBuilderAPI::Precision() << "\n"; | |
454 | } | |
455 | else { | |
91322f44 | 456 | BRepBuilderAPI::Precision(Draw::Atof(a[1])); |
7fd59977 | 457 | } |
458 | return 0; | |
459 | } | |
460 | ||
461 | ||
462 | //======================================================================= | |
463 | //function : reperage shape (Int lin Shape) + pointe double click + maxtol | |
464 | //purpose : | |
465 | //======================================================================= | |
466 | #include <IntCurvesFace_ShapeIntersector.hxx> | |
467 | #include <gp_Lin.hxx> | |
468 | ||
469 | static Standard_Integer reperageshape(Draw_Interpretor& di, Standard_Integer narg , const char** a) | |
470 | { | |
471 | Standard_Integer details=0; | |
472 | if(narg<2) return 1; | |
473 | if(narg==3) details=1; | |
474 | const char *id1 = a[1]; | |
475 | TopoDS_Shape TheShape1 = DBRep::Get(id1); | |
476 | ||
477 | //cout << "Pick positions with button "<<endl; | |
478 | di << "Pick positions with button "<< "\n"; | |
479 | Standard_Integer id,X,Y,b; | |
480 | gp_Trsf T; | |
481 | gp_Pnt P1,P2; | |
482 | dout.Select(id,X,Y,b); | |
483 | ||
484 | dout.GetTrsf(id,T); | |
485 | T.Invert(); | |
486 | Standard_Real z = dout.Zoom(id); | |
487 | P2.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z, 0.0); | |
488 | P2.Transform(T); | |
489 | P1.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,-1.0); | |
490 | P1.Transform(T); | |
491 | ||
492 | ||
493 | gp_Ax1 Axe(P1,gp_Vec(P1,P2)); | |
494 | IntCurvesFace_ShapeIntersector Inter; | |
495 | Inter.Load(TheShape1,1e-7); | |
496 | ||
497 | Inter.Perform(Axe,-RealLast(),RealLast()); | |
498 | ||
499 | //cout<<"\n --> "; | |
500 | di <<"\n --> "; | |
501 | if(Inter.NbPnt()) { | |
502 | for(Standard_Integer i=1; i<=Inter.NbPnt(); i++) { | |
503 | Standard_Integer numface=1; | |
504 | TopExp_Explorer ExF; | |
505 | for(ExF.Init(TheShape1,TopAbs_FACE); | |
506 | ExF.More(); | |
507 | ExF.Next(),numface++) { | |
508 | TopoDS_Face Face=TopoDS::Face(ExF.Current()); | |
509 | if(Face.IsEqual(Inter.Face(i))) { | |
510 | //cout<<" "<<a[1]<<"_"<<numface; | |
511 | di<<" "<<a[1]<<"_"<<numface; | |
512 | continue; | |
513 | } | |
514 | } | |
515 | const gp_Pnt& P = Inter.Pnt(i); | |
516 | Standard_Real PMin = Inter.WParameter(i); | |
517 | if(details) { | |
518 | //cout<<" w:"<<PMin<<endl; | |
519 | di<<" w:"<<PMin<< "\n"; | |
520 | } | |
521 | if(Inter.Transition(i) == IntCurveSurface_In) { | |
522 | if(Inter.State(i) == TopAbs_IN) { | |
523 | Handle(Draw_Marker3D) p = new Draw_Marker3D(P, Draw_Square, Draw_rouge,2); | |
524 | dout << p; dout.Flush(); | |
525 | } | |
526 | else if(Inter.State(i) == TopAbs_ON) { | |
527 | Handle(Draw_Marker3D) p = new Draw_Marker3D(P, Draw_Square, Draw_vert,2); | |
528 | dout << p; dout.Flush(); | |
529 | } | |
530 | } | |
531 | else { | |
532 | if(Inter.Transition(i) == IntCurveSurface_Out) { | |
533 | if(Inter.State(i) == TopAbs_IN) { | |
534 | Handle(Draw_Marker3D) p = new Draw_Marker3D(P, Draw_X, Draw_rouge,2); | |
535 | dout << p; dout.Flush(); | |
536 | } | |
537 | else if(Inter.State(i) == TopAbs_ON) { | |
538 | Handle(Draw_Marker3D) p = new Draw_Marker3D(P, Draw_X, Draw_vert,2); | |
539 | dout << p; dout.Flush(); | |
540 | } | |
541 | } | |
542 | } | |
543 | } | |
544 | } | |
545 | //cout<<endl; | |
546 | di << "\n"; | |
547 | return(0); | |
548 | } | |
549 | ||
550 | ||
551 | static Standard_Integer maxtolerance(Draw_Interpretor& theCommands, | |
552 | Standard_Integer n, const char** a) { | |
553 | if(n<2) return(1); | |
554 | TopoDS_Shape TheShape = DBRep::Get(a[1]); | |
555 | if(TheShape.IsNull()) return(1); | |
556 | ||
557 | Standard_Real T,TMF,TME,TMV,TmF,TmE,TmV; | |
558 | Standard_Integer nbF,nbE,nbV; | |
559 | TMF=TME=TMV=-RealLast(); | |
560 | TmF=TmE=TmV=RealLast(); | |
581971fe | 561 | |
562 | TopTools_MapOfShape mapS; | |
563 | mapS.Clear(); | |
7fd59977 | 564 | |
581971fe | 565 | for(TopExp_Explorer ex(TheShape,TopAbs_FACE); |
566 | ex.More(); | |
567 | ex.Next()) { | |
568 | TopoDS_Face Face=TopoDS::Face(ex.Current()); | |
7fd59977 | 569 | T=BRep_Tool::Tolerance(Face); |
570 | if(T>TMF) TMF=T; | |
571 | if(T<TmF) TmF=T; | |
581971fe | 572 | mapS.Add(Face); |
7fd59977 | 573 | } |
581971fe | 574 | |
575 | nbF = mapS.Extent(); | |
576 | mapS.Clear(); | |
577 | ||
578 | for(TopExp_Explorer ex(TheShape,TopAbs_EDGE); | |
579 | ex.More(); | |
580 | ex.Next()) { | |
581 | TopoDS_Edge Edge=TopoDS::Edge(ex.Current()); | |
7fd59977 | 582 | T=BRep_Tool::Tolerance(Edge); |
583 | if(T>TME) TME=T; | |
584 | if(T<TmE) TmE=T; | |
581971fe | 585 | mapS.Add(Edge); |
7fd59977 | 586 | } |
581971fe | 587 | |
588 | nbE = mapS.Extent(); | |
589 | mapS.Clear(); | |
590 | ||
591 | for(TopExp_Explorer ex(TheShape,TopAbs_VERTEX); | |
592 | ex.More(); | |
593 | ex.Next()) { | |
594 | TopoDS_Vertex Vertex=TopoDS::Vertex(ex.Current()); | |
7fd59977 | 595 | T=BRep_Tool::Tolerance(Vertex); |
596 | if(T>TMV) TMV=T; | |
597 | if(T<TmV) TmV=T; | |
581971fe | 598 | mapS.Add(Vertex); |
7fd59977 | 599 | } |
7fd59977 | 600 | |
581971fe | 601 | nbV = mapS.Extent(); |
602 | ||
603 | //#ifndef WNT | |
7fd59977 | 604 | Standard_SStream sss; |
605 | sss << "\n## Tolerances on the shape " << a[1] << " (nbFaces:" << nbF | |
606 | << " nbEdges:" << nbE << " nbVtx:" << nbV << ")\n" ; | |
607 | sss.precision(5); | |
608 | sss.setf(ios::scientific); | |
609 | if(TmF<=TMF) sss << "\n Face : Min " << setw(8) << TmF <<" Max " << setw(8) << TMF << " \n "; | |
610 | if(TmE<=TME) sss << "\n Edge : Min " << setw(8) << TmE <<" Max " << setw(8) << TME << " \n "; | |
611 | if(TmV<=TMV) sss << "\n Vertex : Min " << setw(8) << TmV <<" Max " << setw(8) << TMV << " \n "; | |
612 | theCommands << sss; | |
581971fe | 613 | //#endif*/ |
614 | return 0; | |
7fd59977 | 615 | } |
616 | ||
617 | ||
618 | static Standard_Integer vecdc(Draw_Interpretor& di,Standard_Integer ,const char** ) { | |
619 | //cout << "Pick positions with button "<<endl; | |
620 | di << "Pick positions with button "<< "\n"; | |
621 | ||
622 | Standard_Integer id,X,Y,b; | |
623 | gp_Trsf T; | |
624 | gp_Pnt P1,P2,PP1,PP2; | |
625 | ||
626 | //----------------------------------------------------------- | |
627 | dout.Select(id,X,Y,b); dout.GetTrsf(id,T); | |
628 | T.Invert(); | |
629 | Standard_Real z = dout.Zoom(id); | |
630 | P1.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0); | |
631 | P1.Transform(T); | |
632 | ||
633 | dout.Select(id,X,Y,b); dout.GetTrsf(id,T); | |
634 | T.Invert(); z = dout.Zoom(id); | |
635 | ||
636 | P2.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0); | |
637 | P2.Transform(T); | |
638 | Standard_Real xa,ya,za; | |
639 | if(Abs(P1.X())>Abs(P2.X())) xa = P1.X(); else xa = P2.X(); | |
640 | if(Abs(P1.Y())>Abs(P2.Y())) ya = P1.Y(); else ya = P2.Y(); | |
641 | if(Abs(P1.Z())>Abs(P2.Z())) za = P1.Z(); else za = P2.Z(); | |
642 | P1.SetCoord(xa,ya,za); | |
643 | Handle(Draw_Marker3D) D0 = new Draw_Marker3D(gp_Pnt(P1.X(), | |
644 | P1.Y(), | |
645 | P1.Z()), | |
646 | Draw_Square,Draw_blanc,1); | |
647 | ||
648 | dout << D0; | |
649 | dout.Flush(); | |
650 | //----------------------------------------------------------- | |
651 | dout.Select(id,X,Y,b); | |
652 | dout.GetTrsf(id,T); | |
653 | T.Invert(); | |
654 | z = dout.Zoom(id); | |
655 | PP1.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0); | |
656 | PP1.Transform(T); | |
657 | dout.Select(id,X,Y,b); | |
658 | dout.GetTrsf(id,T); | |
659 | T.Invert(); | |
660 | z = dout.Zoom(id); | |
661 | PP2.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0); | |
662 | PP2.Transform(T); | |
663 | if(Abs(PP1.X())>Abs(PP2.X())) xa = PP1.X(); else xa = PP2.X(); | |
664 | if(Abs(PP1.Y())>Abs(PP2.Y())) ya = PP1.Y(); else ya = PP2.Y(); | |
665 | if(Abs(PP1.Z())>Abs(PP2.Z())) za = PP1.Z(); else za = PP2.Z(); | |
666 | PP1.SetCoord(xa,ya,za); | |
667 | Handle(Draw_Segment3D) d = new Draw_Segment3D(P1,PP1,Draw_blanc); | |
668 | dout << d; | |
669 | dout.Flush(); | |
670 | //cout<<"\nttran "<<PP1.X()-P1.X()<<" "<<PP1.Y()-P1.Y()<<" "<<PP1.Z()-P1.Z()<<endl; | |
671 | di <<"\nttran "<<PP1.X()-P1.X()<<" "<<PP1.Y()-P1.Y()<<" "<<PP1.Z()-P1.Z()<< "\n"; | |
672 | ||
673 | static Standard_Integer nboxvecdp=0; | |
674 | //cout<<"\nbox b"<<++nboxvecdp<<" "<<Min(P1.X(),PP1.X())<<" "<<Min(P1.Y(),PP1.Y())<<" "<<Min(PP1.Z(),P1.Z()); | |
675 | //cout<<" "<<Abs(PP1.X()-P1.X())<<" "<<Abs(PP1.Y()-P1.Y())<<" "<<Abs(PP1.Z()-P1.Z())<<endl; | |
676 | ||
677 | //cout<<"\nDistance :"<<sqrt( (PP1.X()-P1.X())*(PP1.X()-P1.X()) | |
678 | // +(PP1.Y()-P1.Y())*(PP1.Y()-P1.Y()) | |
679 | // +(PP1.Z()-P1.Z())*(PP1.Z()-P1.Z()))<<endl; | |
680 | ||
681 | di <<"\nbox b"<<++nboxvecdp<<" "<<Min(P1.X(),PP1.X())<<" "<<Min(P1.Y(),PP1.Y())<<" "<<Min(PP1.Z(),P1.Z()); | |
682 | di <<" "<<Abs(PP1.X()-P1.X())<<" "<<Abs(PP1.Y()-P1.Y())<<" "<<Abs(PP1.Z()-P1.Z())<< "\n"; | |
683 | ||
684 | di <<"\nDistance :"<<sqrt( (PP1.X()-P1.X())*(PP1.X()-P1.X()) | |
685 | +(PP1.Y()-P1.Y())*(PP1.Y()-P1.Y()) | |
686 | +(PP1.Z()-P1.Z())*(PP1.Z()-P1.Z()))<< "\n"; | |
687 | return(0); | |
688 | } | |
689 | //======================================================================= | |
690 | // nproject | |
691 | //======================================================================= | |
692 | ||
693 | #include <TopTools_SequenceOfShape.hxx> | |
694 | static Standard_Integer nproject(Draw_Interpretor& di, Standard_Integer n, const char** a) | |
695 | { | |
696 | if ( n < 4) return 1; | |
697 | TopoDS_Shape InpShape; | |
698 | Standard_Integer arg = 2, i; | |
699 | TopTools_SequenceOfShape Args; | |
700 | ||
701 | Standard_Real Tol = 1.e-4; | |
702 | Standard_Real Tol2d; | |
703 | Standard_Real MaxDistance = 1.e-3; | |
704 | GeomAbs_Shape Continuity = GeomAbs_C2; | |
705 | Standard_Integer MaxDeg = 14; | |
706 | Standard_Integer MaxSeg = 16; | |
707 | ||
708 | while((n > arg) && !(InpShape = DBRep::Get(a[arg])).IsNull()){ | |
709 | Args.Append(InpShape); | |
710 | arg++; | |
711 | } | |
712 | if(Args.Length() < 2) return 1; | |
713 | ||
714 | BRepOffsetAPI_NormalProjection OrtProj(Args.Last()); | |
715 | ||
716 | for(i = 1; i < Args.Length(); i++) | |
717 | OrtProj.Add(Args(i)); | |
718 | ||
719 | if(n > arg) | |
720 | if (!strcmp(a[arg],"-g")) { | |
721 | OrtProj.SetLimit(Standard_False); | |
722 | arg++; | |
723 | } | |
724 | ||
725 | if(n > arg) | |
726 | if (!strcmp(a[arg],"-d")) { | |
727 | arg++; | |
728 | if(n > arg) | |
91322f44 | 729 | MaxDistance = Draw::Atof(a[arg++]); |
7fd59977 | 730 | OrtProj.SetMaxDistance(MaxDistance); |
731 | } | |
732 | if(n > arg) { | |
91322f44 | 733 | Tol = Max(Draw::Atof(a[arg++]),1.e-10); |
7fd59977 | 734 | } |
735 | ||
736 | if(n > arg) { | |
91322f44 | 737 | if (Draw::Atoi(a[arg]) == 0) Continuity = GeomAbs_C0; |
738 | else if (Draw::Atoi(a[arg]) == 1) Continuity = GeomAbs_C1; | |
7fd59977 | 739 | arg++; |
740 | } | |
741 | ||
742 | ||
743 | if(n > arg) { | |
91322f44 | 744 | MaxDeg = Draw::Atoi(a[arg++]); |
7fd59977 | 745 | if (MaxDeg<1 || MaxDeg>14) MaxDeg = 14; |
746 | } | |
747 | ||
91322f44 | 748 | if(n > arg) MaxSeg = Draw::Atoi(a[arg]); |
7fd59977 | 749 | |
750 | Tol2d = Pow(Tol, 2./3); | |
751 | ||
752 | OrtProj.SetParams(Tol, Tol2d, Continuity, MaxDeg, MaxSeg); | |
753 | OrtProj.Build(); | |
754 | TopTools_ListOfShape Wire; | |
755 | Standard_Boolean IsWire=OrtProj.BuildWire(Wire); | |
756 | if (IsWire) { | |
757 | //cout << " BuildWire OK " << endl; | |
758 | di << " BuildWire OK " << "\n"; | |
759 | } | |
760 | DBRep::Set(a[1], OrtProj.Shape()); | |
761 | return 0; | |
762 | } | |
763 | ||
764 | //========================================================================== | |
765 | //function : wexplo | |
0d969553 | 766 | // exploration of a wire |
7fd59977 | 767 | //========================================================================== |
768 | static Standard_Integer wexplo (Draw_Interpretor&, | |
769 | Standard_Integer argc, const char** argv) | |
770 | { | |
771 | char name[100]; | |
772 | if (argc < 2) return 1; | |
773 | ||
774 | TopoDS_Shape C1 = DBRep::Get (argv[1],TopAbs_WIRE); | |
775 | TopoDS_Shape C2 ; | |
776 | ||
777 | if (argc > 2) C2 = DBRep::Get (argv[2],TopAbs_FACE); | |
778 | ||
779 | if (C1.IsNull()) return 1; | |
780 | ||
781 | BRepTools_WireExplorer we; | |
782 | if (C2.IsNull()) we.Init(TopoDS::Wire(C1)); | |
783 | else we.Init(TopoDS::Wire(C1),TopoDS::Face(C2)); | |
784 | ||
785 | Standard_Integer k = 1; | |
786 | while (we.More()) { | |
787 | TopoDS_Edge E = we.Current(); | |
91322f44 | 788 | Sprintf(name,"WEDGE_%d",k); |
7fd59977 | 789 | DBRep::Set(name,E); |
790 | we.Next(); | |
791 | k++; | |
792 | } | |
793 | ||
794 | return 0; | |
795 | } | |
796 | ||
35e08fe8 | 797 | static Standard_Integer scalexyz(Draw_Interpretor& /*di*/, Standard_Integer n, const char** a) |
86eff19e J |
798 | { |
799 | if (n < 6) return 1; | |
7fd59977 | 800 | |
86eff19e J |
801 | TopoDS_Shape aShapeBase = DBRep::Get(a[2]); |
802 | if (aShapeBase.IsNull()) return 1; | |
803 | ||
91322f44 | 804 | Standard_Real aFactorX = Draw::Atof(a[3]); |
805 | Standard_Real aFactorY = Draw::Atof(a[4]); | |
806 | Standard_Real aFactorZ = Draw::Atof(a[5]); | |
86eff19e J |
807 | |
808 | gp_GTrsf aGTrsf; | |
809 | gp_Mat rot (aFactorX, 0, 0, | |
810 | 0, aFactorY, 0, | |
811 | 0, 0, aFactorZ); | |
812 | aGTrsf.SetVectorialPart(rot); | |
813 | BRepBuilderAPI_GTransform aBRepGTrsf (aShapeBase, aGTrsf, Standard_False); | |
814 | if (!aBRepGTrsf.IsDone()) | |
815 | Standard_ConstructionError::Raise("Scaling not done"); | |
816 | TopoDS_Shape Result = aBRepGTrsf.Shape(); | |
817 | ||
818 | DBRep::Set(a[1], Result); | |
819 | return 0; | |
820 | } | |
7fd59977 | 821 | |
822 | void BRepTest::BasicCommands(Draw_Interpretor& theCommands) | |
823 | { | |
824 | static Standard_Boolean done = Standard_False; | |
825 | if (done) return; | |
826 | done = Standard_True; | |
827 | ||
828 | DBRep::BasicCommands(theCommands); | |
829 | ||
830 | const char* g = "TOPOLOGY Basic shape commands"; | |
831 | ||
832 | theCommands.Add("addpcurve", | |
833 | "addpcurve edge 2dcurve face [tol (default 1.e-7)]", | |
834 | __FILE__, | |
835 | addpcurve,g); | |
836 | ||
837 | theCommands.Add("reset", | |
513d3443 | 838 | "reset name1 name2 ..., remove location", |
7fd59977 | 839 | __FILE__, |
840 | transform,g); | |
841 | ||
842 | theCommands.Add("tmove", | |
513d3443 | 843 | "tmove name1 name2 ... name, set location from name", |
7fd59977 | 844 | __FILE__, |
845 | transform,g); | |
846 | ||
847 | theCommands.Add("ttranslate", | |
513d3443 | 848 | "ttranslate name1 name2 ... dx dy dz", |
7fd59977 | 849 | __FILE__, |
850 | transform,g); | |
851 | ||
513d3443 | 852 | theCommands.Add("trotate", |
853 | "trotate name1 name2 ... x y z dx dy dz angle", | |
7fd59977 | 854 | __FILE__, |
855 | transform,g); | |
856 | ||
857 | theCommands.Add("tmirror", | |
858 | "tmirror name x y z dx dy dz", | |
859 | __FILE__, | |
860 | transform,g); | |
861 | ||
862 | theCommands.Add("tscale", | |
513d3443 | 863 | "tscale name x y z scale", |
7fd59977 | 864 | __FILE__, |
865 | transform,g); | |
866 | ||
867 | theCommands.Add("tcopy", | |
513d3443 | 868 | "tcopy [-n(ogeom)] name1 result1 [name2 result2 ...]", |
7fd59977 | 869 | __FILE__, |
870 | tcopy,g); | |
871 | ||
513d3443 | 872 | theCommands.Add("bmove", |
873 | "bmove name1 name2 ... name, set location from name", | |
874 | __FILE__, | |
875 | transform,g); | |
876 | ||
877 | theCommands.Add("btranslate", | |
878 | "btranslate name1 name2 ... dx dy dz", | |
879 | __FILE__, | |
880 | transform,g); | |
881 | ||
882 | theCommands.Add("brotate", | |
883 | "brotate name1 name2 ... x y z dx dy dz angle", | |
884 | __FILE__, | |
885 | transform,g); | |
886 | ||
887 | theCommands.Add("bmirror", | |
888 | "bmirror name x y z dx dy dz", | |
889 | __FILE__, | |
890 | transform,g); | |
891 | ||
892 | theCommands.Add("bscale", | |
893 | "bscale name x y z scale", | |
894 | __FILE__, | |
895 | transform,g); | |
896 | ||
7fd59977 | 897 | theCommands.Add("precision", |
898 | "precision [preci]", | |
899 | __FILE__, | |
900 | precision,g); | |
901 | ||
902 | theCommands.Add("mkedgecurve", | |
903 | "mkedgecurve name tolerance", | |
904 | __FILE__, | |
905 | mkedgecurve,g); | |
906 | ||
907 | theCommands.Add("fsameparameter", | |
0d969553 | 908 | "fsameparameter shapename [tol (default 1.e-7)], \nforce sameparameter on all edges of the shape", |
7fd59977 | 909 | __FILE__, |
910 | sameparameter,g); | |
911 | ||
912 | theCommands.Add("sameparameter", | |
913 | "sameparameter shapename [tol (default 1.e-7)]", | |
914 | __FILE__, | |
915 | sameparameter,g); | |
916 | ||
917 | theCommands.Add("updatetolerance", | |
918 | "updatetolerance myShape [param] \n if [param] is absent - not verify of face tolerance, else - perform it", | |
919 | __FILE__, | |
920 | updatetol,g); | |
921 | ||
922 | theCommands.Add("solidorientation", | |
923 | "orientsolid myClosedSolid", | |
924 | __FILE__, | |
925 | orientsolid,g); | |
926 | ||
9f6931fb | 927 | theCommands.Add("getcoords", |
928 | "getcoords vertex1 vertex 2... ; shows coords of input vertices", | |
929 | __FILE__, | |
930 | getcoords,g); | |
931 | ||
7fd59977 | 932 | theCommands.Add("bounding", |
933 | "bounding shape [ xmin ymin zmin xmax ymax zmax] ; draw bounds", | |
934 | __FILE__, | |
935 | bounding,g); | |
936 | ||
937 | theCommands.Add("boundingstr", | |
938 | "boundingstr shape [ xmin ymin zmin xmax ymax zmax] ; print bounding box", | |
939 | __FILE__, | |
940 | boundingstr,g); | |
941 | ||
942 | theCommands.Add("nurbsconvert", | |
943 | "nurbsconvert result name [result name]", | |
944 | __FILE__, | |
945 | nurbsconvert,g); | |
946 | ||
947 | theCommands.Add("deform", | |
948 | "deform newname name CoeffX CoeffY CoeffZ", | |
949 | __FILE__, | |
950 | deform,g); | |
951 | ||
952 | theCommands.Add("findplane", | |
953 | "findplane name planename ", | |
954 | __FILE__, | |
955 | findplane,g) ; | |
956 | ||
957 | theCommands.Add("maxtolerance", | |
958 | "maxtolerance shape ", | |
959 | __FILE__, | |
960 | maxtolerance,g) ; | |
961 | ||
962 | theCommands.Add("reperageshape", | |
963 | "reperage shape -> list of shape (result of interstion shape , line)", | |
964 | __FILE__, | |
965 | reperageshape,g) ; | |
966 | ||
967 | theCommands.Add("vecdc", | |
968 | "vecdc + Pointe double click ", | |
969 | __FILE__, | |
970 | vecdc,g) ; | |
971 | ||
972 | theCommands.Add("nproject","nproject pj e1 e2 e3 ... surf -g -d [dmax] [Tol [continuity [maxdeg [maxseg]]]", | |
973 | __FILE__, | |
974 | nproject,g); | |
975 | ||
976 | theCommands.Add("wexplo","wexplo wire [face] create WEDGE_i", | |
977 | __FILE__, | |
978 | wexplo,g); | |
86eff19e J |
979 | |
980 | theCommands.Add("scalexyz", | |
981 | "scalexyz res shape factor_x factor_y factor_z", | |
982 | __FILE__, | |
983 | scalexyz, g); | |
7fd59977 | 984 | } |