FreeCAD

Форк
0
/
DlgMaterialPropertiesImp.cpp 
177 строк · 6.0 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2006 Werner Mayer <wmayer[at]users.sourceforge.net>     *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
6
 *   This library is free software; you can redistribute it and/or         *
7
 *   modify it under the terms of the GNU Library General Public           *
8
 *   License as published by the Free Software Foundation; either          *
9
 *   version 2 of the License, or (at your option) any later version.      *
10
 *                                                                         *
11
 *   This library  is distributed in the hope that it will be useful,      *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
 *   GNU Library General Public License for more details.                  *
15
 *                                                                         *
16
 *   You should have received a copy of the GNU Library General Public     *
17
 *   License along with this library; see the file COPYING.LIB. If not,    *
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
19
 *   Suite 330, Boston, MA  02111-1307, USA                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23
#include "PreCompiled.h"
24

25
#include <App/PropertyStandard.h>
26

27
#include "DlgMaterialPropertiesImp.h"
28
#include "ui_DlgMaterialProperties.h"
29
#include "ViewProvider.h"
30

31

32
using namespace Gui::Dialog;
33

34

35
/* TRANSLATOR Gui::Dialog::DlgMaterialPropertiesImp */
36

37
DlgMaterialPropertiesImp::DlgMaterialPropertiesImp(QWidget* parent, Qt::WindowFlags fl)
38
    : QDialog(parent, fl)
39
    , ui(new Ui_DlgMaterialProperties)
40
{
41
    ui->setupUi(this);
42
    setupConnections();
43

44
    ui->ambientColor->setAutoChangeColor(true);
45
    ui->diffuseColor->setAutoChangeColor(true);
46
    ui->emissiveColor->setAutoChangeColor(true);
47
    ui->specularColor->setAutoChangeColor(true);
48
}
49

50
DlgMaterialPropertiesImp::~DlgMaterialPropertiesImp() = default;
51

52
void DlgMaterialPropertiesImp::setupConnections()
53
{
54
    // clang-format off
55
    connect(ui->ambientColor, &ColorButton::changed,
56
            this, &DlgMaterialPropertiesImp::onAmbientColorChanged);
57
    connect(ui->diffuseColor, &ColorButton::changed,
58
            this, &DlgMaterialPropertiesImp::onDiffuseColorChanged);
59
    connect(ui->emissiveColor, &ColorButton::clicked,
60
            this, &DlgMaterialPropertiesImp::onEmissiveColorChanged);
61
    connect(ui->specularColor, &ColorButton::clicked,
62
            this, &DlgMaterialPropertiesImp::onSpecularColorChanged);
63
    connect(ui->shininess, qOverload<int>(&QSpinBox::valueChanged),
64
            this, &DlgMaterialPropertiesImp::onShininessValueChanged);
65
    connect(ui->transparency, qOverload<int>(&QSpinBox::valueChanged),
66
            this, &DlgMaterialPropertiesImp::onTransparencyValueChanged);
67
    connect(ui->buttonReset, &QPushButton::clicked,
68
            this, &DlgMaterialPropertiesImp::onButtonReset);
69
    connect(ui->buttonDefault, &QPushButton::clicked,
70
            this, &DlgMaterialPropertiesImp::onButtonDefault);
71
    // clang-format on
72
}
73

74
void DlgMaterialPropertiesImp::setCustomMaterial(const App::Material& mat)
75
{
76
    customMaterial = mat;
77
    setButtonColors(customMaterial);
78
}
79

80
App::Material DlgMaterialPropertiesImp::getCustomMaterial() const
81
{
82
    return customMaterial;
83
}
84

85
void DlgMaterialPropertiesImp::setDefaultMaterial(const App::Material& mat)
86
{
87
    defaultMaterial = mat;
88
}
89

90
App::Material DlgMaterialPropertiesImp::getDefaultMaterial() const
91
{
92
    return defaultMaterial;
93
}
94

95
/**
96
 * Sets the ambient color.
97
 */
98
void DlgMaterialPropertiesImp::onAmbientColorChanged()
99
{
100
    customMaterial.ambientColor.setValue(ui->ambientColor->color());
101
}
102

103
/**
104
 * Sets the diffuse color.
105
 */
106
void DlgMaterialPropertiesImp::onDiffuseColorChanged()
107
{
108
    customMaterial.diffuseColor.setValue(ui->diffuseColor->color());
109
}
110

111
/**
112
 * Sets the emissive color.
113
 */
114
void DlgMaterialPropertiesImp::onEmissiveColorChanged()
115
{
116
    customMaterial.emissiveColor.setValue(ui->emissiveColor->color());
117
}
118

119
/**
120
 * Sets the specular color.
121
 */
122
void DlgMaterialPropertiesImp::onSpecularColorChanged()
123
{
124
    customMaterial.specularColor.setValue(ui->specularColor->color());
125
}
126

127
/**
128
 * Sets the current shininess.
129
 */
130
void DlgMaterialPropertiesImp::onShininessValueChanged(int sh)
131
{
132
    customMaterial.shininess = (float)sh / 100.0F;
133
}
134

135
/**
136
 * Sets the current transparency.
137
 */
138
void DlgMaterialPropertiesImp::onTransparencyValueChanged(int sh)
139
{
140
    customMaterial.transparency = (float)sh / 100.0F;
141
}
142

143
/**
144
 * Reset the colors to the Coin3D defaults
145
 */
146
void DlgMaterialPropertiesImp::onButtonReset()
147
{
148
    setCustomMaterial(getDefaultMaterial());
149
}
150

151
/**
152
 * Reset the colors to the current default
153
 */
154
void DlgMaterialPropertiesImp::onButtonDefault()
155
{
156
    App::Material mat = App::Material::getDefaultAppearance();
157
    setCustomMaterial(mat);
158
}
159

160
/**
161
 * Sets the button colors to match the current material settings.
162
 */
163
void DlgMaterialPropertiesImp::setButtonColors(const App::Material& mat)
164
{
165
    ui->ambientColor->setColor(mat.ambientColor.asValue<QColor>());
166
    ui->diffuseColor->setColor(mat.diffuseColor.asValue<QColor>());
167
    ui->emissiveColor->setColor(mat.emissiveColor.asValue<QColor>());
168
    ui->specularColor->setColor(mat.specularColor.asValue<QColor>());
169
    ui->shininess->blockSignals(true);
170
    ui->shininess->setValue((int)(100.0F * (mat.shininess + 0.001F)));
171
    ui->shininess->blockSignals(false);
172
    ui->transparency->blockSignals(true);
173
    ui->transparency->setValue((int)(100.0F * (mat.transparency + 0.001F)));
174
    ui->transparency->blockSignals(false);
175
}
176

177
#include "moc_DlgMaterialPropertiesImp.cpp"
178

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.