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 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 QAD_HelpWindow* getHelpWindow();
197 void onMouseMove(QMouseEvent*);
198 bool onMousePress(QMouseEvent*);
199 void onKeyPress(QKeyEvent*);
202 bool closeAllStudies( QAD_Application* );
203 void closeEvent( QCloseEvent* );
204 void resizeEvent( QResizeEvent* );
206 virtual QString selectFileName ( bool open );
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 );
214 bool loadComponentData( const QString& );
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);
230 virtual void onStudyProperties();
232 virtual void onViewStatusBar();
233 virtual void onToolBarPopupAboutToShow();
235 virtual void onExit();
237 virtual void onWindowPopupAboutToShow();
238 void onWindowsPopupActivated( int id );
239 void onWindowsPopupStatusText( int id );
241 void onSelectionMode();
247 void onGraphSupervisor();
249 void onConsoleFontAction();
250 //VRV: T2.5 - add default viewer
251 void onDefaultViewer( QAction * theAction);
252 //VRV: T2.5 - add default viewer
254 void onViewerTrihedron();
255 void onObjectBrowser();
256 void onMultiFileSave();
258 void onActivateApp(QAD_Application* app);
259 void onDeactivateApp(QAD_Application* app);
261 void onHelpContents();
265 void onNewWindow3d();
269 void onDispatchTools(int id);
270 void onDispatch(int id);
273 void onButtonActiveComponent();
274 void onComboActiveComponent( const QString & );
275 void onComboActiveComponent( const QString & , bool isLoadData);
278 void onHelpWindowClosed();
281 QMenuBar* myMainMenu; /* the main menu bar */
282 int myMainMenuPos; /* index after which application inserts its items */
283 QPopupMenu myFilePopup;
285 QPopupMenu myEditPopup;
287 QPopupMenu myViewPopup;
289 QPopupMenu myHelpPopup;
292 //VRV: T2.5 - add default viewer
293 QPopupMenu myDefaultViewer;
294 //VRV: T2.5 - add default viewer
295 QPopupMenu myObjBrowserPopup;
296 QPopupMenu myViewerPopup;
298 QPopupMenu myNewViewPopup;
300 QPopupMenu myToolsPopup;
301 QPopupMenu myPrefPopup;
302 QPopupMenu mySelectionModePopup;
303 QPopupMenu myWindowPopup; /* not customized by an application */
305 ActionMap myStdActions; /* default actions */
306 QToolBar* myStdToolBar; /* standard toolbar */
307 QStatusBar* myStatusBar; /* the only status bar */
309 QList<ToggleAction> myToolBarAction;
310 QPopupMenu myToolBarsPopup;
312 QList<QAD_Application> myApps; /* running applications */
313 QAD_Application* myActiveApp; /* the active application */
314 QAD_Study* myActiveStudy; /* the active document */
316 int myCntUntitled; /* number of untitled docs */
317 QWorkspaceP* myWorkspace; /* workspace */
319 QPixmap myDefaultIcon; /* if no application is active */
320 QString myDefaultTitle; /* desktop will use them */
322 QAD_OperatorMenus* myOperatorMenus;
323 QList<QAD_Menus> myMenusList;
324 QAD_Menus* myActiveMenus;
326 QAD_HelpWindow* myHelpWindow;
328 QList<QToolButton> myComponentButton;
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;
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.
351 *********************************************************************/
352 class Desktop_AppSelectionDlg : public QDialog
357 Desktop_AppSelectionDlg( QAD_Desktop*, QList<QAD_Application>& );
358 ~Desktop_AppSelectionDlg();
361 QAD_Application* selectedApp() const;
364 void resizeEvent( QResizeEvent* );
367 void onAppSelected(int);
372 QList<QAD_Application>& myApps;