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(
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);
myPropertyPanel(0),
myObjectBrowser(0),
myDisplayer(0),
- myUpdatePrefs(false)
+ myUpdatePrefs(false),
+ myPartActivating(false)
{
myMainWindow = mySalomeConnector ? 0 : new XGUI_MainWindow();
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();
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);
//**************************************************************
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;
+ }
}
//**************************************************************