AppPointsPy.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 #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
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
00057 if (file.extension() == "")
00058 Py_Error(PyExc_Exception,"no file ending");
00059
00060 if (file.hasExtension("asc")) {
00061
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
00090 if (file.extension() == "")
00091 Py_Error(PyExc_Exception,"no file ending");
00092
00093 if (file.hasExtension("asc")) {
00094
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))
00118 return NULL;
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
00127
00128 pcFeature->Points.setValue(*(pPoints->getPointKernelPtr()));
00129
00130 } PY_CATCH;
00131
00132 Py_Return;
00133 }
00134
00135
00136 struct PyMethodDef Points_Import_methods[] = {
00137 {"open", open, 1},
00138 {"insert",insert, 1},
00139 {"show",show, 1},
00140
00141 {NULL, NULL}
00142 };