From 4b2474807b2f94432e80fbd2da1203208eab3dfb Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 27 Jun 2013 14:16:41 +0200 Subject: [PATCH] 0001160: Freecad sometimes 'forgets' the ability to handle stp files --- src/Mod/Import/Gui/AppImportGuiPy.cpp | 83 +++++++++++++++++---------- src/Mod/Import/Gui/CMakeLists.txt | 2 + src/Mod/Part/App/AppPart.cpp | 10 ---- src/Mod/Part/App/ImportIges.h | 2 +- src/Mod/Part/App/ImportStep.h | 2 +- src/Mod/Part/Init.py | 13 +---- 6 files changed, 59 insertions(+), 53 deletions(-) diff --git a/src/Mod/Import/Gui/AppImportGuiPy.cpp b/src/Mod/Import/Gui/AppImportGuiPy.cpp index f9ce41189..d5cef5a02 100644 --- a/src/Mod/Import/Gui/AppImportGuiPy.cpp +++ b/src/Mod/Import/Gui/AppImportGuiPy.cpp @@ -57,6 +57,7 @@ # include # include # include +# include #if OCC_VERSION_HEX >= 0x060500 # include # else @@ -74,6 +75,8 @@ #include #include #include +#include +#include @@ -507,40 +510,60 @@ static PyObject * importer(PyObject *self, PyObject *args) hApp->NewDocument(TCollection_ExtendedString("MDTV-CAF"), hDoc); if (file.hasExtension("stp") || file.hasExtension("step")) { - STEPCAFControl_Reader aReader; - aReader.SetColorMode(true); - aReader.SetNameMode(true); - aReader.SetLayerMode(true); - if (aReader.ReadFile((Standard_CString)Name) != IFSelect_RetDone) { - PyErr_SetString(PyExc_Exception, "cannot read STEP file"); - return 0; - } + try { + STEPCAFControl_Reader aReader; + aReader.SetColorMode(true); + aReader.SetNameMode(true); + aReader.SetLayerMode(true); + if (aReader.ReadFile((Standard_CString)Name) != IFSelect_RetDone) { + PyErr_SetString(PyExc_Exception, "cannot read STEP file"); + return 0; + } - Handle_Message_ProgressIndicator pi = new Part::ProgressIndicator(100); - aReader.Reader().WS()->MapReader()->SetProgress(pi); - pi->NewScope(100, "Reading STEP file..."); - pi->Show(); - aReader.Transfer(hDoc); - pi->EndScope(); + Handle_Message_ProgressIndicator pi = new Part::ProgressIndicator(100); + aReader.Reader().WS()->MapReader()->SetProgress(pi); + pi->NewScope(100, "Reading STEP file..."); + pi->Show(); + aReader.Transfer(hDoc); + pi->EndScope(); + } + catch (OSD_Exception) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + Base::Console().Error("%s\n", e->GetMessageString()); + Base::Console().Message("Try to load STEP file without colors...\n"); + + Part::ImportStepParts(pcDoc,Name); + pcDoc->recompute(); + } } else if (file.hasExtension("igs") || file.hasExtension("iges")) { - IGESControl_Controller::Init(); - Interface_Static::SetIVal("read.surfacecurve.mode",3); - IGESCAFControl_Reader aReader; - aReader.SetColorMode(true); - aReader.SetNameMode(true); - aReader.SetLayerMode(true); - if (aReader.ReadFile((Standard_CString)Name) != IFSelect_RetDone) { - PyErr_SetString(PyExc_Exception, "cannot read IGES file"); - return 0; - } + try { + IGESControl_Controller::Init(); + Interface_Static::SetIVal("read.surfacecurve.mode",3); + IGESCAFControl_Reader aReader; + aReader.SetColorMode(true); + aReader.SetNameMode(true); + aReader.SetLayerMode(true); + if (aReader.ReadFile((Standard_CString)Name) != IFSelect_RetDone) { + PyErr_SetString(PyExc_Exception, "cannot read IGES file"); + return 0; + } - Handle_Message_ProgressIndicator pi = new Part::ProgressIndicator(100); - aReader.WS()->MapReader()->SetProgress(pi); - pi->NewScope(100, "Reading IGES file..."); - pi->Show(); - aReader.Transfer(hDoc); - pi->EndScope(); + Handle_Message_ProgressIndicator pi = new Part::ProgressIndicator(100); + aReader.WS()->MapReader()->SetProgress(pi); + pi->NewScope(100, "Reading IGES file..."); + pi->Show(); + aReader.Transfer(hDoc); + pi->EndScope(); + } + catch (OSD_Exception) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + Base::Console().Error("%s\n", e->GetMessageString()); + Base::Console().Message("Try to load IGES file without colors...\n"); + + Part::ImportIgesParts(pcDoc,Name); + pcDoc->recompute(); + } } else { PyErr_SetString(PyExc_Exception, "no supported file format"); diff --git a/src/Mod/Import/Gui/CMakeLists.txt b/src/Mod/Import/Gui/CMakeLists.txt index 4d2862ec7..39193982c 100644 --- a/src/Mod/Import/Gui/CMakeLists.txt +++ b/src/Mod/Import/Gui/CMakeLists.txt @@ -50,6 +50,8 @@ if(MSVC) set_target_properties(ImportGui PROPERTIES DEBUG_OUTPUT_NAME "ImportGui_d") set_target_properties(ImportGui PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Mod/Import) set_target_properties(ImportGui PROPERTIES PREFIX "../") + # Set special compiler flag to convert a SIGSEV into an exception + set_target_properties(ImportGui PROPERTIES COMPILE_FLAGS "/EHa") elseif(MINGW) set_target_properties(ImportGui PROPERTIES SUFFIX ".pyd") set_target_properties(ImportGui PROPERTIES DEBUG_OUTPUT_NAME "ImportGui_d") diff --git a/src/Mod/Part/App/AppPart.cpp b/src/Mod/Part/App/AppPart.cpp index 2f5c49189..76ed19154 100644 --- a/src/Mod/Part/App/AppPart.cpp +++ b/src/Mod/Part/App/AppPart.cpp @@ -93,16 +93,6 @@ void PartExport initPart() str << OCC_VERSION_MAJOR << "." << OCC_VERSION_MINOR << "." << OCC_VERSION_MAINTENANCE; App::Application::Config()["OCC_VERSION"] = str.str(); - // see Init.py -#if defined (_OCC64) -#if OCC_VERSION_HEX < 0x060503 - App::GetApplication().addImportType("STEP (*.step *.stp)","Part"); - App::GetApplication().addExportType("STEP (*.step *.stp)","Part"); -#else - App::GetApplication().addImportType("STEP with colors (*.step *.stp)","ImportGui"); - App::GetApplication().addExportType("STEP with colors (*.step *.stp)","ImportGui"); -#endif -#endif // This is highly experimental and we should keep an eye on it // if we have mysterious crashes // The argument must be 'Standard_False' to avoid FPE caused by diff --git a/src/Mod/Part/App/ImportIges.h b/src/Mod/Part/App/ImportIges.h index a6d695710..c527d8be0 100644 --- a/src/Mod/Part/App/ImportIges.h +++ b/src/Mod/Part/App/ImportIges.h @@ -33,7 +33,7 @@ class Document; namespace Part { -int ImportIgesParts(App::Document *pcDoc, const char* Name); +PartExport int ImportIgesParts(App::Document *pcDoc, const char* Name); } //namespace Part diff --git a/src/Mod/Part/App/ImportStep.h b/src/Mod/Part/App/ImportStep.h index 8709e8769..af5e98ad4 100644 --- a/src/Mod/Part/App/ImportStep.h +++ b/src/Mod/Part/App/ImportStep.h @@ -39,7 +39,7 @@ namespace Part /** The part shape property */ -int ImportStepParts(App::Document *pcDoc, const char* Name); +PartExport int ImportStepParts(App::Document *pcDoc, const char* Name); diff --git a/src/Mod/Part/Init.py b/src/Mod/Part/Init.py index 6da3a0373..b81a441b4 100644 --- a/src/Mod/Part/Init.py +++ b/src/Mod/Part/Init.py @@ -49,14 +49,5 @@ FreeCAD.addImportType("BREP format (*.brep *.brp)","Part") FreeCAD.addExportType("BREP format (*.brep *.brp)","Part") FreeCAD.addImportType("IGES format (*.iges *.igs)","Part") FreeCAD.addExportType("IGES format (*.iges *.igs)","Part") - -# There is a bug in OCC 6.5.0 64-bit and older which leads to a crash -# The registration of the STEP filetype for 64-bit is handled in initPart() -import platform -if platform.architecture()[0]=='32bit': - FreeCAD.addImportType("STEP with colors (*.step *.stp)","ImportGui") - FreeCAD.addExportType("STEP with colors (*.step *.stp)","ImportGui") -#else: -# FreeCAD.addImportType("STEP (*.step *.stp)","Part") -# FreeCAD.addExportType("STEP (*.step *.stp)","Part") - +FreeCAD.addImportType("STEP with colors (*.step *.stp)","ImportGui") +FreeCAD.addExportType("STEP with colors (*.step *.stp)","ImportGui")