Modeling Data - Enforce construction-time initialization for Prop and GridEval classes (#1118)

Replace two-step initialization (default constructor + Initialize) with
direct construction for 8 non-copyable/non-movable property and grid
evaluator classes. Objects are now always in a valid state after construction.

Refactored classes:
- GeomProp_Curve, GeomProp_Surface (TKG3d)
- Geom2dProp_Curve (TKG2d)
- BRepProp_Curve, BRepProp_Surface (TKBRep)
- GeomGridEval_Curve, GeomGridEval_Surface (TKG3d)
- Geom2dGridEval_Curve (TKG2d)

Changes per class:
- Remove default constructor and IsInitialized() method.
- Add constructors matching each former Initialize overload.
- Rename Initialize to protected initialization method for internal
  and derived class use.

All callers updated across production code (Extrema, BndLib,
IntCurveSurface, IntPatch, HLRBRep, GeomGridEval derived classes)
and test files to use constructor-based initialization.
This commit is contained in:
Pasukhin Dmitry
2026-02-25 15:06:57 +00:00
committed by GitHub
parent 33ef11ca53
commit 12b54504ee
43 changed files with 670 additions and 958 deletions

View File

@@ -22,7 +22,28 @@
//==================================================================================================
void BRepProp_Curve::Initialize(const TopoDS_Edge& theEdge)
BRepProp_Curve::BRepProp_Curve(const TopoDS_Edge& theEdge)
{
initialization(theEdge);
}
//==================================================================================================
BRepProp_Curve::BRepProp_Curve(const BRepAdaptor_Curve& theCurve)
{
initialization(theCurve);
}
//==================================================================================================
BRepProp_Curve::BRepProp_Curve(const occ::handle<BRepAdaptor_Curve>& theCurve)
{
initialization(theCurve);
}
//==================================================================================================
void BRepProp_Curve::initialization(const TopoDS_Edge& theEdge)
{
if (theEdge.IsNull())
{
@@ -36,7 +57,7 @@ void BRepProp_Curve::Initialize(const TopoDS_Edge& theEdge)
//==================================================================================================
void BRepProp_Curve::Initialize(const BRepAdaptor_Curve& theCurve)
void BRepProp_Curve::initialization(const BRepAdaptor_Curve& theCurve)
{
myOwned.Nullify();
myPtr = &theCurve;
@@ -44,7 +65,7 @@ void BRepProp_Curve::Initialize(const BRepAdaptor_Curve& theCurve)
//==================================================================================================
void BRepProp_Curve::Initialize(const occ::handle<BRepAdaptor_Curve>& theCurve)
void BRepProp_Curve::initialization(const occ::handle<BRepAdaptor_Curve>& theCurve)
{
myOwned = theCurve;
myPtr = myOwned.get();
@@ -54,10 +75,6 @@ void BRepProp_Curve::Initialize(const occ::handle<BRepAdaptor_Curve>& theCurve)
GeomProp::TangentResult BRepProp_Curve::Tangent(const double theParam, const double theTol) const
{
if (!IsInitialized())
{
return {{}, false};
}
gp_Pnt aPnt;
gp_Vec aD1, aD2, aD3;
myPtr->D3(theParam, aPnt, aD1, aD2, aD3);
@@ -69,10 +86,6 @@ GeomProp::TangentResult BRepProp_Curve::Tangent(const double theParam, const dou
GeomProp::CurvatureResult BRepProp_Curve::Curvature(const double theParam,
const double theTol) const
{
if (!IsInitialized())
{
return {};
}
gp_Pnt aPnt;
gp_Vec aD1, aD2;
myPtr->D2(theParam, aPnt, aD1, aD2);
@@ -83,10 +96,6 @@ GeomProp::CurvatureResult BRepProp_Curve::Curvature(const double theParam,
GeomProp::NormalResult BRepProp_Curve::Normal(const double theParam, const double theTol) const
{
if (!IsInitialized())
{
return {{}, false};
}
gp_Pnt aPnt;
gp_Vec aD1, aD2;
myPtr->D2(theParam, aPnt, aD1, aD2);
@@ -98,10 +107,6 @@ GeomProp::NormalResult BRepProp_Curve::Normal(const double theParam, const doubl
GeomProp::CentreResult BRepProp_Curve::CentreOfCurvature(const double theParam,
const double theTol) const
{
if (!IsInitialized())
{
return {{}, false};
}
gp_Pnt aPnt;
gp_Vec aD1, aD2;
myPtr->D2(theParam, aPnt, aD1, aD2);
@@ -139,9 +144,8 @@ GeomAbs_Shape BRepProp_Curve::Continuity(const BRepAdaptor_Curve& theCurve1,
aN2 = 1;
// Evaluate properties at junction points.
BRepProp_Curve aProp1, aProp2;
aProp1.Initialize(theCurve1);
aProp2.Initialize(theCurve2);
BRepProp_Curve aProp1(theCurve1);
BRepProp_Curve aProp2(theCurve2);
// Check point coincidence.
gp_Pnt aPnt1, aPnt2;

View File

@@ -35,8 +35,7 @@ class TopoDS_Edge;
//!
//! Usage:
//! @code
//! BRepProp_Curve aProp;
//! aProp.Initialize(myEdge);
//! BRepProp_Curve aProp(myEdge);
//! GeomProp::CurvatureResult aCurv = aProp.Curvature(0.5, Precision::Confusion());
//! if (aCurv.IsDefined)
//! {
@@ -48,8 +47,21 @@ class BRepProp_Curve
public:
DEFINE_STANDARD_ALLOC
//! Default constructor - uninitialized state.
BRepProp_Curve() = default;
//! Construct from a TopoDS_Edge.
//! Creates an internal BRepAdaptor_Curve (owning).
//! @param[in] theEdge the edge to evaluate
Standard_EXPORT BRepProp_Curve(const TopoDS_Edge& theEdge);
//! Construct from an existing BRepAdaptor_Curve.
//! The adaptor is referenced without copying (non-owning);
//! the caller must ensure the adaptor outlives this object.
//! @param[in] theCurve the adaptor to reference
Standard_EXPORT BRepProp_Curve(const BRepAdaptor_Curve& theCurve);
//! Construct from a handle to BRepAdaptor_Curve.
//! Shares ownership of the adaptor (no copy).
//! @param[in] theCurve handle to the adaptor
Standard_EXPORT BRepProp_Curve(const occ::handle<BRepAdaptor_Curve>& theCurve);
//! Non-copyable and non-movable.
BRepProp_Curve(const BRepProp_Curve&) = delete;
@@ -57,25 +69,6 @@ public:
BRepProp_Curve(BRepProp_Curve&&) = delete;
BRepProp_Curve& operator=(BRepProp_Curve&&) = delete;
//! Initialize from a TopoDS_Edge.
//! Creates an internal BRepAdaptor_Curve (owning).
//! @param[in] theEdge the edge to evaluate
Standard_EXPORT void Initialize(const TopoDS_Edge& theEdge);
//! Initialize from an existing BRepAdaptor_Curve.
//! The adaptor is referenced without copying (non-owning);
//! the caller must ensure the adaptor outlives this object.
//! @param[in] theCurve the adaptor to reference
Standard_EXPORT void Initialize(const BRepAdaptor_Curve& theCurve);
//! Initialize from a handle to BRepAdaptor_Curve.
//! Shares ownership of the adaptor (no copy).
//! @param[in] theCurve handle to the adaptor
Standard_EXPORT void Initialize(const occ::handle<BRepAdaptor_Curve>& theCurve);
//! Returns true if properly initialized.
bool IsInitialized() const { return myPtr != nullptr; }
//! Returns the underlying adaptor.
const BRepAdaptor_Curve& Adaptor() const { return *myPtr; }
@@ -125,6 +118,19 @@ public:
double theU1,
double theU2);
protected:
//! Initialize from a TopoDS_Edge.
//! @param[in] theEdge the edge to evaluate
Standard_EXPORT void initialization(const TopoDS_Edge& theEdge);
//! Initialize from an existing BRepAdaptor_Curve (non-owning).
//! @param[in] theCurve the adaptor to reference
Standard_EXPORT void initialization(const BRepAdaptor_Curve& theCurve);
//! Initialize from a handle to BRepAdaptor_Curve.
//! @param[in] theCurve handle to the adaptor
Standard_EXPORT void initialization(const occ::handle<BRepAdaptor_Curve>& theCurve);
private:
occ::handle<BRepAdaptor_Curve> myOwned; //!< Owns the adaptor when created from TopoDS_Edge.
const BRepAdaptor_Curve* myPtr = nullptr; //!< Non-owning pointer to the active adaptor.

View File

@@ -17,7 +17,28 @@
//==================================================================================================
void BRepProp_Surface::Initialize(const TopoDS_Face& theFace)
BRepProp_Surface::BRepProp_Surface(const TopoDS_Face& theFace)
{
initialization(theFace);
}
//==================================================================================================
BRepProp_Surface::BRepProp_Surface(const BRepAdaptor_Surface& theSurface)
{
initialization(theSurface);
}
//==================================================================================================
BRepProp_Surface::BRepProp_Surface(const occ::handle<BRepAdaptor_Surface>& theSurface)
{
initialization(theSurface);
}
//==================================================================================================
void BRepProp_Surface::initialization(const TopoDS_Face& theFace)
{
if (theFace.IsNull())
{
@@ -31,7 +52,7 @@ void BRepProp_Surface::Initialize(const TopoDS_Face& theFace)
//==================================================================================================
void BRepProp_Surface::Initialize(const BRepAdaptor_Surface& theSurface)
void BRepProp_Surface::initialization(const BRepAdaptor_Surface& theSurface)
{
myOwned.Nullify();
myPtr = &theSurface;
@@ -39,7 +60,7 @@ void BRepProp_Surface::Initialize(const BRepAdaptor_Surface& theSurface)
//==================================================================================================
void BRepProp_Surface::Initialize(const occ::handle<BRepAdaptor_Surface>& theSurface)
void BRepProp_Surface::initialization(const occ::handle<BRepAdaptor_Surface>& theSurface)
{
myOwned = theSurface;
myPtr = myOwned.get();
@@ -51,7 +72,7 @@ GeomProp::SurfaceNormalResult BRepProp_Surface::Normal(const double theU,
const double theV,
const double theTol) const
{
if (!IsInitialized())
if (myPtr == nullptr)
{
return {{}, false};
}
@@ -67,7 +88,7 @@ GeomProp::SurfaceCurvatureResult BRepProp_Surface::Curvatures(const double theU,
const double theV,
const double theTol) const
{
if (!IsInitialized())
if (myPtr == nullptr)
{
return {};
}
@@ -83,7 +104,7 @@ GeomProp::MeanGaussianResult BRepProp_Surface::MeanGaussian(const double theU,
const double theV,
const double theTol) const
{
if (!IsInitialized())
if (myPtr == nullptr)
{
return {};
}

View File

@@ -34,8 +34,7 @@ class TopoDS_Face;
//!
//! Usage:
//! @code
//! BRepProp_Surface aProp;
//! aProp.Initialize(myFace);
//! BRepProp_Surface aProp(myFace);
//! GeomProp::SurfaceNormalResult aNorm = aProp.Normal(0.5, 0.5, Precision::Confusion());
//! if (aNorm.IsDefined)
//! {
@@ -47,8 +46,21 @@ class BRepProp_Surface
public:
DEFINE_STANDARD_ALLOC
//! Default constructor - uninitialized state.
BRepProp_Surface() = default;
//! Construct from a TopoDS_Face.
//! Creates an internal BRepAdaptor_Surface (owning).
//! @param[in] theFace the face to evaluate
Standard_EXPORT BRepProp_Surface(const TopoDS_Face& theFace);
//! Construct from an existing BRepAdaptor_Surface.
//! The adaptor is referenced without copying (non-owning);
//! the caller must ensure the adaptor outlives this object.
//! @param[in] theSurface the adaptor to reference
Standard_EXPORT BRepProp_Surface(const BRepAdaptor_Surface& theSurface);
//! Construct from a handle to BRepAdaptor_Surface.
//! Shares ownership of the adaptor (no copy).
//! @param[in] theSurface handle to the adaptor
Standard_EXPORT BRepProp_Surface(const occ::handle<BRepAdaptor_Surface>& theSurface);
//! Non-copyable and non-movable.
BRepProp_Surface(const BRepProp_Surface&) = delete;
@@ -56,25 +68,6 @@ public:
BRepProp_Surface(BRepProp_Surface&&) = delete;
BRepProp_Surface& operator=(BRepProp_Surface&&) = delete;
//! Initialize from a TopoDS_Face.
//! Creates an internal BRepAdaptor_Surface (owning).
//! @param[in] theFace the face to evaluate
Standard_EXPORT void Initialize(const TopoDS_Face& theFace);
//! Initialize from an existing BRepAdaptor_Surface.
//! The adaptor is referenced without copying (non-owning);
//! the caller must ensure the adaptor outlives this object.
//! @param[in] theSurface the adaptor to reference
Standard_EXPORT void Initialize(const BRepAdaptor_Surface& theSurface);
//! Initialize from a handle to BRepAdaptor_Surface.
//! Shares ownership of the adaptor (no copy).
//! @param[in] theSurface handle to the adaptor
Standard_EXPORT void Initialize(const occ::handle<BRepAdaptor_Surface>& theSurface);
//! Returns true if properly initialized.
bool IsInitialized() const { return myPtr != nullptr; }
//! Returns the underlying adaptor.
const BRepAdaptor_Surface& Adaptor() const { return *myPtr; }
@@ -105,6 +98,19 @@ public:
double theV,
double theTol) const;
protected:
//! Initialize from a TopoDS_Face.
//! @param[in] theFace the face to evaluate
Standard_EXPORT void initialization(const TopoDS_Face& theFace);
//! Initialize from an existing BRepAdaptor_Surface (non-owning).
//! @param[in] theSurface the adaptor to reference
Standard_EXPORT void initialization(const BRepAdaptor_Surface& theSurface);
//! Initialize from a handle to BRepAdaptor_Surface.
//! @param[in] theSurface handle to the adaptor
Standard_EXPORT void initialization(const occ::handle<BRepAdaptor_Surface>& theSurface);
private:
occ::handle<BRepAdaptor_Surface> myOwned; //!< Owns the adaptor when created from TopoDS_Face.
const BRepAdaptor_Surface* myPtr = nullptr; //!< Non-owning pointer to the active adaptor.