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_Hyperbola.hxx>
27
# include <GC_MakeHyperbola.hxx>
28
# include <gp_Hypr.hxx>
31
#include <Base/VectorPy.h>
32
#include <Base/GeometryPyCXX.h>
35
#include "HyperbolaPy.h"
36
#include "HyperbolaPy.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 *HyperbolaPy::representation(void) const
45
return "<Hyperbola object>";
48
PyObject *HyperbolaPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
50
// create a new instance of HyperbolaPy and the Twin object
51
return new HyperbolaPy(new GeomHyperbola);
55
int HyperbolaPy::PyInit(PyObject* args, PyObject* kwds)
57
char* keywords_n[] = {NULL};
58
if (PyArg_ParseTupleAndKeywords(args, kwds, "", keywords_n)) {
59
Handle_Geom_Hyperbola hypr = Handle_Geom_Hyperbola::DownCast(getGeometryPtr()->handle());
60
hypr->SetMajorRadius(2.0);
61
hypr->SetMinorRadius(1.0);
65
char* keywords_e[] = {"Hyperbola",NULL};
68
if (PyArg_ParseTupleAndKeywords(args, kwds, "O!",keywords_e, &(HyperbolaPy::Type), &pHypr)) {
69
HyperbolaPy* pH = static_cast<HyperbolaPy*>(pHypr);
70
Handle_Geom_Hyperbola Hypr1 = Handle_Geom_Hyperbola::DownCast
71
(pH->getGeometryPtr()->handle());
72
Handle_Geom_Hyperbola Hypr2 = Handle_Geom_Hyperbola::DownCast
73
(this->getGeometryPtr()->handle());
74
Hypr2->SetHypr(Hypr1->Hypr());
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_MakeHyperbola mh(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(mh.Status()));
96
Handle_Geom_Hyperbola hyperb = Handle_Geom_Hyperbola::DownCast(getGeometryPtr()->handle());
97
hyperb->SetHypr(mh.Value()->Hypr());
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_MakeHyperbola mh(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(mh.Status()));
116
Handle_Geom_Hyperbola hyperb = Handle_Geom_Hyperbola::DownCast(getGeometryPtr()->handle());
117
hyperb->SetHypr(mh.Value()->Hypr());
121
PyErr_SetString(PyExc_TypeError, "Hyperbola constructor accepts:\n"
122
"-- empty parameter list\n"
124
"-- Point, double, double\n"
125
"-- Point, Point, Point");
129
Py::Float HyperbolaPy::getEccentricity(void) const
131
Handle_Geom_Hyperbola curve = Handle_Geom_Hyperbola::DownCast(getGeometryPtr()->handle());
132
return Py::Float(curve->Eccentricity());
135
Py::Float HyperbolaPy::getFocal(void) const
137
Handle_Geom_Hyperbola curve = Handle_Geom_Hyperbola::DownCast(getGeometryPtr()->handle());
138
return Py::Float(curve->Focal());
141
Py::Object HyperbolaPy::getFocus1(void) const
143
Handle_Geom_Hyperbola c = Handle_Geom_Hyperbola::DownCast
144
(getGeometryPtr()->handle());
145
gp_Pnt loc = c->Focus1();
146
return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
149
Py::Object HyperbolaPy::getFocus2(void) const
151
Handle_Geom_Hyperbola c = Handle_Geom_Hyperbola::DownCast
152
(getGeometryPtr()->handle());
153
gp_Pnt loc = c->Focus2();
154
return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
157
Py::Float HyperbolaPy::getParameter(void) const
159
Handle_Geom_Hyperbola curve = Handle_Geom_Hyperbola::DownCast(getGeometryPtr()->handle());
160
return Py::Float(curve->Parameter());
163
Py::Float HyperbolaPy::getMajorRadius(void) const
165
Handle_Geom_Hyperbola curve = Handle_Geom_Hyperbola::DownCast(getGeometryPtr()->handle());
166
return Py::Float(curve->MajorRadius());
169
void HyperbolaPy::setMajorRadius(Py::Float arg)
171
Handle_Geom_Hyperbola curve = Handle_Geom_Hyperbola::DownCast(getGeometryPtr()->handle());
172
curve->SetMajorRadius((double)arg);
175
Py::Float HyperbolaPy::getMinorRadius(void) const
177
Handle_Geom_Hyperbola curve = Handle_Geom_Hyperbola::DownCast(getGeometryPtr()->handle());
178
return Py::Float(curve->MinorRadius());
181
void HyperbolaPy::setMinorRadius(Py::Float arg)
183
Handle_Geom_Hyperbola curve = Handle_Geom_Hyperbola::DownCast(getGeometryPtr()->handle());
184
curve->SetMinorRadius((double)arg);
187
Py::Object HyperbolaPy::getLocation(void) const
189
Handle_Geom_Hyperbola c = Handle_Geom_Hyperbola::DownCast
190
(getGeometryPtr()->handle());
191
gp_Pnt loc = c->Location();
192
return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
195
void HyperbolaPy::setLocation(Py::Object arg)
197
PyObject* p = arg.ptr();
198
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
199
Base::Vector3d loc = static_cast<Base::VectorPy*>(p)->value();
200
Handle_Geom_Hyperbola c = Handle_Geom_Hyperbola::DownCast
201
(getGeometryPtr()->handle());
202
c->SetLocation(gp_Pnt(loc.x, loc.y, loc.z));
204
else if (PyTuple_Check(p)) {
206
Py::Tuple tuple(arg);
207
loc.SetX((double)Py::Float(tuple.getItem(0)));
208
loc.SetY((double)Py::Float(tuple.getItem(1)));
209
loc.SetZ((double)Py::Float(tuple.getItem(2)));
210
Handle_Geom_Hyperbola c = Handle_Geom_Hyperbola::DownCast
211
(getGeometryPtr()->handle());
215
std::string error = std::string("type must be 'Vector', not ");
216
error += p->ob_type->tp_name;
217
throw Py::TypeError(error);
221
Py::Object HyperbolaPy::getAxis(void) const
223
Handle_Geom_Hyperbola c = Handle_Geom_Hyperbola::DownCast
224
(getGeometryPtr()->handle());
225
gp_Dir dir = c->Axis().Direction();
226
return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z()));
229
void HyperbolaPy::setAxis(Py::Object arg)
231
Standard_Real dir_x, dir_y, dir_z;
232
PyObject *p = arg.ptr();
233
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
234
Base::Vector3d v = static_cast<Base::VectorPy*>(p)->value();
239
else if (PyTuple_Check(p)) {
240
Py::Tuple tuple(arg);
241
dir_x = (double)Py::Float(tuple.getItem(0));
242
dir_y = (double)Py::Float(tuple.getItem(1));
243
dir_z = (double)Py::Float(tuple.getItem(2));
246
std::string error = std::string("type must be 'Vector' or tuple, not ");
247
error += p->ob_type->tp_name;
248
throw Py::TypeError(error);
252
Handle_Geom_Hyperbola this_curv = Handle_Geom_Hyperbola::DownCast
253
(this->getGeometryPtr()->handle());
255
axis.SetLocation(this_curv->Location());
256
axis.SetDirection(gp_Dir(dir_x, dir_y, dir_z));
257
gp_Dir dir = axis.Direction();
258
this_curv->SetAxis(axis);
260
catch (Standard_Failure) {
261
throw Py::Exception("cannot set axis");
265
PyObject *HyperbolaPy::getCustomAttributes(const char* /*attr*/) const
270
int HyperbolaPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)