From: vsr Date: Tue, 22 Jan 2013 11:33:30 +0000 (+0000) Subject: 0022051: [CEA 744] SALOME crashes when calliing "BasicProperties" on a sphere degener... X-Git-Tag: V6_main_FINAL~57 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=011f7da68696a9ff0d9267a439423daf0365a7e8;p=modules%2Fgeom.git 0022051: [CEA 744] SALOME crashes when calliing "BasicProperties" on a sphere degenerated edge --- diff --git a/src/GEOMImpl/GEOMImpl_PointDriver.cxx b/src/GEOMImpl/GEOMImpl_PointDriver.cxx index 9fa9cf9c0..832fdc15c 100644 --- a/src/GEOMImpl/GEOMImpl_PointDriver.cxx +++ b/src/GEOMImpl/GEOMImpl_PointDriver.cxx @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -142,8 +143,27 @@ Standard_Integer GEOMImpl_PointDriver::Execute(TFunction_Logbook& log) const } Standard_Real aFP, aLP, aP; Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aRefShape), aFP, aLP); - aP = aFP + (aLP - aFP) * aPI.GetParameter(); - aPnt = aCurve->Value(aP); + if ( !aCurve.IsNull() ) { + aP = aFP + (aLP - aFP) * aPI.GetParameter(); + aPnt = aCurve->Value(aP); + } + else { + // null curve, e.g. degenerated edge + TopoDS_Iterator It(aRefShape, Standard_False, Standard_False); + TopoDS_Vertex aVertex; + if ( It.More() ) { + TopoDS_Shape aShape = It.Value(); + if ( !aShape.IsNull() ) + aVertex = TopoDS::Vertex( aShape ); + } + if ( !aVertex.IsNull() ) { + aPnt = BRep_Tool::Pnt( aVertex ); + } + else { + Standard_TypeMismatch::Raise + ("Point On Curve creation aborted : null curve"); + } + } } else if (aType == POINT_CURVE_COORD) { Handle(GEOM_Function) aRefFunc = aPI.GetCurve(); @@ -201,25 +221,45 @@ Standard_Integer GEOMImpl_PointDriver::Execute(TFunction_Logbook& log) const // Check orientation Standard_Real UFirst, ULast; Handle(Geom_Curve) EdgeCurve = BRep_Tool::Curve(aRefEdge, UFirst, ULast); - Handle(Geom_Curve) ReOrientedCurve = EdgeCurve; - - Standard_Real dU = ULast - UFirst; - Standard_Real par1 = UFirst + 0.1 * dU; - Standard_Real par2 = ULast - 0.1 * dU; - - gp_Pnt P1 = EdgeCurve->Value(par1); - gp_Pnt P2 = EdgeCurve->Value(par2); - if (aRefPnt.SquareDistance(P2) < aRefPnt.SquareDistance(P1)) { - ReOrientedCurve = EdgeCurve->Reversed(); - UFirst = EdgeCurve->ReversedParameter(ULast); + if ( !EdgeCurve.IsNull() ) { + Handle(Geom_Curve) ReOrientedCurve = EdgeCurve; + + Standard_Real dU = ULast - UFirst; + Standard_Real par1 = UFirst + 0.1 * dU; + Standard_Real par2 = ULast - 0.1 * dU; + + gp_Pnt P1 = EdgeCurve->Value(par1); + gp_Pnt P2 = EdgeCurve->Value(par2); + + if (aRefPnt.SquareDistance(P2) < aRefPnt.SquareDistance(P1)) { + ReOrientedCurve = EdgeCurve->Reversed(); + UFirst = EdgeCurve->ReversedParameter(ULast); + } + + // Get the point by length + GeomAdaptor_Curve AdapCurve = GeomAdaptor_Curve(ReOrientedCurve); + GCPnts_AbscissaPoint anAbsPnt (AdapCurve, aLength, UFirst); + Standard_Real aParam = anAbsPnt.Parameter(); + aPnt = AdapCurve.Value(aParam); + } + else { + // null curve, e.g. degenerated edge + TopoDS_Iterator It(aRefEdge, Standard_False, Standard_False); + TopoDS_Vertex aVertex; + if ( It.More() ) { + TopoDS_Shape aShape = It.Value(); + if ( !aShape.IsNull() ) + aVertex = TopoDS::Vertex( aShape ); + } + if ( !aVertex.IsNull() ) { + aPnt = BRep_Tool::Pnt( aVertex ); + } + else { + Standard_TypeMismatch::Raise + ("Point On Curve creation aborted : null curve"); + } } - - // Get the point by length - GeomAdaptor_Curve AdapCurve = GeomAdaptor_Curve(ReOrientedCurve); - GCPnts_AbscissaPoint anAbsPnt (AdapCurve, aLength, UFirst); - Standard_Real aParam = anAbsPnt.Parameter(); - aPnt = AdapCurve.Value(aParam); } else if (aType == POINT_SURFACE_PAR) { Handle(GEOM_Function) aRefFunc = aPI.GetSurface();