OffsetCurvePyImp.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2008 Werner Mayer <wmayer[at]users.sourceforge.net>     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
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 // returns a string which represents the object e.g. when printed in python
00040 std::string OffsetCurvePy::representation(void) const
00041 {
00042     return "<OffsetCurve object>";
00043 }
00044 
00045 PyObject *OffsetCurvePy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
00046 {
00047     // create a new instance of OffsetCurvePy and the Twin object 
00048     return new OffsetCurvePy(new GeomOffsetCurve);
00049 }
00050 
00051 // constructor method
00052 int OffsetCurvePy::PyInit(PyObject* args, PyObject* /*kwd*/)
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* /*attr*/) const
00154 {
00155     return 0;
00156 }
00157 
00158 int OffsetCurvePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
00159 {
00160     return 0; 
00161 }

Generated on Wed Nov 23 19:00:24 2011 for FreeCAD by  doxygen 1.6.1