1 #include <SketchSolver_ConstraintFixed.h>
2 #include <SketchSolver_Error.h>
3 #include <SketchSolver_Manager.h>
5 #include <SketchPlugin_Arc.h>
6 #include <SketchPlugin_Circle.h>
7 #include <SketchPlugin_ConstraintRigid.h>
8 #include <SketchPlugin_Line.h>
9 #include <SketchPlugin_Point.h>
11 #include <GeomAPI_Pnt2d.h>
12 #include <GeomAPI_XY.h>
13 #include <GeomDataAPI_Point2D.h>
14 #include <ModelAPI_AttributeDouble.h>
18 SketchSolver_ConstraintFixed::SketchSolver_ConstraintFixed(ConstraintPtr theConstraint)
19 : SketchSolver_Constraint()
21 myBaseConstraint = theConstraint;
22 myType = CONSTRAINT_FIXED;
23 myFixedAttribute = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
24 theConstraint->attribute(SketchPlugin_ConstraintRigid::ENTITY_A()));
27 SketchSolver_ConstraintFixed::SketchSolver_ConstraintFixed(FeaturePtr theFeature)
28 : SketchSolver_Constraint(),
29 myBaseFeature(theFeature)
31 myType = CONSTRAINT_FIXED;
35 void SketchSolver_ConstraintFixed::process()
38 if ((!myBaseConstraint && !myBaseFeature) || !myStorage || myGroupID == GID_UNKNOWN) {
39 // Not enough parameters are assigned
43 ParameterWrapperPtr aValue;
44 std::vector<EntityWrapperPtr> anEntities;
45 getAttributes(aValue, anEntities);
46 if (!myErrorMsg.empty() || anEntities.empty())
48 fixFeature(anEntities.front());
51 void SketchSolver_ConstraintFixed::fixFeature(EntityWrapperPtr theFeature)
53 // extract feature from the group
54 if (theFeature->baseAttribute())
55 myStorage->update(theFeature->baseAttribute(), GID_OUTOFGROUP);
56 else if (theFeature->baseFeature())
57 myStorage->update(theFeature->baseFeature(), GID_OUTOFGROUP);
60 void SketchSolver_ConstraintFixed::getAttributes(
61 ParameterWrapperPtr& theValue,
62 std::vector<EntityWrapperPtr>& theAttributes)
64 BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
66 EntityWrapperPtr aSolverEntity;
68 // The feature is fixed.
69 myStorage->update(myBaseFeature, myGroupID);
70 aSolverEntity = myStorage->entity(myBaseFeature);
71 } else if (myBaseConstraint) {
72 // Constraint Fixed is added by user.
73 // Get the attribute of constraint (it should be alone in the list of constraints).
74 AttributePtr anAttr = myBaseConstraint->attribute(SketchPlugin_ConstraintRigid::ENTITY_A());
75 AttributeRefAttrPtr aRefAttr =
76 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttr);
77 if (!aRefAttr || !aRefAttr->isInitialized()) {
78 myErrorMsg = SketchSolver_Error::NOT_INITIALIZED();
82 myStorage->update(anAttr, myGroupID);
83 aSolverEntity = myStorage->entity(anAttr);
85 myErrorMsg = SketchSolver_Error::NOT_INITIALIZED();
88 theAttributes.push_back(aSolverEntity);
92 bool SketchSolver_ConstraintFixed::remove()
95 // Move fixed entities back to the current group
96 FeaturePtr aFeature = myBaseFeature;
97 if (myBaseConstraint && myFixedAttribute) {
98 if (myFixedAttribute->isObject())
99 aFeature = ModelAPI_Feature::feature(myFixedAttribute->object());
101 myStorage->update(AttributePtr(myFixedAttribute), myGroupID);
104 myStorage->update(aFeature, myGroupID);
106 // Remove constraint or base feature
107 if (myBaseConstraint) {
108 bool isRemoved = false;
110 isRemoved = myStorage->removeEntity(aFeature);
111 return SketchSolver_Constraint::remove() || isRemoved;
112 } else if (myBaseFeature)
113 myStorage->removeEntity(myBaseFeature);