[TD] avoid memory leaks by using shared_ptr
TD geometry objects are sometimes double deleted. This change uses shared_ptr instead of raw pointers to manage deletions.
This commit is contained in:
committed by
WandererFan
parent
4c9191d489
commit
e91cc8e329
@@ -23,6 +23,8 @@
|
||||
#ifndef TECHDRAW_GEOMETRY_H
|
||||
#define TECHDRAW_GEOMETRY_H
|
||||
|
||||
#include <Mod/TechDraw/TechDrawGlobal.h>
|
||||
|
||||
#include <boost/uuid/uuid.hpp>
|
||||
#include <boost/uuid/uuid_io.hpp>
|
||||
#include <boost/uuid/uuid_generators.hpp>
|
||||
@@ -74,11 +76,28 @@ enum SourceType {
|
||||
CENTERLINE
|
||||
};
|
||||
|
||||
class BaseGeom;
|
||||
using BaseGeomPtr = std::shared_ptr<BaseGeom>;
|
||||
class Circle;
|
||||
using CirclePtr = std::shared_ptr<Circle>;
|
||||
class AOC;
|
||||
using AOCPtr = std::shared_ptr<AOC>;
|
||||
class Ellipse;
|
||||
using EllipsePtr = std::shared_ptr<Ellipse>;
|
||||
class AOE;
|
||||
using AOEPtr = std::shared_ptr<AOE>;
|
||||
class BezierSegment;
|
||||
using BezierSegmentPtr = std::shared_ptr<BezierSegment>;
|
||||
class BSpline;
|
||||
using BSplinePtr = std::shared_ptr<BSpline>;
|
||||
class Generic;
|
||||
using GenericPtr = std::shared_ptr<Generic>;
|
||||
|
||||
class TechDrawExport BaseGeom
|
||||
{
|
||||
public:
|
||||
BaseGeom();
|
||||
//BaseGeom(BaseGeom* bg); //do we need a copy constructor too?
|
||||
//BaseGeom(BaseGeomPtr bg); //do we need a copy constructor too?
|
||||
virtual ~BaseGeom() = default;
|
||||
|
||||
public:
|
||||
@@ -98,7 +117,6 @@ class TechDrawExport BaseGeom
|
||||
void setCosmeticTag(std::string t) { cosmeticTag = t; }
|
||||
|
||||
virtual std::string toString(void) const;
|
||||
/* virtual bool fromCSV(std::string s);*/
|
||||
virtual void Save(Base::Writer& w) const;
|
||||
virtual void Restore(Base::XMLReader& r);
|
||||
std::vector<Base::Vector3d> findEndPoints();
|
||||
@@ -108,11 +126,11 @@ class TechDrawExport BaseGeom
|
||||
std::vector<Base::Vector3d> getQuads();
|
||||
double minDist(Base::Vector3d p);
|
||||
Base::Vector3d nearPoint(Base::Vector3d p);
|
||||
Base::Vector3d nearPoint(const BaseGeom* p);
|
||||
static BaseGeom* baseFactory(TopoDS_Edge edge);
|
||||
Base::Vector3d nearPoint(const BaseGeomPtr p);
|
||||
static BaseGeomPtr baseFactory(TopoDS_Edge edge);
|
||||
static bool validateEdge(TopoDS_Edge edge);
|
||||
bool closed(void);
|
||||
BaseGeom* copy();
|
||||
BaseGeomPtr copy();
|
||||
std::string dump();
|
||||
|
||||
//Uniqueness
|
||||
@@ -125,12 +143,10 @@ protected:
|
||||
std::string cosmeticTag;
|
||||
|
||||
void createNewTag();
|
||||
/* void assignTag(const TechDraw::BaseGeom* bg);*/
|
||||
|
||||
boost::uuids::uuid tag;
|
||||
};
|
||||
|
||||
typedef std::vector<BaseGeom *> BaseGeomPtrVector; //obs?
|
||||
using BaseGeomPtrVector = std::vector<BaseGeomPtr>; //new style
|
||||
|
||||
class TechDrawExport Circle: public BaseGeom
|
||||
{
|
||||
@@ -138,11 +154,10 @@ class TechDrawExport Circle: public BaseGeom
|
||||
Circle(void);
|
||||
Circle(const TopoDS_Edge &e);
|
||||
Circle(Base::Vector3d center, double radius);
|
||||
~Circle() = default;
|
||||
virtual ~Circle() = default;
|
||||
|
||||
public:
|
||||
virtual std::string toString(void) const override;
|
||||
/* virtual bool fromCSV(std::string s) override;*/
|
||||
virtual void Save(Base::Writer& w) const override;
|
||||
virtual void Restore(Base::XMLReader& r) override;
|
||||
|
||||
@@ -155,7 +170,7 @@ class TechDrawExport Ellipse: public BaseGeom
|
||||
public:
|
||||
Ellipse(const TopoDS_Edge &e);
|
||||
Ellipse(Base::Vector3d c, double mnr, double mjr);
|
||||
~Ellipse() = default;
|
||||
virtual ~Ellipse() = default;
|
||||
|
||||
public:
|
||||
Base::Vector3d center;
|
||||
@@ -198,7 +213,6 @@ class TechDrawExport AOC: public Circle
|
||||
|
||||
public:
|
||||
virtual std::string toString(void) const override;
|
||||
/* virtual bool fromCSV(std::string s) override;*/
|
||||
virtual void Save(Base::Writer& w) const override;
|
||||
virtual void Restore(Base::XMLReader& r) override;
|
||||
|
||||
@@ -231,7 +245,6 @@ public:
|
||||
int poles;
|
||||
int degree;
|
||||
|
||||
//Base::Vector3d pnts[4];
|
||||
std::vector<Base::Vector3d> pnts;
|
||||
};
|
||||
|
||||
@@ -267,12 +280,11 @@ class TechDrawExport Generic: public BaseGeom
|
||||
~Generic() = default;
|
||||
|
||||
virtual std::string toString(void) const override;
|
||||
/* virtual bool fromCSV(std::string s) override;*/
|
||||
virtual void Save(Base::Writer& w) const override;
|
||||
virtual void Restore(Base::XMLReader& r) override;
|
||||
Base::Vector3d asVector(void);
|
||||
double slope(void);
|
||||
Base::Vector3d apparentInter(Generic* g);
|
||||
Base::Vector3d apparentInter(GenericPtr g);
|
||||
std::vector<Base::Vector3d> points;
|
||||
};
|
||||
|
||||
@@ -287,7 +299,7 @@ class TechDrawExport Wire
|
||||
|
||||
TopoDS_Wire toOccWire(void) const;
|
||||
void dump(std::string s);
|
||||
std::vector<BaseGeom *> geoms;
|
||||
BaseGeomPtrVector geoms;
|
||||
};
|
||||
|
||||
/// Simple Collection of geometric features based on BaseGeom inherited classes in order
|
||||
@@ -362,15 +374,15 @@ class TechDrawExport GeometryUtils
|
||||
* returns index[1:geoms.size()),reversed [true,false]
|
||||
*/
|
||||
static ReturnType nextGeom( Base::Vector3d atPoint,
|
||||
std::vector<TechDraw::BaseGeom*> geoms,
|
||||
std::vector<TechDraw::BaseGeomPtr> geoms,
|
||||
std::vector<bool> used,
|
||||
double tolerance );
|
||||
|
||||
//! return a vector of BaseGeom*'s in tail to nose order
|
||||
static std::vector<BaseGeom*> chainGeoms(std::vector<BaseGeom*> geoms);
|
||||
static TopoDS_Edge edgeFromGeneric(TechDraw::Generic* g);
|
||||
static TopoDS_Edge edgeFromCircle(TechDraw::Circle* c);
|
||||
static TopoDS_Edge edgeFromCircleArc(TechDraw::AOC* c);
|
||||
//! return a vector of BaseGeomPtr's in tail to nose order
|
||||
static BaseGeomPtrVector chainGeoms(BaseGeomPtrVector geoms);
|
||||
static TopoDS_Edge edgeFromGeneric(TechDraw::GenericPtr g);
|
||||
static TopoDS_Edge edgeFromCircle(TechDraw::CirclePtr c);
|
||||
static TopoDS_Edge edgeFromCircleArc(TechDraw::AOCPtr c);
|
||||
};
|
||||
|
||||
} //end namespace TechDraw
|
||||
|
||||
Reference in New Issue
Block a user