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_ISolver.h>
15 #include <SketchPlugin_Constraint.h>
16 #include <ModelAPI_Feature.h>
23 typedef std::map<ConstraintPtr, SolverConstraintPtr> ConstraintConstraintMap;
25 /** \class SketchSolver_Group
27 * \brief Keeps the group of constraints which based on the same entities
29 class SketchSolver_Group
32 /** \brief New group based on specified workplane.
33 * Throws an exception if theWorkplane is not an object of SketchPlugin_Sketch type
34 * \remark Type of theSketch is not verified inside
36 SketchSolver_Group(std::shared_ptr<ModelAPI_CompositeFeature> theWorkplane);
38 ~SketchSolver_Group();
40 /// \brief Returns group's unique identifier
41 inline const GroupID& getId() const
46 /// \brief Returns identifier of the workplane
47 inline const EntityID& getWorkplaneId() const
52 /// \brief Returns true if the group has no constraints yet
53 inline bool isEmpty() const
55 return myConstraints.empty();
58 /// \brief Check for valid sketch data
59 inline bool isWorkplaneValid() const
61 return mySketch->data() && mySketch->data()->isValid();
64 /** \brief Adds or updates a constraint in the group
65 * \param[in] theConstraint constraint to be changed
66 * \return \c true if the constraint added or updated successfully
68 bool changeConstraint(std::shared_ptr<SketchPlugin_Constraint> theConstraint);
70 /** \brief Updates the data corresponding the specified feature
71 * \param[in] theFeature the feature to be updated
73 bool updateFeature(FeaturePtr theFeature);
75 /** \brief Updates the data corresponding the specified feature moved in GUI.
76 * Additional Fixed constraints are created.
77 * \param[in] theFeature the feature to be updated
79 void moveFeature(FeaturePtr theFeature);
81 /** \brief Verifies the feature attributes are used in this group
82 * \param[in] theFeature constraint or any other object for verification of interaction
83 * \return \c true if some of attributes are used in current group
85 bool isInteract(FeaturePtr theFeature) const;
87 /** \brief Verifies the specified feature is equal to the base workplane for this group
88 * \param[in] theWorkplane the feature to be compared with base workplane
89 * \return \c true if workplanes are the same
91 bool isBaseWorkplane(CompositeFeaturePtr theWorkplane) const;
93 /// Returns the current workplane
94 std::shared_ptr<ModelAPI_CompositeFeature> getWorkplane() const
99 /** \brief Update parameters of workplane. Should be called when Update event is coming.
100 * \return \c true if workplane updated successfully, \c false if workplane parameters are not consistent
102 bool updateWorkplane();
104 /** \brief Searches invalid features and constraints in the group and removes them
105 * \return \c false if the group several constraints were removed
109 /** \brief Add specified group to this one
110 * \param[in] theGroup group of constraint to be added
112 void mergeGroups(const SketchSolver_Group& theGroup);
114 /** \brief Cut from the group several subgroups, which are not connected to the current one by any constraint
115 * \param[out] theCuts enlarge this list by newly created groups
117 void splitGroup(std::list<SketchSolver_Group*>& theCuts);
119 /** \brief Start solution procedure if necessary and update attributes of features
120 * \return \c false when no need to solve constraints
122 bool resolveConstraints();
124 /** \brief Collect all features applicable for the sketch
125 * \param theObjects list of features
126 * \return list of bolted and sorted features
128 static std::list<FeaturePtr> selectApplicableFeatures(const std::set<ObjectPtr>& theObjects);
131 /** \brief Removes constraints from the group
132 * \param[in] theConstraint constraint to be removed
134 void removeConstraint(ConstraintPtr theConstraint);
136 /// \brief Remove all temporary constraint after computation finished
137 void removeTemporaryConstraints();
140 /** \brief Creates a workplane from the sketch parameters
141 * \param[in] theSketch parameters of workplane are the attributes of this sketch
142 * \return \c true if success, \c false if workplane parameters are not consistent
144 bool addWorkplane(CompositeFeaturePtr theSketch);
146 /// \brief Append given constraint to the group of temporary constraints
147 void setTemporary(SolverConstraintPtr theConstraint);
149 /// \brief Verifies is the feature valid
150 bool checkFeatureValidity(FeaturePtr theFeature);
153 GroupID myID; ///< Index of the group
154 EntityID myWorkplaneID; ///< Index of workplane, the group is based on
155 CompositeFeaturePtr mySketch; ///< Sketch is equivalent to workplane
156 ConstraintConstraintMap myConstraints; ///< List of constraints
157 std::set<SolverConstraintPtr> myTempConstraints; ///< List of temporary constraints
158 std::map<AttributePtr, SolverConstraintPtr> myParametricConstraints; ///< List of parametric constraints
160 StoragePtr myStorage; ///< Container for the set of SolveSpace constraints and their entities
162 SolverPtr mySketchSolver; ///< Solver for set of equations obtained by constraints
164 SketchSolver_SolveStatus myPrevResult; ///< Result of previous solution of the set of constraints