From 16b8d99d623eb568226496296758c73b4e0cd4b9 Mon Sep 17 00:00:00 2001 From: bgbsww Date: Thu, 18 Jul 2024 09:25:54 -0400 Subject: [PATCH] Toponaming: refactor getExportElementName to separate method --- src/Mod/Part/App/PartFeature.cpp | 15 ++++++++------- src/Mod/Part/App/PartFeature.h | 11 +++++++++++ .../Sketcher/App/ExternalGeometryExtension.cpp | 3 --- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/Mod/Part/App/PartFeature.cpp b/src/Mod/Part/App/PartFeature.cpp index 60fad39631..0f2851bee6 100644 --- a/src/Mod/Part/App/PartFeature.cpp +++ b/src/Mod/Part/App/PartFeature.cpp @@ -148,8 +148,12 @@ std::pair Feature::getElementName(const char* name, if (!prop) { return App::GeoFeature::getElementName(name, type); } + return getExportElementName(prop->getShape(), name); +} - TopoShape shape = prop->getShape(); +std::pair Feature::getExportElementName(TopoShape shape, + const char* name) const +{ Data::MappedElement mapped = shape.getElementName(name); auto res = shape.shapeTypeAndIndex(mapped.index); static const int MinLowerTopoNames = 3; @@ -259,10 +263,10 @@ std::pair Feature::getElementName(const char* name, // disambiguation. auto it = std::find(ancestors.begin(), ancestors.end(), res.second); if (it == ancestors.end()) { - assert(0 && "ancestor not found"); // this shouldn't happened + assert(0 && "ancestor not found"); // this shouldn't happen } else { - op = Data::POSTFIX_TAG + std::to_string(it - ancestors.begin()); + op = Data::POSTFIX_INDEX + std::to_string(it - ancestors.begin()); } } @@ -284,10 +288,8 @@ std::pair Feature::getElementName(const char* name, } } } - return App::GeoFeature::_getElementName(name, mapped); } - - if (!res.second && mapped.name) { + else if (!res.second && mapped.name) { const char* dot = strchr(name, '.'); if (dot) { ++dot; @@ -350,7 +352,6 @@ std::pair Feature::getElementName(const char* name, if (ancestors.size() == 1) { idxName.setIndex(ancestors.front()); mapped.index = idxName; - return App::GeoFeature::_getElementName(name, mapped); } } } diff --git a/src/Mod/Part/App/PartFeature.h b/src/Mod/Part/App/PartFeature.h index 4387ccdd74..0288eded67 100644 --- a/src/Mod/Part/App/PartFeature.h +++ b/src/Mod/Part/App/PartFeature.h @@ -171,6 +171,17 @@ protected: void registerElementCache(const std::string &prefix, PropertyPartShape *prop); + /** Helper function to obtain mapped and indexed element name from a shape + * @params shape: source shape + * @param name: the input name, can be either mapped or indexed name + * @return Returns both the indexed and mapped name + * + * If the 'name' referencing a non-primary shape type, i.e. not + * Vertex/Edge/Face, this function will auto generate a name from primary + * sub-shapes. + */ + std::pair getExportElementName(TopoShape shape, const char *name) const; + /** * Build a history of changes * MakeShape: The operation that created the changes, e.g. BRepAlgoAPI_Common diff --git a/src/Mod/Sketcher/App/ExternalGeometryExtension.cpp b/src/Mod/Sketcher/App/ExternalGeometryExtension.cpp index e4437f8fcd..44a0eaa9c7 100644 --- a/src/Mod/Sketcher/App/ExternalGeometryExtension.cpp +++ b/src/Mod/Sketcher/App/ExternalGeometryExtension.cpp @@ -59,10 +59,7 @@ void ExternalGeometryExtension::restoreAttributes(Base::XMLReader& reader) void ExternalGeometryExtension::saveAttributes(Base::Writer& writer) const { Part::GeometryPersistenceExtension::saveAttributes(writer); - // For compatibility with upstream FreeCAD, always save 'Ref' and 'Flags'. - // if (Ref.size()) writer.Stream() << "\" Ref=\"" << Base::Persistence::encodeAttribute(Ref); - // if (Flags.any()) writer.Stream() << "\" Flags=\"" << Flags.to_ulong(); if (RefIndex >= 0) { writer.Stream() << "\" RefIndex=\"" << RefIndex;