diff --git a/src/Mod/Sketcher/App/SketchGeometryExtension.cpp b/src/Mod/Sketcher/App/SketchGeometryExtension.cpp index d1c3867637..af9fa5d3fd 100644 --- a/src/Mod/Sketcher/App/SketchGeometryExtension.cpp +++ b/src/Mod/Sketcher/App/SketchGeometryExtension.cpp @@ -31,19 +31,21 @@ using namespace Sketcher; + //---------- Geometry Extension +constexpr std::array SketchGeometryExtension::internaltype2str; TYPESYSTEM_SOURCE(Sketcher::SketchGeometryExtension,Part::GeometryExtension) // scoped within the class, multithread ready std::atomic SketchGeometryExtension::_GeometryID; -SketchGeometryExtension::SketchGeometryExtension():Id(++SketchGeometryExtension::_GeometryID) +SketchGeometryExtension::SketchGeometryExtension():Id(++SketchGeometryExtension::_GeometryID),InternalGeometryType(InternalType::None) { } -SketchGeometryExtension::SketchGeometryExtension(long cid):Id(cid) +SketchGeometryExtension::SketchGeometryExtension(long cid):Id(cid),InternalGeometryType(InternalType::None) { } @@ -63,7 +65,8 @@ void SketchGeometryExtension::Save(Base::Writer &writer) const if(name.size() > 0) writer.Stream() << "\" name=\"" << name; - writer.Stream() << "\" id=\"" << Id << "\"/>" << std::endl; + writer.Stream() << "\" id=\"" << Id + << "\" internalGeometryType=\"" << (int) InternalGeometryType << "\"/>" << std::endl; } void SketchGeometryExtension::Restore(Base::XMLReader &reader) @@ -71,6 +74,7 @@ void SketchGeometryExtension::Restore(Base::XMLReader &reader) restoreNameAttribute(reader); Id = reader.getAttributeAsInteger("id"); + InternalGeometryType = (InternalType::InternalType) reader.getAttributeAsInteger("internalGeometryType"); } std::unique_ptr SketchGeometryExtension::copy(void) const @@ -78,6 +82,7 @@ std::unique_ptr SketchGeometryExtension::copy(void) con auto cpy = std::make_unique(); cpy->Id = this->Id; + cpy->InternalGeometryType = this->InternalGeometryType; cpy->setName(this->getName()); // Base Class diff --git a/src/Mod/Sketcher/App/SketchGeometryExtension.h b/src/Mod/Sketcher/App/SketchGeometryExtension.h index 1211d97cc2..45c47105ae 100644 --- a/src/Mod/Sketcher/App/SketchGeometryExtension.h +++ b/src/Mod/Sketcher/App/SketchGeometryExtension.h @@ -25,10 +25,29 @@ #include #include +#include +#include namespace Sketcher { + namespace InternalType { + enum InternalType { + None = 0, + EllipseMajorDiameter = 1, + EllipseMinorDiameter = 2, + EllipseFocus1 = 3, + EllipseFocus2 = 4, + HyperbolaMajor = 5, + HyperbolaMinor = 6, + HyperbolaFocus = 7, + ParabolaFocus = 8, + BSplineControlPoint = 9, + BSplineKnotPoint = 10, + NumInternalGeometryType // Must be the last + }; + } + class ISketchGeometryExtension { @@ -36,12 +55,16 @@ public: // Identification information virtual long getId() const = 0; virtual void setId(long id) = 0; + + virtual InternalType::InternalType getInternalType() const = 0; + virtual void setInternalType(InternalType::InternalType type) = 0; }; class SketcherExport SketchGeometryExtension : public Part::GeometryExtension, private ISketchGeometryExtension { TYPESYSTEM_HEADER_WITH_OVERRIDE(); public: + SketchGeometryExtension(); SketchGeometryExtension(long cid); virtual ~SketchGeometryExtension() override = default; @@ -58,11 +81,17 @@ public: virtual long getId() const override {return Id;} virtual void setId(long id) override {Id = id;} + virtual InternalType::InternalType getInternalType() const override {return InternalGeometryType;} + virtual void setInternalType(InternalType::InternalType type) override {InternalGeometryType = type;} + + constexpr static std::array internaltype2str {{ "None", "EllipseMajorDiameter", "EllipseMinorDiameter","EllipseFocus1", "EllipseFocus2", "HyperbolaMajor", "HyperbolaMinor", "HyperbolaFocus", "ParabolaFocus", "BSplineControlPoint", "BSplineKnotPoint" }}; + private: SketchGeometryExtension(const SketchGeometryExtension&) = default; private: - long Id; + long Id; + InternalType::InternalType InternalGeometryType; private: static std::atomic _GeometryID; diff --git a/src/Mod/Sketcher/App/SketchGeometryExtensionPy.xml b/src/Mod/Sketcher/App/SketchGeometryExtensionPy.xml index 5ace89f320..f3cf557101 100644 --- a/src/Mod/Sketcher/App/SketchGeometryExtensionPy.xml +++ b/src/Mod/Sketcher/App/SketchGeometryExtensionPy.xml @@ -23,5 +23,13 @@ + + + + returns the Id of the SketchGeometryExtension. + + + + diff --git a/src/Mod/Sketcher/App/SketchGeometryExtensionPyImp.cpp b/src/Mod/Sketcher/App/SketchGeometryExtensionPyImp.cpp index 8e7bcaa6e8..5d2af73898 100644 --- a/src/Mod/Sketcher/App/SketchGeometryExtensionPyImp.cpp +++ b/src/Mod/Sketcher/App/SketchGeometryExtensionPyImp.cpp @@ -89,6 +89,39 @@ void SketchGeometryExtensionPy::setId(Py::Long Id) this->getSketchGeometryExtensionPtr()->setId(long(Id)); } +Py::String SketchGeometryExtensionPy::getInternalType(void) const +{ + int internaltypeindex = (int)this->getSketchGeometryExtensionPtr()->getInternalType(); + + if(internaltypeindex >= InternalType::NumInternalGeometryType) + throw Py::NotImplementedError("String name of enum not implemented"); + + std::string typestr = this->getSketchGeometryExtensionPtr()->internaltype2str[internaltypeindex]; + + return Py::String(typestr); +} + +void SketchGeometryExtensionPy::setInternalType(Py::String arg) +{ + std::string argstr = arg; + + auto pos = std::find_if(this->getSketchGeometryExtensionPtr()->internaltype2str.begin(), + getSketchGeometryExtensionPtr()->internaltype2str.end(), + [argstr](const char * val) { + return strcmp(val,argstr.c_str())==0;} + ); + + if( pos != getSketchGeometryExtensionPtr()->internaltype2str.end()) { + int index = std::distance( getSketchGeometryExtensionPtr()->internaltype2str.begin(), pos ); + + this->getSketchGeometryExtensionPtr()->setInternalType((InternalType::InternalType)index); + return; + } + + throw Py::ValueError("Argument is not a valid internal geometry type."); +} + + PyObject *SketchGeometryExtensionPy::getCustomAttributes(const char* /*attr*/) const { return 0;