From: azv Date: Wed, 25 Jun 2014 11:39:02 +0000 (+0400) Subject: Updating of constraint presentations while feature edit, and error handling X-Git-Tag: V_0.4.4~238 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1447f0f4a1f0338363928b59134420233e4f69aa;p=modules%2Fshaper.git Updating of constraint presentations while feature edit, and error handling --- diff --git a/src/SketchSolver/SketchSolver_ConstraintGroup.cpp b/src/SketchSolver/SketchSolver_ConstraintGroup.cpp index 5aa275391..0676bd58c 100644 --- a/src/SketchSolver/SketchSolver_ConstraintGroup.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintGroup.cpp @@ -6,6 +6,7 @@ #include +#include #include #include #include @@ -30,6 +31,8 @@ /// Tolerance for value of parameters const double tolerance = 1.e-10; +const std::string ERROR_SOLVE_CONSTRAINTS = "Conflicting constraints"; + /// This value is used to give unique index to the groups static Slvs_hGroup myGroupIndexer = 0; @@ -559,7 +562,8 @@ void SketchSolver_ConstraintGroup::resolveConstraints() for ( ; anEntIter != myEntityAttrMap.end(); anEntIter++) updateAttribute(anEntIter->first, anEntIter->second); } - /// \todo Implement error handling + else if (!myConstraints.empty()) + Events_Error::send(ERROR_SOLVE_CONSTRAINTS, this); removeTemporaryConstraints(); myNeedToSolve = false; @@ -855,6 +859,8 @@ void SketchSolver_ConstraintGroup::updateEntityIfPossible( // Restore flag of changes myNeedToSolve = myNeedToSolve || aNeedToSolveCopy; + + updateRelatedConstraints(theEntity); } } @@ -1090,6 +1096,61 @@ bool SketchSolver_ConstraintGroup::addCoincidentPoints( } +// ============================================================================ +// Function: updateRelatedConstraints +// Class: SketchSolver_ConstraintGroup +// Purpose: emit the signal to update constraints +// ============================================================================ +void SketchSolver_ConstraintGroup::updateRelatedConstraints( + boost::shared_ptr theEntity) const +{ + std::map, Slvs_hConstraint>::const_iterator + aConstrIter = myConstraintMap.begin(); + for ( ; aConstrIter != myConstraintMap.end(); aConstrIter++) + { + std::list< boost::shared_ptr > anAttributes = + aConstrIter->first->data()->attributes(theEntity->attributeType()); + + std::list< boost::shared_ptr >::iterator + anAttrIter = anAttributes.begin(); + for ( ; anAttrIter != anAttributes.end(); anAttrIter++) + if (*anAttrIter == theEntity) + { + static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED); + Model_FeatureUpdatedMessage aMsg(aConstrIter->first, anEvent); + Events_Loop::loop()->send(aMsg, true); + break; + } + } +} + +void SketchSolver_ConstraintGroup::updateRelatedConstraints( + boost::shared_ptr theFeature) const +{ + std::map, Slvs_hConstraint>::const_iterator + aConstrIter = myConstraintMap.begin(); + for ( ; aConstrIter != myConstraintMap.end(); aConstrIter++) + { + std::list< boost::shared_ptr > anAttributes = + aConstrIter->first->data()->attributes(std::string()); + + std::list< boost::shared_ptr >::iterator + anAttrIter = anAttributes.begin(); + for ( ; anAttrIter != anAttributes.end(); anAttrIter++) + { + boost::shared_ptr aRefAttr = + boost::dynamic_pointer_cast(*anAttrIter); + if (aRefAttr && aRefAttr->isFeature() && aRefAttr->feature() == theFeature) + { + static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED); + Model_FeatureUpdatedMessage aMsg(aConstrIter->first, anEvent); + Events_Loop::loop()->send(aMsg, true); + break; + } + } + } +} + // ======================================================== diff --git a/src/SketchSolver/SketchSolver_ConstraintGroup.h b/src/SketchSolver/SketchSolver_ConstraintGroup.h index 69c1a7c04..36d3d12ed 100644 --- a/src/SketchSolver/SketchSolver_ConstraintGroup.h +++ b/src/SketchSolver/SketchSolver_ConstraintGroup.h @@ -94,6 +94,12 @@ public: */ void resolveConstraints(); + /** \brief Searches the constraints built on the entity and emit the signal to update them + * \param[in] theEntity attribute of the constraint + */ + void updateRelatedConstraints(boost::shared_ptr theEntity) const; + void updateRelatedConstraints(boost::shared_ptr theFeature) const; + protected: /** \brief Adds or updates an entity in the group * diff --git a/src/SketchSolver/SketchSolver_ConstraintManager.cpp b/src/SketchSolver/SketchSolver_ConstraintManager.cpp index e91d65a16..0e39b5a42 100644 --- a/src/SketchSolver/SketchSolver_ConstraintManager.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintManager.cpp @@ -293,6 +293,11 @@ void SketchSolver_ConstraintManager::updateEntity(boost::shared_ptrupdateEntityIfPossible(anAttribute); } } + + std::vector::iterator aGroupIter; + for (aGroupIter = myGroups.begin(); aGroupIter != myGroups.end(); aGroupIter++) + if (!(*aGroupIter)->isEmpty()) + (*aGroupIter)->updateRelatedConstraints(theFeature); }