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