+#include <SketchSolver_Manager.h>
+
+#include <GeomDataAPI_Point2D.h>
+#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeRefList.h>
+#include <SketchPlugin_Arc.h>
+#include <SketchPlugin_Circle.h>
+#include <SketchPlugin_Line.h>
+#include <SketchPlugin_Point.h>
+#include <SketchPlugin_IntersectionPoint.h>
+#include <SketchPlugin_ConstraintRigid.h>
+
+
+/// \brief Verify two vectors of constraints are equal.
+/// Vectors differ by the order of elements are equal.
+static bool isEqual(const std::list<ConstraintWrapperPtr>& theCVec1,
+ const std::list<ConstraintWrapperPtr>& theCVec2);
+
+
+void SketchSolver_Storage::addConstraint(ConstraintPtr theConstraint,
+ ConstraintWrapperPtr theSolverConstraint)
+{
+ if (theSolverConstraint) {
+ std::list<ConstraintWrapperPtr> aConstrList(1, theSolverConstraint);
+ addConstraint(theConstraint, aConstrList);
+ } else
+ addConstraint(theConstraint, std::list<ConstraintWrapperPtr>());
+}
+
+void SketchSolver_Storage::addConstraint(
+ ConstraintPtr theConstraint,
+ std::list<ConstraintWrapperPtr> theSolverConstraints)
+{
+ std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
+ aFound = myConstraintMap.find(theConstraint);
+ if (aFound == myConstraintMap.end() || !isEqual(aFound->second, theSolverConstraints))
+ setNeedToResolve(true);
+
+ if (theSolverConstraints.empty()) {
+ // constraint links to the empty list, add its attributes linked to the empty entities
+ std::list<AttributePtr> aRefAttrs =
+ theConstraint->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
+ std::list<AttributePtr>::const_iterator anAttrIt = aRefAttrs.begin();
+ for (; anAttrIt != aRefAttrs.end(); ++anAttrIt) {
+ AttributeRefAttrPtr aRef = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttrIt);
+ if (aRef->isObject()) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(aRef->object());
+ if (aFeature) addEntity(aFeature, EntityWrapperPtr());
+ } else
+ addEntity(aRef->attr(), EntityWrapperPtr());
+ }
+ std::list<AttributePtr> aRefLists =
+ theConstraint->data()->attributes(ModelAPI_AttributeRefList::typeId());
+ for (anAttrIt = aRefLists.begin(); anAttrIt != aRefLists.end(); ++anAttrIt) {
+ AttributeRefListPtr aRef = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(*anAttrIt);
+ std::list<ObjectPtr> anObj = aRef->list();
+ std::list<ObjectPtr>::iterator anIt = anObj.begin();
+ for (; anIt != anObj.end(); ++anIt) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
+ if (aFeature) addEntity(aFeature, EntityWrapperPtr());
+ }
+ }
+ }
+ else if (theSolverConstraints.front()->type() != CONSTRAINT_PT_PT_COINCIDENT) {
+ // Do not add point-point coincidence, because it is already made by setting
+ // the same parameters for both points
+ std::list<ConstraintWrapperPtr>::iterator aCIt = theSolverConstraints.begin();
+ for (; aCIt != theSolverConstraints.end(); ++aCIt)
+ update(*aCIt);
+ }