if(initialize()) {
setBaseFeature(theBaseFeature);
setRecoveredList(theRecoveredList);
- setIsPersistent(thePersistent);
}
}
// do not need to execute because on attribute changed it does everything anyway
}
-//=================================================================================================
-void FeaturesAPI_Recover::setIsPersistent(bool thePersistent)
-{
- fillAttribute(thePersistent, myisPersistent);
- // do not need to execute because on attribute changed it does everything anyway
-}
-
//==================================================================================================
void FeaturesAPI_Recover::dump(ModelHighAPI_Dumper& theDumper) const
{
aBase->reference(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;
}
//=================================================================================================
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
FEATURESAPI_EXPORT
void setRecoveredList(const std::list<ModelHighAPI_Selection>& theRecoverList);
- /// Set auxiliary
- FEATURESAPI_EXPORT
- void setIsPersistent(bool thePersistent);
-
/// Dump wrapped feature
FEATURESAPI_EXPORT
virtual void dump(ModelHighAPI_Dumper& theDumper) const;
#include <ModelAPI_Validator.h>
#include <ModelAPI_Result.h>
#include <ModelAPI_Tools.h>
+#include <GeomAlgoAPI_Copy.h>
FeaturesPlugin_Recover::FeaturesPlugin_Recover()
{
{
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<ModelAPI_Result>(anObj);
+ if (!aResult.get())
+ continue;
+ GeomShapePtr aShape = aResult->shape();
+ if (!aShape.get())
+ continue;
- std::set<ObjectPtr> 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<ModelAPI_Result>(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<std::shared_ptr<ModelAPI_Object> >::iterator aMyReg = myRegistered.begin();
- while(aMyReg != myRegistered.end()) {
- if (aRecoveredInList.find(*aMyReg) == aRecoveredInList.end()) {
- ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(*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<ModelAPI_Feature>(aBaseObj);
- if (aResult.get() == NULL)
- aResult = aBaseObj->document()->feature(std::dynamic_pointer_cast<ModelAPI_Result>(aBaseObj));
- return aResult;
-}
+ // Store result.
+ ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
+ aResultBody->store(aCopyAlgo.shape());//, aCopyAlgo.shape());
+ std::shared_ptr<GeomAPI_DataMapOfShapeShape> 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<std::shared_ptr<ModelAPI_Object> >::iterator aMyReg = myRegistered.begin();
- for(; aMyReg != myRegistered.end(); aMyReg++) {
- ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(*aMyReg);
- ModelAPI_Session::get()->validators()->disableUnconcealment(
- aRes, myPersistent ? FeaturePtr() : myCurrentBase);
+ setResult(aResultBody, aResultIndex);
+ ++aResultIndex;
}
- myRegistered.clear();
+
+ removeResults(aResultIndex);
}
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()
{
/// 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
# 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()
# 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())
<concealed_objects_view id="recovered"\r
tooltip="Concealed results to be recevered"\r
base_shape_attribute="base_feature"/>\r
- <boolvalue id="persistent" label="Persistent" default="false" tooltip="Makes unable to conceal result again" obligatory="0"/>\r
</source>\r
// 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);
}
}
std::shared_ptr<ModelAPI_Result> aRes =
std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
if (aRes.get()) {
- if (!ModelAPI_Session::get()->validators()->isUnconcealed(aRes, aFeature)) {
- aRes->setIsConcealed(true); // set concealed
- return;
- }
+ aRes->setIsConcealed(true); // set concealed
+ return;
}
}
}
return aFind != myConcealed.end() && aFind->second.find(theAttribute) != aFind->second.end();
}
-void Model_ValidatorsFactory::registerUnconcealment(std::shared_ptr<ModelAPI_Result> theUnconcealed,
- std::shared_ptr<ModelAPI_Feature> theCanceledFeat)
-{
- if (myUnconcealed.find(theUnconcealed) == myUnconcealed.end()) {
- myUnconcealed[theUnconcealed] = std::list<std::shared_ptr<ModelAPI_Feature> >();
- }
- myUnconcealed[theUnconcealed].push_back(theCanceledFeat);
- std::dynamic_pointer_cast<Model_Data>(theUnconcealed->data())->updateConcealmentFlag();
-}
-
-void Model_ValidatorsFactory::disableUnconcealment(std::shared_ptr<ModelAPI_Result> theUnconcealed,
- std::shared_ptr<ModelAPI_Feature> theCanceledFeat)
-{
- std::map<std::shared_ptr<ModelAPI_Result>, std::list<std::shared_ptr<ModelAPI_Feature> > >
- ::iterator aResFound = myUnconcealed.find(theUnconcealed);
- if (aResFound != myUnconcealed.end()) {
- std::list<std::shared_ptr<ModelAPI_Feature> >::iterator anIter = aResFound->second.begin();
- for(; anIter != aResFound->second.end(); anIter++) {
- if (*anIter == theCanceledFeat) {
- aResFound->second.erase(anIter);
- std::dynamic_pointer_cast<Model_Data>(theUnconcealed->data())->updateConcealmentFlag();
- break;
- }
- }
- }
-}
-
-bool Model_ValidatorsFactory::isUnconcealed(std::shared_ptr<ModelAPI_Result> theUnconcealed,
- std::shared_ptr<ModelAPI_Feature> theCanceledFeat)
-{
- std::map<std::shared_ptr<ModelAPI_Result>, std::list<std::shared_ptr<ModelAPI_Feature> > >
- ::iterator aResFound = myUnconcealed.find(theUnconcealed);
- if (aResFound != myUnconcealed.end()) {
- std::list<std::shared_ptr<ModelAPI_Feature> >::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<std::pair<std::string, std::string> >& theCases)
{
/// 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<std::string, std::set<std::string> > myConcealed;
- /// Stored the unconcealed results and features that caused the canceled concealment (Recover).
- /// If the feature is empty, unconcealment is persistent.
- std::map<std::shared_ptr<ModelAPI_Result>, std::list<std::shared_ptr<ModelAPI_Feature> > >
- 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))
/// 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<ModelAPI_Result> theUnconcealed,
- std::shared_ptr<ModelAPI_Feature> theCanceledFeat);
-
- /// Disables cancel of concealment of specific result by specific feature.
- virtual void disableUnconcealment(std::shared_ptr<ModelAPI_Result> theUnconcealed,
- std::shared_ptr<ModelAPI_Feature> theCanceledFeat);
-
- /// Returns true if concealment is canceled.
- virtual bool isUnconcealed(std::shared_ptr<ModelAPI_Result> theUnconcealed,
- std::shared_ptr<ModelAPI_Feature> theCanceledFeat);
-
/// register the case-attribute (\a myCases set definition)
virtual void registerCase(std::string theFeature, std::string theAttribute,
const std::list<std::pair<std::string, std::string> >& theCases);
/// 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<ModelAPI_Result> theUnconcealed,
- std::shared_ptr<ModelAPI_Feature> theCanceledFeat) = 0;
-
- /// Disables cancel of concealment of specific result by specific feature.
- virtual void disableUnconcealment(std::shared_ptr<ModelAPI_Result> theUnconcealed,
- std::shared_ptr<ModelAPI_Feature> theCanceledFeat) = 0;
-
- /// Returns true if concealment is canceled.
- virtual bool isUnconcealed(std::shared_ptr<ModelAPI_Result> theUnconcealed,
- std::shared_ptr<ModelAPI_Feature> 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<std::pair<std::string, std::string> >& theCases) = 0;