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 Make entity external
86 virtual void makeExternal(const EntityWrapperPtr& theEntity) = 0;
87 /// \brief Make entity non-external
88 virtual void makeNonExternal(const EntityWrapperPtr& theEntity) = 0;
90 /// \brief Removes constraint from the storage
91 /// \return \c true if the constraint and all its parameters are removed successfully
92 virtual bool removeConstraint(ConstraintPtr theConstraint) = 0;
93 /// \brief Removes feature from the storage
94 void removeFeature(FeaturePtr theFeature);
95 /// \brief Removes attribute from the storage
96 void removeAttribute(AttributePtr theAttribute);
98 /// \brief Remove all features became invalid
99 virtual void removeInvalidEntities() = 0;
101 /// \brief Check the features have not been removed
102 bool areFeaturesValid() const;
104 /// \brief Check the storage has constraints
105 virtual bool isEmpty() const
106 { return myConstraintMap.empty(); }
108 /// \brief Shows the sketch should be resolved
109 virtual bool isNeedToResolve()
110 { return myNeedToResolve; }
111 /// \brief Changes the flag of group to be resolved
112 void setNeedToResolve(bool theFlag)
113 { myNeedToResolve = theFlag; }
115 /// \brief Return list of conflicting constraints
116 std::set<ObjectPtr> getConflictingConstraints(SolverPtr theSolver) const;
118 /// \brief Update SketchPlugin features after resolving constraints
119 virtual void refresh() const = 0;
121 /// \brief Block or unblock events when refreshing features
122 void blockEvents(bool isBlocked);
124 /// \brief Subscribe for updates of features
125 /// \param theSubscriber [in] object which wants to revceive notifications
126 /// \param theGroup [in] group of updates features to be send
127 void subscribeUpdates(SketchSolver_Constraint* theSubscriber, const std::string& theGroup) const;
128 /// \brief Unsubscribe for updates of features
129 /// \param theSubscriber [in] object which does not want to revceive notifications anymore
130 void unsubscribeUpdates(SketchSolver_Constraint* theSubscriber) const;
132 /// \brief Notify all subscribers about update of the feature
133 void notify(const FeaturePtr& theFeature) const;
136 /// \brief Convert result to feature or attribute if theResult is linked to center of circle/arc
137 static void resultToFeatureOrAttribute(const ObjectPtr& theResult,
138 FeaturePtr& theFeature,
139 AttributePtr& theAttribute);
142 SolverPtr mySketchSolver; ///< Sketch solver, prepared in corresponding group
143 bool myNeedToResolve; ///< parameters are changed and group needs to be resolved
144 bool myEventsBlocked; ///< indicates that features do not send events
146 /// map SketchPlugin constraint to a list of solver's constraints
147 std::map<ConstraintPtr, ConstraintWrapperPtr> myConstraintMap;
148 /// map SketchPlugin feature to solver's entity
149 std::map<FeaturePtr, EntityWrapperPtr> myFeatureMap;
150 /// map attribute to solver's entity
151 std::map<AttributePtr, EntityWrapperPtr> myAttributeMap;
153 UpdaterPtr myUpdaters;
156 typedef std::shared_ptr<SketchSolver_Storage> StoragePtr;