1 #include <SketchSolver_ConstraintFixedArcRadius.h>
2 #include <SketchSolver_Error.h>
3 #include <SketchSolver_Manager.h>
5 #include <SketchPlugin_Arc.h>
6 #include <GeomAPI_Pnt2d.h>
8 SketchSolver_ConstraintFixedArcRadius::SketchSolver_ConstraintFixedArcRadius(FeaturePtr theFeature)
9 : SketchSolver_ConstraintFixed(theFeature)
11 myType = CONSTRAINT_RADIUS;
15 void SketchSolver_ConstraintFixedArcRadius::process()
18 if (!myBaseFeature || !myStorage || myGroupID == GID_UNKNOWN) {
19 // Not enough parameters are assigned
23 if (myBaseFeature->getKind() != SketchPlugin_Arc::ID()) {
24 myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
28 ParameterWrapperPtr aValue;
29 std::vector<EntityWrapperPtr> anEntities;
30 getAttributes(aValue, anEntities);
31 if (!myErrorMsg.empty() || anEntities.empty())
33 fixFeature(anEntities.front());
36 void SketchSolver_ConstraintFixedArcRadius::fixFeature(EntityWrapperPtr theFeature)
38 BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
40 // Calculate radius of the arc
41 std::list<EntityWrapperPtr> aSubs = theFeature->subEntities();
42 std::list<EntityWrapperPtr>::const_iterator aSubIt = aSubs.begin();
43 std::shared_ptr<GeomAPI_Pnt2d> aCenter = aBuilder->point(*aSubIt++);
44 std::shared_ptr<GeomAPI_Pnt2d> aStart = aBuilder->point(*aSubIt++);
45 double aRadius = aCenter->distance(aStart);
48 std::list<ConstraintWrapperPtr> aConstrList = aBuilder->createConstraint(ConstraintPtr(),
49 myGroupID, mySketchID, myType, aRadius, EntityWrapperPtr(), EntityWrapperPtr(), theFeature);
50 myRadiusConstraint = aConstrList.front();
51 myStorage->addConstraint(ConstraintPtr(), myRadiusConstraint);
54 bool SketchSolver_ConstraintFixedArcRadius::remove()
56 bool isFullyRemoved = true;
58 isFullyRemoved = myStorage->removeEntity(myBaseFeature) && isFullyRemoved;
59 if (myRadiusConstraint)
60 isFullyRemoved = myStorage->removeConstraint(ConstraintPtr()) &&
61 myStorage->remove(myRadiusConstraint) && isFullyRemoved;
62 return isFullyRemoved;