Part/Sketcher: change geometry extensions APIs for topo naming support
This commit is contained in:
@@ -338,9 +338,7 @@ void Geometry::Restore(Base::XMLReader &reader)
|
||||
|
||||
auto ext = std::static_pointer_cast<GeometryMigrationExtension>(this->getExtension(GeometryMigrationExtension::getClassTypeId()).lock());
|
||||
|
||||
ext->setMigrationType(GeometryMigrationExtension::Construction);
|
||||
ext->setConstruction(construction);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,6 +42,11 @@ void GeometryMigrationExtension::copyAttributes(Part::GeometryExtension * cpy) c
|
||||
Part::GeometryExtension::copyAttributes(cpy);
|
||||
static_cast<GeometryMigrationExtension *>(cpy)->ConstructionState = this->ConstructionState;
|
||||
static_cast<GeometryMigrationExtension *>(cpy)->GeometryMigrationFlags = this->GeometryMigrationFlags;
|
||||
|
||||
static_cast<GeometryMigrationExtension *>(cpy)->Id = this->Id;
|
||||
static_cast<GeometryMigrationExtension *>(cpy)->Flags = this->Flags;
|
||||
static_cast<GeometryMigrationExtension *>(cpy)->Ref = this->Ref;
|
||||
static_cast<GeometryMigrationExtension *>(cpy)->RefIndex = this->RefIndex;
|
||||
}
|
||||
|
||||
std::unique_ptr<Part::GeometryExtension> GeometryMigrationExtension::copy(void) const
|
||||
|
||||
@@ -48,6 +48,8 @@ public:
|
||||
enum MigrationType {
|
||||
None = 0,
|
||||
Construction = 1,
|
||||
GeometryId = 2,
|
||||
ExternalReference = 3,
|
||||
NumMigrationType // Must be the last
|
||||
};
|
||||
|
||||
@@ -60,12 +62,26 @@ public:
|
||||
|
||||
|
||||
virtual bool getConstruction() const {return ConstructionState;}
|
||||
virtual void setConstruction(bool construction) {ConstructionState = construction;}
|
||||
virtual void setConstruction(bool construction)
|
||||
{ConstructionState = construction; setMigrationType(Construction);}
|
||||
|
||||
long getId() const {return Id;}
|
||||
void setId(long id) {Id = id; setMigrationType(GeometryId);}
|
||||
|
||||
const std::string &getRef() const {return Ref;}
|
||||
int getRefIndex() const {return RefIndex;}
|
||||
unsigned long getFlags() const {return Flags;}
|
||||
void setReference(const char *ref, int index, unsigned long flags) {
|
||||
Ref = ref ? ref : "";
|
||||
RefIndex = index;
|
||||
Flags = flags;
|
||||
setMigrationType(ExternalReference);
|
||||
}
|
||||
|
||||
virtual bool testMigrationType(int flag) const { return GeometryMigrationFlags.test((size_t)(flag)); };
|
||||
virtual void setMigrationType(int flag, bool v=true) { GeometryMigrationFlags.set((size_t)(flag), v); };
|
||||
|
||||
protected:
|
||||
virtual void setMigrationType(int flag, bool v=true) { GeometryMigrationFlags.set((size_t)(flag), v); };
|
||||
virtual void copyAttributes(Part::GeometryExtension * cpy) const override;
|
||||
|
||||
private:
|
||||
@@ -75,7 +91,10 @@ private:
|
||||
using MigrationTypeFlagType = std::bitset<32>;
|
||||
MigrationTypeFlagType GeometryMigrationFlags;
|
||||
bool ConstructionState;
|
||||
|
||||
long Id = 0;
|
||||
int RefIndex = -1;
|
||||
unsigned long Flags = 0;
|
||||
std::string Ref;
|
||||
};
|
||||
|
||||
} //namespace Part
|
||||
|
||||
@@ -38,6 +38,8 @@ public:
|
||||
// START_CREDIT_BLOCK: Credit under LGPL for this block to Zheng, Lei (realthunder) <[email protected]>
|
||||
virtual bool testFlag(int flag) const = 0;
|
||||
virtual void setFlag(int flag, bool v=true) = 0;
|
||||
virtual unsigned long getFlags() const = 0;
|
||||
virtual void setFlags(unsigned long flags) = 0;
|
||||
// END_CREDIT_BLOCK: Credit under LGPL for this block to Zheng, Lei (realthunder) <[email protected]>
|
||||
|
||||
virtual bool isClear() const = 0;
|
||||
@@ -45,6 +47,9 @@ public:
|
||||
|
||||
virtual const std::string& getRef() const = 0;
|
||||
virtual void setRef(const std::string & ref) = 0;
|
||||
|
||||
virtual int getRefIndex() const = 0;
|
||||
virtual void setRefIndex(int index) = 0;
|
||||
};
|
||||
|
||||
class SketcherExport ExternalGeometryExtension : public Part::GeometryPersistenceExtension, private ISketchExternalGeometryExtension
|
||||
@@ -75,6 +80,8 @@ public:
|
||||
// START_CREDIT_BLOCK: Credit under LGPL for this block to Zheng, Lei (realthunder) <[email protected]>
|
||||
virtual bool testFlag(int flag) const override { return Flags.test((size_t)(flag)); }
|
||||
virtual void setFlag(int flag, bool v=true) override { Flags.set((size_t)(flag),v); }
|
||||
virtual unsigned long getFlags() const override { return Flags.to_ulong(); }
|
||||
virtual void setFlags(unsigned long flags) override { Flags = flags; }
|
||||
// END_CREDIT_BLOCK: Credit under LGPL for this block to Zheng, Lei (realthunder) <[email protected]>
|
||||
|
||||
virtual bool isClear() const override {return Flags.none();}
|
||||
@@ -83,6 +90,9 @@ public:
|
||||
virtual const std::string& getRef() const override {return Ref;}
|
||||
virtual void setRef(const std::string & ref) override {Ref = ref;}
|
||||
|
||||
virtual int getRefIndex() const override {return RefIndex;}
|
||||
virtual void setRefIndex(int index) override {RefIndex = index;}
|
||||
|
||||
static bool getFlagsFromName(std::string str, ExternalGeometryExtension::Flag &flag);
|
||||
|
||||
protected:
|
||||
@@ -97,6 +107,7 @@ private:
|
||||
using FlagType = std::bitset<32>;
|
||||
// START_CREDIT_BLOCK: Credit under LGPL for this block to Zheng, Lei (realthunder) <[email protected]>
|
||||
std::string Ref;
|
||||
int RefIndex = -1;
|
||||
FlagType Flags;
|
||||
// END_CREDIT_BLOCK: Credit under LGPL for this block to Zheng, Lei (realthunder) <[email protected]>
|
||||
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
|
||||
#include "ExternalGeometryFacadePy.h"
|
||||
|
||||
FC_LOG_LEVEL_INIT("Sketch", true, true);
|
||||
|
||||
using namespace Sketcher;
|
||||
|
||||
TYPESYSTEM_SOURCE(Sketcher::ExternalGeometryFacade,Base::BaseClass)
|
||||
@@ -84,14 +86,14 @@ void ExternalGeometryFacade::initExtensions()
|
||||
|
||||
getGeo()->setExtension(std::make_unique<SketchGeometryExtension>()); // Create getExtension
|
||||
|
||||
Base::Console().Warning("%s\nSketcher External Geometry without Geometry Extension: %s \n", boost::uuids::to_string(Geo->getTag()).c_str());
|
||||
// Base::Console().Warning("%s\nSketcher External Geometry without Geometry Extension: %s \n", boost::uuids::to_string(Geo->getTag()).c_str());
|
||||
}
|
||||
|
||||
if(!Geo->hasExtension(ExternalGeometryExtension::getClassTypeId())) {
|
||||
|
||||
getGeo()->setExtension(std::make_unique<ExternalGeometryExtension>()); // Create getExtension
|
||||
|
||||
Base::Console().Warning("%s\nSketcher External Geometry without ExternalGeometryExtension: %s \n", boost::uuids::to_string(Geo->getTag()).c_str());
|
||||
// Base::Console().Warning("%s\nSketcher External Geometry without ExternalGeometryExtension: %s \n", boost::uuids::to_string(Geo->getTag()).c_str());
|
||||
}
|
||||
|
||||
SketchGeoExtension =
|
||||
@@ -140,6 +142,21 @@ void ExternalGeometryFacade::copyId(const Part::Geometry * src, Part::Geometry *
|
||||
gfdst->setId(gfsrc->getId());
|
||||
}
|
||||
|
||||
void ExternalGeometryFacade::copyFlags(const Part::Geometry * src, Part::Geometry * dst)
|
||||
{
|
||||
auto gfsrc = ExternalGeometryFacade::getFacade(src);
|
||||
auto gfdst = ExternalGeometryFacade::getFacade(dst);
|
||||
gfdst->setFlags(gfsrc->getFlags());
|
||||
}
|
||||
|
||||
void ExternalGeometryFacade::setRef(const std::string &ref)
|
||||
{
|
||||
if (ref.size() && getId() < 0)
|
||||
FC_ERR("Cannot set reference on root geometries");
|
||||
else
|
||||
getExternalGeoExt()->setRef(ref);
|
||||
}
|
||||
|
||||
PyObject * ExternalGeometryFacade::getPyObject(void)
|
||||
{
|
||||
return new ExternalGeometryFacadePy(new ExternalGeometryFacade(this->Geo));
|
||||
|
||||
@@ -66,6 +66,7 @@ public: // Factory methods
|
||||
public: // Utility methods
|
||||
static void ensureSketchGeometryExtensions(Part::Geometry * geometry);
|
||||
static void copyId(const Part::Geometry * src, Part::Geometry * dst);
|
||||
static void copyFlags(const Part::Geometry * src, Part::Geometry * dst);
|
||||
|
||||
public:
|
||||
void setGeometry(Part::Geometry *geometry);
|
||||
@@ -74,11 +75,17 @@ public:
|
||||
virtual bool testFlag(int flag) const override { return getExternalGeoExt()->testFlag(flag); }
|
||||
virtual void setFlag(int flag, bool v=true) override { getExternalGeoExt()->setFlag(flag, v); }
|
||||
|
||||
virtual unsigned long getFlags() const override { return getExternalGeoExt()->getFlags(); }
|
||||
virtual void setFlags(unsigned long flags) override { getExternalGeoExt()->setFlags(flags); }
|
||||
|
||||
virtual bool isClear() const override {return getExternalGeoExt()->isClear();}
|
||||
virtual size_t flagSize() const override {return getExternalGeoExt()->flagSize();}
|
||||
|
||||
virtual const std::string& getRef() const override {return getExternalGeoExt()->getRef();}
|
||||
virtual void setRef(const std::string & ref) override {getExternalGeoExt()->setRef(ref);}
|
||||
virtual void setRef(const std::string & ref) override;
|
||||
|
||||
virtual int getRefIndex() const override {return getExternalGeoExt()->getRefIndex();}
|
||||
virtual void setRefIndex(int index) override {getExternalGeoExt()->setRefIndex(index);}
|
||||
|
||||
/** GeometryExtension Interface **/
|
||||
inline virtual long getId() const override {return getGeoExt()->getId();}
|
||||
|
||||
@@ -136,6 +136,18 @@ void GeometryFacade::copyId(const Part::Geometry * src, Part::Geometry * dst)
|
||||
gfdst->setId(gfsrc->getId());
|
||||
}
|
||||
|
||||
int GeometryFacade::getId(const Part::Geometry * geometry)
|
||||
{
|
||||
auto gf = GeometryFacade::getFacade(geometry);
|
||||
return gf->getId();
|
||||
}
|
||||
|
||||
void GeometryFacade::setId(Part::Geometry * geometry, int id)
|
||||
{
|
||||
auto gf = GeometryFacade::getFacade(geometry);
|
||||
return gf->setId(id);
|
||||
}
|
||||
|
||||
bool GeometryFacade::getConstruction(const Part::Geometry * geometry)
|
||||
{
|
||||
throwOnNullPtr(geometry);
|
||||
|
||||
@@ -124,6 +124,8 @@ public: // Utility methods
|
||||
static void setConstruction(Part::Geometry * geometry, bool construction);
|
||||
static bool isInternalType(const Part::Geometry * geometry, InternalType::InternalType type);
|
||||
static bool getBlocked(const Part::Geometry * geometry);
|
||||
static int getId(const Part::Geometry * geometry);
|
||||
static void setId(Part::Geometry * geometry, int id);
|
||||
|
||||
public:
|
||||
// Explicit deletion to show intent (not that it is needed)
|
||||
|
||||
@@ -70,22 +70,32 @@ void SketchGeometryExtension::restoreAttributes(Base::XMLReader &reader)
|
||||
Part::GeometryPersistenceExtension::restoreAttributes(reader);
|
||||
|
||||
if(reader.hasAttribute("id"))
|
||||
Id = reader.getAttributeAsInteger("id");
|
||||
this->setId(reader.getAttributeAsInteger("id"));
|
||||
|
||||
InternalGeometryType = (InternalType::InternalType) reader.getAttributeAsInteger("internalGeometryType");
|
||||
InternalGeometryType = (InternalType::InternalType)
|
||||
reader.getAttributeAsInteger("internalGeometryType", "0");
|
||||
|
||||
GeometryModeFlags = GeometryModeFlagType(reader.getAttribute("geometryModeFlags"));
|
||||
if (reader.hasAttribute("geometryModeFlags"))
|
||||
GeometryModeFlags = GeometryModeFlagType(
|
||||
reader.getAttribute("geometryModeFlags"));
|
||||
|
||||
if(reader.hasAttribute("geometryLayer"))
|
||||
GeometryLayer = reader.getAttributeAsInteger("geometryLayer");
|
||||
}
|
||||
|
||||
void SketchGeometryExtension::setId(long id)
|
||||
{
|
||||
Id = id;
|
||||
long v = _GeometryID;
|
||||
while(v < Id && !_GeometryID.compare_exchange_weak(v, id))
|
||||
;
|
||||
}
|
||||
|
||||
void SketchGeometryExtension::saveAttributes(Base::Writer &writer) const
|
||||
{
|
||||
Part::GeometryPersistenceExtension::saveAttributes(writer);
|
||||
|
||||
writer.Stream() // << "\" id=\"" << Id // This is removed as the stored Id is not used and it may interfere with RT's future implementation
|
||||
writer.Stream() << "\" id=\"" << Id
|
||||
<< "\" internalGeometryType=\"" << (int) InternalGeometryType
|
||||
<< "\" geometryModeFlags=\"" << GeometryModeFlags.to_string()
|
||||
<< "\" geometryLayer=\"" << GeometryLayer;
|
||||
|
||||
@@ -91,7 +91,7 @@ public:
|
||||
virtual PyObject *getPyObject(void) override;
|
||||
|
||||
virtual long getId() const override {return Id;}
|
||||
virtual void setId(long id) override {Id = id;}
|
||||
virtual void setId(long id) override;
|
||||
|
||||
virtual InternalType::InternalType getInternalType() const override {return InternalGeometryType;}
|
||||
virtual void setInternalType(InternalType::InternalType type) override {InternalGeometryType = type;}
|
||||
|
||||
Reference in New Issue
Block a user