Example code of propagating the result of the partial restore
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -1355,7 +1355,7 @@ void Document::Save (Base::Writer &writer) const
|
||||
}
|
||||
|
||||
void Document::Restore(Base::XMLReader &reader)
|
||||
{
|
||||
{
|
||||
int i,Cnt;
|
||||
Base::ObjectStatusLocker<Status, Document> 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<App::DocumentObject*>& obj,
|
||||
@@ -1510,7 +1514,7 @@ void Document::writeObjects(const std::vector<App::DocumentObject*>& obj,
|
||||
|
||||
std::vector<App::DocumentObject*>
|
||||
Document::readObjects(Base::XMLReader& reader)
|
||||
{
|
||||
{
|
||||
bool keepDigits = testStatus(Document::KeepTrailingDigits);
|
||||
setStatus(Document::KeepTrailingDigits, !reader.doNameMapping());
|
||||
std::vector<App::DocumentObject*> 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
|
||||
|
||||
@@ -68,7 +68,8 @@ public:
|
||||
KeepTrailingDigits = 1,
|
||||
Closable = 2,
|
||||
Restoring = 3,
|
||||
Recomputing = 4
|
||||
Recomputing = 4,
|
||||
PartialRestore = 5
|
||||
};
|
||||
|
||||
/** @name Properties */
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user