RectangularTrimmedSurfacePyImp.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2010 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_RectangularTrimmedSurface.hxx>
00027 # include <Geom_Curve.hxx>
00028 #endif
00029 
00030 #include "Mod/Part/App/Geometry.h"
00031 
00032 // inclusion of the generated files (generated out of RectangularTrimmedSurfacePy.xml)
00033 #include "RectangularTrimmedSurfacePy.h"
00034 #include "RectangularTrimmedSurfacePy.cpp"
00035 #include "GeometryCurvePy.h"
00036 
00037 using namespace Part;
00038 
00039 // returns a string which represents the object e.g. when printed in python
00040 std::string RectangularTrimmedSurfacePy::representation(void) const
00041 {
00042     return std::string("<RectangularTrimmedSurface object>");
00043 }
00044 
00045 PyObject *RectangularTrimmedSurfacePy::PyMake(struct _typeobject *, PyObject *, PyObject *)
00046 {
00047     // create a new instance of RectangularTrimmedSurfacePy and the Twin object 
00048     return new RectangularTrimmedSurfacePy(new GeomTrimmedSurface);
00049 }
00050 
00051 // constructor method
00052 int RectangularTrimmedSurfacePy::PyInit(PyObject* args, PyObject* /*kwd*/)
00053 {
00054     PyObject* surf;
00055     double u1,u2,v1,v2;
00056     PyObject *usense=Py_True, *vsense=Py_True;
00057     if (PyArg_ParseTuple(args, "O!dddd|O!O!",&(Part::GeometrySurfacePy::Type),&surf,
00058                          &u1,&u2,&v1,&v2,&PyBool_Type,&usense,&PyBool_Type,&vsense)) {
00059         getGeomTrimmedSurfacePtr()->setHandle(new Geom_RectangularTrimmedSurface(
00060             Handle_Geom_Surface::DownCast(static_cast<GeometrySurfacePy*>(surf)->
00061                 getGeomSurfacePtr()->handle()),
00062             u1, u2, v1, v2, (usense==Py_True), (vsense==Py_True)
00063         ));
00064         return 0;
00065     }
00066 
00067     PyErr_Clear();
00068     double param1,param2;
00069     PyObject *utrim=0, *sense=Py_True;
00070     if (PyArg_ParseTuple(args, "O!ddO!|O!",&(Part::GeometrySurfacePy::Type),&surf,
00071                          &param1,&param2,&PyBool_Type,&utrim,&PyBool_Type,&sense)) {
00072         Standard_Boolean UTrim = (utrim==Py_True);
00073         Standard_Boolean Sense = (sense==Py_True);
00074         getGeomTrimmedSurfacePtr()->setHandle(new Geom_RectangularTrimmedSurface(
00075             Handle_Geom_Surface::DownCast(static_cast<GeometrySurfacePy*>(surf)->
00076                 getGeomSurfacePtr()->handle()),
00077             param1, param2, UTrim, Sense
00078         ));
00079         return 0;
00080     }
00081 
00082     PyErr_SetString(PyExc_Exception, "A surface and the trim parameters must be given");
00083     return -1;
00084 }
00085 
00086 PyObject* RectangularTrimmedSurfacePy::uIso(PyObject * args)
00087 {
00088     double v;
00089     if (!PyArg_ParseTuple(args, "d", &v))
00090         return 0;
00091 
00092     try {
00093         Handle_Geom_Surface surf = Handle_Geom_Surface::DownCast
00094             (getGeometryPtr()->handle());
00095         Handle_Geom_Curve c = surf->UIso(v);
00096         if (c->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
00097             Handle_Geom_TrimmedCurve aCurve = Handle_Geom_TrimmedCurve::DownCast(c);
00098             return new GeometryCurvePy(new GeomTrimmedCurve(aCurve));
00099         }
00100 
00101         PyErr_Format(PyExc_NotImplementedError, "Iso curve is of type '%s'",
00102             c->DynamicType()->Name());
00103         return 0;
00104     }
00105     catch (Standard_Failure) {
00106         Handle_Standard_Failure e = Standard_Failure::Caught();
00107         PyErr_SetString(PyExc_Exception, e->GetMessageString());
00108         return 0;
00109     }
00110 }
00111 
00112 PyObject* RectangularTrimmedSurfacePy::vIso(PyObject * args)
00113 {
00114     double v;
00115     if (!PyArg_ParseTuple(args, "d", &v))
00116         return 0;
00117 
00118     try {
00119         Handle_Geom_Surface surf = Handle_Geom_Surface::DownCast
00120             (getGeometryPtr()->handle());
00121         Handle_Geom_Curve c = surf->VIso(v);
00122         if (c->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
00123             Handle_Geom_TrimmedCurve aCurve = Handle_Geom_TrimmedCurve::DownCast(c);
00124             return new GeometryCurvePy(new GeomTrimmedCurve(aCurve));
00125         }
00126 
00127         PyErr_Format(PyExc_NotImplementedError, "Iso curve is of type '%s'",
00128             c->DynamicType()->Name());
00129         return 0;
00130     }
00131     catch (Standard_Failure) {
00132         Handle_Standard_Failure e = Standard_Failure::Caught();
00133         PyErr_SetString(PyExc_Exception, e->GetMessageString());
00134         return 0;
00135     }
00136 }
00137 
00138 PyObject *RectangularTrimmedSurfacePy::getCustomAttributes(const char* /*attr*/) const
00139 {
00140     return 0;
00141 }
00142 
00143 int RectangularTrimmedSurfacePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
00144 {
00145     return 0; 
00146 }

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