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