]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchSolver/SketchSolver_Storage.h
Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom.git into Dev_1.1.0
[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 <list>
14 #include <memory>
15 #include <set>
16 #include <vector>
17
18 /** \class   SketchSolver_Storage
19  *  \ingroup Plugins
20  *  \brief   Contains all necessary data in SolveSpace format to solve a single group of constraints
21  */
22 class SketchSolver_Storage
23 {
24 public:
25   SketchSolver_Storage();
26
27   /** \brief Add new parameter to the current group
28    *  \param[in] theParam  SolveSpace parameter
29    *  \return the ID of added parameter
30    */
31   Slvs_hParam addParameter(const Slvs_Param& theParam);
32   /** \brief Updates parameter in the current group. If the ID of parameter is zero, the new item will be added
33    *  \param[in] theParam  SolveSpace parameter
34    *  \return the ID of updated/added parameter
35    */
36   Slvs_hParam updateParameter(const Slvs_Param& theParam);
37   /** \brief Removes the parameter by its ID
38    *  \param[in] theParamID  index of parameter to be removed
39    *  \return \c true if the parameter was successfully removed
40    */
41   bool removeParameter(const Slvs_hParam& theParamID);
42   /// \brief Returns the parameter by its ID
43   const Slvs_Param& getParameter(const Slvs_hParam& theParamID) const;
44
45   /** \brief Add new entity to the current group
46    *  \param[in] theEntity  SolveSpace entity
47    *  \return the ID of added entity
48    */
49   Slvs_hEntity addEntity(const Slvs_Entity& theEntity);
50   /** \brief Updates entity in the current group. If the ID of entity is zero, the new item will be added
51    *  \param[in] theEntity  SolveSpace entity
52    *  \return the ID of updated/added entity
53    */
54   Slvs_hEntity updateEntity(const Slvs_Entity& theEntity);
55   /** \brief Removes the entity by its ID. All parameters used in this entity,
56    *         and not used in other constraints, will be removed too.
57    *  \param[in] theEntityID  index of entity to be removed
58    *  \return \c true if the entity was successfully removed
59    */
60   bool removeEntity(const Slvs_hEntity& theEntityID);
61   /// \brief Returns the entity by its ID
62   const Slvs_Entity& getEntity(const Slvs_hEntity& theEntityID) const;
63   /// \brief Makes a full copy of the given entity
64   Slvs_hEntity copyEntity(const Slvs_hEntity& theCopied);
65   /// \brief Copy one entity to another
66   void copyEntity(const Slvs_hEntity& theFrom, const Slvs_hEntity& theTo);
67
68   /// \brief Verifies the current point or another coincident one is fixed
69   /// \return the ID of the Fixed constraint or SLVS_E_UNKNOWN
70   Slvs_hConstraint isPointFixed(const Slvs_hEntity& thePointID) const;
71
72   /** \brief Add new constraint to the current group
73    *  \param[in] theConstraint   SolveSpace's constraint
74    *  \return the ID of added constraint
75    */
76   Slvs_hConstraint addConstraint(const Slvs_Constraint& theConstraint);
77   /** \brief Updates constraint in the current group.
78    *         If the ID of constraint is zero, the new item will be added
79    *  \param[in] theConstraint  SolveSpace constraint
80    *  \return the ID of updated/added constraint
81    */
82   Slvs_hConstraint updateConstraint(const Slvs_Constraint& theConstraint);
83   /** \brief Removes the constraint by its ID. All entities and parameters depending on this
84    *         constraint, which are not used in other constraints, will be removed too.
85    *  \param[in] theConstraintID  index of constraint to be removed
86    *  \return \c true if the constraint was successfully removed
87    */
88   bool removeConstraint(const Slvs_hConstraint& theConstraintID);
89   /// \brief Returns the constraint by its ID
90   const Slvs_Constraint& getConstraint(const Slvs_hConstraint& theConstraintID) const;
91   /// \brief Returns list of constraints of specified type
92   std::list<Slvs_Constraint> getConstraintsByType(int theConstraintType) const;
93
94   /// \brief Attach constraint SLVS_C_WHERE_DRAGGED to this storage. It need to make precise calculations
95   void addConstraintWhereDragged(const Slvs_hConstraint& theConstraintID);
96
97   /// \brief Add transient constraint
98   void addTemporaryConstraint(const Slvs_hConstraint& theConstraintID);
99   /// \brief Remove all transient constraints
100   void removeTemporaryConstraints();
101   /// \brief Checks the constraint is temporary
102   bool isTemporary(const Slvs_hConstraint& theConstraintID) const;
103
104   /// \brief Shows the sketch should be resolved
105   bool isNeedToResolve() const
106   { return myNeedToResolve; }
107
108   /// \brief Changes the flag of group to be resolved
109   void setNeedToResolve(bool theFlag)
110   { myNeedToResolve = theFlag; }
111
112   /// \brief Returns lists of removed elements
113   void getRemoved(std::set<Slvs_hParam>& theParameters,
114                   std::set<Slvs_hEntity>& theEntities,
115                   std::set<Slvs_hConstraint>& theConstraints);
116
117   /// \brief Initialize constraint solver by the entities collected by current storage
118   void initializeSolver(SketchSolver_Solver& theSolver);
119
120 private:
121   /// \brief Store coincident points
122   void addCoincidentPoints(const Slvs_hEntity& thePoint1, const Slvs_hEntity& thePoint2);
123   /// \brief Remove point from lists of coincidence
124   void removeCoincidentPoint(const Slvs_hEntity& thePoint);
125
126 public:
127   /// \brief Check two points are coincident
128   bool isCoincident(const Slvs_hEntity& thePoint1, const Slvs_hEntity& thePoint2) const;
129
130 private:
131   Slvs_hParam myParamMaxID; ///< current parameter index (may differs with the number of parameters)
132   std::vector<Slvs_Param> myParameters; ///< list of parameters used in the current group of constraints (sorted by the identifier)
133   Slvs_hEntity myEntityMaxID; ///< current entity index (may differs with the number of entities)
134   std::vector<Slvs_Entity> myEntities; ///< list of entities used in the current group of constraints (sorted by the identifier)
135   Slvs_hConstraint myConstrMaxID; ///< current constraint index (may differs with the number of constraints)
136   std::vector<Slvs_Constraint> myConstraints; ///< list of constraints used in the current group (sorted by the identifier)
137
138   std::vector< std::set<Slvs_hEntity> > myCoincidentPoints; ///< lists of coincident points
139   Slvs_hConstraint myFixed; ///< identifier of one of temporary constraints to fix separate point
140
141   bool myNeedToResolve; ///< parameters are changed and group needs to be resolved
142
143   std::set<Slvs_hConstraint> myTemporaryConstraints; ///< list of transient constraints
144   std::set<Slvs_hParam> myRemovedParameters; ///< list of just removed parameters (cleared when returning to applicant)
145   std::set<Slvs_hEntity> myRemovedEntities; ///< list of just removed entities (cleared when returning to applicant)
146   std::set<Slvs_hConstraint> myRemovedConstraints; ///< list of just removed constraints (cleared when returning to applicant)
147 };
148
149 typedef std::shared_ptr<SketchSolver_Storage> StoragePtr;
150
151 #endif