AppJtReaderPy.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 #include "PreCompiled.h"
00024 #ifndef _PreComp_
00025 #endif
00026
00027
00028 #include <Python.h>
00029
00030 #include <Base/Console.h>
00031 #include <Base/FileInfo.h>
00032
00033 #include <App/Application.h>
00034 #include <App/Document.h>
00035
00036 #include <Mod/Mesh/App/Core/MeshKernel.h>
00037 #include <Mod/Mesh/App/Core/Elements.h>
00038 #include <Mod/Mesh/App/MeshPy.h>
00039 #include <Mod/Mesh/App/MeshPy.h>
00040 #include <Mod/Mesh/App/MeshFeature.h>
00041
00042 #include "JtReader.h"
00043
00044 using std::vector;
00045 using namespace MeshCore;
00046
00047
00048
00049
00050
00051 static PyObject * read(PyObject *self, PyObject *args)
00052 {
00053 const char* Name;
00054 if (! PyArg_ParseTuple(args, "s",&Name))
00055 return NULL;
00056
00057 PY_TRY {
00058
00059 std::auto_ptr<MeshCore::MeshKernel> apcKernel(new MeshCore::MeshKernel());
00060
00061 readFile(Name,0);
00062
00063 vector<MeshGeomFacet> facets;
00064 facets.resize(iterSize());
00065
00066 const SimpleMeshFacet* It=iterStart();
00067 int i=0;
00068 while(It=iterGetNext())
00069 {
00070 facets[i]._aclPoints[0].x = It->p1[0];
00071 facets[i]._aclPoints[0].y = It->p1[1];
00072 facets[i]._aclPoints[0].z = It->p1[2];
00073 facets[i]._aclPoints[1].x = It->p2[0];
00074 facets[i]._aclPoints[1].y = It->p2[1];
00075 facets[i]._aclPoints[1].z = It->p2[2];
00076 facets[i]._aclPoints[2].x = It->p3[0];
00077 facets[i]._aclPoints[2].y = It->p3[1];
00078 facets[i]._aclPoints[2].z = It->p3[2];
00079 }
00080 clearData();
00081 (*apcKernel) = facets;
00082
00083 return new Mesh::MeshPy(new Mesh::MeshObject(*(apcKernel.release())));
00084
00085 } PY_CATCH;
00086
00087 Py_Return;
00088 }
00089
00090 static PyObject *
00091 open(PyObject *self, PyObject *args)
00092 {
00093 const char* Name;
00094 if (! PyArg_ParseTuple(args, "s",&Name))
00095 return NULL;
00096
00097 PY_TRY {
00098
00099
00100 Base::FileInfo file(Name);
00101
00102
00103 if(file.extension() == "")
00104 Py_Error(PyExc_Exception,"no file ending");
00105
00106 if(file.hasExtension("jt"))
00107 {
00108
00109 App::Document *pcDoc = App::GetApplication().newDocument("Unnamed");
00110 Mesh::Feature *pcFeature = (Mesh::Feature*)pcDoc->addObject("Mesh::Feature",file.fileNamePure().c_str());
00111
00112 std::auto_ptr<MeshCore::MeshKernel> apcKernel(new MeshCore::MeshKernel());
00113
00114 readFile(Name,0);
00115
00116 vector<MeshGeomFacet> facets;
00117 facets.resize(iterSize());
00118
00119 const SimpleMeshFacet* It=iterStart();
00120 int i=0;
00121 while(It=iterGetNext())
00122 {
00123 facets[i]._aclPoints[0].x = It->p1[0];
00124 facets[i]._aclPoints[0].y = It->p1[1];
00125 facets[i]._aclPoints[0].z = It->p1[2];
00126 facets[i]._aclPoints[1].x = It->p2[0];
00127 facets[i]._aclPoints[1].y = It->p2[1];
00128 facets[i]._aclPoints[1].z = It->p2[2];
00129 facets[i]._aclPoints[2].x = It->p3[0];
00130 facets[i]._aclPoints[2].y = It->p3[1];
00131 facets[i]._aclPoints[2].z = It->p3[2];
00132 i++;
00133 }
00134 clearData();
00135 (*apcKernel) = facets;
00136 pcFeature->Mesh.setValue(*(apcKernel.get()));
00137
00138
00139 pcDoc->recompute();
00140 }
00141 else
00142 {
00143 Py_Error(PyExc_Exception,"unknown file ending");
00144 }
00145
00146
00147 } PY_CATCH;
00148
00149 Py_Return;
00150 }
00151
00152
00153
00154 static PyObject *
00155 insert(PyObject *self, PyObject *args)
00156 {
00157 const char* Name;
00158 const char* DocName;
00159 if (! PyArg_ParseTuple(args, "ss",&Name,&DocName))
00160 return NULL;
00161
00162 PY_TRY {
00163
00164 Base::FileInfo file(Name);
00165
00166
00167 if(file.extension() == "")
00168 Py_Error(PyExc_Exception,"no file ending");
00169
00170 if(file.hasExtension("jt") )
00171 {
00172
00173 App::Document *pcDoc = App::GetApplication().getDocument(DocName);
00174 if (!pcDoc)
00175 {
00176 char szBuf[200];
00177 snprintf(szBuf, 200, "Import called to the non-existing document '%s'", DocName);
00178 Py_Error(PyExc_Exception,szBuf);
00179 }
00180
00181 readFile(Name,0);
00182
00183 vector<MeshGeomFacet> facets;
00184
00185 if(iterSize()>0){
00186 facets.resize(iterSize());
00187
00188 const SimpleMeshFacet* It=iterStart();
00189 int i=0;
00190 while(It=iterGetNext())
00191 {
00192 facets[i]._aclPoints[0].x = It->p1[0];
00193 facets[i]._aclPoints[0].y = It->p1[1];
00194 facets[i]._aclPoints[0].z = It->p1[2];
00195 facets[i]._aclPoints[1].x = It->p2[0];
00196 facets[i]._aclPoints[1].y = It->p2[1];
00197 facets[i]._aclPoints[1].z = It->p2[2];
00198 facets[i]._aclPoints[2].x = It->p3[0];
00199 facets[i]._aclPoints[2].y = It->p3[1];
00200 facets[i]._aclPoints[2].z = It->p3[2];
00201 i++;
00202 }
00203 clearData();
00204 Mesh::Feature *pcFeature = (Mesh::Feature*)pcDoc->addObject("Mesh::Feature",file.fileNamePure().c_str());
00205
00206 std::auto_ptr<MeshCore::MeshKernel> apcKernel(new MeshCore::MeshKernel());
00207 (*apcKernel) = facets;
00208 pcFeature->Mesh.setValue(*(apcKernel.get()));
00209
00210
00211
00212 }else{
00213 clearData();
00214
00215 Base::Console().Warning("No Mesh in file: %s\n",Name);
00216 }
00217 }
00218 else
00219 {
00220 Py_Error(PyExc_Exception,"unknown file ending");
00221 }
00222
00223 } PY_CATCH;
00224
00225 Py_Return;
00226 }
00227
00228
00229
00230 struct PyMethodDef JtReader_methods[] = {
00231 {"open" ,open , Py_NEWARGS, "open a jt file in a new Document"},
00232 {"insert" ,insert, Py_NEWARGS, "isert a jt file in a existing document"},
00233 {"read" ,read, Py_NEWARGS, "Read a Mesh from a jt file and returns a Mesh object."},
00234 {NULL, NULL}
00235 };
00236
00237