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