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)
13 DataPtr aData = myBaseConstraint->data();
15 // Lists of objects and number of copies
16 AttributeRefListPtr anInitialRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
17 aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
18 myNumberOfObjects = anInitialRefList->size();
19 myNumberOfCopies = aData->integer(nameNbObjects())->value() - 1;
20 if (myNumberOfCopies <= 0)
23 AttributeRefListPtr aRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
24 aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
25 if (!aRefList || aRefList->size() == 0) {
26 myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
31 std::list<EntityWrapperPtr> anEntities; // list of transformed entities
32 std::list<ObjectPtr> anObjectList = aRefList->list();
33 std::list<ObjectPtr>::iterator anObjIt = anObjectList.begin();
34 if ((myNumberOfCopies + 1) * myNumberOfObjects != aRefList->size()) // execute for the feature is not called yet
35 myNumberOfCopies = aRefList->size() / myNumberOfObjects - 1;
37 while (anObjIt != anObjectList.end()) {
39 for (int i = 0; i <= myNumberOfCopies && anObjIt != anObjectList.end(); ++i, ++anObjIt) {
40 aFeature = ModelAPI_Feature::feature(*anObjIt);
44 myStorage->update(aFeature);
45 anEntities.push_back(myStorage->entity(aFeature));
47 if (!anEntities.empty())
48 theEntAndCopies.push_back(anEntities);
52 void SketchSolver_ConstraintMulti::update()
58 void SketchSolver_ConstraintMulti::update(bool isForce)
61 AttributeRefListPtr anInitialRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
62 myBaseConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
63 AttributeIntegerPtr aNbObjects = myBaseConstraint->integer(nameNbObjects());
64 if (anInitialRefList->size() != myNumberOfObjects || aNbObjects->value()-1 != myNumberOfCopies) {
70 // update derivative object
74 // update parent object
75 SketchSolver_Constraint::update();
78 void SketchSolver_ConstraintMulti::adjustConstraint()
81 return; // constraint already adjusted, don't do it once again
83 BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
85 const std::list<ConstraintWrapperPtr>& aConstraints = myStorage->constraint(myBaseConstraint);
86 std::list<ConstraintWrapperPtr>::const_iterator anIt = aConstraints.begin();
87 for (; anIt != aConstraints.end(); ++anIt)
88 aBuilder->adjustConstraint(*anIt);
89 myStorage->addConstraint(myBaseConstraint, aConstraints);