implement Hyperbola2d and ArcOfHyperbola2d

This commit is contained in:
wmayer 2016-11-25 17:50:52 +01:00
parent 3067bd6a85
commit ffa942486a
4 changed files with 79 additions and 245 deletions

View File

@ -14,7 +14,6 @@
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" /> <Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
<UserDocu>Describes a portion of an hyperbola</UserDocu> <UserDocu>Describes a portion of an hyperbola</UserDocu>
</Documentation> </Documentation>
<!--
<Attribute Name="MajorRadius" ReadOnly="false"> <Attribute Name="MajorRadius" ReadOnly="false">
<Documentation> <Documentation>
<UserDocu>The major radius of the hyperbola.</UserDocu> <UserDocu>The major radius of the hyperbola.</UserDocu>
@ -33,6 +32,5 @@
</Documentation> </Documentation>
<Parameter Name="Hyperbola" Type="Object"/> <Parameter Name="Hyperbola" Type="Object"/>
</Attribute> </Attribute>
-->
</PythonExport> </PythonExport>
</GenerateModel> </GenerateModel>

View File

@ -23,21 +23,20 @@
#include "PreCompiled.h" #include "PreCompiled.h"
#ifndef _PreComp_ #ifndef _PreComp_
# include <gp_Hypr.hxx> # include <gp_Hypr2d.hxx>
# include <Geom_Hyperbola.hxx> # include <Geom2d_Hyperbola.hxx>
# include <GC_MakeArcOfHyperbola.hxx> # include <GCE2d_MakeArcOfHyperbola.hxx>
# include <GC_MakeHyperbola.hxx> # include <GCE2d_MakeHyperbola.hxx>
# include <Geom_TrimmedCurve.hxx> # include <Geom2d_TrimmedCurve.hxx>
#endif #endif
#include <Mod/Part/App/Geometry2d.h> #include <Mod/Part/App/Geometry2d.h>
#include <Mod/Part/App/Geom2d/ArcOfHyperbola2dPy.h> #include <Mod/Part/App/Geom2d/ArcOfHyperbola2dPy.h>
#include <Mod/Part/App/Geom2d/ArcOfHyperbola2dPy.cpp> #include <Mod/Part/App/Geom2d/ArcOfHyperbola2dPy.cpp>
#include <Mod/Part/App/HyperbolaPy.h> #include <Mod/Part/App/Geom2d/Hyperbola2dPy.h>
#include <Mod/Part/App/OCCError.h> #include <Mod/Part/App/OCCError.h>
#include <Base/GeometryPyCXX.h> #include <Base/GeometryPyCXX.h>
#include <Base/VectorPy.h>
using namespace Part; using namespace Part;
@ -46,41 +45,7 @@ extern const char* gce_ErrorStatusText(gce_ErrorType et);
// returns a string which represents the object e.g. when printed in python // returns a string which represents the object e.g. when printed in python
std::string ArcOfHyperbola2dPy::representation(void) const std::string ArcOfHyperbola2dPy::representation(void) const
{ {
#if 0 return "<ArcOfHyperbola2d object>";
Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast
(getGeomArcOfHyperbolaPtr()->handle());
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(trim->BasisCurve());
gp_Ax1 axis = hyperbola->Axis();
gp_Dir dir = axis.Direction();
gp_Pnt loc = axis.Location();
Standard_Real fMajRad = hyperbola->MajorRadius();
Standard_Real fMinRad = hyperbola->MinorRadius();
Standard_Real u1 = trim->FirstParameter();
Standard_Real u2 = trim->LastParameter();
gp_Dir normal = hyperbola->Axis().Direction();
gp_Dir xdir = hyperbola->XAxis().Direction();
gp_Ax2 xdirref(loc, normal); // this is a reference XY for the hyperbola
Standard_Real fAngleXU = -xdir.AngleWithRef(xdirref.XDirection(),normal);
std::stringstream str;
str << "ArcOfHyperbola (";
str << "MajorRadius : " << fMajRad << ", ";
str << "MinorRadius : " << fMinRad << ", ";
str << "AngleXU : " << fAngleXU << ", ";
str << "Position : (" << loc.X() << ", "<< loc.Y() << ", "<< loc.Z() << "), ";
str << "Direction : (" << dir.X() << ", "<< dir.Y() << ", "<< dir.Z() << "), ";
str << "Parameter : (" << u1 << ", " << u2 << ")";
str << ")";
return str.str();
#else
return "";
#endif
} }
PyObject *ArcOfHyperbola2dPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper PyObject *ArcOfHyperbola2dPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
@ -92,23 +57,20 @@ PyObject *ArcOfHyperbola2dPy::PyMake(struct _typeobject *, PyObject *, PyObject
// constructor method // constructor method
int ArcOfHyperbola2dPy::PyInit(PyObject* args, PyObject* /*kwds*/) int ArcOfHyperbola2dPy::PyInit(PyObject* args, PyObject* /*kwds*/)
{ {
#if 1
return 0;
#else
PyObject* o; PyObject* o;
double u1, u2; double u1, u2;
PyObject *sense=Py_True; PyObject *sense=Py_True;
if (PyArg_ParseTuple(args, "O!dd|O!", &(Part::HyperbolaPy::Type), &o, &u1, &u2, &PyBool_Type, &sense)) { if (PyArg_ParseTuple(args, "O!dd|O!", &(Part::Hyperbola2dPy::Type), &o, &u1, &u2, &PyBool_Type, &sense)) {
try { try {
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast Handle_Geom2d_Hyperbola hyperbola = Handle_Geom2d_Hyperbola::DownCast
(static_cast<HyperbolaPy*>(o)->getGeomHyperbolaPtr()->handle()); (static_cast<Hyperbola2dPy*>(o)->getGeom2dHyperbolaPtr()->handle());
GC_MakeArcOfHyperbola arc(hyperbola->Hypr(), u1, u2, PyObject_IsTrue(sense) ? Standard_True : Standard_False); GCE2d_MakeArcOfHyperbola arc(hyperbola->Hypr2d(), u1, u2, PyObject_IsTrue(sense) ? Standard_True : Standard_False);
if (!arc.IsDone()) { if (!arc.IsDone()) {
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(arc.Status())); PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(arc.Status()));
return -1; return -1;
} }
getGeomArcOfHyperbolaPtr()->setHandle(arc.Value()); getGeom2dArcOfHyperbolaPtr()->setHandle(arc.Value());
return 0; return 0;
} }
catch (Standard_Failure) { catch (Standard_Failure) {
@ -126,37 +88,36 @@ int ArcOfHyperbola2dPy::PyInit(PyObject* args, PyObject* /*kwds*/)
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"ArcOfHyperbola constructor expects an hyperbola curve and a parameter range"); "ArcOfHyperbola constructor expects an hyperbola curve and a parameter range");
return -1; return -1;
#endif
} }
#if 0
Py::Float ArcOfHyperbola2dPy::getMajorRadius(void) const Py::Float ArcOfHyperbola2dPy::getMajorRadius(void) const
{ {
return Py::Float(getGeomArcOfHyperbolaPtr()->getMajorRadius()); return Py::Float(getGeom2dArcOfHyperbolaPtr()->getMajorRadius());
} }
void ArcOfHyperbola2dPy::setMajorRadius(Py::Float arg) void ArcOfHyperbola2dPy::setMajorRadius(Py::Float arg)
{ {
getGeomArcOfHyperbolaPtr()->setMajorRadius((double)arg); getGeom2dArcOfHyperbolaPtr()->setMajorRadius((double)arg);
} }
Py::Float ArcOfHyperbola2dPy::getMinorRadius(void) const Py::Float ArcOfHyperbola2dPy::getMinorRadius(void) const
{ {
return Py::Float(getGeomArcOfHyperbolaPtr()->getMinorRadius()); return Py::Float(getGeom2dArcOfHyperbolaPtr()->getMinorRadius());
} }
void ArcOfHyperbola2dPy::setMinorRadius(Py::Float arg) void ArcOfHyperbola2dPy::setMinorRadius(Py::Float arg)
{ {
getGeomArcOfHyperbolaPtr()->setMinorRadius((double)arg); getGeom2dArcOfHyperbolaPtr()->setMinorRadius((double)arg);
} }
Py::Object ArcOfHyperbola2dPy::getHyperbola(void) const Py::Object ArcOfHyperbola2dPy::getHyperbola(void) const
{ {
Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast Handle_Geom2d_TrimmedCurve trim = Handle_Geom2d_TrimmedCurve::DownCast
(getGeomArcOfHyperbolaPtr()->handle()); (getGeom2dArcOfHyperbolaPtr()->handle());
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(trim->BasisCurve()); Handle_Geom2d_Hyperbola hyperbola = Handle_Geom2d_Hyperbola::DownCast(trim->BasisCurve());
return Py::Object(new HyperbolaPy(new GeomHyperbola(hyperbola)), true); return Py::asObject(new Hyperbola2dPy(new Geom2dHyperbola(hyperbola)));
} }
#endif
PyObject *ArcOfHyperbola2dPy::getCustomAttributes(const char* ) const PyObject *ArcOfHyperbola2dPy::getCustomAttributes(const char* ) const
{ {
return 0; return 0;

View File

@ -12,29 +12,26 @@
Constructor="true"> Constructor="true">
<Documentation> <Documentation>
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" /> <Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
<UserDocu>Describes an hyperbola in 3D space <UserDocu>Describes a hyperbola in 2D space
To create an hyperbola there are several ways: To create a hyperbola there are several ways:
Part.Hyperbola() Part.Hyperbola()
Creates an hyperbola with major radius 2 and minor radius 1 with the Creates a hyperbola with major radius 2 and minor radius 1 with the
center in (0,0,0) center in (0,0)
Part.Hyperbola(Hyperbola) Part.Hyperbola(Hyperbola)
Create a copy of the given hyperbola Create a copy of the given hyperbola
Part.Hyperbola(S1,S2,Center) Part.Hyperbola(S1,S2,Center)
Creates an hyperbola centered on the point Center, where Creates a hyperbola centered on the point Center, S1 and S2,
the plane of the hyperbola is defined by Center, S1 and S2,
its major axis is defined by Center and S1, its major axis is defined by Center and S1,
its major radius is the distance between Center and S1, and its major radius is the distance between Center and S1, and
its minor radius is the distance between S2 and the major axis. its minor radius is the distance between S2 and the major axis.
Part.Hyperbola(Center,MajorRadius,MinorRadius) Part.Hyperbola(Center,MajorRadius,MinorRadius)
Creates an hyperbola with major and minor radii MajorRadius and Creates a hyperbola with major and minor radii MajorRadius and
MinorRadius, and located in the plane defined by Center and MinorRadius and located at Center
the normal (0,0,1)
</UserDocu> </UserDocu>
</Documentation> </Documentation>
<!--
<Attribute Name="MajorRadius" ReadOnly="false"> <Attribute Name="MajorRadius" ReadOnly="false">
<Documentation> <Documentation>
<UserDocu>The major radius of the hyperbola.</UserDocu> <UserDocu>The major radius of the hyperbola.</UserDocu>
@ -47,18 +44,6 @@
</Documentation> </Documentation>
<Parameter Name="MinorRadius" Type="Float"/> <Parameter Name="MinorRadius" Type="Float"/>
</Attribute> </Attribute>
<Attribute Name="AngleXU" ReadOnly="false">
<Documentation>
<UserDocu>The angle between the X axis and the major axis of the hyperbola.</UserDocu>
</Documentation>
<Parameter Name="AngleXU" Type="Float"/>
</Attribute>
<Attribute Name="Eccentricity" ReadOnly="true">
<Documentation>
<UserDocu>The eccentricity of the hyperbola.</UserDocu>
</Documentation>
<Parameter Name="Eccentricity" Type="Float"/>
</Attribute>
<Attribute Name="Focal" ReadOnly="true"> <Attribute Name="Focal" ReadOnly="true">
<Documentation> <Documentation>
<UserDocu>The focal distance of the hyperbola.</UserDocu> <UserDocu>The focal distance of the hyperbola.</UserDocu>
@ -82,18 +67,5 @@ the second focus is on the negative side.
</Documentation> </Documentation>
<Parameter Name="Focus2" Type="Object"/> <Parameter Name="Focus2" Type="Object"/>
</Attribute> </Attribute>
<Attribute Name="Center" ReadOnly="false">
<Documentation>
<UserDocu>Center of the hyperbola.</UserDocu>
</Documentation>
<Parameter Name="Center" Type="Object"/>
</Attribute>
<Attribute Name="Axis" ReadOnly="false">
<Documentation>
<UserDocu>The axis direction of the hyperbola</UserDocu>
</Documentation>
<Parameter Name="Axis" Type="Object"/>
</Attribute>
-->
</PythonExport> </PythonExport>
</GenerateModel> </GenerateModel>

View File

@ -23,13 +23,12 @@
#include "PreCompiled.h" #include "PreCompiled.h"
#ifndef _PreComp_ #ifndef _PreComp_
# include <gp_Hypr.hxx> # include <gp_Hypr2d.hxx>
# include <Geom_Hyperbola.hxx> # include <Geom2d_Hyperbola.hxx>
# include <GC_MakeHyperbola.hxx> # include <GCE2d_MakeHyperbola.hxx>
#endif #endif
#include <Base/GeometryPyCXX.h> #include <Base/GeometryPyCXX.h>
#include <Base/VectorPy.h>
#include <Mod/Part/App/OCCError.h> #include <Mod/Part/App/OCCError.h>
#include <Mod/Part/App/Geometry2d.h> #include <Mod/Part/App/Geometry2d.h>
@ -55,11 +54,9 @@ PyObject *Hyperbola2dPy::PyMake(struct _typeobject *, PyObject *, PyObject *) /
// constructor method // constructor method
int Hyperbola2dPy::PyInit(PyObject* args, PyObject* kwds) int Hyperbola2dPy::PyInit(PyObject* args, PyObject* kwds)
{ {
return 0;
#if 0
char* keywords_n[] = {NULL}; char* keywords_n[] = {NULL};
if (PyArg_ParseTupleAndKeywords(args, kwds, "", keywords_n)) { if (PyArg_ParseTupleAndKeywords(args, kwds, "", keywords_n)) {
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle()); Handle_Geom2d_Hyperbola hyperbola = Handle_Geom2d_Hyperbola::DownCast(getGeom2dHyperbolaPtr()->handle());
hyperbola->SetMajorRadius(2.0); hyperbola->SetMajorRadius(2.0);
hyperbola->SetMinorRadius(1.0); hyperbola->SetMinorRadius(1.0);
return 0; return 0;
@ -70,11 +67,11 @@ int Hyperbola2dPy::PyInit(PyObject* args, PyObject* kwds)
PyObject *pHypr; PyObject *pHypr;
if (PyArg_ParseTupleAndKeywords(args, kwds, "O!",keywords_e, &(Hyperbola2dPy::Type), &pHypr)) { if (PyArg_ParseTupleAndKeywords(args, kwds, "O!",keywords_e, &(Hyperbola2dPy::Type), &pHypr)) {
Hyperbola2dPy* pHyperbola = static_cast<Hyperbola2dPy*>(pHypr); Hyperbola2dPy* pHyperbola = static_cast<Hyperbola2dPy*>(pHypr);
Handle_Geom_Hyperbola Hypr1 = Handle_Geom_Hyperbola::DownCast Handle_Geom2d_Hyperbola Hypr1 = Handle_Geom2d_Hyperbola::DownCast
(pHyperbola->getGeomHyperbolaPtr()->handle()); (pHyperbola->getGeom2dHyperbolaPtr()->handle());
Handle_Geom_Hyperbola Hypr2 = Handle_Geom_Hyperbola::DownCast Handle_Geom2d_Hyperbola Hypr2 = Handle_Geom2d_Hyperbola::DownCast
(this->getGeomHyperbolaPtr()->handle()); (this->getGeom2dHyperbolaPtr()->handle());
Hypr2->SetHypr(Hypr1->Hypr()); Hypr2->SetHypr2d(Hypr1->Hypr2d());
return 0; return 0;
} }
@ -82,22 +79,22 @@ int Hyperbola2dPy::PyInit(PyObject* args, PyObject* kwds)
PyErr_Clear(); PyErr_Clear();
PyObject *pV1, *pV2, *pV3; PyObject *pV1, *pV2, *pV3;
if (PyArg_ParseTupleAndKeywords(args, kwds, "O!O!O!", keywords_ssc, if (PyArg_ParseTupleAndKeywords(args, kwds, "O!O!O!", keywords_ssc,
&(Base::VectorPy::Type), &pV1, Base::Vector2dPy::type_object(), &pV1,
&(Base::VectorPy::Type), &pV2, Base::Vector2dPy::type_object(), &pV2,
&(Base::VectorPy::Type), &pV3)) { Base::Vector2dPy::type_object(), &pV3)) {
Base::Vector3d v1 = static_cast<Base::VectorPy*>(pV1)->value(); Base::Vector2d v1 = Py::Vector2d(pV1).getCxxObject()->value();
Base::Vector3d v2 = static_cast<Base::VectorPy*>(pV2)->value(); Base::Vector2d v2 = Py::Vector2d(pV2).getCxxObject()->value();
Base::Vector3d v3 = static_cast<Base::VectorPy*>(pV3)->value(); Base::Vector2d v3 = Py::Vector2d(pV3).getCxxObject()->value();
GC_MakeHyperbola me(gp_Pnt(v1.x,v1.y,v1.z), GCE2d_MakeHyperbola me(gp_Pnt2d(v1.x,v1.y),
gp_Pnt(v2.x,v2.y,v2.z), gp_Pnt2d(v2.x,v2.y),
gp_Pnt(v3.x,v3.y,v3.z)); gp_Pnt2d(v3.x,v3.y));
if (!me.IsDone()) { if (!me.IsDone()) {
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(me.Status())); PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(me.Status()));
return -1; return -1;
} }
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle()); Handle_Geom2d_Hyperbola hyperbola = Handle_Geom2d_Hyperbola::DownCast(getGeom2dHyperbolaPtr()->handle());
hyperbola->SetHypr(me.Value()->Hypr()); hyperbola->SetHypr2d(me.Value()->Hypr2d());
return 0; return 0;
} }
@ -106,18 +103,18 @@ int Hyperbola2dPy::PyInit(PyObject* args, PyObject* kwds)
PyObject *pV; PyObject *pV;
double major, minor; double major, minor;
if (PyArg_ParseTupleAndKeywords(args, kwds, "O!dd", keywords_cmm, if (PyArg_ParseTupleAndKeywords(args, kwds, "O!dd", keywords_cmm,
&(Base::VectorPy::Type), &pV, Base::Vector2dPy::type_object(), &pV,
&major, &minor)) { &major, &minor)) {
Base::Vector3d c = static_cast<Base::VectorPy*>(pV)->value(); Base::Vector2d c = Py::Vector2d(pV).getCxxObject()->value();;
GC_MakeHyperbola me(gp_Ax2(gp_Pnt(c.x,c.y,c.z), gp_Dir(0.0,0.0,1.0)), GCE2d_MakeHyperbola me(gp_Ax2d(gp_Pnt2d(c.x,c.y), gp_Dir2d(0.0,1.0)),
major, minor); major, minor);
if (!me.IsDone()) { if (!me.IsDone()) {
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(me.Status())); PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(me.Status()));
return -1; return -1;
} }
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle()); Handle_Geom2d_Hyperbola hyperbola = Handle_Geom2d_Hyperbola::DownCast(getGeom2dHyperbolaPtr()->handle());
hyperbola->SetHypr(me.Value()->Hypr()); hyperbola->SetHypr2d(me.Value()->Hypr2d());
return 0; return 0;
} }
@ -127,158 +124,64 @@ int Hyperbola2dPy::PyInit(PyObject* args, PyObject* kwds)
"-- Point, double, double\n" "-- Point, double, double\n"
"-- Point, Point, Point"); "-- Point, Point, Point");
return -1; return -1;
#endif
} }
#if 0
Py::Float Hyperbola2dPy::getMajorRadius(void) const Py::Float Hyperbola2dPy::getMajorRadius(void) const
{ {
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle()); Handle_Geom2d_Hyperbola hyperbola = Handle_Geom2d_Hyperbola::DownCast(getGeom2dHyperbolaPtr()->handle());
return Py::Float(hyperbola->MajorRadius()); return Py::Float(hyperbola->MajorRadius());
} }
void Hyperbola2dPy::setMajorRadius(Py::Float arg) void Hyperbola2dPy::setMajorRadius(Py::Float arg)
{ {
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle()); Handle_Geom2d_Hyperbola hyperbola = Handle_Geom2d_Hyperbola::DownCast(getGeom2dHyperbolaPtr()->handle());
hyperbola->SetMajorRadius((double)arg); hyperbola->SetMajorRadius((double)arg);
} }
Py::Float Hyperbola2dPy::getMinorRadius(void) const Py::Float Hyperbola2dPy::getMinorRadius(void) const
{ {
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle()); Handle_Geom2d_Hyperbola hyperbola = Handle_Geom2d_Hyperbola::DownCast(getGeom2dHyperbolaPtr()->handle());
return Py::Float(hyperbola->MinorRadius()); return Py::Float(hyperbola->MinorRadius());
} }
void Hyperbola2dPy::setMinorRadius(Py::Float arg) void Hyperbola2dPy::setMinorRadius(Py::Float arg)
{ {
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle()); Handle_Geom2d_Hyperbola hyperbola = Handle_Geom2d_Hyperbola::DownCast(getGeom2dHyperbolaPtr()->handle());
hyperbola->SetMinorRadius((double)arg); hyperbola->SetMinorRadius((double)arg);
} }
Py::Float Hyperbola2dPy::getAngleXU(void) const
{
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
gp_Pnt center = hyperbola->Axis().Location();
gp_Dir normal = hyperbola->Axis().Direction();
gp_Dir xdir = hyperbola->XAxis().Direction();
gp_Ax2 xdirref(center, normal); // this is a reference system, might be CCW or CW depending on the creation method
return Py::Float(-xdir.AngleWithRef(xdirref.XDirection(),normal));
}
void Hyperbola2dPy::setAngleXU(Py::Float arg)
{
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
gp_Pnt center = hyperbola->Axis().Location();
gp_Dir normal = hyperbola->Axis().Direction();
gp_Ax1 normaxis(center, normal);
gp_Ax2 xdirref(center, normal);
xdirref.Rotate(normaxis,arg);
hyperbola->SetPosition(xdirref);
}
Py::Float Hyperbola2dPy::getEccentricity(void) const
{
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
return Py::Float(hyperbola->Eccentricity());
}
Py::Float Hyperbola2dPy::getFocal(void) const Py::Float Hyperbola2dPy::getFocal(void) const
{ {
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle()); Handle_Geom2d_Hyperbola hyperbola = Handle_Geom2d_Hyperbola::DownCast(getGeom2dHyperbolaPtr()->handle());
return Py::Float(hyperbola->Focal()); return Py::Float(hyperbola->Focal());
} }
Py::Object Hyperbola2dPy::getFocus1(void) const Py::Object Hyperbola2dPy::getFocus1(void) const
{ {
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle()); Handle_Geom2d_Hyperbola hyperbola = Handle_Geom2d_Hyperbola::DownCast(getGeom2dHyperbolaPtr()->handle());
gp_Pnt loc = hyperbola->Focus1(); gp_Pnt2d loc = hyperbola->Focus1();
return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
arg.setItem(0, Py::Float(loc.X()));
arg.setItem(1, Py::Float(loc.Y()));
return method.apply(arg);
} }
Py::Object Hyperbola2dPy::getFocus2(void) const Py::Object Hyperbola2dPy::getFocus2(void) const
{ {
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle()); Handle_Geom2d_Hyperbola hyperbola = Handle_Geom2d_Hyperbola::DownCast(getGeom2dHyperbolaPtr()->handle());
gp_Pnt loc = hyperbola->Focus2(); gp_Pnt2d loc = hyperbola->Focus2();
return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
arg.setItem(0, Py::Float(loc.X()));
arg.setItem(1, Py::Float(loc.Y()));
return method.apply(arg);
} }
Py::Object Hyperbola2dPy::getCenter(void) const
{
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
gp_Pnt loc = hyperbola->Location();
return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
}
void Hyperbola2dPy::setCenter(Py::Object arg)
{
PyObject* p = arg.ptr();
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
Base::Vector3d loc = static_cast<Base::VectorPy*>(p)->value();
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
hyperbola->SetLocation(gp_Pnt(loc.x, loc.y, loc.z));
}
else if (PyTuple_Check(p)) {
Py::Tuple tuple(arg);
gp_Pnt loc;
loc.SetX((double)Py::Float(tuple.getItem(0)));
loc.SetY((double)Py::Float(tuple.getItem(1)));
loc.SetZ((double)Py::Float(tuple.getItem(2)));
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
hyperbola->SetLocation(loc);
}
else {
std::string error = std::string("type must be 'Vector', not ");
error += p->ob_type->tp_name;
throw Py::TypeError(error);
}
}
Py::Object Hyperbola2dPy::getAxis(void) const
{
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
gp_Ax1 axis = hyperbola->Axis();
gp_Dir dir = axis.Direction();
return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z()));
}
void Hyperbola2dPy::setAxis(Py::Object arg)
{
PyObject* p = arg.ptr();
Base::Vector3d val;
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
val = static_cast<Base::VectorPy*>(p)->value();
}
else if (PyTuple_Check(p)) {
val = Base::getVectorFromTuple<double>(p);
}
else {
std::string error = std::string("type must be 'Vector', not ");
error += p->ob_type->tp_name;
throw Py::TypeError(error);
}
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
try {
gp_Ax1 axis;
axis.SetLocation(hyperbola->Location());
axis.SetDirection(gp_Dir(val.x, val.y, val.z));
hyperbola->SetAxis(axis);
}
catch (Standard_Failure) {
throw Py::Exception("cannot set axis");
}
}
#endif
PyObject *Hyperbola2dPy::getCustomAttributes(const char* /*attr*/) const PyObject *Hyperbola2dPy::getCustomAttributes(const char* /*attr*/) const
{ {
return 0; return 0;