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