ParabolaPyImp.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_Parabola.hxx>
00027 #endif
00028 
00029 #include <Base/VectorPy.h>
00030 #include <Base/GeometryPyCXX.h>
00031 
00032 #include "Geometry.h"
00033 #include "ParabolaPy.h"
00034 #include "ParabolaPy.cpp"
00035 
00036 using namespace Part;
00037 
00038 // returns a string which represents the object e.g. when printed in python
00039 std::string ParabolaPy::representation(void) const
00040 {
00041     return "<Parabola object>";
00042 }
00043 
00044 PyObject *ParabolaPy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
00045 {
00046     // create a new instance of ParabolaPy and the Twin object 
00047     return new ParabolaPy(new GeomParabola);
00048 }
00049 
00050 // constructor method
00051 int ParabolaPy::PyInit(PyObject* args, PyObject* /*kwd*/)
00052 {
00053     if (PyArg_ParseTuple(args, "")) {
00054         Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast
00055             (getGeometryPtr()->handle());
00056         c->SetFocal(1.0);
00057         return 0;
00058     }
00059 
00060     return -1;
00061 }
00062 
00063 Py::Float ParabolaPy::getEccentricity(void) const
00064 {
00065     Handle_Geom_Parabola curve = Handle_Geom_Parabola::DownCast(getGeometryPtr()->handle());
00066     return Py::Float(curve->Eccentricity()); 
00067 }
00068 
00069 Py::Float ParabolaPy::getFocal(void) const
00070 {
00071     Handle_Geom_Parabola curve = Handle_Geom_Parabola::DownCast(getGeometryPtr()->handle());
00072     return Py::Float(curve->Focal()); 
00073 }
00074 
00075 void ParabolaPy::setFocal(Py::Float arg)
00076 {
00077     Handle_Geom_Parabola curve = Handle_Geom_Parabola::DownCast(getGeometryPtr()->handle());
00078     curve->SetFocal((double)arg); 
00079 }
00080 
00081 Py::Object ParabolaPy::getFocus(void) const
00082 {
00083     Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast
00084         (getGeometryPtr()->handle());
00085     gp_Pnt loc = c->Focus();
00086     return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
00087 }
00088 
00089 Py::Float ParabolaPy::getParameter(void) const
00090 {
00091     Handle_Geom_Parabola curve = Handle_Geom_Parabola::DownCast(getGeometryPtr()->handle());
00092     return Py::Float(curve->Parameter()); 
00093 }
00094 
00095 Py::Object ParabolaPy::getLocation(void) const
00096 {
00097     Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast
00098         (getGeometryPtr()->handle());
00099     gp_Pnt loc = c->Location();
00100     return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
00101 }
00102 
00103 void ParabolaPy::setLocation(Py::Object arg)
00104 {
00105     PyObject* p = arg.ptr();
00106     if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
00107         Base::Vector3d loc = static_cast<Base::VectorPy*>(p)->value();
00108         Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast
00109             (getGeometryPtr()->handle());
00110         c->SetLocation(gp_Pnt(loc.x, loc.y, loc.z));
00111     }
00112     else if (PyTuple_Check(p)) {
00113         Py::Tuple tuple(arg);
00114         gp_Pnt loc;
00115         loc.SetX((double)Py::Float(tuple.getItem(0)));
00116         loc.SetY((double)Py::Float(tuple.getItem(1)));
00117         loc.SetZ((double)Py::Float(tuple.getItem(2)));
00118         Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast
00119             (getGeometryPtr()->handle());
00120         c->SetLocation(loc);
00121     }
00122     else {
00123         std::string error = std::string("type must be 'Vector', not ");
00124         error += p->ob_type->tp_name;
00125         throw Py::TypeError(error);
00126     }
00127 }
00128 
00129 Py::Object ParabolaPy::getAxis(void) const
00130 {
00131     Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast
00132         (getGeometryPtr()->handle());
00133     gp_Dir dir = c->Axis().Direction();
00134     return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z()));
00135 }
00136 
00137 void ParabolaPy::setAxis(Py::Object arg)
00138 {
00139     Standard_Real dir_x, dir_y, dir_z;
00140     PyObject *p = arg.ptr();
00141     if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
00142         Base::Vector3d v = static_cast<Base::VectorPy*>(p)->value();
00143         dir_x = v.x;
00144         dir_y = v.y;
00145         dir_z = v.z;
00146     }
00147     else if (PyTuple_Check(p)) {
00148         Py::Tuple tuple(arg);
00149         dir_x = (double)Py::Float(tuple.getItem(0));
00150         dir_y = (double)Py::Float(tuple.getItem(1));
00151         dir_z = (double)Py::Float(tuple.getItem(2));
00152     }
00153     else {
00154         std::string error = std::string("type must be 'Vector' or tuple, not ");
00155         error += p->ob_type->tp_name;
00156         throw Py::TypeError(error);
00157     }
00158 
00159     try {
00160         Handle_Geom_Parabola this_curv = Handle_Geom_Parabola::DownCast
00161             (this->getGeometryPtr()->handle());
00162         gp_Ax1 axis;
00163         axis.SetLocation(this_curv->Location());
00164         axis.SetDirection(gp_Dir(dir_x, dir_y, dir_z));
00165         this_curv->SetAxis(axis);
00166     }
00167     catch (Standard_Failure) {
00168         throw Py::Exception("cannot set axis");
00169     }
00170 }
00171 
00172 PyObject *ParabolaPy::getCustomAttributes(const char* /*attr*/) const
00173 {
00174     return 0;
00175 }
00176 
00177 int ParabolaPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
00178 {
00179     return 0; 
00180 }
00181 
00182 

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