Salome HOME
Issue #2734: Add "Reset" button to the dialog box
[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 <QList>
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& theTBName,
70                               const QString& theId, const QString& theTitle,
71                               const QString& theTip, const QIcon& theIcon,
72                               const QKeySequence& theKeys/* = QKeySequence()*/,
73                               bool isCheckable /*= false*/, const bool isAddSeparator/* = false*/,
74                               const QString& theStatusTip);
75
76   //! Add feature (QAction) in the \a theWBName toolbar with given \a theInfo about action
77   virtual QAction* addFeature(const QString& theWBName,
78                               const ActionInfo& theInfo, const bool isAddSeparator);
79
80   /// Add a nested feature
81   /// \param theWBName a workbench name
82   /// \param theInfo the action  parameters
83   /// \param theNestedActions a list of nested actions
84   virtual QAction* addFeatureOfNested(const QString& theWBName,
85                                     const ActionInfo& theInfo,
86                                     const QList<QAction*>& theNestedActions);
87
88   //! Returns true if the feature action is a nested action, in other words,
89   //! it is created by addNestedFeature().
90   //! \param theAction - an action of a feature
91   //! returns boolean result
92   virtual bool isFeatureOfNested(const QAction* theAction);
93
94   virtual QAction* addDesktopCommand(const QString& theId, const QString& theTitle,
95                                      const QString& theTip, const QIcon& theIcon,
96                                      const QKeySequence& theKeys, bool isCheckable,
97                                      const char* theMenuSourceText,
98                                      const int theMenuPosition = 10);
99
100   virtual void addDesktopMenuSeparator(const char* theMenuSourceText,
101                                        const int theMenuPosition = 10);
102
103   /// Add an action to a tool bar
104   /// \param theAction an ation to add
105   /// \param theToolBarTitle a name of tool bar
106   virtual bool addActionInToolbar( QAction* theAction, const QString& theToolBarTitle );
107
108   /// Creates menu/tool bar actions for loaded features stored in the menu manager
109   virtual void createFeatureActions();
110
111   virtual QMainWindow* desktop() const;
112
113   //! Stores XML information for the feature kind
114   //! \param theFeatureId a feature kind
115   //! \param theMessage a container of the feature XML properties
116   virtual void setFeatureInfo(const QString& theFeatureId,
117                               const std::shared_ptr<Config_FeatureMessage>& theMessage);
118
119   //! Returns XML information for the feature kind
120   //! \param theFeatureId a feature kind
121   //! \return theMessage a container of the feature XML properties
122   virtual std::shared_ptr<Config_FeatureMessage> featureInfo(const QString& theFeatureId);
123
124   //! Returns interface to Salome viewer
125   virtual ModuleBase_IViewer* viewer() const
126   {
127     return myProxyViewer;
128   }
129
130   //! Returns list of defined actions (just by SHAPER module)
131   virtual QList<QAction*> commandList() const;
132
133   /// Redefinition of virtual function.
134   /// \param theClient name of pop-up client
135   /// \param theMenu popup menu instance
136   /// \param theTitle menu title.
137   virtual void contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle);
138
139   /// Redefinition of virtual function for preferences creation.
140   virtual void createPreferences();
141
142   /// Redefinition of virtual function for preferences changed event.
143   virtual void preferencesChanged(const QString& theSection, const QString& theParam);
144
145   //! Shows the given text in status bar as a permanent text
146   //! \theInfo a string value
147   //! \theMsecs interval of msec milliseconds when the message will be hidden, if -1, it stays.
148   //            If 0, default value is used, it is 3000
149   virtual void putInfo(const QString& theInfo, const int theMSecs = 0);
150
151   /// \return Workshop class instance
152   XGUI_Workshop* workshop() const { return myWorkshop; }
153
154   /// \brief Set flag about opened document state
155   void setIsOpened(bool theOpened) { myIsOpened = theOpened; }
156
157   virtual void updateModuleVisibilityState();
158
159   /// Returns list of the module commands
160   QIntList shaperActions() const { return myActionsList; }
161
162   /// Returns structure of tool bars
163   QMap<QString, QIntList> shaperToolbars() const { return myToolbars; }
164
165   /// Returns free commands which are not in toolbars in the module
166   QIntList getFreeCommands() const;
167
168   /// Returns structure of default tool bars
169   QMap<QString, QIntList> defaultToolbars() const
170   { return (myDefaultToolbars.size() == 0)? myToolbars : myDefaultToolbars; }
171
172   void resetToolbars();
173
174  public slots:
175   /// \brief The method is redefined to connect to the study viewer before the data
176   /// model is filled by opened file. This file open will flush redisplay signals for,
177   /// objects which should be visualized
178   //virtual void connectToStudy(CAM_Study* theStudy);
179
180    /// \brief The method is called on the module activation
181    /// \param theStudy current study
182   virtual bool activateModule(SUIT_Study* theStudy);
183
184    /// \brief The method is called on the module activation
185    /// \param theStudy current study
186   virtual bool deactivateModule(SUIT_Study* theStudy);
187
188  protected slots:
189    /// Redefinition of virtual function
190    /// \param theMgr view manager
191   virtual void onViewManagerAdded(SUIT_ViewManager* theMgr);
192
193    /// Redefinition of virtual function
194    /// \param theMgr view manager
195   virtual void onViewManagerRemoved(SUIT_ViewManager* theMgr);
196
197   /// Set preferences to default
198   void onDefaultPreferences();
199
200   /// Hide object browser if it was created during loading script
201   void onScriptLoaded();
202
203   /// Save application functionality with additional processing of aborting the current operation
204   void onSaveDocByShaper();
205
206   /// Save application functionality with additional processing of aborting the current operation
207   void onSaveAsDocByShaper();
208
209   /// Obtains the current application and updates its actions
210   void onUpdateCommandStatus();
211
212  protected:
213    /// Create data model
214   CAM_DataModel* createDataModel();
215
216   /// Create popup menu manager
217   virtual QtxPopupMgr* popupMgr();
218
219   /// Abort all operations
220   virtual bool abortAllOperations();
221
222 private slots:
223   void onWhatIs(bool isToggled);
224
225   void onEditToolbars();
226
227  private:
228    /// Create selector for OCC Viewer
229    /// \param theMgr view manager
230   SHAPERGUI_OCCSelector* createSelector(SUIT_ViewManager* theMgr);
231
232   void registerCommandToolbar(const QString& theToolName, int theCommandId);
233
234   int getNextCommandId() const;
235
236   // Update current toolbars
237   void updateToolbars(const QMap<QString, QIntList>& theNewToolbars);
238
239   void saveToolbarsConfig();
240   void loadToolbarsConfig();
241
242   /// List of registered nested actions
243   QStringList myNestedActionsList;
244
245   /// Reference to workshop
246   XGUI_Workshop* myWorkshop;
247
248   /// OCC viewer selector instance
249   SHAPERGUI_OCCSelector* mySelector;
250
251   /// Proxy viewer for connection to OCC Viewer in SALOME
252   SHAPERGUI_SalomeViewer* myProxyViewer;
253
254   /// Map of feature kind to a container of XML properties for the feature
255   QMap<QString, std::shared_ptr<Config_FeatureMessage> > myFeaturesInfo;
256
257   /// Flag of opened document state
258   bool myIsOpened;
259
260   // the next parameters should be restored after this module deactivation
261
262   /// The application value of the preferences parameter
263   bool myIsStorePositions;
264
265   /// The application value
266   bool myIsEditEnabled;
267
268   /// Popup manager
269   QtxPopupMgr* myPopupMgr;
270
271   QAction* myWhatIsAction;
272
273   bool myIsInspectionVisible;
274   QDockWidget* myInspectionPanel;
275
276   /// List of registered actions
277   QIntList myActionsList;
278   QMap<QString, QIntList> myToolbars;
279   QMap<QString, QIntList> myDefaultToolbars;
280   bool myIsToolbarsModified;
281 };
282
283 #endif