]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_WorkshopListener.h
Salome HOME
Issue #2218: Provide correct display of already shown object
[modules/shaper.git] / src / XGUI / XGUI_WorkshopListener.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 XGUI_WORKSHOP_LISTENER_H
22 #define XGUI_WORKSHOP_LISTENER_H
23
24 #include "XGUI.h"
25 #include <Events_Listener.h>
26 #include <Events_Message.h>
27
28 #include <ModelAPI_Feature.h>
29 #include <Events_InfoMessage.h>
30
31 #include <QObject>
32
33 class Config_FeatureMessage;
34
35 class ModelAPI_ObjectUpdatedMessage;
36 class XGUI_Workshop;
37
38 class ModuleBase_IWorkshop;
39
40 class QString;
41 class Events_InfoMessage;
42
43 /**\class XGUI_WorkshopListener
44  * \ingroup GUI
45  * \brief Class which process the events from the event loop.
46  */
47 class XGUI_EXPORT XGUI_WorkshopListener : public QObject, public Events_Listener
48 {
49   Q_OBJECT
50 public:
51   /// Constructor. Used only if the workshop is launched in Salome environment
52   /// \param theWorkshop a reference to workshop.
53    XGUI_WorkshopListener(ModuleBase_IWorkshop* theWorkshop);
54   virtual ~XGUI_WorkshopListener();
55
56   /// Register this class in the events loop for several types of events
57   void initializeEventListening();
58
59   //! Redefinition of Events_Listener method
60   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
61
62   //! Returns state of blocking fitAll command
63   bool isFitAllBlocked() const { return myBlockFitAll; }
64
65   //! Sets state of blocking fitAll command
66   //! \param toBlock a new blocking state
67   void setFitAllBlocked(bool toBlock) { myBlockFitAll = toBlock; }
68
69 signals:
70   /// Emitted when error in applivation happens
71   void errorOccurred(std::shared_ptr<Events_InfoMessage> theMsg);
72
73 protected:
74   /// Procedure to process postponed events
75   bool event(QEvent * theEvent);
76
77   /// Process feature update message
78   /// \param theMsg a message with a container of objects
79   void onFeatureUpdatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg);
80
81   /// Process feature created message
82   /// \param theMsg a message with a container of objects
83   void onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg);
84
85   /// Process feature redisplay message
86   /// \param theMsg a message with a container of objects
87   void onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg);
88
89   /// Process clearing of presentation
90   /// \param theMsg an event message
91   void onFeatureEmptyPresentationMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg);
92
93   /// Displaus object and fit all viewer if the object is first (update viewer will not be called)
94   /// Asks the module whether the object can be displayed
95   /// \param theObj an object
96   /// \param theFirstVisualizedBody an output state whether there are not object displayed in the
97   /// view and the displayed object is a body
98   /// \return true if the object is displayed
99   bool displayObject(ObjectPtr theObj);
100
101   /// Answer if the viewer needed to be fit all after the object visualization
102   /// The condition is there is not shown objects and the object is a group or body result
103   /// \param theObject a shown object
104   /// \param theNbOfShownObjects a count of already shown objects in the viewer
105   /// \return true if fit all should be done
106   bool neededFitAll(ObjectPtr theObject, const int theNbOfShownObjects);
107
108   /// Calls the module method of cusomize object for the feature of the current operation
109   /// Perform cusomize if the force redisplay flag is true or the list of objects contains the
110   /// current operation feature
111   /// \param theObjects a list of objects to find current operation feature
112   ///                   if forced redisplay is false
113   /// \param theForceRedisplay a flag to customize object even always
114   /// \return true if the object is modified
115   bool customizeCurrentObject(const std::set<ObjectPtr>& theObjects, bool theForceRedisplay);
116
117   /// Returns the workshop
118   XGUI_Workshop* workshop() const;
119
120 private:
121   ModuleBase_IWorkshop* myWorkshop; // the current workshop
122
123   bool myUpdatePrefs;
124   bool myBlockFitAll;
125 };
126
127 #endif