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

@@ -273,7 +273,6 @@ SET(FreeCADApp_CPP_SRCS
AutoTransaction.cpp
Branding.cpp
CleanupProcess.cpp
Color.cpp
ColorModel.cpp
ComplexGeoData.cpp
ComplexGeoDataPyImp.cpp
@@ -303,7 +302,6 @@ SET(FreeCADApp_HPP_SRCS
AutoTransaction.h
Branding.h
CleanupProcess.h
Color.h
ColorModel.h
ComplexGeoData.h
ElementMap.h

View File

@@ -1,196 +0,0 @@
/***************************************************************************
* Copyright (c) 2005 Jürgen Riegel <juergen.riegel@web.de> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#include <iomanip>
#include <sstream>
#endif
#include "Color.h"
using namespace App;
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
Color::Color(float red, float green, float blue, float alpha)
: r(red)
, g(green)
, b(blue)
, a(alpha)
{}
Color::Color(uint32_t rgba)
: Color {}
{
setPackedValue(rgba);
}
bool Color::operator==(const Color& color) const
{
return getPackedValue() == color.getPackedValue();
}
bool Color::operator!=(const Color& color) const
{
return !operator==(color);
}
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
void Color::set(float red, float green, float blue, float alpha)
{
r = red;
g = green;
b = blue;
a = alpha;
}
float Color::transparency() const
{
return 1.0F - a;
}
void Color::setTransparency(float value)
{
a = 1.0F - value;
}
// NOLINTBEGIN(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
Color& Color::setPackedValue(uint32_t rgba)
{
// clang-format off
this->set(static_cast<float> (rgba >> 24) / 255.0F,
static_cast<float>((rgba >> 16) & 0xff) / 255.0F,
static_cast<float>((rgba >> 8) & 0xff) / 255.0F,
static_cast<float> (rgba & 0xff) / 255.0F);
return *this;
// clang-format on
}
uint32_t Color::getPackedValue() const
{
// clang-format off
return (static_cast<uint32_t>(std::lround(r * 255.0F)) << 24 |
static_cast<uint32_t>(std::lround(g * 255.0F)) << 16 |
static_cast<uint32_t>(std::lround(b * 255.0F)) << 8 |
static_cast<uint32_t>(std::lround(a * 255.0F)));
// clang-format on
}
void Color::setPackedRGB(uint32_t rgb)
{
// clang-format off
this->set(static_cast<float>((rgb >> 24) & 0xff) / 255.0F,
static_cast<float>((rgb >> 16) & 0xff) / 255.0F,
static_cast<float>((rgb >> 8) & 0xff) / 255.0F);
// clang-format on
}
uint32_t Color::getPackedRGB() const
{
// clang-format off
return (static_cast<uint32_t>(std::lround(r * 255.0F)) << 24 |
static_cast<uint32_t>(std::lround(g * 255.0F)) << 16 |
static_cast<uint32_t>(std::lround(b * 255.0F)) << 8);
// clang-format on
}
uint32_t Color::getPackedARGB() const
{
// clang-format off
return (static_cast<uint32_t>(std::lround(a * 255.0F)) << 24 |
static_cast<uint32_t>(std::lround(r * 255.0F)) << 16 |
static_cast<uint32_t>(std::lround(g * 255.0F)) << 8 |
static_cast<uint32_t>(std::lround(b * 255.0F)));
// clang-format on
}
void Color::setPackedARGB(uint32_t argb)
{
// clang-format off
this->set(static_cast<float>((argb >> 16) & 0xff) / 255.0F,
static_cast<float>((argb >> 8) & 0xff) / 255.0F,
static_cast<float> (argb & 0xff) / 255.0F,
static_cast<float> (argb >> 24) / 255.0F);
// clang-format on
}
std::string Color::asHexString() const
{
// clang-format off
std::stringstream ss;
ss << "#" << std::hex << std::uppercase << std::setfill('0')
<< std::setw(2) << int(std::lround(r * 255.0F))
<< std::setw(2) << int(std::lround(g * 255.0F))
<< std::setw(2) << int(std::lround(b * 255.0F));
return ss.str();
// clang-format on
}
bool Color::fromHexString(const std::string& hex)
{
if (hex.size() < 7 || hex[0] != '#') {
return false;
}
// #RRGGBB
if (hex.size() == 7) {
std::stringstream ss(hex);
unsigned int rgb;
char ch {};
ss >> ch >> std::hex >> rgb;
int rc = (rgb >> 16) & 0xff;
int gc = (rgb >> 8) & 0xff;
int bc = rgb & 0xff;
r = rc / 255.0F;
g = gc / 255.0F;
b = bc / 255.0F;
return true;
}
// #RRGGBBAA
if (hex.size() == 9) {
std::stringstream ss(hex);
unsigned int rgba;
char ch {};
ss >> ch >> std::hex >> rgba;
int rc = (rgba >> 24) & 0xff;
int gc = (rgba >> 16) & 0xff;
int bc = (rgba >> 8) & 0xff;
int ac = rgba & 0xff;
r = rc / 255.0F;
g = gc / 255.0F;
b = bc / 255.0F;
a = ac / 255.0F;
return true;
}
return false;
}
// NOLINTEND(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)

View File

@@ -1,232 +0,0 @@
/***************************************************************************
* Copyright (c) 2005 Jürgen Riegel <juergen.riegel@web.de> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef APP_COLOR_H
#define APP_COLOR_H
#ifdef __GNUC__
#include <cstdint>
#endif
#include <cmath>
#include <string>
#include <FCGlobal.h>
// NOLINTBEGIN(readability-magic-numbers)
namespace App
{
template<class color_type>
struct color_traits
{
color_traits() = default;
explicit color_traits(const color_type& ct)
: ct(ct)
{}
float redF() const
{
return static_cast<float>(ct.redF());
}
float greenF() const
{
return static_cast<float>(ct.greenF());
}
float blueF() const
{
return static_cast<float>(ct.blueF());
}
float alphaF() const
{
return static_cast<float>(ct.alphaF());
}
int red() const
{
return ct.red();
}
int green() const
{
return ct.green();
}
int blue() const
{
return ct.blue();
}
int alpha() const
{
return ct.alpha();
}
static color_type makeColor(int red, int green, int blue, int alpha = 255)
{
return color_type {red, green, blue, alpha};
}
private:
color_type ct;
};
/** Color class
*/
class AppExport Color
{
public:
/**
* Defines the color as (R,G,B,A) whereas all values are in the range [0,1].
* \a A defines the alpha value.
*/
explicit Color(float R = 0.0, float G = 0.0, float B = 0.0, float A = 1.0);
/**
* Does basically the same as the constructor above unless that (R,G,B,A) is
* encoded as an unsigned int.
*/
explicit Color(uint32_t rgba);
/** Copy constructor. */
Color(const Color& c) = default;
Color(Color&&) = default;
/** Returns true if both colors are equal. Therefore all components must be equal. */
bool operator==(const Color& c) const;
bool operator!=(const Color& c) const;
/**
* Defines the color as (R,G,B,A) whereas all values are in the range [0,1].
* \a A defines the alpha value, 1 means fully opaque and 0 transparent.
*/
void set(float R, float G, float B, float A = 1.0);
float transparency() const;
void setTransparency(float value);
Color& operator=(const Color& c) = default;
Color& operator=(Color&& c) = default;
/**
* Sets the color value as a 32 bit combined red/green/blue/alpha value.
* Each component is 8 bit wide (i.e. from 0x00 to 0xff), and the red
* value should be stored leftmost, like this: 0xRRGGBBAA.
*
* \sa getPackedValue().
*/
Color& setPackedValue(uint32_t rgba);
/**
* Returns color as a 32 bit packed unsigned int in the form 0xRRGGBBAA.
*
* \sa setPackedValue().
*/
uint32_t getPackedValue() const;
/**
* Returns color as a 32 bit packed unsigned int in the form 0xRRGGBB.
*/
uint32_t getPackedRGB() const;
/**
* Sets color as a 32 bit packed unsigned int in the form 0xRRGGBB.
*/
void setPackedRGB(uint32_t);
/**
* Returns color as a 32 bit packed unsigned int in the form 0xAARRGGBB.
*/
uint32_t getPackedARGB() const;
/**
* Sets color as a 32 bit packed unsigned int in the form 0xAARRGGBB.
*/
void setPackedARGB(uint32_t);
template<typename T>
static uint32_t asPackedRGBA(const T& color)
{
color_traits<T> ct {color};
return (ct.red() << 24) | (ct.green() << 16) | (ct.blue() << 8) | ct.alpha();
}
template<typename T>
static T fromPackedRGBA(uint32_t color)
{
return color_traits<T>::makeColor((color >> 24) & 0xff,
(color >> 16) & 0xff,
(color >> 8) & 0xff,
(color & 0xff));
}
template<typename T>
static uint32_t asPackedRGB(const T& color)
{
color_traits<T> ct {color};
return (ct.red() << 24) | (ct.green() << 16) | (ct.blue() << 8);
}
template<typename T>
static T fromPackedRGB(uint32_t color)
{
return color_traits<T>::makeColor((color >> 24) & 0xff,
(color >> 16) & 0xff,
(color >> 8) & 0xff);
}
/**
* creates FC Color from template type, e.g. Qt QColor
*/
template<typename T>
void setValue(const T& q)
{
color_traits<T> ct {q};
set(ct.redF(), ct.greenF(), ct.blueF(), ct.alphaF());
}
/**
* returns a template type e.g. Qt color equivalent to FC color
*
*/
template<typename T>
inline T asValue() const
{
// clang-format off
return color_traits<T>::makeColor(int(std::lround(r * 255.0F)),
int(std::lround(g * 255.0F)),
int(std::lround(b * 255.0F)),
int(std::lround(a * 255.0F)));
// clang-format on
}
/**
* creates FC Color from template type, e.g. Qt QColor
*/
template<typename T>
static Color fromValue(const T& q)
{
color_traits<T> ct {q};
return Color(ct.redF(), ct.greenF(), ct.blueF(), ct.alphaF());
}
/**
* returns color as hex color "#RRGGBB"
*
*/
std::string asHexString() const;
/**
* gets color from hex color "#RRGGBB"
*
*/
bool fromHexString(const std::string& hex);
/// color values, public accessible
float r {}, g {}, b {}, a {};
};
} // namespace App
// NOLINTEND(readability-magic-numbers)
#endif // APP_COLOR_H

View File

@@ -138,8 +138,8 @@ void ColorField::rebuild()
fConstant = -fAscent * fMin;
}
// fuellt das Array von Farbe 1, Index 1 bis Farbe 2, Index 2
void ColorField::interpolate(Color clCol1, std::size_t usInd1, Color clCol2, std::size_t usInd2)
// fills the array from color 1, index 1 to color 2, index 2
void ColorField::interpolate(Base::Color clCol1, std::size_t usInd1, Base::Color clCol2, std::size_t usInd2)
{
float fStep = 1.0f, fLen = float(usInd2 - usInd1);
@@ -154,7 +154,7 @@ void ColorField::interpolate(Color clCol1, std::size_t usInd1, Color clCol2, std
float ucR = clCol1.r + fR * fStep;
float ucG = clCol1.g + fG * fStep;
float ucB = clCol1.b + fB * fStep;
colorField[i] = Color(ucR, ucG, ucB);
colorField[i] = Base::Color(ucR, ucG, ucB);
fStep += 1.0f;
}
}
@@ -370,20 +370,20 @@ bool ColorLegend::setValue(std::size_t ulPos, float fVal)
}
}
Color ColorLegend::getColor(std::size_t ulPos) const
Base::Color ColorLegend::getColor(std::size_t ulPos) const
{
if (ulPos < colorFields.size()) {
return colorFields[ulPos];
}
else {
return Color();
return Base::Color();
}
}
// color as: 0x00rrggbb
uint32_t ColorLegend::getPackedColor(std::size_t ulPos) const
{
Color clRGB = getColor(ulPos);
Base::Color clRGB = getColor(ulPos);
return clRGB.getPackedValue();
}
@@ -402,7 +402,7 @@ std::size_t ColorLegend::addMin(const std::string& rclName)
names.push_front(rclName);
values.push_front(values.front() - 1.0f);
Color clNewRGB;
Base::Color clNewRGB;
clNewRGB.r = ((float)rand() / (float)RAND_MAX);
clNewRGB.g = ((float)rand() / (float)RAND_MAX);
clNewRGB.b = ((float)rand() / (float)RAND_MAX);
@@ -417,7 +417,7 @@ std::size_t ColorLegend::addMax(const std::string& rclName)
names.push_back(rclName);
values.push_back(values.back() + 1.0f);
Color clNewRGB;
Base::Color clNewRGB;
clNewRGB.r = ((float)rand() / (float)RAND_MAX);
clNewRGB.g = ((float)rand() / (float)RAND_MAX);
clNewRGB.b = ((float)rand() / (float)RAND_MAX);
@@ -481,7 +481,7 @@ void ColorLegend::resize(std::size_t ulCt)
bool ColorLegend::setColor(std::size_t ulPos, float ucRed, float ucGreen, float ucBlue)
{
if (ulPos < names.size()) {
colorFields[ulPos] = Color(ucRed, ucGreen, ucBlue);
colorFields[ulPos] = Base::Color(ucRed, ucGreen, ucBlue);
return true;
}

View File

@@ -32,7 +32,6 @@
#include <string>
#include <vector>
namespace App
{
@@ -64,7 +63,7 @@ namespace App
class AppExport ValueFloatToRGB
{
public:
virtual Color getColor(float fVal) const = 0;
virtual Base::Color getColor(float fVal) const = 0;
protected:
ValueFloatToRGB() = default;
@@ -87,7 +86,7 @@ public:
{
return colors.size();
}
std::vector<Color> colors;
std::vector<Base::Color> colors;
};
class AppExport ColorModelBlueGreenRed: public ColorModel
@@ -96,11 +95,11 @@ public:
ColorModelBlueGreenRed()
: ColorModel(5)
{
colors[0] = Color(0, 0, 1);
colors[1] = Color(0, 1, 1);
colors[2] = Color(0, 1, 0);
colors[3] = Color(1, 1, 0);
colors[4] = Color(1, 0, 0);
colors[0] = Base::Color(0, 0, 1);
colors[1] = Base::Color(0, 1, 1);
colors[2] = Base::Color(0, 1, 0);
colors[3] = Base::Color(1, 1, 0);
colors[4] = Base::Color(1, 0, 0);
}
};
@@ -110,9 +109,9 @@ public:
ColorModelBlueCyanGreen()
: ColorModel(3)
{
colors[0] = Color(0, 0, 1);
colors[1] = Color(0, 1, 1);
colors[2] = Color(0, 1, 0);
colors[0] = Base::Color(0, 0, 1);
colors[1] = Base::Color(0, 1, 1);
colors[2] = Base::Color(0, 1, 0);
}
};
@@ -122,9 +121,9 @@ public:
ColorModelGreenYellowRed()
: ColorModel(3)
{
colors[0] = Color(0, 1, 0);
colors[1] = Color(1, 1, 0);
colors[2] = Color(1, 0, 0);
colors[0] = Base::Color(0, 1, 0);
colors[1] = Base::Color(1, 1, 0);
colors[2] = Base::Color(1, 0, 0);
}
};
@@ -134,11 +133,11 @@ public:
ColorModelRedGreenBlue()
: ColorModel(5)
{
colors[0] = Color(1, 0, 0);
colors[1] = Color(1, 1, 0);
colors[2] = Color(0, 1, 0);
colors[3] = Color(0, 1, 1);
colors[4] = Color(0, 0, 1);
colors[0] = Base::Color(1, 0, 0);
colors[1] = Base::Color(1, 1, 0);
colors[2] = Base::Color(0, 1, 0);
colors[3] = Base::Color(0, 1, 1);
colors[4] = Base::Color(0, 0, 1);
}
};
@@ -148,9 +147,9 @@ public:
ColorModelGreenCyanBlue()
: ColorModel(3)
{
colors[0] = Color(0, 1, 0);
colors[1] = Color(0, 1, 1);
colors[2] = Color(0, 0, 1);
colors[0] = Base::Color(0, 1, 0);
colors[1] = Base::Color(0, 1, 1);
colors[2] = Base::Color(0, 0, 1);
}
};
@@ -160,9 +159,9 @@ public:
ColorModelRedYellowGreen()
: ColorModel(3)
{
colors[0] = Color(1, 0, 0);
colors[1] = Color(1, 1, 0);
colors[2] = Color(0, 1, 0);
colors[0] = Base::Color(1, 0, 0);
colors[1] = Base::Color(1, 1, 0);
colors[2] = Base::Color(0, 1, 0);
}
};
@@ -172,11 +171,11 @@ public:
ColorModelBlueWhiteRed()
: ColorModel(5)
{
colors[0] = Color(0, 0, 1);
colors[1] = Color(float(85.0 / 255), float(170.0 / 255), 1);
colors[2] = Color(1, 1, 1);
colors[3] = Color(1, float(85.0 / 255), 0);
colors[4] = Color(1, 0, 0);
colors[0] = Base::Color(0, 0, 1);
colors[1] = Base::Color(float(85.0 / 255), float(170.0 / 255), 1);
colors[2] = Base::Color(1, 1, 1);
colors[3] = Base::Color(1, float(85.0 / 255), 0);
colors[4] = Base::Color(1, 0, 0);
}
};
@@ -186,9 +185,9 @@ public:
ColorModelBlueWhite()
: ColorModel(3)
{
colors[0] = Color(0, 0, 1);
colors[1] = Color(float(85.0 / 255), float(170.0 / 255), 1);
colors[2] = Color(1, 1, 1);
colors[0] = Base::Color(0, 0, 1);
colors[1] = Base::Color(float(85.0 / 255), float(170.0 / 255), 1);
colors[2] = Base::Color(1, 1, 1);
}
};
@@ -198,9 +197,9 @@ public:
ColorModelWhiteRed()
: ColorModel(3)
{
colors[0] = Color(1, 1, 1);
colors[1] = Color(1, float(85.0 / 255), 0);
colors[2] = Color(1, 0, 0);
colors[0] = Base::Color(1, 1, 1);
colors[1] = Base::Color(1, float(85.0 / 255), 0);
colors[2] = Base::Color(1, 0, 0);
}
};
@@ -210,8 +209,8 @@ public:
ColorModelBlackWhite()
: ColorModel(2)
{
colors[0] = Color(0, 0, 0);
colors[1] = Color(1, 1, 1);
colors[0] = Base::Color(0, 0, 0);
colors[1] = Base::Color(1, 1, 1);
}
};
@@ -221,8 +220,8 @@ public:
ColorModelBlackGray()
: ColorModel(2)
{
colors[0] = Color(0.0f, 0.0f, 0.0f);
colors[1] = Color(0.5f, 0.5f, 0.5f);
colors[0] = Base::Color(0.0f, 0.0f, 0.0f);
colors[1] = Base::Color(0.5f, 0.5f, 0.5f);
}
};
@@ -232,8 +231,8 @@ public:
ColorModelGrayWhite()
: ColorModel(2)
{
colors[0] = Color(0.5f, 0.5f, 0.5f);
colors[1] = Color(1.0f, 1.0f, 1.0f);
colors[0] = Base::Color(0.5f, 0.5f, 0.5f);
colors[1] = Base::Color(1.0f, 1.0f, 1.0f);
}
};
@@ -243,8 +242,8 @@ public:
ColorModelWhiteBlack()
: ColorModel(2)
{
colors[0] = Color(1, 1, 1);
colors[1] = Color(0, 0, 0);
colors[0] = Base::Color(1, 1, 1);
colors[1] = Base::Color(0, 0, 0);
}
};
@@ -254,8 +253,8 @@ public:
ColorModelWhiteGray()
: ColorModel(2)
{
colors[0] = Color(1.0f, 1.0f, 1.0f);
colors[1] = Color(0.5f, 0.5f, 0.5f);
colors[0] = Base::Color(1.0f, 1.0f, 1.0f);
colors[1] = Base::Color(0.5f, 0.5f, 0.5f);
}
};
@@ -265,8 +264,8 @@ public:
ColorModelGrayBlack()
: ColorModel(2)
{
colors[0] = Color(0.5f, 0.5f, 0.5f);
colors[1] = Color(0.0f, 0.0f, 0.0f);
colors[0] = Base::Color(0.5f, 0.5f, 0.5f);
colors[1] = Base::Color(0.0f, 0.0f, 0.0f);
}
};
@@ -320,7 +319,7 @@ public:
{
return colorModel;
}
void setDirect(std::size_t usInd, Color clCol)
void setDirect(std::size_t usInd, Base::Color clCol)
{
colorField[usInd] = clCol;
}
@@ -333,11 +332,11 @@ public:
return fMax;
}
Color getColor(std::size_t usIndex) const
Base::Color getColor(std::size_t usIndex) const
{
return colorField[usIndex];
}
inline Color getColor(float fVal) const;
inline Base::Color getColor(float fVal) const;
inline std::size_t getColorIndex(float fVal) const;
protected:
@@ -345,13 +344,13 @@ protected:
float fMin, fMax;
float fAscent, fConstant; // Index := _fConstant + _fAscent * WERT
std::size_t ctColors;
std::vector<Color> colorField;
std::vector<Base::Color> colorField;
void rebuild();
void interpolate(Color clCol1, std::size_t usPos1, Color clCol2, std::size_t usPos2);
void interpolate(Base::Color clCol1, std::size_t usPos1, Base::Color clCol2, std::size_t usPos2);
};
inline Color ColorField::getColor(float fVal) const
inline Base::Color ColorField::getColor(float fVal) const
{
// if the value is outside or at the border of the range
std::size_t ct = colorModel.getCountColors() - 1;
@@ -362,16 +361,16 @@ inline Color ColorField::getColor(float fVal) const
return colorModel.colors[ct];
}
// get the color field position (with 0 < t < 1)
// get the Base::Color field position (with 0 < t < 1)
float t = (fVal - fMin) / (fMax - fMin);
Color col(1.0f, 1.0f, 1.0f); // white as default
Base::Color col(1.0f, 1.0f, 1.0f); // white as default
for (std::size_t i = 0; i < ct; i++) {
float r = (float)(i + 1) / (float)ct;
if (t < r) {
// calculate the exact position in the subrange
float s = t * float(ct) - float(i);
Color c1 = colorModel.colors[i];
Color c2 = colorModel.colors[i + 1];
Base::Color c1 = colorModel.colors[i];
Base::Color c2 = colorModel.colors[i + 1];
col.r = (1.0f - s) * c1.r + s * c2.r;
col.g = (1.0f - s) * c1.g + s * c2.g;
col.b = (1.0f - s) * c1.b + s * c2.b;
@@ -484,11 +483,11 @@ public:
return profile.fMax;
}
inline Color getColor(float fVal) const;
inline Base::Color getColor(float fVal) const;
inline std::size_t getColorIndex(float fVal) const;
private:
inline Color _getColor(float fVal) const;
inline Base::Color _getColor(float fVal) const;
protected:
void createStandardPacks();
@@ -525,7 +524,7 @@ public:
void removeFirst();
void removeLast();
Color getColor(std::size_t ulPos) const;
Base::Color getColor(std::size_t ulPos) const;
uint32_t getPackedColor(std::size_t ulPos) const;
bool setColor(std::size_t ulPos, float ucRed, float ucGreen, float ucBlue);
bool setColor(std::size_t ulPos, unsigned long ulColor);
@@ -548,17 +547,17 @@ public:
inline float getMinValue() const;
inline float getMaxValue() const;
inline Color getColor(float fVal) const;
inline Base::Color getColor(float fVal) const;
inline std::size_t getColorIndex(float fVal) const;
protected:
std::deque<Color> colorFields;
std::deque<Base::Color> colorFields;
std::deque<std::string> names;
std::deque<float> values;
bool outsideGrayed {false};
};
inline Color ColorLegend::getColor(float fVal) const
inline Base::Color ColorLegend::getColor(float fVal) const
{
std::deque<float>::const_iterator pI;
for (pI = values.begin(); pI != values.end(); ++pI) {
@@ -569,7 +568,7 @@ inline Color ColorLegend::getColor(float fVal) const
if (outsideGrayed) {
if ((pI == values.begin()) || (pI == values.end())) {
return Color(0.5f, 0.5f, 0.5f);
return Base::Color(0.5f, 0.5f, 0.5f);
}
else {
return colorFields[pI - values.begin() - 1];
@@ -617,23 +616,23 @@ inline float ColorLegend::getMaxValue() const
return values.back();
}
inline Color ColorGradient::getColor(float fVal) const
inline Base::Color ColorGradient::getColor(float fVal) const
{
Color color = _getColor(fVal);
Base::Color Color = _getColor(fVal);
if (isOutsideInvisible()) {
if (isOutOfRange(fVal)) {
color.a = 0.2F;
Color.a = 0.2F;
}
}
return color;
return Color;
}
inline Color ColorGradient::_getColor(float fVal) const
inline Base::Color ColorGradient::_getColor(float fVal) const
{
if (isOutsideGrayed()) {
if (isOutOfRange(fVal)) {
return Color(0.5f, 0.5f, 0.5f);
return Base::Color(0.5f, 0.5f, 0.5f);
}
}

View File

@@ -70,7 +70,7 @@ FeatureTest::FeatureTest()
ADD_PROPERTY(ConstraintFloat, (5.0));
ConstraintFloat.setConstraints(&floatPercent);
App::Color c;
Base::Color c;
App::Material mat(App::Material::GOLD);
ADD_PROPERTY(Colour, (c));
ADD_PROPERTY(ColourList, (c));

View File

@@ -339,7 +339,7 @@ App::Material Material::getDefaultAppearance()
ParameterGrp::handle hGrp =
App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View");
auto getColor = [hGrp](const char* parameter, App::Color& color) {
auto getColor = [hGrp](const char* parameter, Base::Color& color) {
uint32_t packed = color.getPackedRGB();
packed = hGrp->GetUnsigned(parameter, packed);
color.setPackedRGB(packed);
@@ -363,10 +363,10 @@ App::Material Material::getDefaultAppearance()
float red = static_cast<float>(intRandom(0, 255)) / 255.0F;
float green = static_cast<float>(intRandom(0, 255)) / 255.0F;
float blue = static_cast<float>(intRandom(0, 255)) / 255.0F;
mat.diffuseColor = App::Color(red, green, blue);
mat.diffuseColor = Base::Color(red, green, blue);
}
else {
// Color = (204, 204, 230) = 3435980543UL
// Base::Color = (204, 204, 230) = 3435980543UL
getColor("DefaultShapeColor", mat.diffuseColor);
}

View File

@@ -24,7 +24,7 @@
#ifndef APP_MATERIAL_H
#define APP_MATERIAL_H
#include <App/Color.h>
#include <Base/Color.h>
namespace App
{
@@ -104,7 +104,7 @@ public:
* \li Ruby
* \li Emerald
* Furthermore there two additional modes \a Default which defines a kind of grey metallic and
* user defined that does nothing. The Color and the other properties of the material are
* user defined that does nothing. The Base::Color and the other properties of the material are
* defined in the range [0-1]. If \a MatName is an unknown material name then the type
* USER_DEFINED is set and the material doesn't get changed.
*/
@@ -125,10 +125,10 @@ public:
/** @name Properties */
//@{
// NOLINTBEGIN
Color ambientColor; /**< Defines the ambient color. */
Color diffuseColor; /**< Defines the diffuse color. */
Color specularColor; /**< Defines the specular color. */
Color emissiveColor; /**< Defines the emissive color. */
Base::Color ambientColor; /**< Defines the ambient color. */
Base::Color diffuseColor; /**< Defines the diffuse color. */
Base::Color specularColor; /**< Defines the specular color. */
Base::Color emissiveColor; /**< Defines the emissive color. */
float shininess;
float transparency;
std::string image;

View File

@@ -64,7 +64,7 @@ Satin, Metalized, Neon GNC, Chrome, Aluminium, Obsidian, Neon PHC, Jade, Ruby or
</Attribute>
<CustomAttributes />
<ClassDeclarations>public:
static App::Color toColor(PyObject* value);
static Base::Color toColor(PyObject* value);
</ClassDeclarations>
</PythonExport>
</GenerateModel>

View File

@@ -32,9 +32,9 @@
using namespace App;
Color MaterialPy::toColor(PyObject* value)
Base::Color MaterialPy::toColor(PyObject* value)
{
Color cCol;
Base::Color cCol;
if (PyTuple_Check(value) && (PyTuple_Size(value) == 3 || PyTuple_Size(value) == 4)) {
PyObject* item {};
item = PyTuple_GetItem(value, 0);

View File

@@ -2301,7 +2301,7 @@ PropertyColor::~PropertyColor() = default;
//**************************************************************************
// Base class implementer
void PropertyColor::setValue(const Color& col)
void PropertyColor::setValue(const Base::Color& col)
{
aboutToSetValue();
_cCol = col;
@@ -2322,7 +2322,7 @@ void PropertyColor::setValue(float r, float g, float b, float a)
hasSetValue();
}
const Color& PropertyColor::getValue() const
const Base::Color& PropertyColor::getValue() const
{
return _cCol;
}
@@ -2345,7 +2345,7 @@ PyObject* PropertyColor::getPyObject()
void PropertyColor::setPyObject(PyObject* value)
{
App::Color cCol;
Base::Color cCol;
if (PyTuple_Check(value) && (PyTuple_Size(value) == 3 || PyTuple_Size(value) == 4)) {
PyObject* item;
item = PyTuple_GetItem(value, 0);
@@ -2485,7 +2485,7 @@ PyObject* PropertyColorList::getPyObject()
return list;
}
Color PropertyColorList::getPyValue(PyObject* item) const
Base::Color PropertyColorList::getPyValue(PyObject* item) const
{
PropertyColor col;
col.setPyObject(item);
@@ -2529,7 +2529,7 @@ void PropertyColorList::RestoreDocFile(Base::Reader& reader)
Base::InputStream str(reader);
uint32_t uCt = 0;
str >> uCt;
std::vector<Color> values(uCt);
std::vector<Base::Color> values(uCt);
uint32_t value; // must be 32 bit long
for (auto& it : values) {
str >> value;
@@ -2552,7 +2552,7 @@ void PropertyColorList::Paste(const Property& from)
unsigned int PropertyColorList::getMemSize() const
{
return static_cast<unsigned int>(_lValueList.size() * sizeof(Color));
return static_cast<unsigned int>(_lValueList.size() * sizeof(Base::Color));
}
//**************************************************************************
@@ -2573,7 +2573,7 @@ void PropertyMaterial::setValue(const Material& mat)
hasSetValue();
}
void PropertyMaterial::setValue(const Color& col)
void PropertyMaterial::setValue(const Base::Color& col)
{
setDiffuseColor(col);
}
@@ -2593,7 +2593,7 @@ const Material& PropertyMaterial::getValue() const
return _cMat;
}
void PropertyMaterial::setAmbientColor(const Color& col)
void PropertyMaterial::setAmbientColor(const Base::Color& col)
{
aboutToSetValue();
_cMat.ambientColor = col;
@@ -2614,7 +2614,7 @@ void PropertyMaterial::setAmbientColor(uint32_t rgba)
hasSetValue();
}
void PropertyMaterial::setDiffuseColor(const Color& col)
void PropertyMaterial::setDiffuseColor(const Base::Color& col)
{
aboutToSetValue();
_cMat.diffuseColor = col;
@@ -2635,7 +2635,7 @@ void PropertyMaterial::setDiffuseColor(uint32_t rgba)
hasSetValue();
}
void PropertyMaterial::setSpecularColor(const Color& col)
void PropertyMaterial::setSpecularColor(const Base::Color& col)
{
aboutToSetValue();
_cMat.specularColor = col;
@@ -2656,7 +2656,7 @@ void PropertyMaterial::setSpecularColor(uint32_t rgba)
hasSetValue();
}
void PropertyMaterial::setEmissiveColor(const Color& col)
void PropertyMaterial::setEmissiveColor(const Base::Color& col)
{
aboutToSetValue();
_cMat.emissiveColor = col;
@@ -2691,22 +2691,22 @@ void PropertyMaterial::setTransparency(float val)
hasSetValue();
}
const Color& PropertyMaterial::getAmbientColor() const
const Base::Color& PropertyMaterial::getAmbientColor() const
{
return _cMat.ambientColor;
}
const Color& PropertyMaterial::getDiffuseColor() const
const Base::Color& PropertyMaterial::getDiffuseColor() const
{
return _cMat.diffuseColor;
}
const Color& PropertyMaterial::getSpecularColor() const
const Base::Color& PropertyMaterial::getSpecularColor() const
{
return _cMat.specularColor;
}
const Color& PropertyMaterial::getEmissiveColor() const
const Base::Color& PropertyMaterial::getEmissiveColor() const
{
return _cMat.emissiveColor;
}
@@ -2894,7 +2894,7 @@ void PropertyMaterialList::setValue(int index, const Material& mat)
hasSetValue();
}
void PropertyMaterialList::setAmbientColor(const Color& col)
void PropertyMaterialList::setAmbientColor(const Base::Color& col)
{
aboutToSetValue();
setMinimumSizeOne();
@@ -2924,7 +2924,7 @@ void PropertyMaterialList::setAmbientColor(uint32_t rgba)
hasSetValue();
}
void PropertyMaterialList::setAmbientColor(int index, const Color& col)
void PropertyMaterialList::setAmbientColor(int index, const Base::Color& col)
{
verifyIndex(index);
@@ -2954,7 +2954,7 @@ void PropertyMaterialList::setAmbientColor(int index, uint32_t rgba)
hasSetValue();
}
void PropertyMaterialList::setDiffuseColor(const Color& col)
void PropertyMaterialList::setDiffuseColor(const Base::Color& col)
{
aboutToSetValue();
setMinimumSizeOne();
@@ -2984,7 +2984,7 @@ void PropertyMaterialList::setDiffuseColor(uint32_t rgba)
hasSetValue();
}
void PropertyMaterialList::setDiffuseColor(int index, const Color& col)
void PropertyMaterialList::setDiffuseColor(int index, const Base::Color& col)
{
verifyIndex(index);
@@ -3014,7 +3014,7 @@ void PropertyMaterialList::setDiffuseColor(int index, uint32_t rgba)
hasSetValue();
}
void PropertyMaterialList::setDiffuseColors(const std::vector<App::Color>& colors)
void PropertyMaterialList::setDiffuseColors(const std::vector<Base::Color>& colors)
{
aboutToSetValue();
setSize(colors.size(), _lValueList[0]);
@@ -3025,7 +3025,7 @@ void PropertyMaterialList::setDiffuseColors(const std::vector<App::Color>& color
hasSetValue();
}
void PropertyMaterialList::setSpecularColor(const Color& col)
void PropertyMaterialList::setSpecularColor(const Base::Color& col)
{
aboutToSetValue();
setMinimumSizeOne();
@@ -3055,7 +3055,7 @@ void PropertyMaterialList::setSpecularColor(uint32_t rgba)
hasSetValue();
}
void PropertyMaterialList::setSpecularColor(int index, const Color& col)
void PropertyMaterialList::setSpecularColor(int index, const Base::Color& col)
{
verifyIndex(index);
@@ -3085,7 +3085,7 @@ void PropertyMaterialList::setSpecularColor(int index, uint32_t rgba)
hasSetValue();
}
void PropertyMaterialList::setEmissiveColor(const Color& col)
void PropertyMaterialList::setEmissiveColor(const Base::Color& col)
{
aboutToSetValue();
setMinimumSizeOne();
@@ -3115,7 +3115,7 @@ void PropertyMaterialList::setEmissiveColor(uint32_t rgba)
hasSetValue();
}
void PropertyMaterialList::setEmissiveColor(int index, const Color& col)
void PropertyMaterialList::setEmissiveColor(int index, const Base::Color& col)
{
verifyIndex(index);
@@ -3196,29 +3196,29 @@ void PropertyMaterialList::setTransparencies(const std::vector<float>& transpare
hasSetValue();
}
const Color& PropertyMaterialList::getAmbientColor() const
const Base::Color& PropertyMaterialList::getAmbientColor() const
{
return _lValueList[0].ambientColor;
}
const Color& PropertyMaterialList::getAmbientColor(int index) const
const Base::Color& PropertyMaterialList::getAmbientColor(int index) const
{
return _lValueList[index].ambientColor;
}
const Color& PropertyMaterialList::getDiffuseColor() const
const Base::Color& PropertyMaterialList::getDiffuseColor() const
{
return _lValueList[0].diffuseColor;
}
const Color& PropertyMaterialList::getDiffuseColor(int index) const
const Base::Color& PropertyMaterialList::getDiffuseColor(int index) const
{
return _lValueList[index].diffuseColor;
}
std::vector<App::Color> PropertyMaterialList::getDiffuseColors() const
std::vector<Base::Color> PropertyMaterialList::getDiffuseColors() const
{
std::vector<App::Color> list;
std::vector<Base::Color> list;
for (auto& material : _lValueList) {
list.push_back(material.diffuseColor);
}
@@ -3226,22 +3226,22 @@ std::vector<App::Color> PropertyMaterialList::getDiffuseColors() const
return list;
}
const Color& PropertyMaterialList::getSpecularColor() const
const Base::Color& PropertyMaterialList::getSpecularColor() const
{
return _lValueList[0].specularColor;
}
const Color& PropertyMaterialList::getSpecularColor(int index) const
const Base::Color& PropertyMaterialList::getSpecularColor(int index) const
{
return _lValueList[index].specularColor;
}
const Color& PropertyMaterialList::getEmissiveColor() const
const Base::Color& PropertyMaterialList::getEmissiveColor() const
{
return _lValueList[0].emissiveColor;
}
const Color& PropertyMaterialList::getEmissiveColor(int index) const
const Base::Color& PropertyMaterialList::getEmissiveColor(int index) const
{
return _lValueList[index].emissiveColor;
}

View File

@@ -999,7 +999,7 @@ protected:
};
/** Color properties
/** Base::Color properties
* This is the father of all properties handling colors.
*/
class AppExport PropertyColor: public Property
@@ -1021,13 +1021,13 @@ public:
/** Sets the property
*/
void setValue(const Color& col);
void setValue(const Base::Color& col);
void setValue(float r, float g, float b, float a = 1.0F);
void setValue(uint32_t rgba);
/** This method returns a string representation of the property
*/
const Color& getValue() const;
const Base::Color& getValue() const;
const char* getEditorName() const override
{
@@ -1045,7 +1045,7 @@ public:
unsigned int getMemSize() const override
{
return sizeof(Color);
return sizeof(Base::Color);
}
bool isSame(const Property& other) const override
@@ -1058,10 +1058,10 @@ public:
}
private:
Color _cCol;
Base::Color _cCol;
};
class AppExport PropertyColorList: public PropertyListsT<Color>
class AppExport PropertyColorList: public PropertyListsT<Base::Color>
{
TYPESYSTEM_HEADER_WITH_OVERRIDE();
@@ -1091,7 +1091,7 @@ public:
unsigned int getMemSize() const override;
protected:
Color getPyValue(PyObject* py) const override;
Base::Color getPyValue(PyObject* py) const override;
};
@@ -1118,19 +1118,19 @@ public:
/** Sets the property
*/
void setValue(const Material& mat);
void setValue(const Color& col);
void setValue(const Base::Color& col);
void setValue(float r, float g, float b, float a = 1.0F);
void setValue(uint32_t rgba);
void setAmbientColor(const Color& col);
void setAmbientColor(const Base::Color& col);
void setAmbientColor(float r, float g, float b, float a = 1.0F);
void setAmbientColor(uint32_t rgba);
void setDiffuseColor(const Color& col);
void setDiffuseColor(const Base::Color& col);
void setDiffuseColor(float r, float g, float b, float a = 1.0F);
void setDiffuseColor(uint32_t rgba);
void setSpecularColor(const Color& col);
void setSpecularColor(const Base::Color& col);
void setSpecularColor(float r, float g, float b, float a = 1.0F);
void setSpecularColor(uint32_t rgba);
void setEmissiveColor(const Color& col);
void setEmissiveColor(const Base::Color& col);
void setEmissiveColor(float r, float g, float b, float a = 1.0F);
void setEmissiveColor(uint32_t rgba);
void setShininess(float);
@@ -1139,10 +1139,10 @@ public:
/** This method returns a string representation of the property
*/
const Material& getValue() const;
const Color& getAmbientColor() const;
const Color& getDiffuseColor() const;
const Color& getSpecularColor() const;
const Color& getEmissiveColor() const;
const Base::Color& getAmbientColor() const;
const Base::Color& getDiffuseColor() const;
const Base::Color& getSpecularColor() const;
const Base::Color& getEmissiveColor() const;
double getShininess() const;
double getTransparency() const;
@@ -1204,32 +1204,32 @@ public:
void setValue(const Material& mat);
void setValue(int index, const Material& mat);
void setAmbientColor(const Color& col);
void setAmbientColor(const Base::Color& col);
void setAmbientColor(float r, float g, float b, float a = 1.0F);
void setAmbientColor(uint32_t rgba);
void setAmbientColor(int index, const Color& col);
void setAmbientColor(int index, const Base::Color& col);
void setAmbientColor(int index, float r, float g, float b, float a = 1.0F);
void setAmbientColor(int index, uint32_t rgba);
void setDiffuseColor(const Color& col);
void setDiffuseColor(const Base::Color& col);
void setDiffuseColor(float r, float g, float b, float a = 1.0F);
void setDiffuseColor(uint32_t rgba);
void setDiffuseColor(int index, const Color& col);
void setDiffuseColor(int index, const Base::Color& col);
void setDiffuseColor(int index, float r, float g, float b, float a = 1.0F);
void setDiffuseColor(int index, uint32_t rgba);
void setDiffuseColors(const std::vector<App::Color>& colors);
void setDiffuseColors(const std::vector<Base::Color>& colors);
void setSpecularColor(const Color& col);
void setSpecularColor(const Base::Color& col);
void setSpecularColor(float r, float g, float b, float a = 1.0F);
void setSpecularColor(uint32_t rgba);
void setSpecularColor(int index, const Color& col);
void setSpecularColor(int index, const Base::Color& col);
void setSpecularColor(int index, float r, float g, float b, float a = 1.0F);
void setSpecularColor(int index, uint32_t rgba);
void setEmissiveColor(const Color& col);
void setEmissiveColor(const Base::Color& col);
void setEmissiveColor(float r, float g, float b, float a = 1.0F);
void setEmissiveColor(uint32_t rgba);
void setEmissiveColor(int index, const Color& col);
void setEmissiveColor(int index, const Base::Color& col);
void setEmissiveColor(int index, float r, float g, float b, float a = 1.0F);
void setEmissiveColor(int index, uint32_t rgba);
@@ -1240,18 +1240,18 @@ public:
void setTransparency(int index, float);
void setTransparencies(const std::vector<float>& transparencies);
const Color& getAmbientColor() const;
const Color& getAmbientColor(int index) const;
const Base::Color& getAmbientColor() const;
const Base::Color& getAmbientColor(int index) const;
const Color& getDiffuseColor() const;
const Color& getDiffuseColor(int index) const;
std::vector<App::Color> getDiffuseColors() const;
const Base::Color& getDiffuseColor() const;
const Base::Color& getDiffuseColor(int index) const;
std::vector<Base::Color> getDiffuseColors() const;
const Color& getSpecularColor() const;
const Color& getSpecularColor(int index) const;
const Base::Color& getSpecularColor() const;
const Base::Color& getSpecularColor(int index) const;
const Color& getEmissiveColor() const;
const Color& getEmissiveColor(int index) const;
const Base::Color& getEmissiveColor() const;
const Base::Color& getEmissiveColor(int index) const;
float getShininess() const;
float getShininess(int index) const;