From 08d389e6ee54d3014f9eac9976e13fd67ed06cb8 Mon Sep 17 00:00:00 2001 From: mpv Date: Tue, 23 Sep 2014 12:09:02 +0400 Subject: [PATCH] Make finishing operation in python console produce no warnings: isOperation of root document returns false after this document is committed, but subs are still not. --- src/Events/Events_Loop.cpp | 11 +++++++++-- src/Events/Events_Loop.h | 5 ++++- src/Model/Model_Document.cpp | 10 +++++----- src/Model/Model_Session.cpp | 6 +++--- src/XGUI/XGUI_OperationMgr.cpp | 2 +- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/Events/Events_Loop.cpp b/src/Events/Events_Loop.cpp index 95e9ea6a9..b13472aee 100644 --- a/src/Events/Events_Loop.cpp +++ b/src/Events/Events_Loop.cpp @@ -39,6 +39,9 @@ Events_ID Events_Loop::eventByName(const char* theName) void Events_Loop::send(const boost::shared_ptr& theMessage, bool isGroup) { + if (myImmediateListeners.find(theMessage->eventID().eventText()) != myImmediateListeners.end()) { + myImmediateListeners[theMessage->eventID().eventText()]->processEvent(theMessage); + } // if it is grouped message, just accumulate it if (isGroup) { boost::shared_ptr aGroup = @@ -57,7 +60,7 @@ void Events_Loop::send(const boost::shared_ptr& theMessage, bool } } - // TO DO: make it in thread and with usage of semaphores + // TODO: make it in thread and with usage of semaphores map > >::iterator aFindID = myListeners.find( theMessage->eventID().eventText()); @@ -81,8 +84,12 @@ void Events_Loop::send(const boost::shared_ptr& theMessage, bool } void Events_Loop::registerListener(Events_Listener* theListener, const Events_ID theID, - void* theSender) + void* theSender, bool theImmediate) { + if (theImmediate) { // just register as an immediate + myImmediateListeners[theID.eventText()] = theListener; + return; + } map > >::iterator aFindID = myListeners.find( theID.eventText()); if (aFindID == myListeners.end()) { // create container associated with ID diff --git a/src/Events/Events_Loop.h b/src/Events/Events_Loop.h index 3a02e16a6..b02c978c8 100644 --- a/src/Events/Events_Loop.h +++ b/src/Events/Events_Loop.h @@ -28,6 +28,9 @@ class Events_Loop /// map from event ID to sender pointer to listeners that must be called for this std::map > > myListeners; + /// map from event ID to listeners which must process message without waiting for flush + std::map myImmediateListeners; + /// map from event ID to groupped messages (accumulated on flush) std::map > myGroups; @@ -51,7 +54,7 @@ class Events_Loop //! Registers (or adds if such listener is already registered) a listener //! that will be called on the event and from the defined sender EVENTS_EXPORT void registerListener(Events_Listener* theListener, const Events_ID theID, - void* theSender = 0); + void* theSender = 0, bool theImmediate = false); //! Initializes sending of a group-message by the given ID EVENTS_EXPORT void flush(const Events_ID& theID); diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index 08eb944fa..8b792974c 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -255,8 +255,12 @@ bool Model_Document::compactNested() void Model_Document::finishOperation() { - // just to be sure that everybody knows that changes were performed + // finish for all subs first: to avoid nested finishing and "isOperation" calls problems inside + std::set::iterator aSubIter = mySubs.begin(); + for (; aSubIter != mySubs.end(); aSubIter++) + subDoc(*aSubIter)->finishOperation(); + // just to be sure that everybody knows that changes were performed if (!myDoc->HasOpenCommand() && myNestedNum != -1) boost::static_pointer_cast(Model_Session::get()) ->setCheckTransactions(false); // for nested transaction commit @@ -282,10 +286,6 @@ void Model_Document::finishOperation() myTransactionsAfterSave++; } - // finish for all subs - std::set::iterator aSubIter = mySubs.begin(); - for (; aSubIter != mySubs.end(); aSubIter++) - subDoc(*aSubIter)->finishOperation(); } void Model_Document::abortOperation() diff --git a/src/Model/Model_Session.cpp b/src/Model/Model_Session.cpp index 51f97e0f7..e63c97cab 100644 --- a/src/Model/Model_Session.cpp +++ b/src/Model/Model_Session.cpp @@ -204,9 +204,9 @@ Model_Session::Model_Session() Events_Loop* aLoop = Events_Loop::loop(); static const Events_ID kFeatureEvent = Events_Loop::eventByName("FeatureRegisterEvent"); aLoop->registerListener(this, kFeatureEvent); - aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED)); - aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); - aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED)); + aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED), 0, true); + aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED), 0, true); + aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED), 0, true); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_VALIDATOR_LOADED)); } diff --git a/src/XGUI/XGUI_OperationMgr.cpp b/src/XGUI/XGUI_OperationMgr.cpp index 00cd7df25..aa677172b 100644 --- a/src/XGUI/XGUI_OperationMgr.cpp +++ b/src/XGUI/XGUI_OperationMgr.cpp @@ -112,7 +112,7 @@ bool XGUI_OperationMgr::abortAllOperations() bool XGUI_OperationMgr::validateOperation(ModuleBase_Operation* theOperation) { - if(!theOperation) + if (!theOperation) return false; //Get operation feature to validate FeaturePtr aFeature = theOperation->feature(); -- 2.39.2