GeometryPyImp.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 <gp_Ax1.hxx>
00027 # include <gp_Dir.hxx>
00028 # include <gp_Pnt.hxx>
00029 # include <gp_Vec.hxx>
00030 # include <gp_Trsf.hxx>
00031 # include <Geom_Geometry.hxx>
00032 # include <Geom_Curve.hxx>
00033 # include <Geom_Surface.hxx>
00034 # include <Precision.hxx>
00035 # include <Standard_Failure.hxx>
00036 #endif
00037 
00038 #include <Base/GeometryPyCXX.h>
00039 #include <Base/Matrix.h>
00040 #include <Base/MatrixPy.h>
00041 #include <Base/Vector3D.h>
00042 #include <Base/VectorPy.h>
00043 #include <Base/Rotation.h>
00044 #include <Base/Placement.h>
00045 #include <Base/PlacementPy.h>
00046 
00047 #include "Geometry.h"
00048 #include "GeometryPy.h"
00049 #include "GeometryPy.cpp"
00050 
00051 #include "TopoShape.h"
00052 #include "TopoShapePy.h"
00053 
00054 using namespace Part;
00055 
00056 // returns a string which represents the object e.g. when printed in python
00057 std::string GeometryPy::representation(void) const
00058 {
00059     return "<Geometry object>";
00060 }
00061 
00062 PyObject *GeometryPy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
00063 {
00064     // never create such objects with the constructor
00065     PyErr_SetString(PyExc_RuntimeError,
00066         "You cannot create an instance of the abstract class 'Geometry'.");
00067     return 0;
00068 }
00069 
00070 // constructor method
00071 int GeometryPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
00072 {
00073     return 0;
00074 }
00075 
00076 PyObject* GeometryPy::mirror(PyObject *args)
00077 {
00078     PyObject* o;
00079     if (PyArg_ParseTuple(args, "O!", &(Base::VectorPy::Type),&o)) {
00080         Base::Vector3d vec = static_cast<Base::VectorPy*>(o)->value();
00081         gp_Pnt pnt(vec.x, vec.y, vec.z);
00082         getGeometryPtr()->handle()->Mirror(pnt);
00083         Py_Return;
00084     }
00085 
00086     PyErr_Clear();
00087     PyObject* axis;
00088     if (PyArg_ParseTuple(args, "O!O!", &(Base::VectorPy::Type),&o,
00089                                        &(Base::VectorPy::Type),&axis)) {
00090         Base::Vector3d pnt = static_cast<Base::VectorPy*>(o)->value();
00091         Base::Vector3d dir = static_cast<Base::VectorPy*>(axis)->value();
00092         gp_Ax1 ax1(gp_Pnt(pnt.x,pnt.y,pnt.z), gp_Dir(dir.x,dir.y,dir.z));
00093         getGeometryPtr()->handle()->Mirror(ax1);
00094         Py_Return;
00095     }
00096 
00097     PyErr_SetString(PyExc_Exception, "either a point (vector) or axis (vector, vector) must be given");
00098     return 0;
00099 }
00100 
00101 PyObject* GeometryPy::rotate(PyObject *args)
00102 {
00103     PyObject* o;
00104     if (!PyArg_ParseTuple(args, "O!", &(Base::PlacementPy::Type),&o))
00105         return 0;
00106 
00107     Base::Placement* plm = static_cast<Base::PlacementPy*>(o)->getPlacementPtr();
00108     Base::Rotation rot(plm->getRotation());
00109     Base::Vector3d pnt, dir;
00110     double angle;
00111 
00112     rot.getValue(dir, angle);
00113     pnt = plm->getPosition();
00114     
00115     gp_Ax1 ax1(gp_Pnt(pnt.x,pnt.y,pnt.z), gp_Dir(dir.x,dir.y,dir.z));
00116     getGeometryPtr()->handle()->Rotate(ax1, angle);
00117     Py_Return;
00118 }
00119 
00120 PyObject* GeometryPy::scale(PyObject *args)
00121 {
00122     PyObject* o;
00123     double scale;
00124     Base::Vector3d vec;
00125     if (PyArg_ParseTuple(args, "O!d", &(Base::VectorPy::Type),&o, &scale)) {
00126         vec = static_cast<Base::VectorPy*>(o)->value();
00127         gp_Pnt pnt(vec.x, vec.y, vec.z);
00128         getGeometryPtr()->handle()->Scale(pnt, scale);
00129         Py_Return;
00130     }
00131     
00132     PyErr_Clear();
00133     if (PyArg_ParseTuple(args, "O!d", &PyTuple_Type,&o, &scale)) {
00134         vec = Base::getVectorFromTuple<double>(o);
00135         gp_Pnt pnt(vec.x, vec.y, vec.z);
00136         getGeometryPtr()->handle()->Scale(pnt, scale);
00137         Py_Return;
00138     }
00139 
00140     PyErr_SetString(PyExc_Exception, "either vector or tuple and float expected");
00141     return 0;
00142 }
00143 
00144 PyObject* GeometryPy::transform(PyObject *args)
00145 {
00146     PyObject* o;
00147     if (!PyArg_ParseTuple(args, "O!", &(Base::MatrixPy::Type),&o))
00148         return 0;
00149     Base::Matrix4D mat = static_cast<Base::MatrixPy*>(o)->value();
00150     gp_Trsf trf;
00151     trf.SetValues(mat[0][0],mat[0][1],mat[0][2],mat[0][3],
00152                   mat[1][0],mat[1][1],mat[1][2],mat[1][3],
00153                   mat[2][0],mat[2][1],mat[2][2],mat[2][3],
00154                   0.00001,0.00001);
00155     getGeometryPtr()->handle()->Transform(trf);
00156     Py_Return;
00157 }
00158 
00159 PyObject* GeometryPy::translate(PyObject *args)
00160 {
00161     PyObject* o;
00162     Base::Vector3d vec;
00163     if (PyArg_ParseTuple(args, "O!", &(Base::VectorPy::Type),&o)) {
00164         vec = static_cast<Base::VectorPy*>(o)->value();
00165         gp_Vec trl(vec.x, vec.y, vec.z);
00166         getGeometryPtr()->handle()->Translate(trl);
00167         Py_Return;
00168     }
00169 
00170     PyErr_Clear();
00171     if (PyArg_ParseTuple(args, "O!", &PyTuple_Type,&o)) {
00172         vec = Base::getVectorFromTuple<double>(o);
00173         gp_Vec trl(vec.x, vec.y, vec.z);
00174         getGeometryPtr()->handle()->Translate(trl);
00175         Py_Return;
00176     }
00177 
00178     PyErr_SetString(PyExc_Exception, "either vector or tuple expected");
00179     return 0;
00180 }
00181 
00182 Py::Boolean GeometryPy::getConstruction(void) const
00183 {
00184     return Py::Boolean(getGeometryPtr()->Construction);
00185 }
00186 
00187 void  GeometryPy::setConstruction(Py::Boolean arg)
00188 {
00189     getGeometryPtr()->Construction = arg;
00190 }
00191 
00192 PyObject *GeometryPy::getCustomAttributes(const char* /*attr*/) const
00193 {
00194     return 0;
00195 }
00196 
00197 int GeometryPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
00198 {
00199     return 0; 
00200 }

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