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