]> 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 #ifdef SUPPORT_NEW_MOVE
52   /** \brief Adds or updates a constraint or an entity in the suitable group
53    *  \param[in] theFeature sketch feature to be changed
54    *  \return \c true if the feature changed successfully
55    */
56   bool updateFeature(const std::shared_ptr<SketchPlugin_Feature>& theFeature);
57
58   /** \brief Move feature
59    *  \param[in] theMovedFeature dragged sketch feature
60    *  \param[in] theFromPoint    original position of the feature
61    *  \param[in] theToPoint      prefereble position of the feature (current position of the mouse)
62    *  \return \c true if the feature has been changed successfully
63    */
64   bool moveFeature(const std::shared_ptr<SketchPlugin_Feature>& theMovedFeature,
65                    const std::shared_ptr<GeomAPI_Pnt2d>& theFromPoint,
66                    const std::shared_ptr<GeomAPI_Pnt2d>& theToPoint);
67
68   /** \brief Move feature using its moved attribute
69    *  \param[in] theMovedAttribute dragged point attribute of sketch feature
70    *  \param[in] theFromPoint      original position of the moved point
71    *  \param[in] theToPoint        prefereble position (current position of the mouse)
72    *  \return \c true if the attribute owner has been changed successfully
73    */
74   bool moveAttribute(const std::shared_ptr<GeomDataAPI_Point2D>& theMovedAttribute,
75                      const std::shared_ptr<GeomAPI_Pnt2d>& theFromPoint,
76                      const std::shared_ptr<GeomAPI_Pnt2d>& theToPoint);
77 #else
78   /** \brief Adds or updates a constraint or an entity in the suitable group
79    *  \param[in] theFeature sketch feature to be changed
80    *  \param[in] theMoved   \c true if the feature has been moved in the viewer
81    *  \return \c true if the feature changed successfully
82    */
83   bool updateFeature(std::shared_ptr<SketchPlugin_Feature> theFeature, bool theMoved = false);
84 #endif
85
86   /** \brief Removes a constraint from the manager
87    *  \param[in] theConstraint constraint to be removed
88    *  \return \c true if the constraint removed successfully
89    */
90   bool removeConstraint(std::shared_ptr<SketchPlugin_Constraint> theConstraint);
91
92   /** \brief Goes through the list of groups and solve the constraints
93    *  \return \c true, if groups are resolved, and features should be updated 
94    *  (send the Update event)
95    */
96   bool resolveConstraints();
97
98 private:
99   /** \brief Searches group which interact with specified feature
100    *  \param[in]  theFeature  object to be found
101    *  \return Pointer to corresponding group or NULL if the group cannot be created.
102    */
103   SketchGroupPtr findGroup(std::shared_ptr<SketchPlugin_Feature> theFeature);
104
105   /// \brief Stop sending the Update event until all features updated
106   /// \return \c true, if the last flushed event is Update
107   bool stopSendUpdate() const;
108   /// \brief Allow to send the Update event
109   void allowSendUpdate() const;
110
111   /// \brief Allow send events about changing features in groups
112   void releaseFeaturesIfEventsBlocked() const;
113
114 private:
115   std::list<SketchGroupPtr> myGroups; ///< Groups of constraints
116   /// true if computation is performed and all "updates" are generated by this algo
117   /// and needs no recomputation
118   bool myIsComputed;
119 };
120
121 #endif