1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: SketchSolver_Manager.h
4 // Created: 08 May 2014
5 // Author: Artem ZHIDKOV
7 #ifndef SketchSolver_Manager_H_
8 #define SketchSolver_Manager_H_
10 #include <SketchSolver_Group.h>
12 #include <Events_Listener.h>
18 class GeomDataAPI_Point2D;
19 class SketchPlugin_Constraint;
21 /** \class SketchSolver_Manager
23 * \brief Listens the changes of SketchPlugin features and transforms the Constraint
24 * feature into the format understandable by sketch solver.
26 * \remark This is a singleton.
28 class SketchSolver_Manager : public Events_Listener
31 /** \brief Main method to create constraint manager
32 * \return pointer to the singleton
34 static SketchSolver_Manager* instance();
36 /** \brief Implementation of Event Listener method
37 * \param[in] theMessage the data of the event
39 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
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.
45 virtual bool groupMessages();
48 SketchSolver_Manager();
49 ~SketchSolver_Manager();
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
55 bool updateFeature(const std::shared_ptr<SketchPlugin_Feature>& theFeature);
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
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);
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
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);
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
81 bool removeConstraint(std::shared_ptr<SketchPlugin_Constraint> theConstraint);
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)
87 bool resolveConstraints();
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.
94 SketchGroupPtr findGroup(std::shared_ptr<SketchPlugin_Feature> theFeature);
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;
102 /// \brief Allow send events about changing features in groups
103 void releaseFeaturesIfEventsBlocked() const;
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