1 // Created on: 1999-03-09
2 // Created by: data exchange team
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
21 //gka,rln 30.04.99 S4137: new commands for testing ShapeDivide added, some removed
22 //abv,pdn 05.05.99 S4174: new commands for testing ShapeDivide added, some removed
23 //pdn,gka 10.06.99 S4189: command DT_ShapeConvertRev added
25 #include <SWDRAW_ShapeUpgrade.ixx>
26 //#include <SWDRAW_ShapeUpgrade.hxx>
30 #include <ShapeUpgrade.hxx>
31 #include <ShapeUpgrade_SplitCurve3dContinuity.hxx>
32 #include <ShapeUpgrade_SplitCurve2dContinuity.hxx>
33 #include <ShapeUpgrade_SplitSurfaceContinuity.hxx>
34 //#include <ShapeUpgrade_SupportModification.hxx>
35 #include <Draw_Interpretor.hxx>
36 #include <DrawTrSurf.hxx>
37 #include <Geom_Curve.hxx>
38 #include <Geom_Plane.hxx>
39 #include <Geom_Surface.hxx>
40 #include <Geom2d_Curve.hxx>
41 #include <TColGeom_HArray1OfCurve.hxx>
42 #include <TColGeom_HArray2OfSurface.hxx>
43 #include <TColStd_Array1OfReal.hxx>
44 #include <TColStd_HArray1OfReal.hxx>
45 #include <TColStd_HSequenceOfReal.hxx>
47 #include <TopoDS_Edge.hxx>
48 #include <TopoDS_Face.hxx>
49 #include <TopoDS_Shape.hxx>
50 #include <TopoDS_Shell.hxx>
51 #include <TopoDS_Wire.hxx>
52 #include <TopoDS_Compound.hxx>
53 #include <TopExp_Explorer.hxx>
54 #include <TColGeom_HArray2OfSurface.hxx>
55 #include <TColGeom2d_HArray1OfCurve.hxx>
56 #include <BRepBuilderAPI.hxx>
58 #include <ShapeUpgrade_ShapeDivideArea.hxx>
61 //#include <ShapeExtend_WireData.hxx>
62 //#include <ShapeAnalysis_Shell.hxx>
63 //#include <ShapeAnalysis_WireOrder.hxx>
64 //#include <ShapeAnalysis_Wire.hxx>
65 //#include <ShapeUpgrade_ShellSewing.hxx>
66 #include <Geom2d_Curve.hxx>
67 #include <Geom2d_OffsetCurve.hxx>
68 #include <Geom_OffsetCurve.hxx>
69 #include <ShapeUpgrade_SplitCurve3dContinuity.hxx>
70 #include <TopoDS_Iterator.hxx>
71 #include <BRep_Tool.hxx>
72 #include <ShapeExtend_CompositeSurface.hxx>
73 #include <Geom_RectangularTrimmedSurface.hxx>
74 #include <TColGeom_HArray2OfSurface.hxx>
75 #include <ShapeFix_ComposeShell.hxx>
76 #include <Precision.hxx>
77 #include <ShapeBuild_ReShape.hxx>
78 #include <BRepTools.hxx>
79 #include <ShapeFix.hxx>
80 #include <ShapeUpgrade_ShapeDivideContinuity.hxx>
81 #include <ShapeUpgrade_ShapeDivideAngle.hxx>
82 #include <ShapeUpgrade_ShapeConvertToBezier.hxx>
83 #include <ShapeCustom.hxx>
84 #include <ShapeUpgrade_ShapeDivideClosed.hxx>
85 #include <ShapeUpgrade_RemoveInternalWires.hxx>
86 #include <ShapeUpgrade_RemoveLocations.hxx>
87 #include <ShapeUpgrade_UnifySameDomain.hxx>
88 #include <BRepBuilderAPI_Transform.hxx>
90 // the plane (equation z=0) shared by PlaneDividedFaceContinuity and PlaneGridShell
91 //static Handle(Geom_Plane) ThePlane= new Geom_Plane(0,0,1,0);
94 //=======================================================================
95 //function : DT_ShapeDivide
97 //=======================================================================
99 static Standard_Integer DT_ShapeDivide (Draw_Interpretor& di,
100 Standard_Integer n, const char** a)
102 // DT_ShapeDivide result Shape Tol
104 // a[2]= input Face/Surface
105 // a[3] si n>3= Wire/Face
109 di << "bad number of arguments" <<"\n";
113 // try to read a shape:
114 TopoDS_Shape inputShape=DBRep::Get(a[2]);
115 if (inputShape.IsNull()) {
116 di << "Unknown shape"<< "\n";
119 // a[2] is a shape. managing:
120 // DT_ShapeDivide result Face Tol
122 // giving a face is available only in the constructor:
123 // we make the whole and quit.
124 ShapeUpgrade_ShapeDivideContinuity tool(inputShape);
126 // tolerance is optional
128 Standard_Real Tol=Draw::Atof(a[3]);
129 tool.SetTolerance(Tol);
132 // theTool.SetGlobalCriterion(GeomAbs_C1);
134 TopoDS_Shape res = tool.Result();
136 if ( tool.Status ( ShapeExtend_OK ) ) di << "Status: OK" << "\n";
137 if ( tool.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1" << "\n";
138 if ( tool.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2" << "\n";
139 if ( tool.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3" << "\n";
140 if ( tool.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4" << "\n";
141 if ( tool.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5" << "\n";
142 if ( tool.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6" << "\n";
143 if ( tool.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7" << "\n";
144 if ( tool.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8" << "\n";
145 if ( tool.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1" << "\n";
146 if ( tool.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2" << "\n";
147 if ( tool.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3" << "\n";
148 if ( tool.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4" << "\n";
149 if ( tool.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5" << "\n";
150 if ( tool.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6" << "\n";
151 if ( tool.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7" << "\n";
152 if ( tool.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8" << "\n";
156 ShapeFix::SameParameter ( res, Standard_False );
158 DBRep::Set(a[1],res);
162 static Standard_Integer DT_ShapeConvertRev (Draw_Interpretor& di,
163 Standard_Integer n, const char** a)
166 di << "bad number of arguments" <<"\n";
170 // try to read a shape:
171 TopoDS_Shape inputShape=DBRep::Get(a[2]);
172 if (inputShape.IsNull()) {
173 di << "Unknown shape"<< "\n";
177 Standard_Integer c2d = Draw::Atoi(a[3]);
178 Standard_Integer c3d = Draw::Atoi(a[4]);
179 TopoDS_Shape revsh = ShapeCustom::ConvertToRevolution (inputShape);
180 if (revsh.IsNull()) { di<<"NO RESULT"<<"\n"; return 1; }
181 else if (revsh == inputShape) { di<<"No modif"<<"\n";}
182 else di<<"ConvertToRevolution -> Result : "<<"\n";
184 ShapeUpgrade_ShapeConvertToBezier tool(revsh);
185 tool.SetSurfaceConversion(Standard_True);
187 tool.Set2dConversion(Standard_True);
189 tool.Set3dConversion(Standard_True);
191 tool.Set3dLineConversion(Standard_False);
193 tool.Set3dCircleConversion(Standard_False);
195 tool.Set3dConicConversion(Standard_False);
198 TopoDS_Shape res = tool.Result();
200 if ( tool.Status ( ShapeExtend_OK ) ) di << "Status: OK" << "\n";
201 if ( tool.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1" << "\n";
202 if ( tool.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2" << "\n";
203 if ( tool.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3" << "\n";
204 if ( tool.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4" << "\n";
205 if ( tool.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5" << "\n";
206 if ( tool.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6" << "\n";
207 if ( tool.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7" << "\n";
208 if ( tool.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8" << "\n";
209 if ( tool.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1" << "\n";
210 if ( tool.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2" << "\n";
211 if ( tool.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3" << "\n";
212 if ( tool.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4" << "\n";
213 if ( tool.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5" << "\n";
214 if ( tool.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6" << "\n";
215 if ( tool.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7" << "\n";
216 if ( tool.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8" << "\n";
220 ShapeFix::SameParameter ( res, Standard_False );
222 DBRep::Set(a[1],res);
228 if (!inputShape.IsNull()) {
229 // a[2] is a shape. managing:
230 // DT_ShapeDivide result Face Tol
232 TopoDS_Face inputFace = TopoDS::Face(inputShape);
233 if (inputFace.IsNull()) {
234 di << a[2] << " is not a face" << "\n";
238 // giving a face is available only in the constructor:
239 // we make the whole and quit.
240 ShapeUpgrade_ShapeDivideContinuity theTool(inputFace);
242 // tolerance is optional
244 Standard_Real Tol=Draw::Atof(a[n-1]);
245 theTool.SetTolerance(Tol);
248 theTool.SetGlobalCriterion(GeomAbs_C1);
250 if (!theTool.IsDone()) {
251 ShapeUpgrade_Error theError=theTool.Error();
252 di << "Not done: error=";
253 if (theError==ShapeUpgrade_Done)
255 else if (theError==ShapeUpgrade_NotDone)
256 di << "NotDone"<<"\n";
257 else if (theError==ShapeUpgrade_EmptyShell)
258 di << "EmptyShell"<<"\n";
259 else if (theError==ShapeUpgrade_InvalidCriterion)
260 di << "InvalidCriterion"<<"\n";
261 else if (theError==ShapeUpgrade_InvalidGridSurface)
262 di << "InvalidGridSurface"<<"\n";
263 else if (theError==ShapeUpgrade_DegeneratedEdge)
264 di << "DegeneratedEdge"<<"\n";
265 else if (theError==ShapeUpgrade_NoSurface)
266 di << "NoSurface"<<"\n";
267 else if (theError==ShapeUpgrade_NoTolerance)
268 di << "NoTolerance"<<"\n";
271 TopoDS_Shell res = theTool.Shell();
272 DBRep::Set(a[1],res);
277 // not a face: we can use the empty consturctor.
278 ShapeUpgrade_ShapeDivideContinuity theTool;
279 Standard_Real Tol=Draw::Atof(a[n-1]);
280 theTool.SetTolerance(Tol);
281 theTool.SetGlobalCriterion(GeomAbs_C1);
283 // try to read a surface:
284 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[2]);
286 // a[2] is a surface. managing the configurations:
287 // DT_ShapeDivide result Surface Tol
288 // DT_ShapeDivide result Surface Face Tol
289 // DT_ShapeDivide result Surface Wire Surf Tol
291 theTool.SetSupport(GS);
293 // try to read a Wire or a Face:
295 TopoDS_Shape inputBoundary=DBRep::Get(a[3]);
296 if (inputBoundary.IsNull()) {
297 di << "Invalid Boundary" << "\n";
300 TopoDS_Wire WireBoundary = TopoDS::Wire(inputBoundary);
301 if (!WireBoundary.IsNull()) {
302 // DT_ShapeDivide result Surface Wire Surf Tol
303 Handle(Geom_Surface) WireSupport = DrawTrSurf::GetSurface(a[4]);
304 if (WireSupport.IsNull()) {
305 di << "Invalid Surface supporting the Wire" << "\n";
308 theTool.SetBoundary(WireBoundary, WireSupport);
311 TopoDS_Face FaceBoundary = TopoDS::Face(inputBoundary);
312 // DT_ShapeDivide result Surface Face Tol
313 theTool.SetBoundary(FaceBoundary);
318 // it must be a grid: managing the configurations:
319 // DT_ShapeDivide result NbU NbV {Surf_u_v...} Tol
320 // DT_ShapeDivide result NbU NbV {Surf_u_v...} Face Tol
321 // DT_ShapeDivide result NbU NbV {Surf_u_v...} Wire Surf Tol
323 di << "bad number of arguments for grid input" <<"\n";
327 Standard_Integer NbU=Draw::Atoi(a[2]);
328 Standard_Integer NbV=Draw::Atoi(a[3]);
329 if (n < 4+NbU*NbV+1) {
330 di << "bad number of arguments" <<"\n";
334 Handle(TColGeom_HArray2OfSurface)
335 TheGridSurf= new TColGeom_HArray2OfSurface(1,NbU,1,NbV);
337 for (Standard_Integer iu=1; iu<=NbU; iu++) {
338 for (Standard_Integer jv=1; jv<=NbV; jv++) {
339 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[4+(iu-1)*NbV+jv-1]);
340 TheGridSurf->SetValue(iu,jv,GS);
343 theTool.SetSupport(TheGridSurf,Tol);
345 // try to read a Wire or a Face:
347 TopoDS_Shape inputBoundary=DBRep::Get(a[4+NbU*NbV]);
348 if (inputBoundary.IsNull()) {
349 di << "Invalid Boundary" << "\n";
352 TopoDS_Wire WireBoundary = TopoDS::Wire(inputBoundary);
353 if (!WireBoundary.IsNull()) {
354 // DT_ShapeDivide result Surface Wire Surf Tol
355 Handle(Geom_Surface) WireSupport = DrawTrSurf::GetSurface(a[4+NbU*NbV+1]);
356 if (WireSupport.IsNull()) {
357 di << "Invalid Surface supporting the Wire" << "\n";
360 theTool.SetBoundary(WireBoundary, WireSupport);
363 TopoDS_Face FaceBoundary = TopoDS::Face(inputBoundary);
364 // DT_ShapeDivide result Surface Face Tol
365 theTool.SetBoundary(FaceBoundary);
371 if (!theTool.IsDone()) {
372 ShapeUpgrade_Error theError=theTool.Error();
373 di << "Not done: error=";
374 if (theError==ShapeUpgrade_Done)
376 else if (theError==ShapeUpgrade_NotDone)
377 di << "NotDone"<<"\n";
378 else if (theError==ShapeUpgrade_EmptyShell)
379 di << "EmptyShell"<<"\n";
380 else if (theError==ShapeUpgrade_InvalidCriterion)
381 di << "InvalidCriterion"<<"\n";
382 else if (theError==ShapeUpgrade_InvalidGridSurface)
383 di << "InvalidGridSurface"<<"\n";
384 else if (theError==ShapeUpgrade_DegeneratedEdge)
385 di << "DegeneratedEdge"<<"\n";
386 else if (theError==ShapeUpgrade_NoSurface)
387 di << "NoSurface"<<"\n";
388 else if (theError==ShapeUpgrade_NoTolerance)
389 di << "NoTolerance"<<"\n";
393 TopoDS_Shell res = theTool.Shell();
394 DBRep::Set(a[1],res);
400 static Standard_Integer DT_ShapeConvert (Draw_Interpretor& di,
401 Standard_Integer n, const char** a)
404 di << "bad number of arguments" <<"\n";
408 // try to read a shape:
409 TopoDS_Shape inputShape=DBRep::Get(a[2]);
410 if (inputShape.IsNull()) {
411 di << "Unknown shape"<< "\n";
415 Standard_Integer c2d = Draw::Atoi(a[3]);
416 Standard_Integer c3d = Draw::Atoi(a[4]);
418 ShapeUpgrade_ShapeConvertToBezier tool(inputShape);
419 tool.SetSurfaceConversion(Standard_True);
421 tool.Set2dConversion(Standard_True);
423 tool.Set3dConversion(Standard_True);
425 TopoDS_Shape res = tool.Result();
427 if ( tool.Status ( ShapeExtend_OK ) ) di << "Status: OK" << "\n";
428 if ( tool.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1" << "\n";
429 if ( tool.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2" << "\n";
430 if ( tool.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3" << "\n";
431 if ( tool.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4" << "\n";
432 if ( tool.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5" << "\n";
433 if ( tool.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6" << "\n";
434 if ( tool.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7" << "\n";
435 if ( tool.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8" << "\n";
436 if ( tool.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1" << "\n";
437 if ( tool.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2" << "\n";
438 if ( tool.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3" << "\n";
439 if ( tool.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4" << "\n";
440 if ( tool.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5" << "\n";
441 if ( tool.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6" << "\n";
442 if ( tool.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7" << "\n";
443 if ( tool.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8" << "\n";
447 ShapeFix::SameParameter ( res, Standard_False );
449 DBRep::Set(a[1],res);
452 static Standard_Integer DT_SplitAngle(Draw_Interpretor& di,
453 Standard_Integer n, const char** a)
456 di << "bad number of arguments" <<"\n";
460 TopoDS_Shape inputShape=DBRep::Get(a[2]);
461 if (inputShape.IsNull()) {
462 di << "Unknown shape"<< "\n";
466 Standard_Real maxangle = 95;
468 maxangle = Draw::Atof ( a[3] );
469 if ( maxangle <1 ) maxangle = 1;
472 ShapeUpgrade_ShapeDivideAngle tool(maxangle * M_PI/180,inputShape);
474 TopoDS_Shape res = tool.Result();
476 if ( tool.Status ( ShapeExtend_OK ) ) di << "Status: OK" << "\n";
477 if ( tool.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1" << "\n";
478 if ( tool.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2" << "\n";
479 if ( tool.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3" << "\n";
480 if ( tool.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4" << "\n";
481 if ( tool.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5" << "\n";
482 if ( tool.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6" << "\n";
483 if ( tool.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7" << "\n";
484 if ( tool.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8" << "\n";
485 if ( tool.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1" << "\n";
486 if ( tool.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2" << "\n";
487 if ( tool.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3" << "\n";
488 if ( tool.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4" << "\n";
489 if ( tool.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5" << "\n";
490 if ( tool.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6" << "\n";
491 if ( tool.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7" << "\n";
492 if ( tool.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8" << "\n";
496 ShapeFix::SameParameter ( res, Standard_False );
498 DBRep::Set(a[1],res);
503 //=======================================================================
504 //function : DT_PlaneDividedFace
505 //purpose : Transfer into a plane with boundary divided
508 //=======================================================================
509 static Standard_Integer DT_PlaneDividedFace (Draw_Interpretor& di,
510 Standard_Integer n, const char** a)
518 di << "bad number of arguments" <<"\n";
522 Standard_Real Tol=Draw::Atof(a[3]);
523 TopoDS_Shape inputShape=DBRep::Get(a[2]);
524 TopoDS_Face inputFace = TopoDS::Face(inputShape);
525 if (inputFace.IsNull()) {
526 di << a[2] << " is not a face" << "\n";
530 ShapeUpgrade_PlaneDividedFace theTool(ThePlane);
531 theTool.Init(inputFace);
532 //theTool.SetBoundaryCriterion(GeomAbs_C1);
533 //theTool.SetTolerance(Tol);
535 if (!theTool.IsDone()) {
536 di << "Not done" << "\n";
540 TopoDS_Face res = theTool.Face();
541 DBRep::Set(a[1],res);
543 Standard_Real the2d3dFactor=theTool.Get2d3dFactor();
544 di << "2d3dFactor="<<the2d3dFactor<< "\n";
548 //=======================================================================
549 //function : DT_PlaneGridShell
550 //purpose : Create a Plane Grid Shell from U and V knots
553 //=======================================================================
554 static Standard_Integer DT_PlaneGridShell (Draw_Interpretor& di,
555 Standard_Integer n, const char** a)
564 // a[4+NbU...] = {VKnots}
565 // a[4+NbU+NbV+1] = Tol
568 Standard_Integer NbU=Draw::Atoi(a[2]);
569 Standard_Integer NbV=Draw::Atoi(a[3]);
570 if (n != 4+NbU+NbV+1) {
571 di << "bad number of arguments" <<"\n";
575 TColStd_Array1OfReal TheUKnots(1,NbU);
576 TColStd_Array1OfReal TheVKnots(1,NbV);
578 for (Standard_Integer ii=1; ii<=NbU; ii++) {
579 TheUKnots(ii)=Draw::Atof(a[4+ii-1]);
581 for (ii=1; ii<=NbV; ii++) {
582 TheVKnots(ii)=Draw::Atof(a[4+NbU+ii-1]);
585 Standard_Real Tol=Draw::Atof(a[4+NbU+NbV]);
587 ShapeUpgrade_PlaneGridShell TheGrid(ThePlane,TheUKnots,TheVKnots,Tol);
589 TopoDS_Shell res = TheGrid.Shell();
590 DBRep::Set(a[1],res);
595 //=======================================================================
596 //function : DT_PlaneFaceCommon
597 //purpose : Common between a plane Face and a Shell whose all Faces are
598 // laying in the same plane
601 //=======================================================================
602 static Standard_Integer DT_PlaneFaceCommon (Draw_Interpretor& di,
603 Standard_Integer n, const char** a)
611 di << "bad number of arguments" <<"\n";
615 TopoDS_Shape inputShape= DBRep::Get(a[2]);
616 TopoDS_Face inputFace = TopoDS::Face(inputShape);
617 if (inputFace.IsNull()) {
618 di << a[2] << " is not a face" << "\n";
622 inputShape = DBRep::Get(a[3]);
623 TopoDS_Shell inputShell = TopoDS::Shell(inputShape);
624 if (inputShell.IsNull()) {
625 di << a[3] << " is not a shell" << "\n";
629 ShapeUpgrade_PlaneFaceCommon theTool;
630 theTool.Init(inputFace,inputShell);
632 TopoDS_Shell res = theTool.Shell();
633 DBRep::Set(a[1],res);
638 //=======================================================================
639 //function : DT_SplitCurve
640 //purpose : Splits the curve with C1 criterion
643 //=======================================================================
644 static Standard_Integer DT_SplitCurve (Draw_Interpretor& di,
645 Standard_Integer n, const char** a)
648 // a[1]= input curve. This name is used with a suffix to name the output curves
652 di << "bad number of arguments" <<"\n";
656 Standard_Real Tol=Draw::Atof(a[2]);
657 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(a[1]);
658 if ( GC.IsNull()) return 1;
659 Standard_Integer Split = Draw::Atoi(a[3]);
660 Handle(ShapeUpgrade_SplitCurve3dContinuity) theTool = new ShapeUpgrade_SplitCurve3dContinuity;
662 theTool->SetTolerance (Tol);
663 theTool->SetCriterion (GeomAbs_C1);
665 Handle(TColStd_HSequenceOfReal) spval = new TColStd_HSequenceOfReal;
666 for(Standard_Integer i = 1; i<=5; i++) spval->Append(i);
667 theTool->SetSplitValues(spval);
669 theTool->Perform (Standard_True);
670 Handle(TColGeom_HArray1OfCurve) theCurves= theTool->GetCurves();
671 Standard_Integer NbC=theCurves->Length();
672 for (Standard_Integer icurv=1; icurv<=NbC; icurv++) {
674 Sprintf(name,"%s%s%d",a[1],"_",icurv);
675 char* newname = name;
676 DrawTrSurf::Set(newname, theCurves->Value(icurv));
677 di.AppendElement(newname);
683 //=======================================================================
684 //function : DT_SplitCurve2d
685 //purpose : Splits the curve with C1 criterion
688 //=======================================================================
689 static Standard_Integer DT_SplitCurve2d (Draw_Interpretor& di,
690 Standard_Integer n, const char** a)
693 // a[1]= input 2d curve. This name is used with a suffix to name the output curves
697 di << "bad number of arguments" <<"\n";
701 Standard_Real Tol=Draw::Atof(a[2]);
702 Handle(Geom2d_Curve) GC = DrawTrSurf::GetCurve2d(a[1]);
703 if ( GC.IsNull()) return 1;
704 Standard_Integer Split = Draw::Atoi(a[3]);
705 Handle(ShapeUpgrade_SplitCurve2dContinuity) theTool = new ShapeUpgrade_SplitCurve2dContinuity;
707 theTool->SetTolerance (Tol);
708 theTool->SetCriterion (GeomAbs_C1);
710 Handle(TColStd_HSequenceOfReal) spval = new TColStd_HSequenceOfReal;
711 for(Standard_Integer i = 1; i<=5; i++) spval->Append(i);
712 theTool->SetSplitValues(spval);
714 theTool->Perform (Standard_True);
715 Handle(TColGeom2d_HArray1OfCurve) theCurves= theTool->GetCurves();
716 Standard_Integer NbC=theCurves->Length();
717 for (Standard_Integer icurv=1; icurv<=NbC; icurv++) {
719 Sprintf(name,"%s%s%d",a[1],"_",icurv);
720 char* newname = name;
721 DrawTrSurf::Set(newname, theCurves->Value(icurv));
722 di.AppendElement(newname);
728 //=======================================================================
729 //function : DT_SplitSurface
730 //purpose : Splits the surface with C1 criterion
733 //=======================================================================
735 static Standard_Integer DT_SplitWire (Draw_Interpretor& di,
736 Standard_Integer n, const char** a)
740 di << "bad number of arguments" <<"\n";
744 TopoDS_Face source = TopoDS::Face(DBRep::Get(a[2]));
745 if(source.IsNull()) {
746 di <<"Shape is not face"<<"\n";
749 TopoDS_Iterator wi(source);
751 di <<"Shape is face without wire"<<"\n";
755 TopoDS_Wire wire = TopoDS::Wire(wi.Value());
756 Handle(ShapeUpgrade_WireDivideContinuity) tool = new ShapeUpgrade_WireDivideContinuity;
757 tool->Init(wire,source);
759 Standard_Real Tol=Draw::Atof(a[3]);
761 Handle(ShapeBuild_ReShape) context = new ShapeBuild_ReShape;
762 tool->Perform(context);
763 TopoDS_Wire result = tool->Wire();
764 DBRep::Set(a[1],result);
769 static Standard_Integer DT_SplitFace (Draw_Interpretor& di,
770 Standard_Integer n, const char** a)
774 di << "bad number of arguments" <<"\n";
778 TopoDS_Face source = TopoDS::Face(DBRep::Get(a[2]));
779 if(source.IsNull()) {
780 di <<"Shape is not face"<<"\n";
783 Handle(ShapeUpgrade_ShapeDivideContinuity) tool = new ShapeUpgrade_FaceDivideContinuity;
786 Standard_Real Tol=Draw::Atof(a[3]);
787 tool->SetPrecision(Tol);
790 Handle(ShapeBuild_ReShape) context = new ShapeBuild_ReShape;
791 tool->Perform(context);
792 TopoDS_Shape result = tool->Result();
795 if ( tool->Status ( ShapeExtend_OK ) ) di << "Status: OK" << "\n";
796 if ( tool->Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1" << "\n";
797 if ( tool->Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2" << "\n";
798 if ( tool->Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3" << "\n";
799 if ( tool->Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4" << "\n";
800 if ( tool->Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5" << "\n";
801 if ( tool->Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6" << "\n";
802 if ( tool->Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7" << "\n";
803 if ( tool->Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8" << "\n";
804 if ( tool->Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1" << "\n";
805 if ( tool->Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2" << "\n";
806 if ( tool->Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3" << "\n";
807 if ( tool->Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4" << "\n";
808 if ( tool->Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5" << "\n";
809 if ( tool->Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6" << "\n";
810 if ( tool->Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7" << "\n";
811 if ( tool->Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8" << "\n";
815 ShapeFix::SameParameter ( result, Standard_False );
817 DBRep::Set(a[1],result);
822 static Standard_Integer DT_SplitSurface (Draw_Interpretor& di,
823 Standard_Integer n, const char** a)
826 // a[1]= result (used with a suffix to name the output surfaces)
827 // a[2]= input surface.
833 // a[3+1]..a[3+nbU*nbV] = Input Surfaces
834 // a[4+nbU*nbV]= Tolerance
837 di << "bad number of arguments" <<"\n";
841 Handle(ShapeUpgrade_SplitSurfaceContinuity) theTool = new ShapeUpgrade_SplitSurfaceContinuity;//S4137
843 Standard_Real Tol=Draw::Atof(a[3]);
844 Standard_Integer Split = Draw::Atoi(a[4]);
845 theTool->SetTolerance(Tol);
846 theTool->SetCriterion(GeomAbs_C1);
847 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[2]);
850 // Case of composite grid surface
851 di << "composite surf" << "\n";
852 Standard_Integer nbU=Draw::Atoi(a[2]);
853 Standard_Integer nbV=Draw::Atoi(a[3]);
854 if (nbU==0 || nbV==0) return 1;
855 Handle(TColGeom_HArray2OfSurface)
856 theGrid= new TColGeom_HArray2OfSurface(1,nbU,1,nbV);
857 for (Standard_Integer iu=1; iu<=nbU; iu++) {
858 for (Standard_Integer iv=1; iv<=nbV; iv++) {
859 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[3+(iu-1)*nbV+iv]);
860 theGrid->SetValue(iu,iv,GS);
863 di << "appel a SplitSurface::Init" << "\n";
864 theTool->Init(theGrid);
867 // Case of single surface
868 di << "single surf" << "\n";
870 di << "appel a SplitSurface::Init" << "\n";
873 Handle(TColStd_HSequenceOfReal) spval = new TColStd_HSequenceOfReal;
874 for(Standard_Integer i = 1; i<=5; i++) spval->Append(i);
875 theTool->SetUSplitValues(spval);
876 theTool->SetVSplitValues(spval);
879 di << "appel a SplitSurface::Build" << "\n";
880 theTool->Build(Standard_True);
882 di << "appel a SplitSurface::GlobalU/VKnots" << "\n";
883 Handle(ShapeExtend_CompositeSurface) Grid = theTool->ResSurfaces();
884 Handle(TColStd_HArray1OfReal) GlobalU=Grid->UJointValues();
885 Handle(TColStd_HArray1OfReal) GlobalV=Grid->VJointValues();
886 Standard_Integer nbGlU=GlobalU->Length();
887 Standard_Integer nbGlV=GlobalV->Length();
888 di << "nb GlobalU ; nb GlobalV="<<nbGlU<<" "<<nbGlV;
889 for (Standard_Integer iu=1; iu<=nbGlU; iu++)
890 di <<" "<< GlobalU->Value(iu);
892 // di << "nb GlobalV="<<nbGlV;
893 for (Standard_Integer iv=1; iv<=nbGlV; iv++)
894 di <<" "<< GlobalV->Value(iv);
897 di << "appel a Surfaces" << "\n";
898 Handle(TColGeom_HArray2OfSurface) theSurfaces= Grid->Patches();
900 di << "transfert resultat" << "\n";
901 Standard_Integer NbRow=theSurfaces->ColLength();
902 Standard_Integer NbCol=theSurfaces->RowLength();
903 for (Standard_Integer irow=1; irow<=NbRow; irow++) {
904 for (Standard_Integer icol=1; icol<=NbCol; icol++) {
906 Sprintf(name,"%s%s%d%s%d",a[1],"_",irow,"_",icol);
907 char* newname = name;
908 DrawTrSurf::Set(newname, theSurfaces->Value(irow, icol));
909 di.AppendElement(newname);
917 //=======================================================================
918 //function : DT_SupportModification
919 //purpose : Changes the supports of a Shell
920 // The given surface wil support all the faces of the new shell.
921 // with the PCurves of the old ones.
923 //=======================================================================
924 /*static Standard_Integer DT_SupportModification (Draw_Interpretor& di,
925 Standard_Integer n, const char** a)
931 // a[4]= 2d3d Scale Factor
934 di << "bad number of arguments" <<"\n";
938 TopoDS_Shape inputShape= DBRep::Get(a[2]);
939 TopoDS_Shell inputShell = TopoDS::Shell(inputShape);
940 if (inputShell.IsNull()) {
941 di << a[2] << " is not a shell" << "\n";
945 Handle(Geom_Surface) theSurf = DrawTrSurf::GetSurface(a[3]);
946 if ( theSurf.IsNull()) {
947 di << a[3] << " is not a surface" << "\n";
951 ShapeUpgrade_DataMapOfShapeSurface theMap;
952 // Associates thesurf to each face of inputShell.
953 TopExp_Explorer ExpSh;
954 for (ExpSh.Init(inputShell,TopAbs_FACE); ExpSh.More(); ExpSh.Next()){
955 TopoDS_Face theFace= TopoDS::Face(ExpSh.Current());
956 theMap.Bind(theFace,theSurf);
959 Standard_Real the2d3dFactor=Draw::Atof(a[4]);
960 ShapeUpgrade_SupportModification theTool(inputShell,theMap,the2d3dFactor);
962 TopoDS_Shell res = theTool.Shell();
963 DBRep::Set(a[1],res);
968 //=======================================================================
969 //function : DT_Debug
970 //purpose : activation of the debug mode
972 //=======================================================================
974 static Standard_Integer DT_Debug (Draw_Interpretor& di,
975 Standard_Integer n, const char** a)
981 di << "bad number of arguments" <<"\n";
985 if (Draw::Atoi(a[1])==1) {
986 di << "Activation of debug messages"<<"\n";
987 ShapeUpgrade::SetDebug(Standard_True);
990 di << "Desactivation of debug messages"<<"\n";
991 ShapeUpgrade::SetDebug(Standard_False);
997 /*static Standard_Integer shellsolid
998 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1001 di<<"Donner option + nom de SHAPE + nom de RESULTAT"<<"\n";
1002 di<<"Options : a all (sewing sur tous les shells\n"
1003 << " c check (sewing sur shells avec bad edges\n"
1004 <<" b bad edges\n f free edges"<<"\n";
1007 Standard_CString arg1 = argv[1];
1008 Standard_CString arg2 = argv[2];
1009 Standard_CString arg3 = argv[3];
1011 TopoDS_Shape Shape = DBRep::Get(arg2);
1012 if (Shape.IsNull()) { di<<"Shape unknown : "<<arg2<<"\n"; return 1 ; }
1014 ShapeAnalysis_Shell STS;
1016 if (opt == 'a') STS.LoadShells (Shape);
1017 else if (opt == 'f') STS.CheckOrientedShells (Shape,Standard_True);
1018 else if (opt == 'b' || opt == 'c') STS.CheckOrientedShells (Shape,Standard_False);
1020 else if (opt == 'o') {
1023 Handle(ShapeExtend_WireData) Frees = new ShapeExtend_WireData;//:sw Frees.SetPrecision (BRepBuilderAPI::Precision());
1024 Standard_Integer nbe = 0;
1025 for (TopExp_Explorer edges(Shape,TopAbs_EDGE); edges.More(); edges.Next()) {
1026 Frees->Add (TopoDS::Edge(edges.Current())); nbe ++;
1028 ShapeAnalysis_WireOrder WO (Standard_True,BRepBuilderAPI::Precision());
1029 ShapeAnalysis_Wire saw;
1031 saw.SetPrecision ( BRepBuilderAPI::Precision() );
1032 saw.CheckOrder ( WO );
1034 Standard_Integer stat = WO.Status();
1035 di<<"Wire Order Status = "<<stat<<" on "<<nbe<<" Edges"<<"\n";
1037 for (Standard_Integer ie = 1; ie <= nbe; ie ++) {
1038 Standard_Integer io = WO.Ordered (ie);
1040 WO.XYZ (io,st3d,en3d);
1041 di<<ie<<": Edge."<<io<<" Start:"<<st3d.X()<<" "<<st3d.Y()<<" "<<st3d.Z()
1042 <<" End:"<<en3d.X()<<" "<<en3d.Y()<<" "<<en3d.Z()<<"\n";
1045 Standard_Real gap = BRepBuilderAPI::Precision();
1047 Standard_Integer n1,n2,ic, nc = WO.NbChains();
1048 for (ic = 1; ic <= nc; ic ++) {
1050 di<<"Chain."<<ic<<" From "<<n1<<" To "<<n2<<"\n";
1054 else { di<<"Option non reconnue : "<<arg1<<"\n"; return 1; }
1057 if (opt == 'a' || opt == 'c') {
1058 ShapeUpgrade_ShellSewing sew;
1059 res = sew.ApplySewing (Shape);
1060 if (res.IsEqual(Shape)) {
1062 di<<"ShellSolid : no sewing done"<<"\n";
1064 } else if (opt == 'b') {
1065 if (STS.HasBadEdges()) res = STS.BadEdges();
1066 else di<<"ShellSolid : no bad edge"<<"\n";
1067 } else if (opt == 'f') {
1068 if (STS.HasFreeEdges()) res = STS.FreeEdges();
1069 else di<<"ShellSolid : no free edge"<<"\n";
1070 if (STS.HasConnectedEdges()) di<<"ShellSolid : connected edges"<<"\n";
1071 else di<<"ShellSolid : NO connected edges"<<"\n";
1074 if (!res.IsNull()) DBRep::Set (arg3,res);
1078 //---------------gka
1079 //=======================================================================
1080 //function : offset2dcurve
1083 //=======================================================================
1084 static Standard_Integer offset2dcurve
1085 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1088 di<<"result + curve + offset"<<"\n";
1090 return 1 /* Error */;
1092 // Standard_CString arg1 = argv[1];
1093 // Standard_CString arg2 = argv[2];
1094 Standard_Real Offset = Draw::Atof(argv[3]);
1095 Handle(Geom2d_Curve) GC = DrawTrSurf::GetCurve2d(argv[2]);
1096 if ( GC.IsNull()) return 1;
1097 Handle(Geom2d_OffsetCurve) offcrv = new Geom2d_OffsetCurve(GC,Offset);
1098 DrawTrSurf::Set(argv[1], offcrv);
1102 //=======================================================================
1103 //function : offsetcurve
1106 //=======================================================================
1107 static Standard_Integer offsetcurve
1108 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1111 di<<"result + curve + offset + Dir"<<"\n";
1113 return 1 /* Error */;
1115 // Standard_CString arg1 = argv[1];
1116 // Standard_CString arg2 = argv[2];
1117 Standard_Real Offset = Draw::Atof(argv[3]);
1118 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(argv[2]);
1119 if ( GC.IsNull()) return 1;
1121 DrawTrSurf::GetPoint(argv[4],point);
1122 gp_Dir dir(point.XYZ());
1123 Handle(Geom_OffsetCurve) offcrv = new Geom_OffsetCurve(GC,Offset,dir);
1124 DrawTrSurf::Set(argv[1], offcrv);
1128 //=======================================================================
1129 //function : compose shell
1131 //=======================================================================
1132 static Standard_Integer splitface
1133 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1136 di << "Split face: splitface result face [u usplit1 usplit2...] [v vsplit1 vsplit2 ...]" << "\n";
1140 TopoDS_Shape aLocalShape = DBRep::Get(argv[2]) ;
1141 TopoDS_Face face = TopoDS::Face ( aLocalShape );
1142 if ( face.IsNull() ) {
1143 di << argv[2] << " is not Face" << "\n";
1147 Handle(Geom_Surface) S = BRep_Tool::Surface ( face );
1148 Standard_Real Uf, Ul, Vf, Vl;
1149 BRepTools::UVBounds ( face, Uf, Ul, Vf, Vl );
1150 Standard_Real Umin, Umax, Vmin, Vmax;
1151 S->Bounds ( Umin, Umax, Vmin, Vmax );
1152 if ( Uf < Umin && ! S->IsUPeriodic() ) Uf = Umin;
1153 else if ( Uf > Umin )
1154 if ( Precision::IsInfinite(Umin) ) Uf -= 100;
1156 if ( Vf < Vmin && ! S->IsVPeriodic() ) Vf = Vmin;
1157 else if ( Vf > Vmin )
1158 if ( Precision::IsInfinite(Vmin) ) Vf -= 100;
1160 if ( Ul > Umax && ! S->IsUPeriodic() ) Ul = Umax;
1161 else if ( Ul < Umax )
1162 if ( Precision::IsInfinite(Umax) ) Ul += 100;
1164 if ( Vl > Vmax && ! S->IsVPeriodic() ) Vl = Vmax;
1165 else if ( Vl < Vmax )
1166 if ( Precision::IsInfinite(Vmax) ) Vl += 100;
1169 TColStd_SequenceOfReal uval;
1170 TColStd_SequenceOfReal vval;
1172 Standard_Boolean byV = Standard_False;
1173 Standard_Integer i; // svv Jan11 2000 : porting on DEC
1174 for ( i=3; i < argc; i++ ) {
1175 if ( argv[i][0] == 'u' ) byV = Standard_False;
1176 else if ( argv[i][0] == 'v' ) byV = Standard_True;
1178 Standard_Real val = Draw::Atof ( argv[i] );
1179 TColStd_SequenceOfReal &vals = ( byV ? vval : uval );
1180 if ( vals.Length() >0 && val - vals.Last() < Precision::PConfusion() ) {
1181 di << "Values should be sorted in increasing order; skipped" << "\n";
1184 if ( ( byV && ( val < Vf+Precision::PConfusion() ||
1185 val > Vl-Precision::PConfusion() ) ) ||
1186 (!byV && ( val < Uf+Precision::PConfusion() ||
1187 val > Ul-Precision::PConfusion() ) ) ) {
1188 di << "Values should be inside range of surface; skipped" << "\n";
1191 vals.Append ( val );
1194 if ( uval.Length() <1 && vval.Length() <1 ) {
1195 di << "No splitting defined" << "\n";
1198 if ( uval.Length() >0 ) {
1199 di << "Splitting by U: ";
1200 for ( Standard_Integer j=1; j <= uval.Length(); j++ ) {
1201 //cout << ( i >j ? ", " : "" ) << uval(j);
1211 if ( vval.Length() >0 ) {
1212 di << "Splitting by V: ";
1213 for ( Standard_Integer j=1; j <= vval.Length(); j++ ) {
1214 //cout << ( j >1 ? ", " : "" ) << vval(j);
1225 Handle(TColGeom_HArray2OfSurface) AS = new TColGeom_HArray2OfSurface ( 1, uval.Length()+1,
1226 1, vval.Length()+1 );
1227 for ( i=0; i <= uval.Length(); i++ ) {
1228 Standard_Real umin = ( i ? uval(i) : Uf );
1229 Standard_Real umax = ( i < uval.Length() ? uval(i+1) : Ul );
1230 for ( Standard_Integer j=0; j <= vval.Length(); j++ ) {
1231 Standard_Real vmin = ( j ? vval(j) : Vf );
1232 Standard_Real vmax = ( j < vval.Length() ? vval(j+1) : Vl );
1233 Handle(Geom_RectangularTrimmedSurface) rect =
1234 new Geom_RectangularTrimmedSurface ( S, umin, umax, vmin, vmax );
1235 AS->SetValue ( i+1, j+1, rect );
1239 Handle(ShapeExtend_CompositeSurface) Grid = new ShapeExtend_CompositeSurface;
1240 if ( ! Grid->Init ( AS ) ) di << "Grid badly connected!" << "\n";
1242 ShapeFix_ComposeShell SUCS;
1244 SUCS.Init ( Grid, l, face, Precision::Confusion() );
1245 Handle(ShapeBuild_ReShape) RS = new ShapeBuild_ReShape;
1246 SUCS.SetContext( RS );
1249 if ( SUCS.Status ( ShapeExtend_OK ) ) di << "Status: OK" << "\n";
1250 if ( SUCS.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1" << "\n";
1251 if ( SUCS.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2" << "\n";
1252 if ( SUCS.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3" << "\n";
1253 if ( SUCS.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4" << "\n";
1254 if ( SUCS.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5" << "\n";
1255 if ( SUCS.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6" << "\n";
1256 if ( SUCS.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7" << "\n";
1257 if ( SUCS.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8" << "\n";
1258 if ( SUCS.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1" << "\n";
1259 if ( SUCS.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2" << "\n";
1260 if ( SUCS.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3" << "\n";
1261 if ( SUCS.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4" << "\n";
1262 if ( SUCS.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5" << "\n";
1263 if ( SUCS.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6" << "\n";
1264 if ( SUCS.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7" << "\n";
1265 if ( SUCS.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8" << "\n";
1267 TopoDS_Shape sh = SUCS.Result();
1268 ShapeFix::SameParameter ( sh, Standard_False );
1269 DBRep::Set ( argv[1], sh );
1273 static Standard_Integer converttobspline
1274 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1277 di << "Use: " << argv[0] << " result shape [options=ero]\n";
1278 di << "where options is combination of letters indicating kinds of\n";
1279 di << "surfaces to be converted:\n";
1280 di << "e - extrusion\n";
1281 di << "r - revolution\n";
1282 di << "o - offset\n";
1286 const char *options = ( argc > 3 ? argv[3] : "ero" );
1288 TopoDS_Shape inputShape=DBRep::Get(argv[2]);
1289 if (inputShape.IsNull()) {
1290 di << "Unknown shape"<< "\n";
1293 TopoDS_Shape revsh = ShapeCustom::ConvertToRevolution (inputShape);
1295 ShapeCustom::ConvertToBSpline (revsh, strchr (options, 'e') != 0,
1296 strchr (options, 'r') != 0,
1297 strchr (options, 'o') != 0,
1298 strchr (options, 'p') != 0);
1299 ShapeFix::SameParameter ( res, Standard_False );
1300 DBRep::Set ( argv[1], res );
1305 static Standard_Integer splitclosed (Draw_Interpretor& di,
1306 Standard_Integer argc,
1310 di << "bad number of arguments" <<"\n";
1314 TopoDS_Shape inputShape=DBRep::Get(argv[2]);
1315 if (inputShape.IsNull()) {
1316 di << "Unknown shape"<< "\n";
1320 ShapeUpgrade_ShapeDivideClosed tool (inputShape);
1322 TopoDS_Shape res = tool.Result();
1324 ShapeFix::SameParameter ( res, Standard_False );
1325 DBRep::Set ( argv[1], res );
1329 static Standard_Integer splitarea (Draw_Interpretor& di,
1330 Standard_Integer argc,
1334 di << "bad number of arguments" <<"\n";
1338 TopoDS_Shape inputShape=DBRep::Get(argv[2]);
1339 if (inputShape.IsNull()) {
1340 di << "Unknown shape"<< "\n";
1343 Standard_Real aMaxArea = Draw::Atof(argv[3]);
1346 ShapeUpgrade_ShapeDivideArea tool (inputShape);
1348 Standard_Real prec = Draw::Atof(argv[4]);
1349 tool.SetPrecision(prec);
1351 tool.MaxArea() = aMaxArea;
1353 TopoDS_Shape res = tool.Result();
1355 ShapeFix::SameParameter ( res, Standard_False );
1356 DBRep::Set ( argv[1], res );
1360 static Standard_Integer removeinternalwires (Draw_Interpretor& di,
1361 Standard_Integer argc,
1365 di << "bad number of arguments" <<"\n";
1368 Standard_Real aMinArea = Draw::Atof(argv[2]);
1369 TopoDS_Shape inputShape=DBRep::Get(argv[3]);
1370 if (inputShape.IsNull()) {
1371 di << "Unknown shape"<< "\n";
1374 Handle(ShapeUpgrade_RemoveInternalWires) aTool;
1375 TopTools_SequenceOfShape aSeqShapes;
1376 if(inputShape.ShapeType() < TopAbs_WIRE)
1377 aTool = new ShapeUpgrade_RemoveInternalWires(inputShape);
1379 di<<"Invalid type of first shape: should be FACE,SHELL,SOLID or COMPOUND"<<"\n";
1383 Standard_Integer k = 4;
1384 Standard_Boolean isShape = Standard_True;
1385 Standard_Boolean aModeRemoveFaces =Standard_True;
1388 for( ; k < argc; k++) {
1390 TopoDS_Shape aShape=DBRep::Get(argv[k]);
1391 isShape = !aShape.IsNull();
1393 if(aShape.ShapeType() == TopAbs_FACE || aShape.ShapeType() == TopAbs_WIRE)
1394 aSeqShapes.Append(aShape);
1398 aModeRemoveFaces = (Draw::Atoi(argv[k]) == 1);
1401 aTool->MinArea() = aMinArea;
1402 aTool->RemoveFaceMode() = aModeRemoveFaces;
1403 if(aSeqShapes.Length())
1404 aTool->Perform(aSeqShapes);
1407 if(aTool->Status(ShapeExtend_FAIL1))
1408 di<<"Initial shape has invalid type"<<"\n";
1409 else if(aTool->Status(ShapeExtend_FAIL2))
1410 di<<"Specified sub-shape is not belonged to whole shape"<<"\n";
1411 if(aTool->Status(ShapeExtend_DONE1)) {
1412 const TopTools_SequenceOfShape& aRemovedWires =aTool->RemovedWires();
1413 di<<aRemovedWires.Length()<<" internal wires were removed"<<"\n";
1416 if(aTool->Status(ShapeExtend_DONE2)) {
1417 const TopTools_SequenceOfShape& aRemovedFaces =aTool->RemovedFaces();
1418 di<<aRemovedFaces.Length()<<" small faces were removed"<<"\n";
1421 TopoDS_Shape res = aTool->GetResult();
1424 DBRep::Set ( argv[1], res );
1428 static Standard_Integer removeloc (Draw_Interpretor& di,
1429 Standard_Integer argc,
1433 di << "bad number of arguments. Should be: removeloc res shape" <<"\n";
1437 TopoDS_Shape aShape = DBRep::Get(argv[2]);
1440 ShapeUpgrade_RemoveLocations aRemLoc;
1441 aRemLoc.Remove(aShape);
1442 TopoDS_Shape aNewShape = aRemLoc.GetResult();
1444 DBRep::Set(argv[1],aNewShape);
1448 //=======================================================================
1450 //=======================================================================
1451 static Standard_Integer unifysamedom(Draw_Interpretor& , Standard_Integer n, const char** a)
1456 TopoDS_Shape aShape = DBRep::Get(a[2]);
1457 if (aShape.IsNull())
1460 ShapeUpgrade_UnifySameDomain Unifier(aShape);
1462 TopoDS_Shape Result = Unifier.Shape();
1464 DBRep::Set(a[1], Result);
1468 static Standard_Integer copytranslate(Draw_Interpretor& di,
1469 Standard_Integer argc,
1473 di << "bad number of arguments. Should be: removeloc res shape dx dyy dz" <<"\n";
1476 TopoDS_Shape aShape = DBRep::Get(argv[2]);
1479 Standard_Real aDx = Draw::Atof(argv[3]);
1480 Standard_Real aDy = Draw::Atof(argv[4]);
1481 Standard_Real aDz = Draw::Atof(argv[5]);
1483 aTrsf.SetTranslation(gp_Vec(aDx, aDy, aDz));
1484 BRepBuilderAPI_Transform builderTransform(aTrsf);
1485 builderTransform.Perform (aShape, true);
1486 TopoDS_Shape aNewShape = builderTransform.Shape();
1487 DBRep::Set(argv[1],aNewShape);
1492 //=======================================================================
1493 //function : InitCommands
1495 //=======================================================================
1497 void SWDRAW_ShapeUpgrade::InitCommands(Draw_Interpretor& theCommands)
1499 static Standard_Integer initactor = 0;
1500 if (initactor) return; initactor = 1;
1502 Standard_CString g = SWDRAW::GroupName(); // "Tests of DivideTool";
1504 theCommands.Add("DT_ShapeDivide",
1505 "DT_ShapeDivide Result Shape Tol: Divides shape with C1 Criterion",
1509 theCommands.Add("DT_SplitAngle",
1510 "DT_SplitAngle Result Shape [MaxAngle=95]: Divides revolved surfaces on segments less MaxAngle deg",
1514 theCommands.Add("DT_ShapeConvert",
1515 "DT_ShapeConvert Result Shape convert2d convert3d: Converts curves to beziers",
1519 theCommands.Add("DT_ShapeConvertRev",
1520 "DT_ShapeConvert Result Shape convert2d convert3d: Converts curves to beziers",
1522 DT_ShapeConvertRev,g);
1523 /* theCommands.Add("DT_PlaneDividedFace",
1524 "DT_PlaneDividedFace Result Face Tol: Transfer into a plane with boundary divided",
1526 DT_PlaneDividedFace,g);
1528 theCommands.Add("DT_PlaneGridShell",
1529 "DT_PlaneGridShell Result NbU NbV {UKnots} {VKnots} Tol : Create a plane grid Shell",
1531 DT_PlaneGridShell,g);
1533 theCommands.Add("DT_PlaneFaceCommon",
1534 "DT_PlaneFaceCommon Result Face Shell: Common between a plane Face and a Shell",
1536 DT_PlaneFaceCommon,g);*/
1538 theCommands.Add("DT_SplitCurve2d",
1539 "DT_SplitCurve2d Curve Tol: Splits the curve with C1 criterion",
1543 theCommands.Add("DT_SplitCurve",
1544 "DT_SplitCurve Curve Tol: Splits the curve with C1 criterion",
1548 theCommands.Add("DT_SplitSurface",
1549 "DT_SplitSurface Result Surface/GridSurf Tol: Splits the surface with C1 criterion",
1553 /*theCommands.Add("DT_SupportModification",
1554 "DT_SupportModification Result Shell Surface 2d3dFactor: Surface will support all the faces",
1556 DT_SupportModification,g);*/
1558 // theCommands.Add("DT_SpltWire","DT_SpltWire Result Wire Tol",
1559 // __FILE__,DT_SplitWire,g);
1561 // theCommands.Add("DT_SplitFace", "DT_SplitFace Result Face Tol",
1562 // __FILE__, DT_SplitFace,g);
1564 // theCommands.Add("DT_Debug", "DT_Debug 0/1 : activation/desactivation of the debug messages",
1565 // __FILE__, DT_Debug,g);
1566 // theCommands.Add ("shellsolid","option[a-b-c-f] shape result",
1567 // __FILE__,shellsolid,g);
1568 theCommands.Add ("offset2dcurve","result curve offset",
1569 __FILE__,offset2dcurve,g);
1571 theCommands.Add ("offsetcurve","result curve offset dir",
1572 __FILE__,offsetcurve,g);
1574 theCommands.Add ("splitface","result face [u usplit1 usplit2...] [v vsplit1 vsplit2 ...]",
1575 __FILE__,splitface,g);
1577 theCommands.Add ("DT_ToBspl","result shape [options=erop]",
1578 __FILE__,converttobspline,g);
1579 theCommands.Add ("DT_ClosedSplit","result shape",
1580 __FILE__,splitclosed,g);
1581 theCommands.Add ("DT_SplitByArea","result shape maxarea [preci]",
1582 __FILE__,splitarea,g);
1584 theCommands.Add ("RemoveIntWires","result minarea wholeshape [faces or wires] [moderemoveface ]",
1585 __FILE__,removeinternalwires,g);
1587 theCommands.Add ("removeloc","result shape",__FILE__,removeloc,g);
1589 theCommands.Add ("unifysamedom",
1590 "unifysamedom result shape",__FILE__,unifysamedom,g);
1592 theCommands.Add ("copytranslate","result shape dx dy dz",__FILE__,copytranslate,g);