]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchSolver/SketchSolver_ConstraintMovement.cpp
Salome HOME
850a8c92d1964f44c566aceb91de3f7d75006917
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintMovement.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 #include <SketchSolver_ConstraintMovement.h>
4 #include <SketchSolver_Error.h>
5 #include <SketchSolver_Manager.h>
6
7 #include <SketchPlugin_Arc.h>
8 #include <SketchPlugin_Circle.h>
9 #include <SketchPlugin_Line.h>
10 #include <SketchPlugin_Point.h>
11
12 #include <GeomDataAPI_Point2D.h>
13
14 #include <GeomAPI_Pnt2d.h>
15
16
17 SketchSolver_ConstraintMovement::SketchSolver_ConstraintMovement(FeaturePtr theFeature)
18   : SketchSolver_ConstraintFixed(ConstraintPtr()),
19     myMovedFeature(theFeature)
20 {
21 }
22
23 SketchSolver_ConstraintMovement::SketchSolver_ConstraintMovement(AttributePtr thePoint)
24   : SketchSolver_ConstraintFixed(ConstraintPtr()),
25     myDraggedPoint(thePoint)
26 {
27   myMovedFeature = ModelAPI_Feature::feature(thePoint->owner());
28 }
29
30 void SketchSolver_ConstraintMovement::blockEvents(bool isBlocked)
31 {
32   if (myMovedFeature)
33     myMovedFeature->data()->blockSendAttributeUpdated(isBlocked);
34 }
35
36 void SketchSolver_ConstraintMovement::process()
37 {
38   cleanErrorMsg();
39   if (!myMovedFeature || !myStorage) {
40     // Not enough parameters are initialized
41     return;
42   }
43
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();
49     return;
50   }
51
52   ConstraintWrapperPtr aConstraint = fixFeature(aMovedEntity);
53   myStorage->addMovementConstraint(aConstraint);
54 }
55
56
57 EntityWrapperPtr SketchSolver_ConstraintMovement::entityToFix()
58 {
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();
65   }
66
67   return myStorage->entity(myMovedFeature);
68 }
69
70 void SketchSolver_ConstraintMovement::moveTo(
71     const std::shared_ptr<GeomAPI_Pnt2d>& theDestinationPoint)
72 {
73 #ifdef SUPPORT_NEW_MOVE
74   EntityWrapperPtr aMovedEntity = myStorage->entity(myMovedFeature);
75   if (!aMovedEntity)
76     return;
77
78   double aDelta[2] = { theDestinationPoint->x() - myStartPoint->x(),
79                        theDestinationPoint->y() - myStartPoint->y() };
80
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];
84
85 #endif
86 }