diff --git a/src/App/Application.cpp b/src/App/Application.cpp index 66b02dff3..34d797571 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -1268,10 +1268,12 @@ void Application::processCmdLineFiles(void) else { std::vector mods = App::GetApplication().getImportModules(Ext.c_str()); if (!mods.empty()) { + std::string escapedstr = Base::Tools::escapedUnicodeFromUtf8(File.filePath().c_str()); Base::Interpreter().loadModule(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::Console().Log("Command line open: %s.Open(\"%s\")\n",mods.front().c_str(),File.filePath().c_str()); + Base::Interpreter().runStringArg("%s.open(u\"%s\")",mods.front().c_str(), + escapedstr.c_str()); + Base::Console().Log("Command line open: %s.open(u\"%s\")\n",mods.front().c_str(),escapedstr.c_str()); } else { Console().Warning("File format not supported: %s \n", File.filePath().c_str()); diff --git a/src/App/ApplicationPy.cpp b/src/App/ApplicationPy.cpp index 03972ced6..3b5d1c855 100644 --- a/src/App/ApplicationPy.cpp +++ b/src/App/ApplicationPy.cpp @@ -180,12 +180,14 @@ PyObject* Application::sLoadFile(PyObject * /*self*/, PyObject *args,PyObject * PyObject* Application::sOpenDocument(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/) { - char *pstr; - if (!PyArg_ParseTuple(args, "s", &pstr)) // convert args: Python->C - return NULL; // NULL triggers exception + char* Name; + if (!PyArg_ParseTuple(args, "et","utf-8",&Name)) + return NULL; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); try { // return new document - return (GetApplication().openDocument(pstr)->getPyObject()); + return (GetApplication().openDocument(EncodedName.c_str())->getPyObject()); } catch (const Base::Exception& e) { PyErr_SetString(PyExc_IOError, e.what()); @@ -193,7 +195,7 @@ PyObject* Application::sOpenDocument(PyObject * /*self*/, PyObject *args,PyObjec } catch (const std::exception& e) { // 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; } } diff --git a/src/Base/Tools.cpp b/src/Base/Tools.cpp index 4cbab7b9d..509d61750 100644 --- a/src/Base/Tools.cpp +++ b/src/Base/Tools.cpp @@ -29,7 +29,7 @@ #endif # include - +#include #include "Tools.h" namespace Base { @@ -141,6 +141,16 @@ std::string Base::Tools::narrow(const std::wstring& str) stm << ctfacet.narrow(str[i], 0); 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; +} // ---------------------------------------------------------------------------- @@ -191,3 +201,6 @@ std::string StopWatch::toString(int ms) const str << msec << "ms"; return str.str(); } + + + diff --git a/src/Base/Tools.h b/src/Base/Tools.h index 43cbaa4d6..cb2f551c1 100644 --- a/src/Base/Tools.h +++ b/src/Base/Tools.h @@ -153,6 +153,7 @@ struct BaseExport Tools static std::string getIdentifier(const std::string&); static std::wstring widen(const std::string& str); static std::string narrow(const std::wstring& str); + static std::string escapedUnicodeFromUtf8(const char *s); }; } // namespace Base diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index 71b3c2b28..f3e67e3af 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -479,7 +479,7 @@ void Application::open(const char* FileName, const char* Module) wc.setIgnoreEvents(WaitCursor::NoEvents); Base::FileInfo File(FileName); string te = File.extension(); - + string unicodepath = Base::Tools::escapedUnicodeFromUtf8(File.filePath().c_str()); // if the active document is empty and not modified, close it // in case of an automatically created empty document at startup 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); try { // 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 if (!File.hasExtension("FCStd") && sendHasMsgToActiveView("ViewFit")) { 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); Base::FileInfo File(FileName); std::string te = File.extension(); + string unicodepath = Base::Tools::escapedUnicodeFromUtf8(File.filePath().c_str()); if (Module != 0) { // issue module loading @@ -533,14 +534,14 @@ void Application::importFrom(const char* FileName, const char* DocName, const ch try { // load the file with the module if (File.hasExtension("FCStd")) { - Command::doCommand(Command::App, "%s.open(\"%s\")" - , Module, File.filePath().c_str()); + Command::doCommand(Command::App, "%s.open(u\"%s\")" + , Module, unicodepath.c_str()); if (activeDocument()) activeDocument()->setModified(false); } else { - Command::doCommand(Command::App, "%s.insert(\"%s\",\"%s\")" - , Module, File.filePath().c_str(), DocName); + Command::doCommand(Command::App, "%s.insert(u\"%s\",\"%s\")" + , Module, unicodepath.c_str(), DocName); ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath ("User parameter:BaseApp/Preferences/View"); if (hGrp->GetBool("AutoFitToView", true)) @@ -570,6 +571,7 @@ void Application::exportTo(const char* FileName, const char* DocName, const char WaitCursor wc; Base::FileInfo File(FileName); std::string te = File.extension(); + string unicodepath = Base::Tools::escapedUnicodeFromUtf8(File.filePath().c_str()); if (Module != 0) { try { @@ -588,7 +590,7 @@ void Application::exportTo(const char* FileName, const char* DocName, const char } 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; std::string code = str.str(); diff --git a/src/Gui/ApplicationPy.cpp b/src/Gui/ApplicationPy.cpp index 032abfa8d..0d904f23a 100644 --- a/src/Gui/ApplicationPy.cpp +++ b/src/Gui/ApplicationPy.cpp @@ -233,11 +233,13 @@ PyObject* Application::sShowObject(PyObject * /*self*/, PyObject *args,PyObject PyObject* Application::sOpen(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/) { // only used to open Python files - const char* Name; - if (!PyArg_ParseTuple(args, "s",&Name)) + char* Name; + if (!PyArg_ParseTuple(args, "et","utf-8",&Name)) return NULL; + std::string Utf8Name = std::string(Name); + PyMem_Free(Name); PY_TRY { - QString fileName = QString::fromUtf8(Name); + QString fileName = QString::fromUtf8(Utf8Name.c_str()); QFileInfo fi; fi.setFile(fileName); 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*/) { - const char* Name; - const char* DocName=0; - if (!PyArg_ParseTuple(args, "s|s",&Name,&DocName)) + char* Name; + char* DocName=0; + if (!PyArg_ParseTuple(args, "et|s","utf-8",&Name,&DocName)) return NULL; + std::string Utf8Name = std::string(Name); + PyMem_Free(Name); PY_TRY { - QString fileName = QString::fromUtf8(Name); + QString fileName = QString::fromUtf8(Utf8Name.c_str()); QFileInfo fi; fi.setFile(fileName); 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* object; - const char* filename; - if (!PyArg_ParseTuple(args, "Os",&object,&filename)) + char* Name; + if (!PyArg_ParseTuple(args, "Oet",&object,"utf-8",&Name)) return NULL; + std::string Utf8Name = std::string(Name); + PyMem_Free(Name); PY_TRY { 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 if (doc) { - QString fileName = QString::fromUtf8(filename); + QString fileName = QString::fromUtf8(Utf8Name.c_str()); QFileInfo fi; fi.setFile(fileName); 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*/) { 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 QString path = QString::fromUtf8(filePath); + PyMem_Free(filePath); if (QDir::isRelativePath(path)) { // Home path ends with '/' 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*/) { 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 QString path = QString::fromUtf8(filePath); + PyMem_Free(filePath); if (QDir::isRelativePath(path)) { // Home path ends with '/' 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*/) { char* filePath; - if (!PyArg_ParseTuple(args, "s", &filePath)) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "et", "utf-8", &filePath)) // convert args: Python->C + return NULL; // NULL triggers exception QString path = QString::fromUtf8(filePath); + PyMem_Free(filePath); if (QDir::isRelativePath(path)) { // Home path ends with '/' QString home = QString::fromUtf8(App::GetApplication().GetHomePath()); diff --git a/src/Mod/Cam/App/AppCamPy.cpp b/src/Mod/Cam/App/AppCamPy.cpp index a4c5fad77..1595ff7e4 100644 --- a/src/Mod/Cam/App/AppCamPy.cpp +++ b/src/Mod/Cam/App/AppCamPy.cpp @@ -108,9 +108,11 @@ using MeshCore::MeshKernel; static PyObject * open(PyObject *self, PyObject *args) { - const char* Name; - if (! PyArg_ParseTuple(args, "s",&Name)) + char* Name; + if (!PyArg_ParseTuple(args, "et","utf-8",&Name)) return NULL; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); PY_TRY { @@ -125,10 +127,12 @@ open(PyObject *self, PyObject *args) /* module functions */ static PyObject * insert(PyObject *self, PyObject *args) { - const char* Name; + char* Name; const char* DocName; - if (! PyArg_ParseTuple(args, "ss",&Name,&DocName)) + if (!PyArg_ParseTuple(args, "ets","utf-8",&Name,&DocName)) return NULL; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); PY_TRY { @@ -141,9 +145,11 @@ static PyObject * insert(PyObject *self, PyObject *args) /* module functions */ static PyObject * read(PyObject *self, PyObject *args) { - const char* Name; - if (! PyArg_ParseTuple(args, "s",&Name)) + char* Name; + if (!PyArg_ParseTuple(args, "et","utf-8",&Name)) return NULL; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); PY_TRY { diff --git a/src/Mod/Drawing/Gui/AppDrawingGuiPy.cpp b/src/Mod/Drawing/Gui/AppDrawingGuiPy.cpp index 5c83f288d..1445cd0ab 100644 --- a/src/Mod/Drawing/Gui/AppDrawingGuiPy.cpp +++ b/src/Mod/Drawing/Gui/AppDrawingGuiPy.cpp @@ -50,14 +50,16 @@ using namespace DrawingGui; static PyObject * open(PyObject *self, PyObject *args) { - const char* Name; - if (!PyArg_ParseTuple(args, "s",&Name)) - return NULL; - + char* Name; + if (!PyArg_ParseTuple(args, "et","utf-8",&Name)) + return NULL; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); + PY_TRY { - Base::FileInfo file(Name); + Base::FileInfo file(EncodedName.c_str()); 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 DrawingView* view = new DrawingView(0, Gui::getMainWindow()); view->load(fileName); @@ -80,15 +82,17 @@ open(PyObject *self, PyObject *args) static PyObject * importer(PyObject *self, PyObject *args) { - const char* Name; + char* Name; const char* dummy; - if (!PyArg_ParseTuple(args, "s|s",&Name,&dummy)) - return NULL; - + if (!PyArg_ParseTuple(args, "et|s","utf-8",&Name,&dummy)) + return NULL; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); + PY_TRY { - Base::FileInfo file(Name); + Base::FileInfo file(EncodedName.c_str()); 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 DrawingView* view = new DrawingView(0, Gui::getMainWindow()); view->load(fileName); @@ -110,9 +114,11 @@ static PyObject * exporter(PyObject *self, PyObject *args) { PyObject* object; - const char* filename; - if (!PyArg_ParseTuple(args, "Os",&object,&filename)) + char* Name; + if (!PyArg_ParseTuple(args, "Oet",&object,"utf-8",&Name)) return NULL; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); PY_TRY { Py::Sequence list(object); @@ -121,11 +127,11 @@ exporter(PyObject *self, PyObject *args) if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) { App::DocumentObject* obj = static_cast(item)->getDocumentObjectPtr(); 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); if (!str_out) { 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()); return NULL; } diff --git a/src/Mod/Drawing/Gui/Command.cpp b/src/Mod/Drawing/Gui/Command.cpp index e737504fa..4f317137d 100644 --- a/src/Mod/Drawing/Gui/Command.cpp +++ b/src/Mod/Drawing/Gui/Command.cpp @@ -71,7 +71,7 @@ void CmdDrawingOpen::activated(int iMsg) { // load the file with the module 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()); } } diff --git a/src/Mod/Fem/App/AppFemPy.cpp b/src/Mod/Fem/App/AppFemPy.cpp index d18a335a1..3b3ae7b58 100755 --- a/src/Mod/Fem/App/AppFemPy.cpp +++ b/src/Mod/Fem/App/AppFemPy.cpp @@ -74,14 +74,16 @@ using namespace Fem; /* module functions */ static PyObject * read(PyObject *self, PyObject *args) { - const char* Name; - if (!PyArg_ParseTuple(args, "s",&Name)) + 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 mesh(new FemMesh); try { - mesh->read(Name); + mesh->read(EncodedName.c_str()); return new FemMeshPy(mesh.release()); } catch(...) { @@ -95,14 +97,16 @@ static PyObject * read(PyObject *self, PyObject *args) static PyObject * open(PyObject *self, PyObject *args) { - const char* Name; - if (!PyArg_ParseTuple(args, "s",&Name)) + 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 mesh(new FemMesh); - mesh->read(Name); - Base::FileInfo file(Name); + mesh->read(EncodedName.c_str()); + Base::FileInfo file(EncodedName.c_str()); // create new document and add Import feature App::Document *pcDoc = App::GetApplication().newDocument("Unnamed"); FemMeshObject *pcFeature = static_cast @@ -144,11 +148,12 @@ show(PyObject *self, PyObject *args) static PyObject * importer(PyObject *self, PyObject *args) { - const char* Name; - const char* DocName=0; - - if (!PyArg_ParseTuple(args, "s|s",&Name,&DocName)) + char* Name; + const char* DocName = 0; + if (!PyArg_ParseTuple(args, "et|s","utf-8",&Name,&DocName)) return NULL; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); PY_TRY { App::Document *pcDoc = 0; @@ -162,8 +167,9 @@ static PyObject * importer(PyObject *self, PyObject *args) } std::auto_ptr mesh(new FemMesh); - mesh->read(Name); - Base::FileInfo file(Name); + mesh->read(EncodedName.c_str()); + Base::FileInfo file(EncodedName.c_str()); + FemMeshObject *pcFeature = static_cast (pcDoc->addObject("Fem::FemMeshObject", 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) { PyObject* object; - const char* filename; - if (!PyArg_ParseTuple(args, "Os",&object,&filename)) + char* Name; + if (!PyArg_ParseTuple(args, "Oet",&object,"utf-8",&Name)) return NULL; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); PY_TRY { Py::Sequence list(object); @@ -547,7 +555,7 @@ static PyObject * exporter(PyObject *self, PyObject *args) if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) { App::DocumentObject* obj = static_cast(item)->getDocumentObjectPtr(); if (obj->getTypeId().isDerivedFrom(meshId)) { - static_cast(obj)->FemMesh.getValue().write(filename); + static_cast(obj)->FemMesh.getValue().write(EncodedName.c_str()); break; } } diff --git a/src/Mod/Fem/App/FemMeshPyImp.cpp b/src/Mod/Fem/App/FemMeshPyImp.cpp index c41577b49..4fbacf26f 100755 --- a/src/Mod/Fem/App/FemMeshPyImp.cpp +++ b/src/Mod/Fem/App/FemMeshPyImp.cpp @@ -442,12 +442,14 @@ PyObject* FemMeshPy::copy(PyObject *args) PyObject* FemMeshPy::read(PyObject *args) { - char* filename; - if (!PyArg_ParseTuple(args, "s", &filename)) + char* Name; + if (!PyArg_ParseTuple(args, "et","utf-8",&Name)) return 0; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); try { - getFemMeshPtr()->read(filename); + getFemMeshPtr()->read(EncodedName.c_str()); } catch (const std::exception& e) { PyErr_SetString(Base::BaseExceptionFreeCADError, e.what()); @@ -458,12 +460,14 @@ PyObject* FemMeshPy::read(PyObject *args) PyObject* FemMeshPy::write(PyObject *args) { - char* filename; - if (!PyArg_ParseTuple(args, "s", &filename)) + char* Name; + if (!PyArg_ParseTuple(args, "et","utf-8",&Name)) return 0; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); try { - getFemMeshPtr()->write(filename); + getFemMeshPtr()->write(EncodedName.c_str()); } catch (const std::exception& e) { PyErr_SetString(Base::BaseExceptionFreeCADError, e.what()); @@ -474,12 +478,14 @@ PyObject* FemMeshPy::write(PyObject *args) PyObject* FemMeshPy::writeABAQUS(PyObject *args) { - char* filename; - if (!PyArg_ParseTuple(args, "s", &filename)) + char* Name; + if (!PyArg_ParseTuple(args, "et","utf-8",&Name)) return 0; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); try { - getFemMeshPtr()->writeABAQUS(filename); + getFemMeshPtr()->writeABAQUS(EncodedName.c_str()); } catch (const std::exception& e) { PyErr_SetString(Base::BaseExceptionFreeCADError, e.what()); diff --git a/src/Mod/Image/Gui/AppImageGuiPy.cpp b/src/Mod/Image/Gui/AppImageGuiPy.cpp index bad51ec84..d1ff60403 100644 --- a/src/Mod/Image/Gui/AppImageGuiPy.cpp +++ b/src/Mod/Image/Gui/AppImageGuiPy.cpp @@ -43,15 +43,17 @@ using namespace ImageGui; static PyObject * open(PyObject *self, PyObject *args) { - const char* Name; + char* Name; const char* DocName=0; - if (!PyArg_ParseTuple(args, "s|s",&Name,&DocName)) - return NULL; - + if (!PyArg_ParseTuple(args, "et|s","utf-8",&Name,&DocName)) + return NULL; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); + PY_TRY { - QString fileName = QString::fromUtf8(Name); + QString fileName = QString::fromUtf8(EncodedName.c_str()); QFileInfo file(fileName); - + // Load image from file into a QImage object QImage imageq(fileName); diff --git a/src/Mod/Image/Gui/Command.cpp b/src/Mod/Image/Gui/Command.cpp index 398ee3401..d62ed2dfc 100644 --- a/src/Mod/Image/Gui/Command.cpp +++ b/src/Mod/Image/Gui/Command.cpp @@ -74,7 +74,7 @@ void CmdImageOpen::activated(int iMsg) try{ // load the file with the module 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){ // Usually thrown if the file is invalid somehow diff --git a/src/Mod/Import/App/AppImportPy.cpp b/src/Mod/Import/App/AppImportPy.cpp index d19c375cf..aca225538 100644 --- a/src/Mod/Import/App/AppImportPy.cpp +++ b/src/Mod/Import/App/AppImportPy.cpp @@ -56,8 +56,7 @@ #include #include #include - - +#include /* module functions */ @@ -65,12 +64,15 @@ static PyObject * importer(PyObject *self, PyObject *args) { char* Name; char* DocName=0; - if (!PyArg_ParseTuple(args, "s|s",&Name,&DocName)) - return 0; + if (!PyArg_ParseTuple(args, "et|s","utf-8",&Name,&DocName)) + return NULL; + std::string Utf8Name = std::string(Name); + PyMem_Free(Name); + std::string name8bit = Part::encodeFilename(Utf8Name); PY_TRY { //Base::Console().Log("Insert in Part with %s",Name); - Base::FileInfo file(Name); + Base::FileInfo file(Utf8Name.c_str()); App::Document *pcDoc = 0; if (DocName) { @@ -90,7 +92,7 @@ static PyObject * importer(PyObject *self, PyObject *args) aReader.SetColorMode(true); aReader.SetNameMode(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"); return 0; } @@ -107,7 +109,7 @@ static PyObject * importer(PyObject *self, PyObject *args) Base::Console().Error("%s\n", e->GetMessageString()); Base::Console().Message("Try to load STEP file without colors...\n"); - Part::ImportStepParts(pcDoc,Name); + Part::ImportStepParts(pcDoc,Utf8Name.c_str()); pcDoc->recompute(); } } @@ -119,7 +121,7 @@ static PyObject * importer(PyObject *self, PyObject *args) aReader.SetColorMode(true); aReader.SetNameMode(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"); return 0; } @@ -136,7 +138,7 @@ static PyObject * importer(PyObject *self, PyObject *args) Base::Console().Error("%s\n", e->GetMessageString()); Base::Console().Message("Try to load IGES file without colors...\n"); - Part::ImportIgesParts(pcDoc,Name); + Part::ImportIgesParts(pcDoc,Utf8Name.c_str()); pcDoc->recompute(); } } @@ -173,9 +175,12 @@ static PyObject * open(PyObject *self, PyObject *args) static PyObject * exporter(PyObject *self, PyObject *args) { PyObject* object; - const char* filename; - if (!PyArg_ParseTuple(args, "Os",&object,&filename)) + char* Name; + if (!PyArg_ParseTuple(args, "Oet",&object,"utf-8",&Name)) return NULL; + std::string Utf8Name = std::string(Name); + PyMem_Free(Name); + std::string name8bit = Part::encodeFilename(Utf8Name); PY_TRY { 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")) { //Interface_Static::SetCVal("write.step.schema", "AP214IS"); STEPCAFControl_Writer writer; @@ -228,14 +233,14 @@ static PyObject * exporter(PyObject *self, PyObject *args) #else APIHeaderSection_MakeHeader makeHeader(writer.Writer().Model()); #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.SetOrganizationValue (1, new TCollection_HAsciiString("FreeCAD")); makeHeader.SetOriginatingSystem(new TCollection_HAsciiString("FreeCAD")); 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) { - PyErr_Format(PyExc_IOError, "Cannot open file '%s'", filename); + PyErr_Format(PyExc_IOError, "Cannot open file '%s'", Utf8Name.c_str()); return 0; } } @@ -243,9 +248,9 @@ static PyObject * exporter(PyObject *self, PyObject *args) IGESControl_Controller::Init(); IGESCAFControl_Writer writer; writer.Transfer(hDoc); - Standard_Boolean ret = writer.Write(filename); + Standard_Boolean ret = writer.Write(name8bit.c_str()); if (!ret) { - PyErr_Format(PyExc_IOError, "Cannot open file '%s'", filename); + PyErr_Format(PyExc_IOError, "Cannot open file '%s'", Utf8Name.c_str()); return 0; } } diff --git a/src/Mod/Import/App/CMakeLists.txt b/src/Mod/Import/App/CMakeLists.txt index 8b6f6e958..df7007a05 100644 --- a/src/Mod/Import/App/CMakeLists.txt +++ b/src/Mod/Import/App/CMakeLists.txt @@ -13,6 +13,7 @@ include_directories( ${ZLIB_INCLUDE_DIR} ${PYTHON_INCLUDE_PATH} ${XERCESC_INCLUDE_DIR} + ${QT_INCLUDE_DIR} ) link_directories(${OCC_LIBRARY_DIR}) diff --git a/src/Mod/Import/Gui/AppImportGuiPy.cpp b/src/Mod/Import/Gui/AppImportGuiPy.cpp index 3d70db638..ee75390d6 100644 --- a/src/Mod/Import/Gui/AppImportGuiPy.cpp +++ b/src/Mod/Import/Gui/AppImportGuiPy.cpp @@ -78,10 +78,9 @@ #include #include #include +#include #include - - class ImportOCAFExt : public Import::ImportOCAF { public: @@ -106,12 +105,15 @@ static PyObject * importer(PyObject *self, PyObject *args) { char* Name; char* DocName=0; - if (!PyArg_ParseTuple(args, "s|s",&Name,&DocName)) + if (!PyArg_ParseTuple(args, "et|s","utf-8",&Name,&DocName)) return 0; + std::string Utf8Name = std::string(Name); + PyMem_Free(Name); + std::string name8bit = Part::encodeFilename(Utf8Name); PY_TRY { //Base::Console().Log("Insert in Part with %s",Name); - Base::FileInfo file(Name); + Base::FileInfo file(Utf8Name.c_str()); App::Document *pcDoc = 0; if (DocName) { @@ -131,8 +133,7 @@ static PyObject * importer(PyObject *self, PyObject *args) aReader.SetColorMode(true); aReader.SetNameMode(true); aReader.SetLayerMode(true); - QString fn = QString::fromUtf8(Name); - if (aReader.ReadFile((const char*)fn.toLocal8Bit()) != IFSelect_RetDone) { + if (aReader.ReadFile((const char*)name8bit.c_str()) != IFSelect_RetDone) { PyErr_SetString(Base::BaseExceptionFreeCADError, "cannot read STEP file"); return 0; } @@ -149,7 +150,7 @@ static PyObject * importer(PyObject *self, PyObject *args) Base::Console().Error("%s\n", e->GetMessageString()); Base::Console().Message("Try to load STEP file without colors...\n"); - Part::ImportStepParts(pcDoc,Name); + Part::ImportStepParts(pcDoc,Utf8Name.c_str()); pcDoc->recompute(); } } @@ -161,8 +162,7 @@ static PyObject * importer(PyObject *self, PyObject *args) aReader.SetColorMode(true); aReader.SetNameMode(true); aReader.SetLayerMode(true); - QString fn = QString::fromUtf8(Name); - if (aReader.ReadFile((const char*)fn.toLocal8Bit()) != IFSelect_RetDone) { + if (aReader.ReadFile((const char*)name8bit.c_str()) != IFSelect_RetDone) { PyErr_SetString(Base::BaseExceptionFreeCADError, "cannot read IGES file"); return 0; } @@ -179,7 +179,7 @@ static PyObject * importer(PyObject *self, PyObject *args) Base::Console().Error("%s\n", e->GetMessageString()); Base::Console().Message("Try to load IGES file without colors...\n"); - Part::ImportIgesParts(pcDoc,Name); + Part::ImportIgesParts(pcDoc,Utf8Name.c_str()); pcDoc->recompute(); } } @@ -210,9 +210,12 @@ static PyObject * open(PyObject *self, PyObject *args) static PyObject * exporter(PyObject *self, PyObject *args) { PyObject* object; - const char* filename; - if (!PyArg_ParseTuple(args, "Os",&object,&filename)) + char* Name; + if (!PyArg_ParseTuple(args, "Oet",&object,"utf-8",&Name)) return NULL; + std::string Utf8Name = std::string(Name); + PyMem_Free(Name); + std::string name8bit = Part::encodeFilename(Utf8Name); PY_TRY { 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")) { //Interface_Static::SetCVal("write.step.schema", "AP214IS"); STEPCAFControl_Writer writer; @@ -254,15 +257,14 @@ static PyObject * exporter(PyObject *self, PyObject *args) #else APIHeaderSection_MakeHeader makeHeader(writer.Writer().Model()); #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.SetOrganizationValue (1, new TCollection_HAsciiString("FreeCAD")); makeHeader.SetOriginatingSystem(new TCollection_HAsciiString("FreeCAD")); makeHeader.SetDescriptionValue(1, new TCollection_HAsciiString("FreeCAD Model")); - QString fn = QString::fromUtf8(filename); - IFSelect_ReturnStatus ret = writer.Write((const char*)fn.toLocal8Bit()); + IFSelect_ReturnStatus ret = writer.Write((const char*)name8bit.c_str()); 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; } } @@ -270,10 +272,9 @@ static PyObject * exporter(PyObject *self, PyObject *args) IGESControl_Controller::Init(); IGESCAFControl_Writer writer; writer.Transfer(hDoc); - QString fn = QString::fromUtf8(filename); - Standard_Boolean ret = writer.Write((const char*)fn.toLocal8Bit()); + Standard_Boolean ret = writer.Write((const char*)name8bit.c_str()); if (!ret) { - PyErr_Format(PyExc_IOError, "Cannot open file '%s'", filename); + PyErr_Format(PyExc_IOError, "Cannot open file '%s'", Utf8Name.c_str()); return 0; } } diff --git a/src/Mod/JtReader/App/AppJtReaderPy.cpp b/src/Mod/JtReader/App/AppJtReaderPy.cpp index 9011f0168..8182a38cf 100644 --- a/src/Mod/JtReader/App/AppJtReaderPy.cpp +++ b/src/Mod/JtReader/App/AppJtReaderPy.cpp @@ -48,17 +48,18 @@ using namespace MeshCore; //using namespace JtReader; /* module functions */ -static PyObject * read(PyObject *self, PyObject *args) -{ - const char* Name; - if (! PyArg_ParseTuple(args, "s",&Name)) - return NULL; - +static PyObject * read(PyObject *self, PyObject *args) +{ + 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 apcKernel(new MeshCore::MeshKernel()); - readFile(Name,0); + readFile(EncodedName.c_str(),0); vector facets; facets.resize(iterSize()); @@ -87,17 +88,19 @@ static PyObject * read(PyObject *self, PyObject *args) Py_Return; } -static PyObject * -open(PyObject *self, PyObject *args) -{ - const char* Name; - if (! PyArg_ParseTuple(args, "s",&Name)) - return NULL; - +static PyObject * +open(PyObject *self, PyObject *args) +{ + char* Name; + if (!PyArg_ParseTuple(args, "et","utf-8",&Name)) + return NULL; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); + PY_TRY { //Base::Console().Log("Open in Mesh with %s",Name); - Base::FileInfo file(Name); + Base::FileInfo file(EncodedName.c_str()); // extract ending if(file.extension() == "") @@ -111,7 +114,7 @@ open(PyObject *self, PyObject *args) std::auto_ptr apcKernel(new MeshCore::MeshKernel()); - readFile(Name,0); + readFile(EncodedName.c_str(),0); vector facets; facets.resize(iterSize()); @@ -151,17 +154,19 @@ open(PyObject *self, PyObject *args) /* module functions */ -static PyObject * -insert(PyObject *self, PyObject *args) +static PyObject * +insert(PyObject *self, PyObject *args) { - const char* Name; + char* Name; const char* DocName; - if (! PyArg_ParseTuple(args, "ss",&Name,&DocName)) - return NULL; - + if (!PyArg_ParseTuple(args, "ets","utf-8",&Name,&DocName)) + return NULL; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); + PY_TRY { - Base::FileInfo file(Name); + Base::FileInfo file(EncodedName.c_str()); // extract ending if(file.extension() == "") @@ -178,7 +183,7 @@ insert(PyObject *self, PyObject *args) Py_Error(Base::BaseExceptionFreeCADError,szBuf); } - readFile(Name,0); + readFile(EncodedName.c_str(),0); vector facets; @@ -212,7 +217,7 @@ insert(PyObject *self, PyObject *args) }else{ clearData(); //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 diff --git a/src/Mod/Mesh/App/AppMeshPy.cpp b/src/Mod/Mesh/App/AppMeshPy.cpp index e0577de63..0170f751f 100644 --- a/src/Mod/Mesh/App/AppMeshPy.cpp +++ b/src/Mod/Mesh/App/AppMeshPy.cpp @@ -52,13 +52,15 @@ using namespace MeshCore; /* module functions */ static PyObject * read(PyObject *self, PyObject *args) { - const char* Name; - if (!PyArg_ParseTuple(args, "s",&Name)) + 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 mesh(new MeshObject); - if (mesh->load(Name)) { + if (mesh->load(EncodedName.c_str())) { return new MeshPy(mesh.release()); } else { @@ -72,14 +74,16 @@ static PyObject * read(PyObject *self, PyObject *args) static PyObject * open(PyObject *self, PyObject *args) { - const char* Name; - if (!PyArg_ParseTuple(args, "s",&Name)) + char* Name; + if (!PyArg_ParseTuple(args, "et","utf-8",&Name)) return NULL; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); PY_TRY { MeshObject mesh; - if (mesh.load(Name)) { - Base::FileInfo file(Name); + if (mesh.load(EncodedName.c_str())) { + Base::FileInfo file(EncodedName.c_str()); // create new document and add Import feature App::Document *pcDoc = App::GetApplication().newDocument("Unnamed"); unsigned long segmct = mesh.countSegments(); @@ -108,11 +112,12 @@ static PyObject * open(PyObject *self, PyObject *args) static PyObject * importer(PyObject *self, PyObject *args) { - const char* Name; - const char* DocName=0; - - if (!PyArg_ParseTuple(args, "s|s",&Name,&DocName)) + char* Name; + char* DocName=0; + if (!PyArg_ParseTuple(args, "et|s","utf-8",&Name,&DocName)) return NULL; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); PY_TRY { App::Document *pcDoc = 0; @@ -126,8 +131,8 @@ static PyObject * importer(PyObject *self, PyObject *args) } MeshObject mesh; - if (mesh.load(Name)) { - Base::FileInfo file(Name); + if (mesh.load(EncodedName.c_str())) { + Base::FileInfo file(EncodedName.c_str()); unsigned long segmct = mesh.countSegments(); if (segmct > 1) { for (unsigned long i=0; iaddObject("Part::ImportStep",file.fileNamePure().c_str()); pcFeature->FileName.setValue(Name); @@ -169,14 +171,14 @@ static PyObject * open(PyObject *self, PyObject *args) #if 1 else if (file.hasExtension("igs") || file.hasExtension("iges")) { App::Document *pcDoc = App::GetApplication().newDocument("Unnamed"); - ImportIgesParts(pcDoc,Name); + ImportIgesParts(pcDoc,EncodedName.c_str()); pcDoc->recompute(); } #endif else { try { TopoShape shape; - shape.read(Name); + shape.read(EncodedName.c_str()); // create new document set loaded shape App::Document *pcDoc = App::GetApplication().newDocument(file.fileNamePure().c_str()); @@ -197,14 +199,16 @@ static PyObject * open(PyObject *self, PyObject *args) /* module functions */ static PyObject * insert(PyObject *self, PyObject *args) { - const char* Name; + char* Name; const char* DocName; - if (!PyArg_ParseTuple(args, "ss",&Name,&DocName)) - return NULL; + if (!PyArg_ParseTuple(args, "ets","utf-8",&Name,&DocName)) + return NULL; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); PY_TRY { //Base::Console().Log("Insert in Part with %s",Name); - Base::FileInfo file(Name); + Base::FileInfo file(EncodedName.c_str()); // extract ending if (file.extension() == "") @@ -216,7 +220,7 @@ static PyObject * insert(PyObject *self, PyObject *args) if (file.hasExtension("stp") || file.hasExtension("step")) { #if 1 - ImportStepParts(pcDoc,Name); + ImportStepParts(pcDoc,EncodedName.c_str()); #else // add Import feature 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 else if (file.hasExtension("igs") || file.hasExtension("iges")) { - ImportIgesParts(pcDoc,Name); + ImportIgesParts(pcDoc,EncodedName.c_str()); pcDoc->recompute(); } #endif else { try { TopoShape shape; - shape.read(Name); + shape.read(EncodedName.c_str()); Part::Feature *object = static_cast(pcDoc->addObject ("Part::Feature",file.fileNamePure().c_str())); @@ -253,9 +257,11 @@ static PyObject * insert(PyObject *self, PyObject *args) static PyObject * exporter(PyObject *self, PyObject *args) { PyObject* object; - const char* filename; - if (!PyArg_ParseTuple(args, "Os",&object,&filename)) + char* Name; + if (!PyArg_ParseTuple(args, "Oet",&object,"utf-8",&Name)) return NULL; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); BRep_Builder builder; TopoDS_Compound comp; @@ -280,7 +286,7 @@ static PyObject * exporter(PyObject *self, PyObject *args) } TopoShape shape(comp); - shape.write(filename); + shape.write(EncodedName.c_str()); } PY_CATCH_OCC; @@ -290,12 +296,14 @@ static PyObject * exporter(PyObject *self, PyObject *args) /* module functions */ static PyObject * read(PyObject *self, PyObject *args) { - const char* Name; - if (!PyArg_ParseTuple(args, "s",&Name)) - return NULL; + char* Name; + if (!PyArg_ParseTuple(args, "et","utf-8",&Name)) + return NULL; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); PY_TRY { TopoShape* shape = new TopoShape(); - shape->read(Name); + shape->read(EncodedName.c_str()); return new TopoShapePy(shape); } PY_CATCH_OCC; } diff --git a/src/Mod/Part/App/CMakeLists.txt b/src/Mod/Part/App/CMakeLists.txt index a942a8a70..1d1748622 100644 --- a/src/Mod/Part/App/CMakeLists.txt +++ b/src/Mod/Part/App/CMakeLists.txt @@ -244,6 +244,7 @@ SET(Part_SRCS modelRefine.cpp modelRefine.h Tools.h + encodeFilename.h OCCError.h FT2FC.cpp FT2FC.h diff --git a/src/Mod/Part/App/ImportStep.cpp b/src/Mod/Part/App/ImportStep.cpp index 3c48532fa..69d773a7b 100644 --- a/src/Mod/Part/App/ImportStep.cpp +++ b/src/Mod/Part/App/ImportStep.cpp @@ -76,6 +76,7 @@ #include "ImportStep.h" #include "PartFeature.h" #include "ProgressIndicator.h" +#include "encodeFilename.h" using namespace Part; @@ -95,8 +96,11 @@ int Part::ImportStepParts(App::Document *pcDoc, const char* Name) str << "File '" << Name << "' does not exist!"; 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"); } diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp index c6135df3e..a7ca52187 100644 --- a/src/Mod/Part/App/TopoShape.cpp +++ b/src/Mod/Part/App/TopoShape.cpp @@ -166,6 +166,7 @@ #include "ProgressIndicator.h" #include "modelRefine.h" #include "Tools.h" +#include "encodeFilename.h" using namespace Part; @@ -570,8 +571,7 @@ void TopoShape::importIges(const char *FileName) IGESControl_Controller::Init(); Interface_Static::SetIVal("read.surfacecurve.mode",3); IGESControl_Reader aReader; - QString fn = QString::fromUtf8(FileName); - if (aReader.ReadFile((const char*)fn.toLocal8Bit()) != IFSelect_RetDone) + if (aReader.ReadFile(encodeFilename(FileName).c_str()) != IFSelect_RetDone) throw Base::Exception("Error in reading IGES"); Handle_Message_ProgressIndicator pi = new ProgressIndicator(100); @@ -596,8 +596,7 @@ void TopoShape::importStep(const char *FileName) { try { STEPControl_Reader aReader; - QString fn = QString::fromUtf8(FileName); - if (aReader.ReadFile((const char*)fn.toLocal8Bit()) != IFSelect_RetDone) + if (aReader.ReadFile(encodeFilename(FileName).c_str()) != IFSelect_RetDone) throw Base::Exception("Error in reading STEP"); Handle_Message_ProgressIndicator pi = new ProgressIndicator(100); @@ -627,8 +626,7 @@ void TopoShape::importBrep(const char *FileName) Handle_Message_ProgressIndicator pi = new ProgressIndicator(100); pi->NewScope(100, "Reading BREP file..."); pi->Show(); - QString fn = QString::fromUtf8(FileName); - BRepTools::Read(aShape,(const char*)fn.toLocal8Bit(),aBuilder,pi); + BRepTools::Read(aShape,encodeFilename(FileName).c_str(),aBuilder,pi); pi->EndScope(); #else BRepTools::Read(aShape,(const Standard_CString)FileName,aBuilder); @@ -699,8 +697,7 @@ void TopoShape::exportIges(const char *filename) const IGESControl_Writer aWriter; aWriter.AddShape(this->_Shape); aWriter.ComputeModel(); - QString fn = QString::fromUtf8(filename); - if (aWriter.Write((const char*)fn.toLocal8Bit()) != IFSelect_RetDone) + if (aWriter.Write(encodeFilename(filename).c_str()) != IFSelect_RetDone) throw Base::Exception("Writing of IGES failed"); } catch (Standard_Failure) { @@ -724,14 +721,13 @@ void TopoShape::exportStep(const char *filename) const throw Base::Exception("Error in transferring STEP"); 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.SetOrganizationValue (1, new TCollection_HAsciiString("FreeCAD")); makeHeader.SetOriginatingSystem(new TCollection_HAsciiString("FreeCAD")); makeHeader.SetDescriptionValue(1, new TCollection_HAsciiString("FreeCAD Model")); - QString fn = QString::fromUtf8(filename); - if (aWriter.Write((const char*)fn.toLocal8Bit()) != IFSelect_RetDone) + if (aWriter.Write(encodeFilename(filename).c_str()) != IFSelect_RetDone) throw Base::Exception("Writing of STEP failed"); pi->EndScope(); } @@ -743,8 +739,7 @@ void TopoShape::exportStep(const char *filename) const void TopoShape::exportBrep(const char *filename) const { - QString fn = QString::fromUtf8(filename); - if (!BRepTools::Write(this->_Shape,(const char*)fn.toLocal8Bit())) + if (!BRepTools::Write(this->_Shape,encodeFilename(filename).c_str())) throw Base::Exception("Writing of BREP failed"); } @@ -765,8 +760,7 @@ void TopoShape::exportStl(const char *filename, double deflection) const writer.RelativeMode() = false; writer.SetDeflection(deflection); } - QString fn = QString::fromUtf8(filename); - writer.Write(this->_Shape,(const Standard_CString)fn.toLocal8Bit()); + writer.Write(this->_Shape,encodeFilename(filename).c_str()); } void TopoShape::exportFaceSet(double dev, double ca, std::ostream& str) const diff --git a/src/Mod/Part/App/TopoShapePyImp.cpp b/src/Mod/Part/App/TopoShapePyImp.cpp index 1fdf6b8a8..e28fa73f2 100644 --- a/src/Mod/Part/App/TopoShapePyImp.cpp +++ b/src/Mod/Part/App/TopoShapePyImp.cpp @@ -260,11 +260,13 @@ PyObject* TopoShapePy::removeShape(PyObject *args) PyObject* TopoShapePy::read(PyObject *args) { - char* filename; - if (!PyArg_ParseTuple(args, "s", &filename)) + char* Name; + if (!PyArg_ParseTuple(args, "et","utf-8",&Name)) return NULL; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); - getTopoShapePtr()->read(filename); + getTopoShapePtr()->read(EncodedName.c_str()); Py_Return; } @@ -292,13 +294,15 @@ PyObject* TopoShapePy::writeInventor(PyObject * args) PyObject* TopoShapePy::exportIges(PyObject *args) { - char* filename; - if (!PyArg_ParseTuple(args, "s", &filename)) + char* Name; + if (!PyArg_ParseTuple(args, "et","utf-8",&Name)) return NULL; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); try { // write iges file - getTopoShapePtr()->exportIges(filename); + getTopoShapePtr()->exportIges(EncodedName.c_str()); } catch (const Base::Exception& e) { PyErr_SetString(PartExceptionOCCError,e.what()); @@ -310,13 +314,15 @@ PyObject* TopoShapePy::exportIges(PyObject *args) PyObject* TopoShapePy::exportStep(PyObject *args) { - char* filename; - if (!PyArg_ParseTuple(args, "s", &filename)) + char* Name; + if (!PyArg_ParseTuple(args, "et","utf-8",&Name)) return NULL; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); try { // write step file - getTopoShapePtr()->exportStep(filename); + getTopoShapePtr()->exportStep(EncodedName.c_str()); } catch (const Base::Exception& e) { PyErr_SetString(PartExceptionOCCError,e.what()); @@ -328,13 +334,15 @@ PyObject* TopoShapePy::exportStep(PyObject *args) PyObject* TopoShapePy::exportBrep(PyObject *args) { - char* filename; - if (!PyArg_ParseTuple(args, "s", &filename)) + char* Name; + if (!PyArg_ParseTuple(args, "et","utf-8",&Name)) return NULL; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); try { // write brep file - getTopoShapePtr()->exportBrep(filename); + getTopoShapePtr()->exportBrep(EncodedName.c_str()); } catch (const Base::Exception& e) { PyErr_SetString(PartExceptionOCCError,e.what()); @@ -449,14 +457,16 @@ PyObject* TopoShapePy::importBrepFromString(PyObject *args) PyObject* TopoShapePy::exportStl(PyObject *args) { - char* filename; 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; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); try { // write stl file - getTopoShapePtr()->exportStl(filename, deflection); + getTopoShapePtr()->exportStl(EncodedName.c_str(), deflection); } catch (const Base::Exception& e) { PyErr_SetString(PartExceptionOCCError,e.what()); diff --git a/src/Mod/Part/App/encodeFilename.h b/src/Mod/Part/App/encodeFilename.h new file mode 100644 index 000000000..4fadafa3e --- /dev/null +++ b/src/Mod/Part/App/encodeFilename.h @@ -0,0 +1,48 @@ +/*************************************************************************** + * Copyright (c) 2014 Sebastian Hoogen * + * * + * 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 +#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 diff --git a/src/Mod/Points/App/AppPointsPy.cpp b/src/Mod/Points/App/AppPointsPy.cpp index a7895207f..a0f342339 100644 --- a/src/Mod/Points/App/AppPointsPy.cpp +++ b/src/Mod/Points/App/AppPointsPy.cpp @@ -52,13 +52,15 @@ using namespace Points; static PyObject * open(PyObject *self, PyObject *args) { - const char* Name; - if (!PyArg_ParseTuple(args, "s",&Name)) + char* Name; + if (!PyArg_ParseTuple(args, "et","utf-8",&Name)) return NULL; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); PY_TRY { - Base::Console().Log("Open in Points with %s",Name); - Base::FileInfo file(Name); + Base::Console().Log("Open in Points with %s",EncodedName.c_str()); + Base::FileInfo file(EncodedName.c_str()); // extract ending if (file.extension() == "") @@ -69,7 +71,7 @@ open(PyObject *self, PyObject *args) App::Document *pcDoc = App::GetApplication().newDocument("Unnamed"); Points::Feature *pcFeature = (Points::Feature *)pcDoc->addObject("Points::Feature", file.fileNamePure().c_str()); Points::PointKernel pkTemp; - pkTemp.load(Name); + pkTemp.load(EncodedName.c_str()); pcFeature->Points.setValue( pkTemp ); } @@ -82,7 +84,7 @@ open(PyObject *self, PyObject *args) // pcl test pcl::PointCloud cloud_in; - pcl::io::loadPLYFile(Name,cloud_in); + pcl::io::loadPLYFile(EncodedName.c_str(),cloud_in); for (pcl::PointCloud::const_iterator it = cloud_in.begin();it!=cloud_in.end();++it) pkTemp.push_back(Base::Vector3d(it->x,it->y,it->z)); @@ -100,14 +102,16 @@ open(PyObject *self, PyObject *args) static PyObject * insert(PyObject *self, PyObject *args) { - const char* Name; + char* Name; const char* DocName; - if (!PyArg_ParseTuple(args, "ss",&Name,&DocName)) + if (!PyArg_ParseTuple(args, "ets","utf-8",&Name,&DocName)) return NULL; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); PY_TRY { - Base::Console().Log("Import in Points with %s",Name); - Base::FileInfo file(Name); + Base::Console().Log("Import in Points with %s",EncodedName.c_str()); + Base::FileInfo file(EncodedName.c_str()); // extract ending 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::PointKernel pkTemp; - pkTemp.load(Name); + pkTemp.load(EncodedName.c_str()); pcFeature->Points.setValue( pkTemp ); } #ifdef HAVE_PCL_IO @@ -137,7 +141,7 @@ insert(PyObject *self, PyObject *args) // pcl test pcl::PointCloud cloud_in; - pcl::io::loadPLYFile(Name,cloud_in); + pcl::io::loadPLYFile(EncodedName.c_str(),cloud_in); for (pcl::PointCloud::const_iterator it = cloud_in.begin();it!=cloud_in.end();++it) pkTemp.push_back(Base::Vector3d(it->x,it->y,it->z)); diff --git a/src/Mod/Raytracing/Gui/AppRaytracingGuiPy.cpp b/src/Mod/Raytracing/Gui/AppRaytracingGuiPy.cpp index 62b8692cb..91bb8b063 100644 --- a/src/Mod/Raytracing/Gui/AppRaytracingGuiPy.cpp +++ b/src/Mod/Raytracing/Gui/AppRaytracingGuiPy.cpp @@ -53,12 +53,14 @@ static PyObject * open(PyObject *self, PyObject *args) { // only used to open Povray files - const char* Name; + char* Name; const char* DocName; - if (!PyArg_ParseTuple(args, "s|s",&Name, &DocName)) + if (!PyArg_ParseTuple(args, "et|s","utf-8",&Name,&DocName)) return NULL; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); PY_TRY { - QString fileName = QString::fromUtf8(Name); + QString fileName = QString::fromUtf8(EncodedName.c_str()); QFileInfo fi; fi.setFile(fileName); QString ext = fi.completeSuffix().toLower(); diff --git a/src/Mod/Sketcher/App/AppSketcherPy.cpp b/src/Mod/Sketcher/App/AppSketcherPy.cpp index 348eb709c..e97fb7740 100644 --- a/src/Mod/Sketcher/App/AppSketcherPy.cpp +++ b/src/Mod/Sketcher/App/AppSketcherPy.cpp @@ -50,14 +50,16 @@ using namespace std; /* module functions */ static PyObject * open(PyObject *self, PyObject *args) { - const char* Name; - if (!PyArg_ParseTuple(args, "s",&Name)) - return NULL; + char* Name; + if (!PyArg_ParseTuple(args, "et","utf-8",&Name)) + return NULL; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); PY_TRY { } PY_CATCH; //Base::Console().Log("Open in Part with %s",Name); - Base::FileInfo file(Name); + Base::FileInfo file(EncodedName.c_str()); // extract ending if (file.extension() == "") @@ -80,14 +82,16 @@ static PyObject * open(PyObject *self, PyObject *args) /* module functions */ static PyObject * insert(PyObject *self, PyObject *args) { - const char* Name; - const char* DocName; - if (!PyArg_ParseTuple(args, "ss",&Name,&DocName)) - return NULL; + 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 { //Base::Console().Log("Insert in Part with %s",Name); - Base::FileInfo file(Name); + Base::FileInfo file(EncodedName.c_str()); // extract ending if (file.extension() == "") @@ -100,7 +104,7 @@ static PyObject * insert(PyObject *self, PyObject *args) if (file.hasExtension("skf")) { 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(); } diff --git a/src/Mod/Sketcher/Gui/AppSketcherGuiPy.cpp b/src/Mod/Sketcher/Gui/AppSketcherGuiPy.cpp index d1694ac26..703b3a2fa 100644 --- a/src/Mod/Sketcher/Gui/AppSketcherGuiPy.cpp +++ b/src/Mod/Sketcher/Gui/AppSketcherGuiPy.cpp @@ -39,9 +39,11 @@ static PyObject * open(PyObject *self, PyObject *args) { - const char* Name; - if (! PyArg_ParseTuple(args, "s",&Name)) - return NULL; + char* Name; + if (!PyArg_ParseTuple(args, "et","utf-8",&Name)) + return NULL; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); PY_TRY { } PY_CATCH;