Salome HOME
2a84accc3bc5bf7ddbd571e1a0f086b656a24f1e
[modules/shaper.git] / src / SHAPERGUI / SHAPERGUI.h
1 // Copyright (C) 2014-2023  CEA, EDF
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 class QtxInfoPanel;
39 class ModuleBase_Operation;
40
41 /**
42  * \ingroup Salome
43  * An implementation of SALOME connector class for implementation of
44  * XGUI functionality as a module of SALOME
45  */
46 class SHAPERGUI_EXPORT SHAPERGUI : public LightApp_Module, public XGUI_SalomeConnector
47 {
48 Q_OBJECT
49  public:
50   SHAPERGUI();
51   virtual ~SHAPERGUI();
52
53   //----- LightAPP_Module interface ---------------
54
55   /// \brief Initializing of the module
56   /// \param theApp application instance
57   virtual void initialize(CAM_Application* theApp);
58
59   /// \brief Definition of module standard windows
60   virtual void windows(QMap<int, int>& theWndMap) const;
61
62   /// \brief Definition of module viewer
63   virtual void viewManagers(QStringList& theList) const;
64
65   /// \brief The method is called on selection changed event
66   virtual void selectionChanged();
67
68   //--- XGUI connector interface -----
69
70   virtual QAction* addFeature(const QString& theWBName, const QString& theTBName,
71                               const QString& theId, const QString& theTitle,
72                               const QString& theTip, const QIcon& theIcon,
73                               const QKeySequence& theKeys/* = QKeySequence()*/,
74                               bool isCheckable /*= false*/, const bool isAddSeparator/* = false*/,
75                               const QString& theStatusTip);
76
77   //! Add feature (QAction) in the \a theWBName toolbar with given \a theInfo about action
78   virtual QAction* addFeature(const QString& theWBName,
79                               const ActionInfo& theInfo, const bool isAddSeparator);
80
81   /// Add a nested feature
82   /// \param theWBName a workbench name
83   /// \param theInfo the action  parameters
84   /// \param theNestedActions a list of nested actions
85   virtual QAction* addFeatureOfNested(const QString& theWBName,
86                                     const ActionInfo& theInfo,
87                                     const QList<QAction*>& theNestedActions);
88
89   //! Returns true if the feature action is a nested action, in other words,
90   //! it is created by addNestedFeature().
91   //! \param theAction - an action of a feature
92   //! returns boolean result
93   virtual bool isFeatureOfNested(const QAction* theAction);
94
95   virtual QAction* addDesktopCommand(const QString& theId, const QString& theTitle,
96     const QString& theTip, const QIcon& theIcon,
97     const QKeySequence& theKeys, bool isCheckable,
98     const char* theMenuSourceText, const QString& theSubMenu = QString(),
99     const int theMenuPosition = 10,
100     const int theSuibMenuPosition = -1) Standard_OVERRIDE;
101
102   virtual void addDesktopMenuSeparator(const char* theMenuSourceText,
103                                        const int theMenuPosition = 10);
104
105   /// Add an action to a tool bar
106   /// \param theAction an ation to add
107   /// \param theToolBarTitle a name of tool bar
108   virtual bool addActionInToolbar( QAction* theAction, const QString& theToolBarTitle );
109
110   /// Creates menu/tool bar actions for loaded features stored in the menu manager
111   virtual void createFeatureActions();
112
113   virtual QMainWindow* desktop() const;
114
115   //! Stores XML information for the feature kind
116   //! \param theFeatureId a feature kind
117   //! \param theMessage a container of the feature XML properties
118   virtual void setFeatureInfo(const QString& theFeatureId,
119                               const std::shared_ptr<Config_FeatureMessage>& theMessage);
120
121   //! Returns XML information for the feature kind
122   //! \param theFeatureId a feature kind
123   //! \return theMessage a container of the feature XML properties
124   virtual std::shared_ptr<Config_FeatureMessage> featureInfo(const QString& theFeatureId);
125
126   //! Returns interface to Salome viewer
127   virtual ModuleBase_IViewer* viewer() const
128   {
129     return myProxyViewer;
130   }
131
132   //! Returns list of defined actions (just by SHAPER module)
133   virtual QList<QAction*> commandList() const;
134
135   /// Redefinition of virtual function.
136   /// \param theClient name of pop-up client
137   /// \param theMenu popup menu instance
138   /// \param theTitle menu title.
139   virtual void contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle);
140
141   /// Redefinition of virtual function for preferences creation.
142   virtual void createPreferences();
143
144   /// Redefinition of virtual function for preferences changed event.
145   virtual void preferencesChanged(const QString& theSection, const QString& theParam);
146
147   //! Shows the given text in status bar as a permanent text
148   //! \theInfo a string value
149   //! \theMsecs interval of msec milliseconds when the message will be hidden, if -1, it stays.
150   //            If 0, default value is used, it is 3000
151   virtual void putInfo(const QString& theInfo, const int theMSecs = 0);
152
153   /// \return Workshop class instance
154   XGUI_Workshop* workshop() const { return myWorkshop; }
155
156   /// \brief Set flag about opened document state
157   void setIsOpened(bool theOpened) { myIsOpened = theOpened; }
158
159   virtual void updateModuleVisibilityState();
160
161   /// Returns list of the module commands
162   QIntList shaperActions() const { return myActionsList; }
163
164   /// Returns structure of tool bars
165   QMap<QString, QIntList> shaperToolbars() const { return myToolbars; }
166
167   /// Returns free commands which are not in toolbars in the module
168   QIntList getFreeCommands() const;
169
170   /// Returns structure of default tool bars
171   QMap<QString, QIntList> defaultToolbars() const
172   { return (myDefaultToolbars.size() == 0)? myToolbars : myDefaultToolbars; }
173
174   void resetToolbars();
175
176   void publishToStudy();
177
178   virtual void updateInfoPanel();
179
180  public slots:
181   /// \brief The method is redefined to connect to the study viewer before the data
182   /// model is filled by opened file. This file open will flush redisplay signals for,
183   /// objects which should be visualized
184   //virtual void connectToStudy(CAM_Study* theStudy);
185
186    /// \brief The method is called on the module activation
187    /// \param theStudy current study
188   virtual bool activateModule(SUIT_Study* theStudy);
189
190    /// \brief The method is called on the module activation
191    /// \param theStudy current study
192   virtual bool deactivateModule(SUIT_Study* theStudy);
193
194  protected slots:
195    /// Redefinition of virtual function
196    /// \param theMgr view manager
197   virtual void onViewManagerAdded(SUIT_ViewManager* theMgr);
198
199    /// Redefinition of virtual function
200    /// \param theMgr view manager
201   virtual void onViewManagerRemoved(SUIT_ViewManager* theMgr);
202
203   /// Set preferences to default
204   void onDefaultPreferences();
205
206   /// Hide object browser if it was created during loading script
207   void onScriptLoaded();
208
209   /// Save application functionality with additional processing of aborting the current operation
210   void onSaveDocByShaper();
211
212   /// Save application functionality with additional processing of aborting the current operation
213   void onSaveAsDocByShaper();
214
215   /// Obtains the current application and updates its actions
216   void onUpdateCommandStatus();
217
218    /// \brief The method is called on any GUI action
219   virtual void logShaperGUIEvent();
220
221  protected:
222    /// Create data model
223   CAM_DataModel* createDataModel();
224
225   /// Create popup menu manager
226   virtual QtxPopupMgr* popupMgr();
227
228   /// Abort all operations
229   virtual bool abortAllOperations();
230
231 private slots:
232   void onWhatIs(bool isToggled);
233
234   void onEditToolbars();
235
236   void onOperationCommitted(ModuleBase_Operation*);
237   void onOperationAborted(ModuleBase_Operation*);
238
239  private:
240    /// Create selector for OCC Viewer
241    /// \param theMgr view manager
242   SHAPERGUI_OCCSelector* createSelector(SUIT_ViewManager* theMgr);
243
244   void registerCommandToolbar(const QString& theToolName, int theCommandId);
245
246   int getNextCommandId() const;
247
248   // Update current toolbars
249   void updateToolbars(const QMap<QString, QIntList>& theNewToolbars);
250
251   void saveToolbarsConfig();
252   void loadToolbarsConfig();
253
254   //! Fill Info Panel in Part set mode
255   void fillPartSetInfoPanel(QtxInfoPanel* theInfoPanel);
256
257   //! Fill Info Panel in Part mode
258   void fillPartInfoPanel(QtxInfoPanel* theInfoPanel);
259
260   //! Fill Info Panel in Sketcher mode
261   void fillSketcherInfoPanel(QtxInfoPanel* theInfoPanel);
262
263   //! Fill Info Panel in Sketcher mode
264   void addActionsToInfoGroup(QtxInfoPanel* theInfoPanel, const QString& theGroup, const QSet<QString>& theActions);
265
266   void hideInternalWindows();
267
268   /// List of registered nested actions
269   QStringList myNestedActionsList;
270
271   /// Reference to workshop
272   XGUI_Workshop* myWorkshop;
273
274   /// OCC viewer selector instance
275   SHAPERGUI_OCCSelector* mySelector;
276
277   /// Proxy viewer for connection to OCC Viewer in SALOME
278   SHAPERGUI_SalomeViewer* myProxyViewer;
279
280   /// Map of feature kind to a container of XML properties for the feature
281   QMap<QString, std::shared_ptr<Config_FeatureMessage> > myFeaturesInfo;
282
283   /// Flag of opened document state
284   bool myIsOpened;
285
286   // the next parameter should be restored after this module deactivation
287   /// The application value
288   bool myIsEditEnabled;
289
290   /// Popup manager
291   QtxPopupMgr* myPopupMgr;
292
293   QAction* myWhatIsAction;
294
295   bool myIsInspectionVisible;
296   QDockWidget* myInspectionPanel;
297   bool myIsFacesPanelVisible;
298
299   /// List of registered actions
300   QIntList myActionsList;
301   QMap<QString, QIntList> myToolbars;
302   QMap<QString, QIntList> myDefaultToolbars;
303   bool myIsToolbarsModified;
304
305   std::vector<int> myOldSelectionColor;
306   Handle(Graphic3d_AspectMarker3d) myHighlightPointAspect;
307
308   double myAxisArrowRate;
309 };
310
311 #endif