Salome HOME
Revert "Merge branch 'Pre_2.8.0_development'"
[modules/shaper.git] / src / SketchSolver / SketchSolver_Manager.h
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef SketchSolver_Manager_H_
22 #define SketchSolver_Manager_H_
23
24 #include <SketchSolver_Group.h>
25
26 #include <Events_Listener.h>
27 #include <SketchPlugin_Constraint.h>
28
29 #include <list>
30 #include <set>
31
32 /** \class   SketchSolver_Manager
33  *  \ingroup Plugins
34  *  \brief   Listens the changes of SketchPlugin features and transforms the Constraint
35  *           feature into the format understandable by sketch solver.
36  *
37  *  \remark This is a singleton.
38  */
39 class SketchSolver_Manager : public Events_Listener
40 {
41 public:
42   /** \brief Main method to create constraint manager
43    *  \return pointer to the singleton
44    */
45   static SketchSolver_Manager* instance();
46
47   /** \brief Implementation of Event Listener method
48    *  \param[in] theMessage the data of the event
49    */
50   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
51
52   /**
53    * The solver needs all the updated objects are transfered in one group, not one by one.
54    * This iscreases performance and avoids problems in resolve of only part of the made updates.
55    */
56   virtual bool groupMessages();
57
58 protected:
59   SketchSolver_Manager();
60   ~SketchSolver_Manager();
61
62   /** \brief Adds or updates a constraint or an entity in the suitable group
63    *  \param[in] theFeature sketch feature to be changed
64    *  \param[in] theMoved   \c true if the feature has been moved in the viewer
65    *  \return \c true if the feature changed successfully
66    */
67   bool updateFeature(std::shared_ptr<SketchPlugin_Feature> theFeature, bool theMoved = false);
68
69   /** \brief Removes a constraint from the manager
70    *  \param[in] theConstraint constraint to be removed
71    *  \return \c true if the constraint removed successfully
72    */
73   bool removeConstraint(std::shared_ptr<SketchPlugin_Constraint> theConstraint);
74
75   /** \brief Goes through the list of groups and solve the constraints
76    *  \return \c true, if groups are resolved, and features should be updated 
77    *  (send the Update event)
78    */
79   bool resolveConstraints();
80
81 private:
82   /** \brief Searches group which interact with specified feature
83    *  \param[in]  theFeature  object to be found
84    *  \return Pointer to corresponding group or NULL if the group cannot be created.
85    */
86   SketchGroupPtr findGroup(std::shared_ptr<SketchPlugin_Feature> theFeature);
87
88   /// \brief Stop sending the Update event until all features updated
89   /// \return \c true, if the last flushed event is Update
90   bool stopSendUpdate() const;
91   /// \brief Allow to send the Update event
92   void allowSendUpdate() const;
93
94   /// \brief Allow send events about changing features in groups
95   void releaseFeaturesIfEventsBlocked() const;
96
97 private:
98   std::list<SketchGroupPtr> myGroups; ///< Groups of constraints
99   /// true if computation is performed and all "updates" are generated by this algo
100   /// and needs no recomputation
101   bool myIsComputed;
102 };
103
104 #endif