AppDrawingPy.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) Jürgen Riegel          (juergen.riegel@web.de) 2002     *
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 <Python.h>
00027 #endif
00028 
00029 #include <Mod/Part/App/TopoShapePy.h>
00030 #include "ProjectionAlgos.h"
00031 #include <Base/Console.h>
00032 #include <Base/VectorPy.h>
00033 
00034 
00035 using namespace Drawing;
00036 using namespace Part;
00037 
00038 static PyObject * 
00039 project(PyObject *self, PyObject *args)
00040 {
00041     PyObject *pcObjShape;
00042     PyObject *pcObjDir=0;
00043 
00044     if (!PyArg_ParseTuple(args, "O!|O!", &(TopoShapePy::Type), &pcObjShape,&(Base::VectorPy::Type), &pcObjDir))     // convert args: Python->C
00045         return NULL;                             // NULL triggers exception
00046 
00047     PY_TRY {
00048         TopoShapePy* pShape = static_cast<TopoShapePy*>(pcObjShape);
00049         Base::Vector3d Vector(0,0,1);
00050         if (pcObjDir)
00051             Vector = *static_cast<Base::VectorPy*>(pcObjDir)->getVectorPtr();
00052 
00053         ProjectionAlgos Alg(pShape->getTopoShapePtr()->_Shape,Base::Vector3f((float)Vector.x,(float)Vector.y,(float)Vector.z));
00054 
00055         Py::List list;
00056         list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.V)) , true));
00057         list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.V1)), true));
00058         list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.H)) , true));
00059         list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.H1)), true));
00060 
00061         return Py::new_reference_to(list);
00062 
00063     } PY_CATCH;
00064 
00065 }
00066 
00067 static PyObject * 
00068 projectEx(PyObject *self, PyObject *args)
00069 {
00070     PyObject *pcObjShape;
00071     PyObject *pcObjDir=0;
00072 
00073     if (!PyArg_ParseTuple(args, "O!|O!", &(TopoShapePy::Type), &pcObjShape,&(Base::VectorPy::Type), &pcObjDir))     // convert args: Python->C
00074         return NULL;                             // NULL triggers exception
00075 
00076     PY_TRY {
00077         TopoShapePy* pShape = static_cast<TopoShapePy*>(pcObjShape);
00078         Base::Vector3d Vector(0,0,1);
00079         if (pcObjDir)
00080             Vector = *static_cast<Base::VectorPy*>(pcObjDir)->getVectorPtr();
00081 
00082         ProjectionAlgos Alg(pShape->getTopoShapePtr()->_Shape,Base::Vector3f((float)Vector.x,(float)Vector.y,(float)Vector.z));
00083 
00084         Py::List list;
00085         list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.V)) , true));
00086         list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.V1)), true));
00087         list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.VN)), true));
00088         list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.VO)), true));
00089         list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.VI)), true));
00090         list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.H)) , true));
00091         list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.H1)), true));
00092         list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.HN)), true));
00093         list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.HO)), true));
00094         list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.HI)), true));
00095 
00096         return Py::new_reference_to(list);
00097 
00098     } PY_CATCH;
00099 }
00100 
00101 static PyObject * 
00102 projectToSVG(PyObject *self, PyObject *args)
00103 {
00104     PyObject *pcObjShape;
00105     PyObject *pcObjDir=0;
00106     const char *type=0;
00107     float scale=1.0f;
00108 
00109     if (!PyArg_ParseTuple(args, "O!|O!sf", &(TopoShapePy::Type), &pcObjShape,
00110                                            &(Base::VectorPy::Type), &pcObjDir, &type, &scale))
00111         return NULL;
00112 
00113     PY_TRY {
00114         TopoShapePy* pShape = static_cast<TopoShapePy*>(pcObjShape);
00115         Base::Vector3d Vector(0,0,1);
00116         if (pcObjDir)
00117             Vector = static_cast<Base::VectorPy*>(pcObjDir)->value();
00118         ProjectionAlgos Alg(pShape->getTopoShapePtr()->_Shape,Base::Vector3f((float)Vector.x,(float)Vector.y,(float)Vector.z));
00119 
00120         bool hidden = false;
00121         if (type && std::string(type) == "ShowHiddenLines")
00122             hidden = true;
00123 
00124         Py::String result(Alg.getSVG(hidden?ProjectionAlgos::WithHidden:ProjectionAlgos::Plain, scale));
00125         return Py::new_reference_to(result);
00126 
00127     } PY_CATCH;
00128 }
00129 
00130 static PyObject * 
00131 projectToDXF(PyObject *self, PyObject *args)
00132 {
00133     PyObject *pcObjShape;
00134     PyObject *pcObjDir=0;
00135     const char *type=0;
00136     float scale=1.0f;
00137 
00138     if (!PyArg_ParseTuple(args, "O!|O!sf", &(TopoShapePy::Type), &pcObjShape,
00139                                            &(Base::VectorPy::Type), &pcObjDir, &type, &scale))
00140         return NULL;
00141 
00142     PY_TRY {
00143         TopoShapePy* pShape = static_cast<TopoShapePy*>(pcObjShape);
00144         Base::Vector3d Vector(0,0,1);
00145         if (pcObjDir)
00146             Vector = static_cast<Base::VectorPy*>(pcObjDir)->value();
00147         ProjectionAlgos Alg(pShape->getTopoShapePtr()->_Shape,Base::Vector3f((float)Vector.x,(float)Vector.y,(float)Vector.z));
00148 
00149         bool hidden = false;
00150         if (type && std::string(type) == "ShowHiddenLines")
00151             hidden = true;
00152 
00153         Py::String result(Alg.getDXF(hidden?ProjectionAlgos::WithHidden:ProjectionAlgos::Plain, scale));
00154         return Py::new_reference_to(result);
00155 
00156     } PY_CATCH;
00157 }
00158 
00159 
00160 
00161 /* registration table  */
00162 struct PyMethodDef Drawing_methods[] = {
00163    {"project"       ,project      ,METH_VARARGS,
00164      "[visiblyG0,visiblyG1,hiddenG0,hiddenG1] = project(TopoShape[,App.Vector Direction, string type]) -- Project a shape and return the visible/invisible parts of it."},
00165    {"projectEx"       ,projectEx      ,METH_VARARGS,
00166      "[V,V1,VN,VO,VI,H,H1,HN,HO,HI] = projectEx(TopoShape[,App.Vector Direction, string type]) -- Project a shape and return the all parts of it."},
00167    {"projectToSVG"       ,projectToSVG      ,METH_VARARGS,
00168      "string = projectToSVG(TopoShape[,App.Vector Direction, string type]) -- Project a shape and return the SVG representation as string."},
00169    {"projectToDXF"       ,projectToDXF      ,METH_VARARGS,
00170      "string = projectToDXF(TopoShape[,App.Vector Direction, string type]) -- Project a shape and return the DXF representation as string."},
00171     {NULL, NULL}        /* end of table marker */
00172 };

Generated on Wed Nov 23 18:59:55 2011 for FreeCAD by  doxygen 1.6.1