Salome HOME
Issue #862: new implementation of operations abort on save
[modules/shaper.git] / src / NewGeom / NewGeom_Module.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3
4 #ifndef NewGeom_Module_H
5 #define NewGeom_Module_H
6
7 #include "NewGeom.h"
8 #include "NewGeom_SalomeViewer.h"
9
10 #include <LightApp_Module.h>
11 #include <XGUI_SalomeConnector.h>
12
13 #include <ModuleBase_ActionInfo.h>
14
15 #include <QStringList>
16 #include <QMap>
17
18 class XGUI_Workshop;
19 class NewGeom_OCCSelector;
20 class OCCViewer_Viewer;
21
22 /** 
23  * \ingroup Salome
24  * An implementation of SALOME connector class for implementation of
25  * XGUI functionality as a module of SALOME
26  */
27 class NewGeom_EXPORT NewGeom_Module : public LightApp_Module, public XGUI_SalomeConnector
28 {
29 Q_OBJECT
30  public:
31   NewGeom_Module();
32   virtual ~NewGeom_Module();
33
34   //----- LightAPP_Module interface ---------------
35
36   /// \brief Initializing of the module
37   /// \param theApp application instance
38   virtual void initialize(CAM_Application* theApp);
39
40   /// \brief Definition of module standard windows
41   virtual void windows(QMap<int, int>& theWndMap) const;
42
43   /// \brief Definition of module viewer 
44   virtual void viewManagers(QStringList& theList) const;
45
46   /// \brief The method is called on selection changed event
47   virtual void selectionChanged();
48
49   //--- XGUI connector interface -----
50
51   virtual QAction* addFeature(const QString& theWBName, const QString& theId,
52                               const QString& theTitle, const QString& theTip, const QIcon& theIcon,
53                               const QKeySequence& theKeys = QKeySequence(),
54                               bool isCheckable = false);
55
56   //! Add feature (QAction) in the \a theWBName toolbar with given \a theInfo about action
57   virtual QAction* addFeature(const QString& theWBName,
58                               const ActionInfo& theInfo);
59
60   virtual QAction* addNestedFeature(const QString& theWBName,
61                                     const ActionInfo& theInfo,
62                                     const QList<QAction*>& theNestedActions);
63
64   //! Returns true if the feature action is a nested action, in other words,
65   //! it is created by addNestedFeature().
66   //! \param theId - an action of a feature
67   //! returns boolean result
68   virtual bool isNestedFeature(const QAction* theAction);
69
70   virtual QAction* addDesktopCommand(const QString& theId, const QString& theTitle,
71                                      const QString& theTip, const QIcon& theIcon,
72                                      const QKeySequence& theKeys, bool isCheckable,
73                                      const char* theMenuSourceText,
74                                      const int theMenuPosition = 10);
75
76   virtual void addDesktopMenuSeparator(const char* theMenuSourceText,
77                                        const int theMenuPosition = 10);
78
79   virtual bool addActionInToolbar( QAction* theAction, const QString& theToolBarTitle );
80     
81   virtual QMainWindow* desktop() const;
82
83   virtual QString commandId(const QAction* theCmd) const;
84
85   virtual QAction* command(const QString& theId) const;
86
87   //! Set nested actions dependent on command Id
88   //! \param theId - the command ID
89   //! \param theActions - the list of nested actions
90   virtual void setNestedActions(const QString& theId, const QStringList& theActions);
91
92   //! Returns list of nested actions according to the given command ID
93   virtual QStringList nestedActions(const QString& theId) const;
94
95   //! Set the document kind of the action by the given command Id
96   //! \param theId - the command ID
97   //! \param theKind - the document kind
98   virtual void setDocumentKind(const QString& theId, const QString& theKind);
99
100   //! Returns the document kind of the action by the given command ID
101   virtual QString documentKind(const QString& theId) const;
102
103   //! Returns interface to Salome viewer
104   virtual ModuleBase_IViewer* viewer() const
105   {
106     return myProxyViewer;
107   }
108
109   //! Returns list of defined actions (just by NewGeom module)
110   virtual QList<QAction*> commandList() const;
111
112   //! Returns list of Ids of defined actions (just by NewGeom module)
113   virtual QStringList commandIdList() const;
114
115   /// Redefinition of virtual function. 
116   /// \param theClient name of pop-up client
117   /// \param theMenu popup menu instance
118   /// \param theTitle menu title.
119   virtual void contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle);
120
121   /// Redefinition of virtual function for preferences creation. 
122   virtual void createPreferences();
123
124   /// Redefinition of virtual function for preferences changed event. 
125   virtual void preferencesChanged(const QString& theSection, const QString& theParam);
126   
127   /// \return Workshop class instance
128   XGUI_Workshop* workshop() const { return myWorkshop; }
129
130   /// \brief Set flag about opened document state
131   void setIsOpened(bool theOpened) { myIsOpened = theOpened; }
132
133   /// Register current modules of SALOME
134   void inspectSalomeModules();
135
136  public slots:
137    /// \brief The method is called on the module activation
138    /// \param theStudy current study
139   virtual bool activateModule(SUIT_Study* theStudy);
140
141    /// \brief The method is called on the module activation
142    /// \param theStudy current study
143   virtual bool deactivateModule(SUIT_Study* theStudy);
144
145  protected slots:
146    /// Redefinition of virtual function
147    /// \param theMgr view manager
148   virtual void onViewManagerAdded(SUIT_ViewManager* theMgr);
149
150    /// Redefinition of virtual function
151    /// \param theMgr view manager
152   virtual void onViewManagerRemoved(SUIT_ViewManager* theMgr);
153
154   /// Set preferences to default
155   void onDefaultPreferences();
156
157   /// Obtains the current application and updates its actions
158   void onUpdateCommandStatus();
159
160  protected:
161    /// Create data model
162   CAM_DataModel* createDataModel();
163
164   /// Create popup menu manager
165   virtual QtxPopupMgr* popupMgr();
166
167   virtual bool abortAllOperations();
168
169  private:
170    /// Create selector for OCC Viewer
171    /// \param theMgr view manager
172   NewGeom_OCCSelector* createSelector(SUIT_ViewManager* theMgr);
173
174   /// List of registered actions
175   QStringList myActionsList;
176
177   /// Reference to workshop
178   XGUI_Workshop* myWorkshop;
179
180   /// OCC viewer selector instance
181   NewGeom_OCCSelector* mySelector;
182
183   /// Proxy viewer for connection to OCC Viewer in SALOME
184   NewGeom_SalomeViewer* myProxyViewer;
185
186   /// Map of nested actions [ActionID: list of nested actions Id]
187   QMap<QString, QStringList> myNestedActions;
188
189   /// Map of document types
190   QMap<QString, QString> myDocumentType;
191
192   /// Flag of opened document state
193   bool myIsOpened;
194
195   // the next parameters should be restored after this module deactivation
196
197   /// The application value of the preferences parameter
198   bool myIsStorePositions; 
199
200   /// The application value
201   bool myIsEditEnabled;    
202
203   /// Popup manager
204   QtxPopupMgr* myPopupMgr;
205 };
206
207 #endif