]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchSolver/SketchSolver_ConstraintMulti.cpp
Salome HOME
Correct processing parameters in "Multi" constraints
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintMulti.cpp
1 #include <SketchSolver_ConstraintMulti.h>
2 #include <SketchSolver_Error.h>
3 #include <SketchSolver_Manager.h>
4
5 #include <ModelAPI_AttributeInteger.h>
6 #include <ModelAPI_AttributeRefAttr.h>
7 #include <ModelAPI_AttributeRefList.h>
8
9 void SketchSolver_ConstraintMulti::getEntitiesAndCopies(
10     std::list< std::list<EntityWrapperPtr> >& theEntAndCopies)
11 {
12   myAdjusted = false;
13   DataPtr aData = myBaseConstraint->data();
14
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)
21     return;
22
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();
27     return;
28   }
29
30   FeaturePtr aFeature;
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 != aRefList->size()) // execute for the feature is not called yet
35     myNumberOfCopies = aRefList->size() - 1;
36
37   while (anObjIt != anObjectList.end()) {
38     anEntities.clear();
39     for (int i = 0; i <= myNumberOfCopies && anObjIt != anObjectList.end(); ++i, ++anObjIt) {
40       aFeature = ModelAPI_Feature::feature(*anObjIt);
41       if (!aFeature)
42         continue;
43
44       myStorage->update(aFeature);
45       anEntities.push_back(myStorage->entity(aFeature));
46     }
47     if (!anEntities.empty())
48       theEntAndCopies.push_back(anEntities);
49   }
50 }
51
52 void SketchSolver_ConstraintMulti::update()
53 {
54   update(false);
55 }
56
57
58 void SketchSolver_ConstraintMulti::update(bool isForce)
59 {
60   cleanErrorMsg();
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) {
65     remove();
66     process();
67     return;
68   }
69
70   // update derivative object
71   updateLocal();
72   if (isForce)
73     myAdjusted = false;
74   // update parent object
75   SketchSolver_Constraint::update();
76 }
77
78 void SketchSolver_ConstraintMulti::adjustConstraint()
79 {
80   if (myAdjusted)
81     return; // constraint already adjusted, don't do it once again
82
83   BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
84
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);
90
91   myAdjusted = true;
92 }