PD: use class ReferenceHighlighter inside ViewProviderDressUp
This commit is contained in:
@@ -35,9 +35,9 @@
|
||||
using namespace PartDesignGui;
|
||||
|
||||
ReferenceHighlighter::ReferenceHighlighter(const TopoDS_Shape& shape, const App::Color& color)
|
||||
: lineColor(color)
|
||||
, singleEdges(1.0f,0.0f,1.0f) // magenta
|
||||
, allEdges(0.6f,0.0f,1.0f) // purple
|
||||
: defaultColor(color)
|
||||
, elementColor(1.0f,0.0f,1.0f) // magenta
|
||||
, objectColor(0.6f,0.0f,1.0f) // purple
|
||||
{
|
||||
TopExp::MapShapes(shape, TopAbs_EDGE, eMap);
|
||||
TopExp::MapShapes(shape, TopAbs_FACE, fMap);
|
||||
@@ -49,7 +49,7 @@ void ReferenceHighlighter::getEdgeColor(const std::string& element, std::vector<
|
||||
assert ( idx >= 0 );
|
||||
std::size_t pos = std::size_t(idx);
|
||||
if (pos < colors.size())
|
||||
colors[pos] = singleEdges;
|
||||
colors[pos] = elementColor;
|
||||
}
|
||||
|
||||
void ReferenceHighlighter::getEdgeColorsOfFace(const std::string& element, std::vector<App::Color>& colors) const
|
||||
@@ -65,7 +65,7 @@ void ReferenceHighlighter::getEdgeColorsOfFace(const std::string& element, std::
|
||||
if (edgeIndex > 0) {
|
||||
std::size_t pos = std::size_t(edgeIndex - 1);
|
||||
if (pos < colors.size())
|
||||
colors[pos] = singleEdges;
|
||||
colors[pos] = elementColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,7 +73,7 @@ void ReferenceHighlighter::getEdgeColorsOfFace(const std::string& element, std::
|
||||
void ReferenceHighlighter::getEdgeColors(const std::vector<std::string>& elements,
|
||||
std::vector<App::Color>& colors) const
|
||||
{
|
||||
colors.resize(eMap.Extent(), lineColor);
|
||||
colors.resize(eMap.Extent(), defaultColor);
|
||||
|
||||
if (!elements.empty()) {
|
||||
for (std::string e : elements) {
|
||||
@@ -86,6 +86,32 @@ void ReferenceHighlighter::getEdgeColors(const std::vector<std::string>& element
|
||||
}
|
||||
}
|
||||
else {
|
||||
std::fill(colors.begin(), colors.end(), allEdges);
|
||||
std::fill(colors.begin(), colors.end(), objectColor);
|
||||
}
|
||||
}
|
||||
|
||||
void ReferenceHighlighter::getFaceColor(const std::string& element, std::vector<App::Color>& colors) const
|
||||
{
|
||||
int idx = std::stoi(element.substr(4)) - 1;
|
||||
assert ( idx >= 0 );
|
||||
std::size_t pos = std::size_t(idx);
|
||||
if (pos < colors.size())
|
||||
colors[pos] = elementColor;
|
||||
}
|
||||
|
||||
void ReferenceHighlighter::getFaceColors(const std::vector<std::string>& elements,
|
||||
std::vector<App::Color>& colors) const
|
||||
{
|
||||
colors.resize(fMap.Extent(), defaultColor);
|
||||
|
||||
if (!elements.empty()) {
|
||||
for (std::string e : elements) {
|
||||
if (boost::starts_with(e, "Face")) {
|
||||
getFaceColor(e, colors);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
std::fill(colors.begin(), colors.end(), objectColor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,22 +44,41 @@ public:
|
||||
* \param color The standard edge color.
|
||||
*/
|
||||
ReferenceHighlighter(const TopoDS_Shape& shape, const App::Color& color);
|
||||
|
||||
void setDefaultColor(const App::Color& c) {
|
||||
defaultColor = c;
|
||||
}
|
||||
void setElementColor(const App::Color& c) {
|
||||
elementColor = c;
|
||||
}
|
||||
void setObjectColor(const App::Color& c) {
|
||||
objectColor = c;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief getEdgeColors
|
||||
* \param elements The sub-element names
|
||||
* \param elements The sub-element names. If this list is empty \a colors will be filled with the default color.
|
||||
* \param colors The size of the \a colors array is equal to the number of edges of the shape
|
||||
*/
|
||||
void getEdgeColors(const std::vector<std::string>& elements,
|
||||
std::vector<App::Color>& colors) const;
|
||||
/*!
|
||||
* \brief getFaceColors
|
||||
* \param elements The sub-element names. If this list is empty \a colors will be filled with the default color.
|
||||
* \param colors The size of the \a colors array is equal to the number of faces of the shape
|
||||
*/
|
||||
void getFaceColors(const std::vector<std::string>& elements,
|
||||
std::vector<App::Color>& colors) const;
|
||||
|
||||
private:
|
||||
void getEdgeColor(const std::string& element, std::vector<App::Color>& colors) const;
|
||||
void getEdgeColorsOfFace(const std::string& element, std::vector<App::Color>& colors) const;
|
||||
void getFaceColor(const std::string& element, std::vector<App::Color>& colors) const;
|
||||
|
||||
private:
|
||||
App::Color lineColor;
|
||||
App::Color singleEdges;
|
||||
App::Color allEdges;
|
||||
App::Color defaultColor;
|
||||
App::Color elementColor;
|
||||
App::Color objectColor;
|
||||
TopTools_IndexedMapOfShape eMap;
|
||||
TopTools_IndexedMapOfShape fMap;
|
||||
};
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
#include <Gui/Application.h>
|
||||
|
||||
#include "ViewProviderDressUp.h"
|
||||
|
||||
#include "ReferenceHighlighter.h"
|
||||
#include "TaskDressUpParameters.h"
|
||||
|
||||
using namespace PartDesignGui;
|
||||
@@ -96,35 +96,19 @@ void ViewProviderDressUp::highlightReferences(const bool on)
|
||||
|
||||
if (on) {
|
||||
if (!faces.empty() && originalFaceColors.empty()) {
|
||||
TopTools_IndexedMapOfShape fMap;
|
||||
TopExp::MapShapes(base->Shape.getValue(), TopAbs_FACE, fMap);
|
||||
|
||||
originalFaceColors = vp->DiffuseColor.getValues();
|
||||
std::vector<App::Color> colors = originalFaceColors;
|
||||
colors.resize(fMap.Extent(), ShapeColor.getValue());
|
||||
|
||||
for (std::vector<std::string>::const_iterator f = faces.begin(); f != faces.end(); ++f) {
|
||||
// Note: std::stoi may throw in case of bad or very long face name, but screw the try {} catch
|
||||
int idx = std::stoi(f->substr(4)) - 1;
|
||||
assert ( idx>=0 );
|
||||
if ( idx < (ssize_t) colors.size() )
|
||||
colors[idx] = App::Color(1.0,0.0,1.0); // magenta
|
||||
}
|
||||
ReferenceHighlighter highlighter(base->Shape.getValue(), ShapeColor.getValue());
|
||||
highlighter.getFaceColors(faces, colors);
|
||||
vp->DiffuseColor.setValues(colors);
|
||||
}
|
||||
if (!edges.empty() && originalLineColors.empty()) {
|
||||
TopTools_IndexedMapOfShape eMap;
|
||||
TopExp::MapShapes(base->Shape.getValue(), TopAbs_EDGE, eMap);
|
||||
originalLineColors = vp->LineColorArray.getValues();
|
||||
std::vector<App::Color> colors = originalLineColors;
|
||||
colors.resize(eMap.Extent(), LineColor.getValue());
|
||||
|
||||
for (std::vector<std::string>::const_iterator e = edges.begin(); e != edges.end(); ++e) {
|
||||
int idx = std::stoi(e->substr(4)) - 1;
|
||||
assert ( idx>=0 );
|
||||
if ( idx < (ssize_t) colors.size() )
|
||||
colors[idx] = App::Color(1.0,0.0,1.0); // magenta
|
||||
}
|
||||
ReferenceHighlighter highlighter(base->Shape.getValue(), LineColor.getValue());
|
||||
highlighter.getEdgeColors(edges, colors);
|
||||
vp->LineColorArray.setValues(colors);
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user