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>
22 typedef std::map<ConstraintPtr, SolverConstraintPtr> ConstraintConstraintMap;
24 /** \class SketchSolver_Group
26 * \brief Keeps the group of constraints which placed in the same sketch
28 class SketchSolver_Group
31 /** \brief New group based on specified workplane.
32 * Throws an exception if theWorkplane is not an object of SketchPlugin_Sketch type
33 * \remark Type of theSketch is not verified inside
35 SketchSolver_Group(const CompositeFeaturePtr& theWorkplane);
37 virtual ~SketchSolver_Group();
39 /// \brief Returns true if the group has no constraints yet
40 inline bool isEmpty() const
42 return myConstraints.empty() && myTempConstraints.empty();
45 /// \brief Check for valid sketch data
46 inline bool isWorkplaneValid() const
48 return mySketch->data() && mySketch->data()->isValid();
51 /** \brief Adds or updates a constraint in the group
52 * \param[in] theConstraint constraint to be changed
53 * \return \c true if the constraint added or updated successfully
55 bool changeConstraint(std::shared_ptr<SketchPlugin_Constraint> theConstraint);
57 /** \brief Updates the data corresponding the specified feature
58 * \param[in] theFeature the feature to be updated
60 bool updateFeature(FeaturePtr theFeature);
62 #ifdef SUPPORT_NEW_MOVE
63 /** \brief Updates the data corresponding the specified feature moved in GUI.
64 * Special kind of Fixed constraints is created.
65 * \param[in] theFeature the feature to be updated
66 * \param[in] theFrom start point of the movement
67 * \param[in] theTo final point of the movement
68 * \return \c true, if the feature is really moved
70 bool moveFeature(FeaturePtr theFeature,
71 const std::shared_ptr<GeomAPI_Pnt2d>& theFrom,
72 const std::shared_ptr<GeomAPI_Pnt2d>& theTo);
73 /** \brief Updates the data corresponding the specified point moved in GUI.
74 * Special kind of Fixed constraints is created.
75 * \param[in] thePoint the attribute to be updated
76 * \param[in] theFrom start point of the movement
77 * \param[in] theTo final point of the movement
78 * \return \c true, if the attribute is really moved
80 bool movePoint(AttributePtr thePoint,
81 const std::shared_ptr<GeomAPI_Pnt2d>& theFrom,
82 const std::shared_ptr<GeomAPI_Pnt2d>& theTo);
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
87 * \return \c true, if the feature is moved
89 bool moveFeature(FeaturePtr theFeature);
92 /// Returns the current workplane
93 inline const CompositeFeaturePtr& getWorkplane() const
98 /** \brief Searches invalid features and constraints in the group and removes them
99 * \return \c false if the group several constraints were removed
101 void repairConsistency();
103 /** \brief Start solution procedure if necessary and update attributes of features
104 * \return \c false when no need to solve constraints
106 bool resolveConstraints();
108 /// \brief Block or unblock events sent by features in this group
109 void blockEvents(bool isBlocked);
112 /// \biref Verify constraints have not been removed
113 bool areConstraintsValid() const;
115 /** \brief Removes constraints from the group
116 * \param[in] theConstraint constraint to be removed
118 void removeConstraint(ConstraintPtr theConstraint);
120 /// \brief Remove all temporary constraints after the computation finished
121 void removeTemporaryConstraints();
123 /// \brief Append given constraint to the group of temporary constraints
124 void setTemporary(SolverConstraintPtr theConstraint);
126 /// \brief Compute DoF of the sketch and set corresponding field
130 CompositeFeaturePtr mySketch; ///< Sketch for this group
131 ConstraintConstraintMap myConstraints; ///< List of constraints
132 std::set<SolverConstraintPtr> myTempConstraints; ///< List of temporary constraints
134 StoragePtr myStorage; ///< Container for the set of SolveSpace constraints and their entities
135 SolverPtr mySketchSolver; ///< Solver for set of equations obtained by constraints
137 /// Result of previous solution of the set of constraints
138 PlaneGCSSolver_Solver::SolveStatus myPrevResult;
139 std::set<ObjectPtr> myConflictingConstraints; ///< List of conflicting constraints
141 int myDOF; ///< degrees of freedom of the current sketch
143 bool myIsEventsBlocked; ///< shows the events are blocked for this group
145 int myMultiConstraintUpdateStack; ///< depth of the stack updating "Multi" constraints
148 typedef std::shared_ptr<SketchSolver_Group> SketchGroupPtr;