1
/***************************************************************************
2
* Copyright (c) 2008 Werner Mayer <wmayer@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
***************************************************************************/
24
#include "PreCompiled.h"
26
# include <Geom_Parabola.hxx>
29
#include <Base/VectorPy.h>
30
#include <Base/GeometryPyCXX.h>
33
#include "ParabolaPy.h"
34
#include "ParabolaPy.cpp"
38
// returns a string which represents the object e.g. when printed in python
39
const char *ParabolaPy::representation(void) const
41
return "<Parabola object>";
44
PyObject *ParabolaPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
46
// create a new instance of ParabolaPy and the Twin object
47
return new ParabolaPy(new GeomParabola);
51
int ParabolaPy::PyInit(PyObject* args, PyObject* /*kwd*/)
53
if (PyArg_ParseTuple(args, "")) {
54
Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast
55
(getGeometryPtr()->handle());
63
Py::Float ParabolaPy::getEccentricity(void) const
65
Handle_Geom_Parabola curve = Handle_Geom_Parabola::DownCast(getGeometryPtr()->handle());
66
return Py::Float(curve->Eccentricity());
69
Py::Float ParabolaPy::getFocal(void) const
71
Handle_Geom_Parabola curve = Handle_Geom_Parabola::DownCast(getGeometryPtr()->handle());
72
return Py::Float(curve->Focal());
75
void ParabolaPy::setFocal(Py::Float arg)
77
Handle_Geom_Parabola curve = Handle_Geom_Parabola::DownCast(getGeometryPtr()->handle());
78
curve->SetFocal((double)arg);
81
Py::Object ParabolaPy::getFocus(void) const
83
Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast
84
(getGeometryPtr()->handle());
85
gp_Pnt loc = c->Focus();
86
return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
89
Py::Float ParabolaPy::getParameter(void) const
91
Handle_Geom_Parabola curve = Handle_Geom_Parabola::DownCast(getGeometryPtr()->handle());
92
return Py::Float(curve->Parameter());
95
Py::Object ParabolaPy::getLocation(void) const
97
Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast
98
(getGeometryPtr()->handle());
99
gp_Pnt loc = c->Location();
100
return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
103
void ParabolaPy::setLocation(Py::Object arg)
105
PyObject* p = arg.ptr();
106
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
107
Base::Vector3d loc = static_cast<Base::VectorPy*>(p)->value();
108
Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast
109
(getGeometryPtr()->handle());
110
c->SetLocation(gp_Pnt(loc.x, loc.y, loc.z));
112
else if (PyTuple_Check(p)) {
113
Py::Tuple tuple(arg);
115
loc.SetX((double)Py::Float(tuple.getItem(0)));
116
loc.SetY((double)Py::Float(tuple.getItem(1)));
117
loc.SetZ((double)Py::Float(tuple.getItem(2)));
118
Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast
119
(getGeometryPtr()->handle());
123
std::string error = std::string("type must be 'Vector', not ");
124
error += p->ob_type->tp_name;
125
throw Py::TypeError(error);
129
Py::Object ParabolaPy::getAxis(void) const
131
Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast
132
(getGeometryPtr()->handle());
133
gp_Dir dir = c->Axis().Direction();
134
return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z()));
137
void ParabolaPy::setAxis(Py::Object arg)
139
Standard_Real dir_x, dir_y, dir_z;
140
PyObject *p = arg.ptr();
141
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
142
Base::Vector3d v = static_cast<Base::VectorPy*>(p)->value();
147
else if (PyTuple_Check(p)) {
148
Py::Tuple tuple(arg);
149
dir_x = (double)Py::Float(tuple.getItem(0));
150
dir_y = (double)Py::Float(tuple.getItem(1));
151
dir_z = (double)Py::Float(tuple.getItem(2));
154
std::string error = std::string("type must be 'Vector' or tuple, not ");
155
error += p->ob_type->tp_name;
156
throw Py::TypeError(error);
160
Handle_Geom_Parabola this_curv = Handle_Geom_Parabola::DownCast
161
(this->getGeometryPtr()->handle());
163
axis.SetLocation(this_curv->Location());
164
axis.SetDirection(gp_Dir(dir_x, dir_y, dir_z));
165
gp_Dir dir = axis.Direction();
166
this_curv->SetAxis(axis);
168
catch (Standard_Failure) {
169
throw Py::Exception("cannot set axis");
173
PyObject *ParabolaPy::getCustomAttributes(const char* /*attr*/) const
178
int ParabolaPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)