#include <ModelAPI_CompositeFeature.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Tools.h>
+#include <GeomDataAPI_Point.h>
+#include <GeomDataAPI_Point2D.h>
#include <Events_Loop.h>
#include <Events_LongOp.h>
#include <Events_Error.h>
Config_Prop::Boolean, "false");
myIsAutomatic =
Config_PropManager::findProp("Model update", "automatic_rebuild")->value() == "true";
+ myIsParamUpdated = false;
}
void Model_Update::processEvent(const std::shared_ptr<Events_Message>& theMessage)
if (!std::dynamic_pointer_cast<ModelAPI_Result>(*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) {
isOperationChanged = true;
}
if (isOperationChanged) {
- // remove all macros before clearing all created
+ // remove all macros before clearing all created and execute all not-previewed
std::set<ObjectPtr>::iterator aCreatedIter = myJustCreated.begin();
- for(; aCreatedIter != myJustCreated.end(); aCreatedIter++) {
- FeaturePtr aFeature =
- std::dynamic_pointer_cast<ModelAPI_Feature>(*aCreatedIter);
+ std::set<ObjectPtr>::iterator anUpdatedIter = myJustUpdated.begin();
+ for(; aCreatedIter != myJustCreated.end() || anUpdatedIter != myJustUpdated.end();
+ aCreatedIter == myJustCreated.end() ? anUpdatedIter++ : aCreatedIter++) {
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*
+ (aCreatedIter == myJustCreated.end() ? anUpdatedIter : aCreatedIter));
if (aFeature.get()) {
// execute not-previewed feature on "apply"
if (!aFeature->isPreviewNeeded() && (myJustCreated.find(aFeature) != myJustCreated.end() ||
}
myJustCreated.clear();
myJustUpdated.clear();
+ myIsParamUpdated = false;
}
}
for(aFIter = myJustCreated.begin(); aFIter != myJustCreated.end(); aFIter++)
{
FeaturePtr aF = std::dynamic_pointer_cast<ModelAPI_Feature>(*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--) {
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);
for (; aRIter != aResults.cend(); aRIter++) {
ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aRIter);
if (aPart.get()) {
- if (!aPart->isDisabled() && aPart->isActivated()) {
+ if (!aPart->isDisabled() && aPart->partDoc().get()) {
updateInDoc(aPart->partDoc());
}
}
if (aState == ModelAPI_StateInvalidArgument) // a chance to be corrected
aState = ModelAPI_StateMustBeUpdated;
// check the parameters state
- std::list<AttributePtr> aDoubles =
- theFeature->data()->attributes(ModelAPI_AttributeDouble::typeId());
+ // Double
+ std::list<AttributePtr> aDoubles =
+ theFeature->data()->attributes(ModelAPI_AttributeDouble::typeId());
std::list<AttributePtr>::iterator aDoubleIter = aDoubles.begin();
for(; aDoubleIter != aDoubles.end(); aDoubleIter++) {
- AttributeDoublePtr aDouble =
+ AttributeDoublePtr aDouble =
std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(*aDoubleIter);
- if (aDouble.get() && aDouble->expressionInvalid()) {
- aState = ModelAPI_StateInvalidArgument;
+ if (aDouble.get() && !aDouble->text().empty()) {
+ if (myIsParamUpdated) {
+ ModelAPI_AttributeEvalMessage::send(aDouble, this);
+ }
+ if (aDouble->expressionInvalid()) {
+ aState = ModelAPI_StateInvalidArgument;
+ }
+ }
+ }
+ // Point
+ {
+ std::list<AttributePtr> anAttributes =
+ theFeature->data()->attributes(GeomDataAPI_Point::typeId());
+ std::list<AttributePtr>::iterator anIter = anAttributes.begin();
+ for(; anIter != anAttributes.end(); anIter++) {
+ AttributePointPtr aPointAttribute =
+ std::dynamic_pointer_cast<GeomDataAPI_Point>(*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<AttributePtr> anAttributes =
+ theFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
+ std::list<AttributePtr>::iterator anIter = anAttributes.begin();
+ for(; anIter != anAttributes.end(); anIter++) {
+ AttributePoint2DPtr aPoint2DAttribute =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*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;
+ }
}
}
// check all features this feature depended on (recursive call of updateFeature)
static ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->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;
for(; aRef != aRefs.end(); aRef++) {
std::list<ObjectPtr>::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);
//std::cout<<"Update feature "<<theFeature->getKind()<<" must be updated = "<<aMustbeUpdated<<std::endl;
// execute feature if it must be updated
if (aJustUpdated) {
- if ((std::dynamic_pointer_cast<Model_Document>(theFeature->document())->executeFeatures() ||
- !theFeature->isPersistentResult()) && theFeature->isPreviewNeeded()) {
- if (aFactory->validate(theFeature)) {
- if (myIsAutomatic || !theFeature->isPersistentResult() /* execute quick, not persistent results */
- || (isUpdated(theFeature) &&
- theFeature == theFeature->document()->currentFeature(false))) // 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<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);
+ 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<Model_Document>(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<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);
+ }
+ }
+ } 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 {
- theFeature->eraseResults();
- redisplayWithResults(theFeature, ModelAPI_StateInvalidArgument); // result also must be updated
+ } else { // preview is not needed => make state Done
+ if (theFeature->data()->execState() == ModelAPI_StateMustBeUpdated)
+ theFeature->data()->execState(ModelAPI_StateDone);
}
- } else { // for automatically updated features (on abort, etc) it is necessary to redisplay anyway
- redisplayWithResults(theFeature, ModelAPI_StateNothing);
}
}
}