Salome HOME
Issue #3044: Undo list contains empty string for Load python script
authorazv <azv@opencascade.com>
Wed, 16 Oct 2019 08:55:08 +0000 (11:55 +0300)
committerazv <azv@opencascade.com>
Wed, 16 Oct 2019 08:55:08 +0000 (11:55 +0300)
* Set name for each transaction as "Operation_N"
* Improve dumping to Python to avoid odd call of "model.do()" right before "model.end()" which cause an additional empty transaction.

src/ModelHighAPI/ModelHighAPI_Dumper.cpp
src/ModelHighAPI/ModelHighAPI_Dumper.h
src/ModelHighAPI/ModelHighAPI_Services.cpp

index 836f33c93016d29eb194e2f6e91a8e379842d9a6..9df987e6101f4b342e2a8d7c96f457d38f27448c 100644 (file)
@@ -663,8 +663,12 @@ bool ModelHighAPI_Dumper::process(const std::shared_ptr<ModelAPI_Document>& theD
   // dump all other features
   for (anObjIt = anObjects.begin(); anObjIt != anObjects.end(); ++anObjIt) {
     CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(*anObjIt);
-    if (aCompFeat) // iteratively process composite features
-      isOk = process(aCompFeat) && isOk;
+    if (aCompFeat) {
+      // iteratively process composite features,
+      // if the composite feature is the last in the document, no need to dump "model.do()" action
+      std::list<ObjectPtr>::const_iterator aNext = anObjIt;
+      isOk = process(aCompFeat, false, ++aNext != anObjects.end()) && isOk;
+    }
     else if (!isDumped(EntityPtr(*anObjIt))) {
       // dump folder
       FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(*anObjIt);
@@ -683,7 +687,7 @@ bool ModelHighAPI_Dumper::process(const std::shared_ptr<ModelAPI_Document>& theD
 }
 
 bool ModelHighAPI_Dumper::process(const std::shared_ptr<ModelAPI_CompositeFeature>& theComposite,
-                                  bool isForce)
+                                  bool isForce, bool isDumpModelDo)
 {
   // increase composite features stack
   ++gCompositeStackDepth;
@@ -716,7 +720,9 @@ bool ModelHighAPI_Dumper::process(const std::shared_ptr<ModelAPI_CompositeFeatur
     *this << aDocName << " = " << aPartName << ".document()" << std::endl;
     // dump features in the document
     bool aRes = process(aSubDoc);
-    *this << "model.do()" << std::endl;
+    if (isDumpModelDo)
+      *this << "model.do()\n";
+    *this << std::endl;
     return aRes;
   }
 
index ccd80c626bd8da98bc5c46553cd73418c83284bf..2bbc294357441c7a74ef484ec8124b9ce3b68811 100644 (file)
@@ -348,7 +348,8 @@ private:
 
   /// Dump composite feature and all it sub-features
   bool process(const std::shared_ptr<ModelAPI_CompositeFeature>& theComposite,
-               bool isForce = false);
+               bool isForce = false,
+               bool isDumpModelDo = true);
 
   /// Iterate all features in composite feature and dump them into intermediate buffer
   /// \param theComposite   [in] parent composite feature
index c9be661299b85665b84e2e1d6a438e602fa96d3b..98f7aff84a47776b899e98ace3ca43a7e521f335 100644 (file)
@@ -27,6 +27,7 @@
 #include <ModelAPI_Events.h>
 
 #include <cmath>
+#include <sstream>
 
 //--------------------------------------------------------------------------------------
 std::shared_ptr<ModelAPI_Document> moduleDocument()
@@ -97,7 +98,10 @@ std::shared_ptr<ModelAPI_Result> standardPlane(const std::string & theName){
 //--------------------------------------------------------------------------------------
 void begin()
 {
-  ModelAPI_Session::get()->startOperation();
+  static int aTransactionID = 0;
+  std::ostringstream aTransactionName;
+  aTransactionName << "Operation_" << ++aTransactionID;
+  ModelAPI_Session::get()->startOperation(aTransactionName.str());
 }
 
 void end()
@@ -119,7 +123,7 @@ void apply()
 {
   auto aSession = ModelAPI_Session::get();
   aSession->finishOperation();
-  aSession->startOperation();
+  begin();
 }
 
 void updateFeatures()