Salome HOME
89a9b7acc77aa4d9edd2960c15ce33df67af22e2
[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.h"
11 #include <SketchSolver_Group.h>
12 #include <SketchSolver_Builder.h>
13
14 #include <Events_Listener.h>
15 #include <SketchPlugin_Constraint.h>
16
17 #include <list>
18 #include <set>
19
20 /** \class   SketchSolver_Manager
21  *  \ingroup Plugins
22  *  \brief   Listens the changes of SketchPlugin features and transforms the Constraint
23  *           feature into the format understandable by sketch solver.
24  *
25  *  \remark This is a singleton.
26  */
27 class SketchSolver_Manager : public Events_Listener
28 {
29 public:
30   /** \brief Main method to create constraint manager
31    *  \return pointer to the singleton
32    */
33   static SketchSolver_Manager* instance();
34
35   /** \brief Implementation of Event Listener method
36    *  \param[in] theMessage the data of the event
37    */
38   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
39
40   /**
41    * The solver needs all the updated objects are transfered in one group, not one by one.
42    * This iscreases performance and avoids problems in resolve of only part of the made updates.
43    */
44   virtual bool groupMessages();
45
46   /// \brief Initialize builder for solver's data structure entities
47   /// \param theBuilder [in]  solver's specific builder
48   void setBuilder(BuilderPtr theBuilder);
49   /// \brief Returns the builder specific for the solver
50   BuilderPtr builder();
51
52 protected:
53   SketchSolver_Manager();
54   ~SketchSolver_Manager();
55
56   /** \brief Adds or updates a constraint or an entity in the suitable group
57    *  \param[in] theFeature sketch feature to be changed
58    *  \param[in] theMoved   \c true if the feature has been moved in the viewer
59    *  \return \c true if the feature changed successfully
60    */
61   bool updateFeature(std::shared_ptr<SketchPlugin_Feature> theFeature, bool theMoved = false);
62
63   /** \brief Removes a constraint from the manager
64    *  \param[in] theConstraint constraint to be removed
65    *  \return \c true if the constraint removed successfully
66    */
67   bool removeConstraint(std::shared_ptr<SketchPlugin_Constraint> theConstraint);
68
69   /** \brief Goes through the list of groups and solve the constraints
70    *  \return \c true, if groups are resolved, and features should be updated 
71    *  (send the Update event)
72    */
73   bool resolveConstraints();
74
75 private:
76   /** \brief Searches group which interact with specified feature
77    *  \param[in]  theFeature  object to be found
78    *  \return Pointer to corresponding group or NULL if the group cannot be created.
79    */
80   SketchGroupPtr findGroup(std::shared_ptr<SketchPlugin_Feature> theFeature);
81
82   /// \brief Stop sending the Update event until all features updated
83   /// \return \c true, if the last flushed event is Update
84   bool stopSendUpdate() const;
85   /// \brief Allow to send the Update event
86   void allowSendUpdate() const;
87
88 private:
89   std::list<SketchGroupPtr>   myGroups;  ///< Groups of constraints
90   BuilderPtr                  myBuilder; ///< Builder for solver's entities
91   /// true if computation is performed and all "updates" are generated by this algo
92   /// and needs no recomputation
93   bool myIsComputed;
94 };
95
96 #endif