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