From deb0185764c5a7ab524646cfdc2b7ce22afae81d Mon Sep 17 00:00:00 2001 From: mpv Date: Mon, 8 Sep 2014 17:51:07 +0400 Subject: [PATCH] Make sub-document loaded only on activation --- src/Events/Events_Loop.cpp | 7 ++++++ src/Events/Events_Loop.h | 13 ++++++++---- src/Model/Model_Document.cpp | 27 +++++++++++++++--------- src/Model/Model_ResultPart.cpp | 15 +++++++++++++ src/Model/Model_ResultPart.h | 5 ++++- src/ModelAPI/ModelAPI_Object.h | 2 +- src/ModelAPI/ModelAPI_ResultPart.h | 3 +++ src/PartSetPlugin/PartSetPlugin_Part.cpp | 4 +++- 8 files changed, 59 insertions(+), 17 deletions(-) diff --git a/src/Events/Events_Loop.cpp b/src/Events/Events_Loop.cpp index 80f48ef48..1fb0ed178 100644 --- a/src/Events/Events_Loop.cpp +++ b/src/Events/Events_Loop.cpp @@ -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::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; +} diff --git a/src/Events/Events_Loop.h b/src/Events/Events_Loop.h index d62cea6ad..cd78497ed 100644 --- a/src/Events/Events_Loop.h +++ b/src/Events/Events_Loop.h @@ -31,11 +31,12 @@ class Events_Loop /// map from event ID to groupped messages (accumulated on flush) std::map 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 diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index c0149d789..55c0fa57f 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -253,10 +253,11 @@ void Model_Document::finishOperation() if (!myDoc->HasOpenCommand() && myNestedNum != -1) boost::static_pointer_cast(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::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::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 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 >& aResults = aFeature->results(); std::list >::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::get()) ->setCheckTransactions(true); myExecuteFeatures = true; diff --git a/src/Model/Model_ResultPart.cpp b/src/Model/Model_ResultPart.cpp index aecaac06f..cdafeb6d0 100644 --- a/src/Model/Model_ResultPart.cpp +++ b/src/Model/Model_ResultPart.cpp @@ -5,6 +5,7 @@ #include #include #include +#include boost::shared_ptr Model_ResultPart::partDoc() { @@ -27,3 +28,17 @@ void Model_ResultPart::setData(boost::shared_ptr theData) data()->addAttribute(DOC_REF(), ModelAPI_AttributeDocRef::type()); } } + +void Model_ResultPart::activate() +{ + boost::shared_ptr aDocRef = data()->docRef(DOC_REF()); + + if (!aDocRef->value()) { // create (or open) a document if it is not yet created + boost::shared_ptr aDoc = document()->subDocument(data()->name()); + if (aDoc) { + aDocRef->setValue(aDoc); + } + } + if (aDocRef->value()) + ModelAPI_PluginManager::get()->setCurrentDocument(aDocRef->value()); +} diff --git a/src/Model/Model_ResultPart.h b/src/Model/Model_ResultPart.h index af0f385e8..e26413c3f 100644 --- a/src/Model/Model_ResultPart.h +++ b/src/Model/Model_ResultPart.h @@ -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 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(); diff --git a/src/ModelAPI/ModelAPI_Object.h b/src/ModelAPI/ModelAPI_Object.h index 91167b871..2d4838c17 100644 --- a/src/ModelAPI/ModelAPI_Object.h +++ b/src/ModelAPI/ModelAPI_Object.h @@ -24,7 +24,7 @@ class ModelAPI_Document; class ModelAPI_Object { boost::shared_ptr myData; ///< manager of the data model of a feature - boost::shared_ptr myDoc; ///< document this feature belongs to + boost::shared_ptr myDoc; ///< document this object belongs to public: /// By default object is displayed in the object browser. virtual bool isInHistory() diff --git a/src/ModelAPI/ModelAPI_ResultPart.h b/src/ModelAPI/ModelAPI_ResultPart.h index ca52304cc..bd7a7deea 100644 --- a/src/ModelAPI/ModelAPI_ResultPart.h +++ b/src/ModelAPI/ModelAPI_ResultPart.h @@ -41,6 +41,9 @@ class ModelAPI_ResultPart : public ModelAPI_Result /// Returns the part-document of this result virtual boost::shared_ptr partDoc() = 0; + + /// Sets this document as current and if it is not loaded yet, loads it + virtual void activate() = 0; }; //! Pointer on feature object diff --git a/src/PartSetPlugin/PartSetPlugin_Part.cpp b/src/PartSetPlugin/PartSetPlugin_Part.cpp index edb6ddac3..e01c02bb0 100644 --- a/src/PartSetPlugin/PartSetPlugin_Part.cpp +++ b/src/PartSetPlugin/PartSetPlugin_Part.cpp @@ -26,14 +26,16 @@ void PartSetPlugin_Part::execute() aResult = document()->createPart(data()); setResult(aResult); } + /* boost::shared_ptr aDocRef = aResult->data()->docRef( ModelAPI_ResultPart::DOC_REF()); - + if (!aDocRef->value()) { // create a document if not yet created boost::shared_ptr aPartSetDoc = ModelAPI_PluginManager::get()->rootDocument(); aDocRef->setValue(aPartSetDoc->subDocument(data()->name())); } + */ } boost::shared_ptr PartSetPlugin_Part::documentToAdd() -- 2.39.2