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 mySolverConstraint = fixFeature(aMovedEntity);
53 myStorage->addMovementConstraint(mySolverConstraint);
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 EntityWrapperPtr anEntity =
68 myDraggedPoint ? myStorage->entity(myDraggedPoint) : myStorage->entity(myMovedFeature);
70 myStorage->update(myMovedFeature, true);
71 anEntity = myStorage->entity(myMovedFeature);
76 void SketchSolver_ConstraintMovement::moveTo(
77 const std::shared_ptr<GeomAPI_Pnt2d>& theDestinationPoint)
79 EntityWrapperPtr aMovedEntity =
80 myDraggedPoint ? myStorage->entity(myDraggedPoint) : myStorage->entity(myMovedFeature);
84 double aDelta[2] = { theDestinationPoint->x() - myStartPoint->x(),
85 theDestinationPoint->y() - myStartPoint->y() };
87 GCS::VEC_pD aFixedParams = toParameters(aMovedEntity);
88 for (int i = 0; i < aFixedParams.size() && i < myFixedValues.size(); ++i)
89 myFixedValues[i] = *(aFixedParams[i]) + aDelta[i % 2];
91 // no persistent constraints in the storage, thus store values directly to the feature
92 if (myStorage->isEmpty()) {
93 for (int i = 0; i < aFixedParams.size() && i < myFixedValues.size(); ++i)
94 *(aFixedParams[i]) = myFixedValues[i];
95 myStorage->setNeedToResolve(true);