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.h"
11 #include <SketchSolver_Group.h>
12 #include <SketchSolver_Builder.h>
14 #include <Events_Listener.h>
15 #include <SketchPlugin_Constraint.h>
20 /** \class SketchSolver_Manager
22 * \brief Listens the changes of SketchPlugin features and transforms the Constraint
23 * feature into the format understandable by SolveSpace library.
25 * Constraints created for SolveSpace library are divided into the groups.
26 * The division order based on connectedness of the features by the constraints.
27 * The groups may be fused or separated according to the new constraints.
29 * \remark This is a singleton.
31 class SketchSolver_Manager : public Events_Listener
34 /** \brief Main method to create constraint manager
35 * \return pointer to the singleton
37 SKETCHSOLVER_EXPORT static SketchSolver_Manager* instance();
39 /** \brief Implementation of Event Listener method
40 * \param[in] theMessage the data of the event
42 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
45 * The solver needs all the updated objects are transfered in one group, not one by one.
46 * This iscreases performance and avoids problems in resolve of only part of the made updates.
48 virtual bool groupMessages();
50 /// \brief Initialize builder for solver's data structure entities
51 /// \param theBuilder [in] solver's specific builder
52 SKETCHSOLVER_EXPORT void setBuilder(BuilderPtr theBuilder);
53 /// \brief Returns the builder specific for the solver
57 SketchSolver_Manager();
58 ~SketchSolver_Manager();
60 /** \brief Adds or updates a constraint or an entity in the suitable group
61 * \param[in] theFeature sketch feature to be changed
62 * \return \c true if the feature changed successfully
64 bool changeFeature(std::shared_ptr<SketchPlugin_Feature> theFeature);
66 /** \brief Removes a constraint from the manager
67 * \param[in] theConstraint constraint to be removed
68 * \return \c true if the constraint removed successfully
70 bool removeConstraint(std::shared_ptr<SketchPlugin_Constraint> theConstraint);
72 /** \brief Adds or updates a workplane in the manager
73 * \param[in] theSketch the feature to create or update workplane
74 * \return \c true if the workplane changed successfully
75 * \remark Type of theSketch is not verified inside
77 bool changeWorkplane(CompositeFeaturePtr theSketch);
79 /** \brief Removes a workplane from the manager.
80 * All groups based on such workplane will be removed too.
81 * \param[in] theSketch the feature to be removed
82 * \return \c true if the workplane removed successfully
84 bool removeWorkplane(std::shared_ptr<SketchPlugin_Sketch> theSketch);
86 /** \brief Updates entity which is moved in GUI
87 * \param[in] theFeature entity to be updated
88 * \return \c true, if the entity has been moved
90 bool moveEntity(std::shared_ptr<SketchPlugin_Feature> theFeature);
92 /** \brief Goes through the list of groups and solve the constraints
93 * \param[in] theGroups list of groups to be resolved (if empty list, all groups are resolved)
94 * \return \c true, if groups are resolved, and features should be updated
95 * (send the Update event)
97 bool resolveConstraints(const std::list<SketchSolver_Group*>& theGroups =
98 std::list<SketchSolver_Group*>());
101 /** \brief Searches list of groups which interact with specified feature
102 * \param[in] theFeature object to be found
103 * \param[out] theGroups list of group indexes interacted with the feature
105 void findGroups(std::shared_ptr<SketchPlugin_Feature> theFeature,
106 std::set<GroupID>& theGroupIDs) const;
108 /** \brief Searches in the list of groups the workplane which contains specified feature
109 * \param[in] theFeature object to be found
110 * \return workplane containing the feature
112 std::shared_ptr<ModelAPI_CompositeFeature> findWorkplane(
113 std::shared_ptr<SketchPlugin_Feature> theFeature) const;
115 /// \brief Stop sending the Update event until all features updated
116 /// \return \c true, if the last flushed event is Update
117 bool stopSendUpdate() const;
118 /// \brief Allow to send the Update event
119 void allowSendUpdate() const;
121 /// \brief If the message shows that any group is repaired after conflicting,
122 /// find other groups on the same sketch, which have conflicts.
123 void checkConflictingConstraints(const std::shared_ptr<Events_Message>& theMessage);
125 /// \brief Calculate DoF for each sketch and send messages if changed
126 void degreesOfFreedom();
129 static SketchSolver_Manager* mySelf; ///< Self pointer to implement singleton functionality
130 std::list<SketchSolver_Group*> myGroups; ///< Groups of constraints
131 BuilderPtr myBuilder; ///< Builder for solver's entities
132 /// true if computation is performed and all "updates" are generated by this algo
133 /// and needs no recomputation
136 std::map<CompositeFeaturePtr, int> myDoF; ///< Degree of freedom for corresponding sketch