Sketcher: GeometryFacade Improvements
=============================================== 1. Correct GeometryFacade getGeometry for const objects. 2. Modifications to avoid exceptions on the constructors. 3. Add default move constructor and move assignment operator. 4. Delete default copy constructor and copy assigment operator.
This commit is contained in:
@@ -46,11 +46,9 @@ GeometryFacade::GeometryFacade(): Geo(nullptr), OwnerGeo(false), SketchGeoExtens
|
||||
GeometryFacade::GeometryFacade(const Part::Geometry * geometry)
|
||||
: Geo(geometry), OwnerGeo(false)
|
||||
{
|
||||
if(geometry != nullptr)
|
||||
initExtension();
|
||||
else
|
||||
THROWM(Base::ValueError, "GeometryFacade initialized with Geometry null pointer");
|
||||
assert(geometry != nullptr); // This should never be nullptr, as this constructor is protected
|
||||
|
||||
initExtension();
|
||||
}
|
||||
|
||||
GeometryFacade::~GeometryFacade()
|
||||
@@ -104,8 +102,8 @@ void GeometryFacade::initExtension()
|
||||
|
||||
void GeometryFacade::initExtension() const
|
||||
{
|
||||
if(!Geo->hasExtension(SketchGeometryExtension::getClassTypeId()))
|
||||
THROWM(Base::ValueError, "GeometryConstFacade for const::Geometry without SketchGeometryExtension");
|
||||
// const Geometry without SketchGeometryExtension cannot initiliase a GeometryFacade
|
||||
assert(Geo->hasExtension(SketchGeometryExtension::getClassTypeId()));
|
||||
|
||||
auto ext = std::static_pointer_cast<const SketchGeometryExtension>(Geo->getExtension(SketchGeometryExtension::getClassTypeId()).lock());
|
||||
|
||||
|
||||
@@ -118,12 +118,25 @@ public: // Utility methods
|
||||
static bool getBlocked(const Part::Geometry * geometry);
|
||||
|
||||
public:
|
||||
// Explicit deletion to show intent (not that it is needed)
|
||||
GeometryFacade(const GeometryFacade&) = delete;
|
||||
GeometryFacade& operator=(const GeometryFacade&) = delete;
|
||||
|
||||
GeometryFacade(GeometryFacade&&) = default;
|
||||
GeometryFacade& operator=(GeometryFacade&&) = default;
|
||||
|
||||
~GeometryFacade();
|
||||
void setGeometry(Part::Geometry *geometry);
|
||||
|
||||
void setOwner(bool owner) {
|
||||
OwnerGeo = owner;
|
||||
}
|
||||
|
||||
// returns if the facade is the owner of the geometry pointer.
|
||||
bool getOwner() const {
|
||||
return OwnerGeo;
|
||||
}
|
||||
|
||||
// Geometry Extension Interface
|
||||
inline virtual long getId() const override {return getGeoExt()->getId();}
|
||||
virtual void setId(long id) override {getGeoExt()->setId(id);}
|
||||
@@ -160,7 +173,7 @@ public:
|
||||
std::is_base_of<Part::Geometry, typename std::decay<GeometryT>::type>::value
|
||||
>::type
|
||||
>
|
||||
GeometryT * getGeometry() const {return dynamic_cast<GeometryT *>(Geo);}
|
||||
const GeometryT * getGeometry() const {return dynamic_cast<const GeometryT *>(Geo);}
|
||||
|
||||
virtual PyObject *getPyObject(void) override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user