0022746: Progress indicator in ShapeHealing
[occt.git] / src / ShapeProcess / ShapeProcess_OperLibrary.cxx
CommitLineData
7fd59977 1// File: ShapeProcess_OperLibrary.cxx
2// Created: Thu Aug 31 11:34:26 2000
3// Author: Andrey BETENEV
4// <abv@nnov.matra-dtv.fr>
5
6#include <ShapeProcess_OperLibrary.ixx>
7
8#include <Precision.hxx>
9#include <TopoDS_Shape.hxx>
10#include <TopoDS_Compound.hxx>
11#include <TopoDS_Iterator.hxx>
12#include <BRep_Builder.hxx>
13#include <BRepLib.hxx>
14
15#include <Message_MsgFile.hxx>
b485ee79
KD
16#include <Message_ProgressIndicator.hxx>
17
7fd59977 18#include <ShapeExtend_MsgRegistrator.hxx>
19#include <ShapeProcess.hxx>
20#include <ShapeProcess_UOperator.hxx>
21#include <ShapeProcess_ShapeContext.hxx>
22
23#include <BRepTools_Modifier.hxx>
24#include <BRepTools_Modification.hxx>
25#include <ShapeCustom_DirectModification.hxx>
26#include <ShapeCustom_RestrictionParameters.hxx>
27#include <ShapeCustom_BSplineRestriction.hxx>
28#include <ShapeCustom_ConvertToRevolution.hxx>
29#include <ShapeCustom_SweptToElementary.hxx>
30#include <ShapeCustom_ConvertToBSpline.hxx>
31
32#include <ShapeExtend.hxx>
33#include <ShapeBuild_ReShape.hxx>
34#include <ShapeUpgrade_ShapeDivideAngle.hxx>
35#include <ShapeUpgrade_ShapeConvertToBezier.hxx>
36#include <ShapeUpgrade_ShapeDivideContinuity.hxx>
37#include <ShapeUpgrade_ShapeDivideClosed.hxx>
38#include <ShapeUpgrade_ShapeDivideClosedEdges.hxx>
39
40#include <ShapeFix_ShapeTolerance.hxx>
41#include <ShapeFix_Shape.hxx>
42#include <ShapeFix_Face.hxx>
43#include <ShapeFix_Wire.hxx>
44#include <ShapeFix_FixSmallFace.hxx>
45#include <ShapeFix_Wireframe.hxx>
46#include <ShapeFix.hxx>
47#include <ShapeFix_SplitCommonVertex.hxx>
48
49
50//=======================================================================
51//function : ApplyModifier
52//purpose : Applies BRepTools_Modification to a shape,
53// taking into account sharing of components of compounds
54//=======================================================================
55
56TopoDS_Shape ShapeProcess_OperLibrary::ApplyModifier (const TopoDS_Shape &S,
57 const Handle(ShapeProcess_ShapeContext)& context,
58 const Handle(BRepTools_Modification) &M,
59 TopTools_DataMapOfShapeShape &map)
60{
61 // protect against INTERNAL/EXTERNAL shapes
62 TopoDS_Shape SF = S.Oriented(TopAbs_FORWARD);
63
64 // Process COMPOUNDs separately in order to handle sharing in assemblies
65 if ( SF.ShapeType() == TopAbs_COMPOUND ) {
66 Standard_Boolean locModified = Standard_False;
67 TopoDS_Compound C;
68 BRep_Builder B;
69 B.MakeCompound ( C );
70 for ( TopoDS_Iterator it(SF); it.More(); it.Next() ) {
71 TopoDS_Shape shape = it.Value();
72 TopLoc_Location L = shape.Location(), nullLoc;
73 shape.Location ( nullLoc );
74 TopoDS_Shape res;
75 if(map.IsBound ( shape ))
76 res = map.Find ( shape ).Oriented ( shape.Orientation() );
77
78 else {
79 res = ApplyModifier (shape, context, M, map );
80 map.Bind ( shape, res );
81 }
82 if ( ! res.IsSame ( shape ) ) locModified = Standard_True;
83 res.Location ( L );
84 B.Add ( C, res );
85 }
86 if ( ! locModified ) return S;
87
88 map.Bind ( SF, C );
89 return C.Oriented ( S.Orientation() );
90 }
91
92 // Modify the shape
93 BRepTools_Modifier MD(SF,M);
94 context->RecordModification ( SF, MD );
95 return MD.ModifiedShape(SF).Oriented(S.Orientation());
96}
97
98
99//=======================================================================
100//function : directfaces
101//purpose :
102//=======================================================================
103
104static Standard_Boolean directfaces (const Handle(ShapeProcess_Context)& context)
105{
106 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast ( context );
107 if ( ctx.IsNull() ) return Standard_False;
108
109 Handle(ShapeCustom_DirectModification) DM = new ShapeCustom_DirectModification;
110 TopTools_DataMapOfShapeShape map;
111 TopoDS_Shape res = ShapeProcess_OperLibrary::ApplyModifier ( ctx->Result(), ctx, DM, map );
112 ctx->RecordModification ( map );
113 ctx->SetResult ( res );
b485ee79 114 return Standard_True;
7fd59977 115}
116
117
118//=======================================================================
119//function : sameparam
120//purpose :
121//=======================================================================
122
123static Standard_Boolean sameparam (const Handle(ShapeProcess_Context)& context)
124{
125 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast ( context );
126 if ( ctx.IsNull() ) return Standard_False;
127 ShapeFix::SameParameter ( ctx->Result(),
128 ctx->IntegerVal ( "Force", Standard_False ),
129 ctx->RealVal ( "Tolerance3d", Precision::Confusion() /* -1 */) );
130 // WARNING: no update of context yet!
131 return Standard_True;
132}
133
134
135//=======================================================================
136//function : settol
137//purpose :
138//=======================================================================
139
140static Standard_Boolean settol (const Handle(ShapeProcess_Context)& context)
141{
142 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast ( context );
143 if ( ctx.IsNull() ) return Standard_False;
144
145 Standard_Real val;
146 if ( ctx->IntegerVal ( "Mode", 0 ) >0 && ctx->GetReal ( "Value", val ) ) {
147 Standard_Real rat = ctx->RealVal ( "Ratio", 1. );
148 if ( rat >= 1 ) {
149 ShapeFix_ShapeTolerance SFST;
150 SFST.LimitTolerance (ctx->Result(), val/rat, val*rat);
151 }
152 }
153
154 BRepLib::UpdateTolerances (ctx->Result(),Standard_True);
155
156 Standard_Real reg;
157 if ( ctx->GetReal ("Regularity", reg) )
158 BRepLib::EncodeRegularity (ctx->Result(), reg);
159
160 // WARNING: no update of context yet!
161 return Standard_True;
162}
163
164
165//=======================================================================
166//function : splitangle
167//purpose :
168//=======================================================================
169
170static Standard_Boolean splitangle (const Handle(ShapeProcess_Context)& context)
171{
172 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast ( context );
173 if ( ctx.IsNull() ) return Standard_False;
174
175 ShapeUpgrade_ShapeDivideAngle SDA ( ctx->RealVal ( "Angle", 2*PI ), ctx->Result() );
176 SDA.SetMaxTolerance ( ctx->RealVal ( "MaxTolerance", 1. ) );
177
178 if ( ! SDA.Perform() && SDA.Status (ShapeExtend_FAIL) ) {
179#ifdef DEB
180 cout<<"ShapeDivideAngle failed"<<endl;
181#endif
182 return Standard_False;
183 }
184
185 ctx->RecordModification ( SDA.GetContext() );
186 ctx->SetResult ( SDA.Result() );
187 return Standard_True;
188}
189
190
191//=======================================================================
192//function : bsplinerestriction
193//purpose :
194//=======================================================================
195
196static Standard_Boolean bsplinerestriction (const Handle(ShapeProcess_Context)& context)
197{
198 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast ( context );
199 if ( ctx.IsNull() ) return Standard_False;
200
201 Standard_Boolean ModeSurf = ctx->IntegerVal ( "SurfaceMode", Standard_True );
202 Standard_Boolean ModeC3d = ctx->IntegerVal ( "Curve3dMode", Standard_True );
203 Standard_Boolean ModeC2d = ctx->IntegerVal ( "Curve2dMode", Standard_True );
204
205 Standard_Real aTol3d = ctx->RealVal ( "Tolerance3d", 0.01 );
206 Standard_Real aTol2d = ctx->RealVal ( "Tolerance2d", 1e-06 );
207
208 GeomAbs_Shape aCont3d = ctx->ContinuityVal ( "Continuity3d", GeomAbs_C1 );
209 GeomAbs_Shape aCont2d = ctx->ContinuityVal ( "Continuity2d", GeomAbs_C2 );
210
211 Standard_Integer aMaxDeg = ctx->IntegerVal ( "RequiredDegree", 9 );
212 Standard_Integer aMaxSeg = ctx->IntegerVal ( "RequiredNbSegments", 10000 );
213
214 Standard_Boolean ModeDeg = ctx->IntegerVal ( "PreferDegree", Standard_True );
215 Standard_Boolean Rational = ctx->IntegerVal ( "RationalToPolynomial", Standard_False );
216
217 Handle(ShapeCustom_RestrictionParameters) aParameters = new ShapeCustom_RestrictionParameters;
218 ctx->GetInteger ( "MaxDegree", aParameters->GMaxDegree() );
219 ctx->GetInteger ( "MaxNbSegments", aParameters->GMaxSeg() );
220 ctx->GetBoolean ( "OffsetSurfaceMode", aParameters->ConvertOffsetSurf() );
221 ctx->GetBoolean ( "OffsetCurve3dMode", aParameters->ConvertOffsetCurv3d() );
222 ctx->GetBoolean ( "OffsetCurve2dMode", aParameters->ConvertOffsetCurv2d() );
223 ctx->GetBoolean ( "LinearExtrusionMode",aParameters->ConvertExtrusionSurf() );
224 ctx->GetBoolean ( "RevolutionMode", aParameters->ConvertRevolutionSurf() );
225 ctx->GetBoolean ( "SegmentSurfaceMode", aParameters->SegmentSurfaceMode() );
226 ctx->GetBoolean ( "ConvCurve3dMode", aParameters->ConvertCurve3d() );
227 ctx->GetBoolean ( "ConvCurve2dMode", aParameters->ConvertCurve2d() );
228 ctx->GetBoolean ( "BezierMode", aParameters->ConvertBezierSurf() );
229 //modes to convert elementary surfaces
230 ctx->GetBoolean ( "PlaneMode", aParameters->ConvertPlane() );
231 //ctx->GetBoolean ("ElementarySurfMode", aParameters->ConvertElementarySurf());
232 ctx->GetBoolean ( "ConicalSurfMode", aParameters->ConvertConicalSurf());
233 ctx->GetBoolean ( "CylindricalSurfMode", aParameters->ConvertCylindricalSurf());
234 ctx->GetBoolean ( "ToroidalSurfMode", aParameters->ConvertToroidalSurf());
235 ctx->GetBoolean ( "SphericalSurfMode", aParameters->ConvertSphericalSurf());
236
237 Handle(ShapeCustom_BSplineRestriction) LD =
238 new ShapeCustom_BSplineRestriction ( ModeSurf, ModeC3d, ModeC2d,
239 aTol3d, aTol2d, aCont3d, aCont2d,
240 aMaxDeg, aMaxSeg, ModeDeg, Rational, aParameters );
241 TopTools_DataMapOfShapeShape map;
242 TopoDS_Shape res = ShapeProcess_OperLibrary::ApplyModifier ( ctx->Result(), ctx, LD, map );
243 ctx->RecordModification ( map );
244 ctx->SetResult ( res );
245 return Standard_True;
246}
247
248
249//=======================================================================
250//function : torevol
251//purpose :
252//=======================================================================
253
254static Standard_Boolean torevol (const Handle(ShapeProcess_Context)& context)
255{
256 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast ( context );
257 if ( ctx.IsNull() ) return Standard_False;
258
259 Handle(ShapeCustom_ConvertToRevolution) CR =
260 new ShapeCustom_ConvertToRevolution();
261 TopTools_DataMapOfShapeShape map;
262 TopoDS_Shape res = ShapeProcess_OperLibrary::ApplyModifier ( ctx->Result(), ctx, CR, map );
263 ctx->RecordModification ( map );
264 ctx->SetResult ( res );
265 return Standard_True;
266}
267
268
269//=======================================================================
270//function : swepttoelem
271//purpose :
272//=======================================================================
273
274static Standard_Boolean swepttoelem (const Handle(ShapeProcess_Context)& context)
275{
276 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast ( context );
277 if ( ctx.IsNull() ) return Standard_False;
278
279 Handle(ShapeCustom_SweptToElementary) SE = new ShapeCustom_SweptToElementary();
280 TopTools_DataMapOfShapeShape map;
281 TopoDS_Shape res = ShapeProcess_OperLibrary::ApplyModifier ( ctx->Result(), ctx, SE, map );
282 ctx->RecordModification ( map );
283 ctx->SetResult ( res );
284 return Standard_True;
285}
286
287
288//=======================================================================
289//function : shapetobezier
290//purpose :
291//=======================================================================
292
293static Standard_Boolean shapetobezier (const Handle(ShapeProcess_Context)& context)
294{
295 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast ( context );
296 if ( ctx.IsNull() ) return Standard_False;
297
298 Standard_Boolean ModeC3d = ctx->BooleanVal ( "Curve3dMode", Standard_False );
299 Standard_Boolean ModeC2d = ctx->BooleanVal ( "Curve2dMode", Standard_False );
300 Standard_Boolean ModeSurf = ctx->BooleanVal ( "SurfaceMode", Standard_False );
301 Standard_Boolean ModeLine3d = ctx->BooleanVal ( "Line3dMode", Standard_True );
302 Standard_Boolean ModeCircle3d = ctx->BooleanVal ( "Circle3dMode", Standard_True );
303 Standard_Boolean ModeConic3d = ctx->BooleanVal ( "Conic3dMode", Standard_True );
304 Standard_Boolean SegmentMode = ctx->BooleanVal ( "SegmentSurfaceMode", Standard_True );
305 Standard_Boolean PlaneMode = ctx->BooleanVal ( "PlaneMode", Standard_True );
306 Standard_Boolean RevolutionMode = ctx->BooleanVal ( "RevolutionMode", Standard_True );
307 Standard_Boolean ExtrusionMode = ctx->BooleanVal ( "ExtrusionMode", Standard_True );
308 Standard_Boolean BSplineMode = ctx->BooleanVal ( "BSplineMode", Standard_True );
309
310 ShapeUpgrade_ShapeConvertToBezier SCB (ctx->Result());
311 SCB.SetSurfaceSegmentMode(SegmentMode);
312 SCB.SetSurfaceConversion (ModeSurf);
313 SCB.Set2dConversion (ModeC2d);
314 SCB.Set3dConversion (ModeC3d);
315 if(ModeC3d) {
316 SCB.Set3dLineConversion (ModeLine3d);
317 SCB.Set3dCircleConversion (ModeCircle3d);
318 SCB.Set3dConicConversion (ModeConic3d);
319 }
320 if(ModeSurf) {
321 SCB.SetPlaneMode(PlaneMode);
322 SCB.SetRevolutionMode(RevolutionMode);
323 SCB.SetExtrusionMode(ExtrusionMode);
324 SCB.SetBSplineMode(BSplineMode);
325 }
326
327 Standard_Real maxTol, minTol;
328 if ( ctx->GetReal ( "MaxTolerance", maxTol ) ) SCB.SetMaxTolerance(maxTol);
329 if ( ctx->GetReal ( "MinCurveLength", minTol ) ) SCB.SetMinTolerance(minTol);
330
331 Standard_Boolean EdgeMode;
332 if ( ctx->GetBoolean ( "EdgeMode", EdgeMode ) ) SCB.SetEdgeMode(EdgeMode);
333
334 if ( ! SCB.Perform() && SCB.Status (ShapeExtend_FAIL) ) {
335#ifdef DEB
336 cout<<"Shape::ShapeConvertToBezier failed"<<endl; // !!!!
337#endif
338 return Standard_False;
339 }
340
341 ctx->RecordModification ( SCB.GetContext() );
342 ctx->SetResult ( SCB.Result() );
343 return Standard_True;
344}
345
346
347//=======================================================================
348//function : converttobspline
349//purpose :
350//=======================================================================
351
352static Standard_Boolean converttobspline (const Handle(ShapeProcess_Context)& context)
353{
354 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast ( context );
355 if ( ctx.IsNull() ) return Standard_False;
356
357 Standard_Boolean extrMode = ctx->BooleanVal ( "LinearExtrusionMode", Standard_True );
358 Standard_Boolean revolMode = ctx->BooleanVal ( "RevolutionMode", Standard_True );
359 Standard_Boolean offsetMode = ctx->BooleanVal ( "OffsetMode", Standard_True );
360
361 Handle(ShapeCustom_ConvertToBSpline) CBspl = new ShapeCustom_ConvertToBSpline();
362 CBspl->SetExtrusionMode(extrMode);
363 CBspl->SetRevolutionMode(revolMode);
364 CBspl->SetOffsetMode(offsetMode);
365
366 TopTools_DataMapOfShapeShape map;
367 TopoDS_Shape res = ShapeProcess_OperLibrary::ApplyModifier ( ctx->Result(), ctx, CBspl, map );
368 ctx->RecordModification ( map );
369 ctx->SetResult ( res );
370 return Standard_True;
371}
372
373
374//=======================================================================
375//function : splitcontinuity
376//purpose : Split by Continuity
377//=======================================================================
378
379static Standard_Boolean splitcontinuity (const Handle(ShapeProcess_Context)& context)
380{
381 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast ( context );
382 if ( ctx.IsNull() ) return Standard_False;
383
384 Standard_Real aTol = ctx->RealVal ( "Tolerance3d", 1.e-7 );
385 Standard_Real aTol2D = ctx->RealVal ( "Tolerance2d", 1.e-9 );
386 GeomAbs_Shape aCrvCont = ctx->ContinuityVal ( "CurveContinuity", GeomAbs_C1 );
387 GeomAbs_Shape aSrfCont = ctx->ContinuityVal ( "SurfaceContinuity", GeomAbs_C1 );
388 GeomAbs_Shape aCrv2dCont = ctx->ContinuityVal ( "Curve2dContinuity", GeomAbs_C1 );
389 ShapeUpgrade_ShapeDivideContinuity tool (ctx->Result());
390 tool.SetBoundaryCriterion(aCrvCont);
391 tool.SetSurfaceCriterion(aSrfCont);
392 tool.SetPCurveCriterion(aCrv2dCont);
393 tool.SetTolerance(aTol);
394 tool.SetTolerance2d(aTol2D);
395
396 Standard_Real maxTol;
397 if ( ctx->GetReal ( "MaxTolerance", maxTol ) ) tool.SetMaxTolerance(maxTol);
398
399 if ( ! tool.Perform() && tool.Status (ShapeExtend_FAIL) ) {
400#ifdef DEB
401 cout<<"SplitContinuity failed"<<endl;
402#endif
403 return Standard_False;
404 }
405
406 ctx->RecordModification ( tool.GetContext() );
407 ctx->SetResult ( tool.Result() );
408 return Standard_True;
409}
410
411
412//=======================================================================
413//function : splitclosedfaces
414//purpose :
415//=======================================================================
416
417static Standard_Boolean splitclosedfaces (const Handle(ShapeProcess_Context)& context)
418{
419 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast ( context );
420 if ( ctx.IsNull() ) return Standard_False;
421
422 ShapeUpgrade_ShapeDivideClosed tool ( ctx->Result() );
423
424 Standard_Real closeTol;
425 if ( ctx->GetReal ( "CloseTolerance", closeTol ) ) tool.SetPrecision(closeTol);
426
427 Standard_Real maxTol;
428 if ( ctx->GetReal ( "MaxTolerance", maxTol ) ) tool.SetMaxTolerance(maxTol);
429
430 Standard_Integer num = ctx->IntegerVal ( "NbSplitPoints", 1 );
431 Standard_Boolean hasSeg = Standard_True;
432 ctx->GetBoolean ( "SegmentSurfaceMode", hasSeg);
433
434 tool.SetNbSplitPoints(num);
435 tool.SetSurfaceSegmentMode(hasSeg);
436 if ( ! tool.Perform() && tool.Status (ShapeExtend_FAIL) ) {
437#ifdef DEB
438 cout<<"Splitting of closed faces failed"<<endl;
439#endif
440 return Standard_False;
441 }
442
443 ctx->RecordModification ( tool.GetContext() );
444 ctx->SetResult ( tool.Result() );
445 return Standard_True;
446}
447
448
449//=======================================================================
450//function : fixfacesize
451//purpose :
452//=======================================================================
453
454static Standard_Boolean fixfacesize (const Handle(ShapeProcess_Context)& context)
455{
456 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast ( context );
457 if ( ctx.IsNull() ) return Standard_False;
458
459 Handle(ShapeBuild_ReShape) reshape = new ShapeBuild_ReShape;
460 ShapeFix_FixSmallFace FSC;
461 FSC.SetContext(reshape);
462 FSC.Init(ctx->Result());
463
464 Standard_Real aTol;
465 if ( ctx->GetReal ( "Tolerance", aTol ) ) FSC.SetPrecision (aTol);
466
467 FSC.Perform();
468 TopoDS_Shape newsh = FSC.Shape();
469
470 if ( newsh != ctx->Result() ) {
471 ctx->RecordModification ( reshape );
472 ctx->SetResult ( newsh );
473 }
474
475 return Standard_True;
476}
477
478
479//=======================================================================
480//function : fixwgaps
481//purpose :
482//=======================================================================
483
484static Standard_Boolean fixwgaps (const Handle(ShapeProcess_Context)& context)
485{
486 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast ( context );
487 if ( ctx.IsNull() ) return Standard_False;
488
489 Standard_Real aTol3d = ctx->RealVal ( "Tolerance3d", Precision::Confusion() );
490
491 Handle(ShapeBuild_ReShape) reshape = new ShapeBuild_ReShape;
492 Handle(ShapeFix_Wireframe) sfwf = new ShapeFix_Wireframe(ctx->Result());
493 sfwf->SetContext(reshape);
494 sfwf->SetPrecision(aTol3d);
495 sfwf->FixWireGaps();
496 TopoDS_Shape result = sfwf->Shape();
497
498 if ( result != ctx->Result() ) {
499 ctx->RecordModification ( reshape );
500 ctx->SetResult ( result );
501 }
502 return Standard_True;
503}
504
505/*
506//=======================================================================
507//function :
508//purpose :
509//=======================================================================
510
511static Standard_Boolean dropsmalledges (const Handle(ShapeProcess_Context)& context)
512{
513 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast ( context );
514 if ( ctx.IsNull() ) return Standard_False;
515
516 //Handle(ShapeBuild_ReShape) ctx = new ShapeBuild_ReShape;
517 Handle(MoniFrame_Element) elem = astep->Operand();
518 TopoDS_Shape Shape = MoniShape::Shape(elem);
519 Standard_Real aTol3d = Precision::Confusion();
520 Handle(MoniFrame_TypedValue) ptol3d = aproc->StackParam("Tolerance3d",Standard_True);
521 if (ptol3d->IsSetValue()) aTol3d = ptol3d->RealValue();
522 Handle(ShapeBuild_ReShape) context;
523 TopoDS_Shape result = ShapeFix::RemoveSmallEdges(Shape,aTol3d,context);
524 if (result == Shape) astep->AddTouched (aproc->Infos(),MoniShape::Element(Shape));
525 else
526 MoniShapeSW::UpdateFromReShape (aproc->Infos(), astep, Shape, context, TopAbs_FACE);
527 return 0;
528}
529*/
530
531
532//=======================================================================
533//function : mergesmalledges
534//purpose :
535//=======================================================================
536
537static Standard_Boolean mergesmalledges (const Handle(ShapeProcess_Context)& context)
538{
539 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast ( context );
540 if ( ctx.IsNull() ) return Standard_False;
541
542 Standard_Real aTol3d = ctx->RealVal ( "Tolerance3d", Precision::Confusion() );
543
544 Handle(ShapeBuild_ReShape) reshape = new ShapeBuild_ReShape;
545 ShapeFix_Wireframe ShapeFixWireframe(ctx->Result());
546 ShapeFixWireframe.SetContext(reshape);
547 ShapeFixWireframe.SetPrecision(aTol3d);
548
549 if ( ShapeFixWireframe.FixSmallEdges() ) {
550 ctx->RecordModification ( reshape );
551 }
552 return Standard_True;
553}
554
555
556//=======================================================================
557//function : fixshape
558//purpose :
559//=======================================================================
560
561static Standard_Boolean fixshape (const Handle(ShapeProcess_Context)& context)
562{
563 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast ( context );
564 if ( ctx.IsNull() ) return Standard_False;
565
566 // activate message mechanism if it is supported by context
567 Handle(ShapeExtend_MsgRegistrator) msg;
568 if ( ! ctx->Messages().IsNull() ) msg = new ShapeExtend_MsgRegistrator;
569
570 Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
571 sfs->SetMsgRegistrator ( msg );
572 Handle(ShapeFix_Face) sff = Handle(ShapeFix_Face)::DownCast(sfs->FixFaceTool());
573 Handle(ShapeFix_Wire) sfw = Handle(ShapeFix_Wire)::DownCast(sfs->FixWireTool());
574
575 sfs->SetPrecision ( ctx->RealVal ( "Tolerance3d", Precision::Confusion() ) );
576 sfs->SetMinTolerance ( ctx->RealVal ( "MinTolerance3d", Precision::Confusion() ) );
577 sfs->SetMaxTolerance ( ctx->RealVal ( "MaxTolerance3d", Precision::Confusion() ) );
578
579 sfs->FixFreeShellMode() = ctx->IntegerVal ( "FixFreeShellMode", -1 );
580 sfs->FixFreeFaceMode() = ctx->IntegerVal ( "FixFreeFaceMode", -1 );
581 sfs->FixFreeWireMode() = ctx->IntegerVal ( "FixFreeWireMode", -1 );
582 sfs->FixSameParameterMode() = ctx->IntegerVal ( "FixSameParameterMode", -1 );
583 sfs->FixSolidMode() = ctx->IntegerVal ( "FixSolidMode", -1 );
584 sfs->FixVertexPositionMode() = ctx->IntegerVal ( "FixVertexPositionMode", 0 );
585
586 sfs->FixSolidTool()->FixShellMode() = ctx->IntegerVal ( "FixShellMode", -1 );
587 sfs->FixSolidTool()->CreateOpenSolidMode() = ctx->IntegerVal ( "CreateOpenSolidMode", 1 );
588
589 sfs->FixShellTool()->FixFaceMode() = ctx->IntegerVal ( "FixFaceMode", -1 );
590
591 //parameters for ShapeFix_Face
592 sff->FixWireMode() = ctx->IntegerVal ( "FixWireMode", -1 );
593 sff->FixOrientationMode() = ctx->IntegerVal ( "FixOrientationMode", -1 );
594 sff->FixAddNaturalBoundMode() = ctx->IntegerVal ( "FixAddNaturalBoundMode", -1 );
595 sff->FixMissingSeamMode() = ctx->IntegerVal ( "FixMissingSeamMode", -1 );
596 sff->FixSmallAreaWireMode() = ctx->IntegerVal ( "FixSmallAreaWireMode", -1 );
597 sff->FixIntersectingWiresMode() = ctx->IntegerVal ( "FixIntersectingWiresMode", -1 );
598 sff->FixLoopWiresMode() = ctx->IntegerVal ( "FixLoopWiresMode", -1 );
599 sff->FixSplitFaceMode() = ctx->IntegerVal ( "FixSplitFaceMode", -1 );
600
601 //parameters for ShapeFix_Wire
602 sfw->ModifyTopologyMode() = ctx->BooleanVal ( "ModifyTopologyMode", Standard_False );
603 sfw->ModifyGeometryMode() = ctx->BooleanVal ( "ModifyGeometryMode", Standard_True );
604 sfw->ClosedWireMode() = ctx->BooleanVal ( "ClosedWireMode", Standard_True );
605 sfw->PreferencePCurveMode() = ctx->BooleanVal ( "PreferencePCurveMode", Standard_True );
606 sfw->FixReorderMode() = ctx->IntegerVal ( "FixReorderMode", -1 );
607 sfw->FixSmallMode() = ctx->IntegerVal ( "FixSmallMode", -1 );
608 sfw->FixConnectedMode() = ctx->IntegerVal ( "FixConnectedMode", -1 );
609 sfw->FixEdgeCurvesMode() = ctx->IntegerVal ( "FixEdgeCurvesMode", -1 );
610 sfw->FixDegeneratedMode() = ctx->IntegerVal ( "FixDegeneratedMode", -1 );
611 sfw->FixLackingMode() = ctx->IntegerVal ( "FixLackingMode", -1 );
612 sfw->FixSelfIntersectionMode() = ctx->IntegerVal ( "FixSelfIntersectionMode", -1 );
613 sfw->ModifyRemoveLoopMode() = ctx->IntegerVal ( "RemoveLoopMode", -1);
614 sfw->FixReversed2dMode() = ctx->IntegerVal ( "FixReversed2dMode", -1 );
615 sfw->FixRemovePCurveMode() = ctx->IntegerVal ( "FixRemovePCurveMode", -1 );
616 sfw->FixRemoveCurve3dMode() = ctx->IntegerVal ( "FixRemoveCurve3dMode", -1 );
617 sfw->FixAddPCurveMode() = ctx->IntegerVal ( "FixAddPCurveMode", -1 );
618 sfw->FixAddCurve3dMode() = ctx->IntegerVal ( "FixAddCurve3dMode", -1 );
619 sfw->FixShiftedMode() = ctx->IntegerVal ( "FixShiftedMode", -1 );
620 sfw->FixSeamMode() = ctx->IntegerVal ( "FixSeamMode", -1 );
621 sfw->FixSameParameterMode() = ctx->IntegerVal ( "FixEdgeSameParameterMode", -1 );
622 sfw->FixNotchedEdgesMode() = ctx->IntegerVal ( "FixNotchedEdgesMode", -1 );
623 sfw->FixSelfIntersectingEdgeMode() = ctx->IntegerVal ( "FixSelfIntersectingEdgeMode", -1 );
624 sfw->FixIntersectingEdgesMode() = ctx->IntegerVal ( "FixIntersectingEdgesMode", -1 );
625 sfw->FixNonAdjacentIntersectingEdgesMode() = ctx->IntegerVal ( "FixNonAdjacentIntersectingEdgesMode", -1 );
626
627 sfs->Init(ctx->Result());
b485ee79
KD
628 sfs->Perform(ctx->Progress());
629
630 if ( !ctx->Progress().IsNull() && ctx->Progress()->UserBreak() )
631 return Standard_False;
632
7fd59977 633 TopoDS_Shape result = sfs->Shape();
634 if ( result != ctx->Result() ) {
635 ctx->RecordModification ( sfs->Context(), msg );
636 ctx->SetResult ( result );
637 }
638 return Standard_True;
639}
640
641
642//=======================================================================
643//function : spltclosededges
644//purpose :
645//=======================================================================
646
647static Standard_Boolean spltclosededges (const Handle(ShapeProcess_Context)& context)
648{
649 Handle(ShapeProcess_ShapeContext) ctx =
650 Handle(ShapeProcess_ShapeContext)::DownCast ( context );
651 if ( ctx.IsNull() ) return Standard_False;
652
653 Standard_Integer nbSplits = ctx->IntegerVal ( "NbSplitPoints", 1 );
654
655 ShapeUpgrade_ShapeDivideClosedEdges tool (ctx->Result());
656 tool.SetNbSplitPoints(nbSplits);
657
658 if ( ! tool.Perform() && tool.Status (ShapeExtend_FAIL) ) {
659#ifdef DEB
660 cout<<"Splitting of closed edges failed"<<endl;
661#endif
662 return Standard_False;
663 }
664
665 ctx->RecordModification ( tool.GetContext() );
666 ctx->SetResult ( tool.Result() );
667 return Standard_True;
668}
669
670
671//=======================================================================
672//function : splitcommonvertex
673//purpose : Two wires have common vertex - this case is valid in BRep model
674// and isn't valid in STEP => before writing into STEP it is necessary
675// to split this vertex (each wire must has one vertex)
676//=======================================================================
677static Standard_Boolean splitcommonvertex (const Handle(ShapeProcess_Context)& context)
678{
679 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast ( context );
680 if ( ctx.IsNull() ) return Standard_False;
681
682 Handle(ShapeBuild_ReShape) reshape = new ShapeBuild_ReShape;
683 ShapeFix_SplitCommonVertex SCV;
684 SCV.SetContext(reshape);
685 SCV.Init(ctx->Result());
686
687 SCV.Perform();
688 TopoDS_Shape newsh = SCV.Shape();
689
690 if ( newsh != ctx->Result() ) {
691 ctx->RecordModification ( reshape );
692 ctx->SetResult ( newsh );
693 }
694
695 return Standard_True;
696}
697
698
699//=======================================================================
700//function : Init
701//purpose : Register standard operators
702//=======================================================================
703
704void ShapeProcess_OperLibrary::Init ()
705{
706 static Standard_Boolean done = Standard_False;
707 if ( done ) return;
708 done = Standard_True;
709
710 ShapeExtend::Init();
711
712 // load message file for Shape Processing
713 Message_MsgFile::LoadFromEnv ("CSF_SHMessage", "SHAPE");
714
715 ShapeProcess::RegisterOperator ( "DirectFaces", new ShapeProcess_UOperator ( directfaces ) );
716 ShapeProcess::RegisterOperator ( "SameParameter", new ShapeProcess_UOperator ( sameparam ) );
717 ShapeProcess::RegisterOperator ( "SetTolerance", new ShapeProcess_UOperator ( settol ) );
718 ShapeProcess::RegisterOperator ( "SplitAngle", new ShapeProcess_UOperator ( splitangle ) );
719 ShapeProcess::RegisterOperator ( "BSplineRestriction", new ShapeProcess_UOperator ( bsplinerestriction ) );
720 ShapeProcess::RegisterOperator ( "ElementaryToRevolution",new ShapeProcess_UOperator ( torevol ) );
721 ShapeProcess::RegisterOperator ( "SweptToElementary", new ShapeProcess_UOperator ( swepttoelem ) );
722 ShapeProcess::RegisterOperator ( "SurfaceToBSpline", new ShapeProcess_UOperator ( converttobspline ) );
723 ShapeProcess::RegisterOperator ( "ToBezier", new ShapeProcess_UOperator ( shapetobezier ) );
724 ShapeProcess::RegisterOperator ( "SplitContinuity", new ShapeProcess_UOperator ( splitcontinuity ) );
725 ShapeProcess::RegisterOperator ( "SplitClosedFaces", new ShapeProcess_UOperator ( splitclosedfaces ) );
726 ShapeProcess::RegisterOperator ( "FixWireGaps", new ShapeProcess_UOperator ( fixwgaps ) );
727 ShapeProcess::RegisterOperator ( "FixFaceSize", new ShapeProcess_UOperator ( fixfacesize ) );
728 ShapeProcess::RegisterOperator ( "DropSmallEdges", new ShapeProcess_UOperator ( mergesmalledges ) );
729 ShapeProcess::RegisterOperator ( "FixShape", new ShapeProcess_UOperator ( fixshape ) );
730 ShapeProcess::RegisterOperator ( "SplitClosedEdges", new ShapeProcess_UOperator ( spltclosededges ) );
731 ShapeProcess::RegisterOperator ( "SplitCommonVertex", new ShapeProcess_UOperator ( splitcommonvertex ) );
732}