From: azv Date: Thu, 22 May 2014 11:08:29 +0000 (+0400) Subject: Listening of grouped messages by ConstraintManager X-Git-Tag: V_0.2~26^2~1^2^2~6^2~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=cecb56e63e1fd8ae4d382e15b7f5a89999967584;p=modules%2Fshaper.git Listening of grouped messages by ConstraintManager --- diff --git a/src/SketchSolver/SketchSolver_ConstraintManager.cpp b/src/SketchSolver/SketchSolver_ConstraintManager.cpp index b2ebd3d24..a543a181f 100644 --- a/src/SketchSolver/SketchSolver_ConstraintManager.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintManager.cpp @@ -75,37 +75,56 @@ SketchSolver_ConstraintManager::~SketchSolver_ConstraintManager() void SketchSolver_ConstraintManager::processEvent(const Events_Message* theMessage) { if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_CREATED) || - theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_UPDATED)) + theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_UPDATED) || + theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURES_MOVED)) { - const Model_FeatureUpdatedMessage* aUpdateMsg = dynamic_cast(theMessage); + const Model_FeatureUpdatedMessage* anUpdateMsg = dynamic_cast(theMessage); + std::set< boost::shared_ptr > aFeatures = anUpdateMsg->features(); - // Only sketches and constraints can be added by Create event - const std::string& aFeatureKind = aUpdateMsg->feature()->getKind(); - if (aFeatureKind.compare("Sketch") == 0) + if (!(theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURES_MOVED))) { - boost::shared_ptr aSketch = - boost::dynamic_pointer_cast(aUpdateMsg->feature()); - changeWorkplane(aSketch); - return ; - } - boost::shared_ptr aConstraint = - boost::dynamic_pointer_cast(aUpdateMsg->feature()); - if (aConstraint) - changeConstraint(aConstraint); - else - { - // Sketch plugin features can be only updated - boost::shared_ptr aFeature = - boost::dynamic_pointer_cast(aUpdateMsg->feature()); - if (aFeature) - updateEntity(aFeature); + std::set< boost::shared_ptr >::iterator aFeatIter; + for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) + { + // Only sketches and constraints can be added by Create event + const std::string& aFeatureKind = (*aFeatIter)->getKind(); + if (aFeatureKind.compare("Sketch") == 0) + { + boost::shared_ptr aSketch = + boost::dynamic_pointer_cast(*aFeatIter); + changeWorkplane(aSketch); + return ; + } + boost::shared_ptr aConstraint = + boost::dynamic_pointer_cast(*aFeatIter); + if (aConstraint) + changeConstraint(aConstraint); + else + { + // Sketch plugin features can be only updated + boost::shared_ptr aFeature = + boost::dynamic_pointer_cast(*aFeatIter); + if (aFeature) + updateEntity(aFeature); + } + } } + + // Solve the set of constraints + resolveConstraints(); } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_DELETED)) { const Model_FeatureDeletedMessage* aDeleteMsg = dynamic_cast(theMessage); - - if (aDeleteMsg->group().compare("Sketch") == 0) + const std::set& aFeatureGroups = aDeleteMsg->groups(); + + // Find "Sketch" in groups. The constraint groups should be updated when an object removed from Sketch + std::set::const_iterator aFGrIter; + for (aFGrIter = aFeatureGroups.begin(); aFGrIter != aFeatureGroups.end(); aFGrIter++) + if (aFGrIter->compare("Sketch") == 0) + break; + + if (aFGrIter != aFeatureGroups.end()) { std::vector::iterator aGroupIter = myGroups.begin(); while (aGroupIter != myGroups.end()) @@ -121,11 +140,6 @@ void SketchSolver_ConstraintManager::processEvent(const Events_Message* theMessa } } } - else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURES_MOVED)) - { - // Solve the set of constraints - resolveConstraints(); - } } bool SketchSolver_ConstraintManager::changeWorkplane(boost::shared_ptr theSketch) @@ -268,6 +282,9 @@ void SketchSolver_ConstraintManager::resolveConstraints() std::vector::iterator aGroupIter; for (aGroupIter = myGroups.begin(); aGroupIter != myGroups.end(); aGroupIter++) (*aGroupIter)->resolveConstraints(); + + // Features may be updated => send events + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED)); }