FreeCAD

Форк
0
/
UnifySameDomainPyImp.cpp 
260 строк · 8.6 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2020 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
#ifndef _PreComp_
25
# include <memory>
26
# include <Standard_Failure.hxx>
27

28
// Needed for OCCT 7.5.2
29
#include <TopoDS_Edge.hxx>
30
#endif
31

32
#include <Base/PyWrapParseTupleAndKeywords.h>
33

34
#include "ShapeUpgrade/UnifySameDomainPy.h"
35
#include "ShapeUpgrade/UnifySameDomainPy.cpp"
36
#include "PartPyCXX.h"
37
#include "TopoShapePy.h"
38

39

40
using namespace Part;
41

42
PyObject *UnifySameDomainPy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
43
{
44
    // create a new instance of UnifySameDomainPy
45
    return new UnifySameDomainPy(nullptr);
46
}
47

48
// constructor method
49
int UnifySameDomainPy::PyInit(PyObject* args, PyObject* kwds)
50
{
51
    PyObject *shape;
52
    PyObject *unifyEdges = Py_True; // NOLINT
53
    PyObject *unifyFaces = Py_True; // NOLINT
54
    PyObject *concatBSpl = Py_False; // NOLINT
55

56
    static const std::array<const char *, 5> keywords{"Shape", "UnifyEdges", "UnifyFaces", "ConcatBSplines", nullptr};
57
    if (!Base::Wrapped_ParseTupleAndKeywords(args, kwds, "O!|O!O!O!", keywords,
58
                                             &TopoShapePy::Type, &shape,
59
                                             &PyBool_Type, &unifyEdges,
60
                                             &PyBool_Type, &unifyFaces,
61
                                             &PyBool_Type, &concatBSpl)) {
62
        return -1;
63
    }
64

65
    try {
66
        TopoDS_Shape shp = static_cast<TopoShapePy*>(shape)->getTopoShapePtr()->getShape();
67
        std::unique_ptr<ShapeUpgrade_UnifySameDomain> ptr(new ShapeUpgrade_UnifySameDomain(shp,
68
                                                          Base::asBoolean(unifyEdges),
69
                                                          Base::asBoolean(unifyFaces),
70
                                                          Base::asBoolean(concatBSpl)));
71

72
        setTwinPointer(ptr.release());
73
        return 0;
74
    }
75
    catch (const Standard_Failure& e) {
76
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
77
        return -1;
78
    }
79
}
80

81
PyObject* UnifySameDomainPy::initialize(PyObject *args, PyObject* kwds)
82
{
83
    PyObject *shape;
84
    PyObject *unifyEdges = Py_True;
85
    PyObject *unifyFaces = Py_True;
86
    PyObject *concatBSpl = Py_False;
87

88
    static const std::array<const char *, 5> keywords{"Shape", "UnifyEdges", "UnifyFaces", "ConcatBSplines", nullptr};
89
    if (!Base::Wrapped_ParseTupleAndKeywords(args, kwds, "O!|O!O!O!", keywords,
90
                                             &TopoShapePy::Type, &shape,
91
                                             &PyBool_Type, &unifyEdges,
92
                                             &PyBool_Type, &unifyFaces,
93
                                             &PyBool_Type, &concatBSpl)) {
94
        return nullptr;
95
    }
96

97
    try {
98
        TopoDS_Shape shp = static_cast<TopoShapePy*>(shape)->getTopoShapePtr()->getShape();
99
        getShapeUpgrade_UnifySameDomainPtr()->Initialize(shp,
100
            Base::asBoolean(unifyEdges),
101
            Base::asBoolean(unifyFaces),
102
            Base::asBoolean(concatBSpl));
103

104
        Py_Return;
105
    }
106
    catch (const Standard_Failure& e) {
107
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
108
        return nullptr;
109
    }
110
}
111

112
// returns a string which represents the object e.g. when printed in python
113
std::string UnifySameDomainPy::representation() const
114
{
115
    return {"<ShapeUpgrade_UnifySameDomain object>"};
116
}
117

118
PyObject* UnifySameDomainPy::allowInternalEdges(PyObject *args)
119
{
120
    PyObject* allow;
121
    if (!PyArg_ParseTuple(args, "O!", &PyBool_Type, &allow))
122
        return nullptr;
123

124
    try {
125
        getShapeUpgrade_UnifySameDomainPtr()->AllowInternalEdges(Base::asBoolean(allow));
126
        Py_Return;
127
    }
128
    catch (const Standard_Failure& e) {
129
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
130
        return nullptr;
131
    }
132
}
133

134
PyObject* UnifySameDomainPy::keepShape(PyObject *args)
135
{
136
    PyObject* shape;
137
    if (!PyArg_ParseTuple(args, "O!", &TopoShapePy::Type, &shape))
138
        return nullptr;
139

140
    try {
141
        TopoDS_Shape shp = static_cast<TopoShapePy*>(shape)->getTopoShapePtr()->getShape();
142
        getShapeUpgrade_UnifySameDomainPtr()->KeepShape(shp);
143
        Py_Return;
144
    }
145
    catch (const Standard_Failure& e) {
146
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
147
        return nullptr;
148
    }
149
}
150

151
PyObject* UnifySameDomainPy::keepShapes(PyObject *args)
152
{
153
    PyObject* obj;
154
    if (!PyArg_ParseTuple(args, "O", &obj))
155
        return nullptr;
156

157
    try {
158
        TopTools_MapOfShape theShapes;
159
        Py::Sequence list(obj);
160
        for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
161
            Py::TopoShape shp(*it);
162
            theShapes.Add(shp.extensionObject()->getTopoShapePtr()->getShape());
163
        }
164

165
        getShapeUpgrade_UnifySameDomainPtr()->KeepShapes(theShapes);
166
        Py_Return;
167
    }
168
    catch (const Standard_Failure& e) {
169
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
170
        return nullptr;
171
    }
172
}
173

174
PyObject* UnifySameDomainPy::setSafeInputMode(PyObject *args)
175
{
176
    PyObject* mode;
177
    if (!PyArg_ParseTuple(args, "O!", &PyBool_Type, &mode))
178
        return nullptr;
179

180
    try {
181
        getShapeUpgrade_UnifySameDomainPtr()->SetSafeInputMode(Base::asBoolean(mode));
182
        Py_Return;
183
    }
184
    catch (const Standard_Failure& e) {
185
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
186
        return nullptr;
187
    }
188
}
189

190
PyObject* UnifySameDomainPy::setLinearTolerance(PyObject *args)
191
{
192
    double linTol;
193
    if (!PyArg_ParseTuple(args, "d", &linTol))
194
        return nullptr;
195

196
    try {
197
        getShapeUpgrade_UnifySameDomainPtr()->SetLinearTolerance(linTol);
198
        Py_Return;
199
    }
200
    catch (const Standard_Failure& e) {
201
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
202
        return nullptr;
203
    }
204
}
205

206
PyObject* UnifySameDomainPy::setAngularTolerance(PyObject *args)
207
{
208
    double angTol;
209
    if (!PyArg_ParseTuple(args, "d", &angTol))
210
        return nullptr;
211

212
    try {
213
        getShapeUpgrade_UnifySameDomainPtr()->SetAngularTolerance(angTol);
214
        Py_Return;
215
    }
216
    catch (const Standard_Failure& e) {
217
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
218
        return nullptr;
219
    }
220
}
221

222
PyObject* UnifySameDomainPy::build(PyObject *args)
223
{
224
    if (!PyArg_ParseTuple(args, ""))
225
        return nullptr;
226

227
    try {
228
        getShapeUpgrade_UnifySameDomainPtr()->Build();
229
        Py_Return;
230
    }
231
    catch (const Standard_Failure& e) {
232
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
233
        return nullptr;
234
    }
235
}
236

237
PyObject* UnifySameDomainPy::shape(PyObject *args)
238
{
239
    if (!PyArg_ParseTuple(args, ""))
240
        return nullptr;
241

242
    try {
243
        TopoDS_Shape shape = getShapeUpgrade_UnifySameDomainPtr()->Shape();
244
        return new TopoShapePy(new TopoShape(shape));
245
    }
246
    catch (const Standard_Failure& e) {
247
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
248
        return nullptr;
249
    }
250
}
251

252
PyObject *UnifySameDomainPy::getCustomAttributes(const char* /*attr*/) const
253
{
254
    return nullptr;
255
}
256

257
int UnifySameDomainPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
258
{
259
    return 0;
260
}
261

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

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

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

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