SurfaceOfExtrusionPyImp.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_SurfaceOfLinearExtrusion.hxx>
00027 #endif
00028 
00029 #include "Geometry.h"
00030 #include "SurfaceOfExtrusionPy.h"
00031 #include "SurfaceOfExtrusionPy.cpp"
00032 
00033 #include <Base/GeometryPyCXX.h>
00034 #include <Base/VectorPy.h>
00035 
00036 using namespace Part;
00037 
00038 // returns a string which represents the object e.g. when printed in python
00039 std::string SurfaceOfExtrusionPy::representation(void) const
00040 {
00041     return std::string("<SurfaceOfExtrusion object>");
00042 }
00043 
00044 PyObject *SurfaceOfExtrusionPy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
00045 {
00046     // create a new instance of SurfaceOfExtrusionPy and the Twin object 
00047     return new SurfaceOfExtrusionPy(new GeomSurfaceOfExtrusion);
00048 }
00049 
00050 // constructor method
00051 int SurfaceOfExtrusionPy::PyInit(PyObject* args, PyObject* /*kwd*/)
00052 {
00053     PyObject* pGeom;
00054     PyObject* pDir;
00055     if (!PyArg_ParseTuple(args, "O!O!", 
00056                             &(GeometryPy::Type), &pGeom, 
00057                             &(Base::VectorPy::Type),&pDir))
00058         return -1;
00059 
00060     GeometryPy* pcGeo = static_cast<GeometryPy*>(pGeom);
00061     Handle_Geom_Curve curve = Handle_Geom_Curve::DownCast
00062         (pcGeo->getGeometryPtr()->handle());
00063     if (curve.IsNull()) {
00064         PyErr_SetString(PyExc_TypeError, "geometry is not a curve");
00065         return -1;
00066     }
00067 
00068     try {
00069         Base::Vector3d dir = static_cast<Base::VectorPy*>(pDir)->value();
00070         Handle_Geom_SurfaceOfLinearExtrusion curve2 = new Geom_SurfaceOfLinearExtrusion(curve,
00071             gp_Dir(dir.x,dir.y,dir.z));
00072         getGeomSurfaceOfExtrusionPtr()->setHandle(curve2);
00073         return 0;
00074     }
00075     catch (Standard_Failure) {
00076         Handle_Standard_Failure e = Standard_Failure::Caught();
00077         PyErr_SetString(PyExc_Exception, e->GetMessageString());
00078         return -1;
00079     }
00080 }
00081 
00082 Py::Object SurfaceOfExtrusionPy::getDirection(void) const
00083 {
00084     Handle_Geom_SurfaceOfLinearExtrusion curve = Handle_Geom_SurfaceOfLinearExtrusion::DownCast
00085         (getGeometryPtr()->handle());
00086     const gp_Dir& dir = curve->Direction();
00087     return Py::Vector(Base::Vector3d(dir.X(),dir.Y(),dir.Z()));
00088 }
00089 
00090 void  SurfaceOfExtrusionPy::setDirection(Py::Object arg)
00091 {
00092     PyObject* p = arg.ptr();
00093     if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
00094         Base::Vector3d dir = static_cast<Base::VectorPy*>(p)->value();
00095         Handle_Geom_SurfaceOfLinearExtrusion curve = Handle_Geom_SurfaceOfLinearExtrusion::DownCast
00096             (getGeometryPtr()->handle());
00097         curve->SetDirection(gp_Dir(dir.x,dir.y,dir.z));
00098     }
00099     else if (PyObject_TypeCheck(p, &PyTuple_Type)) {
00100         Base::Vector3d dir = Base::getVectorFromTuple<double>(p);
00101         Handle_Geom_SurfaceOfLinearExtrusion curve = Handle_Geom_SurfaceOfLinearExtrusion::DownCast
00102             (getGeometryPtr()->handle());
00103         curve->SetDirection(gp_Dir(dir.x,dir.y,dir.z));
00104     }
00105     else {
00106         std::string error = std::string("type must be 'Vector', not ");
00107         error += p->ob_type->tp_name;
00108         throw Py::TypeError(error);
00109     }
00110 }
00111 
00112 Py::Object SurfaceOfExtrusionPy::getBasisCurve(void) const
00113 {
00114     throw Py::Exception(PyExc_NotImplementedError, "Not yet implemented");
00115 }
00116 
00117 void  SurfaceOfExtrusionPy::setBasisCurve(Py::Object arg)
00118 {
00119     PyObject* p = arg.ptr();
00120     if (PyObject_TypeCheck(p, &(GeometryPy::Type))) {
00121         GeometryPy* pcGeo = static_cast<GeometryPy*>(p);
00122         Handle_Geom_Curve curve = Handle_Geom_Curve::DownCast
00123             (pcGeo->getGeometryPtr()->handle());
00124         if (curve.IsNull()) {
00125             throw Py::TypeError("geometry is not a curve");
00126         }
00127 
00128         try {
00129             Handle_Geom_SurfaceOfLinearExtrusion curve2 = Handle_Geom_SurfaceOfLinearExtrusion::DownCast
00130                 (getGeometryPtr()->handle());
00131             curve2->SetBasisCurve(curve);
00132         }
00133         catch (Standard_Failure) {
00134             Handle_Standard_Failure e = Standard_Failure::Caught();
00135             throw Py::Exception(e->GetMessageString());
00136         }
00137     }
00138 }
00139 
00140 PyObject *SurfaceOfExtrusionPy::getCustomAttributes(const char* /*attr*/) const
00141 {
00142     return 0;
00143 }
00144 
00145 int SurfaceOfExtrusionPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
00146 {
00147     return 0; 
00148 }

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