JT: clean-up module and move to PyCXX API
This commit is contained in:
@@ -24,18 +24,16 @@
|
||||
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Interpreter.h>
|
||||
#include <Base/PyObjectBase.h>
|
||||
|
||||
|
||||
extern struct PyMethodDef JtReader_methods[];
|
||||
|
||||
|
||||
extern "C" {
|
||||
void AppJtReaderExport initJtReader()
|
||||
namespace JtReaderNS
|
||||
{
|
||||
extern PyObject* initModule();
|
||||
}
|
||||
|
||||
static struct PyModuleDef JtReaderAPIDef =
|
||||
{PyModuleDef_HEAD_INIT, "JtReader", 0, -1, JtReader_methods, NULL, NULL, NULL, NULL};
|
||||
PyModule_Create(&JtReaderAPIDef);
|
||||
PyMOD_INIT_FUNC(JtReader)
|
||||
{
|
||||
PyObject* jtReaderModule = JtReaderNS::initModule();
|
||||
|
||||
// load dependent module
|
||||
Base::Interpreter().loadModule("Mesh");
|
||||
@@ -52,8 +50,5 @@ void AppJtReaderExport initJtReader()
|
||||
|
||||
Base::Console().Log("Loading JtReader module... done\n");
|
||||
|
||||
return;
|
||||
PyMOD_Return(jtReaderModule);
|
||||
}
|
||||
|
||||
|
||||
} // extern "C" {
|
||||
|
||||
@@ -26,209 +26,107 @@
|
||||
#include <App/Document.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/FileInfo.h>
|
||||
#include <Base/Interpreter.h>
|
||||
#include <Base/PyObjectBase.h>
|
||||
#include <Mod/Mesh/App/Core/MeshKernel.h>
|
||||
#include <Mod/Mesh/App/MeshPy.h>
|
||||
|
||||
#include <CXX/Extensions.hxx>
|
||||
|
||||
#include "TestJtReader.h"
|
||||
|
||||
|
||||
using std::vector;
|
||||
using namespace MeshCore;
|
||||
|
||||
// using namespace JtReader;
|
||||
|
||||
/* module functions */
|
||||
static PyObject* read(PyObject* /*self*/, PyObject* args)
|
||||
namespace JtReaderNS
|
||||
{
|
||||
char* Name;
|
||||
if (!PyArg_ParseTuple(args, "et", "utf-8", &Name)) {
|
||||
return NULL;
|
||||
}
|
||||
std::string EncodedName = std::string(Name);
|
||||
PyMem_Free(Name);
|
||||
|
||||
PY_TRY
|
||||
{
|
||||
// std::auto_ptr<MeshCore::MeshKernel> apcKernel(new MeshCore::MeshKernel());
|
||||
|
||||
// vector<MeshGeomFacet> facets;
|
||||
// facets.resize(0 /* some size*/);
|
||||
|
||||
// const SimpleMeshFacet* It=iterStart();
|
||||
// int i=0;
|
||||
// while(It=iterGetNext())
|
||||
//{
|
||||
// facets[i]._aclPoints[0].x = It->p1[0];
|
||||
// facets[i]._aclPoints[0].y = It->p1[1];
|
||||
// facets[i]._aclPoints[0].z = It->p1[2];
|
||||
// facets[i]._aclPoints[1].x = It->p2[0];
|
||||
// facets[i]._aclPoints[1].y = It->p2[1];
|
||||
// facets[i]._aclPoints[1].z = It->p2[2];
|
||||
// facets[i]._aclPoints[2].x = It->p3[0];
|
||||
// facets[i]._aclPoints[2].y = It->p3[1];
|
||||
// facets[i]._aclPoints[2].z = It->p3[2];
|
||||
// }
|
||||
|
||||
//(*apcKernel) = facets;
|
||||
|
||||
// return new Mesh::MeshPy(new Mesh::MeshObject(*(apcKernel.release())));
|
||||
}
|
||||
PY_CATCH;
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
static PyObject* open(PyObject* /*self*/, PyObject* args)
|
||||
class Module: public Py::ExtensionModule<Module>
|
||||
{
|
||||
char* Name;
|
||||
if (!PyArg_ParseTuple(args, "et", "utf-8", &Name)) {
|
||||
return NULL;
|
||||
}
|
||||
std::string EncodedName = std::string(Name);
|
||||
PyMem_Free(Name);
|
||||
|
||||
PY_TRY
|
||||
public:
|
||||
Module()
|
||||
: Py::ExtensionModule<Module>("JtReader")
|
||||
{
|
||||
add_varargs_method("read",
|
||||
&Module::read,
|
||||
"Read the mesh from a JT file and return a mesh object.");
|
||||
add_varargs_method("open",
|
||||
&Module::open,
|
||||
"open(string)\n"
|
||||
"Create a new document and load the JT file into\n"
|
||||
"the document.");
|
||||
add_varargs_method("insert",
|
||||
&Module::importer,
|
||||
"insert(string|mesh,[string])\n"
|
||||
"Load or insert a JT file into the given or active document.");
|
||||
initialize("This module is the JtReader module.");
|
||||
}
|
||||
|
||||
private:
|
||||
Py::Object read(const Py::Tuple& args)
|
||||
{
|
||||
char* Name;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "et", "utf-8", &Name)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
|
||||
std::string EncodedName = std::string(Name);
|
||||
PyMem_Free(Name);
|
||||
return Py::None();
|
||||
}
|
||||
Py::Object open(const Py::Tuple& args)
|
||||
{
|
||||
char* Name;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "et", "utf-8", &Name)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
|
||||
std::string EncodedName = std::string(Name);
|
||||
PyMem_Free(Name);
|
||||
|
||||
|
||||
// Base::Console().Log("Open in Mesh with %s",Name);
|
||||
Base::FileInfo file(EncodedName.c_str());
|
||||
|
||||
// extract ending
|
||||
if (file.extension() == "") {
|
||||
Py_Error(Base::PyExc_FC_GeneralError, "no file ending");
|
||||
}
|
||||
|
||||
if (file.hasExtension("jt")) {
|
||||
TestJtReader reader;
|
||||
reader.setFile(EncodedName.c_str());
|
||||
reader.read();
|
||||
|
||||
// create new document and add Import feature
|
||||
// App::Document *pcDoc = App::GetApplication().newDocument("Unnamed");
|
||||
// Mesh::Feature *pcFeature =
|
||||
// (Mesh::Feature*)pcDoc->addObject("Mesh::Feature",file.fileNamePure().c_str());
|
||||
//
|
||||
// std::auto_ptr<MeshCore::MeshKernel> apcKernel(new MeshCore::MeshKernel());
|
||||
|
||||
// readFile(EncodedName.c_str(),0);
|
||||
|
||||
// vector<MeshGeomFacet> facets;
|
||||
// facets.resize(iterSize());
|
||||
|
||||
// const SimpleMeshFacet* It=iterStart();
|
||||
// int i=0;
|
||||
// while(It=iterGetNext())
|
||||
// {
|
||||
// facets[i]._aclPoints[0].x = It->p1[0];
|
||||
// facets[i]._aclPoints[0].y = It->p1[1];
|
||||
// facets[i]._aclPoints[0].z = It->p1[2];
|
||||
// facets[i]._aclPoints[1].x = It->p2[0];
|
||||
// facets[i]._aclPoints[1].y = It->p2[1];
|
||||
// facets[i]._aclPoints[1].z = It->p2[2];
|
||||
// facets[i]._aclPoints[2].x = It->p3[0];
|
||||
// facets[i]._aclPoints[2].y = It->p3[1];
|
||||
// facets[i]._aclPoints[2].z = It->p3[2];
|
||||
// i++;
|
||||
// }
|
||||
// clearData();
|
||||
// (*apcKernel) = facets;
|
||||
// pcFeature->Mesh.setValue(*(apcKernel.get()));
|
||||
|
||||
////pcFeature->FileName.setValue( Name );
|
||||
// pcDoc->recompute();
|
||||
}
|
||||
else {
|
||||
Py_Error(Base::PyExc_FC_GeneralError, "unknown file ending");
|
||||
return Py::None();
|
||||
}
|
||||
|
||||
throw Py::RuntimeError("unknown file ending");
|
||||
}
|
||||
PY_CATCH;
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
|
||||
/* module functions */
|
||||
static PyObject* insert(PyObject* /*self*/, PyObject* args)
|
||||
{
|
||||
char* Name;
|
||||
const char* DocName;
|
||||
if (!PyArg_ParseTuple(args, "ets", "utf-8", &Name, &DocName)) {
|
||||
return NULL;
|
||||
}
|
||||
std::string EncodedName = std::string(Name);
|
||||
PyMem_Free(Name);
|
||||
|
||||
PY_TRY
|
||||
Py::Object importer(const Py::Tuple& args)
|
||||
{
|
||||
char* Name;
|
||||
const char* DocName;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "ets", "utf-8", &Name, &DocName)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
|
||||
std::string EncodedName = std::string(Name);
|
||||
PyMem_Free(Name);
|
||||
|
||||
Base::FileInfo file(EncodedName.c_str());
|
||||
|
||||
// extract ending
|
||||
if (file.extension() == "") {
|
||||
Py_Error(Base::PyExc_FC_GeneralError, "no file ending");
|
||||
}
|
||||
|
||||
if (file.hasExtension("jt")) {
|
||||
// add Import feature
|
||||
App::Document* pcDoc = App::GetApplication().getDocument(DocName);
|
||||
if (!pcDoc) {
|
||||
char szBuf[200];
|
||||
snprintf(szBuf, 200, "Import called to the non-existing document '%s'", DocName);
|
||||
Py_Error(Base::PyExc_FC_GeneralError, szBuf);
|
||||
pcDoc = App::GetApplication().newDocument(DocName);
|
||||
}
|
||||
|
||||
// readFile(EncodedName.c_str(),0);
|
||||
|
||||
// vector<MeshGeomFacet> facets;
|
||||
|
||||
// if(iterSize()>0){
|
||||
// facets.resize(iterSize());
|
||||
|
||||
// const SimpleMeshFacet* It=iterStart();
|
||||
// int i=0;
|
||||
// while(It=iterGetNext())
|
||||
// {
|
||||
// facets[i]._aclPoints[0].x = It->p1[0];
|
||||
// facets[i]._aclPoints[0].y = It->p1[1];
|
||||
// facets[i]._aclPoints[0].z = It->p1[2];
|
||||
// facets[i]._aclPoints[1].x = It->p2[0];
|
||||
// facets[i]._aclPoints[1].y = It->p2[1];
|
||||
// facets[i]._aclPoints[1].z = It->p2[2];
|
||||
// facets[i]._aclPoints[2].x = It->p3[0];
|
||||
// facets[i]._aclPoints[2].y = It->p3[1];
|
||||
// facets[i]._aclPoints[2].z = It->p3[2];
|
||||
// i++;
|
||||
// }
|
||||
// clearData();
|
||||
// Mesh::Feature *pcFeature =
|
||||
// (Mesh::Feature*)pcDoc->addObject("Mesh::Feature",file.fileNamePure().c_str());
|
||||
//
|
||||
// std::auto_ptr<MeshCore::MeshKernel> apcKernel(new MeshCore::MeshKernel());
|
||||
// (*apcKernel) = facets;
|
||||
// pcFeature->Mesh.setValue(*(apcKernel.get()));
|
||||
|
||||
// //pcDoc->recompute();
|
||||
|
||||
//}else{
|
||||
// clearData();
|
||||
// //Py_Error(Base::BaseExceptionFreeCADError,"No Mesh in file");
|
||||
// Base::Console().Warning("No Mesh in file: %s\n",EncodedName.c_str());
|
||||
//}
|
||||
}
|
||||
else {
|
||||
Py_Error(Base::PyExc_FC_GeneralError, "unknown file ending");
|
||||
return Py::None();
|
||||
}
|
||||
|
||||
throw Py::RuntimeError("unknown file ending");
|
||||
}
|
||||
PY_CATCH;
|
||||
};
|
||||
|
||||
Py_Return;
|
||||
PyObject* initModule()
|
||||
{
|
||||
return Base::Interpreter().addModule(new Module);
|
||||
}
|
||||
|
||||
|
||||
/* registration table */
|
||||
struct PyMethodDef JtReader_methods[] = {
|
||||
{"open", open, Py_NEWARGS, "open a jt file in a new Document"},
|
||||
{"insert", insert, Py_NEWARGS, "isert a jt file in a existing document"},
|
||||
{"read", read, Py_NEWARGS, "Read a Mesh from a jt file and returns a Mesh object."},
|
||||
{NULL, NULL, 0, NULL}};
|
||||
} // namespace JtReaderNS
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#ifndef Context_HEADER
|
||||
#define Context_HEADER
|
||||
|
||||
#include "Context.h"
|
||||
#include <istream>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#ifndef I32_HEADER
|
||||
#define I32_HEADER
|
||||
|
||||
#include "Context.h"
|
||||
#include <istream>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#ifndef U16_HEADER
|
||||
#define U16_HEADER
|
||||
|
||||
#include "Context.h"
|
||||
#include <istream>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#ifndef U32_HEADER
|
||||
#define U32_HEADER
|
||||
|
||||
#include "Context.h"
|
||||
#include <istream>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user