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