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 #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
56 bool updateFeature(const std::shared_ptr<SketchPlugin_Feature>& theFeature);
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
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);
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
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);
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
83 bool updateFeature(std::shared_ptr<SketchPlugin_Feature> theFeature, bool theMoved = false);
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
90 bool removeConstraint(std::shared_ptr<SketchPlugin_Constraint> theConstraint);
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)
96 bool resolveConstraints();
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.
103 SketchGroupPtr findGroup(std::shared_ptr<SketchPlugin_Feature> theFeature);
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;
111 /// \brief Allow send events about changing features in groups
112 void releaseFeaturesIfEventsBlocked() const;
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