Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / SHAPERGUI / SHAPERGUI.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 SHAPERGUI_H
22 #define SHAPERGUI_H
23
24 #include "SHAPER_SHAPERGUI.h"
25 #include "SHAPERGUI_SalomeViewer.h"
26
27 #include <LightApp_Module.h>
28 #include <XGUI_SalomeConnector.h>
29
30 #include <ModuleBase_ActionInfo.h>
31
32 #include <QStringList>
33 #include <QMap>
34
35 class XGUI_Workshop;
36 class SHAPERGUI_OCCSelector;
37 class OCCViewer_Viewer;
38 class CAM_Study;
39
40 /** 
41  * \ingroup Salome
42  * An implementation of SALOME connector class for implementation of
43  * XGUI functionality as a module of SALOME
44  */
45 class SHAPERGUI_EXPORT SHAPERGUI : public LightApp_Module, public XGUI_SalomeConnector
46 {
47 Q_OBJECT
48  public:
49   SHAPERGUI();
50   virtual ~SHAPERGUI();
51
52   //----- LightAPP_Module interface ---------------
53
54   /// \brief Initializing of the module
55   /// \param theApp application instance
56   virtual void initialize(CAM_Application* theApp);
57
58   /// \brief Definition of module standard windows
59   virtual void windows(QMap<int, int>& theWndMap) const;
60
61   /// \brief Definition of module viewer
62   virtual void viewManagers(QStringList& theList) const;
63
64   /// \brief The method is called on selection changed event
65   virtual void selectionChanged();
66
67   //--- XGUI connector interface -----
68
69   virtual QAction* addFeature(const QString& theWBName, const QString& theId,
70                               const QString& theTitle, const QString& theTip, const QIcon& theIcon,
71                               const QKeySequence& theKeys/* = QKeySequence()*/,
72                               bool isCheckable /*= false*/, const bool isAddSeparator/* = false*/,
73                               const QString& theStatusTip);
74
75   //! Add feature (QAction) in the \a theWBName toolbar with given \a theInfo about action
76   virtual QAction* addFeature(const QString& theWBName,
77                               const ActionInfo& theInfo, const bool isAddSeparator);
78
79   /// Add a nested feature
80   /// \param theWBName a workbench name
81   /// \param theInfo the action  parameters
82   /// \param theNestedActions a list of nested actions
83   virtual QAction* addFeatureOfNested(const QString& theWBName,
84                                     const ActionInfo& theInfo,
85                                     const QList<QAction*>& theNestedActions);
86
87   //! Returns true if the feature action is a nested action, in other words,
88   //! it is created by addNestedFeature().
89   //! \param theAction - an action of a feature
90   //! returns boolean result
91   virtual bool isFeatureOfNested(const QAction* theAction);
92
93   virtual QAction* addDesktopCommand(const QString& theId, const QString& theTitle,
94                                      const QString& theTip, const QIcon& theIcon,
95                                      const QKeySequence& theKeys, bool isCheckable,
96                                      const char* theMenuSourceText,
97                                      const int theMenuPosition = 10);
98
99   virtual void addDesktopMenuSeparator(const char* theMenuSourceText,
100                                        const int theMenuPosition = 10);
101
102   /// Add an action to a tool bar
103   /// \param theAction an ation to add
104   /// \param theToolBarTitle a name of tool bar
105   virtual bool addActionInToolbar( QAction* theAction, const QString& theToolBarTitle );
106
107   /// Creates menu/tool bar actions for loaded features stored in the menu manager
108   virtual void createFeatureActions();
109
110   virtual QMainWindow* desktop() const;
111
112   //! Stores XML information for the feature kind
113   //! \param theFeatureId a feature kind
114   //! \param theMessage a container of the feature XML properties
115   virtual void setFeatureInfo(const QString& theFeatureId,
116                               const std::shared_ptr<Config_FeatureMessage>& theMessage);
117
118   //! Returns XML information for the feature kind
119   //! \param theFeatureId a feature kind
120   //! \return theMessage a container of the feature XML properties
121   virtual std::shared_ptr<Config_FeatureMessage> featureInfo(const QString& theFeatureId);
122
123   //! Returns interface to Salome viewer
124   virtual ModuleBase_IViewer* viewer() const
125   {
126     return myProxyViewer;
127   }
128
129   //! Returns list of defined actions (just by SHAPER module)
130   virtual QList<QAction*> commandList() const;
131
132   /// Redefinition of virtual function.
133   /// \param theClient name of pop-up client
134   /// \param theMenu popup menu instance
135   /// \param theTitle menu title.
136   virtual void contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle);
137
138   /// Redefinition of virtual function for preferences creation.
139   virtual void createPreferences();
140
141   /// Redefinition of virtual function for preferences changed event.
142   virtual void preferencesChanged(const QString& theSection, const QString& theParam);
143
144   //! Shows the given text in status bar as a permanent text
145   //! \theInfo a string value
146   //! \theMsecs interval of msec milliseconds when the message will be hidden, if -1, it stays.
147   //            If 0, default value is used, it is 3000
148   virtual void putInfo(const QString& theInfo, const int theMSecs = 0);
149
150   /// \return Workshop class instance
151   XGUI_Workshop* workshop() const { return myWorkshop; }
152
153   /// \brief Set flag about opened document state
154   void setIsOpened(bool theOpened) { myIsOpened = theOpened; }
155
156  public slots:
157   /// \brief The method is redefined to connect to the study viewer before the data
158   /// model is filled by opened file. This file open will flush redisplay signals for,
159   /// objects which should be visualized
160   //virtual void connectToStudy(CAM_Study* theStudy);
161
162    /// \brief The method is called on the module activation
163    /// \param theStudy current study
164   virtual bool activateModule(SUIT_Study* theStudy);
165
166    /// \brief The method is called on the module activation
167    /// \param theStudy current study
168   virtual bool deactivateModule(SUIT_Study* theStudy);
169
170  protected slots:
171    /// Redefinition of virtual function
172    /// \param theMgr view manager
173   virtual void onViewManagerAdded(SUIT_ViewManager* theMgr);
174
175    /// Redefinition of virtual function
176    /// \param theMgr view manager
177   virtual void onViewManagerRemoved(SUIT_ViewManager* theMgr);
178
179   /// Set preferences to default
180   void onDefaultPreferences();
181
182   /// Hide object browser if it was created during loading script
183   void onScriptLoaded();
184
185   /// Obtains the current application and updates its actions
186   void onUpdateCommandStatus();
187
188  protected:
189    /// Create data model
190   CAM_DataModel* createDataModel();
191
192   /// Create popup menu manager
193   virtual QtxPopupMgr* popupMgr();
194
195   /// Abort all operations
196   virtual bool abortAllOperations();
197
198  private:
199    /// Create selector for OCC Viewer
200    /// \param theMgr view manager
201   SHAPERGUI_OCCSelector* createSelector(SUIT_ViewManager* theMgr);
202
203   /// List of registered actions
204   QStringList myActionsList;
205
206   /// List of registered nested actions
207   QStringList myNestedActionsList;
208
209   /// Reference to workshop
210   XGUI_Workshop* myWorkshop;
211
212   /// OCC viewer selector instance
213   SHAPERGUI_OCCSelector* mySelector;
214
215   /// Proxy viewer for connection to OCC Viewer in SALOME
216   SHAPERGUI_SalomeViewer* myProxyViewer;
217
218   /// Map of feature kind to a container of XML properties for the feature
219   QMap<QString, std::shared_ptr<Config_FeatureMessage> > myFeaturesInfo;
220
221   /// Flag of opened document state
222   bool myIsOpened;
223
224   // the next parameters should be restored after this module deactivation
225
226   /// The application value of the preferences parameter
227   bool myIsStorePositions;
228
229   /// The application value
230   bool myIsEditEnabled;
231
232   /// Popup manager
233   QtxPopupMgr* myPopupMgr;
234 };
235
236 #endif