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 Adds or updates a constraint in the group
74 * \param[in] theConstraint constraint to be changed
75 * \return \c true if the constraint added or updated successfully
77 bool changeConstraint(std::shared_ptr<SketchPlugin_Constraint> theConstraint);
79 /** \brief Updates the data corresponding the specified feature
80 * \param[in] theFeature the feature to be updated
82 bool updateFeature(std::shared_ptr<SketchPlugin_Feature> theFeature);
84 /** \brief Updates the data corresponding the specified feature moved in GUI.
85 * Additional Fixed constraints are created.
86 * \param[in] theFeature the feature to be updated
88 void moveFeature(std::shared_ptr<SketchPlugin_Feature> theFeature);
90 /** \brief Verifies the feature attributes are used in this group
91 * \param[in] theFeature constraint or any other object for verification of interaction
92 * \return \c true if some of attributes are used in current group
94 bool isInteract(std::shared_ptr<SketchPlugin_Feature> theFeature) const;
96 /** \brief Verifies the specified feature is equal to the base workplane for this group
97 * \param[in] theWorkplane the feature to be compared with base workplane
98 * \return \c true if workplanes are the same
100 bool isBaseWorkplane(CompositeFeaturePtr theWorkplane) const;
102 /// Returns the current workplane
103 std::shared_ptr<ModelAPI_CompositeFeature> getWorkplane() const
108 /** \brief Update parameters of workplane. Should be called when Update event is coming.
109 * \return \c true if workplane updated successfully, \c false if workplane parameters are not consistent
111 bool updateWorkplane();
113 /** \brief Searches invalid features and constraints in the group and removes them
114 * \return \c false if the group several constraints were removed
118 /** \brief Add specified group to this one
119 * \param[in] theGroup group of constraint to be added
121 void mergeGroups(const SketchSolver_Group& theGroup);
123 /** \brief Cut from the group several subgroups, which are not connected to the current one by any constraint
124 * \param[out] theCuts enlarge this list by newly created groups
126 void splitGroup(std::vector<SketchSolver_Group*>& theCuts);
128 /** \brief Start solution procedure if necessary and update attributes of features
129 * \return \c false when no need to solve constraints
131 bool resolveConstraints();
134 /** \brief Removes constraints from the group
135 * \param[in] theConstraint constraint to be removed
137 void removeConstraint(ConstraintPtr theConstraint);
139 /** \brief Remove all temporary constraint after computation finished
140 * \param[in] theRemoved indexes of constraints to be removed. If empty, all temporary constraints should be deleted
142 void removeTemporaryConstraints();
145 /** \brief Creates a workplane from the sketch parameters
146 * \param[in] theSketch parameters of workplane are the attributes of this sketch
147 * \return \c true if success, \c false if workplane parameters are not consistent
149 bool addWorkplane(CompositeFeaturePtr theSketch);
151 /// \brief Apply temporary rigid constraints for the list of features
152 void fixFeaturesList(AttributeRefListPtr theList);
155 Slvs_hGroup myID; ///< Index of the group
156 Slvs_hEntity myWorkplaneID; ///< Index of workplane, the group is based on
157 CompositeFeaturePtr mySketch; ///< Sketch is equivalent to workplane
158 ConstraintConstraintMap myConstraints; ///< List of constraints
159 std::set<SolverConstraintPtr> myTempConstraints; ///< List of temporary constraints
161 StoragePtr myStorage; ///< Container for the set of SolveSpace constraints and their entities
162 FeatureStoragePtr myFeatureStorage; ///< Container for the set of SketchPlugin features and their dependencies
164 SketchSolver_Solver myConstrSolver; ///< Solver for set of equations obtained by constraints