Salome HOME
Issue #3086: Avoid crash when FeatureInfo is null.
[modules/shaper.git] / src / ModelHighAPI / ModelHighAPI_Services.cpp
index 443b861ad9a99ebc3f25fd8d5174452691570cc6..4bcd182fd39aba1b627f090220c47713cd857ac0 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include "ModelHighAPI_Services.h"
@@ -28,6 +27,7 @@
 #include <ModelAPI_Events.h>
 
 #include <cmath>
+#include <sstream>
 
 //--------------------------------------------------------------------------------------
 std::shared_ptr<ModelAPI_Document> moduleDocument()
@@ -98,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()
@@ -120,7 +130,8 @@ void apply()
 {
   auto aSession = ModelAPI_Session::get();
   aSession->finishOperation();
-  aSession->startOperation();
+  // start the next operation
+  begin();
 }
 
 void updateFeatures()