Salome HOME
Merge remote-tracking branch 'remotes/origin/master'
[modules/shaper.git] / src / SketchSolver / PlaneGCSSolver / PlaneGCSSolver_Solver.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 PlaneGCSSolver_Solver_H_
22 #define PlaneGCSSolver_Solver_H_
23
24 #include <PlaneGCSSolver_Defs.h>
25 #include <PlaneGCSSolver_ConstraintWrapper.h>
26
27 #include <GCS.h>
28
29 /// \brief The main class that performs the high-level operations for connection to the PlaneGCS.
30 class PlaneGCSSolver_Solver
31 {
32 public:
33   /// The result of constraints solution
34   enum SolveStatus {
35     STATUS_OK,
36     STATUS_INCONSISTENT,
37     STATUS_EMPTYSET,
38     STATUS_FAILED, // set if no one other status is applicable
39     STATUS_UNKNOWN // set for newly created groups
40   };
41
42   PlaneGCSSolver_Solver();
43   ~PlaneGCSSolver_Solver();
44
45   /// \brief Clear system of equations
46   void clear();
47
48   /// \brief Add constraint to the system of equations
49   void addConstraint(GCSConstraintPtr theConstraint);
50
51   /// \brief Remove constraint from the system of equations
52   void removeConstraint(ConstraintID theID);
53
54   /// \brief Initialize memory for new solver's parameter
55   double* createParameter();
56   /// \brief Add parameters created elsewhere
57   void addParameters(const GCS::SET_pD& theParams);
58   /// \brief Release memory occupied by parameters
59   void removeParameters(const GCS::SET_pD& theParams);
60
61   /// \brief Preliminary initialization of solver (useful for moving a feature).
62   ///        When called, the solve() method does not reinitialize a set of constraints.
63   void initialize();
64
65   /// \brief Solve the set of equations
66   /// \return identifier whether solution succeeded
67   SolveStatus solve();
68
69   /// \brief Revert solution to initial values
70   void undo();
71
72   /// \brief Check the constraint is conflicted with others
73   bool isConflicting(const ConstraintID& theConstraint) const;
74
75   /// \brief Check conflicting/redundant constraints and DoF
76   void diagnose();
77
78   /// \brief Degrees of freedom
79   int dof();
80
81 private:
82   void collectConflicting();
83
84 private:
85   typedef std::map<ConstraintID, std::set<GCSConstraintPtr> > ConstraintMap;
86
87   GCS::VEC_pD                  myParameters;     ///< list of unknowns
88   ConstraintMap                myConstraints;    ///< list of constraints
89
90   std::shared_ptr<GCS::System> myEquationSystem; ///< set of equations for solving in FreeGCS
91   bool                         myDiagnoseBeforeSolve; ///< is the diagnostic necessary
92   bool                         myInitilized;     ///< is the system already initialized
93
94   GCS::SET_I                   myConflictingIDs; ///< list of IDs of conflicting constraints
95   /// specifies the conflicting constraints are already collected
96   bool                         myConfCollected;
97
98   int                          myDOF;            ///< degrees of freedom
99 };
100
101 typedef std::shared_ptr<PlaneGCSSolver_Solver> SolverPtr;
102
103 #endif