1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #include <SketchSolver_ConstraintMovement.h>
4 #include <SketchSolver_Error.h>
5 #include <SketchSolver_Manager.h>
7 #include <SketchPlugin_Arc.h>
8 #include <SketchPlugin_Circle.h>
9 #include <SketchPlugin_Line.h>
10 #include <SketchPlugin_Point.h>
12 #include <GeomDataAPI_Point2D.h>
14 #include <GeomAPI_Pnt2d.h>
17 SketchSolver_ConstraintMovement::SketchSolver_ConstraintMovement(FeaturePtr theFeature)
18 : SketchSolver_ConstraintFixed(ConstraintPtr()),
19 myMovedFeature(theFeature)
23 SketchSolver_ConstraintMovement::SketchSolver_ConstraintMovement(AttributePtr thePoint)
24 : SketchSolver_ConstraintFixed(ConstraintPtr()),
25 myDraggedPoint(thePoint)
27 myMovedFeature = ModelAPI_Feature::feature(thePoint->owner());
30 void SketchSolver_ConstraintMovement::blockEvents(bool isBlocked)
33 myMovedFeature->data()->blockSendAttributeUpdated(isBlocked);
36 void SketchSolver_ConstraintMovement::process()
39 if (!myMovedFeature || !myStorage) {
40 // Not enough parameters are initialized
44 EntityWrapperPtr aMovedEntity = entityToFix();
45 if (!myErrorMsg.empty() || !aMovedEntity) {
46 // Nothing to move, clear the feature to avoid changing its group
47 // after removing the Movement constraint.
48 myMovedFeature = FeaturePtr();
52 ConstraintWrapperPtr aConstraint = fixFeature(aMovedEntity);
53 myStorage->addMovementConstraint(aConstraint);
57 EntityWrapperPtr SketchSolver_ConstraintMovement::entityToFix()
59 // if the feature is copy, do not move it
60 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
61 std::dynamic_pointer_cast<SketchPlugin_Feature>(myMovedFeature);
62 if (!aSketchFeature || aSketchFeature->isCopy()) {
63 myStorage->setNeedToResolve(true);
64 return EntityWrapperPtr();
67 return myStorage->entity(myMovedFeature);
70 void SketchSolver_ConstraintMovement::moveTo(
71 const std::shared_ptr<GeomAPI_Pnt2d>& theDestinationPoint)
73 #ifdef SUPPORT_NEW_MOVE
74 EntityWrapperPtr aMovedEntity = myStorage->entity(myMovedFeature);
78 double aDelta[2] = { theDestinationPoint->x() - myStartPoint->x(),
79 theDestinationPoint->y() - myStartPoint->y() };
81 GCS::VEC_pD aFixedParams = toParameters(aMovedEntity);
82 for (int i = 0; i < aFixedParams.size() && i < myFixedValues.size(); ++i)
83 myFixedValues[i] = *(aFixedParams[i]) + aDelta[i % 2];