1 // File : QAD_Desktop.h
2 // Created : UI team, 02.10.00
3 // Descr : Main desktop of QAD-based application
5 // Modified : Mon Dec 03 13:40:28 2001
6 // Author : Nicolas REJNERI
9 // Copyright : Open CASCADE 2001
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"
22 #include "SALOME_NamingService.hxx"
23 #include "SALOME_LifeCycleCORBA.hxx"
26 #include <SALOMEconfig.h>
27 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
28 #include CORBA_CLIENT_HEADER(SALOME_Component)
29 #include CORBA_SERVER_HEADER(SALOMEDS)
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>
45 // Open CASCADE Includes
46 #include <OSD_SharedLibrary.hxx>
53 QMapIterator<unsigned int, QAction*> it;
54 for ( it = myMap.begin(); it != myMap.end(); it++ ) delete (QAction*)it.data();
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]; }
64 QMap<unsigned int, QAction*> myMap;
68 class ToggleAction : public QAction {
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 )
76 connect( this, SIGNAL(toggled(bool)), this, SLOT(onToggled(bool)));
79 void onToggled( bool on)
81 on ? emit( toggledOn() ) : emit( toggledOff() );
91 class QAD_EXPORT QAD_Desktop : public QMainWindow
96 //NRI - unused - : enum ComponentType {GEOM, MESH, SOLVER, DATA, VISU, OTHER} ;
98 enum { FileNewId = 0, FileOpenId, FileLoadId, FileCloseId, FileSaveId, FileSaveAsId, FilePropsId, FileExitId,
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,
109 WindowNew3dId, ViewOCCId, ViewVTKId, ViewPlot2dId,
111 WindowCascadeId, WindowTileId,
112 HelpContentsId, HelpSearchId, HelpWhatsThisId, HelpAboutId };
113 enum UpdateCommand { ActivateApp, DeactivateApp };
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 );
122 /* global event filter for qapplication */
123 bool eventFilter( QObject* o, QEvent* e );
126 static QAD_ResourceMgr* getResourceManager();
127 static QAD_ResourceMgr* createResourceManager();
130 static QPalette* getPalette();
131 static QPalette* createPalette();
133 /* activeStudyChanged */
134 void onActiveStudyChanged();
137 void definePopup(QString & theContext,
139 QString & theObject );
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);
149 void SetSelectionMode(int mode, bool activeCompOnly = false);
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;
160 void addApplication(QAD_Application* app);
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 );
173 virtual void helpAbout();
174 virtual void helpSearch();
175 virtual void helpContents();
176 virtual void helpContext(const QString& path, const QString& dir = QString::null);
178 bool loadComponent(QString);
179 void activateComponent(const QString& theName, bool isLoadData = true);
184 SALOME_ModuleCatalog::ModuleCatalog_var getCatalogue();
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;}
192 Engines::Component_var getEngine(const char *containerName,
193 const char *componentName);
195 QString getComponentName(const char *componentUserName);
196 QString getComponentUserName(const char *componentName);
198 QAD_HelpWindow* getHelpWindow();
200 void onMouseMove(QMouseEvent*);
201 bool onMousePress(QMouseEvent*);
202 void onKeyPress(QKeyEvent*);
205 bool closeAllStudies( QAD_Application* );
206 void closeEvent( QCloseEvent* );
207 void resizeEvent( QResizeEvent* );
209 virtual QString selectFileName ( bool open );
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 );
217 bool loadComponentData( const QString& );
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);
233 virtual void onStudyProperties();
235 virtual void onViewStatusBar();
236 virtual void onToolBarPopupAboutToShow();
238 virtual void onExit();
240 virtual void onWindowPopupAboutToShow();
241 void onWindowsPopupActivated( int id );
242 void onWindowsPopupStatusText( int id );
244 void onSelectionMode();
250 void onGraphSupervisor();
252 void onConsoleFontAction();
253 //VRV: T2.5 - add default viewer
254 void onDefaultViewer( QAction * theAction);
255 //VRV: T2.5 - add default viewer
257 void onViewerTrihedron();
258 void onObjectBrowser();
259 void onMultiFileSave();
261 void onActivateApp(QAD_Application* app);
262 void onDeactivateApp(QAD_Application* app);
264 void onHelpContents();
268 void onNewWindow3d();
272 void onDispatchTools(int id);
273 void onDispatch(int id);
276 void onButtonActiveComponent();
277 void onComboActiveComponent( const QString & );
278 void onComboActiveComponent( const QString & , bool isLoadData);
281 void onHelpWindowClosed();
284 QMenuBar* myMainMenu; /* the main menu bar */
285 int myMainMenuPos; /* index after which application inserts its items */
286 QPopupMenu myFilePopup;
288 QPopupMenu myEditPopup;
290 QPopupMenu myViewPopup;
292 QPopupMenu myHelpPopup;
295 //VRV: T2.5 - add default viewer
296 QPopupMenu myDefaultViewer;
297 //VRV: T2.5 - add default viewer
298 QPopupMenu myObjBrowserPopup;
299 QPopupMenu myViewerPopup;
301 QPopupMenu myNewViewPopup;
303 QPopupMenu myToolsPopup;
304 QPopupMenu myPrefPopup;
305 QPopupMenu mySelectionModePopup;
306 QPopupMenu myWindowPopup; /* not customized by an application */
308 ActionMap myStdActions; /* default actions */
309 QToolBar* myStdToolBar; /* standard toolbar */
310 QStatusBar* myStatusBar; /* the only status bar */
312 QList<ToggleAction> myToolBarAction;
313 QPopupMenu myToolBarsPopup;
315 QList<QAD_Application> myApps; /* running applications */
316 QAD_Application* myActiveApp; /* the active application */
317 QAD_Study* myActiveStudy; /* the active document */
319 int myCntUntitled; /* number of untitled docs */
320 QWorkspaceP* myWorkspace; /* workspace */
322 QPixmap myDefaultIcon; /* if no application is active */
323 QString myDefaultTitle; /* desktop will use them */
325 QAD_OperatorMenus* myOperatorMenus;
326 QList<QAD_Menus> myMenusList;
327 QAD_Menus* myActiveMenus;
329 QAD_HelpWindow* myHelpWindow;
331 QList<QToolButton> myComponentButton;
333 QMap<QString,QString> mapComponentName;
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;
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.
356 *********************************************************************/
357 class Desktop_AppSelectionDlg : public QDialog
362 Desktop_AppSelectionDlg( QAD_Desktop*, QList<QAD_Application>& );
363 ~Desktop_AppSelectionDlg();
366 QAD_Application* selectedApp() const;
369 void resizeEvent( QResizeEvent* );
372 void onAppSelected(int);
377 QList<QAD_Application>& myApps;