From 40d23c26390ddb50b03fa597242135ce9de6edab Mon Sep 17 00:00:00 2001 From: bgbsww Date: Thu, 15 Aug 2024 23:41:00 -0400 Subject: [PATCH] Toponaming: Support disabling hashing; getting element history --- src/App/Document.cpp | 17 +++++++++--- src/App/Document.h | 2 ++ src/Mod/Part/App/PartFeaturePy.xml | 15 +++++++++++ src/Mod/Part/App/PartFeaturePyImp.cpp | 39 +++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 3 deletions(-) diff --git a/src/App/Document.cpp b/src/App/Document.cpp index f83c0d4343..91b330bdb8 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -757,6 +757,12 @@ void Document::onChanged(const Property* prop) // recursive call of onChanged() this->Uid.setValue(id); } + } else if(prop == &UseHasher) { + for(auto obj : d->objectArray) { + auto geofeature = dynamic_cast(obj); + if(geofeature && geofeature->getPropertyOfGeometry()) + geofeature->enforceRecompute(); + } } } @@ -864,6 +870,8 @@ Document::Document(const char* documentName) 0, PropertyType(Prop_None), "Whether to show hidden object items in the tree view"); + ADD_PROPERTY_TYPE(UseHasher,(true), 0,PropertyType(Prop_Hidden), + "Whether to use hasher on topological naming"); // this creates and sets 'TransientDir' in onChanged() ADD_PROPERTY_TYPE(TransientDir, @@ -1074,10 +1082,13 @@ std::pair Document::addStringHasher(const StringHasherRef & hasher) co } StringHasherRef Document::getStringHasher(int idx) const { - if(idx<0) { - return d->Hasher; - } StringHasherRef hasher; + if(idx<0) { + if(UseHasher.getValue()) { + return d->Hasher; + } + return hasher; + } auto it = d->hashers.right.find(idx); if(it == d->hashers.right.end()) { hasher = new StringHasher; diff --git a/src/App/Document.h b/src/App/Document.h index 0bb83361c5..c178df04e9 100644 --- a/src/App/Document.h +++ b/src/App/Document.h @@ -117,6 +117,8 @@ public: PropertyString TipName; /// Whether to show hidden items in TreeView PropertyBool ShowHidden; + /// Whether to use hasher on topological naming + PropertyBool UseHasher; //@} /** @name Signals of the document */ diff --git a/src/Mod/Part/App/PartFeaturePy.xml b/src/Mod/Part/App/PartFeaturePy.xml index 21c361bb54..34a67570c6 100644 --- a/src/Mod/Part/App/PartFeaturePy.xml +++ b/src/Mod/Part/App/PartFeaturePy.xml @@ -13,5 +13,20 @@ This is the father of all shape object classes + + + +getElementHistory(name,recursive=True,sameType=False,showName=False) - returns the element mapped name history + +name: mapped element name belonging to this shape +recursive: if True, then track back the history through other objects till the origin +sameType: if True, then stop trace back when element type changes +showName: if False, return the owner object, or else return a tuple of object name and label + +If not recursive, then return tuple(sourceObject, sourceElementName, [intermediateNames...]), +otherwise return a list of tuple. + + + diff --git a/src/Mod/Part/App/PartFeaturePyImp.cpp b/src/Mod/Part/App/PartFeaturePyImp.cpp index 7398ad44d8..d338ffe6aa 100644 --- a/src/Mod/Part/App/PartFeaturePyImp.cpp +++ b/src/Mod/Part/App/PartFeaturePyImp.cpp @@ -37,6 +37,45 @@ std::string PartFeaturePy::representation() const return {""}; } +PyObject *PartFeaturePy::getElementHistory(PyObject *args, PyObject *kwds) { + const char *name; + PyObject *recursive = Py_True; + PyObject *sameType = Py_False; + PyObject *showName = Py_False; + static char *kwlist[] = {"elementName", "recursive", "sameType", "showName", nullptr}; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|OOO", kwlist, &name, &recursive, &sameType, &showName)) + return {}; + + auto feature = getFeaturePtr(); + Py::List list; + bool showObjName = PyObject_IsTrue(showName); + PY_TRY { + std::string tmp; + for (auto &history: Feature::getElementHistory(feature, name, + PyObject_IsTrue(recursive), PyObject_IsTrue(sameType))) { + Py::Tuple ret(3); + if (history.obj) { + if (showObjName) { + ret.setItem(0, Py::TupleN(Py::String(history.obj->getFullName()), + Py::String(history.obj->Label.getValue()))); + } else + ret.setItem(0, Py::Object(history.obj->getPyObject(), true)); + } else + ret.setItem(0, Py::Int(history.tag)); + tmp.clear(); + ret.setItem(1, Py::String(history.element.appendToBuffer(tmp))); + Py::List intermedates; + for (auto &h: history.intermediates) { + tmp.clear(); + intermedates.append(Py::String(h.appendToBuffer(tmp))); + } + ret.setItem(2, intermedates); + list.append(ret); + } + return Py::new_reference_to(list); + } PY_CATCH; +} + PyObject *PartFeaturePy::getCustomAttributes(const char* ) const { return nullptr;