issue #1027 use unicode filepaths
This commit is contained in:
@@ -78,10 +78,9 @@
|
||||
#include <Mod/Part/App/ProgressIndicator.h>
|
||||
#include <Mod/Part/App/ImportIges.h>
|
||||
#include <Mod/Part/App/ImportStep.h>
|
||||
#include <Mod/Part/App/encodeFilename.h>
|
||||
#include <Mod/Import/App/ImportOCAF.h>
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user