-
- //std::cout<<"Update feature "<<theFeature->getKind()<<" must be updated = "<<aMustbeUpdated<<std::endl;
- // execute feature if it must be updated
- if (aMustbeUpdated) {
- if (std::dynamic_pointer_cast<Model_Document>(theFeature->document())->executeFeatures() ||
- !theFeature->isPersistentResult()) {
- if (aFactory->validate(theFeature)) {
- if (myIsAutomatic ||
- (myJustCreatedOrUpdated.find(theFeature) != myJustCreatedOrUpdated.end()) ||
- !theFeature->isPersistentResult() /* execute quick, not persistent results */)
- {
- if (aState == ModelAPI_StateDone) {// all referenced objects are ready to be used
- //std::cout<<"Execute feature "<<theFeature->getKind()<<std::endl;
- // before execution update the selection attributes if any
- list<AttributePtr> aRefs =
- theFeature->data()->attributes(ModelAPI_AttributeSelection::typeId());
- list<AttributePtr>::iterator aRefsIter = aRefs.begin();
- for (; aRefsIter != aRefs.end(); aRefsIter++) {
- std::shared_ptr<ModelAPI_AttributeSelection> aSel =
- std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(*aRefsIter);
- if (!aSel->update()) { // this must be done on execution since it may be long operation
- if (!aFactory->isNotObligatory(theFeature->getKind(), theFeature->data()->id(aSel)) &&
- aFactory->isCase(theFeature, theFeature->data()->id(aSel)))
- aState = ModelAPI_StateInvalidArgument;
- }
- }
- aRefs = theFeature->data()->attributes(ModelAPI_AttributeSelectionList::typeId());
- for (aRefsIter = aRefs.begin(); aRefsIter != aRefs.end(); aRefsIter++) {
- std::shared_ptr<ModelAPI_AttributeSelectionList> aSel =
- std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(*aRefsIter);
- for(int a = aSel->size() - 1; a >= 0; a--) {
- std::shared_ptr<ModelAPI_AttributeSelection> aSelAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(aSel->value(a));
- if (aSelAttr) {
- if (!aSelAttr->update()) {
- if (!aFactory->isNotObligatory(
- theFeature->getKind(), theFeature->data()->id(aSel)) &&
- aFactory->isCase(theFeature, theFeature->data()->id(aSel)))
- aState = ModelAPI_StateInvalidArgument;
- }
- }
- }
- }
- // for sketch after update of plane (by update of selection attribute)
- // but before execute, all sub-elements also must be updated (due to the plane changes)
- if (aComposite) {
- // number of subs can be changed in execution: like fillet
- for(int a = 0; a < aComposite->numberOfSubs(); a++) {
- FeaturePtr aSub = aComposite->subFeature(a);
- bool aWasModified = myUpdated[aSub];
- myUpdated.erase(myUpdated.find(aSub)); // erase to update for sure (plane may be changed)
- myInitial.insert(aSub);
- updateFeature(aSub);
- myUpdated[aSub] = aWasModified; // restore value
- }
- // re-execute after update: solver may update the previous values, so, shapes must be
- // updated
- for(int a = 0; a < aComposite->numberOfSubs(); a++) {
- if (aComposite->subFeature(a) && aFactory->validate(aComposite->subFeature(a)))
- aComposite->subFeature(a)->execute();
- }
- }
- }
-
- // execute in try-catch to avoid internal problems of the feature
- if (aState == ModelAPI_StateDone) {
- theFeature->data()->execState(ModelAPI_StateDone);
- try {
- theFeature->execute();
- if (theFeature->data()->execState() != ModelAPI_StateDone) {
- aState = ModelAPI_StateExecFailed;
- }
- } catch(...) {
- aState = ModelAPI_StateExecFailed;
- Events_Error::send(
- "Feature " + theFeature->getKind() + " has failed during the execution");
- }
- }
- if (aState != ModelAPI_StateDone) {
- theFeature->eraseResults();
- }
- redisplayWithResults(theFeature, aState);
- } else { // must be updatet, but not updated yet
- theFeature->data()->execState(ModelAPI_StateMustBeUpdated);
- const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = theFeature->results();
- std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
- for (; aRIter != aResults.cend(); aRIter++) {
- std::shared_ptr<ModelAPI_Result> aRes = *aRIter;
- aRes->data()->execState(ModelAPI_StateMustBeUpdated);
- }
+ }
+ // check all references: if referenced objects are updated, this object also must be updated
+ // also check state of referenced objects: if they are not ready, inherit corresponding state
+ std::list<std::pair<std::string, std::list<ObjectPtr> > > aRefsObj;
+ std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(theFeature->data());
+ aData->referencesToObjects(aRefsObj);
+ std::list<std::pair<std::string, std::list<ObjectPtr> > >::iterator aRef = aRefsObj.begin();
+ for(; aRef != aRefsObj.end(); aRef++) {
+ std::list<ObjectPtr>::iterator aRefObj = aRef->second.begin();
+ for(; aRefObj != aRef->second.end(); aRefObj++) {
+ // if reference is null, it may mean that this reference is to other document
+ // the does not supported by RefList: parameters may be recomputed
+ if (!aRefObj->get() && theFeature->firstResult().get() &&
+ theFeature->firstResult()->groupName() == ModelAPI_ResultParameter::group()) {
+ if (aState == ModelAPI_StateDone)
+ aState = ModelAPI_StateMustBeUpdated;
+ } else if (aRefObj->get() && isOlder(theFeature, *aRefObj)) {
+ if (aState == ModelAPI_StateDone)
+ aState = ModelAPI_StateMustBeUpdated;
+ }
+ aState = stateByReference(*aRefObj, aState);
+ }
+ }
+ // composites sub-elements
+ CompositeFeaturePtr aCompos = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theFeature);
+ // composite feature must be executed after sub-features execution
+ if (aCompos) {
+ // number of subs can be changed in execution: like fillet
+ for(int a = 0; a < aCompos->numberOfSubs(); a++) {
+ FeaturePtr aSub = aCompos->subFeature(a);
+ if (aSub.get() && aState == ModelAPI_StateDone) {
+ if (isOlder(theFeature, aSub)) {
+ aState = ModelAPI_StateMustBeUpdated;
+ }
+ // also check that all results of subs were updated: composite also depends on the results
+ const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = aSub->results();
+ std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aResIter = aResults.begin();
+ for(; aResIter != aResults.end(); aResIter++) {
+ if (aResIter->get() && (*aResIter)->data()->isValid() && !(*aResIter)->isDisabled() &&
+ isOlder(theFeature, *aResIter)) {
+ aState = ModelAPI_StateMustBeUpdated;