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