Base: Move App::Color to Base

Every basic data type is stored in Base module, color is standing out as
one that does not. Moving it to Base opens possibilities to integrate it
better with the rest of FreeCAD.
This commit is contained in:
Kacper Donat
2025-02-15 22:58:19 +01:00
parent 145af5cddc
commit a72a63232a
215 changed files with 1057 additions and 1054 deletions

View File

@@ -67,7 +67,7 @@ void ViewProviderFemConstraintOnBoundary::highlightReferences(const bool on)
if (originalPointColors[base].empty()) {
originalPointColors[base] = vp->PointColorArray.getValues();
}
std::vector<App::Color> colors = originalPointColors[base];
std::vector<Base::Color> colors = originalPointColors[base];
// go through the subelements with constraint and recolor them
// TODO: Replace `ShapeAppearance` with anything more appropriate
@@ -82,7 +82,7 @@ void ViewProviderFemConstraintOnBoundary::highlightReferences(const bool on)
if (originalLineColors[base].empty()) {
originalLineColors[base] = vp->LineColorArray.getValues();
}
std::vector<App::Color> colors = originalLineColors[base];
std::vector<Base::Color> colors = originalLineColors[base];
// go through the subelements with constraint and recolor them
// TODO: Replace `ShapeAppearance` with anything more appropriate
@@ -97,7 +97,7 @@ void ViewProviderFemConstraintOnBoundary::highlightReferences(const bool on)
if (originalFaceColors[base].empty()) {
originalFaceColors[base] = vp->ShapeAppearance.getDiffuseColors();
}
std::vector<App::Color> colors = originalFaceColors[base];
std::vector<Base::Color> colors = originalFaceColors[base];
// go through the subelements with constraint and recolor them
// TODO: Replace shape DiffuseColor with anything more appropriate

View File

@@ -46,9 +46,9 @@ public:
void highlightReferences(const bool on) override;
private:
std::map<Part::Feature*, std::vector<App::Color>> originalPointColors;
std::map<Part::Feature*, std::vector<App::Color>> originalLineColors;
std::map<Part::Feature*, std::vector<App::Color>> originalFaceColors;
std::map<Part::Feature*, std::vector<Base::Color>> originalPointColors;
std::map<Part::Feature*, std::vector<Base::Color>> originalLineColors;
std::map<Part::Feature*, std::vector<Base::Color>> originalFaceColors;
};
} // namespace FemGui

View File

@@ -192,13 +192,13 @@ ViewProviderFemMesh::ViewProviderFemMesh()
{
sPixmap = "fem-femmesh-from-shape";
ADD_PROPERTY(PointColor, (App::Color(0.7f, 0.7f, 0.7f)));
ADD_PROPERTY(PointColor, (Base::Color(0.7f, 0.7f, 0.7f)));
ADD_PROPERTY(PointSize, (5.0f));
PointSize.setConstraints(&floatRange);
ADD_PROPERTY(LineWidth, (1.0f));
LineWidth.setConstraints(&floatRange);
ShapeAppearance.setDiffuseColor(App::Color(1.0f, 0.7f, 0.0f));
ShapeAppearance.setDiffuseColor(Base::Color(1.0f, 0.7f, 0.0f));
Transparency.setValue(0);
ADD_PROPERTY(BackfaceCulling, (true));
ADD_PROPERTY(ShowInner, (false));
@@ -412,7 +412,7 @@ void ViewProviderFemMesh::onChanged(const App::Property* prop)
pcPointStyle->pointSize = PointSize.getValue();
}
else if (prop == &PointColor) {
const App::Color& c = PointColor.getValue();
const Base::Color& c = PointColor.getValue();
pcPointMaterial->diffuseColor.setValue(c.r, c.g, c.b);
}
else if (prop == &BackfaceCulling) {
@@ -683,11 +683,11 @@ void ViewProviderFemMesh::applyDisplacementToNodes(double factor)
}
void ViewProviderFemMesh::setColorByNodeId(const std::vector<long>& NodeIds,
const std::vector<App::Color>& NodeColors)
const std::vector<Base::Color>& NodeColors)
{
long endId = *(std::max_element(NodeIds.begin(), NodeIds.end()));
std::vector<App::Color> colorVec(endId + 1, App::Color(0, 1, 0));
std::vector<Base::Color> colorVec(endId + 1, Base::Color(0, 1, 0));
long i = 0;
for (std::vector<long>::const_iterator it = NodeIds.begin(); it != NodeIds.end(); ++it, i++) {
colorVec[*it] = NodeColors[i];
@@ -696,7 +696,7 @@ void ViewProviderFemMesh::setColorByNodeId(const std::vector<long>& NodeIds,
setColorByNodeIdHelper(colorVec);
}
void ViewProviderFemMesh::setColorByNodeIdHelper(const std::vector<App::Color>& colorVec)
void ViewProviderFemMesh::setColorByNodeIdHelper(const std::vector<Base::Color>& colorVec)
{
pcMatBinding->value = SoMaterialBinding::PER_VERTEX_INDEXED;
@@ -716,43 +716,43 @@ void ViewProviderFemMesh::setColorByNodeIdHelper(const std::vector<App::Color>&
void ViewProviderFemMesh::resetColorByNodeId()
{
const App::Color& c = ShapeAppearance.getDiffuseColor();
const Base::Color& c = ShapeAppearance.getDiffuseColor();
NodeColorArray.setValue(c);
}
void ViewProviderFemMesh::setColorByNodeId(
const std::map<std::vector<long>, App::Color>& elemColorMap)
const std::map<std::vector<long>, Base::Color>& elemColorMap)
{
setColorByIdHelper(elemColorMap, vNodeElementIdx, 0, NodeColorArray);
}
void ViewProviderFemMesh::setColorByElementId(
const std::map<std::vector<long>, App::Color>& elemColorMap)
const std::map<std::vector<long>, Base::Color>& elemColorMap)
{
setColorByIdHelper(elemColorMap, vFaceElementIdx, 3, ElementColorArray);
}
void ViewProviderFemMesh::setColorByIdHelper(
const std::map<std::vector<long>, App::Color>& elemColorMap,
const std::map<std::vector<long>, Base::Color>& elemColorMap,
const std::vector<unsigned long>& vElementIdx,
int rShift,
App::PropertyColorList& prop)
{
std::vector<App::Color> vecColor(vElementIdx.size());
std::map<long, const App::Color*> colorMap;
std::vector<Base::Color> vecColor(vElementIdx.size());
std::map<long, const Base::Color*> colorMap;
for (const auto& m : elemColorMap) {
for (long i : m.first) {
colorMap[i] = &m.second;
}
}
App::Color baseDif = ShapeAppearance.getDiffuseColor();
Base::Color baseDif = ShapeAppearance.getDiffuseColor();
int i = 0;
for (std::vector<unsigned long>::const_iterator it = vElementIdx.begin();
it != vElementIdx.end();
++it, i++) {
unsigned long ElemIdx = ((*it) >> rShift);
const std::map<long, const App::Color*>::const_iterator pos = colorMap.find(ElemIdx);
const std::map<long, const Base::Color*>::const_iterator pos = colorMap.find(ElemIdx);
vecColor[i] = pos == colorMap.end() ? baseDif : *pos->second;
}
@@ -762,10 +762,10 @@ void ViewProviderFemMesh::setColorByIdHelper(
void ViewProviderFemMesh::setMaterialOverall() const
{
const App::Material& mat = ShapeAppearance[0];
App::Color baseDif = mat.diffuseColor;
App::Color baseAmb = mat.ambientColor;
App::Color baseSpe = mat.specularColor;
App::Color baseEmi = mat.emissiveColor;
Base::Color baseDif = mat.diffuseColor;
Base::Color baseAmb = mat.ambientColor;
Base::Color baseSpe = mat.specularColor;
Base::Color baseEmi = mat.emissiveColor;
float baseShi = mat.shininess;
float baseTra = mat.transparency;
@@ -793,15 +793,15 @@ void ViewProviderFemMesh::setMaterialByColorArray(
const std::vector<unsigned long>& vElementIdx) const
{
const App::Material& baseMat = ShapeAppearance[0];
App::Color baseDif = baseMat.diffuseColor;
App::Color baseAmb = baseMat.ambientColor;
App::Color baseSpe = baseMat.specularColor;
App::Color baseEmi = baseMat.emissiveColor;
Base::Color baseDif = baseMat.diffuseColor;
Base::Color baseAmb = baseMat.ambientColor;
Base::Color baseSpe = baseMat.specularColor;
Base::Color baseEmi = baseMat.emissiveColor;
float baseShi = baseMat.shininess;
float baseTra = baseMat.transparency;
// resizing and writing the color vector:
std::vector<App::Color> vecColor = prop->getValue();
std::vector<Base::Color> vecColor = prop->getValue();
size_t elemSize = vElementIdx.size();
if (vecColor.size() == 1) {
pcMatBinding->value = SoMaterialBinding::OVERALL;
@@ -844,7 +844,7 @@ void ViewProviderFemMesh::setMaterialByColorArray(
vecColor.resize(elemSize, baseDif);
int i = 0;
for (const App::Color& c : vecColor) {
for (const Base::Color& c : vecColor) {
diffuse[i] = SbColor(c.r, c.g, c.b);
ambient[i] = SbColor(baseAmb.r, baseAmb.g, baseAmb.b);
specular[i] = SbColor(baseSpe.r, baseSpe.g, baseSpe.b);
@@ -866,7 +866,7 @@ void ViewProviderFemMesh::setMaterialByColorArray(
void ViewProviderFemMesh::resetColorByElementId()
{
const App::Color& c = ShapeAppearance.getDiffuseColor();
const Base::Color& c = ShapeAppearance.getDiffuseColor();
ElementColorArray.setValue(c);
}

View File

@@ -114,9 +114,9 @@ public:
//@{
/// set the color for each node
void setColorByNodeId(const std::map<std::vector<long>, App::Color>& NodeColorMap);
void setColorByNodeId(const std::map<std::vector<long>, Base::Color>& NodeColorMap);
void setColorByNodeId(const std::vector<long>& NodeIds,
const std::vector<App::Color>& NodeColors);
const std::vector<Base::Color>& NodeColors);
/// reset the view of the node colors
void resetColorByNodeId();
@@ -129,7 +129,7 @@ public:
/// reaply the node displacement with a certain factor and do a redraw
void applyDisplacementToNodes(double factor);
/// set the color for each element
void setColorByElementId(const std::map<std::vector<long>, App::Color>& ElementColorMap);
void setColorByElementId(const std::map<std::vector<long>, Base::Color>& ElementColorMap);
/// reset the view of the element colors
void resetColorByElementId();
void setMaterialByElement();
@@ -151,9 +151,9 @@ protected:
/// get called by the container whenever a property has been changed
void onChanged(const App::Property* prop) override;
void setColorByNodeIdHelper(const std::vector<App::Color>&);
void setColorByNodeIdHelper(const std::vector<Base::Color>&);
void setDisplacementByNodeIdHelper(const std::vector<Base::Vector3d>& DispVector, long startId);
void setColorByIdHelper(const std::map<std::vector<long>, App::Color>& elemColorMap,
void setColorByIdHelper(const std::map<std::vector<long>, Base::Color>& elemColorMap,
const std::vector<unsigned long>& vElementIdx,
int rShift,
App::PropertyColorList& prop);

View File

@@ -41,7 +41,7 @@ PyObject* ViewProviderFemMeshPy::applyDisplacement(PyObject* args)
}
App::Color calcColor(double value, double min, double max)
Base::Color calcColor(double value, double min, double max)
{
if (max < 0) {
max = 0;
@@ -51,27 +51,27 @@ App::Color calcColor(double value, double min, double max)
}
if (value < min) {
return App::Color(0.0, 0.0, 1.0);
return Base::Color(0.0, 0.0, 1.0);
}
if (value > max) {
return App::Color(1.0, 0.0, 0.0);
return Base::Color(1.0, 0.0, 0.0);
}
if (value == 0.0) {
return App::Color(0.0, 1.0, 0.0);
return Base::Color(0.0, 1.0, 0.0);
}
if (value > max / 2.0) {
return App::Color(1.0, 1 - ((value - (max / 2.0)) / (max / 2.0)), 0.0);
return Base::Color(1.0, 1 - ((value - (max / 2.0)) / (max / 2.0)), 0.0);
}
if (value > 0.0) {
return App::Color(value / (max / 2.0), 1.0, 0.0);
return Base::Color(value / (max / 2.0), 1.0, 0.0);
}
if (value < min / 2.0) {
return App::Color(0.0, 1 - ((value - (min / 2.0)) / (min / 2.0)), 1.0);
return Base::Color(0.0, 1 - ((value - (min / 2.0)) / (min / 2.0)), 1.0);
}
if (value < 0.0) {
return App::Color(0.0, 1.0, value / (min / 2.0));
return Base::Color(0.0, 1.0, value / (min / 2.0));
}
return App::Color(0, 0, 0);
return Base::Color(0, 0, 0);
}
@@ -90,7 +90,7 @@ PyObject* ViewProviderFemMeshPy::setNodeColorByScalars(PyObject* args)
PyErr_SetString(PyExc_ValueError, "PyList_Size < 0. That is not a valid list!");
Py_Return;
}
std::vector<App::Color> node_colors(num_items);
std::vector<Base::Color> node_colors(num_items);
for (int i = 0; i < num_items; i++) {
PyObject* id_py = PyList_GetItem(node_ids_py, i);
long id = PyLong_AsLong(id_py);
@@ -182,9 +182,9 @@ Py::Dict ViewProviderFemMeshPy::getNodeColor() const
namespace
{
std::map<std::vector<long>, App::Color> colorMapFromDict(Py::Dict& arg)
std::map<std::vector<long>, Base::Color> colorMapFromDict(Py::Dict& arg)
{
std::map<std::vector<long>, App::Color> colorMap;
std::map<std::vector<long>, Base::Color> colorMap;
for (Py::Dict::iterator it = arg.begin(); it != arg.end(); ++it) {
std::vector<long> vecId;
const Py::Object& id = (*it).first;
@@ -199,7 +199,7 @@ std::map<std::vector<long>, App::Color> colorMapFromDict(Py::Dict& arg)
}
const Py::Object& value = (*it).second;
Py::Tuple color(value);
colorMap[vecId] = App::Color(Py::Float(color[0]), Py::Float(color[1]), Py::Float(color[2]));
colorMap[vecId] = Base::Color(Py::Float(color[0]), Py::Float(color[1]), Py::Float(color[2]));
}
return colorMap;

View File

@@ -701,8 +701,8 @@ void ViewProviderFemPostObject::WriteColorData(bool ResetColorBarRange)
m_matPlainEdges->transparency.setNum(numPts);
float* transp = m_material->transparency.startEditing();
float* edgeTransp = m_matPlainEdges->transparency.startEditing();
App::Color c;
App::Color cEdge = EdgeColor.getValue();
Base::Color c;
Base::Color cEdge = EdgeColor.getValue();
for (int i = 0; i < numPts; i++) {
double value = 0;
@@ -928,7 +928,7 @@ void ViewProviderFemPostObject::onChanged(const App::Property* prop)
m_drawStyle->pointSize.setValue(PointSize.getValue());
}
else if (prop == &EdgeColor && setupPipeline()) {
App::Color c = EdgeColor.getValue();
Base::Color c = EdgeColor.getValue();
SbColor* edgeColor = m_matPlainEdges->diffuseColor.startEditing();
for (int i = 0; i < m_matPlainEdges->diffuseColor.getNum(); ++i) {
edgeColor[i].setValue(c.r, c.g, c.b);