FreeCAD

Форк
0
/
TopoShapeCompSolidPyImp.cpp 
123 строки · 4.2 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2008 Jürgen Riegel <juergen.riegel@web.de>              *
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

25
#ifndef _PreComp_
26
# include <BRep_Builder.hxx>
27
# include <Standard_Failure.hxx>
28
# include <TopoDS.hxx>
29
# include <TopoDS_CompSolid.hxx>
30
#endif
31

32
#include "OCCError.h"
33
#include "PartPyCXX.h"
34

35
// inclusion of the generated files (generated out of TopoShapeCompSolidPy.xml)
36
#include "TopoShapeCompSolidPy.h"
37
#include "TopoShapeCompSolidPy.cpp"
38
#include "TopoShapeSolidPy.h"
39
#include "TopoShapeOpCode.h"
40

41

42
using namespace Part;
43

44
// returns a string which represents the object e.g. when printed in python
45
std::string TopoShapeCompSolidPy::representation() const
46
{
47
    std::stringstream str;
48
    str << "<CompSolid object at " << getTopoShapePtr() << ">";
49

50
    return str.str();
51
}
52

53
PyObject *TopoShapeCompSolidPy::PyMake(struct _typeobject *, PyObject *, PyObject *)
54
{
55
    return new TopoShapeCompSolidPy(new TopoShape);
56
}
57

58
int TopoShapeCompSolidPy::PyInit(PyObject* args, PyObject* /*kwd*/)
59
{
60
    if (PyArg_ParseTuple(args, "")) {
61
        // Undefined CompSolid
62
        getTopoShapePtr()->setShape(TopoDS_CompSolid());
63
        return 0;
64
    }
65

66
    PyErr_Clear();
67
    PyObject* pcObj;
68
    if (!PyArg_ParseTuple(args, "O", &pcObj)) {
69
        return -1;
70
    }
71
    try {
72
        getTopoShapePtr()->makeElementBoolean(Part::OpCodes::Compsolid, getPyShapes(pcObj));
73
    }
74
    _PY_CATCH_OCC(return (-1))
75
    return 0;
76
}
77

78
PyObject* TopoShapeCompSolidPy::add(PyObject* args)
79
{
80
    PyObject* obj;
81
    if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapeSolidPy::Type), &obj)) {
82
        return nullptr;
83
    }
84

85
    BRep_Builder builder;
86
    TopoDS_Shape comp = getTopoShapePtr()->getShape();
87
    if (comp.IsNull()) {
88
        builder.MakeCompSolid(TopoDS::CompSolid(comp));
89
    }
90
    auto shapes = getPyShapes(obj);
91

92
    try {
93
        for (auto& ts : shapes) {
94
            if (!ts.isNull()) {
95
                builder.Add(comp, ts.getShape());
96
            }
97
            else {
98
                Standard_Failure::Raise("Cannot empty shape to compound solid");
99
            }
100
        }
101
        auto& self = *getTopoShapePtr();
102
        shapes.push_back(self);
103
        TopoShape tmp(self.Tag, self.Hasher, comp);
104
        tmp.mapSubElement(shapes);
105
        self = tmp;
106
        Py_Return;
107
    }
108
    catch (Standard_Failure& e) {
109

110
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
111
        return nullptr;
112
    }
113
}
114

115
PyObject *TopoShapeCompSolidPy::getCustomAttributes(const char* /*attr*/) const
116
{
117
    return nullptr;
118
}
119

120
int TopoShapeCompSolidPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
121
{
122
    return 0;
123
}
124

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

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

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

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