Salome HOME
0db5bf72cbbd3f22aac4e3a61b1fb36ad91ebeb9
[modules/shaper.git] / src / SketchSolver / SolveSpaceSolver / SolveSpaceSolver_Solver.h
1 // Copyright (C) 2014-2021  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 SolveSpaceSolver_Solver_H_
21 #define SolveSpaceSolver_Solver_H_
22
23 #include <SketchSolver_ISolver.h>
24
25 // Need to be defined before including SolveSpace to avoid additional
26 // dependences on Windows platform
27 #if defined(WIN32) && !defined(HAVE_C99_INTEGER_TYPES)
28 typedef unsigned int UINT32;
29 #else
30 #include <stdint.h>
31 #endif
32 #include <string.h>
33 #include <slvs.h>
34
35 #include <vector>
36
37 // Unknown constraint (for error reporting)
38 #define SLVS_C_UNKNOWN 0
39 // Fillet constraint identifier
40 #define SLVS_C_FILLET            100100
41 // Multi-rotation constraint identifier
42 #define SLVS_C_MULTI_ROTATION    100101
43 // Multi-translation constraint identifier
44 #define SLVS_C_MULTI_TRANSLATION 100102
45 // Unknown entity
46 #define SLVS_E_UNKNOWN 0
47 // Unknown group
48 #define SLVS_G_UNKNOWN 0
49 // Group ID to store external objects
50 #define SLVS_G_OUTOFGROUP 1
51
52 /** \class SolveSpaceSolver_Solver
53  *  \ingroup Plugins
54  *  \brief Performs high-level operations to solve sketch in SolveSpace.
55  */
56 class SolveSpaceSolver_Solver : public SketchSolver_ISolver
57 {
58 public:
59   SolveSpaceSolver_Solver();
60   virtual ~SolveSpaceSolver_Solver();
61
62   /** \brief Change array of parameters
63    *  \param[in] theParameters pointer to the array of parameters
64    *  \param[in] theSize       size of this array
65    */
66   void setParameters(Slvs_Param* theParameters, int theSize);
67
68   /** \brief Change array of entities
69    *  \param[in] theEntities pointer to the array of entities
70    *  \param[in] theSize     size of this array
71    */
72   void setEntities(Slvs_Entity* theEntities, int theSize);
73
74   /** \brief Change array of constraints
75    *  \param[in] theConstraints pointer to the array of constraints
76    *  \param[in] theSize        size of this array
77    */
78   void setConstraints(Slvs_Constraint* theConstraints, int theSize);
79
80   /** \brief Store the parameters of the point which was moved by user.
81    *         The solver will watch this items to be constant
82    *  \param[in] theDragged list of parameters (not more than 4) which should not be changed during solving
83    */
84   void setDraggedParameters(const Slvs_hParam* theDragged);
85
86   /** \brief Solve the set of equations
87    *  \return identifier whether solution succeeded
88    */
89   virtual SketchSolver_SolveStatus solve();
90
91   /// \brief Prepare for solving. Store initial values of parameters for undo
92   virtual void prepare();
93
94   /// \brief Revert solution to initial values
95   virtual void undo();
96
97   /// \brief Check the constraint is conflicted with others
98   virtual bool isConflicting(const ConstraintID& theConstraint) const;
99
100   /// \brief Degrees of freedom
101   virtual int dof() const;
102
103 private:
104   /// \brief Check whether degenerated arcs exist
105   bool hasDegeneratedArcs() const;
106
107 private:
108   Slvs_System myEquationsSystem; ///< set of equations for solving in SolveSpace
109   Slvs_Param* myParamsCopy;      ///< copy of parameters
110 };
111
112 #endif