1 // File: ShapeProcess_OperLibrary.cxx
2 // Created: Thu Aug 31 11:34:26 2000
3 // Author: Andrey BETENEV
4 // <abv@nnov.matra-dtv.fr>
6 #include <ShapeProcess_OperLibrary.ixx>
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>
15 #include <Message_MsgFile.hxx>
16 #include <Message_ProgressIndicator.hxx>
18 #include <ShapeExtend_MsgRegistrator.hxx>
19 #include <ShapeProcess.hxx>
20 #include <ShapeProcess_UOperator.hxx>
21 #include <ShapeProcess_ShapeContext.hxx>
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>
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>
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>
50 //=======================================================================
51 //function : ApplyModifier
52 //purpose : Applies BRepTools_Modification to a shape,
53 // taking into account sharing of components of compounds
54 //=======================================================================
56 TopoDS_Shape ShapeProcess_OperLibrary::ApplyModifier (const TopoDS_Shape &S,
57 const Handle(ShapeProcess_ShapeContext)& context,
58 const Handle(BRepTools_Modification) &M,
59 TopTools_DataMapOfShapeShape &map)
61 // protect against INTERNAL/EXTERNAL shapes
62 TopoDS_Shape SF = S.Oriented(TopAbs_FORWARD);
64 // Process COMPOUNDs separately in order to handle sharing in assemblies
65 if ( SF.ShapeType() == TopAbs_COMPOUND ) {
66 Standard_Boolean locModified = Standard_False;
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 );
75 if(map.IsBound ( shape ))
76 res = map.Find ( shape ).Oriented ( shape.Orientation() );
79 res = ApplyModifier (shape, context, M, map );
80 map.Bind ( shape, res );
82 if ( ! res.IsSame ( shape ) ) locModified = Standard_True;
86 if ( ! locModified ) return S;
89 return C.Oriented ( S.Orientation() );
93 BRepTools_Modifier MD(SF,M);
94 context->RecordModification ( SF, MD );
95 return MD.ModifiedShape(SF).Oriented(S.Orientation());
99 //=======================================================================
100 //function : directfaces
102 //=======================================================================
104 static Standard_Boolean directfaces (const Handle(ShapeProcess_Context)& context)
106 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast ( context );
107 if ( ctx.IsNull() ) return Standard_False;
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 );
114 return Standard_True;
118 //=======================================================================
119 //function : sameparam
121 //=======================================================================
123 static Standard_Boolean sameparam (const Handle(ShapeProcess_Context)& context)
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;
135 //=======================================================================
138 //=======================================================================
140 static Standard_Boolean settol (const Handle(ShapeProcess_Context)& context)
142 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast ( context );
143 if ( ctx.IsNull() ) return Standard_False;
146 if ( ctx->IntegerVal ( "Mode", 0 ) >0 && ctx->GetReal ( "Value", val ) ) {
147 Standard_Real rat = ctx->RealVal ( "Ratio", 1. );
149 ShapeFix_ShapeTolerance SFST;
150 SFST.LimitTolerance (ctx->Result(), val/rat, val*rat);
154 BRepLib::UpdateTolerances (ctx->Result(),Standard_True);
157 if ( ctx->GetReal ("Regularity", reg) )
158 BRepLib::EncodeRegularity (ctx->Result(), reg);
160 // WARNING: no update of context yet!
161 return Standard_True;
165 //=======================================================================
166 //function : splitangle
168 //=======================================================================
170 static Standard_Boolean splitangle (const Handle(ShapeProcess_Context)& context)
172 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast ( context );
173 if ( ctx.IsNull() ) return Standard_False;
175 ShapeUpgrade_ShapeDivideAngle SDA ( ctx->RealVal ( "Angle", 2*M_PI ), ctx->Result() );
176 SDA.SetMaxTolerance ( ctx->RealVal ( "MaxTolerance", 1. ) );
178 if ( ! SDA.Perform() && SDA.Status (ShapeExtend_FAIL) ) {
180 cout<<"ShapeDivideAngle failed"<<endl;
182 return Standard_False;
185 ctx->RecordModification ( SDA.GetContext() );
186 ctx->SetResult ( SDA.Result() );
187 return Standard_True;
191 //=======================================================================
192 //function : bsplinerestriction
194 //=======================================================================
196 static Standard_Boolean bsplinerestriction (const Handle(ShapeProcess_Context)& context)
198 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast ( context );
199 if ( ctx.IsNull() ) return Standard_False;
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 );
205 Standard_Real aTol3d = ctx->RealVal ( "Tolerance3d", 0.01 );
206 Standard_Real aTol2d = ctx->RealVal ( "Tolerance2d", 1e-06 );
208 GeomAbs_Shape aCont3d = ctx->ContinuityVal ( "Continuity3d", GeomAbs_C1 );
209 GeomAbs_Shape aCont2d = ctx->ContinuityVal ( "Continuity2d", GeomAbs_C2 );
211 Standard_Integer aMaxDeg = ctx->IntegerVal ( "RequiredDegree", 9 );
212 Standard_Integer aMaxSeg = ctx->IntegerVal ( "RequiredNbSegments", 10000 );
214 Standard_Boolean ModeDeg = ctx->IntegerVal ( "PreferDegree", Standard_True );
215 Standard_Boolean Rational = ctx->IntegerVal ( "RationalToPolynomial", Standard_False );
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());
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;
249 //=======================================================================
252 //=======================================================================
254 static Standard_Boolean torevol (const Handle(ShapeProcess_Context)& context)
256 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast ( context );
257 if ( ctx.IsNull() ) return Standard_False;
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;
269 //=======================================================================
270 //function : swepttoelem
272 //=======================================================================
274 static Standard_Boolean swepttoelem (const Handle(ShapeProcess_Context)& context)
276 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast ( context );
277 if ( ctx.IsNull() ) return Standard_False;
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;
288 //=======================================================================
289 //function : shapetobezier
291 //=======================================================================
293 static Standard_Boolean shapetobezier (const Handle(ShapeProcess_Context)& context)
295 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast ( context );
296 if ( ctx.IsNull() ) return Standard_False;
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 );
310 ShapeUpgrade_ShapeConvertToBezier SCB (ctx->Result());
311 SCB.SetSurfaceSegmentMode(SegmentMode);
312 SCB.SetSurfaceConversion (ModeSurf);
313 SCB.Set2dConversion (ModeC2d);
314 SCB.Set3dConversion (ModeC3d);
316 SCB.Set3dLineConversion (ModeLine3d);
317 SCB.Set3dCircleConversion (ModeCircle3d);
318 SCB.Set3dConicConversion (ModeConic3d);
321 SCB.SetPlaneMode(PlaneMode);
322 SCB.SetRevolutionMode(RevolutionMode);
323 SCB.SetExtrusionMode(ExtrusionMode);
324 SCB.SetBSplineMode(BSplineMode);
327 Standard_Real maxTol, minTol;
328 if ( ctx->GetReal ( "MaxTolerance", maxTol ) ) SCB.SetMaxTolerance(maxTol);
329 if ( ctx->GetReal ( "MinCurveLength", minTol ) ) SCB.SetMinTolerance(minTol);
331 Standard_Boolean EdgeMode;
332 if ( ctx->GetBoolean ( "EdgeMode", EdgeMode ) ) SCB.SetEdgeMode(EdgeMode);
334 if ( ! SCB.Perform() && SCB.Status (ShapeExtend_FAIL) ) {
336 cout<<"Shape::ShapeConvertToBezier failed"<<endl; // !!!!
338 return Standard_False;
341 ctx->RecordModification ( SCB.GetContext() );
342 ctx->SetResult ( SCB.Result() );
343 return Standard_True;
347 //=======================================================================
348 //function : converttobspline
350 //=======================================================================
352 static Standard_Boolean converttobspline (const Handle(ShapeProcess_Context)& context)
354 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast ( context );
355 if ( ctx.IsNull() ) return Standard_False;
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 );
361 Handle(ShapeCustom_ConvertToBSpline) CBspl = new ShapeCustom_ConvertToBSpline();
362 CBspl->SetExtrusionMode(extrMode);
363 CBspl->SetRevolutionMode(revolMode);
364 CBspl->SetOffsetMode(offsetMode);
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;
374 //=======================================================================
375 //function : splitcontinuity
376 //purpose : Split by Continuity
377 //=======================================================================
379 static Standard_Boolean splitcontinuity (const Handle(ShapeProcess_Context)& context)
381 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast ( context );
382 if ( ctx.IsNull() ) return Standard_False;
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);
396 Standard_Real maxTol;
397 if ( ctx->GetReal ( "MaxTolerance", maxTol ) ) tool.SetMaxTolerance(maxTol);
399 if ( ! tool.Perform() && tool.Status (ShapeExtend_FAIL) ) {
401 cout<<"SplitContinuity failed"<<endl;
403 return Standard_False;
406 ctx->RecordModification ( tool.GetContext() );
407 ctx->SetResult ( tool.Result() );
408 return Standard_True;
412 //=======================================================================
413 //function : splitclosedfaces
415 //=======================================================================
417 static Standard_Boolean splitclosedfaces (const Handle(ShapeProcess_Context)& context)
419 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast ( context );
420 if ( ctx.IsNull() ) return Standard_False;
422 ShapeUpgrade_ShapeDivideClosed tool ( ctx->Result() );
424 Standard_Real closeTol;
425 if ( ctx->GetReal ( "CloseTolerance", closeTol ) ) tool.SetPrecision(closeTol);
427 Standard_Real maxTol;
428 if ( ctx->GetReal ( "MaxTolerance", maxTol ) ) tool.SetMaxTolerance(maxTol);
430 Standard_Integer num = ctx->IntegerVal ( "NbSplitPoints", 1 );
431 Standard_Boolean hasSeg = Standard_True;
432 ctx->GetBoolean ( "SegmentSurfaceMode", hasSeg);
434 tool.SetNbSplitPoints(num);
435 tool.SetSurfaceSegmentMode(hasSeg);
436 if ( ! tool.Perform() && tool.Status (ShapeExtend_FAIL) ) {
438 cout<<"Splitting of closed faces failed"<<endl;
440 return Standard_False;
443 ctx->RecordModification ( tool.GetContext() );
444 ctx->SetResult ( tool.Result() );
445 return Standard_True;
449 //=======================================================================
450 //function : fixfacesize
452 //=======================================================================
454 static Standard_Boolean fixfacesize (const Handle(ShapeProcess_Context)& context)
456 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast ( context );
457 if ( ctx.IsNull() ) return Standard_False;
459 Handle(ShapeBuild_ReShape) reshape = new ShapeBuild_ReShape;
460 ShapeFix_FixSmallFace FSC;
461 FSC.SetContext(reshape);
462 FSC.Init(ctx->Result());
465 if ( ctx->GetReal ( "Tolerance", aTol ) ) FSC.SetPrecision (aTol);
468 TopoDS_Shape newsh = FSC.Shape();
470 if ( newsh != ctx->Result() ) {
471 ctx->RecordModification ( reshape );
472 ctx->SetResult ( newsh );
475 return Standard_True;
479 //=======================================================================
480 //function : fixwgaps
482 //=======================================================================
484 static Standard_Boolean fixwgaps (const Handle(ShapeProcess_Context)& context)
486 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast ( context );
487 if ( ctx.IsNull() ) return Standard_False;
489 Standard_Real aTol3d = ctx->RealVal ( "Tolerance3d", Precision::Confusion() );
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);
496 TopoDS_Shape result = sfwf->Shape();
498 if ( result != ctx->Result() ) {
499 ctx->RecordModification ( reshape );
500 ctx->SetResult ( result );
502 return Standard_True;
506 //=======================================================================
509 //=======================================================================
511 static Standard_Boolean dropsmalledges (const Handle(ShapeProcess_Context)& context)
513 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast ( context );
514 if ( ctx.IsNull() ) return Standard_False;
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));
526 MoniShapeSW::UpdateFromReShape (aproc->Infos(), astep, Shape, context, TopAbs_FACE);
532 //=======================================================================
533 //function : mergesmalledges
535 //=======================================================================
537 static Standard_Boolean mergesmalledges (const Handle(ShapeProcess_Context)& context)
539 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast ( context );
540 if ( ctx.IsNull() ) return Standard_False;
542 Standard_Real aTol3d = ctx->RealVal ( "Tolerance3d", Precision::Confusion() );
544 Handle(ShapeBuild_ReShape) reshape = new ShapeBuild_ReShape;
545 ShapeFix_Wireframe ShapeFixWireframe(ctx->Result());
546 ShapeFixWireframe.SetContext(reshape);
547 ShapeFixWireframe.SetPrecision(aTol3d);
549 if ( ShapeFixWireframe.FixSmallEdges() ) {
550 ctx->RecordModification ( reshape );
552 return Standard_True;
556 //=======================================================================
557 //function : fixshape
559 //=======================================================================
561 static Standard_Boolean fixshape (const Handle(ShapeProcess_Context)& context)
563 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast ( context );
564 if ( ctx.IsNull() ) return Standard_False;
566 // activate message mechanism if it is supported by context
567 Handle(ShapeExtend_MsgRegistrator) msg;
568 if ( ! ctx->Messages().IsNull() ) msg = new ShapeExtend_MsgRegistrator;
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());
575 sfs->SetPrecision ( ctx->RealVal ( "Tolerance3d", Precision::Confusion() ) );
576 sfs->SetMinTolerance ( ctx->RealVal ( "MinTolerance3d", Precision::Confusion() ) );
577 sfs->SetMaxTolerance ( ctx->RealVal ( "MaxTolerance3d", Precision::Confusion() ) );
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 );
586 sfs->FixSolidTool()->FixShellMode() = ctx->IntegerVal ( "FixShellMode", -1 );
587 sfs->FixSolidTool()->CreateOpenSolidMode() = ctx->IntegerVal ( "CreateOpenSolidMode", 1 );
589 sfs->FixShellTool()->FixFaceMode() = ctx->IntegerVal ( "FixFaceMode", -1 );
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 );
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 );
627 sfs->Init(ctx->Result());
628 sfs->Perform(ctx->Progress());
630 if ( !ctx->Progress().IsNull() && ctx->Progress()->UserBreak() )
631 return Standard_False;
633 TopoDS_Shape result = sfs->Shape();
634 if ( result != ctx->Result() ) {
635 ctx->RecordModification ( sfs->Context(), msg );
636 ctx->SetResult ( result );
638 return Standard_True;
642 //=======================================================================
643 //function : spltclosededges
645 //=======================================================================
647 static Standard_Boolean spltclosededges (const Handle(ShapeProcess_Context)& context)
649 Handle(ShapeProcess_ShapeContext) ctx =
650 Handle(ShapeProcess_ShapeContext)::DownCast ( context );
651 if ( ctx.IsNull() ) return Standard_False;
653 Standard_Integer nbSplits = ctx->IntegerVal ( "NbSplitPoints", 1 );
655 ShapeUpgrade_ShapeDivideClosedEdges tool (ctx->Result());
656 tool.SetNbSplitPoints(nbSplits);
658 if ( ! tool.Perform() && tool.Status (ShapeExtend_FAIL) ) {
660 cout<<"Splitting of closed edges failed"<<endl;
662 return Standard_False;
665 ctx->RecordModification ( tool.GetContext() );
666 ctx->SetResult ( tool.Result() );
667 return Standard_True;
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 //=======================================================================
677 static Standard_Boolean splitcommonvertex (const Handle(ShapeProcess_Context)& context)
679 Handle(ShapeProcess_ShapeContext) ctx = Handle(ShapeProcess_ShapeContext)::DownCast ( context );
680 if ( ctx.IsNull() ) return Standard_False;
682 Handle(ShapeBuild_ReShape) reshape = new ShapeBuild_ReShape;
683 ShapeFix_SplitCommonVertex SCV;
684 SCV.SetContext(reshape);
685 SCV.Init(ctx->Result());
688 TopoDS_Shape newsh = SCV.Shape();
690 if ( newsh != ctx->Result() ) {
691 ctx->RecordModification ( reshape );
692 ctx->SetResult ( newsh );
695 return Standard_True;
699 //=======================================================================
701 //purpose : Register standard operators
702 //=======================================================================
704 void ShapeProcess_OperLibrary::Init ()
706 static Standard_Boolean done = Standard_False;
708 done = Standard_True;
712 // load message file for Shape Processing
713 Message_MsgFile::LoadFromEnv ("CSF_SHMessage", "SHAPE");
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 ) );