Salome HOME
Application::onLoadDoc() method implementation (for VISU batchmode tests)
[modules/gui.git] / src / SUIT / SUIT_Application.h
1 #ifndef SUIT_APPLICATION_H
2 #define SUIT_APPLICATION_H
3
4 #include "SUIT.h"
5 #include "SUIT_Study.h"
6
7 #include <qobject.h>
8 #include <qwidget.h>
9
10 class QAction;
11 class SUIT_Desktop;
12 class SUIT_Convertor;
13 class SUIT_ViewModel;
14 class SUIT_ResourceMgr;
15
16 /*!
17   An <b>Application</b> is a class which defines application configuration and behaviour.
18   For example Application object defines what Viewers are used in this application, what auxilliary windows
19   are present, how user can dial with them. Also Application object defines an sertain type of data structure by 
20   holding of pointer on an instance of SUIT_Study class (which represents Document data structure). In other words
21   Application defines type of sata structure, type of used Viewers, type of main GUI widget (Desktop),
22   and other auxilliary tools.
23 */
24
25 class SUIT_EXPORT SUIT_Application : public QObject
26 {
27   Q_OBJECT
28
29 public:
30   SUIT_Application();
31   virtual ~SUIT_Application();
32
33   //! Returns main widget (Desktop) of the application (if it exists)
34   virtual SUIT_Desktop* desktop();
35
36   /*! Returns FALSE if applic ation can not be closed (because of non saved data for example). 
37       This method called by SUIT_Session whin closing of application was requested. */
38   virtual bool          isPossibleToClose();
39
40   virtual void          closeApplication();
41
42   //! Returns active Study. If Application supports wirking with several studies this method should be redefined
43   virtual SUIT_Study*   activeStudy() const;
44
45   //! Returns Name of application. Using is not defined.
46   virtual QString       applicationName() const = 0;
47
48   virtual QString       applicationVersion() const;
49
50   //! Shows the application's main widget. For non GUI application must be redefined.
51   virtual void          start();
52
53   //! Opens document <theFileName> into active Study. If Study is empty - creates it.
54   virtual bool          useFile( const QString& theFileName);
55
56   //! Loads document <theName> into active Study. If Study is empty - creates it.
57   virtual bool          useStudy( const QString& theName);
58
59   //! Creates new empty Study if active Study = 0
60   virtual void          createEmptyStudy();
61
62   /*! Returns number of Studies. 
63    *  Must be redefined in Applications which support several studies for one Application instance. */
64   virtual int           getNbStudies() const;
65
66   SUIT_ResourceMgr*     resourceMgr() const;
67
68   /*! Returns instance of data object Convertor class according to given Viewer. 
69       If convertation is not supported returns 0. */
70   virtual SUIT_Convertor* getConvertor(const SUIT_ViewModel* theViewer) { return 0; }
71
72   //! Puts the message to the status bar  
73   void putInfo ( const QString&, const int = 0 );
74
75   //! Invokes application-specific "Open/Save File" dialog and returns the selected file name.
76   virtual QString getFileName( bool open, const QString& initial, const QString& filters, 
77                                const QString& caption, QWidget* parent ) = 0;
78
79   //! Invokes application-specific "Select Directory" dialog and returns the selected directory name.
80   virtual QString getDirectory( const QString& initial, const QString& caption, QWidget* parent ) = 0;
81
82 signals:
83   void                  applicationClosed( SUIT_Application* );
84   void                  activated( SUIT_Application* );
85
86 protected:
87   SUIT_Application*     startApplication( int, char** ) const;
88   SUIT_Application*     startApplication( const QString&, int, char** ) const;
89
90   void                  setDesktop( SUIT_Desktop* );
91
92   //! Creates a new Study instance. Must be redefined in new application according to its Study type.
93   virtual SUIT_Study*   createNewStudy();
94   virtual void          setActiveStudy( SUIT_Study* );
95
96   int                   createTool( const QString& );
97   int                   createTool( const int, const int, const int = -1 );
98   int                   createTool( const int, const QString&, const int = -1 );
99   int                   createTool( QAction*, const int, const int = -1, const int = -1 );
100   int                   createTool( QAction*, const QString&, const int = -1, const int = -1 );
101
102   int                   createMenu( const QString&, const int, const int = -1, const int = -1, const int = -1 );
103   int                   createMenu( const QString&, const QString&, const int = -1, const int = -1, const int = -1 );
104   int                   createMenu( const int, const int, const int = -1, const int = -1 );
105   int                   createMenu( const int, const QString&, const int = -1, const int = -1 );
106   int                   createMenu( QAction*, const int, const int = -1, const int = -1, const int = -1 );
107   int                   createMenu( QAction*, const QString&, const int = -1, const int = -1, const int = -1 );
108
109   void                  setMenuShown( QAction*, const bool );
110   void                  setMenuShown( const int, const bool );
111   void                  setToolShown( QAction*, const bool );
112   void                  setToolShown( const int, const bool );
113
114   static QAction*       separator();
115   QAction*              action( const int ) const;
116   int                   actionId( const QAction* ) const;
117   void                  registerAction( const int, QAction* );
118   QAction*              createAction( const int, const QString&, const QIconSet&, const QString&,
119                                       const QString&, const int, QObject* = 0,
120                                       const bool = false, QObject* = 0, const char* = 0 );
121
122 private slots:
123   void                  onDesktopActivated();
124
125 private:
126   SUIT_Study*           myStudy;
127   SUIT_Desktop*         myDesktop;
128 };
129
130 //! This function must return a new application instance.
131 extern "C"
132 {
133   //jfa 22.06.2005:typedef SUIT_Application* (*APP_CREATE_FUNC)( int, char** );
134   typedef SUIT_Application* (*APP_CREATE_FUNC)();
135 }
136
137 #define APP_CREATE_NAME "createApplication"
138
139 #endif