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