Salome HOME
SketchSolver library refactoring
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintManager.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:    SketchSolver_ConstraintManager.h
4 // Created: 08 May 2014
5 // Author:  Artem ZHIDKOV
6
7 #ifndef SketchSolver_ConstraintManager_H_
8 #define SketchSolver_ConstraintManager_H_
9
10 #include "SketchSolver.h"
11 #include <SketchSolver_Solver.h>
12 #include <SketchSolver_Group.h>
13
14 #include <Events_Listener.h>
15 #include <SketchPlugin_Constraint.h>
16
17 #include <string.h>
18 #include <slvs.h>
19
20 #include <list>
21 #include <map>
22 #include <vector>
23 #include <set>
24
25 /** \class   SketchSolver_ConstraintManager
26  *  \ingroup Plugins
27  *  \brief   Listens the changes of SketchPlugin features and transforms the Constraint
28  *           feature into the format understandable by SolveSpace library.
29  *
30  *  Constraints created for SolveSpace library are divided into the groups.
31  *  The division order based on connectedness of the features by the constraints.
32  *  The groups may be fused or separated according to the new constraints.
33  *
34  *  \remark This is a singleton.
35  */
36 class SketchSolver_ConstraintManager : public Events_Listener
37 {
38  public:
39   /** \brief Main method to create constraint manager
40    *  \return pointer to the singleton
41    */
42   static SketchSolver_ConstraintManager* Instance();
43
44   /** \brief Implementation of Event Listener method
45    *  \param[in] theMessage the data of the event
46    */
47   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
48
49  protected:
50   SketchSolver_ConstraintManager();
51   ~SketchSolver_ConstraintManager();
52
53   /** \brief Adds or updates a constraint or an entity in the suitable group
54    *  \param[in] theFeature sketch feature to be changed
55    *  \return \c true if the feature changed successfully
56    */
57   bool changeConstraintOrEntity(std::shared_ptr<SketchPlugin_Feature> theFeature);
58
59   /** \brief Removes a constraint from the manager
60    *  \param[in] theConstraint constraint to be removed
61    *  \return \c true if the constraint removed successfully
62    */
63   bool removeConstraint(std::shared_ptr<SketchPlugin_Constraint> theConstraint);
64
65   /** \brief Adds or updates a workplane in the manager
66    *  \param[in] theSketch the feature to create or update workplane
67    *  \return \c true if the workplane changed successfully
68    *  \remark Type of theSketch is not verified inside
69    */
70   bool changeWorkplane(CompositeFeaturePtr theSketch);
71
72   /** \brief Removes a workplane from the manager.
73    *         All groups based on such workplane will be removed too.
74    *  \param[in] theSketch the feature to be removed
75    *  \return \c true if the workplane removed successfully
76    */
77   bool removeWorkplane(std::shared_ptr<SketchPlugin_Sketch> theSketch);
78
79   /** \brief Updates entity which is moved in GUI
80    *  \param[in] theFeature entity to be updated
81    */
82   void moveEntity(std::shared_ptr<SketchPlugin_Feature> theFeature);
83
84   /** \brief Goes through the list of groups and solve the constraints
85    *  \param theForceUpdate flushes the update event in any case: something changed or not
86    */
87   void resolveConstraints(const bool theForceUpdate);
88
89  private:
90   /** \brief Searches list of groups which interact with specified feature
91    *  \param[in]  theFeature  object to be found
92    *  \param[out] theGroups   list of group indexes interacted with the feature
93    */
94   void findGroups(std::shared_ptr<SketchPlugin_Feature> theFeature,
95                   std::set<Slvs_hGroup>& theGroupIDs) const;
96
97   /** \brief Searches in the list of groups the workplane which constains specified feature
98    *  \param[in] theFeature object to be found
99    *  \return workplane containing the feature
100    */
101   std::shared_ptr<ModelAPI_CompositeFeature> findWorkplane(
102       std::shared_ptr<SketchPlugin_Feature> theFeature) const;
103
104  private:
105   static SketchSolver_ConstraintManager* _self;  ///< Self pointer to implement singleton functionality
106   std::vector<SketchSolver_Group*> myGroups;  ///< Groups of constraints
107   /// true if computation is performed and all "updates" are generated by this algo
108   /// and needs no recomputation
109   bool myIsComputed;
110 };
111
112 #endif