Salome HOME
Porting to Mandrake 10.1 and new products:
[modules/kernel.git] / src / SALOMEGUI / QAD_Desktop.h
1 //  SALOME SALOMEGUI : implementation of desktop and GUI kernel
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : QAD_Desktop.h
25 //  Author : Nicolas REJNERI
26 //  Module : SALOME
27 //  $Header$
28
29 #ifndef QAD_DESKTOP_H
30 #define QAD_DESKTOP_H
31
32 #include "QAD.h"
33 #include "QAD_ResourceMgr.h"
34 #include "QAD_Application.h"
35 #include "QAD_OperatorMenus.h"
36 #include "QAD_Menus.h"
37 //NRI#include "QAD_HelpWindow.h"
38 #include "QAD_Action.h"
39
40 #include "SALOME_NamingService.hxx"
41 #include "SALOME_LifeCycleCORBA.hxx"
42 #include "SALOME_Selection.h"
43
44 // IDL Headers 
45 #include <SALOMEconfig.h>
46 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
47 #include CORBA_CLIENT_HEADER(SALOME_Component)
48 #include CORBA_SERVER_HEADER(SALOMEDS)
49
50 // QT Includes
51 #include <qlist.h>
52 #include <qmap.h>
53 #include <qmenubar.h>
54 #include <qtoolbar.h>
55 #include <qcombobox.h>
56 #include <qstatusbar.h>
57 #include <qpopupmenu.h>
58 #include "qworkspaceP.h"
59 #include <qmainwindow.h>
60 #include <qfiledialog.h>
61 #include <qtoolbutton.h>
62
63 class QAD_XmlHandler;
64 class SALOMEGUI;
65 class SALOME_Event;
66
67 class QAD_EXPORT QAD_Desktop : public QMainWindow
68 {
69   Q_OBJECT
70
71 protected:
72   //NRI - unused - :  enum ComponentType {GEOM, MESH, SOLVER, DATA, VISU, OTHER} ;
73
74   enum {  FileNewId = -1000, FileOpenId, FileLoadId, FileCloseId, FileSaveId, FileSaveAsId, FilePropsId, FileExitId,
75           ViewStatusBarId,
76           SelectionPointId, SelectionEdgeId, SelectionCellId, SelectionActorId,
77           PrefViewerOCCId, PrefViewerVTKId, PrefGraphSupervisorId, PrefViewerPlot2dId,
78           //VRV: T2.5 - add default viewer
79           DefaultViewerOCCId, DefaultViewerVTKId, DefaultGraphSupervisorId, DefaultPlot2dId,
80           //VRV: T2.5 - add default viewer
81           PrefViewerTrihedronId, PrefConsoleFontId, PrefObjectBrowserEntryId, 
82           PrefObjectBrowserIAPPId, PrefObjectBrowserValueId, PrefObjectBrowserCHRONO_SORTId,PrefObjectBrowserShowUseCaseId, 
83           PrefObjectBrowserNoAutoSizeColumnsId,  
84           PrefDirsId, PrefMultiFileSave, PrefASCIISave, PrefUndoLevelId, PrefExternalBrowserId, PrefSaveId,
85           //NRI : SAL2214
86           WindowNew3dId, ViewOCCId, ViewVTKId, ViewPlot2dId,
87           //NRI : SAL2214
88           WindowCascadeId, WindowTileId, 
89           HelpContentsId, HelpContentsModuleId,
90           HelpSearchId, HelpWhatsThisId, HelpAboutId };
91   enum UpdateCommand { ActivateApp, DeactivateApp };
92
93     /* Desktop can be created only by application */
94     friend  bool QAD_Application::createDesktop( SALOME_NamingService* name_service );
95     QAD_Desktop( SALOME_NamingService* name_service );
96
97 public:
98     ~QAD_Desktop();
99
100     /* global event filter for qapplication */
101     bool eventFilter( QObject* o, QEvent* e );
102
103     /* resources */
104     static QAD_ResourceMgr* getResourceManager();
105     static QAD_ResourceMgr* createResourceManager();
106
107     /* palette */
108     static QPalette* getPalette();
109     static QPalette* createPalette();
110
111     /* activeStudyChanged */
112     void onActiveStudyChanged();
113
114     /* popup */
115     void     definePopup(QString & theContext,
116                          QString & theParent, 
117                          QString & theObject );
118     void     createPopup(QPopupMenu* popup, const QString & theContext,
119                          const QString & theParent, const QString & theObject );
120     void     customPopup(QPopupMenu* popup, const QString & theContext,
121                          const QString & theParent, const QString & theObject);
122
123     /* selection mode */
124     void SetSelectionMode(Selection_Mode mode, bool activeCompOnly = false);
125
126     /* desktop */
127     void              showDesktop();
128     void              closeDesktop( bool forceClose = false );
129     void              putInfo ( const QString& );
130     void              putInfo ( const QString&, int );
131     QToolBar*         getStdToolBar() const;
132     QMenuBar*         getMainMenuBar() const;
133
134     /* application */
135     void              addApplication(QAD_Application* app);
136
137     /* studies */
138     const QString&    getDefaultTitle() const;
139     const QPixmap&    getDefaultIcon() const;
140     const QString&    getDefaultStudyName() const;
141     QAD_Application*  getActiveApp() const;
142     QAD_Study*        getActiveStudy() const;
143     QWorkspaceP*      getMainFrame() const;
144     QString           getNewStudyName();
145     QAD_Study*        findStudy( SALOMEDS::Study_ptr theStudy );
146     static int        getUndoLevel();
147     /* help actions */
148     virtual void      helpAbout();    
149 /*    virtual void      helpSearch();
150     virtual void      helpContents();
151     virtual void      helpContext(const QString& path, const QString& dir = QString::null);
152 */
153     bool              loadComponent(QString);
154     bool              loadComponentData( const QString& );
155     QString           changeXmlInputSourceData(QString theData, QString theComponent);
156     void              activateComponent(const QString& theName, bool isLoadData = true);
157     void              deactivateComponent();
158     void              createStudy();
159
160     void              setSettings();
161
162     SALOME_ModuleCatalog::ModuleCatalog_var getCatalogue();
163
164     QAD_Menus*            getActiveMenus()      {return myActiveMenus;}
165     QAD_OperatorMenus*    getOperatorMenus()    {return myOperatorMenus;}
166     const QString&        getActiveComponent() const;
167     SALOMEGUI*            getActiveGUI();
168     SALOMEGUI*            getComponentGUI( const QString& );  // accepts component`s user name
169     QString               getComponentDataType() const;
170     SALOME_NamingService* getNameService()      {return myNameService;}
171
172     Engines::Component_var getEngine(const char *containerName,
173                                      const char *componentName);
174
175     QString getComponentName(const char *componentUserName);
176     QString getComponentUserName(const char *componentName);
177     
178     //NRI    QAD_HelpWindow*   getHelpWindow();
179
180     void              onMouseMove(QMouseEvent*);
181     bool              onMousePress(QMouseEvent*);
182     void              onKeyPress(QKeyEvent*);
183
184     virtual QAD_Study* loadStudy(QString theStudyName);
185
186 protected:
187     bool              closeAllStudies( QAD_Application* );
188     void              closeEvent( QCloseEvent* );
189     void              resizeEvent( QResizeEvent* );
190
191     virtual  QString  selectFileName ( bool open );
192
193     virtual   void    updateDesktop( UpdateCommand  );
194     virtual   void    updateStatusBar( UpdateCommand );
195     virtual   void    updateToolBars( UpdateCommand );
196     virtual   void    updateCaption( UpdateCommand );
197     virtual   void    updateMenu( UpdateCommand );
198
199 protected slots:
200     virtual void      onNewStudy();
201     virtual void      onNewStudy(QAD_Application* app);
202     virtual void      onLoadStudy();
203     virtual void      onOpenStudy();
204     virtual bool      onSaveStudy();
205     virtual bool      onSaveStudy(QAD_Study* doc);
206     virtual bool      onSaveAsStudy();
207     virtual bool      onSaveAsStudy(QAD_Study* doc);
208     virtual bool      onCloseStudy();
209     virtual bool      onCloseStudy(QAD_Study* doc);
210     //ask user to remove study from study manager permanently
211     virtual bool      onCloseStudy(QAD_Study* doc, bool ask);
212
213     virtual void      onStudyProperties();
214
215     virtual void      onViewStatusBar();
216     virtual void      onToolBarPopupAboutToShow();
217
218     virtual void      onExit();
219
220     virtual void      onWindowPopupAboutToShow();
221     void              onWindowsPopupActivated( int id );
222     void              onWindowsPopupStatusText( int id );
223     void              onHelpModulePopupStatusText(int id);
224     
225     void              onFilePopupStatusText( int id );
226     void              onEditPopupStatusText( int id );
227     void              onViewPopupStatusText( int id );
228
229     void              onSelectionMode();
230
231     void              onDirList();
232     void              onSavePref();
233     void              onViewerOCC();
234     void              onViewerVTK();
235     void              onGraphSupervisor();
236     void              onPlot2d();
237     void              onConsoleFontAction();
238   //VRV: T2.5 - add default viewer
239     void              onDefaultViewer( QActionP * theAction);
240   //VRV: T2.5 - add default viewer
241
242     void              onViewerTrihedron();
243     void              onObjectBrowser();
244     void              onMultiFileSave();
245     void              onASCIISave();
246     void              onUndoLevel();
247     void              onExternalBrowser();      
248
249     void              onActivateApp(QAD_Application* app);
250     void              onDeactivateApp(QAD_Application* app);
251
252     void              onHelpContents();
253     void              onHelpContentsModule();
254     /*    void        onHelpContentsTUI(); */
255 /*    void            onHelpSearch(); */
256     void              onHelpAbout();
257
258     void              onNewWindow3d();
259
260     void              onOpenWith();
261
262     void              onDispatchTools(int id);
263     void              onDispatch(int id);
264     void              onDispatch();
265     void              clearMenus();
266     void              onButtonActiveComponent();
267     void              onComboActiveComponent( const QString & );
268     void              onComboActiveComponent( const QString & , bool isLoadData);
269     void              onCascade(); 
270
271     void              onKeyAccel( int id );
272 /* NRI   void              onHelpWindowClosed(); */
273
274 protected:
275     QMenuBar*         myMainMenu;           /* the main menu bar */
276     int               myMainMenuPos;        /* index after which application inserts its items */
277     QPopupMenu        myFilePopup;
278     int               myFilePos;
279     QPopupMenu        myEditPopup;
280     int               myEditPos;
281     QPopupMenu        myViewPopup;
282     int               myViewPos;
283     QPopupMenu        myHelpPopup;
284     int               myHelpPos;
285
286   //VRV: T2.5 - add default viewer
287     QPopupMenu        myDefaultViewer;
288   //VRV: T2.5 - add default viewer
289     QPopupMenu        myObjBrowserPopup;
290     QPopupMenu        myViewerPopup;
291   //NRI : SAL2214
292     QPopupMenu        myNewViewPopup;
293   //NRI : SAL2214
294     QPopupMenu        myHelpContentsModulePopup;
295
296     QPopupMenu        myToolsPopup;
297     QPopupMenu        myPrefPopup;
298     QPopupMenu        mySelectionModePopup;
299     QPopupMenu        myWindowPopup;        /* not customized by an application */
300     
301     ActionMap         myStdActions;         /* default actions */
302     QToolBar*         myStdToolBar;         /* standard toolbar */
303     QStatusBar*       myStatusBar;          /* the only status bar */
304
305     QList<ToggleAction> myToolBarAction;
306     QPopupMenu          myToolBarsPopup;
307
308     QList<QAD_Application> myApps;          /* running applications */
309     QAD_Application*  myActiveApp;          /* the active application */
310     QAD_Study*        myActiveStudy;        /* the active document */
311
312     int               myCntUntitled;        /* number of untitled docs */
313     QWorkspaceP*      myWorkspace;          /* workspace */
314
315     QPixmap           myDefaultIcon;        /* if no application is active */
316     QString           myDefaultTitle;       /* desktop will use them */
317
318     QAD_OperatorMenus* myOperatorMenus;
319     QList<QAD_Menus>   myMenusList;
320     QAD_Menus*         myActiveMenus;
321
322     //NRI QAD_HelpWindow*    myHelpWindow;
323
324     QList<QToolButton> myComponentButton;
325
326     QMap<QString,QString> mapComponentName;
327
328 private:
329     void processEvent( SALOME_Event* );
330
331 private:
332     typedef QMap<QString, SALOMEGUI*> ComponentMap;
333
334 private:
335     static QAD_ResourceMgr*                 resourceMgr;
336     static QPalette*                        palette;
337     void                                    createActions();
338     void                                    updateActions();
339     QAD_XmlHandler*                         myXmlHandler;
340     QString                                 myActiveComp;
341     SALOME_NamingService*                   myNameService;
342     SALOME_ModuleCatalog::ModuleCatalog_var myCatalogue;
343     SALOME_LifeCycleCORBA *                 myEnginesLifeCycle;
344     QComboBox *                             myCombo;
345     bool                                    myQueryClose;
346     bool                                    myAboutToClose;
347     bool                                    _islibso;
348
349     ComponentMap                            myComponents;
350     QMap<int, int>                          myAccelMap;
351 };
352
353 /********************************************************************
354 ** Class: AppSelectionDlg
355 ** Descr: Dialog for the selection of the application when several
356 **        applications exist in the desktop and new document creation
357 **        is activated by user.
358 ** Level: Internal
359 *********************************************************************/
360 class Desktop_AppSelectionDlg : public QDialog
361 {
362    Q_OBJECT
363
364 public:
365    Desktop_AppSelectionDlg( QAD_Desktop*, QList<QAD_Application>& );
366    ~Desktop_AppSelectionDlg();
367
368 public:
369     QAD_Application* selectedApp()  const;
370
371 protected:
372     void             resizeEvent( QResizeEvent* );
373
374 protected slots:
375     void             onAppSelected(int);
376     void             onHelp();
377
378 protected:
379     int                                     myAppId;
380     QList<QAD_Application>&                 myApps;
381 };
382
383 #endif
384