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 myStorage->addConstraint(myBaseConstraint, std::list<ConstraintWrapperPtr>());
63 void SketchSolver_ConstraintFixed::getAttributes(
64 ParameterWrapperPtr& theValue,
65 std::vector<EntityWrapperPtr>& theAttributes)
67 BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
69 EntityWrapperPtr aSolverEntity;
71 // The feature is fixed.
72 myStorage->update(myBaseFeature/*, myGroupID*/);
73 aSolverEntity = myStorage->entity(myBaseFeature);
74 } else if (myBaseConstraint) {
75 // Constraint Fixed is added by user.
76 // Get the attribute of constraint (it should be alone in the list of constraints).
77 AttributePtr anAttr = myBaseConstraint->attribute(SketchPlugin_ConstraintRigid::ENTITY_A());
78 AttributeRefAttrPtr aRefAttr =
79 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttr);
80 if (!aRefAttr || !aRefAttr->isInitialized()) {
81 myErrorMsg = SketchSolver_Error::NOT_INITIALIZED();
85 myStorage->update(anAttr, myGroupID);
86 aSolverEntity = myStorage->entity(anAttr);
88 myErrorMsg = SketchSolver_Error::NOT_INITIALIZED();
91 theAttributes.push_back(aSolverEntity);
95 bool SketchSolver_ConstraintFixed::remove()
98 // Move fixed entities back to the current group
99 FeaturePtr aFeature = myBaseFeature;
100 if (myBaseConstraint && myFixedAttribute) {
101 if (myFixedAttribute->isObject())
102 aFeature = ModelAPI_Feature::feature(myFixedAttribute->object());
104 if (myFixedAttribute->attr().get())
105 myStorage->update(AttributePtr(myFixedAttribute), myGroupID);
109 myStorage->update(aFeature, myGroupID);
111 // Remove constraint or base feature
112 if (myBaseConstraint) {
113 bool isRemoved = false;
115 isRemoved = myStorage->removeEntity(aFeature);
116 return SketchSolver_Constraint::remove() || isRemoved;
117 } else if (myBaseFeature)
118 myStorage->removeEntity(myBaseFeature);