FreeCAD

Форк
0
/
MaterialPyImp.cpp 
212 строк · 6.7 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2010 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

24
#include "PreCompiled.h"
25

26
// inclusion of the generated files (generated out of MaterialPy.xml)
27
#include "MaterialPy.h"
28
#include "MaterialPy.cpp"
29
#include <Base/PyWrapParseTupleAndKeywords.h>
30

31
using namespace App;
32

33
PyObject *MaterialPy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
34
{
35
    // create a new instance of MaterialPy and the Twin object
36
    return new MaterialPy(new Material);
37
}
38

39
// constructor method
40
int MaterialPy::PyInit(PyObject* args, PyObject* kwds)
41
{
42
    PyObject* diffuse = nullptr;
43
    PyObject* ambient = nullptr;
44
    PyObject* specular = nullptr;
45
    PyObject* emissive = nullptr;
46
    PyObject* shininess = nullptr;
47
    PyObject* transparency = nullptr;
48
    static const std::array<const char *, 7> kwds_colors{"DiffuseColor", "AmbientColor", "SpecularColor",
49
                                                         "EmissiveColor", "Shininess", "Transparency", nullptr};
50

51
    if (!Base::Wrapped_ParseTupleAndKeywords(args, kwds, "|OOOOOO", kwds_colors,
52
        &diffuse, &ambient, &specular, &emissive, &shininess, &transparency)) {
53
        return -1;
54
    }
55

56
    if (diffuse) {
57
        setDiffuseColor(Py::Tuple(diffuse));
58
    }
59

60
    if (ambient) {
61
        setAmbientColor(Py::Tuple(ambient));
62
    }
63

64
    if (specular) {
65
        setSpecularColor(Py::Tuple(specular));
66
    }
67

68
    if (emissive) {
69
        setEmissiveColor(Py::Tuple(emissive));
70
    }
71

72
    if (shininess) {
73
        setShininess(Py::Float(shininess));
74
    }
75

76
    if (transparency) {
77
        setTransparency(Py::Float(transparency));
78
    }
79

80
    return 0;
81
}
82

83
// returns a string which represents the object e.g. when printed in python
84
std::string MaterialPy::representation() const
85
{
86
    return {"<Material object>"};
87
}
88

89
PyObject* MaterialPy::set(PyObject * args)
90
{
91
    char *pstr;
92
    if (!PyArg_ParseTuple(args, "s", &pstr))
93
        return nullptr;
94

95
    getMaterialPtr()->set(pstr);
96

97
    Py_Return;
98
}
99

100
Py::Tuple MaterialPy::getAmbientColor() const
101
{
102
    Py::Tuple tuple(4);
103
    tuple.setItem(0, Py::Float(getMaterialPtr()->ambientColor.r));
104
    tuple.setItem(1, Py::Float(getMaterialPtr()->ambientColor.g));
105
    tuple.setItem(2, Py::Float(getMaterialPtr()->ambientColor.b));
106
    tuple.setItem(3, Py::Float(getMaterialPtr()->ambientColor.a));
107
    return tuple;
108
}
109

110
void MaterialPy::setAmbientColor(Py::Tuple arg)
111
{
112
    Color c;
113
    c.r = Py::Float(arg.getItem(0));
114
    c.g = Py::Float(arg.getItem(1));
115
    c.b = Py::Float(arg.getItem(2));
116
    if (arg.size() == 4)
117
    c.a = Py::Float(arg.getItem(3));
118
    getMaterialPtr()->ambientColor = c;
119
}
120

121
Py::Tuple MaterialPy::getDiffuseColor() const
122
{
123
    Py::Tuple tuple(4);
124
    tuple.setItem(0, Py::Float(getMaterialPtr()->diffuseColor.r));
125
    tuple.setItem(1, Py::Float(getMaterialPtr()->diffuseColor.g));
126
    tuple.setItem(2, Py::Float(getMaterialPtr()->diffuseColor.b));
127
    tuple.setItem(3, Py::Float(getMaterialPtr()->diffuseColor.a));
128
    return tuple;
129
}
130

131
void MaterialPy::setDiffuseColor(Py::Tuple arg)
132
{
133
    Color c;
134
    c.r = Py::Float(arg.getItem(0));
135
    c.g = Py::Float(arg.getItem(1));
136
    c.b = Py::Float(arg.getItem(2));
137
    if (arg.size() == 4)
138
    c.a = Py::Float(arg.getItem(3));
139
    getMaterialPtr()->diffuseColor = c;
140
}
141

142
Py::Tuple MaterialPy::getEmissiveColor() const
143
{
144
    Py::Tuple tuple(4);
145
    tuple.setItem(0, Py::Float(getMaterialPtr()->emissiveColor.r));
146
    tuple.setItem(1, Py::Float(getMaterialPtr()->emissiveColor.g));
147
    tuple.setItem(2, Py::Float(getMaterialPtr()->emissiveColor.b));
148
    tuple.setItem(3, Py::Float(getMaterialPtr()->emissiveColor.a));
149
    return tuple;
150
}
151

152
void MaterialPy::setEmissiveColor(Py::Tuple arg)
153
{
154
    Color c;
155
    c.r = Py::Float(arg.getItem(0));
156
    c.g = Py::Float(arg.getItem(1));
157
    c.b = Py::Float(arg.getItem(2));
158
    if (arg.size() == 4)
159
    c.a = Py::Float(arg.getItem(3));
160
    getMaterialPtr()->emissiveColor = c;
161
}
162

163
Py::Tuple MaterialPy::getSpecularColor() const
164
{
165
    Py::Tuple tuple(4);
166
    tuple.setItem(0, Py::Float(getMaterialPtr()->specularColor.r));
167
    tuple.setItem(1, Py::Float(getMaterialPtr()->specularColor.g));
168
    tuple.setItem(2, Py::Float(getMaterialPtr()->specularColor.b));
169
    tuple.setItem(3, Py::Float(getMaterialPtr()->specularColor.a));
170
    return tuple;
171
}
172

173
void MaterialPy::setSpecularColor(Py::Tuple arg)
174
{
175
    Color c;
176
    c.r = Py::Float(arg.getItem(0));
177
    c.g = Py::Float(arg.getItem(1));
178
    c.b = Py::Float(arg.getItem(2));
179
    if (arg.size() == 4)
180
    c.a = Py::Float(arg.getItem(3));
181
    getMaterialPtr()->specularColor = c;
182
}
183

184
Py::Float MaterialPy::getShininess() const
185
{
186
    return Py::Float(getMaterialPtr()->shininess);
187
}
188

189
void MaterialPy::setShininess(Py::Float arg)
190
{
191
    getMaterialPtr()->shininess = arg;
192
}
193

194
Py::Float MaterialPy::getTransparency() const
195
{
196
    return Py::Float(getMaterialPtr()->transparency);
197
}
198

199
void MaterialPy::setTransparency(Py::Float arg)
200
{
201
    getMaterialPtr()->transparency = arg;
202
}
203

204
PyObject *MaterialPy::getCustomAttributes(const char* /*attr*/) const
205
{
206
    return nullptr;
207
}
208

209
int MaterialPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
210
{
211
    return 0;
212
}
213

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

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

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

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