Skip to content

Commit

Permalink
Part: add missing API ViewProviderPartExt::getElementColors()
Browse files Browse the repository at this point in the history
This API is defined in Gui::ViewProvider to allow color override in
Link. In particular, the implementation in PartGui::ViewProviderPartExt
allows override for various part shapes.
  • Loading branch information
realthunder authored and wwmayer committed Oct 8, 2019
1 parent 7c76d2f commit 4c26473
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
87 changes: 87 additions & 0 deletions src/Mod/Part/Gui/ViewProviderExt.cpp
Expand Up @@ -97,6 +97,8 @@
# include <QMenu>
#endif

#include <boost/algorithm/string/predicate.hpp>

/// Here the FreeCAD includes sorted by Base,App,Gui......
#include <Base/Console.h>
#include <Base/Parameter.h>
Expand Down Expand Up @@ -745,6 +747,91 @@ void ViewProviderPartExt::setHighlightedFaces(const std::vector<App::Material>&
}
}

std::map<std::string,App::Color> ViewProviderPartExt::getElementColors(const char *element) const {
std::map<std::string,App::Color> ret;

if(!element || !element[0]) {
auto color = ShapeColor.getValue();
color.a = Transparency.getValue()/100.0f;
ret["Face"] = color;
ret["Edge"] = LineColor.getValue();
ret["Vertex"] = PointColor.getValue();
return ret;
}

if(boost::starts_with(element,"Face")) {
auto size = DiffuseColor.getSize();
if(element[4]=='*') {
auto color = ShapeColor.getValue();
color.a = Transparency.getValue()/100.0f;
bool singleColor = true;
for(int i=0;i<size;++i) {
if(DiffuseColor[i]!=color)
ret[std::string(element,4)+std::to_string(i+1)] = DiffuseColor[i];
singleColor = singleColor && DiffuseColor[0]==DiffuseColor[i];
}
if(size && singleColor) {
color = DiffuseColor[0];
ret.clear();
}
ret["Face"] = color;
}else{
int idx = atoi(element+4);
if(idx>0 && idx<=size)
ret[element] = DiffuseColor[idx-1];
else
ret[element] = ShapeColor.getValue();
if(size==1)
ret[element].a = Transparency.getValue()/100.0f;
}
} else if (boost::starts_with(element,"Edge")) {
auto size = LineColorArray.getSize();
if(element[4]=='*') {
auto color = LineColor.getValue();
bool singleColor = true;
for(int i=0;i<size;++i) {
if(LineColorArray[i]!=color)
ret[std::string(element,4)+std::to_string(i+1)] = LineColorArray[i];
singleColor = singleColor && LineColorArray[0]==LineColorArray[i];
}
if(singleColor && size) {
color = LineColorArray[0];
ret.clear();
}
ret["Edge"] = color;
}else{
int idx = atoi(element+4);
if(idx>0 && idx<=size)
ret[element] = LineColorArray[idx-1];
else
ret[element] = LineColor.getValue();
}
} else if (boost::starts_with(element,"Vertex")) {
auto size = PointColorArray.getSize();
if(element[5]=='*') {
auto color = PointColor.getValue();
bool singleColor = true;
for(int i=0;i<size;++i) {
if(PointColorArray[i]!=color)
ret[std::string(element,5)+std::to_string(i+1)] = PointColorArray[i];
singleColor = singleColor && PointColorArray[0]==PointColorArray[i];
}
if(singleColor && size) {
color = PointColorArray[0];
ret.clear();
}
ret["Vertex"] = color;
}else{
int idx = atoi(element+5);
if(idx>0 && idx<=size)
ret[element] = PointColorArray[idx-1];
else
ret[element] = PointColor.getValue();
}
}
return ret;
}

void ViewProviderPartExt::unsetHighlightedFaces()
{
DiffuseColor.touch();
Expand Down
6 changes: 6 additions & 0 deletions src/Mod/Part/Gui/ViewProviderExt.h
Expand Up @@ -129,6 +129,12 @@ class PartGuiExport ViewProviderPartExt : public Gui::ViewProviderGeometryObject
void unsetHighlightedPoints();
//@}

/** @name Color mangement methods
*/
//@{
virtual std::map<std::string,App::Color> getElementColors(const char *element=0) const override;
//@}

virtual bool isUpdateForced() const override {
return forceUpdateCount>0;
}
Expand Down

0 comments on commit 4c26473

Please sign in to comment.