AppImportPy.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   (c) Jürgen Riegel (juergen.riegel@web.de) 2002                        *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This program is free software; you can redistribute it and/or modify  *
00007  *   it under the terms of the GNU Library General Public License (LGPL)   *
00008  *   as published by the Free Software Foundation; either version 2 of     *
00009  *   the License, or (at your option) any later version.                   *
00010  *   for detail see the LICENCE text file.                                 *
00011  *                                                                         *
00012  *   FreeCAD is distributed in the hope that it will be useful,            *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU Library General Public License for more details.                  *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU Library General Public     *
00018  *   License along with FreeCAD; if not, write to the Free Software        *
00019  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
00020  *   USA                                                                   *
00021  *                                                                         *
00022  *   Juergen Riegel 2002                                                   *
00023  ***************************************************************************/
00024 
00025 
00026 #include "PreCompiled.h"
00027 #ifndef _PreComp_
00028 #       include <stdio.h>
00029 # if defined (_POSIX_C_SOURCE)
00030 #   undef  _POSIX_C_SOURCE
00031 # endif // (re-)defined in pyconfig.h
00032 #       include <Python.h>
00033 # include <BRep_Builder.hxx>
00034 # include <BRepTools.hxx>
00035 #endif
00036 
00037 #include <Base/Console.h>
00038 #include <Base/Interpreter.h>
00039 
00040 #include <App/Application.h>
00041 #include <App/Document.h>
00042 #include <App/Feature.h>
00043 #include <App/Property.h>
00044 #include <Mod/Part/App/TopologyPy.h>
00045 
00046 
00047 
00048 /* module functions */
00049 static PyObject *
00050 open(PyObject *self, PyObject *args)
00051 {
00052   const char* Name;
00053   if (! PyArg_ParseTuple(args, "s",&Name))
00054     return NULL;
00055 
00056   Base::Console().Log("Open in Import with %s",Name);
00057 
00058   // extract ending
00059   std::string cEnding(Name);
00060   unsigned int pos = cEnding.find_last_of('.');
00061   if(pos == cEnding.size())
00062     Py_Error(PyExc_Exception,"no file ending");
00063   cEnding.erase(0,pos+1);
00064 
00065   if(cEnding == "stp" || cEnding == "step")
00066   {
00067     // create new document and add Import feature
00068     App::Document *pcDoc = App::GetApplication().newDocument();
00069     App::AbstractFeature *pcFeature = pcDoc->addFeature("ImportStep","Step Import");
00070     pcFeature->setPropertyString (Name,"FileName");
00071     pcFeature->TouchProperty("FileName");
00072     pcDoc->recompute();
00073 
00074   }else if(cEnding == "igs" || cEnding == "iges")
00075   {
00076     // create new document and add Import feature
00077     App::Document *pcDoc = App::GetApplication().newDocument();
00078     App::AbstractFeature *pcFeature = pcDoc->addFeature("ImportIges","Iges Import");
00079 assert(0);
00080 //    pcFeature->GetProperty("FileName").Set(Name);
00081     pcFeature->TouchProperty("FileName");
00082     pcDoc->recompute();
00083 
00084   }else
00085 
00086     Py_Error(PyExc_Exception,"unknown file ending");
00087 
00088 
00089         Py_Return;
00090 }
00091 
00092 /* module functions */
00093 static PyObject *
00094 save(PyObject *self, PyObject *args)
00095 {
00096         char* str;
00097 
00098     if (! PyArg_ParseTuple(args, "s",&str))
00099         return NULL;
00100 
00101         TopoDS_Shape ResultShape;
00102         BRep_Builder aBuilder;
00103 
00104         BRepTools::Read(ResultShape,(const Standard_CString)str,aBuilder);
00105 
00106   return new Part::TopoShapePy(ResultShape);              /* convert C -> Python */
00107 
00108 }
00109 
00110 
00111 
00112 /* registration table  */
00113 struct PyMethodDef Import_methods[] = {
00114     {"open", open, 1},                          /* method name, C func ptr, always-tuple */
00115     {"save", save, 1},
00116 
00117     {NULL, NULL}                   /* end of table marker */
00118 };

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