Salome HOME
Task 2.4. Ability to modify the radius of circles and arcs of circle with the mouse
[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 <PlaneGCSSolver_ConstraintWrapper.h>
11 #include <PlaneGCSSolver_EntityWrapper.h>
12
13 #include <PlaneGCSSolver_Solver.h>
14 #include <PlaneGCSSolver_UpdateFeature.h>
15
16 #include <ModelAPI_Attribute.h>
17 #include <ModelAPI_AttributeDouble.h>
18 #include <ModelAPI_Feature.h>
19 #include <SketchPlugin_Constraint.h>
20
21 class SketchSolver_ConstraintDistance;
22 class SketchSolver_ConstraintFixedArcRadius;
23 typedef std::map<EntityWrapperPtr, std::set<EntityWrapperPtr> > CoincidentPointsMap;
24
25
26 /** \class   SketchSolver_Storage
27  *  \ingroup Plugins
28  *  \brief   Interface to map SketchPlugin features to the entities of corresponding solver.
29  */
30 class SketchSolver_Storage
31 {
32 private:
33   SketchSolver_Storage(const SketchSolver_Storage&);
34   SketchSolver_Storage& operator=(const SketchSolver_Storage&);
35
36 public:
37   SketchSolver_Storage(SolverPtr theSolver);
38
39   /// \brief Change mapping between constraint from SketchPlugin and
40   ///        a constraint applicable for corresponding solver.
41   /// \param theConstraint       [in]   original SketchPlugin constraint
42   /// \param theSolverConstraint [in]   solver's constraint
43   virtual void addConstraint(ConstraintPtr        theConstraint,
44                              ConstraintWrapperPtr theSolverConstraint);
45
46   /// \brief Add a movement constraint which will be destroyed
47   ///        after the next solving of the set of constraints.
48   /// \param theSolverConstraint [in]  solver's constraint
49   virtual void addMovementConstraint(const ConstraintWrapperPtr& theSolverConstraint) = 0;
50
51   /// \brief Change mapping feature from SketchPlugin and
52   ///        the entity applicable for corresponding solver.
53   /// \param theFeature      [in]  original SketchPlugin feature
54   /// \param theSolverEntity [in]  solver's entity, created outside
55   void addEntity(FeaturePtr       theFeature,
56                  EntityWrapperPtr theSolverEntity);
57
58   /// \brief Change mapping attribute of a feature and the entity
59   /// applicable for corresponding solver.
60   /// \param theAttribute    [in]  original attribute
61   /// \param theSolverEntity [in]  solver's entity, created outside
62   void addEntity(AttributePtr     theAttribute,
63                  EntityWrapperPtr theSolverEntity);
64
65   /// \brief Convert feature to the form applicable for specific solver and map it
66   /// \param theFeature [in]  feature to convert
67   /// \param theForce   [in]  forced feature creation
68   /// \return \c true if the feature has been created or updated
69   virtual bool update(FeaturePtr theFeature, bool theForce = false) = 0;
70
71   /// \brief Convert attribute to the form applicable for specific solver and map it
72   /// \param theAttribute [in]  attribute to convert
73   /// \param theForce     [in]  forced feature creation
74   /// \return \c true if the attribute has been created or updated
75   virtual bool update(AttributePtr theAttribute, bool theForce = false) = 0;
76
77   /// \brief Returns constraint related to corresponding constraint
78   const ConstraintWrapperPtr& constraint(const ConstraintPtr& theConstraint) const;
79
80   /// \brief Returns entity related to corresponding feature
81   const EntityWrapperPtr& entity(const FeaturePtr& theFeature) const;
82   /// \brief Returns entity related to corresponding attribute
83   const EntityWrapperPtr& entity(const AttributePtr& theAttribute) const;
84
85   /// \brief Removes constraint from the storage
86   /// \return \c true if the constraint and all its parameters are removed successfully
87   virtual bool removeConstraint(ConstraintPtr theConstraint) = 0;
88   /// \brief Removes feature from the storage
89   void removeFeature(FeaturePtr theFeature);
90   /// \brief Removes attribute from the storage
91   void removeAttribute(AttributePtr theAttribute);
92
93   /// \brief Remove all features became invalid
94   virtual void removeInvalidEntities() = 0;
95
96   /// \brief Check the features have not been removed
97   bool areFeaturesValid() const;
98
99   /// \brief Check the storage has constraints
100   virtual bool isEmpty() const
101   { return myConstraintMap.empty(); }
102
103   /// \brief Shows the sketch should be resolved
104   virtual bool isNeedToResolve()
105   { return myNeedToResolve; }
106   /// \brief Changes the flag of group to be resolved
107   void setNeedToResolve(bool theFlag)
108   { myNeedToResolve = theFlag; }
109
110   /// \brief Return list of conflicting constraints
111   std::set<ObjectPtr> getConflictingConstraints(SolverPtr theSolver) const;
112
113   /// \brief Update SketchPlugin features after resolving constraints
114   virtual void refresh() const = 0;
115
116   /// \brief Block or unblock events when refreshing features
117   void blockEvents(bool isBlocked);
118
119   /// \brief Subscribe for updates of features
120   /// \param theSubscriber [in]  object which wants to revceive notifications
121   /// \param theGroup      [in]  group of updates features to be send
122   void subscribeUpdates(SketchSolver_Constraint* theSubscriber, const std::string& theGroup) const;
123   /// \brief Unsubscribe for updates of features
124   /// \param theSubscriber [in]  object which does not want to revceive notifications anymore
125   void unsubscribeUpdates(SketchSolver_Constraint* theSubscriber) const;
126
127   /// \brief Notify all subscribers about update of the feature
128   void notify(const FeaturePtr& theFeature) const;
129
130 protected:
131   /// \brief Convert result to feature or attribute if theResult is linked to center of circle/arc
132   static void resultToFeatureOrAttribute(const ObjectPtr& theResult,
133                                          FeaturePtr&      theFeature,
134                                          AttributePtr&    theAttribute);
135
136 protected:
137   SolverPtr mySketchSolver; ///< Sketch solver, prepared in corresponding group
138   bool    myNeedToResolve; ///< parameters are changed and group needs to be resolved
139   bool    myEventsBlocked; ///< indicates that features do not send events
140
141   /// map SketchPlugin constraint to a list of solver's constraints
142   std::map<ConstraintPtr, ConstraintWrapperPtr> myConstraintMap;
143   /// map SketchPlugin feature to solver's entity
144   std::map<FeaturePtr, EntityWrapperPtr>        myFeatureMap;
145   /// map attribute to solver's entity
146   std::map<AttributePtr, EntityWrapperPtr>      myAttributeMap;
147
148   UpdaterPtr myUpdaters;
149 };
150
151 typedef std::shared_ptr<SketchSolver_Storage> StoragePtr;
152
153 #endif