1 // Created on: 1999-03-09
2 // Created by: data exchange team
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 //gka,rln 30.04.99 S4137: new commands for testing ShapeDivide added, some removed
18 //abv,pdn 05.05.99 S4174: new commands for testing ShapeDivide added, some removed
19 //pdn,gka 10.06.99 S4189: command DT_ShapeConvertRev added
21 #include <BRep_Tool.hxx>
22 #include <BRepBuilderAPI.hxx>
23 #include <BRepBuilderAPI_Transform.hxx>
24 #include <BRepTools.hxx>
25 #include <BRepTools_ReShape.hxx>
28 #include <Draw_Interpretor.hxx>
29 #include <DrawTrSurf.hxx>
30 #include <Geom2d_Curve.hxx>
31 #include <Geom2d_OffsetCurve.hxx>
32 #include <Geom_Curve.hxx>
33 #include <Geom_OffsetCurve.hxx>
34 #include <Geom_Plane.hxx>
35 #include <Geom_RectangularTrimmedSurface.hxx>
36 #include <Geom_Surface.hxx>
37 #include <Precision.hxx>
38 #include <ShapeBuild_ReShape.hxx>
39 #include <ShapeCustom.hxx>
40 #include <ShapeExtend_CompositeSurface.hxx>
41 #include <ShapeFix.hxx>
42 #include <ShapeFix_ComposeShell.hxx>
43 #include <ShapeUpgrade.hxx>
44 #include <ShapeUpgrade_RemoveInternalWires.hxx>
45 #include <ShapeUpgrade_RemoveLocations.hxx>
46 #include <ShapeUpgrade_ShapeConvertToBezier.hxx>
47 #include <ShapeUpgrade_ShapeDivideAngle.hxx>
48 #include <ShapeUpgrade_ShapeDivideArea.hxx>
49 #include <ShapeUpgrade_ShapeDivideClosed.hxx>
50 #include <ShapeUpgrade_ShapeDivideContinuity.hxx>
51 #include <ShapeUpgrade_SplitCurve2dContinuity.hxx>
52 #include <ShapeUpgrade_SplitCurve3dContinuity.hxx>
53 #include <ShapeUpgrade_SplitSurfaceContinuity.hxx>
54 #include <ShapeUpgrade_UnifySameDomain.hxx>
56 #include <SWDRAW_ShapeUpgrade.hxx>
57 #include <TColGeom2d_HArray1OfCurve.hxx>
58 #include <TColGeom_HArray1OfCurve.hxx>
59 #include <TColGeom_HArray2OfSurface.hxx>
60 #include <TColStd_Array1OfReal.hxx>
61 #include <TColStd_HArray1OfReal.hxx>
62 #include <TColStd_HSequenceOfReal.hxx>
63 #include <TopExp_Explorer.hxx>
65 #include <TopoDS_Compound.hxx>
66 #include <TopoDS_Edge.hxx>
67 #include <TopoDS_Face.hxx>
68 #include <TopoDS_Iterator.hxx>
69 #include <TopoDS_Shape.hxx>
70 #include <TopoDS_Shell.hxx>
71 #include <TopoDS_Wire.hxx>
74 //#include <SWDRAW_ShapeUpgrade.hxx>
75 //#include <ShapeUpgrade_SupportModification.hxx>
76 //#include <ShapeExtend_WireData.hxx>
77 //#include <ShapeAnalysis_Shell.hxx>
78 //#include <ShapeAnalysis_WireOrder.hxx>
79 //#include <ShapeAnalysis_Wire.hxx>
80 //#include <ShapeUpgrade_ShellSewing.hxx>
81 // the plane (equation z=0) shared by PlaneDividedFaceContinuity and PlaneGridShell
82 //static Handle(Geom_Plane) ThePlane= new Geom_Plane(0,0,1,0);
83 //=======================================================================
84 //function : DT_ShapeDivide
86 //=======================================================================
87 static Standard_Integer DT_ShapeDivide (Draw_Interpretor& di,
88 Standard_Integer n, const char** a)
90 // DT_ShapeDivide result Shape Tol
92 // a[2]= input Face/Surface
93 // a[3] si n>3= Wire/Face
97 di << "bad number of arguments\n";
101 // try to read a shape:
102 TopoDS_Shape inputShape=DBRep::Get(a[2]);
103 if (inputShape.IsNull()) {
104 di << "Unknown shape\n";
107 // a[2] is a shape. managing:
108 // DT_ShapeDivide result Face Tol
110 // giving a face is available only in the constructor:
111 // we make the whole and quit.
112 ShapeUpgrade_ShapeDivideContinuity tool(inputShape);
114 // tolerance is optional
116 Standard_Real Tol=Draw::Atof(a[3]);
117 tool.SetTolerance(Tol);
120 // theTool.SetGlobalCriterion(GeomAbs_C1);
122 TopoDS_Shape res = tool.Result();
124 if ( tool.Status ( ShapeExtend_OK ) ) di << "Status: OK\n";
125 if ( tool.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1\n";
126 if ( tool.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2\n";
127 if ( tool.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3\n";
128 if ( tool.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4\n";
129 if ( tool.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5\n";
130 if ( tool.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6\n";
131 if ( tool.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7\n";
132 if ( tool.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8\n";
133 if ( tool.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1\n";
134 if ( tool.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2\n";
135 if ( tool.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3\n";
136 if ( tool.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4\n";
137 if ( tool.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5\n";
138 if ( tool.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6\n";
139 if ( tool.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7\n";
140 if ( tool.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8\n";
144 ShapeFix::SameParameter ( res, Standard_False );
146 DBRep::Set(a[1],res);
150 static Standard_Integer DT_ShapeConvertRev (Draw_Interpretor& di,
151 Standard_Integer n, const char** a)
154 di << "bad number of arguments\n";
158 // try to read a shape:
159 TopoDS_Shape inputShape=DBRep::Get(a[2]);
160 if (inputShape.IsNull()) {
161 di << "Unknown shape\n";
165 Standard_Integer c2d = Draw::Atoi(a[3]);
166 Standard_Integer c3d = Draw::Atoi(a[4]);
167 TopoDS_Shape revsh = ShapeCustom::ConvertToRevolution (inputShape);
168 if (revsh.IsNull()) { di<<"NO RESULT\n"; return 1; }
169 else if (revsh == inputShape) { di<<"No modif\n";}
170 else di<<"ConvertToRevolution -> Result : \n";
172 ShapeUpgrade_ShapeConvertToBezier tool(revsh);
173 tool.SetSurfaceConversion(Standard_True);
175 tool.Set2dConversion(Standard_True);
177 tool.Set3dConversion(Standard_True);
179 tool.Set3dLineConversion(Standard_False);
181 tool.Set3dCircleConversion(Standard_False);
183 tool.Set3dConicConversion(Standard_False);
186 TopoDS_Shape res = tool.Result();
188 if ( tool.Status ( ShapeExtend_OK ) ) di << "Status: OK\n";
189 if ( tool.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1\n";
190 if ( tool.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2\n";
191 if ( tool.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3\n";
192 if ( tool.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4\n";
193 if ( tool.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5\n";
194 if ( tool.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6\n";
195 if ( tool.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7\n";
196 if ( tool.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8\n";
197 if ( tool.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1\n";
198 if ( tool.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2\n";
199 if ( tool.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3\n";
200 if ( tool.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4\n";
201 if ( tool.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5\n";
202 if ( tool.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6\n";
203 if ( tool.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7\n";
204 if ( tool.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8\n";
208 ShapeFix::SameParameter ( res, Standard_False );
210 DBRep::Set(a[1],res);
216 if (!inputShape.IsNull()) {
217 // a[2] is a shape. managing:
218 // DT_ShapeDivide result Face Tol
220 TopoDS_Face inputFace = TopoDS::Face(inputShape);
221 if (inputFace.IsNull()) {
222 di << a[2] << " is not a face\n";
226 // giving a face is available only in the constructor:
227 // we make the whole and quit.
228 ShapeUpgrade_ShapeDivideContinuity theTool(inputFace);
230 // tolerance is optional
232 Standard_Real Tol=Draw::Atof(a[n-1]);
233 theTool.SetTolerance(Tol);
236 theTool.SetGlobalCriterion(GeomAbs_C1);
238 if (!theTool.IsDone()) {
239 ShapeUpgrade_Error theError=theTool.Error();
240 di << "Not done: error=";
241 if (theError==ShapeUpgrade_Done)
243 else if (theError==ShapeUpgrade_NotDone)
245 else if (theError==ShapeUpgrade_EmptyShell)
246 di << "EmptyShell\n";
247 else if (theError==ShapeUpgrade_InvalidCriterion)
248 di << "InvalidCriterion\n";
249 else if (theError==ShapeUpgrade_InvalidGridSurface)
250 di << "InvalidGridSurface\n";
251 else if (theError==ShapeUpgrade_DegeneratedEdge)
252 di << "DegeneratedEdge\n";
253 else if (theError==ShapeUpgrade_NoSurface)
255 else if (theError==ShapeUpgrade_NoTolerance)
256 di << "NoTolerance\n";
259 TopoDS_Shell res = theTool.Shell();
260 DBRep::Set(a[1],res);
265 // not a face: we can use the empty consturctor.
266 ShapeUpgrade_ShapeDivideContinuity theTool;
267 Standard_Real Tol=Draw::Atof(a[n-1]);
268 theTool.SetTolerance(Tol);
269 theTool.SetGlobalCriterion(GeomAbs_C1);
271 // try to read a surface:
272 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[2]);
274 // a[2] is a surface. managing the configurations:
275 // DT_ShapeDivide result Surface Tol
276 // DT_ShapeDivide result Surface Face Tol
277 // DT_ShapeDivide result Surface Wire Surf Tol
279 theTool.SetSupport(GS);
281 // try to read a Wire or a Face:
283 TopoDS_Shape inputBoundary=DBRep::Get(a[3]);
284 if (inputBoundary.IsNull()) {
285 di << "Invalid Boundary\n";
288 TopoDS_Wire WireBoundary = TopoDS::Wire(inputBoundary);
289 if (!WireBoundary.IsNull()) {
290 // DT_ShapeDivide result Surface Wire Surf Tol
291 Handle(Geom_Surface) WireSupport = DrawTrSurf::GetSurface(a[4]);
292 if (WireSupport.IsNull()) {
293 di << "Invalid Surface supporting the Wire\n";
296 theTool.SetBoundary(WireBoundary, WireSupport);
299 TopoDS_Face FaceBoundary = TopoDS::Face(inputBoundary);
300 // DT_ShapeDivide result Surface Face Tol
301 theTool.SetBoundary(FaceBoundary);
306 // it must be a grid: managing the configurations:
307 // DT_ShapeDivide result NbU NbV {Surf_u_v...} Tol
308 // DT_ShapeDivide result NbU NbV {Surf_u_v...} Face Tol
309 // DT_ShapeDivide result NbU NbV {Surf_u_v...} Wire Surf Tol
311 di << "bad number of arguments for grid input\n";
315 Standard_Integer NbU=Draw::Atoi(a[2]);
316 Standard_Integer NbV=Draw::Atoi(a[3]);
317 if (n < 4+NbU*NbV+1) {
318 di << "bad number of arguments\n";
322 Handle(TColGeom_HArray2OfSurface)
323 TheGridSurf= new TColGeom_HArray2OfSurface(1,NbU,1,NbV);
325 for (Standard_Integer iu=1; iu<=NbU; iu++) {
326 for (Standard_Integer jv=1; jv<=NbV; jv++) {
327 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[4+(iu-1)*NbV+jv-1]);
328 TheGridSurf->SetValue(iu,jv,GS);
331 theTool.SetSupport(TheGridSurf,Tol);
333 // try to read a Wire or a Face:
335 TopoDS_Shape inputBoundary=DBRep::Get(a[4+NbU*NbV]);
336 if (inputBoundary.IsNull()) {
337 di << "Invalid Boundary\n";
340 TopoDS_Wire WireBoundary = TopoDS::Wire(inputBoundary);
341 if (!WireBoundary.IsNull()) {
342 // DT_ShapeDivide result Surface Wire Surf Tol
343 Handle(Geom_Surface) WireSupport = DrawTrSurf::GetSurface(a[4+NbU*NbV+1]);
344 if (WireSupport.IsNull()) {
345 di << "Invalid Surface supporting the Wire\n";
348 theTool.SetBoundary(WireBoundary, WireSupport);
351 TopoDS_Face FaceBoundary = TopoDS::Face(inputBoundary);
352 // DT_ShapeDivide result Surface Face Tol
353 theTool.SetBoundary(FaceBoundary);
359 if (!theTool.IsDone()) {
360 ShapeUpgrade_Error theError=theTool.Error();
361 di << "Not done: error=";
362 if (theError==ShapeUpgrade_Done)
364 else if (theError==ShapeUpgrade_NotDone)
366 else if (theError==ShapeUpgrade_EmptyShell)
367 di << "EmptyShell\n";
368 else if (theError==ShapeUpgrade_InvalidCriterion)
369 di << "InvalidCriterion\n";
370 else if (theError==ShapeUpgrade_InvalidGridSurface)
371 di << "InvalidGridSurface\n";
372 else if (theError==ShapeUpgrade_DegeneratedEdge)
373 di << "DegeneratedEdge\n";
374 else if (theError==ShapeUpgrade_NoSurface)
376 else if (theError==ShapeUpgrade_NoTolerance)
377 di << "NoTolerance\n";
381 TopoDS_Shell res = theTool.Shell();
382 DBRep::Set(a[1],res);
388 static Standard_Integer DT_ShapeConvert (Draw_Interpretor& di,
389 Standard_Integer n, const char** a)
392 di << "bad number of arguments\n";
396 // try to read a shape:
397 TopoDS_Shape inputShape=DBRep::Get(a[2]);
398 if (inputShape.IsNull()) {
399 di << "Unknown shape\n";
403 Standard_Integer c2d = Draw::Atoi(a[3]);
404 Standard_Integer c3d = Draw::Atoi(a[4]);
406 ShapeUpgrade_ShapeConvertToBezier tool(inputShape);
407 tool.SetSurfaceConversion(Standard_True);
409 tool.Set2dConversion(Standard_True);
411 tool.Set3dConversion(Standard_True);
413 TopoDS_Shape res = tool.Result();
415 if ( tool.Status ( ShapeExtend_OK ) ) di << "Status: OK\n";
416 if ( tool.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1\n";
417 if ( tool.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2\n";
418 if ( tool.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3\n";
419 if ( tool.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4\n";
420 if ( tool.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5\n";
421 if ( tool.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6\n";
422 if ( tool.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7\n";
423 if ( tool.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8\n";
424 if ( tool.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1\n";
425 if ( tool.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2\n";
426 if ( tool.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3\n";
427 if ( tool.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4\n";
428 if ( tool.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5\n";
429 if ( tool.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6\n";
430 if ( tool.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7\n";
431 if ( tool.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8\n";
435 ShapeFix::SameParameter ( res, Standard_False );
437 DBRep::Set(a[1],res);
440 static Standard_Integer DT_SplitAngle(Draw_Interpretor& di,
441 Standard_Integer n, const char** a)
444 di << "bad number of arguments\n";
448 TopoDS_Shape inputShape=DBRep::Get(a[2]);
449 if (inputShape.IsNull()) {
450 di << "Unknown shape\n";
454 Standard_Real maxangle = 95;
456 maxangle = Draw::Atof ( a[3] );
457 if ( maxangle <1 ) maxangle = 1;
460 ShapeUpgrade_ShapeDivideAngle tool(maxangle * M_PI/180,inputShape);
462 TopoDS_Shape res = tool.Result();
464 if ( tool.Status ( ShapeExtend_OK ) ) di << "Status: OK\n";
465 if ( tool.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1\n";
466 if ( tool.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2\n";
467 if ( tool.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3\n";
468 if ( tool.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4\n";
469 if ( tool.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5\n";
470 if ( tool.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6\n";
471 if ( tool.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7\n";
472 if ( tool.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8\n";
473 if ( tool.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1\n";
474 if ( tool.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2\n";
475 if ( tool.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3\n";
476 if ( tool.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4\n";
477 if ( tool.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5\n";
478 if ( tool.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6\n";
479 if ( tool.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7\n";
480 if ( tool.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8\n";
484 ShapeFix::SameParameter ( res, Standard_False );
486 DBRep::Set(a[1],res);
491 //=======================================================================
492 //function : DT_PlaneDividedFace
493 //purpose : Transfer into a plane with boundary divided
496 //=======================================================================
497 static Standard_Integer DT_PlaneDividedFace (Draw_Interpretor& di,
498 Standard_Integer n, const char** a)
506 di << "bad number of arguments\n";
510 Standard_Real Tol=Draw::Atof(a[3]);
511 TopoDS_Shape inputShape=DBRep::Get(a[2]);
512 TopoDS_Face inputFace = TopoDS::Face(inputShape);
513 if (inputFace.IsNull()) {
514 di << a[2] << " is not a face\n";
518 ShapeUpgrade_PlaneDividedFace theTool(ThePlane);
519 theTool.Init(inputFace);
520 //theTool.SetBoundaryCriterion(GeomAbs_C1);
521 //theTool.SetTolerance(Tol);
523 if (!theTool.IsDone()) {
528 TopoDS_Face res = theTool.Face();
529 DBRep::Set(a[1],res);
531 Standard_Real the2d3dFactor=theTool.Get2d3dFactor();
532 di << "2d3dFactor="<<the2d3dFactor<< "\n";
536 //=======================================================================
537 //function : DT_PlaneGridShell
538 //purpose : Create a Plane Grid Shell from U and V knots
541 //=======================================================================
542 static Standard_Integer DT_PlaneGridShell (Draw_Interpretor& di,
543 Standard_Integer n, const char** a)
552 // a[4+NbU...] = {VKnots}
553 // a[4+NbU+NbV+1] = Tol
556 Standard_Integer NbU=Draw::Atoi(a[2]);
557 Standard_Integer NbV=Draw::Atoi(a[3]);
558 if (n != 4+NbU+NbV+1) {
559 di << "bad number of arguments\n";
563 TColStd_Array1OfReal TheUKnots(1,NbU);
564 TColStd_Array1OfReal TheVKnots(1,NbV);
566 for (Standard_Integer ii=1; ii<=NbU; ii++) {
567 TheUKnots(ii)=Draw::Atof(a[4+ii-1]);
569 for (ii=1; ii<=NbV; ii++) {
570 TheVKnots(ii)=Draw::Atof(a[4+NbU+ii-1]);
573 Standard_Real Tol=Draw::Atof(a[4+NbU+NbV]);
575 ShapeUpgrade_PlaneGridShell TheGrid(ThePlane,TheUKnots,TheVKnots,Tol);
577 TopoDS_Shell res = TheGrid.Shell();
578 DBRep::Set(a[1],res);
583 //=======================================================================
584 //function : DT_PlaneFaceCommon
585 //purpose : Common between a plane Face and a Shell whose all Faces are
586 // laying in the same plane
589 //=======================================================================
590 static Standard_Integer DT_PlaneFaceCommon (Draw_Interpretor& di,
591 Standard_Integer n, const char** a)
599 di << "bad number of arguments\n";
603 TopoDS_Shape inputShape= DBRep::Get(a[2]);
604 TopoDS_Face inputFace = TopoDS::Face(inputShape);
605 if (inputFace.IsNull()) {
606 di << a[2] << " is not a face\n";
610 inputShape = DBRep::Get(a[3]);
611 TopoDS_Shell inputShell = TopoDS::Shell(inputShape);
612 if (inputShell.IsNull()) {
613 di << a[3] << " is not a shell\n";
617 ShapeUpgrade_PlaneFaceCommon theTool;
618 theTool.Init(inputFace,inputShell);
620 TopoDS_Shell res = theTool.Shell();
621 DBRep::Set(a[1],res);
626 //=======================================================================
627 //function : DT_SplitCurve
628 //purpose : Splits the curve with C1 criterion
631 //=======================================================================
632 static Standard_Integer DT_SplitCurve (Draw_Interpretor& di,
633 Standard_Integer n, const char** a)
636 // a[1]= input curve. This name is used with a suffix to name the output curves
640 di << "bad number of arguments\n";
644 Standard_Real Tol=Draw::Atof(a[2]);
645 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(a[1]);
646 if ( GC.IsNull()) return 1;
647 Standard_Integer Split = Draw::Atoi(a[3]);
648 Handle(ShapeUpgrade_SplitCurve3dContinuity) theTool = new ShapeUpgrade_SplitCurve3dContinuity;
650 theTool->SetTolerance (Tol);
651 theTool->SetCriterion (GeomAbs_C1);
653 Handle(TColStd_HSequenceOfReal) spval = new TColStd_HSequenceOfReal;
654 for(Standard_Integer i = 1; i<=5; i++) spval->Append(i);
655 theTool->SetSplitValues(spval);
657 theTool->Perform (Standard_True);
658 Handle(TColGeom_HArray1OfCurve) theCurves= theTool->GetCurves();
659 Standard_Integer NbC=theCurves->Length();
660 for (Standard_Integer icurv=1; icurv<=NbC; icurv++) {
662 Sprintf(name,"%s%s%d",a[1],"_",icurv);
663 char* newname = name;
664 DrawTrSurf::Set(newname, theCurves->Value(icurv));
665 di.AppendElement(newname);
671 //=======================================================================
672 //function : DT_SplitCurve2d
673 //purpose : Splits the curve with C1 criterion
676 //=======================================================================
677 static Standard_Integer DT_SplitCurve2d (Draw_Interpretor& di,
678 Standard_Integer n, const char** a)
681 // a[1]= input 2d curve. This name is used with a suffix to name the output curves
685 di << "bad number of arguments\n";
689 Standard_Real Tol=Draw::Atof(a[2]);
690 Handle(Geom2d_Curve) GC = DrawTrSurf::GetCurve2d(a[1]);
691 if ( GC.IsNull()) return 1;
692 Standard_Integer Split = Draw::Atoi(a[3]);
693 Handle(ShapeUpgrade_SplitCurve2dContinuity) theTool = new ShapeUpgrade_SplitCurve2dContinuity;
695 theTool->SetTolerance (Tol);
696 theTool->SetCriterion (GeomAbs_C1);
698 Handle(TColStd_HSequenceOfReal) spval = new TColStd_HSequenceOfReal;
699 for(Standard_Integer i = 1; i<=5; i++) spval->Append(i);
700 theTool->SetSplitValues(spval);
702 theTool->Perform (Standard_True);
703 Handle(TColGeom2d_HArray1OfCurve) theCurves= theTool->GetCurves();
704 Standard_Integer NbC=theCurves->Length();
705 for (Standard_Integer icurv=1; icurv<=NbC; icurv++) {
707 Sprintf(name,"%s%s%d",a[1],"_",icurv);
708 char* newname = name;
709 DrawTrSurf::Set(newname, theCurves->Value(icurv));
710 di.AppendElement(newname);
716 //=======================================================================
717 //function : DT_SplitSurface
718 //purpose : Splits the surface with C1 criterion
721 //=======================================================================
723 static Standard_Integer DT_SplitWire (Draw_Interpretor& di,
724 Standard_Integer n, const char** a)
728 di << "bad number of arguments\n";
732 TopoDS_Face source = TopoDS::Face(DBRep::Get(a[2]));
733 if(source.IsNull()) {
734 di <<"Shape is not face\n";
737 TopoDS_Iterator wi(source);
739 di <<"Shape is face without wire\n";
743 TopoDS_Wire wire = TopoDS::Wire(wi.Value());
744 Handle(ShapeUpgrade_WireDivideContinuity) tool = new ShapeUpgrade_WireDivideContinuity;
745 tool->Init(wire,source);
747 Standard_Real Tol=Draw::Atof(a[3]);
749 Handle(ShapeBuild_ReShape) context = new ShapeBuild_ReShape;
750 tool->Perform(context);
751 TopoDS_Wire result = tool->Wire();
752 DBRep::Set(a[1],result);
757 static Standard_Integer DT_SplitFace (Draw_Interpretor& di,
758 Standard_Integer n, const char** a)
762 di << "bad number of arguments\n";
766 TopoDS_Face source = TopoDS::Face(DBRep::Get(a[2]));
767 if(source.IsNull()) {
768 di <<"Shape is not face\n";
771 Handle(ShapeUpgrade_ShapeDivideContinuity) tool = new ShapeUpgrade_FaceDivideContinuity;
774 Standard_Real Tol=Draw::Atof(a[3]);
775 tool->SetPrecision(Tol);
778 Handle(ShapeBuild_ReShape) context = new ShapeBuild_ReShape;
779 tool->Perform(context);
780 TopoDS_Shape result = tool->Result();
783 if ( tool->Status ( ShapeExtend_OK ) ) di << "Status: OK\n";
784 if ( tool->Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1\n";
785 if ( tool->Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2\n";
786 if ( tool->Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3\n";
787 if ( tool->Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4\n";
788 if ( tool->Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5\n";
789 if ( tool->Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6\n";
790 if ( tool->Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7\n";
791 if ( tool->Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8\n";
792 if ( tool->Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1\n";
793 if ( tool->Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2\n";
794 if ( tool->Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3\n";
795 if ( tool->Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4\n";
796 if ( tool->Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5\n";
797 if ( tool->Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6\n";
798 if ( tool->Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7\n";
799 if ( tool->Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8\n";
803 ShapeFix::SameParameter ( result, Standard_False );
805 DBRep::Set(a[1],result);
810 static Standard_Integer DT_SplitSurface (Draw_Interpretor& di,
811 Standard_Integer n, const char** a)
814 // a[1]= result (used with a suffix to name the output surfaces)
815 // a[2]= input surface.
821 // a[3+1]..a[3+nbU*nbV] = Input Surfaces
822 // a[4+nbU*nbV]= Tolerance
825 di << "bad number of arguments\n";
829 Handle(ShapeUpgrade_SplitSurfaceContinuity) theTool = new ShapeUpgrade_SplitSurfaceContinuity;//S4137
831 Standard_Real Tol=Draw::Atof(a[3]);
832 Standard_Integer Split = Draw::Atoi(a[4]);
833 theTool->SetTolerance(Tol);
834 theTool->SetCriterion(GeomAbs_C1);
835 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[2]);
838 // Case of composite grid surface
839 di << "composite surf\n";
840 Standard_Integer nbU=Draw::Atoi(a[2]);
841 Standard_Integer nbV=Draw::Atoi(a[3]);
842 if (nbU==0 || nbV==0) return 1;
843 Handle(TColGeom_HArray2OfSurface)
844 theGrid= new TColGeom_HArray2OfSurface(1,nbU,1,nbV);
845 for (Standard_Integer iu=1; iu<=nbU; iu++) {
846 for (Standard_Integer iv=1; iv<=nbV; iv++) {
847 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[3+(iu-1)*nbV+iv]);
848 theGrid->SetValue(iu,iv,GS);
851 di << "appel a SplitSurface::Init\n";
852 theTool->Init(theGrid);
855 // Case of single surface
856 di << "single surf\n";
858 di << "appel a SplitSurface::Init\n";
861 Handle(TColStd_HSequenceOfReal) spval = new TColStd_HSequenceOfReal;
862 for(Standard_Integer i = 1; i<=5; i++) spval->Append(i);
863 theTool->SetUSplitValues(spval);
864 theTool->SetVSplitValues(spval);
867 di << "appel a SplitSurface::Build\n";
868 theTool->Build(Standard_True);
870 di << "appel a SplitSurface::GlobalU/VKnots\n";
871 Handle(ShapeExtend_CompositeSurface) Grid = theTool->ResSurfaces();
872 Handle(TColStd_HArray1OfReal) GlobalU=Grid->UJointValues();
873 Handle(TColStd_HArray1OfReal) GlobalV=Grid->VJointValues();
874 Standard_Integer nbGlU=GlobalU->Length();
875 Standard_Integer nbGlV=GlobalV->Length();
876 di << "nb GlobalU ; nb GlobalV="<<nbGlU<<" "<<nbGlV;
877 for (Standard_Integer iu=1; iu<=nbGlU; iu++)
878 di <<" "<< GlobalU->Value(iu);
880 // di << "nb GlobalV="<<nbGlV;
881 for (Standard_Integer iv=1; iv<=nbGlV; iv++)
882 di <<" "<< GlobalV->Value(iv);
885 di << "appel a Surfaces\n";
886 Handle(TColGeom_HArray2OfSurface) theSurfaces= Grid->Patches();
888 di << "transfert resultat\n";
889 Standard_Integer NbRow=theSurfaces->ColLength();
890 Standard_Integer NbCol=theSurfaces->RowLength();
891 for (Standard_Integer irow=1; irow<=NbRow; irow++) {
892 for (Standard_Integer icol=1; icol<=NbCol; icol++) {
894 Sprintf(name,"%s%s%d%s%d",a[1],"_",irow,"_",icol);
895 char* newname = name;
896 DrawTrSurf::Set(newname, theSurfaces->Value(irow, icol));
897 di.AppendElement(newname);
904 //=======================================================================
905 //function : offset2dcurve
908 //=======================================================================
909 static Standard_Integer offset2dcurve
910 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
913 di<<"result + curve + offset\n";
915 return 1 /* Error */;
917 // Standard_CString arg1 = argv[1];
918 // Standard_CString arg2 = argv[2];
919 Standard_Real Offset = Draw::Atof(argv[3]);
920 Handle(Geom2d_Curve) GC = DrawTrSurf::GetCurve2d(argv[2]);
921 if ( GC.IsNull()) return 1;
922 Handle(Geom2d_OffsetCurve) offcrv = new Geom2d_OffsetCurve(GC,Offset);
923 DrawTrSurf::Set(argv[1], offcrv);
927 //=======================================================================
928 //function : offsetcurve
931 //=======================================================================
932 static Standard_Integer offsetcurve
933 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
936 di<<"result + curve + offset + Dir\n";
938 return 1 /* Error */;
940 // Standard_CString arg1 = argv[1];
941 // Standard_CString arg2 = argv[2];
942 Standard_Real Offset = Draw::Atof(argv[3]);
943 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(argv[2]);
944 if ( GC.IsNull()) return 1;
946 DrawTrSurf::GetPoint(argv[4],point);
947 gp_Dir dir(point.XYZ());
948 Handle(Geom_OffsetCurve) offcrv = new Geom_OffsetCurve(GC,Offset,dir);
949 DrawTrSurf::Set(argv[1], offcrv);
953 //=======================================================================
954 //function : compose shell
956 //=======================================================================
957 static Standard_Integer splitface
958 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
961 di << "Split face: splitface result face [u usplit1 usplit2...] [v vsplit1 vsplit2 ...]\n";
965 TopoDS_Shape aLocalShape = DBRep::Get(argv[2]) ;
966 TopoDS_Face face = TopoDS::Face ( aLocalShape );
967 if ( face.IsNull() ) {
968 di << argv[2] << " is not Face\n";
972 Handle(Geom_Surface) S = BRep_Tool::Surface ( face );
973 Standard_Real Uf, Ul, Vf, Vl;
974 BRepTools::UVBounds ( face, Uf, Ul, Vf, Vl );
975 Standard_Real Umin, Umax, Vmin, Vmax;
976 S->Bounds ( Umin, Umax, Vmin, Vmax );
977 if ( Uf < Umin && ! S->IsUPeriodic() ) Uf = Umin;
978 else if ( Uf > Umin ) {
979 if ( Precision::IsInfinite(Umin) ) Uf -= 100;
982 if ( Vf < Vmin && ! S->IsVPeriodic() ) Vf = Vmin;
983 else if ( Vf > Vmin ) {
984 if ( Precision::IsInfinite(Vmin) ) Vf -= 100;
987 if ( Ul > Umax && ! S->IsUPeriodic() ) Ul = Umax;
988 else if ( Ul < Umax ) {
989 if ( Precision::IsInfinite(Umax) ) Ul += 100;
992 if ( Vl > Vmax && ! S->IsVPeriodic() ) Vl = Vmax;
993 else if ( Vl < Vmax ) {
994 if ( Precision::IsInfinite(Vmax) ) Vl += 100;
998 TColStd_SequenceOfReal uval;
999 TColStd_SequenceOfReal vval;
1001 Standard_Boolean byV = Standard_False;
1002 Standard_Integer i; // svv Jan11 2000 : porting on DEC
1003 for ( i=3; i < argc; i++ ) {
1004 if ( argv[i][0] == 'u' ) byV = Standard_False;
1005 else if ( argv[i][0] == 'v' ) byV = Standard_True;
1007 Standard_Real val = Draw::Atof ( argv[i] );
1008 TColStd_SequenceOfReal &vals = ( byV ? vval : uval );
1009 if ( vals.Length() >0 && val - vals.Last() < Precision::PConfusion() ) {
1010 di << "Values should be sorted in increasing order; skipped\n";
1013 if ( ( byV && ( val < Vf+Precision::PConfusion() ||
1014 val > Vl-Precision::PConfusion() ) ) ||
1015 (!byV && ( val < Uf+Precision::PConfusion() ||
1016 val > Ul-Precision::PConfusion() ) ) ) {
1017 di << "Values should be inside range of surface; skipped\n";
1020 vals.Append ( val );
1023 if ( uval.Length() <1 && vval.Length() <1 ) {
1024 di << "No splitting defined\n";
1027 if ( uval.Length() >0 ) {
1028 di << "Splitting by U: ";
1029 for ( Standard_Integer j=1; j <= uval.Length(); j++ ) {
1030 //cout << ( i >j ? ", " : "" ) << uval(j);
1040 if ( vval.Length() >0 ) {
1041 di << "Splitting by V: ";
1042 for ( Standard_Integer j=1; j <= vval.Length(); j++ ) {
1043 //cout << ( j >1 ? ", " : "" ) << vval(j);
1054 Handle(TColGeom_HArray2OfSurface) AS = new TColGeom_HArray2OfSurface ( 1, uval.Length()+1,
1055 1, vval.Length()+1 );
1056 for ( i=0; i <= uval.Length(); i++ ) {
1057 Standard_Real umin = ( i ? uval(i) : Uf );
1058 Standard_Real umax = ( i < uval.Length() ? uval(i+1) : Ul );
1059 for ( Standard_Integer j=0; j <= vval.Length(); j++ ) {
1060 Standard_Real vmin = ( j ? vval(j) : Vf );
1061 Standard_Real vmax = ( j < vval.Length() ? vval(j+1) : Vl );
1062 Handle(Geom_RectangularTrimmedSurface) rect =
1063 new Geom_RectangularTrimmedSurface ( S, umin, umax, vmin, vmax );
1064 AS->SetValue ( i+1, j+1, rect );
1068 Handle(ShapeExtend_CompositeSurface) Grid = new ShapeExtend_CompositeSurface;
1069 if ( ! Grid->Init ( AS ) ) di << "Grid badly connected!\n";
1071 ShapeFix_ComposeShell SUCS;
1073 SUCS.Init ( Grid, l, face, Precision::Confusion() );
1074 Handle(ShapeBuild_ReShape) RS = new ShapeBuild_ReShape;
1075 SUCS.SetContext( RS );
1078 if ( SUCS.Status ( ShapeExtend_OK ) ) di << "Status: OK\n";
1079 if ( SUCS.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1\n";
1080 if ( SUCS.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2\n";
1081 if ( SUCS.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3\n";
1082 if ( SUCS.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4\n";
1083 if ( SUCS.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5\n";
1084 if ( SUCS.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6\n";
1085 if ( SUCS.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7\n";
1086 if ( SUCS.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8\n";
1087 if ( SUCS.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1\n";
1088 if ( SUCS.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2\n";
1089 if ( SUCS.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3\n";
1090 if ( SUCS.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4\n";
1091 if ( SUCS.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5\n";
1092 if ( SUCS.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6\n";
1093 if ( SUCS.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7\n";
1094 if ( SUCS.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8\n";
1096 TopoDS_Shape sh = SUCS.Result();
1097 ShapeFix::SameParameter ( sh, Standard_False );
1098 DBRep::Set ( argv[1], sh );
1102 static Standard_Integer converttobspline
1103 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1106 di << "Use: " << argv[0] << " result shape [options=ero]\n";
1107 di << "where options is combination of letters indicating kinds of\n";
1108 di << "surfaces to be converted:\n";
1109 di << "e - extrusion\n";
1110 di << "r - revolution\n";
1111 di << "o - offset\n";
1115 const char *options = ( argc > 3 ? argv[3] : "ero" );
1117 TopoDS_Shape inputShape=DBRep::Get(argv[2]);
1118 if (inputShape.IsNull()) {
1119 di << "Unknown shape\n";
1122 TopoDS_Shape revsh = ShapeCustom::ConvertToRevolution (inputShape);
1124 ShapeCustom::ConvertToBSpline (revsh, strchr (options, 'e') != 0,
1125 strchr (options, 'r') != 0,
1126 strchr (options, 'o') != 0,
1127 strchr (options, 'p') != 0);
1128 ShapeFix::SameParameter ( res, Standard_False );
1129 DBRep::Set ( argv[1], res );
1134 static Standard_Integer splitclosed (Draw_Interpretor& di,
1135 Standard_Integer argc,
1139 di << "bad number of arguments\n";
1143 TopoDS_Shape inputShape=DBRep::Get(argv[2]);
1144 if (inputShape.IsNull()) {
1145 di << "Unknown shape\n";
1149 ShapeUpgrade_ShapeDivideClosed tool (inputShape);
1151 TopoDS_Shape res = tool.Result();
1153 ShapeFix::SameParameter ( res, Standard_False );
1154 DBRep::Set ( argv[1], res );
1158 static Standard_Integer splitarea (Draw_Interpretor& di,
1159 Standard_Integer argc,
1163 di << "bad number of arguments\n";
1167 TopoDS_Shape inputShape=DBRep::Get(argv[2]);
1168 if (inputShape.IsNull()) {
1169 di << "Unknown shape\n";
1172 Standard_Real aMaxArea = Draw::Atof(argv[3]);
1175 ShapeUpgrade_ShapeDivideArea tool (inputShape);
1177 Standard_Real prec = Draw::Atof(argv[4]);
1178 tool.SetPrecision(prec);
1180 tool.MaxArea() = aMaxArea;
1182 TopoDS_Shape res = tool.Result();
1184 ShapeFix::SameParameter ( res, Standard_False );
1185 DBRep::Set ( argv[1], res );
1189 static Standard_Integer removeinternalwires (Draw_Interpretor& di,
1190 Standard_Integer argc,
1194 di << "bad number of arguments\n";
1197 Standard_Real aMinArea = Draw::Atof(argv[2]);
1198 TopoDS_Shape inputShape=DBRep::Get(argv[3]);
1199 if (inputShape.IsNull()) {
1200 di << "Unknown shape\n";
1203 Handle(ShapeUpgrade_RemoveInternalWires) aTool;
1204 TopTools_SequenceOfShape aSeqShapes;
1205 if(inputShape.ShapeType() < TopAbs_WIRE)
1206 aTool = new ShapeUpgrade_RemoveInternalWires(inputShape);
1208 di<<"Invalid type of first shape: should be FACE,SHELL,SOLID or COMPOUND\n";
1212 Standard_Integer k = 4;
1213 Standard_Boolean isShape = Standard_True;
1214 Standard_Boolean aModeRemoveFaces =Standard_True;
1217 for( ; k < argc; k++) {
1219 TopoDS_Shape aShape=DBRep::Get(argv[k]);
1220 isShape = !aShape.IsNull();
1222 if(aShape.ShapeType() == TopAbs_FACE || aShape.ShapeType() == TopAbs_WIRE)
1223 aSeqShapes.Append(aShape);
1227 aModeRemoveFaces = (Draw::Atoi(argv[k]) == 1);
1230 aTool->MinArea() = aMinArea;
1231 aTool->RemoveFaceMode() = aModeRemoveFaces;
1232 if(aSeqShapes.Length())
1233 aTool->Perform(aSeqShapes);
1236 if(aTool->Status(ShapeExtend_FAIL1))
1237 di<<"Initial shape has invalid type\n";
1238 else if(aTool->Status(ShapeExtend_FAIL2))
1239 di<<"Specified sub-shape is not belonged to whole shape\n";
1240 if(aTool->Status(ShapeExtend_DONE1)) {
1241 const TopTools_SequenceOfShape& aRemovedWires =aTool->RemovedWires();
1242 di<<aRemovedWires.Length()<<" internal wires were removed\n";
1245 if(aTool->Status(ShapeExtend_DONE2)) {
1246 const TopTools_SequenceOfShape& aRemovedFaces =aTool->RemovedFaces();
1247 di<<aRemovedFaces.Length()<<" small faces were removed\n";
1250 TopoDS_Shape res = aTool->GetResult();
1253 DBRep::Set ( argv[1], res );
1257 static Standard_Integer removeloc (Draw_Interpretor& di,
1258 Standard_Integer argc,
1262 di << "bad number of arguments. Should be: removeloc res shape\n";
1266 TopoDS_Shape aShape = DBRep::Get(argv[2]);
1269 ShapeUpgrade_RemoveLocations aRemLoc;
1270 aRemLoc.Remove(aShape);
1271 TopoDS_Shape aNewShape = aRemLoc.GetResult();
1273 DBRep::Set(argv[1],aNewShape);
1277 static ShapeUpgrade_UnifySameDomain& Unifier() {
1278 static ShapeUpgrade_UnifySameDomain sUnifier;
1282 //=======================================================================
1284 //=======================================================================
1285 static Standard_Integer unifysamedom(Draw_Interpretor& di, Standard_Integer n, const char** a)
1289 di << "Use unifysamedom result shape [-f] [-e] [+b] [-i] [-t val] [-a val]\n";
1291 di << "-f to switch off 'unify-faces' mode \n";
1292 di << "-e to switch off 'unify-edges' mode\n";
1293 di << "+b to switch on 'concat bspline' mode\n";
1294 di << "+i to switch on 'allow internal edges' mode\n";
1295 di << "-t val to set linear tolerance\n";
1296 di << "-a val to set angular tolerance\n";
1297 di << "'unify-faces' and 'unify-edges' modes are switched on by default";
1301 TopoDS_Shape aShape = DBRep::Get(a[2]);
1302 if (aShape.IsNull())
1306 Standard_Boolean anUFaces = Standard_True;
1307 Standard_Boolean anUEdges = Standard_True;
1308 Standard_Boolean anConBS = Standard_False;
1309 Standard_Boolean isAllowInternal = Standard_False;
1310 Standard_Real aLinTol = Precision::Confusion();
1311 Standard_Real aAngTol = Precision::Angular();
1314 for ( int i = 3; i < n; i++ )
1316 if ( !strcmp(a[i], "-f"))
1317 anUFaces = Standard_False;
1318 else if (!strcmp(a[i], "-e"))
1319 anUEdges = Standard_False;
1320 else if (!strcmp(a[i], "+b"))
1321 anConBS = Standard_True;
1322 else if (!strcmp(a[i], "+i"))
1323 isAllowInternal = Standard_True;
1324 else if (!strcmp(a[i], "-t") || !strcmp(a[i], "-a"))
1328 (a[i-1][1] == 't' ? aLinTol : aAngTol) = Draw::Atof(a[i]);
1332 di << "value expected after " << a[i-1];
1338 Unifier().Initialize(aShape, anUEdges, anUFaces, anConBS);
1339 Unifier().AllowInternalEdges(isAllowInternal);
1340 Unifier().SetLinearTolerance(aLinTol);
1341 Unifier().SetAngularTolerance(aAngTol);
1343 TopoDS_Shape Result = Unifier().Shape();
1345 DBRep::Set(a[1], Result);
1349 Standard_Integer unifysamedomgen (Draw_Interpretor& di,
1354 di << "use unifysamedomgen newshape oldshape";
1357 TopoDS_Shape aShape;
1358 aShape=DBRep::Get(a[2]);
1359 if (aShape.IsNull()) {
1360 di<<" null shape is not allowed here\n";
1363 TopoDS_Shape ResShape = Unifier().Generated(aShape);
1364 if (ResShape.IsNull()) {
1365 di << " null shape\n";
1368 DBRep::Set(a[1], ResShape);
1374 static Standard_Integer copytranslate(Draw_Interpretor& di,
1375 Standard_Integer argc,
1379 di << "bad number of arguments. Should be: removeloc res shape dx dyy dz\n";
1382 TopoDS_Shape aShape = DBRep::Get(argv[2]);
1385 Standard_Real aDx = Draw::Atof(argv[3]);
1386 Standard_Real aDy = Draw::Atof(argv[4]);
1387 Standard_Real aDz = Draw::Atof(argv[5]);
1389 aTrsf.SetTranslation(gp_Vec(aDx, aDy, aDz));
1390 BRepBuilderAPI_Transform builderTransform(aTrsf);
1391 builderTransform.Perform (aShape, true);
1392 TopoDS_Shape aNewShape = builderTransform.Shape();
1393 DBRep::Set(argv[1],aNewShape);
1398 Standard_Integer reshape(Draw_Interpretor& di,
1404 di << "Error: wrong number of arguments. Type 'help " << a[0] << "'\n";
1408 TopoDS_Shape source = DBRep::Get(a[2]);
1409 if ( source.IsNull() )
1411 di << "Error: source shape ('" << a[2] << "') is null\n";
1415 Handle(BRepTools_ReShape) ReShaper = new BRepTools_ReShape;
1417 // Record the requested modifications
1418 for ( Standard_Integer i = 1; i < n; ++i )
1420 Standard_CString arg = a[i];
1421 TCollection_AsciiString opt(arg);
1424 if ( opt == "-replace" )
1428 di << "Error: not enough arguments for replacement\n";
1432 TopoDS_Shape what = DBRep::Get(a[++i]);
1433 if ( what.IsNull() )
1435 di << "Error: argument shape ('" << a[i] << "') is null\n";
1439 TopoDS_Shape with = DBRep::Get(a[++i]);
1440 if ( with.IsNull() )
1442 di << "Error: replacement shape ('" << a[i] << "') is null\n";
1446 ReShaper->Replace(what, with);
1448 else if ( opt == "-remove" )
1452 di << "Error: not enough arguments for removal\n";
1456 TopoDS_Shape what = DBRep::Get(a[++i]);
1457 if ( what.IsNull() )
1459 di << "Error: shape to remove ('" << a[i] << "') is null\n";
1463 ReShaper->Remove(what);
1467 // Apply all the recorded modifications
1468 TopoDS_Shape result = ReShaper->Apply(source);
1469 if ( result.IsNull() )
1471 di << "Error: result shape is null\n";
1475 DBRep::Set(a[1], result);
1479 //=======================================================================
1480 //function : InitCommands
1482 //=======================================================================
1484 void SWDRAW_ShapeUpgrade::InitCommands(Draw_Interpretor& theCommands)
1486 static Standard_Integer initactor = 0;
1487 if (initactor) return; initactor = 1;
1489 Standard_CString g = SWDRAW::GroupName(); // "Tests of DivideTool";
1491 theCommands.Add("DT_ShapeDivide",
1492 "DT_ShapeDivide Result Shape Tol: Divides shape with C1 Criterion",
1496 theCommands.Add("DT_SplitAngle",
1497 "DT_SplitAngle Result Shape [MaxAngle=95]: Divides revolved surfaces on segments less MaxAngle deg",
1501 theCommands.Add("DT_ShapeConvert",
1502 "DT_ShapeConvert Result Shape convert2d convert3d: Converts curves to beziers",
1506 theCommands.Add("DT_ShapeConvertRev",
1507 "DT_ShapeConvert Result Shape convert2d convert3d: Converts curves to beziers",
1509 DT_ShapeConvertRev,g);
1510 /* theCommands.Add("DT_PlaneDividedFace",
1511 "DT_PlaneDividedFace Result Face Tol: Transfer into a plane with boundary divided",
1513 DT_PlaneDividedFace,g);
1515 theCommands.Add("DT_PlaneGridShell",
1516 "DT_PlaneGridShell Result NbU NbV {UKnots} {VKnots} Tol : Create a plane grid Shell",
1518 DT_PlaneGridShell,g);
1520 theCommands.Add("DT_PlaneFaceCommon",
1521 "DT_PlaneFaceCommon Result Face Shell: Common between a plane Face and a Shell",
1523 DT_PlaneFaceCommon,g);*/
1525 theCommands.Add("DT_SplitCurve2d",
1526 "DT_SplitCurve2d Curve Tol: Splits the curve with C1 criterion",
1530 theCommands.Add("DT_SplitCurve",
1531 "DT_SplitCurve Curve Tol: Splits the curve with C1 criterion",
1535 theCommands.Add("DT_SplitSurface",
1536 "DT_SplitSurface Result Surface/GridSurf Tol: Splits the surface with C1 criterion",
1540 /*theCommands.Add("DT_SupportModification",
1541 "DT_SupportModification Result Shell Surface 2d3dFactor: Surface will support all the faces",
1543 DT_SupportModification,g);*/
1545 // theCommands.Add("DT_SpltWire","DT_SpltWire Result Wire Tol",
1546 // __FILE__,DT_SplitWire,g);
1548 // theCommands.Add("DT_SplitFace", "DT_SplitFace Result Face Tol",
1549 // __FILE__, DT_SplitFace,g);
1551 // theCommands.Add("DT_Debug", "DT_Debug 0/1 : activation/desactivation of the debug messages",
1552 // __FILE__, DT_Debug,g);
1553 // theCommands.Add ("shellsolid","option[a-b-c-f] shape result",
1554 // __FILE__,shellsolid,g);
1555 theCommands.Add ("offset2dcurve","result curve offset",
1556 __FILE__,offset2dcurve,g);
1558 theCommands.Add ("offsetcurve","result curve offset dir",
1559 __FILE__,offsetcurve,g);
1561 theCommands.Add ("splitface","result face [u usplit1 usplit2...] [v vsplit1 vsplit2 ...]",
1562 __FILE__,splitface,g);
1564 theCommands.Add ("DT_ToBspl","result shape [options=erop]",
1565 __FILE__,converttobspline,g);
1566 theCommands.Add ("DT_ClosedSplit","result shape",
1567 __FILE__,splitclosed,g);
1568 theCommands.Add ("DT_SplitByArea","result shape maxarea [preci]",
1569 __FILE__,splitarea,g);
1571 theCommands.Add ("RemoveIntWires","result minarea wholeshape [faces or wires] [moderemoveface ]",
1572 __FILE__,removeinternalwires,g);
1574 theCommands.Add ("removeloc","result shape",__FILE__,removeloc,g);
1576 theCommands.Add ("unifysamedom",
1577 "unifysamedom result shape [-f] [-e] [+b] [-i] [-t val] [-a val]", __FILE__,unifysamedom,g);
1579 theCommands.Add ("unifysamedomgen",
1580 "unifysamedomgen newshape oldshape : get new shape generated "
1581 "by unifysamedom command from the old one",
1582 __FILE__,unifysamedomgen,g);
1584 theCommands.Add ("copytranslate","result shape dx dy dz",__FILE__,copytranslate,g);
1586 theCommands.Add ("reshape",
1587 "\n Basic utility for topological modification: "
1588 "\n '-replace what with' Replaces 'what' sub-shape with 'with' sub-shape"
1589 "\n '-remove what' Removes 'what' sub-shape"
1590 "\n Requests '-replace' and '-remove' can be repeated many times.",
1591 __FILE__, reshape, g);