1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-09-08 14:17:06 +03:00

0030146: Visualization - exception during attempt to display Edge without geometry

StdPrs_ToolRFace no skips curves with NULL curves.
Code has been cleaned up from duplicated checks, redundant casts
and dummy Adaptor2d_Curve2dPtr typedef.

StdSelect_BRepSelectionTool::GetSensitiveForFace() now catches
Standard_NullObject exception to skip invalid Edges.
This commit is contained in:
kgv
2018-09-20 11:40:19 +03:00
committed by bugmaster
parent c39bb31bac
commit 4ba5491a50
17 changed files with 188 additions and 208 deletions

View File

@@ -387,12 +387,7 @@ void StdPrs_Isolines::addOnSurface (const Handle(BRepAdaptor_HSurface)& theSurfa
for (anEdgeTool.Init(); anEdgeTool.More(); anEdgeTool.Next())
{
TopAbs_Orientation anOrientation = anEdgeTool.Orientation();
if (anOrientation != TopAbs_FORWARD && anOrientation != TopAbs_REVERSED)
{
continue;
}
Adaptor2d_Curve2dPtr anEdgeCurve = anEdgeTool.Value();
const Adaptor2d_Curve2d* anEdgeCurve = &anEdgeTool.Value();
if (anEdgeCurve->GetType() != GeomAbs_Line)
{
GCPnts_QuasiUniformDeflection aSampler (*anEdgeCurve, aSamplerDeflection);

View File

@@ -12,114 +12,59 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <StdPrs_ToolRFace.hxx>
#include <Adaptor2d_Curve2d.hxx>
#include <BRep_Tool.hxx>
#include <BRepAdaptor_HSurface.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <StdPrs_ToolRFace.hxx>
#include <TopoDS.hxx>
//=======================================================================
//function : StdPrs_ToolRFace
//purpose :
//purpose :
//=======================================================================
StdPrs_ToolRFace::StdPrs_ToolRFace()
: myHasNullCurves (Standard_False)
{
}
//=======================================================================
//function : StdPrs_ToolRFace
//purpose :
//purpose :
//=======================================================================
StdPrs_ToolRFace::StdPrs_ToolRFace(const Handle(BRepAdaptor_HSurface)& aSurface) :
myFace(((BRepAdaptor_Surface*)&(aSurface->Surface()))->Face())
StdPrs_ToolRFace::StdPrs_ToolRFace (const Handle(BRepAdaptor_HSurface)& theSurface)
: myFace (theSurface->ChangeSurface().Face()),
myHasNullCurves (Standard_False)
{
myFace.Orientation(TopAbs_FORWARD);
}
//=======================================================================
//function : IsOriented
//purpose :
//function : next
//purpose :
//=======================================================================
Standard_Boolean StdPrs_ToolRFace::IsOriented () const {
return Standard_True;
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void StdPrs_ToolRFace::Init()
void StdPrs_ToolRFace::next()
{
myExplorer.Init(myFace,TopAbs_EDGE);
if (myExplorer.More()) {
Standard_Real U1,U2;
const Handle(Geom2d_Curve)& C =
BRep_Tool::CurveOnSurface(TopoDS::Edge(myExplorer.Current()),
myFace,
U1,U2);
DummyCurve.Load(C,U1,U2);
}
}
//=======================================================================
//function : More
//purpose :
//=======================================================================
Standard_Boolean StdPrs_ToolRFace::More() const
{
return myExplorer.More();
}
//=======================================================================
//function : Next
//purpose :
//=======================================================================
void StdPrs_ToolRFace::Next()
{
myExplorer.Next();
if (myExplorer.More()) {
Standard_Real aParamU1, aParamU2;
for (; myExplorer.More(); myExplorer.Next())
{
// skip INTERNAL and EXTERNAL edges
while (myExplorer.More() && (myExplorer.Current().Orientation() == TopAbs_INTERNAL
|| myExplorer.Current().Orientation() == TopAbs_EXTERNAL))
myExplorer.Next();
if (myExplorer.More()) {
Standard_Real U1,U2;
const Handle(Geom2d_Curve)& C =
BRep_Tool::CurveOnSurface(TopoDS::Edge(myExplorer.Current()),
myFace,
U1,U2);
if ( !C.IsNull() )
DummyCurve.Load(C,U1,U2);
if (myExplorer.Current().Orientation() != TopAbs_FORWARD
&& myExplorer.Current().Orientation() != TopAbs_REVERSED)
{
continue;
}
if (Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface (TopoDS::Edge (myExplorer.Current()), myFace, aParamU1, aParamU2))
{
myCurve.Load (aCurve, aParamU1, aParamU2);
return;
}
else
{
myHasNullCurves = Standard_True;
}
}
myCurve.Reset();
}
//=======================================================================
//function : Value
//purpose :
//=======================================================================
Adaptor2d_Curve2dPtr StdPrs_ToolRFace::Value() const
{
return (Adaptor2d_Curve2dPtr)&DummyCurve;
}
//=======================================================================
//function : Orientation
//purpose :
//=======================================================================
TopAbs_Orientation StdPrs_ToolRFace::Orientation () const {
return myExplorer.Current().Orientation();
}

View File

@@ -24,60 +24,64 @@
#include <TopoDS_Face.hxx>
#include <TopExp_Explorer.hxx>
#include <Geom2dAdaptor_Curve.hxx>
#include <Standard_Boolean.hxx>
#include <Adaptor2d_Curve2dPtr.hxx>
#include <TopAbs_Orientation.hxx>
class BRepAdaptor_HSurface;
//! Iterator over 2D curves restricting a face (skipping internal/external edges).
//! In addition, the algorithm skips NULL curves - IsInvalidGeometry() can be checked if this should be handled within algorithm.
class StdPrs_ToolRFace
{
public:
DEFINE_STANDARD_ALLOC
//! Empty constructor.
Standard_EXPORT StdPrs_ToolRFace();
//! Constructor with initialization.
Standard_EXPORT StdPrs_ToolRFace(const Handle(BRepAdaptor_HSurface)& aSurface);
Standard_EXPORT Standard_Boolean IsOriented() const;
//! Return TRUE indicating that iterator looks only for oriented edges.
Standard_Boolean IsOriented() const { return Standard_True; }
Standard_EXPORT void Init();
Standard_EXPORT Standard_Boolean More() const;
Standard_EXPORT void Next();
Standard_EXPORT Adaptor2d_Curve2dPtr Value() const;
Standard_EXPORT TopAbs_Orientation Orientation() const;
//! Move iterator to the first element.
void Init()
{
myExplorer.Init (myFace, TopAbs_EDGE);
next();
}
//! Return TRUE if iterator points to the curve.
Standard_Boolean More() const { return myExplorer.More(); }
//! Go to the next curve in the face.
void Next()
{
myExplorer.Next();
next();
}
//! Return current curve.
const Adaptor2d_Curve2d& Value() const { return myCurve; }
protected:
//! Return current edge orientation.
TopAbs_Orientation Orientation() const { return myExplorer.Current().Orientation(); }
//! Return TRUE if NULL curves have been skipped.
Standard_Boolean IsInvalidGeometry() const { return myHasNullCurves; }
private:
//! Find nearest valid item for the iterator.
Standard_EXPORT void next();
private:
TopoDS_Face myFace;
TopExp_Explorer myExplorer;
Geom2dAdaptor_Curve DummyCurve;
Geom2dAdaptor_Curve myCurve;
Standard_Boolean myHasNullCurves;
};
#endif // _StdPrs_ToolRFace_HeaderFile

View File

@@ -146,8 +146,7 @@ void StdPrs_WFDeflectionRestrictedFace::Add
for (ToolRst.Init(); ToolRst.More(); ToolRst.Next()) {
TopAbs_Orientation Orient = ToolRst.Orientation();
if ( Orient == TopAbs_FORWARD || Orient == TopAbs_REVERSED ) {
Adaptor2d_Curve2dPtr TheRCurve = ToolRst.Value();
const Adaptor2d_Curve2d* TheRCurve = &ToolRst.Value();
if (TheRCurve->GetType() != GeomAbs_Line) {
GCPnts_QuasiUniformDeflection UDP(*TheRCurve, ddefle);
if (UDP.IsDone()) {
@@ -180,7 +179,6 @@ void StdPrs_WFDeflectionRestrictedFace::Add
tabP.Append(P1);
}
}
}
}
#ifdef OCCT_DEBUG
else {
@@ -385,7 +383,7 @@ Standard_Boolean StdPrs_WFDeflectionRestrictedFace::Match
UMax = VMax = RealFirst();
for (ToolRst.Init(); ToolRst.More(); ToolRst.Next()) {
Adaptor2d_Curve2dPtr TheRCurve = ToolRst.Value();
const Adaptor2d_Curve2d* TheRCurve = &ToolRst.Value();
u = TheRCurve->FirstParameter();
v = TheRCurve->LastParameter();
step = ( v - u) / nbPoints;
@@ -438,8 +436,7 @@ Standard_Boolean StdPrs_WFDeflectionRestrictedFace::Match
gp_Pnt dummypnt;
for (ToolRst.Init(); ToolRst.More(); ToolRst.Next()) {
TopAbs_Orientation Orient = ToolRst.Orientation();
if ( Orient == TopAbs_FORWARD || Orient == TopAbs_REVERSED ) {
Adaptor2d_Curve2dPtr TheRCurve = ToolRst.Value();
const Adaptor2d_Curve2d* TheRCurve = &ToolRst.Value();
GCPnts_QuasiUniformDeflection UDP(*TheRCurve, Deflection);
if (UDP.IsDone()) {
Standard_Integer NumberOfPoints = UDP.NbPoints();
@@ -462,7 +459,6 @@ Standard_Boolean StdPrs_WFDeflectionRestrictedFace::Match
cout << "Cannot evaluate curve on surface"<<endl;
}
#endif
}
}
// draw the isos

View File

@@ -55,8 +55,8 @@ void StdPrs_WFRestrictedFace::Add
for (aToolRst.Init(); aToolRst.More(); aToolRst.Next())
{
Adaptor2d_Curve2dPtr aRCurve = aToolRst.Value();
BndLib_Add2dCurve::Add(*aRCurve, Precision::PConfusion(), aBndBox);
const Adaptor2d_Curve2d& aRCurve = aToolRst.Value();
BndLib_Add2dCurve::Add(aRCurve, Precision::PConfusion(), aBndBox);
}
if (!aBndBox.IsVoid())
aBndBox.Get(aUMin, aVMin, aUMax, aVMax);
@@ -116,35 +116,32 @@ void StdPrs_WFRestrictedFace::Add
for (aToolRst.Init(); aToolRst.More(); aToolRst.Next())
{
TopAbs_Orientation anOrientation = aToolRst.Orientation();
if (anOrientation == TopAbs_FORWARD || anOrientation == TopAbs_REVERSED)
const Adaptor2d_Curve2d* aRCurve = &aToolRst.Value();
anU1 = aRCurve->FirstParameter();
anU2 = aRCurve->LastParameter();
if (aRCurve->GetType() != GeomAbs_Line)
{
Adaptor2d_Curve2dPtr aRCurve = aToolRst.Value();
anU1 = aRCurve->FirstParameter();
anU2 = aRCurve->LastParameter();
if (aRCurve->GetType() != GeomAbs_Line)
aDU = (anU2-anU1)/(aNbPoints-1);
aPoint2 = aRCurve->Value(anU1);
for (anI = 2; anI <= aNbPoints; ++anI)
{
aDU = (anU2-anU1)/(aNbPoints-1);
aPoint2 = aRCurve->Value(anU1);
for (anI = 2; anI <= aNbPoints; ++anI)
{
anU = anU1 + (anI-1)*aDU;
aPoint1 = aPoint2;
aPoint2 = aRCurve->Value(anU);
if(anOrientation == TopAbs_FORWARD )
anIsoBuild.Trim(aPoint1,aPoint2);
else
anIsoBuild.Trim(aPoint2,aPoint1);
}
}
else {
aPoint1 = aRCurve->Value(anU1);
aPoint2 = aRCurve->Value(anU2);
anU = anU1 + (anI-1)*aDU;
aPoint1 = aPoint2;
aPoint2 = aRCurve->Value(anU);
if(anOrientation == TopAbs_FORWARD )
anIsoBuild.Trim(aPoint1,aPoint2);
else
anIsoBuild.Trim(aPoint2,aPoint1);
}
}
else {
aPoint1 = aRCurve->Value(anU1);
aPoint2 = aRCurve->Value(anU2);
if(anOrientation == TopAbs_FORWARD )
anIsoBuild.Trim(aPoint1,aPoint2);
else
anIsoBuild.Trim(aPoint2,aPoint1);
}
}
// Draw the isos
@@ -243,7 +240,7 @@ Standard_Boolean StdPrs_WFRestrictedFace::Match
for (aToolRst.Init(); aToolRst.More(); aToolRst.Next())
{
Adaptor2d_Curve2dPtr aRCurve = aToolRst.Value();
const Adaptor2d_Curve2d* aRCurve = &aToolRst.Value();
anU = aRCurve->FirstParameter();
aV = aRCurve->LastParameter();
if (aRCurve->GetType() != GeomAbs_Line)
@@ -319,32 +316,29 @@ Standard_Boolean StdPrs_WFRestrictedFace::Match
for (aToolRst.Init(); aToolRst.More(); aToolRst.Next())
{
TopAbs_Orientation Orient = aToolRst.Orientation();
if (Orient == TopAbs_FORWARD || Orient == TopAbs_REVERSED)
{
Adaptor2d_Curve2dPtr aRCurve = aToolRst.Value();
anU1 = aRCurve->FirstParameter();
anU2 = aRCurve->LastParameter();
if (aRCurve->GetType() != GeomAbs_Line) {
aDU = (anU2-anU1)/(aNbPoints-1);
aPoint2 = aRCurve->Value(anU1);
for (anI = 2; anI <= aNbPoints; anI++) {
anU = anU1 + (anI-1)*aDU;
aPoint1 = aPoint2;
aPoint2 = aRCurve->Value(anU);
if(Orient == TopAbs_FORWARD )
anIsoBuild.Trim(aPoint1,aPoint2);
else
anIsoBuild.Trim(aPoint2,aPoint1);
}
}
else {
aPoint1 = aRCurve->Value(anU1);
aPoint2 = aRCurve->Value(anU2);
const Adaptor2d_Curve2d* aRCurve = &aToolRst.Value();
anU1 = aRCurve->FirstParameter();
anU2 = aRCurve->LastParameter();
if (aRCurve->GetType() != GeomAbs_Line) {
aDU = (anU2-anU1)/(aNbPoints-1);
aPoint2 = aRCurve->Value(anU1);
for (anI = 2; anI <= aNbPoints; anI++) {
anU = anU1 + (anI-1)*aDU;
aPoint1 = aPoint2;
aPoint2 = aRCurve->Value(anU);
if(Orient == TopAbs_FORWARD )
anIsoBuild.Trim(aPoint1,aPoint2);
else
anIsoBuild.Trim(aPoint2,aPoint1);
}
}
}
else {
aPoint1 = aRCurve->Value(anU1);
aPoint2 = aRCurve->Value(anU2);
if(Orient == TopAbs_FORWARD )
anIsoBuild.Trim(aPoint1,aPoint2);
else
anIsoBuild.Trim(aPoint2,aPoint1);
}
}