Part Module New Feature: Hyperbola & ArcOfHyperbola

- Completed Hyperbola c++ implementation and python wrapper
- Created ArOfHyperbola c++ and python wrapper implementation
This commit is contained in:
Abdullah Tahiri
2014-10-16 15:02:21 +02:00
committed by Sebastian Hoogen
parent 6997cc9991
commit 75377ebfd3
10 changed files with 961 additions and 154 deletions

View File

@@ -23,13 +23,13 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <gp_Hypr.hxx>
# include <Geom_Hyperbola.hxx>
# include <GC_MakeHyperbola.hxx>
# include <gp_Hypr.hxx>
#endif
#include <Base/VectorPy.h>
#include <Base/GeometryPyCXX.h>
#include <Base/VectorPy.h>
#include "OCCError.h"
#include "Geometry.h"
@@ -57,9 +57,9 @@ int HyperbolaPy::PyInit(PyObject* args, PyObject* kwds)
{
char* keywords_n[] = {NULL};
if (PyArg_ParseTupleAndKeywords(args, kwds, "", keywords_n)) {
Handle_Geom_Hyperbola hypr = Handle_Geom_Hyperbola::DownCast(getGeometryPtr()->handle());
hypr->SetMajorRadius(2.0);
hypr->SetMinorRadius(1.0);
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
hyperbola->SetMajorRadius(2.0);
hyperbola->SetMinorRadius(1.0);
return 0;
}
@@ -67,11 +67,11 @@ int HyperbolaPy::PyInit(PyObject* args, PyObject* kwds)
PyErr_Clear();
PyObject *pHypr;
if (PyArg_ParseTupleAndKeywords(args, kwds, "O!",keywords_e, &(HyperbolaPy::Type), &pHypr)) {
HyperbolaPy* pH = static_cast<HyperbolaPy*>(pHypr);
HyperbolaPy* pHyperbola = static_cast<HyperbolaPy*>(pHypr);
Handle_Geom_Hyperbola Hypr1 = Handle_Geom_Hyperbola::DownCast
(pH->getGeometryPtr()->handle());
(pHyperbola->getGeomHyperbolaPtr()->handle());
Handle_Geom_Hyperbola Hypr2 = Handle_Geom_Hyperbola::DownCast
(this->getGeometryPtr()->handle());
(this->getGeomHyperbolaPtr()->handle());
Hypr2->SetHypr(Hypr1->Hypr());
return 0;
}
@@ -86,16 +86,16 @@ int HyperbolaPy::PyInit(PyObject* args, PyObject* kwds)
Base::Vector3d v1 = static_cast<Base::VectorPy*>(pV1)->value();
Base::Vector3d v2 = static_cast<Base::VectorPy*>(pV2)->value();
Base::Vector3d v3 = static_cast<Base::VectorPy*>(pV3)->value();
GC_MakeHyperbola mh(gp_Pnt(v1.x,v1.y,v1.z),
gp_Pnt(v2.x,v2.y,v2.z),
gp_Pnt(v3.x,v3.y,v3.z));
if (!mh.IsDone()) {
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(mh.Status()));
GC_MakeHyperbola me(gp_Pnt(v1.x,v1.y,v1.z),
gp_Pnt(v2.x,v2.y,v2.z),
gp_Pnt(v3.x,v3.y,v3.z));
if (!me.IsDone()) {
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(me.Status()));
return -1;
}
Handle_Geom_Hyperbola hyperb = Handle_Geom_Hyperbola::DownCast(getGeometryPtr()->handle());
hyperb->SetHypr(mh.Value()->Hypr());
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
hyperbola->SetHypr(me.Value()->Hypr());
return 0;
}
@@ -107,15 +107,15 @@ int HyperbolaPy::PyInit(PyObject* args, PyObject* kwds)
&(Base::VectorPy::Type), &pV,
&major, &minor)) {
Base::Vector3d c = static_cast<Base::VectorPy*>(pV)->value();
GC_MakeHyperbola mh(gp_Ax2(gp_Pnt(c.x,c.y,c.z), gp_Dir(0.0,0.0,1.0)),
GC_MakeHyperbola me(gp_Ax2(gp_Pnt(c.x,c.y,c.z), gp_Dir(0.0,0.0,1.0)),
major, minor);
if (!mh.IsDone()) {
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(mh.Status()));
if (!me.IsDone()) {
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(me.Status()));
return -1;
}
Handle_Geom_Hyperbola hyperb = Handle_Geom_Hyperbola::DownCast(getGeometryPtr()->handle());
hyperb->SetHypr(mh.Value()->Hypr());
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
hyperbola->SetHypr(me.Value()->Hypr());
return 0;
}
@@ -127,90 +127,111 @@ int HyperbolaPy::PyInit(PyObject* args, PyObject* kwds)
return -1;
}
Py::Float HyperbolaPy::getMajorRadius(void) const
{
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
return Py::Float(hyperbola->MajorRadius());
}
void HyperbolaPy::setMajorRadius(Py::Float arg)
{
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
hyperbola->SetMajorRadius((double)arg);
}
Py::Float HyperbolaPy::getMinorRadius(void) const
{
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
return Py::Float(hyperbola->MinorRadius());
}
void HyperbolaPy::setMinorRadius(Py::Float arg)
{
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
hyperbola->SetMinorRadius((double)arg);
}
Py::Float HyperbolaPy::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 HyperbolaPy::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 HyperbolaPy::getEccentricity(void) const
{
Handle_Geom_Hyperbola curve = Handle_Geom_Hyperbola::DownCast(getGeometryPtr()->handle());
return Py::Float(curve->Eccentricity());
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
return Py::Float(hyperbola->Eccentricity());
}
Py::Float HyperbolaPy::getFocal(void) const
{
Handle_Geom_Hyperbola curve = Handle_Geom_Hyperbola::DownCast(getGeometryPtr()->handle());
return Py::Float(curve->Focal());
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
return Py::Float(hyperbola->Focal());
}
Py::Object HyperbolaPy::getFocus1(void) const
{
Handle_Geom_Hyperbola c = Handle_Geom_Hyperbola::DownCast
(getGeometryPtr()->handle());
gp_Pnt loc = c->Focus1();
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
gp_Pnt loc = hyperbola->Focus1();
return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
}
Py::Object HyperbolaPy::getFocus2(void) const
{
Handle_Geom_Hyperbola c = Handle_Geom_Hyperbola::DownCast
(getGeometryPtr()->handle());
gp_Pnt loc = c->Focus2();
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
gp_Pnt loc = hyperbola->Focus2();
return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
}
Py::Float HyperbolaPy::getParameter(void) const
Py::Object HyperbolaPy::getCenter(void) const
{
Handle_Geom_Hyperbola curve = Handle_Geom_Hyperbola::DownCast(getGeometryPtr()->handle());
return Py::Float(curve->Parameter());
}
Py::Float HyperbolaPy::getMajorRadius(void) const
{
Handle_Geom_Hyperbola curve = Handle_Geom_Hyperbola::DownCast(getGeometryPtr()->handle());
return Py::Float(curve->MajorRadius());
}
void HyperbolaPy::setMajorRadius(Py::Float arg)
{
Handle_Geom_Hyperbola curve = Handle_Geom_Hyperbola::DownCast(getGeometryPtr()->handle());
curve->SetMajorRadius((double)arg);
}
Py::Float HyperbolaPy::getMinorRadius(void) const
{
Handle_Geom_Hyperbola curve = Handle_Geom_Hyperbola::DownCast(getGeometryPtr()->handle());
return Py::Float(curve->MinorRadius());
}
void HyperbolaPy::setMinorRadius(Py::Float arg)
{
Handle_Geom_Hyperbola curve = Handle_Geom_Hyperbola::DownCast(getGeometryPtr()->handle());
curve->SetMinorRadius((double)arg);
}
Py::Object HyperbolaPy::getLocation(void) const
{
Handle_Geom_Hyperbola c = Handle_Geom_Hyperbola::DownCast
(getGeometryPtr()->handle());
gp_Pnt loc = c->Location();
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 HyperbolaPy::setLocation(Py::Object arg)
void HyperbolaPy::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 c = Handle_Geom_Hyperbola::DownCast
(getGeometryPtr()->handle());
c->SetLocation(gp_Pnt(loc.x, loc.y, loc.z));
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)) {
gp_Pnt loc;
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 c = Handle_Geom_Hyperbola::DownCast
(getGeometryPtr()->handle());
c->SetLocation(loc);
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
hyperbola->SetLocation(loc);
}
else {
std::string error = std::string("type must be 'Vector', not ");
@@ -221,41 +242,34 @@ void HyperbolaPy::setLocation(Py::Object arg)
Py::Object HyperbolaPy::getAxis(void) const
{
Handle_Geom_Hyperbola c = Handle_Geom_Hyperbola::DownCast
(getGeometryPtr()->handle());
gp_Dir dir = c->Axis().Direction();
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 HyperbolaPy::setAxis(Py::Object arg)
{
Standard_Real dir_x, dir_y, dir_z;
PyObject *p = arg.ptr();
PyObject* p = arg.ptr();
Base::Vector3d val;
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
Base::Vector3d v = static_cast<Base::VectorPy*>(p)->value();
dir_x = v.x;
dir_y = v.y;
dir_z = v.z;
val = static_cast<Base::VectorPy*>(p)->value();
}
else if (PyTuple_Check(p)) {
Py::Tuple tuple(arg);
dir_x = (double)Py::Float(tuple.getItem(0));
dir_y = (double)Py::Float(tuple.getItem(1));
dir_z = (double)Py::Float(tuple.getItem(2));
val = Base::getVectorFromTuple<double>(p);
}
else {
std::string error = std::string("type must be 'Vector' or tuple, not ");
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 {
Handle_Geom_Hyperbola this_curv = Handle_Geom_Hyperbola::DownCast
(this->getGeometryPtr()->handle());
gp_Ax1 axis;
axis.SetLocation(this_curv->Location());
axis.SetDirection(gp_Dir(dir_x, dir_y, dir_z));
this_curv->SetAxis(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");
@@ -271,5 +285,3 @@ int HyperbolaPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}