add class GeomConic to reduce code duplication
This commit is contained in:
@@ -29,8 +29,8 @@
|
||||
#endif
|
||||
|
||||
#include "OCCError.h"
|
||||
#include "CirclePy.h"
|
||||
#include "CirclePy.cpp"
|
||||
#include <Mod/Part/App/CirclePy.h>
|
||||
#include <Mod/Part/App/CirclePy.cpp>
|
||||
|
||||
#include <Base/GeometryPyCXX.h>
|
||||
#include <Base/VectorPy.h>
|
||||
@@ -174,138 +174,6 @@ void CirclePy::setRadius(Py::Float arg)
|
||||
circle->SetRadius((double)arg);
|
||||
}
|
||||
|
||||
Py::Object CirclePy::getCenter(void) const
|
||||
{
|
||||
Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle());
|
||||
gp_Pnt loc = circle->Location();
|
||||
return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
|
||||
}
|
||||
|
||||
void CirclePy::setCenter(Py::Object arg)
|
||||
{
|
||||
PyObject* p = arg.ptr();
|
||||
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
|
||||
Base::Vector3d loc = static_cast<Base::VectorPy*>(p)->value();
|
||||
getGeomCirclePtr()->setCenter(loc);
|
||||
}
|
||||
else if (PyObject_TypeCheck(p, &PyTuple_Type)) {
|
||||
Base::Vector3d loc = Base::getVectorFromTuple<double>(p);
|
||||
getGeomCirclePtr()->setCenter(loc);
|
||||
} else {
|
||||
std::string error = std::string("type must be 'Vector', not ");
|
||||
error += p->ob_type->tp_name;
|
||||
throw Py::TypeError(error);
|
||||
}
|
||||
}
|
||||
|
||||
Py::Object CirclePy::getAxis(void) const
|
||||
{
|
||||
Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle());
|
||||
gp_Ax1 axis = circle->Axis();
|
||||
gp_Dir dir = axis.Direction();
|
||||
return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z()));
|
||||
}
|
||||
|
||||
void CirclePy::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_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle());
|
||||
try {
|
||||
gp_Ax1 axis;
|
||||
axis.SetLocation(circle->Location());
|
||||
axis.SetDirection(gp_Dir(val.x, val.y, val.z));
|
||||
circle->SetAxis(axis);
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
throw Py::Exception("cannot set axis");
|
||||
}
|
||||
}
|
||||
|
||||
Py::Object CirclePy::getXAxis(void) const
|
||||
{
|
||||
Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle());
|
||||
gp_Ax1 axis = circle->XAxis();
|
||||
gp_Dir dir = axis.Direction();
|
||||
return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z()));
|
||||
}
|
||||
|
||||
void CirclePy::setXAxis(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_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle());
|
||||
try {
|
||||
gp_Ax2 pos;
|
||||
pos = circle->Position();
|
||||
pos.SetXDirection(gp_Dir(val.x, val.y, val.z));
|
||||
circle->SetPosition(pos);
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
throw Py::Exception("cannot set X axis");
|
||||
}
|
||||
}
|
||||
|
||||
Py::Object CirclePy::getYAxis(void) const
|
||||
{
|
||||
Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle());
|
||||
gp_Ax1 axis = circle->YAxis();
|
||||
gp_Dir dir = axis.Direction();
|
||||
return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z()));
|
||||
}
|
||||
|
||||
void CirclePy::setYAxis(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_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle());
|
||||
try {
|
||||
gp_Ax2 pos;
|
||||
pos = circle->Position();
|
||||
pos.SetYDirection(gp_Dir(val.x, val.y, val.z));
|
||||
circle->SetPosition(pos);
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
throw Py::Exception("cannot set Y axis");
|
||||
}
|
||||
}
|
||||
|
||||
PyObject *CirclePy::getCustomAttributes(const char* ) const
|
||||
{
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user