From: mpv Date: Wed, 13 May 2015 11:34:09 +0000 (+0300) Subject: Make invisible in the tree objects correctly processed: all invisible after the curre... X-Git-Tag: V_1.2.0~155 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=915fb2da2b16887c46305221513fceac0a1dab0f;p=modules%2Fshaper.git Make invisible in the tree objects correctly processed: all invisible after the current are enabled. This helps with sketch sub-elements processing. --- diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index b5ee4b75b..108bb398e 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -600,7 +600,7 @@ FeaturePtr Model_Document::addFeature(std::string theID) static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED); ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent); aFeature->setDisabled(false); // by default created feature is enabled - setCurrentFeature(aFeature); // after all this feature stays in the document, so make it current + setCurrentFeature(aFeature, false); // after all this feature stays in the document, so make it current } else { // feature must be executed // no creation event => updater not working, problem with remove part aFeature->execute(); @@ -703,11 +703,11 @@ void Model_Document::removeFeature(FeaturePtr theFeature/*, const bool theCheck* } } // if this feature is current, make the current the previous feature - if (theFeature == currentFeature()) { + if (theFeature == currentFeature(false)) { int aCurrentIndex = index(theFeature); if (aCurrentIndex != -1) { setCurrentFeature(std::dynamic_pointer_cast( - object(ModelAPI_Feature::group(), aCurrentIndex - 1))); + object(ModelAPI_Feature::group(), aCurrentIndex - 1)), false); } } @@ -965,24 +965,57 @@ int Model_Document::size(const std::string& theGroupID, const bool theHidden) return aResult; } -std::shared_ptr Model_Document::currentFeature() +std::shared_ptr Model_Document::currentFeature(const bool theVisible) { TDF_Label aRefLab = generalLabel().FindChild(TAG_CURRENT_FEATURE); Handle(TDF_Reference) aRef; if (aRefLab.FindAttribute(TDF_Reference::GetID(), aRef)) { TDF_Label aLab = aRef->Get(); - return feature(aLab); + FeaturePtr aResult = feature(aLab); + if (theVisible) { // get nearest visible (in history) going up + int aTag = aLab.Tag(); + while(aTag > 1 && (!aResult.get() || !aResult->isInHistory())) { + aTag--; + aLab = aLab.Father().FindChild(aTag); + aResult = feature(aLab); + } + if (aTag <= 1) + aResult.reset(); + } + return aResult; } return std::shared_ptr(); // null feature means the higher than first } -void Model_Document::setCurrentFeature(std::shared_ptr theCurrent) +void Model_Document::setCurrentFeature(std::shared_ptr theCurrent, + const bool theVisible) { TDF_Label aRefLab = generalLabel().FindChild(TAG_CURRENT_FEATURE); if (theCurrent.get()) { std::shared_ptr aData = std::static_pointer_cast(theCurrent->data()); if (aData.get()) { TDF_Label aFeatureLabel = aData->label().Father(); + if (theVisible) { // make features below which are not in history also enabled: sketch subs + int aTag = aFeatureLabel.Tag(); + FeaturePtr aNextFeature; + TDF_Label aNextLabel; + for(aTag++; true; aTag++) { + TDF_Label aLabel = aFeatureLabel.Father().FindChild(aTag, 0); + if (aLabel.IsNull()) + break; + FeaturePtr aFeature = feature(aLabel); + if (aFeature.get()) { + if (aFeature->isInHistory()) + break; + aNextFeature = aFeature; + aNextLabel = aLabel; + } + } + if (aNextFeature.get()) { + theCurrent = aNextFeature; + aFeatureLabel = aNextLabel; + } + } Handle(TDF_Reference) aRef; if (aRefLab.FindAttribute(TDF_Reference::GetID(), aRef)) { aRef->Set(aFeatureLabel); diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index 17c14caa9..f190c55df 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -136,12 +136,16 @@ class Model_Document : public ModelAPI_Document //! Returns the feature that is currently edited in this document, normally //! this is the latest created feature + //! \param theVisible use visible features only: flag is true for Object Browser functionality //! \returns null if next created feature must be the first - MODEL_EXPORT virtual std::shared_ptr currentFeature(); + MODEL_EXPORT virtual std::shared_ptr currentFeature(const bool theVisible); //! Sets the current feature: all features below will be disabled, new features //! will be appended after this one. - MODEL_EXPORT virtual void setCurrentFeature(std::shared_ptr theCurrent); + //! \param theCurrent the selected feature as current: blow it everythin become disabled + //! \param theVisible use visible features only: flag is true for Object Browser functionality + MODEL_EXPORT virtual void setCurrentFeature(std::shared_ptr theCurrent, + const bool theVisible); /// Creates a construction cresults MODEL_EXPORT virtual std::shared_ptr createConstruction( diff --git a/src/ModelAPI/ModelAPI_Document.h b/src/ModelAPI/ModelAPI_Document.h index dc43fac41..be7fa566c 100644 --- a/src/ModelAPI/ModelAPI_Document.h +++ b/src/ModelAPI/ModelAPI_Document.h @@ -90,12 +90,16 @@ public: //! Returns the feature that is currently edited in this document, normally //! this is the latest created feature + //! \param theVisible use visible features only: flag is true for Object Browser functionality //! \returns null if next created feature must be the first - virtual std::shared_ptr currentFeature() = 0; + virtual std::shared_ptr currentFeature(const bool theVisible) = 0; //! Sets the current feature: all features below will be disabled, new features //! will be appended after this one. - virtual void setCurrentFeature(std::shared_ptr theCurrent) = 0; + //! \param theCurrent the selected feature as current: blow it everythin become disabled + //! \param theVisible use visible features only: flag is true for Object Browser functionality + virtual void setCurrentFeature(std::shared_ptr theCurrent, + const bool theVisible) = 0; /// To virtually destroy the fields of successors MODELAPI_EXPORT virtual ~ModelAPI_Document(); diff --git a/src/PartSet/PartSet_DocumentDataModel.cpp b/src/PartSet/PartSet_DocumentDataModel.cpp index 5ca4aef65..74df2229e 100644 --- a/src/PartSet/PartSet_DocumentDataModel.cpp +++ b/src/PartSet/PartSet_DocumentDataModel.cpp @@ -718,7 +718,7 @@ void PartSet_DocumentDataModel::clear() int PartSet_DocumentDataModel::lastHistoryRow() const { DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - FeaturePtr aFeature = aRootDoc->currentFeature(); + FeaturePtr aFeature = aRootDoc->currentFeature(true); if (aFeature.get()) return historyOffset() + aRootDoc->index(aFeature); else @@ -733,11 +733,11 @@ void PartSet_DocumentDataModel::setLastHistoryItem(const QModelIndex& theIndex) if (theIndex.internalId() == HistoryNode) { ObjectPtr aObject = object(theIndex); aMgr->startOperation(aOpName); - aRootDoc->setCurrentFeature(std::dynamic_pointer_cast(aObject)); + aRootDoc->setCurrentFeature(std::dynamic_pointer_cast(aObject), true); aMgr->finishOperation(); } else { aMgr->startOperation(aOpName); - aRootDoc->setCurrentFeature(FeaturePtr()); + aRootDoc->setCurrentFeature(FeaturePtr(), true); aMgr->finishOperation(); } } diff --git a/src/PartSet/PartSet_PartDataModel.cpp b/src/PartSet/PartSet_PartDataModel.cpp index 1ad039559..e9d378c30 100644 --- a/src/PartSet/PartSet_PartDataModel.cpp +++ b/src/PartSet/PartSet_PartDataModel.cpp @@ -573,7 +573,7 @@ int PartSet_PartDataModel::getRowsNumber() const int PartSet_PartDataModel::lastHistoryRow() const { DocumentPtr aDoc = partDocument(); - FeaturePtr aFeature = aDoc->currentFeature(); + FeaturePtr aFeature = aDoc->currentFeature(true); if (aFeature.get()) return getRowsNumber() + aDoc->index(aFeature); else @@ -588,11 +588,11 @@ void PartSet_PartDataModel::setLastHistoryItem(const QModelIndex& theIndex) if (theIndex.internalId() == HistoryObject) { ObjectPtr aObject = object(theIndex); aMgr->startOperation(aOpName); - aDoc->setCurrentFeature(std::dynamic_pointer_cast(aObject)); + aDoc->setCurrentFeature(std::dynamic_pointer_cast(aObject), true); aMgr->finishOperation(); } else { aMgr->startOperation(aOpName); - aDoc->setCurrentFeature(FeaturePtr()); + aDoc->setCurrentFeature(FeaturePtr(), true); aMgr->finishOperation(); } }