FreeCAD

Форк
0
/
ChFi2d_AnaFilletAlgoPyImp.cpp 
161 строка · 6.6 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2022 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 <Standard_Failure.hxx>
26
# include <TopoDS.hxx>
27
# include <TopoDS_Edge.hxx>
28
#endif
29

30
#include "ChFi2d/ChFi2d_AnaFilletAlgoPy.h"
31
#include "ChFi2d/ChFi2d_AnaFilletAlgoPy.cpp"
32
#include "PlanePy.h"
33
#include "TopoShapeEdgePy.h"
34
#include "TopoShapeWirePy.h"
35

36

37
using namespace Part;
38

39
PyObject *ChFi2d_AnaFilletAlgoPy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
40
{
41
    // create a new instance of ChFi2d_AnaFilletAlgoPy and the Twin object
42
    return new ChFi2d_AnaFilletAlgoPy(new ChFi2d_AnaFilletAlgo);
43
}
44

45
// constructor method
46
int ChFi2d_AnaFilletAlgoPy::PyInit(PyObject* args, PyObject* /*kwd*/)
47
{
48
    if (PyArg_ParseTuple(args, ""))
49
        return 0;
50

51
    PyErr_Clear();
52
    PyObject* wire;
53
    PyObject* plane;
54
    if (PyArg_ParseTuple(args, "O!O!", &TopoShapeWirePy::Type, &wire, &PlanePy::Type, &plane)) {
55
        TopoDS_Shape shape = static_cast<TopoShapeWirePy*>(wire)->getTopoShapePtr()->getShape();
56
        Handle(Geom_Plane) hPlane = Handle(Geom_Plane)::DownCast(static_cast<PlanePy*>(plane)->getGeomPlanePtr()->handle());
57
        getChFi2d_AnaFilletAlgoPtr()->Init(TopoDS::Wire(shape), hPlane->Pln());
58
        return 0;
59
    }
60

61
    PyErr_Clear();
62
    PyObject* edge1;
63
    PyObject* edge2;
64
    if (PyArg_ParseTuple(args, "O!O!O!", &TopoShapeEdgePy::Type, &edge1,
65
                                         &TopoShapeEdgePy::Type, &edge2,
66
                                         &PlanePy::Type, &plane)) {
67
        TopoDS_Shape shape1 = static_cast<TopoShapeEdgePy*>(edge1)->getTopoShapePtr()->getShape();
68
        TopoDS_Shape shape2 = static_cast<TopoShapeEdgePy*>(edge2)->getTopoShapePtr()->getShape();
69
        Handle(Geom_Plane) hPlane = Handle(Geom_Plane)::DownCast(static_cast<PlanePy*>(plane)->getGeomPlanePtr()->handle());
70
        getChFi2d_AnaFilletAlgoPtr()->Init(TopoDS::Edge(shape1), TopoDS::Edge(shape2), hPlane->Pln());
71
        return 0;
72
    }
73

74
    PyErr_SetString(PyExc_TypeError, "Wrong arguments:\n"
75
                                     "-- AnaFilletAlgo()\n"
76
                                     "-- AnaFilletAlgo(wire, plane)"
77
                                     "-- AnaFilletAlgo(edge, edge, plane)\n");
78
    return -1;
79
}
80

81
// returns a string which represents the object e.g. when printed in python
82
std::string ChFi2d_AnaFilletAlgoPy::representation() const
83
{
84
    return {"<AnaFilletAlgo object>"};
85
}
86

87
PyObject* ChFi2d_AnaFilletAlgoPy::init(PyObject *args)
88
{
89
    PyObject* wire;
90
    PyObject* plane;
91
    if (PyArg_ParseTuple(args, "O!O!", &TopoShapeWirePy::Type, &wire, &PlanePy::Type, &plane)) {
92
        TopoDS_Shape shape = static_cast<TopoShapeWirePy*>(wire)->getTopoShapePtr()->getShape();
93
        Handle(Geom_Plane) hPlane = Handle(Geom_Plane)::DownCast(static_cast<PlanePy*>(plane)->getGeomPlanePtr()->handle());
94
        getChFi2d_AnaFilletAlgoPtr()->Init(TopoDS::Wire(shape), hPlane->Pln());
95
        Py_Return;
96
    }
97

98
    PyErr_Clear();
99
    PyObject* edge1;
100
    PyObject* edge2;
101
    if (PyArg_ParseTuple(args, "O!O!O!", &TopoShapeEdgePy::Type, &edge1,
102
                                         &TopoShapeEdgePy::Type, &edge2,
103
                                         &PlanePy::Type, &plane)) {
104
        TopoDS_Shape shape1 = static_cast<TopoShapeEdgePy*>(edge1)->getTopoShapePtr()->getShape();
105
        TopoDS_Shape shape2 = static_cast<TopoShapeEdgePy*>(edge2)->getTopoShapePtr()->getShape();
106
        Handle(Geom_Plane) hPlane = Handle(Geom_Plane)::DownCast(static_cast<PlanePy*>(plane)->getGeomPlanePtr()->handle());
107
        getChFi2d_AnaFilletAlgoPtr()->Init(TopoDS::Edge(shape1), TopoDS::Edge(shape2), hPlane->Pln());
108
        Py_Return;
109
    }
110

111
    PyErr_SetString(PyExc_TypeError, "Wrong arguments:\n"
112
                                     "-- init(wire, plane)"
113
                                     "-- init(edge, edge, plane)\n");
114
    return nullptr;
115
}
116

117
PyObject* ChFi2d_AnaFilletAlgoPy::perform(PyObject *args)
118
{
119
    double radius;
120
    if (!PyArg_ParseTuple(args, "d", &radius))
121
        return nullptr;
122

123
    try {
124
        bool ok = getChFi2d_AnaFilletAlgoPtr()->Perform(radius);
125
        return Py::new_reference_to(Py::Boolean(ok));
126
    }
127
    catch (Standard_Failure& e) {
128
        PyErr_SetString(Base::PyExc_FC_CADKernelError, e.GetMessageString());
129
        return nullptr;
130
    }
131
}
132

133
PyObject* ChFi2d_AnaFilletAlgoPy::result(PyObject *args)
134
{
135
    if (!PyArg_ParseTuple(args, ""))
136
        return nullptr;
137

138
    try {
139
        TopoDS_Edge theEdge1, theEdge2;
140
        TopoDS_Shape res_edge = getChFi2d_AnaFilletAlgoPtr()->Result(theEdge1, theEdge2);
141

142
        Py::TupleN tuple(Py::asObject(TopoShape(res_edge).getPyObject()),
143
                         Py::asObject(TopoShape(theEdge1).getPyObject()),
144
                         Py::asObject(TopoShape(theEdge2).getPyObject()));
145
        return Py::new_reference_to(tuple);
146
    }
147
    catch (Standard_Failure& e) {
148
        PyErr_SetString(Base::PyExc_FC_CADKernelError, e.GetMessageString());
149
        return nullptr;
150
    }
151
}
152

153
PyObject *ChFi2d_AnaFilletAlgoPy::getCustomAttributes(const char* /*attr*/) const
154
{
155
    return nullptr;
156
}
157

158
int ChFi2d_AnaFilletAlgoPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
159
{
160
    return 0;
161
}
162

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

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

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

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