diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index f58070ef83b0..31483dc8d822 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -9551,14 +9551,28 @@ void SketchObject::setExpression(const App::ObjectIdentifier& path, } } +const std::string &SketchObject::internalPrefix() +{ + static std::string _prefix("Internal"); + return _prefix; +} + +const char *SketchObject::convertInternalName(const char *name) +{ + if (name && boost::starts_with(name, internalPrefix())) + return name + internalPrefix().size(); + return nullptr; +} + std::pair SketchObject::getElementName( const char *name, ElementNameType type) const { // Todo: Toponaming Project March 2024: This method override breaks the sketcher - selection and deletion // of constraints ceases to work. See #13169. We need to prove that this works before - // enabling it. For now, bypass it. + // enabling it. This appears to be okay now. +#ifndef FC_USE_TNP_FIX return Part2DObject::getElementName(name,type); - +#endif std::pair ret; if(!name) return ret; @@ -9566,30 +9580,57 @@ std::pair SketchObject::getElementName( return Part2DObject::getElementName(name,type); const char *mapped = Data::isMappedElement(name); + Data::IndexedName index = checkSubName(name); + index.appendToStringBuffer(ret.second); + if (auto realName = convertInternalName(ret.second.c_str())) { + Data::MappedElement mappedElement; +// Todo: Do we need to add the InternalShape? +// if (mapped) +// mappedElement = InternalShape.getShape().getElementName(name); +// else if (type == ElementNameType::Export) +// ret.first = getExportElementName(InternalShape.getShape(), realName).first; +// else +// mappedElement = InternalShape.getShape().getElementName(realName); + + if (mapped || type != ElementNameType::Export) { + if (mappedElement.index) { + ret.second = internalPrefix(); + mappedElement.index.appendToStringBuffer(ret.second); + } + if (mappedElement.name) { + ret.first = Data::ComplexGeoData::elementMapPrefix(); + mappedElement.name.appendToBuffer(ret.first); + } + else if (mapped) + ret.first = name; + } + + if (ret.first.size()) { + if (auto dot = strrchr(ret.first.c_str(), '.')) + ret.first.resize(dot+1-ret.first.c_str()); + else + ret.first += "."; + ret.first += ret.second; + } + if (mapped && (!mappedElement.index || !mappedElement.name)) + ret.second.insert(0, Data::MISSING_PREFIX); + return ret; + } + if(!mapped) { auto occindex = Part::TopoShape::shapeTypeAndIndex(name); if (occindex.second) return Part2DObject::getElementName(name,type); - - Data::IndexedName index = checkSubName(name); - ret.first = convertSubName(index, true); - if(!Data::isMappedElement(ret.first.c_str())) - ret.first.clear(); - index.appendToStringBuffer(ret.second); - return ret; } - - Data::IndexedName index = checkSubName(name); - if(index) { - index.appendToStringBuffer(ret.second); - ret.first = convertSubName(index, true); - if(type==ElementNameType::Export) { - if(boost::starts_with(ret.second,"Vertex")) - ret.second[0] = 'v'; - else if(boost::starts_with(ret.second,"Edge")) - ret.second[0] = 'e'; - } + if(index && type==ElementNameType::Export) { + if(boost::starts_with(ret.second,"Vertex")) + ret.second[0] = 'v'; + else if(boost::starts_with(ret.second,"Edge")) + ret.second[0] = 'e'; } + ret.first = convertSubName(index, true); + if(!Data::isMappedElement(ret.first.c_str())) + ret.first.clear(); return ret; } diff --git a/src/Mod/Sketcher/App/SketchObject.h b/src/Mod/Sketcher/App/SketchObject.h index 629157faffed..1867d7b04d3c 100644 --- a/src/Mod/Sketcher/App/SketchObject.h +++ b/src/Mod/Sketcher/App/SketchObject.h @@ -699,6 +699,9 @@ class SketcherExport SketchObject: public Part::Part2DObject return convertSubName(subname.c_str(), postfix); } + static const std::string& internalPrefix(); + static const char* convertInternalName(const char* name); + std::string convertSubName(const Data::IndexedName&, bool postfix = true) const; std::pair getElementName(const char* name,