+ myIsProcessed = false;
+ myIsPreviewBlocked = false;
+ myUpdateBlocked = false;
+}
+
+bool Model_Update::addModified(FeaturePtr theFeature, FeaturePtr theReason) {
+
+ if (!theFeature->data()->isValid())
+ return false; // delete an extrusion created on the sketch
+
+
+ bool isNotExecuted = theFeature->isPersistentResult() &&
+ !std::dynamic_pointer_cast<Model_Document>((theFeature)->document())->executeFeatures();
+ if (isNotExecuted) {
+ redisplayWithResults(theFeature, ModelAPI_StateNothing, false); // redisplay even not executed
+ if (!theReason.get()) // no reason => no construction reason
+ return false;
+ if (myNotPersistentRefs.find(theFeature) == myNotPersistentRefs.end()) {
+ myNotPersistentRefs[theFeature].insert(theReason);
+ } else {
+ std::set<std::shared_ptr<ModelAPI_Feature> > aNewSet;
+ aNewSet.insert(theReason);
+ myNotPersistentRefs[theFeature] = aNewSet;
+ }
+ return false;
+ }
+
+ // update arguments for "apply button" state change
+ if ((!theFeature->isPreviewNeeded() && !myIsFinish) || myIsPreviewBlocked) {
+ if (theReason.get())
+ myProcessOnFinish[theFeature].insert(theReason);
+ else if (myProcessOnFinish.find(theFeature) == myProcessOnFinish.end())
+ myProcessOnFinish[theFeature] = std::set<std::shared_ptr<ModelAPI_Feature> >();
+#ifdef DEB_UPDATE
+ std::cout<<"*** Add process on finish "<<theFeature->name()<<std::endl;
+#endif
+ // keeps the currently updated features to avoid infinitive cycling here: where feature on
+ // "updateArguments" sends "updated" (in selection attribute) and goes here again
+ static std::set<FeaturePtr> aCurrentlyUpdated;
+ if (aCurrentlyUpdated.find(theFeature) == aCurrentlyUpdated.end()) {
+ aCurrentlyUpdated.insert(theFeature);
+ updateArguments(theFeature);
+ aCurrentlyUpdated.erase(theFeature);
+ }
+ // make it without conditions otherwise the apply button may have a bad state
+ theFeature->data()->execState(ModelAPI_StateDone);
+ static ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators();
+ // need to be validated to update the "Apply" state if not previewed
+ aFactory->validate(theFeature);
+
+ // to redisplay split's arguments presentation, even result is not computed
+ if (!theFeature->isPreviewNeeded()) {
+ static Events_Loop* aLoop = Events_Loop::loop();
+ static const Events_ID kRedisplayEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+ ModelAPI_EventCreator::get()->sendUpdated(theFeature, kRedisplayEvent);
+ aLoop->flush(kRedisplayEvent);
+ }
+
+ if (!myIsPreviewBlocked)
+ return true;
+ }
+ if (myModified.find(theFeature) != myModified.end()) {
+ if (theReason.get()) {
+#ifdef DEB_UPDATE
+ //std::cout<<"*** Add already modified "
+ // <<theFeature->name()<<" reason "<<theReason->name()<<std::endl;
+#endif
+ myModified[theFeature].insert(theReason);
+ }
+ return true;
+ }
+ // do not add the disabled, but possibly the sub-elements are not disabled
+ bool aIsDisabled = theFeature->isDisabled();
+ if (!aIsDisabled) {
+ std::set<std::shared_ptr<ModelAPI_Feature> > aNewSet;
+ if (theFeature->data()->execState() == ModelAPI_StateMustBeUpdated ||
+ theFeature->data()->execState() == ModelAPI_StateInvalidArgument || // issue 1519
+ theFeature->data()->execState() == ModelAPI_StateExecFailed) {
+ // do not forget that in this case all were the reasons
+ aNewSet.insert(theFeature);
+ } else {
+ if (theReason.get())
+ aNewSet.insert(theReason);
+ }
+ myModified[theFeature] = aNewSet;
+#ifdef DEB_UPDATE
+ if (theReason.get()) {
+ //std::cout<<"*** Add modified "<<theFeature->name()
+ // <<" reason "<<theReason->name()<<std::endl;
+ } else {
+ //std::cout<<"*** Add modified "<<theFeature->name()<<std::endl;
+ }
+#endif
+ } else { // will be updated during the finish of the operation, or when it becomes enabled
+ if (theFeature->data()->execState() == ModelAPI_StateDone ||
+ theFeature->data()->execState() == ModelAPI_StateExecFailed) // fix issue 1819
+ theFeature->data()->execState(ModelAPI_StateMustBeUpdated);
+ else
+ return true; // do not need iteration deeply if it is already marked as modified or so
+#ifdef DEB_UPDATE
+ //std::cout<<"*** Set modified state "<<theFeature->name()<<std::endl;
+#endif
+ }
+ // clear processed and fill modified recursively
+ const std::set<std::shared_ptr<ModelAPI_Attribute> >& aRefs = theFeature->data()->refsToMe();
+ std::set<std::shared_ptr<ModelAPI_Attribute> >::const_iterator aRefIter = aRefs.cbegin();
+ for(; aRefIter != aRefs.cend(); aRefIter++) {
+ if ((*aRefIter)->isArgument()) {
+ FeaturePtr aReferenced = std::dynamic_pointer_cast<ModelAPI_Feature>((*aRefIter)->owner());
+ if (aReferenced.get()) {
+ addModified(aReferenced, theFeature);
+ }
+ }
+ }
+ // process also results
+ std::list<ResultPtr> allResults; // list of this feature and results
+ ModelAPI_Tools::allResults(theFeature, allResults);
+ std::list<ResultPtr>::iterator aRes = allResults.begin();
+ for(; aRes != allResults.end(); aRes++) {
+ const std::set<std::shared_ptr<ModelAPI_Attribute> >& aRefs = (*aRes)->data()->refsToMe();
+ std::set<std::shared_ptr<ModelAPI_Attribute> >::const_iterator aRefIter = aRefs.cbegin();
+ for(; aRefIter != aRefs.cend(); aRefIter++) {
+ if ((*aRefIter)->isArgument()) {
+ FeaturePtr aReferenced = std::dynamic_pointer_cast<ModelAPI_Feature>((*aRefIter)->owner());
+ if (aReferenced.get()) {
+ addModified(aReferenced, theFeature);
+ }
+ }
+ }
+ }
+
+ // also add part feature that contains this feature to the modified
+ if (theFeature->document()->kind() != "PartSet") {
+ FeaturePtr aPart = ModelAPI_Tools::findPartFeature(
+ ModelAPI_Session::get()->moduleDocument(), theFeature->document());
+ if (aPart.get())
+ addModified(aPart, theFeature);
+ }
+ return true;