- //Show error dialog if error message received.
- const Events_Error* anAppError = dynamic_cast<const Events_Error*>(theMessage);
- if (anAppError) {
- emit errorOccurred(QString::fromLatin1(anAppError->description()));
+ else if (theMessage->eventID() == Events_Loop::loop()->eventByName("CurrentDocumentChanged")) {
+ myActionsMgr->update();
+ // 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.
+ boost::shared_ptr<Events_Error> anAppError = boost::dynamic_pointer_cast<Events_Error>(theMessage);
+ if (anAppError) {
+ emit errorOccurred(QString::fromLatin1(anAppError->description()));
+ }
+ }
+ if (!isSalomeMode()) {
+ SessionPtr aMgr = ModelAPI_Session::get();
+ if (aMgr->isModified() != myMainWindow->isModifiedState())
+ myMainWindow->setModifiedState(aMgr->isModified());