Salome HOME
Merge remote-tracking branch 'remotes/origin/HigherLevelObjectsHistory'
[modules/shaper.git] / src / SketchSolver / PlaneGCSSolver / PlaneGCSSolver_Solver.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 PlaneGCSSolver_Solver_H_
21 #define PlaneGCSSolver_Solver_H_
22
23 #include <PlaneGCSSolver_Defs.h>
24 #include <PlaneGCSSolver_ConstraintWrapper.h>
25
26 #include <GCS.h>
27
28 /// \brief The main class that performs the high-level operations for connection to the PlaneGCS.
29 class PlaneGCSSolver_Solver
30 {
31 public:
32   /// The result of constraints solution
33   enum SolveStatus {
34     STATUS_OK,
35     STATUS_INCONSISTENT,
36     STATUS_EMPTYSET,
37     STATUS_DEGENERATED,
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   /// \param[in] theMultiConstraintID  ID of the multi constraint which may consists of
50   ///                                  several primitive constraints
51   /// \param[in] theConstraints        list of primitive constraints
52   void addConstraint(const ConstraintID& theMultiConstraintID,
53                      const std::list<GCSConstraintPtr>& theConstraints);
54
55   /// \brief Remove constraints from the system of equations
56   void removeConstraint(const ConstraintID& theID);
57
58   /// \brief Initialize memory for new solver's parameter
59   double* createParameter();
60   /// \brief Add parameters created elsewhere
61   void addParameters(const GCS::SET_pD& theParams);
62   /// \brief Release memory occupied by parameters
63   void removeParameters(const GCS::SET_pD& theParams);
64
65   /// \brief Preliminary initialization of solver (useful for moving a feature).
66   ///        When called, the solve() method does not reinitialize a set of constraints.
67   void initialize();
68
69   /// \brief Solve the set of equations
70   /// \return identifier whether solution succeeded
71   SolveStatus solve();
72
73   /// \brief Revert solution to initial values
74   void undo();
75
76   /// \brief Check the constraint is conflicted with others
77   bool isConflicting(const ConstraintID& theConstraint) const;
78
79   /// \brief Check conflicting/redundant constraints and DoF
80   void diagnose(const GCS::Algorithm& theAlgo = GCS::DogLeg);
81
82   /// \brief Degrees of freedom
83   int dof();
84
85 private:
86   void collectConflicting(bool withRedundant = true);
87
88   /// \brief Add fictive constraint if the sketch contains temporary constraints only
89   void addFictiveConstraintIfNecessary();
90   /// \brief Remove previously added fictive constraint
91   void removeFictiveConstraint();
92
93 private:
94   typedef std::map<ConstraintID, std::set<GCSConstraintPtr> > ConstraintMap;
95
96   GCS::VEC_pD                  myParameters;     ///< list of unknowns
97   ConstraintMap                myConstraints;    ///< list of constraints
98
99   std::shared_ptr<GCS::System> myEquationSystem; ///< set of equations for solving in FreeGCS
100   bool                         myDiagnoseBeforeSolve; ///< is the diagnostic necessary
101   bool                         myInitilized;     ///< is the system already initialized
102
103   GCS::SET_I                   myConflictingIDs; ///< list of IDs of conflicting constraints
104   /// specifies the conflicting constraints are already collected
105   bool                         myConfCollected;
106
107   int                          myDOF;            ///< degrees of freedom
108
109   GCS::Constraint*             myFictiveConstraint;
110 };
111
112 typedef std::shared_ptr<PlaneGCSSolver_Solver> SolverPtr;
113
114 #endif