1 #include <SketchSolver_ConstraintMulti.h>
2 #include <SketchSolver_Error.h>
3 #include <SketchSolver_Manager.h>
5 #include <ModelAPI_AttributeInteger.h>
6 #include <ModelAPI_AttributeRefAttr.h>
7 #include <ModelAPI_AttributeRefList.h>
9 void SketchSolver_ConstraintMulti::getEntitiesAndCopies(
10 std::list< std::list<EntityWrapperPtr> >& theEntAndCopies)
12 DataPtr aData = myBaseConstraint->data();
14 // Lists of objects and number of copies
15 AttributeRefListPtr anInitialRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
16 aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
17 myNumberOfObjects = anInitialRefList->size();
18 myNumberOfCopies = aData->integer(nameNbObjects())->value() - 1;
19 if (myNumberOfCopies <= 0)
22 AttributeRefListPtr aRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
23 aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
24 if (!aRefList || aRefList->size() == 0) {
25 myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
30 std::list<EntityWrapperPtr> anEntities; // list of transformed entities
31 std::list<ObjectPtr> anObjectList = aRefList->list();
32 std::list<ObjectPtr>::iterator anObjIt = anObjectList.begin();
33 while (anObjIt != anObjectList.end()) {
35 for (int i = 0; i <= myNumberOfCopies && anObjIt != anObjectList.end(); ++i, ++anObjIt) {
36 aFeature = ModelAPI_Feature::feature(*anObjIt);
40 myStorage->update(aFeature);
41 anEntities.push_back(myStorage->entity(aFeature));
43 if (!anEntities.empty())
44 theEntAndCopies.push_back(anEntities);
48 void SketchSolver_ConstraintMulti::update()
54 void SketchSolver_ConstraintMulti::update(bool isForce)
57 AttributeRefListPtr anInitialRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
58 myBaseConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
59 AttributeIntegerPtr aNbObjects = myBaseConstraint->integer(nameNbObjects());
60 if (anInitialRefList->size() != myNumberOfObjects || aNbObjects->value()-1 != myNumberOfCopies) {
66 // update derivative object
70 // update parent object
71 SketchSolver_Constraint::update();
74 void SketchSolver_ConstraintMulti::adjustConstraint()
77 return; // constraint already adjusted, don't do it once again
79 BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
81 const std::list<ConstraintWrapperPtr>& aConstraints = myStorage->constraint(myBaseConstraint);
82 std::list<ConstraintWrapperPtr>::const_iterator anIt = aConstraints.begin();
83 for (; anIt != aConstraints.end(); ++anIt)
84 aBuilder->adjustConstraint(*anIt);
85 myStorage->addConstraint(myBaseConstraint, aConstraints);