]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchSolver/SketchSolver_Manager.h
Salome HOME
Task 2.4. Ability to modify the radius of circles and arcs of circle with the mouse
[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
14 #include <list>
15 #include <set>
16
17 class GeomAPI_Pnt2d;
18 class GeomDataAPI_Point2D;
19 class SketchPlugin_Constraint;
20
21 /** \class   SketchSolver_Manager
22  *  \ingroup Plugins
23  *  \brief   Listens the changes of SketchPlugin features and transforms the Constraint
24  *           feature into the format understandable by sketch solver.
25  *
26  *  \remark This is a singleton.
27  */
28 class SketchSolver_Manager : public Events_Listener
29 {
30 public:
31   /** \brief Main method to create constraint manager
32    *  \return pointer to the singleton
33    */
34   static SketchSolver_Manager* instance();
35
36   /** \brief Implementation of Event Listener method
37    *  \param[in] theMessage the data of the event
38    */
39   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
40
41   /**
42    * The solver needs all the updated objects are transfered in one group, not one by one.
43    * This iscreases performance and avoids problems in resolve of only part of the made updates.
44    */
45   virtual bool groupMessages();
46
47 protected:
48   SketchSolver_Manager();
49   ~SketchSolver_Manager();
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 updateFeature(const std::shared_ptr<SketchPlugin_Feature>& theFeature);
56
57   /** \brief Move feature
58    *  \param[in] theMovedFeature dragged sketch feature
59    *  \param[in] theFromPoint    original position of the feature
60    *  \param[in] theToPoint      prefereble position of the feature (current position of the mouse)
61    *  \return \c true if the feature has been changed successfully
62    */
63   bool moveFeature(const std::shared_ptr<SketchPlugin_Feature>& theMovedFeature,
64                    const std::shared_ptr<GeomAPI_Pnt2d>& theFromPoint,
65                    const std::shared_ptr<GeomAPI_Pnt2d>& theToPoint);
66
67   /** \brief Move feature using its moved attribute
68    *  \param[in] theMovedAttribute dragged point attribute of sketch feature
69    *  \param[in] theFromPoint      original position of the moved point
70    *  \param[in] theToPoint        prefereble position (current position of the mouse)
71    *  \return \c true if the attribute owner has been changed successfully
72    */
73   bool moveAttribute(const std::shared_ptr<GeomDataAPI_Point2D>& theMovedAttribute,
74                      const std::shared_ptr<GeomAPI_Pnt2d>& theFromPoint,
75                      const std::shared_ptr<GeomAPI_Pnt2d>& theToPoint);
76
77   /** \brief Removes a constraint from the manager
78    *  \param[in] theConstraint constraint to be removed
79    *  \return \c true if the constraint removed successfully
80    */
81   bool removeConstraint(std::shared_ptr<SketchPlugin_Constraint> theConstraint);
82
83   /** \brief Goes through the list of groups and solve the constraints
84    *  \return \c true, if groups are resolved, and features should be updated 
85    *  (send the Update event)
86    */
87   bool resolveConstraints();
88
89 private:
90   /** \brief Searches group which interact with specified feature
91    *  \param[in]  theFeature  object to be found
92    *  \return Pointer to corresponding group or NULL if the group cannot be created.
93    */
94   SketchGroupPtr findGroup(std::shared_ptr<SketchPlugin_Feature> theFeature);
95
96   /// \brief Stop sending the Update event until all features updated
97   /// \return \c true, if the last flushed event is Update
98   bool stopSendUpdate() const;
99   /// \brief Allow to send the Update event
100   void allowSendUpdate() const;
101
102   /// \brief Allow send events about changing features in groups
103   void releaseFeaturesIfEventsBlocked() const;
104
105 private:
106   std::list<SketchGroupPtr> myGroups; ///< Groups of constraints
107   /// true if computation is performed and all "updates" are generated by this algo
108   /// and needs no recomputation
109   bool myIsComputed;
110 };
111
112 #endif