Salome HOME
Sketcher: Remove obsolete interfaces. Code cleanup.
[modules/shaper.git] / src / SketchSolver / SketchSolver_Manager.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:    SketchSolver_Manager.h
4 // Created: 08 May 2014
5 // Author:  Artem ZHIDKOV
6
7 #ifndef SketchSolver_Manager_H_
8 #define SketchSolver_Manager_H_
9
10 #include <SketchSolver_Group.h>
11
12 #include <Events_Listener.h>
13 #include <SketchPlugin_Constraint.h>
14
15 #include <list>
16 #include <set>
17
18 /** \class   SketchSolver_Manager
19  *  \ingroup Plugins
20  *  \brief   Listens the changes of SketchPlugin features and transforms the Constraint
21  *           feature into the format understandable by sketch solver.
22  *
23  *  \remark This is a singleton.
24  */
25 class SketchSolver_Manager : public Events_Listener
26 {
27 public:
28   /** \brief Main method to create constraint manager
29    *  \return pointer to the singleton
30    */
31   static SketchSolver_Manager* instance();
32
33   /** \brief Implementation of Event Listener method
34    *  \param[in] theMessage the data of the event
35    */
36   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
37
38   /**
39    * The solver needs all the updated objects are transfered in one group, not one by one.
40    * This iscreases performance and avoids problems in resolve of only part of the made updates.
41    */
42   virtual bool groupMessages();
43
44 protected:
45   SketchSolver_Manager();
46   ~SketchSolver_Manager();
47
48   /** \brief Adds or updates a constraint or an entity in the suitable group
49    *  \param[in] theFeature sketch feature to be changed
50    *  \param[in] theMoved   \c true if the feature has been moved in the viewer
51    *  \return \c true if the feature changed successfully
52    */
53   bool updateFeature(std::shared_ptr<SketchPlugin_Feature> theFeature, bool theMoved = false);
54
55   /** \brief Removes a constraint from the manager
56    *  \param[in] theConstraint constraint to be removed
57    *  \return \c true if the constraint removed successfully
58    */
59   bool removeConstraint(std::shared_ptr<SketchPlugin_Constraint> theConstraint);
60
61   /** \brief Goes through the list of groups and solve the constraints
62    *  \return \c true, if groups are resolved, and features should be updated 
63    *  (send the Update event)
64    */
65   bool resolveConstraints();
66
67 private:
68   /** \brief Searches group which interact with specified feature
69    *  \param[in]  theFeature  object to be found
70    *  \return Pointer to corresponding group or NULL if the group cannot be created.
71    */
72   SketchGroupPtr findGroup(std::shared_ptr<SketchPlugin_Feature> theFeature);
73
74   /// \brief Stop sending the Update event until all features updated
75   /// \return \c true, if the last flushed event is Update
76   bool stopSendUpdate() const;
77   /// \brief Allow to send the Update event
78   void allowSendUpdate() const;
79
80 private:
81   std::list<SketchGroupPtr>   myGroups;  ///< Groups of constraints
82   /// true if computation is performed and all "updates" are generated by this algo
83   /// and needs no recomputation
84   bool myIsComputed;
85 };
86
87 #endif