FreeCAD

Форк
0
/
ChFi2d_FilletAlgoPyImp.cpp 
186 строк · 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 <gp_Pln.hxx>
26
# include <Standard_Failure.hxx>
27
# include <TopoDS.hxx>
28
# include <TopoDS_Edge.hxx>
29
#endif
30

31
#include <Base/VectorPy.h>
32

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

40

41
using namespace Part;
42

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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