From 6acf5a00e6ad9f43e859ee541a0a597d78aabe2c Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Wed, 10 Apr 2024 10:29:57 -0400 Subject: [PATCH] Toponaming/Part: Transfer in python ElementMapVersion --- src/App/DocumentObject.cpp | 18 ++++++++++++++++++ src/App/DocumentObject.h | 14 ++++++++++++++ src/App/DocumentObjectPy.xml | 7 +++++++ src/App/DocumentObjectPyImp.cpp | 16 ++++++++++++++++ src/App/GeoFeaturePy.xml | 6 ++++++ src/App/GeoFeaturePyImp.cpp | 5 +++++ 6 files changed, 66 insertions(+) diff --git a/src/App/DocumentObject.cpp b/src/App/DocumentObject.cpp index 5fa4e91c93..ad2bb4bacb 100644 --- a/src/App/DocumentObject.cpp +++ b/src/App/DocumentObject.cpp @@ -1304,6 +1304,24 @@ bool DocumentObject::adjustRelativeLinks( return touched; } +std::string DocumentObject::getElementMapVersion(const App::Property* _prop, bool restored) const +{ + auto prop = Base::freecad_dynamic_cast(_prop); + if (!prop) { + return std::string(); + } + return prop->getElementMapVersion(restored); +} + +bool DocumentObject::checkElementMapVersion(const App::Property* _prop, const char* ver) const +{ + auto prop = Base::freecad_dynamic_cast(_prop); + if (!prop) { + return false; + } + return prop->checkElementMapVersion(ver); +} + const std::string &DocumentObject::hiddenMarker() { static std::string marker("!hide"); return marker; diff --git a/src/App/DocumentObject.h b/src/App/DocumentObject.h index 4cc24107d3..7052f92d7e 100644 --- a/src/App/DocumentObject.h +++ b/src/App/DocumentObject.h @@ -300,6 +300,20 @@ public: bool testIfLinkDAGCompatible(App::PropertyLinkSubList &linksTo) const; bool testIfLinkDAGCompatible(App::PropertyLinkSub &linkTo) const; + /** Return the element map version of the geometry data stored in the given property + * + * @param prop: the geometry property to query for element map version + * @param restored: whether to query for the restored element map version. + * In case of version upgrade, the restored version may + * be different from the current version. + * + * @return Return the element map version string. + */ + virtual std::string getElementMapVersion(const App::Property *prop, bool restored=false) const; + + /// Return true to signal re-generation of geometry element names + virtual bool checkElementMapVersion(const App::Property *prop, const char *ver) const; + public: /** mustExecute * We call this method to check if the object was modified to diff --git a/src/App/DocumentObjectPy.xml b/src/App/DocumentObjectPy.xml index 8792376ad9..7424fc9a58 100644 --- a/src/App/DocumentObjectPy.xml +++ b/src/App/DocumentObjectPy.xml @@ -225,6 +225,13 @@ Return tuple(obj,newElementName,oldElementName) adjustRelativeLinks(parent,recursive=True) -- auto correct potential cyclic dependencies + + + + getElementMapVersion(property_name): return element map version of a given geometry property + + + A list of all objects this object links to. diff --git a/src/App/DocumentObjectPyImp.cpp b/src/App/DocumentObjectPyImp.cpp index 4b3282a946..07344d2e93 100644 --- a/src/App/DocumentObjectPyImp.cpp +++ b/src/App/DocumentObjectPyImp.cpp @@ -745,6 +745,22 @@ PyObject* DocumentObjectPy::getPathsByOutList(PyObject *args) } } +PyObject* DocumentObjectPy::getElementMapVersion(PyObject* args) +{ + const char* name; + PyObject* restored = Py_False; + if (!PyArg_ParseTuple(args, "s|O", &name, &restored)) { + return NULL; + } + + Property* prop = getDocumentObjectPtr()->getPropertyByName(name); + if (!prop) { + throw Py::ValueError("property not found"); + } + return Py::new_reference_to( + Py::String(getDocumentObjectPtr()->getElementMapVersion(prop, Base::asBoolean(restored)))); +} + PyObject *DocumentObjectPy::getCustomAttributes(const char* ) const { return nullptr; diff --git a/src/App/GeoFeaturePy.xml b/src/App/GeoFeaturePy.xml index 83726bf70a..aeaefe7a4e 100644 --- a/src/App/GeoFeaturePy.xml +++ b/src/App/GeoFeaturePy.xml @@ -58,6 +58,12 @@ If an object has no such property then None is returned. Unlike to getPropertyNameOfGeometry this function returns the geometry, not its name. + + + Element map version + + + diff --git a/src/App/GeoFeaturePyImp.cpp b/src/App/GeoFeaturePyImp.cpp index ec2af688df..26a08a9f2d 100644 --- a/src/App/GeoFeaturePyImp.cpp +++ b/src/App/GeoFeaturePyImp.cpp @@ -93,3 +93,8 @@ int GeoFeaturePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) { return 0; } + +Py::String GeoFeaturePy::getElementMapVersion() const { + return Py::String(getGeoFeaturePtr()->getElementMapVersion( + getGeoFeaturePtr()->getPropertyOfGeometry())); +}