From fa16bd63a969591127eea4d3959ca738d56d2e0f Mon Sep 17 00:00:00 2001 From: mpv Date: Mon, 21 Nov 2016 15:41:18 +0300 Subject: [PATCH] Issue #1786 : make Recover feature duplicate the result, not re-create a previous one. So, this duplicate has no reference to the history of the concealed object. --- src/FeaturesAPI/FeaturesAPI_Recover.cpp | 12 +- src/FeaturesAPI/FeaturesAPI_Recover.h | 10 +- src/FeaturesPlugin/FeaturesPlugin_Recover.cpp | 130 ++++++------------ src/FeaturesPlugin/FeaturesPlugin_Recover.h | 27 ---- src/FeaturesPlugin/Test/TestRecover.py | 13 +- src/FeaturesPlugin/recover_widget.xml | 1 - src/Model/Model_Data.cpp | 9 +- src/Model/Model_Validator.cpp | 48 ------- src/Model/Model_Validator.h | 17 --- src/ModelAPI/ModelAPI_Validator.h | 13 -- 10 files changed, 50 insertions(+), 230 deletions(-) diff --git a/src/FeaturesAPI/FeaturesAPI_Recover.cpp b/src/FeaturesAPI/FeaturesAPI_Recover.cpp index 7f86b7a57..40637b30b 100644 --- a/src/FeaturesAPI/FeaturesAPI_Recover.cpp +++ b/src/FeaturesAPI/FeaturesAPI_Recover.cpp @@ -26,7 +26,6 @@ FeaturesAPI_Recover::FeaturesAPI_Recover(const std::shared_ptr if(initialize()) { setBaseFeature(theBaseFeature); setRecoveredList(theRecoveredList); - setIsPersistent(thePersistent); } } @@ -49,13 +48,6 @@ void FeaturesAPI_Recover::setRecoveredList(const std::listreference(FeaturesPlugin_Recover::BASE_FEATURE()); AttributeRefListPtr anAttrRecoveredEntities = aBase->reflist(FeaturesPlugin_Recover::RECOVERED_ENTITIES()); - AttributeBooleanPtr anAttrPersistent = aBase->boolean(FeaturesPlugin_Recover::PERSISTENT()); FeaturePtr aFeature = ModelAPI_Feature::feature(anAttrBaseFeature->value()); theDumper << aBase << " = model.addRecover(" << aDocName << ", " - << aFeature << ", " << anAttrRecoveredEntities << ", " - << anAttrPersistent << ")" << std::endl; + << aFeature << ", " << anAttrRecoveredEntities << ")" << std::endl; } //================================================================================================= diff --git a/src/FeaturesAPI/FeaturesAPI_Recover.h b/src/FeaturesAPI/FeaturesAPI_Recover.h index 2263ae84f..90af8140d 100644 --- a/src/FeaturesAPI/FeaturesAPI_Recover.h +++ b/src/FeaturesAPI/FeaturesAPI_Recover.h @@ -38,13 +38,11 @@ public: FEATURESAPI_EXPORT virtual ~FeaturesAPI_Recover(); - INTERFACE_3(FeaturesPlugin_Recover::ID(), + INTERFACE_2(FeaturesPlugin_Recover::ID(), baseFeature, FeaturesPlugin_Recover::BASE_FEATURE(), ModelAPI_AttributeReference, /** Concealed feature */, recoveredList, FeaturesPlugin_Recover::RECOVERED_ENTITIES(), - ModelAPI_AttributeRefList, /** Recover list*/, - isPersistent, FeaturesPlugin_Recover::PERSISTENT(), - ModelAPI_AttributeBoolean, /** Is persistent flag */) + ModelAPI_AttributeRefList, /** Recover list*/) /// Set base feature. FEATURESAPI_EXPORT @@ -54,10 +52,6 @@ public: FEATURESAPI_EXPORT void setRecoveredList(const std::list& theRecoverList); - /// Set auxiliary - FEATURESAPI_EXPORT - void setIsPersistent(bool thePersistent); - /// Dump wrapped feature FEATURESAPI_EXPORT virtual void dump(ModelHighAPI_Dumper& theDumper) const; diff --git a/src/FeaturesPlugin/FeaturesPlugin_Recover.cpp b/src/FeaturesPlugin/FeaturesPlugin_Recover.cpp index e521c3a29..4bbfd76e8 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Recover.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Recover.cpp @@ -15,6 +15,7 @@ #include #include #include +#include FeaturesPlugin_Recover::FeaturesPlugin_Recover() { @@ -24,105 +25,54 @@ void FeaturesPlugin_Recover::initAttributes() { data()->addAttribute(BASE_FEATURE(), ModelAPI_AttributeReference::typeId()); data()->addAttribute(RECOVERED_ENTITIES(), ModelAPI_AttributeRefList::typeId()); - data()->addAttribute(PERSISTENT(), ModelAPI_AttributeBoolean::typeId()); - myPersistent = boolean(PERSISTENT())->value(); - 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 || myCurrentBase != aBase) - clearRegistered(); + int aResultIndex = 0; + AttributeRefListPtr aRecovered = reflist(RECOVERED_ENTITIES()); + for(int anIndex = aRecovered->size() - 1; anIndex >= 0; anIndex--) { + ObjectPtr anObj = aRecovered->object(anIndex); + if (!anObj.get()) + continue; + ResultPtr aResult = std::dynamic_pointer_cast(anObj); + if (!aResult.get()) + continue; + GeomShapePtr aShape = aResult->shape(); + if (!aShape.get()) + continue; - 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); - if (aRes.get()) { // this may be on first update after "open" - ModelAPI_Session::get()->validators()->registerUnconcealment( - aRes, aNewPersistent ? FeaturePtr() : aBase); - myRegistered.insert(anObj); - } - } + // Copy shape. + GeomAlgoAPI_Copy aCopyAlgo(aShape); + // Check that algo is done. + if(!aCopyAlgo.isDone()) { + setError("Error: recover algorithm failed."); + return; } - } - // 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++; + // Check if shape is not null. + if(!aCopyAlgo.shape().get() || aCopyAlgo.shape()->isNull()) { + setError("Error: resulting shape is null."); + return; + } + // Check that resulting shape is valid. + if(!aCopyAlgo.isValid()) { + setError("Error: resulting shape is not valid."); + return; } - } - 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; -} + // Store result. + ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); + aResultBody->store(aCopyAlgo.shape());//, aCopyAlgo.shape()); + std::shared_ptr aSubShapes = aCopyAlgo.mapOfSubShapes(); + // like in import: forget any history + int aTag(1); + std::string aNameMS = "Shape"; + aResultBody->loadFirstLevel(aCopyAlgo.shape(), aNameMS, aTag); -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); + setResult(aResultBody, aResultIndex); + ++aResultIndex; } - myRegistered.clear(); + + removeResults(aResultIndex); } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Recover.h b/src/FeaturesPlugin/FeaturesPlugin_Recover.h index 9016ddbd8..438ee950e 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Recover.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Recover.h @@ -46,13 +46,6 @@ class FeaturesPlugin_Recover : public ModelAPI_Feature return MY_RECOVERED_ENTITIES_ID; } - /// Attribute name of persistenc concealment flag. - inline static const std::string& PERSISTENT() - { - static const std::string MY_PERSISTENT_ID("persistent"); - return MY_PERSISTENT_ID; - } - /// Returns the kind of a feature FEATURESPLUGIN_EXPORT virtual const std::string& getKind() { @@ -69,26 +62,6 @@ class FeaturesPlugin_Recover : public ModelAPI_Feature /// Use plugin manager for features creation FeaturesPlugin_Recover(); - /// Called on change of any argument-attribute of this object. Needed here for synchronization - /// of registered unconcealed. - virtual void attributeChanged(const std::string& theID); - - /// Synchronises myRegistered before all attributes are erased - virtual void erase(); - - /// on unstability of feature, remove all unconcealment effect - virtual bool setStable(const bool theFlag); - /// on disable of feature, remove all unconcealment effect - virtual bool setDisabled(const bool theFlag); -private: - /// Synchronises registration of unconcealed entities with the attributes values of this feature - void synchronizeRegistered(); - - /// Returns the base feature of this - FeaturePtr baseFeature(); - - /// erases all registered cashed values - void clearRegistered(); }; #endif diff --git a/src/FeaturesPlugin/Test/TestRecover.py b/src/FeaturesPlugin/Test/TestRecover.py index 1a2765bc9..d591a56d6 100644 --- a/src/FeaturesPlugin/Test/TestRecover.py +++ b/src/FeaturesPlugin/Test/TestRecover.py @@ -45,9 +45,12 @@ assert(mypart.size("Bodies") == 1) # check persistent flag of recover: never concealed model.begin() +recover = model.addRecover(mypart, cut, smallcyl.results()) +model.end() -recover = model.addRecover(mypart, cut, smallcyl.results(), True) assert(mypart.size("Bodies") == 2) + +model.begin() sk3 = model.addSketch(mypart, model.defaultPlane("XOY")) c3 = sk3.addCircle(0, 0, 90) model.do() @@ -60,12 +63,4 @@ model.end() # two booleans and small cylinder assert(mypart.size("Bodies") == 3) - -# make the flag as not-persistent => cylinder must be disappeared -model.begin() -recover.setIsPersistent(False) -model.end() -# only two booleans -assert(mypart.size("Bodies") == 2) - assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/recover_widget.xml b/src/FeaturesPlugin/recover_widget.xml index b2c6e8091..f8b9a7fc2 100644 --- a/src/FeaturesPlugin/recover_widget.xml +++ b/src/FeaturesPlugin/recover_widget.xml @@ -9,5 +9,4 @@ - diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index 4cfc34a59..c60d07cd3 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -462,8 +462,7 @@ void Model_Data::addBackReference(FeaturePtr theFeature, std::string theAttrID, // the second condition is for history upper than concealment causer, so the feature result may // be displayed and previewed; also for avoiding of quick show/hide on history // moving deep down - if (aRes && !theFeature->isDisabled() && - !ModelAPI_Session::get()->validators()->isUnconcealed(aRes, theFeature)) { + if (aRes && !theFeature->isDisabled()) { aRes->setIsConcealed(true); } } @@ -481,10 +480,8 @@ void Model_Data::updateConcealmentFlag() std::shared_ptr aRes = std::dynamic_pointer_cast(myObject); if (aRes.get()) { - if (!ModelAPI_Session::get()->validators()->isUnconcealed(aRes, aFeature)) { - aRes->setIsConcealed(true); // set concealed - return; - } + aRes->setIsConcealed(true); // set concealed + return; } } } diff --git a/src/Model/Model_Validator.cpp b/src/Model/Model_Validator.cpp index 0b7a6ea3a..d34681a13 100644 --- a/src/Model/Model_Validator.cpp +++ b/src/Model/Model_Validator.cpp @@ -317,54 +317,6 @@ bool Model_ValidatorsFactory::isConcealed(std::string theFeature, std::string th return aFind != myConcealed.end() && aFind->second.find(theAttribute) != aFind->second.end(); } -void Model_ValidatorsFactory::registerUnconcealment(std::shared_ptr theUnconcealed, - std::shared_ptr theCanceledFeat) -{ - if (myUnconcealed.find(theUnconcealed) == myUnconcealed.end()) { - myUnconcealed[theUnconcealed] = std::list >(); - } - myUnconcealed[theUnconcealed].push_back(theCanceledFeat); - std::dynamic_pointer_cast(theUnconcealed->data())->updateConcealmentFlag(); -} - -void Model_ValidatorsFactory::disableUnconcealment(std::shared_ptr theUnconcealed, - std::shared_ptr theCanceledFeat) -{ - std::map, std::list > > - ::iterator aResFound = myUnconcealed.find(theUnconcealed); - if (aResFound != myUnconcealed.end()) { - std::list >::iterator anIter = aResFound->second.begin(); - for(; anIter != aResFound->second.end(); anIter++) { - if (*anIter == theCanceledFeat) { - aResFound->second.erase(anIter); - std::dynamic_pointer_cast(theUnconcealed->data())->updateConcealmentFlag(); - break; - } - } - } -} - -bool Model_ValidatorsFactory::isUnconcealed(std::shared_ptr theUnconcealed, - std::shared_ptr theCanceledFeat) -{ - std::map, std::list > > - ::iterator aResFound = myUnconcealed.find(theUnconcealed); - if (aResFound != myUnconcealed.end()) { - std::list >::iterator aFeatIter = aResFound->second.begin(); - for(; aFeatIter != aResFound->second.end(); aFeatIter++) { - if (aFeatIter->get()) { - if ((*aFeatIter)->isDisabled()) continue; - if (*aFeatIter == theCanceledFeat) - return true; // this is exactly canceled - if (theCanceledFeat->document()->isLater(*aFeatIter, theCanceledFeat)) - return true; // if unconcealed feature (from the list) is later than concealed - } else - return true; // empty attribute means that everything is canceled - } - } - return false; -} - void Model_ValidatorsFactory::registerCase(std::string theFeature, std::string theAttribute, const std::list >& theCases) { diff --git a/src/Model/Model_Validator.h b/src/Model/Model_Validator.h index 5ac63fd1b..72a493168 100644 --- a/src/Model/Model_Validator.h +++ b/src/Model/Model_Validator.h @@ -37,10 +37,6 @@ class Model_ValidatorsFactory : public ModelAPI_ValidatorsFactory /// Stores the registered attributes that leads to the concealment of referenced objects in /// data tree. Map from feature kind to set of attribute IDs. std::map > myConcealed; - /// Stored the unconcealed results and features that caused the canceled concealment (Recover). - /// If the feature is empty, unconcealment is persistent. - std::map, std::list > > - myUnconcealed; /// Stores the registered attributes must be checked only if the particular case is activated /// Map from feature kind to map of attribute IDs to pair // (switchId (ID of the attribute) and case Ids (possible values of the switch attribute)) @@ -98,19 +94,6 @@ class Model_ValidatorsFactory : public ModelAPI_ValidatorsFactory /// Returns true that it was registered that attribute conceals the referenced result virtual bool isConcealed(std::string theFeature, std::string theAttribute); - /// Registers (by Recover feature) cancel of concealment of specific result by specific feature. - /// If theCanceledFeat is empty, the concealment is canceled for this result forever. - virtual void registerUnconcealment(std::shared_ptr theUnconcealed, - std::shared_ptr theCanceledFeat); - - /// Disables cancel of concealment of specific result by specific feature. - virtual void disableUnconcealment(std::shared_ptr theUnconcealed, - std::shared_ptr theCanceledFeat); - - /// Returns true if concealment is canceled. - virtual bool isUnconcealed(std::shared_ptr theUnconcealed, - std::shared_ptr theCanceledFeat); - /// register the case-attribute (\a myCases set definition) virtual void registerCase(std::string theFeature, std::string theAttribute, const std::list >& theCases); diff --git a/src/ModelAPI/ModelAPI_Validator.h b/src/ModelAPI/ModelAPI_Validator.h index c621363d5..0557333ba 100644 --- a/src/ModelAPI/ModelAPI_Validator.h +++ b/src/ModelAPI/ModelAPI_Validator.h @@ -101,19 +101,6 @@ class MODELAPI_EXPORT ModelAPI_ValidatorsFactory /// Returns true that it was registered that attribute conceals the referenced result virtual bool isConcealed(std::string theFeature, std::string theAttribute) = 0; - /// Registers (by Recover feature) cancel of concealment of specific result by specific feature. - /// If theCanceledFeat is empty, the concealment is canceled for this result forever. - virtual void registerUnconcealment(std::shared_ptr theUnconcealed, - std::shared_ptr theCanceledFeat) = 0; - - /// Disables cancel of concealment of specific result by specific feature. - virtual void disableUnconcealment(std::shared_ptr theUnconcealed, - std::shared_ptr theCanceledFeat) = 0; - - /// Returns true if concealment is canceled. - virtual bool isUnconcealed(std::shared_ptr theUnconcealed, - std::shared_ptr theCanceledFeat) = 0; - /// Register the case-attribute: this attribute is checked only if its case is selected virtual void registerCase(std::string theFeature, std::string theAttribute, const std::list >& theCases) = 0; -- 2.39.2