FreeCAD

Форк
0
/
ModelPyImp.cpp 
173 строки · 5.4 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2023 David Carter <dcarter@david.carter.ca>             *
3
 *                                                                         *
4
 *   This file is part of FreeCAD.                                         *
5
 *                                                                         *
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.                       *
10
 *                                                                         *
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.                       *
15
 *                                                                         *
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/>.                                      *
19
 *                                                                         *
20
 **************************************************************************/
21

22
#include "PreCompiled.h"
23

24
#include "Model.h"
25
#include "ModelLibrary.h"
26
#include "ModelPropertyPy.h"
27
#include "ModelPy.h"
28
#include "ModelUuids.h"
29

30
#include "ModelPy.cpp"
31

32
using namespace Materials;
33

34
// returns a string which represents the object e.g. when printed in python
35
std::string ModelPy::representation() const
36
{
37
    ModelPy::PointerType ptr = getModelPtr();
38
    std::stringstream str;
39
    str << "Property [Name=(";
40
    str << ptr->getName().toStdString();
41
    str << "), UUID=(";
42
    str << ptr->getUUID().toStdString();
43
    auto library = ptr->getLibrary();
44
    if (library) {
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();
51
    }
52
    str << "), Directory=(";
53
    str << ptr->getDirectory().toStdString();
54
    str << "), URL=(";
55
    str << ptr->getURL().toStdString();
56
    str << "), DOI=(";
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++) {
63
        QString uuid = *it;
64
        if (it != inherited.begin()) {
65
            str << "), UUID=(";
66
        }
67
        else {
68
            str << "UUID=(";
69
        }
70
        str << uuid.toStdString() << ")";
71
    }
72
    str << "]]";
73

74
    return str.str();
75
}
76

77
PyObject* ModelPy::PyMake(struct _typeobject*, PyObject*, PyObject*)  // Python wrapper
78
{
79
    // never create such objects with the constructor
80
    return new ModelPy(new Model());
81
}
82

83
// constructor method
84
int ModelPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
85
{
86
    return 0;
87
}
88

89
Py::String ModelPy::getLibraryName() const
90
{
91
    auto library = getModelPtr()->getLibrary();
92
    return Py::String(library ? library->getName().toStdString() : "");
93
}
94

95
Py::String ModelPy::getLibraryRoot() const
96
{
97
    auto library = getModelPtr()->getLibrary();
98
    return Py::String(library ? library->getDirectoryPath().toStdString() : "");
99
}
100

101
Py::String ModelPy::getLibraryIcon() const
102
{
103
    auto library = getModelPtr()->getLibrary();
104
    return Py::String(library ? library->getIconPath().toStdString() : "");
105
}
106

107
Py::String ModelPy::getName() const
108
{
109
    return Py::String(getModelPtr()->getName().toStdString());
110
}
111

112
Py::String ModelPy::getDirectory() const
113
{
114
    return Py::String(getModelPtr()->getDirectoryPath().toStdString());
115
}
116

117
Py::String ModelPy::getUUID() const
118
{
119
    return Py::String(getModelPtr()->getUUID().toStdString());
120
}
121

122
Py::String ModelPy::getDescription() const
123
{
124
    return Py::String(getModelPtr()->getDescription().toStdString());
125
}
126

127
Py::String ModelPy::getURL() const
128
{
129
    return Py::String(getModelPtr()->getURL().toStdString());
130
}
131

132
Py::String ModelPy::getDOI() const
133
{
134
    return Py::String(getModelPtr()->getDOI().toStdString());
135
}
136

137
Py::List ModelPy::getInherited() const
138
{
139
    auto& inherited = getModelPtr()->getInheritance();
140
    Py::List list;
141

142
    for (auto it = inherited.begin(); it != inherited.end(); it++) {
143
        list.append(Py::String(it->toStdString()));
144
    }
145

146
    return list;
147
}
148

149
Py::Dict ModelPy::getProperties() const
150
{
151
    // std::map<std::string, Model*> *models = getModelPtr()->getModels();
152
    Py::Dict dict;
153

154
    for (auto it = getModelPtr()->begin(); it != getModelPtr()->end(); it++) {
155
        QString key = it->first;
156
        ModelProperty& modelProperty = it->second;
157

158
        PyObject* modelPropertyPy = new ModelPropertyPy(new ModelProperty(modelProperty));
159
        dict.setItem(Py::String(key.toStdString()), Py::Object(modelPropertyPy, true));
160
    }
161

162
    return dict;
163
}
164

165
PyObject* ModelPy::getCustomAttributes(const char* /*attr*/) const
166
{
167
    return nullptr;
168
}
169

170
int ModelPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
171
{
172
    return 0;
173
}
174

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

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

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

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