From 42cd47b33727c9b7f02b43960f8b2633001942ae Mon Sep 17 00:00:00 2001 From: mpv Date: Tue, 30 Aug 2016 17:52:45 +0300 Subject: [PATCH] Fix for the issue #1647 : problem with OB when sub-features are created. --- src/Events/Events_Loop.cpp | 2 - src/Events/Events_Loop.h | 6 ++- .../ExchangePlugin_ImportFeature.cpp | 3 ++ src/Model/Model_Update.cpp | 3 +- src/ModelHighAPI/ModelHighAPI_Services.cpp | 4 ++ src/XGUI/XGUI_DataModel.cpp | 46 ++++++++++--------- 6 files changed, 39 insertions(+), 25 deletions(-) diff --git a/src/Events/Events_Loop.cpp b/src/Events/Events_Loop.cpp index b96974189..e68798aa4 100644 --- a/src/Events/Events_Loop.cpp +++ b/src/Events/Events_Loop.cpp @@ -62,8 +62,6 @@ void Events_Loop::send(const std::shared_ptr& theMessage, bool i } } - // TODO: make it in thread and with usage of semaphores - map > >::iterator aFindID = myListeners.find( theMessage->eventID().eventText()); if (aFindID != myListeners.end()) { diff --git a/src/Events/Events_Loop.h b/src/Events/Events_Loop.h index c1c5f2977..0d1f729bd 100644 --- a/src/Events/Events_Loop.h +++ b/src/Events/Events_Loop.h @@ -60,8 +60,12 @@ 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 + //! \param theListener the object that will listen (process) the event + //! \param theID listen for messages with this ID + //! \param theSender listen only for this sender (NULL - listen everybody) + //! \param theImmediate for listeners who can not wait (no groupping mechanism is used for it) EVENTS_EXPORT void registerListener(Events_Listener* theListener, const Events_ID theID, - void* theSender = 0, bool theImmediate = false); + void* theSender = 0, bool theImmediate = false); //! Remove the listener from internal maps if it was registered there //! \param theListener a listener diff --git a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp index d5eaf2360..4107115ce 100644 --- a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp @@ -187,6 +187,9 @@ void ExchangePlugin_ImportFeature::importXAO(const std::string& theFileName) aSelectionList->value(anElementIndex)->setId(aReferenceID); } } + // Top avoid problems in Object Browser update: issue #1647. + ModelAPI_EventCreator::get()->sendReordered( + std::dynamic_pointer_cast(aRefListOfGroups->owner())); } catch (XAO::XAO_Exception& e) { std::string anError = e.what(); diff --git a/src/Model/Model_Update.cpp b/src/Model/Model_Update.cpp index c081fbd70..48b8dcb00 100755 --- a/src/Model/Model_Update.cpp +++ b/src/Model/Model_Update.cpp @@ -310,7 +310,8 @@ void Model_Update::processEvent(const std::shared_ptr& theMessag } else if (theMessage->eventID() == kReorderEvent) { std::shared_ptr aMsg = std::dynamic_pointer_cast(theMessage); - addModified(aMsg->reordered(), aMsg->reordered()); // to update all attributes + if (aMsg->reordered().get()) + addModified(aMsg->reordered(), aMsg->reordered()); // to update all attributes } } diff --git a/src/ModelHighAPI/ModelHighAPI_Services.cpp b/src/ModelHighAPI/ModelHighAPI_Services.cpp index c1c6e64b3..4b40b09e1 100644 --- a/src/ModelHighAPI/ModelHighAPI_Services.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Services.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include @@ -84,9 +85,12 @@ void begin() { ModelAPI_Session::get()->startOperation(); } + void end() { ModelAPI_Session::get()->finishOperation(); + // to update data tree in the end of dumped script execution + ModelAPI_EventCreator::get()->sendReordered(FeaturePtr()); } void apply() { diff --git a/src/XGUI/XGUI_DataModel.cpp b/src/XGUI/XGUI_DataModel.cpp index cc80025fb..3d14d5108 100644 --- a/src/XGUI/XGUI_DataModel.cpp +++ b/src/XGUI/XGUI_DataModel.cpp @@ -255,29 +255,33 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_ORDER_UPDATED)) { std::shared_ptr aUpdMsg = std::dynamic_pointer_cast(theMessage); - DocumentPtr aDoc = aUpdMsg->reordered()->document(); - std::string aGroup = aUpdMsg->reordered()->group(); - - QModelIndex aParent; - int aStartId = 0; - if (aDoc == aRootDoc) { - // Update a group under root - if (aGroup == myXMLReader->rootType()) // Update objects under root - aStartId = foldersCount(); - else // Update objects in folder under root - aParent = createIndex(folderId(aGroup), 0, -1); + if (aUpdMsg->reordered().get()) { + DocumentPtr aDoc = aUpdMsg->reordered()->document(); + std::string aGroup = aUpdMsg->reordered()->group(); + + QModelIndex aParent; + int aStartId = 0; + if (aDoc == aRootDoc) { + // Update a group under root + if (aGroup == myXMLReader->rootType()) // Update objects under root + aStartId = foldersCount(); + else // Update objects in folder under root + aParent = createIndex(folderId(aGroup), 0, -1); + } else { + // Update a sub-document + if (aGroup == myXMLReader->subType()) { + // Update sub-document root + aParent = findDocumentRootIndex(aDoc.get()); + aStartId = foldersCount(aDoc.get()); + } else + // update folder in sub-document + aParent = createIndex(folderId(aGroup, aDoc.get()), 0, aDoc.get()); + } + int aChildNb = rowCount(aParent); + rebuildBranch(aStartId, aChildNb - aStartId, aParent); } else { - // Update a sub-document - if (aGroup == myXMLReader->subType()) { - // Update sub-document root - aParent = findDocumentRootIndex(aDoc.get()); - aStartId = foldersCount(aDoc.get()); - } else - // update folder in sub-document - aParent = createIndex(folderId(aGroup, aDoc.get()), 0, aDoc.get()); + rebuildDataTree(); } - int aChildNb = rowCount(aParent); - rebuildBranch(aStartId, aChildNb - aStartId, aParent); } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) { DocumentPtr aDoc = ModelAPI_Session::get()->activeDocument(); if (aDoc != aRootDoc) { -- 2.39.2