From 5ca04b52e9ee7926691eaa974523a59a3c81f96e Mon Sep 17 00:00:00 2001 From: vsv Date: Fri, 23 May 2014 16:47:23 +0400 Subject: [PATCH] Fix of activation/deactivation of documents --- src/Model/Model_Document.cpp | 9 ++++++--- src/Model/Model_Object.h | 3 ++- src/XGUI/XGUI_DocumentDataModel.cpp | 16 ++++++++++++++-- src/XGUI/XGUI_Workshop.cpp | 8 -------- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index 6343d8b7b..f1f67b7b6 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -585,11 +585,14 @@ void Model_Document::synchronizeFeatures() aDSTag = aFLabIter.Value()->Label().Tag(); } if (aDSTag > aFeatureTag) { // feature is removed - Model_FeatureDeletedMessage aMsg1(aThis, FEATURES_GROUP); - Model_FeatureDeletedMessage aMsg2(aThis, (*aFIter)->getGroup()); + FeaturePtr aFeature = *aFIter; aFIter = myFeatures.erase(aFIter); // event: model is updated - Events_Loop::loop()->send(aMsg1); + if (aFeature->isInHistory()) { + Model_FeatureDeletedMessage aMsg1(aThis, FEATURES_GROUP); + Events_Loop::loop()->send(aMsg1); + } + Model_FeatureDeletedMessage aMsg2(aThis, aFeature->getGroup()); Events_Loop::loop()->send(aMsg2); } else if (aDSTag < aFeatureTag) { // a new feature is inserted // create a feature diff --git a/src/Model/Model_Object.h b/src/Model/Model_Object.h index 8179d701d..811edf709 100644 --- a/src/Model/Model_Object.h +++ b/src/Model/Model_Object.h @@ -7,6 +7,7 @@ #include #include +#include #include @@ -34,7 +35,7 @@ public: MODEL_EXPORT virtual const std::string& getKind() {return myRef->getKind();} /// Returns to which group in the document must be added feature - MODEL_EXPORT virtual const std::string& getGroup() {return myRef->getGroup();} + MODEL_EXPORT virtual const std::string& getGroup() {return FEATURES_GROUP;} /// Returns document this feature belongs to MODEL_EXPORT virtual boost::shared_ptr document() diff --git a/src/XGUI/XGUI_DocumentDataModel.cpp b/src/XGUI/XGUI_DocumentDataModel.cpp index d1ca2c2ed..37c78f82a 100644 --- a/src/XGUI/XGUI_DocumentDataModel.cpp +++ b/src/XGUI/XGUI_DocumentDataModel.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include @@ -58,7 +59,7 @@ void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage) if (aDoc == myDocument) { // If root objects if (aFeature->getGroup().compare(PARTS_GROUP) == 0) { // Update only Parts group // Add a new part - int aStart = myPartModels.size() + 1; + int aStart = myPartModels.size(); XGUI_PartDataModel* aModel = new XGUI_PartDataModel(myDocument, this); aModel->setPartId(myPartModels.count()); myPartModels.append(aModel); @@ -100,6 +101,11 @@ void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage) int aStart = myPartModels.size() - 1; removeSubModel(aStart); removeRow(aStart, partFolderNode()); + if (myActivePart && (!isPartSubModel(myActivePart))) { + myActivePart = 0; + myActivePartIndex = QModelIndex(); + myModel->setItemsColor(ACTIVE_COLOR); + } } else { // Update top groups (other except parts QModelIndex aIndex = myModel->findGroup(aGroup); int aStart = myModel->rowCount(aIndex); @@ -470,6 +476,7 @@ void XGUI_DocumentDataModel::deactivatePart() if (myActivePart) myActivePart->setItemsColor(PASSIVE_COLOR); myActivePart = 0; + myActivePartIndex = QModelIndex(); myModel->setItemsColor(ACTIVE_COLOR); } @@ -484,11 +491,16 @@ Qt::ItemFlags XGUI_DocumentDataModel::flags(const QModelIndex& theIndex) const QModelIndex XGUI_DocumentDataModel::partIndex(const FeaturePtr& theFeature) const { + FeaturePtr aFeature = theFeature; + if (!aFeature->data()) { + ObjectPtr aObject = boost::dynamic_pointer_cast(aFeature); + aFeature = aObject->featureRef(); + } int aRow = -1; XGUI_PartModel* aModel = 0; foreach (XGUI_PartModel* aPartModel, myPartModels) { aRow++; - if (aPartModel->part() == theFeature) { + if (aPartModel->part() == aFeature) { aModel = aPartModel; break; } diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 389f81420..c18868292 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -121,7 +121,6 @@ void XGUI_Workshop::startApplication() Events_ID aFeatureUpdatedId = aLoop->eventByName(EVENT_FEATURE_UPDATED); aLoop->registerListener(this, aFeatureUpdatedId); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_CREATED)); - aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_DELETED)); activateModule(); if (myMainWindow) { @@ -238,13 +237,6 @@ void XGUI_Workshop::processEvent(const Events_Message* theMessage) } } - // Process deletion of a part - if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_DELETED)) { - PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); - if (aMgr->currentDocument() == aMgr->rootDocument()) - activatePart(FeaturePtr()); // Activate PartSet - } - //Update property panel on corresponding message. If there is no current operation (no //property panel), or received message has different feature to the current - do nothing. static Events_ID aFeatureUpdatedId = Events_Loop::loop()->eventByName(EVENT_FEATURE_UPDATED); -- 2.39.2