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 <gp_Elips.hxx>
27
# include <Geom_Ellipse.hxx>
28
# include <GC_MakeEllipse.hxx>
31
#include <Base/GeometryPyCXX.h>
32
#include <Base/VectorPy.h>
35
#include "EllipsePy.h"
36
#include "EllipsePy.cpp"
40
extern const char* gce_ErrorStatusText(gce_ErrorType et);
42
// returns a string which represents the object e.g. when printed in python
43
const char *EllipsePy::representation(void) const
45
return "<Ellipse object>";
48
PyObject *EllipsePy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
50
// create a new instance of EllipsePy and the Twin object
51
return new EllipsePy(new GeomEllipse);
55
int EllipsePy::PyInit(PyObject* args, PyObject* kwds)
57
char* keywords_n[] = {NULL};
58
if (PyArg_ParseTupleAndKeywords(args, kwds, "", keywords_n)) {
59
Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle());
60
ellipse->SetMajorRadius(2.0);
61
ellipse->SetMinorRadius(1.0);
65
char* keywords_e[] = {"Ellipse",NULL};
68
if (PyArg_ParseTupleAndKeywords(args, kwds, "O!",keywords_e, &(EllipsePy::Type), &pElips)) {
69
EllipsePy* pEllipse = static_cast<EllipsePy*>(pElips);
70
Handle_Geom_Ellipse Elips1 = Handle_Geom_Ellipse::DownCast
71
(pEllipse->getGeomEllipsePtr()->handle());
72
Handle_Geom_Ellipse Elips2 = Handle_Geom_Ellipse::DownCast
73
(this->getGeomEllipsePtr()->handle());
74
Elips2->SetElips(Elips1->Elips());
78
char* keywords_ssc[] = {"S1","S2","Center",NULL};
80
PyObject *pV1, *pV2, *pV3;
81
if (PyArg_ParseTupleAndKeywords(args, kwds, "O!O!O!", keywords_ssc,
82
&(Base::VectorPy::Type), &pV1,
83
&(Base::VectorPy::Type), &pV2,
84
&(Base::VectorPy::Type), &pV3)) {
85
Base::Vector3d v1 = static_cast<Base::VectorPy*>(pV1)->value();
86
Base::Vector3d v2 = static_cast<Base::VectorPy*>(pV2)->value();
87
Base::Vector3d v3 = static_cast<Base::VectorPy*>(pV3)->value();
88
GC_MakeEllipse me(gp_Pnt(v1.x,v1.y,v1.z),
89
gp_Pnt(v2.x,v2.y,v2.z),
90
gp_Pnt(v3.x,v3.y,v3.z));
92
PyErr_SetString(PyExc_Exception, gce_ErrorStatusText(me.Status()));
96
Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle());
97
ellipse->SetElips(me.Value()->Elips());
101
char* keywords_cmm[] = {"Center","MajorRadius","MinorRadius",NULL};
105
if (PyArg_ParseTupleAndKeywords(args, kwds, "O!dd", keywords_cmm,
106
&(Base::VectorPy::Type), &pV,
108
Base::Vector3d c = static_cast<Base::VectorPy*>(pV)->value();
109
GC_MakeEllipse me(gp_Ax2(gp_Pnt(c.x,c.y,c.z), gp_Dir(0.0,0.0,1.0)),
112
PyErr_SetString(PyExc_Exception, gce_ErrorStatusText(me.Status()));
116
Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle());
117
ellipse->SetElips(me.Value()->Elips());
121
PyErr_SetString(PyExc_TypeError, "Ellipse constructor accepts:\n"
122
"-- empty parameter list\n"
124
"-- Point, double, double\n"
125
"-- Point, Point, Point");
129
Py::Float EllipsePy::getMajorRadius(void) const
131
Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle());
132
return Py::Float(ellipse->MajorRadius());
135
void EllipsePy::setMajorRadius(Py::Float arg)
137
Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle());
138
ellipse->SetMajorRadius((double)arg);
141
Py::Float EllipsePy::getMinorRadius(void) const
143
Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle());
144
return Py::Float(ellipse->MinorRadius());
147
void EllipsePy::setMinorRadius(Py::Float arg)
149
Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle());
150
ellipse->SetMinorRadius((double)arg);
153
Py::Float EllipsePy::getEccentricity(void) const
155
Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle());
156
return Py::Float(ellipse->Eccentricity());
159
Py::Float EllipsePy::getFocal(void) const
161
Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle());
162
return Py::Float(ellipse->Focal());
165
Py::Object EllipsePy::getFocus1(void) const
167
Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle());
168
gp_Pnt loc = ellipse->Focus1();
169
return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
172
Py::Object EllipsePy::getFocus2(void) const
174
Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle());
175
gp_Pnt loc = ellipse->Focus2();
176
return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
179
Py::Object EllipsePy::getCenter(void) const
181
Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle());
182
gp_Pnt loc = ellipse->Location();
183
return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
186
void EllipsePy::setCenter(Py::Object arg)
188
PyObject* p = arg.ptr();
189
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
190
Base::Vector3d loc = static_cast<Base::VectorPy*>(p)->value();
191
Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle());
192
ellipse->SetLocation(gp_Pnt(loc.x, loc.y, loc.z));
194
else if (PyTuple_Check(p)) {
195
Py::Tuple tuple(arg);
197
loc.SetX((double)Py::Float(tuple.getItem(0)));
198
loc.SetY((double)Py::Float(tuple.getItem(1)));
199
loc.SetZ((double)Py::Float(tuple.getItem(2)));
200
Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle());
201
ellipse->SetLocation(loc);
204
std::string error = std::string("type must be 'Vector', not ");
205
error += p->ob_type->tp_name;
206
throw Py::TypeError(error);
210
Py::Object EllipsePy::getAxis(void) const
212
Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle());
213
gp_Ax1 axis = ellipse->Axis();
214
gp_Dir dir = axis.Direction();
215
return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z()));
218
void EllipsePy::setAxis(Py::Object arg)
220
PyObject* p = arg.ptr();
222
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
223
val = static_cast<Base::VectorPy*>(p)->value();
225
else if (PyTuple_Check(p)) {
226
val = Base::getVectorFromTuple<double>(p);
229
std::string error = std::string("type must be 'Vector', not ");
230
error += p->ob_type->tp_name;
231
throw Py::TypeError(error);
234
Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle());
237
axis.SetLocation(ellipse->Location());
238
axis.SetDirection(gp_Dir(val.x, val.y, val.z));
239
gp_Dir dir = axis.Direction();
240
ellipse->SetAxis(axis);
242
catch (Standard_Failure) {
243
throw Py::Exception("cannot set axis");
247
PyObject *EllipsePy::getCustomAttributes(const char* /*attr*/) const
252
int EllipsePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)