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_Constraint.h>
11 #include <SketchSolver_Storage.h>
13 #include <PlaneGCSSolver_Solver.h>
15 #include <SketchPlugin_Constraint.h>
20 typedef std::map<ConstraintPtr, SolverConstraintPtr> ConstraintConstraintMap;
22 /** \class SketchSolver_Group
24 * \brief Keeps the group of constraints which placed in the same sketch
26 class SketchSolver_Group
29 /** \brief New group based on specified workplane.
30 * Throws an exception if theWorkplane is not an object of SketchPlugin_Sketch type
31 * \remark Type of theSketch is not verified inside
33 SketchSolver_Group(const CompositeFeaturePtr& theWorkplane);
35 virtual ~SketchSolver_Group();
37 /// \brief Returns true if the group has no constraints yet
38 inline bool isEmpty() const
40 return myConstraints.empty() && myTempConstraints.empty();
43 /// \brief Check for valid sketch data
44 inline bool isWorkplaneValid() const
46 return mySketch->data() && mySketch->data()->isValid();
49 /** \brief Adds or updates a constraint in the group
50 * \param[in] theConstraint constraint to be changed
51 * \return \c true if the constraint added or updated successfully
53 bool changeConstraint(std::shared_ptr<SketchPlugin_Constraint> theConstraint);
55 /** \brief Updates the data corresponding the specified feature
56 * \param[in] theFeature the feature to be updated
58 bool updateFeature(FeaturePtr theFeature);
60 /** \brief Updates the data corresponding the specified feature moved in GUI.
61 * Additional Fixed constraints are created.
62 * \param[in] theFeature the feature to be updated
63 * \return \c true, if the feature is moved
65 bool moveFeature(FeaturePtr theFeature);
67 /// Returns the current workplane
68 inline const CompositeFeaturePtr& getWorkplane() const
73 /** \brief Searches invalid features and constraints in the group and removes them
74 * \return \c false if the group several constraints were removed
76 void repairConsistency();
78 /** \brief Start solution procedure if necessary and update attributes of features
79 * \return \c false when no need to solve constraints
81 bool resolveConstraints();
83 /// \brief Block or unblock events sent by features in this group
84 void blockEvents(bool isBlocked);
87 /// \biref Verify constraints have not been removed
88 bool areConstraintsValid() const;
90 /** \brief Removes constraints from the group
91 * \param[in] theConstraint constraint to be removed
93 void removeConstraint(ConstraintPtr theConstraint);
95 /// \brief Remove all temporary constraints after the computation finished
96 void removeTemporaryConstraints();
98 /// \brief Append given constraint to the group of temporary constraints
99 void setTemporary(SolverConstraintPtr theConstraint);
101 /// \brief Compute DoF of the sketch and set corresponding field
105 CompositeFeaturePtr mySketch; ///< Sketch for this group
106 ConstraintConstraintMap myConstraints; ///< List of constraints
107 std::set<SolverConstraintPtr> myTempConstraints; ///< List of temporary constraints
109 StoragePtr myStorage; ///< Container for the set of SolveSpace constraints and their entities
110 SolverPtr mySketchSolver; ///< Solver for set of equations obtained by constraints
112 /// Result of previous solution of the set of constraints
113 PlaneGCSSolver_Solver::SolveStatus myPrevResult;
114 std::set<ObjectPtr> myConflictingConstraints; ///< List of conflicting constraints
116 int myDOF; ///< degrees of freedom of the current sketch
118 bool myIsEventsBlocked; ///< shows the events are blocked for this group
120 int myMultiConstraintUpdateStack; ///< depth of the stack updating "Multi" constraints
123 typedef std::shared_ptr<SketchSolver_Group> SketchGroupPtr;