Salome HOME
Merge branch 'master' into cgt/devCEA
[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 typedef std::map<ConstraintPtr, SolverConstraintPtr> ConstraintConstraintMap;
21
22 /** \class   SketchSolver_Group
23  *  \ingroup Plugins
24  *  \brief   Keeps the group of constraints which placed in the same sketch
25  */
26 class SketchSolver_Group
27 {
28  public:
29   /** \brief New group based on specified workplane.
30    *         Throws an exception if theWorkplane is not an object of SketchPlugin_Sketch type
31    *  \remark Type of theSketch is not verified inside
32    */
33   SketchSolver_Group(const CompositeFeaturePtr& theWorkplane);
34
35   virtual ~SketchSolver_Group();
36
37   /// \brief Returns true if the group has no constraints yet
38   inline bool isEmpty() const
39   {
40     return myConstraints.empty() && myTempConstraints.empty();
41   }
42
43   /// \brief Check for valid sketch data
44   inline bool isWorkplaneValid() const
45   {
46     return mySketch->data() && mySketch->data()->isValid();
47   }
48
49   /** \brief Adds or updates a constraint in the group
50    *  \param[in] theConstraint constraint to be changed
51    *  \return \c true if the constraint added or updated successfully
52    */
53   bool changeConstraint(std::shared_ptr<SketchPlugin_Constraint> theConstraint);
54
55   /** \brief Updates the data corresponding the specified feature
56    *  \param[in] theFeature the feature to be updated
57    */
58   bool updateFeature(FeaturePtr theFeature);
59
60   /** \brief Updates the data corresponding the specified feature moved in GUI.
61    *         Additional Fixed constraints are created.
62    *  \param[in] theFeature the feature to be updated
63    *  \return \c true, if the feature is moved
64    */
65   bool moveFeature(FeaturePtr theFeature);
66
67   /// Returns the current workplane
68   inline const CompositeFeaturePtr& getWorkplane() const
69   {
70     return mySketch;
71   }
72
73   /** \brief Searches invalid features and constraints in the group and removes them
74    *  \return \c false if the group several constraints were removed
75    */
76   void repairConsistency();
77
78   /** \brief Start solution procedure if necessary and update attributes of features
79    *  \return \c false when no need to solve constraints
80    */
81   bool resolveConstraints();
82
83   /// \brief Block or unblock events sent by features in this group
84   void blockEvents(bool isBlocked);
85
86 private:
87   /// \biref Verify constraints have not been removed
88   bool areConstraintsValid() const;
89
90   /** \brief Removes constraints from the group
91    *  \param[in] theConstraint constraint to be removed
92    */
93   void removeConstraint(ConstraintPtr theConstraint);
94
95   /// \brief Remove all temporary constraints after the computation finished
96   void removeTemporaryConstraints();
97
98   /// \brief Append given constraint to the group of temporary constraints
99   void setTemporary(SolverConstraintPtr theConstraint);
100
101   /// \brief Compute DoF of the sketch and set corresponding field
102   void computeDoF();
103
104 private:
105   CompositeFeaturePtr mySketch; ///< Sketch for this group
106   ConstraintConstraintMap myConstraints; ///< List of constraints
107   std::set<SolverConstraintPtr> myTempConstraints; ///< List of temporary constraints
108
109   StoragePtr myStorage; ///< Container for the set of SolveSpace constraints and their entities
110   SolverPtr mySketchSolver;  ///< Solver for set of equations obtained by constraints
111
112   /// Result of previous solution of the set of constraints
113   PlaneGCSSolver_Solver::SolveStatus myPrevResult;
114   std::set<ObjectPtr>      myConflictingConstraints; ///< List of conflicting constraints
115
116   int  myDOF; ///< degrees of freedom of the current sketch
117
118   bool myIsEventsBlocked; ///< shows the events are blocked for this group
119
120   int myMultiConstraintUpdateStack; ///< depth of the stack updating "Multi" constraints
121 };
122
123 typedef std::shared_ptr<SketchSolver_Group> SketchGroupPtr;
124
125 #endif