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