FreeCAD

Форк
0
/
BRepOffsetAPI_MakePipeShellPyImp.cpp 
486 строк · 15.8 Кб
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 <BRepOffsetAPI_MakePipeShell.hxx>
26
# include <gp_Ax2.hxx>
27
# include <gp_Dir.hxx>
28
# include <gp_Pnt.hxx>
29
# include <Standard_Version.hxx>
30
# include <TopoDS.hxx>
31
# include <TopTools_ListIteratorOfListOfShape.hxx>
32
#endif
33

34
#include <Base/GeometryPyCXX.h>
35
#include <Base/PyWrapParseTupleAndKeywords.h>
36
#include <Base/VectorPy.h>
37

38
#include "BRepOffsetAPI_MakePipeShellPy.h"
39
#include "BRepOffsetAPI_MakePipeShellPy.cpp"
40
#include "OCCError.h"
41
#include "Tools.h"
42
#include "TopoShapePy.h"
43
#include "TopoShapeVertexPy.h"
44

45

46
using namespace Part;
47

48
PyObject *BRepOffsetAPI_MakePipeShellPy::PyMake(struct _typeobject *, PyObject *args, PyObject *)  // Python wrapper
49
{
50
    // create a new instance of BRepOffsetAPI_MakePipeShellPy and the Twin object
51
    PyObject* obj;
52
    if (!PyArg_ParseTuple(args, "O!",&(TopoShapePy::Type),&obj))
53
        return nullptr;
54
    const TopoDS_Shape& wire = static_cast<TopoShapePy*>(obj)->getTopoShapePtr()->getShape();
55
    if (!wire.IsNull() && wire.ShapeType() == TopAbs_WIRE) {
56
        return new BRepOffsetAPI_MakePipeShellPy(new BRepOffsetAPI_MakePipeShell(TopoDS::Wire(wire)));
57
    }
58

59
    PyErr_SetString(PartExceptionOCCError, "A valid wire is needed as argument");
60
    return nullptr;
61
}
62

63
// constructor method
64
int BRepOffsetAPI_MakePipeShellPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
65
{
66
    return 0;
67
}
68

69
// returns a string which represents the object e.g. when printed in python
70
std::string BRepOffsetAPI_MakePipeShellPy::representation() const
71
{
72
    return {"<BRepOffsetAPI_MakePipeShell object>"};
73
}
74

75
PyObject* BRepOffsetAPI_MakePipeShellPy::setFrenetMode(PyObject *args)
76
{
77
    PyObject *obj;
78
    if (!PyArg_ParseTuple(args, "O!",&PyBool_Type,&obj))
79
        return nullptr;
80

81
    try {
82
        this->getBRepOffsetAPI_MakePipeShellPtr()->SetMode(Base::asBoolean(obj));
83
        Py_Return;
84
    }
85
    catch (Standard_Failure& e) {
86
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
87
        return nullptr;
88
    }
89
}
90

91
PyObject* BRepOffsetAPI_MakePipeShellPy::setTrihedronMode(PyObject *args)
92
{
93
    PyObject *pnt, *dir;
94
    if (!PyArg_ParseTuple(args, "O!O!",&Base::VectorPy::Type,&pnt
95
                                      ,&Base::VectorPy::Type,&dir))
96
        return nullptr;
97

98
    try {
99
        gp_Pnt p = Base::convertTo<gp_Pnt>(Py::Vector(pnt,false).toVector());
100
        gp_Dir d = Base::convertTo<gp_Dir>(Py::Vector(dir,false).toVector());
101
        this->getBRepOffsetAPI_MakePipeShellPtr()->SetMode(gp_Ax2(p,d));
102
        Py_Return;
103
    }
104
    catch (Standard_Failure& e) {
105
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
106
        return nullptr;
107
    }
108
}
109

110
PyObject* BRepOffsetAPI_MakePipeShellPy::setBiNormalMode(PyObject *args)
111
{
112
    PyObject *dir;
113
    if (!PyArg_ParseTuple(args, "O!",&Base::VectorPy::Type,&dir))
114
        return nullptr;
115

116
    try {
117
        gp_Dir d = Base::convertTo<gp_Dir>(Py::Vector(dir,false).toVector());
118
        this->getBRepOffsetAPI_MakePipeShellPtr()->SetMode(d);
119
        Py_Return;
120
    }
121
    catch (Standard_Failure& e) {
122
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
123
        return nullptr;
124
    }
125
}
126

127
PyObject* BRepOffsetAPI_MakePipeShellPy::setSpineSupport(PyObject *args)
128
{
129
    PyObject *shape;
130
    if (!PyArg_ParseTuple(args, "O!",&Part::TopoShapePy::Type,&shape))
131
        return nullptr;
132

133
    try {
134
        const TopoDS_Shape& s = static_cast<Part::TopoShapePy*>(shape)->getTopoShapePtr()->getShape();
135
        Standard_Boolean ok = this->getBRepOffsetAPI_MakePipeShellPtr()->SetMode(s);
136
        return Py::new_reference_to(Py::Boolean(ok ? true : false));
137
    }
138
    catch (Standard_Failure& e) {
139
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
140
        return nullptr;
141
    }
142
}
143

144
PyObject* BRepOffsetAPI_MakePipeShellPy::setAuxiliarySpine(PyObject *args)
145
{
146
    PyObject *spine, *curv, *keep;
147
    if (!PyArg_ParseTuple(args, "O!O!O!",&Part::TopoShapePy::Type,&spine
148
                                        ,&PyBool_Type,&curv
149
                                        ,&PyLong_Type,&keep))
150
        return nullptr;
151

152
    try {
153
        const TopoDS_Shape& s = static_cast<Part::TopoShapePy*>(spine)->getTopoShapePtr()->getShape();
154
        if (s.IsNull() || s.ShapeType() != TopAbs_WIRE) {
155
            PyErr_SetString(PyExc_TypeError, "spine is not a wire");
156
            return nullptr;
157
        }
158

159
        BRepFill_TypeOfContact typeOfCantact;
160
        switch (PyLong_AsLong(keep)) {
161
        case 1:
162
            typeOfCantact = BRepFill_Contact;
163
            break;
164
        case 2:
165
            typeOfCantact = BRepFill_ContactOnBorder;
166
            break;
167
        default:
168
            typeOfCantact = BRepFill_NoContact;
169
            break;
170
        }
171
        this->getBRepOffsetAPI_MakePipeShellPtr()->SetMode(
172
            TopoDS::Wire(s),
173
            Base::asBoolean(curv),
174
            typeOfCantact);
175
        Py_Return;
176
    }
177
    catch (Standard_Failure& e) {
178
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
179
        return nullptr;
180
    }
181
}
182

183
PyObject* BRepOffsetAPI_MakePipeShellPy::add(PyObject *args, PyObject *kwds)
184
{
185
    PyObject *prof, *curv=Py_False, *keep=Py_False;
186
    static const std::array<const char *, 4> keywords_pro{"Profile", "WithContact", "WithCorrection", nullptr};
187
    if (Base::Wrapped_ParseTupleAndKeywords(args, kwds, "O!|O!O!", keywords_pro, &Part::TopoShapePy::Type, &prof,
188
                                            &PyBool_Type, &curv, &PyBool_Type, &keep)) {
189
        try {
190
            const TopoDS_Shape& s = static_cast<Part::TopoShapePy*>(prof)->getTopoShapePtr()->getShape();
191
            this->getBRepOffsetAPI_MakePipeShellPtr()->Add(s, Base::asBoolean(curv), Base::asBoolean(keep));
192
            Py_Return;
193
        }
194
        catch (Standard_Failure& e) {
195
            PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
196
            return nullptr;
197
        }
198
    }
199

200
    PyErr_Clear();
201
    PyObject *loc;
202
    static const std::array<const char *, 5> keywords_loc{"Profile", "Location", "WithContact", "WithCorrection",
203
                                                          nullptr};
204
    if (Base::Wrapped_ParseTupleAndKeywords(args, kwds, "O!O!|O!O!", keywords_loc, &Part::TopoShapePy::Type, &prof,
205
                                            &Part::TopoShapeVertexPy::Type, &loc, &PyBool_Type, &curv, &PyBool_Type,
206
                                            &keep)) {
207
        try {
208
            const TopoDS_Shape& s = static_cast<Part::TopoShapePy*>(prof)->getTopoShapePtr()->getShape();
209
            const TopoDS_Vertex& v = TopoDS::Vertex(static_cast<Part::TopoShapePy*>(loc)->getTopoShapePtr()->getShape());
210
            this->getBRepOffsetAPI_MakePipeShellPtr()->Add(s, v, Base::asBoolean(curv), Base::asBoolean(keep));
211
            Py_Return;
212
        }
213
        catch (Standard_Failure& e) {
214
            PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
215
            return nullptr;
216
        }
217
    }
218

219
    PyErr_SetString(PyExc_TypeError, "Wrong arguments:\n"
220
                    "add(Profile, WithContact=False, WithCorrection=False)\n"
221
                    "add(Profile, Location, WithContact=False, WithCorrection=False)"
222
    );
223
    return nullptr;
224
}
225

226
PyObject* BRepOffsetAPI_MakePipeShellPy::remove(PyObject *args)
227
{
228
    PyObject *prof;
229
    if (!PyArg_ParseTuple(args, "O!",&Part::TopoShapePy::Type,&prof))
230
        return nullptr;
231

232
    try {
233
        const TopoDS_Shape& s = static_cast<Part::TopoShapePy*>(prof)->getTopoShapePtr()->getShape();
234
        this->getBRepOffsetAPI_MakePipeShellPtr()->Delete(s);
235
        Py_Return;
236
    }
237
    catch (Standard_Failure& e) {
238
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
239
        return nullptr;
240
    }
241
}
242

243
PyObject* BRepOffsetAPI_MakePipeShellPy::isReady(PyObject *args)
244
{
245
    if (!PyArg_ParseTuple(args, ""))
246
        return nullptr;
247

248
    try {
249
        Standard_Boolean ok = this->getBRepOffsetAPI_MakePipeShellPtr()->IsReady();
250
        return Py::new_reference_to(Py::Boolean(ok ? true : false));
251
    }
252
    catch (Standard_Failure& e) {
253
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
254
        return nullptr;
255
    }
256
}
257

258
PyObject* BRepOffsetAPI_MakePipeShellPy::getStatus(PyObject *args)
259
{
260
    if (!PyArg_ParseTuple(args, ""))
261
        return nullptr;
262

263
    try {
264
        Standard_Integer val = this->getBRepOffsetAPI_MakePipeShellPtr()->GetStatus();
265
        return Py::new_reference_to(Py::Long(val));
266
    }
267
    catch (Standard_Failure& e) {
268
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
269
        return nullptr;
270
    }
271
}
272

273
PyObject* BRepOffsetAPI_MakePipeShellPy::makeSolid(PyObject *args)
274
{
275
    if (!PyArg_ParseTuple(args, ""))
276
        return nullptr;
277

278
    try {
279
        Standard_Boolean ok = this->getBRepOffsetAPI_MakePipeShellPtr()->MakeSolid();
280
        return Py::new_reference_to(Py::Boolean(ok ? true : false));
281
    }
282
    catch (Standard_Failure& e) {
283
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
284
        return nullptr;
285
    }
286
}
287

288
PyObject* BRepOffsetAPI_MakePipeShellPy::build(PyObject *args)
289
{
290
    if (!PyArg_ParseTuple(args, ""))
291
        return nullptr;
292

293
    try {
294
        this->getBRepOffsetAPI_MakePipeShellPtr()->Build();
295
        Py_Return;
296
    }
297
    catch (Standard_Failure& e) {
298
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
299
        return nullptr;
300
    }
301
}
302

303
PyObject* BRepOffsetAPI_MakePipeShellPy::shape(PyObject *args)
304
{
305
    if (!PyArg_ParseTuple(args, ""))
306
        return nullptr;
307

308
    try {
309
        const TopoDS_Shape& shape = this->getBRepOffsetAPI_MakePipeShellPtr()->Shape();
310
        return new TopoShapePy(new TopoShape(shape));
311
    }
312
    catch (Standard_Failure& e) {
313
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
314
        return nullptr;
315
    }
316
}
317

318
PyObject* BRepOffsetAPI_MakePipeShellPy::firstShape(PyObject *args)
319
{
320
    if (!PyArg_ParseTuple(args, ""))
321
        return nullptr;
322

323
    try {
324
        TopoDS_Shape shape = this->getBRepOffsetAPI_MakePipeShellPtr()->FirstShape();
325
        return new TopoShapePy(new TopoShape(shape));
326
    }
327
    catch (Standard_Failure& e) {
328
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
329
        return nullptr;
330
    }
331
}
332

333
PyObject* BRepOffsetAPI_MakePipeShellPy::lastShape(PyObject *args)
334
{
335
    if (!PyArg_ParseTuple(args, ""))
336
        return nullptr;
337

338
    try {
339
        TopoDS_Shape shape = this->getBRepOffsetAPI_MakePipeShellPtr()->LastShape();
340
        return new TopoShapePy(new TopoShape(shape));
341
    }
342
    catch (Standard_Failure& e) {
343
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
344
        return nullptr;
345
    }
346
}
347

348
PyObject* BRepOffsetAPI_MakePipeShellPy::generated(PyObject *args)
349
{
350
    PyObject *shape;
351
    if (!PyArg_ParseTuple(args, "O!",&Part::TopoShapePy::Type,&shape))
352
        return nullptr;
353

354
    try {
355
        const TopoDS_Shape& s = static_cast<Part::TopoShapePy*>(shape)->getTopoShapePtr()->getShape();
356
        const TopTools_ListOfShape& list = this->getBRepOffsetAPI_MakePipeShellPtr()->Generated(s);
357

358
        Py::List shapes;
359
        TopTools_ListIteratorOfListOfShape it;
360
        for (it.Initialize(list); it.More(); it.Next()) {
361
            const TopoDS_Shape& s = it.Value();
362
            shapes.append(Py::asObject(new TopoShapePy(new TopoShape(s))));
363
        }
364
        return Py::new_reference_to(shapes);
365
    }
366
    catch (Standard_Failure& e) {
367
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
368
        return nullptr;
369
    }
370
}
371

372
PyObject* BRepOffsetAPI_MakePipeShellPy::setTolerance(PyObject *args)
373
{
374
    double tol3d, boundTol, tolAngular;
375
    if (!PyArg_ParseTuple(args, "ddd",&tol3d,&boundTol,&tolAngular))
376
        return nullptr;
377

378
    try {
379
        this->getBRepOffsetAPI_MakePipeShellPtr()->SetTolerance(tol3d, boundTol, tolAngular);
380
        Py_Return;
381
    }
382
    catch (Standard_Failure& e) {
383
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
384
        return nullptr;
385
    }
386
}
387

388
PyObject* BRepOffsetAPI_MakePipeShellPy::setTransitionMode(PyObject *args)
389
{
390
    int mode;
391
    if (!PyArg_ParseTuple(args, "i",&mode))
392
        return nullptr;
393

394
    try {
395
        this->getBRepOffsetAPI_MakePipeShellPtr()->SetTransitionMode(BRepBuilderAPI_TransitionMode(mode));
396
        Py_Return;
397
    }
398
    catch (Standard_Failure& e) {
399
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
400
        return nullptr;
401
    }
402
}
403

404
PyObject* BRepOffsetAPI_MakePipeShellPy::setMaxDegree(PyObject *args)
405
{
406
    int degree;
407
    if (!PyArg_ParseTuple(args, "i",&degree))
408
        return nullptr;
409

410
    try {
411
        this->getBRepOffsetAPI_MakePipeShellPtr()->SetMaxDegree(degree);
412
        Py_Return;
413
    }
414
    catch (Standard_Failure& e) {
415
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
416
        return nullptr;
417
    }
418
}
419

420
PyObject* BRepOffsetAPI_MakePipeShellPy::setMaxSegments(PyObject *args)
421
{
422
    int nbseg;
423
    if (!PyArg_ParseTuple(args, "i",&nbseg))
424
        return nullptr;
425

426
    try {
427
        this->getBRepOffsetAPI_MakePipeShellPtr()->SetMaxSegments(nbseg);
428
        Py_Return;
429
    }
430
    catch (Standard_Failure& e) {
431
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
432
        return nullptr;
433
    }
434
}
435

436
PyObject* BRepOffsetAPI_MakePipeShellPy::setForceApproxC1(PyObject *args)
437
{
438
    PyObject *obj;
439
    if (!PyArg_ParseTuple(args, "O!",&PyBool_Type,&obj))
440
        return nullptr;
441

442
    try {
443
        this->getBRepOffsetAPI_MakePipeShellPtr()->SetForceApproxC1(Base::asBoolean(obj));
444
        Py_Return;
445
    }
446
    catch (Standard_Failure& e) {
447
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
448
        return nullptr;
449
    }
450
}
451

452

453
PyObject* BRepOffsetAPI_MakePipeShellPy::simulate(PyObject *args)
454
{
455
    int nbsec;
456
    if (!PyArg_ParseTuple(args, "i",&nbsec))
457
        return nullptr;
458

459
    try {
460
        TopTools_ListOfShape list;
461
        this->getBRepOffsetAPI_MakePipeShellPtr()->Simulate(nbsec, list);
462

463
        Py::List shapes;
464
        TopTools_ListIteratorOfListOfShape it;
465
        for (it.Initialize(list); it.More(); it.Next()) {
466
            const TopoDS_Shape& s = it.Value();
467
            shapes.append(Py::asObject(new TopoShapePy(new TopoShape(s))));
468
        }
469
        return Py::new_reference_to(shapes);
470
    }
471
    catch (Standard_Failure& e) {
472
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
473
        return nullptr;
474
    }
475
}
476

477

478
PyObject *BRepOffsetAPI_MakePipeShellPy::getCustomAttributes(const char* ) const
479
{
480
    return nullptr;
481
}
482

483
int BRepOffsetAPI_MakePipeShellPy::setCustomAttributes(const char* , PyObject *)
484
{
485
    return 0;
486
}
487

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

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

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

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