1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: SketchSolver_Group.h
4 // Created: 27 May 2014
5 // Author: Artem ZHIDKOV
7 #ifndef SketchSolver_Group_H_
8 #define SketchSolver_Group_H_
10 #include "SketchSolver.h"
11 #include <SketchSolver_Constraint.h>
12 #include <SketchSolver_Storage.h>
13 #include <SketchSolver_FeatureStorage.h>
14 #include <SketchSolver_Solver.h>
16 #include <SketchPlugin_Constraint.h>
17 #include <ModelAPI_Data.h>
18 #include <ModelAPI_Feature.h>
19 #include <ModelAPI_AttributeRefList.h>
27 typedef std::map<ConstraintPtr, SolverConstraintPtr> ConstraintConstraintMap;
29 /** \class SketchSolver_Group
31 * \brief Keeps the group of constraints which based on the same entities
33 class SketchSolver_Group
36 /** \brief New group based on specified workplane.
37 * Throws an exception if theWorkplane is not an object of SketchPlugin_Sketch type
38 * \remark Type of theSketch is not verified inside
40 SketchSolver_Group(std::shared_ptr<ModelAPI_CompositeFeature> theWorkplane);
42 ~SketchSolver_Group();
44 /// \brief Returns group's unique identifier
45 inline const Slvs_hGroup& getId() const
50 /// \brief Returns identifier of the workplane
51 inline const Slvs_hEntity& getWorkplaneId() const
56 /// \brief Find the identifier of the feature, if it already exists in the group
57 Slvs_hEntity getFeatureId(FeaturePtr theFeature) const;
58 /// \brief Find the identifier of the attribute, if it already exists in the group
59 Slvs_hEntity getAttributeId(AttributePtr theAttribute) const;
61 /// \brief Returns true if the group has no constraints yet
62 inline bool isEmpty() const
64 return myConstraints.empty();
67 /// \brief Check for valid sketch data
68 inline bool isWorkplaneValid() const
70 return mySketch->data() && mySketch->data()->isValid();
73 /// \brief Verifies the constraint is complex, i.e. it needs another constraints to be created before
74 static bool isComplexConstraint(FeaturePtr theConstraint);
76 /** \brief Adds or updates a constraint in the group
77 * \param[in] theConstraint constraint to be changed
78 * \return \c true if the constraint added or updated successfully
80 bool changeConstraint(std::shared_ptr<SketchPlugin_Constraint> theConstraint);
82 /** \brief Updates the data corresponding the specified feature
83 * \param[in] theFeature the feature to be updated
85 bool updateFeature(std::shared_ptr<SketchPlugin_Feature> theFeature);
87 /** \brief Updates the data corresponding the specified feature moved in GUI.
88 * Additional Fixed constraints are created.
89 * \param[in] theFeature the feature to be updated
91 void moveFeature(std::shared_ptr<SketchPlugin_Feature> theFeature);
93 /** \brief Verifies the feature attributes are used in this group
94 * \param[in] theFeature constraint or any other object for verification of interaction
95 * \return \c true if some of attributes are used in current group
97 bool isInteract(std::shared_ptr<SketchPlugin_Feature> theFeature) const;
99 /** \brief Verifies the specified feature is equal to the base workplane for this group
100 * \param[in] theWorkplane the feature to be compared with base workplane
101 * \return \c true if workplanes are the same
103 bool isBaseWorkplane(CompositeFeaturePtr theWorkplane) const;
105 /// Returns the current workplane
106 std::shared_ptr<ModelAPI_CompositeFeature> getWorkplane() const
111 /** \brief Update parameters of workplane. Should be called when Update event is coming.
112 * \return \c true if workplane updated successfully, \c false if workplane parameters are not consistent
114 bool updateWorkplane();
116 /** \brief Searches invalid features and constraints in the group and removes them
117 * \return \c false if the group several constraints were removed
121 /** \brief Add specified group to this one
122 * \param[in] theGroup group of constraint to be added
124 void mergeGroups(const SketchSolver_Group& theGroup);
126 /** \brief Cut from the group several subgroups, which are not connected to the current one by any constraint
127 * \param[out] theCuts enlarge this list by newly created groups
129 void splitGroup(std::vector<SketchSolver_Group*>& theCuts);
131 /** \brief Start solution procedure if necessary and update attributes of features
132 * \return \c false when no need to solve constraints
134 bool resolveConstraints();
137 /** \brief Removes constraints from the group
138 * \param[in] theConstraint constraint to be removed
140 void removeConstraint(ConstraintPtr theConstraint);
142 /** \brief Remove all temporary constraint after computation finished
143 * \param[in] theRemoved indexes of constraints to be removed. If empty, all temporary constraints should be deleted
145 void removeTemporaryConstraints();
148 /** \brief Creates a workplane from the sketch parameters
149 * \param[in] theSketch parameters of workplane are the attributes of this sketch
150 * \return \c true if success, \c false if workplane parameters are not consistent
152 bool addWorkplane(CompositeFeaturePtr theSketch);
154 /// \brief Apply temporary rigid constraints for the list of features
155 void fixFeaturesList(AttributeRefListPtr theList);
157 /// \brief Append given constraint to th group of temporary constraints
158 void setTemporary(SolverConstraintPtr theConstraint);
161 Slvs_hGroup myID; ///< Index of the group
162 Slvs_hEntity myWorkplaneID; ///< Index of workplane, the group is based on
163 CompositeFeaturePtr mySketch; ///< Sketch is equivalent to workplane
164 ConstraintConstraintMap myConstraints; ///< List of constraints
165 std::set<SolverConstraintPtr> myTempConstraints; ///< List of temporary constraints
167 StoragePtr myStorage; ///< Container for the set of SolveSpace constraints and their entities
168 FeatureStoragePtr myFeatureStorage; ///< Container for the set of SketchPlugin features and their dependencies
170 SketchSolver_Solver myConstrSolver; ///< Solver for set of equations obtained by constraints