SurfaceOfRevolutionPyImp.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_SurfaceOfRevolution.hxx>
00027 #endif
00028 
00029 #include "Geometry.h"
00030 #include "SurfaceOfRevolutionPy.h"
00031 #include "SurfaceOfRevolutionPy.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 SurfaceOfRevolutionPy::representation(void) const
00040 {
00041     return std::string("<SurfaceOfRevolution object>");
00042 }
00043 
00044 PyObject *SurfaceOfRevolutionPy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
00045 {
00046     // create a new instance of SurfaceOfRevolutionPy and the Twin object 
00047     return new SurfaceOfRevolutionPy(new GeomSurfaceOfRevolution);
00048 }
00049 
00050 // constructor method
00051 int SurfaceOfRevolutionPy::PyInit(PyObject* args, PyObject* /*kwd*/)
00052 {
00053     PyObject* pGeom;
00054     PyObject* pPnt;
00055     PyObject* pDir;
00056     if (!PyArg_ParseTuple(args, "O!O!O!", 
00057                             &(GeometryPy::Type), &pGeom, 
00058                             &(Base::VectorPy::Type),&pPnt,
00059                             &(Base::VectorPy::Type),&pDir))
00060         return -1;
00061 
00062     GeometryPy* pcGeo = static_cast<GeometryPy*>(pGeom);
00063     Handle_Geom_Curve curve = Handle_Geom_Curve::DownCast
00064         (pcGeo->getGeometryPtr()->handle());
00065     if (curve.IsNull()) {
00066         PyErr_SetString(PyExc_TypeError, "geometry is not a curve");
00067         return -1;
00068     }
00069 
00070     try {
00071         Base::Vector3d pnt = static_cast<Base::VectorPy*>(pPnt)->value();
00072         Base::Vector3d dir = static_cast<Base::VectorPy*>(pDir)->value();
00073         Handle_Geom_SurfaceOfRevolution curve2 = new Geom_SurfaceOfRevolution(curve,
00074             gp_Ax1(gp_Pnt(pnt.x,pnt.y,pnt.z),
00075                    gp_Dir(dir.x,dir.y,dir.z)));
00076         getGeomSurfaceOfRevolutionPtr()->setHandle(curve2);
00077         return 0;
00078     }
00079     catch (Standard_Failure) {
00080         Handle_Standard_Failure e = Standard_Failure::Caught();
00081         PyErr_SetString(PyExc_Exception, e->GetMessageString());
00082         return -1;
00083     }
00084 }
00085 
00086 Py::Object SurfaceOfRevolutionPy::getLocation(void) const
00087 {
00088     Handle_Geom_SurfaceOfRevolution curve = Handle_Geom_SurfaceOfRevolution::DownCast
00089         (getGeometryPtr()->handle());
00090     const gp_Pnt& pnt = curve->Location();
00091     return Py::Vector(Base::Vector3d(pnt.X(),pnt.Y(),pnt.Z()));
00092 }
00093 
00094 void  SurfaceOfRevolutionPy::setLocation(Py::Object arg)
00095 {
00096     PyObject* p = arg.ptr();
00097     if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
00098         Base::Vector3d pnt = static_cast<Base::VectorPy*>(p)->value();
00099         Handle_Geom_SurfaceOfRevolution curve = Handle_Geom_SurfaceOfRevolution::DownCast
00100             (getGeometryPtr()->handle());
00101         curve->SetLocation(gp_Pnt(pnt.x,pnt.y,pnt.z));
00102     }
00103     else if (PyObject_TypeCheck(p, &PyTuple_Type)) {
00104         Base::Vector3d pnt = Base::getVectorFromTuple<double>(p);
00105         Handle_Geom_SurfaceOfRevolution curve = Handle_Geom_SurfaceOfRevolution::DownCast
00106             (getGeometryPtr()->handle());
00107         curve->SetLocation(gp_Pnt(pnt.x,pnt.y,pnt.z));
00108     }
00109     else {
00110         std::string error = std::string("type must be 'Vector', not ");
00111         error += p->ob_type->tp_name;
00112         throw Py::TypeError(error);
00113     }
00114 }
00115 
00116 Py::Object SurfaceOfRevolutionPy::getDirection(void) const
00117 {
00118     Handle_Geom_SurfaceOfRevolution curve = Handle_Geom_SurfaceOfRevolution::DownCast
00119         (getGeometryPtr()->handle());
00120     const gp_Dir& dir = curve->Direction();
00121     return Py::Vector(Base::Vector3d(dir.X(),dir.Y(),dir.Z()));
00122 }
00123 
00124 void  SurfaceOfRevolutionPy::setDirection(Py::Object arg)
00125 {
00126     PyObject* p = arg.ptr();
00127     if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
00128         Base::Vector3d dir = static_cast<Base::VectorPy*>(p)->value();
00129         Handle_Geom_SurfaceOfRevolution curve = Handle_Geom_SurfaceOfRevolution::DownCast
00130             (getGeometryPtr()->handle());
00131         curve->SetDirection(gp_Dir(dir.x,dir.y,dir.z));
00132     }
00133     else if (PyObject_TypeCheck(p, &PyTuple_Type)) {
00134         Base::Vector3d dir = Base::getVectorFromTuple<double>(p);
00135         Handle_Geom_SurfaceOfRevolution curve = Handle_Geom_SurfaceOfRevolution::DownCast
00136             (getGeometryPtr()->handle());
00137         curve->SetDirection(gp_Dir(dir.x,dir.y,dir.z));
00138     }
00139     else {
00140         std::string error = std::string("type must be 'Vector', not ");
00141         error += p->ob_type->tp_name;
00142         throw Py::TypeError(error);
00143     }
00144 }
00145 
00146 Py::Object SurfaceOfRevolutionPy::getBasisCurve(void) const
00147 {
00148     throw Py::Exception(PyExc_NotImplementedError, "Not yet implemented");
00149 }
00150 
00151 void  SurfaceOfRevolutionPy::setBasisCurve(Py::Object arg)
00152 {
00153     PyObject* p = arg.ptr();
00154     if (PyObject_TypeCheck(p, &(GeometryPy::Type))) {
00155         GeometryPy* pcGeo = static_cast<GeometryPy*>(p);
00156         Handle_Geom_Curve curve = Handle_Geom_Curve::DownCast
00157             (pcGeo->getGeometryPtr()->handle());
00158         if (curve.IsNull()) {
00159             throw Py::TypeError("geometry is not a curve");
00160         }
00161 
00162         try {
00163             Handle_Geom_SurfaceOfRevolution curve2 = Handle_Geom_SurfaceOfRevolution::DownCast
00164                 (getGeometryPtr()->handle());
00165             curve2->SetBasisCurve(curve);
00166         }
00167         catch (Standard_Failure) {
00168             Handle_Standard_Failure e = Standard_Failure::Caught();
00169             throw Py::Exception(e->GetMessageString());
00170         }
00171     }
00172 }
00173 
00174 PyObject *SurfaceOfRevolutionPy::getCustomAttributes(const char* /*attr*/) const
00175 {
00176     return 0;
00177 }
00178 
00179 int SurfaceOfRevolutionPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
00180 {
00181     return 0; 
00182 }
00183 
00184 

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