FreeCAD

Форк
0
/
BRepOffsetAPI_MakeFillingPyImp.cpp 
459 строк · 15.9 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2012 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 <BRepOffsetAPI_MakeFilling.hxx>
27
# include <GeomAbs_Shape.hxx>
28
# include <gp_Pnt.hxx>
29
# include <TopoDS.hxx>
30
# include <TopoDS_Face.hxx>
31
#endif
32

33
#include <Base/PyWrapParseTupleAndKeywords.h>
34
#include <Base/VectorPy.h>
35

36
#include "BRepOffsetAPI_MakeFillingPy.h"
37
#include "BRepOffsetAPI_MakeFillingPy.cpp"
38
#include "TopoShapeEdgePy.h"
39
#include "TopoShapeFacePy.h"
40

41

42
using namespace Part;
43
/*!
44
 * \brief BRepOffsetAPI_MakeFillingPy::PyMake
45
 * \code
46
v1=App.Vector(0,0,0)
47
v2=App.Vector(10,0,0)
48
v3=App.Vector(10,10,3)
49
v4=App.Vector(0,10,0)
50
v5=App.Vector(5,5,5)
51

52
l1=Part.makeLine(v1, v2)
53
l2=Part.makeLine(v2, v3)
54
l3=Part.makeLine(v3, v4)
55
l4=Part.makeLine(v4, v1)
56

57
bp=Part.BRepOffsetAPI.MakeFilling()
58
bp.add(l1, 0, True)
59
bp.add(l2, 0, True)
60
bp.add(l3, 0, True)
61
bp.add(l4, 0, True)
62
bp.add(v5)
63
bp.build()
64
s=bp.shape()
65
Part.show(s)
66
Part.show(l1)
67
Part.show(l2)
68
Part.show(l3)
69
Part.show(l4)
70

71
bp.surfInit()
72
 * \endcode
73
 */
74

75
PyObject *BRepOffsetAPI_MakeFillingPy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
76
{
77
    // create a new instance of BRepOffsetAPI_MakeFillingPy
78
    return new BRepOffsetAPI_MakeFillingPy(nullptr);
79
}
80

81
// constructor method
82
int BRepOffsetAPI_MakeFillingPy::PyInit(PyObject* args, PyObject* kwds)
83
{
84
    int degree = 3;
85
    int nbPtsOnCur = 15;
86
    int nbIter = 2;
87
    int maxDeg = 8;
88
    int maxSegments = 9;
89
    double tol2d = 0.00001;
90
    double tol3d = 0.0001;
91
    double tolAng = 0.01;
92
    double tolCurv = 0.1;
93
    PyObject* anisotropy = Py_False;
94

95
    static const std::array<const char *, 11> keywords{"Degree", "NbPtsOnCur", "NbIter", "MaxDegree", "MaxSegments",
96
                                                       "Tol2d", "Tol3d", "TolAng", "TolCurv", "Anisotropy", nullptr};
97
    if (!Base::Wrapped_ParseTupleAndKeywords(args, kwds, "|iiiiiddddO!", keywords,
98
                                             &degree, &nbPtsOnCur, &nbIter, &maxDeg, &maxSegments,
99
                                             &tol2d, &tol3d, &tolAng, &tolCurv, &PyBool_Type, &anisotropy)) {
100
        return -1;
101
    }
102

103
    try {
104
        std::unique_ptr<BRepOffsetAPI_MakeFilling> ptr(new BRepOffsetAPI_MakeFilling(degree, nbPtsOnCur, nbIter,
105
                                                          Base::asBoolean(anisotropy),
106
                                                          tol2d, tol3d, tolAng, tolCurv, maxDeg, maxSegments));
107

108

109
        setTwinPointer(ptr.release());
110
        return 0;
111
    }
112
    catch (const Standard_Failure& e) {
113
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
114
        return -1;
115
    }
116
}
117

118
// returns a string which represents the object e.g. when printed in python
119
std::string BRepOffsetAPI_MakeFillingPy::representation() const
120
{
121
    return {"<BRepOffsetAPI_MakeFilling object>"};
122
}
123

124
PyObject* BRepOffsetAPI_MakeFillingPy::setConstrParam(PyObject *args, PyObject *kwds)
125
{
126
    double tol2d = 0.00001;
127
    double tol3d = 0.0001;
128
    double tolAng = 0.01;
129
    double tolCurv = 0.1;
130

131
    static const std::array<const char *, 5> keywords {"Tol2d", "Tol3d", "TolAng", "TolCurv", nullptr};
132
    if (!Base::Wrapped_ParseTupleAndKeywords(args, kwds, "|dddd", keywords,
133
                                            &tol2d, &tol3d, &tolAng, &tolCurv)) {
134
        return nullptr;
135
    }
136

137
    try {
138
        getBRepOffsetAPI_MakeFillingPtr()->SetConstrParam(tol2d, tol3d, tolAng, tolCurv);
139
        Py_Return;
140
    }
141
    catch (const Standard_Failure& e) {
142
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
143
        return nullptr;
144
    }
145
}
146

147
PyObject* BRepOffsetAPI_MakeFillingPy::setResolParam(PyObject *args, PyObject *kwds)
148
{
149
    int degree = 3;
150
    int nbPtsOnCur = 15;
151
    int nbIter = 2;
152
    PyObject* anisotropy = Py_False;
153

154
    static const std::array<const char *, 5> keywords {"Degree", "NbPtsOnCur", "NbIter", "Anisotropy", nullptr};
155
    if (!Base::Wrapped_ParseTupleAndKeywords(args, kwds, "|iiiO!", keywords,
156
                                             &degree, &nbPtsOnCur, &nbIter, &PyBool_Type, &anisotropy)) {
157
        return nullptr;
158
    }
159

160
    try {
161
        getBRepOffsetAPI_MakeFillingPtr()->SetResolParam(degree, nbPtsOnCur, nbIter,
162
                                                         Base::asBoolean(anisotropy));
163
        Py_Return;
164
    }
165
    catch (const Standard_Failure& e) {
166
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
167
        return nullptr;
168
    }
169
}
170

171
PyObject* BRepOffsetAPI_MakeFillingPy::setApproxParam(PyObject *args, PyObject *kwds)
172
{
173
    int maxDeg = 8;
174
    int maxSegments = 9;
175

176
    static const std::array<const char *, 3> keywords {"MaxDegree", "MaxSegments", nullptr};
177
    if (!Base::Wrapped_ParseTupleAndKeywords(args, kwds, "|ii", keywords,
178
                                             &maxDeg, &maxSegments)) {
179
        return nullptr;
180
    }
181

182
    try {
183
        getBRepOffsetAPI_MakeFillingPtr()->SetApproxParam(maxDeg, maxSegments);
184
        Py_Return;
185
    }
186
    catch (const Standard_Failure& e) {
187
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
188
        return nullptr;
189
    }
190
}
191

192
PyObject* BRepOffsetAPI_MakeFillingPy::loadInitSurface(PyObject *args)
193
{
194
    PyObject* shape;
195
    if (!PyArg_ParseTuple(args, "O!", &(TopoShapeFacePy::Type), &shape))
196
        return nullptr;
197

198
    TopoDS_Face face = TopoDS::Face(static_cast<TopoShapeFacePy*>(shape)->getTopoShapePtr()->getShape());
199
    if (face.IsNull()) {
200
        PyErr_SetString(PyExc_ReferenceError, "No valid face");
201
        return nullptr;
202
    }
203

204
    try {
205
        getBRepOffsetAPI_MakeFillingPtr()->LoadInitSurface(face);
206
        Py_Return;
207
    }
208
    catch (const Standard_Failure& e) {
209
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
210
        return nullptr;
211
    }
212
}
213

214
PyObject* BRepOffsetAPI_MakeFillingPy::add(PyObject *args, PyObject *kwds)
215
{
216
    // 1st
217
    PyObject* pnt;
218
    static const std::array<const char *, 2> keywords_pnt {"Point", nullptr};
219
    if (Base::Wrapped_ParseTupleAndKeywords(args, kwds, "O!", keywords_pnt,
220
                                            &Base::VectorPy::Type, &pnt)) {
221
        try {
222
            Base::Vector3d vec = static_cast<Base::VectorPy*>(pnt)->value();
223
            getBRepOffsetAPI_MakeFillingPtr()->Add(gp_Pnt(vec.x, vec.y, vec.z));
224
            Py_Return;
225
        }
226
        catch (const Standard_Failure& e) {
227
            PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
228
            return nullptr;
229
        }
230
    }
231

232
    // 2nd
233
    PyObject* support;
234
    int order;
235
    static const std::array<const char *, 3> keywords_sup_ord {"Support", "Order", nullptr};
236
    PyErr_Clear();
237
    if (Base::Wrapped_ParseTupleAndKeywords(args, kwds, "O!i", keywords_sup_ord,
238
                                            &TopoShapeFacePy::Type, &support, &order)) {
239
        try {
240
            TopoDS_Face face = TopoDS::Face(static_cast<TopoShapeFacePy*>(support)->getTopoShapePtr()->getShape());
241
            if (face.IsNull()) {
242
                PyErr_SetString(PyExc_ReferenceError, "No valid face");
243
                return nullptr;
244
            }
245

246
            if (order < 0 || order > 2) {
247
                PyErr_SetString(PyExc_ReferenceError, "Order must be in the [0, 2] with 0 -> C0, 1 -> G1, 2 -> G2");
248
                return nullptr;
249
            }
250

251
            getBRepOffsetAPI_MakeFillingPtr()->Add(face, static_cast<GeomAbs_Shape>(order));
252
            Py_Return;
253
        }
254
        catch (const Standard_Failure& e) {
255
            PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
256
            return nullptr;
257
        }
258
    }
259

260
    // 3rd
261
    PyObject* constr;
262
    PyObject* isbound = Py_True;
263
    static const std::array<const char *, 4> keywords_const {"Constraint", "Order", "IsBound", nullptr};
264
    PyErr_Clear();
265
    if (Base::Wrapped_ParseTupleAndKeywords(args, kwds, "O!i|O!", keywords_const,
266
                                            &TopoShapeEdgePy::Type, &constr,
267
                                            &order, &PyBool_Type, isbound)) {
268
        try {
269
            TopoDS_Edge edge = TopoDS::Edge(static_cast<TopoShapeEdgePy*>(constr)->getTopoShapePtr()->getShape());
270
            if (edge.IsNull()) {
271
                PyErr_SetString(PyExc_ReferenceError, "No valid constraint edge");
272
                return nullptr;
273
            }
274

275
            if (order < 0 || order > 2) {
276
                PyErr_SetString(PyExc_ReferenceError, "Order must be in the [0, 2] with 0 -> C0, 1 -> G1, 2 -> G2");
277
                return nullptr;
278
            }
279

280
            getBRepOffsetAPI_MakeFillingPtr()->Add(edge, static_cast<GeomAbs_Shape>(order),
281
                                                   Base::asBoolean(isbound));
282
            Py_Return;
283
        }
284
        catch (const Standard_Failure& e) {
285
            PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
286
            return nullptr;
287
        }
288
    }
289

290
    // 4th
291
    static const std::array<const char *, 5> keywords_const_sup {"Constraint", "Support", "Order", "IsBound", nullptr};
292
    PyErr_Clear();
293
    if (Base::Wrapped_ParseTupleAndKeywords(args, kwds, "O!O!i|O!", keywords_const_sup,
294
                                            &TopoShapeEdgePy::Type, &constr,
295
                                            &TopoShapeFacePy::Type, &support,
296
                                            &order, &PyBool_Type, isbound)) {
297
        try {
298
            TopoDS_Edge edge = TopoDS::Edge(static_cast<TopoShapeEdgePy*>(constr)->getTopoShapePtr()->getShape());
299
            if (edge.IsNull()) {
300
                PyErr_SetString(PyExc_ReferenceError, "No valid constraint edge");
301
                return nullptr;
302
            }
303
            TopoDS_Face face = TopoDS::Face(static_cast<TopoShapeFacePy*>(support)->getTopoShapePtr()->getShape());
304
            if (face.IsNull()) {
305
                PyErr_SetString(PyExc_ReferenceError, "No valid face");
306
                return nullptr;
307
            }
308

309
            if (order < 0 || order > 2) {
310
                PyErr_SetString(PyExc_ReferenceError, "Order must be in the [0, 2] with 0 -> C0, 1 -> G1, 2 -> G2");
311
                return nullptr;
312
            }
313

314
            getBRepOffsetAPI_MakeFillingPtr()->Add(edge, face, static_cast<GeomAbs_Shape>(order),
315
                                                   Base::asBoolean(isbound));
316
            Py_Return;
317
        }
318
        catch (const Standard_Failure& e) {
319
            PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
320
            return nullptr;
321
        }
322
    }
323

324
    // 5th
325
    double u, v;
326
    static const std::array<const char *, 5> keywords_uv {"U", "V", "Support", "Order", nullptr};
327
    PyErr_Clear();
328
    if (Base::Wrapped_ParseTupleAndKeywords(args, kwds, "ddO!i", keywords_uv,
329
                                            &u, &v, &TopoShapeFacePy::Type, &support, &order)) {
330
        try {
331
            TopoDS_Face face = TopoDS::Face(static_cast<TopoShapeFacePy*>(support)->getTopoShapePtr()->getShape());
332
            if (face.IsNull()) {
333
                PyErr_SetString(PyExc_ReferenceError, "No valid face");
334
                return nullptr;
335
            }
336

337
            if (order < 0 || order > 2) {
338
                PyErr_SetString(PyExc_ReferenceError, "Order must be in the [0, 2] with 0 -> C0, 1 -> G1, 2 -> G2");
339
                return nullptr;
340
            }
341

342
            getBRepOffsetAPI_MakeFillingPtr()->Add(u, v, face, static_cast<GeomAbs_Shape>(order));
343
            Py_Return;
344
        }
345
        catch (const Standard_Failure& e) {
346
            PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
347
            return nullptr;
348
        }
349
    }
350

351
    PyErr_SetString(PyExc_TypeError, "wrong argument");
352
    return nullptr;
353
}
354

355
PyObject* BRepOffsetAPI_MakeFillingPy::build(PyObject *args)
356
{
357
    if (!PyArg_ParseTuple(args, ""))
358
        return nullptr;
359

360
    try {
361
        getBRepOffsetAPI_MakeFillingPtr()->Build();
362
        Py_Return;
363
    }
364
    catch (const Standard_Failure& e) {
365
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
366
        return nullptr;
367
    }
368
}
369

370
PyObject* BRepOffsetAPI_MakeFillingPy::isDone(PyObject *args)
371
{
372
    if (!PyArg_ParseTuple(args, ""))
373
        return nullptr;
374

375
    try {
376
        Standard_Boolean ok = getBRepOffsetAPI_MakeFillingPtr()->IsDone();
377
        return Py_BuildValue("O", (ok ? Py_True : Py_False));
378
    }
379
    catch (const Standard_Failure& e) {
380
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
381
        return nullptr;
382
    }
383
}
384

385
PyObject* BRepOffsetAPI_MakeFillingPy::G0Error(PyObject *args)
386
{
387
    int index = 0;
388
    if (!PyArg_ParseTuple(args, "|i", &index))
389
        return nullptr;
390

391
    try {
392
        Standard_Real v = index < 1 ? getBRepOffsetAPI_MakeFillingPtr()->G0Error()
393
                                    : getBRepOffsetAPI_MakeFillingPtr()->G0Error(index);
394
        return PyFloat_FromDouble(v);
395
    }
396
    catch (const Standard_Failure& e) {
397
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
398
        return nullptr;
399
    }
400
}
401

402
PyObject* BRepOffsetAPI_MakeFillingPy::G1Error(PyObject *args)
403
{
404
    int index = 0;
405
    if (!PyArg_ParseTuple(args, "|i", &index))
406
        return nullptr;
407

408
    try {
409
        Standard_Real v = index < 1 ? getBRepOffsetAPI_MakeFillingPtr()->G1Error()
410
                                    : getBRepOffsetAPI_MakeFillingPtr()->G1Error(index);
411
        return PyFloat_FromDouble(v);
412
    }
413
    catch (const Standard_Failure& e) {
414
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
415
        return nullptr;
416
    }
417
}
418

419
PyObject* BRepOffsetAPI_MakeFillingPy::G2Error(PyObject *args)
420
{
421
    int index = 0;
422
    if (!PyArg_ParseTuple(args, "|i", &index))
423
        return nullptr;
424

425
    try {
426
        Standard_Real v = index < 1 ? getBRepOffsetAPI_MakeFillingPtr()->G2Error()
427
                                    : getBRepOffsetAPI_MakeFillingPtr()->G2Error(index);
428
        return PyFloat_FromDouble(v);
429
    }
430
    catch (const Standard_Failure& e) {
431
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
432
        return nullptr;
433
    }
434
}
435

436
PyObject* BRepOffsetAPI_MakeFillingPy::shape(PyObject *args)
437
{
438
    if (!PyArg_ParseTuple(args, ""))
439
        return nullptr;
440

441
    try {
442
        const TopoDS_Shape& shape = this->getBRepOffsetAPI_MakeFillingPtr()->Shape();
443
        return new TopoShapePy(new TopoShape(shape));
444
    }
445
    catch (Standard_Failure& e) {
446
        PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
447
        return nullptr;
448
    }
449
}
450

451
PyObject *BRepOffsetAPI_MakeFillingPy::getCustomAttributes(const char* /*attr*/) const
452
{
453
    return nullptr;
454
}
455

456
int BRepOffsetAPI_MakeFillingPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
457
{
458
    return 0;
459
}
460

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

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

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

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