1
/***************************************************************************
2
* Copyright (c) 2008 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 <GC_MakeArcOfCircle.hxx>
26
# include <GC_MakeArcOfEllipse.hxx>
27
# include <GC_MakeArcOfHyperbola.hxx>
28
# include <GC_MakeArcOfParabola.hxx>
29
# include <Geom_Circle.hxx>
30
# include <Geom_Ellipse.hxx>
31
# include <Geom_Hyperbola.hxx>
32
# include <Geom_Parabola.hxx>
35
#include <Base/VectorPy.h>
41
#include "HyperbolaPy.h"
43
#include "ParabolaPy.h"
48
extern const char* gce_ErrorStatusText(gce_ErrorType et);
50
// returns a string which represents the object e.g. when printed in python
51
std::string ArcPy::representation() const
53
return "<Arc object>";
56
PyObject *ArcPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
58
// never create such objects with the constructor
59
return new ArcPy(new GeomTrimmedCurve());
63
int ArcPy::PyInit(PyObject* args, PyObject* /*kwd*/)
67
PyObject *sense=Py_True;
68
if (PyArg_ParseTuple(args, "O!dd|O!", &(Part::CirclePy::Type), &o, &u1, &u2, &PyBool_Type, &sense)) {
70
Handle(Geom_Circle) circle = Handle(Geom_Circle)::DownCast
71
(static_cast<CirclePy*>(o)->getGeomCirclePtr()->handle());
72
GC_MakeArcOfCircle arc(circle->Circ(), u1, u2, Base::asBoolean(sense));
74
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(arc.Status()));
78
getGeomTrimmedCurvePtr()->setHandle(arc.Value());
81
catch (Standard_Failure& e) {
82
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
86
PyErr_SetString(PartExceptionOCCError, "creation of arc failed");
92
PyObject *pV1, *pV2, *pV3;
93
if (PyArg_ParseTuple(args, "O!O!O!", &(Base::VectorPy::Type), &pV1,
94
&(Base::VectorPy::Type), &pV2,
95
&(Base::VectorPy::Type), &pV3)) {
96
Base::Vector3d v1 = static_cast<Base::VectorPy*>(pV1)->value();
97
Base::Vector3d v2 = static_cast<Base::VectorPy*>(pV2)->value();
98
Base::Vector3d v3 = static_cast<Base::VectorPy*>(pV3)->value();
100
GC_MakeArcOfCircle arc(gp_Pnt(v1.x,v1.y,v1.z),
101
gp_Pnt(v2.x,v2.y,v2.z),
102
gp_Pnt(v3.x,v3.y,v3.z));
104
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(arc.Status()));
108
getGeomTrimmedCurvePtr()->setHandle(arc.Value());
113
if (PyArg_ParseTuple(args, "O!dd|O!", &(Part::EllipsePy::Type), &o, &u1, &u2, &PyBool_Type, &sense)) {
115
Handle(Geom_Ellipse) ellipse = Handle(Geom_Ellipse)::DownCast
116
(static_cast<EllipsePy*>(o)->getGeomEllipsePtr()->handle());
117
GC_MakeArcOfEllipse arc(ellipse->Elips(), u1, u2, Base::asBoolean(sense));
119
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(arc.Status()));
123
getGeomTrimmedCurvePtr()->setHandle(arc.Value());
126
catch (Standard_Failure& e) {
127
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
131
PyErr_SetString(PartExceptionOCCError, "creation of arc failed");
138
if (PyArg_ParseTuple(args, "O!dd|O!", &(Part::ParabolaPy::Type), &o, &u1, &u2, &PyBool_Type, &sense)) {
140
Handle(Geom_Parabola) parabola = Handle(Geom_Parabola)::DownCast
141
(static_cast<ParabolaPy*>(o)->getGeomParabolaPtr()->handle());
142
GC_MakeArcOfParabola arc(parabola->Parab(), u1, u2, Base::asBoolean(sense));
144
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(arc.Status()));
148
getGeomTrimmedCurvePtr()->setHandle(arc.Value());
151
catch (Standard_Failure& e) {
152
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
156
PyErr_SetString(PartExceptionOCCError, "creation of arc failed");
163
if (PyArg_ParseTuple(args, "O!dd|O!", &(Part::HyperbolaPy::Type), &o, &u1, &u2, &PyBool_Type, &sense)) {
165
Handle(Geom_Hyperbola) hyperbola = Handle(Geom_Hyperbola)::DownCast
166
(static_cast<HyperbolaPy*>(o)->getGeomHyperbolaPtr()->handle());
167
GC_MakeArcOfHyperbola arc(hyperbola->Hypr(), u1, u2, Base::asBoolean(sense));
169
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(arc.Status()));
173
getGeomTrimmedCurvePtr()->setHandle(arc.Value());
176
catch (Standard_Failure& e) {
177
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
181
PyErr_SetString(PartExceptionOCCError, "creation of arc failed");
187
PyErr_SetString(PyExc_TypeError, "Arc constructor expects a conic curve and a parameter range");
191
PyObject *ArcPy::getCustomAttributes(const char* /*attr*/) const
196
int ArcPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)