From 846707c6284d806f13acdde02ae74bfbf5e6531b Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Wed, 18 Sep 2019 17:26:32 +0800 Subject: [PATCH] Gui: improve array element color override in ViewProviderLink --- src/Gui/ViewProviderLink.cpp | 78 ++++++++++++++++++++++++++++++++++-- 1 file changed, 74 insertions(+), 4 deletions(-) diff --git a/src/Gui/ViewProviderLink.cpp b/src/Gui/ViewProviderLink.cpp index 6b0b928387..cbd66ef3a9 100644 --- a/src/Gui/ViewProviderLink.cpp +++ b/src/Gui/ViewProviderLink.cpp @@ -2783,13 +2783,47 @@ std::map ViewProviderLink::getElementColors(const char return colors; } + int element_count = ext->getElementCountValue(); + for(auto &sub : subs) { if(++i >= size) break; - if((isPrefix && (boost::starts_with(sub.first,subname) || boost::starts_with(sub.second,subname))) || - (!isPrefix && (sub.first==subname || sub.second==subname))) + + int offset = 0; + + if(sub.second.size() && element_count && !std::isdigit(sub.second[0])) { + // For checking and expanding color override of array base + if(!subname[0]) { + std::ostringstream ss; + ss << "0." << sub.second; + if(getObject()->getSubObject(ss.str().c_str())) { + for(int j=0;j if(!ext || ! ext->getColoredElementsProperty()) return; + // For checking and collapsing array element color + std::map > subMap; + int element_count = ext->getElementCountValue(); + std::vector subs; std::vector colors; App::Color faceColor; @@ -2835,11 +2873,43 @@ void ViewProviderLink::setElementColors(const std::map if(!hasFaceColor && v.first == "Face") { hasFaceColor = true; faceColor = v.second; - }else{ + continue; + } + + if(element_count && v.first.size() && std::isdigit(v.first[0])) { + // In case of array, check if there are override of the same + // sub-element for every array element. And collapse those overrides + // into one without the index. + const char *dot = strchr(v.first.c_str(),'.'); + if(dot) { + subMap[dot+1][std::atoi(v.first.c_str())] = v.second; + continue; + } + } + subs.push_back(v.first); + colors.push_back(v.second); + } + for(auto &v : subMap) { + if(element_count == (int)v.second.size()) { + App::Color firstColor = v.second.begin()->second; subs.push_back(v.first); - colors.push_back(v.second); + colors.push_back(firstColor); + for(auto it=v.second.begin();it!=v.second.end();) { + if(it->second==firstColor) + it = v.second.erase(it); + else + ++it; + } + } + std::ostringstream ss; + for(auto &colorInfo : v.second) { + ss.str(""); + ss << colorInfo.first << '.' << v.first; + subs.push_back(ss.str()); + colors.push_back(colorInfo.second); } } + auto prop = ext->getColoredElementsProperty(); if(subs!=prop->getSubValues() || colors!=OverrideColorList.getValues()) { prop->setStatus(App::Property::User3,true);