issue #1027 use unicode filepaths
This commit is contained in:
parent
05af9207a3
commit
a53a239f2f
|
@ -1268,10 +1268,12 @@ void Application::processCmdLineFiles(void)
|
||||||
else {
|
else {
|
||||||
std::vector<std::string> mods = App::GetApplication().getImportModules(Ext.c_str());
|
std::vector<std::string> mods = App::GetApplication().getImportModules(Ext.c_str());
|
||||||
if (!mods.empty()) {
|
if (!mods.empty()) {
|
||||||
|
std::string escapedstr = Base::Tools::escapedUnicodeFromUtf8(File.filePath().c_str());
|
||||||
Base::Interpreter().loadModule(mods.front().c_str());
|
Base::Interpreter().loadModule(mods.front().c_str());
|
||||||
Base::Interpreter().runStringArg("import %s",mods.front().c_str());
|
Base::Interpreter().runStringArg("import %s",mods.front().c_str());
|
||||||
Base::Interpreter().runStringArg("%s.open(\"%s\")",mods.front().c_str(),File.filePath().c_str());
|
Base::Interpreter().runStringArg("%s.open(u\"%s\")",mods.front().c_str(),
|
||||||
Base::Console().Log("Command line open: %s.Open(\"%s\")\n",mods.front().c_str(),File.filePath().c_str());
|
escapedstr.c_str());
|
||||||
|
Base::Console().Log("Command line open: %s.open(u\"%s\")\n",mods.front().c_str(),escapedstr.c_str());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Console().Warning("File format not supported: %s \n", File.filePath().c_str());
|
Console().Warning("File format not supported: %s \n", File.filePath().c_str());
|
||||||
|
|
|
@ -180,12 +180,14 @@ PyObject* Application::sLoadFile(PyObject * /*self*/, PyObject *args,PyObject *
|
||||||
|
|
||||||
PyObject* Application::sOpenDocument(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/)
|
PyObject* Application::sOpenDocument(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/)
|
||||||
{
|
{
|
||||||
char *pstr;
|
char* Name;
|
||||||
if (!PyArg_ParseTuple(args, "s", &pstr)) // convert args: Python->C
|
if (!PyArg_ParseTuple(args, "et","utf-8",&Name))
|
||||||
return NULL; // NULL triggers exception
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
try {
|
try {
|
||||||
// return new document
|
// return new document
|
||||||
return (GetApplication().openDocument(pstr)->getPyObject());
|
return (GetApplication().openDocument(EncodedName.c_str())->getPyObject());
|
||||||
}
|
}
|
||||||
catch (const Base::Exception& e) {
|
catch (const Base::Exception& e) {
|
||||||
PyErr_SetString(PyExc_IOError, e.what());
|
PyErr_SetString(PyExc_IOError, e.what());
|
||||||
|
@ -193,7 +195,7 @@ PyObject* Application::sOpenDocument(PyObject * /*self*/, PyObject *args,PyObjec
|
||||||
}
|
}
|
||||||
catch (const std::exception& e) {
|
catch (const std::exception& e) {
|
||||||
// might be subclass from zipios
|
// might be subclass from zipios
|
||||||
PyErr_Format(PyExc_IOError, "Invalid project file %s: %s\n", pstr, e.what());
|
PyErr_Format(PyExc_IOError, "Invalid project file %s: %s\n", EncodedName.c_str(), e.what());
|
||||||
return 0L;
|
return 0L;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
# include <QTime>
|
# include <QTime>
|
||||||
|
#include <Python.h>
|
||||||
#include "Tools.h"
|
#include "Tools.h"
|
||||||
|
|
||||||
namespace Base {
|
namespace Base {
|
||||||
|
@ -142,6 +142,16 @@ std::string Base::Tools::narrow(const std::wstring& str)
|
||||||
return stm.str();
|
return stm.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Base::Tools::escapedUnicodeFromUtf8(const char *s)
|
||||||
|
{
|
||||||
|
PyObject* unicode = PyUnicode_FromString(s);
|
||||||
|
PyObject* escaped = PyUnicode_AsUnicodeEscapeString(unicode);
|
||||||
|
Py_DECREF(unicode);
|
||||||
|
std::string escapedstr = std::string(PyString_AsString(escaped));
|
||||||
|
Py_DECREF(escaped);
|
||||||
|
return escapedstr;
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
using namespace Base;
|
using namespace Base;
|
||||||
|
@ -191,3 +201,6 @@ std::string StopWatch::toString(int ms) const
|
||||||
str << msec << "ms";
|
str << msec << "ms";
|
||||||
return str.str();
|
return str.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -153,6 +153,7 @@ struct BaseExport Tools
|
||||||
static std::string getIdentifier(const std::string&);
|
static std::string getIdentifier(const std::string&);
|
||||||
static std::wstring widen(const std::string& str);
|
static std::wstring widen(const std::string& str);
|
||||||
static std::string narrow(const std::wstring& str);
|
static std::string narrow(const std::wstring& str);
|
||||||
|
static std::string escapedUnicodeFromUtf8(const char *s);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Base
|
} // namespace Base
|
||||||
|
|
|
@ -479,7 +479,7 @@ void Application::open(const char* FileName, const char* Module)
|
||||||
wc.setIgnoreEvents(WaitCursor::NoEvents);
|
wc.setIgnoreEvents(WaitCursor::NoEvents);
|
||||||
Base::FileInfo File(FileName);
|
Base::FileInfo File(FileName);
|
||||||
string te = File.extension();
|
string te = File.extension();
|
||||||
|
string unicodepath = Base::Tools::escapedUnicodeFromUtf8(File.filePath().c_str());
|
||||||
// if the active document is empty and not modified, close it
|
// if the active document is empty and not modified, close it
|
||||||
// in case of an automatically created empty document at startup
|
// in case of an automatically created empty document at startup
|
||||||
App::Document* act = App::GetApplication().getActiveDocument();
|
App::Document* act = App::GetApplication().getActiveDocument();
|
||||||
|
@ -494,7 +494,7 @@ void Application::open(const char* FileName, const char* Module)
|
||||||
Command::doCommand(Command::App, "import %s", Module);
|
Command::doCommand(Command::App, "import %s", Module);
|
||||||
try {
|
try {
|
||||||
// load the file with the module
|
// load the file with the module
|
||||||
Command::doCommand(Command::App, "%s.open(\"%s\")", Module, File.filePath().c_str());
|
Command::doCommand(Command::App, "%s.open(u\"%s\")", Module, unicodepath.c_str());
|
||||||
// ViewFit
|
// ViewFit
|
||||||
if (!File.hasExtension("FCStd") && sendHasMsgToActiveView("ViewFit")) {
|
if (!File.hasExtension("FCStd") && sendHasMsgToActiveView("ViewFit")) {
|
||||||
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath
|
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath
|
||||||
|
@ -525,6 +525,7 @@ void Application::importFrom(const char* FileName, const char* DocName, const ch
|
||||||
wc.setIgnoreEvents(WaitCursor::NoEvents);
|
wc.setIgnoreEvents(WaitCursor::NoEvents);
|
||||||
Base::FileInfo File(FileName);
|
Base::FileInfo File(FileName);
|
||||||
std::string te = File.extension();
|
std::string te = File.extension();
|
||||||
|
string unicodepath = Base::Tools::escapedUnicodeFromUtf8(File.filePath().c_str());
|
||||||
|
|
||||||
if (Module != 0) {
|
if (Module != 0) {
|
||||||
// issue module loading
|
// issue module loading
|
||||||
|
@ -533,14 +534,14 @@ void Application::importFrom(const char* FileName, const char* DocName, const ch
|
||||||
try {
|
try {
|
||||||
// load the file with the module
|
// load the file with the module
|
||||||
if (File.hasExtension("FCStd")) {
|
if (File.hasExtension("FCStd")) {
|
||||||
Command::doCommand(Command::App, "%s.open(\"%s\")"
|
Command::doCommand(Command::App, "%s.open(u\"%s\")"
|
||||||
, Module, File.filePath().c_str());
|
, Module, unicodepath.c_str());
|
||||||
if (activeDocument())
|
if (activeDocument())
|
||||||
activeDocument()->setModified(false);
|
activeDocument()->setModified(false);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Command::doCommand(Command::App, "%s.insert(\"%s\",\"%s\")"
|
Command::doCommand(Command::App, "%s.insert(u\"%s\",\"%s\")"
|
||||||
, Module, File.filePath().c_str(), DocName);
|
, Module, unicodepath.c_str(), DocName);
|
||||||
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath
|
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath
|
||||||
("User parameter:BaseApp/Preferences/View");
|
("User parameter:BaseApp/Preferences/View");
|
||||||
if (hGrp->GetBool("AutoFitToView", true))
|
if (hGrp->GetBool("AutoFitToView", true))
|
||||||
|
@ -570,6 +571,7 @@ void Application::exportTo(const char* FileName, const char* DocName, const char
|
||||||
WaitCursor wc;
|
WaitCursor wc;
|
||||||
Base::FileInfo File(FileName);
|
Base::FileInfo File(FileName);
|
||||||
std::string te = File.extension();
|
std::string te = File.extension();
|
||||||
|
string unicodepath = Base::Tools::escapedUnicodeFromUtf8(File.filePath().c_str());
|
||||||
|
|
||||||
if (Module != 0) {
|
if (Module != 0) {
|
||||||
try {
|
try {
|
||||||
|
@ -588,7 +590,7 @@ void Application::exportTo(const char* FileName, const char* DocName, const char
|
||||||
}
|
}
|
||||||
|
|
||||||
str << "import " << Module << std::endl;
|
str << "import " << Module << std::endl;
|
||||||
str << Module << ".export(__objs__,\"" << File.filePath() << "\")" << std::endl;
|
str << Module << ".export(__objs__,u\"" << unicodepath << "\")" << std::endl;
|
||||||
str << "del __objs__" << std::endl;
|
str << "del __objs__" << std::endl;
|
||||||
|
|
||||||
std::string code = str.str();
|
std::string code = str.str();
|
||||||
|
|
|
@ -233,11 +233,13 @@ PyObject* Application::sShowObject(PyObject * /*self*/, PyObject *args,PyObject
|
||||||
PyObject* Application::sOpen(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/)
|
PyObject* Application::sOpen(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/)
|
||||||
{
|
{
|
||||||
// only used to open Python files
|
// only used to open Python files
|
||||||
const char* Name;
|
char* Name;
|
||||||
if (!PyArg_ParseTuple(args, "s",&Name))
|
if (!PyArg_ParseTuple(args, "et","utf-8",&Name))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string Utf8Name = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
PY_TRY {
|
PY_TRY {
|
||||||
QString fileName = QString::fromUtf8(Name);
|
QString fileName = QString::fromUtf8(Utf8Name.c_str());
|
||||||
QFileInfo fi;
|
QFileInfo fi;
|
||||||
fi.setFile(fileName);
|
fi.setFile(fileName);
|
||||||
QString ext = fi.completeSuffix().toLower();
|
QString ext = fi.completeSuffix().toLower();
|
||||||
|
@ -291,13 +293,15 @@ PyObject* Application::sOpen(PyObject * /*self*/, PyObject *args,PyObject * /*kw
|
||||||
|
|
||||||
PyObject* Application::sInsert(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/)
|
PyObject* Application::sInsert(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/)
|
||||||
{
|
{
|
||||||
const char* Name;
|
char* Name;
|
||||||
const char* DocName=0;
|
char* DocName=0;
|
||||||
if (!PyArg_ParseTuple(args, "s|s",&Name,&DocName))
|
if (!PyArg_ParseTuple(args, "et|s","utf-8",&Name,&DocName))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string Utf8Name = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
PY_TRY {
|
PY_TRY {
|
||||||
QString fileName = QString::fromUtf8(Name);
|
QString fileName = QString::fromUtf8(Utf8Name.c_str());
|
||||||
QFileInfo fi;
|
QFileInfo fi;
|
||||||
fi.setFile(fileName);
|
fi.setFile(fileName);
|
||||||
QString ext = fi.completeSuffix().toLower();
|
QString ext = fi.completeSuffix().toLower();
|
||||||
|
@ -352,9 +356,11 @@ PyObject* Application::sInsert(PyObject * /*self*/, PyObject *args,PyObject * /*
|
||||||
PyObject* Application::sExport(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/)
|
PyObject* Application::sExport(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/)
|
||||||
{
|
{
|
||||||
PyObject* object;
|
PyObject* object;
|
||||||
const char* filename;
|
char* Name;
|
||||||
if (!PyArg_ParseTuple(args, "Os",&object,&filename))
|
if (!PyArg_ParseTuple(args, "Oet",&object,"utf-8",&Name))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string Utf8Name = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
PY_TRY {
|
PY_TRY {
|
||||||
App::Document* doc = 0;
|
App::Document* doc = 0;
|
||||||
|
@ -370,7 +376,7 @@ PyObject* Application::sExport(PyObject * /*self*/, PyObject *args,PyObject * /*
|
||||||
|
|
||||||
// get the view that belongs to the found document
|
// get the view that belongs to the found document
|
||||||
if (doc) {
|
if (doc) {
|
||||||
QString fileName = QString::fromUtf8(filename);
|
QString fileName = QString::fromUtf8(Utf8Name.c_str());
|
||||||
QFileInfo fi;
|
QFileInfo fi;
|
||||||
fi.setFile(fileName);
|
fi.setFile(fileName);
|
||||||
QString ext = fi.completeSuffix().toLower();
|
QString ext = fi.completeSuffix().toLower();
|
||||||
|
@ -687,9 +693,10 @@ PyObject* Application::sActiveWorkbenchHandler(PyObject * /*self*/, PyObject *ar
|
||||||
PyObject* Application::sAddResPath(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/)
|
PyObject* Application::sAddResPath(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/)
|
||||||
{
|
{
|
||||||
char* filePath;
|
char* filePath;
|
||||||
if (!PyArg_ParseTuple(args, "s", &filePath)) // convert args: Python->C
|
if (!PyArg_ParseTuple(args, "et", "utf-8", &filePath)) // convert args: Python->C
|
||||||
return NULL; // NULL triggers exception
|
return NULL; // NULL triggers exception
|
||||||
QString path = QString::fromUtf8(filePath);
|
QString path = QString::fromUtf8(filePath);
|
||||||
|
PyMem_Free(filePath);
|
||||||
if (QDir::isRelativePath(path)) {
|
if (QDir::isRelativePath(path)) {
|
||||||
// Home path ends with '/'
|
// Home path ends with '/'
|
||||||
QString home = QString::fromUtf8(App::GetApplication().GetHomePath());
|
QString home = QString::fromUtf8(App::GetApplication().GetHomePath());
|
||||||
|
@ -705,9 +712,10 @@ PyObject* Application::sAddResPath(PyObject * /*self*/, PyObject *args,PyObject
|
||||||
PyObject* Application::sAddLangPath(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/)
|
PyObject* Application::sAddLangPath(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/)
|
||||||
{
|
{
|
||||||
char* filePath;
|
char* filePath;
|
||||||
if (!PyArg_ParseTuple(args, "s", &filePath)) // convert args: Python->C
|
if (!PyArg_ParseTuple(args, "et", "utf-8", &filePath)) // convert args: Python->C
|
||||||
return NULL; // NULL triggers exception
|
return NULL; // NULL triggers exception
|
||||||
QString path = QString::fromUtf8(filePath);
|
QString path = QString::fromUtf8(filePath);
|
||||||
|
PyMem_Free(filePath);
|
||||||
if (QDir::isRelativePath(path)) {
|
if (QDir::isRelativePath(path)) {
|
||||||
// Home path ends with '/'
|
// Home path ends with '/'
|
||||||
QString home = QString::fromUtf8(App::GetApplication().GetHomePath());
|
QString home = QString::fromUtf8(App::GetApplication().GetHomePath());
|
||||||
|
@ -722,9 +730,10 @@ PyObject* Application::sAddLangPath(PyObject * /*self*/, PyObject *args,PyObject
|
||||||
PyObject* Application::sAddIconPath(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/)
|
PyObject* Application::sAddIconPath(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/)
|
||||||
{
|
{
|
||||||
char* filePath;
|
char* filePath;
|
||||||
if (!PyArg_ParseTuple(args, "s", &filePath)) // convert args: Python->C
|
if (!PyArg_ParseTuple(args, "et", "utf-8", &filePath)) // convert args: Python->C
|
||||||
return NULL; // NULL triggers exception
|
return NULL; // NULL triggers exception
|
||||||
QString path = QString::fromUtf8(filePath);
|
QString path = QString::fromUtf8(filePath);
|
||||||
|
PyMem_Free(filePath);
|
||||||
if (QDir::isRelativePath(path)) {
|
if (QDir::isRelativePath(path)) {
|
||||||
// Home path ends with '/'
|
// Home path ends with '/'
|
||||||
QString home = QString::fromUtf8(App::GetApplication().GetHomePath());
|
QString home = QString::fromUtf8(App::GetApplication().GetHomePath());
|
||||||
|
|
|
@ -108,9 +108,11 @@ using MeshCore::MeshKernel;
|
||||||
static PyObject *
|
static PyObject *
|
||||||
open(PyObject *self, PyObject *args)
|
open(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
const char* Name;
|
char* Name;
|
||||||
if (! PyArg_ParseTuple(args, "s",&Name))
|
if (!PyArg_ParseTuple(args, "et","utf-8",&Name))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
PY_TRY
|
PY_TRY
|
||||||
{
|
{
|
||||||
|
@ -125,10 +127,12 @@ open(PyObject *self, PyObject *args)
|
||||||
/* module functions */
|
/* module functions */
|
||||||
static PyObject * insert(PyObject *self, PyObject *args)
|
static PyObject * insert(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
const char* Name;
|
char* Name;
|
||||||
const char* DocName;
|
const char* DocName;
|
||||||
if (! PyArg_ParseTuple(args, "ss",&Name,&DocName))
|
if (!PyArg_ParseTuple(args, "ets","utf-8",&Name,&DocName))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
PY_TRY
|
PY_TRY
|
||||||
{
|
{
|
||||||
|
@ -141,9 +145,11 @@ static PyObject * insert(PyObject *self, PyObject *args)
|
||||||
/* module functions */
|
/* module functions */
|
||||||
static PyObject * read(PyObject *self, PyObject *args)
|
static PyObject * read(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
const char* Name;
|
char* Name;
|
||||||
if (! PyArg_ParseTuple(args, "s",&Name))
|
if (!PyArg_ParseTuple(args, "et","utf-8",&Name))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
PY_TRY
|
PY_TRY
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -50,14 +50,16 @@ using namespace DrawingGui;
|
||||||
static PyObject *
|
static PyObject *
|
||||||
open(PyObject *self, PyObject *args)
|
open(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
const char* Name;
|
char* Name;
|
||||||
if (!PyArg_ParseTuple(args, "s",&Name))
|
if (!PyArg_ParseTuple(args, "et","utf-8",&Name))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
PY_TRY {
|
PY_TRY {
|
||||||
Base::FileInfo file(Name);
|
Base::FileInfo file(EncodedName.c_str());
|
||||||
if (file.hasExtension("svg") || file.hasExtension("svgz")) {
|
if (file.hasExtension("svg") || file.hasExtension("svgz")) {
|
||||||
QString fileName = QString::fromUtf8(Name);
|
QString fileName = QString::fromUtf8(EncodedName.c_str());
|
||||||
// Displaying the image in a view
|
// Displaying the image in a view
|
||||||
DrawingView* view = new DrawingView(0, Gui::getMainWindow());
|
DrawingView* view = new DrawingView(0, Gui::getMainWindow());
|
||||||
view->load(fileName);
|
view->load(fileName);
|
||||||
|
@ -80,15 +82,17 @@ open(PyObject *self, PyObject *args)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
importer(PyObject *self, PyObject *args)
|
importer(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
const char* Name;
|
char* Name;
|
||||||
const char* dummy;
|
const char* dummy;
|
||||||
if (!PyArg_ParseTuple(args, "s|s",&Name,&dummy))
|
if (!PyArg_ParseTuple(args, "et|s","utf-8",&Name,&dummy))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
PY_TRY {
|
PY_TRY {
|
||||||
Base::FileInfo file(Name);
|
Base::FileInfo file(EncodedName.c_str());
|
||||||
if (file.hasExtension("svg") || file.hasExtension("svgz")) {
|
if (file.hasExtension("svg") || file.hasExtension("svgz")) {
|
||||||
QString fileName = QString::fromUtf8(Name);
|
QString fileName = QString::fromUtf8(EncodedName.c_str());
|
||||||
// Displaying the image in a view
|
// Displaying the image in a view
|
||||||
DrawingView* view = new DrawingView(0, Gui::getMainWindow());
|
DrawingView* view = new DrawingView(0, Gui::getMainWindow());
|
||||||
view->load(fileName);
|
view->load(fileName);
|
||||||
|
@ -110,9 +114,11 @@ static PyObject *
|
||||||
exporter(PyObject *self, PyObject *args)
|
exporter(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject* object;
|
PyObject* object;
|
||||||
const char* filename;
|
char* Name;
|
||||||
if (!PyArg_ParseTuple(args, "Os",&object,&filename))
|
if (!PyArg_ParseTuple(args, "Oet",&object,"utf-8",&Name))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
PY_TRY {
|
PY_TRY {
|
||||||
Py::Sequence list(object);
|
Py::Sequence list(object);
|
||||||
|
@ -121,11 +127,11 @@ exporter(PyObject *self, PyObject *args)
|
||||||
if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) {
|
if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) {
|
||||||
App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr();
|
App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr();
|
||||||
if (obj->getTypeId().isDerivedFrom(Drawing::FeaturePage::getClassTypeId())) {
|
if (obj->getTypeId().isDerivedFrom(Drawing::FeaturePage::getClassTypeId())) {
|
||||||
Base::FileInfo fi_out(filename);
|
Base::FileInfo fi_out(EncodedName.c_str());
|
||||||
Base::ofstream str_out(fi_out, std::ios::out | std::ios::binary);
|
Base::ofstream str_out(fi_out, std::ios::out | std::ios::binary);
|
||||||
if (!str_out) {
|
if (!str_out) {
|
||||||
std::stringstream str;
|
std::stringstream str;
|
||||||
str << "Cannot open file '" << filename << "' for writing";
|
str << "Cannot open file '" << EncodedName << "' for writing";
|
||||||
PyErr_SetString(PyExc_IOError, str.str().c_str());
|
PyErr_SetString(PyExc_IOError, str.str().c_str());
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ void CmdDrawingOpen::activated(int iMsg)
|
||||||
{
|
{
|
||||||
// load the file with the module
|
// load the file with the module
|
||||||
Command::doCommand(Command::Gui, "import Drawing, DrawingGui");
|
Command::doCommand(Command::Gui, "import Drawing, DrawingGui");
|
||||||
Command::doCommand(Command::Gui, "DrawingGui.open(\"%s\")", (const char*)filename.toUtf8());
|
Command::doCommand(Command::Gui, "DrawingGui.open(unicode(\"%s\",\"utf-8\"))", (const char*)filename.toUtf8());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,14 +74,16 @@ using namespace Fem;
|
||||||
/* module functions */
|
/* module functions */
|
||||||
static PyObject * read(PyObject *self, PyObject *args)
|
static PyObject * read(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
const char* Name;
|
char* Name;
|
||||||
if (!PyArg_ParseTuple(args, "s",&Name))
|
if (!PyArg_ParseTuple(args, "et","utf-8",&Name))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
PY_TRY {
|
PY_TRY {
|
||||||
std::auto_ptr<FemMesh> mesh(new FemMesh);
|
std::auto_ptr<FemMesh> mesh(new FemMesh);
|
||||||
try {
|
try {
|
||||||
mesh->read(Name);
|
mesh->read(EncodedName.c_str());
|
||||||
return new FemMeshPy(mesh.release());
|
return new FemMeshPy(mesh.release());
|
||||||
}
|
}
|
||||||
catch(...) {
|
catch(...) {
|
||||||
|
@ -95,14 +97,16 @@ static PyObject * read(PyObject *self, PyObject *args)
|
||||||
|
|
||||||
static PyObject * open(PyObject *self, PyObject *args)
|
static PyObject * open(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
const char* Name;
|
char* Name;
|
||||||
if (!PyArg_ParseTuple(args, "s",&Name))
|
if (!PyArg_ParseTuple(args, "et","utf-8",&Name))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
PY_TRY {
|
PY_TRY {
|
||||||
std::auto_ptr<FemMesh> mesh(new FemMesh);
|
std::auto_ptr<FemMesh> mesh(new FemMesh);
|
||||||
mesh->read(Name);
|
mesh->read(EncodedName.c_str());
|
||||||
Base::FileInfo file(Name);
|
Base::FileInfo file(EncodedName.c_str());
|
||||||
// create new document and add Import feature
|
// create new document and add Import feature
|
||||||
App::Document *pcDoc = App::GetApplication().newDocument("Unnamed");
|
App::Document *pcDoc = App::GetApplication().newDocument("Unnamed");
|
||||||
FemMeshObject *pcFeature = static_cast<FemMeshObject *>
|
FemMeshObject *pcFeature = static_cast<FemMeshObject *>
|
||||||
|
@ -144,11 +148,12 @@ show(PyObject *self, PyObject *args)
|
||||||
|
|
||||||
static PyObject * importer(PyObject *self, PyObject *args)
|
static PyObject * importer(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
const char* Name;
|
char* Name;
|
||||||
const char* DocName=0;
|
const char* DocName = 0;
|
||||||
|
if (!PyArg_ParseTuple(args, "et|s","utf-8",&Name,&DocName))
|
||||||
if (!PyArg_ParseTuple(args, "s|s",&Name,&DocName))
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
PY_TRY {
|
PY_TRY {
|
||||||
App::Document *pcDoc = 0;
|
App::Document *pcDoc = 0;
|
||||||
|
@ -162,8 +167,9 @@ static PyObject * importer(PyObject *self, PyObject *args)
|
||||||
}
|
}
|
||||||
|
|
||||||
std::auto_ptr<FemMesh> mesh(new FemMesh);
|
std::auto_ptr<FemMesh> mesh(new FemMesh);
|
||||||
mesh->read(Name);
|
mesh->read(EncodedName.c_str());
|
||||||
Base::FileInfo file(Name);
|
Base::FileInfo file(EncodedName.c_str());
|
||||||
|
|
||||||
FemMeshObject *pcFeature = static_cast<FemMeshObject *>
|
FemMeshObject *pcFeature = static_cast<FemMeshObject *>
|
||||||
(pcDoc->addObject("Fem::FemMeshObject", file.fileNamePure().c_str()));
|
(pcDoc->addObject("Fem::FemMeshObject", file.fileNamePure().c_str()));
|
||||||
pcFeature->Label.setValue(file.fileNamePure().c_str());
|
pcFeature->Label.setValue(file.fileNamePure().c_str());
|
||||||
|
@ -535,9 +541,11 @@ static PyObject * importer(PyObject *self, PyObject *args)
|
||||||
static PyObject * exporter(PyObject *self, PyObject *args)
|
static PyObject * exporter(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject* object;
|
PyObject* object;
|
||||||
const char* filename;
|
char* Name;
|
||||||
if (!PyArg_ParseTuple(args, "Os",&object,&filename))
|
if (!PyArg_ParseTuple(args, "Oet",&object,"utf-8",&Name))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
PY_TRY {
|
PY_TRY {
|
||||||
Py::Sequence list(object);
|
Py::Sequence list(object);
|
||||||
|
@ -547,7 +555,7 @@ static PyObject * exporter(PyObject *self, PyObject *args)
|
||||||
if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) {
|
if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) {
|
||||||
App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr();
|
App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr();
|
||||||
if (obj->getTypeId().isDerivedFrom(meshId)) {
|
if (obj->getTypeId().isDerivedFrom(meshId)) {
|
||||||
static_cast<FemMeshObject*>(obj)->FemMesh.getValue().write(filename);
|
static_cast<FemMeshObject*>(obj)->FemMesh.getValue().write(EncodedName.c_str());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -442,12 +442,14 @@ PyObject* FemMeshPy::copy(PyObject *args)
|
||||||
|
|
||||||
PyObject* FemMeshPy::read(PyObject *args)
|
PyObject* FemMeshPy::read(PyObject *args)
|
||||||
{
|
{
|
||||||
char* filename;
|
char* Name;
|
||||||
if (!PyArg_ParseTuple(args, "s", &filename))
|
if (!PyArg_ParseTuple(args, "et","utf-8",&Name))
|
||||||
return 0;
|
return 0;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
getFemMeshPtr()->read(filename);
|
getFemMeshPtr()->read(EncodedName.c_str());
|
||||||
}
|
}
|
||||||
catch (const std::exception& e) {
|
catch (const std::exception& e) {
|
||||||
PyErr_SetString(Base::BaseExceptionFreeCADError, e.what());
|
PyErr_SetString(Base::BaseExceptionFreeCADError, e.what());
|
||||||
|
@ -458,12 +460,14 @@ PyObject* FemMeshPy::read(PyObject *args)
|
||||||
|
|
||||||
PyObject* FemMeshPy::write(PyObject *args)
|
PyObject* FemMeshPy::write(PyObject *args)
|
||||||
{
|
{
|
||||||
char* filename;
|
char* Name;
|
||||||
if (!PyArg_ParseTuple(args, "s", &filename))
|
if (!PyArg_ParseTuple(args, "et","utf-8",&Name))
|
||||||
return 0;
|
return 0;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
getFemMeshPtr()->write(filename);
|
getFemMeshPtr()->write(EncodedName.c_str());
|
||||||
}
|
}
|
||||||
catch (const std::exception& e) {
|
catch (const std::exception& e) {
|
||||||
PyErr_SetString(Base::BaseExceptionFreeCADError, e.what());
|
PyErr_SetString(Base::BaseExceptionFreeCADError, e.what());
|
||||||
|
@ -474,12 +478,14 @@ PyObject* FemMeshPy::write(PyObject *args)
|
||||||
|
|
||||||
PyObject* FemMeshPy::writeABAQUS(PyObject *args)
|
PyObject* FemMeshPy::writeABAQUS(PyObject *args)
|
||||||
{
|
{
|
||||||
char* filename;
|
char* Name;
|
||||||
if (!PyArg_ParseTuple(args, "s", &filename))
|
if (!PyArg_ParseTuple(args, "et","utf-8",&Name))
|
||||||
return 0;
|
return 0;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
getFemMeshPtr()->writeABAQUS(filename);
|
getFemMeshPtr()->writeABAQUS(EncodedName.c_str());
|
||||||
}
|
}
|
||||||
catch (const std::exception& e) {
|
catch (const std::exception& e) {
|
||||||
PyErr_SetString(Base::BaseExceptionFreeCADError, e.what());
|
PyErr_SetString(Base::BaseExceptionFreeCADError, e.what());
|
||||||
|
|
|
@ -43,13 +43,15 @@ using namespace ImageGui;
|
||||||
static PyObject *
|
static PyObject *
|
||||||
open(PyObject *self, PyObject *args)
|
open(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
const char* Name;
|
char* Name;
|
||||||
const char* DocName=0;
|
const char* DocName=0;
|
||||||
if (!PyArg_ParseTuple(args, "s|s",&Name,&DocName))
|
if (!PyArg_ParseTuple(args, "et|s","utf-8",&Name,&DocName))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
PY_TRY {
|
PY_TRY {
|
||||||
QString fileName = QString::fromUtf8(Name);
|
QString fileName = QString::fromUtf8(EncodedName.c_str());
|
||||||
QFileInfo file(fileName);
|
QFileInfo file(fileName);
|
||||||
|
|
||||||
// Load image from file into a QImage object
|
// Load image from file into a QImage object
|
||||||
|
|
|
@ -74,7 +74,7 @@ void CmdImageOpen::activated(int iMsg)
|
||||||
try{
|
try{
|
||||||
// load the file with the module
|
// load the file with the module
|
||||||
Command::doCommand(Command::Gui, "import Image, ImageGui");
|
Command::doCommand(Command::Gui, "import Image, ImageGui");
|
||||||
Command::doCommand(Command::Gui, "ImageGui.open(\"%s\")", (const char*)s.toUtf8());
|
Command::doCommand(Command::Gui, "ImageGui.open(unicode(\"%s\",\"utf-8\"))", (const char*)s.toUtf8());
|
||||||
}
|
}
|
||||||
catch (const Base::PyException& e){
|
catch (const Base::PyException& e){
|
||||||
// Usually thrown if the file is invalid somehow
|
// Usually thrown if the file is invalid somehow
|
||||||
|
|
|
@ -56,8 +56,7 @@
|
||||||
#include <Mod/Part/App/ProgressIndicator.h>
|
#include <Mod/Part/App/ProgressIndicator.h>
|
||||||
#include <Mod/Part/App/ImportIges.h>
|
#include <Mod/Part/App/ImportIges.h>
|
||||||
#include <Mod/Part/App/ImportStep.h>
|
#include <Mod/Part/App/ImportStep.h>
|
||||||
|
#include <Mod/Part/App/encodeFilename.h>
|
||||||
|
|
||||||
|
|
||||||
/* module functions */
|
/* module functions */
|
||||||
|
|
||||||
|
@ -65,12 +64,15 @@ static PyObject * importer(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
char* Name;
|
char* Name;
|
||||||
char* DocName=0;
|
char* DocName=0;
|
||||||
if (!PyArg_ParseTuple(args, "s|s",&Name,&DocName))
|
if (!PyArg_ParseTuple(args, "et|s","utf-8",&Name,&DocName))
|
||||||
return 0;
|
return NULL;
|
||||||
|
std::string Utf8Name = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
std::string name8bit = Part::encodeFilename(Utf8Name);
|
||||||
|
|
||||||
PY_TRY {
|
PY_TRY {
|
||||||
//Base::Console().Log("Insert in Part with %s",Name);
|
//Base::Console().Log("Insert in Part with %s",Name);
|
||||||
Base::FileInfo file(Name);
|
Base::FileInfo file(Utf8Name.c_str());
|
||||||
|
|
||||||
App::Document *pcDoc = 0;
|
App::Document *pcDoc = 0;
|
||||||
if (DocName) {
|
if (DocName) {
|
||||||
|
@ -90,7 +92,7 @@ static PyObject * importer(PyObject *self, PyObject *args)
|
||||||
aReader.SetColorMode(true);
|
aReader.SetColorMode(true);
|
||||||
aReader.SetNameMode(true);
|
aReader.SetNameMode(true);
|
||||||
aReader.SetLayerMode(true);
|
aReader.SetLayerMode(true);
|
||||||
if (aReader.ReadFile((Standard_CString)Name) != IFSelect_RetDone) {
|
if (aReader.ReadFile((Standard_CString)(name8bit.c_str())) != IFSelect_RetDone) {
|
||||||
PyErr_SetString(Base::BaseExceptionFreeCADError, "cannot read STEP file");
|
PyErr_SetString(Base::BaseExceptionFreeCADError, "cannot read STEP file");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -107,7 +109,7 @@ static PyObject * importer(PyObject *self, PyObject *args)
|
||||||
Base::Console().Error("%s\n", e->GetMessageString());
|
Base::Console().Error("%s\n", e->GetMessageString());
|
||||||
Base::Console().Message("Try to load STEP file without colors...\n");
|
Base::Console().Message("Try to load STEP file without colors...\n");
|
||||||
|
|
||||||
Part::ImportStepParts(pcDoc,Name);
|
Part::ImportStepParts(pcDoc,Utf8Name.c_str());
|
||||||
pcDoc->recompute();
|
pcDoc->recompute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,7 +121,7 @@ static PyObject * importer(PyObject *self, PyObject *args)
|
||||||
aReader.SetColorMode(true);
|
aReader.SetColorMode(true);
|
||||||
aReader.SetNameMode(true);
|
aReader.SetNameMode(true);
|
||||||
aReader.SetLayerMode(true);
|
aReader.SetLayerMode(true);
|
||||||
if (aReader.ReadFile((Standard_CString)Name) != IFSelect_RetDone) {
|
if (aReader.ReadFile((Standard_CString)(name8bit.c_str())) != IFSelect_RetDone) {
|
||||||
PyErr_SetString(Base::BaseExceptionFreeCADError, "cannot read IGES file");
|
PyErr_SetString(Base::BaseExceptionFreeCADError, "cannot read IGES file");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -136,7 +138,7 @@ static PyObject * importer(PyObject *self, PyObject *args)
|
||||||
Base::Console().Error("%s\n", e->GetMessageString());
|
Base::Console().Error("%s\n", e->GetMessageString());
|
||||||
Base::Console().Message("Try to load IGES file without colors...\n");
|
Base::Console().Message("Try to load IGES file without colors...\n");
|
||||||
|
|
||||||
Part::ImportIgesParts(pcDoc,Name);
|
Part::ImportIgesParts(pcDoc,Utf8Name.c_str());
|
||||||
pcDoc->recompute();
|
pcDoc->recompute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -173,9 +175,12 @@ static PyObject * open(PyObject *self, PyObject *args)
|
||||||
static PyObject * exporter(PyObject *self, PyObject *args)
|
static PyObject * exporter(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject* object;
|
PyObject* object;
|
||||||
const char* filename;
|
char* Name;
|
||||||
if (!PyArg_ParseTuple(args, "Os",&object,&filename))
|
if (!PyArg_ParseTuple(args, "Oet",&object,"utf-8",&Name))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string Utf8Name = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
std::string name8bit = Part::encodeFilename(Utf8Name);
|
||||||
|
|
||||||
PY_TRY {
|
PY_TRY {
|
||||||
Handle(XCAFApp_Application) hApp = XCAFApp_Application::GetApplication();
|
Handle(XCAFApp_Application) hApp = XCAFApp_Application::GetApplication();
|
||||||
|
@ -216,7 +221,7 @@ static PyObject * exporter(PyObject *self, PyObject *args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Base::FileInfo file(filename);
|
Base::FileInfo file(Utf8Name.c_str());
|
||||||
if (file.hasExtension("stp") || file.hasExtension("step")) {
|
if (file.hasExtension("stp") || file.hasExtension("step")) {
|
||||||
//Interface_Static::SetCVal("write.step.schema", "AP214IS");
|
//Interface_Static::SetCVal("write.step.schema", "AP214IS");
|
||||||
STEPCAFControl_Writer writer;
|
STEPCAFControl_Writer writer;
|
||||||
|
@ -228,14 +233,14 @@ static PyObject * exporter(PyObject *self, PyObject *args)
|
||||||
#else
|
#else
|
||||||
APIHeaderSection_MakeHeader makeHeader(writer.Writer().Model());
|
APIHeaderSection_MakeHeader makeHeader(writer.Writer().Model());
|
||||||
#endif
|
#endif
|
||||||
makeHeader.SetName(new TCollection_HAsciiString((const Standard_CString)filename));
|
makeHeader.SetName(new TCollection_HAsciiString((const Standard_CString)Utf8Name.c_str()));
|
||||||
makeHeader.SetAuthorValue (1, new TCollection_HAsciiString("FreeCAD"));
|
makeHeader.SetAuthorValue (1, new TCollection_HAsciiString("FreeCAD"));
|
||||||
makeHeader.SetOrganizationValue (1, new TCollection_HAsciiString("FreeCAD"));
|
makeHeader.SetOrganizationValue (1, new TCollection_HAsciiString("FreeCAD"));
|
||||||
makeHeader.SetOriginatingSystem(new TCollection_HAsciiString("FreeCAD"));
|
makeHeader.SetOriginatingSystem(new TCollection_HAsciiString("FreeCAD"));
|
||||||
makeHeader.SetDescriptionValue(1, new TCollection_HAsciiString("FreeCAD Model"));
|
makeHeader.SetDescriptionValue(1, new TCollection_HAsciiString("FreeCAD Model"));
|
||||||
IFSelect_ReturnStatus ret = writer.Write(filename);
|
IFSelect_ReturnStatus ret = writer.Write(name8bit.c_str());
|
||||||
if (ret == IFSelect_RetError || ret == IFSelect_RetFail || ret == IFSelect_RetStop) {
|
if (ret == IFSelect_RetError || ret == IFSelect_RetFail || ret == IFSelect_RetStop) {
|
||||||
PyErr_Format(PyExc_IOError, "Cannot open file '%s'", filename);
|
PyErr_Format(PyExc_IOError, "Cannot open file '%s'", Utf8Name.c_str());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -243,9 +248,9 @@ static PyObject * exporter(PyObject *self, PyObject *args)
|
||||||
IGESControl_Controller::Init();
|
IGESControl_Controller::Init();
|
||||||
IGESCAFControl_Writer writer;
|
IGESCAFControl_Writer writer;
|
||||||
writer.Transfer(hDoc);
|
writer.Transfer(hDoc);
|
||||||
Standard_Boolean ret = writer.Write(filename);
|
Standard_Boolean ret = writer.Write(name8bit.c_str());
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
PyErr_Format(PyExc_IOError, "Cannot open file '%s'", filename);
|
PyErr_Format(PyExc_IOError, "Cannot open file '%s'", Utf8Name.c_str());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ include_directories(
|
||||||
${ZLIB_INCLUDE_DIR}
|
${ZLIB_INCLUDE_DIR}
|
||||||
${PYTHON_INCLUDE_PATH}
|
${PYTHON_INCLUDE_PATH}
|
||||||
${XERCESC_INCLUDE_DIR}
|
${XERCESC_INCLUDE_DIR}
|
||||||
|
${QT_INCLUDE_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
link_directories(${OCC_LIBRARY_DIR})
|
link_directories(${OCC_LIBRARY_DIR})
|
||||||
|
|
|
@ -78,10 +78,9 @@
|
||||||
#include <Mod/Part/App/ProgressIndicator.h>
|
#include <Mod/Part/App/ProgressIndicator.h>
|
||||||
#include <Mod/Part/App/ImportIges.h>
|
#include <Mod/Part/App/ImportIges.h>
|
||||||
#include <Mod/Part/App/ImportStep.h>
|
#include <Mod/Part/App/ImportStep.h>
|
||||||
|
#include <Mod/Part/App/encodeFilename.h>
|
||||||
#include <Mod/Import/App/ImportOCAF.h>
|
#include <Mod/Import/App/ImportOCAF.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ImportOCAFExt : public Import::ImportOCAF
|
class ImportOCAFExt : public Import::ImportOCAF
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -106,12 +105,15 @@ static PyObject * importer(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
char* Name;
|
char* Name;
|
||||||
char* DocName=0;
|
char* DocName=0;
|
||||||
if (!PyArg_ParseTuple(args, "s|s",&Name,&DocName))
|
if (!PyArg_ParseTuple(args, "et|s","utf-8",&Name,&DocName))
|
||||||
return 0;
|
return 0;
|
||||||
|
std::string Utf8Name = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
std::string name8bit = Part::encodeFilename(Utf8Name);
|
||||||
|
|
||||||
PY_TRY {
|
PY_TRY {
|
||||||
//Base::Console().Log("Insert in Part with %s",Name);
|
//Base::Console().Log("Insert in Part with %s",Name);
|
||||||
Base::FileInfo file(Name);
|
Base::FileInfo file(Utf8Name.c_str());
|
||||||
|
|
||||||
App::Document *pcDoc = 0;
|
App::Document *pcDoc = 0;
|
||||||
if (DocName) {
|
if (DocName) {
|
||||||
|
@ -131,8 +133,7 @@ static PyObject * importer(PyObject *self, PyObject *args)
|
||||||
aReader.SetColorMode(true);
|
aReader.SetColorMode(true);
|
||||||
aReader.SetNameMode(true);
|
aReader.SetNameMode(true);
|
||||||
aReader.SetLayerMode(true);
|
aReader.SetLayerMode(true);
|
||||||
QString fn = QString::fromUtf8(Name);
|
if (aReader.ReadFile((const char*)name8bit.c_str()) != IFSelect_RetDone) {
|
||||||
if (aReader.ReadFile((const char*)fn.toLocal8Bit()) != IFSelect_RetDone) {
|
|
||||||
PyErr_SetString(Base::BaseExceptionFreeCADError, "cannot read STEP file");
|
PyErr_SetString(Base::BaseExceptionFreeCADError, "cannot read STEP file");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -149,7 +150,7 @@ static PyObject * importer(PyObject *self, PyObject *args)
|
||||||
Base::Console().Error("%s\n", e->GetMessageString());
|
Base::Console().Error("%s\n", e->GetMessageString());
|
||||||
Base::Console().Message("Try to load STEP file without colors...\n");
|
Base::Console().Message("Try to load STEP file without colors...\n");
|
||||||
|
|
||||||
Part::ImportStepParts(pcDoc,Name);
|
Part::ImportStepParts(pcDoc,Utf8Name.c_str());
|
||||||
pcDoc->recompute();
|
pcDoc->recompute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,8 +162,7 @@ static PyObject * importer(PyObject *self, PyObject *args)
|
||||||
aReader.SetColorMode(true);
|
aReader.SetColorMode(true);
|
||||||
aReader.SetNameMode(true);
|
aReader.SetNameMode(true);
|
||||||
aReader.SetLayerMode(true);
|
aReader.SetLayerMode(true);
|
||||||
QString fn = QString::fromUtf8(Name);
|
if (aReader.ReadFile((const char*)name8bit.c_str()) != IFSelect_RetDone) {
|
||||||
if (aReader.ReadFile((const char*)fn.toLocal8Bit()) != IFSelect_RetDone) {
|
|
||||||
PyErr_SetString(Base::BaseExceptionFreeCADError, "cannot read IGES file");
|
PyErr_SetString(Base::BaseExceptionFreeCADError, "cannot read IGES file");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -179,7 +179,7 @@ static PyObject * importer(PyObject *self, PyObject *args)
|
||||||
Base::Console().Error("%s\n", e->GetMessageString());
|
Base::Console().Error("%s\n", e->GetMessageString());
|
||||||
Base::Console().Message("Try to load IGES file without colors...\n");
|
Base::Console().Message("Try to load IGES file without colors...\n");
|
||||||
|
|
||||||
Part::ImportIgesParts(pcDoc,Name);
|
Part::ImportIgesParts(pcDoc,Utf8Name.c_str());
|
||||||
pcDoc->recompute();
|
pcDoc->recompute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -210,9 +210,12 @@ static PyObject * open(PyObject *self, PyObject *args)
|
||||||
static PyObject * exporter(PyObject *self, PyObject *args)
|
static PyObject * exporter(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject* object;
|
PyObject* object;
|
||||||
const char* filename;
|
char* Name;
|
||||||
if (!PyArg_ParseTuple(args, "Os",&object,&filename))
|
if (!PyArg_ParseTuple(args, "Oet",&object,"utf-8",&Name))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string Utf8Name = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
std::string name8bit = Part::encodeFilename(Utf8Name);
|
||||||
|
|
||||||
PY_TRY {
|
PY_TRY {
|
||||||
Handle(XCAFApp_Application) hApp = XCAFApp_Application::GetApplication();
|
Handle(XCAFApp_Application) hApp = XCAFApp_Application::GetApplication();
|
||||||
|
@ -242,7 +245,7 @@ static PyObject * exporter(PyObject *self, PyObject *args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Base::FileInfo file(filename);
|
Base::FileInfo file(Utf8Name.c_str());
|
||||||
if (file.hasExtension("stp") || file.hasExtension("step")) {
|
if (file.hasExtension("stp") || file.hasExtension("step")) {
|
||||||
//Interface_Static::SetCVal("write.step.schema", "AP214IS");
|
//Interface_Static::SetCVal("write.step.schema", "AP214IS");
|
||||||
STEPCAFControl_Writer writer;
|
STEPCAFControl_Writer writer;
|
||||||
|
@ -254,15 +257,14 @@ static PyObject * exporter(PyObject *self, PyObject *args)
|
||||||
#else
|
#else
|
||||||
APIHeaderSection_MakeHeader makeHeader(writer.Writer().Model());
|
APIHeaderSection_MakeHeader makeHeader(writer.Writer().Model());
|
||||||
#endif
|
#endif
|
||||||
makeHeader.SetName(new TCollection_HAsciiString((const Standard_CString)filename));
|
makeHeader.SetName(new TCollection_HAsciiString((const Standard_CString)(Utf8Name.c_str())));
|
||||||
makeHeader.SetAuthorValue (1, new TCollection_HAsciiString("FreeCAD"));
|
makeHeader.SetAuthorValue (1, new TCollection_HAsciiString("FreeCAD"));
|
||||||
makeHeader.SetOrganizationValue (1, new TCollection_HAsciiString("FreeCAD"));
|
makeHeader.SetOrganizationValue (1, new TCollection_HAsciiString("FreeCAD"));
|
||||||
makeHeader.SetOriginatingSystem(new TCollection_HAsciiString("FreeCAD"));
|
makeHeader.SetOriginatingSystem(new TCollection_HAsciiString("FreeCAD"));
|
||||||
makeHeader.SetDescriptionValue(1, new TCollection_HAsciiString("FreeCAD Model"));
|
makeHeader.SetDescriptionValue(1, new TCollection_HAsciiString("FreeCAD Model"));
|
||||||
QString fn = QString::fromUtf8(filename);
|
IFSelect_ReturnStatus ret = writer.Write((const char*)name8bit.c_str());
|
||||||
IFSelect_ReturnStatus ret = writer.Write((const char*)fn.toLocal8Bit());
|
|
||||||
if (ret == IFSelect_RetError || ret == IFSelect_RetFail || ret == IFSelect_RetStop) {
|
if (ret == IFSelect_RetError || ret == IFSelect_RetFail || ret == IFSelect_RetStop) {
|
||||||
PyErr_Format(PyExc_IOError, "Cannot open file '%s'", filename);
|
PyErr_Format(PyExc_IOError, "Cannot open file '%s'", Utf8Name.c_str());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -270,10 +272,9 @@ static PyObject * exporter(PyObject *self, PyObject *args)
|
||||||
IGESControl_Controller::Init();
|
IGESControl_Controller::Init();
|
||||||
IGESCAFControl_Writer writer;
|
IGESCAFControl_Writer writer;
|
||||||
writer.Transfer(hDoc);
|
writer.Transfer(hDoc);
|
||||||
QString fn = QString::fromUtf8(filename);
|
Standard_Boolean ret = writer.Write((const char*)name8bit.c_str());
|
||||||
Standard_Boolean ret = writer.Write((const char*)fn.toLocal8Bit());
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
PyErr_Format(PyExc_IOError, "Cannot open file '%s'", filename);
|
PyErr_Format(PyExc_IOError, "Cannot open file '%s'", Utf8Name.c_str());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,15 +50,16 @@ using namespace MeshCore;
|
||||||
/* module functions */
|
/* module functions */
|
||||||
static PyObject * read(PyObject *self, PyObject *args)
|
static PyObject * read(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
const char* Name;
|
char* Name;
|
||||||
if (! PyArg_ParseTuple(args, "s",&Name))
|
if (!PyArg_ParseTuple(args, "et","utf-8",&Name))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
PY_TRY {
|
PY_TRY {
|
||||||
|
|
||||||
std::auto_ptr<MeshCore::MeshKernel> apcKernel(new MeshCore::MeshKernel());
|
std::auto_ptr<MeshCore::MeshKernel> apcKernel(new MeshCore::MeshKernel());
|
||||||
|
|
||||||
readFile(Name,0);
|
readFile(EncodedName.c_str(),0);
|
||||||
|
|
||||||
vector<MeshGeomFacet> facets;
|
vector<MeshGeomFacet> facets;
|
||||||
facets.resize(iterSize());
|
facets.resize(iterSize());
|
||||||
|
@ -90,14 +91,16 @@ static PyObject * read(PyObject *self, PyObject *args)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
open(PyObject *self, PyObject *args)
|
open(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
const char* Name;
|
char* Name;
|
||||||
if (! PyArg_ParseTuple(args, "s",&Name))
|
if (!PyArg_ParseTuple(args, "et","utf-8",&Name))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
PY_TRY {
|
PY_TRY {
|
||||||
|
|
||||||
//Base::Console().Log("Open in Mesh with %s",Name);
|
//Base::Console().Log("Open in Mesh with %s",Name);
|
||||||
Base::FileInfo file(Name);
|
Base::FileInfo file(EncodedName.c_str());
|
||||||
|
|
||||||
// extract ending
|
// extract ending
|
||||||
if(file.extension() == "")
|
if(file.extension() == "")
|
||||||
|
@ -111,7 +114,7 @@ open(PyObject *self, PyObject *args)
|
||||||
|
|
||||||
std::auto_ptr<MeshCore::MeshKernel> apcKernel(new MeshCore::MeshKernel());
|
std::auto_ptr<MeshCore::MeshKernel> apcKernel(new MeshCore::MeshKernel());
|
||||||
|
|
||||||
readFile(Name,0);
|
readFile(EncodedName.c_str(),0);
|
||||||
|
|
||||||
vector<MeshGeomFacet> facets;
|
vector<MeshGeomFacet> facets;
|
||||||
facets.resize(iterSize());
|
facets.resize(iterSize());
|
||||||
|
@ -154,14 +157,16 @@ open(PyObject *self, PyObject *args)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
insert(PyObject *self, PyObject *args)
|
insert(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
const char* Name;
|
char* Name;
|
||||||
const char* DocName;
|
const char* DocName;
|
||||||
if (! PyArg_ParseTuple(args, "ss",&Name,&DocName))
|
if (!PyArg_ParseTuple(args, "ets","utf-8",&Name,&DocName))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
PY_TRY {
|
PY_TRY {
|
||||||
|
|
||||||
Base::FileInfo file(Name);
|
Base::FileInfo file(EncodedName.c_str());
|
||||||
|
|
||||||
// extract ending
|
// extract ending
|
||||||
if(file.extension() == "")
|
if(file.extension() == "")
|
||||||
|
@ -178,7 +183,7 @@ insert(PyObject *self, PyObject *args)
|
||||||
Py_Error(Base::BaseExceptionFreeCADError,szBuf);
|
Py_Error(Base::BaseExceptionFreeCADError,szBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
readFile(Name,0);
|
readFile(EncodedName.c_str(),0);
|
||||||
|
|
||||||
vector<MeshGeomFacet> facets;
|
vector<MeshGeomFacet> facets;
|
||||||
|
|
||||||
|
@ -212,7 +217,7 @@ insert(PyObject *self, PyObject *args)
|
||||||
}else{
|
}else{
|
||||||
clearData();
|
clearData();
|
||||||
//Py_Error(Base::BaseExceptionFreeCADError,"No Mesh in file");
|
//Py_Error(Base::BaseExceptionFreeCADError,"No Mesh in file");
|
||||||
Base::Console().Warning("No Mesh in file: %s\n",Name);
|
Base::Console().Warning("No Mesh in file: %s\n",EncodedName.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -52,13 +52,15 @@ using namespace MeshCore;
|
||||||
/* module functions */
|
/* module functions */
|
||||||
static PyObject * read(PyObject *self, PyObject *args)
|
static PyObject * read(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
const char* Name;
|
char* Name;
|
||||||
if (!PyArg_ParseTuple(args, "s",&Name))
|
if (!PyArg_ParseTuple(args, "et","utf-8",&Name))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
PY_TRY {
|
PY_TRY {
|
||||||
std::auto_ptr<MeshObject> mesh(new MeshObject);
|
std::auto_ptr<MeshObject> mesh(new MeshObject);
|
||||||
if (mesh->load(Name)) {
|
if (mesh->load(EncodedName.c_str())) {
|
||||||
return new MeshPy(mesh.release());
|
return new MeshPy(mesh.release());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -72,14 +74,16 @@ static PyObject * read(PyObject *self, PyObject *args)
|
||||||
|
|
||||||
static PyObject * open(PyObject *self, PyObject *args)
|
static PyObject * open(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
const char* Name;
|
char* Name;
|
||||||
if (!PyArg_ParseTuple(args, "s",&Name))
|
if (!PyArg_ParseTuple(args, "et","utf-8",&Name))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
PY_TRY {
|
PY_TRY {
|
||||||
MeshObject mesh;
|
MeshObject mesh;
|
||||||
if (mesh.load(Name)) {
|
if (mesh.load(EncodedName.c_str())) {
|
||||||
Base::FileInfo file(Name);
|
Base::FileInfo file(EncodedName.c_str());
|
||||||
// create new document and add Import feature
|
// create new document and add Import feature
|
||||||
App::Document *pcDoc = App::GetApplication().newDocument("Unnamed");
|
App::Document *pcDoc = App::GetApplication().newDocument("Unnamed");
|
||||||
unsigned long segmct = mesh.countSegments();
|
unsigned long segmct = mesh.countSegments();
|
||||||
|
@ -108,11 +112,12 @@ static PyObject * open(PyObject *self, PyObject *args)
|
||||||
|
|
||||||
static PyObject * importer(PyObject *self, PyObject *args)
|
static PyObject * importer(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
const char* Name;
|
char* Name;
|
||||||
const char* DocName=0;
|
char* DocName=0;
|
||||||
|
if (!PyArg_ParseTuple(args, "et|s","utf-8",&Name,&DocName))
|
||||||
if (!PyArg_ParseTuple(args, "s|s",&Name,&DocName))
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
PY_TRY {
|
PY_TRY {
|
||||||
App::Document *pcDoc = 0;
|
App::Document *pcDoc = 0;
|
||||||
|
@ -126,8 +131,8 @@ static PyObject * importer(PyObject *self, PyObject *args)
|
||||||
}
|
}
|
||||||
|
|
||||||
MeshObject mesh;
|
MeshObject mesh;
|
||||||
if (mesh.load(Name)) {
|
if (mesh.load(EncodedName.c_str())) {
|
||||||
Base::FileInfo file(Name);
|
Base::FileInfo file(EncodedName.c_str());
|
||||||
unsigned long segmct = mesh.countSegments();
|
unsigned long segmct = mesh.countSegments();
|
||||||
if (segmct > 1) {
|
if (segmct > 1) {
|
||||||
for (unsigned long i=0; i<segmct; i++) {
|
for (unsigned long i=0; i<segmct; i++) {
|
||||||
|
@ -155,9 +160,11 @@ static PyObject * importer(PyObject *self, PyObject *args)
|
||||||
static PyObject * exporter(PyObject *self, PyObject *args)
|
static PyObject * exporter(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject* object;
|
PyObject* object;
|
||||||
const char* filename;
|
char* Name;
|
||||||
if (!PyArg_ParseTuple(args, "Os",&object,&filename))
|
if (!PyArg_ParseTuple(args, "Oet",&object,"utf-8",&Name))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
float fTolerance = 0.1f;
|
float fTolerance = 0.1f;
|
||||||
MeshObject global_mesh;
|
MeshObject global_mesh;
|
||||||
|
@ -200,7 +207,7 @@ static PyObject * exporter(PyObject *self, PyObject *args)
|
||||||
}
|
}
|
||||||
|
|
||||||
// export mesh compound
|
// export mesh compound
|
||||||
global_mesh.save(filename);
|
global_mesh.save(EncodedName.c_str());
|
||||||
} PY_CATCH;
|
} PY_CATCH;
|
||||||
|
|
||||||
Py_Return;
|
Py_Return;
|
||||||
|
|
|
@ -143,13 +143,15 @@ extern const char* BRepBuilderAPI_FaceErrorText(BRepBuilderAPI_FaceError fe);
|
||||||
/* module functions */
|
/* module functions */
|
||||||
static PyObject * open(PyObject *self, PyObject *args)
|
static PyObject * open(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
const char* Name;
|
char* Name;
|
||||||
if (!PyArg_ParseTuple(args, "s",&Name))
|
if (!PyArg_ParseTuple(args, "et","utf-8",&Name))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
PY_TRY {
|
PY_TRY {
|
||||||
//Base::Console().Log("Open in Part with %s",Name);
|
//Base::Console().Log("Open in Part with %s",Name);
|
||||||
Base::FileInfo file(Name);
|
Base::FileInfo file(EncodedName.c_str());
|
||||||
|
|
||||||
// extract ending
|
// extract ending
|
||||||
if (file.extension() == "")
|
if (file.extension() == "")
|
||||||
|
@ -159,7 +161,7 @@ static PyObject * open(PyObject *self, PyObject *args)
|
||||||
// create new document and add Import feature
|
// create new document and add Import feature
|
||||||
App::Document *pcDoc = App::GetApplication().newDocument("Unnamed");
|
App::Document *pcDoc = App::GetApplication().newDocument("Unnamed");
|
||||||
#if 1
|
#if 1
|
||||||
ImportStepParts(pcDoc,Name);
|
ImportStepParts(pcDoc,EncodedName.c_str());
|
||||||
#else
|
#else
|
||||||
Part::ImportStep *pcFeature = (Part::ImportStep *)pcDoc->addObject("Part::ImportStep",file.fileNamePure().c_str());
|
Part::ImportStep *pcFeature = (Part::ImportStep *)pcDoc->addObject("Part::ImportStep",file.fileNamePure().c_str());
|
||||||
pcFeature->FileName.setValue(Name);
|
pcFeature->FileName.setValue(Name);
|
||||||
|
@ -169,14 +171,14 @@ static PyObject * open(PyObject *self, PyObject *args)
|
||||||
#if 1
|
#if 1
|
||||||
else if (file.hasExtension("igs") || file.hasExtension("iges")) {
|
else if (file.hasExtension("igs") || file.hasExtension("iges")) {
|
||||||
App::Document *pcDoc = App::GetApplication().newDocument("Unnamed");
|
App::Document *pcDoc = App::GetApplication().newDocument("Unnamed");
|
||||||
ImportIgesParts(pcDoc,Name);
|
ImportIgesParts(pcDoc,EncodedName.c_str());
|
||||||
pcDoc->recompute();
|
pcDoc->recompute();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else {
|
else {
|
||||||
try {
|
try {
|
||||||
TopoShape shape;
|
TopoShape shape;
|
||||||
shape.read(Name);
|
shape.read(EncodedName.c_str());
|
||||||
|
|
||||||
// create new document set loaded shape
|
// create new document set loaded shape
|
||||||
App::Document *pcDoc = App::GetApplication().newDocument(file.fileNamePure().c_str());
|
App::Document *pcDoc = App::GetApplication().newDocument(file.fileNamePure().c_str());
|
||||||
|
@ -197,14 +199,16 @@ static PyObject * open(PyObject *self, PyObject *args)
|
||||||
/* module functions */
|
/* module functions */
|
||||||
static PyObject * insert(PyObject *self, PyObject *args)
|
static PyObject * insert(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
const char* Name;
|
char* Name;
|
||||||
const char* DocName;
|
const char* DocName;
|
||||||
if (!PyArg_ParseTuple(args, "ss",&Name,&DocName))
|
if (!PyArg_ParseTuple(args, "ets","utf-8",&Name,&DocName))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
PY_TRY {
|
PY_TRY {
|
||||||
//Base::Console().Log("Insert in Part with %s",Name);
|
//Base::Console().Log("Insert in Part with %s",Name);
|
||||||
Base::FileInfo file(Name);
|
Base::FileInfo file(EncodedName.c_str());
|
||||||
|
|
||||||
// extract ending
|
// extract ending
|
||||||
if (file.extension() == "")
|
if (file.extension() == "")
|
||||||
|
@ -216,7 +220,7 @@ static PyObject * insert(PyObject *self, PyObject *args)
|
||||||
|
|
||||||
if (file.hasExtension("stp") || file.hasExtension("step")) {
|
if (file.hasExtension("stp") || file.hasExtension("step")) {
|
||||||
#if 1
|
#if 1
|
||||||
ImportStepParts(pcDoc,Name);
|
ImportStepParts(pcDoc,EncodedName.c_str());
|
||||||
#else
|
#else
|
||||||
// add Import feature
|
// add Import feature
|
||||||
Part::ImportStep *pcFeature = (Part::ImportStep *)pcDoc->addObject("Part::ImportStep",file.fileNamePure().c_str());
|
Part::ImportStep *pcFeature = (Part::ImportStep *)pcDoc->addObject("Part::ImportStep",file.fileNamePure().c_str());
|
||||||
|
@ -226,14 +230,14 @@ static PyObject * insert(PyObject *self, PyObject *args)
|
||||||
}
|
}
|
||||||
#if 1
|
#if 1
|
||||||
else if (file.hasExtension("igs") || file.hasExtension("iges")) {
|
else if (file.hasExtension("igs") || file.hasExtension("iges")) {
|
||||||
ImportIgesParts(pcDoc,Name);
|
ImportIgesParts(pcDoc,EncodedName.c_str());
|
||||||
pcDoc->recompute();
|
pcDoc->recompute();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else {
|
else {
|
||||||
try {
|
try {
|
||||||
TopoShape shape;
|
TopoShape shape;
|
||||||
shape.read(Name);
|
shape.read(EncodedName.c_str());
|
||||||
|
|
||||||
Part::Feature *object = static_cast<Part::Feature *>(pcDoc->addObject
|
Part::Feature *object = static_cast<Part::Feature *>(pcDoc->addObject
|
||||||
("Part::Feature",file.fileNamePure().c_str()));
|
("Part::Feature",file.fileNamePure().c_str()));
|
||||||
|
@ -253,9 +257,11 @@ static PyObject * insert(PyObject *self, PyObject *args)
|
||||||
static PyObject * exporter(PyObject *self, PyObject *args)
|
static PyObject * exporter(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject* object;
|
PyObject* object;
|
||||||
const char* filename;
|
char* Name;
|
||||||
if (!PyArg_ParseTuple(args, "Os",&object,&filename))
|
if (!PyArg_ParseTuple(args, "Oet",&object,"utf-8",&Name))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
BRep_Builder builder;
|
BRep_Builder builder;
|
||||||
TopoDS_Compound comp;
|
TopoDS_Compound comp;
|
||||||
|
@ -280,7 +286,7 @@ static PyObject * exporter(PyObject *self, PyObject *args)
|
||||||
}
|
}
|
||||||
|
|
||||||
TopoShape shape(comp);
|
TopoShape shape(comp);
|
||||||
shape.write(filename);
|
shape.write(EncodedName.c_str());
|
||||||
|
|
||||||
} PY_CATCH_OCC;
|
} PY_CATCH_OCC;
|
||||||
|
|
||||||
|
@ -290,12 +296,14 @@ static PyObject * exporter(PyObject *self, PyObject *args)
|
||||||
/* module functions */
|
/* module functions */
|
||||||
static PyObject * read(PyObject *self, PyObject *args)
|
static PyObject * read(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
const char* Name;
|
char* Name;
|
||||||
if (!PyArg_ParseTuple(args, "s",&Name))
|
if (!PyArg_ParseTuple(args, "et","utf-8",&Name))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
PY_TRY {
|
PY_TRY {
|
||||||
TopoShape* shape = new TopoShape();
|
TopoShape* shape = new TopoShape();
|
||||||
shape->read(Name);
|
shape->read(EncodedName.c_str());
|
||||||
return new TopoShapePy(shape);
|
return new TopoShapePy(shape);
|
||||||
} PY_CATCH_OCC;
|
} PY_CATCH_OCC;
|
||||||
}
|
}
|
||||||
|
|
|
@ -244,6 +244,7 @@ SET(Part_SRCS
|
||||||
modelRefine.cpp
|
modelRefine.cpp
|
||||||
modelRefine.h
|
modelRefine.h
|
||||||
Tools.h
|
Tools.h
|
||||||
|
encodeFilename.h
|
||||||
OCCError.h
|
OCCError.h
|
||||||
FT2FC.cpp
|
FT2FC.cpp
|
||||||
FT2FC.h
|
FT2FC.h
|
||||||
|
|
|
@ -76,6 +76,7 @@
|
||||||
#include "ImportStep.h"
|
#include "ImportStep.h"
|
||||||
#include "PartFeature.h"
|
#include "PartFeature.h"
|
||||||
#include "ProgressIndicator.h"
|
#include "ProgressIndicator.h"
|
||||||
|
#include "encodeFilename.h"
|
||||||
|
|
||||||
using namespace Part;
|
using namespace Part;
|
||||||
|
|
||||||
|
@ -95,8 +96,11 @@ int Part::ImportStepParts(App::Document *pcDoc, const char* Name)
|
||||||
str << "File '" << Name << "' does not exist!";
|
str << "File '" << Name << "' does not exist!";
|
||||||
throw Base::Exception(str.str().c_str());
|
throw Base::Exception(str.str().c_str());
|
||||||
}
|
}
|
||||||
|
std::string encodednamestr = encodeFilename(std::string(Name));
|
||||||
|
const char * encodedname = encodednamestr.c_str();
|
||||||
|
|
||||||
if (aReader.ReadFile((Standard_CString)Name) != IFSelect_RetDone) {
|
if (aReader.ReadFile((Standard_CString)encodedname) !=
|
||||||
|
IFSelect_RetDone) {
|
||||||
throw Base::Exception("Cannot open STEP file");
|
throw Base::Exception("Cannot open STEP file");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -166,6 +166,7 @@
|
||||||
#include "ProgressIndicator.h"
|
#include "ProgressIndicator.h"
|
||||||
#include "modelRefine.h"
|
#include "modelRefine.h"
|
||||||
#include "Tools.h"
|
#include "Tools.h"
|
||||||
|
#include "encodeFilename.h"
|
||||||
|
|
||||||
using namespace Part;
|
using namespace Part;
|
||||||
|
|
||||||
|
@ -570,8 +571,7 @@ void TopoShape::importIges(const char *FileName)
|
||||||
IGESControl_Controller::Init();
|
IGESControl_Controller::Init();
|
||||||
Interface_Static::SetIVal("read.surfacecurve.mode",3);
|
Interface_Static::SetIVal("read.surfacecurve.mode",3);
|
||||||
IGESControl_Reader aReader;
|
IGESControl_Reader aReader;
|
||||||
QString fn = QString::fromUtf8(FileName);
|
if (aReader.ReadFile(encodeFilename(FileName).c_str()) != IFSelect_RetDone)
|
||||||
if (aReader.ReadFile((const char*)fn.toLocal8Bit()) != IFSelect_RetDone)
|
|
||||||
throw Base::Exception("Error in reading IGES");
|
throw Base::Exception("Error in reading IGES");
|
||||||
|
|
||||||
Handle_Message_ProgressIndicator pi = new ProgressIndicator(100);
|
Handle_Message_ProgressIndicator pi = new ProgressIndicator(100);
|
||||||
|
@ -596,8 +596,7 @@ void TopoShape::importStep(const char *FileName)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
STEPControl_Reader aReader;
|
STEPControl_Reader aReader;
|
||||||
QString fn = QString::fromUtf8(FileName);
|
if (aReader.ReadFile(encodeFilename(FileName).c_str()) != IFSelect_RetDone)
|
||||||
if (aReader.ReadFile((const char*)fn.toLocal8Bit()) != IFSelect_RetDone)
|
|
||||||
throw Base::Exception("Error in reading STEP");
|
throw Base::Exception("Error in reading STEP");
|
||||||
|
|
||||||
Handle_Message_ProgressIndicator pi = new ProgressIndicator(100);
|
Handle_Message_ProgressIndicator pi = new ProgressIndicator(100);
|
||||||
|
@ -627,8 +626,7 @@ void TopoShape::importBrep(const char *FileName)
|
||||||
Handle_Message_ProgressIndicator pi = new ProgressIndicator(100);
|
Handle_Message_ProgressIndicator pi = new ProgressIndicator(100);
|
||||||
pi->NewScope(100, "Reading BREP file...");
|
pi->NewScope(100, "Reading BREP file...");
|
||||||
pi->Show();
|
pi->Show();
|
||||||
QString fn = QString::fromUtf8(FileName);
|
BRepTools::Read(aShape,encodeFilename(FileName).c_str(),aBuilder,pi);
|
||||||
BRepTools::Read(aShape,(const char*)fn.toLocal8Bit(),aBuilder,pi);
|
|
||||||
pi->EndScope();
|
pi->EndScope();
|
||||||
#else
|
#else
|
||||||
BRepTools::Read(aShape,(const Standard_CString)FileName,aBuilder);
|
BRepTools::Read(aShape,(const Standard_CString)FileName,aBuilder);
|
||||||
|
@ -699,8 +697,7 @@ void TopoShape::exportIges(const char *filename) const
|
||||||
IGESControl_Writer aWriter;
|
IGESControl_Writer aWriter;
|
||||||
aWriter.AddShape(this->_Shape);
|
aWriter.AddShape(this->_Shape);
|
||||||
aWriter.ComputeModel();
|
aWriter.ComputeModel();
|
||||||
QString fn = QString::fromUtf8(filename);
|
if (aWriter.Write(encodeFilename(filename).c_str()) != IFSelect_RetDone)
|
||||||
if (aWriter.Write((const char*)fn.toLocal8Bit()) != IFSelect_RetDone)
|
|
||||||
throw Base::Exception("Writing of IGES failed");
|
throw Base::Exception("Writing of IGES failed");
|
||||||
}
|
}
|
||||||
catch (Standard_Failure) {
|
catch (Standard_Failure) {
|
||||||
|
@ -724,14 +721,13 @@ void TopoShape::exportStep(const char *filename) const
|
||||||
throw Base::Exception("Error in transferring STEP");
|
throw Base::Exception("Error in transferring STEP");
|
||||||
|
|
||||||
APIHeaderSection_MakeHeader makeHeader(aWriter.Model());
|
APIHeaderSection_MakeHeader makeHeader(aWriter.Model());
|
||||||
makeHeader.SetName(new TCollection_HAsciiString((const Standard_CString)filename));
|
makeHeader.SetName(new TCollection_HAsciiString((const Standard_CString)(encodeFilename(filename).c_str())));
|
||||||
makeHeader.SetAuthorValue (1, new TCollection_HAsciiString("FreeCAD"));
|
makeHeader.SetAuthorValue (1, new TCollection_HAsciiString("FreeCAD"));
|
||||||
makeHeader.SetOrganizationValue (1, new TCollection_HAsciiString("FreeCAD"));
|
makeHeader.SetOrganizationValue (1, new TCollection_HAsciiString("FreeCAD"));
|
||||||
makeHeader.SetOriginatingSystem(new TCollection_HAsciiString("FreeCAD"));
|
makeHeader.SetOriginatingSystem(new TCollection_HAsciiString("FreeCAD"));
|
||||||
makeHeader.SetDescriptionValue(1, new TCollection_HAsciiString("FreeCAD Model"));
|
makeHeader.SetDescriptionValue(1, new TCollection_HAsciiString("FreeCAD Model"));
|
||||||
|
|
||||||
QString fn = QString::fromUtf8(filename);
|
if (aWriter.Write(encodeFilename(filename).c_str()) != IFSelect_RetDone)
|
||||||
if (aWriter.Write((const char*)fn.toLocal8Bit()) != IFSelect_RetDone)
|
|
||||||
throw Base::Exception("Writing of STEP failed");
|
throw Base::Exception("Writing of STEP failed");
|
||||||
pi->EndScope();
|
pi->EndScope();
|
||||||
}
|
}
|
||||||
|
@ -743,8 +739,7 @@ void TopoShape::exportStep(const char *filename) const
|
||||||
|
|
||||||
void TopoShape::exportBrep(const char *filename) const
|
void TopoShape::exportBrep(const char *filename) const
|
||||||
{
|
{
|
||||||
QString fn = QString::fromUtf8(filename);
|
if (!BRepTools::Write(this->_Shape,encodeFilename(filename).c_str()))
|
||||||
if (!BRepTools::Write(this->_Shape,(const char*)fn.toLocal8Bit()))
|
|
||||||
throw Base::Exception("Writing of BREP failed");
|
throw Base::Exception("Writing of BREP failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -765,8 +760,7 @@ void TopoShape::exportStl(const char *filename, double deflection) const
|
||||||
writer.RelativeMode() = false;
|
writer.RelativeMode() = false;
|
||||||
writer.SetDeflection(deflection);
|
writer.SetDeflection(deflection);
|
||||||
}
|
}
|
||||||
QString fn = QString::fromUtf8(filename);
|
writer.Write(this->_Shape,encodeFilename(filename).c_str());
|
||||||
writer.Write(this->_Shape,(const Standard_CString)fn.toLocal8Bit());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TopoShape::exportFaceSet(double dev, double ca, std::ostream& str) const
|
void TopoShape::exportFaceSet(double dev, double ca, std::ostream& str) const
|
||||||
|
|
|
@ -260,11 +260,13 @@ PyObject* TopoShapePy::removeShape(PyObject *args)
|
||||||
|
|
||||||
PyObject* TopoShapePy::read(PyObject *args)
|
PyObject* TopoShapePy::read(PyObject *args)
|
||||||
{
|
{
|
||||||
char* filename;
|
char* Name;
|
||||||
if (!PyArg_ParseTuple(args, "s", &filename))
|
if (!PyArg_ParseTuple(args, "et","utf-8",&Name))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
getTopoShapePtr()->read(filename);
|
getTopoShapePtr()->read(EncodedName.c_str());
|
||||||
Py_Return;
|
Py_Return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,13 +294,15 @@ PyObject* TopoShapePy::writeInventor(PyObject * args)
|
||||||
|
|
||||||
PyObject* TopoShapePy::exportIges(PyObject *args)
|
PyObject* TopoShapePy::exportIges(PyObject *args)
|
||||||
{
|
{
|
||||||
char* filename;
|
char* Name;
|
||||||
if (!PyArg_ParseTuple(args, "s", &filename))
|
if (!PyArg_ParseTuple(args, "et","utf-8",&Name))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// write iges file
|
// write iges file
|
||||||
getTopoShapePtr()->exportIges(filename);
|
getTopoShapePtr()->exportIges(EncodedName.c_str());
|
||||||
}
|
}
|
||||||
catch (const Base::Exception& e) {
|
catch (const Base::Exception& e) {
|
||||||
PyErr_SetString(PartExceptionOCCError,e.what());
|
PyErr_SetString(PartExceptionOCCError,e.what());
|
||||||
|
@ -310,13 +314,15 @@ PyObject* TopoShapePy::exportIges(PyObject *args)
|
||||||
|
|
||||||
PyObject* TopoShapePy::exportStep(PyObject *args)
|
PyObject* TopoShapePy::exportStep(PyObject *args)
|
||||||
{
|
{
|
||||||
char* filename;
|
char* Name;
|
||||||
if (!PyArg_ParseTuple(args, "s", &filename))
|
if (!PyArg_ParseTuple(args, "et","utf-8",&Name))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// write step file
|
// write step file
|
||||||
getTopoShapePtr()->exportStep(filename);
|
getTopoShapePtr()->exportStep(EncodedName.c_str());
|
||||||
}
|
}
|
||||||
catch (const Base::Exception& e) {
|
catch (const Base::Exception& e) {
|
||||||
PyErr_SetString(PartExceptionOCCError,e.what());
|
PyErr_SetString(PartExceptionOCCError,e.what());
|
||||||
|
@ -328,13 +334,15 @@ PyObject* TopoShapePy::exportStep(PyObject *args)
|
||||||
|
|
||||||
PyObject* TopoShapePy::exportBrep(PyObject *args)
|
PyObject* TopoShapePy::exportBrep(PyObject *args)
|
||||||
{
|
{
|
||||||
char* filename;
|
char* Name;
|
||||||
if (!PyArg_ParseTuple(args, "s", &filename))
|
if (!PyArg_ParseTuple(args, "et","utf-8",&Name))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// write brep file
|
// write brep file
|
||||||
getTopoShapePtr()->exportBrep(filename);
|
getTopoShapePtr()->exportBrep(EncodedName.c_str());
|
||||||
}
|
}
|
||||||
catch (const Base::Exception& e) {
|
catch (const Base::Exception& e) {
|
||||||
PyErr_SetString(PartExceptionOCCError,e.what());
|
PyErr_SetString(PartExceptionOCCError,e.what());
|
||||||
|
@ -449,14 +457,16 @@ PyObject* TopoShapePy::importBrepFromString(PyObject *args)
|
||||||
|
|
||||||
PyObject* TopoShapePy::exportStl(PyObject *args)
|
PyObject* TopoShapePy::exportStl(PyObject *args)
|
||||||
{
|
{
|
||||||
char* filename;
|
|
||||||
double deflection = 0;
|
double deflection = 0;
|
||||||
if (!PyArg_ParseTuple(args, "s|d", &filename, &deflection))
|
char* Name;
|
||||||
|
if (!PyArg_ParseTuple(args, "et|d","utf-8",&Name,&deflection))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// write stl file
|
// write stl file
|
||||||
getTopoShapePtr()->exportStl(filename, deflection);
|
getTopoShapePtr()->exportStl(EncodedName.c_str(), deflection);
|
||||||
}
|
}
|
||||||
catch (const Base::Exception& e) {
|
catch (const Base::Exception& e) {
|
||||||
PyErr_SetString(PartExceptionOCCError,e.what());
|
PyErr_SetString(PartExceptionOCCError,e.what());
|
||||||
|
|
48
src/Mod/Part/App/encodeFilename.h
Normal file
48
src/Mod/Part/App/encodeFilename.h
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
/***************************************************************************
|
||||||
|
* Copyright (c) 2014 Sebastian Hoogen <github[at]sebastianhoogen.de> *
|
||||||
|
* *
|
||||||
|
* This file is part of the FreeCAD CAx development system. *
|
||||||
|
* *
|
||||||
|
* This library is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU Library General Public *
|
||||||
|
* License as published by the Free Software Foundation; either *
|
||||||
|
* version 2 of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This library is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU Library General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU Library General Public *
|
||||||
|
* License along with this library; see the file COPYING.LIB. If not, *
|
||||||
|
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||||
|
* Suite 330, Boston, MA 02111-1307, USA *
|
||||||
|
* *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef PART_ENCODEFILENAME_H
|
||||||
|
#define PART_ENCODEFILENAME_H
|
||||||
|
|
||||||
|
#if (OCC_VERSION_HEX < 0x060800 && defined(_WIN32))
|
||||||
|
#include <QString>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace Part
|
||||||
|
{
|
||||||
|
inline std::string encodeFilename(std::string fn)
|
||||||
|
{
|
||||||
|
#if (OCC_VERSION_HEX < 0x060800 && defined(_WIN32))
|
||||||
|
// Workaround to support latin1 characters in path until OCCT supports
|
||||||
|
// conversion from UTF8 to wchar_t on windows
|
||||||
|
// http://tracker.dev.opencascade.org/view.php?id=22484
|
||||||
|
QByteArray str8bit = QString::fromUtf8(fn.c_str()).toLocal8Bit();
|
||||||
|
return std::string(str8bit.constData());
|
||||||
|
#else
|
||||||
|
return fn;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
} //namespace Part
|
||||||
|
|
||||||
|
#endif // PART_ENCODEFILENAME_H
|
|
@ -52,13 +52,15 @@ using namespace Points;
|
||||||
static PyObject *
|
static PyObject *
|
||||||
open(PyObject *self, PyObject *args)
|
open(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
const char* Name;
|
char* Name;
|
||||||
if (!PyArg_ParseTuple(args, "s",&Name))
|
if (!PyArg_ParseTuple(args, "et","utf-8",&Name))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
PY_TRY {
|
PY_TRY {
|
||||||
Base::Console().Log("Open in Points with %s",Name);
|
Base::Console().Log("Open in Points with %s",EncodedName.c_str());
|
||||||
Base::FileInfo file(Name);
|
Base::FileInfo file(EncodedName.c_str());
|
||||||
|
|
||||||
// extract ending
|
// extract ending
|
||||||
if (file.extension() == "")
|
if (file.extension() == "")
|
||||||
|
@ -69,7 +71,7 @@ open(PyObject *self, PyObject *args)
|
||||||
App::Document *pcDoc = App::GetApplication().newDocument("Unnamed");
|
App::Document *pcDoc = App::GetApplication().newDocument("Unnamed");
|
||||||
Points::Feature *pcFeature = (Points::Feature *)pcDoc->addObject("Points::Feature", file.fileNamePure().c_str());
|
Points::Feature *pcFeature = (Points::Feature *)pcDoc->addObject("Points::Feature", file.fileNamePure().c_str());
|
||||||
Points::PointKernel pkTemp;
|
Points::PointKernel pkTemp;
|
||||||
pkTemp.load(Name);
|
pkTemp.load(EncodedName.c_str());
|
||||||
pcFeature->Points.setValue( pkTemp );
|
pcFeature->Points.setValue( pkTemp );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -82,7 +84,7 @@ open(PyObject *self, PyObject *args)
|
||||||
|
|
||||||
// pcl test
|
// pcl test
|
||||||
pcl::PointCloud<pcl::PointXYZRGB> cloud_in;
|
pcl::PointCloud<pcl::PointXYZRGB> cloud_in;
|
||||||
pcl::io::loadPLYFile<pcl::PointXYZRGB>(Name,cloud_in);
|
pcl::io::loadPLYFile<pcl::PointXYZRGB>(EncodedName.c_str(),cloud_in);
|
||||||
|
|
||||||
for (pcl::PointCloud<pcl::PointXYZRGB>::const_iterator it = cloud_in.begin();it!=cloud_in.end();++it)
|
for (pcl::PointCloud<pcl::PointXYZRGB>::const_iterator it = cloud_in.begin();it!=cloud_in.end();++it)
|
||||||
pkTemp.push_back(Base::Vector3d(it->x,it->y,it->z));
|
pkTemp.push_back(Base::Vector3d(it->x,it->y,it->z));
|
||||||
|
@ -100,14 +102,16 @@ open(PyObject *self, PyObject *args)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
insert(PyObject *self, PyObject *args)
|
insert(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
const char* Name;
|
char* Name;
|
||||||
const char* DocName;
|
const char* DocName;
|
||||||
if (!PyArg_ParseTuple(args, "ss",&Name,&DocName))
|
if (!PyArg_ParseTuple(args, "ets","utf-8",&Name,&DocName))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
PY_TRY {
|
PY_TRY {
|
||||||
Base::Console().Log("Import in Points with %s",Name);
|
Base::Console().Log("Import in Points with %s",EncodedName.c_str());
|
||||||
Base::FileInfo file(Name);
|
Base::FileInfo file(EncodedName.c_str());
|
||||||
|
|
||||||
// extract ending
|
// extract ending
|
||||||
if (file.extension() == "")
|
if (file.extension() == "")
|
||||||
|
@ -122,7 +126,7 @@ insert(PyObject *self, PyObject *args)
|
||||||
|
|
||||||
Points::Feature *pcFeature = (Points::Feature *)pcDoc->addObject("Points::Feature", file.fileNamePure().c_str());
|
Points::Feature *pcFeature = (Points::Feature *)pcDoc->addObject("Points::Feature", file.fileNamePure().c_str());
|
||||||
Points::PointKernel pkTemp;
|
Points::PointKernel pkTemp;
|
||||||
pkTemp.load(Name);
|
pkTemp.load(EncodedName.c_str());
|
||||||
pcFeature->Points.setValue( pkTemp );
|
pcFeature->Points.setValue( pkTemp );
|
||||||
}
|
}
|
||||||
#ifdef HAVE_PCL_IO
|
#ifdef HAVE_PCL_IO
|
||||||
|
@ -137,7 +141,7 @@ insert(PyObject *self, PyObject *args)
|
||||||
|
|
||||||
// pcl test
|
// pcl test
|
||||||
pcl::PointCloud<pcl::PointXYZRGB> cloud_in;
|
pcl::PointCloud<pcl::PointXYZRGB> cloud_in;
|
||||||
pcl::io::loadPLYFile<pcl::PointXYZRGB>(Name,cloud_in);
|
pcl::io::loadPLYFile<pcl::PointXYZRGB>(EncodedName.c_str(),cloud_in);
|
||||||
|
|
||||||
for (pcl::PointCloud<pcl::PointXYZRGB>::const_iterator it = cloud_in.begin();it!=cloud_in.end();++it)
|
for (pcl::PointCloud<pcl::PointXYZRGB>::const_iterator it = cloud_in.begin();it!=cloud_in.end();++it)
|
||||||
pkTemp.push_back(Base::Vector3d(it->x,it->y,it->z));
|
pkTemp.push_back(Base::Vector3d(it->x,it->y,it->z));
|
||||||
|
|
|
@ -53,12 +53,14 @@ static PyObject *
|
||||||
open(PyObject *self, PyObject *args)
|
open(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
// only used to open Povray files
|
// only used to open Povray files
|
||||||
const char* Name;
|
char* Name;
|
||||||
const char* DocName;
|
const char* DocName;
|
||||||
if (!PyArg_ParseTuple(args, "s|s",&Name, &DocName))
|
if (!PyArg_ParseTuple(args, "et|s","utf-8",&Name,&DocName))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
PY_TRY {
|
PY_TRY {
|
||||||
QString fileName = QString::fromUtf8(Name);
|
QString fileName = QString::fromUtf8(EncodedName.c_str());
|
||||||
QFileInfo fi;
|
QFileInfo fi;
|
||||||
fi.setFile(fileName);
|
fi.setFile(fileName);
|
||||||
QString ext = fi.completeSuffix().toLower();
|
QString ext = fi.completeSuffix().toLower();
|
||||||
|
|
|
@ -50,14 +50,16 @@ using namespace std;
|
||||||
/* module functions */
|
/* module functions */
|
||||||
static PyObject * open(PyObject *self, PyObject *args)
|
static PyObject * open(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
const char* Name;
|
char* Name;
|
||||||
if (!PyArg_ParseTuple(args, "s",&Name))
|
if (!PyArg_ParseTuple(args, "et","utf-8",&Name))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
PY_TRY {
|
PY_TRY {
|
||||||
} PY_CATCH;
|
} PY_CATCH;
|
||||||
//Base::Console().Log("Open in Part with %s",Name);
|
//Base::Console().Log("Open in Part with %s",Name);
|
||||||
Base::FileInfo file(Name);
|
Base::FileInfo file(EncodedName.c_str());
|
||||||
|
|
||||||
// extract ending
|
// extract ending
|
||||||
if (file.extension() == "")
|
if (file.extension() == "")
|
||||||
|
@ -80,14 +82,16 @@ static PyObject * open(PyObject *self, PyObject *args)
|
||||||
/* module functions */
|
/* module functions */
|
||||||
static PyObject * insert(PyObject *self, PyObject *args)
|
static PyObject * insert(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
const char* Name;
|
char* Name;
|
||||||
const char* DocName;
|
const char* DocName;
|
||||||
if (!PyArg_ParseTuple(args, "ss",&Name,&DocName))
|
if (!PyArg_ParseTuple(args, "ets","utf-8",&Name,&DocName))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
PY_TRY {
|
PY_TRY {
|
||||||
//Base::Console().Log("Insert in Part with %s",Name);
|
//Base::Console().Log("Insert in Part with %s",Name);
|
||||||
Base::FileInfo file(Name);
|
Base::FileInfo file(EncodedName.c_str());
|
||||||
|
|
||||||
// extract ending
|
// extract ending
|
||||||
if (file.extension() == "")
|
if (file.extension() == "")
|
||||||
|
@ -100,7 +104,7 @@ static PyObject * insert(PyObject *self, PyObject *args)
|
||||||
if (file.hasExtension("skf")) {
|
if (file.hasExtension("skf")) {
|
||||||
|
|
||||||
Sketcher::SketchObjectSF *pcFeature = (Sketcher::SketchObjectSF *)pcDoc->addObject("Sketcher::SketchObjectSF",file.fileNamePure().c_str());
|
Sketcher::SketchObjectSF *pcFeature = (Sketcher::SketchObjectSF *)pcDoc->addObject("Sketcher::SketchObjectSF",file.fileNamePure().c_str());
|
||||||
pcFeature->SketchFlatFile.setValue(Name);
|
pcFeature->SketchFlatFile.setValue(EncodedName.c_str());
|
||||||
|
|
||||||
pcDoc->recompute();
|
pcDoc->recompute();
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,9 +39,11 @@
|
||||||
static PyObject *
|
static PyObject *
|
||||||
open(PyObject *self, PyObject *args)
|
open(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
const char* Name;
|
char* Name;
|
||||||
if (! PyArg_ParseTuple(args, "s",&Name))
|
if (!PyArg_ParseTuple(args, "et","utf-8",&Name))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
std::string EncodedName = std::string(Name);
|
||||||
|
PyMem_Free(Name);
|
||||||
|
|
||||||
PY_TRY {
|
PY_TRY {
|
||||||
} PY_CATCH;
|
} PY_CATCH;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user