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 <SketchSolver.h>
11 #include <SketchSolver_IConstraintWrapper.h>
12 #include <SketchSolver_IEntityWrapper.h>
14 #include <PlaneGCSSolver_Solver.h>
15 #include <PlaneGCSSolver_UpdateFeature.h>
17 #include <ModelAPI_Attribute.h>
18 #include <ModelAPI_AttributeDouble.h>
19 #include <ModelAPI_Feature.h>
20 #include <SketchPlugin_Constraint.h>
22 class SketchSolver_ConstraintDistance;
23 class SketchSolver_ConstraintFixedArcRadius;
24 typedef std::map<EntityWrapperPtr, std::set<EntityWrapperPtr> > CoincidentPointsMap;
27 /** \class SketchSolver_Storage
29 * \brief Interface to map SketchPlugin features to the entities of corresponding solver.
31 class SketchSolver_Storage
34 SketchSolver_Storage(const SketchSolver_Storage&);
35 SketchSolver_Storage& operator=(const SketchSolver_Storage&);
38 SketchSolver_Storage(SolverPtr theSolver);
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 constraint
44 virtual void addConstraint(ConstraintPtr theConstraint,
45 ConstraintWrapperPtr theSolverConstraint);
47 /// \brief Add list of temporary constraints which will be destroyed
48 /// after the next solving of the set of constraints.
49 /// \param theSolverConstraint [in] solver's constraint
50 virtual void addTemporaryConstraint(const ConstraintWrapperPtr& theSolverConstraint) = 0;
52 /// \brief Change mapping feature from SketchPlugin and
53 /// the entity applicable for corresponding solver.
54 /// \param theFeature [in] original SketchPlugin feature
55 /// \param theSolverEntity [in] solver's entity, created outside
56 void addEntity(FeaturePtr theFeature,
57 EntityWrapperPtr theSolverEntity);
59 /// \brief Change mapping attribute of a feature and the entity
60 /// applicable for corresponding solver.
61 /// \param theAttribute [in] original attribute
62 /// \param theSolverEntity [in] solver's entity, created outside
63 void addEntity(AttributePtr theAttribute,
64 EntityWrapperPtr theSolverEntity);
66 /// \brief Convert feature to the form applicable for specific solver and map it
67 /// \param theFeature [in] feature to convert
68 /// \param theForce [in] forced feature creation
69 /// \return \c true if the feature has been created or updated
70 virtual bool update(FeaturePtr theFeature, bool theForce = false) = 0;
72 /// \brief Convert attribute to the form applicable for specific solver and map it
73 /// \param theAttribute [in] attribute to convert
74 /// \param theForce [in] forced feature creation
75 /// \return \c true if the attribute has been created or updated
76 virtual bool update(AttributePtr theAttribute, bool theForce = false) = 0;
78 /// \brief Returns constraint related to corresponding constraint
79 const ConstraintWrapperPtr& constraint(const ConstraintPtr& theConstraint) const;
81 /// \brief Returns entity related to corresponding feature
82 const EntityWrapperPtr& entity(const FeaturePtr& theFeature) const;
83 /// \brief Returns entity related to corresponding attribute
84 const EntityWrapperPtr& entity(const AttributePtr& theAttribute) const;
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 void removeFeature(FeaturePtr theFeature);
91 /// \brief Removes attribute from the storage
92 void removeAttribute(AttributePtr theAttribute);
94 /// \brief Remove all features became invalid
95 virtual void removeInvalidEntities() = 0;
97 /// \brief Check the features is not removed
98 bool isConsistent() const;
100 /// \brief Check the storage has constraints
102 { return myConstraintMap.empty(); }
104 /// \brief Shows the sketch should be resolved
105 virtual bool isNeedToResolve()
106 { return myNeedToResolve; }
107 /// \brief Changes the flag of group to be resolved
108 void setNeedToResolve(bool theFlag)
109 { myNeedToResolve = theFlag; }
111 /// \brief Return list of conflicting constraints
112 std::set<ObjectPtr> getConflictingConstraints(SolverPtr theSolver) const;
114 /// \brief Update SketchPlugin features after resolving constraints
115 virtual void refresh() const = 0;
117 /// \brief Block or unblock events when refreshing features
118 void blockEvents(bool isBlocked);
120 /// \brief Subscribe for updates of features
121 /// \param theSubscriber [in] object which wants to revceive notifications
122 /// \param theGroup [in] group of updates features to be send
123 void subscribeUpdates(SketchSolver_Constraint* theSubscriber, const std::string& theGroup) const;
124 /// \brief Unsubscribe for updates of features
125 /// \param theSubscriber [in] object which does not want to revceive notifications anymore
126 void unsubscribeUpdates(SketchSolver_Constraint* theSubscriber) const;
128 /// \brief Notify all subscribers about update of the feature
129 void notify(const FeaturePtr& theFeature) const;
132 /// \brief Convert result to feature or attribute if theResult is linked to center of circle/arc
133 static void resultToFeatureOrAttribute(const ObjectPtr& theResult,
134 FeaturePtr& theFeature,
135 AttributePtr& theAttribute);
138 SolverPtr mySketchSolver; ///< Sketch solver, prepared in corresponding group
139 bool myNeedToResolve; ///< parameters are changed and group needs to be resolved
140 bool myEventsBlocked; ///< indicates that features do not send events
142 /// map SketchPlugin constraint to a list of solver's constraints
143 std::map<ConstraintPtr, ConstraintWrapperPtr> myConstraintMap;
144 /// map SketchPlugin feature to solver's entity
145 std::map<FeaturePtr, EntityWrapperPtr> myFeatureMap;
146 /// map attribute to solver's entity
147 std::map<AttributePtr, EntityWrapperPtr> myAttributeMap;
149 UpdaterPtr myUpdaters;
152 typedef std::shared_ptr<SketchSolver_Storage> StoragePtr;