Salome HOME
Merge branch 'master' of newgeom:newgeom
[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 /** \class   SketchSolver_ConstraintManager
24  *  \ingroup DataModel
25  *  \brief   Listens the changes of SketchPlugin features and transforms the Constraint
26  *           feature into the format understandable by SolveSpace library.
27  *
28  *  Constraints created for SolveSpace library are divided into the groups.
29  *  The division order based on connectedness of the features by the constraints.
30  *  The groups may be fused or separated according to the new constraints.
31  *
32  *  \remark This is a singleton.
33  */
34 class SketchSolver_ConstraintManager : public Events_Listener
35 {
36  public:
37   /** \brief Main method to create constraint manager
38    *  \return pointer to the singleton
39    */
40   static SketchSolver_ConstraintManager* Instance();
41
42   /** \brief Implementation of Event Listener method
43    *  \param[in] theMessage the data of the event
44    */
45   virtual void processEvent(const boost::shared_ptr<Events_Message>& theMessage);
46
47  protected:
48   SketchSolver_ConstraintManager();
49   ~SketchSolver_ConstraintManager();
50
51   /** \brief Adds or updates a constraint or an entity in the suitable group
52    *  \param[in] theFeature sketch feature to be changed
53    *  \return \c true if the feature changed successfully
54    */
55   bool changeConstraintOrEntity(boost::shared_ptr<SketchPlugin_Feature> theFeature);
56
57   /** \brief Removes a constraint from the manager
58    *  \param[in] theConstraint constraint to be removed
59    *  \return \c true if the constraint removed successfully
60    */
61   bool removeConstraint(boost::shared_ptr<SketchPlugin_Constraint> theConstraint);
62
63   /** \brief Adds or updates a workplane in the manager
64    *  \param[in] theSketch the feature to create or update workplane
65    *  \return \c true if the workplane changed successfully
66    *  \remark Type of theSketch is not verified inside
67    */
68   bool changeWorkplane(boost::shared_ptr<ModelAPI_CompositeFeature> theSketch);
69
70   /** \brief Removes a workplane from the manager.
71    *         All groups based on such workplane will be removed too.
72    *  \param[in] theSketch the feature to be removed
73    *  \return \c true if the workplane removed successfully
74    */
75   bool removeWorkplane(boost::shared_ptr<SketchPlugin_Sketch> theSketch);
76
77   /** \brief Updates entity which is neither workplane nor constraint
78    *  \param[in] theFeature entity to be updated
79    */
80   void updateEntity(boost::shared_ptr<SketchPlugin_Feature> theFeature);
81
82   /** \brief Goes through the list of groups and solve the constraints
83    */
84   void resolveConstraints();
85
86  private:
87   /** \brief Searches list of groups which interact with specified feature
88    *  \param[in]  theFeature  object to be found
89    *  \param[out] theGroups   list of group indexes interacted with the feature
90    */
91   void findGroups(boost::shared_ptr<SketchPlugin_Feature> theFeature,
92                   std::set<Slvs_hGroup>& theGroupIDs) const;
93
94   /** \brief Searches in the list of groups the workplane which constains specified feature
95    *  \param[in] theFeature object to be found
96    *  \return workplane containing the feature
97    */
98   boost::shared_ptr<ModelAPI_CompositeFeature> findWorkplane(
99       boost::shared_ptr<SketchPlugin_Feature> theFeature) const;
100
101  private:
102   static SketchSolver_ConstraintManager* _self;  ///< Self pointer to implement singleton functionality
103   std::vector<SketchSolver_ConstraintGroup*> myGroups;  ///< Groups of constraints
104 };
105
106 #endif