Salome HOME
Merge branch 'V9_2_2_BR'
[modules/shaper.git] / src / SketchSolver / SketchSolver_Group.h
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef SketchSolver_Group_H_
21 #define SketchSolver_Group_H_
22
23 #include <SketchSolver_Constraint.h>
24 #include <SketchSolver_Storage.h>
25
26 #include <PlaneGCSSolver_Solver.h>
27
28 #include <SketchPlugin_Constraint.h>
29
30 #include <memory>
31 #include <map>
32
33 class GeomAPI_Pnt2d;
34
35 typedef std::map<ConstraintPtr, SolverConstraintPtr> ConstraintConstraintMap;
36
37 /** \class   SketchSolver_Group
38  *  \ingroup Plugins
39  *  \brief   Keeps the group of constraints which placed in the same sketch
40  */
41 class SketchSolver_Group
42 {
43  public:
44   /** \brief New group based on specified workplane.
45    *         Throws an exception if theWorkplane is not an object of SketchPlugin_Sketch type
46    *  \remark Type of theSketch is not verified inside
47    */
48   SketchSolver_Group(const CompositeFeaturePtr& theWorkplane);
49
50   virtual ~SketchSolver_Group();
51
52   /// \brief Returns true if the group has no constraints yet
53   inline bool isEmpty() const
54   {
55     return myConstraints.empty() && myTempConstraints.empty();
56   }
57
58   /// \brief Check for valid sketch data
59   inline bool isWorkplaneValid() const
60   {
61     return mySketch->data() && mySketch->data()->isValid();
62   }
63
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
67    */
68   bool changeConstraint(std::shared_ptr<SketchPlugin_Constraint> theConstraint);
69
70   /** \brief Updates the data corresponding the specified feature
71    *  \param[in] theFeature the feature to be updated
72    */
73   bool updateFeature(FeaturePtr theFeature);
74
75   /** \brief Updates the data corresponding the specified feature moved in GUI.
76    *         Special kind of Fixed constraints is created.
77    *  \param[in] theFeature the feature to be updated
78    *  \param[in] theFrom    start point of the movement
79    *  \param[in] theTo      final point of the movement
80    *  \return \c true, if the feature is really moved
81    */
82   bool moveFeature(FeaturePtr theFeature,
83                    const std::shared_ptr<GeomAPI_Pnt2d>& theFrom,
84                    const std::shared_ptr<GeomAPI_Pnt2d>& theTo);
85   /** \brief Updates the data corresponding the specified point moved in GUI.
86    *         Special kind of Fixed constraints is created.
87    *  \param[in] thePoint the attribute to be updated
88    *  \param[in] theFrom  start point of the movement
89    *  \param[in] theTo    final point of the movement
90    *  \return \c true, if the attribute is really moved
91    */
92   bool movePoint(AttributePtr thePoint,
93                  const std::shared_ptr<GeomAPI_Pnt2d>& theFrom,
94                  const std::shared_ptr<GeomAPI_Pnt2d>& theTo);
95
96   /// Returns the current workplane
97   inline const CompositeFeaturePtr& getWorkplane() const
98   {
99     return mySketch;
100   }
101
102   /** \brief Searches invalid features and constraints in the group and removes them
103    *  \return \c false if the group several constraints were removed
104    */
105   void repairConsistency();
106
107   /** \brief Start solution procedure if necessary and update attributes of features
108    *  \return \c false when no need to solve constraints
109    */
110   bool resolveConstraints();
111
112   /// \brief Block or unblock events sent by features in this group
113   void blockEvents(bool isBlocked);
114
115 private:
116   /// \biref Verify constraints have not been removed
117   bool areConstraintsValid() const;
118
119   /** \brief Removes constraints from the group
120    *  \param[in] theConstraint constraint to be removed
121    */
122   void removeConstraint(ConstraintPtr theConstraint);
123
124   /// \brief Remove all temporary constraints after the computation finished
125   void removeTemporaryConstraints();
126
127   /// \brief Append given constraint to the group of temporary constraints
128   void setTemporary(SolverConstraintPtr theConstraint);
129
130   /// \brief Compute DoF of the sketch and set corresponding field
131   void computeDoF();
132
133 private:
134   CompositeFeaturePtr mySketch; ///< Sketch for this group
135   ConstraintConstraintMap myConstraints; ///< List of constraints
136   std::set<SolverConstraintPtr> myTempConstraints; ///< List of temporary constraints
137
138   StoragePtr myStorage; ///< Container for the set of SolveSpace constraints and their entities
139   SolverPtr mySketchSolver;  ///< Solver for set of equations obtained by constraints
140
141   /// Result of previous solution of the set of constraints
142   PlaneGCSSolver_Solver::SolveStatus myPrevResult;
143   std::set<ObjectPtr>      myConflictingConstraints; ///< List of conflicting constraints
144
145   int  myDOF; ///< degrees of freedom of the current sketch
146
147   bool myIsEventsBlocked; ///< shows the events are blocked for this group
148
149   int myMultiConstraintUpdateStack; ///< depth of the stack updating "Multi" constraints
150 };
151
152 typedef std::shared_ptr<SketchSolver_Group> SketchGroupPtr;
153
154 #endif