1 // File: SketchSolver_ConstraintManager.cpp
2 // Created: 08 May 2014
3 // Author: Artem ZHIDKOV
5 #include "SketchSolver_ConstraintManager.h"
7 #include <Events_Loop.h>
8 #include <GeomDataAPI_Dir.h>
9 #include <GeomDataAPI_Point.h>
10 #include <GeomDataAPI_Point2D.h>
11 #include <ModelAPI_AttributeDouble.h>
12 #include <ModelAPI_AttributeRefList.h>
13 #include <ModelAPI_Data.h>
14 #include <Model_Events.h>
15 #include <SketchPlugin_Constraint.h>
16 #include <SketchPlugin_ConstraintCoincidence.h>
17 #include <SketchPlugin_Line.h>
18 #include <SketchPlugin_Point.h>
19 #include <SketchPlugin_Sketch.h>
23 /// Tolerance for value of parameters
24 const double tolerance = 1.e-10;
26 // Initialization of constraint manager self pointer
27 SketchSolver_ConstraintManager* SketchSolver_ConstraintManager::_self = 0;
29 /// Global constaint manager object
30 SketchSolver_ConstraintManager* myManager = SketchSolver_ConstraintManager::Instance();
32 /// This value is used to give unique index to the groups
33 static Slvs_hGroup myGroupIndexer = 0;
35 /** \brief Search the entity/parameter with specified ID in the list of elements
36 * \param[in] theEntityID unique ID of the element
37 * \param[in] theEntities list of elements
38 * \return position of the found element or -1 if the element is not found
41 static int Search(const uint32_t& theEntityID, const std::vector<T>& theEntities);
45 // ========================================================
46 // ========= SketchSolver_ConstraintManager ===============
47 // ========================================================
48 SketchSolver_ConstraintManager* SketchSolver_ConstraintManager::Instance()
51 _self = new SketchSolver_ConstraintManager();
55 SketchSolver_ConstraintManager::SketchSolver_ConstraintManager()
59 // Register in event loop
60 Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_CREATED));
61 Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
62 Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_DELETED));
65 SketchSolver_ConstraintManager::~SketchSolver_ConstraintManager()
70 void SketchSolver_ConstraintManager::processEvent(const Events_Message* theMessage)
72 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_CREATED) ||
73 theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_UPDATED))
75 const Model_FeatureUpdatedMessage* aUpdateMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
77 // Only sketches and constraints can be added by Create event
78 boost::shared_ptr<SketchPlugin_Sketch> aSketch =
79 boost::dynamic_pointer_cast<SketchPlugin_Sketch>(aUpdateMsg->feature());
82 changeWorkplane(aSketch);
85 boost::shared_ptr<SketchPlugin_Constraint> aConstraint =
86 boost::dynamic_pointer_cast<SketchPlugin_Constraint>(aUpdateMsg->feature());
89 changeConstraint(aConstraint);
91 // Solve the set of constraints
96 /// \todo Implement feature update handling
97 boost::shared_ptr<SketchPlugin_Feature> aFeature =
98 boost::dynamic_pointer_cast<SketchPlugin_Feature>(aUpdateMsg->feature());
101 updateEntity(aFeature);
103 // Solve the set of constraints
104 ResolveConstraints();
107 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_DELETED))
109 const Model_FeatureDeletedMessage* aDeleteMsg = dynamic_cast<const Model_FeatureDeletedMessage*>(theMessage);
110 /// \todo Implement deleting objects on event
114 bool SketchSolver_ConstraintManager::changeWorkplane(boost::shared_ptr<SketchPlugin_Sketch> theSketch)
116 bool aResult = true; // changed when a workplane wrongly updated
117 bool isUpdated = false;
118 // Try to update specified workplane in all groups
119 std::vector<SketchSolver_ConstraintGroup*>::iterator aGroupIter;
120 for (aGroupIter = myGroups.begin(); aGroupIter != myGroups.end(); aGroupIter++)
121 if ((*aGroupIter)->isBaseWorkplane(theSketch))
124 if (!(*aGroupIter)->updateWorkplane())
127 // If the workplane is not updated, so this is a new workplane
130 SketchSolver_ConstraintGroup* aNewGroup = new SketchSolver_ConstraintGroup(theSketch);
131 // Verify that the group is created successfully
132 if (!aNewGroup->isBaseWorkplane(theSketch))
137 myGroups.push_back(aNewGroup);
142 bool SketchSolver_ConstraintManager::changeConstraint(
143 boost::shared_ptr<SketchPlugin_Constraint> theConstraint)
145 // Search the groups which this constraint touchs
146 std::vector<Slvs_hGroup> aGroups;
147 findGroups(theConstraint, aGroups);
149 // Process the groups list
150 if (aGroups.size() == 0)
151 { // There are no groups applicable for this constraint => create new one
152 boost::shared_ptr<SketchPlugin_Sketch> aWP = findWorkplaneForConstraint(theConstraint);
153 if (!aWP) return false;
154 SketchSolver_ConstraintGroup* aGroup = new SketchSolver_ConstraintGroup(aWP);
155 if (!aGroup->changeConstraint(theConstraint))
160 myGroups.push_back(aGroup);
163 else if (aGroups.size() == 1)
164 { // Only one group => add constraint into it
165 Slvs_hGroup aGroupId = *(aGroups.begin());
166 std::vector<SketchSolver_ConstraintGroup*>::iterator aGroupIter;
167 for (aGroupIter = myGroups.begin(); aGroupIter != myGroups.end(); aGroupIter++)
168 if ((*aGroupIter)->getId() == aGroupId)
169 return (*aGroupIter)->changeConstraint(theConstraint);
171 else if (aGroups.size() > 1)
172 { // Several groups applicable for this constraint => need to merge them
173 /// \todo Implement merging of groups
176 // Something goes wrong
180 void SketchSolver_ConstraintManager::updateEntity(boost::shared_ptr<SketchPlugin_Feature> theFeature)
182 // Create list of attributes depending on type of the feature
183 std::vector<std::string> anAttrList;
185 boost::shared_ptr<SketchPlugin_Point> aPoint =
186 boost::dynamic_pointer_cast<SketchPlugin_Point>(theFeature);
188 anAttrList.push_back(POINT_ATTR_COORD);
190 boost::shared_ptr<SketchPlugin_Line> aLine =
191 boost::dynamic_pointer_cast<SketchPlugin_Line>(theFeature);
194 anAttrList.push_back(LINE_ATTR_START);
195 anAttrList.push_back(LINE_ATTR_END);
197 /// \todo Other types of features should be implemented
199 // Check changing of feature's attributes (go through the groups and search usage of the attributes)
200 std::vector<std::string>::const_iterator anAttrIter;
201 for (anAttrIter = anAttrList.begin(); anAttrIter != anAttrList.end(); anAttrIter++)
203 std::vector<SketchSolver_ConstraintGroup*>::iterator aGroupIter;
204 for (aGroupIter = myGroups.begin(); aGroupIter != myGroups.end(); aGroupIter++)
206 boost::shared_ptr<ModelAPI_Attribute> anAttribute =
207 boost::dynamic_pointer_cast<ModelAPI_Attribute>(theFeature->data()->attribute(*anAttrIter));
208 (*aGroupIter)->updateEntityIfPossible(anAttribute);
214 void SketchSolver_ConstraintManager::findGroups(
215 boost::shared_ptr<SketchPlugin_Constraint> theConstraint,
216 std::vector<Slvs_hGroup>& theGroupIDs) const
218 boost::shared_ptr<SketchPlugin_Sketch> aWP = findWorkplaneForConstraint(theConstraint);
220 std::vector<SketchSolver_ConstraintGroup*>::const_iterator aGroupIter;
221 for (aGroupIter = myGroups.begin(); aGroupIter != myGroups.end(); aGroupIter++)
222 if (aWP == (*aGroupIter)->getWorkplane() && (*aGroupIter)->isInteract(theConstraint))
223 theGroupIDs.push_back((*aGroupIter)->getId());
226 boost::shared_ptr<SketchPlugin_Sketch> SketchSolver_ConstraintManager::findWorkplaneForConstraint(
227 boost::shared_ptr<SketchPlugin_Constraint> theConstraint) const
229 std::vector<SketchSolver_ConstraintGroup*>::const_iterator aGroupIter;
230 for (aGroupIter = myGroups.begin(); aGroupIter != myGroups.end(); aGroupIter++)
232 boost::shared_ptr<SketchPlugin_Sketch> aWP = (*aGroupIter)->getWorkplane();
233 boost::shared_ptr<ModelAPI_AttributeRefList> aWPFeatures =
234 boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(aWP->data()->attribute(SKETCH_ATTR_FEATURES));
235 std::list< boost::shared_ptr<ModelAPI_Feature> > aFeaturesList = aWPFeatures->list();
236 std::list< boost::shared_ptr<ModelAPI_Feature> >::const_iterator anIter;
237 for (anIter = aFeaturesList.begin(); anIter != aFeaturesList.end(); anIter++)
238 if (*anIter == theConstraint)
239 return aWP; // workplane is found
242 return boost::shared_ptr<SketchPlugin_Sketch>();
245 void SketchSolver_ConstraintManager::ResolveConstraints()
247 std::vector<SketchSolver_ConstraintGroup*>::iterator aGroupIter;
248 for (aGroupIter = myGroups.begin(); aGroupIter != myGroups.end(); aGroupIter++)
249 (*aGroupIter)->ResolveConstraints();
254 // ========================================================
255 // ========= SketchSolver_ConstraintGroup ===============
256 // ========================================================
258 SketchSolver_ConstraintManager::SketchSolver_ConstraintGroup::
259 SketchSolver_ConstraintGroup(boost::shared_ptr<SketchPlugin_Sketch> theWorkplane)
260 : myID(++myGroupIndexer),
265 myNeedToSolve(false),
270 myConstraints.clear();
272 // Initialize workplane
273 myWorkplane.h = SLVS_E_UNKNOWN;
274 addWorkplane(theWorkplane);
277 SketchSolver_ConstraintManager::SketchSolver_ConstraintGroup::~SketchSolver_ConstraintGroup()
281 myConstraints.clear();
282 myConstraintMap.clear();
285 bool SketchSolver_ConstraintManager::SketchSolver_ConstraintGroup::isBaseWorkplane(
286 boost::shared_ptr<SketchPlugin_Sketch> theWorkplane) const
288 return theWorkplane == mySketch;
291 bool SketchSolver_ConstraintManager::SketchSolver_ConstraintGroup::isInteract(
292 boost::shared_ptr<SketchPlugin_Constraint> theConstraint) const
294 // Check the group is empty
295 if (myWorkplane.h != SLVS_E_UNKNOWN && myConstraints.empty())
298 /// \todo Should be implemented
302 bool SketchSolver_ConstraintManager::SketchSolver_ConstraintGroup::changeConstraint(
303 boost::shared_ptr<SketchPlugin_Constraint> theConstraint)
305 // There is no workplane yet, something wrong
306 if (myWorkplane.h == SLVS_E_UNKNOWN)
309 // Search this constraint in the current group to update it
310 std::map<boost::shared_ptr<SketchPlugin_Constraint>, Slvs_hConstraint>::const_iterator
311 aConstrMapIter = myConstraintMap.find(theConstraint);
312 std::vector<Slvs_Constraint>::iterator aConstrIter;
313 if (aConstrMapIter != myConstraintMap.end())
315 int aConstrPos = Search(aConstrMapIter->second, myConstraints);
316 aConstrIter = myConstraints.begin() + aConstrPos;
319 // Get constraint type and verify the constraint parameters are correct
320 int aConstrType = getConstraintType(theConstraint);
321 if (aConstrType == SLVS_C_UNKNOWN ||
322 (aConstrMapIter != myConstraintMap.end() && aConstrIter->type != aConstrType))
325 // Create constraint parameters
326 double aDistance = 0.0; // scalar value of the constraint
327 boost::shared_ptr<ModelAPI_AttributeDouble> aDistAttr =
328 boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theConstraint->data()->attribute(CONSTRAINT_ATTR_VALUE));
331 aDistance = aDistAttr->value();
332 if (aConstrMapIter != myConstraintMap.end() && aConstrIter->valA != aDistance)
334 myNeedToSolve = true;
335 aConstrIter->valA = aDistance;
339 Slvs_hEntity aConstrEnt[CONSTRAINT_ATTR_SIZE]; // parameters of the constraint
340 for (unsigned int indAttr = 0; indAttr < CONSTRAINT_ATTR_SIZE; indAttr++)
342 aConstrEnt[indAttr] = SLVS_E_UNKNOWN;
343 boost::shared_ptr<ModelAPI_AttributeRefAttr> aConstrAttr =
344 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
345 theConstraint->data()->attribute(CONSTRAINT_ATTRIBUTES[indAttr])
347 if (!aConstrAttr) continue;
348 aConstrEnt[indAttr] = changeEntity(aConstrAttr->attr());
351 if (aConstrMapIter == myConstraintMap.end())
353 // Create SolveSpace constraint structure
354 Slvs_Constraint aConstraint =
355 Slvs_MakeConstraint(++myConstrMaxID, myID, aConstrType, myWorkplane.h,
356 aDistance, aConstrEnt[0], aConstrEnt[1], aConstrEnt[2], aConstrEnt[3]);
357 myConstraints.push_back(aConstraint);
358 myConstraintMap[theConstraint] = aConstraint.h;
363 Slvs_hEntity SketchSolver_ConstraintManager::SketchSolver_ConstraintGroup::changeEntity(
364 boost::shared_ptr<ModelAPI_Attribute> theEntity)
366 // If the entity is already in the group, try to find it
367 std::map<boost::shared_ptr<ModelAPI_Attribute>, Slvs_hEntity>::const_iterator
368 aEntIter = myEntityMap.find(theEntity);
369 std::vector<Slvs_Param>::const_iterator aParamIter; // looks at first parameter of already existent entity or at the end of vector otherwise
370 if (aEntIter == myEntityMap.end()) // no such entity => should be created
371 aParamIter = myParams.end();
373 { // the entity already exists
374 int aEntPos = Search(aEntIter->second, myEntities);
375 int aParamPos = Search(myEntities[aEntPos].param[0], myParams);
376 aParamIter = myParams.begin() + aParamPos;
379 // Look over supported types of entities
382 boost::shared_ptr<GeomDataAPI_Point> aPoint =
383 boost::dynamic_pointer_cast<GeomDataAPI_Point>(theEntity);
386 Slvs_hParam aX = changeParameter(aPoint->x(), aParamIter);
387 Slvs_hParam aY = changeParameter(aPoint->y(), aParamIter);
388 Slvs_hParam aZ = changeParameter(aPoint->z(), aParamIter);
390 if (aEntIter != myEntityMap.end()) // the entity already exists
391 return aEntIter->second;
394 Slvs_Entity aPtEntity = Slvs_MakePoint3d(++myEntityMaxID, myID, aX, aY, aZ);
395 myEntities.push_back(aPtEntity);
396 myEntityMap[theEntity] = aPtEntity.h;
401 boost::shared_ptr<GeomDataAPI_Point2D> aPoint2D =
402 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(theEntity);
405 // The 2D points are created on workplane. So, if there is no workplane yet, then error
406 if (myWorkplane.h == SLVS_E_UNKNOWN)
407 return SLVS_E_UNKNOWN;
408 Slvs_hParam aU = changeParameter(aPoint2D->x(), aParamIter);
409 Slvs_hParam aV = changeParameter(aPoint2D->y(), aParamIter);
411 if (aEntIter != myEntityMap.end()) // the entity already exists
412 return aEntIter->second;
415 Slvs_Entity aPt2DEntity = Slvs_MakePoint2d(++myEntityMaxID, myID, myWorkplane.h, aU, aV);
416 myEntities.push_back(aPt2DEntity);
417 myEntityMap[theEntity] = aPt2DEntity.h;
418 return aPt2DEntity.h;
421 /// \todo Other types of entities
423 // Unsupported or wrong entity type
424 return SLVS_E_UNKNOWN;
427 Slvs_hEntity SketchSolver_ConstraintManager::SketchSolver_ConstraintGroup::changeNormal(
428 boost::shared_ptr<ModelAPI_Attribute> theDirX,
429 boost::shared_ptr<ModelAPI_Attribute> theDirY,
430 boost::shared_ptr<ModelAPI_Attribute> theNorm)
432 boost::shared_ptr<GeomDataAPI_Dir> aDirX =
433 boost::dynamic_pointer_cast<GeomDataAPI_Dir>(theDirX);
434 boost::shared_ptr<GeomDataAPI_Dir> aDirY =
435 boost::dynamic_pointer_cast<GeomDataAPI_Dir>(theDirY);
436 if (!aDirX || !aDirY ||
437 (fabs(aDirX->x()) + fabs(aDirX->y()) + fabs(aDirX->z()) < tolerance) ||
438 (fabs(aDirY->x()) + fabs(aDirY->y()) + fabs(aDirY->z()) < tolerance))
439 return SLVS_E_UNKNOWN;
441 // quaternion parameters of normal vector
442 double qw, qx, qy, qz;
443 Slvs_MakeQuaternion(aDirX->x(), aDirX->y(), aDirX->z(),
444 aDirY->x(), aDirY->y(), aDirY->z(),
446 double aNormCoord[4] = {qw, qx, qy, qz};
448 // Try to find existent normal
449 std::map<boost::shared_ptr<ModelAPI_Attribute>, Slvs_hEntity>::const_iterator
450 aEntIter = myEntityMap.find(theNorm);
451 std::vector<Slvs_Param>::const_iterator aParamIter; // looks at first parameter of already existent entity or at the end of vector otherwise
452 if (aEntIter == myEntityMap.end()) // no such entity => should be created
453 aParamIter = myParams.end();
455 { // the entity already exists, update it
456 int aEntPos = Search(aEntIter->second, myEntities);
457 int aParamPos = Search(myEntities[aEntPos].param[0], myParams);
458 aParamIter = myParams.begin() + aParamPos;
461 // Change parameters of the normal
462 Slvs_hParam aNormParams[4];
463 for (int i = 0; i < 4; i++)
464 aNormParams[i] = changeParameter(aNormCoord[i], aParamIter);
466 if (aEntIter != myEntityMap.end()) // the entity already exists
467 return aEntIter->second;
470 Slvs_Entity aNormal = Slvs_MakeNormal3d(++myEntityMaxID, myID,
471 aNormParams[0], aNormParams[1], aNormParams[2], aNormParams[3]);
472 myEntities.push_back(aNormal);
473 myEntityMap[theNorm] = aNormal.h;
478 bool SketchSolver_ConstraintManager::SketchSolver_ConstraintGroup::addWorkplane(
479 boost::shared_ptr<SketchPlugin_Sketch> theSketch)
482 return false; // the workplane already exists
484 mySketch = theSketch;
485 return updateWorkplane();
488 bool SketchSolver_ConstraintManager::SketchSolver_ConstraintGroup::updateWorkplane()
490 // Get parameters of workplane
491 boost::shared_ptr<ModelAPI_Attribute> aDirX = mySketch->data()->attribute(SKETCH_ATTR_DIRX);
492 boost::shared_ptr<ModelAPI_Attribute> aDirY = mySketch->data()->attribute(SKETCH_ATTR_DIRY);
493 boost::shared_ptr<ModelAPI_Attribute> aNorm = mySketch->data()->attribute(SKETCH_ATTR_NORM);
494 boost::shared_ptr<ModelAPI_Attribute> anOrigin = mySketch->data()->attribute(SKETCH_ATTR_ORIGIN);
495 // Transform them into SolveSpace format
496 Slvs_hEntity aNormalWP = changeNormal(aDirX, aDirY, aNorm);
497 if (!aNormalWP) return false;
498 Slvs_hEntity anOriginWP = changeEntity(anOrigin);
499 if (!anOriginWP) return false;
504 myWorkplane = Slvs_MakeWorkplane(++myEntityMaxID, myID, anOriginWP, aNormalWP);
505 // Workplane should be added to the list of entities
506 myEntities.push_back(myWorkplane);
512 Slvs_hParam SketchSolver_ConstraintManager::SketchSolver_ConstraintGroup::changeParameter(
513 const double& theParam,
514 std::vector<Slvs_Param>::const_iterator& thePrmIter)
516 if (thePrmIter != myParams.end())
517 { // Parameter should be updated
518 if (thePrmIter->val != theParam)
519 myNeedToSolve = true; // parameter is changed, need to resolve constraints
520 int aParamPos = thePrmIter - myParams.begin();
521 myParams[aParamPos].val = theParam;
523 return myParams[aParamPos].h;
526 // Newly created parameter
527 Slvs_Param aParam = Slvs_MakeParam(++myParamMaxID, myID, theParam);
528 myParams.push_back(aParam);
529 myNeedToSolve = true;
530 // The list of parameters is changed, move iterator to the end of the list to avoid problems
531 thePrmIter = myParams.end();
535 int SketchSolver_ConstraintManager::SketchSolver_ConstraintGroup::getConstraintType(
536 const boost::shared_ptr<SketchPlugin_Constraint>& theConstraint) const
538 // Constraint for coincidence of two points
539 boost::shared_ptr<SketchPlugin_ConstraintCoincidence> aPtEquiv =
540 boost::dynamic_pointer_cast<SketchPlugin_ConstraintCoincidence>(theConstraint);
543 // Verify the constraint has only two attributes and they are points
544 int aPt2d = 0; // bit-mapped field, each bit indicates whether the attribute is 2D point
545 int aPt3d = 0; // bit-mapped field, the same information for 3D points
546 for (unsigned int indAttr = 0; indAttr < CONSTRAINT_ATTR_SIZE; indAttr++)
548 boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
549 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
550 theConstraint->data()->attribute(CONSTRAINT_ATTRIBUTES[indAttr])
552 if (!anAttr) continue;
553 // Verify the attribute is a 2D point
554 boost::shared_ptr<GeomDataAPI_Point2D> aPoint2D =
555 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
558 aPt2d |= (1 << indAttr);
561 // Verify the attribute is a 3D point
562 boost::shared_ptr<GeomDataAPI_Point> aPoint3D =
563 boost::dynamic_pointer_cast<GeomDataAPI_Point>(anAttr->attr());
566 aPt3d |= (1 << indAttr);
569 // Attribute neither 2D nor 3D point is not supported by this type of constraint
570 return SLVS_C_UNKNOWN;
572 // The constrained points should be in first and second positions,
573 // so the expected value of aPt2d or aPt3d is 3
574 if ((aPt2d == 3 && aPt3d == 0) || (aPt2d == 0 && aPt3d == 3))
575 return SLVS_C_POINTS_COINCIDENT;
576 // Constraint parameters are wrong
577 return SLVS_C_UNKNOWN;
580 /// \todo Implement other kind of constrtaints
582 return SLVS_C_UNKNOWN;
585 void SketchSolver_ConstraintManager::SketchSolver_ConstraintGroup::ResolveConstraints()
590 myConstrSolver.setGroupID(myID);
591 myConstrSolver.setParameters(myParams);
592 myConstrSolver.setEntities(myEntities);
593 myConstrSolver.setConstraints(myConstraints);
595 if (myConstrSolver.solve() == SLVS_RESULT_OKAY)
596 { // solution succeeded, store results into correspondent attributes
597 // Obtain result into the same list of parameters
598 if (!myConstrSolver.getResult(myParams))
601 std::map<boost::shared_ptr<ModelAPI_Attribute>, Slvs_hEntity>::iterator
602 anEntIter = myEntityMap.begin();
603 for ( ; anEntIter != myEntityMap.end(); anEntIter++)
604 updateAttribute(anEntIter->first, anEntIter->second);
606 /// \todo Implement error handling
608 myNeedToSolve = false;
612 void SketchSolver_ConstraintManager::SketchSolver_ConstraintGroup::updateAttribute(
613 boost::shared_ptr<ModelAPI_Attribute> theAttribute,
614 const Slvs_hEntity& theEntityID)
616 // Search the position of the first parameter of the entity
617 int anEntPos = Search(theEntityID, myEntities);
618 int aFirstParamPos = Search(myEntities[anEntPos].param[0], myParams);
620 // Look over supported types of entities
623 boost::shared_ptr<GeomDataAPI_Point> aPoint =
624 boost::dynamic_pointer_cast<GeomDataAPI_Point>(theAttribute);
627 aPoint->setValue(myParams[aFirstParamPos].val,
628 myParams[aFirstParamPos+1].val,
629 myParams[aFirstParamPos+2].val);
634 boost::shared_ptr<GeomDataAPI_Point2D> aPoint2D =
635 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(theAttribute);
638 aPoint2D->setValue(myParams[aFirstParamPos].val,
639 myParams[aFirstParamPos+1].val);
643 /// \todo Support other types of entities
646 void SketchSolver_ConstraintManager::SketchSolver_ConstraintGroup::updateEntityIfPossible(
647 boost::shared_ptr<ModelAPI_Attribute> theEntity)
649 if (myEntityMap.find(theEntity) != myEntityMap.end())
650 changeEntity(theEntity);
655 // ========================================================
656 // ========= Auxiliary functions ===============
657 // ========================================================
659 template <typename T>
660 int Search(const uint32_t& theEntityID, const std::vector<T>& theEntities)
662 std::vector<T>::const_iterator aEntIter = theEntities.begin() + theEntityID - 1;
663 while (aEntIter != theEntities.end() && aEntIter->h > theEntityID)
665 while (aEntIter != theEntities.end() && aEntIter->h < theEntityID)
667 if (aEntIter == theEntities.end())
669 return aEntIter - theEntities.begin();