X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchSolver%2FSketchSolver_ConstraintGroup.cpp;h=954c6c5963fb779fba5116bbe9132eab4e6cba89;hb=d34bc15bf8fafedd9188f47ff5962b5a1661d5b0;hp=d54915677b9f3ceffc9560e94fd574e6e9440145;hpb=33b1651955732ed43b64f9555f2405fb067eaba3;p=modules%2Fshaper.git diff --git a/src/SketchSolver/SketchSolver_ConstraintGroup.cpp b/src/SketchSolver/SketchSolver_ConstraintGroup.cpp index d54915677..954c6c596 100644 --- a/src/SketchSolver/SketchSolver_ConstraintGroup.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintGroup.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include @@ -121,11 +121,12 @@ bool SketchSolver_ConstraintGroup::isInteract( theConstraint->data()->attribute(CONSTRAINT_ATTRIBUTES[i]) ); if (!aCAttrRef) continue; - if (!aCAttrRef->isFeature() && + if (!aCAttrRef->isObject() && myEntityAttrMap.find(aCAttrRef->attr()) != myEntityAttrMap.end()) return true; - if (aCAttrRef->isFeature() && - myEntityFeatMap.find(aCAttrRef->feature()) != myEntityFeatMap.end()) + if (aCAttrRef->isObject() && + myEntityFeatMap.find(boost::dynamic_pointer_cast(aCAttrRef->object())) + != myEntityFeatMap.end()) return true; } @@ -193,14 +194,15 @@ bool SketchSolver_ConstraintGroup::changeConstraint( // For the length constraint the start and end points of the line should be added to the entities list instead of line if (aConstrType == SLVS_C_PT_PT_DISTANCE && theConstraint->getKind().compare(SKETCH_CONSTRAINT_LENGTH_KIND) == 0) { - boost::shared_ptr aData = aConstrAttr->feature()->data(); + boost::shared_ptr aData = aConstrAttr->object()->data(); aConstrEnt[indAttr] = changeEntity(aData->attribute(LINE_ATTR_START)); aConstrEnt[indAttr+1] = changeEntity(aData->attribute(LINE_ATTR_END)); - myEntityFeatMap[aConstrAttr->feature()] = 0; // measured object is added into the map of objects to avoid problems with interaction betwee constraint and group + // measured object is added into the map of objects to avoid problems with interaction betwee constraint and group + myEntityFeatMap[boost::dynamic_pointer_cast(aConstrAttr->object())] = 0; break; // there should be no other entities } - else if (aConstrAttr->isFeature()) - aConstrEnt[indAttr] = changeEntity(aConstrAttr->feature()); + else if (aConstrAttr->isObject()) + aConstrEnt[indAttr] = changeEntity(boost::dynamic_pointer_cast(aConstrAttr->object())); else aConstrEnt[indAttr] = changeEntity(aConstrAttr->attr()); } @@ -566,7 +568,8 @@ void SketchSolver_ConstraintGroup::resolveConstraints() std::map, Slvs_hEntity>::iterator anEntIter = myEntityAttrMap.begin(); for ( ; anEntIter != myEntityAttrMap.end(); anEntIter++) - updateAttribute(anEntIter->first, anEntIter->second); + if (updateAttribute(anEntIter->first, anEntIter->second)) + updateRelatedConstraints(anEntIter->first); } else if (!myConstraints.empty()) Events_Error::send(ERROR_SOLVE_CONSTRAINTS, this); @@ -789,7 +792,7 @@ bool SketchSolver_ConstraintGroup::updateGroup() // Class: SketchSolver_ConstraintGroup // Purpose: update features of sketch after resolving constraints // ============================================================================ -void SketchSolver_ConstraintGroup::updateAttribute( +bool SketchSolver_ConstraintGroup::updateAttribute( boost::shared_ptr theAttribute, const Slvs_hEntity& theEntityID) { @@ -804,10 +807,16 @@ void SketchSolver_ConstraintGroup::updateAttribute( boost::dynamic_pointer_cast(theAttribute); if (aPoint) { - aPoint->setValue(myParams[aFirstParamPos].val, - myParams[aFirstParamPos+1].val, - myParams[aFirstParamPos+2].val); - return ; + if (fabs(aPoint->x() - myParams[aFirstParamPos].val) > tolerance || + fabs(aPoint->y() - myParams[aFirstParamPos+1].val) > tolerance || + fabs(aPoint->z() - myParams[aFirstParamPos+2].val) > tolerance) + { + aPoint->setValue(myParams[aFirstParamPos].val, + myParams[aFirstParamPos+1].val, + myParams[aFirstParamPos+2].val); + return true; + } + return false; } // Point in 2D @@ -815,9 +824,14 @@ void SketchSolver_ConstraintGroup::updateAttribute( boost::dynamic_pointer_cast(theAttribute); if (aPoint2D) { - aPoint2D->setValue(myParams[aFirstParamPos].val, - myParams[aFirstParamPos+1].val); - return ; + if (fabs(aPoint2D->x() - myParams[aFirstParamPos].val) > tolerance || + fabs(aPoint2D->y() - myParams[aFirstParamPos+1].val) > tolerance) + { + aPoint2D->setValue(myParams[aFirstParamPos].val, + myParams[aFirstParamPos+1].val); + return true; + } + return false; } // Scalar value @@ -825,11 +839,16 @@ void SketchSolver_ConstraintGroup::updateAttribute( boost::dynamic_pointer_cast(theAttribute); if (aScalar) { - aScalar->setValue(myParams[aFirstParamPos].val); - return ; + if (fabs(aScalar->value() - myParams[aFirstParamPos].val) > tolerance) + { + aScalar->setValue(myParams[aFirstParamPos].val); + return true; + } + return false; } /// \todo Support other types of entities + return false; } // ============================================================================ @@ -866,7 +885,8 @@ void SketchSolver_ConstraintGroup::updateEntityIfPossible( // Restore flag of changes myNeedToSolve = myNeedToSolve || aNeedToSolveCopy; - updateRelatedConstraints(theEntity); + if (myNeedToSolve) + updateRelatedConstraints(theEntity); } } @@ -1115,18 +1135,25 @@ void SketchSolver_ConstraintGroup::updateRelatedConstraints( for ( ; aConstrIter != myConstraintMap.end(); aConstrIter++) { std::list< boost::shared_ptr > anAttributes = - aConstrIter->first->data()->attributes(theEntity->attributeType()); + aConstrIter->first->data()->attributes(std::string()); std::list< boost::shared_ptr >::iterator anAttrIter = anAttributes.begin(); for ( ; anAttrIter != anAttributes.end(); anAttrIter++) - if (*anAttrIter == theEntity) + { + bool isUpd = (*anAttrIter == theEntity); + boost::shared_ptr aRefAttr = + boost::dynamic_pointer_cast(*anAttrIter); + if (aRefAttr && !aRefAttr->isObject() && aRefAttr->attr() == theEntity) + isUpd = true; + + if (isUpd) { - static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED); - Model_FeatureUpdatedMessage aMsg(aConstrIter->first, anEvent); - Events_Loop::loop()->send(aMsg, true); + static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED); + ModelAPI_EventCreator::get()->sendUpdated(aConstrIter->first, anEvent); break; } + } } } @@ -1146,11 +1173,10 @@ void SketchSolver_ConstraintGroup::updateRelatedConstraints( { boost::shared_ptr aRefAttr = boost::dynamic_pointer_cast(*anAttrIter); - if (aRefAttr && aRefAttr->isFeature() && aRefAttr->feature() == theFeature) + if (aRefAttr && aRefAttr->isObject() && aRefAttr->object() == theFeature) { - static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED); - Model_FeatureUpdatedMessage aMsg(aConstrIter->first, anEvent); - Events_Loop::loop()->send(aMsg, true); + static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED); + ModelAPI_EventCreator::get()->sendUpdated(aConstrIter->first, anEvent); break; } }