0023934: Compiler warnings in MS VC++ 10
[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
91322f44 28#include <Draw.hxx>
7fd59977 29#include <DBRep.hxx>
30#include <ShapeUpgrade.hxx>
31#include <ShapeUpgrade_SplitCurve3dContinuity.hxx>
32#include <ShapeUpgrade_SplitCurve2dContinuity.hxx>
33#include <ShapeUpgrade_SplitSurfaceContinuity.hxx>
34//#include <ShapeUpgrade_SupportModification.hxx>
35#include <Draw_Interpretor.hxx>
36#include <DrawTrSurf.hxx>
37#include <Geom_Curve.hxx>
38#include <Geom_Plane.hxx>
39#include <Geom_Surface.hxx>
40#include <Geom2d_Curve.hxx>
41#include <TColGeom_HArray1OfCurve.hxx>
42#include <TColGeom_HArray2OfSurface.hxx>
43#include <TColStd_Array1OfReal.hxx>
44#include <TColStd_HArray1OfReal.hxx>
45#include <TColStd_HSequenceOfReal.hxx>
46#include <TopoDS.hxx>
47#include <TopoDS_Edge.hxx>
48#include <TopoDS_Face.hxx>
49#include <TopoDS_Shape.hxx>
50#include <TopoDS_Shell.hxx>
51#include <TopoDS_Wire.hxx>
52#include <TopoDS_Compound.hxx>
53#include <TopExp_Explorer.hxx>
54#include <TColGeom_HArray2OfSurface.hxx>
55#include <TColGeom2d_HArray1OfCurve.hxx>
56#include <BRepBuilderAPI.hxx>
57#include <SWDRAW.hxx>
58#include <ShapeUpgrade_ShapeDivideArea.hxx>
59
60#include <stdio.h>
61//#include <ShapeExtend_WireData.hxx>
62//#include <ShapeAnalysis_Shell.hxx>
63//#include <ShapeAnalysis_WireOrder.hxx>
64//#include <ShapeAnalysis_Wire.hxx>
65//#include <ShapeUpgrade_ShellSewing.hxx>
66#include <Geom2d_Curve.hxx>
67#include <Geom2d_OffsetCurve.hxx>
68#include <Geom_OffsetCurve.hxx>
69#include <ShapeUpgrade_SplitCurve3dContinuity.hxx>
70#include <TopoDS_Iterator.hxx>
71#include <BRep_Tool.hxx>
72#include <ShapeExtend_CompositeSurface.hxx>
73#include <Geom_RectangularTrimmedSurface.hxx>
74#include <TColGeom_HArray2OfSurface.hxx>
75#include <ShapeFix_ComposeShell.hxx>
76#include <Precision.hxx>
77#include <ShapeBuild_ReShape.hxx>
78#include <BRepTools.hxx>
79#include <ShapeFix.hxx>
80#include <ShapeUpgrade_ShapeDivideContinuity.hxx>
81#include <ShapeUpgrade_ShapeDivideAngle.hxx>
82#include <ShapeUpgrade_ShapeConvertToBezier.hxx>
83#include <ShapeCustom.hxx>
84#include <ShapeUpgrade_ShapeDivideClosed.hxx>
85#include <ShapeUpgrade_RemoveInternalWires.hxx>
982a90fc 86#include <ShapeUpgrade_RemoveLocations.hxx>
2277323d 87#include <ShapeUpgrade_UnifySameDomain.hxx>
982a90fc
G
88#include <BRepBuilderAPI_Transform.hxx>
89
7fd59977 90// the plane (equation z=0) shared by PlaneDividedFaceContinuity and PlaneGridShell
91//static Handle(Geom_Plane) ThePlane= new Geom_Plane(0,0,1,0);
92
93
94//=======================================================================
95//function : DT_ShapeDivide
96//purpose :
97//=======================================================================
98
99static Standard_Integer DT_ShapeDivide (Draw_Interpretor& di,
100 Standard_Integer n, const char** a)
101{
102 // DT_ShapeDivide result Shape Tol
103 // a[1]= result
104 // a[2]= input Face/Surface
105 // a[3] si n>3= Wire/Face
106 // a[n-1]= Tolerance
107
108 if (n<3) {
109 di << "bad number of arguments" <<"\n";
110 return 1;
111 }
112
113 // try to read a shape:
114 TopoDS_Shape inputShape=DBRep::Get(a[2]);
115 if (inputShape.IsNull()) {
116 di << "Unknown shape"<< "\n";
117 return 1;
118 }
119 // a[2] is a shape. managing:
120 // DT_ShapeDivide result Face Tol
121
122 // giving a face is available only in the constructor:
123 // we make the whole and quit.
124 ShapeUpgrade_ShapeDivideContinuity tool(inputShape);
125
126 // tolerance is optional
127 if (n==4) {
91322f44 128 Standard_Real Tol=Draw::Atof(a[3]);
7fd59977 129 tool.SetTolerance(Tol);
130 }
131
132 // theTool.SetGlobalCriterion(GeomAbs_C1);
133 tool.Perform();
134 TopoDS_Shape res = tool.Result();
135
136 if ( tool.Status ( ShapeExtend_OK ) ) di << "Status: OK" << "\n";
137 if ( tool.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1" << "\n";
138 if ( tool.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2" << "\n";
139 if ( tool.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3" << "\n";
140 if ( tool.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4" << "\n";
141 if ( tool.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5" << "\n";
142 if ( tool.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6" << "\n";
143 if ( tool.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7" << "\n";
144 if ( tool.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8" << "\n";
145 if ( tool.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1" << "\n";
146 if ( tool.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2" << "\n";
147 if ( tool.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3" << "\n";
148 if ( tool.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4" << "\n";
149 if ( tool.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5" << "\n";
150 if ( tool.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6" << "\n";
151 if ( tool.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7" << "\n";
152 if ( tool.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8" << "\n";
153
154 // fixes
155
156 ShapeFix::SameParameter ( res, Standard_False );
157
158 DBRep::Set(a[1],res);
159 return 0;
160}
161
162static Standard_Integer DT_ShapeConvertRev (Draw_Interpretor& di,
163 Standard_Integer n, const char** a)
164{
165 if (n<5) {
166 di << "bad number of arguments" <<"\n";
167 return 1;
168 }
169
170 // try to read a shape:
171 TopoDS_Shape inputShape=DBRep::Get(a[2]);
172 if (inputShape.IsNull()) {
173 di << "Unknown shape"<< "\n";
174 return 1;
175 }
176
91322f44 177 Standard_Integer c2d = Draw::Atoi(a[3]);
178 Standard_Integer c3d = Draw::Atoi(a[4]);
7fd59977 179 TopoDS_Shape revsh = ShapeCustom::ConvertToRevolution (inputShape);
180 if (revsh.IsNull()) { di<<"NO RESULT"<<"\n"; return 1; }
181 else if (revsh == inputShape) { di<<"No modif"<<"\n";}
182 else di<<"ConvertToRevolution -> Result : "<<"\n";
183
184 ShapeUpgrade_ShapeConvertToBezier tool(revsh);
185 tool.SetSurfaceConversion(Standard_True);
186 if(c2d)
187 tool.Set2dConversion(Standard_True);
188 if(c3d) {
189 tool.Set3dConversion(Standard_True);
190 if(n > 5)
191 tool.Set3dLineConversion(Standard_False);
192 if(n > 6)
193 tool.Set3dCircleConversion(Standard_False);
194 if(n > 7)
195 tool.Set3dConicConversion(Standard_False);
196 }
197 tool.Perform();
198 TopoDS_Shape res = tool.Result();
199
200 if ( tool.Status ( ShapeExtend_OK ) ) di << "Status: OK" << "\n";
201 if ( tool.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1" << "\n";
202 if ( tool.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2" << "\n";
203 if ( tool.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3" << "\n";
204 if ( tool.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4" << "\n";
205 if ( tool.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5" << "\n";
206 if ( tool.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6" << "\n";
207 if ( tool.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7" << "\n";
208 if ( tool.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8" << "\n";
209 if ( tool.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1" << "\n";
210 if ( tool.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2" << "\n";
211 if ( tool.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3" << "\n";
212 if ( tool.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4" << "\n";
213 if ( tool.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5" << "\n";
214 if ( tool.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6" << "\n";
215 if ( tool.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7" << "\n";
216 if ( tool.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8" << "\n";
217
218 // fixes
219
220 ShapeFix::SameParameter ( res, Standard_False );
221
222 DBRep::Set(a[1],res);
223 return 0;
224}
225
226
227/*
228 if (!inputShape.IsNull()) {
229 // a[2] is a shape. managing:
230 // DT_ShapeDivide result Face Tol
231
232 TopoDS_Face inputFace = TopoDS::Face(inputShape);
233 if (inputFace.IsNull()) {
234 di << a[2] << " is not a face" << "\n";
235 return 1;
236 }
237
238 // giving a face is available only in the constructor:
239 // we make the whole and quit.
240 ShapeUpgrade_ShapeDivideContinuity theTool(inputFace);
241
242 // tolerance is optional
243 if (n==4) {
91322f44 244 Standard_Real Tol=Draw::Atof(a[n-1]);
7fd59977 245 theTool.SetTolerance(Tol);
246 }
247
248 theTool.SetGlobalCriterion(GeomAbs_C1);
249 theTool.Build();
250 if (!theTool.IsDone()) {
251 ShapeUpgrade_Error theError=theTool.Error();
252 di << "Not done: error=";
253 if (theError==ShapeUpgrade_Done)
254 di << "Done"<<"\n";
255 else if (theError==ShapeUpgrade_NotDone)
256 di << "NotDone"<<"\n";
257 else if (theError==ShapeUpgrade_EmptyShell)
258 di << "EmptyShell"<<"\n";
259 else if (theError==ShapeUpgrade_InvalidCriterion)
260 di << "InvalidCriterion"<<"\n";
261 else if (theError==ShapeUpgrade_InvalidGridSurface)
262 di << "InvalidGridSurface"<<"\n";
263 else if (theError==ShapeUpgrade_DegeneratedEdge)
264 di << "DegeneratedEdge"<<"\n";
265 else if (theError==ShapeUpgrade_NoSurface)
266 di << "NoSurface"<<"\n";
267 else if (theError==ShapeUpgrade_NoTolerance)
268 di << "NoTolerance"<<"\n";
269 return 1;
270 }
271 TopoDS_Shell res = theTool.Shell();
272 DBRep::Set(a[1],res);
273
274 return 0;
275 }
276 else {
277 // not a face: we can use the empty consturctor.
278 ShapeUpgrade_ShapeDivideContinuity theTool;
91322f44 279 Standard_Real Tol=Draw::Atof(a[n-1]);
7fd59977 280 theTool.SetTolerance(Tol);
281 theTool.SetGlobalCriterion(GeomAbs_C1);
282
283 // try to read a surface:
284 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[2]);
285 if (! GS.IsNull()) {
286 // a[2] is a surface. managing the configurations:
287 // DT_ShapeDivide result Surface Tol
288 // DT_ShapeDivide result Surface Face Tol
289 // DT_ShapeDivide result Surface Wire Surf Tol
290
291 theTool.SetSupport(GS);
292
293 // try to read a Wire or a Face:
294 if (n>=5) {
295 TopoDS_Shape inputBoundary=DBRep::Get(a[3]);
296 if (inputBoundary.IsNull()) {
297 di << "Invalid Boundary" << "\n";
298 return 1;
299 }
300 TopoDS_Wire WireBoundary = TopoDS::Wire(inputBoundary);
301 if (!WireBoundary.IsNull()) {
302 // DT_ShapeDivide result Surface Wire Surf Tol
303 Handle(Geom_Surface) WireSupport = DrawTrSurf::GetSurface(a[4]);
304 if (WireSupport.IsNull()) {
305 di << "Invalid Surface supporting the Wire" << "\n";
306 return 1;
307 }
308 theTool.SetBoundary(WireBoundary, WireSupport);
309 }
310 else {
311 TopoDS_Face FaceBoundary = TopoDS::Face(inputBoundary);
312 // DT_ShapeDivide result Surface Face Tol
313 theTool.SetBoundary(FaceBoundary);
314 }
315 }
316 }
317 else {
318 // it must be a grid: managing the configurations:
319 // DT_ShapeDivide result NbU NbV {Surf_u_v...} Tol
320 // DT_ShapeDivide result NbU NbV {Surf_u_v...} Face Tol
321 // DT_ShapeDivide result NbU NbV {Surf_u_v...} Wire Surf Tol
322 if (n<6) {
323 di << "bad number of arguments for grid input" <<"\n";
324 return 1;
325 }
326 // number of surf:
91322f44 327 Standard_Integer NbU=Draw::Atoi(a[2]);
328 Standard_Integer NbV=Draw::Atoi(a[3]);
7fd59977 329 if (n < 4+NbU*NbV+1) {
330 di << "bad number of arguments" <<"\n";
331 return 1;
332 }
333
334 Handle(TColGeom_HArray2OfSurface)
335 TheGridSurf= new TColGeom_HArray2OfSurface(1,NbU,1,NbV);
336
337 for (Standard_Integer iu=1; iu<=NbU; iu++) {
338 for (Standard_Integer jv=1; jv<=NbV; jv++) {
339 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[4+(iu-1)*NbV+jv-1]);
340 TheGridSurf->SetValue(iu,jv,GS);
341 }
342 }
343 theTool.SetSupport(TheGridSurf,Tol);
344
345 // try to read a Wire or a Face:
346 if (n>=6+NbU*NbV) {
347 TopoDS_Shape inputBoundary=DBRep::Get(a[4+NbU*NbV]);
348 if (inputBoundary.IsNull()) {
349 di << "Invalid Boundary" << "\n";
350 return 1;
351 }
352 TopoDS_Wire WireBoundary = TopoDS::Wire(inputBoundary);
353 if (!WireBoundary.IsNull()) {
354 // DT_ShapeDivide result Surface Wire Surf Tol
355 Handle(Geom_Surface) WireSupport = DrawTrSurf::GetSurface(a[4+NbU*NbV+1]);
356 if (WireSupport.IsNull()) {
357 di << "Invalid Surface supporting the Wire" << "\n";
358 return 1;
359 }
360 theTool.SetBoundary(WireBoundary, WireSupport);
361 }
362 else {
363 TopoDS_Face FaceBoundary = TopoDS::Face(inputBoundary);
364 // DT_ShapeDivide result Surface Face Tol
365 theTool.SetBoundary(FaceBoundary);
366 }
367 }
368 }
369
370 theTool.Build();
371 if (!theTool.IsDone()) {
372 ShapeUpgrade_Error theError=theTool.Error();
373 di << "Not done: error=";
374 if (theError==ShapeUpgrade_Done)
375 di << "Done"<<"\n";
376 else if (theError==ShapeUpgrade_NotDone)
377 di << "NotDone"<<"\n";
378 else if (theError==ShapeUpgrade_EmptyShell)
379 di << "EmptyShell"<<"\n";
380 else if (theError==ShapeUpgrade_InvalidCriterion)
381 di << "InvalidCriterion"<<"\n";
382 else if (theError==ShapeUpgrade_InvalidGridSurface)
383 di << "InvalidGridSurface"<<"\n";
384 else if (theError==ShapeUpgrade_DegeneratedEdge)
385 di << "DegeneratedEdge"<<"\n";
386 else if (theError==ShapeUpgrade_NoSurface)
387 di << "NoSurface"<<"\n";
388 else if (theError==ShapeUpgrade_NoTolerance)
389 di << "NoTolerance"<<"\n";
390 return 1;
391 }
392
393 TopoDS_Shell res = theTool.Shell();
394 DBRep::Set(a[1],res);
395
396 return 0;
397 }
398}
399*/
400static Standard_Integer DT_ShapeConvert (Draw_Interpretor& di,
401 Standard_Integer n, const char** a)
402{
403 if (n<5) {
404 di << "bad number of arguments" <<"\n";
405 return 1;
406 }
407
408 // try to read a shape:
409 TopoDS_Shape inputShape=DBRep::Get(a[2]);
410 if (inputShape.IsNull()) {
411 di << "Unknown shape"<< "\n";
412 return 1;
413 }
414
91322f44 415 Standard_Integer c2d = Draw::Atoi(a[3]);
416 Standard_Integer c3d = Draw::Atoi(a[4]);
7fd59977 417
418 ShapeUpgrade_ShapeConvertToBezier tool(inputShape);
419 tool.SetSurfaceConversion(Standard_True);
420 if(c2d)
421 tool.Set2dConversion(Standard_True);
422 if(c3d)
423 tool.Set3dConversion(Standard_True);
424 tool.Perform();
425 TopoDS_Shape res = tool.Result();
426
427 if ( tool.Status ( ShapeExtend_OK ) ) di << "Status: OK" << "\n";
428 if ( tool.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1" << "\n";
429 if ( tool.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2" << "\n";
430 if ( tool.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3" << "\n";
431 if ( tool.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4" << "\n";
432 if ( tool.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5" << "\n";
433 if ( tool.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6" << "\n";
434 if ( tool.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7" << "\n";
435 if ( tool.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8" << "\n";
436 if ( tool.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1" << "\n";
437 if ( tool.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2" << "\n";
438 if ( tool.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3" << "\n";
439 if ( tool.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4" << "\n";
440 if ( tool.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5" << "\n";
441 if ( tool.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6" << "\n";
442 if ( tool.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7" << "\n";
443 if ( tool.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8" << "\n";
444
445 // fixes
446
447 ShapeFix::SameParameter ( res, Standard_False );
448
449 DBRep::Set(a[1],res);
450 return 0;
451}
452static Standard_Integer DT_SplitAngle(Draw_Interpretor& di,
453 Standard_Integer n, const char** a)
454{
455 if (n<3) {
456 di << "bad number of arguments" <<"\n";
457 return 1;
458 }
459
460 TopoDS_Shape inputShape=DBRep::Get(a[2]);
461 if (inputShape.IsNull()) {
462 di << "Unknown shape"<< "\n";
463 return 1;
464 }
465
466 Standard_Real maxangle = 95;
467 if ( n >3 ) {
91322f44 468 maxangle = Draw::Atof ( a[3] );
7fd59977 469 if ( maxangle <1 ) maxangle = 1;
470 }
471
982a90fc 472 ShapeUpgrade_ShapeDivideAngle tool(maxangle * M_PI/180,inputShape);
7fd59977 473 tool.Perform();
474 TopoDS_Shape res = tool.Result();
475
476 if ( tool.Status ( ShapeExtend_OK ) ) di << "Status: OK" << "\n";
477 if ( tool.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1" << "\n";
478 if ( tool.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2" << "\n";
479 if ( tool.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3" << "\n";
480 if ( tool.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4" << "\n";
481 if ( tool.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5" << "\n";
482 if ( tool.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6" << "\n";
483 if ( tool.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7" << "\n";
484 if ( tool.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8" << "\n";
485 if ( tool.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1" << "\n";
486 if ( tool.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2" << "\n";
487 if ( tool.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3" << "\n";
488 if ( tool.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4" << "\n";
489 if ( tool.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5" << "\n";
490 if ( tool.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6" << "\n";
491 if ( tool.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7" << "\n";
492 if ( tool.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8" << "\n";
493
494 // fixes
495
496 ShapeFix::SameParameter ( res, Standard_False );
497
498 DBRep::Set(a[1],res);
499 return 0;
500}
501
502/*
503//=======================================================================
504//function : DT_PlaneDividedFace
505//purpose : Transfer into a plane with boundary divided
506//
507//
508//=======================================================================
509static Standard_Integer DT_PlaneDividedFace (Draw_Interpretor& di,
510 Standard_Integer n, const char** a)
511
512{
513 // a[1]= result
514 // a[2]= input Face
515 // a[3]= Tolerance
516
517 if (n !=4) {
518 di << "bad number of arguments" <<"\n";
519 return 1;
520 }
521
91322f44 522 Standard_Real Tol=Draw::Atof(a[3]);
7fd59977 523 TopoDS_Shape inputShape=DBRep::Get(a[2]);
524 TopoDS_Face inputFace = TopoDS::Face(inputShape);
525 if (inputFace.IsNull()) {
526 di << a[2] << " is not a face" << "\n";
527 return 1;
528 }
529
530 ShapeUpgrade_PlaneDividedFace theTool(ThePlane);
531 theTool.Init(inputFace);
532 //theTool.SetBoundaryCriterion(GeomAbs_C1);
533 //theTool.SetTolerance(Tol);
534 theTool.Build();
535 if (!theTool.IsDone()) {
536 di << "Not done" << "\n";
537 return 1;
538 }
539
540 TopoDS_Face res = theTool.Face();
541 DBRep::Set(a[1],res);
542
543 Standard_Real the2d3dFactor=theTool.Get2d3dFactor();
544 di << "2d3dFactor="<<the2d3dFactor<< "\n";
545 return 0;
546}
547
548//=======================================================================
549//function : DT_PlaneGridShell
550//purpose : Create a Plane Grid Shell from U and V knots
551//
552//
553//=======================================================================
554static Standard_Integer DT_PlaneGridShell (Draw_Interpretor& di,
555 Standard_Integer n, const char** a)
556
557{
558
559 if (n < 4) return 1;
560 // a[1]= result
561 // a[2]= NbU >=2
562 // a[3]= NbV >=2
563 // a[4..]= {UKnots}
564 // a[4+NbU...] = {VKnots}
565 // a[4+NbU+NbV+1] = Tol
566
567 // number of knots:
91322f44 568 Standard_Integer NbU=Draw::Atoi(a[2]);
569 Standard_Integer NbV=Draw::Atoi(a[3]);
7fd59977 570 if (n != 4+NbU+NbV+1) {
571 di << "bad number of arguments" <<"\n";
572 return 1;
573 }
574
575 TColStd_Array1OfReal TheUKnots(1,NbU);
576 TColStd_Array1OfReal TheVKnots(1,NbV);
577
578 for (Standard_Integer ii=1; ii<=NbU; ii++) {
91322f44 579 TheUKnots(ii)=Draw::Atof(a[4+ii-1]);
7fd59977 580 }
581 for (ii=1; ii<=NbV; ii++) {
91322f44 582 TheVKnots(ii)=Draw::Atof(a[4+NbU+ii-1]);
7fd59977 583 }
584
91322f44 585 Standard_Real Tol=Draw::Atof(a[4+NbU+NbV]);
7fd59977 586
587 ShapeUpgrade_PlaneGridShell TheGrid(ThePlane,TheUKnots,TheVKnots,Tol);
588
589 TopoDS_Shell res = TheGrid.Shell();
590 DBRep::Set(a[1],res);
591
592 return 0;
593}
594
595//=======================================================================
596//function : DT_PlaneFaceCommon
597//purpose : Common between a plane Face and a Shell whose all Faces are
598// laying in the same plane
599//
600//
601//=======================================================================
602static Standard_Integer DT_PlaneFaceCommon (Draw_Interpretor& di,
603 Standard_Integer n, const char** a)
604
605{
606 // a[1]= result
607 // a[2]= input Face
608 // a[3]= input Shell
609
610 if (n !=4) {
611 di << "bad number of arguments" <<"\n";
612 return 1;
613 }
614
615 TopoDS_Shape inputShape= DBRep::Get(a[2]);
616 TopoDS_Face inputFace = TopoDS::Face(inputShape);
617 if (inputFace.IsNull()) {
618 di << a[2] << " is not a face" << "\n";
619 return 1;
620 }
621
622 inputShape = DBRep::Get(a[3]);
623 TopoDS_Shell inputShell = TopoDS::Shell(inputShape);
624 if (inputShell.IsNull()) {
625 di << a[3] << " is not a shell" << "\n";
626 return 1;
627 }
628
629 ShapeUpgrade_PlaneFaceCommon theTool;
630 theTool.Init(inputFace,inputShell);
631
632 TopoDS_Shell res = theTool.Shell();
633 DBRep::Set(a[1],res);
634
635 return 0;
636}*/
637
638//=======================================================================
639//function : DT_SplitCurve
640//purpose : Splits the curve with C1 criterion
641//
642//
643//=======================================================================
644static Standard_Integer DT_SplitCurve (Draw_Interpretor& di,
645 Standard_Integer n, const char** a)
646
647{
648 // a[1]= input curve. This name is used with a suffix to name the output curves
649 // a[2]= Tolerance
650
651 if (n < 3) {
652 di << "bad number of arguments" <<"\n";
653 return 1;
654 }
655
91322f44 656 Standard_Real Tol=Draw::Atof(a[2]);
7fd59977 657 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(a[1]);
658 if ( GC.IsNull()) return 1;
91322f44 659 Standard_Integer Split = Draw::Atoi(a[3]);
7fd59977 660 Handle(ShapeUpgrade_SplitCurve3dContinuity) theTool = new ShapeUpgrade_SplitCurve3dContinuity;
661 theTool->Init(GC);
662 theTool->SetTolerance (Tol);
663 theTool->SetCriterion (GeomAbs_C1);
664 if(Split == 1) {
665 Handle(TColStd_HSequenceOfReal) spval = new TColStd_HSequenceOfReal;
666 for(Standard_Integer i = 1; i<=5; i++) spval->Append(i);
667 theTool->SetSplitValues(spval);
668 }
669 theTool->Perform (Standard_True);
670 Handle(TColGeom_HArray1OfCurve) theCurves= theTool->GetCurves();
671 Standard_Integer NbC=theCurves->Length();
672 for (Standard_Integer icurv=1; icurv<=NbC; icurv++) {
673 char name[100];
91322f44 674 Sprintf(name,"%s%s%d",a[1],"_",icurv);
7fd59977 675 char* newname = name;
676 DrawTrSurf::Set(newname, theCurves->Value(icurv));
677 di.AppendElement(newname);
678 }
679 return 0;
680}
681
682
683//=======================================================================
684//function : DT_SplitCurve2d
685//purpose : Splits the curve with C1 criterion
686//
687//
688//=======================================================================
689static Standard_Integer DT_SplitCurve2d (Draw_Interpretor& di,
690 Standard_Integer n, const char** a)
691
692{
693 // a[1]= input 2d curve. This name is used with a suffix to name the output curves
694 // a[2]= Tolerance
695
696 if (n < 3) {
697 di << "bad number of arguments" <<"\n";
698 return 1;
699 }
700
91322f44 701 Standard_Real Tol=Draw::Atof(a[2]);
7fd59977 702 Handle(Geom2d_Curve) GC = DrawTrSurf::GetCurve2d(a[1]);
703 if ( GC.IsNull()) return 1;
91322f44 704 Standard_Integer Split = Draw::Atoi(a[3]);
7fd59977 705 Handle(ShapeUpgrade_SplitCurve2dContinuity) theTool = new ShapeUpgrade_SplitCurve2dContinuity;
706 theTool->Init(GC);
707 theTool->SetTolerance (Tol);
708 theTool->SetCriterion (GeomAbs_C1);
709 if(Split == 1) {
710 Handle(TColStd_HSequenceOfReal) spval = new TColStd_HSequenceOfReal;
711 for(Standard_Integer i = 1; i<=5; i++) spval->Append(i);
712 theTool->SetSplitValues(spval);
713 }
714 theTool->Perform (Standard_True);
715 Handle(TColGeom2d_HArray1OfCurve) theCurves= theTool->GetCurves();
716 Standard_Integer NbC=theCurves->Length();
717 for (Standard_Integer icurv=1; icurv<=NbC; icurv++) {
718 char name[100];
91322f44 719 Sprintf(name,"%s%s%d",a[1],"_",icurv);
7fd59977 720 char* newname = name;
721 DrawTrSurf::Set(newname, theCurves->Value(icurv));
722 di.AppendElement(newname);
723 }
724 return 0;
725}
726
727
728//=======================================================================
729//function : DT_SplitSurface
730//purpose : Splits the surface with C1 criterion
731//
732//
733//=======================================================================
734/*
735static Standard_Integer DT_SplitWire (Draw_Interpretor& di,
736 Standard_Integer n, const char** a)
737{
738
739 if (n <3) {
740 di << "bad number of arguments" <<"\n";
741 return 1;
742 }
743
744 TopoDS_Face source = TopoDS::Face(DBRep::Get(a[2]));
745 if(source.IsNull()) {
746 di <<"Shape is not face"<<"\n";
747 return 1;
748 }
749 TopoDS_Iterator wi(source);
750 if(!wi.More()) {
751 di <<"Shape is face without wire"<<"\n";
752 return 1;
753 }
754
755 TopoDS_Wire wire = TopoDS::Wire(wi.Value());
756 Handle(ShapeUpgrade_WireDivideContinuity) tool = new ShapeUpgrade_WireDivideContinuity;
757 tool->Init(wire,source);
758 if(n >=4 ) {
91322f44 759 Standard_Real Tol=Draw::Atof(a[3]);
7fd59977 760 }
761 Handle(ShapeBuild_ReShape) context = new ShapeBuild_ReShape;
762 tool->Perform(context);
763 TopoDS_Wire result = tool->Wire();
764 DBRep::Set(a[1],result);
765 return 0;
766}
767*/
768/*
769static Standard_Integer DT_SplitFace (Draw_Interpretor& di,
770 Standard_Integer n, const char** a)
771{
772
773 if (n <3) {
774 di << "bad number of arguments" <<"\n";
775 return 1;
776 }
777
778 TopoDS_Face source = TopoDS::Face(DBRep::Get(a[2]));
779 if(source.IsNull()) {
780 di <<"Shape is not face"<<"\n";
781 return 1;
782 }
783 Handle(ShapeUpgrade_ShapeDivideContinuity) tool = new ShapeUpgrade_FaceDivideContinuity;
784 tool->Init(source);
785 if(n >=4 ) {
91322f44 786 Standard_Real Tol=Draw::Atof(a[3]);
7fd59977 787 tool->SetPrecision(Tol);
788 }
789
790 Handle(ShapeBuild_ReShape) context = new ShapeBuild_ReShape;
791 tool->Perform(context);
792 TopoDS_Shape result = tool->Result();
793
794
795 if ( tool->Status ( ShapeExtend_OK ) ) di << "Status: OK" << "\n";
796 if ( tool->Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1" << "\n";
797 if ( tool->Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2" << "\n";
798 if ( tool->Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3" << "\n";
799 if ( tool->Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4" << "\n";
800 if ( tool->Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5" << "\n";
801 if ( tool->Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6" << "\n";
802 if ( tool->Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7" << "\n";
803 if ( tool->Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8" << "\n";
804 if ( tool->Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1" << "\n";
805 if ( tool->Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2" << "\n";
806 if ( tool->Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3" << "\n";
807 if ( tool->Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4" << "\n";
808 if ( tool->Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5" << "\n";
809 if ( tool->Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6" << "\n";
810 if ( tool->Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7" << "\n";
811 if ( tool->Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8" << "\n";
812
813 // fixes
814
815 ShapeFix::SameParameter ( result, Standard_False );
816
817 DBRep::Set(a[1],result);
818 return 0;
819}
820*/
821
822static Standard_Integer DT_SplitSurface (Draw_Interpretor& di,
823 Standard_Integer n, const char** a)
824
825{
826 // a[1]= result (used with a suffix to name the output surfaces)
827 // a[2]= input surface.
828 // a[3]= Tolerance
829
830 // a[1]= result
831 // a[2]= nbU
832 // a[3]= nbV
833 // a[3+1]..a[3+nbU*nbV] = Input Surfaces
834 // a[4+nbU*nbV]= Tolerance
835
836 if (n <4) {
837 di << "bad number of arguments" <<"\n";
838 return 1;
839 }
840
841 Handle(ShapeUpgrade_SplitSurfaceContinuity) theTool = new ShapeUpgrade_SplitSurfaceContinuity;//S4137
842
91322f44 843 Standard_Real Tol=Draw::Atof(a[3]);
844 Standard_Integer Split = Draw::Atoi(a[4]);
7fd59977 845 theTool->SetTolerance(Tol);
846 theTool->SetCriterion(GeomAbs_C1);
847 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[2]);
848/*
849 if ( GS.IsNull()) {
850 // Case of composite grid surface
851 di << "composite surf" << "\n";
91322f44 852 Standard_Integer nbU=Draw::Atoi(a[2]);
853 Standard_Integer nbV=Draw::Atoi(a[3]);
7fd59977 854 if (nbU==0 || nbV==0) return 1;
855 Handle(TColGeom_HArray2OfSurface)
856 theGrid= new TColGeom_HArray2OfSurface(1,nbU,1,nbV);
857 for (Standard_Integer iu=1; iu<=nbU; iu++) {
858 for (Standard_Integer iv=1; iv<=nbV; iv++) {
859 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[3+(iu-1)*nbV+iv]);
860 theGrid->SetValue(iu,iv,GS);
861 }
862 }
863 di << "appel a SplitSurface::Init" << "\n";
864 theTool->Init(theGrid);
865 }
866 else {*/
867 // Case of single surface
868 di << "single surf" << "\n";
869
870 di << "appel a SplitSurface::Init" << "\n";
871 theTool->Init(GS);
872 if(Split ==1) {
873 Handle(TColStd_HSequenceOfReal) spval = new TColStd_HSequenceOfReal;
874 for(Standard_Integer i = 1; i<=5; i++) spval->Append(i);
875 theTool->SetUSplitValues(spval);
876 theTool->SetVSplitValues(spval);
877 }
878
879 di << "appel a SplitSurface::Build" << "\n";
880 theTool->Build(Standard_True);
881
882 di << "appel a SplitSurface::GlobalU/VKnots" << "\n";
883 Handle(ShapeExtend_CompositeSurface) Grid = theTool->ResSurfaces();
884 Handle(TColStd_HArray1OfReal) GlobalU=Grid->UJointValues();
885 Handle(TColStd_HArray1OfReal) GlobalV=Grid->VJointValues();
886 Standard_Integer nbGlU=GlobalU->Length();
887 Standard_Integer nbGlV=GlobalV->Length();
888 di << "nb GlobalU ; nb GlobalV="<<nbGlU<<" "<<nbGlV;
889 for (Standard_Integer iu=1; iu<=nbGlU; iu++)
890 di <<" "<< GlobalU->Value(iu);
891// di <<"\n";
892// di << "nb GlobalV="<<nbGlV;
893 for (Standard_Integer iv=1; iv<=nbGlV; iv++)
894 di <<" "<< GlobalV->Value(iv);
895 di <<"\n";
896
897di << "appel a Surfaces" << "\n";
898 Handle(TColGeom_HArray2OfSurface) theSurfaces= Grid->Patches();
899
900di << "transfert resultat" << "\n";
901 Standard_Integer NbRow=theSurfaces->ColLength();
902 Standard_Integer NbCol=theSurfaces->RowLength();
903 for (Standard_Integer irow=1; irow<=NbRow; irow++) {
904 for (Standard_Integer icol=1; icol<=NbCol; icol++) {
905 char name[100];
91322f44 906 Sprintf(name,"%s%s%d%s%d",a[1],"_",irow,"_",icol);
7fd59977 907 char* newname = name;
908 DrawTrSurf::Set(newname, theSurfaces->Value(irow, icol));
909 di.AppendElement(newname);
910 }
911 }
912 return 0;
913}
914
915
916
917//=======================================================================
918//function : DT_SupportModification
919//purpose : Changes the supports of a Shell
920// The given surface wil support all the faces of the new shell.
921// with the PCurves of the old ones.
922//
923//=======================================================================
924/*static Standard_Integer DT_SupportModification (Draw_Interpretor& di,
925 Standard_Integer n, const char** a)
926
927{
928 // a[1]= result
929 // a[2]= input Shell
930 // a[3]= new Surface
931 // a[4]= 2d3d Scale Factor
932
933 if (n !=5) {
934 di << "bad number of arguments" <<"\n";
935 return 1;
936 }
937
938 TopoDS_Shape inputShape= DBRep::Get(a[2]);
939 TopoDS_Shell inputShell = TopoDS::Shell(inputShape);
940 if (inputShell.IsNull()) {
941 di << a[2] << " is not a shell" << "\n";
942 return 1;
943 }
944
945 Handle(Geom_Surface) theSurf = DrawTrSurf::GetSurface(a[3]);
946 if ( theSurf.IsNull()) {
947 di << a[3] << " is not a surface" << "\n";
948 return 1;
949 }
950
951 ShapeUpgrade_DataMapOfShapeSurface theMap;
952 // Associates thesurf to each face of inputShell.
953 TopExp_Explorer ExpSh;
954 for (ExpSh.Init(inputShell,TopAbs_FACE); ExpSh.More(); ExpSh.Next()){
955 TopoDS_Face theFace= TopoDS::Face(ExpSh.Current());
956 theMap.Bind(theFace,theSurf);
957 }
958
91322f44 959 Standard_Real the2d3dFactor=Draw::Atof(a[4]);
7fd59977 960 ShapeUpgrade_SupportModification theTool(inputShell,theMap,the2d3dFactor);
961
962 TopoDS_Shell res = theTool.Shell();
963 DBRep::Set(a[1],res);
964
965 return 0;
966}*/
967
968//=======================================================================
969//function : DT_Debug
970//purpose : activation of the debug mode
971//
972//=======================================================================
973/*
974static Standard_Integer DT_Debug (Draw_Interpretor& di,
975 Standard_Integer n, const char** a)
976
977{
978 // a[1]= 0/1
979
980 if (n !=2) {
981 di << "bad number of arguments" <<"\n";
982 return 1;
983 }
984
91322f44 985 if (Draw::Atoi(a[1])==1) {
7fd59977 986 di << "Activation of debug messages"<<"\n";
987 ShapeUpgrade::SetDebug(Standard_True);
988 }
989 else {
990 di << "Desactivation of debug messages"<<"\n";
991 ShapeUpgrade::SetDebug(Standard_False);
992 }
993 return 0;
994}
995*/
996
997/*static Standard_Integer shellsolid
998 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
999{
1000 if (argc < 4) {
1001 di<<"Donner option + nom de SHAPE + nom de RESULTAT"<<"\n";
1002 di<<"Options : a all (sewing sur tous les shells\n"
1003 << " c check (sewing sur shells avec bad edges\n"
1004 <<" b bad edges\n f free edges"<<"\n";
1005 return 1 ;
1006 }
1007 Standard_CString arg1 = argv[1];
1008 Standard_CString arg2 = argv[2];
1009 Standard_CString arg3 = argv[3];
1010
1011 TopoDS_Shape Shape = DBRep::Get(arg2);
1012 if (Shape.IsNull()) { di<<"Shape unknown : "<<arg2<<"\n"; return 1 ; }
1013
1014 ShapeAnalysis_Shell STS;
1015 char opt = arg1[0];
1016 if (opt == 'a') STS.LoadShells (Shape);
1017 else if (opt == 'f') STS.CheckOrientedShells (Shape,Standard_True);
1018 else if (opt == 'b' || opt == 'c') STS.CheckOrientedShells (Shape,Standard_False);
1019
1020 else if (opt == 'o') {
1021
1022// Test WireOrder
1023 Handle(ShapeExtend_WireData) Frees = new ShapeExtend_WireData;//:sw Frees.SetPrecision (BRepBuilderAPI::Precision());
1024 Standard_Integer nbe = 0;
1025 for (TopExp_Explorer edges(Shape,TopAbs_EDGE); edges.More(); edges.Next()) {
1026 Frees->Add (TopoDS::Edge(edges.Current())); nbe ++;
1027 }
1028 ShapeAnalysis_WireOrder WO (Standard_True,BRepBuilderAPI::Precision());
1029 ShapeAnalysis_Wire saw;
1030 saw.Load ( Frees );
1031 saw.SetPrecision ( BRepBuilderAPI::Precision() );
1032 saw.CheckOrder ( WO );
1033
1034 Standard_Integer stat = WO.Status();
1035 di<<"Wire Order Status = "<<stat<<" on "<<nbe<<" Edges"<<"\n";
1036 nbe = WO.NbEdges();
1037 for (Standard_Integer ie = 1; ie <= nbe; ie ++) {
1038 Standard_Integer io = WO.Ordered (ie);
1039 gp_XYZ st3d,en3d;
1040 WO.XYZ (io,st3d,en3d);
1041 di<<ie<<": Edge."<<io<<" Start:"<<st3d.X()<<" "<<st3d.Y()<<" "<<st3d.Z()
1042 <<" End:"<<en3d.X()<<" "<<en3d.Y()<<" "<<en3d.Z()<<"\n";
1043 }
1044// Chainage ?
1045 Standard_Real gap = BRepBuilderAPI::Precision();
1046 WO.SetChains (gap);
1047 Standard_Integer n1,n2,ic, nc = WO.NbChains();
1048 for (ic = 1; ic <= nc; ic ++) {
1049 WO.Chain(ic,n1,n2);
1050 di<<"Chain."<<ic<<" From "<<n1<<" To "<<n2<<"\n";
1051 }
1052 }
1053
1054 else { di<<"Option non reconnue : "<<arg1<<"\n"; return 1; }
1055
1056 TopoDS_Shape res;
1057 if (opt == 'a' || opt == 'c') {
1058 ShapeUpgrade_ShellSewing sew;
1059 res = sew.ApplySewing (Shape);
1060 if (res.IsEqual(Shape)) {
1061 res.Nullify();
1062 di<<"ShellSolid : no sewing done"<<"\n";
1063 }
1064 } else if (opt == 'b') {
1065 if (STS.HasBadEdges()) res = STS.BadEdges();
1066 else di<<"ShellSolid : no bad edge"<<"\n";
1067 } else if (opt == 'f') {
1068 if (STS.HasFreeEdges()) res = STS.FreeEdges();
1069 else di<<"ShellSolid : no free edge"<<"\n";
1070 if (STS.HasConnectedEdges()) di<<"ShellSolid : connected edges"<<"\n";
1071 else di<<"ShellSolid : NO connected edges"<<"\n";
1072 }
1073
1074 if (!res.IsNull()) DBRep::Set (arg3,res);
1075
1076 return 0; // Done
1077}*/
1078//---------------gka
1079//=======================================================================
1080//function : offset2dcurve
1081//purpose :
1082//
1083//=======================================================================
1084static Standard_Integer offset2dcurve
1085 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1086{
1087 if (argc < 4) {
1088 di<<"result + curve + offset"<<"\n";
1089
1090 return 1 /* Error */;
1091 }
1092// Standard_CString arg1 = argv[1];
1093// Standard_CString arg2 = argv[2];
91322f44 1094 Standard_Real Offset = Draw::Atof(argv[3]);
7fd59977 1095 Handle(Geom2d_Curve) GC = DrawTrSurf::GetCurve2d(argv[2]);
1096 if ( GC.IsNull()) return 1;
1097 Handle(Geom2d_OffsetCurve) offcrv = new Geom2d_OffsetCurve(GC,Offset);
1098 DrawTrSurf::Set(argv[1], offcrv);
1099 return 0;
1100}
1101
1102//=======================================================================
1103//function : offsetcurve
1104//purpose :
1105//
1106//=======================================================================
1107static Standard_Integer offsetcurve
1108 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1109{
1110 if (argc < 5) {
1111 di<<"result + curve + offset + Dir"<<"\n";
1112
1113 return 1 /* Error */;
1114 }
1115// Standard_CString arg1 = argv[1];
1116// Standard_CString arg2 = argv[2];
91322f44 1117 Standard_Real Offset = Draw::Atof(argv[3]);
7fd59977 1118 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(argv[2]);
1119 if ( GC.IsNull()) return 1;
1120 gp_Pnt point;
1121 DrawTrSurf::GetPoint(argv[4],point);
1122 gp_Dir dir(point.XYZ());
1123 Handle(Geom_OffsetCurve) offcrv = new Geom_OffsetCurve(GC,Offset,dir);
1124 DrawTrSurf::Set(argv[1], offcrv);
1125 return 0;
1126}
1127
1128//=======================================================================
1129//function : compose shell
1130//purpose :
1131//=======================================================================
1132static Standard_Integer splitface
1133 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1134{
1135 if (argc < 5) {
1136 di << "Split face: splitface result face [u usplit1 usplit2...] [v vsplit1 vsplit2 ...]" << "\n";
1137 return 1;
1138 }
1139
1140 TopoDS_Shape aLocalShape = DBRep::Get(argv[2]) ;
1141 TopoDS_Face face = TopoDS::Face ( aLocalShape );
1142 if ( face.IsNull() ) {
1143 di << argv[2] << " is not Face" << "\n";
1144 return 1;
1145 }
1146
1147 Handle(Geom_Surface) S = BRep_Tool::Surface ( face );
1148 Standard_Real Uf, Ul, Vf, Vl;
1149 BRepTools::UVBounds ( face, Uf, Ul, Vf, Vl );
1150 Standard_Real Umin, Umax, Vmin, Vmax;
1151 S->Bounds ( Umin, Umax, Vmin, Vmax );
1152 if ( Uf < Umin && ! S->IsUPeriodic() ) Uf = Umin;
1153 else if ( Uf > Umin )
1154 if ( Precision::IsInfinite(Umin) ) Uf -= 100;
1155 else Uf = Umin;
1156 if ( Vf < Vmin && ! S->IsVPeriodic() ) Vf = Vmin;
1157 else if ( Vf > Vmin )
1158 if ( Precision::IsInfinite(Vmin) ) Vf -= 100;
1159 else Vf = Vmin;
1160 if ( Ul > Umax && ! S->IsUPeriodic() ) Ul = Umax;
1161 else if ( Ul < Umax )
1162 if ( Precision::IsInfinite(Umax) ) Ul += 100;
1163 else Ul = Umax;
1164 if ( Vl > Vmax && ! S->IsVPeriodic() ) Vl = Vmax;
1165 else if ( Vl < Vmax )
1166 if ( Precision::IsInfinite(Vmax) ) Vl += 100;
1167 else Vl = Vmax;
1168
1169 TColStd_SequenceOfReal uval;
1170 TColStd_SequenceOfReal vval;
1171
1172 Standard_Boolean byV = Standard_False;
1173 Standard_Integer i; // svv Jan11 2000 : porting on DEC
1174 for ( i=3; i < argc; i++ ) {
1175 if ( argv[i][0] == 'u' ) byV = Standard_False;
1176 else if ( argv[i][0] == 'v' ) byV = Standard_True;
1177 else {
91322f44 1178 Standard_Real val = Draw::Atof ( argv[i] );
7fd59977 1179 TColStd_SequenceOfReal &vals = ( byV ? vval : uval );
1180 if ( vals.Length() >0 && val - vals.Last() < Precision::PConfusion() ) {
1181 di << "Values should be sorted in increasing order; skipped" << "\n";
1182 continue;
1183 }
1184 if ( ( byV && ( val < Vf+Precision::PConfusion() ||
1185 val > Vl-Precision::PConfusion() ) ) ||
1186 (!byV && ( val < Uf+Precision::PConfusion() ||
1187 val > Ul-Precision::PConfusion() ) ) ) {
1188 di << "Values should be inside range of surface; skipped" << "\n";
1189 continue;
1190 }
1191 vals.Append ( val );
1192 }
1193 }
1194 if ( uval.Length() <1 && vval.Length() <1 ) {
1195 di << "No splitting defined" << "\n";
1196 return 1;
1197 }
1198 if ( uval.Length() >0 ) {
1199 di << "Splitting by U: ";
1200 for ( Standard_Integer j=1; j <= uval.Length(); j++ ) {
1201 //cout << ( i >j ? ", " : "" ) << uval(j);
1202 if (i >j) {
1203 di << ", ";
1204 } else {
1205 di << "";
1206 }
1207 di << uval(j);
1208 }
1209 di << "\n";
1210 }
1211 if ( vval.Length() >0 ) {
1212 di << "Splitting by V: ";
1213 for ( Standard_Integer j=1; j <= vval.Length(); j++ ) {
1214 //cout << ( j >1 ? ", " : "" ) << vval(j);
1215 if (j >1) {
1216 di << ", ";
1217 } else {
1218 di << "";
1219 }
1220 di << vval(j);
1221 }
1222 di << "\n";
1223 }
1224
1225 Handle(TColGeom_HArray2OfSurface) AS = new TColGeom_HArray2OfSurface ( 1, uval.Length()+1,
1226 1, vval.Length()+1 );
1227 for ( i=0; i <= uval.Length(); i++ ) {
1228 Standard_Real umin = ( i ? uval(i) : Uf );
1229 Standard_Real umax = ( i < uval.Length() ? uval(i+1) : Ul );
1230 for ( Standard_Integer j=0; j <= vval.Length(); j++ ) {
1231 Standard_Real vmin = ( j ? vval(j) : Vf );
1232 Standard_Real vmax = ( j < vval.Length() ? vval(j+1) : Vl );
1233 Handle(Geom_RectangularTrimmedSurface) rect =
1234 new Geom_RectangularTrimmedSurface ( S, umin, umax, vmin, vmax );
1235 AS->SetValue ( i+1, j+1, rect );
1236 }
1237 }
1238
1239 Handle(ShapeExtend_CompositeSurface) Grid = new ShapeExtend_CompositeSurface;
1240 if ( ! Grid->Init ( AS ) ) di << "Grid badly connected!" << "\n";
1241
1242 ShapeFix_ComposeShell SUCS;
1243 TopLoc_Location l;
1244 SUCS.Init ( Grid, l, face, Precision::Confusion() );
1245 Handle(ShapeBuild_ReShape) RS = new ShapeBuild_ReShape;
1246 SUCS.SetContext( RS );
1247 SUCS.Perform ();
1248
1249 if ( SUCS.Status ( ShapeExtend_OK ) ) di << "Status: OK" << "\n";
1250 if ( SUCS.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1" << "\n";
1251 if ( SUCS.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2" << "\n";
1252 if ( SUCS.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3" << "\n";
1253 if ( SUCS.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4" << "\n";
1254 if ( SUCS.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5" << "\n";
1255 if ( SUCS.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6" << "\n";
1256 if ( SUCS.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7" << "\n";
1257 if ( SUCS.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8" << "\n";
1258 if ( SUCS.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1" << "\n";
1259 if ( SUCS.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2" << "\n";
1260 if ( SUCS.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3" << "\n";
1261 if ( SUCS.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4" << "\n";
1262 if ( SUCS.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5" << "\n";
1263 if ( SUCS.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6" << "\n";
1264 if ( SUCS.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7" << "\n";
1265 if ( SUCS.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8" << "\n";
1266
1267 TopoDS_Shape sh = SUCS.Result();
1268 ShapeFix::SameParameter ( sh, Standard_False );
1269 DBRep::Set ( argv[1], sh );
1270 return 0;
1271}
1272
1273static Standard_Integer converttobspline
1274 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1275{
1276 if (argc<3) {
1277 di << "Use: " << argv[0] << " result shape [options=ero]\n";
1278 di << "where options is combination of letters indicating kinds of\n";
1279 di << "surfaces to be converted:\n";
1280 di << "e - extrusion\n";
1281 di << "r - revolution\n";
1282 di << "o - offset\n";
1283 di << "p - plane";
1284 return 1;
1285 }
1286 const char *options = ( argc > 3 ? argv[3] : "ero" );
1287
1288 TopoDS_Shape inputShape=DBRep::Get(argv[2]);
1289 if (inputShape.IsNull()) {
1290 di << "Unknown shape"<< "\n";
1291 return 1;
1292 }
1293 TopoDS_Shape revsh = ShapeCustom::ConvertToRevolution (inputShape);
1294 TopoDS_Shape res =
1295 ShapeCustom::ConvertToBSpline (revsh, strchr (options, 'e') != 0,
1296 strchr (options, 'r') != 0,
1297 strchr (options, 'o') != 0,
1298 strchr (options, 'p') != 0);
1299 ShapeFix::SameParameter ( res, Standard_False );
1300 DBRep::Set ( argv[1], res );
1301 return 0;
1302}
1303
1304
1305static Standard_Integer splitclosed (Draw_Interpretor& di,
1306 Standard_Integer argc,
1307 const char** argv)
1308{
1309 if (argc<3) {
1310 di << "bad number of arguments" <<"\n";
1311 return 1;
1312 }
1313
1314 TopoDS_Shape inputShape=DBRep::Get(argv[2]);
1315 if (inputShape.IsNull()) {
1316 di << "Unknown shape"<< "\n";
1317 return 1;
1318 }
1319
1320 ShapeUpgrade_ShapeDivideClosed tool (inputShape);
1321 tool.Perform();
1322 TopoDS_Shape res = tool.Result();
1323
1324 ShapeFix::SameParameter ( res, Standard_False );
1325 DBRep::Set ( argv[1], res );
1326 return 0;
1327}
1328
1329static Standard_Integer splitarea (Draw_Interpretor& di,
1330 Standard_Integer argc,
1331 const char** argv)
1332{
1333 if (argc<4) {
1334 di << "bad number of arguments" <<"\n";
1335 return 1;
1336 }
1337
1338 TopoDS_Shape inputShape=DBRep::Get(argv[2]);
1339 if (inputShape.IsNull()) {
1340 di << "Unknown shape"<< "\n";
1341 return 1;
1342 }
91322f44 1343 Standard_Real aMaxArea = Draw::Atof(argv[3]);
7fd59977 1344
1345
1346 ShapeUpgrade_ShapeDivideArea tool (inputShape);
1347 if(argc >4) {
91322f44 1348 Standard_Real prec = Draw::Atof(argv[4]);
7fd59977 1349 tool.SetPrecision(prec);
1350 }
1351 tool.MaxArea() = aMaxArea;
1352 tool.Perform();
1353 TopoDS_Shape res = tool.Result();
1354
1355 ShapeFix::SameParameter ( res, Standard_False );
1356 DBRep::Set ( argv[1], res );
1357 return 0;
1358}
1359
1360static Standard_Integer removeinternalwires (Draw_Interpretor& di,
1361 Standard_Integer argc,
1362 const char** argv)
1363{
1364 if (argc<4) {
1365 di << "bad number of arguments" <<"\n";
1366 return 1;
1367 }
91322f44 1368 Standard_Real aMinArea = Draw::Atof(argv[2]);
7fd59977 1369 TopoDS_Shape inputShape=DBRep::Get(argv[3]);
1370 if (inputShape.IsNull()) {
1371 di << "Unknown shape"<< "\n";
1372 return 1;
1373 }
1374 Handle(ShapeUpgrade_RemoveInternalWires) aTool;
1375 TopTools_SequenceOfShape aSeqShapes;
1376 if(inputShape.ShapeType() < TopAbs_WIRE)
1377 aTool = new ShapeUpgrade_RemoveInternalWires(inputShape);
1378 else {
1379 di<<"Invalid type of first shape: should be FACE,SHELL,SOLID or COMPOUND"<<"\n";
1380 return 1;
1381 }
1382
1383 Standard_Integer k = 4;
1384 Standard_Boolean isShape = Standard_True;
1385 Standard_Boolean aModeRemoveFaces =Standard_True;
1386
1387
1388 for( ; k < argc; k++) {
1389 if(isShape) {
1390 TopoDS_Shape aShape=DBRep::Get(argv[k]);
1391 isShape = !aShape.IsNull();
1392 if(isShape) {
1393 if(aShape.ShapeType() == TopAbs_FACE || aShape.ShapeType() == TopAbs_WIRE)
1394 aSeqShapes.Append(aShape);
1395 }
1396 }
1397 if(!isShape)
91322f44 1398 aModeRemoveFaces = (Draw::Atoi(argv[k]) == 1);
7fd59977 1399 }
1400
1401 aTool->MinArea() = aMinArea;
1402 aTool->RemoveFaceMode() = aModeRemoveFaces;
1403 if(aSeqShapes.Length())
1404 aTool->Perform(aSeqShapes);
1405 else
1406 aTool->Perform();
1407 if(aTool->Status(ShapeExtend_FAIL1))
1408 di<<"Initial shape has invalid type"<<"\n";
1409 else if(aTool->Status(ShapeExtend_FAIL2))
1410 di<<"Specified sub-shape is not belonged to whole shape"<<"\n";
1411 if(aTool->Status(ShapeExtend_DONE1)) {
1412 const TopTools_SequenceOfShape& aRemovedWires =aTool->RemovedWires();
1413 di<<aRemovedWires.Length()<<" internal wires were removed"<<"\n";
1414
1415 }
1416 if(aTool->Status(ShapeExtend_DONE2)) {
1417 const TopTools_SequenceOfShape& aRemovedFaces =aTool->RemovedFaces();
1418 di<<aRemovedFaces.Length()<<" small faces were removed"<<"\n";
1419
1420 }
1421 TopoDS_Shape res = aTool->GetResult();
1422
1423
1424 DBRep::Set ( argv[1], res );
1425 return 0;
1426}
1427
982a90fc
G
1428static Standard_Integer removeloc (Draw_Interpretor& di,
1429 Standard_Integer argc,
1430 const char** argv)
1431{
1432 if (argc<3) {
1433 di << "bad number of arguments. Should be: removeloc res shape" <<"\n";
1434 return 1;
1435 }
1436
1437 TopoDS_Shape aShape = DBRep::Get(argv[2]);
1438 if(aShape.IsNull())
1439 return 1;
1440 ShapeUpgrade_RemoveLocations aRemLoc;
1441 aRemLoc.Remove(aShape);
1442 TopoDS_Shape aNewShape = aRemLoc.GetResult();
1443
1444 DBRep::Set(argv[1],aNewShape);
1445 return 0;
1446}
2277323d 1447
1448//=======================================================================
1449// unifysamedom
1450//=======================================================================
1451static Standard_Integer unifysamedom(Draw_Interpretor& , Standard_Integer n, const char** a)
1452{
1453 if (n < 3)
1454 return 1;
1455
1456 TopoDS_Shape aShape = DBRep::Get(a[2]);
1457 if (aShape.IsNull())
1458 return 1;
1459
1460 ShapeUpgrade_UnifySameDomain Unifier(aShape);
1461 Unifier.Build();
1462 TopoDS_Shape Result = Unifier.Shape();
1463
1464 DBRep::Set(a[1], Result);
1465 return 0;
1466}
1467
982a90fc
G
1468static Standard_Integer copytranslate(Draw_Interpretor& di,
1469 Standard_Integer argc,
1470 const char** argv)
1471{
1472 if (argc<6) {
1473 di << "bad number of arguments. Should be: removeloc res shape dx dyy dz" <<"\n";
1474 return 1;
1475 }
1476 TopoDS_Shape aShape = DBRep::Get(argv[2]);
1477 if(aShape.IsNull())
1478 return 1;
91322f44 1479 Standard_Real aDx = Draw::Atof(argv[3]);
1480 Standard_Real aDy = Draw::Atof(argv[4]);
1481 Standard_Real aDz = Draw::Atof(argv[5]);
982a90fc
G
1482 gp_Trsf aTrsf;
1483 aTrsf.SetTranslation(gp_Vec(aDx, aDy, aDz));
1484 BRepBuilderAPI_Transform builderTransform(aTrsf);
1485 builderTransform.Perform (aShape, true);
1486 TopoDS_Shape aNewShape = builderTransform.Shape();
1487 DBRep::Set(argv[1],aNewShape);
1488 return 0;
1489
1490}
1491
7fd59977 1492//=======================================================================
1493//function : InitCommands
1494//purpose :
1495//=======================================================================
1496
1497 void SWDRAW_ShapeUpgrade::InitCommands(Draw_Interpretor& theCommands)
1498{
1499 static Standard_Integer initactor = 0;
1500 if (initactor) return; initactor = 1;
1501
1502 Standard_CString g = SWDRAW::GroupName(); // "Tests of DivideTool";
1503
1504 theCommands.Add("DT_ShapeDivide",
1505 "DT_ShapeDivide Result Shape Tol: Divides shape with C1 Criterion",
1506 __FILE__,
1507 DT_ShapeDivide,g);
1508
1509 theCommands.Add("DT_SplitAngle",
1510 "DT_SplitAngle Result Shape [MaxAngle=95]: Divides revolved surfaces on segments less MaxAngle deg",
1511 __FILE__,
1512 DT_SplitAngle,g);
1513
1514 theCommands.Add("DT_ShapeConvert",
1515 "DT_ShapeConvert Result Shape convert2d convert3d: Converts curves to beziers",
1516 __FILE__,
1517 DT_ShapeConvert,g);
1518
1519 theCommands.Add("DT_ShapeConvertRev",
1520 "DT_ShapeConvert Result Shape convert2d convert3d: Converts curves to beziers",
1521 __FILE__,
1522 DT_ShapeConvertRev,g);
1523/* theCommands.Add("DT_PlaneDividedFace",
1524 "DT_PlaneDividedFace Result Face Tol: Transfer into a plane with boundary divided",
1525 __FILE__,
1526 DT_PlaneDividedFace,g);
1527
1528 theCommands.Add("DT_PlaneGridShell",
1529 "DT_PlaneGridShell Result NbU NbV {UKnots} {VKnots} Tol : Create a plane grid Shell",
1530 __FILE__,
1531 DT_PlaneGridShell,g);
1532
1533 theCommands.Add("DT_PlaneFaceCommon",
1534 "DT_PlaneFaceCommon Result Face Shell: Common between a plane Face and a Shell",
1535 __FILE__,
1536 DT_PlaneFaceCommon,g);*/
1537
1538 theCommands.Add("DT_SplitCurve2d",
1539 "DT_SplitCurve2d Curve Tol: Splits the curve with C1 criterion",
1540 __FILE__,
1541 DT_SplitCurve2d,g);
1542
1543 theCommands.Add("DT_SplitCurve",
1544 "DT_SplitCurve Curve Tol: Splits the curve with C1 criterion",
1545 __FILE__,
1546 DT_SplitCurve,g);
1547
1548 theCommands.Add("DT_SplitSurface",
1549 "DT_SplitSurface Result Surface/GridSurf Tol: Splits the surface with C1 criterion",
1550 __FILE__,
1551 DT_SplitSurface,g);
1552
1553 /*theCommands.Add("DT_SupportModification",
1554 "DT_SupportModification Result Shell Surface 2d3dFactor: Surface will support all the faces",
1555 __FILE__,
1556 DT_SupportModification,g);*/
1557
1558// theCommands.Add("DT_SpltWire","DT_SpltWire Result Wire Tol",
1559// __FILE__,DT_SplitWire,g);
1560
1561// theCommands.Add("DT_SplitFace", "DT_SplitFace Result Face Tol",
1562// __FILE__, DT_SplitFace,g);
1563
1564// theCommands.Add("DT_Debug", "DT_Debug 0/1 : activation/desactivation of the debug messages",
1565// __FILE__, DT_Debug,g);
1566// theCommands.Add ("shellsolid","option[a-b-c-f] shape result",
1567// __FILE__,shellsolid,g);
1568 theCommands.Add ("offset2dcurve","result curve offset",
1569 __FILE__,offset2dcurve,g);
1570
1571 theCommands.Add ("offsetcurve","result curve offset dir",
1572 __FILE__,offsetcurve,g);
1573
1574 theCommands.Add ("splitface","result face [u usplit1 usplit2...] [v vsplit1 vsplit2 ...]",
1575 __FILE__,splitface,g);
1576
1577 theCommands.Add ("DT_ToBspl","result shape [options=erop]",
1578 __FILE__,converttobspline,g);
1579 theCommands.Add ("DT_ClosedSplit","result shape",
1580 __FILE__,splitclosed,g);
1581 theCommands.Add ("DT_SplitByArea","result shape maxarea [preci]",
1582 __FILE__,splitarea,g);
1583
1584 theCommands.Add ("RemoveIntWires","result minarea wholeshape [faces or wires] [moderemoveface ]",
1585 __FILE__,removeinternalwires,g);
982a90fc
G
1586
1587 theCommands.Add ("removeloc","result shape",__FILE__,removeloc,g);
2277323d 1588
1589 theCommands.Add ("unifysamedom",
1590 "unifysamedom result shape",__FILE__,unifysamedom,g);
1591
982a90fc 1592 theCommands.Add ("copytranslate","result shape dx dy dz",__FILE__,copytranslate,g);
7fd59977 1593}