X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FFeaturesPlugin%2FFeaturesPlugin_Recover.cpp;h=5bdff264fcb0f19c7ac866d3bea76509edbecc81;hb=919584a7e5ee83c384873c2627b9865e8ba02272;hp=5eb5aa84e27911e9e68b7d56a398197c2134dd36;hpb=95b5b61c8b3e0ab0de64955952894cd32bc49e06;p=modules%2Fshaper.git diff --git a/src/FeaturesPlugin/FeaturesPlugin_Recover.cpp b/src/FeaturesPlugin/FeaturesPlugin_Recover.cpp index 5eb5aa84e..5bdff264f 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Recover.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Recover.cpp @@ -10,8 +10,11 @@ #include #include #include +#include #include #include +#include +#include using namespace std; @@ -21,13 +24,108 @@ FeaturesPlugin_Recover::FeaturesPlugin_Recover() void FeaturesPlugin_Recover::initAttributes() { - data()->addAttribute(BASE_SHAPE_ID(), ModelAPI_AttributeReference::typeId()); + data()->addAttribute(BASE_FEATURE(), ModelAPI_AttributeReference::typeId()); data()->addAttribute(RECOVERED_ENTITIES(), ModelAPI_AttributeRefList::typeId()); + data()->addAttribute(PERSISTENT(), ModelAPI_AttributeBoolean::typeId()); - /// temporary modification for empty list - ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), RECOVERED_ENTITIES()); + myPersistent = boolean(PERSISTENT())->value(); + // temporary modification for empty list + // ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), RECOVERED_ENTITIES()); + + synchronizeRegistered(); } void FeaturesPlugin_Recover::execute() { + synchronizeRegistered(); +} + +void FeaturesPlugin_Recover::attributeChanged(const std::string& theID) +{ + synchronizeRegistered(); +} + +void FeaturesPlugin_Recover::synchronizeRegistered() +{ + FeaturePtr aBase = baseFeature(); + bool aNewPersistent = boolean(PERSISTENT())->value(); + if (aNewPersistent != myPersistent) + clearRegistered(); + + std::set aRecoveredInList; + // add unconcealed which are not in the myRegistered map + if (isStable() && !isDisabled()) { // if unstable, clear any unconcealment effect + AttributeRefListPtr aRecovered = reflist(RECOVERED_ENTITIES()); + for(int anIndex = aRecovered->size() - 1; anIndex >= 0; anIndex--) { + ObjectPtr anObj = aRecovered->object(anIndex); + aRecoveredInList.insert(anObj); + if (myRegistered.find(anObj) == myRegistered.end()) { + // not found, so register a new + ResultPtr aRes = std::dynamic_pointer_cast(anObj); + ModelAPI_Session::get()->validators()->registerUnconcealment( + aRes, aNewPersistent ? FeaturePtr() : aBase); + myRegistered.insert(anObj); + } + } + } + // remove unconcealed which are not in the stored list, but in the map + std::set >::iterator aMyReg = myRegistered.begin(); + while(aMyReg != myRegistered.end()) { + if (aRecoveredInList.find(*aMyReg) == aRecoveredInList.end()) { + ResultPtr aRes = std::dynamic_pointer_cast(*aMyReg); + ModelAPI_Session::get()->validators()->disableUnconcealment( + aRes, aNewPersistent ? FeaturePtr() : myCurrentBase); + myRegistered.erase(aMyReg); + aMyReg = myRegistered.begin(); // restart iteration because after erase iterator may be bad + } else { + aMyReg++; + } + } + myCurrentBase = aBase; + myPersistent = aNewPersistent; +} + +void FeaturesPlugin_Recover::erase() +{ + // clears myRegistered before all information is destroyed + clearRegistered(); + ModelAPI_Feature::erase(); +} + +bool FeaturesPlugin_Recover::setStable(const bool theFlag) +{ + bool aRes = ModelAPI_Feature::setStable(theFlag); + synchronizeRegistered(); + return aRes; +} + +bool FeaturesPlugin_Recover::setDisabled(const bool theFlag) +{ + bool aRes = ModelAPI_Feature::setDisabled(theFlag); + synchronizeRegistered(); + return aRes; +} + +FeaturePtr FeaturesPlugin_Recover::baseFeature() +{ + // for the current moment it can be result of feature of feature: GUI is not debugged + ObjectPtr aBaseObj = reference(BASE_FEATURE())->value(); + FeaturePtr aResult; + if (aBaseObj.get() == NULL) + return aResult; + aResult = std::dynamic_pointer_cast(aBaseObj); + if (aResult.get() == NULL) + aResult = aBaseObj->document()->feature(std::dynamic_pointer_cast(aBaseObj)); + return aResult; +} + +void FeaturesPlugin_Recover::clearRegistered() +{ + std::set >::iterator aMyReg = myRegistered.begin(); + for(; aMyReg != myRegistered.end(); aMyReg++) { + ResultPtr aRes = std::dynamic_pointer_cast(*aMyReg); + ModelAPI_Session::get()->validators()->disableUnconcealment( + aRes, myPersistent ? FeaturePtr() : myCurrentBase); + } + myRegistered.clear(); }