Salome HOME
Move MakeBrick*.py to examples module for availability for testing.
[modules/shaper.git] / src / SketchSolver / SketchSolver_Solver.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:    SketchSolver_Solver.h
4 // Created: 07 May 2014
5 // Author:  Artem ZHIDKOV
6
7 #ifndef SketchSolver_Solver_H_
8 #define SketchSolver_Solver_H_
9
10 #include "SketchSolver.h"
11
12 // Need to be defined before including SolveSpace to avoid additional dependances on Windows platform
13 #if defined(WIN32) && !defined(HAVE_C99_INTEGER_TYPES)
14 typedef unsigned int UINT32;
15 #else
16 #include <stdint.h>
17 #endif
18 #include <string.h>
19 #include <slvs.h>
20
21 #include <vector>
22
23 #define SLVS_RESULT_EMPTY_SET -1
24
25 // Unknown constraint (for error reporting)
26 #define SLVS_C_UNKNOWN 0
27 // Fillet constraint identifier
28 #define SLVS_C_FILLET            100100
29 // Multi-rotation constraint identifier
30 #define SLVS_C_MULTI_ROTATION    100101
31 // Multi-translation constraint identifier
32 #define SLVS_C_MULTI_TRANSLATION 100102
33 // Unknown entity
34 #define SLVS_E_UNKNOWN 0
35 // Unknown group
36 #define SLVS_G_UNKNOWN 0
37
38 /**
39  * The main class that performs the high-level operations for connection to the SolveSpace.
40  */
41 class SketchSolver_Solver
42 {
43  public:
44   SketchSolver_Solver();
45   ~SketchSolver_Solver();
46
47   /** \brief Initialize the ID of the group
48    */
49   inline void setGroupID(Slvs_hGroup theGroupID)
50   {
51     myGroupID = theGroupID;
52   }
53
54   /** \brief Change array of parameters
55    *  \param[in] theParameters pointer to the array of parameters
56    *  \param[in] theSize       size of this array
57    */
58   void setParameters(Slvs_Param* theParameters, int theSize);
59
60   /** \brief Change array of entities
61    *  \param[in] theEntities pointer to the array of entities
62    *  \param[in] theSize     size of this array
63    */
64   void setEntities(Slvs_Entity* theEntities, int theSize);
65
66   /** \brief Change array of constraints
67    *  \param[in] theConstraints pointer to the array of constraints
68    *  \param[in] theSize        size of this array
69    */
70   void setConstraints(Slvs_Constraint* theConstraints, int theSize);
71
72   /** \brief Store the parameters of the point which was moved by user.
73    *         The solver will watch this items to be constant
74    *  \param[in] theDragged list of parameters (not more than 4) which should not be changed during solving
75    */
76   void setDraggedParameters(const Slvs_hParam* theDragged);
77
78   /** \brief Set or unset the flag which allows to find all failed constraints
79    */
80   void calculateFailedConstraints(bool theSic)
81   { myEquationsSystem.calculateFaileds = theSic ? 1 : 0; }
82
83   /** \brief Solve the set of equations
84    *  \return identifier whether solution succeeded
85    */
86   int solve();
87
88   /** \brief Updates the list of parameters by calculated values
89    *  \param[in,out] theParameters parameters to be updated
90    *  \return \c true if parameters are updated correctly
91    */
92   bool getResult(std::vector<Slvs_Param>& theParameters);
93
94  private:
95   Slvs_hGroup myGroupID;         ///< identifier of the group to be solved
96   Slvs_System myEquationsSystem;  ///< set of equations for solving in SolveSpace
97 };
98
99 #endif