From 6d85c9eb0084d8c6aff9aaff940bd022f85bf2bd Mon Sep 17 00:00:00 2001 From: vsv Date: Fri, 12 Sep 2014 11:37:02 +0400 Subject: [PATCH] Issue #126: Activate a part on current document changed event --- src/Model/Model_Session.cpp | 8 +++--- src/XGUI/XGUI_DocumentDataModel.cpp | 1 - src/XGUI/XGUI_Workshop.cpp | 39 +++++++++++++++++++++++++---- src/XGUI/XGUI_Workshop.h | 3 +++ 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/Model/Model_Session.cpp b/src/Model/Model_Session.cpp index 6f334290c..3bc3dee03 100644 --- a/src/Model/Model_Session.cpp +++ b/src/Model/Model_Session.cpp @@ -133,9 +133,11 @@ boost::shared_ptr Model_Session::activeDocument() void Model_Session::setActiveDocument(boost::shared_ptr theDoc) { - myCurrentDoc = theDoc; - static Events_Message aMsg(Events_Loop::eventByName("CurrentDocumentChanged")); - Events_Loop::loop()->send(aMsg); + if (myCurrentDoc != theDoc) { + myCurrentDoc = theDoc; + static Events_Message aMsg(Events_Loop::eventByName("CurrentDocumentChanged")); + Events_Loop::loop()->send(aMsg); + } } boost::shared_ptr Model_Session::copy( diff --git a/src/XGUI/XGUI_DocumentDataModel.cpp b/src/XGUI/XGUI_DocumentDataModel.cpp index 35198dccc..fcb176d1a 100644 --- a/src/XGUI/XGUI_DocumentDataModel.cpp +++ b/src/XGUI/XGUI_DocumentDataModel.cpp @@ -33,7 +33,6 @@ XGUI_DocumentDataModel::XGUI_DocumentDataModel(QObject* theParent) 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("CurrentDocumentChanged")); // Create a top part of data tree model myModel = new XGUI_TopDataModel(this); diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 8e8babd3b..2f286672d 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -87,7 +87,8 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) myPropertyPanel(0), myObjectBrowser(0), myDisplayer(0), - myUpdatePrefs(false) + myUpdatePrefs(false), + myPartActivating(false) { myMainWindow = mySalomeConnector ? 0 : new XGUI_MainWindow(); @@ -141,6 +142,7 @@ void XGUI_Workshop::startApplication() aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED)); aLoop->registerListener(this, Events_Loop::eventByName("LongOperation")); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_PLUGIN_LOADED)); + aLoop->registerListener(this, Events_Loop::eventByName("CurrentDocumentChanged")); registerValidators(); activateModule(); @@ -297,6 +299,29 @@ void XGUI_Workshop::processEvent(const Events_Message* theMessage) updateCommandStatus(); } } + } + else if (theMessage->eventID() == Events_Loop::loop()->eventByName("CurrentDocumentChanged")) { + // Find and Activate active part + if (myPartActivating) + return; + SessionPtr aMgr = ModelAPI_Session::get(); + DocumentPtr aActiveDoc = aMgr->activeDocument(); + DocumentPtr aDoc = aMgr->moduleDocument(); + if (aActiveDoc == aDoc) { + activatePart(ResultPartPtr()); + return; + } + std::string aGrpName = ModelAPI_ResultPart::group(); + for (int i = 0; i < aDoc->size(aGrpName); i++) { + ResultPartPtr aPart = boost::dynamic_pointer_cast(aDoc->object(aGrpName, i)); + if (aPart->partDoc() == aActiveDoc) { + activatePart(aPart); // Activate a part which corresponds to active Doc + return; + } + } + // If not found then activate global document + activatePart(ResultPartPtr()); + } else { //Show error dialog if error message received. const Events_Error* anAppError = dynamic_cast(theMessage); @@ -1005,10 +1030,14 @@ void XGUI_Workshop::onWidgetValuesChanged() //************************************************************** void XGUI_Workshop::activatePart(ResultPartPtr theFeature) { - if (theFeature) - theFeature->activate(); - changeCurrentDocument(theFeature); - myObjectBrowser->activatePart(theFeature); + if (!myPartActivating) { + myPartActivating = true; + if (theFeature) + theFeature->activate(); + changeCurrentDocument(theFeature); + myObjectBrowser->activatePart(theFeature); + myPartActivating = false; + } } //************************************************************** diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 946e75c9d..f9a5ee50d 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -269,6 +269,9 @@ signals: static QMap myIcons; bool myUpdatePrefs; + + // Flag to check that part document is in process of activating + bool myPartActivating; }; #endif -- 2.39.2