1
/***************************************************************************
2
* Copyright (c) 2023 David Carter <dcarter@david.carter.ca> *
4
* This file is part of FreeCAD. *
6
* FreeCAD is free software: you can redistribute it and/or modify it *
7
* under the terms of the GNU Lesser General Public License as *
8
* published by the Free Software Foundation, either version 2.1 of the *
9
* License, or (at your option) any later version. *
11
* FreeCAD is distributed in the hope that it will be useful, but *
12
* WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14
* Lesser General Public License for more details. *
16
* You should have received a copy of the GNU Lesser General Public *
17
* License along with FreeCAD. If not, see *
18
* <https://www.gnu.org/licenses/>. *
20
**************************************************************************/
22
#include "PreCompiled.h"
25
#include "ModelLibrary.h"
26
#include "ModelPropertyPy.h"
28
#include "ModelUuids.h"
32
using namespace Materials;
34
// returns a string which represents the object e.g. when printed in python
35
std::string ModelPy::representation() const
37
ModelPy::PointerType ptr = getModelPtr();
38
std::stringstream str;
39
str << "Property [Name=(";
40
str << ptr->getName().toStdString();
42
str << ptr->getUUID().toStdString();
43
auto library = ptr->getLibrary();
45
str << "), Library Name=(";
46
str << ptr->getLibrary()->getName().toStdString();
47
str << "), Library Root=(";
48
str << ptr->getLibrary()->getDirectoryPath().toStdString();
49
str << "), Library Icon=(";
50
str << ptr->getLibrary()->getIconPath().toStdString();
52
str << "), Directory=(";
53
str << ptr->getDirectory().toStdString();
55
str << ptr->getURL().toStdString();
57
str << ptr->getDOI().toStdString();
58
str << "), Description=(";
59
str << ptr->getDescription().toStdString();
60
str << "), Inherits=[";
61
auto& inherited = getModelPtr()->getInheritance();
62
for (auto it = inherited.begin(); it != inherited.end(); it++) {
64
if (it != inherited.begin()) {
70
str << uuid.toStdString() << ")";
77
PyObject* ModelPy::PyMake(struct _typeobject*, PyObject*, PyObject*) // Python wrapper
79
// never create such objects with the constructor
80
return new ModelPy(new Model());
84
int ModelPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
89
Py::String ModelPy::getLibraryName() const
91
auto library = getModelPtr()->getLibrary();
92
return Py::String(library ? library->getName().toStdString() : "");
95
Py::String ModelPy::getLibraryRoot() const
97
auto library = getModelPtr()->getLibrary();
98
return Py::String(library ? library->getDirectoryPath().toStdString() : "");
101
Py::String ModelPy::getLibraryIcon() const
103
auto library = getModelPtr()->getLibrary();
104
return Py::String(library ? library->getIconPath().toStdString() : "");
107
Py::String ModelPy::getName() const
109
return Py::String(getModelPtr()->getName().toStdString());
112
Py::String ModelPy::getDirectory() const
114
return Py::String(getModelPtr()->getDirectoryPath().toStdString());
117
Py::String ModelPy::getUUID() const
119
return Py::String(getModelPtr()->getUUID().toStdString());
122
Py::String ModelPy::getDescription() const
124
return Py::String(getModelPtr()->getDescription().toStdString());
127
Py::String ModelPy::getURL() const
129
return Py::String(getModelPtr()->getURL().toStdString());
132
Py::String ModelPy::getDOI() const
134
return Py::String(getModelPtr()->getDOI().toStdString());
137
Py::List ModelPy::getInherited() const
139
auto& inherited = getModelPtr()->getInheritance();
142
for (auto it = inherited.begin(); it != inherited.end(); it++) {
143
list.append(Py::String(it->toStdString()));
149
Py::Dict ModelPy::getProperties() const
151
// std::map<std::string, Model*> *models = getModelPtr()->getModels();
154
for (auto it = getModelPtr()->begin(); it != getModelPtr()->end(); it++) {
155
QString key = it->first;
156
ModelProperty& modelProperty = it->second;
158
PyObject* modelPropertyPy = new ModelPropertyPy(new ModelProperty(modelProperty));
159
dict.setItem(Py::String(key.toStdString()), Py::Object(modelPropertyPy, true));
165
PyObject* ModelPy::getCustomAttributes(const char* /*attr*/) const
170
int ModelPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)