]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #126: Activate a part on current document changed event
authorvsv <vitaly.smetannikov@opencascade.com>
Fri, 12 Sep 2014 07:37:02 +0000 (11:37 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Fri, 12 Sep 2014 07:37:02 +0000 (11:37 +0400)
src/Model/Model_Session.cpp
src/XGUI/XGUI_DocumentDataModel.cpp
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 6f334290c900e761b3dcf56414b59b1951691ae4..3bc3dee03835ddcda2adbe36cc71b32d77e9b1d1 100644 (file)
@@ -133,9 +133,11 @@ boost::shared_ptr<ModelAPI_Document> Model_Session::activeDocument()
 
 void Model_Session::setActiveDocument(boost::shared_ptr<ModelAPI_Document> 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<ModelAPI_Document> Model_Session::copy(
index 35198dccc09d1bc49e5c8c698e538e2ab70b5f6a..fcb176d1afcc0ccd61e5bb1b138d1f03e4a71431 100644 (file)
@@ -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);
index 8e8babd3b923b047629ac19c94f095f31e959137..2f286672d00acfa7f7124292b82b6c66c26eeb8e 100644 (file)
@@ -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<ModelAPI_ResultPart>(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<const Events_Error*>(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;
+  }
 }
 
 //**************************************************************
index 946e75c9d9ccc44ccb609f1a338a10765e2aec31..f9a5ee50dc7c19e7031dcd8746764a0959dbff9d 100644 (file)
@@ -269,6 +269,9 @@ signals:
   static QMap<QString, QString> myIcons;
 
   bool myUpdatePrefs;
+
+  // Flag to check that part document is in process of activating
+  bool myPartActivating;
 };
 
 #endif