AppPointsPy.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) Juergen Riegel         <juergen.riegel@web.de>          *
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 #endif
00027 
00028 #include <Base/Console.h>
00029 #include <Base/Interpreter.h>
00030 #include <Base/FileInfo.h>
00031 
00032 #include <App/Application.h>
00033 #include <App/Document.h>
00034 #include <App/DocumentObject.h>
00035 #include <App/Property.h>
00036 
00037 #include "Points.h"
00038 #include "PointsPy.h"
00039 #include "PointsAlgos.h"
00040 #include "FeaturePointsImportAscii.h"
00041 
00042 using namespace Points;
00043 
00044 /* module functions */
00045 static PyObject *
00046 open(PyObject *self, PyObject *args)
00047 {
00048     const char* Name;
00049     if (! PyArg_ParseTuple(args, "s",&Name))
00050         return NULL;
00051 
00052     PY_TRY {
00053         Base::Console().Log("Open in Points with %s",Name);
00054         Base::FileInfo file(Name);
00055 
00056         // extract ending
00057         if (file.extension() == "")
00058             Py_Error(PyExc_Exception,"no file ending");
00059 
00060         if (file.hasExtension("asc")) {
00061             // create new document and add Import feature
00062             App::Document *pcDoc = App::GetApplication().newDocument("Unnamed");
00063             Points::Feature *pcFeature = (Points::Feature *)pcDoc->addObject("Points::Feature", file.fileNamePure().c_str());
00064             Points::PointKernel pkTemp;
00065             pkTemp.load(Name);
00066             pcFeature->Points.setValue( pkTemp );
00067 
00068         }
00069         else {
00070             Py_Error(PyExc_Exception,"unknown file ending");
00071         }
00072     } PY_CATCH;
00073 
00074     Py_Return;
00075 }
00076 
00077 static PyObject *
00078 insert(PyObject *self, PyObject *args)
00079 {
00080     const char* Name;
00081     const char* DocName;
00082     if (!PyArg_ParseTuple(args, "ss",&Name,&DocName))
00083         return NULL;
00084 
00085     PY_TRY {
00086         Base::Console().Log("Import in Points with %s",Name);
00087         Base::FileInfo file(Name);
00088 
00089         // extract ending
00090         if (file.extension() == "")
00091             Py_Error(PyExc_Exception,"no file ending");
00092 
00093         if (file.hasExtension("asc")) {
00094             // add Import feature
00095             App::Document *pcDoc = App::GetApplication().getDocument(DocName);
00096             if (!pcDoc) {
00097                 pcDoc = App::GetApplication().newDocument(DocName);
00098             }
00099 
00100             Points::Feature *pcFeature = (Points::Feature *)pcDoc->addObject("Points::Feature", file.fileNamePure().c_str());
00101             Points::PointKernel pkTemp;
00102             pkTemp.load(Name);
00103             pcFeature->Points.setValue( pkTemp );
00104         }
00105         else {
00106             Py_Error(PyExc_Exception,"unknown file ending");
00107         }
00108     } PY_CATCH;
00109 
00110     Py_Return;
00111 }
00112 
00113 static PyObject * 
00114 show(PyObject *self, PyObject *args)
00115 {
00116     PyObject *pcObj;
00117     if (!PyArg_ParseTuple(args, "O!", &(PointsPy::Type), &pcObj))     // convert args: Python->C
00118         return NULL;                             // NULL triggers exception
00119 
00120     PY_TRY {
00121         App::Document *pcDoc = App::GetApplication().getActiveDocument();        
00122         if (!pcDoc)
00123             pcDoc = App::GetApplication().newDocument();
00124         PointsPy* pPoints = static_cast<PointsPy*>(pcObj);
00125         Points::Feature *pcFeature = (Points::Feature *)pcDoc->addObject("Points::Feature", "Points");
00126         // copy the data
00127         //TopoShape* shape = new MeshObject(*pShape->getTopoShapeObjectPtr());
00128         pcFeature->Points.setValue(*(pPoints->getPointKernelPtr()));
00129         //pcDoc->recompute();
00130     } PY_CATCH;
00131 
00132     Py_Return;
00133 }
00134 
00135 // registration table  
00136 struct PyMethodDef Points_Import_methods[] = {
00137     {"open",  open,   1},                               /* method name, C func ptr, always-tuple */
00138     {"insert",insert, 1},
00139     {"show",show, 1},
00140 
00141     {NULL, NULL}                /* end of table marker */
00142 };

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