Salome HOME
Task 3.2. Concealment into multi-level Compounds
[modules/shaper.git] / src / SketchSolver / SketchSolver_Manager.h
1 // Copyright (C) 2014-2019  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 email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef SketchSolver_Manager_H_
21 #define SketchSolver_Manager_H_
22
23 #include <SketchSolver_Group.h>
24
25 #include <Events_Listener.h>
26
27 #include <list>
28 #include <set>
29
30 class GeomAPI_Pnt2d;
31 class GeomDataAPI_Point2D;
32 class SketchPlugin_Constraint;
33
34 /** \class   SketchSolver_Manager
35  *  \ingroup Plugins
36  *  \brief   Listens the changes of SketchPlugin features and transforms the Constraint
37  *           feature into the format understandable by sketch solver.
38  *
39  *  \remark This is a singleton.
40  */
41 class SketchSolver_Manager : public Events_Listener
42 {
43 public:
44   /** \brief Main method to create constraint manager
45    *  \return pointer to the singleton
46    */
47   static SketchSolver_Manager* instance();
48
49   /** \brief Implementation of Event Listener method
50    *  \param[in] theMessage the data of the event
51    */
52   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
53
54   /**
55    * The solver needs all the updated objects are transfered in one group, not one by one.
56    * This iscreases performance and avoids problems in resolve of only part of the made updates.
57    */
58   virtual bool groupMessages();
59
60 protected:
61   SketchSolver_Manager();
62   ~SketchSolver_Manager();
63
64   /** \brief Adds or updates a constraint or an entity in the suitable group
65    *  \param[in] theFeature sketch feature to be changed
66    *  \return \c true if the feature changed successfully
67    */
68   bool updateFeature(const std::shared_ptr<SketchPlugin_Feature>& theFeature);
69
70   /** \brief Move feature
71    *  \param[in] theMovedFeature dragged sketch feature
72    *  \param[in] theFromPoint    original position of the feature
73    *  \param[in] theToPoint      prefereble position of the feature (current position of the mouse)
74    *  \return \c true if the feature has been changed successfully
75    */
76   bool moveFeature(const std::shared_ptr<SketchPlugin_Feature>& theMovedFeature,
77                    const std::shared_ptr<GeomAPI_Pnt2d>& theFromPoint,
78                    const std::shared_ptr<GeomAPI_Pnt2d>& theToPoint);
79
80   /** \brief Move feature using its moved attribute
81    *  \param[in] theMovedAttribute dragged point attribute of sketch feature
82    *  \param[in] theFromPoint      original position of the moved point
83    *  \param[in] theToPoint        prefereble position (current position of the mouse)
84    *  \return \c true if the attribute owner has been changed successfully
85    */
86   bool moveAttribute(const std::shared_ptr<GeomDataAPI_Point2D>& theMovedAttribute,
87                      const std::shared_ptr<GeomAPI_Pnt2d>& theFromPoint,
88                      const std::shared_ptr<GeomAPI_Pnt2d>& theToPoint);
89
90   /** \brief Removes a constraint from the manager
91    *  \param[in] theConstraint constraint to be removed
92    *  \return \c true if the constraint removed successfully
93    */
94   bool removeConstraint(std::shared_ptr<SketchPlugin_Constraint> theConstraint);
95
96   /** \brief Goes through the list of groups and solve the constraints
97    *  \return \c true, if groups are resolved, and features should be updated 
98    *  (send the Update event)
99    */
100   bool resolveConstraints();
101
102 private:
103   /** \brief Searches group which interact with specified feature
104    *  \param[in]  theFeature  object to be found
105    *  \return Pointer to corresponding group or NULL if the group cannot be created.
106    */
107   SketchGroupPtr findGroup(std::shared_ptr<SketchPlugin_Feature> theFeature);
108
109   /// \brief Stop sending the Update event until all features updated
110   /// \return \c true, if the last flushed event is Update
111   bool stopSendUpdate() const;
112   /// \brief Allow to send the Update event
113   void allowSendUpdate() const;
114
115   /// \brief Allow send events about changing features in groups
116   void releaseFeaturesIfEventsBlocked() const;
117
118 private:
119   std::list<SketchGroupPtr> myGroups; ///< Groups of constraints
120   /// true if computation is performed and all "updates" are generated by this algo
121   /// and needs no recomputation
122   bool myIsComputed;
123 };
124
125 #endif