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 AttributeRefAttrPtr anAttribute =
24 theConstraint->refattr(SketchPlugin_ConstraintRigid::ENTITY_A());
25 if (anAttribute->isObject())
26 myFixedFeature = ModelAPI_Feature::feature(anAttribute->object());
28 myFixedAttribute = anAttribute->attr();
31 SketchSolver_ConstraintFixed::SketchSolver_ConstraintFixed(FeaturePtr theFeature)
32 : SketchSolver_Constraint(),
33 myBaseFeature(theFeature)
35 myType = CONSTRAINT_FIXED;
39 void SketchSolver_ConstraintFixed::process()
42 if ((!myBaseConstraint && !myBaseFeature) || !myStorage || myGroupID == GID_UNKNOWN) {
43 // Not enough parameters are assigned
47 ParameterWrapperPtr aValue;
48 std::vector<EntityWrapperPtr> anEntities;
49 getAttributes(aValue, anEntities);
50 if (!myErrorMsg.empty() || anEntities.empty())
52 fixFeature(anEntities.front());
55 void SketchSolver_ConstraintFixed::fixFeature(EntityWrapperPtr theFeature)
57 // extract feature from the group
58 if (theFeature->baseAttribute())
59 myStorage->update(theFeature->baseAttribute(), GID_OUTOFGROUP);
60 else if (theFeature->baseFeature())
61 myStorage->update(theFeature->baseFeature(), GID_OUTOFGROUP);
64 myStorage->addConstraint(myBaseConstraint, std::list<ConstraintWrapperPtr>());
67 void SketchSolver_ConstraintFixed::getAttributes(
68 ParameterWrapperPtr& theValue,
69 std::vector<EntityWrapperPtr>& theAttributes)
71 BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
73 EntityWrapperPtr aSolverEntity;
75 // The feature is fixed.
76 myStorage->update(myBaseFeature/*, myGroupID*/);
77 aSolverEntity = myStorage->entity(myBaseFeature);
78 } else if (myBaseConstraint) {
79 // Constraint Fixed is added by user.
80 // Get the attribute of constraint (it should be alone in the list of constraints).
81 AttributePtr anAttr = myBaseConstraint->attribute(SketchPlugin_ConstraintRigid::ENTITY_A());
82 AttributeRefAttrPtr aRefAttr =
83 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttr);
84 if (!aRefAttr || !aRefAttr->isInitialized()) {
85 myErrorMsg = SketchSolver_Error::NOT_INITIALIZED();
89 myStorage->update(anAttr, myGroupID);
90 aSolverEntity = myStorage->entity(anAttr);
92 myErrorMsg = SketchSolver_Error::NOT_INITIALIZED();
95 theAttributes.push_back(aSolverEntity);
99 bool SketchSolver_ConstraintFixed::remove()
102 // Move fixed entities back to the current group
103 FeaturePtr aFeature = myBaseFeature;
104 if (myBaseConstraint) {
106 aFeature = myFixedFeature;
107 else if (myFixedAttribute)
108 myStorage->update(AttributePtr(myFixedAttribute), myGroupID);
111 myStorage->update(aFeature, myGroupID);
112 myStorage->setNeedToResolve(true);
114 // Remove constraint or base feature
115 if (myBaseConstraint) {
116 bool isRemoved = false;
118 isRemoved = myStorage->removeEntity(aFeature);
119 return SketchSolver_Constraint::remove() || isRemoved;
120 } else if (myBaseFeature)
121 myStorage->removeEntity(myBaseFeature);