From: razmyslovich Date: Wed, 20 Aug 2014 13:17:53 +0000 (+0200) Subject: 0025174: Provide ShapeCustom and BRepModifier with ProgressIndicator and ReShape... X-Git-Tag: V6_8_0~18 X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=commitdiff_plain;h=b350f6ee1e2644dd2d1b1fb0c2eb65f55fd9fc40 0025174: Provide ShapeCustom and BRepModifier with ProgressIndicator and ReShape features Conflicts: src/TNaming/TNaming_Name.cxx --- diff --git a/src/BOPTools/BOPTools_AlgoTools_1.cxx b/src/BOPTools/BOPTools_AlgoTools_1.cxx index ade9bc9d9d..01cc7b7989 100644 --- a/src/BOPTools/BOPTools_AlgoTools_1.cxx +++ b/src/BOPTools/BOPTools_AlgoTools_1.cxx @@ -352,7 +352,7 @@ class BOPTools_CheckCurveOnSurface : // theFVal = -1.0*aP1.SquareDistance(aP2); } - catch(...) { + catch(Standard_Failure) { return Standard_False; } // @@ -382,7 +382,7 @@ class BOPTools_CheckCurveOnSurface : theGrad(1) = -2.0*aP1.XYZ().Dot(aP2.XYZ()); } - catch(...) { + catch(Standard_Failure) { return Standard_False; } @@ -1260,7 +1260,7 @@ Standard_Boolean BOPTools_AlgoTools:: theMaxDist = sqrt(Abs(theMaxDist)); } - catch (...) { + catch (Standard_Failure) { return Standard_False; } // diff --git a/src/BRepFill/BRepFill_OffsetWire.cxx b/src/BRepFill/BRepFill_OffsetWire.cxx index 80c29e589b..668066f6db 100644 --- a/src/BRepFill/BRepFill_OffsetWire.cxx +++ b/src/BRepFill/BRepFill_OffsetWire.cxx @@ -644,7 +644,7 @@ void BRepFill_OffsetWire::Perform (const Standard_Real Offset, PerformWithBiLo(myWorkSpine,Offset,myBilo,myLink,myJoinType,Alt); } } - catch (...)//Every exception was caught. + catch (Standard_Failure)//Every exception was caught. { myShape.Nullify(); myIsDone = Standard_False; diff --git a/src/BRepOffsetAPI/BRepOffsetAPI_MakeOffset.cxx b/src/BRepOffsetAPI/BRepOffsetAPI_MakeOffset.cxx index 7520b7bc05..1889738d79 100644 --- a/src/BRepOffsetAPI/BRepOffsetAPI_MakeOffset.cxx +++ b/src/BRepOffsetAPI/BRepOffsetAPI_MakeOffset.cxx @@ -333,7 +333,7 @@ void BRepOffsetAPI_MakeOffset::Perform(const Standard_Real Offset, else Done(); } - catch(...) //Every exception was caught. + catch(Standard_Failure) //Every exception was caught. { #ifdef OCCT_DEBUG cout<<"An exception was caught in BRepOffsetAPI_MakeOffset::Perform : "; diff --git a/src/BRepTools/BRepTools_Modifier.cdl b/src/BRepTools/BRepTools_Modifier.cdl index 2420f73700..d2896b7523 100644 --- a/src/BRepTools/BRepTools_Modifier.cdl +++ b/src/BRepTools/BRepTools_Modifier.cdl @@ -20,7 +20,8 @@ class Modifier from BRepTools uses Shape from TopoDS, Modification from BRepTools, - DataMapOfShapeShape from TopTools + DataMapOfShapeShape from TopTools, + ProgressIndicator from Message raises NullObject from Standard, NoSuchObject from Standard @@ -47,7 +48,7 @@ is ---Purpose: Initializes the modifier with the shape . - Perform(me: in out; M: Modification from BRepTools) + Perform(me: in out; M: Modification from BRepTools; aProgress: ProgressIndicator from Message = NULL) ---Purpose: Performs the modifications described by . raises NullObject from Standard -- if the modifier has not been initialized with a shape. @@ -61,7 +62,7 @@ is ---C++: inline returns Boolean from Standard is static; - + ModifiedShape(me; S: Shape from TopoDS) returns Shape from TopoDS @@ -82,7 +83,7 @@ is is static private; - Rebuild(me: in out; S: Shape from TopoDS; M: Modification from BRepTools) + Rebuild(me: in out; S: Shape from TopoDS; M: Modification from BRepTools; aProgress: ProgressIndicator from Message = NULL) returns Boolean from Standard is static private; diff --git a/src/BRepTools/BRepTools_Modifier.cxx b/src/BRepTools/BRepTools_Modifier.cxx index 3c2e66791d..0b47f43dfb 100644 --- a/src/BRepTools/BRepTools_Modifier.cxx +++ b/src/BRepTools/BRepTools_Modifier.cxx @@ -51,6 +51,7 @@ #include #include #include +#include @@ -108,7 +109,7 @@ void BRepTools_Modifier::Init(const TopoDS_Shape& S) //purpose : //======================================================================= -void BRepTools_Modifier::Perform(const Handle(BRepTools_Modification)& M) +void BRepTools_Modifier::Perform(const Handle(BRepTools_Modification)& M, const Handle(Message_ProgressIndicator) & aProgress) { if (myShape.IsNull()) { Standard_NullObject::Raise(); @@ -132,7 +133,17 @@ void BRepTools_Modifier::Perform(const Handle(BRepTools_Modification)& M) } */ - Rebuild(myShape,M); + Message_ProgressSentry aPSentry(aProgress, "Converting Shape", 0, 2, 1); + + Rebuild(myShape, M, aProgress); + + if (!aPSentry.More()) + { + // The processing was broken + return; + } + + aPSentry.Next(); if (myShape.ShapeType() == TopAbs_FACE) { if (myShape.Orientation() == TopAbs_REVERSED) { @@ -166,8 +177,8 @@ void BRepTools_Modifier::Perform(const Handle(BRepTools_Modification)& M) if (S.ShapeType() == TopAbs_FACE && !S.IsSame(theIter.Value())) { Tr = BRep_Tool::Triangulation(TopoDS::Face(S),Loc); if (!Tr.IsNull()) { - RecomputeTriangles = Standard_True; - MaxDeflection = Max(MaxDeflection,Tr->Deflection()); + RecomputeTriangles = Standard_True; + MaxDeflection = Max(MaxDeflection,Tr->Deflection()); } } else */ if (S.ShapeType() == TopAbs_EDGE && !S.IsSame(theIter.Value())) { @@ -183,22 +194,22 @@ void BRepTools_Modifier::Perform(const Handle(BRepTools_Modification)& M) it.Initialize(theEFMap.FindFromKey(edg)); TopoDS_Face F1,F2; while (it.More() && F2.IsNull()) { - if (F1.IsNull()) { - F1 = TopoDS::Face(it.Value()); - } - else { - F2 = TopoDS::Face(it.Value()); - } - it.Next(); + if (F1.IsNull()) { + F1 = TopoDS::Face(it.Value()); + } + else { + F2 = TopoDS::Face(it.Value()); + } + it.Next(); } if (!F2.IsNull()) { - const TopoDS_Edge& newedg = TopoDS::Edge(myMap(edg)); - const TopoDS_Face& newf1 = TopoDS::Face(myMap(F1)); - const TopoDS_Face& newf2 = TopoDS::Face(myMap(F2)); - GeomAbs_Shape Newcont = M->Continuity(edg,F1,F2,newedg,newf1,newf2); - if (Newcont > GeomAbs_C0) { - B.Continuity(newedg,newf1,newf2,Newcont); - } + const TopoDS_Edge& newedg = TopoDS::Edge(myMap(edg)); + const TopoDS_Face& newf1 = TopoDS::Face(myMap(F1)); + const TopoDS_Face& newf2 = TopoDS::Face(myMap(F2)); + GeomAbs_Shape Newcont = M->Continuity(edg,F1,F2,newedg,newf1,newf2); + if (Newcont > GeomAbs_C0) { + B.Continuity(newedg,newf1,newf2,Newcont); + } } } theIter.Next(); @@ -236,7 +247,8 @@ void BRepTools_Modifier::Put(const TopoDS_Shape& S) Standard_Boolean BRepTools_Modifier::Rebuild (const TopoDS_Shape& S, - const Handle(BRepTools_Modification)& M) + const Handle(BRepTools_Modification)& M, + const Handle(Message_ProgressIndicator)& aProgress) { TopoDS_Shape& result = myMap(S); // if (!result.IsNull()) return ! S.IsEqual(result); @@ -325,10 +337,24 @@ Standard_Boolean BRepTools_Modifier::Rebuild TopoDS_Iterator it; - for (it.Initialize(S, Standard_False); it.More(); it.Next()) { - // always call Rebuild - Standard_Boolean subrebuilt = Rebuild(it.Value(),M); - rebuild = subrebuilt || rebuild ; + { + Standard_Integer aShapeCount = 0; + { + for (it.Initialize(S, Standard_False); it.More(); it.Next()) ++aShapeCount; + } + + Message_ProgressSentry aPSentry(aProgress, "Converting SubShapes", 0, aShapeCount, 1); + // + for (it.Initialize(S, Standard_False); it.More() && aPSentry.More(); it.Next(), aPSentry.Next()) { + // always call Rebuild + Standard_Boolean subrebuilt = Rebuild(it.Value(), M, aProgress); + rebuild = subrebuilt || rebuild ; + } + if (!aPSentry.More()) + { + // The processing was broken + return Standard_False; + } } // make an empty copy @@ -360,15 +386,14 @@ Standard_Boolean BRepTools_Modifier::Rebuild TopExp_Explorer ex(face.Oriented(fcor),TopAbs_EDGE); for (;ex.More(); ex.Next()) { - const TopoDS_Edge& edge = TopoDS::Edge(ex.Current()); + const TopoDS_Edge& edge = TopoDS::Edge(ex.Current()); - if (M->NewCurve2d(edge, face,TopoDS::Edge(myMap(ex.Current())), - TopoDS::Face(result),curve2d, tol)) + if (M->NewCurve2d(edge, face, TopoDS::Edge(myMap(ex.Current())), TopoDS::Face(result), curve2d, tol)) { - // rem dub 16/09/97 : Make constant topology or not make at all. - // Do not make if CopySurface = 1 - // Atention, TRUE sewing edges (RealyClosed) - // stay even if CopySurface is true. + // rem dub 16/09/97 : Make constant topology or not make at all. + // Do not make if CopySurface = 1 + // Atention, TRUE sewing edges (RealyClosed) + // stay even if CopySurface is true. // check that edge contains two pcurves on this surface: // either it is true seam on the current face, or belongs to two faces @@ -407,72 +432,67 @@ Standard_Boolean BRepTools_Modifier::Rebuild } } } - if (isClosed) - { - TopoDS_Edge CurE = TopoDS::Edge(myMap(edge)); - TopoDS_Shape aLocalResult = result; - aLocalResult.Orientation(TopAbs_FORWARD); - TopoDS_Face CurF = TopoDS::Face(aLocalResult); - Handle(Geom2d_Curve) curve2d1, currcurv; - Standard_Real f,l; - if ((!RevWires && fcor != edge.Orientation()) || - ( RevWires && fcor == edge.Orientation())) { - CurE.Orientation(TopAbs_FORWARD); - curve2d1 = BRep_Tool::CurveOnSurface(CurE,CurF,f,l); - if (curve2d1.IsNull()) curve2d1 = new Geom2d_Line(gp::OX2d()); - B.UpdateEdge (CurE, curve2d1, curve2d, CurF, 0.); - } - else { - CurE.Orientation(TopAbs_REVERSED); - curve2d1 = BRep_Tool::CurveOnSurface(CurE,CurF,f,l); - if (curve2d1.IsNull()) curve2d1 = new Geom2d_Line(gp::OX2d()); - B.UpdateEdge (CurE, curve2d, curve2d1, CurF, 0.); - } - currcurv = BRep_Tool::CurveOnSurface(edge,face,f,l); - B.Range(edge,f,l); - } - else { - B.UpdateEdge(TopoDS::Edge(myMap(ex.Current())), - curve2d, - TopoDS::Face(result), 0.); - } - - TopLoc_Location theLoc; - Standard_Real theF,theL; - Handle(Geom_Curve) C3D = - BRep_Tool::Curve(TopoDS::Edge(myMap(ex.Current())), - theLoc,theF,theL); - if (C3D.IsNull()) { // Update vertices - Standard_Real param; - TopExp_Explorer ex2(edge,TopAbs_VERTEX); - while (ex2.More()) { - const TopoDS_Vertex& vertex = TopoDS::Vertex(ex2.Current()); - if (!M->NewParameter(vertex, edge, param, tol)) { - tol = BRep_Tool::Tolerance(vertex); - param = BRep_Tool::Parameter(vertex,edge); - } - - TopAbs_Orientation vtxrelat = vertex.Orientation(); - if (edge.Orientation() == TopAbs_REVERSED) { - // Update considere l'edge FORWARD, et le vertex en relatif - vtxrelat= TopAbs::Reverse(vtxrelat); - } -// if (myMap(edge).Orientation() == TopAbs_REVERSED) { -// vtxrelat= TopAbs::Reverse(vtxrelat); -// } - TopoDS_Vertex aLocalVertex = TopoDS::Vertex(myMap(vertex)); - aLocalVertex.Orientation(vtxrelat); -// B.UpdateVertex(TopoDS::Vertex -// (myMap(vertex).Oriented(vtxrelat)), - B.UpdateVertex(aLocalVertex, - param, - TopoDS::Edge(myMap(edge)), - tol); - ex2.Next(); - } - } + if (isClosed) + { + TopoDS_Edge CurE = TopoDS::Edge(myMap(edge)); + TopoDS_Shape aLocalResult = result; + aLocalResult.Orientation(TopAbs_FORWARD); + TopoDS_Face CurF = TopoDS::Face(aLocalResult); + Handle(Geom2d_Curve) curve2d1, currcurv; + Standard_Real f,l; + if ((!RevWires && fcor != edge.Orientation()) || + ( RevWires && fcor == edge.Orientation())) { + CurE.Orientation(TopAbs_FORWARD); + curve2d1 = BRep_Tool::CurveOnSurface(CurE,CurF,f,l); + if (curve2d1.IsNull()) curve2d1 = new Geom2d_Line(gp::OX2d()); + B.UpdateEdge (CurE, curve2d1, curve2d, CurF, 0.); + } + else { + CurE.Orientation(TopAbs_REVERSED); + curve2d1 = BRep_Tool::CurveOnSurface(CurE,CurF,f,l); + if (curve2d1.IsNull()) curve2d1 = new Geom2d_Line(gp::OX2d()); + B.UpdateEdge (CurE, curve2d, curve2d1, CurF, 0.); + } + currcurv = BRep_Tool::CurveOnSurface(edge,face,f,l); + B.Range(edge,f,l); + } + else { + B.UpdateEdge(TopoDS::Edge(myMap(ex.Current())), + curve2d, + TopoDS::Face(result), 0.); + } - } + TopLoc_Location theLoc; + Standard_Real theF,theL; + Handle(Geom_Curve) C3D = BRep_Tool::Curve(TopoDS::Edge(myMap(ex.Current())), theLoc, theF, theL); + if (C3D.IsNull()) { // Update vertices + Standard_Real param; + TopExp_Explorer ex2(edge,TopAbs_VERTEX); + while (ex2.More()) { + const TopoDS_Vertex& vertex = TopoDS::Vertex(ex2.Current()); + if (!M->NewParameter(vertex, edge, param, tol)) { + tol = BRep_Tool::Tolerance(vertex); + param = BRep_Tool::Parameter(vertex,edge); + } + + TopAbs_Orientation vtxrelat = vertex.Orientation(); + if (edge.Orientation() == TopAbs_REVERSED) { + // Update considere l'edge FORWARD, et le vertex en relatif + vtxrelat= TopAbs::Reverse(vtxrelat); + } + //if (myMap(edge).Orientation() == TopAbs_REVERSED) { + // vtxrelat= TopAbs::Reverse(vtxrelat); + //} + + TopoDS_Vertex aLocalVertex = TopoDS::Vertex(myMap(vertex)); + aLocalVertex.Orientation(vtxrelat); + //B.UpdateVertex(TopoDS::Vertex + //(myMap(vertex).Oriented(vtxrelat)), + B.UpdateVertex(aLocalVertex, param, TopoDS::Edge(myMap(edge)), tol); + ex2.Next(); + } + } + } } } @@ -486,32 +506,28 @@ Standard_Boolean BRepTools_Modifier::Rebuild if(edor != TopAbs_REVERSED) edor = TopAbs_FORWARD; TopExp_Explorer ex(edge.Oriented(edor), TopAbs_VERTEX); while (ex.More()) { - const TopoDS_Vertex& vertex = TopoDS::Vertex(ex.Current()); - - if (!M->NewParameter(vertex, edge, param, tol)) { - tol = BRep_Tool::Tolerance(vertex); - param = BRep_Tool::Parameter(vertex,edge); - } - - - TopAbs_Orientation vtxrelat = vertex.Orientation(); - if (edor == TopAbs_REVERSED) { - // Update considere l'edge FORWARD, et le vertex en relatif - vtxrelat= TopAbs::Reverse(vtxrelat); - } -// if (result.Orientation() == TopAbs_REVERSED) { -// vtxrelat= TopAbs::Reverse(vtxrelat); -// } - TopoDS_Vertex aLocalVertex = TopoDS::Vertex(myMap(vertex)); - aLocalVertex.Orientation(vtxrelat); -// B.UpdateVertex(TopoDS::Vertex -// (myMap(vertex).Oriented(vtxrelat)), - B.UpdateVertex(aLocalVertex, - param, - TopoDS::Edge(result), - tol); - - ex.Next(); + const TopoDS_Vertex& vertex = TopoDS::Vertex(ex.Current()); + + if (!M->NewParameter(vertex, edge, param, tol)) { + tol = BRep_Tool::Tolerance(vertex); + param = BRep_Tool::Parameter(vertex,edge); + } + + TopAbs_Orientation vtxrelat = vertex.Orientation(); + if (edor == TopAbs_REVERSED) { + // Update considere l'edge FORWARD, et le vertex en relatif + vtxrelat= TopAbs::Reverse(vtxrelat); + } + + //if (result.Orientation() == TopAbs_REVERSED) { + // vtxrelat= TopAbs::Reverse(vtxrelat); + //} + TopoDS_Vertex aLocalVertex = TopoDS::Vertex(myMap(vertex)); + aLocalVertex.Orientation(vtxrelat); + //B.UpdateVertex(TopoDS::Vertex(myMap(vertex).Oriented(vtxrelat)), + B.UpdateVertex(aLocalVertex, param, TopoDS::Edge(result), tol); + + ex.Next(); } } diff --git a/src/DNaming/DNaming_ModelingCommands.cxx b/src/DNaming/DNaming_ModelingCommands.cxx index fb5fe17684..ddf159f85b 100644 --- a/src/DNaming/DNaming_ModelingCommands.cxx +++ b/src/DNaming/DNaming_ModelingCommands.cxx @@ -697,7 +697,8 @@ static Standard_Integer DNaming_AttachShape (Draw_Interpretor& di, TNaming_Selector aSelector(aResultLabel); if(!aSelector.Select(aShape, aCONTEXT, aGeometry, aKeepOrientation)) return 1; - }catch (...) { + } + catch (Standard_Failure) { cout << "EXCEPTION: SELECTION_IMPOSSIBLE" < #include #include +#include +#include +#include +#include //======================================================================= //function : ApplyModifier @@ -42,7 +46,9 @@ TopoDS_Shape ShapeCustom::ApplyModifier (const TopoDS_Shape &S, const Handle(BRepTools_Modification) &M, TopTools_DataMapOfShapeShape &context, - BRepTools_Modifier& MD ) + BRepTools_Modifier& MD, + const Handle(Message_ProgressIndicator) & aProgress, + const Handle(ShapeBuild_ReShape) & aReShape) { // protect against INTERNAL/EXTERNAL shapes TopoDS_Shape SF = S.Oriented(TopAbs_FORWARD); @@ -53,14 +59,23 @@ TopoDS_Shape ShapeCustom::ApplyModifier (const TopoDS_Shape &S, TopoDS_Compound C; BRep_Builder B; B.MakeCompound ( C ); - for ( TopoDS_Iterator it(SF); it.More(); it.Next() ) { + + Standard_Integer aShapeCount = 0; + { + for (TopoDS_Iterator it(SF); it.More(); it.Next()) ++aShapeCount; + } + + Message_ProgressSentry aPSentry(aProgress, "Applying Modifier For Solids", 0, aShapeCount, 1); + for ( TopoDS_Iterator it(SF); it.More() && aPSentry.More(); it.Next(), aPSentry.Next() ) { TopoDS_Shape shape = it.Value(); TopLoc_Location L = shape.Location(), nullLoc; shape.Location ( nullLoc ); TopoDS_Shape res; if ( context.IsBound ( shape ) ) - res = context.Find ( shape ).Oriented ( shape.Orientation() ); - else res = ApplyModifier ( shape, M, context ,MD); + res = context.Find ( shape ).Oriented ( shape.Orientation() ); + else + res = ApplyModifier ( shape, M, context ,MD, aProgress); + if ( ! res.IsSame ( shape ) ) { context.Bind ( shape, res ); locModified = Standard_True; @@ -68,17 +83,48 @@ TopoDS_Shape ShapeCustom::ApplyModifier (const TopoDS_Shape &S, res.Location ( L ); B.Add ( C, res ); } + + if ( !aPSentry.More() ) + { + // Was cancelled + return S; + } + if ( ! locModified ) return S; context.Bind ( SF, C ); return C.Oriented ( S.Orientation() ); } + Message_ProgressSentry aPSentry(aProgress, "Modify the Shape", 0, 1, 1); // Modify the shape - //BRepTools_Modifier Op(SF,M); MD.Init(SF); - MD.Perform(M); - - if ( ! MD.IsDone() ) return S; + MD.Perform(M, aProgress); + + if ( !aPSentry.More() || !MD.IsDone() ) return S; + if ( !aReShape.IsNull() ) + { + for(TopoDS_Iterator theIterator(SF,Standard_False);theIterator.More();theIterator.Next()) + { + const TopoDS_Shape & current = theIterator.Value(); + TopoDS_Shape result; + try + { + OCC_CATCH_SIGNALS + result = MD.ModifiedShape( current ); + } + catch (Standard_NoSuchObject) + { + // the sub shape isn't in the map + result.Nullify(); + } + + if (!result.IsNull() && !current.IsSame(result)) + { + aReShape->Replace(current, result); + } + } + } + return MD.ModifiedShape(SF).Oriented(S.Orientation()); } diff --git a/src/TNaming/TNaming_Name.cxx b/src/TNaming/TNaming_Name.cxx index 980df27b2c..8ab351631a 100644 --- a/src/TNaming/TNaming_Name.cxx +++ b/src/TNaming/TNaming_Name.cxx @@ -40,6 +40,7 @@ #include #include +#include #include #include #include @@ -2075,6 +2076,7 @@ Standard_Boolean TNaming_Name::Solve(const TDF_Label& aLab, PrintEntry(aLab); #endif try { + OCC_CATCH_SIGNALS switch (myType) { case TNaming_UNKNOWN : { @@ -2145,7 +2147,7 @@ case TNaming_SHELLIN: break; } } -} catch (...) { +} catch (Standard_Failure) { #ifdef OCCT_DEBUG cout << "Name::Solve: EXCEPTION==> NameType = " << NameTypeToString(myType) << " "; PrintEntry(aLab);