]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchSolver/SketchSolver_Storage.h
Salome HOME
SketchSolver library refactoring
[modules/shaper.git] / src / SketchSolver / SketchSolver_Storage.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:    SketchSolver_Storage.h
4 // Created: 18 Mar 2015
5 // Author:  Artem ZHIDKOV
6
7 #ifndef SketchSolver_Storage_H_
8 #define SketchSolver_Storage_H_
9
10 #include "SketchSolver.h"
11 #include <SketchSolver_Solver.h>
12
13 #include <memory>
14 #include <set>
15 #include <vector>
16
17 /** \class   SketchSolver_Storage
18  *  \ingroup Plugins
19  *  \brief   Contains all necessary data in SolveSpace format to solve a single group of constraints
20  */
21 class SketchSolver_Storage
22 {
23 public:
24   SketchSolver_Storage();
25
26   /** \brief Add new parameter to the current group
27    *  \param[in] theParam  SolveSpace parameter
28    *  \return the ID of added parameter
29    */
30   Slvs_hParam addParameter(const Slvs_Param& theParam);
31   /** \brief Updates parameter in the current group. If the ID of parameter is zero, the new item will be added
32    *  \param[in] theParam  SolveSpace parameter
33    *  \return the ID of updated/added parameter
34    */
35   Slvs_hParam updateParameter(const Slvs_Param& theParam);
36   /** \brief Removes the parameter by its ID
37    *  \param[in] theParamID  index of parameter to be removed
38    *  \return \c true if the parameter was successfully removed
39    */
40   bool removeParameter(const Slvs_hParam& theParamID);
41   /// \brief Returns the parameter by its ID
42   const Slvs_Param& getParameter(const Slvs_hParam& theParamID) const;
43
44   /** \brief Add new entity to the current group
45    *  \param[in] theEntity  SolveSpace entity
46    *  \return the ID of added entity
47    */
48   Slvs_hEntity addEntity(const Slvs_Entity& theEntity);
49   /** \brief Updates entity in the current group. If the ID of entity is zero, the new item will be added
50    *  \param[in] theEntity  SolveSpace entity
51    *  \return the ID of updated/added entity
52    */
53   Slvs_hEntity updateEntity(const Slvs_Entity& theEntity);
54   /** \brief Removes the entity by its ID. All parameters used in this entity,
55    *         and not used in other constraints, will be removed too.
56    *  \param[in] theEntityID  index of entity to be removed
57    *  \return \c true if the entity was successfully removed
58    */
59   bool removeEntity(const Slvs_hEntity& theEntityID);
60   /// \brief Returns the entity by its ID
61   const Slvs_Entity& getEntity(const Slvs_hEntity& theEntityID) const;
62
63   /** \brief Add new constraint to the current group
64    *  \param[in] theConstraint  SolveSpace constraint
65    *  \return the ID of added constraint
66    */
67   Slvs_hConstraint addConstraint(const Slvs_Constraint& theConstraint);
68   /** \brief Updates constraint in the current group.
69    *         If the ID of constraint is zero, the new item will be added
70    *  \param[in] theConstraint  SolveSpace constraint
71    *  \return the ID of updated/added constraint
72    */
73   Slvs_hConstraint updateConstraint(const Slvs_Constraint& theConstraint);
74   /** \brief Removes the constraint by its ID. All entities and parameters depending on this
75    *         constraint, which are not used in other constraints, will be removed too.
76    *  \param[in] theConstraintID  index of constraint to be removed
77    *  \return \c true if the constraint was successfully removed
78    */
79   bool removeConstraint(const Slvs_hConstraint& theConstraintID);
80   /// \brief Returns the constraint by its ID
81   const Slvs_Constraint& getConstraint(const Slvs_hConstraint& theConstraintID) const;
82
83   /// \brief Attach temporary constraint to this storage. It need to make precise calculations
84   void addTemporaryConstraint(const Slvs_hConstraint& theConstraintID);
85
86   /// \brief Shows the sketch should be resolved
87   bool isNeedToResolve() const
88   { return myNeedToResolve; }
89
90   /// \brief Changes the flag of group to be resolved
91   void setNeedToResolve(bool theFlag)
92   { myNeedToResolve = theFlag; }
93
94   /// \brief Returns lists of removed elements
95   void getRemoved(std::set<Slvs_hParam>& theParameters,
96                   std::set<Slvs_hEntity>& theEntities,
97                   std::set<Slvs_hConstraint>& theConstraints);
98
99   /// \brief Initialize constraint solver by the entities collected by current storage
100   void initializeSolver(SketchSolver_Solver& theSolver);
101
102 private:
103   Slvs_hParam myParamMaxID; ///< current parameter index (may differs with the number of parameters)
104   std::vector<Slvs_Param> myParameters; ///< list of parameters used in the current group of constraints
105   Slvs_hEntity myEntityMaxID; ///< current entity index (may differs with the number of entities)
106   std::vector<Slvs_Entity> myEntities; ///< list of entities used in the current group of constraints
107   Slvs_hConstraint myConstrMaxID; ///< current constraint index (may differs with the number of constraints)
108   std::vector<Slvs_Constraint> myConstraints; ///< list of constraints used in the current group
109
110   std::vector<Slvs_hEntity> myFixedPoints; ///< identifiers of entities which relate to temporary constraints
111
112   bool myNeedToResolve; ///< parameters are changed and group needs to be resolved
113
114   std::set<Slvs_hParam> myRemovedParameters; ///< list of just removed parameters (cleared when returning to applicant)
115   std::set<Slvs_hEntity> myRemovedEntities; ///< list of just removed entities (cleared when returning to applicant)
116   std::set<Slvs_hConstraint> myRemovedConstraints; ///< list of just removed constraints (cleared when returning to applicant)
117 };
118
119 typedef std::shared_ptr<SketchSolver_Storage> StoragePtr;
120
121 #endif