]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchSolver/SketchSolver_Storage.h
Salome HOME
Problem with moving fixed point
[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: 30 Nov 2015
5 // Author:  Artem ZHIDKOV
6
7 #ifndef SketchSolver_Storage_H_
8 #define SketchSolver_Storage_H_
9
10 #include <SketchSolver.h>
11 #include <SketchSolver_IConstraintWrapper.h>
12 #include <SketchSolver_IEntityWrapper.h>
13 #include <SketchSolver_IParameterWrapper.h>
14 #include <SketchSolver_ISolver.h>
15
16 #include <ModelAPI_Attribute.h>
17 #include <ModelAPI_AttributeDouble.h>
18 #include <ModelAPI_Feature.h>
19 #include <SketchPlugin_Constraint.h>
20
21 typedef std::map<EntityWrapperPtr, std::set<EntityWrapperPtr> > CoincidentPointsMap;
22
23 /** \class   SketchSolver_Storage
24  *  \ingroup Plugins
25  *  \brief   Interface to map SketchPlugin features to the entities of corresponding solver.
26  */
27 class SketchSolver_Storage
28 {
29 private:
30   SketchSolver_Storage();
31   SketchSolver_Storage(const SketchSolver_Storage&);
32   SketchSolver_Storage& operator=(const SketchSolver_Storage&);
33
34 public:
35   SketchSolver_Storage(const GroupID& theGroup)
36     : myGroupID(theGroup),
37       myNeedToResolve(false)
38   {}
39
40   /// \brief Change mapping between constraint from SketchPlugin and
41   ///        a constraint applicable for corresponding solver.
42   /// \param theConstraint       [in]   original SketchPlugin constraint
43   /// \param theSolverConstraint [in]   solver's constraints
44   SKETCHSOLVER_EXPORT void addConstraint(ConstraintPtr        theConstraint,
45                                          ConstraintWrapperPtr theSolverConstraints);
46   /// \brief Change mapping between constraint from SketchPlugin and
47   ///        the list of constraints applicable for corresponding solver.
48   /// \param theConstraint        [in]   original SketchPlugin constraint
49   /// \param theSolverConstraints [in]   list of solver's constraints
50   SKETCHSOLVER_EXPORT
51     void addConstraint(ConstraintPtr                   theConstraint,
52                        std::list<ConstraintWrapperPtr> theSolverConstraints);
53
54   /// \brief Convert feature to the form applicable for specific solver and map it
55   /// \param theFeature [in]  feature to convert
56   /// \param theGroup   [in]  id of the group where the feature should be placed
57   /// \return \c true if the feature has been created or updated
58   SKETCHSOLVER_EXPORT bool update(FeaturePtr theFeature, const GroupID& theGroup = GID_UNKNOWN);
59   /// \brief Convert attribute to the form applicable for specific solver and map it
60   /// \param theFeature [in]  feature to convert
61   /// \return \c true if the attribute has been created or updated
62   SKETCHSOLVER_EXPORT bool update(AttributePtr theAttribute, const GroupID& theGroup = GID_UNKNOWN);
63
64   /// \brief Returns constraint related to corresponding constraint
65   SKETCHSOLVER_EXPORT
66     const std::list<ConstraintWrapperPtr>& constraint(const ConstraintPtr& theConstraint) const;
67
68   /// \brief Returns entity related to corresponding feature
69   SKETCHSOLVER_EXPORT const EntityWrapperPtr& entity(const FeaturePtr& theFeature) const;
70   /// \brief Returns entity related to corresponding attribute
71   SKETCHSOLVER_EXPORT const EntityWrapperPtr& entity(const AttributePtr& theAttribute) const;
72
73   /// \brief Return parsed sketch entity
74   const EntityWrapperPtr& sketch() const;
75   /// \brief Set parsed sketch entity.
76   /// Be careful, this method does not update fields of the storage specific for the solver.
77   /// Does not update if the sketch already exists.
78   void setSketch(const EntityWrapperPtr& theSketch);
79
80   /// \brief Mark two points as coincident
81   virtual void addCoincidentPoints(EntityWrapperPtr theMaster, EntityWrapperPtr theSlave) = 0;
82
83   /// \brief Shows the storage has any constraint twice
84   virtual bool hasDuplicatedConstraint() const = 0;
85
86   /// \brief Removes constraint from the storage
87   /// \return \c true if the constraint and all its parameters are removed successfully
88   virtual bool removeConstraint(ConstraintPtr theConstraint) = 0;
89   /// \brief Removes feature from the storage
90   /// \return \c true if the feature and its attributes are removed successfully;
91   ///         \c false if the feature or any it attribute is used by remaining constraints.
92   virtual bool removeEntity(FeaturePtr theFeature) = 0;
93   /// \brief Removes attribute from the storage
94   /// \return \c true if the attribute is not used by remaining features and constraints
95   virtual bool removeEntity(AttributePtr theAttribute) = 0;
96
97   /// \brief Remove all features became invalid
98   SKETCHSOLVER_EXPORT void removeInvalidEntities();
99
100   /// \brief Mark specified constraint as temporary
101   virtual void setTemporary(ConstraintPtr theConstraint) = 0;
102   /// \brief Returns number of temporary constraints
103   virtual size_t nbTemporary() const = 0;
104   /// \brief Remove temporary constraints
105   /// \param theNbConstraints [in]  number of temporary constraints to be deleted
106   /// \return number of remaining temporary constraints
107   virtual size_t removeTemporary(size_t theNbConstraints = 1) = 0;
108
109   /// \brief Check whether the feature or its attributes are used by this storage
110   /// \param theFeature [in]  feature to be checked
111   /// \return \c true if the feature interacts with the storage
112   bool isInteract(const FeaturePtr& theFeature) const;
113   /// \brief Check whether the attribute is used by this storage
114   /// \param theAttribute [in]  attribute to be checked
115   /// \return \c true if the attribute interacts with the storage
116   bool isInteract(const AttributePtr& theAttribute) const;
117
118   /// \brief Check the features is not removed
119   bool isConsistent() const;
120
121   /// \brief Check the entity is fixed.
122   ///        If the point is under verification, all coincident points are checked too.
123   bool isFixed(EntityWrapperPtr theEntity) const;
124
125   /// \brief Shows the sketch should be resolved
126   virtual bool isNeedToResolve()
127   { return myNeedToResolve; }
128   /// \brief Changes the flag of group to be resolved
129   void setNeedToResolve(bool theFlag)
130   { myNeedToResolve = theFlag; }
131
132   /// \brief Initialize solver by constraints, entities and parameters
133   virtual void initializeSolver(SolverPtr theSolver) = 0;
134
135   /// \brief Update SketchPlugin features after resolving constraints
136   /// \param theFixedOnly [in]  if \c true the fixed points will be updated only
137   virtual void refresh(bool theFixedOnly = false) const = 0;
138
139   /// \brief Check if some parameters or entities are returned
140   ///        to the current group after removing temporary constraints
141   virtual void verifyFixed() = 0;
142
143   /// \brief Calculate point on theBase entity. Value theCoeff is in [0.0 .. 1.0] and
144   ///        shows the distance from the start point.
145   virtual EntityWrapperPtr calculateMiddlePoint(EntityWrapperPtr theBase,
146                                                 double theCoeff) = 0;
147
148 protected:
149   /// \brief Change mapping feature from SketchPlugin and
150   ///        the entity applicable for corresponding solver.
151   /// \param theFeature      [in]  original SketchPlugin feature
152   /// \param theSolverEntity [in]  solver's entity, created outside
153   SKETCHSOLVER_EXPORT
154     void addEntity(FeaturePtr       theFeature,
155                    EntityWrapperPtr theSolverEntity);
156
157   /// \brief Change mapping attribute of a feature and the entity applicable for corresponding solver.
158   /// \param theAttribute    [in]  original attribute
159   /// \param theSolverEntity [in]  solver's entity, created outside
160   SKETCHSOLVER_EXPORT
161     void addEntity(AttributePtr     theAttribute,
162                    EntityWrapperPtr theSolverEntity);
163
164   /// \brief Update constraint's data
165   /// \return \c true if any value is updated
166   virtual bool update(ConstraintWrapperPtr& theConstraint) = 0;
167   /// \brief Update entity's data
168   /// \return \c true if any value is updated
169   virtual bool update(EntityWrapperPtr& theEntity) = 0;
170   /// \brief Update parameter's data
171   /// \return \c true if the value of parameter is updated
172   virtual bool update(ParameterWrapperPtr& theParameter) = 0;
173
174   /// \brief Remove constraint
175   /// \return \c true if the constraint and all its parameters are removed successfully
176   virtual bool remove(ConstraintWrapperPtr theConstraint) = 0;
177   /// \brief Remove entity
178   /// \return \c true if the entity and all its parameters are removed successfully
179   virtual bool remove(EntityWrapperPtr theEntity) = 0;
180   /// \brief Remove parameter
181   /// \return \c true if the parameter has been removed
182   virtual bool remove(ParameterWrapperPtr theParameter) = 0;
183
184   /// \brief Update the group for the given entity, its sub-entities and parameters
185   virtual void changeGroup(EntityWrapperPtr theEntity, const GroupID& theGroup) = 0;
186   /// \brief Update the group for the given parameter
187   virtual void changeGroup(ParameterWrapperPtr theParam, const GroupID& theGroup) = 0;
188
189   /// \brief Block or unblock events when refreshing features
190   SKETCHSOLVER_EXPORT void blockEvents(bool isBlocked) const;
191
192 private:
193   /// \brief Find the normal of the sketch
194   EntityWrapperPtr getNormal() const;
195
196 protected:
197   GroupID myGroupID;       ///< identifier of the group, this storage belongs to
198   bool    myNeedToResolve; ///< parameters are changed and group needs to be resolved
199
200   /// map SketchPlugin constraint to a list of solver's constraints
201   std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> > myConstraintMap;
202   /// map SketchPlugin feature to solver's entity
203   std::map<FeaturePtr, EntityWrapperPtr>                    myFeatureMap;
204   /// map attribute to solver's entity
205   std::map<AttributePtr, EntityWrapperPtr>                  myAttributeMap;
206
207   CoincidentPointsMap myCoincidentPoints; ///< lists of coincident points (first is a master point, second is a set of slaves)
208 };
209
210 typedef std::shared_ptr<SketchSolver_Storage> StoragePtr;
211
212 #endif