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>
24 /** \class SketchSolver_ConstraintManager
26 * \brief Listens the changes of SketchPlugin features and transforms the Constraint
27 * feature into the format understandable by SolveSpace library.
29 * Constraints created for SolveSpace library are divided into the groups.
30 * The division order based on connectedness of the features by the constraints.
31 * The groups may be fused or separated according to the new constraints.
33 * \remark This is a singleton.
35 class SketchSolver_ConstraintManager : public Events_Listener
38 /** \brief Main method to create constraint manager
39 * \return pointer to the singleton
41 static SketchSolver_ConstraintManager* Instance();
43 /** \brief Implementation of Event Listener method
44 * \param[in] theMessage the data of the event
46 virtual void processEvent(const Events_Message* theMessage);
49 SketchSolver_ConstraintManager();
50 ~SketchSolver_ConstraintManager();
52 /** \brief Adds or updates a constraint in the suitable group
53 * \param[in] theConstraint constraint to be changed
54 * \return \c true if the constraint changed successfully
56 bool changeConstraint(boost::shared_ptr<SketchPlugin_Constraint> theConstraint);
58 /** \brief Removes a constraint from the manager
59 * \param[in] theConstraint constraint to be removed
60 * \return \c true if the constraint removed successfully
62 bool removeConstraint(boost::shared_ptr<SketchPlugin_Constraint> theConstraint);
64 /** \brief Adds or updates a workplane in the manager
65 * \param[in] theSketch the feature to create or update workplane
66 * \return \c true if the workplane changed successfully
67 * \remark Type of theSketch is not verified inside
69 bool changeWorkplane(boost::shared_ptr<SketchPlugin_Feature> theSketch);
71 /** \brief Removes a workplane from the manager.
72 * All groups based on such workplane will be removed too.
73 * \param[in] theSketch the feature to be removed
74 * \return \c true if the workplane removed successfully
76 bool removeWorkplane(boost::shared_ptr<SketchPlugin_Sketch> theSketch);
78 /** \brief Updates entity which is neither workplane nor constraint
79 * \param[in] theFeature entity to be updated
81 void updateEntity(boost::shared_ptr<SketchPlugin_Feature> theFeature);
83 /** \brief Goes through the list of groups and solve the constraints
85 void resolveConstraints();
88 /** \brief Searches list of groups which interact with specified constraint
89 * \param[in] theConstraint constraint to be found
90 * \param[out] theGroups list of group indexes interacted with constraint
92 void findGroups(boost::shared_ptr<SketchPlugin_Constraint> theConstraint,
93 std::set<Slvs_hGroup>& theGroupIDs) const;
95 /** \brief Searches in the list of groups the workplane which constains specified constraint
96 * \param[in] theConstraint constraint to be found
97 * \return workplane containing the constraint
99 boost::shared_ptr<SketchPlugin_Feature> findWorkplaneForConstraint(
100 boost::shared_ptr<SketchPlugin_Constraint> theConstraint) const;
103 static SketchSolver_ConstraintManager* _self; ///< Self pointer to implement singleton functionality
104 std::vector<SketchSolver_ConstraintGroup*> myGroups; ///< Groups of constraints