Salome HOME
Implementation of Open/Save and Break-Link functionality on SHAPER shapes
[modules/shaper.git] / src / SHAPERGUI / SHAPERGUI.h
1 // Copyright (C) 2014-2019  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
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 <QList>
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& theTBName,
69                               const QString& theId, const QString& theTitle,
70                               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   virtual void updateModuleVisibilityState();
157
158   /// Returns list of the module commands
159   QIntList shaperActions() const { return myActionsList; }
160
161   /// Returns structure of tool bars
162   QMap<QString, QIntList> shaperToolbars() const { return myToolbars; }
163
164   /// Returns free commands which are not in toolbars in the module
165   QIntList getFreeCommands() const;
166
167   /// Returns structure of default tool bars
168   QMap<QString, QIntList> defaultToolbars() const
169   { return (myDefaultToolbars.size() == 0)? myToolbars : myDefaultToolbars; }
170
171   void resetToolbars();
172
173   void publishToStudy();
174
175  public slots:
176   /// \brief The method is redefined to connect to the study viewer before the data
177   /// model is filled by opened file. This file open will flush redisplay signals for,
178   /// objects which should be visualized
179   //virtual void connectToStudy(CAM_Study* theStudy);
180
181    /// \brief The method is called on the module activation
182    /// \param theStudy current study
183   virtual bool activateModule(SUIT_Study* theStudy);
184
185    /// \brief The method is called on the module activation
186    /// \param theStudy current study
187   virtual bool deactivateModule(SUIT_Study* theStudy);
188
189  protected slots:
190    /// Redefinition of virtual function
191    /// \param theMgr view manager
192   virtual void onViewManagerAdded(SUIT_ViewManager* theMgr);
193
194    /// Redefinition of virtual function
195    /// \param theMgr view manager
196   virtual void onViewManagerRemoved(SUIT_ViewManager* theMgr);
197
198   /// Set preferences to default
199   void onDefaultPreferences();
200
201   /// Hide object browser if it was created during loading script
202   void onScriptLoaded();
203
204   /// Save application functionality with additional processing of aborting the current operation
205   void onSaveDocByShaper();
206
207   /// Save application functionality with additional processing of aborting the current operation
208   void onSaveAsDocByShaper();
209
210   /// Obtains the current application and updates its actions
211   void onUpdateCommandStatus();
212
213  protected:
214    /// Create data model
215   CAM_DataModel* createDataModel();
216
217   /// Create popup menu manager
218   virtual QtxPopupMgr* popupMgr();
219
220   /// Abort all operations
221   virtual bool abortAllOperations();
222
223 private slots:
224   void onWhatIs(bool isToggled);
225
226   void onEditToolbars();
227
228  private:
229    /// Create selector for OCC Viewer
230    /// \param theMgr view manager
231   SHAPERGUI_OCCSelector* createSelector(SUIT_ViewManager* theMgr);
232
233   void registerCommandToolbar(const QString& theToolName, int theCommandId);
234
235   int getNextCommandId() const;
236
237   // Update current toolbars
238   void updateToolbars(const QMap<QString, QIntList>& theNewToolbars);
239
240   void saveToolbarsConfig();
241   void loadToolbarsConfig();
242
243   /// List of registered nested actions
244   QStringList myNestedActionsList;
245
246   /// Reference to workshop
247   XGUI_Workshop* myWorkshop;
248
249   /// OCC viewer selector instance
250   SHAPERGUI_OCCSelector* mySelector;
251
252   /// Proxy viewer for connection to OCC Viewer in SALOME
253   SHAPERGUI_SalomeViewer* myProxyViewer;
254
255   /// Map of feature kind to a container of XML properties for the feature
256   QMap<QString, std::shared_ptr<Config_FeatureMessage> > myFeaturesInfo;
257
258   /// Flag of opened document state
259   bool myIsOpened;
260
261   // the next parameters should be restored after this module deactivation
262
263   /// The application value of the preferences parameter
264   bool myIsStorePositions;
265
266   /// The application value
267   bool myIsEditEnabled;
268
269   /// Popup manager
270   QtxPopupMgr* myPopupMgr;
271
272   QAction* myWhatIsAction;
273
274   bool myIsInspectionVisible;
275   QDockWidget* myInspectionPanel;
276
277   /// List of registered actions
278   QIntList myActionsList;
279   QMap<QString, QIntList> myToolbars;
280   QMap<QString, QIntList> myDefaultToolbars;
281   bool myIsToolbarsModified;
282
283   std::vector<int> myOldSelectionColor;
284   Handle(Graphic3d_AspectMarker3d) myHighlightPointAspect;
285 };
286
287 #endif