]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'master' of newgeom:newgeom
authorvsv <vitaly.smetannikov@opencascade.com>
Fri, 12 Sep 2014 07:37:24 +0000 (11:37 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Fri, 12 Sep 2014 07:37:24 +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 84d5f184d547f27e93dd0e7a80a74376cb3eedd5..9e21d483181271c7392633267faedee67cd52ab0 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);
@@ -1011,10 +1036,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 f129faddff2d287e58e0a0ed2d6344d9b30b2fae..b969861682dec1ec56492aa3dbdf5e594737f444 100644 (file)
@@ -275,6 +275,9 @@ signals:
   static QMap<QString, QString> myIcons;
 
   bool myUpdatePrefs;
+
+  // Flag to check that part document is in process of activating
+  bool myPartActivating;
 };
 
 #endif