AppImportPy.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
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
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
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
00077 App::Document *pcDoc = App::GetApplication().newDocument();
00078 App::AbstractFeature *pcFeature = pcDoc->addFeature("ImportIges","Iges Import");
00079 assert(0);
00080
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
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);
00107
00108 }
00109
00110
00111
00112
00113 struct PyMethodDef Import_methods[] = {
00114 {"open", open, 1},
00115 {"save", save, 1},
00116
00117 {NULL, NULL}
00118 };