Salome HOME
Angle presentation from NewGEOM_2.0.0. It is moved here to prepare a patch for OCCT...
[modules/shaper.git] / src / SketchSolver / SolveSpaceSolver / SolveSpaceSolver_Storage.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:    SolveSpaceSolver_Storage.h
4 // Created: 18 Mar 2015
5 // Author:  Artem ZHIDKOV
6
7 #ifndef SolveSpaceSolver_Storage_H_
8 #define SolveSpaceSolver_Storage_H_
9
10 #include <SketchSolver_Storage.h>
11 #include <SolveSpaceSolver_Solver.h>
12
13 #include <list>
14 #include <memory>
15 #include <set>
16 #include <vector>
17
18 typedef std::list< std::set<ConstraintWrapperPtr> >             SameConstraintMap;
19
20 /** \class   SolveSpaceSolver_Storage
21  *  \ingroup Plugins
22  *  \brief   Contains all necessary data in SolveSpace format to solve a single group of constraints
23  */
24 class SolveSpaceSolver_Storage : public SketchSolver_Storage
25 {
26 public:
27   SolveSpaceSolver_Storage(const GroupID& theGroup);
28
29 // =============   Inherited from SketchSolver_Storage   =============
30
31   /// \brief Update constraint's data
32   /// \return \c true if any value is updated
33   virtual bool update(ConstraintWrapperPtr theConstraint);
34   /// \brief Update entity's data
35   /// \return \c true if any value is updated
36   virtual bool update(EntityWrapperPtr theEntity);
37   /// \brief Update parameter's data
38   /// \return \c true if the value of parameter is updated
39   virtual bool update(ParameterWrapperPtr theParameter);
40
41   /// \brief Update SketchPlugin features after resolving constraints
42   /// \param theFixedOnly [in]  if \c true the fixed points will be updated only
43   virtual void refresh(bool theFixedOnly = false) const;
44
45   /// \brief Check if some parameters or entities are returned
46   ///        to the current group after removing temporary constraints
47   virtual void verifyFixed();
48
49   /// \brief Mark two points as coincident
50   virtual void addCoincidentPoints(EntityWrapperPtr theMaster, EntityWrapperPtr theSlave);
51
52   /// \brief Calculate point on theBase entity. Value theCoeff is in [0.0 .. 1.0] and
53   ///        shows the distance from the start point.
54   virtual EntityWrapperPtr calculateMiddlePoint(EntityWrapperPtr theBase, double theCoeff);
55
56 protected:
57   /// \brief Remove constraint
58   /// \return \c true if the constraint and all its parameters are removed successfully
59   virtual bool remove(ConstraintWrapperPtr theConstraint);
60   /// \brief Remove entity
61   /// \return \c true if the entity and all its parameters are removed successfully
62   virtual bool remove(EntityWrapperPtr theEntity);
63   /// \brief Remove parameter
64   /// \return \c true if the parameter has been removed
65   virtual bool remove(ParameterWrapperPtr theParameter);
66
67   /// \brief Remove point-point coincidence
68   bool removeCoincidence(ConstraintWrapperPtr theConstraint);
69
70   /// \brief Update the group for the given entity, its sub-entities and parameters
71   virtual void changeGroup(EntityWrapperPtr theEntity, const GroupID& theGroup);
72   /// \brief Update the group for the given parameter
73   virtual void changeGroup(ParameterWrapperPtr theParam, const GroupID& theGroup);
74
75
76 // =============   Own methods   =============
77 public:
78   /// \brief Obtain and store identifier of sketch
79   void storeWorkplane(EntityWrapperPtr theSketch);
80
81   /** \brief Add new parameter to the current group
82    *  \param[in] theParam  SolveSpace parameter
83    *  \return the ID of added parameter
84    */
85   Slvs_hParam addParameter(const Slvs_Param& theParam);
86   /** \brief Updates parameter in the current group. If the ID of parameter is zero, the new item will be added
87    *  \param[in] theParam  SolveSpace parameter
88    *  \return the ID of updated/added parameter
89    */
90   Slvs_hParam updateParameter(const Slvs_Param& theParam);
91   /** \brief Removes the parameter by its ID
92    *  \param[in] theParamID  index of parameter to be removed
93    *  \return \c true if the parameter was successfully removed
94    */
95   bool removeParameter(const Slvs_hParam& theParamID);
96   /// \brief Returns the parameter by its ID
97   const Slvs_Param& getParameter(const Slvs_hParam& theParamID) const;
98
99   /** \brief Add new entity to the current group
100    *  \param[in] theEntity  SolveSpace entity
101    *  \return the ID of added entity
102    */
103   Slvs_hEntity addEntity(const Slvs_Entity& theEntity);
104   /** \brief Updates entity in the current group. If the ID of entity is zero, the new item will be added
105    *  \param[in] theEntity  SolveSpace entity
106    *  \return the ID of updated/added entity
107    */
108   Slvs_hEntity updateEntity(const Slvs_Entity& theEntity);
109   /** \brief Removes the entity by its ID. All parameters used in this entity,
110    *         and not used in other constraints, will be removed too.
111    *  \param[in] theEntityID  index of entity to be removed
112    *  \return \c true if the entity was successfully removed
113    */
114   bool removeEntity(const Slvs_hEntity& theEntityID);
115   /// \brief Returns the entity by its ID
116   const Slvs_Entity& getEntity(const Slvs_hEntity& theEntityID) const;
117   /// \brief Returns maximal ID of entities in this storage
118   const Slvs_hEntity& entityMaxID() const
119   { return myEntityMaxID; }
120
121   /** \brief Add new constraint to the current group
122    *  \param[in] theConstraint   SolveSpace's constraint
123    *  \return the ID of added constraint
124    */
125   Slvs_hConstraint addConstraint(const Slvs_Constraint& theConstraint);
126   /** \brief Updates constraint in the current group.
127    *         If the ID of constraint is zero, the new item will be added
128    *  \param[in] theConstraint  SolveSpace constraint
129    *  \return the ID of updated/added constraint
130    */
131   Slvs_hConstraint updateConstraint(const Slvs_Constraint& theConstraint);
132   /** \brief Removes the constraint by its ID. All entities and parameters depending on this
133    *         constraint, which are not used in other constraints, will be removed too.
134    *  \param[in] theConstraintID  index of constraint to be removed
135    *  \return \c true if the constraint was successfully removed
136    */
137   bool removeConstraint(const Slvs_hConstraint& theConstraintID);
138   /// \brief Returns the constraint by its ID
139   const Slvs_Constraint& getConstraint(const Slvs_hConstraint& theConstraintID) const;
140   /// \brief Returns quantity of constraints in this storage
141   size_t nbConstraints() const
142   { return myConstraints.size(); }
143
144   /// \brief Shows the storage has the same constraint twice
145   virtual bool hasDuplicatedConstraint() const
146   { return myDuplicatedConstraint; }
147
148   /// \brief Initialize constraint solver by the entities collected by current storage
149   virtual void initializeSolver(SolverPtr theSolver);
150
151 private:
152   /// \brief Update arc points to be on circle sharp.
153   void adjustArc(const Slvs_Entity& theArc);
154
155   /// \brief Replace sub-entity theSource in all features by theDest
156   void replaceInFeatures(EntityWrapperPtr theSource, EntityWrapperPtr theDest);
157   /// \brief Replace constrained entity theSource by theDest in all constraints;
158   void replaceInConstraints(EntityWrapperPtr theSource, EntityWrapperPtr theDest);
159
160   /// \brief Add pair of constraints which have same representation in SolveSpace notation.
161   ///
162   ///        These constraints may be different and become the same after the substitution
163   ///        of point coincidence.
164   void addSameConstraints(ConstraintWrapperPtr theConstraint1, ConstraintWrapperPtr theConstraint2);
165
166   /// \brief Search constraint equal to the given in terms of SolveSpace notation
167   bool findSameConstraint(ConstraintWrapperPtr theConstraint);
168
169 private:
170   Slvs_hEntity myWorkplaneID; ///< identifier of workplane
171
172   Slvs_hParam myParamMaxID; ///< current parameter index (may differs with the number of parameters)
173   std::vector<Slvs_Param> myParameters; ///< list of parameters used in the current group of constraints (sorted by the identifier)
174   Slvs_hEntity myEntityMaxID; ///< current entity index (may differs with the number of entities)
175   std::vector<Slvs_Entity> myEntities; ///< list of entities used in the current group of constraints (sorted by the identifier)
176   Slvs_hConstraint myConstrMaxID; ///< current constraint index (may differs with the number of constraints)
177   std::vector<Slvs_Constraint> myConstraints; ///< list of constraints used in the current group (sorted by the identifier)
178
179   bool myDuplicatedConstraint; ///< shows the storage has same constraint twice
180
181   SameConstraintMap myEqualConstraints; ///< list of groups of equal constraints
182 };
183
184 #endif