From fcc7ab4e48eada6e02cb586a253d08d626ccdd87 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 18 Mar 2024 13:19:13 +0100 Subject: [PATCH] App: fixes #13022 App::VRMLObject with more than one texture isn't properly displayed when file is reopened --- src/App/VRMLObject.cpp | 32 +++++++++++++++++++++++++------- src/App/VRMLObject.h | 9 +++++++-- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/App/VRMLObject.cpp b/src/App/VRMLObject.cpp index 10c1787c28..10887abf32 100644 --- a/src/App/VRMLObject.cpp +++ b/src/App/VRMLObject.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include @@ -55,6 +56,10 @@ short VRMLObject::mustExecute() const void VRMLObject::onChanged(const App::Property* prop) { + if (restoreData) { + return; + } + if (prop == &VrmlFile) { std::string orig = VrmlFile.getOriginalFileName(); if (!orig.empty()) { @@ -183,8 +188,9 @@ void VRMLObject::SaveDocFile (Base::Writer &writer) const } } -void VRMLObject::RestoreDocFile(Base::Reader &reader) +bool VRMLObject::restoreTextureFinished(Base::Reader &reader) { + Base::StateLocker locker(restoreData, true); if (this->indexRestore < Resources.getSize()) { std::string path = getDocument()->TransientDir.getValue(); std::string url = Resources[this->indexRestore]; @@ -204,11 +210,23 @@ void VRMLObject::RestoreDocFile(Base::Reader &reader) file.close(); } - // after restoring all inline files reload the VRML file - if (this->indexRestore == Urls.getSize()) { - VrmlFile.touch(); - Base::FileInfo fi(VrmlFile.getValue()); - this->vrmlPath = fi.dirPath(); - } + return (this->indexRestore == Urls.getSize()); + } + + return false; +} + +void VRMLObject::reloadFile() +{ + // after restoring all inline files reload the VRML file + VrmlFile.touch(); + Base::FileInfo fi(VrmlFile.getValue()); + this->vrmlPath = fi.dirPath(); +} + +void VRMLObject::RestoreDocFile(Base::Reader &reader) +{ + if (restoreTextureFinished(reader)) { + reloadFile(); } } diff --git a/src/App/VRMLObject.h b/src/App/VRMLObject.h index b2d4035a5f..3360e6a9ed 100644 --- a/src/App/VRMLObject.h +++ b/src/App/VRMLObject.h @@ -61,14 +61,19 @@ public: protected: void onChanged(const App::Property*) override; + +private: std::string getRelativePath(const std::string&, const std::string&) const; std::string fixRelativePath(const std::string&, const std::string&) const; void makeDirectories(const std::string&, const std::string&); + bool restoreTextureFinished(Base::Reader &reader); + void reloadFile(); private: mutable std::string vrmlPath; - mutable int indexRestore{0}; - mutable int indexSave{0}; + mutable int indexRestore {0}; + mutable int indexSave {0}; + mutable bool restoreData {false}; }; } //namespace App