// File: BlockFix.cxx // Created: Tue Dec 7 11:59:05 2004 // Author: Pavel DURANDIN // Copyright: Open CASCADE SA 2004 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //======================================================================= //function : FixResult //purpose : auxilary //======================================================================= static void FixResult(const TopoDS_Shape& result, Handle(ShapeBuild_ReShape)& Context, const Standard_Real Tol) { for (TopExp_Explorer ex_f(result,TopAbs_FACE); ex_f.More(); ex_f.Next()) { TopoDS_Shape aShape = Context->Apply(ex_f.Current().Oriented(TopAbs_FORWARD)); // face coud not be dropped or splitted on this step TopoDS_Face aFace = TopoDS::Face(aShape); TopLoc_Location L; Handle(Geom_Surface) Surf = BRep_Tool::Surface(aFace,L); if (Surf->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) || Surf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) { Standard_Integer nbWires = 0; for (TopExp_Explorer ex_w(aFace,TopAbs_WIRE); ex_w.More(); ex_w.Next()) { nbWires++; Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire(TopoDS::Wire(ex_w.Current()), aFace, Precision::Confusion()); sfw->FixReorder(); if(sfw->StatusReorder ( ShapeExtend_FAIL )) continue; sfw->SetPrecision(2.*Tol); sfw->FixShifted(); Standard_Boolean isDone = sfw->LastFixStatus ( ShapeExtend_DONE ); isDone |= sfw->FixDegenerated(); // remove degenerated edges from not degenerated points ShapeAnalysis_Edge sae; Handle(ShapeExtend_WireData) sewd = sfw->WireData(); Standard_Integer i; for( i = 1; i<=sewd->NbEdges();i++) { TopoDS_Edge E = sewd->Edge(i); if(BRep_Tool::Degenerated(E)&&!sae.HasPCurve(E,aFace)) { sewd->Remove(i); isDone = Standard_True; i--; } } isDone |= sfw->FixLacking(); // remove neighbour seam edges if(isDone) { for( i = 1; iNbEdges();i++) { if(sewd->IsSeam(i) && sewd->IsSeam(i+1)) { isDone = Standard_True; sewd->Remove(i); sewd->Remove(i); i--; } } if(sewd->IsSeam(1) && sewd->IsSeam(sewd->NbEdges())) { sewd->Remove(1); sewd->Remove(sewd->NbEdges()); } } if(isDone) { TopoDS_Wire ResWire = sfw->Wire(); Context->Replace(ex_w.Current(), ResWire); }; } // Implement fix orientation in case of several wires if(nbWires > 1) { TopoDS_Face aFixedFace = TopoDS::Face(Context->Apply(aFace)); Handle(ShapeFix_Face) sff = new ShapeFix_Face(aFixedFace); if(sff->FixOrientation()) Context->Replace(aFixedFace,sff->Face()); } } } } //======================================================================= //function : ConvertToAnalytical //purpose : //======================================================================= TopoDS_Shape BlockFix::RotateSphereSpace (const TopoDS_Shape& S, const Standard_Real Tol) { // Create a modification description Handle(BlockFix_SphereSpaceModifier) SR = new BlockFix_SphereSpaceModifier; SR->SetTolerance(Tol); TopTools_DataMapOfShapeShape context; BRepTools_Modifier MD; TopoDS_Shape result = ShapeCustom::ApplyModifier ( S, SR, context,MD ); Handle(ShapeBuild_ReShape) RS = new ShapeBuild_ReShape; FixResult(result,RS,Tol); result = RS->Apply(result); ShapeFix_Edge sfe; for(TopExp_Explorer exp(result,TopAbs_EDGE); exp.More(); exp.Next()) { TopoDS_Edge E = TopoDS::Edge(exp.Current()); sfe.FixVertexTolerance (E); } ShapeFix::SameParameter(result,Standard_False); return result; } //======================================================================= //function : FixRanges //purpose : //======================================================================= TopoDS_Shape BlockFix::FixRanges (const TopoDS_Shape& S, const Standard_Real Tol) { // Create a modification description Handle(BlockFix_PeriodicSurfaceModifier) SR = new BlockFix_PeriodicSurfaceModifier; SR->SetTolerance(Tol); TopTools_DataMapOfShapeShape context; BRepTools_Modifier MD; TopoDS_Shape result = ShapeCustom::ApplyModifier ( S, SR, context,MD ); Handle(ShapeBuild_ReShape) RS = new ShapeBuild_ReShape; FixResult(result,RS,Tol); result = RS->Apply(result); ShapeFix_Edge sfe; for(TopExp_Explorer exp(result,TopAbs_EDGE); exp.More(); exp.Next()) { TopoDS_Edge E = TopoDS::Edge(exp.Current()); sfe.FixVertexTolerance (E); } ShapeFix::SameParameter(result,Standard_False); return result; }