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_MakeHyperbola.hxx>
26
# include <Geom_Hyperbola.hxx>
29
#include <Base/GeometryPyCXX.h>
30
#include <Base/PyWrapParseTupleAndKeywords.h>
31
#include <Base/VectorPy.h>
33
#include "HyperbolaPy.h"
34
#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
std::string HyperbolaPy::representation() 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
static const std::array<const char *, 1> keywords_n {nullptr};
58
if (Base::Wrapped_ParseTupleAndKeywords(args, kwds, "", keywords_n)) {
59
Handle(Geom_Hyperbola) hyperbola = Handle(Geom_Hyperbola)::DownCast(getGeomHyperbolaPtr()->handle());
60
hyperbola->SetMajorRadius(2.0);
61
hyperbola->SetMinorRadius(1.0);
65
static const std::array<const char *, 2> keywords_e {"Hyperbola", nullptr};
68
if (Base::Wrapped_ParseTupleAndKeywords(args, kwds, "O!",keywords_e, &(HyperbolaPy::Type), &pHypr)) {
69
HyperbolaPy* pHyperbola = static_cast<HyperbolaPy*>(pHypr);
70
Handle(Geom_Hyperbola) Hypr1 = Handle(Geom_Hyperbola)::DownCast
71
(pHyperbola->getGeomHyperbolaPtr()->handle());
72
Handle(Geom_Hyperbola) Hypr2 = Handle(Geom_Hyperbola)::DownCast
73
(this->getGeomHyperbolaPtr()->handle());
74
Hypr2->SetHypr(Hypr1->Hypr());
78
static const std::array<const char *, 4> keywords_ssc{"S1", "S2", "Center", nullptr};
80
PyObject *pV1, *pV2, *pV3;
81
if (Base::Wrapped_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 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(PartExceptionOCCError, gce_ErrorStatusText(me.Status()));
96
Handle(Geom_Hyperbola) hyperbola = Handle(Geom_Hyperbola)::DownCast(getGeomHyperbolaPtr()->handle());
97
hyperbola->SetHypr(me.Value()->Hypr());
101
static const std::array<const char *, 4> keywords_cmm {"Center","MajorRadius","MinorRadius",nullptr};
105
if (Base::Wrapped_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 me(gp_Ax2(gp_Pnt(c.x,c.y,c.z), gp_Dir(0.0,0.0,1.0)),
112
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(me.Status()));
116
Handle(Geom_Hyperbola) hyperbola = Handle(Geom_Hyperbola)::DownCast(getGeomHyperbolaPtr()->handle());
117
hyperbola->SetHypr(me.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::getMajorRadius() const
131
Handle(Geom_Hyperbola) hyperbola = Handle(Geom_Hyperbola)::DownCast(getGeomHyperbolaPtr()->handle());
132
return Py::Float(hyperbola->MajorRadius());
135
void HyperbolaPy::setMajorRadius(Py::Float arg)
137
Handle(Geom_Hyperbola) hyperbola = Handle(Geom_Hyperbola)::DownCast(getGeomHyperbolaPtr()->handle());
138
hyperbola->SetMajorRadius((double)arg);
141
Py::Float HyperbolaPy::getMinorRadius() const
143
Handle(Geom_Hyperbola) hyperbola = Handle(Geom_Hyperbola)::DownCast(getGeomHyperbolaPtr()->handle());
144
return Py::Float(hyperbola->MinorRadius());
147
void HyperbolaPy::setMinorRadius(Py::Float arg)
149
Handle(Geom_Hyperbola) hyperbola = Handle(Geom_Hyperbola)::DownCast(getGeomHyperbolaPtr()->handle());
150
hyperbola->SetMinorRadius((double)arg);
153
Py::Float HyperbolaPy::getFocal() const
155
Handle(Geom_Hyperbola) hyperbola = Handle(Geom_Hyperbola)::DownCast(getGeomHyperbolaPtr()->handle());
156
return Py::Float(hyperbola->Focal());
159
Py::Object HyperbolaPy::getFocus1() const
161
Handle(Geom_Hyperbola) hyperbola = Handle(Geom_Hyperbola)::DownCast(getGeomHyperbolaPtr()->handle());
162
gp_Pnt loc = hyperbola->Focus1();
163
return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
166
Py::Object HyperbolaPy::getFocus2() const
168
Handle(Geom_Hyperbola) hyperbola = Handle(Geom_Hyperbola)::DownCast(getGeomHyperbolaPtr()->handle());
169
gp_Pnt loc = hyperbola->Focus2();
170
return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
173
PyObject *HyperbolaPy::getCustomAttributes(const char* /*attr*/) const
178
int HyperbolaPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)