]> SALOME platform Git repositories - modules/gui.git/blob - src/SUIT/SUIT_Application.h
Salome HOME
Redesign SALOME documentation: update link to youtube channel
[modules/gui.git] / src / SUIT / SUIT_Application.h
1 // Copyright (C) 2007-2016  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 SUIT_APPLICATION_H
24 #define SUIT_APPLICATION_H
25
26 #include "SUIT.h"
27
28 #include <QObject>
29 #include <QMap>
30
31 class QIcon;
32 class QLabel;
33 class QString;
34 class QAction;
35 class QWidget;
36 class QKeySequence;
37
38 class SUIT_Desktop;
39 class SUIT_ViewManager;
40 class SUIT_ResourceMgr;
41 class SUIT_ShortcutMgr;
42 class SUIT_Study;
43
44 #ifdef WIN32
45 #pragma warning ( disable:4251 )
46 #endif
47
48 /*! \class QObject
49  * \brief For more information see <a href="http://doc.trolltech.com">QT documentation</a>.
50  */
51 /*!
52   An <b>Application</b> is a class which defines application configuration and behaviour.
53   For example Application object defines what Viewers are used in this application, what auxilliary windows
54   are present, how user can dial with them. Also Application object defines an sertain type of data structure by 
55   holding of pointer on an instance of SUIT_Study class (which represents Document data structure). In other words
56   Application defines type of sata structure, type of used Viewers, type of main GUI widget (Desktop),
57   and other auxilliary tools.
58 */
59
60 class SUIT_EXPORT SUIT_Application : public QObject
61 {
62   Q_OBJECT
63
64 public:
65   SUIT_Application();
66   virtual ~SUIT_Application();
67
68   //! Returns main widget (Desktop) of the application (if it exists)
69   virtual SUIT_Desktop* desktop();
70
71   /*! Returns \c false if application can not be closed (because of non saved data for example). 
72       This method called by SUIT_Session whin closing of application was requested. */
73   virtual bool          isPossibleToClose( bool& );
74
75   /*! Performs some finalization of life cycle of this application.
76       For instance, the application can force its documents(s) to close. */
77   virtual void          closeApplication();
78
79   //! Returns active Study. If Application supports wirking with several studies this method should be redefined
80   virtual SUIT_Study*   activeStudy() const;
81
82   //! Returns Name of application. Using is not defined.
83   virtual QString       applicationName() const = 0;
84
85   virtual QString       applicationVersion() const;
86
87   //! Shows the application's main widget. For non GUI application must be redefined.
88   virtual void          start();
89
90   //! Opens document <theFileName> into active Study. If Study is empty - creates it.
91   virtual bool          useFile( const QString& theFileName);
92
93   //! Creates new empty Study if active Study = 0
94   virtual void          createEmptyStudy();
95
96   /*! Returns number of Studies. 
97    *  Must be redefined in Applications which support several studies for one Application instance. */
98   virtual int           getNbStudies() const;
99
100   SUIT_ResourceMgr*     resourceMgr() const;
101
102   SUIT_ShortcutMgr*     shortcutMgr() const;
103
104   //! Puts the message to the status bar  
105   void                  putInfo ( const QString&, const int = 0 );
106
107   //! Invokes application-specific "Open/Save File" dialog and returns the selected file name.
108   virtual QString       getFileName( bool open, const QString& initial, const QString& filters, 
109                                      const QString& caption, QWidget* parent ) = 0;
110
111   //! Invokes application-specific "Select Directory" dialog and returns the selected directory name.
112   virtual QString       getDirectory( const QString& initial, const QString& caption, QWidget* parent ) = 0;
113
114
115   virtual int           viewManagerId ( const SUIT_ViewManager* ) const = 0;
116   virtual void          viewManagers( const QString&, QList<SUIT_ViewManager*>& ) const = 0;
117   QAction*              action( const int ) const;
118
119   void                  addPostRoutine( void (*theRoutine)() );
120
121 signals:
122   void                  applicationClosed( SUIT_Application* );
123   void                  activated( SUIT_Application* );
124 //  void                  moving();
125   void                  infoChanged( QString );
126
127 public slots:
128   virtual void          updateCommandsStatus();
129   virtual void          onHelpContextModule( const QString&, const QString&, const QString& = QString() );
130
131 private slots:
132   void                  onInfoClear();
133
134 protected:
135   SUIT_Application*     startApplication( int, char** ) const;
136   SUIT_Application*     startApplication( const QString&, int, char** ) const;
137
138   virtual void          setDesktop( SUIT_Desktop* );
139
140   //! Creates a new Study instance. Must be redefined in new application according to its Study type.
141   virtual SUIT_Study*   createNewStudy();
142   virtual void          setActiveStudy( SUIT_Study* );
143   
144   /** @name Create tool functions*/ //@{
145   int                   createTool( const QString&, const QString& = QString() );
146   int                   createTool( const int, const int, const int = -1 );
147   int                   createTool( const int, const QString&, const int = -1 );
148   int                   createTool( QAction*, const int, const int = -1, const int = -1 );
149   int                   createTool( QAction*, const QString&, const int = -1, const int = -1 );//@}
150
151   /** @name Create menu functions*/ //@{
152   int                   createMenu( const QString&, const int, const int = -1, const int = -1, const int = -1 );
153   int                   createMenu( const QString&, const QString&, const int = -1, const int = -1, const int = -1 );
154   int                   createMenu( const int, const int, const int = -1, const int = -1 );
155   int                   createMenu( const int, const QString&, const int = -1, const int = -1 );
156   int                   createMenu( QAction*, const int, const int = -1, const int = -1, const int = -1 );
157   int                   createMenu( QAction*, const QString&, const int = -1, const int = -1, const int = -1 );//@}
158
159   /** @name Set menu shown functions*/ //@{
160   void                  setMenuShown( QAction*, const bool );
161   void                  setMenuShown( const int, const bool );//@}
162   /** @name Set tool shown functions*/ //@{
163   void                  setToolShown( QAction*, const bool );
164   void                  setToolShown( const int, const bool );//@}
165
166   void                  setActionShown( QAction*, const bool );
167   void                  setActionShown( const int, const bool );
168
169   static QAction*       separator();
170   int                   actionId( const QAction* ) const;
171
172   QList<QAction*>       actions() const;
173   QList<int>            actionIds() const;
174
175   int                   registerAction( const int, QAction* );
176   QAction*              createAction( const int, const QString&, const QIcon&, const QString&,
177                                       const QString&, const int, QObject* = 0,
178                                       const bool = false, QObject* = 0, const char* = 0,
179                                       const QString& = QString() );
180   QAction*              createAction( const int, const QString&, const QIcon&, const QString&,
181                                       const QString&, const QKeySequence&, QObject* = 0,
182                                       const bool = false, QObject* = 0, const char* = 0,
183                                       const QString& = QString() );
184
185 protected slots:
186   virtual void          onDesktopActivated();
187 //  void                  onDesktopMoved();
188
189 private:
190   SUIT_Study*           myStudy;
191   SUIT_Desktop*         myDesktop;
192   QMap<int, QAction*>   myActionMap;
193   SUIT_ShortcutMgr*     myShortcutMgr;
194
195   QLabel*               myStatusLabel;
196
197   typedef void (*PostRoutine)();
198   QList<PostRoutine>    myPostRoutines;
199 };
200
201 //! This function must return a new application instance.
202 extern "C"
203 {
204   //jfa 22.06.2005:typedef SUIT_Application* (*APP_CREATE_FUNC)( int, char** );
205   typedef SUIT_Application* (*APP_CREATE_FUNC)();
206 }
207
208 #define APP_CREATE_NAME "createApplication"
209
210 #ifdef WIN32
211 #pragma warning ( default:4251 )
212 #endif
213
214 #endif