Skip to content

Commit

Permalink
implement Hyperbola2d and ArcOfHyperbola2d
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Nov 25, 2016
1 parent 3067bd6 commit ffa9424
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 244 deletions.
2 changes: 0 additions & 2 deletions src/Mod/Part/App/Geom2d/ArcOfHyperbola2dPy.xml
Expand Up @@ -14,7 +14,6 @@
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
<UserDocu>Describes a portion of an hyperbola</UserDocu>
</Documentation>
<!--
<Attribute Name="MajorRadius" ReadOnly="false">
<Documentation>
<UserDocu>The major radius of the hyperbola.</UserDocu>
Expand All @@ -33,6 +32,5 @@
</Documentation>
<Parameter Name="Hyperbola" Type="Object"/>
</Attribute>
-->
</PythonExport>
</GenerateModel>
83 changes: 22 additions & 61 deletions src/Mod/Part/App/Geom2d/ArcOfHyperbola2dPyImp.cpp
Expand Up @@ -23,21 +23,20 @@

#include "PreCompiled.h"
#ifndef _PreComp_
# include <gp_Hypr.hxx>
# include <Geom_Hyperbola.hxx>
# include <GC_MakeArcOfHyperbola.hxx>
# include <GC_MakeHyperbola.hxx>
# include <Geom_TrimmedCurve.hxx>
# include <gp_Hypr2d.hxx>
# include <Geom2d_Hyperbola.hxx>
# include <GCE2d_MakeArcOfHyperbola.hxx>
# include <GCE2d_MakeHyperbola.hxx>
# include <Geom2d_TrimmedCurve.hxx>
#endif

#include <Mod/Part/App/Geometry2d.h>
#include <Mod/Part/App/Geom2d/ArcOfHyperbola2dPy.h>
#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 <Base/GeometryPyCXX.h>
#include <Base/VectorPy.h>

using namespace Part;

Expand All @@ -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
std::string ArcOfHyperbola2dPy::representation(void) const
{
#if 0
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
return "<ArcOfHyperbola2d object>";
}

PyObject *ArcOfHyperbola2dPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
Expand All @@ -92,23 +57,20 @@ PyObject *ArcOfHyperbola2dPy::PyMake(struct _typeobject *, PyObject *, PyObject
// constructor method
int ArcOfHyperbola2dPy::PyInit(PyObject* args, PyObject* /*kwds*/)
{
#if 1
return 0;
#else
PyObject* o;
double u1, u2;
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 {
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast
(static_cast<HyperbolaPy*>(o)->getGeomHyperbolaPtr()->handle());
GC_MakeArcOfHyperbola arc(hyperbola->Hypr(), u1, u2, PyObject_IsTrue(sense) ? Standard_True : Standard_False);
Handle_Geom2d_Hyperbola hyperbola = Handle_Geom2d_Hyperbola::DownCast
(static_cast<Hyperbola2dPy*>(o)->getGeom2dHyperbolaPtr()->handle());
GCE2d_MakeArcOfHyperbola arc(hyperbola->Hypr2d(), u1, u2, PyObject_IsTrue(sense) ? Standard_True : Standard_False);
if (!arc.IsDone()) {
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(arc.Status()));
return -1;
}

getGeomArcOfHyperbolaPtr()->setHandle(arc.Value());
getGeom2dArcOfHyperbolaPtr()->setHandle(arc.Value());
return 0;
}
catch (Standard_Failure) {
Expand All @@ -126,37 +88,36 @@ int ArcOfHyperbola2dPy::PyInit(PyObject* args, PyObject* /*kwds*/)
PyErr_SetString(PyExc_TypeError,
"ArcOfHyperbola constructor expects an hyperbola curve and a parameter range");
return -1;
#endif
}
#if 0

Py::Float ArcOfHyperbola2dPy::getMajorRadius(void) const
{
return Py::Float(getGeomArcOfHyperbolaPtr()->getMajorRadius());
return Py::Float(getGeom2dArcOfHyperbolaPtr()->getMajorRadius());
}

void ArcOfHyperbola2dPy::setMajorRadius(Py::Float arg)
{
getGeomArcOfHyperbolaPtr()->setMajorRadius((double)arg);
getGeom2dArcOfHyperbolaPtr()->setMajorRadius((double)arg);
}

Py::Float ArcOfHyperbola2dPy::getMinorRadius(void) const
{
return Py::Float(getGeomArcOfHyperbolaPtr()->getMinorRadius());
return Py::Float(getGeom2dArcOfHyperbolaPtr()->getMinorRadius());
}

void ArcOfHyperbola2dPy::setMinorRadius(Py::Float arg)
{
getGeomArcOfHyperbolaPtr()->setMinorRadius((double)arg);
getGeom2dArcOfHyperbolaPtr()->setMinorRadius((double)arg);
}

Py::Object ArcOfHyperbola2dPy::getHyperbola(void) const
{
Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast
(getGeomArcOfHyperbolaPtr()->handle());
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(trim->BasisCurve());
return Py::Object(new HyperbolaPy(new GeomHyperbola(hyperbola)), true);
Handle_Geom2d_TrimmedCurve trim = Handle_Geom2d_TrimmedCurve::DownCast
(getGeom2dArcOfHyperbolaPtr()->handle());
Handle_Geom2d_Hyperbola hyperbola = Handle_Geom2d_Hyperbola::DownCast(trim->BasisCurve());
return Py::asObject(new Hyperbola2dPy(new Geom2dHyperbola(hyperbola)));
}
#endif

PyObject *ArcOfHyperbola2dPy::getCustomAttributes(const char* ) const
{
return 0;
Expand Down
42 changes: 7 additions & 35 deletions src/Mod/Part/App/Geom2d/Hyperbola2dPy.xml
Expand Up @@ -12,29 +12,26 @@
Constructor="true">
<Documentation>
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
<UserDocu>Describes an hyperbola in 3D space
To create an hyperbola there are several ways:
<UserDocu>Describes a hyperbola in 2D space
To create a hyperbola there are several ways:
Part.Hyperbola()
Creates an hyperbola with major radius 2 and minor radius 1 with the
center in (0,0,0)
Creates a hyperbola with major radius 2 and minor radius 1 with the
center in (0,0)

Part.Hyperbola(Hyperbola)
Create a copy of the given hyperbola

Part.Hyperbola(S1,S2,Center)
Creates an hyperbola centered on the point Center, where
the plane of the hyperbola is defined by Center, S1 and S2,
Creates a hyperbola centered on the point Center, S1 and S2,
its major axis is defined by Center and S1,
its major radius is the distance between Center and S1, and
its minor radius is the distance between S2 and the major axis.

Part.Hyperbola(Center,MajorRadius,MinorRadius)
Creates an hyperbola with major and minor radii MajorRadius and
MinorRadius, and located in the plane defined by Center and
the normal (0,0,1)
Creates a hyperbola with major and minor radii MajorRadius and
MinorRadius and located at Center
</UserDocu>
</Documentation>
<!--
<Attribute Name="MajorRadius" ReadOnly="false">
<Documentation>
<UserDocu>The major radius of the hyperbola.</UserDocu>
Expand All @@ -47,18 +44,6 @@
</Documentation>
<Parameter Name="MinorRadius" Type="Float"/>
</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">
<Documentation>
<UserDocu>The focal distance of the hyperbola.</UserDocu>
Expand All @@ -82,18 +67,5 @@ the second focus is on the negative side.
</Documentation>
<Parameter Name="Focus2" Type="Object"/>
</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>
</GenerateModel>

0 comments on commit ffa9424

Please sign in to comment.