-
-#include <GeomAPI_Pnt2d.h>
-#include <GeomAPI_XY.h>
-#include <math.h>
-
-/** \brief Search the entity/parameter with specified ID in the list of elements
- * \param[in] theEntityID unique ID of the element
- * \param[in] theEntities list of elements
- * \return position of the found element or -1 if the element is not found
- */
-template<typename T>
-static int Search(const uint32_t& theEntityID, const std::vector<T>& theEntities);
-
-/// \brief Compare two parameters to be different
-static bool IsNotEqual(const Slvs_Param& theParam1, const Slvs_Param& theParam2);
-/// \brief Compare two entities to be different
-static bool IsNotEqual(const Slvs_Entity& theEntity1, const Slvs_Entity& theEntity2);
-/// \brief Compare two constriants to be different
-static bool IsNotEqual(const Slvs_Constraint& theConstraint1, const Slvs_Constraint& theConstraint2);
-
-
-SketchSolver_Storage::SketchSolver_Storage()
- : myParamMaxID(SLVS_E_UNKNOWN),
- myEntityMaxID(SLVS_E_UNKNOWN),
- myConstrMaxID(SLVS_C_UNKNOWN),
- myFixed(SLVS_E_UNKNOWN),
- myNeedToResolve(false),
- myDuplicatedConstraint(false)
-{
-}
-
-Slvs_hParam SketchSolver_Storage::addParameter(const Slvs_Param& theParam)
-{
- if (theParam.h > 0 && theParam.h <= myParamMaxID) {
- // parameter is already used, rewrite it
- return updateParameter(theParam);
- }
-
- Slvs_Param aParam = theParam;
- if (aParam.h > myParamMaxID)
- myParamMaxID = aParam.h;
- else
- aParam.h = ++myParamMaxID;
- myParameters.push_back(aParam);
- myNeedToResolve = true;
- return aParam.h;
-}
-
-Slvs_hParam SketchSolver_Storage::updateParameter(const Slvs_Param& theParam)
-{
- if (theParam.h > 0 && theParam.h <= myParamMaxID) {
- // parameter already used, rewrite it
- int aPos = Search(theParam.h, myParameters);
- if (aPos >= 0 && aPos < (int)myParameters.size()) {
- myNeedToResolve = myNeedToResolve || IsNotEqual(myParameters[aPos], theParam);
- myParameters[aPos] = theParam;
- return theParam.h;
+#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_ConstraintCoincidence.h>
+#include <SketchPlugin_ConstraintMirror.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);
+
+/// \brief Convert result to feature or attribute
+static void resultToFeatureOrAttribute(const ObjectPtr& theResult,
+ FeaturePtr& theFeature, AttributePtr& theAttribute);
+
+
+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());
+ }