1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef XGUI_WORKSHOP_LISTENER_H
22 #define XGUI_WORKSHOP_LISTENER_H
25 #include <Events_Listener.h>
26 #include <Events_Message.h>
28 #include <ModelAPI_Feature.h>
29 #include <Events_InfoMessage.h>
33 class Config_FeatureMessage;
35 class ModelAPI_ObjectUpdatedMessage;
38 class ModuleBase_IWorkshop;
41 class Events_InfoMessage;
43 /**\class XGUI_WorkshopListener
45 * \brief Class which process the events from the event loop.
47 class XGUI_EXPORT XGUI_WorkshopListener : public QObject, public Events_Listener
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();
56 /// Register this class in the events loop for several types of events
57 void initializeEventListening();
59 //! Redefinition of Events_Listener method
60 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
62 //! Returns state of blocking fitAll command
63 bool isFitAllBlocked() const { return myBlockFitAll; }
65 //! Sets state of blocking fitAll command
66 //! \param toBlock a new blocking state
67 void setFitAllBlocked(bool toBlock) { myBlockFitAll = toBlock; }
70 /// Emitted when error in applivation happens
71 void errorOccurred(std::shared_ptr<Events_InfoMessage> theMsg);
74 /// Procedure to process postponed events
75 bool event(QEvent * theEvent);
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);
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);
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);
89 /// Process clearing of presentation
90 /// \param theMsg an event message
91 void onFeatureEmptyPresentationMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg);
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);
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);
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);
117 /// Returns the workshop
118 XGUI_Workshop* workshop() const;
121 ModuleBase_IWorkshop* myWorkshop; // the current workshop