1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: SketchSolver_Storage.h
4 // Created: 30 Nov 2015
5 // Author: Artem ZHIDKOV
7 #ifndef SketchSolver_Storage_H_
8 #define SketchSolver_Storage_H_
10 #include <PlaneGCSSolver_ConstraintWrapper.h>
11 #include <PlaneGCSSolver_EntityWrapper.h>
13 #include <PlaneGCSSolver_Solver.h>
14 #include <PlaneGCSSolver_UpdateFeature.h>
16 #include <ModelAPI_Attribute.h>
17 #include <ModelAPI_AttributeDouble.h>
18 #include <ModelAPI_Feature.h>
19 #include <SketchPlugin_Constraint.h>
21 class SketchSolver_ConstraintDistance;
22 class SketchSolver_ConstraintFixedArcRadius;
23 typedef std::map<EntityWrapperPtr, std::set<EntityWrapperPtr> > CoincidentPointsMap;
26 /** \class SketchSolver_Storage
28 * \brief Interface to map SketchPlugin features to the entities of corresponding solver.
30 class SketchSolver_Storage
33 SketchSolver_Storage(const SketchSolver_Storage&);
34 SketchSolver_Storage& operator=(const SketchSolver_Storage&);
37 SketchSolver_Storage(SolverPtr theSolver);
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);
46 /// \brief Add list of temporary constraints which will be destroyed
47 /// after the next solving of the set of constraints.
48 /// \param theSolverConstraint [in] solver's constraint
49 virtual void addTemporaryConstraint(const ConstraintWrapperPtr& theSolverConstraint) = 0;
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);
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);
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;
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;
77 /// \brief Returns constraint related to corresponding constraint
78 const ConstraintWrapperPtr& constraint(const ConstraintPtr& theConstraint) const;
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;
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);
93 /// \brief Remove all features became invalid
94 virtual void removeInvalidEntities() = 0;
96 /// \brief Check the features is not removed
97 bool isConsistent() const;
99 /// \brief Check the storage has constraints
101 { return myConstraintMap.empty(); }
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; }
110 /// \brief Return list of conflicting constraints
111 std::set<ObjectPtr> getConflictingConstraints(SolverPtr theSolver) const;
113 /// \brief Update SketchPlugin features after resolving constraints
114 virtual void refresh() const = 0;
116 /// \brief Block or unblock events when refreshing features
117 void blockEvents(bool isBlocked);
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;
127 /// \brief Notify all subscribers about update of the feature
128 void notify(const FeaturePtr& theFeature) const;
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);
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
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;
148 UpdaterPtr myUpdaters;
151 typedef std::shared_ptr<SketchSolver_Storage> StoragePtr;