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"
26
# include <Standard_Failure.hxx>
28
# include <TopoDS_Edge.hxx>
31
#include <Base/VectorPy.h>
33
#include "ChFi2d/ChFi2d_FilletAlgoPy.h"
34
#include "ChFi2d/ChFi2d_FilletAlgoPy.cpp"
35
#include "TopoShapeEdgePy.h"
36
#include "TopoShapeWirePy.h"
43
PyObject *ChFi2d_FilletAlgoPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
45
// create a new instance of ChFi2d_FilletAlgoPy and the Twin object
46
return new ChFi2d_FilletAlgoPy(new ChFi2d_FilletAlgo);
50
int ChFi2d_FilletAlgoPy::PyInit(PyObject* args, PyObject* /*kwd*/)
52
if (PyArg_ParseTuple(args, ""))
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());
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());
78
PyErr_SetString(PyExc_TypeError, "Wrong arguments:\n"
80
"-- FilletAlgo(wire, plane)"
81
"-- FilletAlgo(edge, edge, plane)\n");
85
// returns a string which represents the object e.g. when printed in python
86
std::string ChFi2d_FilletAlgoPy::representation() const
88
return {"<FilletAlgo object>"};
91
PyObject* ChFi2d_FilletAlgoPy::init(PyObject *args)
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());
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());
115
PyErr_SetString(PyExc_TypeError, "Wrong arguments:\n"
116
"-- init(wire, plane)"
117
"-- init(edge, edge, plane)\n");
121
PyObject* ChFi2d_FilletAlgoPy::perform(PyObject *args)
124
if (!PyArg_ParseTuple(args, "d", &radius))
128
bool ok = getChFi2d_FilletAlgoPtr()->Perform(radius);
129
return Py::new_reference_to(Py::Boolean(ok));
131
catch (Standard_Failure& e) {
132
PyErr_SetString(Base::PyExc_FC_CADKernelError, e.GetMessageString());
137
PyObject* ChFi2d_FilletAlgoPy::numberOfResults(PyObject *args)
140
if (!PyArg_ParseTuple(args, "O!", &Base::VectorPy::Type, &pnt))
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));
148
catch (Standard_Failure& e) {
149
PyErr_SetString(Base::PyExc_FC_CADKernelError, e.GetMessageString());
154
PyObject* ChFi2d_FilletAlgoPy::result(PyObject *args)
158
if (!PyArg_ParseTuple(args, "O!|i", &Base::VectorPy::Type, &pnt, &solution))
161
Base::Vector3d* vec = static_cast<Base::VectorPy*>(pnt)->getVectorPtr();
164
TopoDS_Edge theEdge1, theEdge2;
165
TopoDS_Shape res_edge = getChFi2d_FilletAlgoPtr()->Result(Base::convertTo<gp_Pnt>(*vec), theEdge1, theEdge2, solution);
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);
172
catch (Standard_Failure& e) {
173
PyErr_SetString(Base::PyExc_FC_CADKernelError, e.GetMessageString());
178
PyObject *ChFi2d_FilletAlgoPy::getCustomAttributes(const char* /*attr*/) const
183
int ChFi2d_FilletAlgoPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)