Salome HOME
Merge branch 'master' of https://git.salome-platform.org/git/modules/gui
[modules/gui.git] / src / CAM / CAM_Module.h
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #ifndef CAM_MODULE_H
24 #define CAM_MODULE_H
25
26 #include "CAM.h"
27
28 #include <QObject>
29 #include <QPixmap>
30 #include <QString>
31 #include <QMap>
32 #include <QPair>
33 #include <QKeySequence>
34
35 class QAction;
36 class QMenu;
37 class QIcon;
38
39 class QtxActionGroup;
40 class QtxActionMenuMgr;
41 class QtxActionToolMgr;
42 class SUIT_Study;
43 class SUIT_Application;
44 class CAM_Study;
45 class CAM_DataModel;
46 class CAM_Application;
47
48 #ifdef WIN32
49 #pragma warning( disable: 4251 )
50 #endif
51
52 class CAM_EXPORT CAM_Module : public QObject
53 {
54   Q_OBJECT
55
56 public:
57   CAM_Module();
58   CAM_Module( const QString& );
59   virtual ~CAM_Module();
60
61   virtual void           initialize( CAM_Application* );
62
63   QString                name() const;
64   QString                moduleName() const;
65   virtual QPixmap        moduleIcon() const;
66   virtual QString        iconName() const;
67
68   CAM_DataModel*         dataModel() const;
69   CAM_Application*       application() const;
70
71   virtual void           contextMenuPopup( const QString&, QMenu*, QString& ) {};
72   virtual void           updateCommandsStatus() {};
73
74   virtual void           putInfo( const QString&, const int = -1 );
75
76   bool                   isActiveModule() const;
77
78   virtual void           setMenuShown( const bool );
79   void                   setMenuShown( QAction*, const bool );
80   void                   setMenuShown( const int, const bool );
81
82   virtual void           setToolShown( const bool );
83   void                   setToolShown( QAction*, const bool );
84   void                   setToolShown( const int, const bool );
85
86   virtual void           updateModuleVisibilityState();
87
88   virtual bool           activateOperation( int actionId );
89   virtual bool           activateOperation( const QString& actionId );
90   virtual bool           activateOperation( const QString& actionId, const QString& pluginName );
91
92   // actions/menu/toolbars management
93
94   QtxActionMenuMgr*      menuMgr() const;
95   QtxActionToolMgr*      toolMgr() const;
96
97   virtual QAction*       action( const int ) const;
98   virtual int            actionId( const QAction* ) const;
99   virtual QAction*       createAction( const int, const QString&, const QIcon&, const QString&,
100                                        const QString&, const int, QObject* = 0,
101                                        const bool = false, QObject* = 0, const char* = 0, const QString& = QString() );
102   QtxActionGroup*        createActionGroup( const int, const bool = true );
103
104   int                    createTool( const QString&, const QString& = QString() );
105   int                    createTool( const int, const int, const int = -1 );
106   int                    createTool( const int, const QString&, const int = -1 );
107   int                    createTool( QAction*, const int, const int = -1, const int = -1 );
108   int                    createTool( QAction*, const QString&, const int = -1, const int = -1 );
109
110   int                    createMenu( const QString&, const int, const int = -1, const int = -1, const int = -1,QMenu * = 0);
111   int                    createMenu( const QString&, const QString&, const int = -1, const int = -1, const int = -1 );
112   int                    createMenu( const int, const int, const int = -1, const int = -1 );
113   int                    createMenu( const int, const QString&, const int = -1, const int = -1 );
114   int                    createMenu( QAction*, const int, const int = -1, const int = -1, const int = -1 );
115   int                    createMenu( QAction*, const QString&, const int = -1, const int = -1, const int = -1 );
116
117   static QAction*        separator();
118
119 public slots:
120   virtual bool           activateModule( SUIT_Study* );
121   virtual bool           deactivateModule( SUIT_Study* );
122
123   virtual void           connectToStudy( CAM_Study* );
124
125   virtual void           studyClosed( SUIT_Study* );
126   virtual void           studyChanged( SUIT_Study*, SUIT_Study* );
127
128   virtual void           onApplicationClosed( SUIT_Application* );
129
130 private slots:
131   void                   onInfoChanged( QString );
132
133 protected: 
134   virtual bool           isSelectionCompatible();
135
136   virtual CAM_DataModel* createDataModel();
137
138   void                   setName( const QString& );
139   virtual void           setModuleName( const QString& );
140
141   int                    registerAction( const int, QAction* );
142   bool                   unregisterAction( const int );
143   bool                   unregisterAction( QAction* );
144   // IMN 05/03/2015: we copied myActionMap for reset/unset actions accelerator keys
145   // after activate/deactivate modules
146   QMap<QAction*, QKeySequence> myActionShortcutMap; //!< copy actions shortcut map
147
148   virtual bool           abortAllOperations();
149
150 private:
151   CAM_Application*       myApp;             //!< parent application object
152   QString                myName;            //!< module title (user name)
153   QPixmap                myIcon;            //!< module icon
154   QString                myInfo;            //!< latest info message
155   CAM_DataModel*         myDataModel;       //!< data model
156   QMap<int, QAction*>    myActionMap;       //!< menu actions
157   bool                   myMenuShown;       //!< menu shown flag
158   bool                   myToolShown;       //!< tool shown flag
159
160   friend class CAM_Application;
161 };
162
163 #ifdef WIN32
164 #pragma warning( default: 4251 )
165 #endif
166
167 extern "C"
168 {
169   typedef CAM_Module* (*GET_MODULE_FUNC)();
170   typedef char* (*GET_VERSION_FUNC)();
171 }
172
173 #define GET_MODULE_NAME "createModule"
174 #define GET_VERSION_NAME "getModuleVersion"
175 #endif