1
/***************************************************************************
2
* Copyright (c) 2016 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 <GCE2d_MakeHyperbola.hxx>
26
# include <Geom2d_Hyperbola.hxx>
27
# include <gp_Hypr2d.hxx>
30
#include <Base/GeometryPyCXX.h>
31
#include <Base/PyWrapParseTupleAndKeywords.h>
33
#include "Geom2d/Hyperbola2dPy.h"
34
#include "Geom2d/Hyperbola2dPy.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 Hyperbola2dPy::representation() const
45
return "<Hyperbola2d object>";
48
PyObject *Hyperbola2dPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
50
// create a new instance of Hyperbola2dPy and the Twin object
51
return new Hyperbola2dPy(new Geom2dHyperbola);
55
int Hyperbola2dPy::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(Geom2d_Hyperbola) hyperbola = Handle(Geom2d_Hyperbola)::DownCast(getGeom2dHyperbolaPtr()->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, &(Hyperbola2dPy::Type), &pHypr)) {
69
Hyperbola2dPy* pHyperbola = static_cast<Hyperbola2dPy*>(pHypr);
70
Handle(Geom2d_Hyperbola) Hypr1 = Handle(Geom2d_Hyperbola)::DownCast
71
(pHyperbola->getGeom2dHyperbolaPtr()->handle());
72
Handle(Geom2d_Hyperbola) Hypr2 = Handle(Geom2d_Hyperbola)::DownCast
73
(this->getGeom2dHyperbolaPtr()->handle());
74
Hypr2->SetHypr2d(Hypr1->Hypr2d());
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::Vector2dPy::type_object(), &pV1,
83
Base::Vector2dPy::type_object(), &pV2,
84
Base::Vector2dPy::type_object(), &pV3)) {
85
Base::Vector2d v1 = Py::toVector2d(pV1);
86
Base::Vector2d v2 = Py::toVector2d(pV2);
87
Base::Vector2d v3 = Py::toVector2d(pV3);
88
GCE2d_MakeHyperbola me(gp_Pnt2d(v1.x,v1.y),
92
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(me.Status()));
96
Handle(Geom2d_Hyperbola) hyperbola = Handle(Geom2d_Hyperbola)::DownCast(getGeom2dHyperbolaPtr()->handle());
97
hyperbola->SetHypr2d(me.Value()->Hypr2d());
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::Vector2dPy::type_object(), &pV,
108
Base::Vector2d c = Py::toVector2d(pV);
109
GCE2d_MakeHyperbola me(gp_Ax2d(gp_Pnt2d(c.x,c.y), gp_Dir2d(0.0,1.0)),
112
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(me.Status()));
116
Handle(Geom2d_Hyperbola) hyperbola = Handle(Geom2d_Hyperbola)::DownCast(getGeom2dHyperbolaPtr()->handle());
117
hyperbola->SetHypr2d(me.Value()->Hypr2d());
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 Hyperbola2dPy::getMajorRadius() const
131
Handle(Geom2d_Hyperbola) hyperbola = Handle(Geom2d_Hyperbola)::DownCast(getGeom2dHyperbolaPtr()->handle());
132
return Py::Float(hyperbola->MajorRadius());
135
void Hyperbola2dPy::setMajorRadius(Py::Float arg)
137
Handle(Geom2d_Hyperbola) hyperbola = Handle(Geom2d_Hyperbola)::DownCast(getGeom2dHyperbolaPtr()->handle());
138
hyperbola->SetMajorRadius((double)arg);
141
Py::Float Hyperbola2dPy::getMinorRadius() const
143
Handle(Geom2d_Hyperbola) hyperbola = Handle(Geom2d_Hyperbola)::DownCast(getGeom2dHyperbolaPtr()->handle());
144
return Py::Float(hyperbola->MinorRadius());
147
void Hyperbola2dPy::setMinorRadius(Py::Float arg)
149
Handle(Geom2d_Hyperbola) hyperbola = Handle(Geom2d_Hyperbola)::DownCast(getGeom2dHyperbolaPtr()->handle());
150
hyperbola->SetMinorRadius((double)arg);
153
Py::Float Hyperbola2dPy::getFocal() const
155
Handle(Geom2d_Hyperbola) hyperbola = Handle(Geom2d_Hyperbola)::DownCast(getGeom2dHyperbolaPtr()->handle());
156
return Py::Float(hyperbola->Focal());
159
Py::Object Hyperbola2dPy::getFocus1() const
161
Handle(Geom2d_Hyperbola) hyperbola = Handle(Geom2d_Hyperbola)::DownCast(getGeom2dHyperbolaPtr()->handle());
162
gp_Pnt2d loc = hyperbola->Focus1();
163
return Base::Vector2dPy::create(loc.X(), loc.Y());
166
Py::Object Hyperbola2dPy::getFocus2() const
168
Handle(Geom2d_Hyperbola) hyperbola = Handle(Geom2d_Hyperbola)::DownCast(getGeom2dHyperbolaPtr()->handle());
169
gp_Pnt2d loc = hyperbola->Focus2();
170
return Base::Vector2dPy::create(loc.X(), loc.Y());
173
PyObject *Hyperbola2dPy::getCustomAttributes(const char* /*attr*/) const
178
int Hyperbola2dPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)