Salome HOME
PR : KERNEL 5165
[modules/yacs.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
43 // IDL Headers 
44 #include <SALOMEconfig.h>
45 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
46 #include CORBA_CLIENT_HEADER(SALOME_Component)
47 #include CORBA_SERVER_HEADER(SALOMEDS)
48
49 // QT Includes
50 #include <qlist.h>
51 #include <qmap.h>
52 #include <qmenubar.h>
53 #include <qtoolbar.h>
54 #include <qcombobox.h>
55 #include <qstatusbar.h>
56 #include <qpopupmenu.h>
57 #include "qworkspaceP.h"
58 #include <qmainwindow.h>
59 #include <qfiledialog.h>
60 #include <qtoolbutton.h>
61
62 // Open CASCADE Includes
63 #include <OSD_SharedLibrary.hxx>
64
65 class QAD_XmlHandler;
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 = 0, 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, HelpSearchId, HelpWhatsThisId, HelpAboutId };
90   enum UpdateCommand { ActivateApp, DeactivateApp };
91
92     /* Desktop can be created only by application */
93     friend  bool QAD_Application::createDesktop( SALOME_NamingService* name_service );
94     QAD_Desktop( SALOME_NamingService* name_service );
95
96 public:
97     ~QAD_Desktop();
98
99     /* global event filter for qapplication */
100     bool eventFilter( QObject* o, QEvent* e );
101
102     /* resources */
103     static QAD_ResourceMgr* getResourceManager();
104     static QAD_ResourceMgr* createResourceManager();
105
106     /* palette */
107     static QPalette* getPalette();
108     static QPalette* createPalette();
109
110     /* activeStudyChanged */
111     void onActiveStudyChanged();
112
113     /* popup */
114     void     definePopup(QString & theContext,
115                          QString & theParent, 
116                          QString & theObject );
117
118     void     createPopup(QPopupMenu* popupFather, QPopupMenu* popup,
119                          QString text, int popupID, bool separator = false);
120     void     createPopup(QPopupMenu* popup, const QString & theContext,
121                          const QString & theParent, const QString & theObject );
122     void     customPopup(QPopupMenu* popup, const QString & theContext,
123                          const QString & theParent, const QString & theObject);
124
125     /* selection mode */
126     void SetSelectionMode(int mode, bool activeCompOnly = false);
127
128     /* desktop */
129     void              showDesktop();
130     void              closeDesktop( bool forceClose = false );
131     void              putInfo ( const QString& );
132     void              putInfo ( const QString&, int );
133     QToolBar*         getStdToolBar() const;
134     QMenuBar*         getMainMenuBar() const;
135
136     /* application */
137     void              addApplication(QAD_Application* app);
138
139     /* studies */
140     const QString&    getDefaultTitle() const;
141     const QPixmap&    getDefaultIcon() const;
142     const QString&    getDefaultStudyName() const;
143     QAD_Application*  getActiveApp() const;
144     QAD_Study*        getActiveStudy() const;
145     QWorkspaceP*      getMainFrame() const;
146     QString           getNewStudyName();
147     QAD_Study*        findStudy( SALOMEDS::Study_ptr theStudy );
148     static int        getUndoLevel();
149     /* help actions */
150     virtual void      helpAbout();    
151 /*    virtual void      helpSearch();
152     virtual void      helpContents();
153     virtual void      helpContext(const QString& path, const QString& dir = QString::null);
154 */
155     bool              loadComponent(QString);
156     QString           changeXmlInputSourceData(QString theData, QString theComponent);
157     void              activateComponent(const QString& theName, bool isLoadData = true);
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 OSD_SharedLibrary&  getHandle() const {return mySharedLibrary;}// never return sych objects "by value"
167     const QString&        getActiveComponent() const;
168     SALOME_NamingService* getNameService()      {return myNameService;}
169
170     Engines::Component_var getEngine(const char *containerName,
171                                      const char *componentName);
172
173     QString getComponentName(const char *componentUserName);
174     QString getComponentUserName(const char *componentName);
175     
176     //NRI    QAD_HelpWindow*   getHelpWindow();
177
178     void              onMouseMove(QMouseEvent*);
179     bool              onMousePress(QMouseEvent*);
180     void              onKeyPress(QKeyEvent*);
181
182     virtual QAD_Study* loadStudy(QString theStudyName);
183
184 protected:
185     bool              closeAllStudies( QAD_Application* );
186     void              closeEvent( QCloseEvent* );
187     void              resizeEvent( QResizeEvent* );
188
189     virtual  QString  selectFileName ( bool open );
190
191     virtual   void    updateDesktop( UpdateCommand  );
192     virtual   void    updateStatusBar( UpdateCommand );
193     virtual   void    updateToolBars( UpdateCommand );
194     virtual   void    updateCaption( UpdateCommand );
195     virtual   void    updateMenu( UpdateCommand );
196
197     bool              loadComponentData( const QString& );
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
224     void              onSelectionMode();
225
226     void              onDirList();
227     void              onSavePref();
228     void              onViewerOCC();
229     void              onViewerVTK();
230     void              onGraphSupervisor();
231     void              onPlot2d();
232     void              onConsoleFontAction();
233   //VRV: T2.5 - add default viewer
234     void              onDefaultViewer( QActionP * theAction);
235   //VRV: T2.5 - add default viewer
236
237     void              onViewerTrihedron();
238     void              onObjectBrowser();
239     void              onMultiFileSave();
240     void              onASCIISave();
241     void              onUndoLevel();
242     void              onExternalBrowser();      
243
244     void              onActivateApp(QAD_Application* app);
245     void              onDeactivateApp(QAD_Application* app);
246
247     void              onHelpContents();
248     void              onHelpContentsGUI();
249     void              onHelpContentsTUI();
250 /*    void            onHelpSearch(); */
251     void              onHelpAbout();
252
253     void              onNewWindow3d();
254
255     void              onOpenWith();
256
257     void              onDispatchTools(int id);
258     void              onDispatch(int id);
259     void              onDispatch();
260     void              clearMenus();
261     void              onButtonActiveComponent();
262     void              onComboActiveComponent( const QString & );
263     void              onComboActiveComponent( const QString & , bool isLoadData);
264     void              onCascade(); 
265
266 /* NRI   void              onHelpWindowClosed(); */
267
268 protected:
269     QMenuBar*         myMainMenu;           /* the main menu bar */
270     int               myMainMenuPos;        /* index after which application inserts its items */
271     QPopupMenu        myFilePopup;
272     int               myFilePos;
273     QPopupMenu        myEditPopup;
274     int               myEditPos;
275     QPopupMenu        myViewPopup;
276     int               myViewPos;
277     QPopupMenu        myHelpPopup;
278     int               myHelpPos;
279
280   //VRV: T2.5 - add default viewer
281     QPopupMenu        myDefaultViewer;
282   //VRV: T2.5 - add default viewer
283     QPopupMenu        myObjBrowserPopup;
284     QPopupMenu        myViewerPopup;
285   //NRI : SAL2214
286     QPopupMenu        myNewViewPopup;
287   //NRI : SAL2214
288     QPopupMenu        myToolsPopup;
289     QPopupMenu        myPrefPopup;
290     QPopupMenu        mySelectionModePopup;
291     QPopupMenu        myWindowPopup;        /* not customized by an application */
292
293     ActionMap         myStdActions;         /* default actions */
294     QToolBar*         myStdToolBar;         /* standard toolbar */
295     QStatusBar*       myStatusBar;          /* the only status bar */
296
297     QList<ToggleAction> myToolBarAction;
298     QPopupMenu          myToolBarsPopup;
299
300     QList<QAD_Application> myApps;          /* running applications */
301     QAD_Application*  myActiveApp;          /* the active application */
302     QAD_Study*        myActiveStudy;        /* the active document */
303
304     int               myCntUntitled;        /* number of untitled docs */
305     QWorkspaceP*      myWorkspace;          /* workspace */
306
307     QPixmap           myDefaultIcon;        /* if no application is active */
308     QString           myDefaultTitle;       /* desktop will use them */
309
310     QAD_OperatorMenus* myOperatorMenus;
311     QList<QAD_Menus>   myMenusList;
312     QAD_Menus*         myActiveMenus;
313
314     //NRI QAD_HelpWindow*    myHelpWindow;
315
316     QList<QToolButton> myComponentButton;
317
318     QMap<QString,QString> mapComponentName;
319
320 private:
321     static QAD_ResourceMgr*                 resourceMgr;
322     static QPalette*                        palette;
323     void                                    createActions();
324     void                                    updateActions();
325     OSD_SharedLibrary                       mySharedLibrary;
326     QAD_XmlHandler*                         myXmlHandler;
327     QString                                 myActiveComp;
328     SALOME_NamingService*                   myNameService;
329     SALOME_ModuleCatalog::ModuleCatalog_var myCatalogue;
330     SALOME_LifeCycleCORBA *                 myEnginesLifeCycle;
331     QComboBox *                             myCombo;
332     bool                                    myQueryClose;
333     bool                                    _islibso;
334 };
335
336 /********************************************************************
337 ** Class: AppSelectionDlg
338 ** Descr: Dialog for the selection of the application when several
339 **        applications exist in the desktop and new document creation
340 **        is activated by user.
341 ** Level: Internal
342 *********************************************************************/
343 class Desktop_AppSelectionDlg : public QDialog
344 {
345    Q_OBJECT
346
347 public:
348    Desktop_AppSelectionDlg( QAD_Desktop*, QList<QAD_Application>& );
349    ~Desktop_AppSelectionDlg();
350
351 public:
352     QAD_Application* selectedApp()  const;
353
354 protected:
355     void             resizeEvent( QResizeEvent* );
356
357 protected slots:
358     void             onAppSelected(int);
359     void             onHelp();
360
361 protected:
362     int                                     myAppId;
363     QList<QAD_Application>&                 myApps;
364 };
365
366 #endif
367