+ if (myCoincidentPoints.size() == 1 && myCoincidentPoints.front().empty())
+ myCoincidentPoints.clear();
+}
+
+
+// ============================================================================
+// Function: addCoincidentPoints
+// Class: SketchSolver_ConstraintGroup
+// Purpose: add coincident point the appropriate list of such points
+// ============================================================================
+bool SketchSolver_ConstraintGroup::addCoincidentPoints(
+ const Slvs_hEntity& thePoint1, const Slvs_hEntity& thePoint2)
+{
+ std::vector< std::set<Slvs_hEntity> >::iterator aCoPtIter = myCoincidentPoints.begin();
+ std::vector< std::set<Slvs_hEntity> >::iterator aFirstFound = myCoincidentPoints.end();
+ while (aCoPtIter != myCoincidentPoints.end())
+ {
+ bool isFound[2] = { // indicate which point ID was already in coincidence constraint
+ aCoPtIter->find(thePoint1) != aCoPtIter->end(),
+ aCoPtIter->find(thePoint2) != aCoPtIter->end(),
+ };
+ if (isFound[0] && isFound[1]) // points are already connected by coincidence constraints => no need additional one
+ return false;
+ if ((isFound[0] && !isFound[1]) || (!isFound[0] && isFound[1]))
+ {
+ if (aFirstFound != myCoincidentPoints.end())
+ { // there are two groups of coincident points connected by created constraint => merge them
+ int aFirstFoundShift = aFirstFound - myCoincidentPoints.begin();
+ int aCurrentShift = aCoPtIter - myCoincidentPoints.begin();
+ aFirstFound->insert(aCoPtIter->begin(), aCoPtIter->end());
+ myCoincidentPoints.erase(aCoPtIter);
+ aFirstFound = myCoincidentPoints.begin() + aFirstFoundShift;
+ aCoPtIter = myCoincidentPoints.begin() + aCurrentShift;
+ continue;
+ }
+ else
+ {
+ aCoPtIter->insert(isFound[0] ? thePoint2 : thePoint1);
+ aFirstFound = aCoPtIter;
+ }
+ }
+ aCoPtIter++;
+ }
+ // No points were found, need to create new set
+ if (aFirstFound == myCoincidentPoints.end())
+ {
+ std::set<Slvs_hEntity> aNewSet;
+ aNewSet.insert(thePoint1);
+ aNewSet.insert(thePoint2);
+ myCoincidentPoints.push_back(aNewSet);
+ }
+
+ return true;
+}
+
+
+// ============================================================================
+// Function: updateRelatedConstraints
+// Class: SketchSolver_ConstraintGroup
+// Purpose: emit the signal to update constraints
+// ============================================================================
+void SketchSolver_ConstraintGroup::updateRelatedConstraints(
+ boost::shared_ptr<ModelAPI_Attribute> theEntity) const
+{
+ std::map<boost::shared_ptr<SketchPlugin_Constraint>, Slvs_hConstraint>::const_iterator
+ aConstrIter = myConstraintMap.begin();
+ for ( ; aConstrIter != myConstraintMap.end(); aConstrIter++)
+ {
+ std::list< boost::shared_ptr<ModelAPI_Attribute> > anAttributes =
+ aConstrIter->first->data()->attributes(std::string());
+
+ std::list< boost::shared_ptr<ModelAPI_Attribute> >::iterator
+ anAttrIter = anAttributes.begin();
+ for ( ; anAttrIter != anAttributes.end(); anAttrIter++)
+ {
+ bool isUpd = (*anAttrIter == theEntity);
+ boost::shared_ptr<ModelAPI_AttributeRefAttr> aRefAttr =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttrIter);
+ if (aRefAttr && !aRefAttr->isObject() && aRefAttr->attr() == theEntity)
+ isUpd = true;
+
+ if (isUpd)
+ {
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
+ ModelAPI_EventCreator::get()->sendUpdated(aConstrIter->first, anEvent);
+ break;
+ }
+ }
+ }
+}
+
+void SketchSolver_ConstraintGroup::updateRelatedConstraints(
+ boost::shared_ptr<ModelAPI_Feature> theFeature) const
+{
+ std::map<boost::shared_ptr<SketchPlugin_Constraint>, Slvs_hConstraint>::const_iterator
+ aConstrIter = myConstraintMap.begin();
+ for ( ; aConstrIter != myConstraintMap.end(); aConstrIter++)
+ {
+ std::list< boost::shared_ptr<ModelAPI_Attribute> > anAttributes =
+ aConstrIter->first->data()->attributes(std::string());
+
+ std::list< boost::shared_ptr<ModelAPI_Attribute> >::iterator
+ anAttrIter = anAttributes.begin();
+ for ( ; anAttrIter != anAttributes.end(); anAttrIter++)
+ {
+ boost::shared_ptr<ModelAPI_AttributeRefAttr> aRefAttr =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttrIter);
+ if (aRefAttr && aRefAttr->isObject() && aRefAttr->object() == theFeature)
+ {
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
+ ModelAPI_EventCreator::get()->sendUpdated(aConstrIter->first, anEvent);
+ break;
+ }
+ }
+ }