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 /** \brief Updates the data corresponding the specified feature moved in GUI.
63 * Special kind of Fixed constraints is created.
64 * \param[in] theFeature the feature to be updated
65 * \param[in] theFrom start point of the movement
66 * \param[in] theTo final point of the movement
67 * \return \c true, if the feature is really moved
69 bool moveFeature(FeaturePtr theFeature,
70 const std::shared_ptr<GeomAPI_Pnt2d>& theFrom,
71 const std::shared_ptr<GeomAPI_Pnt2d>& theTo);
72 /** \brief Updates the data corresponding the specified point moved in GUI.
73 * Special kind of Fixed constraints is created.
74 * \param[in] thePoint the attribute to be updated
75 * \param[in] theFrom start point of the movement
76 * \param[in] theTo final point of the movement
77 * \return \c true, if the attribute is really moved
79 bool movePoint(AttributePtr thePoint,
80 const std::shared_ptr<GeomAPI_Pnt2d>& theFrom,
81 const std::shared_ptr<GeomAPI_Pnt2d>& theTo);
83 /// Returns the current workplane
84 inline const CompositeFeaturePtr& getWorkplane() const
89 /** \brief Searches invalid features and constraints in the group and removes them
90 * \return \c false if the group several constraints were removed
92 void repairConsistency();
94 /** \brief Start solution procedure if necessary and update attributes of features
95 * \return \c false when no need to solve constraints
97 bool resolveConstraints();
99 /// \brief Block or unblock events sent by features in this group
100 void blockEvents(bool isBlocked);
103 /// \biref Verify constraints have not been removed
104 bool areConstraintsValid() const;
106 /** \brief Removes constraints from the group
107 * \param[in] theConstraint constraint to be removed
109 void removeConstraint(ConstraintPtr theConstraint);
111 /// \brief Remove all temporary constraints after the computation finished
112 void removeTemporaryConstraints();
114 /// \brief Append given constraint to the group of temporary constraints
115 void setTemporary(SolverConstraintPtr theConstraint);
117 /// \brief Compute DoF of the sketch and set corresponding field
121 CompositeFeaturePtr mySketch; ///< Sketch for this group
122 ConstraintConstraintMap myConstraints; ///< List of constraints
123 std::set<SolverConstraintPtr> myTempConstraints; ///< List of temporary constraints
125 StoragePtr myStorage; ///< Container for the set of SolveSpace constraints and their entities
126 SolverPtr mySketchSolver; ///< Solver for set of equations obtained by constraints
128 /// Result of previous solution of the set of constraints
129 PlaneGCSSolver_Solver::SolveStatus myPrevResult;
130 std::set<ObjectPtr> myConflictingConstraints; ///< List of conflicting constraints
132 int myDOF; ///< degrees of freedom of the current sketch
134 bool myIsEventsBlocked; ///< shows the events are blocked for this group
136 int myMultiConstraintUpdateStack; ///< depth of the stack updating "Multi" constraints
139 typedef std::shared_ptr<SketchSolver_Group> SketchGroupPtr;