issue #1027 use unicode filepaths

This commit is contained in:
Sebastian Hoogen
2014-09-21 23:45:32 +02:00
committed by wmayer
parent 7db2cdc008
commit 01cf0f5872
28 changed files with 396 additions and 243 deletions

View File

@@ -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
{

View File

@@ -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<App::DocumentObjectPy*>(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;
}

View File

@@ -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());
}
}

View File

@@ -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<FemMesh> 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<FemMesh> 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<FemMeshObject *>
@@ -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<FemMesh> 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<FemMeshObject *>
(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<App::DocumentObjectPy*>(item)->getDocumentObjectPtr();
if (obj->getTypeId().isDerivedFrom(meshId)) {
static_cast<FemMeshObject*>(obj)->FemMesh.getValue().write(filename);
static_cast<FemMeshObject*>(obj)->FemMesh.getValue().write(EncodedName.c_str());
break;
}
}

View File

@@ -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());

View File

@@ -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);

View File

@@ -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

View File

@@ -56,8 +56,7 @@
#include <Mod/Part/App/ProgressIndicator.h>
#include <Mod/Part/App/ImportIges.h>
#include <Mod/Part/App/ImportStep.h>
#include <Mod/Part/App/encodeFilename.h>
/* 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;
}
}

View File

@@ -13,6 +13,7 @@ include_directories(
${ZLIB_INCLUDE_DIR}
${PYTHON_INCLUDE_PATH}
${XERCESC_INCLUDE_DIR}
${QT_INCLUDE_DIR}
)
link_directories(${OCC_LIBRARY_DIR})

View File

@@ -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;
}
}

View File

@@ -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<MeshCore::MeshKernel> apcKernel(new MeshCore::MeshKernel());
readFile(Name,0);
readFile(EncodedName.c_str(),0);
vector<MeshGeomFacet> 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<MeshCore::MeshKernel> apcKernel(new MeshCore::MeshKernel());
readFile(Name,0);
readFile(EncodedName.c_str(),0);
vector<MeshGeomFacet> 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<MeshGeomFacet> 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

View File

@@ -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<MeshObject> 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; i<segmct; i++) {
@@ -155,9 +160,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);
float fTolerance = 0.1f;
MeshObject global_mesh;
@@ -200,7 +207,7 @@ static PyObject * exporter(PyObject *self, PyObject *args)
}
// export mesh compound
global_mesh.save(filename);
global_mesh.save(EncodedName.c_str());
} PY_CATCH;
Py_Return;

View File

@@ -143,13 +143,15 @@ extern const char* BRepBuilderAPI_FaceErrorText(BRepBuilderAPI_FaceError fe);
/* 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 {
//Base::Console().Log("Open in Part with %s",Name);
Base::FileInfo file(Name);
Base::FileInfo file(EncodedName.c_str());
// extract ending
if (file.extension() == "")
@@ -159,7 +161,7 @@ static PyObject * open(PyObject *self, PyObject *args)
// create new document and add Import feature
App::Document *pcDoc = App::GetApplication().newDocument("Unnamed");
#if 1
ImportStepParts(pcDoc,Name);
ImportStepParts(pcDoc,EncodedName.c_str());
#else
Part::ImportStep *pcFeature = (Part::ImportStep *)pcDoc->addObject("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<Part::Feature *>(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;
}

View File

@@ -244,6 +244,7 @@ SET(Part_SRCS
modelRefine.cpp
modelRefine.h
Tools.h
encodeFilename.h
OCCError.h
FT2FC.cpp
FT2FC.h

View File

@@ -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");
}

View File

@@ -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

View File

@@ -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());

View 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

View File

@@ -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<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)
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<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)
pkTemp.push_back(Base::Vector3d(it->x,it->y,it->z));

View File

@@ -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();

View File

@@ -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();
}

View File

@@ -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;