OffsetCurvePyImp.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <Geom_OffsetCurve.hxx>
00027 #endif
00028
00029 #include "Geometry.h"
00030 #include "OffsetCurvePy.h"
00031 #include "OffsetCurvePy.cpp"
00032
00033 #include <Base/GeometryPyCXX.h>
00034 #include <Base/VectorPy.h>
00035 #include <Base/Vector3D.h>
00036
00037 using namespace Part;
00038
00039
00040 std::string OffsetCurvePy::representation(void) const
00041 {
00042 return "<OffsetCurve object>";
00043 }
00044
00045 PyObject *OffsetCurvePy::PyMake(struct _typeobject *, PyObject *, PyObject *)
00046 {
00047
00048 return new OffsetCurvePy(new GeomOffsetCurve);
00049 }
00050
00051
00052 int OffsetCurvePy::PyInit(PyObject* args, PyObject* )
00053 {
00054 PyObject* pGeom;
00055 PyObject* pDir;
00056 double offset;
00057 if (!PyArg_ParseTuple(args, "O!dO!",
00058 &(GeometryPy::Type), &pGeom,
00059 &offset,
00060 &(Base::VectorPy::Type),&pDir))
00061 return -1;
00062
00063 GeometryPy* pcGeo = static_cast<GeometryPy*>(pGeom);
00064 Handle_Geom_Curve curve = Handle_Geom_Curve::DownCast
00065 (pcGeo->getGeometryPtr()->handle());
00066 if (curve.IsNull()) {
00067 PyErr_SetString(PyExc_TypeError, "geometry is not a curve");
00068 return -1;
00069 }
00070
00071 try {
00072 Base::Vector3d dir = static_cast<Base::VectorPy*>(pDir)->value();
00073 Handle_Geom_OffsetCurve curve2 = new Geom_OffsetCurve(curve, offset, gp_Dir(dir.x,dir.y,dir.z));
00074 getGeomOffsetCurvePtr()->setHandle(curve2);
00075 return 0;
00076 }
00077 catch (Standard_Failure) {
00078 Handle_Standard_Failure e = Standard_Failure::Caught();
00079 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00080 return -1;
00081 }
00082 }
00083
00084 Py::Float OffsetCurvePy::getOffsetValue(void) const
00085 {
00086 Handle_Geom_OffsetCurve curve = Handle_Geom_OffsetCurve::DownCast(getGeometryPtr()->handle());
00087 return Py::Float(curve->Offset());
00088 }
00089
00090 void OffsetCurvePy::setOffsetValue(Py::Float arg)
00091 {
00092 Handle_Geom_OffsetCurve curve = Handle_Geom_OffsetCurve::DownCast(getGeometryPtr()->handle());
00093 curve->SetOffsetValue((double)arg);
00094 }
00095
00096 Py::Object OffsetCurvePy::getOffsetDirection(void) const
00097 {
00098 Handle_Geom_OffsetCurve curve = Handle_Geom_OffsetCurve::DownCast(getGeometryPtr()->handle());
00099 const gp_Dir& dir = curve->Direction();
00100 return Py::Vector(Base::Vector3d(dir.X(),dir.Y(),dir.Z()));
00101 }
00102
00103 void OffsetCurvePy::setOffsetDirection(Py::Object arg)
00104 {
00105 PyObject* p = arg.ptr();
00106 if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
00107 Base::Vector3d dir = static_cast<Base::VectorPy*>(p)->value();
00108 Handle_Geom_OffsetCurve curve = Handle_Geom_OffsetCurve::DownCast(getGeometryPtr()->handle());
00109 curve->SetDirection(gp_Dir(dir.x,dir.y,dir.z));
00110 }
00111 else if (PyObject_TypeCheck(p, &PyTuple_Type)) {
00112 Base::Vector3d dir = Base::getVectorFromTuple<double>(p);
00113 Handle_Geom_OffsetCurve curve = Handle_Geom_OffsetCurve::DownCast(getGeometryPtr()->handle());
00114 curve->SetDirection(gp_Dir(dir.x,dir.y,dir.z));
00115 }
00116 else {
00117 std::string error = std::string("type must be 'Vector', not ");
00118 error += p->ob_type->tp_name;
00119 throw Py::TypeError(error);
00120 }
00121 }
00122
00123 Py::Object OffsetCurvePy::getBasisCurve(void) const
00124 {
00125 Handle_Geom_OffsetCurve curve = Handle_Geom_OffsetCurve::DownCast(getGeometryPtr()->handle());
00126 Handle_Geom_Curve basis = curve->BasisCurve();
00127 throw Py::Exception(PyExc_NotImplementedError, "Not yet implemented");
00128 }
00129
00130 void OffsetCurvePy::setBasisCurve(Py::Object arg)
00131 {
00132 PyObject* p = arg.ptr();
00133 if (PyObject_TypeCheck(p, &(GeometryPy::Type))) {
00134 GeometryPy* pcGeo = static_cast<GeometryPy*>(p);
00135 Handle_Geom_Curve curve = Handle_Geom_Curve::DownCast
00136 (pcGeo->getGeometryPtr()->handle());
00137 if (curve.IsNull()) {
00138 throw Py::TypeError("geometry is not a curve");
00139 }
00140
00141 try {
00142 Handle_Geom_OffsetCurve curve2 = Handle_Geom_OffsetCurve::DownCast
00143 (getGeometryPtr()->handle());
00144 curve2->SetBasisCurve(curve);
00145 }
00146 catch (Standard_Failure) {
00147 Handle_Standard_Failure e = Standard_Failure::Caught();
00148 throw Py::Exception(e->GetMessageString());
00149 }
00150 }
00151 }
00152
00153 PyObject *OffsetCurvePy::getCustomAttributes(const char* ) const
00154 {
00155 return 0;
00156 }
00157
00158 int OffsetCurvePy::setCustomAttributes(const char* , PyObject* )
00159 {
00160 return 0;
00161 }