]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Make sub-document loaded only on activation
authormpv <mikhail.ponikarov@opencascade.com>
Mon, 8 Sep 2014 13:51:07 +0000 (17:51 +0400)
committermpv <mikhail.ponikarov@opencascade.com>
Mon, 8 Sep 2014 13:51:07 +0000 (17:51 +0400)
src/Events/Events_Loop.cpp
src/Events/Events_Loop.h
src/Model/Model_Document.cpp
src/Model/Model_ResultPart.cpp
src/Model/Model_ResultPart.h
src/ModelAPI/ModelAPI_Object.h
src/ModelAPI/ModelAPI_ResultPart.h
src/PartSetPlugin/PartSetPlugin_Part.cpp

index 80f48ef48a0004cfdf509664fb779e36b22439d4..1fb0ed1780636c244923a3b50469ce0e68ab22f4 100644 (file)
@@ -103,6 +103,8 @@ void Events_Loop::registerListener(Events_Listener* theListener, const Events_ID
 
 void Events_Loop::flush(const Events_ID& theID)
 {
+  if (!myFlushActive)
+    return;
   std::map<char*, Events_MessageGroup*>::iterator aMyGroup = myGroups.find(theID.eventText());
   if (aMyGroup != myGroups.end()) {  // really sends
     Events_MessageGroup* aGroup = aMyGroup->second;
@@ -111,3 +113,8 @@ void Events_Loop::flush(const Events_ID& theID)
     delete aGroup;
   }
 }
+
+void Events_Loop::activateFlushes(const bool theActivate)
+{
+  myFlushActive = theActivate;
+}
index d62cea6add1f17f6b4fffe17f021c89df90b42bd..cd78497ed1c67b0c7b3482d5964df9b49674572b 100644 (file)
@@ -31,11 +31,12 @@ class Events_Loop
   /// map from event ID to groupped messages (accumulated on flush)
   std::map<char*, Events_MessageGroup*> myGroups;
 
+  /// to process flushes or not
+  bool myFlushActive;
+
   //! The empty constructor, will be called at startup of the application, only once
-  Events_Loop()
-  {
-  }
-  ;
+  Events_Loop() : myFlushActive(true) {}
+
  public:
   ///! Returns the main object of the loop, one per application.
   EVENTS_EXPORT static Events_Loop* loop();
@@ -54,6 +55,10 @@ class Events_Loop
 
   //! Initializes sending of a group-message by the given ID
   EVENTS_EXPORT void flush(const Events_ID& theID);
+
+  //! Allows to disable flushes: needed in synchronization of document mechanism 
+  //! (to synchronize all and only then flush create, update, etc in correct order)
+  EVENTS_EXPORT void activateFlushes(const bool theActivate);
 };
 
 #endif
index c0149d789da09fce371ac1f760bd31c1f2de4231..55c0fa57faebc798ad55ece6cd46a5ed92f88cb7 100644 (file)
@@ -253,10 +253,11 @@ void Model_Document::finishOperation()
   if (!myDoc->HasOpenCommand() && myNestedNum != -1)
     boost::static_pointer_cast<Model_PluginManager>(Model_PluginManager::get())
         ->setCheckTransactions(false);  // for nested transaction commit
-  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
-  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
-  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
-  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
+  Events_Loop* aLoop = Events_Loop::loop();
+  aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+  aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+  aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+  aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
   if (!myDoc->HasOpenCommand() && myNestedNum != -1)
     boost::static_pointer_cast<Model_PluginManager>(Model_PluginManager::get())
         ->setCheckTransactions(true);  // for nested transaction commit
@@ -654,6 +655,9 @@ void Model_Document::synchronizeFeatures(const bool theMarkUpdated)
   // 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* aLoop = Events_Loop::loop();
+  aLoop->activateFlushes(false);
+
   // update all objects by checking are they of labels or not
   std::set<FeaturePtr> aNewFeatures, aKeptFeatures;
   TDF_ChildIDIterator aLabIter(featuresLabel(), TDataStd_Comment::GetID());
@@ -709,7 +713,7 @@ void Model_Document::synchronizeFeatures(const bool theMarkUpdated)
         ModelAPI_EventCreator::get()->sendDeleted(aThis, ModelAPI_Feature::group());
       }
       // results of this feature must be redisplayed (hided)
-      static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+      static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
       const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
       std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
       for (; aRIter != aResults.cend(); aRIter++) {
@@ -725,11 +729,14 @@ void Model_Document::synchronizeFeatures(const bool theMarkUpdated)
   }
 
   myExecuteFeatures = false;
-  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
-  if (theMarkUpdated)
-    Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
-  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
-  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+  aLoop->activateFlushes(true);
+
+  aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+  if (theMarkUpdated) {
+    aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+  }
+  aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
+  aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
   boost::static_pointer_cast<Model_PluginManager>(Model_PluginManager::get())
     ->setCheckTransactions(true);
   myExecuteFeatures = true;
index aecaac06f6957d58d434df93ed1b501c2b49c34b..cdafeb6d0e7ae59a9603ea6b3063d17a5e577a27 100644 (file)
@@ -5,6 +5,7 @@
 #include <Model_ResultPart.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_AttributeDocRef.h>
+#include <ModelAPI_PluginManager.h>
 
 boost::shared_ptr<ModelAPI_Document> Model_ResultPart::partDoc()
 {
@@ -27,3 +28,17 @@ void Model_ResultPart::setData(boost::shared_ptr<ModelAPI_Data> theData)
     data()->addAttribute(DOC_REF(), ModelAPI_AttributeDocRef::type());
   }
 }
+
+void Model_ResultPart::activate()
+{
+  boost::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = data()->docRef(DOC_REF());
+  
+  if (!aDocRef->value()) {  // create (or open) a document if it is not yet created
+    boost::shared_ptr<ModelAPI_Document> aDoc = document()->subDocument(data()->name());
+    if (aDoc) {
+      aDocRef->setValue(aDoc);
+    }
+  }
+  if (aDocRef->value())
+    ModelAPI_PluginManager::get()->setCurrentDocument(aDocRef->value());
+}
index af0f385e8289946c1c90c738e0ad6cd3b3545d6b..e26413c3fb13d0b69c59395070c7bee3cd0b3212 100644 (file)
@@ -23,7 +23,10 @@ class Model_ResultPart : public ModelAPI_ResultPart
   /// Part has no stored feature: this method returns NULL
   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> owner();
 
- protected:
+  /// Sets this document as current and if it is not loaded yet, loads it
+  MODEL_EXPORT virtual void activate();
+
+protected:
   /// makes a result on a temporary feature (an action)
   Model_ResultPart();
 
index 91167b871b71331c26b305d006d64570a62f1ae7..2d4838c17252f4feed9cfb8d078d21e0514f01ad 100644 (file)
@@ -24,7 +24,7 @@ class ModelAPI_Document;
 class ModelAPI_Object
 {
   boost::shared_ptr<ModelAPI_Data> myData;  ///< manager of the data model of a feature
-  boost::shared_ptr<ModelAPI_Document> myDoc;  ///< document this feature belongs to
+  boost::shared_ptr<ModelAPI_Document> myDoc;  ///< document this object belongs to
  public:
   /// By default object is displayed in the object browser.
   virtual bool isInHistory()
index ca52304cc36c2e0712fdf82e3a7d88696d17291a..bd7a7deeab05c1e9ae8f50d67010e80c513137dc 100644 (file)
@@ -41,6 +41,9 @@ class ModelAPI_ResultPart : public ModelAPI_Result
 
   /// Returns the part-document of this result
   virtual boost::shared_ptr<ModelAPI_Document> partDoc() = 0;
+
+  /// Sets this document as current and if it is not loaded yet, loads it
+  virtual void activate() = 0;
 };
 
 //! Pointer on feature object
index edb6ddac3f0c0de9f9c2828c877b975b0f31f9b3..e01c02bb0814c803cc5421576be65547e9479e15 100644 (file)
@@ -26,14 +26,16 @@ void PartSetPlugin_Part::execute()
     aResult = document()->createPart(data());
     setResult(aResult);
   }
+  /*
   boost::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = aResult->data()->docRef(
       ModelAPI_ResultPart::DOC_REF());
-
+  
   if (!aDocRef->value()) {  // create a document if not yet created
     boost::shared_ptr<ModelAPI_Document> aPartSetDoc =
         ModelAPI_PluginManager::get()->rootDocument();
     aDocRef->setValue(aPartSetDoc->subDocument(data()->name()));
   }
+  */
 }
 
 boost::shared_ptr<ModelAPI_Document> PartSetPlugin_Part::documentToAdd()