Salome HOME
Task 2.4. Ability to modify the radius of circles and arcs of circle with the mouse
[modules/shaper.git] / src / SketchSolver / SketchSolver_Group.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:    SketchSolver_Group.h
4 // Created: 27 May 2014
5 // Author:  Artem ZHIDKOV
6
7 #ifndef SketchSolver_Group_H_
8 #define SketchSolver_Group_H_
9
10 #include <SketchSolver_Constraint.h>
11 #include <SketchSolver_Storage.h>
12
13 #include <PlaneGCSSolver_Solver.h>
14
15 #include <SketchPlugin_Constraint.h>
16
17 #include <memory>
18 #include <map>
19
20 class GeomAPI_Pnt2d;
21
22 typedef std::map<ConstraintPtr, SolverConstraintPtr> ConstraintConstraintMap;
23
24 /** \class   SketchSolver_Group
25  *  \ingroup Plugins
26  *  \brief   Keeps the group of constraints which placed in the same sketch
27  */
28 class SketchSolver_Group
29 {
30  public:
31   /** \brief New group based on specified workplane.
32    *         Throws an exception if theWorkplane is not an object of SketchPlugin_Sketch type
33    *  \remark Type of theSketch is not verified inside
34    */
35   SketchSolver_Group(const CompositeFeaturePtr& theWorkplane);
36
37   virtual ~SketchSolver_Group();
38
39   /// \brief Returns true if the group has no constraints yet
40   inline bool isEmpty() const
41   {
42     return myConstraints.empty() && myTempConstraints.empty();
43   }
44
45   /// \brief Check for valid sketch data
46   inline bool isWorkplaneValid() const
47   {
48     return mySketch->data() && mySketch->data()->isValid();
49   }
50
51   /** \brief Adds or updates a constraint in the group
52    *  \param[in] theConstraint constraint to be changed
53    *  \return \c true if the constraint added or updated successfully
54    */
55   bool changeConstraint(std::shared_ptr<SketchPlugin_Constraint> theConstraint);
56
57   /** \brief Updates the data corresponding the specified feature
58    *  \param[in] theFeature the feature to be updated
59    */
60   bool updateFeature(FeaturePtr theFeature);
61
62 #ifdef SUPPORT_NEW_MOVE
63   /** \brief Updates the data corresponding the specified feature moved in GUI.
64    *         Special kind of Fixed constraints is created.
65    *  \param[in] theFeature the feature to be updated
66    *  \param[in] theFrom    start point of the movement
67    *  \param[in] theTo      final point of the movement
68    *  \return \c true, if the feature is really moved
69    */
70   bool moveFeature(FeaturePtr theFeature,
71                    const std::shared_ptr<GeomAPI_Pnt2d>& theFrom,
72                    const std::shared_ptr<GeomAPI_Pnt2d>& theTo);
73   /** \brief Updates the data corresponding the specified point moved in GUI.
74    *         Special kind of Fixed constraints is created.
75    *  \param[in] thePoint the attribute to be updated
76    *  \param[in] theFrom  start point of the movement
77    *  \param[in] theTo    final point of the movement
78    *  \return \c true, if the attribute is really moved
79    */
80   bool movePoint(AttributePtr thePoint,
81                  const std::shared_ptr<GeomAPI_Pnt2d>& theFrom,
82                  const std::shared_ptr<GeomAPI_Pnt2d>& theTo);
83 #else
84   /** \brief Updates the data corresponding the specified feature moved in GUI.
85    *         Additional Fixed constraints are created.
86    *  \param[in] theFeature the feature to be updated
87    *  \return \c true, if the feature is moved
88    */
89   bool moveFeature(FeaturePtr theFeature);
90 #endif
91
92   /// Returns the current workplane
93   inline const CompositeFeaturePtr& getWorkplane() const
94   {
95     return mySketch;
96   }
97
98   /** \brief Searches invalid features and constraints in the group and removes them
99    *  \return \c false if the group several constraints were removed
100    */
101   void repairConsistency();
102
103   /** \brief Start solution procedure if necessary and update attributes of features
104    *  \return \c false when no need to solve constraints
105    */
106   bool resolveConstraints();
107
108   /// \brief Block or unblock events sent by features in this group
109   void blockEvents(bool isBlocked);
110
111 private:
112   /// \biref Verify constraints have not been removed
113   bool areConstraintsValid() const;
114
115   /** \brief Removes constraints from the group
116    *  \param[in] theConstraint constraint to be removed
117    */
118   void removeConstraint(ConstraintPtr theConstraint);
119
120   /// \brief Remove all temporary constraints after the computation finished
121   void removeTemporaryConstraints();
122
123   /// \brief Append given constraint to the group of temporary constraints
124   void setTemporary(SolverConstraintPtr theConstraint);
125
126   /// \brief Compute DoF of the sketch and set corresponding field
127   void computeDoF();
128
129 private:
130   CompositeFeaturePtr mySketch; ///< Sketch for this group
131   ConstraintConstraintMap myConstraints; ///< List of constraints
132   std::set<SolverConstraintPtr> myTempConstraints; ///< List of temporary constraints
133
134   StoragePtr myStorage; ///< Container for the set of SolveSpace constraints and their entities
135   SolverPtr mySketchSolver;  ///< Solver for set of equations obtained by constraints
136
137   /// Result of previous solution of the set of constraints
138   PlaneGCSSolver_Solver::SolveStatus myPrevResult;
139   std::set<ObjectPtr>      myConflictingConstraints; ///< List of conflicting constraints
140
141   int  myDOF; ///< degrees of freedom of the current sketch
142
143   bool myIsEventsBlocked; ///< shows the events are blocked for this group
144
145   int myMultiConstraintUpdateStack; ///< depth of the stack updating "Multi" constraints
146 };
147
148 typedef std::shared_ptr<SketchSolver_Group> SketchGroupPtr;
149
150 #endif