Adding test cases from chl grid
[occt.git] / src / SWDRAW / SWDRAW_ShapeUpgrade.cxx
CommitLineData
b311480e 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
5//
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.
10//
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.
13//
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.
20
7fd59977 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
24
25#include <SWDRAW_ShapeUpgrade.ixx>
2277323d 26//#include <SWDRAW_ShapeUpgrade.hxx>
7fd59977 27
28#include <DBRep.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>
45#include <TopoDS.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>
56#include <SWDRAW.hxx>
57#include <ShapeUpgrade_ShapeDivideArea.hxx>
58
59#include <stdio.h>
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>
982a90fc 85#include <ShapeUpgrade_RemoveLocations.hxx>
2277323d 86#include <ShapeUpgrade_UnifySameDomain.hxx>
982a90fc
G
87#include <BRepBuilderAPI_Transform.hxx>
88
7fd59977 89// the plane (equation z=0) shared by PlaneDividedFaceContinuity and PlaneGridShell
90//static Handle(Geom_Plane) ThePlane= new Geom_Plane(0,0,1,0);
91
92
93//=======================================================================
94//function : DT_ShapeDivide
95//purpose :
96//=======================================================================
97
98static Standard_Integer DT_ShapeDivide (Draw_Interpretor& di,
99 Standard_Integer n, const char** a)
100{
101 // DT_ShapeDivide result Shape Tol
102 // a[1]= result
103 // a[2]= input Face/Surface
104 // a[3] si n>3= Wire/Face
105 // a[n-1]= Tolerance
106
107 if (n<3) {
108 di << "bad number of arguments" <<"\n";
109 return 1;
110 }
111
112 // try to read a shape:
113 TopoDS_Shape inputShape=DBRep::Get(a[2]);
114 if (inputShape.IsNull()) {
115 di << "Unknown shape"<< "\n";
116 return 1;
117 }
118 // a[2] is a shape. managing:
119 // DT_ShapeDivide result Face Tol
120
121 // giving a face is available only in the constructor:
122 // we make the whole and quit.
123 ShapeUpgrade_ShapeDivideContinuity tool(inputShape);
124
125 // tolerance is optional
126 if (n==4) {
127 Standard_Real Tol=atof(a[3]);
128 tool.SetTolerance(Tol);
129 }
130
131 // theTool.SetGlobalCriterion(GeomAbs_C1);
132 tool.Perform();
133 TopoDS_Shape res = tool.Result();
134
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";
152
153 // fixes
154
155 ShapeFix::SameParameter ( res, Standard_False );
156
157 DBRep::Set(a[1],res);
158 return 0;
159}
160
161static Standard_Integer DT_ShapeConvertRev (Draw_Interpretor& di,
162 Standard_Integer n, const char** a)
163{
164 if (n<5) {
165 di << "bad number of arguments" <<"\n";
166 return 1;
167 }
168
169 // try to read a shape:
170 TopoDS_Shape inputShape=DBRep::Get(a[2]);
171 if (inputShape.IsNull()) {
172 di << "Unknown shape"<< "\n";
173 return 1;
174 }
175
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";
182
183 ShapeUpgrade_ShapeConvertToBezier tool(revsh);
184 tool.SetSurfaceConversion(Standard_True);
185 if(c2d)
186 tool.Set2dConversion(Standard_True);
187 if(c3d) {
188 tool.Set3dConversion(Standard_True);
189 if(n > 5)
190 tool.Set3dLineConversion(Standard_False);
191 if(n > 6)
192 tool.Set3dCircleConversion(Standard_False);
193 if(n > 7)
194 tool.Set3dConicConversion(Standard_False);
195 }
196 tool.Perform();
197 TopoDS_Shape res = tool.Result();
198
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";
216
217 // fixes
218
219 ShapeFix::SameParameter ( res, Standard_False );
220
221 DBRep::Set(a[1],res);
222 return 0;
223}
224
225
226/*
227 if (!inputShape.IsNull()) {
228 // a[2] is a shape. managing:
229 // DT_ShapeDivide result Face Tol
230
231 TopoDS_Face inputFace = TopoDS::Face(inputShape);
232 if (inputFace.IsNull()) {
233 di << a[2] << " is not a face" << "\n";
234 return 1;
235 }
236
237 // giving a face is available only in the constructor:
238 // we make the whole and quit.
239 ShapeUpgrade_ShapeDivideContinuity theTool(inputFace);
240
241 // tolerance is optional
242 if (n==4) {
243 Standard_Real Tol=atof(a[n-1]);
244 theTool.SetTolerance(Tol);
245 }
246
247 theTool.SetGlobalCriterion(GeomAbs_C1);
248 theTool.Build();
249 if (!theTool.IsDone()) {
250 ShapeUpgrade_Error theError=theTool.Error();
251 di << "Not done: error=";
252 if (theError==ShapeUpgrade_Done)
253 di << "Done"<<"\n";
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";
268 return 1;
269 }
270 TopoDS_Shell res = theTool.Shell();
271 DBRep::Set(a[1],res);
272
273 return 0;
274 }
275 else {
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);
281
282 // try to read a surface:
283 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[2]);
284 if (! GS.IsNull()) {
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
289
290 theTool.SetSupport(GS);
291
292 // try to read a Wire or a Face:
293 if (n>=5) {
294 TopoDS_Shape inputBoundary=DBRep::Get(a[3]);
295 if (inputBoundary.IsNull()) {
296 di << "Invalid Boundary" << "\n";
297 return 1;
298 }
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";
305 return 1;
306 }
307 theTool.SetBoundary(WireBoundary, WireSupport);
308 }
309 else {
310 TopoDS_Face FaceBoundary = TopoDS::Face(inputBoundary);
311 // DT_ShapeDivide result Surface Face Tol
312 theTool.SetBoundary(FaceBoundary);
313 }
314 }
315 }
316 else {
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
321 if (n<6) {
322 di << "bad number of arguments for grid input" <<"\n";
323 return 1;
324 }
325 // number of surf:
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";
330 return 1;
331 }
332
333 Handle(TColGeom_HArray2OfSurface)
334 TheGridSurf= new TColGeom_HArray2OfSurface(1,NbU,1,NbV);
335
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);
340 }
341 }
342 theTool.SetSupport(TheGridSurf,Tol);
343
344 // try to read a Wire or a Face:
345 if (n>=6+NbU*NbV) {
346 TopoDS_Shape inputBoundary=DBRep::Get(a[4+NbU*NbV]);
347 if (inputBoundary.IsNull()) {
348 di << "Invalid Boundary" << "\n";
349 return 1;
350 }
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";
357 return 1;
358 }
359 theTool.SetBoundary(WireBoundary, WireSupport);
360 }
361 else {
362 TopoDS_Face FaceBoundary = TopoDS::Face(inputBoundary);
363 // DT_ShapeDivide result Surface Face Tol
364 theTool.SetBoundary(FaceBoundary);
365 }
366 }
367 }
368
369 theTool.Build();
370 if (!theTool.IsDone()) {
371 ShapeUpgrade_Error theError=theTool.Error();
372 di << "Not done: error=";
373 if (theError==ShapeUpgrade_Done)
374 di << "Done"<<"\n";
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";
389 return 1;
390 }
391
392 TopoDS_Shell res = theTool.Shell();
393 DBRep::Set(a[1],res);
394
395 return 0;
396 }
397}
398*/
399static Standard_Integer DT_ShapeConvert (Draw_Interpretor& di,
400 Standard_Integer n, const char** a)
401{
402 if (n<5) {
403 di << "bad number of arguments" <<"\n";
404 return 1;
405 }
406
407 // try to read a shape:
408 TopoDS_Shape inputShape=DBRep::Get(a[2]);
409 if (inputShape.IsNull()) {
410 di << "Unknown shape"<< "\n";
411 return 1;
412 }
413
414 Standard_Integer c2d = atoi(a[3]);
415 Standard_Integer c3d = atoi(a[4]);
416
417 ShapeUpgrade_ShapeConvertToBezier tool(inputShape);
418 tool.SetSurfaceConversion(Standard_True);
419 if(c2d)
420 tool.Set2dConversion(Standard_True);
421 if(c3d)
422 tool.Set3dConversion(Standard_True);
423 tool.Perform();
424 TopoDS_Shape res = tool.Result();
425
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";
443
444 // fixes
445
446 ShapeFix::SameParameter ( res, Standard_False );
447
448 DBRep::Set(a[1],res);
449 return 0;
450}
451static Standard_Integer DT_SplitAngle(Draw_Interpretor& di,
452 Standard_Integer n, const char** a)
453{
454 if (n<3) {
455 di << "bad number of arguments" <<"\n";
456 return 1;
457 }
458
459 TopoDS_Shape inputShape=DBRep::Get(a[2]);
460 if (inputShape.IsNull()) {
461 di << "Unknown shape"<< "\n";
462 return 1;
463 }
464
465 Standard_Real maxangle = 95;
466 if ( n >3 ) {
467 maxangle = atof ( a[3] );
468 if ( maxangle <1 ) maxangle = 1;
469 }
470
982a90fc 471 ShapeUpgrade_ShapeDivideAngle tool(maxangle * M_PI/180,inputShape);
7fd59977 472 tool.Perform();
473 TopoDS_Shape res = tool.Result();
474
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";
492
493 // fixes
494
495 ShapeFix::SameParameter ( res, Standard_False );
496
497 DBRep::Set(a[1],res);
498 return 0;
499}
500
501/*
502//=======================================================================
503//function : DT_PlaneDividedFace
504//purpose : Transfer into a plane with boundary divided
505//
506//
507//=======================================================================
508static Standard_Integer DT_PlaneDividedFace (Draw_Interpretor& di,
509 Standard_Integer n, const char** a)
510
511{
512 // a[1]= result
513 // a[2]= input Face
514 // a[3]= Tolerance
515
516 if (n !=4) {
517 di << "bad number of arguments" <<"\n";
518 return 1;
519 }
520
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";
526 return 1;
527 }
528
529 ShapeUpgrade_PlaneDividedFace theTool(ThePlane);
530 theTool.Init(inputFace);
531 //theTool.SetBoundaryCriterion(GeomAbs_C1);
532 //theTool.SetTolerance(Tol);
533 theTool.Build();
534 if (!theTool.IsDone()) {
535 di << "Not done" << "\n";
536 return 1;
537 }
538
539 TopoDS_Face res = theTool.Face();
540 DBRep::Set(a[1],res);
541
542 Standard_Real the2d3dFactor=theTool.Get2d3dFactor();
543 di << "2d3dFactor="<<the2d3dFactor<< "\n";
544 return 0;
545}
546
547//=======================================================================
548//function : DT_PlaneGridShell
549//purpose : Create a Plane Grid Shell from U and V knots
550//
551//
552//=======================================================================
553static Standard_Integer DT_PlaneGridShell (Draw_Interpretor& di,
554 Standard_Integer n, const char** a)
555
556{
557
558 if (n < 4) return 1;
559 // a[1]= result
560 // a[2]= NbU >=2
561 // a[3]= NbV >=2
562 // a[4..]= {UKnots}
563 // a[4+NbU...] = {VKnots}
564 // a[4+NbU+NbV+1] = Tol
565
566 // number of knots:
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";
571 return 1;
572 }
573
574 TColStd_Array1OfReal TheUKnots(1,NbU);
575 TColStd_Array1OfReal TheVKnots(1,NbV);
576
577 for (Standard_Integer ii=1; ii<=NbU; ii++) {
578 TheUKnots(ii)=atof(a[4+ii-1]);
579 }
580 for (ii=1; ii<=NbV; ii++) {
581 TheVKnots(ii)=atof(a[4+NbU+ii-1]);
582 }
583
584 Standard_Real Tol=atof(a[4+NbU+NbV]);
585
586 ShapeUpgrade_PlaneGridShell TheGrid(ThePlane,TheUKnots,TheVKnots,Tol);
587
588 TopoDS_Shell res = TheGrid.Shell();
589 DBRep::Set(a[1],res);
590
591 return 0;
592}
593
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
598//
599//
600//=======================================================================
601static Standard_Integer DT_PlaneFaceCommon (Draw_Interpretor& di,
602 Standard_Integer n, const char** a)
603
604{
605 // a[1]= result
606 // a[2]= input Face
607 // a[3]= input Shell
608
609 if (n !=4) {
610 di << "bad number of arguments" <<"\n";
611 return 1;
612 }
613
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";
618 return 1;
619 }
620
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";
625 return 1;
626 }
627
628 ShapeUpgrade_PlaneFaceCommon theTool;
629 theTool.Init(inputFace,inputShell);
630
631 TopoDS_Shell res = theTool.Shell();
632 DBRep::Set(a[1],res);
633
634 return 0;
635}*/
636
637//=======================================================================
638//function : DT_SplitCurve
639//purpose : Splits the curve with C1 criterion
640//
641//
642//=======================================================================
643static Standard_Integer DT_SplitCurve (Draw_Interpretor& di,
644 Standard_Integer n, const char** a)
645
646{
647 // a[1]= input curve. This name is used with a suffix to name the output curves
648 // a[2]= Tolerance
649
650 if (n < 3) {
651 di << "bad number of arguments" <<"\n";
652 return 1;
653 }
654
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;
660 theTool->Init(GC);
661 theTool->SetTolerance (Tol);
662 theTool->SetCriterion (GeomAbs_C1);
663 if(Split == 1) {
664 Handle(TColStd_HSequenceOfReal) spval = new TColStd_HSequenceOfReal;
665 for(Standard_Integer i = 1; i<=5; i++) spval->Append(i);
666 theTool->SetSplitValues(spval);
667 }
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++) {
672 char name[100];
673 sprintf(name,"%s%s%d",a[1],"_",icurv);
674 char* newname = name;
675 DrawTrSurf::Set(newname, theCurves->Value(icurv));
676 di.AppendElement(newname);
677 }
678 return 0;
679}
680
681
682//=======================================================================
683//function : DT_SplitCurve2d
684//purpose : Splits the curve with C1 criterion
685//
686//
687//=======================================================================
688static Standard_Integer DT_SplitCurve2d (Draw_Interpretor& di,
689 Standard_Integer n, const char** a)
690
691{
692 // a[1]= input 2d curve. This name is used with a suffix to name the output curves
693 // a[2]= Tolerance
694
695 if (n < 3) {
696 di << "bad number of arguments" <<"\n";
697 return 1;
698 }
699
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;
705 theTool->Init(GC);
706 theTool->SetTolerance (Tol);
707 theTool->SetCriterion (GeomAbs_C1);
708 if(Split == 1) {
709 Handle(TColStd_HSequenceOfReal) spval = new TColStd_HSequenceOfReal;
710 for(Standard_Integer i = 1; i<=5; i++) spval->Append(i);
711 theTool->SetSplitValues(spval);
712 }
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++) {
717 char name[100];
718 sprintf(name,"%s%s%d",a[1],"_",icurv);
719 char* newname = name;
720 DrawTrSurf::Set(newname, theCurves->Value(icurv));
721 di.AppendElement(newname);
722 }
723 return 0;
724}
725
726
727//=======================================================================
728//function : DT_SplitSurface
729//purpose : Splits the surface with C1 criterion
730//
731//
732//=======================================================================
733/*
734static Standard_Integer DT_SplitWire (Draw_Interpretor& di,
735 Standard_Integer n, const char** a)
736{
737
738 if (n <3) {
739 di << "bad number of arguments" <<"\n";
740 return 1;
741 }
742
743 TopoDS_Face source = TopoDS::Face(DBRep::Get(a[2]));
744 if(source.IsNull()) {
745 di <<"Shape is not face"<<"\n";
746 return 1;
747 }
748 TopoDS_Iterator wi(source);
749 if(!wi.More()) {
750 di <<"Shape is face without wire"<<"\n";
751 return 1;
752 }
753
754 TopoDS_Wire wire = TopoDS::Wire(wi.Value());
755 Handle(ShapeUpgrade_WireDivideContinuity) tool = new ShapeUpgrade_WireDivideContinuity;
756 tool->Init(wire,source);
757 if(n >=4 ) {
758 Standard_Real Tol=atof(a[3]);
759 }
760 Handle(ShapeBuild_ReShape) context = new ShapeBuild_ReShape;
761 tool->Perform(context);
762 TopoDS_Wire result = tool->Wire();
763 DBRep::Set(a[1],result);
764 return 0;
765}
766*/
767/*
768static Standard_Integer DT_SplitFace (Draw_Interpretor& di,
769 Standard_Integer n, const char** a)
770{
771
772 if (n <3) {
773 di << "bad number of arguments" <<"\n";
774 return 1;
775 }
776
777 TopoDS_Face source = TopoDS::Face(DBRep::Get(a[2]));
778 if(source.IsNull()) {
779 di <<"Shape is not face"<<"\n";
780 return 1;
781 }
782 Handle(ShapeUpgrade_ShapeDivideContinuity) tool = new ShapeUpgrade_FaceDivideContinuity;
783 tool->Init(source);
784 if(n >=4 ) {
785 Standard_Real Tol=atof(a[3]);
786 tool->SetPrecision(Tol);
787 }
788
789 Handle(ShapeBuild_ReShape) context = new ShapeBuild_ReShape;
790 tool->Perform(context);
791 TopoDS_Shape result = tool->Result();
792
793
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";
811
812 // fixes
813
814 ShapeFix::SameParameter ( result, Standard_False );
815
816 DBRep::Set(a[1],result);
817 return 0;
818}
819*/
820
821static Standard_Integer DT_SplitSurface (Draw_Interpretor& di,
822 Standard_Integer n, const char** a)
823
824{
825 // a[1]= result (used with a suffix to name the output surfaces)
826 // a[2]= input surface.
827 // a[3]= Tolerance
828
829 // a[1]= result
830 // a[2]= nbU
831 // a[3]= nbV
832 // a[3+1]..a[3+nbU*nbV] = Input Surfaces
833 // a[4+nbU*nbV]= Tolerance
834
835 if (n <4) {
836 di << "bad number of arguments" <<"\n";
837 return 1;
838 }
839
840 Handle(ShapeUpgrade_SplitSurfaceContinuity) theTool = new ShapeUpgrade_SplitSurfaceContinuity;//S4137
841
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]);
847/*
848 if ( GS.IsNull()) {
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);
860 }
861 }
862 di << "appel a SplitSurface::Init" << "\n";
863 theTool->Init(theGrid);
864 }
865 else {*/
866 // Case of single surface
867 di << "single surf" << "\n";
868
869 di << "appel a SplitSurface::Init" << "\n";
870 theTool->Init(GS);
871 if(Split ==1) {
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);
876 }
877
878 di << "appel a SplitSurface::Build" << "\n";
879 theTool->Build(Standard_True);
880
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);
890// di <<"\n";
891// di << "nb GlobalV="<<nbGlV;
892 for (Standard_Integer iv=1; iv<=nbGlV; iv++)
893 di <<" "<< GlobalV->Value(iv);
894 di <<"\n";
895
896di << "appel a Surfaces" << "\n";
897 Handle(TColGeom_HArray2OfSurface) theSurfaces= Grid->Patches();
898
899di << "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++) {
904 char name[100];
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);
909 }
910 }
911 return 0;
912}
913
914
915
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.
921//
922//=======================================================================
923/*static Standard_Integer DT_SupportModification (Draw_Interpretor& di,
924 Standard_Integer n, const char** a)
925
926{
927 // a[1]= result
928 // a[2]= input Shell
929 // a[3]= new Surface
930 // a[4]= 2d3d Scale Factor
931
932 if (n !=5) {
933 di << "bad number of arguments" <<"\n";
934 return 1;
935 }
936
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";
941 return 1;
942 }
943
944 Handle(Geom_Surface) theSurf = DrawTrSurf::GetSurface(a[3]);
945 if ( theSurf.IsNull()) {
946 di << a[3] << " is not a surface" << "\n";
947 return 1;
948 }
949
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);
956 }
957
958 Standard_Real the2d3dFactor=atof(a[4]);
959 ShapeUpgrade_SupportModification theTool(inputShell,theMap,the2d3dFactor);
960
961 TopoDS_Shell res = theTool.Shell();
962 DBRep::Set(a[1],res);
963
964 return 0;
965}*/
966
967//=======================================================================
968//function : DT_Debug
969//purpose : activation of the debug mode
970//
971//=======================================================================
972/*
973static Standard_Integer DT_Debug (Draw_Interpretor& di,
974 Standard_Integer n, const char** a)
975
976{
977 // a[1]= 0/1
978
979 if (n !=2) {
980 di << "bad number of arguments" <<"\n";
981 return 1;
982 }
983
984 if (atoi(a[1])==1) {
985 di << "Activation of debug messages"<<"\n";
986 ShapeUpgrade::SetDebug(Standard_True);
987 }
988 else {
989 di << "Desactivation of debug messages"<<"\n";
990 ShapeUpgrade::SetDebug(Standard_False);
991 }
992 return 0;
993}
994*/
995
996/*static Standard_Integer shellsolid
997 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
998{
999 if (argc < 4) {
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";
1004 return 1 ;
1005 }
1006 Standard_CString arg1 = argv[1];
1007 Standard_CString arg2 = argv[2];
1008 Standard_CString arg3 = argv[3];
1009
1010 TopoDS_Shape Shape = DBRep::Get(arg2);
1011 if (Shape.IsNull()) { di<<"Shape unknown : "<<arg2<<"\n"; return 1 ; }
1012
1013 ShapeAnalysis_Shell STS;
1014 char opt = arg1[0];
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);
1018
1019 else if (opt == 'o') {
1020
1021// Test WireOrder
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 ++;
1026 }
1027 ShapeAnalysis_WireOrder WO (Standard_True,BRepBuilderAPI::Precision());
1028 ShapeAnalysis_Wire saw;
1029 saw.Load ( Frees );
1030 saw.SetPrecision ( BRepBuilderAPI::Precision() );
1031 saw.CheckOrder ( WO );
1032
1033 Standard_Integer stat = WO.Status();
1034 di<<"Wire Order Status = "<<stat<<" on "<<nbe<<" Edges"<<"\n";
1035 nbe = WO.NbEdges();
1036 for (Standard_Integer ie = 1; ie <= nbe; ie ++) {
1037 Standard_Integer io = WO.Ordered (ie);
1038 gp_XYZ st3d,en3d;
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";
1042 }
1043// Chainage ?
1044 Standard_Real gap = BRepBuilderAPI::Precision();
1045 WO.SetChains (gap);
1046 Standard_Integer n1,n2,ic, nc = WO.NbChains();
1047 for (ic = 1; ic <= nc; ic ++) {
1048 WO.Chain(ic,n1,n2);
1049 di<<"Chain."<<ic<<" From "<<n1<<" To "<<n2<<"\n";
1050 }
1051 }
1052
1053 else { di<<"Option non reconnue : "<<arg1<<"\n"; return 1; }
1054
1055 TopoDS_Shape res;
1056 if (opt == 'a' || opt == 'c') {
1057 ShapeUpgrade_ShellSewing sew;
1058 res = sew.ApplySewing (Shape);
1059 if (res.IsEqual(Shape)) {
1060 res.Nullify();
1061 di<<"ShellSolid : no sewing done"<<"\n";
1062 }
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";
1071 }
1072
1073 if (!res.IsNull()) DBRep::Set (arg3,res);
1074
1075 return 0; // Done
1076}*/
1077//---------------gka
1078//=======================================================================
1079//function : offset2dcurve
1080//purpose :
1081//
1082//=======================================================================
1083static Standard_Integer offset2dcurve
1084 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1085{
1086 if (argc < 4) {
1087 di<<"result + curve + offset"<<"\n";
1088
1089 return 1 /* Error */;
1090 }
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);
1098 return 0;
1099}
1100
1101//=======================================================================
1102//function : offsetcurve
1103//purpose :
1104//
1105//=======================================================================
1106static Standard_Integer offsetcurve
1107 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1108{
1109 if (argc < 5) {
1110 di<<"result + curve + offset + Dir"<<"\n";
1111
1112 return 1 /* Error */;
1113 }
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;
1119 gp_Pnt point;
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);
1124 return 0;
1125}
1126
1127//=======================================================================
1128//function : compose shell
1129//purpose :
1130//=======================================================================
1131static Standard_Integer splitface
1132 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1133{
1134 if (argc < 5) {
1135 di << "Split face: splitface result face [u usplit1 usplit2...] [v vsplit1 vsplit2 ...]" << "\n";
1136 return 1;
1137 }
1138
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";
1143 return 1;
1144 }
1145
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;
1154 else Uf = Umin;
1155 if ( Vf < Vmin && ! S->IsVPeriodic() ) Vf = Vmin;
1156 else if ( Vf > Vmin )
1157 if ( Precision::IsInfinite(Vmin) ) Vf -= 100;
1158 else Vf = Vmin;
1159 if ( Ul > Umax && ! S->IsUPeriodic() ) Ul = Umax;
1160 else if ( Ul < Umax )
1161 if ( Precision::IsInfinite(Umax) ) Ul += 100;
1162 else Ul = Umax;
1163 if ( Vl > Vmax && ! S->IsVPeriodic() ) Vl = Vmax;
1164 else if ( Vl < Vmax )
1165 if ( Precision::IsInfinite(Vmax) ) Vl += 100;
1166 else Vl = Vmax;
1167
1168 TColStd_SequenceOfReal uval;
1169 TColStd_SequenceOfReal vval;
1170
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;
1176 else {
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";
1181 continue;
1182 }
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";
1188 continue;
1189 }
1190 vals.Append ( val );
1191 }
1192 }
1193 if ( uval.Length() <1 && vval.Length() <1 ) {
1194 di << "No splitting defined" << "\n";
1195 return 1;
1196 }
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);
1201 if (i >j) {
1202 di << ", ";
1203 } else {
1204 di << "";
1205 }
1206 di << uval(j);
1207 }
1208 di << "\n";
1209 }
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);
1214 if (j >1) {
1215 di << ", ";
1216 } else {
1217 di << "";
1218 }
1219 di << vval(j);
1220 }
1221 di << "\n";
1222 }
1223
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 );
1235 }
1236 }
1237
1238 Handle(ShapeExtend_CompositeSurface) Grid = new ShapeExtend_CompositeSurface;
1239 if ( ! Grid->Init ( AS ) ) di << "Grid badly connected!" << "\n";
1240
1241 ShapeFix_ComposeShell SUCS;
1242 TopLoc_Location l;
1243 SUCS.Init ( Grid, l, face, Precision::Confusion() );
1244 Handle(ShapeBuild_ReShape) RS = new ShapeBuild_ReShape;
1245 SUCS.SetContext( RS );
1246 SUCS.Perform ();
1247
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";
1265
1266 TopoDS_Shape sh = SUCS.Result();
1267 ShapeFix::SameParameter ( sh, Standard_False );
1268 DBRep::Set ( argv[1], sh );
1269 return 0;
1270}
1271
1272static Standard_Integer converttobspline
1273 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1274{
1275 if (argc<3) {
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";
1282 di << "p - plane";
1283 return 1;
1284 }
1285 const char *options = ( argc > 3 ? argv[3] : "ero" );
1286
1287 TopoDS_Shape inputShape=DBRep::Get(argv[2]);
1288 if (inputShape.IsNull()) {
1289 di << "Unknown shape"<< "\n";
1290 return 1;
1291 }
1292 TopoDS_Shape revsh = ShapeCustom::ConvertToRevolution (inputShape);
1293 TopoDS_Shape res =
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 );
1300 return 0;
1301}
1302
1303
1304static Standard_Integer splitclosed (Draw_Interpretor& di,
1305 Standard_Integer argc,
1306 const char** argv)
1307{
1308 if (argc<3) {
1309 di << "bad number of arguments" <<"\n";
1310 return 1;
1311 }
1312
1313 TopoDS_Shape inputShape=DBRep::Get(argv[2]);
1314 if (inputShape.IsNull()) {
1315 di << "Unknown shape"<< "\n";
1316 return 1;
1317 }
1318
1319 ShapeUpgrade_ShapeDivideClosed tool (inputShape);
1320 tool.Perform();
1321 TopoDS_Shape res = tool.Result();
1322
1323 ShapeFix::SameParameter ( res, Standard_False );
1324 DBRep::Set ( argv[1], res );
1325 return 0;
1326}
1327
1328static Standard_Integer splitarea (Draw_Interpretor& di,
1329 Standard_Integer argc,
1330 const char** argv)
1331{
1332 if (argc<4) {
1333 di << "bad number of arguments" <<"\n";
1334 return 1;
1335 }
1336
1337 TopoDS_Shape inputShape=DBRep::Get(argv[2]);
1338 if (inputShape.IsNull()) {
1339 di << "Unknown shape"<< "\n";
1340 return 1;
1341 }
1342 Standard_Real aMaxArea = atof(argv[3]);
1343
1344
1345 ShapeUpgrade_ShapeDivideArea tool (inputShape);
1346 if(argc >4) {
1347 Standard_Real prec = atof(argv[4]);
1348 tool.SetPrecision(prec);
1349 }
1350 tool.MaxArea() = aMaxArea;
1351 tool.Perform();
1352 TopoDS_Shape res = tool.Result();
1353
1354 ShapeFix::SameParameter ( res, Standard_False );
1355 DBRep::Set ( argv[1], res );
1356 return 0;
1357}
1358
1359static Standard_Integer removeinternalwires (Draw_Interpretor& di,
1360 Standard_Integer argc,
1361 const char** argv)
1362{
1363 if (argc<4) {
1364 di << "bad number of arguments" <<"\n";
1365 return 1;
1366 }
1367 Standard_Real aMinArea = atof(argv[2]);
1368 TopoDS_Shape inputShape=DBRep::Get(argv[3]);
1369 if (inputShape.IsNull()) {
1370 di << "Unknown shape"<< "\n";
1371 return 1;
1372 }
1373 Handle(ShapeUpgrade_RemoveInternalWires) aTool;
1374 TopTools_SequenceOfShape aSeqShapes;
1375 if(inputShape.ShapeType() < TopAbs_WIRE)
1376 aTool = new ShapeUpgrade_RemoveInternalWires(inputShape);
1377 else {
1378 di<<"Invalid type of first shape: should be FACE,SHELL,SOLID or COMPOUND"<<"\n";
1379 return 1;
1380 }
1381
1382 Standard_Integer k = 4;
1383 Standard_Boolean isShape = Standard_True;
1384 Standard_Boolean aModeRemoveFaces =Standard_True;
1385
1386
1387 for( ; k < argc; k++) {
1388 if(isShape) {
1389 TopoDS_Shape aShape=DBRep::Get(argv[k]);
1390 isShape = !aShape.IsNull();
1391 if(isShape) {
1392 if(aShape.ShapeType() == TopAbs_FACE || aShape.ShapeType() == TopAbs_WIRE)
1393 aSeqShapes.Append(aShape);
1394 }
1395 }
1396 if(!isShape)
1397 aModeRemoveFaces = (atoi(argv[k]) == 1);
1398 }
1399
1400 aTool->MinArea() = aMinArea;
1401 aTool->RemoveFaceMode() = aModeRemoveFaces;
1402 if(aSeqShapes.Length())
1403 aTool->Perform(aSeqShapes);
1404 else
1405 aTool->Perform();
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";
1413
1414 }
1415 if(aTool->Status(ShapeExtend_DONE2)) {
1416 const TopTools_SequenceOfShape& aRemovedFaces =aTool->RemovedFaces();
1417 di<<aRemovedFaces.Length()<<" small faces were removed"<<"\n";
1418
1419 }
1420 TopoDS_Shape res = aTool->GetResult();
1421
1422
1423 DBRep::Set ( argv[1], res );
1424 return 0;
1425}
1426
982a90fc
G
1427static Standard_Integer removeloc (Draw_Interpretor& di,
1428 Standard_Integer argc,
1429 const char** argv)
1430{
1431 if (argc<3) {
1432 di << "bad number of arguments. Should be: removeloc res shape" <<"\n";
1433 return 1;
1434 }
1435
1436 TopoDS_Shape aShape = DBRep::Get(argv[2]);
1437 if(aShape.IsNull())
1438 return 1;
1439 ShapeUpgrade_RemoveLocations aRemLoc;
1440 aRemLoc.Remove(aShape);
1441 TopoDS_Shape aNewShape = aRemLoc.GetResult();
1442
1443 DBRep::Set(argv[1],aNewShape);
1444 return 0;
1445}
2277323d 1446
1447//=======================================================================
1448// unifysamedom
1449//=======================================================================
1450static Standard_Integer unifysamedom(Draw_Interpretor& , Standard_Integer n, const char** a)
1451{
1452 if (n < 3)
1453 return 1;
1454
1455 TopoDS_Shape aShape = DBRep::Get(a[2]);
1456 if (aShape.IsNull())
1457 return 1;
1458
1459 ShapeUpgrade_UnifySameDomain Unifier(aShape);
1460 Unifier.Build();
1461 TopoDS_Shape Result = Unifier.Shape();
1462
1463 DBRep::Set(a[1], Result);
1464 return 0;
1465}
1466
982a90fc
G
1467static Standard_Integer copytranslate(Draw_Interpretor& di,
1468 Standard_Integer argc,
1469 const char** argv)
1470{
1471 if (argc<6) {
1472 di << "bad number of arguments. Should be: removeloc res shape dx dyy dz" <<"\n";
1473 return 1;
1474 }
1475 TopoDS_Shape aShape = DBRep::Get(argv[2]);
1476 if(aShape.IsNull())
1477 return 1;
1478 Standard_Real aDx = atof(argv[3]);
1479 Standard_Real aDy = atof(argv[4]);
1480 Standard_Real aDz = atof(argv[5]);
1481 gp_Trsf aTrsf;
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);
1487 return 0;
1488
1489}
1490
7fd59977 1491//=======================================================================
1492//function : InitCommands
1493//purpose :
1494//=======================================================================
1495
1496 void SWDRAW_ShapeUpgrade::InitCommands(Draw_Interpretor& theCommands)
1497{
1498 static Standard_Integer initactor = 0;
1499 if (initactor) return; initactor = 1;
1500
1501 Standard_CString g = SWDRAW::GroupName(); // "Tests of DivideTool";
1502
1503 theCommands.Add("DT_ShapeDivide",
1504 "DT_ShapeDivide Result Shape Tol: Divides shape with C1 Criterion",
1505 __FILE__,
1506 DT_ShapeDivide,g);
1507
1508 theCommands.Add("DT_SplitAngle",
1509 "DT_SplitAngle Result Shape [MaxAngle=95]: Divides revolved surfaces on segments less MaxAngle deg",
1510 __FILE__,
1511 DT_SplitAngle,g);
1512
1513 theCommands.Add("DT_ShapeConvert",
1514 "DT_ShapeConvert Result Shape convert2d convert3d: Converts curves to beziers",
1515 __FILE__,
1516 DT_ShapeConvert,g);
1517
1518 theCommands.Add("DT_ShapeConvertRev",
1519 "DT_ShapeConvert Result Shape convert2d convert3d: Converts curves to beziers",
1520 __FILE__,
1521 DT_ShapeConvertRev,g);
1522/* theCommands.Add("DT_PlaneDividedFace",
1523 "DT_PlaneDividedFace Result Face Tol: Transfer into a plane with boundary divided",
1524 __FILE__,
1525 DT_PlaneDividedFace,g);
1526
1527 theCommands.Add("DT_PlaneGridShell",
1528 "DT_PlaneGridShell Result NbU NbV {UKnots} {VKnots} Tol : Create a plane grid Shell",
1529 __FILE__,
1530 DT_PlaneGridShell,g);
1531
1532 theCommands.Add("DT_PlaneFaceCommon",
1533 "DT_PlaneFaceCommon Result Face Shell: Common between a plane Face and a Shell",
1534 __FILE__,
1535 DT_PlaneFaceCommon,g);*/
1536
1537 theCommands.Add("DT_SplitCurve2d",
1538 "DT_SplitCurve2d Curve Tol: Splits the curve with C1 criterion",
1539 __FILE__,
1540 DT_SplitCurve2d,g);
1541
1542 theCommands.Add("DT_SplitCurve",
1543 "DT_SplitCurve Curve Tol: Splits the curve with C1 criterion",
1544 __FILE__,
1545 DT_SplitCurve,g);
1546
1547 theCommands.Add("DT_SplitSurface",
1548 "DT_SplitSurface Result Surface/GridSurf Tol: Splits the surface with C1 criterion",
1549 __FILE__,
1550 DT_SplitSurface,g);
1551
1552 /*theCommands.Add("DT_SupportModification",
1553 "DT_SupportModification Result Shell Surface 2d3dFactor: Surface will support all the faces",
1554 __FILE__,
1555 DT_SupportModification,g);*/
1556
1557// theCommands.Add("DT_SpltWire","DT_SpltWire Result Wire Tol",
1558// __FILE__,DT_SplitWire,g);
1559
1560// theCommands.Add("DT_SplitFace", "DT_SplitFace Result Face Tol",
1561// __FILE__, DT_SplitFace,g);
1562
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);
1569
1570 theCommands.Add ("offsetcurve","result curve offset dir",
1571 __FILE__,offsetcurve,g);
1572
1573 theCommands.Add ("splitface","result face [u usplit1 usplit2...] [v vsplit1 vsplit2 ...]",
1574 __FILE__,splitface,g);
1575
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);
1582
1583 theCommands.Add ("RemoveIntWires","result minarea wholeshape [faces or wires] [moderemoveface ]",
1584 __FILE__,removeinternalwires,g);
982a90fc
G
1585
1586 theCommands.Add ("removeloc","result shape",__FILE__,removeloc,g);
2277323d 1587
1588 theCommands.Add ("unifysamedom",
1589 "unifysamedom result shape",__FILE__,unifysamedom,g);
1590
982a90fc 1591 theCommands.Add ("copytranslate","result shape dx dy dz",__FILE__,copytranslate,g);
7fd59977 1592}