OffsetSurfacePyImp.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_OffsetSurface.hxx>
00027 #endif
00028 
00029 #include <Base/VectorPy.h>
00030 #include <Base/Vector3D.h>
00031 
00032 #include "Geometry.h"
00033 #include "OffsetSurfacePy.h"
00034 #include "OffsetSurfacePy.cpp"
00035 
00036 using namespace Part;
00037 
00038 // returns a string which represents the object e.g. when printed in python
00039 std::string OffsetSurfacePy::representation(void) const
00040 {
00041     return "<OffsetSurface object>";
00042 }
00043 
00044 PyObject *OffsetSurfacePy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
00045 {
00046     // create a new instance of OffsetSurfacePy and the Twin object 
00047     return new OffsetSurfacePy(new GeomOffsetSurface);
00048 }
00049 
00050 // constructor method
00051 int OffsetSurfacePy::PyInit(PyObject* args, PyObject* /*kwd*/)
00052 {
00053     PyObject* pGeom;
00054     double offset;
00055     if (!PyArg_ParseTuple(args, "O!d", 
00056                             &(GeometryPy::Type), &pGeom, 
00057                             &offset))
00058         return -1;
00059 
00060     GeometryPy* pcGeo = static_cast<GeometryPy*>(pGeom);
00061     Handle_Geom_Surface surf = Handle_Geom_Surface::DownCast
00062         (pcGeo->getGeometryPtr()->handle());
00063     if (surf.IsNull()) {
00064         PyErr_SetString(PyExc_TypeError, "geometry is not a surface");
00065         return -1;
00066     }
00067 
00068     try {
00069         Handle_Geom_OffsetSurface surf2 = new Geom_OffsetSurface(surf, offset);
00070         getGeomOffsetSurfacePtr()->setHandle(surf2);
00071         return 0;
00072     }
00073     catch (Standard_Failure) {
00074         Handle_Standard_Failure e = Standard_Failure::Caught();
00075         PyErr_SetString(PyExc_Exception, e->GetMessageString());
00076         return -1;
00077     }
00078 }
00079 
00080 PyObject* OffsetSurfacePy::uIso(PyObject *args)
00081 {
00082     PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00083     return 0;
00084 }
00085 
00086 PyObject* OffsetSurfacePy::vIso(PyObject *args)
00087 {
00088     PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00089     return 0;
00090 }
00091 
00092 Py::Float OffsetSurfacePy::getOffsetValue(void) const
00093 {
00094     Handle_Geom_OffsetSurface surf = Handle_Geom_OffsetSurface::DownCast(getGeometryPtr()->handle());
00095     return Py::Float(surf->Offset());
00096 }
00097 
00098 void  OffsetSurfacePy::setOffsetValue(Py::Float arg)
00099 {
00100     Handle_Geom_OffsetSurface surf = Handle_Geom_OffsetSurface::DownCast(getGeometryPtr()->handle());
00101     surf->SetOffsetValue((double)arg);
00102 }
00103 
00104 Py::Object OffsetSurfacePy::getBasisSurface(void) const
00105 {
00106     throw Py::Exception(PyExc_NotImplementedError, "Not yet implemented");
00107 }
00108 
00109 void  OffsetSurfacePy::setBasisSurface(Py::Object arg)
00110 {
00111     PyObject* p = arg.ptr();
00112     if (PyObject_TypeCheck(p, &(GeometryPy::Type))) {
00113         GeometryPy* pcGeo = static_cast<GeometryPy*>(p);
00114         Handle_Geom_Surface surf = Handle_Geom_Surface::DownCast
00115             (pcGeo->getGeometryPtr()->handle());
00116         if (surf.IsNull()) {
00117             throw Py::TypeError("geometry is not a surface");
00118         }
00119 
00120         try {
00121             Handle_Geom_OffsetSurface surf2 = Handle_Geom_OffsetSurface::DownCast
00122                 (getGeometryPtr()->handle());
00123             surf2->SetBasisSurface(surf);
00124         }
00125         catch (Standard_Failure) {
00126             Handle_Standard_Failure e = Standard_Failure::Caught();
00127             throw Py::Exception(e->GetMessageString());
00128         }
00129     }
00130 }
00131 
00132 PyObject *OffsetSurfacePy::getCustomAttributes(const char* /*attr*/) const
00133 {
00134     return 0;
00135 }
00136 
00137 int OffsetSurfacePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
00138 {
00139     return 0; 
00140 }

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