1 #include <SketchSolver_ConstraintMovement.h>
2 #include <SketchSolver_Error.h>
3 #include <SketchSolver_Group.h>
5 #include <GeomDataAPI_Point2D.h>
7 SketchSolver_ConstraintMovement::SketchSolver_ConstraintMovement(FeaturePtr theFeature)
8 : SketchSolver_ConstraintRigid(theFeature)
13 void SketchSolver_ConstraintMovement::process()
16 if (!myBaseFeature || !myStorage || myGroup == 0) {
17 /// TODO: Put error message here
20 if (!mySlvsConstraints.empty()) // some data is changed, update constraint
21 update(myBaseConstraint);
24 std::vector<Slvs_hEntity> anEntities;
26 getAttributes(aValue, anEntities, isFullyMoved);
27 if (!myErrorMsg.empty() || (myFeatureMap.empty() && myAttributeMap.empty()))
33 std::vector<Slvs_hEntity>::iterator anEntIt = anEntities.begin();
34 for (; anEntIt != anEntities.end(); ++anEntIt)
40 void SketchSolver_ConstraintMovement::getAttributes(
42 std::vector<Slvs_hEntity>& theAttributes,
43 bool& theIsFullyMoved)
46 theIsFullyMoved = true;
47 int aType = SLVS_E_UNKNOWN; // type of created entity
48 Slvs_hEntity anEntityID = SLVS_E_UNKNOWN;
49 anEntityID = myGroup->getFeatureId(myBaseFeature);
50 if (anEntityID == SLVS_E_UNKNOWN) {
51 anEntityID = changeEntity(myBaseFeature, aType);
52 if (anEntityID == SLVS_E_UNKNOWN) {
53 myErrorMsg = SketchSolver_Error::NOT_INITIALIZED();
57 // Check the entity is complex
58 Slvs_Entity anEntity = myStorage->getEntity(anEntityID);
59 if (anEntity.point[0] != SLVS_E_UNKNOWN) {
60 for (int i = 0; i < 4 && anEntity.point[i]; i++)
61 theAttributes.push_back(anEntity.point[i]);
62 } else // simple entity
63 theAttributes.push_back(anEntityID);
66 myFeatureMap[myBaseFeature] = anEntityID;
68 std::list<AttributePtr> aPoints =
69 myBaseFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
70 std::list<AttributePtr>::iterator anIt = aPoints.begin();
71 for (; anIt != aPoints.end(); ++anIt) {
72 Slvs_hEntity anAttr = myGroup->getAttributeId(*anIt);
74 // Check the attribute changes coordinates
75 Slvs_Entity anAttrEnt = myStorage->getEntity(anAttr);
76 double aDeltaX = myStorage->getParameter(anAttrEnt.param[0]).val;
77 double aDeltaY = myStorage->getParameter(anAttrEnt.param[1]).val;
78 std::shared_ptr<GeomDataAPI_Point2D> aPt =
79 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
82 if (aDeltaX * aDeltaX + aDeltaY * aDeltaY >= tolerance * tolerance) {
83 theAttributes.push_back(anAttr);
84 // update point coordinates
85 double aNewPos[2] = {aPt->x(), aPt->y()};
86 for (int i = 0; i < 2; i++) {
87 Slvs_Param aParam = myStorage->getParameter(anAttrEnt.param[i]);
88 aParam.val = aNewPos[i];
89 myStorage->updateParameter(aParam);
93 theIsFullyMoved = false;