From 61df79ab9f72d85c4a7ecbbcb10436414a548166 Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Thu, 8 Aug 2019 11:10:53 +0800 Subject: [PATCH] Gui::Document: fix saving of camera setting --- src/Gui/Document.cpp | 42 +++++++++++++++++++++++++++--------------- src/Gui/Document.h | 6 +++--- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/Gui/Document.cpp b/src/Gui/Document.cpp index ebdbb6130e3f..f5ec97a95737 100644 --- a/src/Gui/Document.cpp +++ b/src/Gui/Document.cpp @@ -1360,27 +1360,20 @@ void Document::SaveDocFile (Base::Writer &writer) const writer.Stream() << writer.ind() << "" << std::endl; writer.decInd(); // indentation for 'ViewProviderData Count' - // set camera settings - QString viewPos; + // save camera settings std::list mdi = getMDIViews(); for (std::list::iterator it = mdi.begin(); it != mdi.end(); ++it) { if ((*it)->onHasMsg("GetCamera")) { const char* ppReturn=0; (*it)->onMsg("GetCamera",&ppReturn); - - // remove the first line because it's a comment like '#Inventor V2.1 ascii' - QStringList lines = QString(QString::fromLatin1(ppReturn)).split(QLatin1String("\n")); - if (lines.size() > 1) { - lines.pop_front(); - viewPos = lines.join(QLatin1String(" ")); + if(saveCameraSettings(ppReturn)) break; - } } } writer.incInd(); // indentation for camera settings writer.Stream() << writer.ind() << "" << std::endl; + << encodeAttribute(getCameraSettings()) << "\"/>\n"; writer.decInd(); // indentation for camera settings writer.Stream() << "" << std::endl; } @@ -1621,13 +1614,32 @@ Gui::MDIView* Document::cloneView(Gui::MDIView* oldview) return 0; } -const std::string &Document::getCameraSettings() const { - return cameraSettings; +const char *Document::getCameraSettings() const { + return cameraSettings.size()>10?cameraSettings.c_str()+10:cameraSettings.c_str(); } -void Document::saveCameraSettings(const char *settings) { - if(settings && settings[0]) - cameraSettings = std::string("SetCamera ") + settings; +bool Document::saveCameraSettings(const char *settings) const { + if(!settings) + return false; + + // skip starting comment lines + bool skipping = false; + char c = *settings; + for(;c;c=*(++settings)) { + if(skipping) { + if(c == '\n') + skipping = false; + } else if(c == '#') + skipping = true; + else if(!std::isspace(c)) + break; + } + + if(!c) + return false; + + cameraSettings = std::string("SetCamera ") + settings; + return true; } void Document::attachView(Gui::BaseView* pcView, bool bPassiv) diff --git a/src/Gui/Document.h b/src/Gui/Document.h index f2dbd8e8348a..97a57dfe2393 100644 --- a/src/Gui/Document.h +++ b/src/Gui/Document.h @@ -293,8 +293,8 @@ class GuiExport Document : public Base::Persistence virtual PyObject *getPyObject(void); - const std::string &getCameraSettings() const; - void saveCameraSettings(const char *); + const char *getCameraSettings() const; + bool saveCameraSettings(const char *) const; protected: // pointer to the python class @@ -310,7 +310,7 @@ class GuiExport Document : public Base::Persistence struct DocumentP* d; static int _iDocCount; - std::string cameraSettings; + mutable std::string cameraSettings; /** @name attributes for the UNDO REDO facility */