1 // File: SketchSolver_ConstraintManager.h
2 // Created: 08 May 2014
3 // Author: Artem ZHIDKOV
5 #ifndef SketchSolver_ConstraintManager_H_
6 #define SketchSolver_ConstraintManager_H_
8 #include "SketchSolver.h"
9 #include <SketchSolver_Solver.h>
10 #include <SketchSolver_ConstraintGroup.h>
12 #include <Events_Listener.h>
13 #include <SketchPlugin_Constraint.h>
23 /** \class SketchSolver_ConstraintManager
25 * \brief Listens the changes of SketchPlugin features and transforms the Constraint
26 * feature into the format understandable by SolveSpace library.
28 * Constraints created for SolveSpace library are divided into the groups.
29 * The division order based on connectedness of the features by the constraints.
30 * The groups may be fused or separated according to the new constraints.
32 * \remark This is a singleton.
34 class SketchSolver_ConstraintManager : public Events_Listener
37 /** \brief Main method to create constraint manager
38 * \return pointer to the singleton
40 static SketchSolver_ConstraintManager* Instance();
42 /** \brief Implementation of Event Listener method
43 * \param[in] theMessage the data of the event
45 virtual void processEvent(const Events_Message* theMessage);
48 SketchSolver_ConstraintManager();
49 ~SketchSolver_ConstraintManager();
51 /** \brief Adds or updates a constraint in the suitable group
52 * \param[in] theConstraint constraint to be changed
53 * \return \c true if the constraint changed successfully
55 bool changeConstraint(boost::shared_ptr<SketchPlugin_Constraint> theConstraint);
57 /** \brief Removes a constraint from the manager
58 * \param[in] theConstraint constraint to be removed
59 * \return \c true if the constraint removed successfully
61 bool removeConstraint(boost::shared_ptr<SketchPlugin_Constraint> theConstraint);
63 /** \brief Adds or updates a workplane in the manager
64 * \param[in] theSketch the feature to create or update workplane
65 * \return \c true if the workplane changed successfully
66 * \remark Type of theSketch is not verified inside
68 bool changeWorkplane(boost::shared_ptr<SketchPlugin_Feature> theSketch);
70 /** \brief Removes a workplane from the manager.
71 * All groups based on such workplane will be removed too.
72 * \param[in] theSketch the feature to be removed
73 * \return \c true if the workplane removed successfully
75 bool removeWorkplane(boost::shared_ptr<SketchPlugin_Sketch> theSketch);
77 /** \brief Updates entity which is neither workplane nor constraint
78 * \param[in] theFeature entity to be updated
80 void updateEntity(boost::shared_ptr<SketchPlugin_Feature> theFeature);
82 /** \brief Goes through the list of groups and solve the constraints
84 void resolveConstraints();
87 /** \brief Searches list of groups which interact with specified constraint
88 * \param[in] theConstraint constraint to be found
89 * \param[out] theGroups list of group indexes interacted with constraint
91 void findGroups(boost::shared_ptr<SketchPlugin_Constraint> theConstraint,
92 std::set<Slvs_hGroup>& theGroupIDs) const;
94 /** \brief Searches in the list of groups the workplane which constains specified constraint
95 * \param[in] theConstraint constraint to be found
96 * \return workplane containing the constraint
98 boost::shared_ptr<SketchPlugin_Feature> findWorkplaneForConstraint(
99 boost::shared_ptr<SketchPlugin_Constraint> theConstraint) const;
102 static SketchSolver_ConstraintManager* _self; ///< Self pointer to implement singleton functionality
103 std::vector<SketchSolver_ConstraintGroup*> myGroups; ///< Groups of constraints