FreeCAD

Форк
0
/
ChFi2d_FilletAPIPyImp.cpp 
185 строк · 7.4 Кб
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 <Base/VectorPy.h>
31

32
#include "ChFi2d/ChFi2d_FilletAPIPy.h"
33
#include "ChFi2d/ChFi2d_FilletAPIPy.cpp"
34
#include "TopoShapeEdgePy.h"
35
#include "TopoShapeWirePy.h"
36
#include "PlanePy.h"
37
#include "Tools.h"
38

39

40
using namespace Part;
41

42
PyObject *ChFi2d_FilletAPIPy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
43
{
44
    // create a new instance of ChFi2d_FilletAPIPy and the Twin object
45
    return new ChFi2d_FilletAPIPy(new ChFi2d_FilletAPI);
46
}
47

48
// constructor method
49
int ChFi2d_FilletAPIPy::PyInit(PyObject* args, PyObject* /*kwd*/)
50
{
51
    if (PyArg_ParseTuple(args, ""))
52
        return 0;
53

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

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

77
    PyErr_SetString(PyExc_TypeError, "Wrong arguments:\n"
78
                                     "-- FilletAPI()\n"
79
                                     "-- FilletAPI(wire, plane)"
80
                                     "-- FilletAPI(edge, edge, plane)\n");
81
    return -1;
82
}
83

84
// returns a string which represents the object e.g. when printed in python
85
std::string ChFi2d_FilletAPIPy::representation() const
86
{
87
    return {"<FilletAPI object>"};
88
}
89

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

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

114
    PyErr_SetString(PyExc_TypeError, "Wrong arguments:\n"
115
                                     "-- init(wire, plane)"
116
                                     "-- init(edge, edge, plane)\n");
117
    return nullptr;
118
}
119

120
PyObject* ChFi2d_FilletAPIPy::perform(PyObject *args)
121
{
122
    double radius;
123
    if (!PyArg_ParseTuple(args, "d", &radius))
124
        return nullptr;
125

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

136
PyObject* ChFi2d_FilletAPIPy::numberOfResults(PyObject *args)
137
{
138
    PyObject* pnt;
139
    if (!PyArg_ParseTuple(args, "O!", &Base::VectorPy::Type, &pnt))
140
        return nullptr;
141

142
    try {
143
        Base::Vector3d* vec = static_cast<Base::VectorPy*>(pnt)->getVectorPtr();
144
        Standard_Integer num = getChFi2d_FilletAPIPtr()->NbResults(gp_Pnt(vec->x, vec->y, vec->z));
145
        return Py::new_reference_to(Py::Long(num));
146
    }
147
    catch (Standard_Failure& e) {
148
        PyErr_SetString(Base::PyExc_FC_CADKernelError, e.GetMessageString());
149
        return nullptr;
150
    }
151
}
152

153
PyObject* ChFi2d_FilletAPIPy::result(PyObject *args)
154
{
155
    PyObject* pnt;
156
    int solution = -1;
157
    if (!PyArg_ParseTuple(args, "O!|i", &Base::VectorPy::Type, &pnt, &solution))
158
        return nullptr;
159

160
    Base::Vector3d* vec = static_cast<Base::VectorPy*>(pnt)->getVectorPtr();
161

162
    try {
163
        TopoDS_Edge theEdge1, theEdge2;
164
        TopoDS_Shape res_edge = getChFi2d_FilletAPIPtr()->Result(Base::convertTo<gp_Pnt>(*vec), theEdge1, theEdge2, solution);
165

166
        Py::TupleN tuple(Py::asObject(TopoShape(res_edge).getPyObject()),
167
                         Py::asObject(TopoShape(theEdge1).getPyObject()),
168
                         Py::asObject(TopoShape(theEdge2).getPyObject()));
169
        return Py::new_reference_to(tuple);
170
    }
171
    catch (Standard_Failure& e) {
172
        PyErr_SetString(Base::PyExc_FC_CADKernelError, e.GetMessageString());
173
        return nullptr;
174
    }
175
}
176

177
PyObject *ChFi2d_FilletAPIPy::getCustomAttributes(const char* /*attr*/) const
178
{
179
    return nullptr;
180
}
181

182
int ChFi2d_FilletAPIPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
183
{
184
    return 0;
185
}
186

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

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

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

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