Salome HOME
Copyrights update
[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 applic ation 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   virtual void          closeApplication();
64
65   //! Returns active Study. If Application supports wirking with several studies this method should be redefined
66   virtual SUIT_Study*   activeStudy() const;
67
68   //! Returns Name of application. Using is not defined.
69   virtual QString       applicationName() const = 0;
70
71   virtual QString       applicationVersion() const;
72
73   //! Shows the application's main widget. For non GUI application must be redefined.
74   virtual void          start();
75
76   //! Opens document <theFileName> into active Study. If Study is empty - creates it.
77   virtual bool          useFile( const QString& theFileName);
78
79   //! Loads document <theName> into active Study. If Study is empty - creates it.
80   virtual bool          useStudy( const QString& theName);
81
82   //! Creates new empty Study if active Study = 0
83   virtual void          createEmptyStudy();
84
85   /*! Returns number of Studies. 
86    *  Must be redefined in Applications which support several studies for one Application instance. */
87   virtual int           getNbStudies() const;
88
89   SUIT_ResourceMgr*     resourceMgr() const;
90
91   /*! Returns instance of data object Convertor class according to given Viewer. 
92       If convertation is not supported returns 0. */
93   virtual SUIT_Convertor* getConvertor(const SUIT_ViewModel* theViewer) { return 0; }
94
95   //! Puts the message to the status bar  
96   void putInfo ( const QString&, const int = 0 );
97
98   //! Invokes application-specific "Open/Save File" dialog and returns the selected file name.
99   virtual QString getFileName( bool open, const QString& initial, const QString& filters, 
100                                const QString& caption, QWidget* parent ) = 0;
101
102   //! Invokes application-specific "Select Directory" dialog and returns the selected directory name.
103   virtual QString getDirectory( const QString& initial, const QString& caption, QWidget* parent ) = 0;
104
105 signals:
106   void                  applicationClosed( SUIT_Application* );
107   void                  activated( SUIT_Application* );
108
109 protected:
110   SUIT_Application*     startApplication( int, char** ) const;
111   SUIT_Application*     startApplication( const QString&, int, char** ) const;
112
113   virtual void          setDesktop( SUIT_Desktop* );
114
115   //! Creates a new Study instance. Must be redefined in new application according to its Study type.
116   virtual SUIT_Study*   createNewStudy();
117   virtual void          setActiveStudy( SUIT_Study* );
118   
119   /** @name Create tool functions*/ //@{
120   int                   createTool( const QString& );
121   int                   createTool( const int, const int, const int = -1 );
122   int                   createTool( const int, const QString&, const int = -1 );
123   int                   createTool( QAction*, const int, const int = -1, const int = -1 );
124   int                   createTool( QAction*, const QString&, const int = -1, const int = -1 );//@}
125
126   /** @name Create menu functions*/ //@{
127   int                   createMenu( const QString&, const int, const int = -1, const int = -1, const int = -1 );
128   int                   createMenu( const QString&, const QString&, const int = -1, const int = -1, const int = -1 );
129   int                   createMenu( const int, const int, const int = -1, const int = -1 );
130   int                   createMenu( const int, const QString&, const int = -1, const int = -1 );
131   int                   createMenu( QAction*, const int, const int = -1, const int = -1, const int = -1 );
132   int                   createMenu( QAction*, const QString&, const int = -1, const int = -1, const int = -1 );//@}
133
134   /** @name Set menu shown functions*/ //@{
135   void                  setMenuShown( QAction*, const bool );
136   void                  setMenuShown( const int, const bool );//@}
137   /** @name Set tool shown functions*/ //@{
138   void                  setToolShown( QAction*, const bool );
139   void                  setToolShown( const int, const bool );//@}
140
141   void                  setActionShown( QAction*, const bool );
142   void                  setActionShown( const int, const bool );
143
144   static QAction*       separator();
145   QAction*              action( const int ) const;
146   int                   actionId( const QAction* ) const;
147   void                  registerAction( const int, QAction* );
148   QAction*              createAction( const int, const QString&, const QIconSet&, const QString&,
149                                       const QString&, const int, QObject* = 0,
150                                       const bool = false, QObject* = 0, const char* = 0 );
151
152 protected slots:
153   virtual void          onDesktopActivated();
154
155 private:
156   SUIT_Study*           myStudy;
157   SUIT_Desktop*         myDesktop;
158
159   QLabel*               myStatusLabel;
160 };
161
162 //! This function must return a new application instance.
163 extern "C"
164 {
165   //jfa 22.06.2005:typedef SUIT_Application* (*APP_CREATE_FUNC)( int, char** );
166   typedef SUIT_Application* (*APP_CREATE_FUNC)();
167 }
168
169 #define APP_CREATE_NAME "createApplication"
170
171 #endif