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