MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / updateGeometryRefs

Method updateGeometryRefs

src/Mod/Sketcher/App/SketchObjectExternal.cpp:2800–2917  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2798}
2799
2800void SketchObject::updateGeometryRefs()
2801{
2802 const auto &objs = ExternalGeometry.getValues();
2803 const auto &subs = ExternalGeometry.getSubValues();
2804 const auto &shadows = ExternalGeometry.getShadowSubs();
2805 assert(subs.size() == shadows.size());
2806 std::vector<std::string> originalRefs;
2807 std::map<std::string,std::string> refMap;
2808 if (updateGeoRef) {
2809 assert(externalGeoRef.size() == objs.size());
2810 updateGeoRef = false;
2811 originalRefs = std::move(externalGeoRef);
2812 }
2813 externalGeoRef.clear();
2814 std::unordered_map<std::string, int> legacyMap;
2815 for (int i=0;i<(int)objs.size();++i) {
2816 auto obj = objs[i];
2817 const std::string& sub = shadows[i].newName.empty() ? subs[i] : shadows[i].newName;
2818 externalGeoRef.emplace_back(obj->getNameInDocument());
2819 auto &key = externalGeoRef.back();
2820 key += '.';
2821
2822 legacyMap[key + Data::oldElementName(sub.c_str())] = i;
2823
2824 if (!obj->isDerivedFrom<Part::Datum>()) {
2825 key += Data::newElementName(sub.c_str());
2826 }
2827 if (!originalRefs.empty() && originalRefs[i] != key) {
2828 refMap[originalRefs[i]] = key;
2829 }
2830 }
2831 bool touched = false;
2832 auto geos = ExternalGeo.getValues();
2833 if (!refMap.empty()) {
2834 for(auto &v : refMap) {
2835 auto it = externalGeoRefMap.find(v.first);
2836 if (it == externalGeoRefMap.end()) {
2837 continue;
2838 }
2839 for (long id : it->second) {
2840 auto iter = externalGeoMap.find(id);
2841 if (iter != externalGeoMap.end()) {
2842 auto &geo = geos[iter->second];
2843 geo = geo->clone();
2844 auto egf = ExternalGeometryFacade::getFacade(geo);
2845 // NOLINTNEXTLINE
2846 FC_LOG(getFullName() << " ref change on ExternalEdge" << iter->second - 1 << ' '
2847 << egf->getRef() << " -> " << v.second);
2848 egf->setRef(v.second);
2849 touched = true;
2850 }
2851 }
2852 }
2853
2854 if (touched) {
2855 ExternalGeo.setValues(std::move(geos));
2856 }
2857 return;

Callers

nothing calls this directly

Calls 15

getFullNameFunction · 0.85
getSubValuesMethod · 0.80
moveFunction · 0.50
getDocumentFunction · 0.50
getValuesMethod · 0.45
sizeMethod · 0.45
clearMethod · 0.45
emptyMethod · 0.45
getNameInDocumentMethod · 0.45
backMethod · 0.45
c_strMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected