From 388e48fa27951a0e544686f323a917d897aa8f55 Mon Sep 17 00:00:00 2001 From: mpv Date: Tue, 16 Dec 2014 14:38:03 +0300 Subject: [PATCH] Make not active document in the "save" action also stored into new folder: just copy the file --- src/Model/Model_Application.cpp | 6 ++++++ src/Model/Model_Application.h | 2 ++ src/Model/Model_Document.cpp | 30 ++++++++++++++++++++++++++- src/Model/Model_Session.cpp | 6 ++++++ src/PartSet/PartSet_WidgetPoint2d.cpp | 2 ++ 5 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/Model/Model_Application.cpp b/src/Model/Model_Application.cpp index bdd9eda3a..147bb4ac2 100644 --- a/src/Model/Model_Application.cpp +++ b/src/Model/Model_Application.cpp @@ -67,6 +67,12 @@ void Model_Application::setLoadPath(std::string thePath) myPath = thePath; } +//======================================================================= +const std::string& Model_Application::loadPath() const +{ + return myPath; +} + //======================================================================= void Model_Application::setLoadByDemand(std::string theID) { diff --git a/src/Model/Model_Application.h b/src/Model/Model_Application.h index 364a394d0..aa25bcb4e 100644 --- a/src/Model/Model_Application.h +++ b/src/Model/Model_Application.h @@ -43,6 +43,8 @@ class Model_Application : public TDocStd_Application //! Set path for the loaded by demand documents void setLoadPath(std::string thePath); + //! Returns the path for the loaded by demand documents + const std::string& loadPath() const; //! Defines that specified document must be loaded by demand void setLoadByDemand(std::string theID); //! Returns true if specified document must be loaded by demand diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index deff00477..557ee00e5 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include #ifndef WIN32 @@ -161,6 +163,7 @@ bool Model_Document::load(const char* theFileName) bool Model_Document::save(const char* theFileName, std::list& theResults) { // create a directory in the root document if it is not yet exist + Handle(Model_Application) anApp = Model_Application::getApplication(); if (this == Model_Session::get()->moduleDocument().get()) { #ifdef WIN32 CreateDirectory(theFileName, NULL); @@ -172,7 +175,7 @@ bool Model_Document::save(const char* theFileName, std::list& theRe TCollection_ExtendedString aPath(DocFileName(theFileName, myID)); PCDM_StoreStatus aStatus; try { - aStatus = Model_Application::getApplication()->SaveAs(myDoc, aPath); + aStatus = anApp->SaveAs(myDoc, aPath); } catch (Standard_Failure) { Handle(Standard_Failure) aFail = Standard_Failure::Caught(); Events_Error::send( @@ -201,6 +204,31 @@ bool Model_Document::save(const char* theFileName, std::list& theRe for (; aSubIter != mySubs.end() && isDone; aSubIter++) { isDone = subDoc(*aSubIter)->save(theFileName, theResults); } + if (isDone) { // also try to copy the not-activated sub-documents + // they are not in mySubs but as ResultParts + int aPartsNum = size(ModelAPI_ResultPart::group()); + for(int aPart = 0; aPart < aPartsNum; aPart++) { + ResultPartPtr aPartRes = std::dynamic_pointer_cast + (object(ModelAPI_ResultPart::group(), aPart)); + if (aPartRes) { + std::string aDocName = aPartRes->data()->name(); + if (!aDocName.empty() && mySubs.find(aDocName) == mySubs.end()) { + // just copy file + TCollection_AsciiString aSubPath(DocFileName(anApp->loadPath().c_str(), aDocName)); + OSD_Path aPath(aSubPath); + OSD_File aFile(aPath); + if (aFile.Exists()) { + TCollection_AsciiString aDestinationDir(DocFileName(theFileName, aDocName)); + OSD_Path aDestination(aDestinationDir); + aFile.Copy(aDestination); + } else { + Events_Error::send( + std::string("Can not open file ") + aSubPath.ToCString() + " for saving"); + } + } + } + } + } } return isDone; } diff --git a/src/Model/Model_Session.cpp b/src/Model/Model_Session.cpp index 94f6cf2a8..d264be4d3 100644 --- a/src/Model/Model_Session.cpp +++ b/src/Model/Model_Session.cpp @@ -63,9 +63,15 @@ void Model_Session::finishOperation() void Model_Session::abortOperation() { ROOT_DOC->abortOperation(); + // here the update mechanism may work after abort, so, supress the warnings about + // modifications outside of the transactions + bool aWasCheck = myCheckTransactions; + myCheckTransactions = false; static std::shared_ptr anAbortMsg (new Events_Message(Events_Loop::eventByName("AbortOperation"))); Events_Loop::loop()->send(anAbortMsg); + myCheckTransactions = true; + myCheckTransactions = aWasCheck; } bool Model_Session::isOperation() diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index 51c3289a5..104c9cfb5 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -124,6 +124,8 @@ void PartSet_WidgetPoint2D::setPoint(double theX, double theY) bool PartSet_WidgetPoint2D::storeValue() const { std::shared_ptr aData = myFeature->data(); + if (!aData) // can be on abort of sketcher element + return false; std::shared_ptr aPoint = std::dynamic_pointer_cast( aData->attribute(attributeID())); -- 2.39.2