0022627: Change OCCT memory management defaults
[occt.git] / src / SWDRAW / SWDRAW_ShapeUpgrade.cxx
CommitLineData
7fd59977 1// File: SWDRAW_ShapeUpgrade.cxx
2// Created: Tue Mar 9 15:49:27 1999
3// Author: data exchange team
4// <det@kinox.nnov.matra-dtv.fr>
5//gka,rln 30.04.99 S4137: new commands for testing ShapeDivide added, some removed
6//abv,pdn 05.05.99 S4174: new commands for testing ShapeDivide added, some removed
7//pdn,gka 10.06.99 S4189: command DT_ShapeConvertRev added
8
9#include <SWDRAW_ShapeUpgrade.ixx>
10
11#include <DBRep.hxx>
12#include <ShapeUpgrade.hxx>
13#include <ShapeUpgrade_SplitCurve3dContinuity.hxx>
14#include <ShapeUpgrade_SplitCurve2dContinuity.hxx>
15#include <ShapeUpgrade_SplitSurfaceContinuity.hxx>
16//#include <ShapeUpgrade_SupportModification.hxx>
17#include <Draw_Interpretor.hxx>
18#include <DrawTrSurf.hxx>
19#include <Geom_Curve.hxx>
20#include <Geom_Plane.hxx>
21#include <Geom_Surface.hxx>
22#include <Geom2d_Curve.hxx>
23#include <TColGeom_HArray1OfCurve.hxx>
24#include <TColGeom_HArray2OfSurface.hxx>
25#include <TColStd_Array1OfReal.hxx>
26#include <TColStd_HArray1OfReal.hxx>
27#include <TColStd_HSequenceOfReal.hxx>
28#include <TopoDS.hxx>
29#include <TopoDS_Edge.hxx>
30#include <TopoDS_Face.hxx>
31#include <TopoDS_Shape.hxx>
32#include <TopoDS_Shell.hxx>
33#include <TopoDS_Wire.hxx>
34#include <TopoDS_Compound.hxx>
35#include <TopExp_Explorer.hxx>
36#include <TColGeom_HArray2OfSurface.hxx>
37#include <TColGeom2d_HArray1OfCurve.hxx>
38#include <BRepBuilderAPI.hxx>
39#include <SWDRAW.hxx>
40#include <ShapeUpgrade_ShapeDivideArea.hxx>
41
42#include <stdio.h>
43//#include <ShapeExtend_WireData.hxx>
44//#include <ShapeAnalysis_Shell.hxx>
45//#include <ShapeAnalysis_WireOrder.hxx>
46//#include <ShapeAnalysis_Wire.hxx>
47//#include <ShapeUpgrade_ShellSewing.hxx>
48#include <Geom2d_Curve.hxx>
49#include <Geom2d_OffsetCurve.hxx>
50#include <Geom_OffsetCurve.hxx>
51#include <ShapeUpgrade_SplitCurve3dContinuity.hxx>
52#include <TopoDS_Iterator.hxx>
53#include <BRep_Tool.hxx>
54#include <ShapeExtend_CompositeSurface.hxx>
55#include <Geom_RectangularTrimmedSurface.hxx>
56#include <TColGeom_HArray2OfSurface.hxx>
57#include <ShapeFix_ComposeShell.hxx>
58#include <Precision.hxx>
59#include <ShapeBuild_ReShape.hxx>
60#include <BRepTools.hxx>
61#include <ShapeFix.hxx>
62#include <ShapeUpgrade_ShapeDivideContinuity.hxx>
63#include <ShapeUpgrade_ShapeDivideAngle.hxx>
64#include <ShapeUpgrade_ShapeConvertToBezier.hxx>
65#include <ShapeCustom.hxx>
66#include <ShapeUpgrade_ShapeDivideClosed.hxx>
67#include <ShapeUpgrade_RemoveInternalWires.hxx>
982a90fc
G
68#include <ShapeUpgrade_RemoveLocations.hxx>
69#include <BRepBuilderAPI_Transform.hxx>
70
7fd59977 71// the plane (equation z=0) shared by PlaneDividedFaceContinuity and PlaneGridShell
72//static Handle(Geom_Plane) ThePlane= new Geom_Plane(0,0,1,0);
73
74
75//=======================================================================
76//function : DT_ShapeDivide
77//purpose :
78//=======================================================================
79
80static Standard_Integer DT_ShapeDivide (Draw_Interpretor& di,
81 Standard_Integer n, const char** a)
82{
83 // DT_ShapeDivide result Shape Tol
84 // a[1]= result
85 // a[2]= input Face/Surface
86 // a[3] si n>3= Wire/Face
87 // a[n-1]= Tolerance
88
89 if (n<3) {
90 di << "bad number of arguments" <<"\n";
91 return 1;
92 }
93
94 // try to read a shape:
95 TopoDS_Shape inputShape=DBRep::Get(a[2]);
96 if (inputShape.IsNull()) {
97 di << "Unknown shape"<< "\n";
98 return 1;
99 }
100 // a[2] is a shape. managing:
101 // DT_ShapeDivide result Face Tol
102
103 // giving a face is available only in the constructor:
104 // we make the whole and quit.
105 ShapeUpgrade_ShapeDivideContinuity tool(inputShape);
106
107 // tolerance is optional
108 if (n==4) {
109 Standard_Real Tol=atof(a[3]);
110 tool.SetTolerance(Tol);
111 }
112
113 // theTool.SetGlobalCriterion(GeomAbs_C1);
114 tool.Perform();
115 TopoDS_Shape res = tool.Result();
116
117 if ( tool.Status ( ShapeExtend_OK ) ) di << "Status: OK" << "\n";
118 if ( tool.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1" << "\n";
119 if ( tool.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2" << "\n";
120 if ( tool.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3" << "\n";
121 if ( tool.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4" << "\n";
122 if ( tool.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5" << "\n";
123 if ( tool.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6" << "\n";
124 if ( tool.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7" << "\n";
125 if ( tool.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8" << "\n";
126 if ( tool.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1" << "\n";
127 if ( tool.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2" << "\n";
128 if ( tool.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3" << "\n";
129 if ( tool.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4" << "\n";
130 if ( tool.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5" << "\n";
131 if ( tool.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6" << "\n";
132 if ( tool.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7" << "\n";
133 if ( tool.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8" << "\n";
134
135 // fixes
136
137 ShapeFix::SameParameter ( res, Standard_False );
138
139 DBRep::Set(a[1],res);
140 return 0;
141}
142
143static Standard_Integer DT_ShapeConvertRev (Draw_Interpretor& di,
144 Standard_Integer n, const char** a)
145{
146 if (n<5) {
147 di << "bad number of arguments" <<"\n";
148 return 1;
149 }
150
151 // try to read a shape:
152 TopoDS_Shape inputShape=DBRep::Get(a[2]);
153 if (inputShape.IsNull()) {
154 di << "Unknown shape"<< "\n";
155 return 1;
156 }
157
158 Standard_Integer c2d = atoi(a[3]);
159 Standard_Integer c3d = atoi(a[4]);
160 TopoDS_Shape revsh = ShapeCustom::ConvertToRevolution (inputShape);
161 if (revsh.IsNull()) { di<<"NO RESULT"<<"\n"; return 1; }
162 else if (revsh == inputShape) { di<<"No modif"<<"\n";}
163 else di<<"ConvertToRevolution -> Result : "<<"\n";
164
165 ShapeUpgrade_ShapeConvertToBezier tool(revsh);
166 tool.SetSurfaceConversion(Standard_True);
167 if(c2d)
168 tool.Set2dConversion(Standard_True);
169 if(c3d) {
170 tool.Set3dConversion(Standard_True);
171 if(n > 5)
172 tool.Set3dLineConversion(Standard_False);
173 if(n > 6)
174 tool.Set3dCircleConversion(Standard_False);
175 if(n > 7)
176 tool.Set3dConicConversion(Standard_False);
177 }
178 tool.Perform();
179 TopoDS_Shape res = tool.Result();
180
181 if ( tool.Status ( ShapeExtend_OK ) ) di << "Status: OK" << "\n";
182 if ( tool.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1" << "\n";
183 if ( tool.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2" << "\n";
184 if ( tool.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3" << "\n";
185 if ( tool.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4" << "\n";
186 if ( tool.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5" << "\n";
187 if ( tool.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6" << "\n";
188 if ( tool.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7" << "\n";
189 if ( tool.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8" << "\n";
190 if ( tool.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1" << "\n";
191 if ( tool.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2" << "\n";
192 if ( tool.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3" << "\n";
193 if ( tool.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4" << "\n";
194 if ( tool.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5" << "\n";
195 if ( tool.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6" << "\n";
196 if ( tool.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7" << "\n";
197 if ( tool.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8" << "\n";
198
199 // fixes
200
201 ShapeFix::SameParameter ( res, Standard_False );
202
203 DBRep::Set(a[1],res);
204 return 0;
205}
206
207
208/*
209 if (!inputShape.IsNull()) {
210 // a[2] is a shape. managing:
211 // DT_ShapeDivide result Face Tol
212
213 TopoDS_Face inputFace = TopoDS::Face(inputShape);
214 if (inputFace.IsNull()) {
215 di << a[2] << " is not a face" << "\n";
216 return 1;
217 }
218
219 // giving a face is available only in the constructor:
220 // we make the whole and quit.
221 ShapeUpgrade_ShapeDivideContinuity theTool(inputFace);
222
223 // tolerance is optional
224 if (n==4) {
225 Standard_Real Tol=atof(a[n-1]);
226 theTool.SetTolerance(Tol);
227 }
228
229 theTool.SetGlobalCriterion(GeomAbs_C1);
230 theTool.Build();
231 if (!theTool.IsDone()) {
232 ShapeUpgrade_Error theError=theTool.Error();
233 di << "Not done: error=";
234 if (theError==ShapeUpgrade_Done)
235 di << "Done"<<"\n";
236 else if (theError==ShapeUpgrade_NotDone)
237 di << "NotDone"<<"\n";
238 else if (theError==ShapeUpgrade_EmptyShell)
239 di << "EmptyShell"<<"\n";
240 else if (theError==ShapeUpgrade_InvalidCriterion)
241 di << "InvalidCriterion"<<"\n";
242 else if (theError==ShapeUpgrade_InvalidGridSurface)
243 di << "InvalidGridSurface"<<"\n";
244 else if (theError==ShapeUpgrade_DegeneratedEdge)
245 di << "DegeneratedEdge"<<"\n";
246 else if (theError==ShapeUpgrade_NoSurface)
247 di << "NoSurface"<<"\n";
248 else if (theError==ShapeUpgrade_NoTolerance)
249 di << "NoTolerance"<<"\n";
250 return 1;
251 }
252 TopoDS_Shell res = theTool.Shell();
253 DBRep::Set(a[1],res);
254
255 return 0;
256 }
257 else {
258 // not a face: we can use the empty consturctor.
259 ShapeUpgrade_ShapeDivideContinuity theTool;
260 Standard_Real Tol=atof(a[n-1]);
261 theTool.SetTolerance(Tol);
262 theTool.SetGlobalCriterion(GeomAbs_C1);
263
264 // try to read a surface:
265 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[2]);
266 if (! GS.IsNull()) {
267 // a[2] is a surface. managing the configurations:
268 // DT_ShapeDivide result Surface Tol
269 // DT_ShapeDivide result Surface Face Tol
270 // DT_ShapeDivide result Surface Wire Surf Tol
271
272 theTool.SetSupport(GS);
273
274 // try to read a Wire or a Face:
275 if (n>=5) {
276 TopoDS_Shape inputBoundary=DBRep::Get(a[3]);
277 if (inputBoundary.IsNull()) {
278 di << "Invalid Boundary" << "\n";
279 return 1;
280 }
281 TopoDS_Wire WireBoundary = TopoDS::Wire(inputBoundary);
282 if (!WireBoundary.IsNull()) {
283 // DT_ShapeDivide result Surface Wire Surf Tol
284 Handle(Geom_Surface) WireSupport = DrawTrSurf::GetSurface(a[4]);
285 if (WireSupport.IsNull()) {
286 di << "Invalid Surface supporting the Wire" << "\n";
287 return 1;
288 }
289 theTool.SetBoundary(WireBoundary, WireSupport);
290 }
291 else {
292 TopoDS_Face FaceBoundary = TopoDS::Face(inputBoundary);
293 // DT_ShapeDivide result Surface Face Tol
294 theTool.SetBoundary(FaceBoundary);
295 }
296 }
297 }
298 else {
299 // it must be a grid: managing the configurations:
300 // DT_ShapeDivide result NbU NbV {Surf_u_v...} Tol
301 // DT_ShapeDivide result NbU NbV {Surf_u_v...} Face Tol
302 // DT_ShapeDivide result NbU NbV {Surf_u_v...} Wire Surf Tol
303 if (n<6) {
304 di << "bad number of arguments for grid input" <<"\n";
305 return 1;
306 }
307 // number of surf:
308 Standard_Integer NbU=atoi(a[2]);
309 Standard_Integer NbV=atoi(a[3]);
310 if (n < 4+NbU*NbV+1) {
311 di << "bad number of arguments" <<"\n";
312 return 1;
313 }
314
315 Handle(TColGeom_HArray2OfSurface)
316 TheGridSurf= new TColGeom_HArray2OfSurface(1,NbU,1,NbV);
317
318 for (Standard_Integer iu=1; iu<=NbU; iu++) {
319 for (Standard_Integer jv=1; jv<=NbV; jv++) {
320 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[4+(iu-1)*NbV+jv-1]);
321 TheGridSurf->SetValue(iu,jv,GS);
322 }
323 }
324 theTool.SetSupport(TheGridSurf,Tol);
325
326 // try to read a Wire or a Face:
327 if (n>=6+NbU*NbV) {
328 TopoDS_Shape inputBoundary=DBRep::Get(a[4+NbU*NbV]);
329 if (inputBoundary.IsNull()) {
330 di << "Invalid Boundary" << "\n";
331 return 1;
332 }
333 TopoDS_Wire WireBoundary = TopoDS::Wire(inputBoundary);
334 if (!WireBoundary.IsNull()) {
335 // DT_ShapeDivide result Surface Wire Surf Tol
336 Handle(Geom_Surface) WireSupport = DrawTrSurf::GetSurface(a[4+NbU*NbV+1]);
337 if (WireSupport.IsNull()) {
338 di << "Invalid Surface supporting the Wire" << "\n";
339 return 1;
340 }
341 theTool.SetBoundary(WireBoundary, WireSupport);
342 }
343 else {
344 TopoDS_Face FaceBoundary = TopoDS::Face(inputBoundary);
345 // DT_ShapeDivide result Surface Face Tol
346 theTool.SetBoundary(FaceBoundary);
347 }
348 }
349 }
350
351 theTool.Build();
352 if (!theTool.IsDone()) {
353 ShapeUpgrade_Error theError=theTool.Error();
354 di << "Not done: error=";
355 if (theError==ShapeUpgrade_Done)
356 di << "Done"<<"\n";
357 else if (theError==ShapeUpgrade_NotDone)
358 di << "NotDone"<<"\n";
359 else if (theError==ShapeUpgrade_EmptyShell)
360 di << "EmptyShell"<<"\n";
361 else if (theError==ShapeUpgrade_InvalidCriterion)
362 di << "InvalidCriterion"<<"\n";
363 else if (theError==ShapeUpgrade_InvalidGridSurface)
364 di << "InvalidGridSurface"<<"\n";
365 else if (theError==ShapeUpgrade_DegeneratedEdge)
366 di << "DegeneratedEdge"<<"\n";
367 else if (theError==ShapeUpgrade_NoSurface)
368 di << "NoSurface"<<"\n";
369 else if (theError==ShapeUpgrade_NoTolerance)
370 di << "NoTolerance"<<"\n";
371 return 1;
372 }
373
374 TopoDS_Shell res = theTool.Shell();
375 DBRep::Set(a[1],res);
376
377 return 0;
378 }
379}
380*/
381static Standard_Integer DT_ShapeConvert (Draw_Interpretor& di,
382 Standard_Integer n, const char** a)
383{
384 if (n<5) {
385 di << "bad number of arguments" <<"\n";
386 return 1;
387 }
388
389 // try to read a shape:
390 TopoDS_Shape inputShape=DBRep::Get(a[2]);
391 if (inputShape.IsNull()) {
392 di << "Unknown shape"<< "\n";
393 return 1;
394 }
395
396 Standard_Integer c2d = atoi(a[3]);
397 Standard_Integer c3d = atoi(a[4]);
398
399 ShapeUpgrade_ShapeConvertToBezier tool(inputShape);
400 tool.SetSurfaceConversion(Standard_True);
401 if(c2d)
402 tool.Set2dConversion(Standard_True);
403 if(c3d)
404 tool.Set3dConversion(Standard_True);
405 tool.Perform();
406 TopoDS_Shape res = tool.Result();
407
408 if ( tool.Status ( ShapeExtend_OK ) ) di << "Status: OK" << "\n";
409 if ( tool.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1" << "\n";
410 if ( tool.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2" << "\n";
411 if ( tool.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3" << "\n";
412 if ( tool.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4" << "\n";
413 if ( tool.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5" << "\n";
414 if ( tool.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6" << "\n";
415 if ( tool.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7" << "\n";
416 if ( tool.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8" << "\n";
417 if ( tool.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1" << "\n";
418 if ( tool.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2" << "\n";
419 if ( tool.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3" << "\n";
420 if ( tool.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4" << "\n";
421 if ( tool.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5" << "\n";
422 if ( tool.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6" << "\n";
423 if ( tool.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7" << "\n";
424 if ( tool.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8" << "\n";
425
426 // fixes
427
428 ShapeFix::SameParameter ( res, Standard_False );
429
430 DBRep::Set(a[1],res);
431 return 0;
432}
433static Standard_Integer DT_SplitAngle(Draw_Interpretor& di,
434 Standard_Integer n, const char** a)
435{
436 if (n<3) {
437 di << "bad number of arguments" <<"\n";
438 return 1;
439 }
440
441 TopoDS_Shape inputShape=DBRep::Get(a[2]);
442 if (inputShape.IsNull()) {
443 di << "Unknown shape"<< "\n";
444 return 1;
445 }
446
447 Standard_Real maxangle = 95;
448 if ( n >3 ) {
449 maxangle = atof ( a[3] );
450 if ( maxangle <1 ) maxangle = 1;
451 }
452
982a90fc 453 ShapeUpgrade_ShapeDivideAngle tool(maxangle * M_PI/180,inputShape);
7fd59977 454 tool.Perform();
455 TopoDS_Shape res = tool.Result();
456
457 if ( tool.Status ( ShapeExtend_OK ) ) di << "Status: OK" << "\n";
458 if ( tool.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1" << "\n";
459 if ( tool.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2" << "\n";
460 if ( tool.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3" << "\n";
461 if ( tool.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4" << "\n";
462 if ( tool.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5" << "\n";
463 if ( tool.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6" << "\n";
464 if ( tool.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7" << "\n";
465 if ( tool.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8" << "\n";
466 if ( tool.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1" << "\n";
467 if ( tool.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2" << "\n";
468 if ( tool.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3" << "\n";
469 if ( tool.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4" << "\n";
470 if ( tool.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5" << "\n";
471 if ( tool.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6" << "\n";
472 if ( tool.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7" << "\n";
473 if ( tool.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8" << "\n";
474
475 // fixes
476
477 ShapeFix::SameParameter ( res, Standard_False );
478
479 DBRep::Set(a[1],res);
480 return 0;
481}
482
483/*
484//=======================================================================
485//function : DT_PlaneDividedFace
486//purpose : Transfer into a plane with boundary divided
487//
488//
489//=======================================================================
490static Standard_Integer DT_PlaneDividedFace (Draw_Interpretor& di,
491 Standard_Integer n, const char** a)
492
493{
494 // a[1]= result
495 // a[2]= input Face
496 // a[3]= Tolerance
497
498 if (n !=4) {
499 di << "bad number of arguments" <<"\n";
500 return 1;
501 }
502
503 Standard_Real Tol=atof(a[3]);
504 TopoDS_Shape inputShape=DBRep::Get(a[2]);
505 TopoDS_Face inputFace = TopoDS::Face(inputShape);
506 if (inputFace.IsNull()) {
507 di << a[2] << " is not a face" << "\n";
508 return 1;
509 }
510
511 ShapeUpgrade_PlaneDividedFace theTool(ThePlane);
512 theTool.Init(inputFace);
513 //theTool.SetBoundaryCriterion(GeomAbs_C1);
514 //theTool.SetTolerance(Tol);
515 theTool.Build();
516 if (!theTool.IsDone()) {
517 di << "Not done" << "\n";
518 return 1;
519 }
520
521 TopoDS_Face res = theTool.Face();
522 DBRep::Set(a[1],res);
523
524 Standard_Real the2d3dFactor=theTool.Get2d3dFactor();
525 di << "2d3dFactor="<<the2d3dFactor<< "\n";
526 return 0;
527}
528
529//=======================================================================
530//function : DT_PlaneGridShell
531//purpose : Create a Plane Grid Shell from U and V knots
532//
533//
534//=======================================================================
535static Standard_Integer DT_PlaneGridShell (Draw_Interpretor& di,
536 Standard_Integer n, const char** a)
537
538{
539
540 if (n < 4) return 1;
541 // a[1]= result
542 // a[2]= NbU >=2
543 // a[3]= NbV >=2
544 // a[4..]= {UKnots}
545 // a[4+NbU...] = {VKnots}
546 // a[4+NbU+NbV+1] = Tol
547
548 // number of knots:
549 Standard_Integer NbU=atoi(a[2]);
550 Standard_Integer NbV=atoi(a[3]);
551 if (n != 4+NbU+NbV+1) {
552 di << "bad number of arguments" <<"\n";
553 return 1;
554 }
555
556 TColStd_Array1OfReal TheUKnots(1,NbU);
557 TColStd_Array1OfReal TheVKnots(1,NbV);
558
559 for (Standard_Integer ii=1; ii<=NbU; ii++) {
560 TheUKnots(ii)=atof(a[4+ii-1]);
561 }
562 for (ii=1; ii<=NbV; ii++) {
563 TheVKnots(ii)=atof(a[4+NbU+ii-1]);
564 }
565
566 Standard_Real Tol=atof(a[4+NbU+NbV]);
567
568 ShapeUpgrade_PlaneGridShell TheGrid(ThePlane,TheUKnots,TheVKnots,Tol);
569
570 TopoDS_Shell res = TheGrid.Shell();
571 DBRep::Set(a[1],res);
572
573 return 0;
574}
575
576//=======================================================================
577//function : DT_PlaneFaceCommon
578//purpose : Common between a plane Face and a Shell whose all Faces are
579// laying in the same plane
580//
581//
582//=======================================================================
583static Standard_Integer DT_PlaneFaceCommon (Draw_Interpretor& di,
584 Standard_Integer n, const char** a)
585
586{
587 // a[1]= result
588 // a[2]= input Face
589 // a[3]= input Shell
590
591 if (n !=4) {
592 di << "bad number of arguments" <<"\n";
593 return 1;
594 }
595
596 TopoDS_Shape inputShape= DBRep::Get(a[2]);
597 TopoDS_Face inputFace = TopoDS::Face(inputShape);
598 if (inputFace.IsNull()) {
599 di << a[2] << " is not a face" << "\n";
600 return 1;
601 }
602
603 inputShape = DBRep::Get(a[3]);
604 TopoDS_Shell inputShell = TopoDS::Shell(inputShape);
605 if (inputShell.IsNull()) {
606 di << a[3] << " is not a shell" << "\n";
607 return 1;
608 }
609
610 ShapeUpgrade_PlaneFaceCommon theTool;
611 theTool.Init(inputFace,inputShell);
612
613 TopoDS_Shell res = theTool.Shell();
614 DBRep::Set(a[1],res);
615
616 return 0;
617}*/
618
619//=======================================================================
620//function : DT_SplitCurve
621//purpose : Splits the curve with C1 criterion
622//
623//
624//=======================================================================
625static Standard_Integer DT_SplitCurve (Draw_Interpretor& di,
626 Standard_Integer n, const char** a)
627
628{
629 // a[1]= input curve. This name is used with a suffix to name the output curves
630 // a[2]= Tolerance
631
632 if (n < 3) {
633 di << "bad number of arguments" <<"\n";
634 return 1;
635 }
636
637 Standard_Real Tol=atof(a[2]);
638 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(a[1]);
639 if ( GC.IsNull()) return 1;
640 Standard_Integer Split = atoi(a[3]);
641 Handle(ShapeUpgrade_SplitCurve3dContinuity) theTool = new ShapeUpgrade_SplitCurve3dContinuity;
642 theTool->Init(GC);
643 theTool->SetTolerance (Tol);
644 theTool->SetCriterion (GeomAbs_C1);
645 if(Split == 1) {
646 Handle(TColStd_HSequenceOfReal) spval = new TColStd_HSequenceOfReal;
647 for(Standard_Integer i = 1; i<=5; i++) spval->Append(i);
648 theTool->SetSplitValues(spval);
649 }
650 theTool->Perform (Standard_True);
651 Handle(TColGeom_HArray1OfCurve) theCurves= theTool->GetCurves();
652 Standard_Integer NbC=theCurves->Length();
653 for (Standard_Integer icurv=1; icurv<=NbC; icurv++) {
654 char name[100];
655 sprintf(name,"%s%s%d",a[1],"_",icurv);
656 char* newname = name;
657 DrawTrSurf::Set(newname, theCurves->Value(icurv));
658 di.AppendElement(newname);
659 }
660 return 0;
661}
662
663
664//=======================================================================
665//function : DT_SplitCurve2d
666//purpose : Splits the curve with C1 criterion
667//
668//
669//=======================================================================
670static Standard_Integer DT_SplitCurve2d (Draw_Interpretor& di,
671 Standard_Integer n, const char** a)
672
673{
674 // a[1]= input 2d curve. This name is used with a suffix to name the output curves
675 // a[2]= Tolerance
676
677 if (n < 3) {
678 di << "bad number of arguments" <<"\n";
679 return 1;
680 }
681
682 Standard_Real Tol=atof(a[2]);
683 Handle(Geom2d_Curve) GC = DrawTrSurf::GetCurve2d(a[1]);
684 if ( GC.IsNull()) return 1;
685 Standard_Integer Split = atoi(a[3]);
686 Handle(ShapeUpgrade_SplitCurve2dContinuity) theTool = new ShapeUpgrade_SplitCurve2dContinuity;
687 theTool->Init(GC);
688 theTool->SetTolerance (Tol);
689 theTool->SetCriterion (GeomAbs_C1);
690 if(Split == 1) {
691 Handle(TColStd_HSequenceOfReal) spval = new TColStd_HSequenceOfReal;
692 for(Standard_Integer i = 1; i<=5; i++) spval->Append(i);
693 theTool->SetSplitValues(spval);
694 }
695 theTool->Perform (Standard_True);
696 Handle(TColGeom2d_HArray1OfCurve) theCurves= theTool->GetCurves();
697 Standard_Integer NbC=theCurves->Length();
698 for (Standard_Integer icurv=1; icurv<=NbC; icurv++) {
699 char name[100];
700 sprintf(name,"%s%s%d",a[1],"_",icurv);
701 char* newname = name;
702 DrawTrSurf::Set(newname, theCurves->Value(icurv));
703 di.AppendElement(newname);
704 }
705 return 0;
706}
707
708
709//=======================================================================
710//function : DT_SplitSurface
711//purpose : Splits the surface with C1 criterion
712//
713//
714//=======================================================================
715/*
716static Standard_Integer DT_SplitWire (Draw_Interpretor& di,
717 Standard_Integer n, const char** a)
718{
719
720 if (n <3) {
721 di << "bad number of arguments" <<"\n";
722 return 1;
723 }
724
725 TopoDS_Face source = TopoDS::Face(DBRep::Get(a[2]));
726 if(source.IsNull()) {
727 di <<"Shape is not face"<<"\n";
728 return 1;
729 }
730 TopoDS_Iterator wi(source);
731 if(!wi.More()) {
732 di <<"Shape is face without wire"<<"\n";
733 return 1;
734 }
735
736 TopoDS_Wire wire = TopoDS::Wire(wi.Value());
737 Handle(ShapeUpgrade_WireDivideContinuity) tool = new ShapeUpgrade_WireDivideContinuity;
738 tool->Init(wire,source);
739 if(n >=4 ) {
740 Standard_Real Tol=atof(a[3]);
741 }
742 Handle(ShapeBuild_ReShape) context = new ShapeBuild_ReShape;
743 tool->Perform(context);
744 TopoDS_Wire result = tool->Wire();
745 DBRep::Set(a[1],result);
746 return 0;
747}
748*/
749/*
750static Standard_Integer DT_SplitFace (Draw_Interpretor& di,
751 Standard_Integer n, const char** a)
752{
753
754 if (n <3) {
755 di << "bad number of arguments" <<"\n";
756 return 1;
757 }
758
759 TopoDS_Face source = TopoDS::Face(DBRep::Get(a[2]));
760 if(source.IsNull()) {
761 di <<"Shape is not face"<<"\n";
762 return 1;
763 }
764 Handle(ShapeUpgrade_ShapeDivideContinuity) tool = new ShapeUpgrade_FaceDivideContinuity;
765 tool->Init(source);
766 if(n >=4 ) {
767 Standard_Real Tol=atof(a[3]);
768 tool->SetPrecision(Tol);
769 }
770
771 Handle(ShapeBuild_ReShape) context = new ShapeBuild_ReShape;
772 tool->Perform(context);
773 TopoDS_Shape result = tool->Result();
774
775
776 if ( tool->Status ( ShapeExtend_OK ) ) di << "Status: OK" << "\n";
777 if ( tool->Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1" << "\n";
778 if ( tool->Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2" << "\n";
779 if ( tool->Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3" << "\n";
780 if ( tool->Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4" << "\n";
781 if ( tool->Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5" << "\n";
782 if ( tool->Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6" << "\n";
783 if ( tool->Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7" << "\n";
784 if ( tool->Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8" << "\n";
785 if ( tool->Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1" << "\n";
786 if ( tool->Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2" << "\n";
787 if ( tool->Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3" << "\n";
788 if ( tool->Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4" << "\n";
789 if ( tool->Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5" << "\n";
790 if ( tool->Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6" << "\n";
791 if ( tool->Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7" << "\n";
792 if ( tool->Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8" << "\n";
793
794 // fixes
795
796 ShapeFix::SameParameter ( result, Standard_False );
797
798 DBRep::Set(a[1],result);
799 return 0;
800}
801*/
802
803static Standard_Integer DT_SplitSurface (Draw_Interpretor& di,
804 Standard_Integer n, const char** a)
805
806{
807 // a[1]= result (used with a suffix to name the output surfaces)
808 // a[2]= input surface.
809 // a[3]= Tolerance
810
811 // a[1]= result
812 // a[2]= nbU
813 // a[3]= nbV
814 // a[3+1]..a[3+nbU*nbV] = Input Surfaces
815 // a[4+nbU*nbV]= Tolerance
816
817 if (n <4) {
818 di << "bad number of arguments" <<"\n";
819 return 1;
820 }
821
822 Handle(ShapeUpgrade_SplitSurfaceContinuity) theTool = new ShapeUpgrade_SplitSurfaceContinuity;//S4137
823
824 Standard_Real Tol=atof(a[3]);
825 Standard_Integer Split = atoi(a[4]);
826 theTool->SetTolerance(Tol);
827 theTool->SetCriterion(GeomAbs_C1);
828 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[2]);
829/*
830 if ( GS.IsNull()) {
831 // Case of composite grid surface
832 di << "composite surf" << "\n";
833 Standard_Integer nbU=atoi(a[2]);
834 Standard_Integer nbV=atoi(a[3]);
835 if (nbU==0 || nbV==0) return 1;
836 Handle(TColGeom_HArray2OfSurface)
837 theGrid= new TColGeom_HArray2OfSurface(1,nbU,1,nbV);
838 for (Standard_Integer iu=1; iu<=nbU; iu++) {
839 for (Standard_Integer iv=1; iv<=nbV; iv++) {
840 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[3+(iu-1)*nbV+iv]);
841 theGrid->SetValue(iu,iv,GS);
842 }
843 }
844 di << "appel a SplitSurface::Init" << "\n";
845 theTool->Init(theGrid);
846 }
847 else {*/
848 // Case of single surface
849 di << "single surf" << "\n";
850
851 di << "appel a SplitSurface::Init" << "\n";
852 theTool->Init(GS);
853 if(Split ==1) {
854 Handle(TColStd_HSequenceOfReal) spval = new TColStd_HSequenceOfReal;
855 for(Standard_Integer i = 1; i<=5; i++) spval->Append(i);
856 theTool->SetUSplitValues(spval);
857 theTool->SetVSplitValues(spval);
858 }
859
860 di << "appel a SplitSurface::Build" << "\n";
861 theTool->Build(Standard_True);
862
863 di << "appel a SplitSurface::GlobalU/VKnots" << "\n";
864 Handle(ShapeExtend_CompositeSurface) Grid = theTool->ResSurfaces();
865 Handle(TColStd_HArray1OfReal) GlobalU=Grid->UJointValues();
866 Handle(TColStd_HArray1OfReal) GlobalV=Grid->VJointValues();
867 Standard_Integer nbGlU=GlobalU->Length();
868 Standard_Integer nbGlV=GlobalV->Length();
869 di << "nb GlobalU ; nb GlobalV="<<nbGlU<<" "<<nbGlV;
870 for (Standard_Integer iu=1; iu<=nbGlU; iu++)
871 di <<" "<< GlobalU->Value(iu);
872// di <<"\n";
873// di << "nb GlobalV="<<nbGlV;
874 for (Standard_Integer iv=1; iv<=nbGlV; iv++)
875 di <<" "<< GlobalV->Value(iv);
876 di <<"\n";
877
878di << "appel a Surfaces" << "\n";
879 Handle(TColGeom_HArray2OfSurface) theSurfaces= Grid->Patches();
880
881di << "transfert resultat" << "\n";
882 Standard_Integer NbRow=theSurfaces->ColLength();
883 Standard_Integer NbCol=theSurfaces->RowLength();
884 for (Standard_Integer irow=1; irow<=NbRow; irow++) {
885 for (Standard_Integer icol=1; icol<=NbCol; icol++) {
886 char name[100];
887 sprintf(name,"%s%s%d%s%d",a[1],"_",irow,"_",icol);
888 char* newname = name;
889 DrawTrSurf::Set(newname, theSurfaces->Value(irow, icol));
890 di.AppendElement(newname);
891 }
892 }
893 return 0;
894}
895
896
897
898//=======================================================================
899//function : DT_SupportModification
900//purpose : Changes the supports of a Shell
901// The given surface wil support all the faces of the new shell.
902// with the PCurves of the old ones.
903//
904//=======================================================================
905/*static Standard_Integer DT_SupportModification (Draw_Interpretor& di,
906 Standard_Integer n, const char** a)
907
908{
909 // a[1]= result
910 // a[2]= input Shell
911 // a[3]= new Surface
912 // a[4]= 2d3d Scale Factor
913
914 if (n !=5) {
915 di << "bad number of arguments" <<"\n";
916 return 1;
917 }
918
919 TopoDS_Shape inputShape= DBRep::Get(a[2]);
920 TopoDS_Shell inputShell = TopoDS::Shell(inputShape);
921 if (inputShell.IsNull()) {
922 di << a[2] << " is not a shell" << "\n";
923 return 1;
924 }
925
926 Handle(Geom_Surface) theSurf = DrawTrSurf::GetSurface(a[3]);
927 if ( theSurf.IsNull()) {
928 di << a[3] << " is not a surface" << "\n";
929 return 1;
930 }
931
932 ShapeUpgrade_DataMapOfShapeSurface theMap;
933 // Associates thesurf to each face of inputShell.
934 TopExp_Explorer ExpSh;
935 for (ExpSh.Init(inputShell,TopAbs_FACE); ExpSh.More(); ExpSh.Next()){
936 TopoDS_Face theFace= TopoDS::Face(ExpSh.Current());
937 theMap.Bind(theFace,theSurf);
938 }
939
940 Standard_Real the2d3dFactor=atof(a[4]);
941 ShapeUpgrade_SupportModification theTool(inputShell,theMap,the2d3dFactor);
942
943 TopoDS_Shell res = theTool.Shell();
944 DBRep::Set(a[1],res);
945
946 return 0;
947}*/
948
949//=======================================================================
950//function : DT_Debug
951//purpose : activation of the debug mode
952//
953//=======================================================================
954/*
955static Standard_Integer DT_Debug (Draw_Interpretor& di,
956 Standard_Integer n, const char** a)
957
958{
959 // a[1]= 0/1
960
961 if (n !=2) {
962 di << "bad number of arguments" <<"\n";
963 return 1;
964 }
965
966 if (atoi(a[1])==1) {
967 di << "Activation of debug messages"<<"\n";
968 ShapeUpgrade::SetDebug(Standard_True);
969 }
970 else {
971 di << "Desactivation of debug messages"<<"\n";
972 ShapeUpgrade::SetDebug(Standard_False);
973 }
974 return 0;
975}
976*/
977
978/*static Standard_Integer shellsolid
979 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
980{
981 if (argc < 4) {
982 di<<"Donner option + nom de SHAPE + nom de RESULTAT"<<"\n";
983 di<<"Options : a all (sewing sur tous les shells\n"
984 << " c check (sewing sur shells avec bad edges\n"
985 <<" b bad edges\n f free edges"<<"\n";
986 return 1 ;
987 }
988 Standard_CString arg1 = argv[1];
989 Standard_CString arg2 = argv[2];
990 Standard_CString arg3 = argv[3];
991
992 TopoDS_Shape Shape = DBRep::Get(arg2);
993 if (Shape.IsNull()) { di<<"Shape unknown : "<<arg2<<"\n"; return 1 ; }
994
995 ShapeAnalysis_Shell STS;
996 char opt = arg1[0];
997 if (opt == 'a') STS.LoadShells (Shape);
998 else if (opt == 'f') STS.CheckOrientedShells (Shape,Standard_True);
999 else if (opt == 'b' || opt == 'c') STS.CheckOrientedShells (Shape,Standard_False);
1000
1001 else if (opt == 'o') {
1002
1003// Test WireOrder
1004 Handle(ShapeExtend_WireData) Frees = new ShapeExtend_WireData;//:sw Frees.SetPrecision (BRepBuilderAPI::Precision());
1005 Standard_Integer nbe = 0;
1006 for (TopExp_Explorer edges(Shape,TopAbs_EDGE); edges.More(); edges.Next()) {
1007 Frees->Add (TopoDS::Edge(edges.Current())); nbe ++;
1008 }
1009 ShapeAnalysis_WireOrder WO (Standard_True,BRepBuilderAPI::Precision());
1010 ShapeAnalysis_Wire saw;
1011 saw.Load ( Frees );
1012 saw.SetPrecision ( BRepBuilderAPI::Precision() );
1013 saw.CheckOrder ( WO );
1014
1015 Standard_Integer stat = WO.Status();
1016 di<<"Wire Order Status = "<<stat<<" on "<<nbe<<" Edges"<<"\n";
1017 nbe = WO.NbEdges();
1018 for (Standard_Integer ie = 1; ie <= nbe; ie ++) {
1019 Standard_Integer io = WO.Ordered (ie);
1020 gp_XYZ st3d,en3d;
1021 WO.XYZ (io,st3d,en3d);
1022 di<<ie<<": Edge."<<io<<" Start:"<<st3d.X()<<" "<<st3d.Y()<<" "<<st3d.Z()
1023 <<" End:"<<en3d.X()<<" "<<en3d.Y()<<" "<<en3d.Z()<<"\n";
1024 }
1025// Chainage ?
1026 Standard_Real gap = BRepBuilderAPI::Precision();
1027 WO.SetChains (gap);
1028 Standard_Integer n1,n2,ic, nc = WO.NbChains();
1029 for (ic = 1; ic <= nc; ic ++) {
1030 WO.Chain(ic,n1,n2);
1031 di<<"Chain."<<ic<<" From "<<n1<<" To "<<n2<<"\n";
1032 }
1033 }
1034
1035 else { di<<"Option non reconnue : "<<arg1<<"\n"; return 1; }
1036
1037 TopoDS_Shape res;
1038 if (opt == 'a' || opt == 'c') {
1039 ShapeUpgrade_ShellSewing sew;
1040 res = sew.ApplySewing (Shape);
1041 if (res.IsEqual(Shape)) {
1042 res.Nullify();
1043 di<<"ShellSolid : no sewing done"<<"\n";
1044 }
1045 } else if (opt == 'b') {
1046 if (STS.HasBadEdges()) res = STS.BadEdges();
1047 else di<<"ShellSolid : no bad edge"<<"\n";
1048 } else if (opt == 'f') {
1049 if (STS.HasFreeEdges()) res = STS.FreeEdges();
1050 else di<<"ShellSolid : no free edge"<<"\n";
1051 if (STS.HasConnectedEdges()) di<<"ShellSolid : connected edges"<<"\n";
1052 else di<<"ShellSolid : NO connected edges"<<"\n";
1053 }
1054
1055 if (!res.IsNull()) DBRep::Set (arg3,res);
1056
1057 return 0; // Done
1058}*/
1059//---------------gka
1060//=======================================================================
1061//function : offset2dcurve
1062//purpose :
1063//
1064//=======================================================================
1065static Standard_Integer offset2dcurve
1066 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1067{
1068 if (argc < 4) {
1069 di<<"result + curve + offset"<<"\n";
1070
1071 return 1 /* Error */;
1072 }
1073// Standard_CString arg1 = argv[1];
1074// Standard_CString arg2 = argv[2];
1075 Standard_Real Offset = atof(argv[3]);
1076 Handle(Geom2d_Curve) GC = DrawTrSurf::GetCurve2d(argv[2]);
1077 if ( GC.IsNull()) return 1;
1078 Handle(Geom2d_OffsetCurve) offcrv = new Geom2d_OffsetCurve(GC,Offset);
1079 DrawTrSurf::Set(argv[1], offcrv);
1080 return 0;
1081}
1082
1083//=======================================================================
1084//function : offsetcurve
1085//purpose :
1086//
1087//=======================================================================
1088static Standard_Integer offsetcurve
1089 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1090{
1091 if (argc < 5) {
1092 di<<"result + curve + offset + Dir"<<"\n";
1093
1094 return 1 /* Error */;
1095 }
1096// Standard_CString arg1 = argv[1];
1097// Standard_CString arg2 = argv[2];
1098 Standard_Real Offset = atof(argv[3]);
1099 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(argv[2]);
1100 if ( GC.IsNull()) return 1;
1101 gp_Pnt point;
1102 DrawTrSurf::GetPoint(argv[4],point);
1103 gp_Dir dir(point.XYZ());
1104 Handle(Geom_OffsetCurve) offcrv = new Geom_OffsetCurve(GC,Offset,dir);
1105 DrawTrSurf::Set(argv[1], offcrv);
1106 return 0;
1107}
1108
1109//=======================================================================
1110//function : compose shell
1111//purpose :
1112//=======================================================================
1113static Standard_Integer splitface
1114 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1115{
1116 if (argc < 5) {
1117 di << "Split face: splitface result face [u usplit1 usplit2...] [v vsplit1 vsplit2 ...]" << "\n";
1118 return 1;
1119 }
1120
1121 TopoDS_Shape aLocalShape = DBRep::Get(argv[2]) ;
1122 TopoDS_Face face = TopoDS::Face ( aLocalShape );
1123 if ( face.IsNull() ) {
1124 di << argv[2] << " is not Face" << "\n";
1125 return 1;
1126 }
1127
1128 Handle(Geom_Surface) S = BRep_Tool::Surface ( face );
1129 Standard_Real Uf, Ul, Vf, Vl;
1130 BRepTools::UVBounds ( face, Uf, Ul, Vf, Vl );
1131 Standard_Real Umin, Umax, Vmin, Vmax;
1132 S->Bounds ( Umin, Umax, Vmin, Vmax );
1133 if ( Uf < Umin && ! S->IsUPeriodic() ) Uf = Umin;
1134 else if ( Uf > Umin )
1135 if ( Precision::IsInfinite(Umin) ) Uf -= 100;
1136 else Uf = Umin;
1137 if ( Vf < Vmin && ! S->IsVPeriodic() ) Vf = Vmin;
1138 else if ( Vf > Vmin )
1139 if ( Precision::IsInfinite(Vmin) ) Vf -= 100;
1140 else Vf = Vmin;
1141 if ( Ul > Umax && ! S->IsUPeriodic() ) Ul = Umax;
1142 else if ( Ul < Umax )
1143 if ( Precision::IsInfinite(Umax) ) Ul += 100;
1144 else Ul = Umax;
1145 if ( Vl > Vmax && ! S->IsVPeriodic() ) Vl = Vmax;
1146 else if ( Vl < Vmax )
1147 if ( Precision::IsInfinite(Vmax) ) Vl += 100;
1148 else Vl = Vmax;
1149
1150 TColStd_SequenceOfReal uval;
1151 TColStd_SequenceOfReal vval;
1152
1153 Standard_Boolean byV = Standard_False;
1154 Standard_Integer i; // svv Jan11 2000 : porting on DEC
1155 for ( i=3; i < argc; i++ ) {
1156 if ( argv[i][0] == 'u' ) byV = Standard_False;
1157 else if ( argv[i][0] == 'v' ) byV = Standard_True;
1158 else {
1159 Standard_Real val = atof ( argv[i] );
1160 TColStd_SequenceOfReal &vals = ( byV ? vval : uval );
1161 if ( vals.Length() >0 && val - vals.Last() < Precision::PConfusion() ) {
1162 di << "Values should be sorted in increasing order; skipped" << "\n";
1163 continue;
1164 }
1165 if ( ( byV && ( val < Vf+Precision::PConfusion() ||
1166 val > Vl-Precision::PConfusion() ) ) ||
1167 (!byV && ( val < Uf+Precision::PConfusion() ||
1168 val > Ul-Precision::PConfusion() ) ) ) {
1169 di << "Values should be inside range of surface; skipped" << "\n";
1170 continue;
1171 }
1172 vals.Append ( val );
1173 }
1174 }
1175 if ( uval.Length() <1 && vval.Length() <1 ) {
1176 di << "No splitting defined" << "\n";
1177 return 1;
1178 }
1179 if ( uval.Length() >0 ) {
1180 di << "Splitting by U: ";
1181 for ( Standard_Integer j=1; j <= uval.Length(); j++ ) {
1182 //cout << ( i >j ? ", " : "" ) << uval(j);
1183 if (i >j) {
1184 di << ", ";
1185 } else {
1186 di << "";
1187 }
1188 di << uval(j);
1189 }
1190 di << "\n";
1191 }
1192 if ( vval.Length() >0 ) {
1193 di << "Splitting by V: ";
1194 for ( Standard_Integer j=1; j <= vval.Length(); j++ ) {
1195 //cout << ( j >1 ? ", " : "" ) << vval(j);
1196 if (j >1) {
1197 di << ", ";
1198 } else {
1199 di << "";
1200 }
1201 di << vval(j);
1202 }
1203 di << "\n";
1204 }
1205
1206 Handle(TColGeom_HArray2OfSurface) AS = new TColGeom_HArray2OfSurface ( 1, uval.Length()+1,
1207 1, vval.Length()+1 );
1208 for ( i=0; i <= uval.Length(); i++ ) {
1209 Standard_Real umin = ( i ? uval(i) : Uf );
1210 Standard_Real umax = ( i < uval.Length() ? uval(i+1) : Ul );
1211 for ( Standard_Integer j=0; j <= vval.Length(); j++ ) {
1212 Standard_Real vmin = ( j ? vval(j) : Vf );
1213 Standard_Real vmax = ( j < vval.Length() ? vval(j+1) : Vl );
1214 Handle(Geom_RectangularTrimmedSurface) rect =
1215 new Geom_RectangularTrimmedSurface ( S, umin, umax, vmin, vmax );
1216 AS->SetValue ( i+1, j+1, rect );
1217 }
1218 }
1219
1220 Handle(ShapeExtend_CompositeSurface) Grid = new ShapeExtend_CompositeSurface;
1221 if ( ! Grid->Init ( AS ) ) di << "Grid badly connected!" << "\n";
1222
1223 ShapeFix_ComposeShell SUCS;
1224 TopLoc_Location l;
1225 SUCS.Init ( Grid, l, face, Precision::Confusion() );
1226 Handle(ShapeBuild_ReShape) RS = new ShapeBuild_ReShape;
1227 SUCS.SetContext( RS );
1228 SUCS.Perform ();
1229
1230 if ( SUCS.Status ( ShapeExtend_OK ) ) di << "Status: OK" << "\n";
1231 if ( SUCS.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1" << "\n";
1232 if ( SUCS.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2" << "\n";
1233 if ( SUCS.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3" << "\n";
1234 if ( SUCS.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4" << "\n";
1235 if ( SUCS.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5" << "\n";
1236 if ( SUCS.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6" << "\n";
1237 if ( SUCS.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7" << "\n";
1238 if ( SUCS.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8" << "\n";
1239 if ( SUCS.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1" << "\n";
1240 if ( SUCS.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2" << "\n";
1241 if ( SUCS.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3" << "\n";
1242 if ( SUCS.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4" << "\n";
1243 if ( SUCS.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5" << "\n";
1244 if ( SUCS.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6" << "\n";
1245 if ( SUCS.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7" << "\n";
1246 if ( SUCS.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8" << "\n";
1247
1248 TopoDS_Shape sh = SUCS.Result();
1249 ShapeFix::SameParameter ( sh, Standard_False );
1250 DBRep::Set ( argv[1], sh );
1251 return 0;
1252}
1253
1254static Standard_Integer converttobspline
1255 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1256{
1257 if (argc<3) {
1258 di << "Use: " << argv[0] << " result shape [options=ero]\n";
1259 di << "where options is combination of letters indicating kinds of\n";
1260 di << "surfaces to be converted:\n";
1261 di << "e - extrusion\n";
1262 di << "r - revolution\n";
1263 di << "o - offset\n";
1264 di << "p - plane";
1265 return 1;
1266 }
1267 const char *options = ( argc > 3 ? argv[3] : "ero" );
1268
1269 TopoDS_Shape inputShape=DBRep::Get(argv[2]);
1270 if (inputShape.IsNull()) {
1271 di << "Unknown shape"<< "\n";
1272 return 1;
1273 }
1274 TopoDS_Shape revsh = ShapeCustom::ConvertToRevolution (inputShape);
1275 TopoDS_Shape res =
1276 ShapeCustom::ConvertToBSpline (revsh, strchr (options, 'e') != 0,
1277 strchr (options, 'r') != 0,
1278 strchr (options, 'o') != 0,
1279 strchr (options, 'p') != 0);
1280 ShapeFix::SameParameter ( res, Standard_False );
1281 DBRep::Set ( argv[1], res );
1282 return 0;
1283}
1284
1285
1286static Standard_Integer splitclosed (Draw_Interpretor& di,
1287 Standard_Integer argc,
1288 const char** argv)
1289{
1290 if (argc<3) {
1291 di << "bad number of arguments" <<"\n";
1292 return 1;
1293 }
1294
1295 TopoDS_Shape inputShape=DBRep::Get(argv[2]);
1296 if (inputShape.IsNull()) {
1297 di << "Unknown shape"<< "\n";
1298 return 1;
1299 }
1300
1301 ShapeUpgrade_ShapeDivideClosed tool (inputShape);
1302 tool.Perform();
1303 TopoDS_Shape res = tool.Result();
1304
1305 ShapeFix::SameParameter ( res, Standard_False );
1306 DBRep::Set ( argv[1], res );
1307 return 0;
1308}
1309
1310static Standard_Integer splitarea (Draw_Interpretor& di,
1311 Standard_Integer argc,
1312 const char** argv)
1313{
1314 if (argc<4) {
1315 di << "bad number of arguments" <<"\n";
1316 return 1;
1317 }
1318
1319 TopoDS_Shape inputShape=DBRep::Get(argv[2]);
1320 if (inputShape.IsNull()) {
1321 di << "Unknown shape"<< "\n";
1322 return 1;
1323 }
1324 Standard_Real aMaxArea = atof(argv[3]);
1325
1326
1327 ShapeUpgrade_ShapeDivideArea tool (inputShape);
1328 if(argc >4) {
1329 Standard_Real prec = atof(argv[4]);
1330 tool.SetPrecision(prec);
1331 }
1332 tool.MaxArea() = aMaxArea;
1333 tool.Perform();
1334 TopoDS_Shape res = tool.Result();
1335
1336 ShapeFix::SameParameter ( res, Standard_False );
1337 DBRep::Set ( argv[1], res );
1338 return 0;
1339}
1340
1341static Standard_Integer removeinternalwires (Draw_Interpretor& di,
1342 Standard_Integer argc,
1343 const char** argv)
1344{
1345 if (argc<4) {
1346 di << "bad number of arguments" <<"\n";
1347 return 1;
1348 }
1349 Standard_Real aMinArea = atof(argv[2]);
1350 TopoDS_Shape inputShape=DBRep::Get(argv[3]);
1351 if (inputShape.IsNull()) {
1352 di << "Unknown shape"<< "\n";
1353 return 1;
1354 }
1355 Handle(ShapeUpgrade_RemoveInternalWires) aTool;
1356 TopTools_SequenceOfShape aSeqShapes;
1357 if(inputShape.ShapeType() < TopAbs_WIRE)
1358 aTool = new ShapeUpgrade_RemoveInternalWires(inputShape);
1359 else {
1360 di<<"Invalid type of first shape: should be FACE,SHELL,SOLID or COMPOUND"<<"\n";
1361 return 1;
1362 }
1363
1364 Standard_Integer k = 4;
1365 Standard_Boolean isShape = Standard_True;
1366 Standard_Boolean aModeRemoveFaces =Standard_True;
1367
1368
1369 for( ; k < argc; k++) {
1370 if(isShape) {
1371 TopoDS_Shape aShape=DBRep::Get(argv[k]);
1372 isShape = !aShape.IsNull();
1373 if(isShape) {
1374 if(aShape.ShapeType() == TopAbs_FACE || aShape.ShapeType() == TopAbs_WIRE)
1375 aSeqShapes.Append(aShape);
1376 }
1377 }
1378 if(!isShape)
1379 aModeRemoveFaces = (atoi(argv[k]) == 1);
1380 }
1381
1382 aTool->MinArea() = aMinArea;
1383 aTool->RemoveFaceMode() = aModeRemoveFaces;
1384 if(aSeqShapes.Length())
1385 aTool->Perform(aSeqShapes);
1386 else
1387 aTool->Perform();
1388 if(aTool->Status(ShapeExtend_FAIL1))
1389 di<<"Initial shape has invalid type"<<"\n";
1390 else if(aTool->Status(ShapeExtend_FAIL2))
1391 di<<"Specified sub-shape is not belonged to whole shape"<<"\n";
1392 if(aTool->Status(ShapeExtend_DONE1)) {
1393 const TopTools_SequenceOfShape& aRemovedWires =aTool->RemovedWires();
1394 di<<aRemovedWires.Length()<<" internal wires were removed"<<"\n";
1395
1396 }
1397 if(aTool->Status(ShapeExtend_DONE2)) {
1398 const TopTools_SequenceOfShape& aRemovedFaces =aTool->RemovedFaces();
1399 di<<aRemovedFaces.Length()<<" small faces were removed"<<"\n";
1400
1401 }
1402 TopoDS_Shape res = aTool->GetResult();
1403
1404
1405 DBRep::Set ( argv[1], res );
1406 return 0;
1407}
1408
982a90fc
G
1409static Standard_Integer removeloc (Draw_Interpretor& di,
1410 Standard_Integer argc,
1411 const char** argv)
1412{
1413 if (argc<3) {
1414 di << "bad number of arguments. Should be: removeloc res shape" <<"\n";
1415 return 1;
1416 }
1417
1418 TopoDS_Shape aShape = DBRep::Get(argv[2]);
1419 if(aShape.IsNull())
1420 return 1;
1421 ShapeUpgrade_RemoveLocations aRemLoc;
1422 aRemLoc.Remove(aShape);
1423 TopoDS_Shape aNewShape = aRemLoc.GetResult();
1424
1425 DBRep::Set(argv[1],aNewShape);
1426 return 0;
1427}
1428static Standard_Integer copytranslate(Draw_Interpretor& di,
1429 Standard_Integer argc,
1430 const char** argv)
1431{
1432 if (argc<6) {
1433 di << "bad number of arguments. Should be: removeloc res shape dx dyy dz" <<"\n";
1434 return 1;
1435 }
1436 TopoDS_Shape aShape = DBRep::Get(argv[2]);
1437 if(aShape.IsNull())
1438 return 1;
1439 Standard_Real aDx = atof(argv[3]);
1440 Standard_Real aDy = atof(argv[4]);
1441 Standard_Real aDz = atof(argv[5]);
1442 gp_Trsf aTrsf;
1443 aTrsf.SetTranslation(gp_Vec(aDx, aDy, aDz));
1444 BRepBuilderAPI_Transform builderTransform(aTrsf);
1445 builderTransform.Perform (aShape, true);
1446 TopoDS_Shape aNewShape = builderTransform.Shape();
1447 DBRep::Set(argv[1],aNewShape);
1448 return 0;
1449
1450}
1451
7fd59977 1452//=======================================================================
1453//function : InitCommands
1454//purpose :
1455//=======================================================================
1456
1457 void SWDRAW_ShapeUpgrade::InitCommands(Draw_Interpretor& theCommands)
1458{
1459 static Standard_Integer initactor = 0;
1460 if (initactor) return; initactor = 1;
1461
1462 Standard_CString g = SWDRAW::GroupName(); // "Tests of DivideTool";
1463
1464 theCommands.Add("DT_ShapeDivide",
1465 "DT_ShapeDivide Result Shape Tol: Divides shape with C1 Criterion",
1466 __FILE__,
1467 DT_ShapeDivide,g);
1468
1469 theCommands.Add("DT_SplitAngle",
1470 "DT_SplitAngle Result Shape [MaxAngle=95]: Divides revolved surfaces on segments less MaxAngle deg",
1471 __FILE__,
1472 DT_SplitAngle,g);
1473
1474 theCommands.Add("DT_ShapeConvert",
1475 "DT_ShapeConvert Result Shape convert2d convert3d: Converts curves to beziers",
1476 __FILE__,
1477 DT_ShapeConvert,g);
1478
1479 theCommands.Add("DT_ShapeConvertRev",
1480 "DT_ShapeConvert Result Shape convert2d convert3d: Converts curves to beziers",
1481 __FILE__,
1482 DT_ShapeConvertRev,g);
1483/* theCommands.Add("DT_PlaneDividedFace",
1484 "DT_PlaneDividedFace Result Face Tol: Transfer into a plane with boundary divided",
1485 __FILE__,
1486 DT_PlaneDividedFace,g);
1487
1488 theCommands.Add("DT_PlaneGridShell",
1489 "DT_PlaneGridShell Result NbU NbV {UKnots} {VKnots} Tol : Create a plane grid Shell",
1490 __FILE__,
1491 DT_PlaneGridShell,g);
1492
1493 theCommands.Add("DT_PlaneFaceCommon",
1494 "DT_PlaneFaceCommon Result Face Shell: Common between a plane Face and a Shell",
1495 __FILE__,
1496 DT_PlaneFaceCommon,g);*/
1497
1498 theCommands.Add("DT_SplitCurve2d",
1499 "DT_SplitCurve2d Curve Tol: Splits the curve with C1 criterion",
1500 __FILE__,
1501 DT_SplitCurve2d,g);
1502
1503 theCommands.Add("DT_SplitCurve",
1504 "DT_SplitCurve Curve Tol: Splits the curve with C1 criterion",
1505 __FILE__,
1506 DT_SplitCurve,g);
1507
1508 theCommands.Add("DT_SplitSurface",
1509 "DT_SplitSurface Result Surface/GridSurf Tol: Splits the surface with C1 criterion",
1510 __FILE__,
1511 DT_SplitSurface,g);
1512
1513 /*theCommands.Add("DT_SupportModification",
1514 "DT_SupportModification Result Shell Surface 2d3dFactor: Surface will support all the faces",
1515 __FILE__,
1516 DT_SupportModification,g);*/
1517
1518// theCommands.Add("DT_SpltWire","DT_SpltWire Result Wire Tol",
1519// __FILE__,DT_SplitWire,g);
1520
1521// theCommands.Add("DT_SplitFace", "DT_SplitFace Result Face Tol",
1522// __FILE__, DT_SplitFace,g);
1523
1524// theCommands.Add("DT_Debug", "DT_Debug 0/1 : activation/desactivation of the debug messages",
1525// __FILE__, DT_Debug,g);
1526// theCommands.Add ("shellsolid","option[a-b-c-f] shape result",
1527// __FILE__,shellsolid,g);
1528 theCommands.Add ("offset2dcurve","result curve offset",
1529 __FILE__,offset2dcurve,g);
1530
1531 theCommands.Add ("offsetcurve","result curve offset dir",
1532 __FILE__,offsetcurve,g);
1533
1534 theCommands.Add ("splitface","result face [u usplit1 usplit2...] [v vsplit1 vsplit2 ...]",
1535 __FILE__,splitface,g);
1536
1537 theCommands.Add ("DT_ToBspl","result shape [options=erop]",
1538 __FILE__,converttobspline,g);
1539 theCommands.Add ("DT_ClosedSplit","result shape",
1540 __FILE__,splitclosed,g);
1541 theCommands.Add ("DT_SplitByArea","result shape maxarea [preci]",
1542 __FILE__,splitarea,g);
1543
1544 theCommands.Add ("RemoveIntWires","result minarea wholeshape [faces or wires] [moderemoveface ]",
1545 __FILE__,removeinternalwires,g);
982a90fc
G
1546
1547 theCommands.Add ("removeloc","result shape",__FILE__,removeloc,g);
1548 theCommands.Add ("copytranslate","result shape dx dy dz",__FILE__,copytranslate,g);
7fd59977 1549}