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   /** \brief Updates the data corresponding the specified feature moved in GUI.
63    *         Special kind of Fixed constraints is created.
64    *  \param[in] theFeature the feature to be updated
65    *  \param[in] theFrom    start point of the movement
66    *  \param[in] theTo      final point of the movement
67    *  \return \c true, if the feature is really moved
68    */
69   bool moveFeature(FeaturePtr theFeature,
70                    const std::shared_ptr<GeomAPI_Pnt2d>& theFrom,
71                    const std::shared_ptr<GeomAPI_Pnt2d>& theTo);
72   /** \brief Updates the data corresponding the specified point moved in GUI.
73    *         Special kind of Fixed constraints is created.
74    *  \param[in] thePoint the attribute to be updated
75    *  \param[in] theFrom  start point of the movement
76    *  \param[in] theTo    final point of the movement
77    *  \return \c true, if the attribute is really moved
78    */
79   bool movePoint(AttributePtr thePoint,
80                  const std::shared_ptr<GeomAPI_Pnt2d>& theFrom,
81                  const std::shared_ptr<GeomAPI_Pnt2d>& theTo);
82
83   /// Returns the current workplane
84   inline const CompositeFeaturePtr& getWorkplane() const
85   {
86     return mySketch;
87   }
88
89   /** \brief Searches invalid features and constraints in the group and removes them
90    *  \return \c false if the group several constraints were removed
91    */
92   void repairConsistency();
93
94   /** \brief Start solution procedure if necessary and update attributes of features
95    *  \return \c false when no need to solve constraints
96    */
97   bool resolveConstraints();
98
99   /// \brief Block or unblock events sent by features in this group
100   void blockEvents(bool isBlocked);
101
102 private:
103   /// \biref Verify constraints have not been removed
104   bool areConstraintsValid() const;
105
106   /** \brief Removes constraints from the group
107    *  \param[in] theConstraint constraint to be removed
108    */
109   void removeConstraint(ConstraintPtr theConstraint);
110
111   /// \brief Remove all temporary constraints after the computation finished
112   void removeTemporaryConstraints();
113
114   /// \brief Append given constraint to the group of temporary constraints
115   void setTemporary(SolverConstraintPtr theConstraint);
116
117   /// \brief Compute DoF of the sketch and set corresponding field
118   void computeDoF();
119
120 private:
121   CompositeFeaturePtr mySketch; ///< Sketch for this group
122   ConstraintConstraintMap myConstraints; ///< List of constraints
123   std::set<SolverConstraintPtr> myTempConstraints; ///< List of temporary constraints
124
125   StoragePtr myStorage; ///< Container for the set of SolveSpace constraints and their entities
126   SolverPtr mySketchSolver;  ///< Solver for set of equations obtained by constraints
127
128   /// Result of previous solution of the set of constraints
129   PlaneGCSSolver_Solver::SolveStatus myPrevResult;
130   std::set<ObjectPtr>      myConflictingConstraints; ///< List of conflicting constraints
131
132   int  myDOF; ///< degrees of freedom of the current sketch
133
134   bool myIsEventsBlocked; ///< shows the events are blocked for this group
135
136   int myMultiConstraintUpdateStack; ///< depth of the stack updating "Multi" constraints
137 };
138
139 typedef std::shared_ptr<SketchSolver_Group> SketchGroupPtr;
140
141 #endif