1
/***************************************************************************
2
* Copyright (c) 2022 Werner Mayer <wmayer[at]users.sourceforge.net> *
4
* This file is part of the FreeCAD CAx development system. *
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. *
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. *
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 *
21
***************************************************************************/
23
#include "PreCompiled.h"
25
# include <Standard_Failure.hxx>
27
# include <TopoDS_Edge.hxx>
30
#include <Base/VectorPy.h>
32
#include "ChFi2d/ChFi2d_FilletAPIPy.h"
33
#include "ChFi2d/ChFi2d_FilletAPIPy.cpp"
34
#include "TopoShapeEdgePy.h"
35
#include "TopoShapeWirePy.h"
42
PyObject *ChFi2d_FilletAPIPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
44
// create a new instance of ChFi2d_FilletAPIPy and the Twin object
45
return new ChFi2d_FilletAPIPy(new ChFi2d_FilletAPI);
49
int ChFi2d_FilletAPIPy::PyInit(PyObject* args, PyObject* /*kwd*/)
51
if (PyArg_ParseTuple(args, ""))
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());
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());
77
PyErr_SetString(PyExc_TypeError, "Wrong arguments:\n"
79
"-- FilletAPI(wire, plane)"
80
"-- FilletAPI(edge, edge, plane)\n");
84
// returns a string which represents the object e.g. when printed in python
85
std::string ChFi2d_FilletAPIPy::representation() const
87
return {"<FilletAPI object>"};
90
PyObject* ChFi2d_FilletAPIPy::init(PyObject *args)
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());
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());
114
PyErr_SetString(PyExc_TypeError, "Wrong arguments:\n"
115
"-- init(wire, plane)"
116
"-- init(edge, edge, plane)\n");
120
PyObject* ChFi2d_FilletAPIPy::perform(PyObject *args)
123
if (!PyArg_ParseTuple(args, "d", &radius))
127
bool ok = getChFi2d_FilletAPIPtr()->Perform(radius);
128
return Py::new_reference_to(Py::Boolean(ok));
130
catch (Standard_Failure& e) {
131
PyErr_SetString(Base::PyExc_FC_CADKernelError, e.GetMessageString());
136
PyObject* ChFi2d_FilletAPIPy::numberOfResults(PyObject *args)
139
if (!PyArg_ParseTuple(args, "O!", &Base::VectorPy::Type, &pnt))
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));
147
catch (Standard_Failure& e) {
148
PyErr_SetString(Base::PyExc_FC_CADKernelError, e.GetMessageString());
153
PyObject* ChFi2d_FilletAPIPy::result(PyObject *args)
157
if (!PyArg_ParseTuple(args, "O!|i", &Base::VectorPy::Type, &pnt, &solution))
160
Base::Vector3d* vec = static_cast<Base::VectorPy*>(pnt)->getVectorPtr();
163
TopoDS_Edge theEdge1, theEdge2;
164
TopoDS_Shape res_edge = getChFi2d_FilletAPIPtr()->Result(Base::convertTo<gp_Pnt>(*vec), theEdge1, theEdge2, solution);
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);
171
catch (Standard_Failure& e) {
172
PyErr_SetString(Base::PyExc_FC_CADKernelError, e.GetMessageString());
177
PyObject *ChFi2d_FilletAPIPy::getCustomAttributes(const char* /*attr*/) const
182
int ChFi2d_FilletAPIPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)