diff --git a/src/App/ApplicationPy.cpp b/src/App/ApplicationPy.cpp index 815390cee9..c69db57686 100644 --- a/src/App/ApplicationPy.cpp +++ b/src/App/ApplicationPy.cpp @@ -205,6 +205,9 @@ PyObject* Application::sOpenDocument(PyObject * /*self*/, PyObject *args) // return new document return (GetApplication().openDocument(EncodedName.c_str())->getPyObject()); } + catch(const Base::RestoreError) { + throw; // propagate it to python/gui + } catch (const Base::Exception& e) { PyErr_SetString(PyExc_IOError, e.what()); return 0L; diff --git a/src/App/Document.cpp b/src/App/Document.cpp index bf5220cd30..6257eca1d8 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -1355,7 +1355,7 @@ void Document::Save (Base::Writer &writer) const } void Document::Restore(Base::XMLReader &reader) -{ +{ int i,Cnt; Base::ObjectStatusLocker restoreBit(Status::Restoring, this); @@ -1436,6 +1436,10 @@ void Document::Restore(Base::XMLReader &reader) } reader.readEndElement("Document"); + + if(testStatus(Document::PartialRestore)) { + THROW(Base::RestoreError); + } } void Document::exportObjects(const std::vector& obj, @@ -1510,7 +1514,7 @@ void Document::writeObjects(const std::vector& obj, std::vector Document::readObjects(Base::XMLReader& reader) -{ +{ bool keepDigits = testStatus(Document::KeepTrailingDigits); setStatus(Document::KeepTrailingDigits, !reader.doNameMapping()); std::vector objs; @@ -1576,6 +1580,13 @@ Document::readObjects(Base::XMLReader& reader) catch (const Base::RuntimeError &e) { e.ReportException(); } + catch(const Base::RestoreError &e) { + e.ReportException(); + Base::Console().Error("Object \"%s\" was subject to a partial restore. As a result geometry may have changed or be incomplete.",name.c_str()); + + setStatus(Document::PartialRestore, true); + } + pObj->setStatus(ObjectStatus::Restore, false); } reader.readEndElement("Object"); @@ -1809,6 +1820,7 @@ bool Document::saveToFile(const char* filename) const // Open the document void Document::restore (void) { + bool partialrestore; // clean up if the document is not empty // !TODO mind exceptions while restoring! clearUndos(); @@ -1847,6 +1859,10 @@ void Document::restore (void) try { Document::Restore(reader); } + catch(Base::RestoreError &e) { + e.ReportException(); + partialrestore = true; + } catch (const Base::Exception& e) { Base::Console().Error("Invalid Document.xml: %s\n", e.what()); } @@ -1873,6 +1889,9 @@ void Document::restore (void) GetApplication().signalFinishRestoreDocument(*this); setStatus(Document::Restoring, false); + + if(partialrestore) + THROWMT(Base::RestoreError,QT_TRANSLATE_NOOP("Exceptions", "There were errors while loading the file. Geometry might have been modified or not recovered at all. Look in the report view for more specific information about the objects involved.")); } bool Document::isSaved() const diff --git a/src/App/Document.h b/src/App/Document.h index 6c046bb119..d0dba649cf 100644 --- a/src/App/Document.h +++ b/src/App/Document.h @@ -68,7 +68,8 @@ public: KeepTrailingDigits = 1, Closable = 2, Restoring = 3, - Recomputing = 4 + Recomputing = 4, + PartialRestore = 5 }; /** @name Properties */ diff --git a/src/App/PropertyContainer.cpp b/src/App/PropertyContainer.cpp index 5b3d208812..a03a80a3d4 100644 --- a/src/App/PropertyContainer.cpp +++ b/src/App/PropertyContainer.cpp @@ -260,6 +260,8 @@ void PropertyContainer::Save (Base::Writer &writer) const void PropertyContainer::Restore(Base::XMLReader &reader) { + bool partialrestore = false; + reader.readElement("Properties"); int Cnt = reader.getAttributeAsInteger("Count"); @@ -275,7 +277,15 @@ void PropertyContainer::Restore(Base::XMLReader &reader) try { // name and type match if (prop && strcmp(prop->getTypeId().getName(), TypeName) == 0) { - prop->Restore(reader); + + try { + prop->Restore(reader); + } + catch(RestoreError &e) { + e.ReportException(); + Base::Console().Error("Property %s of type %s was subject to a partial restore.\n",PropName,TypeName); + partialrestore = true; + } } // name matches but not the type else if (prop) { @@ -308,6 +318,9 @@ void PropertyContainer::Restore(Base::XMLReader &reader) reader.readEndElement("Property"); } reader.readEndElement("Properties"); + + if(partialrestore) + THROW(Base::RestoreError); } void PropertyData::addProperty(OffsetBase offsetBase,const char* PropName, Property *Prop, const char* PropertyGroup , PropertyType Type, const char* PropertyDocu) diff --git a/src/Mod/Part/App/PropertyGeometryList.cpp b/src/Mod/Part/App/PropertyGeometryList.cpp index 0cb69e101d..563e3e5ab6 100644 --- a/src/Mod/Part/App/PropertyGeometryList.cpp +++ b/src/Mod/Part/App/PropertyGeometryList.cpp @@ -187,7 +187,7 @@ void PropertyGeometryList::Restore(Base::XMLReader &reader) values.push_back(newG); reader.readEndElement("Geometry"); } - catch(Base::RestoreError e) { + catch(Base::RestoreError &e) { e.ReportException(); @@ -214,8 +214,8 @@ void PropertyGeometryList::Restore(Base::XMLReader &reader) // assignment setValues(values); - /*if(partialrestore) - THROWMT(Base::RestoreError, QT_TRANSLATE_NOOP("Exceptions","There were errors during the restoring process. Some geometry objects may not correspond to the version that was saved or might have been deleted."));*/ + if(partialrestore) + THROW(Base::RestoreError); } App::Property *PropertyGeometryList::Copy(void) const diff --git a/src/Mod/Web/Gui/BrowserView.cpp b/src/Mod/Web/Gui/BrowserView.cpp index 47d0bb2347..1b3575917e 100644 --- a/src/Mod/Web/Gui/BrowserView.cpp +++ b/src/Mod/Web/Gui/BrowserView.cpp @@ -325,6 +325,13 @@ void BrowserView::onLinkClicked (const QUrl & url) // Gui::Command::doCommand(Gui::Command::Gui,"execfile('%s')",(const char*) fi.absoluteFilePath(). toLocal8Bit()); Gui::Command::doCommand(Gui::Command::Gui,"exec(open('%s').read())",(const char*) fi.absoluteFilePath() .toLocal8Bit()); } + catch (const Base::RestoreError& e) { + e.ReportException(); + if(e.getTranslatable()) { + QMessageBox::critical(Gui::getMainWindow(), QObject::tr("Error loading file"), + QObject::tr(e.getMessage().c_str())); + } + } catch (const Base::Exception& e) { QMessageBox::critical(this, tr("Error"), QString::fromUtf8(e.what())); }