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> | |
ece3f950 | 41 | #include <Bnd_Box2d.hxx> |
7fd59977 | 42 | #include <TopExp_Explorer.hxx> |
43 | #include <TopoDS.hxx> | |
44 | #include <BRepTools_WireExplorer.hxx> | |
45 | ||
46 | #include <GCPnts_QuasiUniformAbscissa.hxx> | |
47 | #include <Geom2dAdaptor_Curve.hxx> | |
48 | #include <GeomAdaptor_Curve.hxx> | |
49 | #include <ProjLib_ComputeApproxOnPolarSurface.hxx> | |
50 | #include <DrawTrSurf.hxx> | |
c04c30b3 | 51 | #include <Geom_Plane.hxx> |
7fd59977 | 52 | |
53 | #include <Draw_Segment3D.hxx> | |
54 | #include <Draw_Marker3D.hxx> | |
55 | #include <Draw_MarkerShape.hxx> | |
56 | ||
7fd59977 | 57 | #include <stdio.h> |
58 | ||
59 | Standard_IMPORT Draw_Viewer dout; | |
60 | ||
61 | ||
62 | ||
63 | //======================================================================= | |
64 | // addpcurve | |
65 | //======================================================================= | |
66 | ||
67 | static Standard_Integer addpcurve(Draw_Interpretor& , Standard_Integer n, const char** a) | |
68 | { | |
69 | if(n < 4) return 1; | |
70 | TopoDS_Shape E = DBRep::Get(a[1]); | |
71 | if (E.IsNull()) return 1; | |
72 | Handle(Geom2d_Curve) PC = DrawTrSurf::GetCurve2d(a[2]); | |
73 | TopoDS_Shape F = DBRep::Get(a[3]); | |
74 | Standard_Real tol = 1.e-7; | |
75 | if (n > 4) { | |
91322f44 | 76 | tol = Draw::Atof(a[4]); |
7fd59977 | 77 | } |
78 | BRep_Builder BB; | |
79 | BB.UpdateEdge(TopoDS::Edge(E), PC, TopoDS::Face(F),tol); | |
80 | DBRep::Set(a[1], E); | |
81 | return 0; | |
82 | } | |
83 | ||
84 | ||
85 | //======================================================================= | |
86 | // transform | |
87 | //======================================================================= | |
88 | ||
867acdec | 89 | static Standard_Integer transform(Draw_Interpretor& ,Standard_Integer n,const char** a) |
7fd59977 | 90 | { |
91 | if (n <= 1) return 1; | |
92 | ||
93 | gp_Trsf T; | |
94 | Standard_Integer last = n; | |
513d3443 | 95 | const char* aName = a[0]; |
7fd59977 | 96 | |
513d3443 | 97 | Standard_Boolean isBasic = Standard_False; |
7fd59977 | 98 | |
513d3443 | 99 | if (!strcmp(aName,"reset")) { |
100 | } | |
101 | else { | |
102 | isBasic = (aName[0] == 'b'); | |
103 | aName++; | |
104 | ||
105 | if (!strcmp(aName,"move")) { | |
106 | if (n < 3) return 1; | |
107 | TopoDS_Shape SL = DBRep::Get(a[n-1]); | |
108 | if (SL.IsNull()) return 0; | |
109 | T = SL.Location().Transformation(); | |
110 | last = n-1; | |
111 | } | |
112 | else if (!strcmp(aName,"translate")) { | |
113 | if (n < 5) return 1; | |
114 | T.SetTranslation(gp_Vec(Draw::Atof(a[n-3]),Draw::Atof(a[n-2]),Draw::Atof(a[n-1]))); | |
115 | last = n-3; | |
116 | } | |
117 | else if (!strcmp(aName,"rotate")) { | |
118 | if (n < 9) return 1; | |
119 | T.SetRotation(gp_Ax1(gp_Pnt(Draw::Atof(a[n-7]),Draw::Atof(a[n-6]),Draw::Atof(a[n-5])), | |
120 | gp_Vec(Draw::Atof(a[n-4]),Draw::Atof(a[n-3]),Draw::Atof(a[n-2]))), | |
121 | Draw::Atof(a[n-1])* (M_PI / 180.0)); | |
122 | last = n-7; | |
123 | } | |
124 | else if (!strcmp(aName,"mirror")) { | |
125 | if (n < 8) return 1; | |
126 | T.SetMirror(gp_Ax2(gp_Pnt(Draw::Atof(a[n-6]),Draw::Atof(a[n-5]),Draw::Atof(a[n-4])), | |
127 | gp_Vec(Draw::Atof(a[n-3]),Draw::Atof(a[n-2]),Draw::Atof(a[n-1])))); | |
128 | last = n-6; | |
129 | } | |
130 | else if (!strcmp(aName,"scale")) { | |
131 | if (n < 6) return 1; | |
132 | T.SetScale(gp_Pnt(Draw::Atof(a[n-4]),Draw::Atof(a[n-3]),Draw::Atof(a[n-2])),Draw::Atof(a[n-1])); | |
133 | last = n-4; | |
134 | } | |
7fd59977 | 135 | } |
136 | ||
513d3443 | 137 | if (T.Form() == gp_Identity || isBasic) { |
138 | TopLoc_Location L(T); | |
7fd59977 | 139 | for (Standard_Integer i = 1; i < last; i++) { |
140 | TopoDS_Shape S = DBRep::Get(a[i]); | |
513d3443 | 141 | if (S.IsNull()) |
af65fb19 | 142 | { |
143 | std::cerr << "Error: " << a[i] << " is not a valid shape\n"; | |
144 | return 1; | |
145 | } | |
513d3443 | 146 | else |
147 | DBRep::Set(a[i],S.Located(L)); | |
7fd59977 | 148 | } |
149 | } | |
150 | else { | |
151 | BRepBuilderAPI_Transform trf(T); | |
152 | for (Standard_Integer i = 1; i < last; i++) { | |
153 | TopoDS_Shape S = DBRep::Get(a[i]); | |
154 | if (S.IsNull()) { | |
af65fb19 | 155 | std::cerr << "Error: " << a[i] << " is not a valid shape\n"; |
156 | return 1; | |
7fd59977 | 157 | } |
158 | else { | |
513d3443 | 159 | trf.Perform(S); |
160 | if (!trf.IsDone()) | |
161 | return 1; | |
162 | DBRep::Set(a[i],trf.Shape()); | |
7fd59977 | 163 | } |
164 | } | |
165 | } | |
166 | return 0; | |
167 | } | |
168 | ||
7fd59977 | 169 | ///======================================================================= |
170 | // gtransform | |
171 | //======================================================================= | |
172 | ||
173 | static Standard_Integer deform(Draw_Interpretor& di,Standard_Integer n,const char** a) | |
174 | { | |
175 | if (n <= 1) return 1; | |
176 | ||
177 | Standard_Integer last = n; | |
178 | ||
179 | gp_Trsf T; | |
180 | gp_GTrsf GT(T); | |
181 | ||
91322f44 | 182 | // gp_Mat rot(Draw::Atof(a[last-3]),0,0,0,Draw::Atof(a[last-2]),0,0,0,Draw::Atof(a[last-1])); |
183 | gp_Mat rot(Draw::Atof(a[3]),0,0,0,Draw::Atof(a[4]),0,0,0,Draw::Atof(a[5])); | |
7fd59977 | 184 | GT.SetVectorialPart(rot); |
185 | last -= 3; | |
186 | BRepBuilderAPI_GTransform gtrf(GT); | |
187 | BRepBuilderAPI_NurbsConvert nbscv; | |
188 | // for (Standard_Integer i = 1; i < last; i++) { | |
189 | // TopoDS_Shape S = DBRep::Get(a[i]); | |
190 | TopoDS_Shape S = DBRep::Get(a[2]); | |
191 | if (S.IsNull()) { | |
192 | //cout << a[2] << " is not a valid shape" << endl; | |
586db386 | 193 | di << a[2] << " is not a valid shape\n"; |
7fd59977 | 194 | } |
195 | else { | |
196 | gtrf.Perform(S); | |
197 | if (gtrf.IsDone()){ | |
198 | DBRep::Set(a[1],gtrf.Shape()); | |
199 | } | |
200 | else { | |
201 | return 1; | |
202 | } | |
203 | } | |
204 | ||
205 | return 0; | |
206 | } | |
207 | ||
208 | //======================================================================= | |
209 | // tcopy | |
210 | //======================================================================= | |
211 | ||
212 | static Standard_Integer tcopy(Draw_Interpretor& di,Standard_Integer n,const char** a) | |
213 | { | |
214 | Standard_Boolean copyGeom = Standard_True; | |
55e738d2 | 215 | Standard_Boolean copyMesh = Standard_False; |
7fd59977 | 216 | Standard_Integer iFirst = 1; // index of first shape argument |
217 | ||
55e738d2 | 218 | if (n > 1) |
7fd59977 | 219 | { |
55e738d2 | 220 | for (Standard_Integer i = 1; i <= 2; i++) |
221 | { | |
222 | if (a[i][0] != '-') | |
223 | break; | |
224 | if (a[i][1] == 'n') | |
225 | { | |
226 | copyGeom = Standard_False; | |
227 | iFirst++; | |
228 | } | |
229 | else if (a[i][1] == 'm') | |
230 | { | |
231 | copyMesh = Standard_True; | |
232 | iFirst++; | |
233 | } | |
234 | } | |
7fd59977 | 235 | } |
236 | ||
237 | if (n < 3 || (n - iFirst) % 2) { | |
55e738d2 | 238 | cout << "Use: " << a[0] << " [-n(ogeom)] [-m(esh)] shape1 copy1 [shape2 copy2 [...]]" << endl; |
239 | cout << "Option -n forbids copying of geometry (it will be shared)" << endl; | |
240 | cout << "Option -m forces copying of mesh (disabled by default)" << endl; | |
7fd59977 | 241 | return 1; |
242 | } | |
243 | ||
244 | BRepBuilderAPI_Copy cop; | |
245 | Standard_Integer nbPairs = (n - iFirst) / 2; | |
246 | for (Standard_Integer i=0; i < nbPairs; i++) { | |
55e738d2 | 247 | cop.Perform(DBRep::Get(a[i+iFirst]), copyGeom, copyMesh); |
7fd59977 | 248 | DBRep::Set(a[i+iFirst+1],cop.Shape()); |
249 | di << a[i+iFirst+1] << " "; | |
250 | } | |
251 | return 0; | |
252 | } | |
253 | ||
254 | ||
255 | //======================================================================= | |
256 | // NurbsConvert | |
257 | //======================================================================= | |
258 | ||
259 | static Standard_Integer nurbsconvert(Draw_Interpretor& di,Standard_Integer n,const char** a) | |
260 | { | |
261 | if (n < 3) return 1; | |
262 | if ((n-1)%2 != 0) return 1; | |
263 | BRepBuilderAPI_NurbsConvert nbscv; | |
264 | for (Standard_Integer i=0; i<(n-1)/2; i++) { | |
265 | TopoDS_Shape S = DBRep::Get(a[2*i+2]); | |
266 | if (S.IsNull()) { | |
267 | //cout << a[2*i+2] << " is not a valid shape" << endl; | |
586db386 | 268 | di << a[2*i+2] << " is not a valid shape\n"; |
7fd59977 | 269 | } |
270 | else { | |
271 | nbscv.Perform(S); | |
272 | if (nbscv.IsDone()){ | |
273 | DBRep::Set(a[2*i+1],nbscv.Shape()); | |
274 | } | |
275 | else { | |
276 | return 1; | |
277 | } | |
278 | } | |
279 | } | |
280 | ||
281 | return 0; | |
282 | ||
283 | } | |
284 | ||
285 | //======================================================================= | |
286 | // make a 3D edge curve | |
287 | //======================================================================= | |
288 | ||
289 | static Standard_Integer mkedgecurve (Draw_Interpretor& ,Standard_Integer n,const char** a) | |
290 | { | |
291 | ||
7fd59977 | 292 | if (n < 3) return 1; |
91322f44 | 293 | Standard_Real Tolerance = Draw::Atof(a[2]) ; |
7fd59977 | 294 | |
295 | TopoDS_Shape S = DBRep::Get(a[1]); | |
296 | ||
297 | if (S.IsNull()) return 1; | |
298 | ||
7fd59977 | 299 | BRepLib::BuildCurves3d(S, |
300 | Tolerance) ; | |
301 | return 0 ; | |
302 | } | |
303 | ||
304 | //======================================================================= | |
305 | // sameparameter | |
306 | //======================================================================= | |
307 | ||
b60e8432 | 308 | static Standard_Integer sameparameter(Draw_Interpretor& di,Standard_Integer n,const char** a) |
7fd59977 | 309 | { |
b60e8432 | 310 | if (n < 2) |
311 | { | |
312 | di << "Use sameparameter [result] shape [toler]\n"; | |
313 | di << "shape is an initial shape\n"; | |
314 | di << "result is a result shape. if skipped = > initial shape will be modified\n"; | |
315 | di << "toler is tolerance (default is 1.e-7)"; | |
316 | return 1; | |
317 | } | |
318 | Standard_Real aTol = 1.e-7; | |
7fd59977 | 319 | Standard_Boolean force = !strcmp(a[0],"fsameparameter"); |
7fd59977 | 320 | |
b60e8432 | 321 | Standard_Real aTol1 = Draw::Atof(a[n-1]); |
322 | Standard_Boolean IsUseTol = aTol1>0; | |
323 | if (IsUseTol) | |
324 | aTol = aTol1; | |
325 | ||
326 | TopoDS_Shape anInpS = DBRep::Get(IsUseTol ? a[n-2] : a[n-1]); | |
327 | if (anInpS.IsNull()) | |
328 | return 1; | |
329 | ||
330 | if ((n == 4 && IsUseTol) || (n == 3 && !IsUseTol)) | |
331 | { | |
332 | TopoDS_Shape aResultSh; | |
333 | BRepTools_ReShape aResh; | |
334 | BRepLib::SameParameter(anInpS,aResh,aTol,force); | |
335 | aResultSh = aResh.Apply(anInpS); | |
336 | DBRep::Set(a[1],aResultSh); | |
337 | } | |
338 | else | |
339 | { | |
340 | BRepLib::SameParameter(anInpS,aTol,force); | |
341 | DBRep::Set(a[1],anInpS); | |
342 | } | |
7fd59977 | 343 | |
7fd59977 | 344 | return 0; |
345 | } | |
346 | //======================================================================= | |
347 | //function : updatetol | |
348 | //purpose : | |
349 | //======================================================================= | |
b60e8432 | 350 | static Standard_Integer updatetol(Draw_Interpretor& di,Standard_Integer n,const char** a) |
7fd59977 | 351 | { |
b60e8432 | 352 | if (n < 2) |
353 | { | |
354 | di << "Use updatetololerance [result] shape [param]\n"; | |
355 | di << "shape is an initial shape\n"; | |
356 | di << "result is a result shape. if skipped = > initial shape will be modified\n"; | |
357 | di << "if [param] is absent - not verify of face tolerance, else - perform it"; | |
358 | return 1; | |
359 | } | |
360 | TopoDS_Shape aSh1 = DBRep::Get(a[n-1]); | |
361 | Standard_Boolean IsF = aSh1.IsNull(); | |
7fd59977 | 362 | |
b60e8432 | 363 | TopoDS_Shape anInpS = IsF ? DBRep::Get(a[n-2]) : aSh1; |
364 | if (anInpS.IsNull()) | |
365 | return 1; | |
7fd59977 | 366 | |
b60e8432 | 367 | if ((n == 4 && IsF) || (n == 3 && !IsF)) |
368 | { | |
369 | TopoDS_Shape aResultSh; | |
370 | BRepTools_ReShape aResh; | |
371 | BRepLib::UpdateTolerances(anInpS,aResh, IsF); | |
372 | aResultSh = aResh.Apply(anInpS); | |
373 | DBRep::Set(a[1],aResultSh); | |
374 | } | |
375 | else | |
376 | { | |
377 | BRepLib::UpdateTolerances(anInpS, IsF); | |
378 | DBRep::Set(a[1],anInpS); | |
379 | } | |
7fd59977 | 380 | |
b60e8432 | 381 | return 0; |
7fd59977 | 382 | } |
383 | ||
384 | //======================================================================= | |
385 | //function : OrienSolid | |
386 | //purpose : | |
387 | //======================================================================= | |
388 | static Standard_Integer orientsolid(Draw_Interpretor& ,Standard_Integer n,const char** a) | |
389 | { | |
390 | if (n < 2) return 1; | |
391 | ||
392 | TopoDS_Shape S = DBRep::Get(a[1]); | |
393 | if (S.IsNull()) return 1; | |
394 | if (S.ShapeType()!=TopAbs_SOLID) return 1; | |
395 | ||
396 | BRepLib::OrientClosedSolid(TopoDS::Solid(S)); | |
397 | ||
398 | DBRep::Set(a[1],S); | |
399 | return 0; | |
400 | ||
401 | } | |
402 | ||
403 | //======================================================================= | |
404 | //function : boundingstr | |
405 | //purpose : | |
406 | //======================================================================= | |
407 | static Standard_Integer boundingstr(Draw_Interpretor& di,Standard_Integer n,const char** a) | |
408 | { | |
409 | if (n < 2) return 1; | |
410 | TopoDS_Shape S = DBRep::Get(a[1]); | |
411 | if (S.IsNull()) return 1; | |
412 | Bnd_Box B; | |
413 | BRepBndLib::Add(S,B); | |
414 | Standard_Real axmin,aymin,azmin,axmax,aymax,azmax; | |
415 | B.Get(axmin,aymin,azmin,axmax,aymax,azmax); | |
416 | di << axmin<<" "<< aymin<<" "<< azmin<<" "<< axmax<<" "<< aymax<<" "<< azmax; | |
417 | if (n >= 8) { | |
418 | Draw::Set(a[2],axmin) ; | |
419 | Draw::Set(a[3],aymin) ; | |
420 | Draw::Set(a[4],azmin) ; | |
421 | Draw::Set(a[5],axmax) ; | |
422 | Draw::Set(a[6],aymax) ; | |
423 | Draw::Set(a[7],azmax) ; | |
424 | } | |
425 | return 0; | |
426 | } | |
427 | ||
9f6931fb | 428 | //======================================================================= |
429 | //function : getcoords | |
430 | //purpose : | |
431 | //======================================================================= | |
432 | static Standard_Integer getcoords(Draw_Interpretor& di,Standard_Integer n,const char** a) | |
433 | { | |
434 | if(n < 2) | |
435 | return 1; | |
436 | ||
437 | for (Standard_Integer i = 1; i < n; i++) | |
438 | { | |
439 | const TopoDS_Shape aShape = DBRep::Get (a[i]); | |
440 | ||
441 | if (aShape.IsNull()) | |
442 | continue; | |
443 | ||
444 | if (aShape.ShapeType() == TopAbs_VERTEX) | |
445 | { | |
446 | const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape); | |
447 | gp_Pnt aPnt = BRep_Tool::Pnt(aVertex); | |
448 | ||
449 | di << a[i] << " (x,y,z) : " << aPnt.X() << " " << aPnt.Y() << " " << aPnt.Z() << "\n"; | |
450 | } | |
451 | } | |
452 | ||
453 | return 0; | |
454 | } | |
455 | ||
7fd59977 | 456 | //======================================================================= |
457 | //function : bounding | |
458 | //purpose : | |
459 | //======================================================================= | |
460 | static Standard_Integer bounding(Draw_Interpretor& di,Standard_Integer n,const char** a) | |
461 | { | |
462 | if (n < 2) return 1; | |
463 | Standard_Real axmin,aymin,azmin,axmax,aymax,azmax; | |
464 | Bnd_Box B; Handle(Draw_Box) DB; | |
465 | ||
466 | if (n == 2) { | |
467 | TopoDS_Shape S = DBRep::Get(a[1]); | |
468 | if (S.IsNull()) return 1; | |
469 | BRepBndLib::Add(S,B); | |
470 | B.Get(axmin,aymin,azmin,axmax,aymax,azmax); | |
471 | DB = new Draw_Box(gp_Pnt(axmin,aymin,azmin),gp_Pnt(axmax,aymax,azmax),Draw_orange); | |
472 | dout<<DB; | |
473 | di << axmin<<" "<< aymin<<" "<< azmin<<" "<< axmax<<" "<< aymax<<" "<< azmax; | |
474 | } | |
475 | else if (n == 7) { | |
91322f44 | 476 | axmin=Draw::Atof(a[1]); |
477 | aymin=Draw::Atof(a[2]); | |
478 | azmin=Draw::Atof(a[3]); | |
479 | axmax=Draw::Atof(a[4]); | |
480 | aymax=Draw::Atof(a[5]); | |
481 | azmax=Draw::Atof(a[6]); | |
7fd59977 | 482 | DB = new Draw_Box(gp_Pnt(axmin,aymin,azmin),gp_Pnt(axmax,aymax,azmax),Draw_orange); |
483 | dout<<DB; | |
484 | } | |
485 | return 0; | |
486 | } | |
487 | //======================================================================= | |
3ba87fdb | 488 | //function : optbounding |
489 | //purpose : | |
490 | //======================================================================= | |
491 | static Standard_Integer optbounding(Draw_Interpretor& di,Standard_Integer n,const char** a) | |
492 | { | |
493 | if (n < 2) | |
494 | { | |
495 | di << "Usage: optbounding shape [usetri [usetol]]\n"; | |
496 | di << "usetri and usetol can be 0 or 1, by default usetri = 1, usetol = 0\n"; | |
497 | return 1; | |
498 | } | |
499 | Standard_Real axmin,aymin,azmin,axmax,aymax,azmax; | |
500 | Bnd_Box B; Handle(Draw_Box) DB; | |
501 | ||
502 | TopoDS_Shape S = DBRep::Get(a[1]); | |
503 | if (S.IsNull()) | |
504 | { | |
505 | di << "Null shape\n"; | |
506 | return 1; | |
507 | } | |
508 | Standard_Boolean useTri = Standard_True; | |
509 | Standard_Boolean useTol = Standard_False; | |
510 | if(n > 2 ) | |
511 | { | |
512 | Standard_Integer ii = atoi(a[2]); | |
513 | useTri = ii > 0; | |
514 | } | |
515 | if(n > 3 ) | |
516 | { | |
517 | Standard_Integer ii = atoi(a[3]); | |
518 | useTol = ii > 0; | |
519 | } | |
520 | BRepBndLib::AddOptimal(S, B, useTri, useTol); | |
521 | B.Get(axmin, aymin, azmin, axmax, aymax, azmax); | |
522 | DB = new Draw_Box(gp_Pnt(axmin,aymin,azmin),gp_Pnt(axmax,aymax,azmax),Draw_vert); | |
523 | dout<<DB; | |
524 | di << axmin<<" "<< aymin<<" "<< azmin<<" "<< axmax<<" "<< aymax<<" "<< azmax; | |
525 | return 0; | |
526 | } | |
527 | //======================================================================= | |
528 | //function : gbounding | |
529 | //purpose : | |
530 | //======================================================================= | |
531 | #include <GeomAdaptor_Surface.hxx> | |
532 | #include <BndLib_AddSurface.hxx> | |
533 | #include <BndLib_Add3dCurve.hxx> | |
ece3f950 | 534 | #include <BndLib_Add2dCurve.hxx> |
535 | #include <Draw_Segment2D.hxx> | |
3ba87fdb | 536 | static Standard_Integer gbounding(Draw_Interpretor& di,Standard_Integer n,const char** a) |
537 | { | |
ece3f950 | 538 | if (n != 2 && n != 3) |
3ba87fdb | 539 | { |
ece3f950 | 540 | di << "Usage: gbounding surf/curve/curve2d [-o] \n"; |
541 | di << "[-o] turn on Optimal mode ('off' by default) \n"; | |
3ba87fdb | 542 | return 1; |
543 | } | |
ece3f950 | 544 | else |
545 | { | |
546 | Standard_Boolean IsOptimal = Standard_False; | |
547 | if (n == 3 && !strcmp(a[2], "-o")) | |
548 | IsOptimal = Standard_True; | |
549 | ||
550 | Standard_Real axmin,aymin,azmin,axmax,aymax,azmax; | |
551 | Bnd_Box B; | |
552 | Bnd_Box2d B2d; | |
553 | Handle(Draw_Box) DB; | |
554 | Standard_Boolean Is3d = Standard_True; | |
3ba87fdb | 555 | Handle(Geom_Curve) C; |
556 | Handle(Geom_Surface) S; | |
ece3f950 | 557 | Handle_Geom2d_Curve C2d; |
3ba87fdb | 558 | S = DrawTrSurf::GetSurface(a[1]); |
ece3f950 | 559 | if (!S.IsNull()) |
3ba87fdb | 560 | { |
ece3f950 | 561 | //add surf |
562 | GeomAdaptor_Surface aGAS(S); | |
563 | if (IsOptimal) | |
564 | BndLib_AddSurface::AddOptimal(aGAS, Precision::Confusion(), B); | |
565 | else | |
566 | BndLib_AddSurface::Add(aGAS, Precision::Confusion(), B); | |
3ba87fdb | 567 | } |
ece3f950 | 568 | else |
3ba87fdb | 569 | { |
ece3f950 | 570 | C = DrawTrSurf::GetCurve(a[1]); |
571 | if (!C.IsNull()) | |
572 | { | |
573 | // add cur | |
574 | GeomAdaptor_Curve aGAC(C); | |
575 | if (IsOptimal) | |
576 | BndLib_Add3dCurve::AddOptimal(aGAC, Precision::Confusion(), B); | |
577 | else | |
578 | BndLib_Add3dCurve::Add(aGAC, Precision::Confusion(), B); | |
579 | } | |
580 | else | |
581 | { | |
582 | C2d = DrawTrSurf::GetCurve2d(a[1]); | |
583 | if (!C2d.IsNull()) | |
584 | { | |
585 | //add cur2d | |
586 | Is3d = Standard_False; | |
587 | if (IsOptimal) | |
588 | BndLib_Add2dCurve::AddOptimal(C2d, C2d->FirstParameter(), C2d->LastParameter(), Precision::Confusion(), B2d); | |
589 | else | |
590 | BndLib_Add2dCurve::Add(C2d, C2d->FirstParameter(), C2d->LastParameter(), Precision::Confusion(), B2d); | |
591 | } | |
592 | else | |
593 | { | |
594 | di << "Wrong argument \n"; | |
595 | return 1; | |
596 | } | |
597 | } | |
3ba87fdb | 598 | } |
ece3f950 | 599 | |
600 | if (Is3d) | |
3ba87fdb | 601 | { |
ece3f950 | 602 | B.Get(axmin,aymin,azmin,axmax,aymax,azmax); |
603 | DB = new Draw_Box(gp_Pnt(axmin,aymin,azmin),gp_Pnt(axmax,aymax,azmax),Draw_vert); | |
604 | dout<<DB; | |
605 | di << axmin<<" "<< aymin<<" "<< azmin<<" "<< axmax<<" "<< aymax<<" "<< azmax; | |
3ba87fdb | 606 | } |
607 | else | |
608 | { | |
ece3f950 | 609 | B2d.Get(axmin,aymin,axmax,aymax); |
610 | gp_Pnt2d p1(axmin, aymin); | |
611 | gp_Pnt2d p2(axmax, aymin); | |
612 | gp_Pnt2d p3(axmax, aymax); | |
613 | gp_Pnt2d p4(axmin, aymax); | |
614 | Draw_Segment2D* S1 = new Draw_Segment2D(p1, p2, Draw_vert); | |
615 | Draw_Segment2D* S2 = new Draw_Segment2D(p2, p3, Draw_vert); | |
616 | Draw_Segment2D* S3 = new Draw_Segment2D(p3, p4, Draw_vert); | |
617 | Draw_Segment2D* S4 = new Draw_Segment2D(p4, p1, Draw_vert); | |
618 | dout << S1 << S2 << S3 << S4; | |
619 | di << axmin<<" "<< aymin<<" "<< axmax<<" "<< aymax; | |
3ba87fdb | 620 | } |
3ba87fdb | 621 | } |
622 | return 0; | |
ece3f950 | 623 | } |
624 | ||
625 | //======================================================================= | |
7fd59977 | 626 | //function : findplane |
627 | //purpose : | |
628 | //======================================================================= | |
629 | static Standard_Integer findplane(Draw_Interpretor& di,Standard_Integer n,const char** a) | |
630 | { | |
631 | if (n < 3) return 1; | |
632 | TopoDS_Shape S = DBRep::Get(a[1]); | |
633 | if (S.IsNull()) return 1; | |
634 | Standard_Real tolerance = 1.0e-5 ; | |
635 | BRepBuilderAPI_FindPlane a_plane_finder(S, | |
636 | tolerance) ; | |
637 | if (a_plane_finder.Found()) { | |
638 | //cout << " a plane is found " ; | |
639 | di << " a plane is found \n"; | |
543a9964 | 640 | const Handle(Geom_Geometry)& aSurf = a_plane_finder.Plane(); // to avoid ambiguity |
641 | DrawTrSurf::Set(a[2],aSurf) ; | |
7fd59977 | 642 | } |
643 | return 0 ; | |
644 | } | |
645 | //======================================================================= | |
646 | //function : precision | |
647 | //purpose : | |
648 | //======================================================================= | |
649 | ||
650 | static Standard_Integer precision(Draw_Interpretor& di,Standard_Integer n,const char** a) | |
651 | { | |
652 | n--; | |
653 | ||
654 | if ( n == 0) { | |
655 | //cout << " Current Precision = " << BRepBuilderAPI::Precision() << endl; | |
656 | di << " Current Precision = " << BRepBuilderAPI::Precision() << "\n"; | |
657 | } | |
658 | else { | |
91322f44 | 659 | BRepBuilderAPI::Precision(Draw::Atof(a[1])); |
7fd59977 | 660 | } |
661 | return 0; | |
662 | } | |
663 | ||
664 | ||
665 | //======================================================================= | |
666 | //function : reperage shape (Int lin Shape) + pointe double click + maxtol | |
667 | //purpose : | |
668 | //======================================================================= | |
669 | #include <IntCurvesFace_ShapeIntersector.hxx> | |
670 | #include <gp_Lin.hxx> | |
671 | ||
672 | static Standard_Integer reperageshape(Draw_Interpretor& di, Standard_Integer narg , const char** a) | |
673 | { | |
674 | Standard_Integer details=0; | |
675 | if(narg<2) return 1; | |
676 | if(narg==3) details=1; | |
677 | const char *id1 = a[1]; | |
678 | TopoDS_Shape TheShape1 = DBRep::Get(id1); | |
679 | ||
680 | //cout << "Pick positions with button "<<endl; | |
586db386 | 681 | di << "Pick positions with button \n"; |
7fd59977 | 682 | Standard_Integer id,X,Y,b; |
683 | gp_Trsf T; | |
684 | gp_Pnt P1,P2; | |
685 | dout.Select(id,X,Y,b); | |
686 | ||
687 | dout.GetTrsf(id,T); | |
688 | T.Invert(); | |
689 | Standard_Real z = dout.Zoom(id); | |
690 | P2.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z, 0.0); | |
691 | P2.Transform(T); | |
692 | P1.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,-1.0); | |
693 | P1.Transform(T); | |
694 | ||
695 | ||
696 | gp_Ax1 Axe(P1,gp_Vec(P1,P2)); | |
697 | IntCurvesFace_ShapeIntersector Inter; | |
698 | Inter.Load(TheShape1,1e-7); | |
699 | ||
700 | Inter.Perform(Axe,-RealLast(),RealLast()); | |
701 | ||
702 | //cout<<"\n --> "; | |
703 | di <<"\n --> "; | |
704 | if(Inter.NbPnt()) { | |
705 | for(Standard_Integer i=1; i<=Inter.NbPnt(); i++) { | |
706 | Standard_Integer numface=1; | |
707 | TopExp_Explorer ExF; | |
708 | for(ExF.Init(TheShape1,TopAbs_FACE); | |
709 | ExF.More(); | |
710 | ExF.Next(),numface++) { | |
711 | TopoDS_Face Face=TopoDS::Face(ExF.Current()); | |
712 | if(Face.IsEqual(Inter.Face(i))) { | |
713 | //cout<<" "<<a[1]<<"_"<<numface; | |
714 | di<<" "<<a[1]<<"_"<<numface; | |
715 | continue; | |
716 | } | |
717 | } | |
718 | const gp_Pnt& P = Inter.Pnt(i); | |
719 | Standard_Real PMin = Inter.WParameter(i); | |
720 | if(details) { | |
721 | //cout<<" w:"<<PMin<<endl; | |
722 | di<<" w:"<<PMin<< "\n"; | |
723 | } | |
724 | if(Inter.Transition(i) == IntCurveSurface_In) { | |
725 | if(Inter.State(i) == TopAbs_IN) { | |
726 | Handle(Draw_Marker3D) p = new Draw_Marker3D(P, Draw_Square, Draw_rouge,2); | |
727 | dout << p; dout.Flush(); | |
728 | } | |
729 | else if(Inter.State(i) == TopAbs_ON) { | |
730 | Handle(Draw_Marker3D) p = new Draw_Marker3D(P, Draw_Square, Draw_vert,2); | |
731 | dout << p; dout.Flush(); | |
732 | } | |
733 | } | |
734 | else { | |
735 | if(Inter.Transition(i) == IntCurveSurface_Out) { | |
736 | if(Inter.State(i) == TopAbs_IN) { | |
737 | Handle(Draw_Marker3D) p = new Draw_Marker3D(P, Draw_X, Draw_rouge,2); | |
738 | dout << p; dout.Flush(); | |
739 | } | |
740 | else if(Inter.State(i) == TopAbs_ON) { | |
741 | Handle(Draw_Marker3D) p = new Draw_Marker3D(P, Draw_X, Draw_vert,2); | |
742 | dout << p; dout.Flush(); | |
743 | } | |
744 | } | |
745 | } | |
746 | } | |
747 | } | |
748 | //cout<<endl; | |
749 | di << "\n"; | |
750 | return(0); | |
751 | } | |
752 | ||
753 | ||
754 | static Standard_Integer maxtolerance(Draw_Interpretor& theCommands, | |
755 | Standard_Integer n, const char** a) { | |
756 | if(n<2) return(1); | |
757 | TopoDS_Shape TheShape = DBRep::Get(a[1]); | |
758 | if(TheShape.IsNull()) return(1); | |
759 | ||
760 | Standard_Real T,TMF,TME,TMV,TmF,TmE,TmV; | |
761 | Standard_Integer nbF,nbE,nbV; | |
762 | TMF=TME=TMV=-RealLast(); | |
763 | TmF=TmE=TmV=RealLast(); | |
581971fe | 764 | |
765 | TopTools_MapOfShape mapS; | |
766 | mapS.Clear(); | |
7fd59977 | 767 | |
581971fe | 768 | for(TopExp_Explorer ex(TheShape,TopAbs_FACE); |
769 | ex.More(); | |
770 | ex.Next()) { | |
771 | TopoDS_Face Face=TopoDS::Face(ex.Current()); | |
7fd59977 | 772 | T=BRep_Tool::Tolerance(Face); |
773 | if(T>TMF) TMF=T; | |
774 | if(T<TmF) TmF=T; | |
581971fe | 775 | mapS.Add(Face); |
7fd59977 | 776 | } |
581971fe | 777 | |
778 | nbF = mapS.Extent(); | |
779 | mapS.Clear(); | |
780 | ||
781 | for(TopExp_Explorer ex(TheShape,TopAbs_EDGE); | |
782 | ex.More(); | |
783 | ex.Next()) { | |
784 | TopoDS_Edge Edge=TopoDS::Edge(ex.Current()); | |
7fd59977 | 785 | T=BRep_Tool::Tolerance(Edge); |
786 | if(T>TME) TME=T; | |
787 | if(T<TmE) TmE=T; | |
581971fe | 788 | mapS.Add(Edge); |
7fd59977 | 789 | } |
581971fe | 790 | |
791 | nbE = mapS.Extent(); | |
792 | mapS.Clear(); | |
793 | ||
794 | for(TopExp_Explorer ex(TheShape,TopAbs_VERTEX); | |
795 | ex.More(); | |
796 | ex.Next()) { | |
797 | TopoDS_Vertex Vertex=TopoDS::Vertex(ex.Current()); | |
7fd59977 | 798 | T=BRep_Tool::Tolerance(Vertex); |
799 | if(T>TMV) TMV=T; | |
800 | if(T<TmV) TmV=T; | |
581971fe | 801 | mapS.Add(Vertex); |
7fd59977 | 802 | } |
7fd59977 | 803 | |
581971fe | 804 | nbV = mapS.Extent(); |
805 | ||
7fd59977 | 806 | Standard_SStream sss; |
807 | sss << "\n## Tolerances on the shape " << a[1] << " (nbFaces:" << nbF | |
808 | << " nbEdges:" << nbE << " nbVtx:" << nbV << ")\n" ; | |
809 | sss.precision(5); | |
810 | sss.setf(ios::scientific); | |
811 | if(TmF<=TMF) sss << "\n Face : Min " << setw(8) << TmF <<" Max " << setw(8) << TMF << " \n "; | |
812 | if(TmE<=TME) sss << "\n Edge : Min " << setw(8) << TmE <<" Max " << setw(8) << TME << " \n "; | |
813 | if(TmV<=TMV) sss << "\n Vertex : Min " << setw(8) << TmV <<" Max " << setw(8) << TMV << " \n "; | |
814 | theCommands << sss; | |
57c28b61 | 815 | |
581971fe | 816 | return 0; |
7fd59977 | 817 | } |
818 | ||
819 | ||
820 | static Standard_Integer vecdc(Draw_Interpretor& di,Standard_Integer ,const char** ) { | |
821 | //cout << "Pick positions with button "<<endl; | |
586db386 | 822 | di << "Pick positions with button \n"; |
7fd59977 | 823 | |
824 | Standard_Integer id,X,Y,b; | |
825 | gp_Trsf T; | |
826 | gp_Pnt P1,P2,PP1,PP2; | |
827 | ||
828 | //----------------------------------------------------------- | |
829 | dout.Select(id,X,Y,b); dout.GetTrsf(id,T); | |
830 | T.Invert(); | |
831 | Standard_Real z = dout.Zoom(id); | |
832 | P1.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0); | |
833 | P1.Transform(T); | |
834 | ||
835 | dout.Select(id,X,Y,b); dout.GetTrsf(id,T); | |
836 | T.Invert(); z = dout.Zoom(id); | |
837 | ||
838 | P2.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0); | |
839 | P2.Transform(T); | |
840 | Standard_Real xa,ya,za; | |
841 | if(Abs(P1.X())>Abs(P2.X())) xa = P1.X(); else xa = P2.X(); | |
842 | if(Abs(P1.Y())>Abs(P2.Y())) ya = P1.Y(); else ya = P2.Y(); | |
843 | if(Abs(P1.Z())>Abs(P2.Z())) za = P1.Z(); else za = P2.Z(); | |
844 | P1.SetCoord(xa,ya,za); | |
845 | Handle(Draw_Marker3D) D0 = new Draw_Marker3D(gp_Pnt(P1.X(), | |
846 | P1.Y(), | |
847 | P1.Z()), | |
848 | Draw_Square,Draw_blanc,1); | |
849 | ||
850 | dout << D0; | |
851 | dout.Flush(); | |
852 | //----------------------------------------------------------- | |
853 | dout.Select(id,X,Y,b); | |
854 | dout.GetTrsf(id,T); | |
855 | T.Invert(); | |
856 | z = dout.Zoom(id); | |
857 | PP1.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0); | |
858 | PP1.Transform(T); | |
859 | dout.Select(id,X,Y,b); | |
860 | dout.GetTrsf(id,T); | |
861 | T.Invert(); | |
862 | z = dout.Zoom(id); | |
863 | PP2.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0); | |
864 | PP2.Transform(T); | |
865 | if(Abs(PP1.X())>Abs(PP2.X())) xa = PP1.X(); else xa = PP2.X(); | |
866 | if(Abs(PP1.Y())>Abs(PP2.Y())) ya = PP1.Y(); else ya = PP2.Y(); | |
867 | if(Abs(PP1.Z())>Abs(PP2.Z())) za = PP1.Z(); else za = PP2.Z(); | |
868 | PP1.SetCoord(xa,ya,za); | |
869 | Handle(Draw_Segment3D) d = new Draw_Segment3D(P1,PP1,Draw_blanc); | |
870 | dout << d; | |
871 | dout.Flush(); | |
872 | //cout<<"\nttran "<<PP1.X()-P1.X()<<" "<<PP1.Y()-P1.Y()<<" "<<PP1.Z()-P1.Z()<<endl; | |
873 | di <<"\nttran "<<PP1.X()-P1.X()<<" "<<PP1.Y()-P1.Y()<<" "<<PP1.Z()-P1.Z()<< "\n"; | |
874 | ||
875 | static Standard_Integer nboxvecdp=0; | |
876 | //cout<<"\nbox b"<<++nboxvecdp<<" "<<Min(P1.X(),PP1.X())<<" "<<Min(P1.Y(),PP1.Y())<<" "<<Min(PP1.Z(),P1.Z()); | |
877 | //cout<<" "<<Abs(PP1.X()-P1.X())<<" "<<Abs(PP1.Y()-P1.Y())<<" "<<Abs(PP1.Z()-P1.Z())<<endl; | |
878 | ||
879 | //cout<<"\nDistance :"<<sqrt( (PP1.X()-P1.X())*(PP1.X()-P1.X()) | |
880 | // +(PP1.Y()-P1.Y())*(PP1.Y()-P1.Y()) | |
881 | // +(PP1.Z()-P1.Z())*(PP1.Z()-P1.Z()))<<endl; | |
882 | ||
883 | di <<"\nbox b"<<++nboxvecdp<<" "<<Min(P1.X(),PP1.X())<<" "<<Min(P1.Y(),PP1.Y())<<" "<<Min(PP1.Z(),P1.Z()); | |
884 | di <<" "<<Abs(PP1.X()-P1.X())<<" "<<Abs(PP1.Y()-P1.Y())<<" "<<Abs(PP1.Z()-P1.Z())<< "\n"; | |
885 | ||
886 | di <<"\nDistance :"<<sqrt( (PP1.X()-P1.X())*(PP1.X()-P1.X()) | |
887 | +(PP1.Y()-P1.Y())*(PP1.Y()-P1.Y()) | |
888 | +(PP1.Z()-P1.Z())*(PP1.Z()-P1.Z()))<< "\n"; | |
889 | return(0); | |
890 | } | |
891 | //======================================================================= | |
892 | // nproject | |
893 | //======================================================================= | |
894 | ||
895 | #include <TopTools_SequenceOfShape.hxx> | |
896 | static Standard_Integer nproject(Draw_Interpretor& di, Standard_Integer n, const char** a) | |
897 | { | |
898 | if ( n < 4) return 1; | |
899 | TopoDS_Shape InpShape; | |
900 | Standard_Integer arg = 2, i; | |
901 | TopTools_SequenceOfShape Args; | |
902 | ||
903 | Standard_Real Tol = 1.e-4; | |
904 | Standard_Real Tol2d; | |
905 | Standard_Real MaxDistance = 1.e-3; | |
906 | GeomAbs_Shape Continuity = GeomAbs_C2; | |
907 | Standard_Integer MaxDeg = 14; | |
908 | Standard_Integer MaxSeg = 16; | |
909 | ||
910 | while((n > arg) && !(InpShape = DBRep::Get(a[arg])).IsNull()){ | |
911 | Args.Append(InpShape); | |
912 | arg++; | |
913 | } | |
914 | if(Args.Length() < 2) return 1; | |
915 | ||
916 | BRepOffsetAPI_NormalProjection OrtProj(Args.Last()); | |
917 | ||
918 | for(i = 1; i < Args.Length(); i++) | |
919 | OrtProj.Add(Args(i)); | |
920 | ||
921 | if(n > arg) | |
922 | if (!strcmp(a[arg],"-g")) { | |
923 | OrtProj.SetLimit(Standard_False); | |
924 | arg++; | |
925 | } | |
926 | ||
927 | if(n > arg) | |
928 | if (!strcmp(a[arg],"-d")) { | |
929 | arg++; | |
930 | if(n > arg) | |
91322f44 | 931 | MaxDistance = Draw::Atof(a[arg++]); |
7fd59977 | 932 | OrtProj.SetMaxDistance(MaxDistance); |
933 | } | |
934 | if(n > arg) { | |
91322f44 | 935 | Tol = Max(Draw::Atof(a[arg++]),1.e-10); |
7fd59977 | 936 | } |
937 | ||
938 | if(n > arg) { | |
91322f44 | 939 | if (Draw::Atoi(a[arg]) == 0) Continuity = GeomAbs_C0; |
940 | else if (Draw::Atoi(a[arg]) == 1) Continuity = GeomAbs_C1; | |
7fd59977 | 941 | arg++; |
942 | } | |
943 | ||
944 | ||
945 | if(n > arg) { | |
91322f44 | 946 | MaxDeg = Draw::Atoi(a[arg++]); |
7fd59977 | 947 | if (MaxDeg<1 || MaxDeg>14) MaxDeg = 14; |
948 | } | |
949 | ||
91322f44 | 950 | if(n > arg) MaxSeg = Draw::Atoi(a[arg]); |
7fd59977 | 951 | |
952 | Tol2d = Pow(Tol, 2./3); | |
953 | ||
954 | OrtProj.SetParams(Tol, Tol2d, Continuity, MaxDeg, MaxSeg); | |
955 | OrtProj.Build(); | |
956 | TopTools_ListOfShape Wire; | |
957 | Standard_Boolean IsWire=OrtProj.BuildWire(Wire); | |
958 | if (IsWire) { | |
959 | //cout << " BuildWire OK " << endl; | |
586db386 | 960 | di << " BuildWire OK \n"; |
7fd59977 | 961 | } |
962 | DBRep::Set(a[1], OrtProj.Shape()); | |
963 | return 0; | |
964 | } | |
965 | ||
966 | //========================================================================== | |
967 | //function : wexplo | |
0d969553 | 968 | // exploration of a wire |
7fd59977 | 969 | //========================================================================== |
970 | static Standard_Integer wexplo (Draw_Interpretor&, | |
971 | Standard_Integer argc, const char** argv) | |
972 | { | |
973 | char name[100]; | |
974 | if (argc < 2) return 1; | |
975 | ||
976 | TopoDS_Shape C1 = DBRep::Get (argv[1],TopAbs_WIRE); | |
977 | TopoDS_Shape C2 ; | |
978 | ||
979 | if (argc > 2) C2 = DBRep::Get (argv[2],TopAbs_FACE); | |
980 | ||
981 | if (C1.IsNull()) return 1; | |
982 | ||
983 | BRepTools_WireExplorer we; | |
984 | if (C2.IsNull()) we.Init(TopoDS::Wire(C1)); | |
985 | else we.Init(TopoDS::Wire(C1),TopoDS::Face(C2)); | |
986 | ||
987 | Standard_Integer k = 1; | |
988 | while (we.More()) { | |
989 | TopoDS_Edge E = we.Current(); | |
91322f44 | 990 | Sprintf(name,"WEDGE_%d",k); |
7fd59977 | 991 | DBRep::Set(name,E); |
992 | we.Next(); | |
993 | k++; | |
994 | } | |
995 | ||
996 | return 0; | |
997 | } | |
998 | ||
35e08fe8 | 999 | static Standard_Integer scalexyz(Draw_Interpretor& /*di*/, Standard_Integer n, const char** a) |
86eff19e J |
1000 | { |
1001 | if (n < 6) return 1; | |
7fd59977 | 1002 | |
86eff19e J |
1003 | TopoDS_Shape aShapeBase = DBRep::Get(a[2]); |
1004 | if (aShapeBase.IsNull()) return 1; | |
1005 | ||
91322f44 | 1006 | Standard_Real aFactorX = Draw::Atof(a[3]); |
1007 | Standard_Real aFactorY = Draw::Atof(a[4]); | |
1008 | Standard_Real aFactorZ = Draw::Atof(a[5]); | |
86eff19e J |
1009 | |
1010 | gp_GTrsf aGTrsf; | |
1011 | gp_Mat rot (aFactorX, 0, 0, | |
1012 | 0, aFactorY, 0, | |
1013 | 0, 0, aFactorZ); | |
1014 | aGTrsf.SetVectorialPart(rot); | |
1015 | BRepBuilderAPI_GTransform aBRepGTrsf (aShapeBase, aGTrsf, Standard_False); | |
1016 | if (!aBRepGTrsf.IsDone()) | |
9775fa61 | 1017 | throw Standard_ConstructionError("Scaling not done"); |
86eff19e J |
1018 | TopoDS_Shape Result = aBRepGTrsf.Shape(); |
1019 | ||
1020 | DBRep::Set(a[1], Result); | |
1021 | return 0; | |
1022 | } | |
7fd59977 | 1023 | |
7868210d | 1024 | //======================================================================= |
1025 | //function : compareshapes | |
1026 | //purpose : | |
1027 | //======================================================================= | |
1028 | static Standard_Integer compareshapes(Draw_Interpretor& di, | |
1029 | Standard_Integer n, | |
1030 | const char** a) | |
1031 | { | |
1032 | if (n != 3) { | |
1033 | di << "Compare shapes. Usage: compare shape1 shape2\n"; | |
1034 | return 1; | |
1035 | } | |
1036 | // get shapes | |
1037 | TopoDS_Shape aS1 = DBRep::Get(a[1]); | |
1038 | TopoDS_Shape aS2 = DBRep::Get(a[2]); | |
1039 | // check shapes | |
1040 | if (aS1.IsNull() || aS2.IsNull()) { | |
1041 | di << "null shapes\n"; | |
1042 | return 0; | |
1043 | } | |
1044 | // compare shapes | |
1045 | if (aS1.IsSame(aS2)) { | |
1046 | di << "same shapes\n"; | |
1047 | if (aS1.IsEqual(aS2)) { | |
1048 | di << "equal shapes\n"; | |
1049 | } | |
1050 | } | |
1051 | else { | |
1052 | di << "shapes are not same\n"; | |
1053 | } | |
1054 | return 0; | |
1055 | } | |
1056 | ||
1057 | //======================================================================= | |
1058 | //function : issubshape | |
1059 | //purpose : | |
1060 | //======================================================================= | |
1061 | static Standard_Integer issubshape(Draw_Interpretor& di, | |
1062 | Standard_Integer n, | |
1063 | const char** a) | |
1064 | { | |
1065 | if (n != 3) { | |
1066 | di << "Check if the shape is sub-shape of other shape and get its index in the shape.\n"; | |
1067 | di << "Usage: issubshape subshape shape\n"; | |
1068 | return 1; | |
1069 | } | |
1070 | // get shapes | |
1071 | TopoDS_Shape aSubShape = DBRep::Get(a[1]); | |
1072 | TopoDS_Shape aShape = DBRep::Get(a[2]); | |
1073 | // check shapes | |
1074 | if (aSubShape.IsNull() || aShape.IsNull()) { | |
1075 | di << "null shapes\n"; | |
1076 | return 0; | |
1077 | } | |
1078 | // find index of the sub-shape in the shape | |
1079 | TopTools_MapOfShape aMShapes; | |
1080 | // try to find the SubShape in Shape | |
1081 | TopExp_Explorer anExp(aShape, aSubShape.ShapeType()); | |
1082 | for (; anExp.More(); anExp.Next()) { | |
1083 | const TopoDS_Shape& aSS = anExp.Current(); | |
1084 | if (aMShapes.Add(aSS)) { | |
1085 | if (aSS.IsSame(aSubShape)) { | |
1086 | break; | |
1087 | } | |
1088 | } | |
1089 | } | |
1090 | // | |
1091 | if (anExp.More()) { | |
1092 | di << a[1] << " is sub-shape of " << a[2] << ". Index in the shape: " << aMShapes.Extent() << ".\n"; | |
1093 | } | |
1094 | else { | |
1095 | di << a[1] << " is NOT sub-shape of " << a[2] << ".\n"; | |
1096 | } | |
1097 | // | |
1098 | return 0; | |
1099 | } | |
1100 | ||
7fd59977 | 1101 | void BRepTest::BasicCommands(Draw_Interpretor& theCommands) |
1102 | { | |
1103 | static Standard_Boolean done = Standard_False; | |
1104 | if (done) return; | |
1105 | done = Standard_True; | |
1106 | ||
1107 | DBRep::BasicCommands(theCommands); | |
1108 | ||
1109 | const char* g = "TOPOLOGY Basic shape commands"; | |
1110 | ||
1111 | theCommands.Add("addpcurve", | |
1112 | "addpcurve edge 2dcurve face [tol (default 1.e-7)]", | |
1113 | __FILE__, | |
1114 | addpcurve,g); | |
1115 | ||
1116 | theCommands.Add("reset", | |
513d3443 | 1117 | "reset name1 name2 ..., remove location", |
7fd59977 | 1118 | __FILE__, |
1119 | transform,g); | |
1120 | ||
1121 | theCommands.Add("tmove", | |
513d3443 | 1122 | "tmove name1 name2 ... name, set location from name", |
7fd59977 | 1123 | __FILE__, |
1124 | transform,g); | |
1125 | ||
1126 | theCommands.Add("ttranslate", | |
513d3443 | 1127 | "ttranslate name1 name2 ... dx dy dz", |
7fd59977 | 1128 | __FILE__, |
1129 | transform,g); | |
1130 | ||
513d3443 | 1131 | theCommands.Add("trotate", |
1132 | "trotate name1 name2 ... x y z dx dy dz angle", | |
7fd59977 | 1133 | __FILE__, |
1134 | transform,g); | |
1135 | ||
1136 | theCommands.Add("tmirror", | |
1137 | "tmirror name x y z dx dy dz", | |
1138 | __FILE__, | |
1139 | transform,g); | |
1140 | ||
1141 | theCommands.Add("tscale", | |
513d3443 | 1142 | "tscale name x y z scale", |
7fd59977 | 1143 | __FILE__, |
1144 | transform,g); | |
1145 | ||
1146 | theCommands.Add("tcopy", | |
55e738d2 | 1147 | "tcopy [-n(ogeom)] [-m(esh)] name1 result1 [name2 result2 ...]", |
7fd59977 | 1148 | __FILE__, |
1149 | tcopy,g); | |
1150 | ||
513d3443 | 1151 | theCommands.Add("bmove", |
1152 | "bmove name1 name2 ... name, set location from name", | |
1153 | __FILE__, | |
1154 | transform,g); | |
1155 | ||
1156 | theCommands.Add("btranslate", | |
1157 | "btranslate name1 name2 ... dx dy dz", | |
1158 | __FILE__, | |
1159 | transform,g); | |
1160 | ||
1161 | theCommands.Add("brotate", | |
1162 | "brotate name1 name2 ... x y z dx dy dz angle", | |
1163 | __FILE__, | |
1164 | transform,g); | |
1165 | ||
1166 | theCommands.Add("bmirror", | |
1167 | "bmirror name x y z dx dy dz", | |
1168 | __FILE__, | |
1169 | transform,g); | |
1170 | ||
1171 | theCommands.Add("bscale", | |
1172 | "bscale name x y z scale", | |
1173 | __FILE__, | |
1174 | transform,g); | |
1175 | ||
7fd59977 | 1176 | theCommands.Add("precision", |
1177 | "precision [preci]", | |
1178 | __FILE__, | |
1179 | precision,g); | |
1180 | ||
1181 | theCommands.Add("mkedgecurve", | |
1182 | "mkedgecurve name tolerance", | |
1183 | __FILE__, | |
1184 | mkedgecurve,g); | |
1185 | ||
1186 | theCommands.Add("fsameparameter", | |
0d969553 | 1187 | "fsameparameter shapename [tol (default 1.e-7)], \nforce sameparameter on all edges of the shape", |
7fd59977 | 1188 | __FILE__, |
1189 | sameparameter,g); | |
1190 | ||
1191 | theCommands.Add("sameparameter", | |
b60e8432 | 1192 | "sameparameter [result] shape [tol]", |
7fd59977 | 1193 | __FILE__, |
1194 | sameparameter,g); | |
1195 | ||
1196 | theCommands.Add("updatetolerance", | |
b60e8432 | 1197 | "updatetolerance [result] shape [param] \n if [param] is absent - not verify of face tolerance, else - perform it", |
7fd59977 | 1198 | __FILE__, |
1199 | updatetol,g); | |
1200 | ||
1201 | theCommands.Add("solidorientation", | |
1202 | "orientsolid myClosedSolid", | |
1203 | __FILE__, | |
1204 | orientsolid,g); | |
1205 | ||
9f6931fb | 1206 | theCommands.Add("getcoords", |
1207 | "getcoords vertex1 vertex 2... ; shows coords of input vertices", | |
1208 | __FILE__, | |
1209 | getcoords,g); | |
1210 | ||
7fd59977 | 1211 | theCommands.Add("bounding", |
1212 | "bounding shape [ xmin ymin zmin xmax ymax zmax] ; draw bounds", | |
1213 | __FILE__, | |
1214 | bounding,g); | |
1215 | ||
3ba87fdb | 1216 | theCommands.Add("optbounding", |
1217 | "optbounding shape [usetri (0/1) [usetol (0/1)]] ; ", | |
1218 | __FILE__, | |
1219 | optbounding,g); | |
1220 | // | |
1221 | theCommands.Add("gbounding", | |
ece3f950 | 1222 | "gbounding surf/curve/curve2d [-o] ", |
3ba87fdb | 1223 | __FILE__, |
1224 | gbounding,g); | |
1225 | ||
7fd59977 | 1226 | theCommands.Add("boundingstr", |
1227 | "boundingstr shape [ xmin ymin zmin xmax ymax zmax] ; print bounding box", | |
1228 | __FILE__, | |
1229 | boundingstr,g); | |
1230 | ||
1231 | theCommands.Add("nurbsconvert", | |
1232 | "nurbsconvert result name [result name]", | |
1233 | __FILE__, | |
1234 | nurbsconvert,g); | |
1235 | ||
1236 | theCommands.Add("deform", | |
1237 | "deform newname name CoeffX CoeffY CoeffZ", | |
1238 | __FILE__, | |
1239 | deform,g); | |
1240 | ||
1241 | theCommands.Add("findplane", | |
1242 | "findplane name planename ", | |
1243 | __FILE__, | |
1244 | findplane,g) ; | |
1245 | ||
1246 | theCommands.Add("maxtolerance", | |
1247 | "maxtolerance shape ", | |
1248 | __FILE__, | |
1249 | maxtolerance,g) ; | |
1250 | ||
1251 | theCommands.Add("reperageshape", | |
1252 | "reperage shape -> list of shape (result of interstion shape , line)", | |
1253 | __FILE__, | |
1254 | reperageshape,g) ; | |
1255 | ||
1256 | theCommands.Add("vecdc", | |
1257 | "vecdc + Pointe double click ", | |
1258 | __FILE__, | |
1259 | vecdc,g) ; | |
1260 | ||
1261 | theCommands.Add("nproject","nproject pj e1 e2 e3 ... surf -g -d [dmax] [Tol [continuity [maxdeg [maxseg]]]", | |
1262 | __FILE__, | |
1263 | nproject,g); | |
1264 | ||
1265 | theCommands.Add("wexplo","wexplo wire [face] create WEDGE_i", | |
1266 | __FILE__, | |
1267 | wexplo,g); | |
86eff19e J |
1268 | |
1269 | theCommands.Add("scalexyz", | |
1270 | "scalexyz res shape factor_x factor_y factor_z", | |
1271 | __FILE__, | |
1272 | scalexyz, g); | |
7868210d | 1273 | |
1274 | theCommands.Add("compare", | |
1275 | "Compare shapes. Usage: compare shape1 shape2", | |
1276 | __FILE__, | |
1277 | compareshapes, g); | |
1278 | ||
1279 | theCommands.Add("issubshape", | |
1280 | "issubshape subshape shape\n" | |
1281 | "\t\tCheck if the shape is sub-shape of other shape and get its index in the shape.", | |
1282 | __FILE__, | |
1283 | issubshape, g); | |
7fd59977 | 1284 | } |