Salome HOME
Make not active document in the "save" action also stored into new folder: just copy...
authormpv <mikhail.ponikarov@opencascade.com>
Tue, 16 Dec 2014 11:38:03 +0000 (14:38 +0300)
committermpv <mikhail.ponikarov@opencascade.com>
Tue, 16 Dec 2014 11:38:03 +0000 (14:38 +0300)
src/Model/Model_Application.cpp
src/Model/Model_Application.h
src/Model/Model_Document.cpp
src/Model/Model_Session.cpp
src/PartSet/PartSet_WidgetPoint2d.cpp

index bdd9eda3a5ff2862d808fa76f141e3ff38b00aba..147bb4ac29e2c4450b28c73bafa042215c8c8c18 100644 (file)
@@ -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)
 {
index 364a394d0e3f5238f70a27b2ae15ce0c751026be..aa25bcb4e161c9b6bfa1a389a12dff6942618463 100644 (file)
@@ -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
index deff00477196890fdcfa8334b475ae4a4007e9b6..557ee00e59e6fc53e2e96ee73eccc9793c3df541 100644 (file)
@@ -26,6 +26,8 @@
 #include <TDF_Reference.hxx>
 #include <TDF_ChildIDIterator.hxx>
 #include <TDF_LabelMapHasher.hxx>
+#include <OSD_File.hxx>
+#include <OSD_Path.hxx>
 
 #include <climits>
 #ifndef WIN32
@@ -161,6 +163,7 @@ bool Model_Document::load(const char* theFileName)
 bool Model_Document::save(const char* theFileName, std::list<std::string>& 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<std::string>& 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<std::string>& 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<ModelAPI_ResultPart>
+          (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;
 }
index 94f6cf2a87ca245ac8dce804f76e0ae36381f841..d264be4d34519940d9dd5cda5dbc55886f388248 100644 (file)
@@ -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<Events_Message> anAbortMsg
     (new Events_Message(Events_Loop::eventByName("AbortOperation")));
   Events_Loop::loop()->send(anAbortMsg);
+  myCheckTransactions = true;
+  myCheckTransactions = aWasCheck;
 }
 
 bool Model_Session::isOperation()
index 51c3289a57fbfb919cb614688f6a05ad799eb2ff..104c9cfb5db9928eb2a20363cb69146ad6b70d5d 100644 (file)
@@ -124,6 +124,8 @@ void PartSet_WidgetPoint2D::setPoint(double theX, double theY)
 bool PartSet_WidgetPoint2D::storeValue() const
 {
   std::shared_ptr<ModelAPI_Data> aData = myFeature->data();
+  if (!aData) // can be on abort of sketcher element
+    return false;
   std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
       aData->attribute(attributeID()));