File size: 19,747 Bytes
985c397
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
// SPDX-License-Identifier: LGPL-2.1-or-later

/***************************************************************************
 *   Copyright (c) 2023 David Carter <dcarter@david.carter.ca>             *
 *                                                                         *
 *   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                               *
 *   <https://www.gnu.org/licenses/>.                                      *
 *                                                                         *
 **************************************************************************/


#include <QMetaType>

#include <Base/Quantity.h>
#include <Base/QuantityPy.h>
#include <CXX/Objects.hxx>
#include <Gui/MetaTypes.h>

#include "Materials.h"

#include "Array2DPy.h"
#include "Array3DPy.h"
#include "Exceptions.h"
#include "MaterialLibrary.h"
#include "MaterialPy.h"
#include "MaterialValue.h"
#include "PyVariants.h"

#include "ModelPropertyPy.h"
#include "MaterialPropertyPy.h"

#include "MaterialPy.cpp"

using namespace Materials;

// returns a string which represents the object e.g. when printed in python
std::string MaterialPy::representation() const
{
    std::ostringstream str;
    str << "<Material at " << getMaterialPtr() << ">";
    return str.str();
}

PyObject* MaterialPy::PyMake(struct _typeobject*, PyObject*, PyObject*)  // Python wrapper
{
    // never create such objects with the constructor
    return new MaterialPy(new Material());
}

// constructor method
int MaterialPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
{
    return 0;
}

Py::String MaterialPy::getLibraryName() const
{
    auto library = getMaterialPtr()->getLibrary();
    if (library->isLocal()) {
        auto materialLibrary =
            reinterpret_cast<const std::shared_ptr<Materials::MaterialLibraryLocal>&>(library);
        return {materialLibrary ? materialLibrary->getName().toStdString() : ""};
    }
    return "";
}

Py::String MaterialPy::getLibraryRoot() const
{
    auto library = getMaterialPtr()->getLibrary();
    if (library->isLocal()) {
        auto materialLibrary =
            reinterpret_cast<const std::shared_ptr<Materials::MaterialLibraryLocal>&>(library);
        return {materialLibrary ? materialLibrary->getDirectoryPath().toStdString() : ""};
    }
    return "";
}

Py::Object MaterialPy::getLibraryIcon() const
{
    auto library = getMaterialPtr()->getLibrary();
    if (library->isLocal()) {
        auto materialLibrary =
            reinterpret_cast<const std::shared_ptr<Materials::MaterialLibraryLocal>&>(library);
        auto icon = materialLibrary->getIcon();
        if (icon.isNull()) {
            return Py::Bytes();
        }
        return Py::Bytes(icon.data(), icon.size());
    }
    return Py::Bytes();
}

Py::String MaterialPy::getName() const
{
    return {getMaterialPtr()->getName().toStdString()};
}

void MaterialPy::setName(Py::String arg)
{
    getMaterialPtr()->setName(QString::fromStdString(arg));
}

Py::String MaterialPy::getDirectory() const
{
    return {getMaterialPtr()->getDirectory().toStdString()};
}

void MaterialPy::setDirectory(Py::String arg)
{
    getMaterialPtr()->setDirectory(QString::fromStdString(arg));
}

Py::String MaterialPy::getUUID() const
{
    return {getMaterialPtr()->getUUID().toStdString()};
}

Py::String MaterialPy::getDescription() const
{
    return {getMaterialPtr()->getDescription().toStdString()};
}

void MaterialPy::setDescription(Py::String arg)
{
    getMaterialPtr()->setDescription(QString::fromStdString(arg));
}

Py::String MaterialPy::getURL() const
{
    return {getMaterialPtr()->getURL().toStdString()};
}

void MaterialPy::setURL(Py::String arg)
{
    getMaterialPtr()->setURL(QString::fromStdString(arg));
}

Py::String MaterialPy::getReference() const
{
    return {getMaterialPtr()->getReference().toStdString()};
}

void MaterialPy::setReference(Py::String arg)
{
    getMaterialPtr()->setReference(QString::fromStdString(arg));
}

Py::String MaterialPy::getParent() const
{
    return {getMaterialPtr()->getParentUUID().toStdString()};
}

void MaterialPy::setParent(Py::String arg)
{
    getMaterialPtr()->setParentUUID(QString::fromStdString(arg));
}

Py::String MaterialPy::getAuthorAndLicense() const
{
    return {getMaterialPtr()->getAuthorAndLicense().toStdString()};
}

Py::String MaterialPy::getAuthor() const
{
    return {getMaterialPtr()->getAuthor().toStdString()};
}

void MaterialPy::setAuthor(Py::String arg)
{
    getMaterialPtr()->setAuthor(QString::fromStdString(arg));
}

Py::String MaterialPy::getLicense() const
{
    return {getMaterialPtr()->getLicense().toStdString()};
}

void MaterialPy::setLicense(Py::String arg)
{
    getMaterialPtr()->setLicense(QString::fromStdString(arg));
}

Py::List MaterialPy::getPhysicalModels() const
{
    auto models = getMaterialPtr()->getPhysicalModels();
    Py::List list;

    for (auto it : *models) {
        list.append(Py::String(it.toStdString()));
    }

    return list;
}

Py::List MaterialPy::getAppearanceModels() const
{
    auto models = getMaterialPtr()->getAppearanceModels();
    Py::List list;

    for (auto it : *models) {
        list.append(Py::String(it.toStdString()));
    }

    return list;
}

Py::List MaterialPy::getTags() const
{
    auto& tags = getMaterialPtr()->getTags();
    Py::List list;

    for (auto it : tags) {
        list.append(Py::String(it.toStdString()));
    }

    return list;
}

PyObject* MaterialPy::getCustomAttributes(const char* /*attr*/) const
{
    return nullptr;
}

int MaterialPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
    return 0;
}

PyObject* MaterialPy::addPhysicalModel(PyObject* args)
{
    char* uuid;
    if (!PyArg_ParseTuple(args, "s", &uuid)) {
        return nullptr;
    }

    getMaterialPtr()->addPhysical(QString::fromStdString(uuid));
    Py_INCREF(Py_None);
    return Py_None;
}

PyObject* MaterialPy::removePhysicalModel(PyObject* args)
{
    char* uuid;
    if (!PyArg_ParseTuple(args, "s", &uuid)) {
        return nullptr;
    }

    getMaterialPtr()->removePhysical(QString::fromStdString(uuid));
    Py_INCREF(Py_None);
    return Py_None;
}

PyObject* MaterialPy::hasPhysicalModel(PyObject* args)
{
    char* uuid;
    if (!PyArg_ParseTuple(args, "s", &uuid)) {
        return nullptr;
    }

    bool hasProperty = getMaterialPtr()->hasPhysicalModel(QString::fromStdString(uuid));
    return PyBool_FromLong(hasProperty ? 1 : 0);
}

PyObject* MaterialPy::addAppearanceModel(PyObject* args)
{
    char* uuid;
    if (!PyArg_ParseTuple(args, "s", &uuid)) {
        return nullptr;
    }

    getMaterialPtr()->addAppearance(QString::fromStdString(uuid));
    Py_INCREF(Py_None);
    return Py_None;
}

PyObject* MaterialPy::removeAppearanceModel(PyObject* args)
{
    char* uuid;
    if (!PyArg_ParseTuple(args, "s", &uuid)) {
        return nullptr;
    }

    getMaterialPtr()->removeAppearance(QString::fromStdString(uuid));
    Py_INCREF(Py_None);
    return Py_None;
}

PyObject* MaterialPy::hasAppearanceModel(PyObject* args)
{
    char* uuid;
    if (!PyArg_ParseTuple(args, "s", &uuid)) {
        return nullptr;
    }

    bool hasProperty = getMaterialPtr()->hasAppearanceModel(QString::fromStdString(uuid));
    return PyBool_FromLong(hasProperty ? 1 : 0);
}

PyObject* MaterialPy::isPhysicalModelComplete(PyObject* args)
{
    char* name;
    if (!PyArg_ParseTuple(args, "s", &name)) {
        return nullptr;
    }

    bool isComplete = getMaterialPtr()->isPhysicalModelComplete(QString::fromStdString(name));
    return PyBool_FromLong(isComplete ? 1 : 0);
}

PyObject* MaterialPy::isAppearanceModelComplete(PyObject* args)
{
    char* name;
    if (!PyArg_ParseTuple(args, "s", &name)) {
        return nullptr;
    }

    bool isComplete = getMaterialPtr()->isAppearanceModelComplete(QString::fromStdString(name));
    return PyBool_FromLong(isComplete ? 1 : 0);
}

PyObject* MaterialPy::hasPhysicalProperty(PyObject* args)
{
    char* name;
    if (!PyArg_ParseTuple(args, "s", &name)) {
        return nullptr;
    }

    bool hasProperty = getMaterialPtr()->hasPhysicalProperty(QString::fromStdString(name));
    return PyBool_FromLong(hasProperty ? 1 : 0);
}

PyObject* MaterialPy::hasAppearanceProperty(PyObject* args)
{
    char* name;
    if (!PyArg_ParseTuple(args, "s", &name)) {
        return nullptr;
    }

    bool hasProperty = getMaterialPtr()->hasAppearanceProperty(QString::fromStdString(name));
    return PyBool_FromLong(hasProperty ? 1 : 0);
}

PyObject* MaterialPy::hasLegacyProperties(PyObject* args)
{
    if (!PyArg_ParseTuple(args, "")) {
        return nullptr;
    }

    bool hasProperty = getMaterialPtr()->hasLegacyProperties();
    return PyBool_FromLong(hasProperty ? 1 : 0);
}

Py::Dict MaterialPy::getProperties() const
{
    Py::Dict dict;

    // Maintain backwards compatibility
    dict.setItem(Py::String("CardName"), Py::String(getMaterialPtr()->getName().toStdString()));
    dict.setItem(Py::String("AuthorAndLicense"),
                 Py::String(getMaterialPtr()->getAuthorAndLicense().toStdString()));
    dict.setItem(Py::String("Author"), Py::String(getMaterialPtr()->getAuthor().toStdString()));
    dict.setItem(Py::String("License"), Py::String(getMaterialPtr()->getLicense().toStdString()));
    dict.setItem(Py::String("Name"), Py::String(getMaterialPtr()->getName().toStdString()));
    dict.setItem(Py::String("Description"),
                 Py::String(getMaterialPtr()->getDescription().toStdString()));
    dict.setItem(Py::String("ReferenceSource"),
                 Py::String(getMaterialPtr()->getReference().toStdString()));
    dict.setItem(Py::String("SourceURL"), Py::String(getMaterialPtr()->getURL().toStdString()));

    auto properties = getMaterialPtr()->getPhysicalProperties();
    for (auto& it : properties) {
        QString key = it.first;
        auto materialProperty = it.second;

        if (!materialProperty->isNull()) {
            auto value = materialProperty->getDictionaryString();
            dict.setItem(Py::String(key.toStdString()), Py::String(value.toStdString()));
        }
    }

    properties = getMaterialPtr()->getAppearanceProperties();
    for (auto& it : properties) {
        QString key = it.first;
        auto materialProperty = it.second;

        if (!materialProperty->isNull()) {
            auto value = materialProperty->getDictionaryString();
            dict.setItem(Py::String(key.toStdString()), Py::String(value.toStdString()));
        }
    }

    auto legacy = getMaterialPtr()->getLegacyProperties();
    for (auto& it : legacy) {
        auto key = it.first;
        auto value = it.second;

        if (!value.isEmpty()) {
            dict.setItem(Py::String(key.toStdString()), Py::String(value.toStdString()));
        }
    }

    return dict;
}

Py::Dict MaterialPy::getPhysicalProperties() const
{
    Py::Dict dict;

    auto properties = getMaterialPtr()->getPhysicalProperties();
    for (auto& it : properties) {
        QString key = it.first;
        auto materialProperty = it.second;

        if (!materialProperty->isNull()) {
            auto value = materialProperty->getDictionaryString();
            dict.setItem(Py::String(key.toStdString()), Py::String(value.toStdString()));
        }
    }

    return dict;
}

Py::Dict MaterialPy::getAppearanceProperties() const
{
    Py::Dict dict;

    auto properties = getMaterialPtr()->getAppearanceProperties();
    for (auto& it : properties) {
        QString key = it.first;
        auto materialProperty = it.second;

        if (!materialProperty->isNull()) {
            auto value = materialProperty->getDictionaryString();
            dict.setItem(Py::String(key.toStdString()), Py::String(value.toStdString()));
        }
    }

    return dict;
}

Py::Dict MaterialPy::getLegacyProperties() const
{
    Py::Dict dict;

    auto legacy = getMaterialPtr()->getLegacyProperties();
    for (auto& it : legacy) {
        auto key = it.first;
        auto value = it.second;

        if (!value.isEmpty()) {
            dict.setItem(Py::String(key.toStdString()), Py::String(value.toStdString()));
        }
    }

    return dict;
}

PyObject* MaterialPy::getPhysicalValue(PyObject* args)
{
    char* name;
    if (!PyArg_ParseTuple(args, "s", &name)) {
        return nullptr;
    }

    if (!getMaterialPtr()->hasPhysicalProperty(QString::fromStdString(name))) {
        Py_RETURN_NONE;
    }

    auto property = getMaterialPtr()->getPhysicalProperty(QString::fromStdString(name));
    if (!property) {
        Py_RETURN_NONE;
    }

    if (property->getType() == MaterialValue::Array2D) {
        auto value =
            std::static_pointer_cast<Materials::Array2D>(property->getMaterialValue());
        return new Array2DPy(new Array2D(*value));
    }
    if (property->getType() == MaterialValue::Array3D) {
        auto value =
            std::static_pointer_cast<Materials::Array3D>(property->getMaterialValue());
        return new Array3DPy(new Array3D(*value));
    }

    QVariant value = property->getValue();
    return _pyObjectFromVariant(value);
}

PyObject* MaterialPy::setPhysicalValue(PyObject* args)
{
    char* name;
    char* value;
    if (!PyArg_ParseTuple(args, "ss", &name, &value)) {
        return nullptr;
    }

    getMaterialPtr()->setPhysicalValue(QString::fromStdString(name), QString::fromStdString(value));
    Py_INCREF(Py_None);
    return Py_None;
}

PyObject* MaterialPy::getAppearanceValue(PyObject* args)
{
    char* name;
    if (!PyArg_ParseTuple(args, "s", &name)) {
        return nullptr;
    }

    if (!getMaterialPtr()->hasAppearanceProperty(QString::fromStdString(name))) {
        Py_RETURN_NONE;
    }

    auto property = getMaterialPtr()->getAppearanceProperty(QString::fromStdString(name));
    if (!property) {
        Py_RETURN_NONE;
    }

    if (property->getType() == MaterialValue::Array2D) {
        auto value =
            std::static_pointer_cast<Materials::Array2D>(property->getMaterialValue());
        return new Array2DPy(new Array2D(*value));
    }
    if (property->getType() == MaterialValue::Array3D) {
        auto value =
            std::static_pointer_cast<Materials::Array3D>(property->getMaterialValue());
        return new Array3DPy(new Array3D(*value));
    }

    QVariant value = property->getValue();
    return _pyObjectFromVariant(value);
}

PyObject* MaterialPy::setAppearanceValue(PyObject* args)
{
    char* name;
    char* value;
    if (!PyArg_ParseTuple(args, "ss", &name, &value)) {
        return nullptr;
    }

    getMaterialPtr()->setAppearanceValue(QString::fromStdString(name),
                                         QString::fromStdString(value));
    Py_INCREF(Py_None);
    return Py_None;
}

PyObject* MaterialPy::setValue(PyObject* args)
{
    char* name;
    char* value;
    PyObject* listObj;
    PyObject* arrayObj;
    if (PyArg_ParseTuple(args, "ss", &name, &value)) {
        getMaterialPtr()->setValue(QString::fromStdString(name), QString::fromStdString(value));
        Py_Return;
    }

    PyErr_Clear();
    if (PyArg_ParseTuple(args, "sO!", &name, &PyList_Type, &listObj)) {
        QList<QVariant> variantList;
        Py::List list(listObj);
        for (auto itemObj : list) {
            Py::String item(itemObj);
            QString value(QString::fromStdString(item.as_string()));
            QVariant variant = QVariant::fromValue(value);
            variantList.append(variant);
        }

        getMaterialPtr()->setValue(QString::fromStdString(name), variantList);
        Py_Return;
    }

    PyErr_Clear();
    if (PyArg_ParseTuple(args, "sO!", &name, &(Array2DPy::Type), &arrayObj)) {
        auto array = static_cast<Array2DPy*>(arrayObj);
        auto shared = std::make_shared<Array2D>(*array->getArray2DPtr());

        getMaterialPtr()->setValue(QString::fromStdString(name), shared);
        Py_Return;
    }

    PyErr_Clear();
    if (PyArg_ParseTuple(args, "sO!", &name, &(Array3DPy::Type), &arrayObj)) {
        auto array = static_cast<Array3DPy*>(arrayObj);
        auto shared = std::make_shared<Array3D>(*array->getArray3DPtr());

        getMaterialPtr()->setValue(QString::fromStdString(name), shared);
        Py_Return;
    }

    PyErr_SetString(PyExc_TypeError,
                    "Either a string, a list, or an array are expected");
    return nullptr;
}

Py::Dict MaterialPy::getPropertyObjects() const
{
    Py::Dict dict;

    auto properties = getMaterialPtr()->getPhysicalProperties();
    for (auto& it : properties) {
        QString key = it.first;
        auto materialProperty = it.second;

        // if (materialProperty->getType() == MaterialValue::Array2D) {
        //     auto value = std::static_pointer_cast<Materials::Array2D>(
        //         materialProperty->getMaterialValue());
        //     dict.setItem(Py::String(key.toStdString()),
        //                  Py::Object(new Array2DPy(new Array2D(*value)), true));
        // }
        // else if (materialProperty->getType() == MaterialValue::Array3D) {
        //     auto value = std::static_pointer_cast<Materials::Array3D>(
        //         materialProperty->getMaterialValue());
        //     dict.setItem(Py::String(key.toStdString()),
        //                  Py::Object(new Array3DPy(new Array3D(*value)), true));
        // }
        // else {
        dict.setItem(
            Py::String(key.toStdString()),
            Py::Object(new MaterialPropertyPy(new MaterialProperty(materialProperty)), true));
        // }
    }

    properties = getMaterialPtr()->getAppearanceProperties();
    for (auto& it : properties) {
        QString key = it.first;
        auto materialProperty = it.second;
        dict.setItem(
            Py::String(key.toStdString()),
            Py::Object(new MaterialPropertyPy(new MaterialProperty(materialProperty)), true));
    }

    return dict;
}

PyObject* MaterialPy::keys()
{
    return Py::new_reference_to(this->getProperties().keys());
}

PyObject* MaterialPy::values()
{
    return Py::new_reference_to(this->getProperties().values());
}

Py_ssize_t MaterialPy::sequence_length(PyObject *self)
{
    return static_cast<MaterialPy*>(self)->getProperties().size();
}

PyObject* MaterialPy::sequence_item(PyObject* self, Py_ssize_t item)
{
    Py::List keys = static_cast<MaterialPy*>(self)->getProperties().keys();
    return Py::new_reference_to(keys.getItem(item));
}

int MaterialPy::sequence_contains(PyObject* self, PyObject* key)
{
    return PyDict_Contains(static_cast<MaterialPy*>(self)->getProperties().ptr(), key);
}

PyObject* MaterialPy::mapping_subscript(PyObject* self, PyObject* key)
{
    Py::Dict dict = static_cast<MaterialPy*>(self)->getProperties();
    return Py::new_reference_to(dict.getItem(Py::Object(key)));
}