From: vsv Date: Tue, 12 May 2015 07:46:54 +0000 (+0300) Subject: Files to reproduce bug with Current feature X-Git-Tag: V_1.2.0~161 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5eed4d5391e6f79c7062c19fab6a392e71ea2822;p=modules%2Fshaper.git Files to reproduce bug with Current feature --- diff --git a/src/PartSet/PartSet_DocumentDataModel.cpp b/src/PartSet/PartSet_DocumentDataModel.cpp index fcf37a140..64ac554c2 100644 --- a/src/PartSet/PartSet_DocumentDataModel.cpp +++ b/src/PartSet/PartSet_DocumentDataModel.cpp @@ -36,7 +36,7 @@ QMap PartSet_DocumentDataModel::myIcons; PartSet_DocumentDataModel::PartSet_DocumentDataModel(QObject* theParent) : ModuleBase_IDocumentDataModel(theParent), - myActivePartId(-1), myHistoryBackOffset(0) + myActivePartId(-1) { // Create a top part of data tree model myModel = new PartSet_TopDataModel(this); @@ -598,34 +598,6 @@ bool PartSet_DocumentDataModel::activatePart(const QModelIndex& theIndex) myActivePartId = aRootDoc->index(aFeature); myPartModels[myActivePartId]->setItemsColor(ACTIVE_COLOR); } - //QModelIndex* aIndex = toSourceModelIndex(theIndex); - //if (!aIndex) - // return false; - - //const QAbstractItemModel* aModel = aIndex->model(); - - //if (isPartSubModel(aModel)) { - // // if this is root node (Part item index) - // if (!aIndex->parent().isValid()) { - // if (myActivePart) - // myActivePart->setItemsColor(PASSIVE_COLOR); - - // if (myActivePart == aModel) { - // myActivePart = 0; - // myActivePartIndex = QModelIndex(); - // } else { - // myActivePart = (PartSet_PartModel*)aModel; - // myActivePartIndex = theIndex; - // } - - // if (myActivePart) { - // myActivePart->setItemsColor(ACTIVE_COLOR); - // myModel->setItemsColor(PASSIVE_COLOR); - // } else - // myModel->setItemsColor(ACTIVE_COLOR); - // return true; - // } - // } return true; } @@ -745,12 +717,21 @@ void PartSet_DocumentDataModel::clear() int PartSet_DocumentDataModel::lastHistoryRow() const { - return rowCount() - 1 - myHistoryBackOffset; + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); + FeaturePtr aFeature = aRootDoc->currentFeature(); + return historyOffset() + aRootDoc->index(aFeature); } void PartSet_DocumentDataModel::setLastHistoryItem(const QModelIndex& theIndex) { - myHistoryBackOffset = rowCount() - 1 - theIndex.row(); + if (theIndex.internalId() == HistoryNode) { + ObjectPtr aObject = object(theIndex); + SessionPtr aMgr = ModelAPI_Session::get(); + DocumentPtr aRootDoc = aMgr->moduleDocument(); + aMgr->startOperation(tr("History change").toStdString()); + aRootDoc->setCurrentFeature(std::dynamic_pointer_cast(aObject)); + aMgr->finishOperation(); + } } QModelIndex PartSet_DocumentDataModel::lastHistoryItem() const diff --git a/src/PartSet/PartSet_DocumentDataModel.h b/src/PartSet/PartSet_DocumentDataModel.h index 6ab69bf3c..6692d085a 100644 --- a/src/PartSet/PartSet_DocumentDataModel.h +++ b/src/PartSet/PartSet_DocumentDataModel.h @@ -197,8 +197,6 @@ Q_OBJECT //! List of saved QModelIndexes created by sub-models QList myIndexes; - int myHistoryBackOffset; - static QMap myIcons; }; diff --git a/src/PartSet/PartSet_MenuMgr.cpp b/src/PartSet/PartSet_MenuMgr.cpp index e453a5525..1664be769 100644 --- a/src/PartSet/PartSet_MenuMgr.cpp +++ b/src/PartSet/PartSet_MenuMgr.cpp @@ -9,6 +9,8 @@ #include "PartSet_SketcherMgr.h" #include "PartSet_Tools.h" +#include + #include #include @@ -470,10 +472,16 @@ void PartSet_MenuMgr::onActivatePart(bool) { QObjectPtrList aObjects = myModule->workshop()->selection()->selectedObjects(); if (aObjects.size() > 0) { - ResultPartPtr aPart = std::dynamic_pointer_cast(aObjects.first()); - if (aPart) { - aPart->activate(); + ObjectPtr aObj = aObjects.first(); + ResultPartPtr aPart = std::dynamic_pointer_cast(aObj); + if (!aPart.get()) { + FeaturePtr aPartFeature = std::dynamic_pointer_cast(aObj); + if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) { + aPart = std::dynamic_pointer_cast(aPartFeature->firstResult()); + } } + if (aPart.get()) + aPart->activate(); } } diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 860ca9e37..ffe80756d 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -669,8 +669,16 @@ void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const ObjectPtr aObject = aObjects.first(); if (aObject) { ResultPartPtr aPart = std::dynamic_pointer_cast(aObject); - if (aPart) { - if (aMgr->activeDocument() == aPart->partDoc()) + FeaturePtr aPartFeature = std::dynamic_pointer_cast(aObject); + bool isPart = aPart.get() || + (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())); + if (isPart) { + DocumentPtr aPartDoc; + if (!aPart.get()) { + aPart = std::dynamic_pointer_cast(aPartFeature->firstResult()); + } + aPartDoc = aPart->partDoc(); + if (aMgr->activeDocument() == aPartDoc) theMenu->addAction(myMenuMgr->action("DEACTIVATE_PART_CMD")); else theMenu->addAction(myMenuMgr->action("ACTIVATE_PART_CMD")); @@ -684,8 +692,10 @@ void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const } } else if (aSelected == 0) { // if there is no selection then it means that upper label is selected - if (aMgr->activeDocument() != aMgr->moduleDocument()) - theMenu->addAction(myMenuMgr->action("ACTIVATE_PARTSET_CMD")); + QModelIndexList aIndexes = myWorkshop->selection()->selectedIndexes(); + if (aIndexes.size() == 0) // it means that selection happens in top label outside of tree view + if (aMgr->activeDocument() != aMgr->moduleDocument()) + theMenu->addAction(myMenuMgr->action("ACTIVATE_PARTSET_CMD")); } } diff --git a/src/PartSet/PartSet_PartDataModel.cpp b/src/PartSet/PartSet_PartDataModel.cpp index ec4dabffa..1398e5957 100644 --- a/src/PartSet/PartSet_PartDataModel.cpp +++ b/src/PartSet/PartSet_PartDataModel.cpp @@ -246,7 +246,7 @@ QModelIndex PartSet_TopDataModel::objectIndex(const ObjectPtr& theObject) const //****************************************************************** //****************************************************************** PartSet_PartDataModel::PartSet_PartDataModel(QObject* theParent) - : PartSet_PartModel(theParent), myHistoryBackOffset(0) + : PartSet_PartModel(theParent) { } @@ -572,13 +572,20 @@ int PartSet_PartDataModel::getRowsNumber() const int PartSet_PartDataModel::lastHistoryRow() const { - return rowCount() - 1 - myHistoryBackOffset; + DocumentPtr aDoc = partDocument(); + FeaturePtr aFeature = aDoc->currentFeature(); + return getRowsNumber() + aDoc->index(aFeature); } void PartSet_PartDataModel::setLastHistoryItem(const QModelIndex& theIndex) { if (theIndex.internalId() == HistoryObject) { - myHistoryBackOffset = rowCount() - 1 - theIndex.row(); + SessionPtr aMgr = ModelAPI_Session::get(); + ObjectPtr aObject = object(theIndex); + DocumentPtr aDoc = partDocument(); + aMgr->startOperation(tr("History change").toStdString()); + aDoc->setCurrentFeature(std::dynamic_pointer_cast(aObject)); + aMgr->finishOperation(); } } diff --git a/src/PartSet/PartSet_PartDataModel.h b/src/PartSet/PartSet_PartDataModel.h index c821b4b50..08be66b30 100644 --- a/src/PartSet/PartSet_PartDataModel.h +++ b/src/PartSet/PartSet_PartDataModel.h @@ -198,8 +198,6 @@ Q_OBJECT GroupObject, HistoryObject }; - - int myHistoryBackOffset; }; #endif