Skip to content

Commit

Permalink
JtReader: allow to open JT files using TKJT
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Nov 9, 2023
1 parent ba95a53 commit 640018b
Show file tree
Hide file tree
Showing 4 changed files with 401 additions and 10 deletions.
48 changes: 38 additions & 10 deletions src/Mod/JtReader/App/AppJtReaderPy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <App/Application.h>
#include <App/Document.h>
#include <App/InventorObject.h>
#include <Base/Console.h>
#include <Base/FileInfo.h>
#include <Base/Interpreter.h>
Expand All @@ -34,6 +35,7 @@
#include <CXX/Extensions.hxx>

#include "TestJtReader.h"
#include "TKJtReader.h"


using std::vector;
Expand Down Expand Up @@ -64,9 +66,10 @@ class Module: public Py::ExtensionModule<Module>
}

private:
// NOLINTBEGIN
Py::Object read(const Py::Tuple& args)
{
char* Name;
char* Name {};
if (!PyArg_ParseTuple(args.ptr(), "et", "utf-8", &Name)) {
throw Py::Exception();
}
Expand All @@ -77,7 +80,7 @@ class Module: public Py::ExtensionModule<Module>
}
Py::Object open(const Py::Tuple& args)
{
char* Name;
char* Name {};
if (!PyArg_ParseTuple(args.ptr(), "et", "utf-8", &Name)) {
throw Py::Exception();
}
Expand All @@ -87,20 +90,33 @@ class Module: public Py::ExtensionModule<Module>


// Base::Console().Log("Open in Mesh with %s",Name);
Base::FileInfo file(EncodedName.c_str());
Base::FileInfo file(EncodedName);
if (file.hasExtension("jt")) {
TestJtReader reader;
reader.setFile(EncodedName.c_str());
reader.setFile(EncodedName);
reader.read();

#ifdef JTREADER_HAVE_TKJT
JtReaderNS::TKJtReader jtReader;
jtReader.open(EncodedName);

App::Document* doc = App::GetApplication().newDocument();
std::string objname = file.fileNamePure();
auto iv = dynamic_cast<App::InventorObject*>(
doc->addObject("App::InventorObject", objname.c_str()));
iv->Buffer.setValue(jtReader.getOutput());
iv->purgeTouched();
#endif

return Py::None();
}

throw Py::RuntimeError("unknown file ending");
}
Py::Object importer(const Py::Tuple& args)
{
char* Name;
const char* DocName;
char* Name {};
const char* DocName {};
if (!PyArg_ParseTuple(args.ptr(), "ets", "utf-8", &Name, &DocName)) {
throw Py::Exception();
}
Expand All @@ -112,21 +128,33 @@ class Module: public Py::ExtensionModule<Module>

if (file.hasExtension("jt")) {
// add Import feature
App::Document* pcDoc = App::GetApplication().getDocument(DocName);
if (!pcDoc) {
pcDoc = App::GetApplication().newDocument(DocName);
App::Document* doc = App::GetApplication().getDocument(DocName);
if (!doc) {
doc = App::GetApplication().newDocument(DocName);
}

#ifdef JTREADER_HAVE_TKJT
JtReaderNS::TKJtReader jtReader;
jtReader.open(EncodedName);

std::string objname = file.fileNamePure();
auto iv = dynamic_cast<App::InventorObject*>(
doc->addObject("App::InventorObject", objname.c_str()));
iv->Buffer.setValue(jtReader.getOutput());
iv->purgeTouched();
#endif

return Py::None();
}

throw Py::RuntimeError("unknown file ending");
}
// NOLINTEND
};

PyObject* initModule()
{
return Base::Interpreter().addModule(new Module);
return Base::Interpreter().addModule(new Module); // NOLINT
}

} // namespace JtReaderNS
17 changes: 17 additions & 0 deletions src/Mod/JtReader/App/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
set(JTREADER_TKJT_INCLUDE_DIRS CACHE PATH "Include directory of TKJT headers")
set(JTREADER_TKJT_LIBRARIES CACHE FILEPATH "File path to TKJT library")

include_directories(
${CMAKE_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}
Expand All @@ -12,6 +15,7 @@ link_directories(${OCC_LIBRARY_DIR})

set(JtReader_LIBS
Mesh
${OCC_LIBRARIES}
#${OCC_OCAF_LIBRARIES}
#${OCC_OCAF_DEBUG_LIBRARIES}
)
Expand All @@ -27,6 +31,19 @@ SET(JtReader_SRCS
FcLodHandler.cpp
)

if (EXISTS "${JTREADER_TKJT_INCLUDE_DIRS}/JtData_Object.hxx")
add_definitions(-DJTREADER_HAVE_TKJT)
include_directories(${JTREADER_TKJT_INCLUDE_DIRS})
list (APPEND JtReader_LIBS
${JTREADER_TKJT_LIBRARIES}
)

list (APPEND JtReader_SRCS
TKJtReader.cpp
TKJtReader.h
)
endif ()

set (JtReader_Scripts
../Init.py
)
Expand Down
Loading

0 comments on commit 640018b

Please sign in to comment.