Import: Fix import/export of STEP file
For the import/export use the transparency value of the material property. Since v1.0 the alpha channel of the diffuse color is used for this but when changing the transparency in the user interface this alpha channel won't be adjusted and thus leads to unexpected results. This fixes issue 18569
This commit is contained in:
@@ -21,22 +21,25 @@
|
||||
* *
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
#include "ExportOCAFGui.h"
|
||||
#include <Gui/Application.h>
|
||||
#include <Mod/Part/Gui/ViewProvider.h>
|
||||
|
||||
using namespace ImportGui;
|
||||
|
||||
|
||||
ExportOCAFGui::ExportOCAFGui(Handle(TDocStd_Document) hDoc, bool explicitPlacement)
|
||||
: ExportOCAF(hDoc, explicitPlacement)
|
||||
{}
|
||||
|
||||
void ExportOCAFGui::findColors(Part::Feature* part, std::vector<Base::Color>& colors) const
|
||||
{
|
||||
Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider(part);
|
||||
if (vp && vp->isDerivedFrom<PartGui::ViewProviderPartExt>()) {
|
||||
colors = static_cast<PartGui::ViewProviderPartExt*>(vp)->ShapeAppearance.getDiffuseColors();
|
||||
if (auto vp = Gui::Application::Instance->getViewProvider(part)) {
|
||||
if (auto vppe = freecad_cast<PartGui::ViewProviderPartExt*>(vp)) {
|
||||
colors = vppe->ShapeAppearance.getDiffuseColors();
|
||||
auto transp = vppe->ShapeAppearance.getTransparency();
|
||||
for (auto& it : colors) {
|
||||
it.setTransparency(transp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,15 @@ void ImportOCAFGui::applyFaceColors(Part::Feature* part, const std::vector<Base:
|
||||
}
|
||||
else {
|
||||
vp->ShapeAppearance.setDiffuseColors(colors);
|
||||
std::vector<float> transp;
|
||||
transp.reserve(colors.size());
|
||||
std::transform(
|
||||
colors.cbegin(),
|
||||
colors.cend(),
|
||||
std::back_inserter(transp),
|
||||
[](const Base::Color& col) { return col.transparency(); }
|
||||
);
|
||||
vp->ShapeAppearance.setTransparencies(transp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -759,7 +759,7 @@ std::map<std::string, Base::Color> ViewProviderPartExt::getElementColors(const c
|
||||
|
||||
if (!element || !element[0]) {
|
||||
auto color = ShapeAppearance.getDiffuseColor();
|
||||
color.setTransparency(Base::fromPercent(Transparency.getValue()));
|
||||
color.setTransparency(ShapeAppearance.getTransparency());
|
||||
ret["Face"] = color;
|
||||
ret["Edge"] = LineColor.getValue();
|
||||
ret["Vertex"] = PointColor.getValue();
|
||||
@@ -773,18 +773,16 @@ std::map<std::string, Base::Color> ViewProviderPartExt::getElementColors(const c
|
||||
color.setTransparency(Base::fromPercent(Transparency.getValue()));
|
||||
bool singleColor = true;
|
||||
for (int i = 0; i < size; ++i) {
|
||||
Base::Color faceColor = ShapeAppearance.getDiffuseColor(i);
|
||||
faceColor.setTransparency(ShapeAppearance.getTransparency(i));
|
||||
if (faceColor != color) {
|
||||
ret[std::string(element, 4) + std::to_string(i + 1)] = faceColor;
|
||||
auto color_i = ShapeAppearance.getDiffuseColor(i);
|
||||
color_i.setTransparency(ShapeAppearance.getTransparency(i));
|
||||
if (color_i != color) {
|
||||
ret[std::string(element, 4) + std::to_string(i + 1)] = color_i;
|
||||
}
|
||||
Base::Color firstFaceColor = ShapeAppearance.getDiffuseColor(0);
|
||||
firstFaceColor.setTransparency(ShapeAppearance.getTransparency(0));
|
||||
singleColor = singleColor && (faceColor == firstFaceColor);
|
||||
singleColor = singleColor && color == color_i;
|
||||
}
|
||||
if (size > 0 && singleColor) {
|
||||
color = ShapeAppearance.getDiffuseColor(0);
|
||||
color.setTransparency(ShapeAppearance.getTransparency(0));
|
||||
color.setTransparency(ShapeAppearance.getTransparency());
|
||||
ret.clear();
|
||||
}
|
||||
ret["Face"] = color;
|
||||
@@ -792,13 +790,17 @@ std::map<std::string, Base::Color> ViewProviderPartExt::getElementColors(const c
|
||||
else {
|
||||
int idx = atoi(element + 4);
|
||||
if (idx > 0 && idx <= size) {
|
||||
ret[element] = ShapeAppearance.getDiffuseColor(idx - 1);
|
||||
auto color_i = ShapeAppearance.getDiffuseColor(idx - 1);
|
||||
color_i.setTransparency(ShapeAppearance.getTransparency(idx - 1));
|
||||
ret[element] = color_i;
|
||||
}
|
||||
else {
|
||||
ret[element] = ShapeAppearance.getDiffuseColor();
|
||||
auto color_i = ShapeAppearance.getDiffuseColor();
|
||||
color_i.setTransparency(ShapeAppearance.getTransparency());
|
||||
ret[element] = color_i;
|
||||
}
|
||||
if (size == 1) {
|
||||
ret[element].setTransparency(Base::fromPercent(Transparency.getValue()));
|
||||
ret[element].setTransparency(ShapeAppearance.getTransparency());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user