1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: SketchSolver_ConstraintManager.h
4 // Created: 08 May 2014
5 // Author: Artem ZHIDKOV
7 #ifndef SketchSolver_ConstraintManager_H_
8 #define SketchSolver_ConstraintManager_H_
10 #include "SketchSolver.h"
11 #include <SketchSolver_Solver.h>
12 #include <SketchSolver_ConstraintGroup.h>
14 #include <Events_Listener.h>
15 #include <SketchPlugin_Constraint.h>
25 /** \class SketchSolver_ConstraintManager
27 * \brief Listens the changes of SketchPlugin features and transforms the Constraint
28 * feature into the format understandable by SolveSpace library.
30 * Constraints created for SolveSpace library are divided into the groups.
31 * The division order based on connectedness of the features by the constraints.
32 * The groups may be fused or separated according to the new constraints.
34 * \remark This is a singleton.
36 class SketchSolver_ConstraintManager : public Events_Listener
39 /** \brief Main method to create constraint manager
40 * \return pointer to the singleton
42 static SketchSolver_ConstraintManager* Instance();
44 /** \brief Implementation of Event Listener method
45 * \param[in] theMessage the data of the event
47 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
50 SketchSolver_ConstraintManager();
51 ~SketchSolver_ConstraintManager();
53 /** \brief Adds or updates a constraint or an entity in the suitable group
54 * \param[in] theFeature sketch feature to be changed
55 * \return \c true if the feature changed successfully
57 bool changeConstraintOrEntity(std::shared_ptr<SketchPlugin_Feature> theFeature);
59 /** \brief Removes a constraint from the manager
60 * \param[in] theConstraint constraint to be removed
61 * \return \c true if the constraint removed successfully
63 bool removeConstraint(std::shared_ptr<SketchPlugin_Constraint> theConstraint);
65 /** \brief Adds or updates a workplane in the manager
66 * \param[in] theSketch the feature to create or update workplane
67 * \return \c true if the workplane changed successfully
68 * \remark Type of theSketch is not verified inside
70 bool changeWorkplane(std::shared_ptr<ModelAPI_CompositeFeature> theSketch);
72 /** \brief Removes a workplane from the manager.
73 * All groups based on such workplane will be removed too.
74 * \param[in] theSketch the feature to be removed
75 * \return \c true if the workplane removed successfully
77 bool removeWorkplane(std::shared_ptr<SketchPlugin_Sketch> theSketch);
79 /** \brief Updates entity which is neither workplane nor constraint
80 * \param[in] theFeature entity to be updated
82 void updateEntity(std::shared_ptr<SketchPlugin_Feature> theFeature);
84 /** \brief Goes through the list of groups and solve the constraints
85 * \param theForceUpdate flushes the update event in any case: something changed or not
87 void resolveConstraints(const bool theForceUpdate);
90 /** \brief Searches list of groups which interact with specified feature
91 * \param[in] theFeature object to be found
92 * \param[out] theGroups list of group indexes interacted with the feature
94 void findGroups(std::shared_ptr<SketchPlugin_Feature> theFeature,
95 std::set<Slvs_hGroup>& theGroupIDs) const;
97 /** \brief Searches in the list of groups the workplane which constains specified feature
98 * \param[in] theFeature object to be found
99 * \return workplane containing the feature
101 std::shared_ptr<ModelAPI_CompositeFeature> findWorkplane(
102 std::shared_ptr<SketchPlugin_Feature> theFeature) const;
105 static SketchSolver_ConstraintManager* _self; ///< Self pointer to implement singleton functionality
106 std::vector<SketchSolver_ConstraintGroup*> myGroups; ///< Groups of constraints
107 /// true if computation is performed and all "updates" are generated by this algo
108 /// and needs no recomputation