Salome HOME
Issue #3086: Avoid crash when FeatureInfo is null.
[modules/shaper.git] / src / ModelHighAPI / ModelHighAPI_Services.cpp
index c9be661299b85665b84e2e1d6a438e602fa96d3b..4bcd182fd39aba1b627f090220c47713cd857ac0 100644 (file)
@@ -27,6 +27,7 @@
 #include <ModelAPI_Events.h>
 
 #include <cmath>
+#include <sstream>
 
 //--------------------------------------------------------------------------------------
 std::shared_ptr<ModelAPI_Document> moduleDocument()
@@ -97,7 +98,17 @@ std::shared_ptr<ModelAPI_Result> standardPlane(const std::string & theName){
 //--------------------------------------------------------------------------------------
 void begin()
 {
-  ModelAPI_Session::get()->startOperation();
+  static size_t aTransactionID = 0;
+  static size_t aNbTransactions = -1;
+  size_t aNbUndo = ModelAPI_Session::get()->undoList().size();
+  if (aNbUndo != aNbTransactions) {
+    // the last transaction was not empty, thus increase the ID
+    aNbTransactions = aNbUndo;
+    ++aTransactionID;
+  }
+  std::ostringstream aTransactionName;
+  aTransactionName << "Operation_" << aTransactionID;
+  ModelAPI_Session::get()->startOperation(aTransactionName.str());
 }
 
 void end()
@@ -119,7 +130,8 @@ void apply()
 {
   auto aSession = ModelAPI_Session::get();
   aSession->finishOperation();
-  aSession->startOperation();
+  // start the next operation
+  begin();
 }
 
 void updateFeatures()