1
/***************************************************************************
2
* Copyright (c) 2014 Abdullah Tahiri <abdullah.tahiri.yo@gmail.com> *
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_MakeArcOfHyperbola.hxx>
26
# include <Geom_Hyperbola.hxx>
27
# include <Geom_TrimmedCurve.hxx>
30
#include "ArcOfHyperbolaPy.h"
31
#include "ArcOfHyperbolaPy.cpp"
32
#include "HyperbolaPy.h"
38
extern const char* gce_ErrorStatusText(gce_ErrorType et);
40
// returns a string which represents the object e.g. when printed in python
41
std::string ArcOfHyperbolaPy::representation() const
43
Handle(Geom_TrimmedCurve) trim = Handle(Geom_TrimmedCurve)::DownCast
44
(getGeomArcOfHyperbolaPtr()->handle());
45
Handle(Geom_Hyperbola) hyperbola = Handle(Geom_Hyperbola)::DownCast(trim->BasisCurve());
47
gp_Ax1 axis = hyperbola->Axis();
48
gp_Dir dir = axis.Direction();
49
gp_Pnt loc = axis.Location();
50
Standard_Real fMajRad = hyperbola->MajorRadius();
51
Standard_Real fMinRad = hyperbola->MinorRadius();
52
Standard_Real u1 = trim->FirstParameter();
53
Standard_Real u2 = trim->LastParameter();
55
gp_Dir normal = hyperbola->Axis().Direction();
56
gp_Dir xdir = hyperbola->XAxis().Direction();
58
gp_Ax2 xdirref(loc, normal); // this is a reference XY for the hyperbola
60
Standard_Real fAngleXU = -xdir.AngleWithRef(xdirref.XDirection(),normal);
63
std::stringstream str;
64
str << "ArcOfHyperbola (";
65
str << "MajorRadius : " << fMajRad << ", ";
66
str << "MinorRadius : " << fMinRad << ", ";
67
str << "AngleXU : " << fAngleXU << ", ";
68
str << "Position : (" << loc.X() << ", "<< loc.Y() << ", "<< loc.Z() << "), ";
69
str << "Direction : (" << dir.X() << ", "<< dir.Y() << ", "<< dir.Z() << "), ";
70
str << "Parameter : (" << u1 << ", " << u2 << ")";
76
PyObject *ArcOfHyperbolaPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
78
// create a new instance of ArcOfHyperbolaPy and the Twin object
79
return new ArcOfHyperbolaPy(new GeomArcOfHyperbola);
83
int ArcOfHyperbolaPy::PyInit(PyObject* args, PyObject* /*kwds*/)
87
PyObject *sense=Py_True;
88
if (PyArg_ParseTuple(args, "O!dd|O!", &(Part::HyperbolaPy::Type), &o, &u1, &u2, &PyBool_Type, &sense)) {
90
Handle(Geom_Hyperbola) hyperbola = Handle(Geom_Hyperbola)::DownCast
91
(static_cast<HyperbolaPy*>(o)->getGeomHyperbolaPtr()->handle());
92
GC_MakeArcOfHyperbola arc(hyperbola->Hypr(), u1, u2, Base::asBoolean(sense));
94
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(arc.Status()));
98
getGeomArcOfHyperbolaPtr()->setHandle(arc.Value());
101
catch (Standard_Failure& e) {
102
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
106
PyErr_SetString(PartExceptionOCCError, "creation of arc failed");
112
PyErr_SetString(PyExc_TypeError,
113
"ArcOfHyperbola constructor expects an hyperbola curve and a parameter range");
117
Py::Float ArcOfHyperbolaPy::getMajorRadius() const
119
return Py::Float(getGeomArcOfHyperbolaPtr()->getMajorRadius());
122
void ArcOfHyperbolaPy::setMajorRadius(Py::Float arg)
124
getGeomArcOfHyperbolaPtr()->setMajorRadius((double)arg);
127
Py::Float ArcOfHyperbolaPy::getMinorRadius() const
129
return Py::Float(getGeomArcOfHyperbolaPtr()->getMinorRadius());
132
void ArcOfHyperbolaPy::setMinorRadius(Py::Float arg)
134
getGeomArcOfHyperbolaPtr()->setMinorRadius((double)arg);
137
Py::Object ArcOfHyperbolaPy::getHyperbola() const
139
Handle(Geom_TrimmedCurve) trim = Handle(Geom_TrimmedCurve)::DownCast
140
(getGeomArcOfHyperbolaPtr()->handle());
141
Handle(Geom_Hyperbola) hyperbola = Handle(Geom_Hyperbola)::DownCast(trim->BasisCurve());
142
return Py::Object(new HyperbolaPy(new GeomHyperbola(hyperbola)), true);
145
PyObject *ArcOfHyperbolaPy::getCustomAttributes(const char* ) const
150
int ArcOfHyperbolaPy::setCustomAttributes(const char* , PyObject *)