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