]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Checking of modifications outside of the transaction
authormpv <mikhail.ponikarov@opencascade.com>
Thu, 22 May 2014 14:09:36 +0000 (18:09 +0400)
committermpv <mikhail.ponikarov@opencascade.com>
Thu, 22 May 2014 14:09:36 +0000 (18:09 +0400)
src/Model/Model_Data.cpp
src/Model/Model_Document.cpp
src/Model/Model_Object.cpp
src/Model/Model_PluginManager.cpp
src/Model/Model_PluginManager.h

index e6c5c02f2e7311aefacbe361f9733014634c9cc4..03effc8e3c9058cfb99083ea373862931075cde2 100644 (file)
@@ -12,6 +12,8 @@
 #include <GeomData_Point2D.h>
 #include <GeomData_Dir.h>
 #include <TDataStd_Name.hxx>
+#include "Model_Events.h"
+#include <Events_Loop.h>
 
 using namespace std;
 
@@ -35,6 +37,9 @@ string Model_Data::getName()
 void Model_Data::setName(string theName)
 {
   TDataStd_Name::Set(myLab, theName.c_str());
+  static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
+  Model_FeatureUpdatedMessage aMsg(myFeature, anEvent);
+  Events_Loop::loop()->send(aMsg, false);
 }
 
 void Model_Data::addAttribute(string theID, string theAttrType)
index 67953331d65992b1c1d0d991b1cddd0586b43307..662374984bd3b0b081d63566b2b3d8a7a169df61 100644 (file)
@@ -594,6 +594,10 @@ void Model_Document::synchronizeFeatures()
     }
   }
   // after all updates, sends a message that groups of features were created or updated
+  boost::static_pointer_cast<Model_PluginManager>(Model_PluginManager::get())->
+    setCheckTransactions(false);
   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_CREATED));
   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_DELETED));
+  boost::static_pointer_cast<Model_PluginManager>(Model_PluginManager::get())->
+    setCheckTransactions(true);
 }
index 9b39c6d2f2d02c339f0c1cc00860fea09ce82a00..c8a852b511c0eb5e2edefbd9811b426d2b4cda35 100644 (file)
@@ -4,6 +4,8 @@
 
 #include "Model_Object.h"
 #include <TCollection_AsciiString.hxx>
+#include "Model_Events.h"
+#include <Events_Loop.h>
 
 boost::shared_ptr<ModelAPI_Feature> Model_Object::featureRef()
 {
@@ -17,7 +19,12 @@ std::string Model_Object::getName()
 
 void Model_Object::setName(std::string theName)
 {
-  myName->Set(theName.c_str());
+  if (myName->Get() != theName.c_str()) {
+    myName->Set(theName.c_str());
+    static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
+    Model_FeatureUpdatedMessage aMsg(boost::shared_ptr<ModelAPI_Object>(this), anEvent);
+    Events_Loop::loop()->send(aMsg, false);
+  }
 }
 
 Model_Object::Model_Object(boost::shared_ptr<ModelAPI_Feature> theRef,
index 05f1586e678f1c1b5ba1df48cd2b668ee71926d8..1a6cef9d82964e297c036547464e3240ac0bdeec 100644 (file)
@@ -98,6 +98,7 @@ boost::shared_ptr<ModelAPI_Document> Model_PluginManager::copy(
 Model_PluginManager::Model_PluginManager()
 {
   myPluginsInfoLoaded = false;
+  myCheckTransactions = true;
   ModelAPI_PluginManager::SetPluginManager(boost::shared_ptr<ModelAPI_PluginManager>(this));
   // register the configuration reading listener
   Events_Loop* aLoop = Events_Loop::loop();
@@ -123,7 +124,7 @@ void Model_PluginManager::processEvent(const Events_Message* theMessage)
     // plugins information was started to load, so, it will be loaded
     myPluginsInfoLoaded = true;
   } else { // create/update/delete
-    if (!rootDocument()->isOperation())
+    if (myCheckTransactions && !rootDocument()->isOperation())
       Events_Error::send("Modification of data structure outside of the transaction");
   }
 }
index aa230700a1dc5d44e33bd8020402a25ad5971a8a..4efef6a4cd5034c79e8ff69a405cc49b852ceb33 100644 (file)
@@ -26,6 +26,7 @@ class Model_PluginManager : public ModelAPI_PluginManager, public Events_Listene
   std::map<std::string, ModelAPI_Plugin*> myPluginObjs; ///< instances of the already plugins
   std::string myCurrentPluginName; ///< name of the plugin that must be loaded currently
   boost::shared_ptr<ModelAPI_Document> myCurrentDoc; ///< current working document
+  bool myCheckTransactions; ///< if true, generates error if document is updated outside of transaction
 public:
   /// Returns the root document of the application (that may contains sub-documents)
   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Document> rootDocument();
@@ -51,6 +52,8 @@ public:
   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Document> copy(
     boost::shared_ptr<ModelAPI_Document> theSource, std::string theID);
 
+  void setCheckTransactions(const bool theCheck) {myCheckTransactions = theCheck;}
+
   /// Is called only once, on startup of the application
   Model_PluginManager();