1 #include <SketchSolver_ConstraintMultiRotation.h>
2 #include <SketchSolver_Error.h>
3 #include <SketchSolver_Manager.h>
5 #include <SketchPlugin_MultiRotation.h>
9 void SketchSolver_ConstraintMultiRotation::getAttributes(
10 EntityWrapperPtr& theCenter, double& theAngle,
11 std::list< std::list<EntityWrapperPtr> >& theEntities)
13 DataPtr aData = myBaseConstraint->data();
14 theAngle = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
15 aData->attribute(SketchPlugin_MultiRotation::ANGLE_ID()))->value();
17 AttributePtr aCenterAttr = aData->attribute(SketchPlugin_MultiRotation::CENTER_ID());
18 if (!aCenterAttr || !aCenterAttr->isInitialized()) {
19 myErrorMsg = SketchSolver_Error::NOT_INITIALIZED();
23 myType = CONSTRAINT_MULTI_ROTATION;
25 myStorage->update(aCenterAttr, GID_OUTOFGROUP);
26 theCenter = myStorage->entity(aCenterAttr);
28 getEntitiesAndCopies(theEntities);
31 void SketchSolver_ConstraintMultiRotation::process()
34 if (!myBaseConstraint || !myStorage || myGroupID == GID_UNKNOWN) {
35 /// TODO: Put error message here
39 EntityWrapperPtr aRotationCenter;
40 std::list<std::list<EntityWrapperPtr> > anEntitiesAndCopies;
41 getAttributes(aRotationCenter, myAngle, anEntitiesAndCopies);
42 if (!myErrorMsg.empty())
45 BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
46 std::list<ConstraintWrapperPtr> aRotConstraints;
48 std::list< std::list<EntityWrapperPtr> >::iterator anEntIt = anEntitiesAndCopies.begin();
49 for (; anEntIt != anEntitiesAndCopies.end(); ++anEntIt) {
50 std::list<ConstraintWrapperPtr> aNewConstraints =
51 aBuilder->createConstraint(myBaseConstraint, myGroupID, mySketchID, myType,
52 myAngle, aRotationCenter, EntityWrapperPtr(), *anEntIt);
53 aRotConstraints.insert(aRotConstraints.end(), aNewConstraints.begin(), aNewConstraints.end());
55 myStorage->addConstraint(myBaseConstraint, aRotConstraints);
61 void SketchSolver_ConstraintMultiRotation::updateLocal()
63 double aValue = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
64 myBaseConstraint->attribute(SketchPlugin_MultiRotation::ANGLE_ID()))->value();
65 if (fabs(myAngle - aValue) > tolerance)
71 AttributePtr aCenterAttr = myBaseConstraint->attribute(SketchPlugin_MultiRotation::CENTER_ID());
72 if (myStorage->update(aCenterAttr, myGroupID)) {
73 myStorage->update(aCenterAttr, GID_UNKNOWN);
78 void SketchSolver_ConstraintMultiRotation::adjustConstraint()
80 if (fabs(myAngle) < tolerance) {
81 myStorage->setNeedToResolve(false);
85 const std::list<ConstraintWrapperPtr>& aConstraints = myStorage->constraint(myBaseConstraint);
86 std::list<ConstraintWrapperPtr>::const_iterator aCIt = aConstraints.begin();
87 for (; aCIt != aConstraints.end(); ++aCIt)
88 (*aCIt)->setValue(myAngle);
90 SketchSolver_ConstraintMulti::adjustConstraint();
93 const std::string& SketchSolver_ConstraintMultiRotation::nameNbObjects()
95 return SketchPlugin_MultiRotation::NUMBER_OF_OBJECTS_ID();