Salome HOME
Fix for the issue #2753 : error when dump/load script
[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_DEGENERATED,
39     STATUS_FAILED, // set if no one other status is applicable
40     STATUS_UNKNOWN // set for newly created groups
41   };
42
43   PlaneGCSSolver_Solver();
44   ~PlaneGCSSolver_Solver();
45
46   /// \brief Clear system of equations
47   void clear();
48
49   /// \brief Add constraint to the system of equations
50   /// \param[in] theMultiConstraintID  ID of the multi constraint which may consists of
51   ///                                  several primitive constraints
52   /// \param[in] theConstraints        list of primitive constraints
53   void addConstraint(const ConstraintID& theMultiConstraintID,
54                      const std::list<GCSConstraintPtr>& theConstraints);
55
56   /// \brief Remove constraints from the system of equations
57   void removeConstraint(const ConstraintID& theID);
58
59   /// \brief Initialize memory for new solver's parameter
60   double* createParameter();
61   /// \brief Add parameters created elsewhere
62   void addParameters(const GCS::SET_pD& theParams);
63   /// \brief Release memory occupied by parameters
64   void removeParameters(const GCS::SET_pD& theParams);
65
66   /// \brief Preliminary initialization of solver (useful for moving a feature).
67   ///        When called, the solve() method does not reinitialize a set of constraints.
68   void initialize();
69
70   /// \brief Solve the set of equations
71   /// \return identifier whether solution succeeded
72   SolveStatus solve();
73
74   /// \brief Revert solution to initial values
75   void undo();
76
77   /// \brief Check the constraint is conflicted with others
78   bool isConflicting(const ConstraintID& theConstraint) const;
79
80   /// \brief Check conflicting/redundant constraints and DoF
81   void diagnose(const GCS::Algorithm& theAlgo = GCS::DogLeg);
82
83   /// \brief Degrees of freedom
84   int dof();
85
86 private:
87   void collectConflicting(bool withRedundant = true);
88
89   /// \brief Add fictive constraint if the sketch contains temporary constraints only
90   void addFictiveConstraintIfNecessary();
91   /// \brief Remove previously added fictive constraint
92   void removeFictiveConstraint();
93
94 private:
95   typedef std::map<ConstraintID, std::set<GCSConstraintPtr> > ConstraintMap;
96
97   GCS::VEC_pD                  myParameters;     ///< list of unknowns
98   ConstraintMap                myConstraints;    ///< list of constraints
99
100   std::shared_ptr<GCS::System> myEquationSystem; ///< set of equations for solving in FreeGCS
101   bool                         myDiagnoseBeforeSolve; ///< is the diagnostic necessary
102   bool                         myInitilized;     ///< is the system already initialized
103
104   GCS::SET_I                   myConflictingIDs; ///< list of IDs of conflicting constraints
105   /// specifies the conflicting constraints are already collected
106   bool                         myConfCollected;
107
108   int                          myDOF;            ///< degrees of freedom
109
110   GCS::Constraint*             myFictiveConstraint;
111 };
112
113 typedef std::shared_ptr<PlaneGCSSolver_Solver> SolverPtr;
114
115 #endif