From: mpv Date: Wed, 20 May 2015 12:59:59 +0000 (+0300) Subject: Make feature nested into other feature makes all nested features active X-Git-Tag: V_1.2.0~136 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a38f270b638caaae45d18674b48b8b7479e2ee26;p=modules%2Fshaper.git Make feature nested into other feature makes all nested features active --- diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index 4bf71d034..3f1ae6a4d 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -655,6 +655,7 @@ void Model_Document::setCurrentFeature(std::shared_ptr theCurr { TDF_Label aRefLab = generalLabel().FindChild(TAG_CURRENT_FEATURE); if (theCurrent.get()) { + /* if (theVisible) { // make features below which are not in history also enabled: sketch subs FeaturePtr aNext = myObjs->nextFeature(theCurrent); for (; aNext.get(); aNext = myObjs->nextFeature(theCurrent)) { @@ -664,7 +665,18 @@ void Model_Document::setCurrentFeature(std::shared_ptr theCurr theCurrent = aNext; } } + }*/ + // if feature nests into compisite feature, make the composite feature as current + const std::set& aRefsToMe = theCurrent->data()->refsToMe(); + std::set::const_iterator aRefToMe = aRefsToMe.begin(); + for(; aRefToMe != aRefsToMe.end(); aRefToMe++) { + CompositeFeaturePtr aComposite = + std::dynamic_pointer_cast((*aRefToMe)->owner()); + if (aComposite.get() && aComposite->isSub(theCurrent)) { + theCurrent = aComposite; + } } + std::shared_ptr aData = std::static_pointer_cast(theCurrent->data()); if (!aData.get()) return; // unknown case TDF_Label aFeatureLabel = aData->label().Father(); @@ -679,19 +691,31 @@ void Model_Document::setCurrentFeature(std::shared_ptr theCurr aRefLab.ForgetAttribute(TDF_Reference::GetID()); } // make all features after this feature disabled in reversed order (to remove results without deps) + static Events_Loop* aLoop = Events_Loop::loop(); + static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); + + // if the current feature is composite features, all sub-features also must be enabled + CompositeFeaturePtr aCurComp = std::dynamic_pointer_cast(theCurrent); + + bool aPassed = false; // flag that the current object is already passed in cycle FeaturePtr anIter = myObjs->lastFeature(); for(; anIter.get(); anIter = myObjs->nextFeature(anIter, true)) { // check this before passed become enabled: the current feature is enabled! if (anIter == theCurrent) aPassed = true; - if (anIter->setDisabled(!aPassed)) { + bool aDisabledFlag = !aPassed; + if (aCurComp.get() && aCurComp->isSub(anIter)) + aDisabledFlag = false; + if (anIter->setDisabled(aDisabledFlag)) { // state of feature is changed => so feature become updated - static Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED); + static Events_ID anUpdateEvent = aLoop->eventByName(EVENT_OBJECT_UPDATED); ModelAPI_EventCreator::get()->sendUpdated(anIter, anUpdateEvent); - + // flush is in the end of this method + ModelAPI_EventCreator::get()->sendUpdated(anIter, aRedispEvent /*, false*/); } } + aLoop->flush(aRedispEvent); } TDF_Label Model_Document::generalLabel() const diff --git a/src/ModelAPI/ModelAPI_Feature.cpp b/src/ModelAPI/ModelAPI_Feature.cpp index 3002d889e..1fe0244f0 100644 --- a/src/ModelAPI/ModelAPI_Feature.cpp +++ b/src/ModelAPI/ModelAPI_Feature.cpp @@ -45,8 +45,11 @@ void ModelAPI_Feature::setResult(const std::shared_ptr& theResu } else { myResults.push_back(theResult); } - // in any case result decomes enabled + // in any case result becomes enabled theResult->setDisabled(theResult, false); + // flush vidualisation changes + static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); + aLoop->flush(aRedispEvent); } void ModelAPI_Feature::setResult(const std::shared_ptr& theResult, @@ -62,14 +65,22 @@ void ModelAPI_Feature::setResult(const std::shared_ptr& theResu *aResIter = theResult; } theResult->setDisabled(theResult, false); + // flush visualisation changes + static Events_Loop* aLoop = Events_Loop::loop(); + static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); + aLoop->flush(aRedispEvent); } void ModelAPI_Feature::removeResult(const std::shared_ptr& theResult) { theResult->setDisabled(theResult, true); + // flush visualisation changes + static Events_Loop* aLoop = Events_Loop::loop(); + static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); + aLoop->flush(aRedispEvent); } -void ModelAPI_Feature::removeResults(const int theSinceIndex) +void ModelAPI_Feature::removeResults(const int theSinceIndex, const bool theFlush) { std::list >::iterator aResIter = myResults.begin(); for(int anIndex = 0; anIndex < theSinceIndex && aResIter != myResults.end(); anIndex++) @@ -84,6 +95,12 @@ void ModelAPI_Feature::removeResults(const int theSinceIndex) aNextIter++; } } + if (theFlush) { + // flush visualisation changes + static Events_Loop* aLoop = Events_Loop::loop(); + static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); + aLoop->flush(aRedispEvent); + } } void ModelAPI_Feature::eraseResults() @@ -131,7 +148,6 @@ FeaturePtr ModelAPI_Feature::feature(ObjectPtr theObject) return aFeature; } - bool ModelAPI_Feature::isMacro() const { return false; @@ -142,12 +158,12 @@ bool ModelAPI_Feature::setDisabled(const bool theFlag) if (myIsDisabled != theFlag) { myIsDisabled = theFlag; if (myIsDisabled) { - eraseResults(); + removeResults(0, false); // flush will be in setCurrentFeature } else { // enable all disabled previously results std::list >::iterator aResIter = myResults.begin(); for(; aResIter != myResults.end(); aResIter++) { - (*aResIter)->setDisabled(*aResIter, false); // just enable results + (*aResIter)->setDisabled(*aResIter, false); } } return true; diff --git a/src/ModelAPI/ModelAPI_Feature.h b/src/ModelAPI/ModelAPI_Feature.h index 72d58660d..436a1adbf 100644 --- a/src/ModelAPI/ModelAPI_Feature.h +++ b/src/ModelAPI/ModelAPI_Feature.h @@ -83,7 +83,9 @@ class ModelAPI_Feature : public ModelAPI_Object /// removes the result from the feature MODELAPI_EXPORT void removeResult(const std::shared_ptr& theResult); /// removes all results starting from the gived index (zero-based) - MODELAPI_EXPORT void removeResults(const int theSinceIndex); + /// \param theSinceIndex - index of the deleted result and all after also will be deleted + /// \param theFlush - if it is false, REDISPLAY message is not flushed + MODELAPI_EXPORT void removeResults(const int theSinceIndex, const bool theFlush = true); /// removes all results from the feature MODELAPI_EXPORT void eraseResults(); /// removes all fields from this feature: results, data, etc diff --git a/src/ModelAPI/ModelAPI_Result.cpp b/src/ModelAPI/ModelAPI_Result.cpp index c16732d99..1816c54d9 100644 --- a/src/ModelAPI/ModelAPI_Result.cpp +++ b/src/ModelAPI/ModelAPI_Result.cpp @@ -27,10 +27,10 @@ bool ModelAPI_Result::setDisabled(std::shared_ptr theThis, cons aECreator->sendDeleted(document(), groupName()); } else { // un-disabled equals to created static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED); - aECreator->sendUpdated(theThis, anEvent, false); // do not group: creation must be immediate + aECreator->sendUpdated(theThis, anEvent /*, false*/); // flush is in setCurrentFeature } static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); - aECreator->sendUpdated(theThis, EVENT_DISP, false); + aECreator->sendUpdated(theThis, EVENT_DISP/*, false*/); // flush is in setCurrentFeature return true; } return false;