X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModel%2FModel_Update.cpp;h=d3cc6c9c166782b76a9148ccd46bfdf7cbab6740;hb=refs%2Ftags%2FV_1.2.1;hp=6a2d435ff2ebad9f7e9da7e0d3888c16b4be39b2;hpb=96e85a57787c129a73586c195661284e01beb81a;p=modules%2Fshaper.git diff --git a/src/Model/Model_Update.cpp b/src/Model/Model_Update.cpp index 6a2d435ff..d3cc6c9c1 100644 --- a/src/Model/Model_Update.cpp +++ b/src/Model/Model_Update.cpp @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include #include #include @@ -56,6 +58,7 @@ Model_Update::Model_Update() Config_Prop::Boolean, "false"); myIsAutomatic = Config_PropManager::findProp("Model update", "automatic_rebuild")->value() == "true"; + myIsParamUpdated = false; } void Model_Update::processEvent(const std::shared_ptr& theMessage) @@ -91,6 +94,9 @@ void Model_Update::processEvent(const std::shared_ptr& theMessag if (!std::dynamic_pointer_cast(*anObjIter).get()) { isOnlyResults = false; } + if ((*anObjIter)->groupName() == ModelAPI_ResultParameter::group()) { + myIsParamUpdated = true; + } // created objects are always must be up to date (python box feature) // and updated not in internal uptation chain if (theMessage->eventID() == kCreatedEvent) { @@ -134,6 +140,7 @@ void Model_Update::processEvent(const std::shared_ptr& theMessag } myJustCreated.clear(); myJustUpdated.clear(); + myIsParamUpdated = false; } } @@ -145,7 +152,7 @@ void Model_Update::processOperation(const bool theTotalUpdate, const bool theFin for(aFIter = myJustCreated.begin(); aFIter != myJustCreated.end(); aFIter++) { FeaturePtr aF = std::dynamic_pointer_cast(*aFIter); - if (aF && aF->data().get() && aF->getKind() == "Extrusion") { + if (aF && aF->data()->isValid() && aF->getKind() == "Extrusion") { AttributeSelectionListPtr aBase = aF->selectionList("base"); if (aBase.get()) { for(int a = aBase->size() - 1; a >= 0; a--) { @@ -189,6 +196,8 @@ void Model_Update::updateInDoc(std::shared_ptr theDoc) if (!anObjs) return; FeaturePtr aFeatureIter = anObjs->firstFeature(); for (; aFeatureIter.get(); aFeatureIter = anObjs->nextFeature(aFeatureIter)) { + if (!aFeatureIter->data()->isValid()) // this may be on close of the document + continue; if (aFeatureIter && alreadyProcessed.find(aFeatureIter) == alreadyProcessed.end()) { // update selection and parameters attributes first, before sub-features analysis (sketch plane) updateArguments(aFeatureIter); @@ -212,7 +221,7 @@ void Model_Update::updateInDoc(std::shared_ptr theDoc) for (; aRIter != aResults.cend(); aRIter++) { ResultPartPtr aPart = std::dynamic_pointer_cast(*aRIter); if (aPart.get()) { - if (!aPart->isDisabled() && aPart->isActivated()) { + if (!aPart->isDisabled() && aPart->partDoc().get()) { updateInDoc(aPart->partDoc()); } } @@ -263,18 +272,59 @@ void Model_Update::updateArguments(FeaturePtr theFeature) { if (aState == ModelAPI_StateInvalidArgument) // a chance to be corrected aState = ModelAPI_StateMustBeUpdated; // check the parameters state - std::list aDoubles = - theFeature->data()->attributes(ModelAPI_AttributeDouble::typeId()); + // Double + std::list aDoubles = + theFeature->data()->attributes(ModelAPI_AttributeDouble::typeId()); std::list::iterator aDoubleIter = aDoubles.begin(); for(; aDoubleIter != aDoubles.end(); aDoubleIter++) { - AttributeDoublePtr aDouble = + AttributeDoublePtr aDouble = std::dynamic_pointer_cast(*aDoubleIter); if (aDouble.get() && !aDouble->text().empty()) { + if (myIsParamUpdated) { + ModelAPI_AttributeEvalMessage::send(aDouble, this); + } if (aDouble->expressionInvalid()) { aState = ModelAPI_StateInvalidArgument; } } } + // Point + { + std::list anAttributes = + theFeature->data()->attributes(GeomDataAPI_Point::typeId()); + std::list::iterator anIter = anAttributes.begin(); + for(; anIter != anAttributes.end(); anIter++) { + AttributePointPtr aPointAttribute = + std::dynamic_pointer_cast(*anIter); + if (aPointAttribute.get()) { + if (myIsParamUpdated) { + ModelAPI_AttributeEvalMessage::send(aPointAttribute, this); + } + if ((!aPointAttribute->textX().empty() && aPointAttribute->expressionInvalid(0)) || + (!aPointAttribute->textY().empty() && aPointAttribute->expressionInvalid(1)) || + (!aPointAttribute->textZ().empty() && aPointAttribute->expressionInvalid(2))) + aState = ModelAPI_StateInvalidArgument; + } + } + } + // Point2D + { + std::list anAttributes = + theFeature->data()->attributes(GeomDataAPI_Point2D::typeId()); + std::list::iterator anIter = anAttributes.begin(); + for(; anIter != anAttributes.end(); anIter++) { + AttributePoint2DPtr aPoint2DAttribute = + std::dynamic_pointer_cast(*anIter); + if (aPoint2DAttribute.get()) { + if (myIsParamUpdated) { + ModelAPI_AttributeEvalMessage::send(aPoint2DAttribute, this); + } + if ((!aPoint2DAttribute->textX().empty() && aPoint2DAttribute->expressionInvalid(0)) || + (!aPoint2DAttribute->textY().empty() && aPoint2DAttribute->expressionInvalid(1))) + aState = ModelAPI_StateInvalidArgument; + } + } + } //if (aState == ModelAPI_StateDone) {// all referenced objects are ready to be used //std::cout<<"Execute feature "<getKind()<validators(); - if (theFeature->isDisabled() || // nothing to do with disabled feature - theFeature->data()->execState() == ModelAPI_StateInvalidArgument) + if (theFeature->data()->execState() == ModelAPI_StateInvalidArgument) return; bool aJustUpdated = false; @@ -353,8 +402,13 @@ void Model_Update::updateFeature(FeaturePtr theFeature) for(; aRef != aRefs.end(); aRef++) { std::list::iterator aRefObj = aRef->second.begin(); for(; aRefObj != aRef->second.end(); aRefObj++) { - if (myJustCreated.find(*aRefObj) != myJustCreated.end() || - myJustUpdated.find(*aRefObj) != myJustUpdated.end()) { + // if reference is null, it may mean that this reference is to other document + // the does not supported by RefList: peremeters may be recomputed + if (!aRefObj->get() && theFeature->firstResult().get() && + theFeature->firstResult()->groupName() == ModelAPI_ResultParameter::group()) { + aJustUpdated = true; + } else if (myJustCreated.find(*aRefObj) != myJustCreated.end() || + myJustUpdated.find(*aRefObj) != myJustUpdated.end()) { aJustUpdated = true; } aState = stateByReference(*aRefObj, aState); @@ -375,37 +429,45 @@ void Model_Update::updateFeature(FeaturePtr theFeature) //std::cout<<"Update feature "<getKind()<<" must be updated = "<isPreviewNeeded()) { - if (std::dynamic_pointer_cast(theFeature->document())->executeFeatures() || - !theFeature->isPersistentResult()) { - if (aFactory->validate(theFeature)) { - if (myIsAutomatic || !theFeature->isPersistentResult() /* execute quick, not persistent results */ - || (isUpdated(theFeature) && - (theFeature == theFeature->document()->currentFeature(false) || - theFeature->document()->currentFeature(false)->isMacro()))) // currently edited - { - if (aState == ModelAPI_StateDone || aState == ModelAPI_StateMustBeUpdated) { - executeFeature(theFeature); - } - } else { // must be updatet, but not updated yet - theFeature->data()->execState(ModelAPI_StateMustBeUpdated); - const std::list >& aResults = theFeature->results(); - std::list >::const_iterator aRIter = aResults.begin(); - for (; aRIter != aResults.cend(); aRIter++) { - std::shared_ptr aRes = *aRIter; - aRes->data()->execState(ModelAPI_StateMustBeUpdated); + if (theFeature->isDisabled()) { // do not execute the disabled feature + // the disabled features must be updated after enabling anyway if their arguments were changed + if (theFeature->data()->execState() == ModelAPI_StateDone && + aState == ModelAPI_StateMustBeUpdated) + theFeature->data()->execState(ModelAPI_StateMustBeUpdated); + } else { + if (theFeature->isPreviewNeeded()) { + if (std::dynamic_pointer_cast(theFeature->document())->executeFeatures() || + !theFeature->isPersistentResult()) { + if (aFactory->validate(theFeature)) { + FeaturePtr aCurrent = theFeature->document()->currentFeature(false); + if (myIsAutomatic || !theFeature->isPersistentResult() /* execute quick, not persistent results */ + || (isUpdated(theFeature) && + (theFeature == aCurrent || + (aCurrent.get() && aCurrent->isMacro())))) // currently edited + { + if (aState == ModelAPI_StateDone || aState == ModelAPI_StateMustBeUpdated) { + executeFeature(theFeature); + } + } else { // must be updatet, but not updated yet + theFeature->data()->execState(ModelAPI_StateMustBeUpdated); + const std::list >& aResults = theFeature->results(); + std::list >::const_iterator aRIter = aResults.begin(); + for (; aRIter != aResults.cend(); aRIter++) { + std::shared_ptr aRes = *aRIter; + aRes->data()->execState(ModelAPI_StateMustBeUpdated); + } } + } else { + theFeature->eraseResults(); + redisplayWithResults(theFeature, ModelAPI_StateInvalidArgument); // result also must be updated } - } else { - theFeature->eraseResults(); - redisplayWithResults(theFeature, ModelAPI_StateInvalidArgument); // result also must be updated + } else { // for automatically updated features (on abort, etc) it is necessary to redisplay anyway + redisplayWithResults(theFeature, ModelAPI_StateNothing); } - } else { // for automatically updated features (on abort, etc) it is necessary to redisplay anyway - redisplayWithResults(theFeature, ModelAPI_StateNothing); + } else { // preview is not needed => make state Done + if (theFeature->data()->execState() == ModelAPI_StateMustBeUpdated) + theFeature->data()->execState(ModelAPI_StateDone); } - } else { // preview is not needed => make state Done - if (theFeature->data()->execState() == ModelAPI_StateMustBeUpdated) - theFeature->data()->execState(ModelAPI_StateDone); } } }