From 19e450a6675b068b9f565662a1141f91bb3f8802 Mon Sep 17 00:00:00 2001 From: bgbsww Date: Fri, 19 Jul 2024 16:23:27 -0400 Subject: [PATCH] Refactor all element name pairs into clearer struct names - renames --- src/App/DocumentObjectPyImp.cpp | 6 +- src/App/DocumentObserver.cpp | 16 +- src/App/GeoFeature.cpp | 51 +++--- src/App/GeoFeature.h | 15 +- src/App/ObjectIdentifier.cpp | 16 +- src/App/PropertyLinks.cpp | 174 ++++++++++---------- src/App/PropertyLinks.h | 3 +- src/Gui/DlgPropertyLink.cpp | 4 +- src/Gui/Selection.cpp | 34 ++-- src/Gui/Selection.h | 2 +- src/Gui/SelectionView.cpp | 6 +- src/Gui/SoFCUnifiedSelection.cpp | 12 +- src/Gui/View3DInventorSelection.cpp | 6 +- src/Gui/View3DInventorViewer.cpp | 2 +- src/Gui/View3DPy.cpp | 8 +- src/Gui/ViewProviderLink.cpp | 24 +-- src/Mod/Part/App/Attacher.cpp | 4 +- src/Mod/Part/App/FeatureChamfer.cpp | 2 +- src/Mod/Part/App/FeatureFillet.cpp | 2 +- src/Mod/Part/App/PartFeature.cpp | 41 ++--- src/Mod/Part/App/PartFeature.h | 4 +- src/Mod/Part/Gui/DlgFilletEdges.cpp | 10 +- src/Mod/PartDesign/App/FeatureDressUp.cpp | 4 +- src/Mod/Sketcher/App/SketchObject.cpp | 46 +++--- src/Mod/Sketcher/App/SketchObject.h | 3 +- tests/src/Mod/Part/App/PartFeature.cpp | 12 +- tests/src/Mod/Sketcher/App/SketchObject.cpp | 28 ++-- 27 files changed, 268 insertions(+), 267 deletions(-) diff --git a/src/App/DocumentObjectPyImp.cpp b/src/App/DocumentObjectPyImp.cpp index 701da74b56..36e863c8f2 100644 --- a/src/App/DocumentObjectPyImp.cpp +++ b/src/App/DocumentObjectPyImp.cpp @@ -805,13 +805,13 @@ PyObject *DocumentObjectPy::resolveSubElement(PyObject *args) return nullptr; PY_TRY { - std::pair elementName; + ElementNamePair elementName; auto obj = GeoFeature::resolveElement(getDocumentObjectPtr(), subname,elementName, Base::asBoolean(append), static_cast(type)); Py::Tuple ret(3); ret.setItem(0,obj?Py::Object(obj->getPyObject(),true):Py::None()); - ret.setItem(1,Py::String(elementName.first)); - ret.setItem(2,Py::String(elementName.second)); + ret.setItem(1,Py::String(elementName.newName)); + ret.setItem(2,Py::String(elementName.oldName)); return Py::new_reference_to(ret); } PY_CATCH; diff --git a/src/App/DocumentObserver.cpp b/src/App/DocumentObserver.cpp index 411cada33f..896f6c1f38 100644 --- a/src/App/DocumentObserver.cpp +++ b/src/App/DocumentObserver.cpp @@ -458,30 +458,30 @@ bool SubObjectT::hasSubElement() const } std::string SubObjectT::getNewElementName() const { - std::pair element; + ElementNamePair element; auto obj = getObject(); if(!obj) return {}; GeoFeature::resolveElement(obj,subname.c_str(),element); - return std::move(element.first); + return std::move(element.newName); } std::string SubObjectT::getOldElementName(int *index) const { - std::pair element; + ElementNamePair element; auto obj = getObject(); if(!obj) return {}; GeoFeature::resolveElement(obj,subname.c_str(),element); if(!index) - return std::move(element.second); - std::size_t pos = element.second.find_first_of("0123456789"); + return std::move(element.oldName); + std::size_t pos = element.oldName.find_first_of("0123456789"); if(pos == std::string::npos) *index = -1; else { - *index = std::atoi(element.second.c_str()+pos); - element.second.resize(pos); + *index = std::atoi(element.oldName.c_str()+pos); + element.oldName.resize(pos); } - return std::move(element.second); + return std::move(element.oldName); } App::DocumentObject *SubObjectT::getSubObject() const { diff --git a/src/App/GeoFeature.cpp b/src/App/GeoFeature.cpp index 0040503e93..b2d639591f 100644 --- a/src/App/GeoFeature.cpp +++ b/src/App/GeoFeature.cpp @@ -81,70 +81,71 @@ PyObject* GeoFeature::getPyObject() return Py::new_reference_to(PythonObject); } -std::pair +ElementNamePair GeoFeature::getElementName(const char *name, ElementNameType type) const { (void)type; - std::pair ret; if(!name) - return ret; + return {}; #ifndef FC_USE_TNP_FIX - ret.second = name; + ret.oldName = name; return ret; #else auto prop = getPropertyOfGeometry(); if (!prop) { - return std::make_pair("", name); + return ElementNamePair("",name); } auto geo = prop->getComplexData(); if (!geo) { - return std::make_pair("", name); + return ElementNamePair("", name); } return _getElementName(name, geo->getElementName(name)); #endif } -std::pair +ElementNamePair GeoFeature::_getElementName(const char* name, const Data::MappedElement& mapped) const { - std::pair ret; + ElementNamePair ret; if (mapped.index && mapped.name) { std::ostringstream ss; ss << Data::ComplexGeoData::elementMapPrefix() << mapped.name << '.' << mapped.index; - ret.first = ss.str(); - mapped.index.appendToStringBuffer(ret.second); + std::string result; + mapped.index.appendToStringBuffer(result); + return ElementNamePair(ss.str().c_str(), result.c_str()); } else if (mapped.name) { // FC_TRACE("element mapped name " << name << " not found in " << getFullName()); - ret.first = name; const char* dot = strrchr(name, '.'); if (dot) { // deliberately mangle the old style element name to signal a // missing reference - ret.second = Data::MISSING_PREFIX; - ret.second += dot + 1; + std::ostringstream ss; + ss << Data::MISSING_PREFIX << dot + 1; + return ElementNamePair(name, ss.str().c_str() ); } + return ElementNamePair(name,""); } else { - mapped.index.appendToStringBuffer(ret.second); + std::string oldName; + mapped.index.appendToStringBuffer(oldName); + return ElementNamePair("", oldName.c_str()); } - - return ret; } DocumentObject *GeoFeature::resolveElement(DocumentObject *obj, const char *subname, - std::pair &elementName, bool append, + ElementNamePair &elementName, bool append, ElementNameType type, const DocumentObject *filter, const char **_element, GeoFeature **geoFeature) { #ifdef FC_USE_TNP_FIX - elementName.first.clear(); - elementName.second.clear(); + elementName.newName.clear(); + elementName.oldName.clear(); #endif if(!obj || !obj->isAttachedToDocument()) return nullptr; @@ -176,15 +177,15 @@ DocumentObject *GeoFeature::resolveElement(DocumentObject *obj, const char *subn return nullptr; if(!element || !element[0]) { if(append) - elementName.second = Data::oldElementName(subname); + elementName.oldName = Data::oldElementName(subname); return sobj; } if(!geo || hasHiddenMarker(element)) { if(!append) - elementName.second = element; + elementName.oldName = element; else - elementName.second = Data::oldElementName(subname); + elementName.oldName = Data::oldElementName(subname); return sobj; } if(!append) @@ -192,9 +193,9 @@ DocumentObject *GeoFeature::resolveElement(DocumentObject *obj, const char *subn else{ const auto &names = geo->getElementName(element,type); std::string prefix(subname,element-subname); - if(!names.first.empty()) - elementName.first = prefix + names.first; - elementName.second = prefix + names.second; + if(!names.newName.empty()) + elementName.newName = prefix + names.newName; + elementName.oldName = prefix + names.oldName; } return sobj; } diff --git a/src/App/GeoFeature.h b/src/App/GeoFeature.h index 66e1f795b5..6e75cef0e8 100644 --- a/src/App/GeoFeature.h +++ b/src/App/GeoFeature.h @@ -77,17 +77,15 @@ public: /// For exporting Export=2, }; + /** Return the new and old style sub-element name * * @param name: input name * @param type: desired element name type to return * - * @return a pair(newName,oldName). New element name may be empty. - * - * This function currently is does nothing. The new style element name - * generation will be added in the next batch of patches. + * @return a struct with the newName and oldName. New element name may be empty. */ - virtual std::pair getElementName( + virtual ElementNamePair getElementName( // NOLINT(google-default-arguments) const char *name, ElementNameType type=Normal) const; /** Resolve both the new and old style element name @@ -105,7 +103,7 @@ public: * @return Return the owner object of the element */ static DocumentObject *resolveElement(App::DocumentObject *obj, - const char *subname, std::pair &elementName, + const char *subname, ElementNamePair &elementName, bool append=false, ElementNameType type=Normal, const DocumentObject *filter=nullptr,const char **element=nullptr, GeoFeature **geo=nullptr); @@ -185,9 +183,10 @@ protected: // void onDocumentRestored() override; void updateElementReference(); #endif + protected: - std::pair _getElementName(const char* name, - const Data::MappedElement& mapped) const; + ElementNamePair _getElementName(const char* name, + const Data::MappedElement& mapped) const; }; } //namespace App diff --git a/src/App/ObjectIdentifier.cpp b/src/App/ObjectIdentifier.cpp index 451066fd73..a8294d3d9a 100644 --- a/src/App/ObjectIdentifier.cpp +++ b/src/App/ObjectIdentifier.cpp @@ -461,8 +461,8 @@ bool ObjectIdentifier::replaceObject(ObjectIdentifier &res, const App::DocumentO } res.subObjectName = String(r.second,true); res._cache.clear(); - res.shadowSub.first.clear(); - res.shadowSub.second.clear(); + res.shadowSub.newName.clear(); + res.shadowSub.oldName.clear(); return true; } @@ -1833,10 +1833,10 @@ void ObjectIdentifier::setValue(const App::any &value) const } const std::string &ObjectIdentifier::getSubObjectName(bool newStyle) const { - if(newStyle && !shadowSub.first.empty()) - return shadowSub.first; - if(!shadowSub.second.empty()) - return shadowSub.second; + if(newStyle && !shadowSub.newName.empty()) + return shadowSub.newName; + if(!shadowSub.oldName.empty()) + return shadowSub.oldName; return subObjectName.getString(); } @@ -1873,8 +1873,8 @@ void ObjectIdentifier::importSubNames(const ObjectIdentifier::SubNameMap &subNam return; subObjectName = String(it->second,true); _cache.clear(); - shadowSub.first.clear(); - shadowSub.second.clear(); + shadowSub.newName.clear(); + shadowSub.oldName.clear(); } bool ObjectIdentifier::updateElementReference(ExpressionVisitor &v, diff --git a/src/App/PropertyLinks.cpp b/src/App/PropertyLinks.cpp index 589065e4a7..d68a371f8d 100644 --- a/src/App/PropertyLinks.cpp +++ b/src/App/PropertyLinks.cpp @@ -270,13 +270,13 @@ void PropertyLinkBase::_registerElementReference(App::DocumentObject *obj, std:: if (!obj || !obj->getNameInDocument() || sub.empty()) { return; } - if (shadow.first.empty()) { + if (shadow.newName.empty()) { _updateElementReference(0, obj, sub, shadow, false); return; } GeoFeature* geo = nullptr; const char* element = nullptr; - std::pair elementName; + ShadowSub elementName; GeoFeature::resolveElement(obj, sub.c_str(), elementName, @@ -350,10 +350,10 @@ void PropertyLinkBase::restoreLabelReference(const DocumentObject *obj, size_t count = sub-subname.c_str(); const auto &newSub = ss.str(); - if(shadow && shadow->second.size()>=count) - shadow->second = newSub + (shadow->second.c_str()+count); - if(shadow && shadow->first.size()>=count) - shadow->first = newSub + (shadow->first.c_str()+count); + if(shadow && shadow->oldName.size()>=count) + shadow->oldName = newSub + (shadow->oldName.c_str()+count); + if(shadow && shadow->newName.size()>=count) + shadow->newName = newSub + (shadow->newName.c_str()+count); subname = newSub + sub; } @@ -367,11 +367,11 @@ bool PropertyLinkBase::_updateElementReference(DocumentObject *feature, } ShadowSub elementName; const char* subname; - if (shadow.first.size()) { - subname = shadow.first.c_str(); + if (shadow.newName.size()) { + subname = shadow.newName.c_str(); } - else if (shadow.second.size()) { - subname = shadow.second.c_str(); + else if (shadow.oldName.size()) { + subname = shadow.oldName.c_str(); } else { subname = sub.c_str(); @@ -387,8 +387,8 @@ bool PropertyLinkBase::_updateElementReference(DocumentObject *feature, &element, &geo); if (!ret || !geo || !element || !element[0]) { - if (elementName.second.size()) { - shadow.second.swap(elementName.second); + if (elementName.oldName.size()) { + shadow.oldName.swap(elementName.oldName); } return false; } @@ -398,8 +398,8 @@ bool PropertyLinkBase::_updateElementReference(DocumentObject *feature, } if (!reverse) { - if (elementName.first.empty()) { - shadow.second.swap(elementName.second); + if (elementName.newName.empty()) { + shadow.oldName.swap(elementName.oldName); return false; } if (shadow == elementName) { @@ -407,12 +407,12 @@ bool PropertyLinkBase::_updateElementReference(DocumentObject *feature, } } - bool missing = GeoFeature::hasMissingElement(elementName.second.c_str()); + bool missing = GeoFeature::hasMissingElement(elementName.oldName.c_str()); if (feature == geo && (missing || reverse)) { // If the referenced element is missing, or we are generating element // map for the first time, or we are re-generating the element map due // to version change, i.e. 'reverse', try search by geometry first - const char* oldElement = Data::findElementName(shadow.second.c_str()); + const char* oldElement = Data::findElementName(shadow.oldName.c_str()); if (!Data::hasMissingElement(oldElement)) { const auto& names = geo->searchElementCache(oldElement); if (names.size()) { @@ -425,9 +425,9 @@ bool PropertyLinkBase::_updateElementReference(DocumentObject *feature, true, GeoFeature::ElementNameType::Export, feature); - const auto& oldName = shadow.first.size() ? shadow.first : shadow.second; + const auto& oldName = shadow.newName.size() ? shadow.newName : shadow.oldName; const auto& newName = - elementName.first.size() ? elementName.first : elementName.second; + elementName.newName.size() ? elementName.newName : elementName.oldName; if (oldName != newName) { FC_WARN(propertyName(this) << " auto change element reference " << ret->getFullName() << " " @@ -451,34 +451,34 @@ bool PropertyLinkBase::_updateElementReference(DocumentObject *feature, if (missing) { FC_WARN(propertyName(this) << " missing element reference " << ret->getFullName() << " " - << (elementName.first.size() ? elementName.first : elementName.second)); - shadow.second.swap(elementName.second); + << (elementName.newName.size() ? elementName.newName : elementName.oldName)); + shadow.oldName.swap(elementName.oldName); } else { FC_TRACE(propertyName(this) << " element reference shadow update " << ret->getFullName() - << " " << shadow.first << " -> " << elementName.first); + << " " << shadow.newName << " -> " << elementName.newName); shadow.swap(elementName); - if (shadow.first.size() && Data::hasMappedElementName(sub.c_str())) { - updateSub(shadow.first); + if (shadow.newName.size() && Data::hasMappedElementName(sub.c_str())) { + updateSub(shadow.newName); } } if (reverse) { - if (shadow.first.size() && Data::hasMappedElementName(sub.c_str())) { - updateSub(shadow.first); + if (shadow.newName.size() && Data::hasMappedElementName(sub.c_str())) { + updateSub(shadow.newName); } else { - updateSub(shadow.second); + updateSub(shadow.oldName); } return true; } if (missing) { - if (sub != shadow.first) { - updateSub(shadow.second); + if (sub != shadow.newName) { + updateSub(shadow.oldName); } return true; } - auto pos2 = shadow.first.rfind('.'); + auto pos2 = shadow.newName.rfind('.'); if (pos2 == std::string::npos) { return true; } @@ -491,16 +491,16 @@ bool PropertyLinkBase::_updateElementReference(DocumentObject *feature, ++pos; } if (pos == pos2) { - if (sub.compare(pos, sub.size() - pos, &shadow.first[pos2]) != 0) { - FC_LOG("element reference update " << sub << " -> " << shadow.first); + if (sub.compare(pos, sub.size() - pos, &shadow.newName[pos2]) != 0) { + FC_LOG("element reference update " << sub << " -> " << shadow.newName); std::string newSub(sub); - newSub.replace(pos, sub.size() - pos, &shadow.first[pos2]); + newSub.replace(pos, sub.size() - pos, &shadow.newName[pos2]); updateSub(newSub); } } - else if (sub != shadow.second) { - FC_LOG("element reference update " << sub << " -> " << shadow.second); - updateSub(shadow.second); + else if (sub != shadow.oldName) { + FC_LOG("element reference update " << sub << " -> " << shadow.oldName); + updateSub(shadow.oldName); } return true; #else @@ -1217,22 +1217,22 @@ static inline const std::string &getSubNameWithStyle(const std::string &subName, const PropertyLinkBase::ShadowSub &shadow, bool newStyle, std::string &tmp) { if(!newStyle) { - if(!shadow.second.empty()) - return shadow.second; - }else if(!shadow.first.empty()) { + if(!shadow.oldName.empty()) + return shadow.oldName; + }else if(!shadow.newName.empty()) { #ifdef FC_USE_TNP_FIX - if (Data::hasMissingElement(shadow.second.c_str())) { - auto pos = shadow.first.rfind('.'); + if (Data::hasMissingElement(shadow.oldName.c_str())) { + auto pos = shadow.newName.rfind('.'); if (pos != std::string::npos) { - tmp = shadow.first.substr(0, pos+1); - tmp += shadow.second; + tmp = shadow.newName.substr(0, pos+1); + tmp += shadow.oldName; return tmp; } } #else (void) tmp; #endif - return shadow.first; + return shadow.newName; } return subName; } @@ -1380,8 +1380,8 @@ static bool updateLinkReference(App::PropertyLinkBase *prop, if(!touched) return false; for(int idx : mapped) { - if(idx<(int)subs.size() && !shadows[idx].first.empty()) - subs[idx] = shadows[idx].first; + if(idx<(int)subs.size() && !shadows[idx].newName.empty()) + subs[idx] = shadows[idx].newName; } mapped.clear(); if(owner && feature) @@ -1593,15 +1593,15 @@ void PropertyLinkSub::Save (Base::Writer &writer) const bool exporting = owner && owner->isExporting(); for(unsigned int i = 0;i<_cSubList.size(); i++) { const auto &shadow = _ShadowSubList[i]; - // shadow.second stores the old style element name. For backward + // shadow.oldName stores the old style element name. For backward // compatibility reason, we shall store the old name into attribute // 'value' whenever possible. - const auto &sub = shadow.second.empty()?_cSubList[i]:shadow.second; + const auto &sub = shadow.oldName.empty()?_cSubList[i]:shadow.oldName; writer.Stream() << writer.ind() << " PropertyLinkSubList::getSubListValues(b for (std::size_t i = 0; i < _lValueList.size(); i++) { App::DocumentObject* link = _lValueList[i]; std::string sub; - if(newStyle && !_ShadowSubList[i].first.empty()) - sub = _ShadowSubList[i].first; - else if(!newStyle && !_ShadowSubList[i].second.empty()) - sub = _ShadowSubList[i].second; + if(newStyle && !_ShadowSubList[i].newName.empty()) + sub = _ShadowSubList[i].newName; + else if(!newStyle && !_ShadowSubList[i].oldName.empty()) + sub = _ShadowSubList[i].oldName; else sub = _lSubList[i]; if (values.empty() || values.back().first != link){ @@ -2404,8 +2404,8 @@ void PropertyLinkSubList::updateElementReference(DocumentObject *feature, bool r mapped.reserve(_mapped.size()); for(int idx : _mapped) { if(idx<(int)_lSubList.size()) { - if(!_ShadowSubList[idx].first.empty()) - _lSubList[idx] = _ShadowSubList[idx].first; + if(!_ShadowSubList[idx].newName.empty()) + _lSubList[idx] = _ShadowSubList[idx].newName; else mapped.push_back(idx); } @@ -2439,16 +2439,16 @@ void PropertyLinkSubList::Save (Base::Writer &writer) const if(!obj || !obj->isAttachedToDocument()) continue; const auto &shadow = _ShadowSubList[i]; - // shadow.second stores the old style element name. For backward + // shadow.oldName stores the old style element name. For backward // compatibility reason, we shall store the old name into attribute // 'value' whenever possible. - const auto &sub = shadow.second.empty()?_lSubList[i]:shadow.second; + const auto &sub = shadow.oldName.empty()?_lSubList[i]:shadow.oldName; writer.Stream() << writer.ind() << "getExportName() << "\" sub=\""; if(exporting) { std::string exportName; writer.Stream() << encodeAttribute(exportSubName(exportName,obj,sub.c_str())); - if(!shadow.second.empty() && _lSubList[i]==shadow.first) + if(!shadow.oldName.empty() && _lSubList[i]==shadow.newName) writer.Stream() << "\" " ATTR_MAPPED "=\"1"; } else { writer.Stream() << encodeAttribute(sub); @@ -2457,10 +2457,10 @@ void PropertyLinkSubList::Save (Base::Writer &writer) const // Stores the actual value that is shadowed. For new version FC, // we will restore this shadowed value instead. writer.Stream() << "\" " ATTR_SHADOWED "=\"" << encodeAttribute(_lSubList[i]); - }else if(!shadow.first.empty()) { + }else if(!shadow.newName.empty()) { // Here means the user set value is old style element name. // We shall then store the shadow somewhere else. - writer.Stream() << "\" " ATTR_SHADOW "=\"" << encodeAttribute(shadow.first); + writer.Stream() << "\" " ATTR_SHADOW "=\"" << encodeAttribute(shadow.newName); } } } @@ -2500,14 +2500,14 @@ void PropertyLinkSubList::Restore(Base::XMLReader &reader) values.push_back(child); shadows.emplace_back(); auto &shadow = shadows.back(); - shadow.second = importSubName(reader,reader.getAttribute("sub"),restoreLabel); + shadow.oldName = importSubName(reader,reader.getAttribute("sub"),restoreLabel); if(reader.hasAttribute(ATTR_SHADOWED) && !IGNORE_SHADOW) { - shadow.first = importSubName(reader,reader.getAttribute(ATTR_SHADOWED),restoreLabel); - SubNames.push_back(shadow.first); + shadow.newName = importSubName(reader,reader.getAttribute(ATTR_SHADOWED),restoreLabel); + SubNames.push_back(shadow.newName); }else{ - SubNames.push_back(shadow.second); + SubNames.push_back(shadow.oldName); if(reader.hasAttribute(ATTR_SHADOW) && !IGNORE_SHADOW) - shadow.first = importSubName(reader,reader.getAttribute(ATTR_SHADOW),restoreLabel); + shadow.newName = importSubName(reader,reader.getAttribute(ATTR_SHADOW),restoreLabel); } if(reader.hasAttribute(ATTR_MAPPED)) mapped.push_back(i); @@ -3608,20 +3608,20 @@ void PropertyXLink::Save (Base::Writer &writer) const { } else if(_SubList.size() == 1) { const auto &subName = _SubList[0]; const auto &shadowSub = _ShadowSubList[0]; - const auto &sub = shadowSub.second.empty()?subName:shadowSub.second; + const auto &sub = shadowSub.oldName.empty()?subName:shadowSub.oldName; if(exporting) { std::string exportName; writer.Stream() << "\" sub=\"" << encodeAttribute(exportSubName(exportName,_pcLink,sub.c_str())); - if(!shadowSub.second.empty() && shadowSub.first==subName) + if(!shadowSub.oldName.empty() && shadowSub.newName==subName) writer.Stream() << "\" " ATTR_MAPPED "=\"1"; }else{ writer.Stream() << "\" sub=\"" << encodeAttribute(sub); if(!sub.empty()) { if(sub!=subName) writer.Stream() << "\" " ATTR_SHADOWED "=\"" << encodeAttribute(subName); - else if(!shadowSub.first.empty()) - writer.Stream() << "\" " ATTR_SHADOW "=\"" << encodeAttribute(shadowSub.first); + else if(!shadowSub.newName.empty()) + writer.Stream() << "\" " ATTR_SHADOW "=\"" << encodeAttribute(shadowSub.newName); } } writer.Stream() << "\"/>" << std::endl; @@ -3630,23 +3630,23 @@ void PropertyXLink::Save (Base::Writer &writer) const { writer.incInd(); for(unsigned int i = 0;i<_SubList.size(); i++) { const auto &shadow = _ShadowSubList[i]; - // shadow.second stores the old style element name. For backward + // shadow.oldName stores the old style element name. For backward // compatibility reason, we shall store the old name into attribute // 'value' whenever possible. - const auto &sub = shadow.second.empty()?_SubList[i]:shadow.second; + const auto &sub = shadow.oldName.empty()?_SubList[i]:shadow.oldName; writer.Stream() << writer.ind() << "" << endl; @@ -3699,13 +3699,13 @@ void PropertyXLink::Restore(Base::XMLReader &reader) auto &subname = subs.back(); shadows.emplace_back(); auto &shadow = shadows.back(); - shadow.second = importSubName(reader,reader.getAttribute("sub"),restoreLabel); + shadow.oldName = importSubName(reader,reader.getAttribute("sub"),restoreLabel); if(reader.hasAttribute(ATTR_SHADOWED) && !IGNORE_SHADOW) - subname = shadow.first = importSubName(reader,reader.getAttribute(ATTR_SHADOWED),restoreLabel); + subname = shadow.newName = importSubName(reader,reader.getAttribute(ATTR_SHADOWED),restoreLabel); else { - subname = shadow.second; + subname = shadow.oldName; if(reader.hasAttribute(ATTR_SHADOW) && !IGNORE_SHADOW) - shadow.first = importSubName(reader,reader.getAttribute(ATTR_SHADOW),restoreLabel); + shadow.newName = importSubName(reader,reader.getAttribute(ATTR_SHADOW),restoreLabel); } }else if(reader.hasAttribute("count")) { int count = reader.getAttributeAsInteger("count"); @@ -3713,14 +3713,14 @@ void PropertyXLink::Restore(Base::XMLReader &reader) shadows.resize(count); for (int i = 0; i < count; i++) { reader.readElement("Sub"); - shadows[i].second = importSubName(reader,reader.getAttribute("value"),restoreLabel); + shadows[i].oldName = importSubName(reader,reader.getAttribute("value"),restoreLabel); if(reader.hasAttribute(ATTR_SHADOWED) && !IGNORE_SHADOW) - subs[i] = shadows[i].first = + subs[i] = shadows[i].newName = importSubName(reader,reader.getAttribute(ATTR_SHADOWED),restoreLabel); else { - subs[i] = shadows[i].second; + subs[i] = shadows[i].oldName; if(reader.hasAttribute(ATTR_SHADOW) && !IGNORE_SHADOW) - shadows[i].first = importSubName(reader,reader.getAttribute(ATTR_SHADOW),restoreLabel); + shadows[i].newName = importSubName(reader,reader.getAttribute(ATTR_SHADOW),restoreLabel); } if(reader.hasAttribute(ATTR_MAPPED)) mapped.push_back(i); diff --git a/src/App/PropertyLinks.h b/src/App/PropertyLinks.h index 4bbf6f65aa..29b7a7e547 100644 --- a/src/App/PropertyLinks.h +++ b/src/App/PropertyLinks.h @@ -31,6 +31,7 @@ #include #include +// #include "GeoFeature.h" #include "Property.h" namespace Base { @@ -104,7 +105,7 @@ class AppExport PropertyLinkBase : public Property, public ScopedLink { TYPESYSTEM_HEADER_WITH_OVERRIDE(); public: - using ShadowSub = std::pair; + using ShadowSub = ElementNamePair; PropertyLinkBase(); ~PropertyLinkBase() override; diff --git a/src/Gui/DlgPropertyLink.cpp b/src/Gui/DlgPropertyLink.cpp index dcabbe8c7f..95213926d8 100644 --- a/src/Gui/DlgPropertyLink.cpp +++ b/src/Gui/DlgPropertyLink.cpp @@ -639,13 +639,13 @@ void DlgPropertyLink::onSelectionChanged(const Gui::SelectionChanges& msg) bool found = false; auto selObj = msg.Object.getObject(); - std::pair elementName; + App::ElementNamePair elementName; const char *subname = msg.pSubName; if(!ui->checkSubObject->isChecked()) { selObj = App::GeoFeature::resolveElement(selObj,subname,elementName); if(!selObj) return; - subname = elementName.second.c_str(); + subname = elementName.oldName.c_str(); } auto item = findItem(selObj, msg.pSubName, &found); diff --git a/src/Gui/Selection.cpp b/src/Gui/Selection.cpp index 6665c2b9d8..29b634df65 100644 --- a/src/Gui/Selection.cpp +++ b/src/Gui/Selection.cpp @@ -472,10 +472,10 @@ App::DocumentObject *SelectionSingleton::getObjectOfType(_SelObj &sel, Base::Typ const char *subname = sel.SubName.c_str(); if (resolve != ResolveMode::NoResolve) { obj = sel.pResolvedObject; - if (resolve == ResolveMode::NewStyleElement && !sel.elementName.first.empty()) - subname = sel.elementName.first.c_str(); + if (resolve == ResolveMode::NewStyleElement && !sel.elementName.newName.empty()) + subname = sel.elementName.newName.c_str(); else - subname = sel.elementName.second.c_str(); + subname = sel.elementName.oldName.c_str(); } if (!obj) @@ -561,9 +561,9 @@ void SelectionSingleton::slotSelectionChanged(const SelectionChanges& msg) auto pParent = msg.Object.getObject(); if(!pParent) return; - std::pair elementName; - auto &newElementName = elementName.first; - auto &oldElementName = elementName.second; + App::ElementNamePair elementName; + auto &newElementName = elementName.newName; + auto &oldElementName = elementName.oldName; auto pObject = App::GeoFeature::resolveElement(pParent,msg.pSubName,elementName); if (!pObject) return; @@ -616,15 +616,15 @@ int SelectionSingleton::setPreselect(const char* pDocName, const char* pObjectNa App::Document* pDoc = getDocument(pDocName); if (!pDoc || !pObjectName) return 0; - std::pair elementName; + App::ElementNamePair elementName; auto pObject = pDoc->getObject(pObjectName); if(!pObject) return 0; const char *subelement = pSubName; if (gateResolve != ResolveMode::NoResolve) { - auto &newElementName = elementName.first; - auto &oldElementName = elementName.second; + auto &newElementName = elementName.newName; + auto &oldElementName = elementName.oldName; pObject = App::GeoFeature::resolveElement(pObject,pSubName,elementName); if (!pObject) return 0; @@ -876,9 +876,9 @@ void SelectionSingleton::_SelObj::log(bool remove, bool clearPreselect) { ss << "Gui.Selection." << (remove?"removeSelection":"addSelection") << "('" << DocName << "','" << FeatName << "'"; if(!SubName.empty()) { - if(!elementName.second.empty() && !elementName.first.empty()) - ss << ",'" << SubName.substr(0,SubName.size()-elementName.first.size()) - << elementName.second << "'"; + if(!elementName.oldName.empty() && !elementName.newName.empty()) + ss << ",'" << SubName.substr(0,SubName.size()-elementName.newName.size()) + << elementName.oldName << "'"; else ss << ",'" << SubName << "'"; } @@ -1527,9 +1527,9 @@ int SelectionSingleton::checkSelection(const char *pDocName, const char *pObject std::string prefix; if(pSubName && element) { prefix = std::string(pSubName, element-pSubName); - if(!sel.elementName.first.empty()) { + if(!sel.elementName.newName.empty()) { // make sure the selected sub name is a new style if available - subname = prefix + sel.elementName.first; + subname = prefix + sel.elementName.newName; pSubName = subname.c_str(); sel.SubName = subname; } @@ -1554,11 +1554,11 @@ int SelectionSingleton::checkSelection(const char *pDocName, const char *pObject continue; if(!pSubName[0]) return 1; - if (!s.elementName.first.empty()) { - if (s.elementName.first == sel.elementName.first) + if (!s.elementName.newName.empty()) { + if (s.elementName.newName == sel.elementName.newName) return 1; } - else if(s.SubName == sel.elementName.second) + else if(s.SubName == sel.elementName.oldName) return 1; } } diff --git a/src/Gui/Selection.h b/src/Gui/Selection.h index 7d31e89a12..ff299b3c5e 100644 --- a/src/Gui/Selection.h +++ b/src/Gui/Selection.h @@ -686,7 +686,7 @@ protected: float z = 0.0f; bool logged = false; - std::pair elementName; + App::ElementNamePair elementName; App::DocumentObject* pResolvedObject = nullptr; void log(bool remove=false, bool clearPreselect=true); diff --git a/src/Gui/SelectionView.cpp b/src/Gui/SelectionView.cpp index 05956cc156..0e7aab2dfe 100644 --- a/src/Gui/SelectionView.cpp +++ b/src/Gui/SelectionView.cpp @@ -159,12 +159,12 @@ void SelectionView::onSelectionChanged(const SelectionChanges& Reason) str << subName; */ /* Remove the history from the displayed subelement name */ - std::pair elementName; + App::ElementNamePair elementName; App::GeoFeature::resolveElement(obj, subName, elementName); - str << elementName.second.c_str(); // Use the shortened element name not the full one. + str << elementName.oldName.c_str(); // Use the shortened element name not the full one. /* Mark it visually if there was a history as a "tell" for if a given selection has TNP * fixes in it. */ - if (elementName.first.size() > 0) { + if (elementName.newName.size() > 0) { str << " []"; } auto subObj = obj->getSubObject(subName); diff --git a/src/Gui/SoFCUnifiedSelection.cpp b/src/Gui/SoFCUnifiedSelection.cpp index 4c62bc7184..a509012e07 100644 --- a/src/Gui/SoFCUnifiedSelection.cpp +++ b/src/Gui/SoFCUnifiedSelection.cpp @@ -399,11 +399,11 @@ void SoFCUnifiedSelection::doAction(SoAction *action) detailPath->truncate(0); auto subName = selaction->SelChange.pSubName; #ifdef FC_USE_TNP_FIX - std::pair elementName; + App::ElementNamePair elementName;; App::GeoFeature::resolveElement(obj, subName, elementName); if (Data::isMappedElement(subName) - && !elementName.second.empty()) { // If we have a shortened element name - subName = elementName.second.c_str(); // use it. + && !elementName.oldName.empty()) { // If we have a shortened element name + subName = elementName.oldName.c_str(); // use it. } #endif if(!selaction->SelChange.pSubName || !selaction->SelChange.pSubName[0] || @@ -628,12 +628,12 @@ bool SoFCUnifiedSelection::setSelection(const std::vector &infos, bo #ifdef FC_USE_TNP_FIX // We need to convert the short name in the selection to a full element path to look it up // Ex: Body.Pad.Face9 to Body.Pad.;g3;SKT;:H12dc,E;FAC;:H12dc:4,F;:G0;XTR;:H12dc:8,F.Face9 - std::pair elementName; + App::ElementNamePair elementName; App::GeoFeature::resolveElement(vpd->getObject(), subName.c_str(), elementName); - if ( !elementName.first.empty()) { // If we have a mapped name use it + if ( !elementName.newName.empty()) { // If we have a mapped name use it auto elementNameSuffix = Data::findElementName(subName.c_str()); // Only suffix subName.erase(subName.find(elementNameSuffix)); // Everything except original suffix suffix - subName = subName.append(elementName.first); // Add the mapped name suffix, + subName = subName.append(elementName.newName); // Add the mapped name suffix, } #endif const char *subSelected = Gui::Selection().getSelectedElement( diff --git a/src/Gui/View3DInventorSelection.cpp b/src/Gui/View3DInventorSelection.cpp index 6999d090f3..6a6c681dab 100644 --- a/src/Gui/View3DInventorSelection.cpp +++ b/src/Gui/View3DInventorSelection.cpp @@ -115,11 +115,11 @@ void View3DInventorSelection::checkGroupOnTop(const SelectionChanges &Reason) key += '.'; auto subname = Reason.pSubName; #ifdef FC_USE_TNP_FIX - std::pair element; + App::ElementNamePair element; App::GeoFeature::resolveElement(obj, Reason.pSubName, element); if (Data::isMappedElement(subname) - && !element.second.empty()) { // If we have a shortened element name - subname = element.second.c_str(); // use if + && !element.oldName.empty()) { // If we have a shortened element name + subname = element.oldName.c_str(); // use if } #endif if(subname) diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index d168c25f55..a54cc3bdfa 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -3356,7 +3356,7 @@ void View3DInventorViewer::alignToSelection() // Get the geo feature App::GeoFeature* geoFeature = nullptr; - std::pair elementName; + App::ElementNamePair elementName; App::GeoFeature::resolveElement(selection[0].pObject, selection[0].SubName, elementName, false, App::GeoFeature::ElementNameType::Normal, nullptr, nullptr, &geoFeature); if (!geoFeature) { return; diff --git a/src/Gui/View3DPy.cpp b/src/Gui/View3DPy.cpp index f6113588f1..9ec7fb3a07 100644 --- a/src/Gui/View3DPy.cpp +++ b/src/Gui/View3DPy.cpp @@ -1328,7 +1328,7 @@ Py::Object View3DInventorPy::getObjectInfo(const Py::Tuple& args) if (!obj) return ret; if (!subname.empty()) { - std::pair elementName; + App::ElementNamePair elementName; auto sobj = App::GeoFeature::resolveElement(obj,subname.c_str(),elementName); if (!sobj) return ret; @@ -1337,7 +1337,7 @@ Py::Object View3DInventorPy::getObjectInfo(const Py::Tuple& args) dict.setItem("SubName",Py::String(subname)); obj = sobj; } - subname = !elementName.second.empty()?elementName.second:elementName.first; + subname = !elementName.oldName.empty()?elementName.oldName:elementName.newName; } dict.setItem("Document", Py::String(obj->getDocument()->getName())); @@ -1438,7 +1438,7 @@ Py::Object View3DInventorPy::getObjectsInfo(const Py::Tuple& args) if (!obj) continue; if (!subname.empty()) { - std::pair elementName; + App::ElementNamePair elementName; auto sobj = App::GeoFeature::resolveElement(obj,subname.c_str(),elementName); if (!sobj) continue; @@ -1447,7 +1447,7 @@ Py::Object View3DInventorPy::getObjectsInfo(const Py::Tuple& args) dict.setItem("SubName",Py::String(subname)); obj = sobj; } - subname = !elementName.second.empty()?elementName.second:elementName.first; + subname = !elementName.oldName.empty()?elementName.oldName:elementName.newName; } dict.setItem("Document", Py::String(obj->getDocument()->getName())); diff --git a/src/Gui/ViewProviderLink.cpp b/src/Gui/ViewProviderLink.cpp index abacf012e4..e7f6c25b1f 100644 --- a/src/Gui/ViewProviderLink.cpp +++ b/src/Gui/ViewProviderLink.cpp @@ -3073,16 +3073,16 @@ std::map ViewProviderLink::getElementColors(const char for(const auto &sub : subs) { if(++i >= size) break; - auto pos = sub.second.rfind('.'); + auto pos = sub.oldName.rfind('.'); if(pos == std::string::npos) pos = 0; else ++pos; - const char *element = sub.second.c_str()+pos; + const char *element = sub.oldName.c_str()+pos; if(boost::starts_with(element,wildcard)) - colors[sub.second] = OverrideColorList[i]; + colors[sub.oldName] = OverrideColorList[i]; else if(!element[0] && wildcard=="Face") - colors[sub.second.substr(0,element-sub.second.c_str())+wildcard] = OverrideColorList[i]; + colors[sub.oldName.substr(0,element-sub.oldName.c_str())+wildcard] = OverrideColorList[i]; } // In case of multi-level linking, we recursively call into each level, @@ -3133,15 +3133,15 @@ std::map ViewProviderLink::getElementColors(const char int offset = 0; - if(!sub.second.empty() && element_count && !std::isdigit(sub.second[0])) { + if(!sub.oldName.empty() && element_count && !std::isdigit(sub.oldName[0])) { // For checking and expanding color override of array base if(!subname[0]) { std::ostringstream ss; - ss << "0." << sub.second; + ss << "0." << sub.oldName; if(getObject()->getSubObject(ss.str().c_str())) { for(int j=0;j ViewProviderLink::getElementColors(const char } if(isPrefix) { - if(!boost::starts_with(sub.first,subname+offset) - && !boost::starts_with(sub.second,subname+offset)) + if(!boost::starts_with(sub.newName,subname+offset) + && !boost::starts_with(sub.oldName,subname+offset)) continue; - }else if(sub.first!=subname+offset && sub.second!=subname+offset) + }else if(sub.newName!=subname+offset && sub.oldName!=subname+offset) continue; if(offset) - colors.emplace(std::string(subname,offset)+sub.second, OverrideColorList[i]); + colors.emplace(std::string(subname,offset)+sub.oldName, OverrideColorList[i]); else - colors[sub.second] = OverrideColorList[i]; + colors[sub.oldName] = OverrideColorList[i]; } if(!subname[0]) diff --git a/src/Mod/Part/App/Attacher.cpp b/src/Mod/Part/App/Attacher.cpp index 5138333a68..c0b04c2aa8 100644 --- a/src/Mod/Part/App/Attacher.cpp +++ b/src/Mod/Part/App/Attacher.cpp @@ -198,8 +198,8 @@ void AttachEngine::setReferences(const App::PropertyLinkSubList& references) this->shadowSubs.clear(); this->shadowSubs.reserve(this->objNames.size()); for (auto& shadow : references.getShadowSubs()) { - this->shadowSubs.push_back(shadow.first); - this->subnames.push_back(shadow.second); + this->shadowSubs.push_back(shadow.newName); + this->subnames.push_back(shadow.oldName); } assert(this->objNames.size() == this->subnames.size()); } diff --git a/src/Mod/Part/App/FeatureChamfer.cpp b/src/Mod/Part/App/FeatureChamfer.cpp index 45ee4f748a..7de82f9f26 100644 --- a/src/Mod/Part/App/FeatureChamfer.cpp +++ b/src/Mod/Part/App/FeatureChamfer.cpp @@ -100,7 +100,7 @@ App::DocumentObjectExecReturn *Chamfer::execute() size_t i=0; for(const auto &info : Edges.getValues()) { auto &sub = subs[i]; - auto &ref = sub.first.size()?sub.first:vals[i]; + auto &ref = sub.newName.size()?sub.newName:vals[i]; ++i; // Toponaming project March 2024: Replaced this code because it wouldn't work: // TopoDS_Shape edge; diff --git a/src/Mod/Part/App/FeatureFillet.cpp b/src/Mod/Part/App/FeatureFillet.cpp index d9a574fcc3..0bea8d99d5 100644 --- a/src/Mod/Part/App/FeatureFillet.cpp +++ b/src/Mod/Part/App/FeatureFillet.cpp @@ -105,7 +105,7 @@ App::DocumentObjectExecReturn *Fillet::execute() size_t i=0; for(const auto &info : Edges.getValues()) { auto &sub = subs[i]; - auto &ref = sub.first.size()?sub.first:vals[i]; + auto &ref = sub.newName.size()?sub.newName:vals[i]; ++i; // Toponaming project March 2024: Replaced this code because it wouldn't work: // TopoDS_Shape edge; diff --git a/src/Mod/Part/App/PartFeature.cpp b/src/Mod/Part/App/PartFeature.cpp index 0f2851bee6..9be1923ce2 100644 --- a/src/Mod/Part/App/PartFeature.cpp +++ b/src/Mod/Part/App/PartFeature.cpp @@ -58,6 +58,7 @@ #include #include #include +#include #include #include #include @@ -132,10 +133,10 @@ PyObject *Feature::getPyObject() * method * @param name The name to search for, or if non existent, name of current Feature is returned * @param type An element type name. - * @return The element name located, of + * @return a struct with the newName and oldName. New element name may be empty. */ -std::pair Feature::getElementName(const char* name, - ElementNameType type) const +App::ElementNamePair Feature::getElementName(const char* name, + ElementNameType type) const { if (type != ElementNameType::Export) { return App::GeoFeature::getElementName(name, type); @@ -151,7 +152,7 @@ std::pair Feature::getElementName(const char* name, return getExportElementName(prop->getShape(), name); } -std::pair Feature::getExportElementName(TopoShape shape, +App::ElementNamePair Feature::getExportElementName(TopoShape shape, const char* name) const { Data::MappedElement mapped = shape.getElementName(name); @@ -657,14 +658,14 @@ QVector Feature::getElementFromSource(App::DocumentObject* return true; } if (name == element.name) { - std::pair objElement; + App::ElementNamePair objElement; std::size_t len = sub.size(); checkingSubname.appendToStringBuffer(sub); GeoFeature::resolveElement(obj, sub.c_str(), objElement); sub.resize(len); - if (objElement.second.size()) { - res.push_back(Data::MappedElement(Data::MappedName(objElement.first), - Data::IndexedName(objElement.second.c_str()))); + if (objElement.oldName.size()) { + res.push_back(Data::MappedElement(Data::MappedName(objElement.newName), + Data::IndexedName(objElement.oldName.c_str()))); return true; } } @@ -672,13 +673,13 @@ QVector Feature::getElementFromSource(App::DocumentObject* }; // obtain both the old and new style element name - std::pair objElement; + App::ElementNamePair objElement; GeoFeature::resolveElement(src, srcSub, objElement, false); - element.index = Data::IndexedName(objElement.second.c_str()); - if (!objElement.first.empty()) { + element.index = Data::IndexedName(objElement.oldName.c_str()); + if (!objElement.newName.empty()) { // Strip prefix and indexed based name at the tail of the new style element name - auto mappedName = Data::newElementName(objElement.first.c_str()); + auto mappedName = Data::newElementName(objElement.newName.c_str()); auto mapped = Data::isMappedElement(mappedName.c_str()); if (mapped) { element.name = Data::MappedName(mapped); @@ -686,18 +687,18 @@ QVector Feature::getElementFromSource(App::DocumentObject* } // Translate the element name for datum - if (objElement.second == "Plane") { - objElement.second = "Face1"; + if (objElement.oldName == "Plane") { + objElement.oldName = "Face1"; } - else if (objElement.second == "Line") { - objElement.second = "Edge1"; + else if (objElement.oldName == "Line") { + objElement.oldName = "Edge1"; } - else if (objElement.second == "Point") { - objElement.second = "Vertex1"; + else if (objElement.oldName == "Point") { + objElement.oldName = "Vertex1"; } // Use the old style name to obtain the shape type - auto type = TopoShape::shapeType(Data::findElementName(objElement.second.c_str())); + auto type = TopoShape::shapeType(Data::findElementName(objElement.oldName.c_str())); // If the given shape has the same number of sub shapes as the source (e.g. // a compound operation), then take a shortcut and assume the element index // remains the same. But we still need to trace the shape history to @@ -714,7 +715,7 @@ QVector Feature::getElementFromSource(App::DocumentObject* } // Try geometry search first - auto subShape = srcShape.getSubShape(objElement.second.c_str()); + auto subShape = srcShape.getSubShape(objElement.oldName.c_str()); std::vector names; shape.findSubShapesWithSharedVertex(subShape, &names); if (names.size()) { diff --git a/src/Mod/Part/App/PartFeature.h b/src/Mod/Part/App/PartFeature.h index 0288eded67..a468eb6ef1 100644 --- a/src/Mod/Part/App/PartFeature.h +++ b/src/Mod/Part/App/PartFeature.h @@ -71,7 +71,7 @@ public: PyObject* getPyObject() override; - std::pair getElementName( + App::ElementNamePair getElementName( const char *name, ElementNameType type=Normal) const override; static std::list getElementHistory(App::DocumentObject *obj, @@ -180,7 +180,7 @@ protected: * Vertex/Edge/Face, this function will auto generate a name from primary * sub-shapes. */ - std::pair getExportElementName(TopoShape shape, const char *name) const; + App::ElementNamePair getExportElementName(TopoShape shape, const char *name) const; /** * Build a history of changes diff --git a/src/Mod/Part/Gui/DlgFilletEdges.cpp b/src/Mod/Part/Gui/DlgFilletEdges.cpp index dd85b4e2a9..7ce7a6ce88 100644 --- a/src/Mod/Part/Gui/DlgFilletEdges.cpp +++ b/src/Mod/Part/Gui/DlgFilletEdges.cpp @@ -600,7 +600,7 @@ void DlgFilletEdges::setupFillet(const std::vector& objs) } std::set subSet; for(auto &sub : subs) - subSet.insert(sub.first.empty()?sub.second:sub.first); + subSet.insert(sub.newName.empty()?sub.oldName:sub.newName); std::string tmp; std::vector::const_iterator it = std::find(objs.begin(), objs.end(), base); @@ -628,16 +628,16 @@ void DlgFilletEdges::setupFillet(const std::vector& objs) std::set elements; for(size_t i=0;i DressUp::getContinuousEdges(const TopoShape& shape) for (const auto& v : Base.getShadowSubs()) { TopoDS_Shape subshape; - const auto& ref = v.first.size() ? v.first : v.second; + const auto& ref = v.newName.size() ? v.newName : v.oldName; subshape = shape.getSubShape(ref.c_str(), true); if (subshape.IsNull()) { FC_THROWM(Base::CADKernelError, "Invalid edge link: " << ref); @@ -236,7 +236,7 @@ std::vector DressUp::getFaces(const TopoShape& shape) continue; } auto& sub = subs[i++]; - auto& ref = sub.first.size() ? sub.first : val; + auto& ref = sub.newName.size() ? sub.newName : val; TopoShape subshape; try { subshape = shape.getSubTopoShape(ref.c_str()); diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 1284ee9902..f63db00b59 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -9640,7 +9640,7 @@ const char *SketchObject::convertInternalName(const char *name) return nullptr; } -std::pair SketchObject::getElementName( +App::ElementNamePair SketchObject::getElementName( const char *name, ElementNameType type) const { // Todo: Toponaming Project March 2024: This method override breaks the sketcher - selection and deletion @@ -9650,7 +9650,7 @@ std::pair SketchObject::getElementName( #ifndef FC_USE_TNP_FIX return Part2DObject::getElementName(name,type); #endif - std::pair ret; + App::ElementNamePair ret; if(!name) return ret; if(hasSketchMarker(name)) @@ -9658,40 +9658,40 @@ std::pair SketchObject::getElementName( const char *mapped = Data::isMappedElement(name); Data::IndexedName index = checkSubName(name); - index.appendToStringBuffer(ret.second); - if (auto realName = convertInternalName(ret.second.c_str())) { + index.appendToStringBuffer(ret.oldName); + if (auto realName = convertInternalName(ret.oldName.c_str())) { Data::MappedElement mappedElement; (void)realName; // 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; +// ret.newName = 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); + ret.oldName = internalPrefix(); + mappedElement.index.appendToStringBuffer(ret.oldName); } if (mappedElement.name) { - ret.first = Data::ComplexGeoData::elementMapPrefix(); - mappedElement.name.appendToBuffer(ret.first); + ret.newName = Data::ComplexGeoData::elementMapPrefix(); + mappedElement.name.appendToBuffer(ret.newName); } else if (mapped) - ret.first = name; + ret.newName = name; } - if (ret.first.size()) { - if (auto dot = strrchr(ret.first.c_str(), '.')) - ret.first.resize(dot+1-ret.first.c_str()); + if (ret.newName.size()) { + if (auto dot = strrchr(ret.newName.c_str(), '.')) + ret.newName.resize(dot+1-ret.newName.c_str()); else - ret.first += "."; - ret.first += ret.second; + ret.newName += "."; + ret.newName += ret.oldName; } if (mapped && (!mappedElement.index || !mappedElement.name)) - ret.second.insert(0, Data::MISSING_PREFIX); + ret.oldName.insert(0, Data::MISSING_PREFIX); return ret; } @@ -9701,14 +9701,14 @@ std::pair SketchObject::getElementName( return Part2DObject::getElementName(name,type); } 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'; + if(boost::starts_with(ret.oldName,"Vertex")) + ret.oldName[0] = 'v'; + else if(boost::starts_with(ret.oldName,"Edge")) + ret.oldName[0] = 'e'; } - ret.first = convertSubName(index, true); - if(!Data::isMappedElement(ret.first.c_str())) - ret.first.clear(); + ret.newName = convertSubName(index, true); + if(!Data::isMappedElement(ret.newName.c_str())) + ret.newName.clear(); return ret; } diff --git a/src/Mod/Sketcher/App/SketchObject.h b/src/Mod/Sketcher/App/SketchObject.h index d88bca68c0..aafbca8ca9 100644 --- a/src/Mod/Sketcher/App/SketchObject.h +++ b/src/Mod/Sketcher/App/SketchObject.h @@ -710,8 +710,7 @@ public: std::string convertSubName(const Data::IndexedName&, bool postfix = true) const; - std::pair getElementName(const char* name, - ElementNameType type) const override; + App::ElementNamePair getElementName(const char* name, ElementNameType type) const override; bool isPerformingInternalTransaction() const { diff --git a/tests/src/Mod/Part/App/PartFeature.cpp b/tests/src/Mod/Part/App/PartFeature.cpp index c89799af69..7acd99e450 100644 --- a/tests/src/Mod/Part/App/PartFeature.cpp +++ b/tests/src/Mod/Part/App/PartFeature.cpp @@ -47,12 +47,12 @@ TEST_F(FeaturePartTest, testGetElementName) auto namePairExport = _common->getElementName("test", App::GeoFeature::Export); auto namePairSelf = _common->getElementName(nullptr); // Assert - EXPECT_STREQ(namePair.first.c_str(), ""); - EXPECT_STREQ(namePair.second.c_str(), "test"); - EXPECT_STREQ(namePairExport.first.c_str(), ""); - EXPECT_STREQ(namePairExport.second.c_str(), "test"); - EXPECT_STREQ(namePairSelf.first.c_str(), ""); - EXPECT_STREQ(namePairSelf.second.c_str(), ""); + EXPECT_STREQ(namePair.newName.c_str(), ""); + EXPECT_STREQ(namePair.oldName.c_str(), "test"); + EXPECT_STREQ(namePairExport.newName.c_str(), ""); + EXPECT_STREQ(namePairExport.oldName.c_str(), "test"); + EXPECT_STREQ(namePairSelf.newName.c_str(), ""); + EXPECT_STREQ(namePairSelf.oldName.c_str(), ""); #ifndef FC_USE_TNP_FIX EXPECT_EQ(ts.getElementMap().size(), 0); #else diff --git a/tests/src/Mod/Sketcher/App/SketchObject.cpp b/tests/src/Mod/Sketcher/App/SketchObject.cpp index e02e891bda..761ebf97ff 100644 --- a/tests/src/Mod/Sketcher/App/SketchObject.cpp +++ b/tests/src/Mod/Sketcher/App/SketchObject.cpp @@ -24,7 +24,7 @@ protected: { _docName = App::GetApplication().getUniqueDocumentName("test"); auto _doc = App::GetApplication().newDocument(_docName.c_str(), "testUser"); - // TODO: Do we add a body first, or is just adding sketch sufficient for this test? + // TODO: Do we add a body newName, or is just adding sketch sufficient for this test? _sketchobj = static_cast(_doc->addObject("Sketcher::SketchObject")); } @@ -80,7 +80,7 @@ TEST_F(SketchObjectTest, testGeoIdFromShapeTypeEdge) TEST_F(SketchObjectTest, testGeoIdFromShapeTypeVertex) { // Arrange - // For operating on vertices, there is first a check if the vertex exists. + // For operating on vertices, there is newName a check if the vertex exists. Base::Vector3d p1(0.0, 0.0, 0.0), p2(1.0, 0.0, 0.0); std::unique_ptr geoline(new Part::GeomLineSegment()); static_cast(geoline.get())->setPoints(p1, p2); @@ -277,18 +277,18 @@ TEST_F(SketchObjectTest, testGetElementName) EXPECT_EQ(map[0].index.toString(), "Edge1"); // Assert #ifndef FC_USE_TNP_FIX - EXPECT_STREQ(forward_normal_name.first.c_str(), ""); - EXPECT_STREQ(forward_normal_name.second.c_str(), "g39;SKT"); - EXPECT_STREQ(reverse_normal_name.first.c_str(), ""); - EXPECT_STREQ(reverse_normal_name.second.c_str(), "Vertex2"); - EXPECT_STREQ(reverse_export_name.first.c_str(), ";g39v1;SKT.Vertex1"); - EXPECT_STREQ(reverse_export_name.second.c_str(), "Vertex1"); + EXPECT_STREQ(forward_normal_name.newName.c_str(), ""); + EXPECT_STREQ(forward_normal_name.oldName.c_str(), "g39;SKT"); + EXPECT_STREQ(reverse_normal_name.newName.c_str(), ""); + EXPECT_STREQ(reverse_normal_name.oldName.c_str(), "Vertex2"); + EXPECT_STREQ(reverse_export_name.newName.c_str(), ";g39v1;SKT.Vertex1"); + EXPECT_STREQ(reverse_export_name.oldName.c_str(), "Vertex1"); #else - EXPECT_STREQ(forward_normal_name.first.c_str(), ";g39;SKT.Edge1"); - EXPECT_STREQ(forward_normal_name.second.c_str(), "Edge1"); - EXPECT_STREQ(reverse_normal_name.first.c_str(), ";g39v2;SKT.Vertex2"); - EXPECT_STREQ(reverse_normal_name.second.c_str(), "Vertex2"); - EXPECT_STREQ(reverse_export_name.first.c_str(), ";g39v1;SKT.Vertex1"); - EXPECT_STREQ(reverse_export_name.second.c_str(), "Vertex1"); + EXPECT_STREQ(forward_normal_name.newName.c_str(), ";g39;SKT.Edge1"); + EXPECT_STREQ(forward_normal_name.oldName.c_str(), "Edge1"); + EXPECT_STREQ(reverse_normal_name.newName.c_str(), ";g39v2;SKT.Vertex2"); + EXPECT_STREQ(reverse_normal_name.oldName.c_str(), "Vertex2"); + EXPECT_STREQ(reverse_export_name.newName.c_str(), ";g39v1;SKT.Vertex1"); + EXPECT_STREQ(reverse_export_name.oldName.c_str(), "Vertex1"); #endif }