// SPDX-License-Identifier: LGPL-2.1-or-later /*************************************************************************** * Copyright (c) 2024 David Carter * * * * This file is part of FreeCAD. * * * * FreeCAD is free software: you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as * * published by the Free Software Foundation, either version 2.1 of the * * License, or (at your option) any later version. * * * * FreeCAD 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with FreeCAD. If not, see * * . * * * **************************************************************************/ #include "PreCompiled.h" #ifndef _PreComp_ #include #endif #include #include #include "ViewProviderPartExtPy.h" #include "ViewProviderPartExtPy.cpp" using namespace PartGui; // returns a string which represents the object e.g. when printed in python std::string ViewProviderPartExtPy::representation() const { std::stringstream str; str << ""; return str.str(); } PyObject* ViewProviderPartExtPy::getCustomAttributes(const char* attr) const { ViewProviderPartExt* vp = getViewProviderPartExtPtr(); if (strcmp(attr, "DiffuseColor") == 0) { // Get the color properties App::PropertyColorList prop; std::vector colors = vp->ShapeAppearance.getDiffuseColors(); std::vector transparencies = vp->ShapeAppearance.getTransparencies(); for (int i = 0; i < static_cast(colors.size()); i++) { colors[i].setTransparency(transparencies[i]); } prop.setValues(colors); return prop.getPyObject(); } return nullptr; } int ViewProviderPartExtPy::setCustomAttributes(const char* attr, PyObject* obj) { ViewProviderPartExt* vp = getViewProviderPartExtPtr(); if (strcmp(attr, "DiffuseColor") == 0) { // Set the color properties App::PropertyColorList prop; prop.setPyObject(obj); std::vector colors = prop.getValues(); std::vector transparencies; transparencies.resize(static_cast(colors.size())); for (int i = 0; i < static_cast(colors.size()); i++) { transparencies[i] = colors[i].transparency(); colors[i].a = 1.0F; } vp->ShapeAppearance.setDiffuseColors(colors); vp->ShapeAppearance.setTransparencies(transparencies); return 1; } return 0; }