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>
29 #include <ShapeUpgrade.hxx>
30 #include <ShapeUpgrade_SplitCurve3dContinuity.hxx>
31 #include <ShapeUpgrade_SplitCurve2dContinuity.hxx>
32 #include <ShapeUpgrade_SplitSurfaceContinuity.hxx>
33 //#include <ShapeUpgrade_SupportModification.hxx>
34 #include <Draw_Interpretor.hxx>
35 #include <DrawTrSurf.hxx>
36 #include <Geom_Curve.hxx>
37 #include <Geom_Plane.hxx>
38 #include <Geom_Surface.hxx>
39 #include <Geom2d_Curve.hxx>
40 #include <TColGeom_HArray1OfCurve.hxx>
41 #include <TColGeom_HArray2OfSurface.hxx>
42 #include <TColStd_Array1OfReal.hxx>
43 #include <TColStd_HArray1OfReal.hxx>
44 #include <TColStd_HSequenceOfReal.hxx>
46 #include <TopoDS_Edge.hxx>
47 #include <TopoDS_Face.hxx>
48 #include <TopoDS_Shape.hxx>
49 #include <TopoDS_Shell.hxx>
50 #include <TopoDS_Wire.hxx>
51 #include <TopoDS_Compound.hxx>
52 #include <TopExp_Explorer.hxx>
53 #include <TColGeom_HArray2OfSurface.hxx>
54 #include <TColGeom2d_HArray1OfCurve.hxx>
55 #include <BRepBuilderAPI.hxx>
57 #include <ShapeUpgrade_ShapeDivideArea.hxx>
60 //#include <ShapeExtend_WireData.hxx>
61 //#include <ShapeAnalysis_Shell.hxx>
62 //#include <ShapeAnalysis_WireOrder.hxx>
63 //#include <ShapeAnalysis_Wire.hxx>
64 //#include <ShapeUpgrade_ShellSewing.hxx>
65 #include <Geom2d_Curve.hxx>
66 #include <Geom2d_OffsetCurve.hxx>
67 #include <Geom_OffsetCurve.hxx>
68 #include <ShapeUpgrade_SplitCurve3dContinuity.hxx>
69 #include <TopoDS_Iterator.hxx>
70 #include <BRep_Tool.hxx>
71 #include <ShapeExtend_CompositeSurface.hxx>
72 #include <Geom_RectangularTrimmedSurface.hxx>
73 #include <TColGeom_HArray2OfSurface.hxx>
74 #include <ShapeFix_ComposeShell.hxx>
75 #include <Precision.hxx>
76 #include <ShapeBuild_ReShape.hxx>
77 #include <BRepTools.hxx>
78 #include <ShapeFix.hxx>
79 #include <ShapeUpgrade_ShapeDivideContinuity.hxx>
80 #include <ShapeUpgrade_ShapeDivideAngle.hxx>
81 #include <ShapeUpgrade_ShapeConvertToBezier.hxx>
82 #include <ShapeCustom.hxx>
83 #include <ShapeUpgrade_ShapeDivideClosed.hxx>
84 #include <ShapeUpgrade_RemoveInternalWires.hxx>
85 #include <ShapeUpgrade_RemoveLocations.hxx>
86 #include <ShapeUpgrade_UnifySameDomain.hxx>
87 #include <BRepBuilderAPI_Transform.hxx>
89 // the plane (equation z=0) shared by PlaneDividedFaceContinuity and PlaneGridShell
90 //static Handle(Geom_Plane) ThePlane= new Geom_Plane(0,0,1,0);
93 //=======================================================================
94 //function : DT_ShapeDivide
96 //=======================================================================
98 static Standard_Integer DT_ShapeDivide (Draw_Interpretor& di,
99 Standard_Integer n, const char** a)
101 // DT_ShapeDivide result Shape Tol
103 // a[2]= input Face/Surface
104 // a[3] si n>3= Wire/Face
108 di << "bad number of arguments" <<"\n";
112 // try to read a shape:
113 TopoDS_Shape inputShape=DBRep::Get(a[2]);
114 if (inputShape.IsNull()) {
115 di << "Unknown shape"<< "\n";
118 // a[2] is a shape. managing:
119 // DT_ShapeDivide result Face Tol
121 // giving a face is available only in the constructor:
122 // we make the whole and quit.
123 ShapeUpgrade_ShapeDivideContinuity tool(inputShape);
125 // tolerance is optional
127 Standard_Real Tol=atof(a[3]);
128 tool.SetTolerance(Tol);
131 // theTool.SetGlobalCriterion(GeomAbs_C1);
133 TopoDS_Shape res = tool.Result();
135 if ( tool.Status ( ShapeExtend_OK ) ) di << "Status: OK" << "\n";
136 if ( tool.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1" << "\n";
137 if ( tool.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2" << "\n";
138 if ( tool.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3" << "\n";
139 if ( tool.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4" << "\n";
140 if ( tool.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5" << "\n";
141 if ( tool.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6" << "\n";
142 if ( tool.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7" << "\n";
143 if ( tool.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8" << "\n";
144 if ( tool.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1" << "\n";
145 if ( tool.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2" << "\n";
146 if ( tool.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3" << "\n";
147 if ( tool.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4" << "\n";
148 if ( tool.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5" << "\n";
149 if ( tool.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6" << "\n";
150 if ( tool.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7" << "\n";
151 if ( tool.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8" << "\n";
155 ShapeFix::SameParameter ( res, Standard_False );
157 DBRep::Set(a[1],res);
161 static Standard_Integer DT_ShapeConvertRev (Draw_Interpretor& di,
162 Standard_Integer n, const char** a)
165 di << "bad number of arguments" <<"\n";
169 // try to read a shape:
170 TopoDS_Shape inputShape=DBRep::Get(a[2]);
171 if (inputShape.IsNull()) {
172 di << "Unknown shape"<< "\n";
176 Standard_Integer c2d = atoi(a[3]);
177 Standard_Integer c3d = atoi(a[4]);
178 TopoDS_Shape revsh = ShapeCustom::ConvertToRevolution (inputShape);
179 if (revsh.IsNull()) { di<<"NO RESULT"<<"\n"; return 1; }
180 else if (revsh == inputShape) { di<<"No modif"<<"\n";}
181 else di<<"ConvertToRevolution -> Result : "<<"\n";
183 ShapeUpgrade_ShapeConvertToBezier tool(revsh);
184 tool.SetSurfaceConversion(Standard_True);
186 tool.Set2dConversion(Standard_True);
188 tool.Set3dConversion(Standard_True);
190 tool.Set3dLineConversion(Standard_False);
192 tool.Set3dCircleConversion(Standard_False);
194 tool.Set3dConicConversion(Standard_False);
197 TopoDS_Shape res = tool.Result();
199 if ( tool.Status ( ShapeExtend_OK ) ) di << "Status: OK" << "\n";
200 if ( tool.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1" << "\n";
201 if ( tool.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2" << "\n";
202 if ( tool.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3" << "\n";
203 if ( tool.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4" << "\n";
204 if ( tool.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5" << "\n";
205 if ( tool.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6" << "\n";
206 if ( tool.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7" << "\n";
207 if ( tool.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8" << "\n";
208 if ( tool.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1" << "\n";
209 if ( tool.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2" << "\n";
210 if ( tool.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3" << "\n";
211 if ( tool.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4" << "\n";
212 if ( tool.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5" << "\n";
213 if ( tool.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6" << "\n";
214 if ( tool.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7" << "\n";
215 if ( tool.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8" << "\n";
219 ShapeFix::SameParameter ( res, Standard_False );
221 DBRep::Set(a[1],res);
227 if (!inputShape.IsNull()) {
228 // a[2] is a shape. managing:
229 // DT_ShapeDivide result Face Tol
231 TopoDS_Face inputFace = TopoDS::Face(inputShape);
232 if (inputFace.IsNull()) {
233 di << a[2] << " is not a face" << "\n";
237 // giving a face is available only in the constructor:
238 // we make the whole and quit.
239 ShapeUpgrade_ShapeDivideContinuity theTool(inputFace);
241 // tolerance is optional
243 Standard_Real Tol=atof(a[n-1]);
244 theTool.SetTolerance(Tol);
247 theTool.SetGlobalCriterion(GeomAbs_C1);
249 if (!theTool.IsDone()) {
250 ShapeUpgrade_Error theError=theTool.Error();
251 di << "Not done: error=";
252 if (theError==ShapeUpgrade_Done)
254 else if (theError==ShapeUpgrade_NotDone)
255 di << "NotDone"<<"\n";
256 else if (theError==ShapeUpgrade_EmptyShell)
257 di << "EmptyShell"<<"\n";
258 else if (theError==ShapeUpgrade_InvalidCriterion)
259 di << "InvalidCriterion"<<"\n";
260 else if (theError==ShapeUpgrade_InvalidGridSurface)
261 di << "InvalidGridSurface"<<"\n";
262 else if (theError==ShapeUpgrade_DegeneratedEdge)
263 di << "DegeneratedEdge"<<"\n";
264 else if (theError==ShapeUpgrade_NoSurface)
265 di << "NoSurface"<<"\n";
266 else if (theError==ShapeUpgrade_NoTolerance)
267 di << "NoTolerance"<<"\n";
270 TopoDS_Shell res = theTool.Shell();
271 DBRep::Set(a[1],res);
276 // not a face: we can use the empty consturctor.
277 ShapeUpgrade_ShapeDivideContinuity theTool;
278 Standard_Real Tol=atof(a[n-1]);
279 theTool.SetTolerance(Tol);
280 theTool.SetGlobalCriterion(GeomAbs_C1);
282 // try to read a surface:
283 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[2]);
285 // a[2] is a surface. managing the configurations:
286 // DT_ShapeDivide result Surface Tol
287 // DT_ShapeDivide result Surface Face Tol
288 // DT_ShapeDivide result Surface Wire Surf Tol
290 theTool.SetSupport(GS);
292 // try to read a Wire or a Face:
294 TopoDS_Shape inputBoundary=DBRep::Get(a[3]);
295 if (inputBoundary.IsNull()) {
296 di << "Invalid Boundary" << "\n";
299 TopoDS_Wire WireBoundary = TopoDS::Wire(inputBoundary);
300 if (!WireBoundary.IsNull()) {
301 // DT_ShapeDivide result Surface Wire Surf Tol
302 Handle(Geom_Surface) WireSupport = DrawTrSurf::GetSurface(a[4]);
303 if (WireSupport.IsNull()) {
304 di << "Invalid Surface supporting the Wire" << "\n";
307 theTool.SetBoundary(WireBoundary, WireSupport);
310 TopoDS_Face FaceBoundary = TopoDS::Face(inputBoundary);
311 // DT_ShapeDivide result Surface Face Tol
312 theTool.SetBoundary(FaceBoundary);
317 // it must be a grid: managing the configurations:
318 // DT_ShapeDivide result NbU NbV {Surf_u_v...} Tol
319 // DT_ShapeDivide result NbU NbV {Surf_u_v...} Face Tol
320 // DT_ShapeDivide result NbU NbV {Surf_u_v...} Wire Surf Tol
322 di << "bad number of arguments for grid input" <<"\n";
326 Standard_Integer NbU=atoi(a[2]);
327 Standard_Integer NbV=atoi(a[3]);
328 if (n < 4+NbU*NbV+1) {
329 di << "bad number of arguments" <<"\n";
333 Handle(TColGeom_HArray2OfSurface)
334 TheGridSurf= new TColGeom_HArray2OfSurface(1,NbU,1,NbV);
336 for (Standard_Integer iu=1; iu<=NbU; iu++) {
337 for (Standard_Integer jv=1; jv<=NbV; jv++) {
338 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[4+(iu-1)*NbV+jv-1]);
339 TheGridSurf->SetValue(iu,jv,GS);
342 theTool.SetSupport(TheGridSurf,Tol);
344 // try to read a Wire or a Face:
346 TopoDS_Shape inputBoundary=DBRep::Get(a[4+NbU*NbV]);
347 if (inputBoundary.IsNull()) {
348 di << "Invalid Boundary" << "\n";
351 TopoDS_Wire WireBoundary = TopoDS::Wire(inputBoundary);
352 if (!WireBoundary.IsNull()) {
353 // DT_ShapeDivide result Surface Wire Surf Tol
354 Handle(Geom_Surface) WireSupport = DrawTrSurf::GetSurface(a[4+NbU*NbV+1]);
355 if (WireSupport.IsNull()) {
356 di << "Invalid Surface supporting the Wire" << "\n";
359 theTool.SetBoundary(WireBoundary, WireSupport);
362 TopoDS_Face FaceBoundary = TopoDS::Face(inputBoundary);
363 // DT_ShapeDivide result Surface Face Tol
364 theTool.SetBoundary(FaceBoundary);
370 if (!theTool.IsDone()) {
371 ShapeUpgrade_Error theError=theTool.Error();
372 di << "Not done: error=";
373 if (theError==ShapeUpgrade_Done)
375 else if (theError==ShapeUpgrade_NotDone)
376 di << "NotDone"<<"\n";
377 else if (theError==ShapeUpgrade_EmptyShell)
378 di << "EmptyShell"<<"\n";
379 else if (theError==ShapeUpgrade_InvalidCriterion)
380 di << "InvalidCriterion"<<"\n";
381 else if (theError==ShapeUpgrade_InvalidGridSurface)
382 di << "InvalidGridSurface"<<"\n";
383 else if (theError==ShapeUpgrade_DegeneratedEdge)
384 di << "DegeneratedEdge"<<"\n";
385 else if (theError==ShapeUpgrade_NoSurface)
386 di << "NoSurface"<<"\n";
387 else if (theError==ShapeUpgrade_NoTolerance)
388 di << "NoTolerance"<<"\n";
392 TopoDS_Shell res = theTool.Shell();
393 DBRep::Set(a[1],res);
399 static Standard_Integer DT_ShapeConvert (Draw_Interpretor& di,
400 Standard_Integer n, const char** a)
403 di << "bad number of arguments" <<"\n";
407 // try to read a shape:
408 TopoDS_Shape inputShape=DBRep::Get(a[2]);
409 if (inputShape.IsNull()) {
410 di << "Unknown shape"<< "\n";
414 Standard_Integer c2d = atoi(a[3]);
415 Standard_Integer c3d = atoi(a[4]);
417 ShapeUpgrade_ShapeConvertToBezier tool(inputShape);
418 tool.SetSurfaceConversion(Standard_True);
420 tool.Set2dConversion(Standard_True);
422 tool.Set3dConversion(Standard_True);
424 TopoDS_Shape res = tool.Result();
426 if ( tool.Status ( ShapeExtend_OK ) ) di << "Status: OK" << "\n";
427 if ( tool.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1" << "\n";
428 if ( tool.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2" << "\n";
429 if ( tool.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3" << "\n";
430 if ( tool.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4" << "\n";
431 if ( tool.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5" << "\n";
432 if ( tool.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6" << "\n";
433 if ( tool.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7" << "\n";
434 if ( tool.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8" << "\n";
435 if ( tool.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1" << "\n";
436 if ( tool.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2" << "\n";
437 if ( tool.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3" << "\n";
438 if ( tool.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4" << "\n";
439 if ( tool.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5" << "\n";
440 if ( tool.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6" << "\n";
441 if ( tool.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7" << "\n";
442 if ( tool.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8" << "\n";
446 ShapeFix::SameParameter ( res, Standard_False );
448 DBRep::Set(a[1],res);
451 static Standard_Integer DT_SplitAngle(Draw_Interpretor& di,
452 Standard_Integer n, const char** a)
455 di << "bad number of arguments" <<"\n";
459 TopoDS_Shape inputShape=DBRep::Get(a[2]);
460 if (inputShape.IsNull()) {
461 di << "Unknown shape"<< "\n";
465 Standard_Real maxangle = 95;
467 maxangle = atof ( a[3] );
468 if ( maxangle <1 ) maxangle = 1;
471 ShapeUpgrade_ShapeDivideAngle tool(maxangle * M_PI/180,inputShape);
473 TopoDS_Shape res = tool.Result();
475 if ( tool.Status ( ShapeExtend_OK ) ) di << "Status: OK" << "\n";
476 if ( tool.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1" << "\n";
477 if ( tool.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2" << "\n";
478 if ( tool.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3" << "\n";
479 if ( tool.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4" << "\n";
480 if ( tool.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5" << "\n";
481 if ( tool.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6" << "\n";
482 if ( tool.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7" << "\n";
483 if ( tool.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8" << "\n";
484 if ( tool.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1" << "\n";
485 if ( tool.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2" << "\n";
486 if ( tool.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3" << "\n";
487 if ( tool.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4" << "\n";
488 if ( tool.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5" << "\n";
489 if ( tool.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6" << "\n";
490 if ( tool.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7" << "\n";
491 if ( tool.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8" << "\n";
495 ShapeFix::SameParameter ( res, Standard_False );
497 DBRep::Set(a[1],res);
502 //=======================================================================
503 //function : DT_PlaneDividedFace
504 //purpose : Transfer into a plane with boundary divided
507 //=======================================================================
508 static Standard_Integer DT_PlaneDividedFace (Draw_Interpretor& di,
509 Standard_Integer n, const char** a)
517 di << "bad number of arguments" <<"\n";
521 Standard_Real Tol=atof(a[3]);
522 TopoDS_Shape inputShape=DBRep::Get(a[2]);
523 TopoDS_Face inputFace = TopoDS::Face(inputShape);
524 if (inputFace.IsNull()) {
525 di << a[2] << " is not a face" << "\n";
529 ShapeUpgrade_PlaneDividedFace theTool(ThePlane);
530 theTool.Init(inputFace);
531 //theTool.SetBoundaryCriterion(GeomAbs_C1);
532 //theTool.SetTolerance(Tol);
534 if (!theTool.IsDone()) {
535 di << "Not done" << "\n";
539 TopoDS_Face res = theTool.Face();
540 DBRep::Set(a[1],res);
542 Standard_Real the2d3dFactor=theTool.Get2d3dFactor();
543 di << "2d3dFactor="<<the2d3dFactor<< "\n";
547 //=======================================================================
548 //function : DT_PlaneGridShell
549 //purpose : Create a Plane Grid Shell from U and V knots
552 //=======================================================================
553 static Standard_Integer DT_PlaneGridShell (Draw_Interpretor& di,
554 Standard_Integer n, const char** a)
563 // a[4+NbU...] = {VKnots}
564 // a[4+NbU+NbV+1] = Tol
567 Standard_Integer NbU=atoi(a[2]);
568 Standard_Integer NbV=atoi(a[3]);
569 if (n != 4+NbU+NbV+1) {
570 di << "bad number of arguments" <<"\n";
574 TColStd_Array1OfReal TheUKnots(1,NbU);
575 TColStd_Array1OfReal TheVKnots(1,NbV);
577 for (Standard_Integer ii=1; ii<=NbU; ii++) {
578 TheUKnots(ii)=atof(a[4+ii-1]);
580 for (ii=1; ii<=NbV; ii++) {
581 TheVKnots(ii)=atof(a[4+NbU+ii-1]);
584 Standard_Real Tol=atof(a[4+NbU+NbV]);
586 ShapeUpgrade_PlaneGridShell TheGrid(ThePlane,TheUKnots,TheVKnots,Tol);
588 TopoDS_Shell res = TheGrid.Shell();
589 DBRep::Set(a[1],res);
594 //=======================================================================
595 //function : DT_PlaneFaceCommon
596 //purpose : Common between a plane Face and a Shell whose all Faces are
597 // laying in the same plane
600 //=======================================================================
601 static Standard_Integer DT_PlaneFaceCommon (Draw_Interpretor& di,
602 Standard_Integer n, const char** a)
610 di << "bad number of arguments" <<"\n";
614 TopoDS_Shape inputShape= DBRep::Get(a[2]);
615 TopoDS_Face inputFace = TopoDS::Face(inputShape);
616 if (inputFace.IsNull()) {
617 di << a[2] << " is not a face" << "\n";
621 inputShape = DBRep::Get(a[3]);
622 TopoDS_Shell inputShell = TopoDS::Shell(inputShape);
623 if (inputShell.IsNull()) {
624 di << a[3] << " is not a shell" << "\n";
628 ShapeUpgrade_PlaneFaceCommon theTool;
629 theTool.Init(inputFace,inputShell);
631 TopoDS_Shell res = theTool.Shell();
632 DBRep::Set(a[1],res);
637 //=======================================================================
638 //function : DT_SplitCurve
639 //purpose : Splits the curve with C1 criterion
642 //=======================================================================
643 static Standard_Integer DT_SplitCurve (Draw_Interpretor& di,
644 Standard_Integer n, const char** a)
647 // a[1]= input curve. This name is used with a suffix to name the output curves
651 di << "bad number of arguments" <<"\n";
655 Standard_Real Tol=atof(a[2]);
656 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(a[1]);
657 if ( GC.IsNull()) return 1;
658 Standard_Integer Split = atoi(a[3]);
659 Handle(ShapeUpgrade_SplitCurve3dContinuity) theTool = new ShapeUpgrade_SplitCurve3dContinuity;
661 theTool->SetTolerance (Tol);
662 theTool->SetCriterion (GeomAbs_C1);
664 Handle(TColStd_HSequenceOfReal) spval = new TColStd_HSequenceOfReal;
665 for(Standard_Integer i = 1; i<=5; i++) spval->Append(i);
666 theTool->SetSplitValues(spval);
668 theTool->Perform (Standard_True);
669 Handle(TColGeom_HArray1OfCurve) theCurves= theTool->GetCurves();
670 Standard_Integer NbC=theCurves->Length();
671 for (Standard_Integer icurv=1; icurv<=NbC; icurv++) {
673 sprintf(name,"%s%s%d",a[1],"_",icurv);
674 char* newname = name;
675 DrawTrSurf::Set(newname, theCurves->Value(icurv));
676 di.AppendElement(newname);
682 //=======================================================================
683 //function : DT_SplitCurve2d
684 //purpose : Splits the curve with C1 criterion
687 //=======================================================================
688 static Standard_Integer DT_SplitCurve2d (Draw_Interpretor& di,
689 Standard_Integer n, const char** a)
692 // a[1]= input 2d curve. This name is used with a suffix to name the output curves
696 di << "bad number of arguments" <<"\n";
700 Standard_Real Tol=atof(a[2]);
701 Handle(Geom2d_Curve) GC = DrawTrSurf::GetCurve2d(a[1]);
702 if ( GC.IsNull()) return 1;
703 Standard_Integer Split = atoi(a[3]);
704 Handle(ShapeUpgrade_SplitCurve2dContinuity) theTool = new ShapeUpgrade_SplitCurve2dContinuity;
706 theTool->SetTolerance (Tol);
707 theTool->SetCriterion (GeomAbs_C1);
709 Handle(TColStd_HSequenceOfReal) spval = new TColStd_HSequenceOfReal;
710 for(Standard_Integer i = 1; i<=5; i++) spval->Append(i);
711 theTool->SetSplitValues(spval);
713 theTool->Perform (Standard_True);
714 Handle(TColGeom2d_HArray1OfCurve) theCurves= theTool->GetCurves();
715 Standard_Integer NbC=theCurves->Length();
716 for (Standard_Integer icurv=1; icurv<=NbC; icurv++) {
718 sprintf(name,"%s%s%d",a[1],"_",icurv);
719 char* newname = name;
720 DrawTrSurf::Set(newname, theCurves->Value(icurv));
721 di.AppendElement(newname);
727 //=======================================================================
728 //function : DT_SplitSurface
729 //purpose : Splits the surface with C1 criterion
732 //=======================================================================
734 static Standard_Integer DT_SplitWire (Draw_Interpretor& di,
735 Standard_Integer n, const char** a)
739 di << "bad number of arguments" <<"\n";
743 TopoDS_Face source = TopoDS::Face(DBRep::Get(a[2]));
744 if(source.IsNull()) {
745 di <<"Shape is not face"<<"\n";
748 TopoDS_Iterator wi(source);
750 di <<"Shape is face without wire"<<"\n";
754 TopoDS_Wire wire = TopoDS::Wire(wi.Value());
755 Handle(ShapeUpgrade_WireDivideContinuity) tool = new ShapeUpgrade_WireDivideContinuity;
756 tool->Init(wire,source);
758 Standard_Real Tol=atof(a[3]);
760 Handle(ShapeBuild_ReShape) context = new ShapeBuild_ReShape;
761 tool->Perform(context);
762 TopoDS_Wire result = tool->Wire();
763 DBRep::Set(a[1],result);
768 static Standard_Integer DT_SplitFace (Draw_Interpretor& di,
769 Standard_Integer n, const char** a)
773 di << "bad number of arguments" <<"\n";
777 TopoDS_Face source = TopoDS::Face(DBRep::Get(a[2]));
778 if(source.IsNull()) {
779 di <<"Shape is not face"<<"\n";
782 Handle(ShapeUpgrade_ShapeDivideContinuity) tool = new ShapeUpgrade_FaceDivideContinuity;
785 Standard_Real Tol=atof(a[3]);
786 tool->SetPrecision(Tol);
789 Handle(ShapeBuild_ReShape) context = new ShapeBuild_ReShape;
790 tool->Perform(context);
791 TopoDS_Shape result = tool->Result();
794 if ( tool->Status ( ShapeExtend_OK ) ) di << "Status: OK" << "\n";
795 if ( tool->Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1" << "\n";
796 if ( tool->Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2" << "\n";
797 if ( tool->Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3" << "\n";
798 if ( tool->Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4" << "\n";
799 if ( tool->Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5" << "\n";
800 if ( tool->Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6" << "\n";
801 if ( tool->Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7" << "\n";
802 if ( tool->Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8" << "\n";
803 if ( tool->Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1" << "\n";
804 if ( tool->Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2" << "\n";
805 if ( tool->Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3" << "\n";
806 if ( tool->Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4" << "\n";
807 if ( tool->Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5" << "\n";
808 if ( tool->Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6" << "\n";
809 if ( tool->Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7" << "\n";
810 if ( tool->Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8" << "\n";
814 ShapeFix::SameParameter ( result, Standard_False );
816 DBRep::Set(a[1],result);
821 static Standard_Integer DT_SplitSurface (Draw_Interpretor& di,
822 Standard_Integer n, const char** a)
825 // a[1]= result (used with a suffix to name the output surfaces)
826 // a[2]= input surface.
832 // a[3+1]..a[3+nbU*nbV] = Input Surfaces
833 // a[4+nbU*nbV]= Tolerance
836 di << "bad number of arguments" <<"\n";
840 Handle(ShapeUpgrade_SplitSurfaceContinuity) theTool = new ShapeUpgrade_SplitSurfaceContinuity;//S4137
842 Standard_Real Tol=atof(a[3]);
843 Standard_Integer Split = atoi(a[4]);
844 theTool->SetTolerance(Tol);
845 theTool->SetCriterion(GeomAbs_C1);
846 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[2]);
849 // Case of composite grid surface
850 di << "composite surf" << "\n";
851 Standard_Integer nbU=atoi(a[2]);
852 Standard_Integer nbV=atoi(a[3]);
853 if (nbU==0 || nbV==0) return 1;
854 Handle(TColGeom_HArray2OfSurface)
855 theGrid= new TColGeom_HArray2OfSurface(1,nbU,1,nbV);
856 for (Standard_Integer iu=1; iu<=nbU; iu++) {
857 for (Standard_Integer iv=1; iv<=nbV; iv++) {
858 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[3+(iu-1)*nbV+iv]);
859 theGrid->SetValue(iu,iv,GS);
862 di << "appel a SplitSurface::Init" << "\n";
863 theTool->Init(theGrid);
866 // Case of single surface
867 di << "single surf" << "\n";
869 di << "appel a SplitSurface::Init" << "\n";
872 Handle(TColStd_HSequenceOfReal) spval = new TColStd_HSequenceOfReal;
873 for(Standard_Integer i = 1; i<=5; i++) spval->Append(i);
874 theTool->SetUSplitValues(spval);
875 theTool->SetVSplitValues(spval);
878 di << "appel a SplitSurface::Build" << "\n";
879 theTool->Build(Standard_True);
881 di << "appel a SplitSurface::GlobalU/VKnots" << "\n";
882 Handle(ShapeExtend_CompositeSurface) Grid = theTool->ResSurfaces();
883 Handle(TColStd_HArray1OfReal) GlobalU=Grid->UJointValues();
884 Handle(TColStd_HArray1OfReal) GlobalV=Grid->VJointValues();
885 Standard_Integer nbGlU=GlobalU->Length();
886 Standard_Integer nbGlV=GlobalV->Length();
887 di << "nb GlobalU ; nb GlobalV="<<nbGlU<<" "<<nbGlV;
888 for (Standard_Integer iu=1; iu<=nbGlU; iu++)
889 di <<" "<< GlobalU->Value(iu);
891 // di << "nb GlobalV="<<nbGlV;
892 for (Standard_Integer iv=1; iv<=nbGlV; iv++)
893 di <<" "<< GlobalV->Value(iv);
896 di << "appel a Surfaces" << "\n";
897 Handle(TColGeom_HArray2OfSurface) theSurfaces= Grid->Patches();
899 di << "transfert resultat" << "\n";
900 Standard_Integer NbRow=theSurfaces->ColLength();
901 Standard_Integer NbCol=theSurfaces->RowLength();
902 for (Standard_Integer irow=1; irow<=NbRow; irow++) {
903 for (Standard_Integer icol=1; icol<=NbCol; icol++) {
905 sprintf(name,"%s%s%d%s%d",a[1],"_",irow,"_",icol);
906 char* newname = name;
907 DrawTrSurf::Set(newname, theSurfaces->Value(irow, icol));
908 di.AppendElement(newname);
916 //=======================================================================
917 //function : DT_SupportModification
918 //purpose : Changes the supports of a Shell
919 // The given surface wil support all the faces of the new shell.
920 // with the PCurves of the old ones.
922 //=======================================================================
923 /*static Standard_Integer DT_SupportModification (Draw_Interpretor& di,
924 Standard_Integer n, const char** a)
930 // a[4]= 2d3d Scale Factor
933 di << "bad number of arguments" <<"\n";
937 TopoDS_Shape inputShape= DBRep::Get(a[2]);
938 TopoDS_Shell inputShell = TopoDS::Shell(inputShape);
939 if (inputShell.IsNull()) {
940 di << a[2] << " is not a shell" << "\n";
944 Handle(Geom_Surface) theSurf = DrawTrSurf::GetSurface(a[3]);
945 if ( theSurf.IsNull()) {
946 di << a[3] << " is not a surface" << "\n";
950 ShapeUpgrade_DataMapOfShapeSurface theMap;
951 // Associates thesurf to each face of inputShell.
952 TopExp_Explorer ExpSh;
953 for (ExpSh.Init(inputShell,TopAbs_FACE); ExpSh.More(); ExpSh.Next()){
954 TopoDS_Face theFace= TopoDS::Face(ExpSh.Current());
955 theMap.Bind(theFace,theSurf);
958 Standard_Real the2d3dFactor=atof(a[4]);
959 ShapeUpgrade_SupportModification theTool(inputShell,theMap,the2d3dFactor);
961 TopoDS_Shell res = theTool.Shell();
962 DBRep::Set(a[1],res);
967 //=======================================================================
968 //function : DT_Debug
969 //purpose : activation of the debug mode
971 //=======================================================================
973 static Standard_Integer DT_Debug (Draw_Interpretor& di,
974 Standard_Integer n, const char** a)
980 di << "bad number of arguments" <<"\n";
985 di << "Activation of debug messages"<<"\n";
986 ShapeUpgrade::SetDebug(Standard_True);
989 di << "Desactivation of debug messages"<<"\n";
990 ShapeUpgrade::SetDebug(Standard_False);
996 /*static Standard_Integer shellsolid
997 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1000 di<<"Donner option + nom de SHAPE + nom de RESULTAT"<<"\n";
1001 di<<"Options : a all (sewing sur tous les shells\n"
1002 << " c check (sewing sur shells avec bad edges\n"
1003 <<" b bad edges\n f free edges"<<"\n";
1006 Standard_CString arg1 = argv[1];
1007 Standard_CString arg2 = argv[2];
1008 Standard_CString arg3 = argv[3];
1010 TopoDS_Shape Shape = DBRep::Get(arg2);
1011 if (Shape.IsNull()) { di<<"Shape unknown : "<<arg2<<"\n"; return 1 ; }
1013 ShapeAnalysis_Shell STS;
1015 if (opt == 'a') STS.LoadShells (Shape);
1016 else if (opt == 'f') STS.CheckOrientedShells (Shape,Standard_True);
1017 else if (opt == 'b' || opt == 'c') STS.CheckOrientedShells (Shape,Standard_False);
1019 else if (opt == 'o') {
1022 Handle(ShapeExtend_WireData) Frees = new ShapeExtend_WireData;//:sw Frees.SetPrecision (BRepBuilderAPI::Precision());
1023 Standard_Integer nbe = 0;
1024 for (TopExp_Explorer edges(Shape,TopAbs_EDGE); edges.More(); edges.Next()) {
1025 Frees->Add (TopoDS::Edge(edges.Current())); nbe ++;
1027 ShapeAnalysis_WireOrder WO (Standard_True,BRepBuilderAPI::Precision());
1028 ShapeAnalysis_Wire saw;
1030 saw.SetPrecision ( BRepBuilderAPI::Precision() );
1031 saw.CheckOrder ( WO );
1033 Standard_Integer stat = WO.Status();
1034 di<<"Wire Order Status = "<<stat<<" on "<<nbe<<" Edges"<<"\n";
1036 for (Standard_Integer ie = 1; ie <= nbe; ie ++) {
1037 Standard_Integer io = WO.Ordered (ie);
1039 WO.XYZ (io,st3d,en3d);
1040 di<<ie<<": Edge."<<io<<" Start:"<<st3d.X()<<" "<<st3d.Y()<<" "<<st3d.Z()
1041 <<" End:"<<en3d.X()<<" "<<en3d.Y()<<" "<<en3d.Z()<<"\n";
1044 Standard_Real gap = BRepBuilderAPI::Precision();
1046 Standard_Integer n1,n2,ic, nc = WO.NbChains();
1047 for (ic = 1; ic <= nc; ic ++) {
1049 di<<"Chain."<<ic<<" From "<<n1<<" To "<<n2<<"\n";
1053 else { di<<"Option non reconnue : "<<arg1<<"\n"; return 1; }
1056 if (opt == 'a' || opt == 'c') {
1057 ShapeUpgrade_ShellSewing sew;
1058 res = sew.ApplySewing (Shape);
1059 if (res.IsEqual(Shape)) {
1061 di<<"ShellSolid : no sewing done"<<"\n";
1063 } else if (opt == 'b') {
1064 if (STS.HasBadEdges()) res = STS.BadEdges();
1065 else di<<"ShellSolid : no bad edge"<<"\n";
1066 } else if (opt == 'f') {
1067 if (STS.HasFreeEdges()) res = STS.FreeEdges();
1068 else di<<"ShellSolid : no free edge"<<"\n";
1069 if (STS.HasConnectedEdges()) di<<"ShellSolid : connected edges"<<"\n";
1070 else di<<"ShellSolid : NO connected edges"<<"\n";
1073 if (!res.IsNull()) DBRep::Set (arg3,res);
1077 //---------------gka
1078 //=======================================================================
1079 //function : offset2dcurve
1082 //=======================================================================
1083 static Standard_Integer offset2dcurve
1084 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1087 di<<"result + curve + offset"<<"\n";
1089 return 1 /* Error */;
1091 // Standard_CString arg1 = argv[1];
1092 // Standard_CString arg2 = argv[2];
1093 Standard_Real Offset = atof(argv[3]);
1094 Handle(Geom2d_Curve) GC = DrawTrSurf::GetCurve2d(argv[2]);
1095 if ( GC.IsNull()) return 1;
1096 Handle(Geom2d_OffsetCurve) offcrv = new Geom2d_OffsetCurve(GC,Offset);
1097 DrawTrSurf::Set(argv[1], offcrv);
1101 //=======================================================================
1102 //function : offsetcurve
1105 //=======================================================================
1106 static Standard_Integer offsetcurve
1107 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1110 di<<"result + curve + offset + Dir"<<"\n";
1112 return 1 /* Error */;
1114 // Standard_CString arg1 = argv[1];
1115 // Standard_CString arg2 = argv[2];
1116 Standard_Real Offset = atof(argv[3]);
1117 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(argv[2]);
1118 if ( GC.IsNull()) return 1;
1120 DrawTrSurf::GetPoint(argv[4],point);
1121 gp_Dir dir(point.XYZ());
1122 Handle(Geom_OffsetCurve) offcrv = new Geom_OffsetCurve(GC,Offset,dir);
1123 DrawTrSurf::Set(argv[1], offcrv);
1127 //=======================================================================
1128 //function : compose shell
1130 //=======================================================================
1131 static Standard_Integer splitface
1132 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1135 di << "Split face: splitface result face [u usplit1 usplit2...] [v vsplit1 vsplit2 ...]" << "\n";
1139 TopoDS_Shape aLocalShape = DBRep::Get(argv[2]) ;
1140 TopoDS_Face face = TopoDS::Face ( aLocalShape );
1141 if ( face.IsNull() ) {
1142 di << argv[2] << " is not Face" << "\n";
1146 Handle(Geom_Surface) S = BRep_Tool::Surface ( face );
1147 Standard_Real Uf, Ul, Vf, Vl;
1148 BRepTools::UVBounds ( face, Uf, Ul, Vf, Vl );
1149 Standard_Real Umin, Umax, Vmin, Vmax;
1150 S->Bounds ( Umin, Umax, Vmin, Vmax );
1151 if ( Uf < Umin && ! S->IsUPeriodic() ) Uf = Umin;
1152 else if ( Uf > Umin )
1153 if ( Precision::IsInfinite(Umin) ) Uf -= 100;
1155 if ( Vf < Vmin && ! S->IsVPeriodic() ) Vf = Vmin;
1156 else if ( Vf > Vmin )
1157 if ( Precision::IsInfinite(Vmin) ) Vf -= 100;
1159 if ( Ul > Umax && ! S->IsUPeriodic() ) Ul = Umax;
1160 else if ( Ul < Umax )
1161 if ( Precision::IsInfinite(Umax) ) Ul += 100;
1163 if ( Vl > Vmax && ! S->IsVPeriodic() ) Vl = Vmax;
1164 else if ( Vl < Vmax )
1165 if ( Precision::IsInfinite(Vmax) ) Vl += 100;
1168 TColStd_SequenceOfReal uval;
1169 TColStd_SequenceOfReal vval;
1171 Standard_Boolean byV = Standard_False;
1172 Standard_Integer i; // svv Jan11 2000 : porting on DEC
1173 for ( i=3; i < argc; i++ ) {
1174 if ( argv[i][0] == 'u' ) byV = Standard_False;
1175 else if ( argv[i][0] == 'v' ) byV = Standard_True;
1177 Standard_Real val = atof ( argv[i] );
1178 TColStd_SequenceOfReal &vals = ( byV ? vval : uval );
1179 if ( vals.Length() >0 && val - vals.Last() < Precision::PConfusion() ) {
1180 di << "Values should be sorted in increasing order; skipped" << "\n";
1183 if ( ( byV && ( val < Vf+Precision::PConfusion() ||
1184 val > Vl-Precision::PConfusion() ) ) ||
1185 (!byV && ( val < Uf+Precision::PConfusion() ||
1186 val > Ul-Precision::PConfusion() ) ) ) {
1187 di << "Values should be inside range of surface; skipped" << "\n";
1190 vals.Append ( val );
1193 if ( uval.Length() <1 && vval.Length() <1 ) {
1194 di << "No splitting defined" << "\n";
1197 if ( uval.Length() >0 ) {
1198 di << "Splitting by U: ";
1199 for ( Standard_Integer j=1; j <= uval.Length(); j++ ) {
1200 //cout << ( i >j ? ", " : "" ) << uval(j);
1210 if ( vval.Length() >0 ) {
1211 di << "Splitting by V: ";
1212 for ( Standard_Integer j=1; j <= vval.Length(); j++ ) {
1213 //cout << ( j >1 ? ", " : "" ) << vval(j);
1224 Handle(TColGeom_HArray2OfSurface) AS = new TColGeom_HArray2OfSurface ( 1, uval.Length()+1,
1225 1, vval.Length()+1 );
1226 for ( i=0; i <= uval.Length(); i++ ) {
1227 Standard_Real umin = ( i ? uval(i) : Uf );
1228 Standard_Real umax = ( i < uval.Length() ? uval(i+1) : Ul );
1229 for ( Standard_Integer j=0; j <= vval.Length(); j++ ) {
1230 Standard_Real vmin = ( j ? vval(j) : Vf );
1231 Standard_Real vmax = ( j < vval.Length() ? vval(j+1) : Vl );
1232 Handle(Geom_RectangularTrimmedSurface) rect =
1233 new Geom_RectangularTrimmedSurface ( S, umin, umax, vmin, vmax );
1234 AS->SetValue ( i+1, j+1, rect );
1238 Handle(ShapeExtend_CompositeSurface) Grid = new ShapeExtend_CompositeSurface;
1239 if ( ! Grid->Init ( AS ) ) di << "Grid badly connected!" << "\n";
1241 ShapeFix_ComposeShell SUCS;
1243 SUCS.Init ( Grid, l, face, Precision::Confusion() );
1244 Handle(ShapeBuild_ReShape) RS = new ShapeBuild_ReShape;
1245 SUCS.SetContext( RS );
1248 if ( SUCS.Status ( ShapeExtend_OK ) ) di << "Status: OK" << "\n";
1249 if ( SUCS.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1" << "\n";
1250 if ( SUCS.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2" << "\n";
1251 if ( SUCS.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3" << "\n";
1252 if ( SUCS.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4" << "\n";
1253 if ( SUCS.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5" << "\n";
1254 if ( SUCS.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6" << "\n";
1255 if ( SUCS.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7" << "\n";
1256 if ( SUCS.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8" << "\n";
1257 if ( SUCS.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1" << "\n";
1258 if ( SUCS.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2" << "\n";
1259 if ( SUCS.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3" << "\n";
1260 if ( SUCS.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4" << "\n";
1261 if ( SUCS.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5" << "\n";
1262 if ( SUCS.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6" << "\n";
1263 if ( SUCS.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7" << "\n";
1264 if ( SUCS.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8" << "\n";
1266 TopoDS_Shape sh = SUCS.Result();
1267 ShapeFix::SameParameter ( sh, Standard_False );
1268 DBRep::Set ( argv[1], sh );
1272 static Standard_Integer converttobspline
1273 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1276 di << "Use: " << argv[0] << " result shape [options=ero]\n";
1277 di << "where options is combination of letters indicating kinds of\n";
1278 di << "surfaces to be converted:\n";
1279 di << "e - extrusion\n";
1280 di << "r - revolution\n";
1281 di << "o - offset\n";
1285 const char *options = ( argc > 3 ? argv[3] : "ero" );
1287 TopoDS_Shape inputShape=DBRep::Get(argv[2]);
1288 if (inputShape.IsNull()) {
1289 di << "Unknown shape"<< "\n";
1292 TopoDS_Shape revsh = ShapeCustom::ConvertToRevolution (inputShape);
1294 ShapeCustom::ConvertToBSpline (revsh, strchr (options, 'e') != 0,
1295 strchr (options, 'r') != 0,
1296 strchr (options, 'o') != 0,
1297 strchr (options, 'p') != 0);
1298 ShapeFix::SameParameter ( res, Standard_False );
1299 DBRep::Set ( argv[1], res );
1304 static Standard_Integer splitclosed (Draw_Interpretor& di,
1305 Standard_Integer argc,
1309 di << "bad number of arguments" <<"\n";
1313 TopoDS_Shape inputShape=DBRep::Get(argv[2]);
1314 if (inputShape.IsNull()) {
1315 di << "Unknown shape"<< "\n";
1319 ShapeUpgrade_ShapeDivideClosed tool (inputShape);
1321 TopoDS_Shape res = tool.Result();
1323 ShapeFix::SameParameter ( res, Standard_False );
1324 DBRep::Set ( argv[1], res );
1328 static Standard_Integer splitarea (Draw_Interpretor& di,
1329 Standard_Integer argc,
1333 di << "bad number of arguments" <<"\n";
1337 TopoDS_Shape inputShape=DBRep::Get(argv[2]);
1338 if (inputShape.IsNull()) {
1339 di << "Unknown shape"<< "\n";
1342 Standard_Real aMaxArea = atof(argv[3]);
1345 ShapeUpgrade_ShapeDivideArea tool (inputShape);
1347 Standard_Real prec = atof(argv[4]);
1348 tool.SetPrecision(prec);
1350 tool.MaxArea() = aMaxArea;
1352 TopoDS_Shape res = tool.Result();
1354 ShapeFix::SameParameter ( res, Standard_False );
1355 DBRep::Set ( argv[1], res );
1359 static Standard_Integer removeinternalwires (Draw_Interpretor& di,
1360 Standard_Integer argc,
1364 di << "bad number of arguments" <<"\n";
1367 Standard_Real aMinArea = atof(argv[2]);
1368 TopoDS_Shape inputShape=DBRep::Get(argv[3]);
1369 if (inputShape.IsNull()) {
1370 di << "Unknown shape"<< "\n";
1373 Handle(ShapeUpgrade_RemoveInternalWires) aTool;
1374 TopTools_SequenceOfShape aSeqShapes;
1375 if(inputShape.ShapeType() < TopAbs_WIRE)
1376 aTool = new ShapeUpgrade_RemoveInternalWires(inputShape);
1378 di<<"Invalid type of first shape: should be FACE,SHELL,SOLID or COMPOUND"<<"\n";
1382 Standard_Integer k = 4;
1383 Standard_Boolean isShape = Standard_True;
1384 Standard_Boolean aModeRemoveFaces =Standard_True;
1387 for( ; k < argc; k++) {
1389 TopoDS_Shape aShape=DBRep::Get(argv[k]);
1390 isShape = !aShape.IsNull();
1392 if(aShape.ShapeType() == TopAbs_FACE || aShape.ShapeType() == TopAbs_WIRE)
1393 aSeqShapes.Append(aShape);
1397 aModeRemoveFaces = (atoi(argv[k]) == 1);
1400 aTool->MinArea() = aMinArea;
1401 aTool->RemoveFaceMode() = aModeRemoveFaces;
1402 if(aSeqShapes.Length())
1403 aTool->Perform(aSeqShapes);
1406 if(aTool->Status(ShapeExtend_FAIL1))
1407 di<<"Initial shape has invalid type"<<"\n";
1408 else if(aTool->Status(ShapeExtend_FAIL2))
1409 di<<"Specified sub-shape is not belonged to whole shape"<<"\n";
1410 if(aTool->Status(ShapeExtend_DONE1)) {
1411 const TopTools_SequenceOfShape& aRemovedWires =aTool->RemovedWires();
1412 di<<aRemovedWires.Length()<<" internal wires were removed"<<"\n";
1415 if(aTool->Status(ShapeExtend_DONE2)) {
1416 const TopTools_SequenceOfShape& aRemovedFaces =aTool->RemovedFaces();
1417 di<<aRemovedFaces.Length()<<" small faces were removed"<<"\n";
1420 TopoDS_Shape res = aTool->GetResult();
1423 DBRep::Set ( argv[1], res );
1427 static Standard_Integer removeloc (Draw_Interpretor& di,
1428 Standard_Integer argc,
1432 di << "bad number of arguments. Should be: removeloc res shape" <<"\n";
1436 TopoDS_Shape aShape = DBRep::Get(argv[2]);
1439 ShapeUpgrade_RemoveLocations aRemLoc;
1440 aRemLoc.Remove(aShape);
1441 TopoDS_Shape aNewShape = aRemLoc.GetResult();
1443 DBRep::Set(argv[1],aNewShape);
1447 //=======================================================================
1449 //=======================================================================
1450 static Standard_Integer unifysamedom(Draw_Interpretor& , Standard_Integer n, const char** a)
1455 TopoDS_Shape aShape = DBRep::Get(a[2]);
1456 if (aShape.IsNull())
1459 ShapeUpgrade_UnifySameDomain Unifier(aShape);
1461 TopoDS_Shape Result = Unifier.Shape();
1463 DBRep::Set(a[1], Result);
1467 static Standard_Integer copytranslate(Draw_Interpretor& di,
1468 Standard_Integer argc,
1472 di << "bad number of arguments. Should be: removeloc res shape dx dyy dz" <<"\n";
1475 TopoDS_Shape aShape = DBRep::Get(argv[2]);
1478 Standard_Real aDx = atof(argv[3]);
1479 Standard_Real aDy = atof(argv[4]);
1480 Standard_Real aDz = atof(argv[5]);
1482 aTrsf.SetTranslation(gp_Vec(aDx, aDy, aDz));
1483 BRepBuilderAPI_Transform builderTransform(aTrsf);
1484 builderTransform.Perform (aShape, true);
1485 TopoDS_Shape aNewShape = builderTransform.Shape();
1486 DBRep::Set(argv[1],aNewShape);
1491 //=======================================================================
1492 //function : InitCommands
1494 //=======================================================================
1496 void SWDRAW_ShapeUpgrade::InitCommands(Draw_Interpretor& theCommands)
1498 static Standard_Integer initactor = 0;
1499 if (initactor) return; initactor = 1;
1501 Standard_CString g = SWDRAW::GroupName(); // "Tests of DivideTool";
1503 theCommands.Add("DT_ShapeDivide",
1504 "DT_ShapeDivide Result Shape Tol: Divides shape with C1 Criterion",
1508 theCommands.Add("DT_SplitAngle",
1509 "DT_SplitAngle Result Shape [MaxAngle=95]: Divides revolved surfaces on segments less MaxAngle deg",
1513 theCommands.Add("DT_ShapeConvert",
1514 "DT_ShapeConvert Result Shape convert2d convert3d: Converts curves to beziers",
1518 theCommands.Add("DT_ShapeConvertRev",
1519 "DT_ShapeConvert Result Shape convert2d convert3d: Converts curves to beziers",
1521 DT_ShapeConvertRev,g);
1522 /* theCommands.Add("DT_PlaneDividedFace",
1523 "DT_PlaneDividedFace Result Face Tol: Transfer into a plane with boundary divided",
1525 DT_PlaneDividedFace,g);
1527 theCommands.Add("DT_PlaneGridShell",
1528 "DT_PlaneGridShell Result NbU NbV {UKnots} {VKnots} Tol : Create a plane grid Shell",
1530 DT_PlaneGridShell,g);
1532 theCommands.Add("DT_PlaneFaceCommon",
1533 "DT_PlaneFaceCommon Result Face Shell: Common between a plane Face and a Shell",
1535 DT_PlaneFaceCommon,g);*/
1537 theCommands.Add("DT_SplitCurve2d",
1538 "DT_SplitCurve2d Curve Tol: Splits the curve with C1 criterion",
1542 theCommands.Add("DT_SplitCurve",
1543 "DT_SplitCurve Curve Tol: Splits the curve with C1 criterion",
1547 theCommands.Add("DT_SplitSurface",
1548 "DT_SplitSurface Result Surface/GridSurf Tol: Splits the surface with C1 criterion",
1552 /*theCommands.Add("DT_SupportModification",
1553 "DT_SupportModification Result Shell Surface 2d3dFactor: Surface will support all the faces",
1555 DT_SupportModification,g);*/
1557 // theCommands.Add("DT_SpltWire","DT_SpltWire Result Wire Tol",
1558 // __FILE__,DT_SplitWire,g);
1560 // theCommands.Add("DT_SplitFace", "DT_SplitFace Result Face Tol",
1561 // __FILE__, DT_SplitFace,g);
1563 // theCommands.Add("DT_Debug", "DT_Debug 0/1 : activation/desactivation of the debug messages",
1564 // __FILE__, DT_Debug,g);
1565 // theCommands.Add ("shellsolid","option[a-b-c-f] shape result",
1566 // __FILE__,shellsolid,g);
1567 theCommands.Add ("offset2dcurve","result curve offset",
1568 __FILE__,offset2dcurve,g);
1570 theCommands.Add ("offsetcurve","result curve offset dir",
1571 __FILE__,offsetcurve,g);
1573 theCommands.Add ("splitface","result face [u usplit1 usplit2...] [v vsplit1 vsplit2 ...]",
1574 __FILE__,splitface,g);
1576 theCommands.Add ("DT_ToBspl","result shape [options=erop]",
1577 __FILE__,converttobspline,g);
1578 theCommands.Add ("DT_ClosedSplit","result shape",
1579 __FILE__,splitclosed,g);
1580 theCommands.Add ("DT_SplitByArea","result shape maxarea [preci]",
1581 __FILE__,splitarea,g);
1583 theCommands.Add ("RemoveIntWires","result minarea wholeshape [faces or wires] [moderemoveface ]",
1584 __FILE__,removeinternalwires,g);
1586 theCommands.Add ("removeloc","result shape",__FILE__,removeloc,g);
1588 theCommands.Add ("unifysamedom",
1589 "unifysamedom result shape",__FILE__,unifysamedom,g);
1591 theCommands.Add ("copytranslate","result shape dx dy dz",__FILE__,copytranslate,g);