diff --git a/src/Mod/Import/App/AppImportPy.cpp b/src/Mod/Import/App/AppImportPy.cpp index 25bfa7169..c9cb6918a 100644 --- a/src/Mod/Import/App/AppImportPy.cpp +++ b/src/Mod/Import/App/AppImportPy.cpp @@ -233,13 +233,21 @@ static PyObject * exporter(PyObject *self, PyObject *args) makeHeader.SetOrganizationValue (1, new TCollection_HAsciiString("FreeCAD")); makeHeader.SetOriginatingSystem(new TCollection_HAsciiString("FreeCAD")); makeHeader.SetDescriptionValue(1, new TCollection_HAsciiString("FreeCAD Model")); - writer.Write(filename); + IFSelect_ReturnStatus ret = writer.Write(filename); + if (ret == IFSelect_RetError || ret == IFSelect_RetFail || ret == IFSelect_RetStop) { + PyErr_Format(PyExc_IOError, "Cannot open file '%s'", filename); + return 0; + } } else if (file.hasExtension("igs") || file.hasExtension("iges")) { IGESControl_Controller::Init(); IGESCAFControl_Writer writer; writer.Transfer(hDoc); - writer.Write(filename); + Standard_Boolean ret = writer.Write(filename); + if (!ret) { + PyErr_Format(PyExc_IOError, "Cannot open file '%s'", filename); + return 0; + } } } catch (Standard_Failure) { diff --git a/src/Mod/Import/Gui/AppImportGuiPy.cpp b/src/Mod/Import/Gui/AppImportGuiPy.cpp index 4563f1466..96f9b784f 100644 --- a/src/Mod/Import/Gui/AppImportGuiPy.cpp +++ b/src/Mod/Import/Gui/AppImportGuiPy.cpp @@ -28,6 +28,7 @@ #ifndef _PreComp_ # include # include +# include # include # include # include @@ -130,7 +131,8 @@ static PyObject * importer(PyObject *self, PyObject *args) aReader.SetColorMode(true); aReader.SetNameMode(true); aReader.SetLayerMode(true); - if (aReader.ReadFile((Standard_CString)Name) != IFSelect_RetDone) { + QString fn = QString::fromUtf8(Name); + if (aReader.ReadFile((const char*)fn.toLocal8Bit()) != IFSelect_RetDone) { PyErr_SetString(PyExc_Exception, "cannot read STEP file"); return 0; } @@ -159,7 +161,8 @@ static PyObject * importer(PyObject *self, PyObject *args) aReader.SetColorMode(true); aReader.SetNameMode(true); aReader.SetLayerMode(true); - if (aReader.ReadFile((Standard_CString)Name) != IFSelect_RetDone) { + QString fn = QString::fromUtf8(Name); + if (aReader.ReadFile((const char*)fn.toLocal8Bit()) != IFSelect_RetDone) { PyErr_SetString(PyExc_Exception, "cannot read IGES file"); return 0; } @@ -256,13 +259,23 @@ static PyObject * exporter(PyObject *self, PyObject *args) makeHeader.SetOrganizationValue (1, new TCollection_HAsciiString("FreeCAD")); makeHeader.SetOriginatingSystem(new TCollection_HAsciiString("FreeCAD")); makeHeader.SetDescriptionValue(1, new TCollection_HAsciiString("FreeCAD Model")); - writer.Write(filename); + QString fn = QString::fromUtf8(filename); + IFSelect_ReturnStatus ret = writer.Write((const char*)fn.toLocal8Bit()); + if (ret == IFSelect_RetError || ret == IFSelect_RetFail || ret == IFSelect_RetStop) { + PyErr_Format(PyExc_IOError, "Cannot open file '%s'", filename); + return 0; + } } else if (file.hasExtension("igs") || file.hasExtension("iges")) { IGESControl_Controller::Init(); IGESCAFControl_Writer writer; writer.Transfer(hDoc); - writer.Write(filename); + QString fn = QString::fromUtf8(filename); + Standard_Boolean ret = writer.Write((const char*)fn.toLocal8Bit()); + if (!ret) { + PyErr_Format(PyExc_IOError, "Cannot open file '%s'", filename); + return 0; + } } } catch (Standard_Failure) { diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp index 4bdc9741a..6ef33e341 100644 --- a/src/Mod/Part/App/TopoShape.cpp +++ b/src/Mod/Part/App/TopoShape.cpp @@ -27,6 +27,7 @@ # include # include # include +# include # include # include # include @@ -563,7 +564,8 @@ void TopoShape::importIges(const char *FileName) IGESControl_Controller::Init(); Interface_Static::SetIVal("read.surfacecurve.mode",3); IGESControl_Reader aReader; - if (aReader.ReadFile((const Standard_CString)FileName) != IFSelect_RetDone) + QString fn = QString::fromUtf8(FileName); + if (aReader.ReadFile((const char*)fn.toLocal8Bit()) != IFSelect_RetDone) throw Base::Exception("Error in reading IGES"); Handle_Message_ProgressIndicator pi = new ProgressIndicator(100); @@ -588,7 +590,8 @@ void TopoShape::importStep(const char *FileName) { try { STEPControl_Reader aReader; - if (aReader.ReadFile((const Standard_CString)FileName) != IFSelect_RetDone) + QString fn = QString::fromUtf8(FileName); + if (aReader.ReadFile((const char*)fn.toLocal8Bit()) != IFSelect_RetDone) throw Base::Exception("Error in reading STEP"); Handle_Message_ProgressIndicator pi = new ProgressIndicator(100); @@ -618,7 +621,8 @@ void TopoShape::importBrep(const char *FileName) Handle_Message_ProgressIndicator pi = new ProgressIndicator(100); pi->NewScope(100, "Reading BREP file..."); pi->Show(); - BRepTools::Read(aShape,(const Standard_CString)FileName,aBuilder,pi); + QString fn = QString::fromUtf8(FileName); + BRepTools::Read(aShape,(const char*)fn.toLocal8Bit(),aBuilder,pi); pi->EndScope(); #else BRepTools::Read(aShape,(const Standard_CString)FileName,aBuilder); @@ -691,7 +695,8 @@ void TopoShape::exportIges(const char *filename) const //IGESControl_Writer aWriter(Interface_Static::CVal("write.iges.unit"), 1); aWriter.AddShape(this->_Shape); aWriter.ComputeModel(); - if (aWriter.Write((const Standard_CString)filename) != IFSelect_RetDone) + QString fn = QString::fromUtf8(filename); + if (aWriter.Write((const char*)fn.toLocal8Bit()) != IFSelect_RetDone) throw Base::Exception("Writing of IGES failed"); } catch (Standard_Failure) { @@ -721,7 +726,8 @@ void TopoShape::exportStep(const char *filename) const makeHeader.SetOriginatingSystem(new TCollection_HAsciiString("FreeCAD")); makeHeader.SetDescriptionValue(1, new TCollection_HAsciiString("FreeCAD Model")); - if (aWriter.Write((const Standard_CString)filename) != IFSelect_RetDone) + QString fn = QString::fromUtf8(filename); + if (aWriter.Write((const char*)fn.toLocal8Bit()) != IFSelect_RetDone) throw Base::Exception("Writing of STEP failed"); pi->EndScope(); } @@ -733,7 +739,8 @@ void TopoShape::exportStep(const char *filename) const void TopoShape::exportBrep(const char *filename) const { - if (!BRepTools::Write(this->_Shape,(const Standard_CString)filename)) + QString fn = QString::fromUtf8(filename); + if (!BRepTools::Write(this->_Shape,(const char*)fn.toLocal8Bit())) throw Base::Exception("Writing of BREP failed"); } @@ -752,7 +759,8 @@ void TopoShape::exportStl(const char *filename) const StlAPI_Writer writer; //writer.RelativeMode() = false; //writer.SetDeflection(0.1); - writer.Write(this->_Shape,(const Standard_CString)filename); + QString fn = QString::fromUtf8(filename); + writer.Write(this->_Shape,(const Standard_CString)fn.toLocal8Bit()); } void TopoShape::exportFaceSet(double dev, double ca, std::ostream& str) const