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 "ChFi2d/ChFi2d_AnaFilletAlgoPy.h"
31
#include "ChFi2d/ChFi2d_AnaFilletAlgoPy.cpp"
33
#include "TopoShapeEdgePy.h"
34
#include "TopoShapeWirePy.h"
39
PyObject *ChFi2d_AnaFilletAlgoPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
41
// create a new instance of ChFi2d_AnaFilletAlgoPy and the Twin object
42
return new ChFi2d_AnaFilletAlgoPy(new ChFi2d_AnaFilletAlgo);
46
int ChFi2d_AnaFilletAlgoPy::PyInit(PyObject* args, PyObject* /*kwd*/)
48
if (PyArg_ParseTuple(args, ""))
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());
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());
74
PyErr_SetString(PyExc_TypeError, "Wrong arguments:\n"
75
"-- AnaFilletAlgo()\n"
76
"-- AnaFilletAlgo(wire, plane)"
77
"-- AnaFilletAlgo(edge, edge, plane)\n");
81
// returns a string which represents the object e.g. when printed in python
82
std::string ChFi2d_AnaFilletAlgoPy::representation() const
84
return {"<AnaFilletAlgo object>"};
87
PyObject* ChFi2d_AnaFilletAlgoPy::init(PyObject *args)
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());
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());
111
PyErr_SetString(PyExc_TypeError, "Wrong arguments:\n"
112
"-- init(wire, plane)"
113
"-- init(edge, edge, plane)\n");
117
PyObject* ChFi2d_AnaFilletAlgoPy::perform(PyObject *args)
120
if (!PyArg_ParseTuple(args, "d", &radius))
124
bool ok = getChFi2d_AnaFilletAlgoPtr()->Perform(radius);
125
return Py::new_reference_to(Py::Boolean(ok));
127
catch (Standard_Failure& e) {
128
PyErr_SetString(Base::PyExc_FC_CADKernelError, e.GetMessageString());
133
PyObject* ChFi2d_AnaFilletAlgoPy::result(PyObject *args)
135
if (!PyArg_ParseTuple(args, ""))
139
TopoDS_Edge theEdge1, theEdge2;
140
TopoDS_Shape res_edge = getChFi2d_AnaFilletAlgoPtr()->Result(theEdge1, theEdge2);
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);
147
catch (Standard_Failure& e) {
148
PyErr_SetString(Base::PyExc_FC_CADKernelError, e.GetMessageString());
153
PyObject *ChFi2d_AnaFilletAlgoPy::getCustomAttributes(const char* /*attr*/) const
158
int ChFi2d_AnaFilletAlgoPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)