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 <BRep_Builder.hxx>
23 #include <BRepBuilderAPI.hxx>
24 #include <BRepBuilderAPI_Transform.hxx>
25 #include <BRepTools.hxx>
26 #include <BRepTools_ReShape.hxx>
29 #include <Draw_Interpretor.hxx>
30 #include <DrawTrSurf.hxx>
31 #include <Geom2d_Curve.hxx>
32 #include <Geom2d_OffsetCurve.hxx>
33 #include <Geom_Curve.hxx>
34 #include <Geom_OffsetCurve.hxx>
35 #include <Geom_Plane.hxx>
36 #include <Geom_RectangularTrimmedSurface.hxx>
37 #include <Geom_Surface.hxx>
38 #include <Precision.hxx>
39 #include <ShapeBuild_ReShape.hxx>
40 #include <ShapeCustom.hxx>
41 #include <ShapeExtend_CompositeSurface.hxx>
42 #include <ShapeFix.hxx>
43 #include <ShapeFix_ComposeShell.hxx>
44 #include <ShapeUpgrade.hxx>
45 #include <ShapeUpgrade_RemoveInternalWires.hxx>
46 #include <ShapeUpgrade_RemoveLocations.hxx>
47 #include <ShapeUpgrade_ShapeConvertToBezier.hxx>
48 #include <ShapeUpgrade_ShapeDivideAngle.hxx>
49 #include <ShapeUpgrade_ShapeDivideArea.hxx>
50 #include <ShapeUpgrade_ShapeDivideClosed.hxx>
51 #include <ShapeUpgrade_ShapeDivideContinuity.hxx>
52 #include <ShapeUpgrade_SplitCurve2dContinuity.hxx>
53 #include <ShapeUpgrade_SplitCurve3dContinuity.hxx>
54 #include <ShapeUpgrade_SplitSurfaceContinuity.hxx>
55 #include <ShapeUpgrade_UnifySameDomain.hxx>
57 #include <SWDRAW_ShapeUpgrade.hxx>
58 #include <TColGeom2d_HArray1OfCurve.hxx>
59 #include <TColGeom_HArray1OfCurve.hxx>
60 #include <TColGeom_HArray2OfSurface.hxx>
61 #include <TColStd_Array1OfReal.hxx>
62 #include <TColStd_HArray1OfReal.hxx>
63 #include <TColStd_HSequenceOfReal.hxx>
64 #include <TopExp_Explorer.hxx>
66 #include <TopoDS_Compound.hxx>
67 #include <TopoDS_Edge.hxx>
68 #include <TopoDS_Face.hxx>
69 #include <TopoDS_Iterator.hxx>
70 #include <TopoDS_Shape.hxx>
71 #include <TopoDS_Shell.hxx>
72 #include <TopoDS_Wire.hxx>
75 //#include <SWDRAW_ShapeUpgrade.hxx>
76 //#include <ShapeUpgrade_SupportModification.hxx>
77 //#include <ShapeExtend_WireData.hxx>
78 //#include <ShapeAnalysis_Shell.hxx>
79 //#include <ShapeAnalysis_WireOrder.hxx>
80 //#include <ShapeAnalysis_Wire.hxx>
81 //#include <ShapeUpgrade_ShellSewing.hxx>
82 // the plane (equation z=0) shared by PlaneDividedFaceContinuity and PlaneGridShell
83 //static Handle(Geom_Plane) ThePlane= new Geom_Plane(0,0,1,0);
84 //=======================================================================
85 //function : DT_ShapeDivide
87 //=======================================================================
88 static Standard_Integer DT_ShapeDivide (Draw_Interpretor& di,
89 Standard_Integer n, const char** a)
91 // DT_ShapeDivide result Shape Tol
93 // a[2]= input Face/Surface
94 // a[3] si n>3= Wire/Face
98 di << "bad number of arguments\n";
102 // try to read a shape:
103 TopoDS_Shape inputShape=DBRep::Get(a[2]);
104 if (inputShape.IsNull()) {
105 di << "Unknown shape\n";
108 // a[2] is a shape. managing:
109 // DT_ShapeDivide result Face Tol
111 // giving a face is available only in the constructor:
112 // we make the whole and quit.
113 ShapeUpgrade_ShapeDivideContinuity tool(inputShape);
115 // tolerance is optional
117 Standard_Real Tol=Draw::Atof(a[3]);
118 tool.SetTolerance(Tol);
121 // theTool.SetGlobalCriterion(GeomAbs_C1);
123 TopoDS_Shape res = tool.Result();
125 if ( tool.Status ( ShapeExtend_OK ) ) di << "Status: OK\n";
126 if ( tool.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1\n";
127 if ( tool.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2\n";
128 if ( tool.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3\n";
129 if ( tool.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4\n";
130 if ( tool.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5\n";
131 if ( tool.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6\n";
132 if ( tool.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7\n";
133 if ( tool.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8\n";
134 if ( tool.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1\n";
135 if ( tool.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2\n";
136 if ( tool.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3\n";
137 if ( tool.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4\n";
138 if ( tool.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5\n";
139 if ( tool.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6\n";
140 if ( tool.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7\n";
141 if ( tool.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8\n";
145 ShapeFix::SameParameter ( res, Standard_False );
147 DBRep::Set(a[1],res);
151 static Standard_Integer DT_ShapeConvertRev (Draw_Interpretor& di,
152 Standard_Integer n, const char** a)
155 di << "bad number of arguments\n";
159 // try to read a shape:
160 TopoDS_Shape inputShape=DBRep::Get(a[2]);
161 if (inputShape.IsNull()) {
162 di << "Unknown shape\n";
166 Standard_Integer c2d = Draw::Atoi(a[3]);
167 Standard_Integer c3d = Draw::Atoi(a[4]);
168 TopoDS_Shape revsh = ShapeCustom::ConvertToRevolution (inputShape);
169 if (revsh.IsNull()) { di<<"NO RESULT\n"; return 1; }
170 else if (revsh == inputShape) { di<<"No modif\n";}
171 else di<<"ConvertToRevolution -> Result : \n";
173 ShapeUpgrade_ShapeConvertToBezier tool(revsh);
174 tool.SetSurfaceConversion(Standard_True);
176 tool.Set2dConversion(Standard_True);
178 tool.Set3dConversion(Standard_True);
180 tool.Set3dLineConversion(Standard_False);
182 tool.Set3dCircleConversion(Standard_False);
184 tool.Set3dConicConversion(Standard_False);
187 TopoDS_Shape res = tool.Result();
189 if ( tool.Status ( ShapeExtend_OK ) ) di << "Status: OK\n";
190 if ( tool.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1\n";
191 if ( tool.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2\n";
192 if ( tool.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3\n";
193 if ( tool.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4\n";
194 if ( tool.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5\n";
195 if ( tool.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6\n";
196 if ( tool.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7\n";
197 if ( tool.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8\n";
198 if ( tool.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1\n";
199 if ( tool.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2\n";
200 if ( tool.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3\n";
201 if ( tool.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4\n";
202 if ( tool.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5\n";
203 if ( tool.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6\n";
204 if ( tool.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7\n";
205 if ( tool.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8\n";
209 ShapeFix::SameParameter ( res, Standard_False );
211 DBRep::Set(a[1],res);
217 if (!inputShape.IsNull()) {
218 // a[2] is a shape. managing:
219 // DT_ShapeDivide result Face Tol
221 TopoDS_Face inputFace = TopoDS::Face(inputShape);
222 if (inputFace.IsNull()) {
223 di << a[2] << " is not a face\n";
227 // giving a face is available only in the constructor:
228 // we make the whole and quit.
229 ShapeUpgrade_ShapeDivideContinuity theTool(inputFace);
231 // tolerance is optional
233 Standard_Real Tol=Draw::Atof(a[n-1]);
234 theTool.SetTolerance(Tol);
237 theTool.SetGlobalCriterion(GeomAbs_C1);
239 if (!theTool.IsDone()) {
240 ShapeUpgrade_Error theError=theTool.Error();
241 di << "Not done: error=";
242 if (theError==ShapeUpgrade_Done)
244 else if (theError==ShapeUpgrade_NotDone)
246 else if (theError==ShapeUpgrade_EmptyShell)
247 di << "EmptyShell\n";
248 else if (theError==ShapeUpgrade_InvalidCriterion)
249 di << "InvalidCriterion\n";
250 else if (theError==ShapeUpgrade_InvalidGridSurface)
251 di << "InvalidGridSurface\n";
252 else if (theError==ShapeUpgrade_DegeneratedEdge)
253 di << "DegeneratedEdge\n";
254 else if (theError==ShapeUpgrade_NoSurface)
256 else if (theError==ShapeUpgrade_NoTolerance)
257 di << "NoTolerance\n";
260 TopoDS_Shell res = theTool.Shell();
261 DBRep::Set(a[1],res);
266 // not a face: we can use the empty consturctor.
267 ShapeUpgrade_ShapeDivideContinuity theTool;
268 Standard_Real Tol=Draw::Atof(a[n-1]);
269 theTool.SetTolerance(Tol);
270 theTool.SetGlobalCriterion(GeomAbs_C1);
272 // try to read a surface:
273 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[2]);
275 // a[2] is a surface. managing the configurations:
276 // DT_ShapeDivide result Surface Tol
277 // DT_ShapeDivide result Surface Face Tol
278 // DT_ShapeDivide result Surface Wire Surf Tol
280 theTool.SetSupport(GS);
282 // try to read a Wire or a Face:
284 TopoDS_Shape inputBoundary=DBRep::Get(a[3]);
285 if (inputBoundary.IsNull()) {
286 di << "Invalid Boundary\n";
289 TopoDS_Wire WireBoundary = TopoDS::Wire(inputBoundary);
290 if (!WireBoundary.IsNull()) {
291 // DT_ShapeDivide result Surface Wire Surf Tol
292 Handle(Geom_Surface) WireSupport = DrawTrSurf::GetSurface(a[4]);
293 if (WireSupport.IsNull()) {
294 di << "Invalid Surface supporting the Wire\n";
297 theTool.SetBoundary(WireBoundary, WireSupport);
300 TopoDS_Face FaceBoundary = TopoDS::Face(inputBoundary);
301 // DT_ShapeDivide result Surface Face Tol
302 theTool.SetBoundary(FaceBoundary);
307 // it must be a grid: managing the configurations:
308 // DT_ShapeDivide result NbU NbV {Surf_u_v...} Tol
309 // DT_ShapeDivide result NbU NbV {Surf_u_v...} Face Tol
310 // DT_ShapeDivide result NbU NbV {Surf_u_v...} Wire Surf Tol
312 di << "bad number of arguments for grid input\n";
316 Standard_Integer NbU=Draw::Atoi(a[2]);
317 Standard_Integer NbV=Draw::Atoi(a[3]);
318 if (n < 4+NbU*NbV+1) {
319 di << "bad number of arguments\n";
323 Handle(TColGeom_HArray2OfSurface)
324 TheGridSurf= new TColGeom_HArray2OfSurface(1,NbU,1,NbV);
326 for (Standard_Integer iu=1; iu<=NbU; iu++) {
327 for (Standard_Integer jv=1; jv<=NbV; jv++) {
328 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[4+(iu-1)*NbV+jv-1]);
329 TheGridSurf->SetValue(iu,jv,GS);
332 theTool.SetSupport(TheGridSurf,Tol);
334 // try to read a Wire or a Face:
336 TopoDS_Shape inputBoundary=DBRep::Get(a[4+NbU*NbV]);
337 if (inputBoundary.IsNull()) {
338 di << "Invalid Boundary\n";
341 TopoDS_Wire WireBoundary = TopoDS::Wire(inputBoundary);
342 if (!WireBoundary.IsNull()) {
343 // DT_ShapeDivide result Surface Wire Surf Tol
344 Handle(Geom_Surface) WireSupport = DrawTrSurf::GetSurface(a[4+NbU*NbV+1]);
345 if (WireSupport.IsNull()) {
346 di << "Invalid Surface supporting the Wire\n";
349 theTool.SetBoundary(WireBoundary, WireSupport);
352 TopoDS_Face FaceBoundary = TopoDS::Face(inputBoundary);
353 // DT_ShapeDivide result Surface Face Tol
354 theTool.SetBoundary(FaceBoundary);
360 if (!theTool.IsDone()) {
361 ShapeUpgrade_Error theError=theTool.Error();
362 di << "Not done: error=";
363 if (theError==ShapeUpgrade_Done)
365 else if (theError==ShapeUpgrade_NotDone)
367 else if (theError==ShapeUpgrade_EmptyShell)
368 di << "EmptyShell\n";
369 else if (theError==ShapeUpgrade_InvalidCriterion)
370 di << "InvalidCriterion\n";
371 else if (theError==ShapeUpgrade_InvalidGridSurface)
372 di << "InvalidGridSurface\n";
373 else if (theError==ShapeUpgrade_DegeneratedEdge)
374 di << "DegeneratedEdge\n";
375 else if (theError==ShapeUpgrade_NoSurface)
377 else if (theError==ShapeUpgrade_NoTolerance)
378 di << "NoTolerance\n";
382 TopoDS_Shell res = theTool.Shell();
383 DBRep::Set(a[1],res);
389 static Standard_Integer DT_ShapeConvert (Draw_Interpretor& di,
390 Standard_Integer n, const char** a)
393 di << "bad number of arguments\n";
397 // try to read a shape:
398 TopoDS_Shape inputShape=DBRep::Get(a[2]);
399 if (inputShape.IsNull()) {
400 di << "Unknown shape\n";
404 Standard_Integer c2d = Draw::Atoi(a[3]);
405 Standard_Integer c3d = Draw::Atoi(a[4]);
407 ShapeUpgrade_ShapeConvertToBezier tool(inputShape);
408 tool.SetSurfaceConversion(Standard_True);
410 tool.Set2dConversion(Standard_True);
412 tool.Set3dConversion(Standard_True);
414 TopoDS_Shape res = tool.Result();
416 if ( tool.Status ( ShapeExtend_OK ) ) di << "Status: OK\n";
417 if ( tool.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1\n";
418 if ( tool.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2\n";
419 if ( tool.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3\n";
420 if ( tool.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4\n";
421 if ( tool.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5\n";
422 if ( tool.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6\n";
423 if ( tool.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7\n";
424 if ( tool.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8\n";
425 if ( tool.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1\n";
426 if ( tool.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2\n";
427 if ( tool.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3\n";
428 if ( tool.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4\n";
429 if ( tool.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5\n";
430 if ( tool.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6\n";
431 if ( tool.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7\n";
432 if ( tool.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8\n";
436 ShapeFix::SameParameter ( res, Standard_False );
438 DBRep::Set(a[1],res);
441 static Standard_Integer DT_SplitAngle(Draw_Interpretor& di,
442 Standard_Integer n, const char** a)
445 di << "bad number of arguments\n";
449 TopoDS_Shape inputShape=DBRep::Get(a[2]);
450 if (inputShape.IsNull()) {
451 di << "Unknown shape\n";
455 Standard_Real maxangle = 95;
457 maxangle = Draw::Atof ( a[3] );
458 if ( maxangle <1 ) maxangle = 1;
461 ShapeUpgrade_ShapeDivideAngle tool(maxangle * M_PI/180,inputShape);
463 TopoDS_Shape res = tool.Result();
465 if ( tool.Status ( ShapeExtend_OK ) ) di << "Status: OK\n";
466 if ( tool.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1\n";
467 if ( tool.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2\n";
468 if ( tool.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3\n";
469 if ( tool.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4\n";
470 if ( tool.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5\n";
471 if ( tool.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6\n";
472 if ( tool.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7\n";
473 if ( tool.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8\n";
474 if ( tool.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1\n";
475 if ( tool.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2\n";
476 if ( tool.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3\n";
477 if ( tool.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4\n";
478 if ( tool.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5\n";
479 if ( tool.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6\n";
480 if ( tool.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7\n";
481 if ( tool.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8\n";
485 ShapeFix::SameParameter ( res, Standard_False );
487 DBRep::Set(a[1],res);
492 //=======================================================================
493 //function : DT_PlaneDividedFace
494 //purpose : Transfer into a plane with boundary divided
497 //=======================================================================
498 static Standard_Integer DT_PlaneDividedFace (Draw_Interpretor& di,
499 Standard_Integer n, const char** a)
507 di << "bad number of arguments\n";
511 Standard_Real Tol=Draw::Atof(a[3]);
512 TopoDS_Shape inputShape=DBRep::Get(a[2]);
513 TopoDS_Face inputFace = TopoDS::Face(inputShape);
514 if (inputFace.IsNull()) {
515 di << a[2] << " is not a face\n";
519 ShapeUpgrade_PlaneDividedFace theTool(ThePlane);
520 theTool.Init(inputFace);
521 //theTool.SetBoundaryCriterion(GeomAbs_C1);
522 //theTool.SetTolerance(Tol);
524 if (!theTool.IsDone()) {
529 TopoDS_Face res = theTool.Face();
530 DBRep::Set(a[1],res);
532 Standard_Real the2d3dFactor=theTool.Get2d3dFactor();
533 di << "2d3dFactor="<<the2d3dFactor<< "\n";
537 //=======================================================================
538 //function : DT_PlaneGridShell
539 //purpose : Create a Plane Grid Shell from U and V knots
542 //=======================================================================
543 static Standard_Integer DT_PlaneGridShell (Draw_Interpretor& di,
544 Standard_Integer n, const char** a)
553 // a[4+NbU...] = {VKnots}
554 // a[4+NbU+NbV+1] = Tol
557 Standard_Integer NbU=Draw::Atoi(a[2]);
558 Standard_Integer NbV=Draw::Atoi(a[3]);
559 if (n != 4+NbU+NbV+1) {
560 di << "bad number of arguments\n";
564 TColStd_Array1OfReal TheUKnots(1,NbU);
565 TColStd_Array1OfReal TheVKnots(1,NbV);
567 for (Standard_Integer ii=1; ii<=NbU; ii++) {
568 TheUKnots(ii)=Draw::Atof(a[4+ii-1]);
570 for (ii=1; ii<=NbV; ii++) {
571 TheVKnots(ii)=Draw::Atof(a[4+NbU+ii-1]);
574 Standard_Real Tol=Draw::Atof(a[4+NbU+NbV]);
576 ShapeUpgrade_PlaneGridShell TheGrid(ThePlane,TheUKnots,TheVKnots,Tol);
578 TopoDS_Shell res = TheGrid.Shell();
579 DBRep::Set(a[1],res);
584 //=======================================================================
585 //function : DT_PlaneFaceCommon
586 //purpose : Common between a plane Face and a Shell whose all Faces are
587 // laying in the same plane
590 //=======================================================================
591 static Standard_Integer DT_PlaneFaceCommon (Draw_Interpretor& di,
592 Standard_Integer n, const char** a)
600 di << "bad number of arguments\n";
604 TopoDS_Shape inputShape= DBRep::Get(a[2]);
605 TopoDS_Face inputFace = TopoDS::Face(inputShape);
606 if (inputFace.IsNull()) {
607 di << a[2] << " is not a face\n";
611 inputShape = DBRep::Get(a[3]);
612 TopoDS_Shell inputShell = TopoDS::Shell(inputShape);
613 if (inputShell.IsNull()) {
614 di << a[3] << " is not a shell\n";
618 ShapeUpgrade_PlaneFaceCommon theTool;
619 theTool.Init(inputFace,inputShell);
621 TopoDS_Shell res = theTool.Shell();
622 DBRep::Set(a[1],res);
627 //=======================================================================
628 //function : DT_SplitCurve
629 //purpose : Splits the curve with C1 criterion
632 //=======================================================================
633 static Standard_Integer DT_SplitCurve (Draw_Interpretor& di,
634 Standard_Integer n, const char** a)
637 // a[1]= input curve. This name is used with a suffix to name the output curves
641 di << "bad number of arguments\n";
645 Standard_Real Tol=Draw::Atof(a[2]);
646 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(a[1]);
647 if ( GC.IsNull()) return 1;
648 Standard_Integer Split = Draw::Atoi(a[3]);
649 Handle(ShapeUpgrade_SplitCurve3dContinuity) theTool = new ShapeUpgrade_SplitCurve3dContinuity;
651 theTool->SetTolerance (Tol);
652 theTool->SetCriterion (GeomAbs_C1);
654 Handle(TColStd_HSequenceOfReal) spval = new TColStd_HSequenceOfReal;
655 for(Standard_Integer i = 1; i<=5; i++) spval->Append(i);
656 theTool->SetSplitValues(spval);
658 theTool->Perform (Standard_True);
659 Handle(TColGeom_HArray1OfCurve) theCurves= theTool->GetCurves();
660 Standard_Integer NbC=theCurves->Length();
661 for (Standard_Integer icurv=1; icurv<=NbC; icurv++) {
663 Sprintf(name,"%s%s%d",a[1],"_",icurv);
664 char* newname = name;
665 DrawTrSurf::Set(newname, theCurves->Value(icurv));
666 di.AppendElement(newname);
672 //=======================================================================
673 //function : DT_SplitCurve2d
674 //purpose : Splits the curve with C1 criterion
677 //=======================================================================
678 static Standard_Integer DT_SplitCurve2d (Draw_Interpretor& di,
679 Standard_Integer n, const char** a)
682 // a[1]= input 2d curve. This name is used with a suffix to name the output curves
686 di << "bad number of arguments\n";
690 Standard_Real Tol=Draw::Atof(a[2]);
691 Handle(Geom2d_Curve) GC = DrawTrSurf::GetCurve2d(a[1]);
692 if ( GC.IsNull()) return 1;
693 Standard_Integer Split = Draw::Atoi(a[3]);
694 Handle(ShapeUpgrade_SplitCurve2dContinuity) theTool = new ShapeUpgrade_SplitCurve2dContinuity;
696 theTool->SetTolerance (Tol);
697 theTool->SetCriterion (GeomAbs_C1);
699 Handle(TColStd_HSequenceOfReal) spval = new TColStd_HSequenceOfReal;
700 for(Standard_Integer i = 1; i<=5; i++) spval->Append(i);
701 theTool->SetSplitValues(spval);
703 theTool->Perform (Standard_True);
704 Handle(TColGeom2d_HArray1OfCurve) theCurves= theTool->GetCurves();
705 Standard_Integer NbC=theCurves->Length();
706 for (Standard_Integer icurv=1; icurv<=NbC; icurv++) {
708 Sprintf(name,"%s%s%d",a[1],"_",icurv);
709 char* newname = name;
710 DrawTrSurf::Set(newname, theCurves->Value(icurv));
711 di.AppendElement(newname);
717 //=======================================================================
718 //function : DT_SplitSurface
719 //purpose : Splits the surface with C1 criterion
722 //=======================================================================
724 static Standard_Integer DT_SplitWire (Draw_Interpretor& di,
725 Standard_Integer n, const char** a)
729 di << "bad number of arguments\n";
733 TopoDS_Face source = TopoDS::Face(DBRep::Get(a[2]));
734 if(source.IsNull()) {
735 di <<"Shape is not face\n";
738 TopoDS_Iterator wi(source);
740 di <<"Shape is face without wire\n";
744 TopoDS_Wire wire = TopoDS::Wire(wi.Value());
745 Handle(ShapeUpgrade_WireDivideContinuity) tool = new ShapeUpgrade_WireDivideContinuity;
746 tool->Init(wire,source);
748 Standard_Real Tol=Draw::Atof(a[3]);
750 Handle(ShapeBuild_ReShape) context = new ShapeBuild_ReShape;
751 tool->Perform(context);
752 TopoDS_Wire result = tool->Wire();
753 DBRep::Set(a[1],result);
758 static Standard_Integer DT_SplitFace (Draw_Interpretor& di,
759 Standard_Integer n, const char** a)
763 di << "bad number of arguments\n";
767 TopoDS_Face source = TopoDS::Face(DBRep::Get(a[2]));
768 if(source.IsNull()) {
769 di <<"Shape is not face\n";
772 Handle(ShapeUpgrade_ShapeDivideContinuity) tool = new ShapeUpgrade_FaceDivideContinuity;
775 Standard_Real Tol=Draw::Atof(a[3]);
776 tool->SetPrecision(Tol);
779 Handle(ShapeBuild_ReShape) context = new ShapeBuild_ReShape;
780 tool->Perform(context);
781 TopoDS_Shape result = tool->Result();
784 if ( tool->Status ( ShapeExtend_OK ) ) di << "Status: OK\n";
785 if ( tool->Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1\n";
786 if ( tool->Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2\n";
787 if ( tool->Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3\n";
788 if ( tool->Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4\n";
789 if ( tool->Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5\n";
790 if ( tool->Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6\n";
791 if ( tool->Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7\n";
792 if ( tool->Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8\n";
793 if ( tool->Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1\n";
794 if ( tool->Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2\n";
795 if ( tool->Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3\n";
796 if ( tool->Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4\n";
797 if ( tool->Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5\n";
798 if ( tool->Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6\n";
799 if ( tool->Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7\n";
800 if ( tool->Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8\n";
804 ShapeFix::SameParameter ( result, Standard_False );
806 DBRep::Set(a[1],result);
811 static Standard_Integer DT_SplitSurface (Draw_Interpretor& di,
812 Standard_Integer n, const char** a)
815 // a[1]= result (used with a suffix to name the output surfaces)
816 // a[2]= input surface.
822 // a[3+1]..a[3+nbU*nbV] = Input Surfaces
823 // a[4+nbU*nbV]= Tolerance
826 di << "bad number of arguments\n";
830 Handle(ShapeUpgrade_SplitSurfaceContinuity) theTool = new ShapeUpgrade_SplitSurfaceContinuity;//S4137
832 Standard_Real Tol=Draw::Atof(a[3]);
833 Standard_Integer Split = Draw::Atoi(a[4]);
834 theTool->SetTolerance(Tol);
835 theTool->SetCriterion(GeomAbs_C1);
836 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[2]);
839 // Case of composite grid surface
840 di << "composite surf\n";
841 Standard_Integer nbU=Draw::Atoi(a[2]);
842 Standard_Integer nbV=Draw::Atoi(a[3]);
843 if (nbU==0 || nbV==0) return 1;
844 Handle(TColGeom_HArray2OfSurface)
845 theGrid= new TColGeom_HArray2OfSurface(1,nbU,1,nbV);
846 for (Standard_Integer iu=1; iu<=nbU; iu++) {
847 for (Standard_Integer iv=1; iv<=nbV; iv++) {
848 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[3+(iu-1)*nbV+iv]);
849 theGrid->SetValue(iu,iv,GS);
852 di << "appel a SplitSurface::Init\n";
853 theTool->Init(theGrid);
856 // Case of single surface
857 di << "single surf\n";
859 di << "appel a SplitSurface::Init\n";
862 Handle(TColStd_HSequenceOfReal) spval = new TColStd_HSequenceOfReal;
863 for(Standard_Integer i = 1; i<=5; i++) spval->Append(i);
864 theTool->SetUSplitValues(spval);
865 theTool->SetVSplitValues(spval);
868 di << "appel a SplitSurface::Build\n";
869 theTool->Build(Standard_True);
871 di << "appel a SplitSurface::GlobalU/VKnots\n";
872 Handle(ShapeExtend_CompositeSurface) Grid = theTool->ResSurfaces();
873 Handle(TColStd_HArray1OfReal) GlobalU=Grid->UJointValues();
874 Handle(TColStd_HArray1OfReal) GlobalV=Grid->VJointValues();
875 Standard_Integer nbGlU=GlobalU->Length();
876 Standard_Integer nbGlV=GlobalV->Length();
877 di << "nb GlobalU ; nb GlobalV="<<nbGlU<<" "<<nbGlV;
878 for (Standard_Integer iu=1; iu<=nbGlU; iu++)
879 di <<" "<< GlobalU->Value(iu);
881 // di << "nb GlobalV="<<nbGlV;
882 for (Standard_Integer iv=1; iv<=nbGlV; iv++)
883 di <<" "<< GlobalV->Value(iv);
886 di << "appel a Surfaces\n";
887 Handle(TColGeom_HArray2OfSurface) theSurfaces= Grid->Patches();
889 di << "transfert resultat\n";
890 Standard_Integer NbRow=theSurfaces->ColLength();
891 Standard_Integer NbCol=theSurfaces->RowLength();
892 for (Standard_Integer irow=1; irow<=NbRow; irow++) {
893 for (Standard_Integer icol=1; icol<=NbCol; icol++) {
895 Sprintf(name,"%s%s%d%s%d",a[1],"_",irow,"_",icol);
896 char* newname = name;
897 DrawTrSurf::Set(newname, theSurfaces->Value(irow, icol));
898 di.AppendElement(newname);
905 //=======================================================================
906 //function : offset2dcurve
909 //=======================================================================
910 static Standard_Integer offset2dcurve
911 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
914 di<<"result + curve + offset\n";
916 return 1 /* Error */;
918 // Standard_CString arg1 = argv[1];
919 // Standard_CString arg2 = argv[2];
920 Standard_Real Offset = Draw::Atof(argv[3]);
921 Handle(Geom2d_Curve) GC = DrawTrSurf::GetCurve2d(argv[2]);
922 if ( GC.IsNull()) return 1;
923 Handle(Geom2d_OffsetCurve) offcrv = new Geom2d_OffsetCurve(GC,Offset);
924 DrawTrSurf::Set(argv[1], offcrv);
928 //=======================================================================
929 //function : offsetcurve
932 //=======================================================================
933 static Standard_Integer offsetcurve
934 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
937 di<<"result + curve + offset + Dir\n";
939 return 1 /* Error */;
941 // Standard_CString arg1 = argv[1];
942 // Standard_CString arg2 = argv[2];
943 Standard_Real Offset = Draw::Atof(argv[3]);
944 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(argv[2]);
945 if ( GC.IsNull()) return 1;
947 DrawTrSurf::GetPoint(argv[4],point);
948 gp_Dir dir(point.XYZ());
949 Handle(Geom_OffsetCurve) offcrv = new Geom_OffsetCurve(GC,Offset,dir);
950 DrawTrSurf::Set(argv[1], offcrv);
954 //=======================================================================
955 //function : compose shell
957 //=======================================================================
958 static Standard_Integer splitface
959 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
962 di << "Split face: splitface result face [u usplit1 usplit2...] [v vsplit1 vsplit2 ...]\n";
966 TopoDS_Shape aLocalShape = DBRep::Get(argv[2]) ;
967 TopoDS_Face face = TopoDS::Face ( aLocalShape );
968 if ( face.IsNull() ) {
969 di << argv[2] << " is not Face\n";
973 Handle(Geom_Surface) S = BRep_Tool::Surface ( face );
974 Standard_Real Uf, Ul, Vf, Vl;
975 BRepTools::UVBounds ( face, Uf, Ul, Vf, Vl );
976 Standard_Real Umin, Umax, Vmin, Vmax;
977 S->Bounds ( Umin, Umax, Vmin, Vmax );
978 if ( Uf < Umin && ! S->IsUPeriodic() ) Uf = Umin;
979 else if ( Uf > Umin ) {
980 if ( Precision::IsInfinite(Umin) ) Uf -= 100;
983 if ( Vf < Vmin && ! S->IsVPeriodic() ) Vf = Vmin;
984 else if ( Vf > Vmin ) {
985 if ( Precision::IsInfinite(Vmin) ) Vf -= 100;
988 if ( Ul > Umax && ! S->IsUPeriodic() ) Ul = Umax;
989 else if ( Ul < Umax ) {
990 if ( Precision::IsInfinite(Umax) ) Ul += 100;
993 if ( Vl > Vmax && ! S->IsVPeriodic() ) Vl = Vmax;
994 else if ( Vl < Vmax ) {
995 if ( Precision::IsInfinite(Vmax) ) Vl += 100;
999 TColStd_SequenceOfReal uval;
1000 TColStd_SequenceOfReal vval;
1002 Standard_Boolean byV = Standard_False;
1003 Standard_Integer i; // svv Jan11 2000 : porting on DEC
1004 for ( i=3; i < argc; i++ ) {
1005 if ( argv[i][0] == 'u' ) byV = Standard_False;
1006 else if ( argv[i][0] == 'v' ) byV = Standard_True;
1008 Standard_Real val = Draw::Atof ( argv[i] );
1009 TColStd_SequenceOfReal &vals = ( byV ? vval : uval );
1010 if ( vals.Length() >0 && val - vals.Last() < Precision::PConfusion() ) {
1011 di << "Values should be sorted in increasing order; skipped\n";
1014 if ( ( byV && ( val < Vf+Precision::PConfusion() ||
1015 val > Vl-Precision::PConfusion() ) ) ||
1016 (!byV && ( val < Uf+Precision::PConfusion() ||
1017 val > Ul-Precision::PConfusion() ) ) ) {
1018 di << "Values should be inside range of surface; skipped\n";
1021 vals.Append ( val );
1024 if ( uval.Length() <1 && vval.Length() <1 ) {
1025 di << "No splitting defined\n";
1028 if ( uval.Length() >0 ) {
1029 di << "Splitting by U: ";
1030 for ( Standard_Integer j=1; j <= uval.Length(); j++ ) {
1031 //cout << ( i >j ? ", " : "" ) << uval(j);
1041 if ( vval.Length() >0 ) {
1042 di << "Splitting by V: ";
1043 for ( Standard_Integer j=1; j <= vval.Length(); j++ ) {
1044 //cout << ( j >1 ? ", " : "" ) << vval(j);
1055 Handle(TColGeom_HArray2OfSurface) AS = new TColGeom_HArray2OfSurface ( 1, uval.Length()+1,
1056 1, vval.Length()+1 );
1057 for ( i=0; i <= uval.Length(); i++ ) {
1058 Standard_Real umin = ( i ? uval(i) : Uf );
1059 Standard_Real umax = ( i < uval.Length() ? uval(i+1) : Ul );
1060 for ( Standard_Integer j=0; j <= vval.Length(); j++ ) {
1061 Standard_Real vmin = ( j ? vval(j) : Vf );
1062 Standard_Real vmax = ( j < vval.Length() ? vval(j+1) : Vl );
1063 Handle(Geom_RectangularTrimmedSurface) rect =
1064 new Geom_RectangularTrimmedSurface ( S, umin, umax, vmin, vmax );
1065 AS->SetValue ( i+1, j+1, rect );
1069 Handle(ShapeExtend_CompositeSurface) Grid = new ShapeExtend_CompositeSurface;
1070 if ( ! Grid->Init ( AS ) ) di << "Grid badly connected!\n";
1072 ShapeFix_ComposeShell SUCS;
1074 SUCS.Init ( Grid, l, face, Precision::Confusion() );
1075 Handle(ShapeBuild_ReShape) RS = new ShapeBuild_ReShape;
1076 SUCS.SetContext( RS );
1079 if ( SUCS.Status ( ShapeExtend_OK ) ) di << "Status: OK\n";
1080 if ( SUCS.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1\n";
1081 if ( SUCS.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2\n";
1082 if ( SUCS.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3\n";
1083 if ( SUCS.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4\n";
1084 if ( SUCS.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5\n";
1085 if ( SUCS.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6\n";
1086 if ( SUCS.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7\n";
1087 if ( SUCS.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8\n";
1088 if ( SUCS.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1\n";
1089 if ( SUCS.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2\n";
1090 if ( SUCS.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3\n";
1091 if ( SUCS.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4\n";
1092 if ( SUCS.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5\n";
1093 if ( SUCS.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6\n";
1094 if ( SUCS.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7\n";
1095 if ( SUCS.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8\n";
1097 TopoDS_Shape sh = SUCS.Result();
1098 ShapeFix::SameParameter ( sh, Standard_False );
1099 DBRep::Set ( argv[1], sh );
1103 static Standard_Integer converttobspline
1104 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1107 di << "Use: " << argv[0] << " result shape [options=ero]\n";
1108 di << "where options is combination of letters indicating kinds of\n";
1109 di << "surfaces to be converted:\n";
1110 di << "e - extrusion\n";
1111 di << "r - revolution\n";
1112 di << "o - offset\n";
1116 const char *options = ( argc > 3 ? argv[3] : "ero" );
1118 TopoDS_Shape inputShape=DBRep::Get(argv[2]);
1119 if (inputShape.IsNull()) {
1120 di << "Unknown shape\n";
1123 TopoDS_Shape revsh = ShapeCustom::ConvertToRevolution (inputShape);
1125 ShapeCustom::ConvertToBSpline (revsh, strchr (options, 'e') != 0,
1126 strchr (options, 'r') != 0,
1127 strchr (options, 'o') != 0,
1128 strchr (options, 'p') != 0);
1129 ShapeFix::SameParameter ( res, Standard_False );
1130 DBRep::Set ( argv[1], res );
1135 static Standard_Integer splitclosed (Draw_Interpretor& di,
1136 Standard_Integer argc,
1140 di << "bad number of arguments\n";
1144 TopoDS_Shape inputShape=DBRep::Get(argv[2]);
1145 if (inputShape.IsNull()) {
1146 di << "Unknown shape\n";
1150 ShapeUpgrade_ShapeDivideClosed tool (inputShape);
1152 TopoDS_Shape res = tool.Result();
1154 ShapeFix::SameParameter ( res, Standard_False );
1155 DBRep::Set ( argv[1], res );
1159 static Standard_Integer splitarea (Draw_Interpretor& di,
1160 Standard_Integer argc,
1164 di << "bad number of arguments\n";
1168 TopoDS_Shape inputShape=DBRep::Get(argv[2]);
1169 if (inputShape.IsNull()) {
1170 di << "Unknown shape\n";
1173 Standard_Real aMaxArea = Draw::Atof(argv[3]);
1176 ShapeUpgrade_ShapeDivideArea tool (inputShape);
1178 Standard_Real prec = Draw::Atof(argv[4]);
1179 tool.SetPrecision(prec);
1181 tool.MaxArea() = aMaxArea;
1183 TopoDS_Shape res = tool.Result();
1185 ShapeFix::SameParameter ( res, Standard_False );
1186 DBRep::Set ( argv[1], res );
1190 static Standard_Integer removeinternalwires (Draw_Interpretor& di,
1191 Standard_Integer argc,
1195 di << "bad number of arguments\n";
1198 Standard_Real aMinArea = Draw::Atof(argv[2]);
1199 TopoDS_Shape inputShape=DBRep::Get(argv[3]);
1200 if (inputShape.IsNull()) {
1201 di << "Unknown shape\n";
1204 Handle(ShapeUpgrade_RemoveInternalWires) aTool;
1205 TopTools_SequenceOfShape aSeqShapes;
1206 if(inputShape.ShapeType() < TopAbs_WIRE)
1207 aTool = new ShapeUpgrade_RemoveInternalWires(inputShape);
1209 di<<"Invalid type of first shape: should be FACE,SHELL,SOLID or COMPOUND\n";
1213 Standard_Integer k = 4;
1214 Standard_Boolean isShape = Standard_True;
1215 Standard_Boolean aModeRemoveFaces =Standard_True;
1218 for( ; k < argc; k++) {
1220 TopoDS_Shape aShape=DBRep::Get(argv[k]);
1221 isShape = !aShape.IsNull();
1223 if(aShape.ShapeType() == TopAbs_FACE || aShape.ShapeType() == TopAbs_WIRE)
1224 aSeqShapes.Append(aShape);
1228 aModeRemoveFaces = (Draw::Atoi(argv[k]) == 1);
1231 aTool->MinArea() = aMinArea;
1232 aTool->RemoveFaceMode() = aModeRemoveFaces;
1233 if(aSeqShapes.Length())
1234 aTool->Perform(aSeqShapes);
1237 if(aTool->Status(ShapeExtend_FAIL1))
1238 di<<"Initial shape has invalid type\n";
1239 else if(aTool->Status(ShapeExtend_FAIL2))
1240 di<<"Specified sub-shape is not belonged to whole shape\n";
1241 if(aTool->Status(ShapeExtend_DONE1)) {
1242 const TopTools_SequenceOfShape& aRemovedWires =aTool->RemovedWires();
1243 di<<aRemovedWires.Length()<<" internal wires were removed\n";
1246 if(aTool->Status(ShapeExtend_DONE2)) {
1247 const TopTools_SequenceOfShape& aRemovedFaces =aTool->RemovedFaces();
1248 di<<aRemovedFaces.Length()<<" small faces were removed\n";
1251 TopoDS_Shape res = aTool->GetResult();
1254 DBRep::Set ( argv[1], res );
1258 static Standard_Integer removeloc (Draw_Interpretor& di,
1259 Standard_Integer argc,
1263 di << "bad number of arguments. Should be: removeloc res shape [remove_level(see ShapeEnum)]\n";
1267 TopoDS_Shape aShape = DBRep::Get(argv[2]);
1270 ShapeUpgrade_RemoveLocations aRemLoc;
1272 aRemLoc.SetRemoveLevel((TopAbs_ShapeEnum)Draw::Atoi(argv[3]));
1273 aRemLoc.Remove(aShape);
1274 TopoDS_Shape aNewShape = aRemLoc.GetResult();
1276 DBRep::Set(argv[1],aNewShape);
1280 static ShapeUpgrade_UnifySameDomain& Unifier() {
1281 static ShapeUpgrade_UnifySameDomain sUnifier;
1285 //=======================================================================
1287 //=======================================================================
1288 static Standard_Integer unifysamedom(Draw_Interpretor& di, Standard_Integer n, const char** a)
1292 di << "Use unifysamedom result shape [s1 s2 ...] [-f] [-e] [+b] [+i] [-t val] [-a val]\n";
1294 di << "s1 s2 ... to keep the given edges during unification of faces\n";
1295 di << "-f to switch off 'unify-faces' mode \n";
1296 di << "-e to switch off 'unify-edges' mode\n";
1297 di << "+b to switch on 'concat bspline' mode\n";
1298 di << "+i to switch on 'allow internal edges' mode\n";
1299 di << "-t val to set linear tolerance\n";
1300 di << "-a val to set angular tolerance\n";
1301 di << "'unify-faces' and 'unify-edges' modes are switched on by default";
1305 TopoDS_Shape aShape = DBRep::Get(a[2]);
1306 if (aShape.IsNull())
1310 Standard_Boolean anUFaces = Standard_True;
1311 Standard_Boolean anUEdges = Standard_True;
1312 Standard_Boolean anConBS = Standard_False;
1313 Standard_Boolean isAllowInternal = Standard_False;
1314 Standard_Real aLinTol = Precision::Confusion();
1315 Standard_Real aAngTol = Precision::Angular();
1316 TopoDS_Shape aKeepShape;
1317 TopTools_MapOfShape aMapOfShapes;
1320 for ( int i = 3; i < n; i++ )
1322 aKeepShape = DBRep::Get(a[i]);
1323 if (!aKeepShape.IsNull()) {
1324 aMapOfShapes.Add(aKeepShape);
1327 if ( !strcmp(a[i], "-f"))
1328 anUFaces = Standard_False;
1329 else if (!strcmp(a[i], "-e"))
1330 anUEdges = Standard_False;
1331 else if (!strcmp(a[i], "+b"))
1332 anConBS = Standard_True;
1333 else if (!strcmp(a[i], "+i"))
1334 isAllowInternal = Standard_True;
1335 else if (!strcmp(a[i], "-t") || !strcmp(a[i], "-a"))
1339 (a[i-1][1] == 't' ? aLinTol : aAngTol) = Draw::Atof(a[i]);
1343 di << "value expected after " << a[i-1];
1350 Unifier().Initialize(aShape, anUEdges, anUFaces, anConBS);
1351 Unifier().KeepShapes(aMapOfShapes);
1352 Unifier().AllowInternalEdges(isAllowInternal);
1353 Unifier().SetLinearTolerance(aLinTol);
1354 Unifier().SetAngularTolerance(aAngTol);
1356 TopoDS_Shape Result = Unifier().Shape();
1358 DBRep::Set(a[1], Result);
1362 Standard_Integer unifysamedomgen(Draw_Interpretor& di,
1367 di << "use unifysamedomgen newshape oldshape\n";
1370 TopoDS_Shape aShape;
1371 aShape = DBRep::Get(a[2]);
1372 if (aShape.IsNull()) {
1373 di << "Null shape is not allowed here\n";
1377 const TopTools_ListOfShape& aLS = Unifier().Generated(aShape);
1379 if (aLS.Extent() > 1) {
1381 TopoDS_Compound aRes;
1382 aBB.MakeCompound(aRes);
1383 TopTools_ListIteratorOfListOfShape aIt(aLS);
1384 for (; aIt.More(); aIt.Next()) {
1385 const TopoDS_Shape& aShape = aIt.Value();
1386 aBB.Add(aRes, aShape);
1388 DBRep::Set(a[1], aRes);
1390 else if (aLS.Extent() == 1) {
1391 DBRep::Set(a[1], aLS.First());
1394 di << "No shapes were generated from the shape\n";
1399 Standard_Integer unifysamedommod(Draw_Interpretor& di,
1404 di << "use unifysamedommod newshape oldshape\n";
1407 TopoDS_Shape aShape;
1408 aShape = DBRep::Get(a[2]);
1409 if (aShape.IsNull()) {
1410 di << "Null shape is not allowed here\n";
1414 const TopTools_ListOfShape& aLS = Unifier().Modified(aShape);
1416 if (aLS.Extent() > 1) {
1418 TopoDS_Compound aRes;
1419 aBB.MakeCompound(aRes);
1420 TopTools_ListIteratorOfListOfShape aIt(aLS);
1421 for (; aIt.More(); aIt.Next()) {
1422 const TopoDS_Shape& aShape = aIt.Value();
1423 aBB.Add(aRes, aShape);
1425 DBRep::Set(a[1], aRes);
1427 else if (aLS.Extent() == 1) {
1428 DBRep::Set(a[1], aLS.First());
1431 di << "The shape has not been modified\n";
1436 Standard_Integer unifysamedomisdel(Draw_Interpretor& di,
1441 di << "Use: unifysamedomisdel shape\n";
1444 TopoDS_Shape aShape = DBRep::Get(a[1]);
1445 if (aShape.IsNull()) {
1446 di << "Null shape is not allowed here\n";
1449 Standard_Boolean IsDeleted = Unifier().IsDeleted(aShape);
1450 di << "The shape has" << (IsDeleted ? " " : " not ") << "been deleted" << "\n";
1454 static Standard_Integer copytranslate(Draw_Interpretor& di,
1455 Standard_Integer argc,
1459 di << "bad number of arguments. Should be: copytranslate res shape dx dy dz\n";
1462 TopoDS_Shape aShape = DBRep::Get(argv[2]);
1465 Standard_Real aDx = Draw::Atof(argv[3]);
1466 Standard_Real aDy = Draw::Atof(argv[4]);
1467 Standard_Real aDz = Draw::Atof(argv[5]);
1469 aTrsf.SetTranslation(gp_Vec(aDx, aDy, aDz));
1470 BRepBuilderAPI_Transform builderTransform(aTrsf);
1471 builderTransform.Perform (aShape, true);
1472 TopoDS_Shape aNewShape = builderTransform.Shape();
1473 DBRep::Set(argv[1],aNewShape);
1478 Standard_Integer reshape(Draw_Interpretor& di,
1484 di << "Error: wrong number of arguments. Type 'help " << a[0] << "'\n";
1488 TopoDS_Shape source = DBRep::Get(a[2]);
1489 if ( source.IsNull() )
1491 di << "Error: source shape ('" << a[2] << "') is null\n";
1495 Handle(BRepTools_ReShape) ReShaper = new BRepTools_ReShape;
1497 // Record the requested modifications
1498 for ( Standard_Integer i = 1; i < n; ++i )
1500 Standard_CString arg = a[i];
1501 TCollection_AsciiString opt(arg);
1504 if ( opt == "-replace" )
1508 di << "Error: not enough arguments for replacement\n";
1512 TopoDS_Shape what = DBRep::Get(a[++i]);
1513 if ( what.IsNull() )
1515 di << "Error: argument shape ('" << a[i] << "') is null\n";
1519 TopoDS_Shape with = DBRep::Get(a[++i]);
1520 if ( with.IsNull() )
1522 di << "Error: replacement shape ('" << a[i] << "') is null\n";
1526 ReShaper->Replace(what, with);
1528 else if ( opt == "-remove" )
1532 di << "Error: not enough arguments for removal\n";
1536 TopoDS_Shape what = DBRep::Get(a[++i]);
1537 if ( what.IsNull() )
1539 di << "Error: shape to remove ('" << a[i] << "') is null\n";
1543 ReShaper->Remove(what);
1547 // Apply all the recorded modifications
1548 TopoDS_Shape result = ReShaper->Apply(source);
1549 if ( result.IsNull() )
1551 di << "Error: result shape is null\n";
1555 DBRep::Set(a[1], result);
1559 //=======================================================================
1560 //function : InitCommands
1562 //=======================================================================
1564 void SWDRAW_ShapeUpgrade::InitCommands(Draw_Interpretor& theCommands)
1566 static Standard_Integer initactor = 0;
1567 if (initactor) return; initactor = 1;
1569 Standard_CString g = SWDRAW::GroupName(); // "Tests of DivideTool";
1571 theCommands.Add("DT_ShapeDivide",
1572 "DT_ShapeDivide Result Shape Tol: Divides shape with C1 Criterion",
1576 theCommands.Add("DT_SplitAngle",
1577 "DT_SplitAngle Result Shape [MaxAngle=95]: Divides revolved surfaces on segments less MaxAngle deg",
1581 theCommands.Add("DT_ShapeConvert",
1582 "DT_ShapeConvert Result Shape convert2d convert3d: Converts curves to beziers",
1586 theCommands.Add("DT_ShapeConvertRev",
1587 "DT_ShapeConvert Result Shape convert2d convert3d: Converts curves to beziers",
1589 DT_ShapeConvertRev,g);
1590 /* theCommands.Add("DT_PlaneDividedFace",
1591 "DT_PlaneDividedFace Result Face Tol: Transfer into a plane with boundary divided",
1593 DT_PlaneDividedFace,g);
1595 theCommands.Add("DT_PlaneGridShell",
1596 "DT_PlaneGridShell Result NbU NbV {UKnots} {VKnots} Tol : Create a plane grid Shell",
1598 DT_PlaneGridShell,g);
1600 theCommands.Add("DT_PlaneFaceCommon",
1601 "DT_PlaneFaceCommon Result Face Shell: Common between a plane Face and a Shell",
1603 DT_PlaneFaceCommon,g);*/
1605 theCommands.Add("DT_SplitCurve2d",
1606 "DT_SplitCurve2d Curve Tol: Splits the curve with C1 criterion",
1610 theCommands.Add("DT_SplitCurve",
1611 "DT_SplitCurve Curve Tol: Splits the curve with C1 criterion",
1615 theCommands.Add("DT_SplitSurface",
1616 "DT_SplitSurface Result Surface/GridSurf Tol: Splits the surface with C1 criterion",
1620 /*theCommands.Add("DT_SupportModification",
1621 "DT_SupportModification Result Shell Surface 2d3dFactor: Surface will support all the faces",
1623 DT_SupportModification,g);*/
1625 // theCommands.Add("DT_SpltWire","DT_SpltWire Result Wire Tol",
1626 // __FILE__,DT_SplitWire,g);
1628 // theCommands.Add("DT_SplitFace", "DT_SplitFace Result Face Tol",
1629 // __FILE__, DT_SplitFace,g);
1631 // theCommands.Add("DT_Debug", "DT_Debug 0/1 : activation/desactivation of the debug messages",
1632 // __FILE__, DT_Debug,g);
1633 // theCommands.Add ("shellsolid","option[a-b-c-f] shape result",
1634 // __FILE__,shellsolid,g);
1635 theCommands.Add ("offset2dcurve","result curve offset",
1636 __FILE__,offset2dcurve,g);
1638 theCommands.Add ("offsetcurve","result curve offset dir",
1639 __FILE__,offsetcurve,g);
1641 theCommands.Add ("splitface","result face [u usplit1 usplit2...] [v vsplit1 vsplit2 ...]",
1642 __FILE__,splitface,g);
1644 theCommands.Add ("DT_ToBspl","result shape [options=erop]",
1645 __FILE__,converttobspline,g);
1646 theCommands.Add ("DT_ClosedSplit","result shape",
1647 __FILE__,splitclosed,g);
1648 theCommands.Add ("DT_SplitByArea","result shape maxarea [preci]",
1649 __FILE__,splitarea,g);
1651 theCommands.Add ("RemoveIntWires","result minarea wholeshape [faces or wires] [moderemoveface ]",
1652 __FILE__,removeinternalwires,g);
1654 theCommands.Add ("removeloc","result shape [remove_level(see ShapeEnum)]",__FILE__,removeloc,g);
1656 theCommands.Add ("unifysamedom",
1657 "unifysamedom result shape [s1 s2 ...] [-f] [-e] [+b] [+i] [-t val] [-a val]", __FILE__,unifysamedom,g);
1659 theCommands.Add("unifysamedomgen",
1660 "unifysamedomgen newshape oldshape : get new shape generated "
1661 "by unifysamedom command from the old one",
1662 __FILE__, unifysamedomgen, g);
1664 theCommands.Add("unifysamedommod",
1665 "unifysamedommod newshape oldshape : get new shape modified "
1666 "by unifysamedom command from the old one",
1667 __FILE__, unifysamedommod, g);
1669 theCommands.Add("unifysamedomisdel",
1670 "unifysamedomisdel shape : shape is deleted ",
1671 __FILE__, unifysamedomisdel, g);
1673 theCommands.Add ("copytranslate","result shape dx dy dz",__FILE__,copytranslate,g);
1675 theCommands.Add ("reshape",
1676 "\n Basic utility for topological modification: "
1677 "\n '-replace what with' Replaces 'what' sub-shape with 'with' sub-shape"
1678 "\n '-remove what' Removes 'what' sub-shape"
1679 "\n Requests '-replace' and '-remove' can be repeated many times.",
1680 __FILE__, reshape, g);