Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / SketchSolver / SketchSolver_Group.h
1 // Copyright (C) 2014-2017  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<mailto: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 typedef std::map<ConstraintPtr, SolverConstraintPtr> ConstraintConstraintMap;
34
35 /** \class   SketchSolver_Group
36  *  \ingroup Plugins
37  *  \brief   Keeps the group of constraints which placed in the same sketch
38  */
39 class SketchSolver_Group
40 {
41  public:
42   /** \brief New group based on specified workplane.
43    *         Throws an exception if theWorkplane is not an object of SketchPlugin_Sketch type
44    *  \remark Type of theSketch is not verified inside
45    */
46   SketchSolver_Group(const CompositeFeaturePtr& theWorkplane);
47
48   virtual ~SketchSolver_Group();
49
50   /// \brief Returns true if the group has no constraints yet
51   inline bool isEmpty() const
52   {
53     return myConstraints.empty() && myTempConstraints.empty();
54   }
55
56   /// \brief Check for valid sketch data
57   inline bool isWorkplaneValid() const
58   {
59     return mySketch->data() && mySketch->data()->isValid();
60   }
61
62   /** \brief Adds or updates a constraint in the group
63    *  \param[in] theConstraint constraint to be changed
64    *  \return \c true if the constraint added or updated successfully
65    */
66   bool changeConstraint(std::shared_ptr<SketchPlugin_Constraint> theConstraint);
67
68   /** \brief Updates the data corresponding the specified feature
69    *  \param[in] theFeature the feature to be updated
70    */
71   bool updateFeature(FeaturePtr theFeature);
72
73   /** \brief Updates the data corresponding the specified feature moved in GUI.
74    *         Additional Fixed constraints are created.
75    *  \param[in] theFeature the feature to be updated
76    *  \return \c true, if the feature is moved
77    */
78   bool moveFeature(FeaturePtr theFeature);
79
80   /// Returns the current workplane
81   inline const CompositeFeaturePtr& getWorkplane() const
82   {
83     return mySketch;
84   }
85
86   /** \brief Searches invalid features and constraints in the group and removes them
87    *  \return \c false if the group several constraints were removed
88    */
89   void repairConsistency();
90
91   /** \brief Start solution procedure if necessary and update attributes of features
92    *  \return \c false when no need to solve constraints
93    */
94   bool resolveConstraints();
95
96   /// \brief Block or unblock events sent by features in this group
97   void blockEvents(bool isBlocked);
98
99 private:
100   /// \biref Verify constraints have not been removed
101   bool areConstraintsValid() const;
102
103   /** \brief Removes constraints from the group
104    *  \param[in] theConstraint constraint to be removed
105    */
106   void removeConstraint(ConstraintPtr theConstraint);
107
108   /// \brief Remove all temporary constraints after the computation finished
109   void removeTemporaryConstraints();
110
111   /// \brief Append given constraint to the group of temporary constraints
112   void setTemporary(SolverConstraintPtr theConstraint);
113
114   /// \brief Compute DoF of the sketch and set corresponding field
115   void computeDoF();
116
117 private:
118   CompositeFeaturePtr mySketch; ///< Sketch for this group
119   ConstraintConstraintMap myConstraints; ///< List of constraints
120   std::set<SolverConstraintPtr> myTempConstraints; ///< List of temporary constraints
121
122   StoragePtr myStorage; ///< Container for the set of SolveSpace constraints and their entities
123   SolverPtr mySketchSolver;  ///< Solver for set of equations obtained by constraints
124
125   /// Result of previous solution of the set of constraints
126   PlaneGCSSolver_Solver::SolveStatus myPrevResult;
127   std::set<ObjectPtr>      myConflictingConstraints; ///< List of conflicting constraints
128
129   int  myDOF; ///< degrees of freedom of the current sketch
130
131   bool myIsEventsBlocked; ///< shows the events are blocked for this group
132
133   int myMultiConstraintUpdateStack; ///< depth of the stack updating "Multi" constraints
134 };
135
136 typedef std::shared_ptr<SketchSolver_Group> SketchGroupPtr;
137
138 #endif