1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #include <SketchSolver_ConstraintFixedArcRadius.h>
4 #include <SketchSolver_Error.h>
5 #include <SketchSolver_Manager.h>
7 #include <SketchPlugin_Arc.h>
8 #include <GeomAPI_Pnt2d.h>
10 SketchSolver_ConstraintFixedArcRadius::SketchSolver_ConstraintFixedArcRadius(FeaturePtr theFeature)
11 : SketchSolver_ConstraintFixed(theFeature)
13 myType = CONSTRAINT_RADIUS;
17 void SketchSolver_ConstraintFixedArcRadius::process()
20 if (!myBaseFeature || !myStorage || myGroupID == GID_UNKNOWN) {
21 // Not enough parameters are assigned
25 if (myBaseFeature->getKind() != SketchPlugin_Arc::ID()) {
26 myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
30 ParameterWrapperPtr aValue;
31 std::vector<EntityWrapperPtr> anEntities;
32 getAttributes(aValue, anEntities);
33 if (!myErrorMsg.empty() || anEntities.empty())
35 fixFeature(anEntities.front());
38 void SketchSolver_ConstraintFixedArcRadius::fixFeature(EntityWrapperPtr theFeature)
40 BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
42 // Calculate radius of the arc
43 std::list<EntityWrapperPtr> aSubs = theFeature->subEntities();
44 std::list<EntityWrapperPtr>::const_iterator aSubIt = aSubs.begin();
45 std::shared_ptr<GeomAPI_Pnt2d> aCenter = aBuilder->point(*aSubIt++);
46 std::shared_ptr<GeomAPI_Pnt2d> aStart = aBuilder->point(*aSubIt++);
47 double aRadius = aCenter->distance(aStart);
50 std::list<ConstraintWrapperPtr> aConstrList = aBuilder->createConstraint(ConstraintPtr(),
51 myGroupID, mySketchID, myType, aRadius, EntityWrapperPtr(), EntityWrapperPtr(), theFeature);
52 myRadiusConstraint = aConstrList.front();
53 myStorage->addConstraint(ConstraintPtr(), myRadiusConstraint);
56 bool SketchSolver_ConstraintFixedArcRadius::remove()
58 bool isFullyRemoved = true;
60 isFullyRemoved = myStorage->removeEntity(myBaseFeature) && isFullyRemoved;
61 if (myRadiusConstraint)
62 isFullyRemoved = myStorage->removeConstraint(ConstraintPtr()) &&
63 myStorage->remove(myRadiusConstraint) && isFullyRemoved;
64 return isFullyRemoved;