Salome HOME
NRI : Add KERNEL_ROOT_DIR in addition to SALOME_[ROOT, SITE]_DIR.
[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   //NRI - unused - :  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     QString getComponentName(const char *componentUserName);
196     QString getComponentUserName(const char *componentName);
197     
198     QAD_HelpWindow*   getHelpWindow();
199
200     void              onMouseMove(QMouseEvent*);
201     bool              onMousePress(QMouseEvent*);
202     void              onKeyPress(QKeyEvent*);
203
204 protected:
205     bool              closeAllStudies( QAD_Application* );
206     void              closeEvent( QCloseEvent* );
207     void              resizeEvent( QResizeEvent* );
208
209     virtual  QString  selectFileName ( bool open );
210
211     virtual   void    updateDesktop( UpdateCommand  );
212     virtual   void    updateStatusBar( UpdateCommand );
213     virtual   void    updateToolBars( UpdateCommand );
214     virtual   void    updateCaption( UpdateCommand );
215     virtual   void    updateMenu( UpdateCommand );
216
217     bool              loadComponentData( const QString& );
218
219 protected slots:
220     virtual void      onNewStudy();
221     virtual void      onNewStudy(QAD_Application* app);
222     virtual void      onLoadStudy();
223     virtual void      onOpenStudy();
224     virtual bool      onSaveStudy();
225     virtual bool      onSaveStudy(QAD_Study* doc);
226     virtual bool      onSaveAsStudy();
227     virtual bool      onSaveAsStudy(QAD_Study* doc);
228     virtual bool      onCloseStudy();
229     virtual bool      onCloseStudy(QAD_Study* doc);
230     //ask user to remove study from study manager permanently
231     virtual bool      onCloseStudy(QAD_Study* doc, bool ask);
232
233     virtual void      onStudyProperties();
234
235     virtual void      onViewStatusBar();
236     virtual void      onToolBarPopupAboutToShow();
237
238     virtual void      onExit();
239
240     virtual void      onWindowPopupAboutToShow();
241     void              onWindowsPopupActivated( int id );
242     void              onWindowsPopupStatusText( int id );
243
244     void              onSelectionMode();
245
246     void              onDirList();
247     void              onSavePref();
248     void              onViewerOCC();
249     void              onViewerVTK();
250     void              onGraphSupervisor();
251     void              onPlot2d();
252     void              onConsoleFontAction();
253   //VRV: T2.5 - add default viewer
254     void              onDefaultViewer( QAction * theAction);
255   //VRV: T2.5 - add default viewer
256
257     void              onViewerTrihedron();
258     void              onObjectBrowser();
259     void              onMultiFileSave();
260
261     void              onActivateApp(QAD_Application* app);
262     void              onDeactivateApp(QAD_Application* app);
263
264     void              onHelpContents();
265     void              onHelpSearch();
266     void              onHelpAbout();
267
268     void              onNewWindow3d();
269
270     void              onOpenWith();
271
272     void              onDispatchTools(int id);
273     void              onDispatch(int id);
274     void              onDispatch();
275     void              clearMenus();
276     void              onButtonActiveComponent();
277     void              onComboActiveComponent( const QString & );
278     void              onComboActiveComponent( const QString & , bool isLoadData);
279     void              onCascade(); 
280
281     void              onHelpWindowClosed();
282
283 protected:
284     QMenuBar*         myMainMenu;           /* the main menu bar */
285     int               myMainMenuPos;        /* index after which application inserts its items */
286     QPopupMenu        myFilePopup;
287     int               myFilePos;
288     QPopupMenu        myEditPopup;
289     int               myEditPos;
290     QPopupMenu        myViewPopup;
291     int               myViewPos;
292     QPopupMenu        myHelpPopup;
293     int               myHelpPos;
294
295   //VRV: T2.5 - add default viewer
296     QPopupMenu        myDefaultViewer;
297   //VRV: T2.5 - add default viewer
298     QPopupMenu        myObjBrowserPopup;
299     QPopupMenu        myViewerPopup;
300   //NRI : SAL2214
301     QPopupMenu        myNewViewPopup;
302   //NRI : SAL2214
303     QPopupMenu        myToolsPopup;
304     QPopupMenu        myPrefPopup;
305     QPopupMenu        mySelectionModePopup;
306     QPopupMenu        myWindowPopup;        /* not customized by an application */
307
308     ActionMap         myStdActions;         /* default actions */
309     QToolBar*         myStdToolBar;         /* standard toolbar */
310     QStatusBar*       myStatusBar;          /* the only status bar */
311
312     QList<ToggleAction> myToolBarAction;
313     QPopupMenu          myToolBarsPopup;
314
315     QList<QAD_Application> myApps;          /* running applications */
316     QAD_Application*  myActiveApp;          /* the active application */
317     QAD_Study*        myActiveStudy;        /* the active document */
318
319     int               myCntUntitled;        /* number of untitled docs */
320     QWorkspaceP*      myWorkspace;          /* workspace */
321
322     QPixmap           myDefaultIcon;        /* if no application is active */
323     QString           myDefaultTitle;       /* desktop will use them */
324
325     QAD_OperatorMenus* myOperatorMenus;
326     QList<QAD_Menus>   myMenusList;
327     QAD_Menus*         myActiveMenus;
328
329     QAD_HelpWindow*    myHelpWindow;
330
331     QList<QToolButton> myComponentButton;
332
333     QMap<QString,QString> mapComponentName;
334
335 private:
336     static QAD_ResourceMgr*                 resourceMgr;
337     static QPalette*                        palette;
338     void                                    createActions();
339     void                                    updateActions();
340     OSD_SharedLibrary                       mySharedLibrary;
341     QAD_XmlHandler*                         myXmlHandler;
342     QString                                 myActiveComp;
343     SALOME_NamingService*                   myNameService;
344     SALOME_ModuleCatalog::ModuleCatalog_var myCatalogue;
345     SALOME_LifeCycleCORBA *                 myEnginesLifeCycle;
346     QComboBox *                             myCombo;
347     bool                                    myQueryClose;
348 };
349
350 /********************************************************************
351 ** Class: AppSelectionDlg
352 ** Descr: Dialog for the selection of the application when several
353 **        applications exist in the desktop and new document creation
354 **        is activated by user.
355 ** Level: Internal
356 *********************************************************************/
357 class Desktop_AppSelectionDlg : public QDialog
358 {
359    Q_OBJECT
360
361 public:
362    Desktop_AppSelectionDlg( QAD_Desktop*, QList<QAD_Application>& );
363    ~Desktop_AppSelectionDlg();
364
365 public:
366     QAD_Application* selectedApp()  const;
367
368 protected:
369     void             resizeEvent( QResizeEvent* );
370
371 protected slots:
372     void             onAppSelected(int);
373     void             onHelp();
374
375 protected:
376     int                                     myAppId;
377     QList<QAD_Application>&                 myApps;
378 };
379
380 #endif
381