Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/kernel.git] / src / SALOMEGUI / QAD_Desktop.cxx
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.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SALOME
27 //  $Header$
28
29 /*!
30   \class QAD_Desktop QAD_Desktop.h
31   \brief Main desktop of QAD-based application.
32 */
33 using namespace std;
34 # include "Utils_ORB_INIT.hxx"
35 # include "Utils_SINGLETON.hxx"
36
37 #define  INCLUDE_MENUITEM_DEF
38
39 #include "QAD.h"
40 #include "QAD_Help.h"
41 #include "QAD_Tools.h"
42 #include "QAD_Desktop.h"
43 #include "QAD_LeftFrame.h"
44 #include "QAD_RightFrame.h"
45 #include "QAD_Operation.h"
46 #include "QAD_XmlHandler.h"
47 #include "QAD_MessageBox.h"
48 #include "QAD_Application.h"
49 #include "QAD_Settings.h"
50 #include "QAD_Config.h"
51 #include "QAD_ObjectBrowser.h"
52 #include "QAD_Resource.h"
53 #include "QAD_FileDlg.h"
54 #include "QAD_HelpWindow.h"
55 #include "QAD_DirListDlg.h"
56 #include "QAD_WaitCursor.h"
57 #include "SALOMEGUI_OpenWith.h"
58 #include "SALOMEGUI_StudyPropertiesDlg.h"
59 #include "SALOMEGUI_TrihedronSizeDlg.h"
60 #include "SALOMEGUI_LoadStudiesDlg.h"
61 #include "SALOME_Selection.h"
62 #include "SALOME_InteractiveObject.hxx"
63 #include "SALOME_ListIteratorOfListIO.hxx"
64 #include "SALOMEGUI_AboutDlg.h"
65 #include "SALOMEGUI_ViewChoiceDlg.h"
66 #include "utilities.h"
67
68 #include "SALOMEGUI_CloseDlg.h"
69
70 // QT Includes
71 #include <qlabel.h>
72 #include <qlayout.h>
73 #include <qmessagebox.h>
74 #include <qcolordialog.h>
75 #include <qradiobutton.h>
76 #include <qapplication.h>
77 #include <qvbuttongroup.h>
78 #include <qpixmap.h>
79 #include <qmessagebox.h>
80 #include <qwidget.h>
81 #include <stdio.h>
82 #include <qpopupmenu.h>
83 #include <qlistview.h>
84 #include <qspinbox.h>
85 #include <qhbox.h>
86 #include <qiconset.h>
87 #include <qfontdialog.h>
88 #include <qlineedit.h>
89 #include <qdatetime.h>
90
91 #if QT_VERSION > 300
92   #include <qlistbox.h>
93   #include <qregexp.h>
94 #endif
95
96 // Open CASCADE Includes
97 #include <OSD_LoadMode.hxx>
98 #include <OSD_Function.hxx>
99 #include <TCollection_AsciiString.hxx>
100
101 static const char* SEPARATOR    = ":";
102
103 extern "C"
104 {
105 # include <string.h>
106 }
107
108 QAD_ResourceMgr* QAD_Desktop::resourceMgr = 0;
109 QPalette*        QAD_Desktop::palette = 0;
110
111
112 /*!
113     Creates the resource manager [ static ]
114 */
115 QAD_ResourceMgr* QAD_Desktop::createResourceManager()
116 {
117   if ( !resourceMgr )
118     resourceMgr = new QAD_ResourceMgr;
119   return resourceMgr;
120 }
121
122 /*!
123     Returns the resource manager [ static ]
124 */
125 QAD_ResourceMgr* QAD_Desktop::getResourceManager()
126 {
127   return resourceMgr;
128 }
129
130
131 /*!
132     Loads the palette from settings [ static ]
133 */
134 QPalette* QAD_Desktop::createPalette()
135 {
136   if ( !palette )
137     palette = new QPalette();
138
139   return palette;
140 }
141
142 /*!
143     Returns the palette [ static ]
144 */
145 QPalette* QAD_Desktop::getPalette()
146 {
147   return palette;
148 }
149
150 /*!
151     Gets window ratio width/heght [ static ]
152 */
153 static double myWindowRatio = 1;
154 static double getWindowRatio()
155 {
156   return myWindowRatio;
157 }
158
159 /*!
160     Sets window ratio width/heght [ static ]
161 */
162 static void setWindowRatio(double aRatio)
163 {
164   myWindowRatio = aRatio;
165 }
166
167 /*!
168     Constructor
169 */
170 QAD_Desktop::QAD_Desktop(SALOME_NamingService* name_service) :
171 QMainWindow(0, 0, WType_TopLevel | WDestructiveClose),
172 myStdToolBar(0),
173 myStatusBar(0),
174 myActiveApp(0),
175 myActiveStudy(0),
176 myCntUntitled(0),
177 myHelpWindow(0),
178 myDefaultTitle( tr("DESK_DEFAULTTITLE") ),
179 myQueryClose( true )
180 {
181   /* Force reading of user config file */
182   QAD_CONFIG->readConfigFile();  
183
184   /* menubar and status bar */
185   myStatusBar = statusBar();
186   myMainMenu = menuBar();
187   myActiveComp = "";
188   myNameService = name_service;
189
190   /* default background icon */
191   QPixmap backgroundicon ( QAD_Desktop::getResourceManager()->loadPixmap( "CLIENT",
192                                                                           tr("ICON_DESK_BACKGROUNDICON") ));
193 //myToolBarAction.setAutoDelete( true );
194
195   /* default icon and title */
196   QPixmap icon ( QAD_Desktop::getResourceManager()->loadPixmap( "CLIENT",
197                                                                 tr("ICON_DESK_DEFAULTICON") ));
198   if ( !icon.isNull() ) {
199     myDefaultIcon = icon;
200     setIcon( myDefaultIcon );
201   }
202   setCaption( myDefaultTitle );
203
204   /* set size as 1/2 of the screen and center it */
205   QWidget* d = QApplication::desktop();
206   resize( 2*d->width()/3, 2*d->height()/3 );
207   QAD_Tools::centerWidget( this, d );
208
209   /* workspace will manage child frames */
210   QHBox* border = new QHBox ( this );
211   border->setFrameStyle ( QFrame::Panel | QFrame::Sunken );
212   setCentralWidget( border );
213   myWorkspace = new QWorkspaceP( border );
214
215   QPalette pal = QAD_Application::getPalette();
216   setPalette(pal);
217   QColorGroup cgA = pal.active();
218   QColorGroup cgI = pal.inactive();
219   QColorGroup cgD = pal.disabled();
220   cgA.setColor( QColorGroup::Background, QColor(192, 192, 192));
221   cgI.setColor( QColorGroup::Background, QColor(192, 192, 192));
222   cgD.setColor( QColorGroup::Background, QColor(192, 192, 192));
223   pal.setActive  ( cgA );
224   pal.setInactive( cgI );
225   pal.setDisabled( cgD );
226   myWorkspace->setPalette( pal );
227   if ( !backgroundicon.isNull() ) {
228     MESSAGE("!!!DESKTOP background icon found!!!");
229     myWorkspace->setPaletteBackgroundPixmap(backgroundicon);
230   }
231
232   /* define standard file commands */
233   createActions();
234
235   /* define operator menus for xml */
236   myOperatorMenus = new QAD_OperatorMenus(this);
237   myXmlHandler = new QAD_XmlHandler();
238
239   /* New catalogue */
240   CORBA::Object_var objVarN = myNameService->Resolve("/Kernel/ModulCatalog");
241   myCatalogue  = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
242
243   SALOME_ModuleCatalog::ListOfIAPP_Affich_var list_composants =
244     myCatalogue->GetComponentIconeList();
245
246
247   QToolBar* tbComponent = new QToolBar( tr("MEN_DESK_COMPONENTTOOLBAR"), this );
248   tbComponent->setCloseMode( QDockWindow::Undocked );
249   addToolBar(tbComponent, tr("MEN_DESK_COMPONENTTOOLBAR"), Bottom, TRUE );
250   setDockEnabled( tbComponent, DockLeft,  false );
251   setDockEnabled( tbComponent, DockRight, false );
252
253   myCombo = new QComboBox( FALSE, tbComponent, "comboBox" );
254   myCombo->setFocusPolicy( NoFocus );
255
256   tbComponent->addSeparator();
257
258   // PG : add ResourceManager to get function findFile !!
259   QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
260
261   for (unsigned int ind = 0; ind < list_composants->length();ind++) {
262     QString resDir;
263
264     /* find component icon */
265     QString iconfile = strdup(list_composants[ind].moduleicone) ;
266     QString modulename = strdup(list_composants[ind].modulename) ;
267     QString moduleusername = strdup(list_composants[ind].moduleusername) ;
268
269     //    MESSAGE ( " MODULE = " << modulename )
270     //    MESSAGE ( " MODULE icon = " << iconfile )
271     //    MESSAGE ( " MODULE username = " << moduleusername )
272
273     if ( mapComponentName.contains( moduleusername ) ) {
274       QMessageBox::warning( this, tr("WRN_WARNING"), QString( moduleusername + " is already associated with " + mapComponentName[moduleusername] + ".\nPlease, change the component username of " + modulename) , tr ("BUT_OK") );
275       continue;
276     }
277     mapComponentName.insert( moduleusername, modulename );
278       
279     resDir = resMgr->findFile(iconfile,modulename) ;
280     if (resDir)
281       {
282         MESSAGE ( "resDir" << resDir )
283         //resDir = QAD_Tools::addSlash(resDir) ;
284         //QPixmap Icone(resDir+iconfile) ;
285         QPixmap Icone( QAD_Tools::addSlash( resDir ) + iconfile );
286         QToolButton * toolb = 
287           new QToolButton( QIconSet( Icone ), moduleusername, QString::null, this, 
288                            SLOT( onButtonActiveComponent () ),tbComponent );
289         toolb->setToggleButton( true );
290         myComponentButton.append(toolb);
291       }
292     else
293       {
294         QString errMsg =  tr("INF_ICON_RESOURCES").arg(iconfile).arg(modulename) +
295           tr("INF_RESOURCES");
296         //QMessageBox::warning( this, tr("WRN_WARNING"), errMsg, tr ("BUT_OK") );
297       }
298
299     if ( !QString(list_composants[ind].modulename).isEmpty() )
300       myCombo->insertItem( strdup(list_composants[ind].moduleusername) );
301
302   }
303
304   myCombo->adjustSize();
305   connect( myCombo, SIGNAL(activated(const QString&)),
306            this, SLOT( onComboActiveComponent(const QString&) ) );
307
308   /* new LifeCycleCORBA client, for Engines */
309   myEnginesLifeCycle = new SALOME_LifeCycleCORBA(name_service);
310   
311   /* VSR 13/01/03 : installing global event filter for the application */
312   qApp->installEventFilter( this );
313
314   /* init pseudo random numbers generator */
315   QTime cTime = QTime::currentTime();
316   int secs = cTime.second() + 1;
317   for ( int s = 0; s < secs; s++ ) random();
318 }
319
320 /*!
321     Destructor
322 */
323 QAD_Desktop::~QAD_Desktop ()
324 {
325   qApp->removeEventFilter( this );
326   myFilePopup.clear();
327   myEditPopup.clear();
328   myViewPopup.clear();
329   myObjBrowserPopup.clear();
330   //VRV: T2.5 - add default viewer
331   myDefaultViewer.clear();
332   //VRV: T2.5 - add default viewer
333   myViewerPopup.clear();
334   //NRI : SAL2214
335   myNewViewPopup.clear();
336   //NRI : SAL2214
337   myToolsPopup.clear();
338   myPrefPopup.clear();
339   myStdActions.clear();
340   myHelpPopup.clear();
341   myToolBarsPopup.clear();
342   myToolBarAction.clear();
343   myApps.clear();
344   delete resourceMgr;
345   if (myHelpWindow)
346     myHelpWindow->close();
347   resourceMgr = 0;
348   QAD_Application::desktop = 0;
349 }
350
351 const int IdCut       = 1001;
352 const int IdCopy      = 1002;
353 const int IdPaste     = 1003;
354 const int IdSelectAll = 1004;
355 #ifndef QT_NO_ACCEL
356 #include <qkeysequence.h>
357 #define ACCEL_KEY(k) "\t" + QString(QKeySequence( Qt::CTRL | Qt::Key_ ## k ))
358 #else
359 #define ACCEL_KEY(k) "\t" + QString("Ctrl+" #k)
360 #endif
361 #include <qclipboard.h>
362 /*!
363   Global event filter for qapplication (VSR 13/01/03)
364 */
365 bool QAD_Desktop::eventFilter( QObject* o, QEvent* e )
366 {
367   if ( e->type() == QEvent::ContextMenu ) {
368     QContextMenuEvent* ce = (QContextMenuEvent*)e;
369     if ( o->inherits("QRenameEdit") ) {
370       return TRUE;
371     }
372     else if ( o->inherits("QLineEdit") ) {
373       QLineEdit* le = (QLineEdit*)o;
374       if ( le->parentWidget() ) {
375         if ( ( le->parentWidget()->inherits("QSpinBox") || 
376                le->parentWidget()->inherits("QSpinWidget") ||
377                le->parentWidget()->inherits("QAD_SpinBoxDbl") ) &&
378              le->isEnabled() ) {
379           QPopupMenu* popup = new QPopupMenu( 0, "qt_edit_menu" );
380           popup->insertItem( tr( "EDIT_CUT_CMD" ) + ACCEL_KEY( X ), IdCut );
381           popup->insertItem( tr( "EDIT_COPY_CMD" ) + ACCEL_KEY( C ), IdCopy );
382           popup->insertItem( tr( "EDIT_PASTE_CMD" ) + ACCEL_KEY( V ), IdPaste );
383           popup->insertSeparator();
384 #if defined(Q_WS_X11)
385           popup->insertItem( tr( "EDIT_SELECTALL_CMD" ), IdSelectAll );
386 #else
387           popup->insertItem( tr( "EDIT_SELECTALL_CMD" ) + ACCEL_KEY( A ), IdSelectAll );
388 #endif
389           bool enableCut = !le->isReadOnly() && le->hasSelectedText();
390           popup->setItemEnabled( IdCut, enableCut );
391           popup->setItemEnabled( IdCopy, le->hasSelectedText() );
392           bool enablePaste = !le->isReadOnly() && !QApplication::clipboard()->text().isEmpty();
393           popup->setItemEnabled( IdPaste, enablePaste );
394           bool allSelected = (le->selectedText() == le->text() );
395           popup->setItemEnabled( IdSelectAll, (bool)(le->text().length()) && !allSelected );
396
397           QPoint pos = ce->reason() == QContextMenuEvent::Mouse ? ce->globalPos() :
398             le->mapToGlobal( QPoint(ce->pos().x(), 0) ) + QPoint( le->width() / 2, le->height() / 2 );
399           if ( popup ) {
400             int r = popup->exec( pos );
401             switch ( r ) {
402             case IdCut:
403               le->cut();
404               break;
405             case IdCopy:
406               le->copy();
407               break;
408             case IdPaste:
409               le->paste();
410               break;
411             case IdSelectAll:
412               le->selectAll();
413               break;
414             }
415             delete popup;
416           }
417           return TRUE;
418         }
419       }
420     }
421   }
422   return QMainWindow::eventFilter( o, e );
423 }
424
425 /*!
426     Creates and initializes the standard file operations
427     such as 'New/Open/Save/SaveAs/Close' and 'Help'.
428 */
429 void QAD_Desktop::createActions()
430 {
431
432   /* Used for string compare */
433   const QString& aTrueQString = "true" ;
434   
435   /* create 'standard' toolbar */
436   if ( !myStdToolBar ) {
437         myStdToolBar = new QToolBar ( tr("MEN_DESK_VIEW_STDTOOLBAR"), this );
438         myStdToolBar->setCloseMode( QDockWindow::Undocked );
439   }
440
441   if ( !myMainMenu->count() ) {
442     /* Create main menu bar */
443     myMainMenu->insertItem ( tr("MEN_DESK_FILE"),   &myFilePopup, 1 );  /* add popup FILE */
444     myMainMenu->insertItem ( tr("MEN_DESK_VIEW"),   &myViewPopup, 2 );  /* add popup VIEW */
445     myMainMenu->insertItem ( tr("MEN_DESK_TOOLS"),  &myToolsPopup, 5 ); /* add popup TOOLS */
446     myMainMenu->insertItem ( tr("MEN_DESK_PREF"),   &myPrefPopup, 4 );  /* add popup PREF */
447     myMainMenu->insertItem ( tr("MEN_DESK_WINDOW"), &myWindowPopup, 6 );        /* add popup WINDOW */
448     myMainMenu->insertItem ( tr("MEN_DESK_HELP"),   &myHelpPopup, 7 );  /* add popup HELP */
449
450     /*  Applications will insert their items after 'File' 'Edit' and 'View'
451         ( 'Edit' will be inserted later )
452     */
453     myMainMenuPos = 3;
454   }
455   
456   /* insert logo picture to menu bar */
457   QHBox* aLogoFrm = new QHBox(this);
458   aLogoFrm->setFrameStyle( QFrame::Plain | QFrame::NoFrame );
459   QPixmap aLogoPixmap ( QAD_Desktop::getResourceManager()->loadPixmap( "CLIENT",
460                                                                        tr("ICON_DESK_LOGO") ));
461   QLabel* aLogoLab = new QLabel(aLogoFrm);
462   aLogoLab->setPixmap(aLogoPixmap);
463   aLogoLab->setAlignment(AlignCenter);
464   aLogoLab->setScaledContents(false);
465   myMainMenu->insertItem(aLogoFrm);
466
467   if ( myStdActions.isEmpty() ) {
468     /*  Define standard actions. They should be inserted
469         into the list in order of their IDs.
470     */
471
472     /*  'File' actions */
473     /* new */
474     QAD_ResourceMgr* rmgr = QAD_Desktop::getResourceManager();
475     QActionP* fileNewAction = new QActionP ( tr("TOT_DESK_FILE_NEW"),
476                                            rmgr->loadPixmap( "QAD", tr("ICON_FILE_NEW") ) ,
477                                            tr("MEN_DESK_FILE_NEW"), CTRL+Key_N, this );
478     fileNewAction->setStatusTip ( tr("PRP_DESK_FILE_NEW") );
479     fileNewAction->setEnabled ( true );
480     QAD_ASSERT ( connect( fileNewAction, SIGNAL( activated() ), this, SLOT( onNewStudy() )));
481     fileNewAction->addTo( myStdToolBar );
482     fileNewAction->addTo( &myFilePopup );
483     myStdActions.insert ( FileNewId, fileNewAction );
484
485     /* open */
486     QActionP* fileOpenAction = new QActionP( tr("TOT_DESK_FILE_OPEN"), rmgr->loadPixmap( "QAD", tr("ICON_FILE_OPEN") ),
487                                            tr("MEN_DESK_FILE_OPEN"), CTRL+Key_O, this );
488     fileOpenAction->setStatusTip ( tr("PRP_DESK_FILE_OPEN") );
489     fileOpenAction->setEnabled ( true );
490     QAD_ASSERT ( connect( fileOpenAction, SIGNAL( activated() ), this, SLOT( onOpenStudy() )));
491     fileOpenAction->addTo( myStdToolBar );
492     fileOpenAction->addTo( &myFilePopup );
493     myStdActions.insert ( FileOpenId, fileOpenAction );
494
495     /* load */
496     QActionP* fileLoadAction = new QActionP( tr("TOT_DESK_FILE_LOAD"), rmgr->loadPixmap( "QAD", tr("ICON_FILE_LOAD") ),
497                                            tr("MEN_DESK_FILE_LOAD"), CTRL+Key_L, this );
498     fileLoadAction->setStatusTip ( tr("PRP_DESK_FILE_LOAD") );
499     fileLoadAction->setEnabled ( true );
500     QAD_ASSERT ( connect( fileLoadAction, SIGNAL( activated() ), this, SLOT( onLoadStudy() )));
501     fileLoadAction->addTo( &myFilePopup );
502     myStdActions.insert ( FileLoadId, fileLoadAction );
503
504     /* close */
505     QActionP* fileCloseAction = new QActionP( "", rmgr->loadPixmap( "QAD", tr("ICON_FILE_CLOSE") ),
506                                             tr("MEN_DESK_FILE_CLOSE"), CTRL+Key_W, this );
507     fileCloseAction->setStatusTip ( tr("PRP_DESK_FILE_CLOSE") );
508     QAD_ASSERT ( connect( fileCloseAction, SIGNAL( activated() ), this, SLOT( onCloseStudy() )));
509     fileCloseAction->addTo( &myFilePopup );
510     myStdActions.insert ( FileCloseId, fileCloseAction );
511
512     /* separator */
513     myFilePopup.insertSeparator();
514
515     /* save */
516     QActionP* fileSaveAction = new QActionP( tr("TOT_DESK_FILE_SAVE"), rmgr->loadPixmap( "QAD", tr("ICON_FILE_SAVE") ),
517                                            tr("MEN_DESK_FILE_SAVE"), CTRL+Key_S, this );
518     fileSaveAction->setStatusTip ( tr("PRP_DESK_FILE_SAVE") );
519     QAD_ASSERT ( connect( fileSaveAction, SIGNAL( activated() ), this, SLOT( onSaveStudy() )));
520     fileSaveAction->addTo( myStdToolBar );
521     fileSaveAction->addTo( &myFilePopup );
522     myStdActions.insert ( FileSaveId, fileSaveAction );
523
524     /* save as */
525     QActionP* fileSaveAsAction = new QActionP( "", tr("MEN_DESK_FILE_SAVEAS"), 0, this );
526     fileSaveAsAction->setStatusTip ( tr("PRP_DESK_FILE_SAVEAS") );
527     QAD_ASSERT ( connect( fileSaveAsAction, SIGNAL( activated() ),
528                           this, SLOT( onSaveAsStudy() )));
529     fileSaveAsAction->addTo( &myFilePopup );
530     myStdActions.insert ( FileSaveAsId, fileSaveAsAction );
531
532     
533     /* separator */
534     myFilePopup.insertSeparator();
535
536     // Study properties
537     QActionP* filePropsAction = new QActionP( "", QPixmap(), tr("MEN_DESK_FILE_PROPERTIES"), 0, this );
538     filePropsAction->setStatusTip ( tr("PRP_DESK_FILE_PROPERTIES") );
539     filePropsAction->setEnabled(false);
540     QAD_ASSERT ( connect( filePropsAction, SIGNAL( activated() ), this, SLOT( onStudyProperties() )));
541     filePropsAction->addTo( &myFilePopup );
542     myStdActions.insert ( FilePropsId, filePropsAction );
543
544
545     int id = myFilePopup.insertSeparator();
546     /*  keep the position from which an application will insert its items
547         to menu 'File' at the time of customization of the desktop */
548
549     myFilePos = myFilePopup.indexOf( id ) + 1;
550
551     /* exit application */
552     QActionP* exitAction = new QActionP( "", tr("MEN_DESK_FILE_EXIT"),
553                                        CTRL+Key_X, this );
554     exitAction->setStatusTip ( tr("PRP_DESK_FILE_EXIT") );
555     QAD_ASSERT ( connect( exitAction, SIGNAL( activated() ),
556                           this, SLOT( onExit() )));
557     exitAction->addTo( &myFilePopup );
558     myStdActions.insert ( FileExitId, exitAction );
559  
560     /* 'Edit' actions : provided by application only */
561     myEditPos = 0;
562
563     /* 'View' actions */
564     /* toolbars popup menu */
565     myViewPopup.insertItem( tr("MEN_DESK_VIEW_TOOLBARS"), &myToolBarsPopup );
566     QAD_ASSERT( connect ( &myViewPopup, SIGNAL(aboutToShow()),
567                           this, SLOT(onToolBarPopupAboutToShow()) ));
568
569     /*  status bar */
570     QActionP* viewStatusBarAction = new QActionP( "",
571                                                 tr("MEN_DESK_VIEW_STATUSBAR"),
572                                                 0, this, 0, true );
573     viewStatusBarAction->setStatusTip ( tr("PRP_DESK_VIEW_STATUSBAR") );
574     viewStatusBarAction->setOn( true );
575     QAD_ASSERT(connect( viewStatusBarAction, SIGNAL(activated()), this, SLOT(onViewStatusBar() )));
576     viewStatusBarAction->addTo( &myViewPopup );
577     myStdActions.insert( ViewStatusBarId, viewStatusBarAction );
578
579 //    myViewPopup.insertItem( tr("MEN_DESK_SELECTION_MODE"), &mySelectionModePopup );
580
581     QActionP* SelectionPointAction = new QActionP( "", tr("MEN_DESK_SELECTION_POINT"), 0, this, 0, true  );
582     QAD_ASSERT(connect( SelectionPointAction, SIGNAL(activated()), this, SLOT(onSelectionMode() )));
583     SelectionPointAction->addTo( &mySelectionModePopup );
584     myStdActions.insert( SelectionPointId, SelectionPointAction );
585
586     QActionP* SelectionEdgeAction = new QActionP( "", tr("MEN_DESK_SELECTION_EDGE"), 0, this, 0, true  );
587     QAD_ASSERT(connect( SelectionEdgeAction, SIGNAL(activated()), this, SLOT(onSelectionMode() )));
588     SelectionEdgeAction->addTo( &mySelectionModePopup );
589     myStdActions.insert( SelectionEdgeId, SelectionEdgeAction );
590
591     QActionP* SelectionCellAction = new QActionP( "", tr("MEN_DESK_SELECTION_CELL"), 0, this, 0, true  );
592     QAD_ASSERT(connect( SelectionCellAction, SIGNAL(activated()), this, SLOT(onSelectionMode() )));
593     SelectionCellAction->addTo( &mySelectionModePopup );
594     myStdActions.insert( SelectionCellId, SelectionCellAction );
595
596     QActionP* SelectionActorAction = new QActionP( "", tr("MEN_DESK_SELECTION_ACTOR"), 0, this, 0, true );
597     QAD_ASSERT(connect( SelectionActorAction, SIGNAL(activated()), this, SLOT(onSelectionMode() )));
598     SelectionActorAction->addTo( &mySelectionModePopup );
599     myStdActions.insert( SelectionActorId, SelectionActorAction );
600     SelectionActorAction->setOn(true);
601
602     myViewPos = myViewPopup.count();
603
604     /* Parse xml file */
605     QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
606     if ( resMgr ) {
607       QString msg;
608       if(!resMgr->loadResources( "ToolsGUI", msg ))
609         {
610           //NRI     QCString errMsg;
611           //        errMsg.sprintf( "Do not load all resources for module ToolsGUI.\n" );
612           QMessageBox::warning( this, tr("WRN_WARNING"), msg, tr ("BUT_OK") );
613         }
614     }
615     
616     myOperatorMenus = new QAD_OperatorMenus(this);
617     myXmlHandler = new QAD_XmlHandler();
618     ASSERT(myXmlHandler) ;
619     myXmlHandler->setMainWindow(this);
620     if ( myXmlHandler->setComponent( resMgr->resources( "ToolsGUI" ) ) ) {
621       QString language = resMgr->language( "ToolsGUI" );
622       QString ToolsXml = QString( "Tools_" ) + language + QString( ".xml" );
623
624       //ToolsXml = resMgr->resources("ToolsGUI") ;
625       //ToolsXml = QAD_Tools::addSlash(ToolsXml) ;
626       //ToolsXml = ToolsXml + "Tools_" + language + ".xml" ;
627       ToolsXml = QAD_Tools::addSlash( resMgr->findFile( ToolsXml, "ToolsGUI" ) ) + ToolsXml;
628
629       QFile file( QAD_Tools::unix2win( ToolsXml ) );
630       if ( file.exists() && file.open( IO_ReadOnly ) )  {
631         file.close();
632         QXmlInputSource source( file );
633         QXmlSimpleReader reader;
634         reader.setContentHandler( myXmlHandler );
635         reader.setErrorHandler( myXmlHandler );
636         bool ok = reader.parse( source );
637         file.close();
638         if ( !ok ) {
639           QMessageBox::critical( 0,
640                                  tr( "INF_PARSE_ERROR" ),
641                                  tr( myXmlHandler->errorProtocol() ) );
642         } else {
643           myMenusList=myXmlHandler->myMenusList;
644           myActiveMenus=myMenusList.at(0);
645           myOperatorMenus->showMenuBar(0);
646           myActiveMenus->showAllToolBars();
647         }
648       }
649     }
650     //  }
651
652     if ( myToolsPopup.count() == 0 ) {
653       myMainMenu->removeItem(5);
654     }
655
656     /* 'Pref' actions  */
657     /* Viewer BackgroundColor */
658     myPrefPopup.insertItem( tr("MEN_DESK_PREF_VIEWER"), &myViewerPopup );
659     
660     QActionP* viewerOCCAction = new QActionP( "", tr("MEN_DESK_PREF_VIEWER_OCC"), 0, this );
661     QAD_ASSERT(connect( viewerOCCAction, SIGNAL(activated()), this, SLOT(onViewerOCC() )));
662     viewerOCCAction->addTo( &myViewerPopup );
663     myStdActions.insert( PrefViewerOCCId, viewerOCCAction );
664
665     QActionP* viewerVTKAction = new QActionP( "", tr("MEN_DESK_PREF_VIEWER_VTK"), 0, this );
666     QAD_ASSERT(connect( viewerVTKAction, SIGNAL(activated()), this, SLOT(onViewerVTK() )));
667     viewerVTKAction->addTo( &myViewerPopup );
668     myStdActions.insert( PrefViewerVTKId, viewerVTKAction );
669
670     QActionP* graphSupervisorAction = new QActionP( "", tr("MEN_DESK_PREF_GRAPH_SUPERVISOR"), 0, this );
671     QAD_ASSERT(connect( graphSupervisorAction, SIGNAL(activated()), this, SLOT(onGraphSupervisor() )));
672     graphSupervisorAction->addTo( &myViewerPopup );
673     myStdActions.insert( PrefGraphSupervisorId, graphSupervisorAction );
674
675     QActionP* viewerPlot2dAction = new QActionP( "", tr("MEN_DESK_PREF_VIEWER_PLOT2D"), 0, this );
676     QAD_ASSERT(connect( viewerPlot2dAction, SIGNAL(activated()), this, SLOT(onPlot2d() )));
677     viewerPlot2dAction->addTo( &myViewerPopup );
678     myStdActions.insert( PrefViewerPlot2dId, viewerPlot2dAction );
679
680     //VRV: T2.5 - add default viewer
681     QString viewerValue = QAD_CONFIG->getSetting( "Viewer:DefaultViewer" );
682     bool ok;
683     int aViewerValue = viewerValue.toInt( &ok, 10 ); 
684     if (!ok || aViewerValue < VIEW_OCC || aViewerValue >= VIEW_TYPE_MAX)
685       aViewerValue = VIEW_VTK;
686
687     myPrefPopup.insertItem( tr("MEN_DESK_PREF_DEFAULT_VIEWER"), &myDefaultViewer );
688     QActionPGroup* myQAG = new QActionPGroup ( this);
689     QActionP* viewerOCCAction1 = new QActionP( "", tr("MEN_DESK_PREF_VIEWER_OCC"), 0, this );
690     viewerOCCAction1->setToggleAction ( true);
691     viewerOCCAction1->setOn ( aViewerValue == VIEW_OCC );
692     myQAG->insert( viewerOCCAction1 );
693     myStdActions.insert( DefaultViewerOCCId, viewerOCCAction1 );
694
695     QActionP* viewerVTKAction1 = new QActionP( "", tr("MEN_DESK_PREF_VIEWER_VTK"), 0, this );
696     viewerVTKAction1->setToggleAction ( true);
697     viewerVTKAction1->setOn ( aViewerValue == VIEW_VTK );
698     myQAG->insert( viewerVTKAction1 );
699     myStdActions.insert( DefaultViewerVTKId, viewerVTKAction1 );
700
701 /*    Remove Supervisor viewer from setting the background */
702 //    QActionP* graphSupervisorAction1 = new QActionP( "", tr("MEN_DESK_PREF_GRAPH_SUPERVISOR"), 0, this );
703 //    graphSupervisorAction1->setToggleAction ( true);
704 //    graphSupervisorAction1->setOn ( aViewerValue == VIEW_GRAPHSUPERV );
705 //    myQAG->insert( graphSupervisorAction1 );
706 //    myStdActions.insert( DefaultGraphSupervisorId, graphSupervisorAction1 );
707
708     QActionP* viewerPlot2dAction1 = new QActionP( "", tr("MEN_DESK_PREF_VIEWER_PLOT2D"), 0, this );
709     viewerPlot2dAction1->setToggleAction ( true);
710     viewerPlot2dAction1->setOn ( aViewerValue == VIEW_PLOT2D );
711     myQAG->insert( viewerPlot2dAction1 );
712     myStdActions.insert( DefaultPlot2dId, viewerPlot2dAction1 );
713
714     myQAG->addTo( &myDefaultViewer );
715     QAD_ASSERT(connect( myQAG, SIGNAL(selected(QActionP * )), this, SLOT(onDefaultViewer(QActionP *) )));
716     //VRV: T2.5 - add default viewer
717
718     QActionP* viewerTrihedronAction = new QActionP( "", tr("MEN_DESK_PREF_VIEWER_TRIHEDRON"), 0, this );
719     QAD_ASSERT(connect( viewerTrihedronAction, SIGNAL(activated()), this, SLOT(onViewerTrihedron() )));
720     viewerTrihedronAction->addTo( &myPrefPopup );
721     myStdActions.insert( PrefViewerTrihedronId, viewerTrihedronAction );
722
723     QActionP* consoleFontAction = new QActionP( "", tr("MEN_DESK_PREF_CONSOLE_FONT"), 0, this );
724     QAD_ASSERT(connect( consoleFontAction, SIGNAL(activated()), this, SLOT(onConsoleFontAction() )));
725     consoleFontAction->addTo( &myPrefPopup );
726     myStdActions.insert( PrefConsoleFontId, consoleFontAction );
727
728     /* MultiFile save */
729     QActionP* multiFileSaveAction = new QActionP( "", tr("MEN_DESK_PREF_MULTI_FILE_SAVE"), 0, this, 0, true );
730     QAD_ASSERT(connect( multiFileSaveAction, SIGNAL(activated()), this, SLOT(onMultiFileSave() )));
731     multiFileSaveAction->setToggleAction( true );
732     QString MultiSave = QAD_CONFIG->getSetting("Desktop:MultiFileSave");
733     multiFileSaveAction->setOn( MultiSave.compare( aTrueQString ) == 0 );
734     multiFileSaveAction->addTo( &myPrefPopup );
735     myStdActions.insert( PrefMultiFileSave, multiFileSaveAction );
736
737     /* ASCII save */
738     QActionP* ASCIISaveAction = new QActionP( "", tr("MEN_DESK_PREF_ASCII_SAVE"), 0, this, 0, true );
739     QAD_ASSERT(connect( ASCIISaveAction, SIGNAL(activated()), this, SLOT(onASCIISave() )));
740     ASCIISaveAction->setToggleAction( true );
741     QString ASCIISave = QAD_CONFIG->getSetting("Desktop:ASCIISave");
742     ASCIISaveAction->setOn( ASCIISave.compare( aTrueQString ) == 0 );
743     ASCIISaveAction->addTo( &myPrefPopup );
744     myStdActions.insert( PrefASCIISave, ASCIISaveAction );
745
746     myPrefPopup.insertSeparator();
747     
748     /* BrowserPopup */
749     myPrefPopup.insertItem( tr("MEN_DESK_PREF_OBJECTBROWSER"), &myObjBrowserPopup );
750     
751     QActionP* objectBrowserEntryAction = new QActionP( "", tr("MEN_DESK_PREF_OBJECTBROWSER_ENTRY"), 0, this, 0, true );
752     QAD_ASSERT(connect( objectBrowserEntryAction, SIGNAL(activated()), this, SLOT(onObjectBrowser() )));
753     objectBrowserEntryAction->setToggleAction(true);
754     QString AddColumn = QAD_CONFIG->getSetting("ObjectBrowser:AddColumn");
755     
756     if ( AddColumn.compare( aTrueQString ) == 0 )
757       objectBrowserEntryAction->setOn(true);
758     else
759       objectBrowserEntryAction->setOn(false);
760
761     objectBrowserEntryAction->addTo( &myObjBrowserPopup );
762     myStdActions.insert( PrefObjectBrowserEntryId, objectBrowserEntryAction );
763
764     QActionP* objectBrowserValueAction = new QActionP( "", tr("MEN_DESK_PREF_OBJECTBROWSER_VALUE"), 0, this, 0, true );
765     QAD_ASSERT(connect( objectBrowserValueAction, SIGNAL(activated()), this, SLOT(onObjectBrowser() )));
766     objectBrowserValueAction->setToggleAction(true);
767     QString ValueColumn = QAD_CONFIG->getSetting("ObjectBrowser:ValueColumn");
768     
769     if ( ValueColumn.compare( aTrueQString ) == 0 )
770       objectBrowserValueAction->setOn(true);
771     else
772       objectBrowserValueAction->setOn(false);
773
774     objectBrowserValueAction->addTo( &myObjBrowserPopup );
775     myStdActions.insert( PrefObjectBrowserValueId, objectBrowserValueAction );
776
777     QActionP* objectBrowserIAPPAction = new QActionP( "", tr("MEN_DESK_PREF_OBJECTBROWSER_IAPP"), 0, this, 0, true );
778     QAD_ASSERT(connect( objectBrowserIAPPAction, SIGNAL(activated()), this, SLOT(onObjectBrowser() )));
779     objectBrowserIAPPAction->setToggleAction(true);
780     QString showIAPP = QAD_CONFIG->getSetting("ObjectBrowser:IAPP");
781
782     if ( showIAPP.compare( aTrueQString ) == 0 )
783       objectBrowserIAPPAction->setOn(true);
784     else
785       objectBrowserIAPPAction->setOn(false);
786
787     objectBrowserIAPPAction->addTo( &myObjBrowserPopup );
788     myStdActions.insert( PrefObjectBrowserIAPPId, objectBrowserIAPPAction );
789     
790     /* Chronological sorting of shapes on the entry creation */
791     QActionP* objectBrowserCHRONO_SORTAction = new QActionP( "", tr("MEN_DESK_PREF_OBJECTBROWSER_CHRONO_SORT"), 0, this, 0, true );
792     QAD_ASSERT(connect( objectBrowserCHRONO_SORTAction, SIGNAL(activated()), this, SLOT(onObjectBrowser() )));
793     objectBrowserCHRONO_SORTAction->setToggleAction(true);
794     QString showSORT = QAD_CONFIG->getSetting("ObjectBrowser:CHRONO_SORT");
795     
796     if ( showSORT.compare( aTrueQString ) == 0 )
797       objectBrowserCHRONO_SORTAction->setOn(true) ;
798     else
799       objectBrowserCHRONO_SORTAction->setOn(false) ;
800
801     objectBrowserCHRONO_SORTAction->addTo( &myObjBrowserPopup );
802     myStdActions.insert( PrefObjectBrowserCHRONO_SORTId, objectBrowserCHRONO_SORTAction ) ;
803     
804     myPrefPopup.insertSeparator();
805
806     QActionP* dirAction = new QActionP( "", tr("MEN_DESK_PREF_DIRICTORIES"), ALT+Key_D, this );
807     QAD_ASSERT(connect( dirAction, SIGNAL(activated()), this, SLOT(onDirList() )));
808     dirAction->addTo( &myPrefPopup );
809     myStdActions.insert( PrefDirsId, dirAction );
810     
811     myPrefPopup.insertSeparator();
812
813     QActionP* saveAction = new QActionP( "", tr("MEN_DESK_PREF_SAVE"), 0, this );
814     QAD_ASSERT(connect( saveAction, SIGNAL(activated()), this, SLOT(onSavePref() )));
815     saveAction->addTo( &myPrefPopup );
816     myStdActions.insert( PrefSaveId, saveAction );
817
818     /* 'Window' actions  */
819     /*  new Window 3D    */
820     //NRI : SAL2214
821     myWindowPopup.insertItem( tr("MEN_DESK_WINDOW_NEW3D"), &myNewViewPopup, WindowNew3dId );
822     
823     QActionP* viewOCCAction = new QActionP( "", tr("MEN_DESK_VIEW_OCC"), ALT+Key_O, this );
824     QAD_ASSERT(connect( viewOCCAction, SIGNAL(activated()), this, SLOT(onNewWindow3d() )));
825     viewOCCAction->addTo( &myNewViewPopup );
826     myStdActions.insert( ViewOCCId, viewOCCAction );
827
828     QActionP* viewVTKAction = new QActionP( "", tr("MEN_DESK_VIEW_VTK"), ALT+Key_K, this );
829     QAD_ASSERT(connect( viewVTKAction, SIGNAL(activated()), this, SLOT(onNewWindow3d() )));
830     viewVTKAction->addTo( &myNewViewPopup );
831     myStdActions.insert( ViewVTKId, viewVTKAction );
832
833     QActionP* viewPlot2dAction = new QActionP( "", tr("MEN_DESK_VIEW_PLOT2D"), ALT+Key_P, this );
834     QAD_ASSERT(connect( viewPlot2dAction, SIGNAL(activated()), this, SLOT(onNewWindow3d() )));
835     viewPlot2dAction->addTo( &myNewViewPopup );
836     myStdActions.insert( ViewPlot2dId, viewPlot2dAction );
837     
838     //  QActionP* windowNew3dAction = new QActionP( "",/* rmgr->loadPixmap( "QAD", tr("ICON_DESK_WINDOW_NEW3D") ), */
839     /*tr("MEN_DESK_WINDOW_NEW3D"), 0, this );
840       windowNew3dAction->addTo( &myWindowPopup );
841       QAD_ASSERT( connect( windowNew3dAction, SIGNAL(activated()), this ,
842       SLOT( onNewWindow3d() )));
843       myStdActions.insert( WindowNew3dId, windowNew3dAction );
844     */
845  
846     //NRI : SAL2214
847
848     /* cascaded */
849     QActionP* windowCascadeAction = new QActionP( "", rmgr->loadPixmap( "QAD", tr("ICON_DESK_WINDOW_CASCADE") ),
850                                                 tr("MEN_DESK_WINDOW_CASCADE"), 0, this );
851     windowCascadeAction->setStatusTip ( tr("PRP_DESK_WINDOW_CASCADE") );
852     QAD_ASSERT( connect( windowCascadeAction, SIGNAL(activated()), this,
853                          SLOT( onCascade() )));
854     myStdActions.insert( WindowCascadeId, windowCascadeAction );
855
856     /* tiled */
857     QActionP* windowTileAction = new QActionP( "", rmgr->loadPixmap( "QAD", tr("ICON_DESK_WINDOW_TILE") ),
858                                              tr("MEN_DESK_WINDOW_TILE"), 0, this );
859     windowTileAction->setStatusTip ( tr("PRP_DESK_WINDOW_TILE") );
860     QAD_ASSERT( connect( windowTileAction, SIGNAL(activated()), myWorkspace, SLOT( tile() )));
861     myStdActions.insert( WindowTileId, windowTileAction );
862
863     QAD_ASSERT( connect ( &myWindowPopup, SIGNAL(aboutToShow()),
864                           this, SLOT(onWindowPopupAboutToShow()) ));
865     /* 'Help' actions
866      */
867     /* contents */
868     QActionP* helpContentsAction = new QActionP( "", tr("MEN_DESK_HELP_CONTENTS"), Key_F1, this );
869     helpContentsAction->setStatusTip ( tr("PRP_DESK_HELP_CONTENTS") );
870     QAD_ASSERT(connect( helpContentsAction, SIGNAL(activated()),
871                         this, SLOT( onHelpContents() )));
872     helpContentsAction->addTo( &myHelpPopup );
873     myStdActions.insert( HelpContentsId , helpContentsAction );
874
875     /* search */
876 //    QActionP* helpSearchAction = new QActionP( "", tr("MEN_DESK_HELP_SEARCH"), 0, this );
877 //    helpSearchAction->setStatusTip ( tr("PRP_DESK_HELP_SEARCH") );
878 //    QAD_ASSERT( connect( helpSearchAction, SIGNAL(activated()), this, SLOT( onHelpSearch() )));
879 //    helpSearchAction->addTo( &myHelpPopup );
880 //    myStdActions.insert( HelpSearchId, helpSearchAction );
881
882     /* What's This */
883 //    QActionP* helpWhatsThisAction = new QActionP( "", tr("MEN_DESK_HELP_WHATSTHIS"), SHIFT+Key_F1, this );
884 //    helpWhatsThisAction->setStatusTip ( tr("PRP_DESK_HELP_WHATSTHIS" ));
885 //    QAD_ASSERT( connect( helpWhatsThisAction, SIGNAL(activated()), this, SLOT( whatsThis() )));
886 //    helpWhatsThisAction->addTo( &myHelpPopup );
887 //    myStdActions.insert( HelpWhatsThisId, helpWhatsThisAction );
888 //    (void)QWhatsThis::whatsThisButton( myStdToolBar );
889
890     id = myHelpPopup.insertSeparator();
891     myHelpPos = myHelpPopup.indexOf( id );
892
893     /* about */
894     QActionP* helpAboutAction = new QActionP( "", tr("MEN_DESK_HELP_ABOUT"), 0, this );
895     helpAboutAction->setStatusTip ( tr("PRP_DESK_HELP_ABOUT") );
896     QAD_ASSERT( connect( helpAboutAction, SIGNAL(activated()), this, SLOT( onHelpAbout() )));
897     helpAboutAction->addTo( &myHelpPopup );
898     myStdActions.insert(HelpAboutId, helpAboutAction );
899   }
900   updateActions();
901 }
902
903 /*!
904     Adds the given application into the list of supported applications
905 */
906 void QAD_Desktop::addApplication(QAD_Application* app)
907 {
908   /* add only if is not already in the list */
909   if ( myApps.findRef( app ) == -1 )
910     {
911       myApps.append( app );
912
913       /* set activation/deactivation listener */
914       QAD_ASSERT ( connect( app, SIGNAL(appActivated(QAD_Application*)),
915                             this, SLOT(onActivateApp(QAD_Application*))) );
916
917       QAD_ASSERT ( connect( app, SIGNAL(appDeactivated(QAD_Application*)),
918                             this, SLOT(onDeactivateApp(QAD_Application*))) );
919     }
920 }
921
922 /*!
923     Displays the control panel of the application.
924     This function is called when the desktop is shown first time.
925 */
926 void QAD_Desktop::showDesktop()
927 {
928   show();
929 }
930
931 /*!
932   Closes Desktop. If <forceClose> is true query for exit will be skipped.
933 */
934 void QAD_Desktop::closeDesktop( bool forceClose )
935 {
936   if ( forceClose)
937     myQueryClose = false;
938   close();
939 }
940
941 /*!
942     Puts the message to the status bar
943 */
944 void QAD_Desktop::putInfo ( const QString& msg )
945 {
946   if ( myStatusBar )
947     //NRI : bug 1209. message is now displayed during 3000 ms
948     myStatusBar->message ( msg, 3000 );
949 }
950
951 /*!
952     Puts the message to the status bar for ms milli-seconds
953 */
954 void QAD_Desktop::putInfo ( const QString& msg, int ms )
955 {
956   if ( myStatusBar )
957     myStatusBar->message ( msg, ms );
958 }
959
960 /*!
961     Returns the standard toolbar
962 */
963 QMenuBar* QAD_Desktop::getMainMenuBar() const
964 {
965     return myMainMenu;
966 }
967
968 /*!
969     Returns the standard toolbar
970 */
971 QToolBar* QAD_Desktop::getStdToolBar() const
972 {
973     return myStdToolBar;
974 }
975
976 /*!
977     Updates desktop panel (menu, toolbar and status bar) according to current state of
978     the application. Calls update() for the active application.
979     The command { UD_ADD_APP or UD_REMOVE_APP ) specifies the desktop components
980     will be changed according to new active application.
981     This function is called after activating new study, closing current study etc.
982 */
983 void QAD_Desktop::updateDesktop( UpdateCommand cmd )
984 {
985   updateMenu( cmd );
986   updateToolBars( cmd );
987   updateStatusBar( cmd );
988   updateActions();
989 }
990
991 /*!
992     Updates the desktop caption
993 */
994 void QAD_Desktop::updateCaption( UpdateCommand cmd )
995 {
996     if ( cmd == ActivateApp )
997     {   /* application's icon and title */
998         setIcon( myActiveApp->getApplicationIcon() );
999         setCaption( myActiveApp->getApplicationName() );
1000     }
1001     else
1002     {   /* default icon and title */
1003         setIcon( myDefaultIcon );
1004         setCaption( myDefaultTitle );
1005     }
1006 }
1007
1008 /*!
1009     Updates status bar when a new application becomes current
1010 */
1011 void QAD_Desktop::updateStatusBar( UpdateCommand cmd )
1012 {
1013     if ( myActiveApp )
1014     {
1015         bool activate = ( cmd == ActivateApp );
1016         myActiveApp->updateStatusBar ( myStatusBar, activate );
1017     }
1018 }
1019
1020 /*!
1021     Updates toolbars according to current active application.
1022     This function is called from updateDesktop().
1023 */
1024 void QAD_Desktop::updateToolBars( UpdateCommand cmd )
1025 {
1026     if ( myActiveApp )
1027     {
1028         bool activate = ( cmd == ActivateApp );
1029         myActiveApp->updateToolBars ( activate );
1030     }
1031 }
1032
1033 /*!
1034     Updates main menu bar of the application when application is activated
1035     or deactivated.
1036     This function is called by updateDesktop()
1037 */
1038 void QAD_Desktop::updateMenu( UpdateCommand cmd )
1039 {
1040     if ( myActiveApp )
1041     {
1042         bool activate = ( cmd == ActivateApp );
1043         myActiveApp->updateFilePopup( &myFilePopup, activate, myFilePos );
1044         myActiveApp->updateEditPopup( &myEditPopup, activate, myEditPos );
1045         myActiveApp->updateViewPopup( &myViewPopup, activate, myViewPos );
1046         myActiveApp->updateHelpPopup( &myHelpPopup, activate, myHelpPos );
1047         myActiveApp->updateMainMenu( myMainMenu, activate, myMainMenuPos );
1048
1049         /*  NOTE:
1050             Since 'Edit' popup is completely customized by applications
1051             desktop doesn't show it in main menubar without the active
1052             application and we insert/remove this popup from the menubar
1053             when activating/deactivating applications.
1054
1055             We can't have 'Edit' popup be customized by an application
1056             via UpdateMainMenu() method because applications may insert
1057             its items to the menubar only AFTER 'View' item ( this fact
1058             is respected by myMainMenuPos ) and the possibility of an
1059             application to add its items into any arbitrary positions of
1060             the main menubar requires a bit sophisticated implementation,
1061             so we decided to avoid it, sorry :-(.
1062         */
1063 #if defined( DEBUG )
1064         if ( !activate )
1065             /* applications MUST clear 'Edit' after themselves */
1066             QAD_ASSERT_DEBUG_ONLY( !myEditPopup.count() );
1067 #endif
1068
1069         if ( activate )  /* insert after 'File' item */
1070           myMainMenu->insertItem( tr("MEN_DESK_EDIT"), &myEditPopup, 3, 1 );
1071         else
1072           myMainMenu->removeItem( 3 );
1073     }
1074 }
1075
1076 /*!
1077     Returns icon file name used by the application
1078 */
1079 const QPixmap& QAD_Desktop::getDefaultIcon() const
1080 {
1081     static QPixmap defaultPixmap( QAD_Desktop::getResourceManager()->loadPixmap( "QAD",
1082                                                             tr("ICON_DESK_DEFAULTICON") ));
1083     return defaultPixmap;
1084 }
1085
1086 /*!
1087     Returns name of the application used as the title of desktop panel
1088 */
1089 const QString& QAD_Desktop::getDefaultTitle() const
1090 {
1091     static QString defaultTitle ( tr("DESK_DEFAULTTITLE") );
1092     return defaultTitle;
1093 }
1094
1095 /*!
1096     Returns default name of new studies
1097 */
1098 const QString& QAD_Desktop::getDefaultStudyName() const
1099 {
1100   static QString defaultStudyName( tr("DESK_DEFAULTDOC") );
1101   return defaultStudyName;
1102 }
1103
1104 /*!
1105     Returns next name for new study
1106 */
1107 QString QAD_Desktop::getNewStudyName()
1108 {
1109     QString number;
1110     number.sprintf( "%d", ++myCntUntitled );
1111     return ( getDefaultStudyName() + number );
1112 }
1113
1114 /*!
1115   Searches QAD_Study corresponding to <study>, returns NULL if fails
1116 */
1117 QAD_Study* QAD_Desktop::findStudy( SALOMEDS::Study_ptr theStudy )
1118 {
1119   for ( QAD_Application* app = myApps.first(); app; app = myApps.next() ) {
1120     QList<QAD_Study> studies; 
1121     studies.setAutoDelete( false );
1122     studies = app->getStudies();
1123     for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
1124       if ( study->getStudyDocument()->_is_equivalent( theStudy ) )
1125         return study;
1126     }
1127   }
1128   return 0;
1129 }
1130
1131 /*!
1132     Returns current active application
1133 */
1134 QAD_Application* QAD_Desktop::getActiveApp() const
1135 {
1136     return myActiveApp;
1137 }
1138
1139 /*!
1140     Returns current active study
1141 */
1142 QAD_Study* QAD_Desktop::getActiveStudy() const
1143 {
1144     return myActiveStudy;
1145 }
1146
1147 /*!
1148     Returns main frame
1149 */
1150 QWorkspaceP* QAD_Desktop::getMainFrame() const
1151 {
1152   return myWorkspace;
1153 }
1154
1155 /*!
1156     Find or load Engine, given a container name and an engine name
1157 */
1158 Engines::Component_var QAD_Desktop::getEngine(const char *containerName,
1159                                               const char *componentName)
1160 {
1161   Engines::Component_var eng =
1162     myEnginesLifeCycle->FindOrLoad_Component(containerName,
1163                                              componentName);
1164   return eng._retn();
1165 }
1166
1167 QString QAD_Desktop::getComponentName(const char *componentUserName)
1168 {
1169   if ( mapComponentName.contains(componentUserName) )
1170     return mapComponentName[ componentUserName ] ;
1171   else
1172     return "";
1173 }
1174
1175 QString QAD_Desktop::getComponentUserName(const char *componentName)
1176 {
1177   QMap<QString,QString>::Iterator it;
1178   for( it = mapComponentName.begin(); it != mapComponentName.end(); ++it )
1179     if (it.data() == componentName )
1180       return it.key();
1181   return "";
1182 }
1183
1184 /*!
1185   gets application Help Window (and creates if necessary)
1186 */
1187 QAD_HelpWindow* QAD_Desktop::getHelpWindow()
1188 {
1189   if (!myHelpWindow) {
1190     myHelpWindow = new QAD_HelpWindow();  
1191     
1192     QMap<QString,QString>::Iterator it;
1193     for( it = mapComponentName.begin(); it != mapComponentName.end(); ++it ) {
1194       QCString dir;
1195       QString root;
1196       
1197       // look for index.html and set homeDir
1198       // 1. $(MODULE_ROOT_DIR)/doc/index.html
1199       // 2. $(MODULE_ROOT_DIR)/doc/html/index.html
1200       // 3. $(MODULE_ROOT_DIR)/doc/html/html/index.html
1201
1202       if (dir = getenv( QString( it.data() + "_ROOT_DIR")) ) {
1203         root = QAD_Tools::addSlash( QAD_Tools::addSlash(dir) + QAD_Tools::addSlash("share")  + QAD_Tools::addSlash("salome")  + "doc" );
1204         if ( QFileInfo( root + "index.html" ).exists() ) {
1205           helpContext( root + "index.html", "" );
1206         }
1207         else {
1208           root = QAD_Tools::addSlash( root + "html" );
1209           if ( QFileInfo( root + "index.html" ).exists() ) {
1210             helpContext( root + "index.html", "" );
1211           }
1212           else {
1213             root = QAD_Tools::addSlash( root + "html" );
1214             if ( QFileInfo( root + "index.html" ).exists() ) {
1215               helpContext( root + "index.html", "" );
1216             }
1217           }
1218         }
1219       }
1220     }
1221     
1222     connect(myHelpWindow, SIGNAL(helpWindowClosed()), this, SLOT(onHelpWindowClosed()));
1223   }
1224   return myHelpWindow;
1225 }
1226
1227 /*!
1228     Called when desktop is closing
1229 */
1230 void QAD_Desktop::closeEvent ( QCloseEvent* e )
1231 {
1232   bool doClose = true;
1233   if  ( myQueryClose ) {
1234     doClose = QAD_MessageBox::info2 ( this, tr("INF_DESK_EXIT"),
1235                                       tr("QUE_DESK_EXIT"), tr ("BUT_OK"),
1236                                       tr ("BUT_CANCEL"), QAD_YES,
1237                                       QAD_NO, QAD_NO ) == QAD_YES;
1238   }
1239
1240   if ( doClose ) { 
1241     for ( QAD_Application* app = myApps.first(); app; app = myApps.next() ) { 
1242       QList<QAD_Study>& studies = app->getStudies();
1243       for(QAD_Study* study = studies.first(); study != 0; study = studies.next()) {
1244         if(myQueryClose && study->getStudyDocument()->IsModified()) {
1245           SALOMEGUI_CloseDlg aDlg( this );
1246           switch ( aDlg.exec() ) {
1247           case 1:
1248             if ( !onSaveStudy( study ) ) {
1249               putInfo( tr("INF_CANCELLED") );
1250               e->ignore();
1251               return;
1252             }
1253             break;
1254           case 2:
1255           case 3:
1256             break;
1257           case 0:
1258           default: 
1259             e->ignore();
1260             putInfo( tr("INF_CANCELLED") );
1261             return;
1262           }
1263         }
1264         study->close();
1265       }
1266     }
1267   }
1268   myQueryClose = true;
1269   doClose ? e->accept() : e->ignore();
1270 }
1271
1272 /*!
1273     Called when desktop is resized
1274 */
1275 void QAD_Desktop::resizeEvent( QResizeEvent* e )
1276 {
1277     QMainWindow::resizeEvent( e );
1278     myWorkspace->setGeometry( 1,1, centralWidget()->width()-2,
1279                               centralWidget()->height()-2 );
1280 }
1281
1282
1283 /*!
1284     Terminates the application.
1285 */
1286 void QAD_Desktop::onExit()
1287 {
1288   close();
1289 }
1290
1291 /************************************************************************
1292 **                      Study operations
1293 *************************************************************************/
1294
1295 /*!
1296     Creates new study.
1297     If several application are supported it displays dialog window
1298     to choose type of study.
1299 */
1300 void QAD_Desktop::createStudy(){
1301   onNewStudy();
1302 }
1303 void QAD_Desktop::onNewStudy()
1304 {
1305   unsigned numApps = myApps.count();
1306   if ( numApps ) {
1307     if ( numApps == 1 )
1308       onNewStudy ( myApps.at(0) );
1309     else  {   /* select the type of application for new study */
1310       Desktop_AppSelectionDlg selDlg( this, myApps );
1311       if ( selDlg.exec() == QDialog::Accepted ) {
1312         onNewStudy ( selDlg.selectedApp() );
1313       }
1314     }
1315   } else  {   /* no applications available in desktop */
1316     QAD_MessageBox::error1( this, 
1317                             tr("ERR_ERROR"),
1318                             tr("ERR_APP_NOAPP"), 
1319                             tr("BUT_OK") );
1320   }
1321 }
1322
1323 /*!
1324     Creates new study for the given application.
1325     Calls the respective function of the application class.
1326 */
1327 void QAD_Desktop::onNewStudy( QAD_Application* app )
1328 {
1329   if ( !app ) return;
1330
1331   /* create new study of the specific app */
1332   putInfo ( tr ("INF_DOC_CREATING") );
1333   QAD_Study* newStudy = app->newStudy();
1334
1335   if ( !newStudy ) {
1336     /* can't create new study */
1337     QAD_MessageBox::error1( this, tr("ERR_ERROR"),
1338                             tr("ERR_DOC_CANTCREATE"), 
1339                             tr("BUT_OK") );
1340   }
1341   putInfo ( tr("INF_READY") );
1342 }
1343
1344 /*!
1345     Loads the existing study.
1346 */
1347 void QAD_Desktop::onLoadStudy()
1348 {
1349   QString name, studyname, ext;
1350
1351   SALOMEGUI_LoadStudiesDlg* aDlg = new SALOMEGUI_LoadStudiesDlg( this, "Load Study", TRUE);
1352
1353   CORBA::Object_var obj = myNameService->Resolve("/myStudyManager");
1354   SALOMEDS::StudyManager_var myStudyMgr = SALOMEDS::StudyManager::_narrow(obj);
1355   ASSERT(! CORBA::is_nil(myStudyMgr));
1356   SALOMEDS::ListOfOpenStudies_var List = myStudyMgr->GetOpenStudies();
1357   for (unsigned int ind = 0; ind < List->length();ind++) {
1358     studyname = List[ind];
1359     aDlg->ListComponent->insertItem( studyname );
1360   }
1361   
1362   int retVal = aDlg->exec();
1363   studyname = aDlg->ListComponent->currentText();
1364   delete aDlg;
1365   if (retVal == QDialog::Rejected) 
1366     return;
1367
1368   if ( studyname.isNull() || studyname.isEmpty() )
1369     return;
1370   
1371   name = studyname;
1372   name.replace( QRegExp(":"), "/" );
1373   
1374   /*
1375     Try to associate an application to the opened study.
1376     Assumed that the association study<->application is unique.
1377   */
1378   bool appFound = false;
1379   putInfo ( tr("INF_DOC_OPENING") + " " + name );
1380   for ( QAD_Application* app = myApps.first(); app; app = myApps.next() )
1381     {
1382       /* application found */
1383       if ( app->isStudyOpened( name ) )
1384         {
1385           /* already opened: prompt for reopen */
1386           if ( QAD_MessageBox::warn2 ( this, tr("WRN_WARNING"),
1387                                        tr("QUE_DOC_ALREADYOPEN").arg( name ),
1388                                        tr ("BUT_YES"), tr ("BUT_NO"), QAD_YES, QAD_NO,
1389                                        QAD_NO ) == QAD_NO )
1390             {
1391               putInfo ( tr("INF_READY") );
1392               return;
1393             }
1394           /* now the study is closed to be re-opened */
1395           //don't ask user to remove study permanently
1396           if (app->getStudyByName ( name ) != NULL)
1397             onCloseStudy ( app->getStudyByName ( name ), false );
1398           else if (app->getStudyByName ( QAD_Tools::getFileNameFromPath( name, false )) != NULL)
1399             onCloseStudy ( app->getStudyByName ( QAD_Tools::getFileNameFromPath( name, false )), false );
1400         }
1401       appFound = true;
1402       
1403       /* open the study */
1404       QAD_Study* openStudy = app->loadStudy( studyname );
1405       if ( !openStudy ) {
1406         QAD_MessageBox::error1( this, 
1407                                 tr("ERR_ERROR"),
1408                                 tr("ERR_DOC_CANTOPEN") + "\n" + name,
1409                                 tr("BUT_OK") );
1410       }
1411       break;
1412     }
1413   
1414   if ( !appFound ) {
1415     QAD_MessageBox::error1( this, 
1416                             tr("ERR_ERROR"), 
1417                             tr("ERR_DOC_UNKNOWNTYPE"), 
1418                             tr("BUT_OK") );
1419   }
1420   putInfo ( tr("INF_READY") );
1421 }
1422
1423
1424
1425 QAD_Study* QAD_Desktop::loadStudy(QString theStudyName) {
1426   QString studyname("");
1427
1428   CORBA::Object_var obj = myNameService->Resolve("/myStudyManager");
1429   SALOMEDS::StudyManager_var myStudyMgr = SALOMEDS::StudyManager::_narrow(obj);
1430   ASSERT(! CORBA::is_nil(myStudyMgr));
1431
1432   SALOMEDS::ListOfOpenStudies_var List = myStudyMgr->GetOpenStudies();
1433   for (unsigned int ind = 0; ind < List->length();ind++) {
1434     if (theStudyName == QString(List[ind])) {
1435       studyname = theStudyName;
1436       break;
1437     }
1438   }
1439   if (studyname == "") {
1440     return NULL;
1441   }
1442   bool appFound = false;
1443   for ( QAD_Application* app = myApps.first(); app; app = myApps.next() ) {
1444     appFound = true;
1445     QAD_Study* openStudy = app->loadStudy( studyname );
1446     if (openStudy) {
1447       //      if (myActiveApp == 0)
1448       //myActiveApp = app;
1449       return openStudy;
1450     }
1451     break;
1452   }
1453   return NULL;
1454 }
1455
1456
1457 /*!
1458     Opens the existing study.
1459     Displays select file dialog and calls corresponding function of
1460     application class
1461     (application is defined according to extension of selected file).
1462 */
1463 void QAD_Desktop::onOpenStudy()
1464 {
1465     QString name, ext;
1466
1467     /* Select a file to open  */
1468     name = selectFileName ( true );
1469     if ( name.isNull() || name.isEmpty() )
1470         return;
1471     
1472     // Workaround for non-existent files
1473     QFileInfo fi(name);
1474     if (!fi.exists() || !fi.isFile()) {
1475       QAD_MessageBox::error1 ( this, tr("ERR_ERROR"),
1476                                      tr("ERR_DOC_CANTOPEN") +": " +  name,
1477                                      tr("BUT_OK") );
1478       return;
1479     }
1480
1481     CORBA::Object_var obj = myNameService->Resolve("/myStudyManager");
1482     SALOMEDS::StudyManager_var myStudyMgr = SALOMEDS::StudyManager::_narrow(obj);
1483     ASSERT(! CORBA::is_nil(myStudyMgr));
1484     SALOMEDS::ListOfOpenStudies_var List = myStudyMgr->GetOpenStudies();
1485     for (unsigned int ind = 0; ind < List->length();ind++) {
1486       QString NameExistingStudy(List[ind]);
1487       QString NameOpeningStudy = QAD_Tools::getFileNameFromPath( name, false );
1488      
1489       if ( NameExistingStudy.compare( NameOpeningStudy ) == 0 ) {
1490         if ( QAD_MessageBox::warn2 ( this, tr("WRN_WARNING"),
1491                                      tr("QUE_DOC_ALREADYEXIST").arg( name ),
1492                                      tr ("BUT_YES"), tr ("BUT_NO"), QAD_YES, QAD_NO,
1493                                      QAD_NO ) == QAD_NO )
1494           {
1495             putInfo ( tr("INF_READY") );
1496             return;
1497           }
1498 //      else 
1499 //        {
1500 //          onLoadStudy();
1501 //          return;
1502 //        }
1503       }
1504     }
1505
1506     /*
1507         Try to associate an application to the opened study.
1508         Assumed that the association study<->application is unique.
1509     */
1510     bool appFound = false;
1511     putInfo ( tr("INF_DOC_OPENING") + " " + name );
1512     for ( QAD_Application* app = myApps.first(); app; app = myApps.next() )
1513     {
1514         QString ext = QAD_Tools::getFileExtensionFromPath ( name );
1515         if ( app->getStudyExtension() == ext )
1516         {
1517             /* application found */
1518             if ( app->isStudyOpened( name ) )
1519             {
1520                 /* already opened: prompt for reopen */
1521                 if ( QAD_MessageBox::warn2 ( this, tr("WRN_WARNING"),
1522                                              tr("QUE_DOC_ALREADYOPEN").arg( name ),
1523                                              tr ("BUT_YES"), tr ("BUT_NO"), QAD_YES, QAD_NO,
1524                                              QAD_NO ) == QAD_NO )
1525                 {
1526                     putInfo ( tr("INF_READY") );
1527                     return;
1528                 }
1529                 /* now the study is closed to be re-opened */
1530                 //don't ask user to remove study permanently
1531                 if (app->getStudyByName ( name ) != NULL)
1532                   onCloseStudy ( app->getStudyByName ( name ), false );
1533                 else if (app->getStudyByName ( QAD_Tools::getFileNameFromPath( name, false )) != NULL)
1534                   onCloseStudy ( app->getStudyByName ( QAD_Tools::getFileNameFromPath( name, false )), false );
1535             }
1536             appFound = true;
1537
1538             /* open the study */
1539             QAD_Study* openStudy = app->openStudy( name );
1540             if ( !openStudy ) {
1541               QAD_MessageBox::error1( this, 
1542                                       tr("ERR_ERROR"),
1543                                       tr("ERR_DOC_CANTOPEN") + "\n" + name,
1544                                       tr("BUT_OK") );
1545             } else if (myActiveComp != "") {
1546               QApplication::setOverrideCursor( Qt::waitCursor );
1547               loadComponentData(mapComponentName[myActiveComp]);
1548               openStudy->updateObjBrowser(true);
1549               QApplication::restoreOverrideCursor();
1550             }
1551             break;
1552         }
1553     }
1554
1555     if ( !appFound )
1556     {
1557       QAD_MessageBox::error1( this, 
1558                               tr("ERR_ERROR"), 
1559                               tr("ERR_DOC_UNKNOWNTYPE"), 
1560                               tr("BUT_OK"));
1561     }
1562     putInfo ( tr("INF_READY") );
1563 }
1564
1565 bool QAD_Desktop::loadComponentData( const QString& compName )
1566 {
1567   // Open component's data in active study if any
1568   MESSAGE("loadComponentData(): Opening " << compName << " component data ")
1569   if (!myActiveStudy) {
1570     MESSAGE("loadComponentData(): No active study exists")
1571     return false;
1572   }
1573
1574   Engines::Component_var comp ;
1575   if ( compName.compare("SUPERV") == 0 ) {
1576     comp = getEngine( "SuperVisionContainer", compName) ;
1577   }
1578   else {
1579     /*    comp = ( compName.compare("Data1") != 0 ) ? getEngine( "FactoryServer", compName) :
1580                                                 getEngine( "FactoryServerPy", compName);
1581     */
1582     comp = getEngine( "FactoryServer", compName);
1583     if ( comp->_is_nil() )
1584       comp = getEngine( "FactoryServerPy", compName);
1585   }
1586
1587   SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
1588   SALOMEDS::SComponent_var SCO = SALOMEDS::SComponent::_narrow(aStudy->FindObject( getComponentUserName(compName) ));
1589            
1590   if (!SCO->_is_nil()) {
1591     if (!CORBA::is_nil(comp)) {
1592       SALOMEDS::Driver_var   driver = SALOMEDS::Driver::_narrow(comp);
1593       if (!CORBA::is_nil(driver)) {
1594         SALOMEDS::StudyBuilder_var  B = aStudy->NewBuilder();
1595         if (!CORBA::is_nil(B)) {
1596           QAD_Operation* op = new QAD_Operation( myActiveStudy );
1597           op->start();
1598           B->LoadWith(SCO,driver);
1599           op->finish();
1600         } else {
1601           return false;
1602         }
1603       } else {
1604         MESSAGE("loadComponentData(): Driver is null");
1605         return false;
1606       }
1607     } else {
1608       MESSAGE("loadComponentData(): Engine is null");
1609       return false;
1610     }
1611   } else {
1612     MESSAGE("loadComponentData(): SComponent is null");
1613     return false;
1614   }
1615
1616   return true;
1617 }
1618
1619 /*!
1620     Saves the active study
1621 */
1622 bool QAD_Desktop::onSaveStudy()
1623 {
1624     return onSaveStudy ( myActiveStudy );
1625 }
1626
1627 /*!
1628     Saves the given study
1629 */
1630 bool QAD_Desktop::onSaveStudy( QAD_Study* study )
1631 {
1632     if ( !study ) return true;
1633
1634     if ( !study->isSaved() )
1635         return onSaveAsStudy ( study );
1636
1637     /* saving study... */
1638     QAD_Application* app = study->getApp();
1639     QAD_ASSERT_DEBUG_ONLY ( app );
1640     putInfo ( tr("INF_DOC_SAVING") + study->getTitle() );
1641     if ( !app->saveStudy( study ) )
1642     {
1643         putInfo( tr("INF_CANCELLED") );
1644         return false;
1645     }
1646
1647     /* saved ok */
1648     putInfo ( tr("INF_DOC_SAVED").arg( "" ) );
1649     return true;
1650 }
1651
1652 /*!
1653     Saves the active study under a new name
1654 */
1655 bool QAD_Desktop::onSaveAsStudy()
1656 {
1657     return onSaveAsStudy( myActiveStudy );
1658 }
1659
1660 /*!
1661     Saves the given study under a new name
1662 */
1663 bool QAD_Desktop::onSaveAsStudy( QAD_Study* study )
1664 {
1665     if ( !study ) return true;
1666
1667     /* Save study in a format supported by its application
1668     */
1669     QAD_Application* app = study->getApp();
1670     QAD_ASSERT_DEBUG_ONLY ( app );
1671
1672     /*  Select a file where to save
1673     */
1674     QString name = selectFileName ( false );
1675     if ( name.isNull() || name.isEmpty() )
1676     {
1677         putInfo( tr("INF_CANCELLED") );
1678         return false;
1679     }
1680
1681     /*  Saving study
1682     */
1683     putInfo ( tr("INF_DOC_SAVING") + name );
1684     if ( !app->saveAsStudy( study, name ) ) {
1685       /* can't save the file */
1686       QAD_MessageBox::error1( this, 
1687                               tr("ERR_ERROR"), 
1688                               tr("ERR_DOC_CANTWRITE") + "\n" + name,
1689                               tr("BUT_OK") );
1690       putInfo("");
1691       return false;     /* cannot save */
1692     }
1693     putInfo ( tr("INF_DOC_SAVED").arg( name ) );
1694     return true;        /* saved ok */
1695 }
1696
1697 /*!
1698     Closes the active study
1699 */
1700 bool QAD_Desktop::onCloseStudy()
1701 {
1702   bool close = this->onCloseStudy ( myActiveStudy, true );
1703   if ( close && !myXmlHandler->myIdList.IsEmpty() ) {
1704     clearMenus();
1705     myActiveComp = "";
1706     myCombo->setCurrentItem (0);
1707     for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
1708       aButton->setOn(false);
1709     }
1710   }
1711   return close;
1712 }
1713
1714 /*!
1715     Closes the given study and ask user to remove study
1716     from the study manager permanently
1717 */
1718 bool QAD_Desktop::onCloseStudy( QAD_Study* study )
1719 {
1720   return onCloseStudy( study, true );
1721 }
1722
1723 /*!
1724     Closes the given study and ask user to remove study
1725     from the study manager permanently if ask is equal true
1726 */
1727 bool QAD_Desktop::onCloseStudy( QAD_Study* study, bool ask ) 
1728 {
1729   bool removePerm = false;
1730
1731   if ( ask )
1732     {
1733       SALOMEGUI_CloseDlg aDlg( this );
1734       int res = aDlg.exec();
1735       
1736       switch ( res )
1737         {
1738         case 1:
1739           //if ( study->isModified() )
1740           if ( !onSaveStudy( study ) ) {
1741             putInfo( tr("INF_CANCELLED") );
1742             return false;
1743           }
1744           removePerm = true;
1745           break;
1746         case 2:
1747           removePerm = true;
1748           break;
1749         case 3:
1750           removePerm = false;
1751           break;
1752         case 0:
1753         default:
1754           putInfo( tr("INF_CANCELLED") );
1755           return false;
1756         }
1757     }
1758   /* close active component */
1759   if (!myXmlHandler->myIdList.IsEmpty())
1760     {
1761       clearMenus();
1762       myActiveComp="";
1763       myCombo->setCurrentItem (0);
1764       for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() )
1765         aButton->setOn(false);
1766       qApp->processEvents();
1767     }
1768   /* close the study */
1769   return study->getApp()->closeStudy( study, removePerm );
1770 }
1771
1772 // Displays study properties dialog box
1773 void QAD_Desktop::onStudyProperties()
1774 {
1775   if (myActiveStudy) {
1776     // open transaction
1777     QAD_Operation* op = new QAD_Operation( myActiveStudy );
1778     op->start();
1779
1780     SALOMEGUI_StudyPropertiesDlg aDlg(this);
1781     int res = aDlg.exec();
1782
1783     if ( res == QDialog::Accepted && aDlg.isChanged() )
1784       op->finish();
1785     else
1786       op->abort(); 
1787
1788     // T2.12 - add the word "locked" to study frame captions if <myActiveStudy> study is locked
1789     myActiveStudy->updateCaptions();
1790   }
1791 }
1792
1793
1794 /*!
1795   locate all windows in cascade mode
1796   and resize them
1797 */
1798 void QAD_Desktop::onCascade()
1799 {
1800   myWorkspace->cascade();
1801   int w = myWorkspace->width();
1802   int h = myWorkspace->height();
1803   QWidgetList wList = myWorkspace->windowList();
1804   QWidgetListIt it(wList);
1805
1806   for(;it.current(); ++it)
1807       it.current()->resize((int)(0.8*w), (int)(0.8*h));
1808 }
1809
1810 /*!
1811   called when help window closed
1812 */
1813 void QAD_Desktop::onHelpWindowClosed()
1814 {
1815   myHelpWindow = 0;
1816 }
1817
1818 /*!
1819     Called when 'view status bar' option
1820     is switched on/off.
1821 */
1822 void QAD_Desktop::onViewStatusBar()
1823 {
1824     bool show = myStdActions.at( ViewStatusBarId )->isOn();
1825     if ( show == myStatusBar->isVisible() )
1826         return;
1827     if ( show )
1828         myStatusBar->show();
1829     else
1830         myStatusBar->hide();
1831 }
1832
1833 /*!
1834   Called when View/Toolbars popup menu is about to show
1835 */
1836 void QAD_Desktop::onToolBarPopupAboutToShow()
1837 {
1838   myToolBarAction.clear();
1839   myToolBarsPopup.clear();
1840   QPtrList<QDockWindow> wlist = dockWindows();
1841   for ( QDockWindow* w = wlist.first(); w; w = wlist.next() ) {
1842     if ( w->inherits( "QToolBar" ) ) {
1843       QToolBar* tb = ( QToolBar* )w;
1844       if ( appropriate( tb ) ) { 
1845         ToggleAction* a = new ToggleAction( tb->label(), tb->label(), 0, this, 0, true );
1846         a->setStatusTip ( tr("PRP_DESK_VIEW_TOOLBAR") );
1847         a->setOn( tb->isVisible() );
1848         QAD_ASSERT( connect( a, SIGNAL( toggledOn()  ), tb, SLOT( show() ) ) );
1849         QAD_ASSERT( connect( a, SIGNAL( toggledOff() ), tb, SLOT( hide() ) ) );
1850         a->addTo( &myToolBarsPopup );
1851         myToolBarAction.append( a );
1852       }
1853     }
1854   }
1855 }
1856
1857 /*!
1858     Called on 'View\Selection Mode'
1859 */
1860 void QAD_Desktop::onSelectionMode()
1861 {
1862   const QActionP* obj = (QActionP*) sender();
1863   
1864   int SelectionMode = 4;
1865
1866   if ( obj == myStdActions.at(SelectionActorId) ) {
1867     SelectionMode = 4;
1868     if ( obj->isOn() ) {
1869       myStdActions.at(SelectionCellId)->setOn(false);
1870       myStdActions.at(SelectionEdgeId)->setOn(false);
1871       myStdActions.at(SelectionPointId)->setOn(false);
1872     } else
1873       myStdActions.at(SelectionActorId)->setOn(true);
1874
1875   } else if ( obj == myStdActions.at(SelectionCellId) ) {
1876     SelectionMode = 3; 
1877     if ( obj->isOn() ) {
1878       myStdActions.at(SelectionActorId)->setOn(false);
1879       myStdActions.at(SelectionEdgeId)->setOn(false);
1880       myStdActions.at(SelectionPointId)->setOn(false);
1881     } else
1882       myStdActions.at(SelectionActorId)->setOn(true);
1883       
1884   } else if ( obj == myStdActions.at(SelectionEdgeId) ) {
1885     SelectionMode = 2;    
1886     if ( obj->isOn() ) {
1887       myStdActions.at(SelectionActorId)->setOn(false);
1888       myStdActions.at(SelectionCellId)->setOn(false);
1889       myStdActions.at(SelectionPointId)->setOn(false);
1890     } else
1891       myStdActions.at(SelectionActorId)->setOn(true);
1892       
1893   } else if ( obj == myStdActions.at(SelectionPointId) ) {
1894     SelectionMode = 1;
1895     if ( obj->isOn() ) {
1896       myStdActions.at(SelectionEdgeId)->setOn(false);
1897       myStdActions.at(SelectionCellId)->setOn(false);
1898       myStdActions.at(SelectionActorId)->setOn(false);
1899     } else
1900       myStdActions.at(SelectionActorId)->setOn(true);
1901   }
1902
1903   QAD_StudyFrame* sf = myActiveApp->getActiveStudy()->getActiveStudyFrame();
1904   sf->getRightFrame()->getViewFrame()->SetSelectionMode( SelectionMode );
1905   
1906   SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveApp->getActiveStudy()->getSelection() );
1907   Sel->SetSelectionMode( SelectionMode );
1908 }
1909
1910 /*!
1911     Called on 'View\Selection Mode'
1912 */
1913 void QAD_Desktop::SetSelectionMode(int mode, bool activeCompOnly)
1914 {
1915   switch (mode) {
1916   case 1:
1917     {
1918       myStdActions.at(SelectionEdgeId)->setOn(false);
1919       myStdActions.at(SelectionCellId)->setOn(false);
1920       myStdActions.at(SelectionActorId)->setOn(false);
1921       myStdActions.at(SelectionPointId)->setOn(true);
1922       break;
1923     }
1924   case 2:
1925     {
1926       myStdActions.at(SelectionActorId)->setOn(false);
1927       myStdActions.at(SelectionCellId)->setOn(false);
1928       myStdActions.at(SelectionPointId)->setOn(false);
1929       myStdActions.at(SelectionEdgeId)->setOn(true);
1930       break;
1931     }
1932   case 3:
1933     {
1934       myStdActions.at(SelectionActorId)->setOn(false);
1935       myStdActions.at(SelectionEdgeId)->setOn(false);
1936       myStdActions.at(SelectionPointId)->setOn(false);
1937       myStdActions.at(SelectionCellId)->setOn(true);
1938       break;
1939     }
1940   case 4:
1941     {
1942       myStdActions.at(SelectionCellId)->setOn(false);
1943       myStdActions.at(SelectionEdgeId)->setOn(false);
1944       myStdActions.at(SelectionPointId)->setOn(false);
1945       myStdActions.at(SelectionActorId)->setOn(true);
1946       break;
1947     }
1948   }
1949
1950   QAD_StudyFrame* sf = myActiveApp->getActiveStudy()->getActiveStudyFrame();
1951   if ( sf->getTypeView() == VIEW_VTK ) {
1952     sf->getRightFrame()->getViewFrame()->SetSelectionMode( mode );
1953     SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveApp->getActiveStudy()->getSelection() );
1954     Sel->SetSelectionMode( mode, activeCompOnly );
1955   } else {
1956   }
1957 }
1958
1959 /*!
1960     Called on 'Window\NewWindow3d'
1961 */
1962 void QAD_Desktop::onNewWindow3d()
1963 {
1964   //NRI : SAL2214
1965   /*
1966     //VRV: T2.5 - add default viewer
1967     QApplication::restoreOverrideCursor();
1968     SALOMEGUI_ViewChoiceDlg *choice = new SALOMEGUI_ViewChoiceDlg(this, "", TRUE);
1969     int r = choice->exec();
1970     if (r) 
1971     {
1972     myActiveApp->getActiveStudy()->newWindow3d(QString(""),(ViewType)(choice->getSelectedViewer()));
1973     }
1974     //VRV: T2.5 - add default viewer
1975   */
1976   const QActionP* obj = (QActionP*) sender();
1977   if ( obj == myStdActions.at(ViewOCCId) ) {
1978     myActiveApp->getActiveStudy()->newWindow3d(QString(""),(ViewType)(0));
1979   } else if ( obj == myStdActions.at(ViewVTKId) ) {
1980     myActiveApp->getActiveStudy()->newWindow3d(QString(""),(ViewType)(1));
1981   } else if ( obj == myStdActions.at(ViewPlot2dId) ) {
1982     myActiveApp->getActiveStudy()->newWindow3d(QString(""),(ViewType)(3));
1983   }
1984   //NRI : SAL2214
1985 }
1986
1987 /*!
1988     Called on 'help\contents'
1989 */
1990 void QAD_Desktop::onHelpContents()
1991 {
1992   if (myActiveApp)
1993     myActiveApp->helpContents();
1994   else
1995     helpContents();
1996 }
1997
1998 /*!
1999     Called on 'help\search'
2000 */
2001 void QAD_Desktop::onHelpSearch()
2002 {
2003   if (myActiveApp)
2004     myActiveApp->helpSearch();
2005   else
2006     helpSearch();
2007 }
2008
2009 /*!
2010     Called on 'help\about'
2011 */
2012 void QAD_Desktop::onHelpAbout()
2013 {
2014   if (myActiveApp)
2015     myActiveApp->helpAbout();
2016   else
2017     helpAbout();
2018 }
2019
2020
2021 /*!
2022     Activates the application and its active study
2023 */
2024 void QAD_Desktop::onActivateApp( QAD_Application* activeApp )
2025 {
2026   bool appChanged = ( activeApp != myActiveApp );
2027   if ( appChanged )
2028     {
2029       updateDesktop( DeactivateApp );
2030     }
2031   if ( activeApp )
2032     {
2033       myActiveApp = activeApp;
2034       myActiveStudy = myActiveApp->getActiveStudy();
2035     }
2036   else
2037     {
2038       myActiveApp = 0;
2039       myActiveStudy = 0;
2040     }
2041
2042   if ( appChanged )
2043     {
2044       updateDesktop( ActivateApp );
2045       updateCaption( (activeApp != NULL) ? ActivateApp : DeactivateApp );
2046     }
2047   updateActions();
2048 }
2049
2050 /*!
2051     Called when the last study is removed from
2052     the application 'app'.
2053 */
2054 void QAD_Desktop::onDeactivateApp(QAD_Application* app)
2055 {
2056   if ( app && app == myActiveApp )
2057     onActivateApp( 0 );
2058 }
2059
2060 /*!
2061     Enables/disables standard actions
2062 */
2063 void QAD_Desktop::updateActions()
2064 {
2065     myStdActions.at( FileCloseId )->setEnabled ( myActiveStudy != NULL );
2066     myStdActions.at( FileSaveId )->setEnabled ( myActiveStudy != NULL );
2067     myStdActions.at( FileSaveAsId )->setEnabled ( myActiveStudy != NULL );
2068     myStdActions.at( FilePropsId )->setEnabled( myActiveStudy != NULL );
2069 //    myStdActions.at( HelpContentsId )->setEnabled ( myActiveApp != NULL );
2070 //    myStdActions.at( HelpSearchId )->setEnabled ( myActiveApp != NULL );
2071 //    myStdActions.at( HelpWhatsThisId )->setEnabled ( myActiveApp != NULL );
2072 //    myStdActions.at( HelpAboutId )->setEnabled ( myActiveApp != NULL );
2073
2074 //    myToolsPopup.setEnabled ( myActiveStudy != NULL );
2075 //    myPrefPopup.setEnabled ( myActiveStudy != NULL );
2076
2077     mySelectionModePopup.setEnabled ( myActiveStudy != NULL );
2078
2079     // VSR ==> SAL2982
2080     myStdActions.at( ViewOCCId )->setEnabled( myActiveStudy != NULL );
2081     myStdActions.at( ViewVTKId )->setEnabled( myActiveStudy != NULL );
2082     myStdActions.at( ViewPlot2dId )->setEnabled( myActiveStudy != NULL );
2083     // VSR <== SAL2982
2084 }
2085
2086 /*!
2087     Called when 'Window' popup is about to show
2088 */
2089 void QAD_Desktop::onWindowPopupAboutToShow()
2090 {
2091     /* add cascade/tile items */
2092     myWindowPopup.clear();
2093
2094     //NRI : SAL2214
2095     //myStdActions.at( WindowNew3dId )->addTo( &myWindowPopup );
2096     myWindowPopup.insertItem( tr("MEN_DESK_WINDOW_NEW3D"), &myNewViewPopup, WindowNew3dId );
2097     //myStdActions.at( WindowNew3dId )->setEnabled( true );
2098     myWindowPopup.setItemEnabled( WindowNew3dId, true );
2099     //NRI : SAL2214
2100     myStdActions.at( WindowCascadeId )->addTo( &myWindowPopup );
2101     myStdActions.at( WindowCascadeId )->setEnabled( true );
2102     myStdActions.at( WindowTileId )->addTo( &myWindowPopup );
2103     myStdActions.at( WindowTileId )->setEnabled( true );
2104
2105     /* add names of opened studies */
2106     QWidgetList windows = myWorkspace->windowList();
2107     if ( windows.isEmpty() )
2108     {
2109       //NRI : SAL2214 myStdActions.at( WindowNew3dId )->setEnabled( false );
2110       myWindowPopup.setItemEnabled( WindowNew3dId, false );
2111       //NRI : SAL2214
2112       myStdActions.at( WindowCascadeId )->setEnabled( false );
2113       myStdActions.at( WindowTileId )->setEnabled( false );
2114     }
2115     else
2116       {
2117         myWindowPopup.insertSeparator();
2118         for ( int i = 0; i < int(windows.count()); ++i )
2119           {
2120             int id = myWindowPopup.insertItem( windows.at(i)->caption(),
2121                                                this, SLOT( onWindowsPopupActivated( int ) ) );
2122             myWindowPopup.setItemParameter( id, i );
2123             myWindowPopup.setItemChecked( id, myWorkspace->activeWindow() == windows.at(i) );
2124           }
2125         QAD_ASSERT( connect( &myWindowPopup, SIGNAL(highlighted( int )), this,
2126                              SLOT(onWindowsPopupStatusText( int )) ));
2127     }
2128 }
2129
2130 /*!
2131     Called when the item with 'id' of 'Windows' popup
2132     is highlighted
2133 */
2134 void QAD_Desktop::onWindowsPopupStatusText( int id )
2135 {
2136     int cascadeId = myWindowPopup.idAt( 0 );
2137     int tileId = myWindowPopup.idAt( 1 );
2138     if ( id == cascadeId || id == tileId )
2139         return;
2140     putInfo( tr("PRP_DESK_WINDOW_ACTIVATE") );
2141 }
2142
2143 /*!
2144     Called when user wants to activate a child  window with 'wid'
2145     in the main frame
2146 */
2147 void QAD_Desktop::onWindowsPopupActivated( int wid )
2148 {
2149     QWidget* w = myWorkspace->windowList().at( wid );
2150     if ( w ) w->setFocus();
2151 }
2152
2153 /*!
2154     Selects a file name when opening or saving files.
2155     The basic implementation just uses the standard
2156     Open/Save dialogs.
2157     Please redefine if another behaviour is required.
2158 */
2159 QString QAD_Desktop::selectFileName ( bool open )
2160 {
2161   QAD_FileDlg* fd = new QAD_FileDlg( this, open, true, true );    
2162
2163   QString name = "";
2164   QString dir  = "";
2165   QStringList filters;
2166
2167   if (open) {
2168     //  All the file types of the supported applications
2169     //    can be opened 
2170     for ( QAD_Application* app = myApps.first(); app; app = myApps.next() )
2171       {
2172         filters += app->getStudyDescription() + " " + tr("DESK_FILES") + " " +
2173                                  "(*." + app->getStudyExtension() + ")";
2174       }
2175   }
2176   else {
2177     QAD_ASSERT_DEBUG_ONLY ( myActiveStudy );
2178     if (myActiveStudy) {
2179       // get file name of active study
2180       name = QAD_Tools::getFileNameFromPath ( myActiveStudy->getTitle() );
2181       // get path to the active study file
2182       dir = QAD_Tools::getDirFromPath ( myActiveStudy->getPath(), false );
2183     }
2184     QAD_ASSERT_DEBUG_ONLY ( !name.isNull() );
2185     // the file types supported by the active application
2186     filters += myActiveApp->getStudyDescription() + " " + tr("DESK_FILES") + " " +
2187                                  "(*." + myActiveApp->getStudyExtension() + ")" ;
2188   }
2189   if (!dir.isEmpty()) {
2190     // when saving document ("Save As" command) - to get dir from active study filename
2191     // for new documents - to use last opened directory
2192     fd->setDir( dir );
2193   }
2194   fd->setSelection( name );
2195   fd->setFilters( filters );
2196    
2197   fd->exec();
2198   QString filename = fd->selectedFile();
2199   delete fd;
2200   qApp->processEvents();
2201   return filename;
2202 }
2203
2204 /*!
2205     Closes all the studies of 'app'. Returns
2206     'true' if thay are closed OK, 'false' at least
2207     one can't be closed or user cancel the closure.
2208 */
2209 bool QAD_Desktop::closeAllStudies( QAD_Application* app )
2210 {
2211     QList<QAD_Study>& studies = app->getStudies();
2212     while ( !studies.isEmpty() )
2213     {
2214       //don't ask user to remove study permanently
2215       if ( !onCloseStudy( studies.at(0), false ) )
2216             return false;   /* user cancelled closing */
2217     }
2218     return true;
2219 }
2220
2221 /*!
2222   Called on Popup item when SComponent representation in Object Browser is selected.
2223 */
2224 void QAD_Desktop::onOpenWith()
2225 {
2226   Engines::Component_var comp;
2227   QString ComponentSelected;
2228
2229   SALOMEDS::SObject_var SO;
2230   SALOMEDS::SComponent_var SCO;
2231   SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
2232   SALOMEDS::GenericAttribute_var anAttr;
2233   SALOMEDS::AttributeName_var aName;
2234
2235   SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2236   if ( Sel->IObjectCount() == 1 ) {
2237     Handle(SALOME_InteractiveObject) IO = Sel->firstIObject();
2238     SO = aStudy->FindObjectID( IO->getEntry() );
2239     SCO = SO->GetFatherComponent();
2240     char* name;
2241     if (SCO->FindAttribute(anAttr, "AttributeName")) {
2242       aName = SALOMEDS::AttributeName::_narrow(anAttr);
2243       name = aName->Value();
2244       SALOME_ModuleCatalog::Acomponent_var Comp = myCatalogue->GetComponent( mapComponentName[name] );
2245       if ( !Comp->_is_nil() ) {
2246         
2247         SALOME_ModuleCatalog::ListOfComponents_var list_type_composants =
2248           myCatalogue->GetTypedComponentList( Comp->component_type() );
2249         
2250         if ( list_type_composants->length() == 1 ) {
2251           ComponentSelected = name;
2252         } else if ( list_type_composants->length() > 1 ) {
2253           SALOMEGUI_OpenWith* aDlg = new SALOMEGUI_OpenWith( this );
2254           for (unsigned int ind = 0; ind < list_type_composants->length();ind++) {
2255             aDlg->addComponent( strdup(list_type_composants[ind]) );
2256           }
2257           
2258           int retVal = aDlg->exec();
2259           ComponentSelected = aDlg->getComponent();
2260           delete aDlg;
2261           if ( retVal == QDialog::Rejected || ComponentSelected.isEmpty()) {
2262             return;
2263           }
2264         } else {
2265           MESSAGE( "No component with type : " << Comp->component_type() << " exists" );
2266           return;
2267         }
2268         
2269       } else {
2270         MESSAGE( "This component not exists in the catalog" );
2271         return;
2272       }
2273       
2274       QApplication::setOverrideCursor( Qt::waitCursor );
2275       Sel->ClearIObjects();
2276       
2277 //      if (loadComponentData(ComponentSelected)) {
2278         onComboActiveComponent(ComponentSelected);
2279 //      int nbItem = myCombo->count();
2280 //      int Index = 0;
2281 //      for (int i = 0; i < nbItem; i++) {
2282 //        if (myCombo->text(i).compare(ComponentSelected)==0) {
2283 //          Index = i;
2284 //          break;
2285 //        }
2286 //      }
2287 //      myCombo->setCurrentItem(Index);
2288 //      myActiveStudy->updateObjBrowser(true);
2289 //      }
2290     }
2291   }
2292   QApplication::restoreOverrideCursor();
2293 }
2294
2295 typedef bool OneDim1(QAD_Desktop*);
2296 typedef bool OneDim2(QAD_Desktop*, char*);
2297
2298 /*!
2299   Called to define settings of component.
2300 */
2301 void QAD_Desktop::setSettings()
2302 {
2303   if (!myActiveComp.isEmpty())  {
2304     OSD_Function osdF = mySharedLibrary.DlSymb("SetSettings");
2305     if ( osdF != NULL )
2306       if (_islibso)
2307         {
2308           OneDim1 (*f1) = (bool (*) (QAD_Desktop*)) osdF;
2309           (*f1)(this);
2310         }
2311       else
2312         {
2313           QString Component =mapComponentName[myActiveComp];
2314           OneDim2 (*f1) = (bool (*) (QAD_Desktop*, char*)) osdF;
2315           (*f1)(this, (char*)Component.latin1());
2316         }
2317   }
2318 }
2319
2320 /*!
2321   Called to load Component : xml resources and GUI librairy.
2322 */
2323 bool QAD_Desktop::loadComponent(QString Component)
2324 {
2325   QAD_WaitCursor wc;
2326   QString resDir("/");  //NRI : Pb under Windows
2327
2328   QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
2329   if ( resMgr ) {
2330     QString msg;
2331     if (!resMgr->loadResources( Component, msg ))
2332       {
2333         //NRI   QCString errMsg;
2334         //      errMsg.sprintf( "Do not load all resources for module %sGUI.\n" ,
2335         //              Component.latin1() );
2336         wc.stop();
2337         QMessageBox::warning( this, tr("WRN_WARNING"), msg, tr ("BUT_OK") );
2338         return false;
2339       }
2340   }
2341     
2342   /* Parse xml file */
2343   myXmlHandler = new QAD_XmlHandler();
2344   myXmlHandler->setMainWindow(this);
2345   if (!myXmlHandler->setComponent(resMgr->resources( Component ))) return false;
2346
2347   QString language = resMgr->language( Component );
2348
2349   QString ComponentXml = Component + "_" + language + ".xml";
2350   //ComponentXml = resMgr->resources(Component + "GUI") ;
2351   //ComponentXml = QAD_Tools::addSlash(ComponentXml) ;
2352   ComponentXml = QAD_Tools::addSlash( resMgr->findFile( ComponentXml, Component ) ) + ComponentXml;
2353   QFile file( ComponentXml );
2354
2355   if ( !file.exists() || !file.open( IO_ReadOnly ) )  {
2356     QString errMsg;
2357     errMsg.sprintf( "Cannot open xml file: %s\n.",
2358                     (file.name()).latin1() );
2359     wc.stop();
2360     QMessageBox::critical( this, tr("ERR_ERROR"), errMsg, tr ("BUT_OK") );
2361     return false;
2362   }
2363   file.close();
2364
2365   QXmlInputSource source( file );
2366   QXmlSimpleReader reader;
2367   reader.setContentHandler( myXmlHandler );
2368   reader.setErrorHandler( myXmlHandler );
2369   bool ok = reader.parse( source );
2370   file.close();
2371   if ( !ok ) {
2372     wc.stop();
2373     QMessageBox::critical( this,
2374                            tr( "INF_PARSE_ERROR" ),
2375                            tr( myXmlHandler->errorProtocol() ) );
2376     return false;
2377   }
2378
2379   myMenusList=myXmlHandler->myMenusList;
2380   myActiveMenus=myMenusList.at(0);
2381   myOperatorMenus->showMenuBar(0);
2382   myActiveMenus->showAllToolBars();
2383
2384   /* Components toolbars */
2385   int nbToolbars = 0;
2386   if (myActiveMenus)
2387     nbToolbars = myActiveMenus->getToolBarList().count();
2388   /* Open Shared Library */
2389   mySharedLibrary = OSD_SharedLibrary();
2390   _islibso = false;
2391
2392   QString ComponentLib;
2393   QCString libs;
2394   QFileInfo fileInfo ;
2395   QString fileString ;
2396   QString dir;
2397
2398   if ( libs = getenv("LD_LIBRARY_PATH")) {
2399     //    MESSAGE ( " LD_LIBRARY_PATH : " << libs );
2400     QStringList dirList = QStringList::split( SEPARATOR, libs, false ); // skip empty entries
2401     for ( int i = dirList.count()-1; i >= 0; i-- ) {
2402       dir = dirList[ i ];
2403 #ifdef WNT
2404       fileString = QAD_Tools::addSlash( dir ) + "lib" + Component + "GUI.dll" ;
2405 #else
2406       fileString = QAD_Tools::addSlash( dir ) + "lib" + Component + "GUI.so" ;
2407 #endif
2408     
2409       fileInfo.setFile(fileString) ;
2410       if (fileInfo.exists()) {
2411         //      MESSAGE ( " GUI library = " << fileString );
2412         ComponentLib = fileInfo.fileName() ;
2413         _islibso = true;
2414         break;
2415       }
2416     }
2417   }
2418
2419   if (!_islibso) // component GUI could be in PyQt, use generic library
2420     {
2421       MESSAGE("GUI library not found, trying generic library for PyQt GUI");
2422       bool found = false;
2423       if (dir = getenv("KERNEL_ROOT_DIR"))
2424         {
2425           dir = QAD_Tools::addSlash(dir) ;
2426           dir = dir + "lib" ;
2427           dir = QAD_Tools::addSlash(dir) ;
2428           dir = dir + "salome" ;
2429           dir = QAD_Tools::addSlash(dir) ;
2430 #ifdef WNT
2431           dir = dir + "libSalomePyQtcmodule.dll" ;
2432 #else
2433           dir = dir + "libSalomePyQtcmodule.so" ;
2434 #endif
2435           MESSAGE ( " GUI library = " << dir );
2436           fileInfo.setFile(dir) ;
2437           if (fileInfo.exists())
2438             {
2439               ComponentLib = fileInfo.fileName() ;
2440               found = true;
2441             }
2442         }
2443       if ( !found )
2444         {
2445           QMessageBox::critical( this,
2446                                  tr("ERR_ERROR"),
2447                                  tr("ERR_LIBGUI" ).arg(Component) );
2448           return false;
2449         }
2450     }
2451
2452   mySharedLibrary.SetName(TCollection_AsciiString((char*)ComponentLib.latin1()).ToCString());
2453   ok = mySharedLibrary.DlOpen(OSD_RTLD_LAZY);
2454   if (!ok) {
2455     wc.stop();
2456     QMessageBox::critical( this,
2457                            tr("ERR_ERROR"),
2458                            tr( mySharedLibrary.DlError() ) );
2459     return false;
2460   }
2461
2462   /* SETTINGS */
2463   OSD_Function osdF = mySharedLibrary.DlSymb("SetSettings");
2464   if ( osdF != NULL )
2465     if (_islibso)
2466       {
2467         OneDim1 (*f1) = (bool (*) (QAD_Desktop*)) osdF;
2468         (*f1)(this);
2469       }
2470     else
2471       {
2472         OneDim2 (*f1) = (bool (*) (QAD_Desktop*, char*)) osdF;
2473         (*f1)(this, (char*)Component.latin1());
2474       }
2475
2476   
2477
2478   /* COMPONENT INTERFACE */
2479   SALOME_ModuleCatalog::Acomponent_ptr aComponent =
2480     myCatalogue->GetComponent(Component.latin1());
2481
2482   if (CORBA::is_nil (aComponent)) {
2483     MESSAGE( "Catalog Error : Component not found in the catalog" )
2484     return false;
2485   }
2486
2487   myActiveStudy->setMessage(QString("Component : ") +
2488                             aComponent->componentusername() + " created " );
2489   myActiveStudy->setMessage(QString("Type : ") +
2490                             QString::number(aComponent->component_type()));
2491   myActiveStudy->setMessage(QString("Constraint : ") +
2492                             aComponent->constraint() );
2493
2494   /* obtain interfaces list of the component */
2495   SALOME_ModuleCatalog::ListOfInterfaces_var _list =
2496     new SALOME_ModuleCatalog::ListOfInterfaces;
2497   _list = aComponent->GetInterfaceList();
2498
2499   if (_list->length() != 0 ) {
2500
2501     for (unsigned int ind = 0; ind < _list->length();ind++)
2502       myActiveStudy->setMessage( QString("Interface name : ") +
2503                                  _list[ind] );
2504
2505
2506     /* obtain services list of the component */
2507     SALOME_ModuleCatalog::ListOfServices_var list_services_component =
2508       new SALOME_ModuleCatalog::ListOfServices;
2509     list_services_component = aComponent->GetServiceList(_list[0]);
2510
2511     if (list_services_component->length() != 0 ) {
2512
2513       for (unsigned int ind = 0; ind < list_services_component->length();ind++)
2514         myActiveStudy->setMessage( QString("Service name : ") +
2515                                    list_services_component[ind] );
2516
2517       // Get a service of the component
2518       SALOME_ModuleCatalog::Service_var service = new SALOME_ModuleCatalog::Service;
2519       service  = aComponent->GetService(_list[0],list_services_component[0]) ;
2520       myActiveStudy->setMessage( QString("Service name: ") + service->ServiceName);
2521       for (unsigned int ind1 = 0; ind1 <service->ServiceinParameter.length();ind1++) {
2522         myActiveStudy->setMessage( QString("Type of the in Parameter of this service : ") +
2523                                    (const char *) service->ServiceinParameter[ind1].Parametertype);
2524         myActiveStudy->setMessage( QString("Name of the in Parameter of this service : ") +
2525                                    (const char *) service->ServiceinParameter[ind1].Parametername);
2526       }
2527       for (unsigned int ind1 = 0; ind1 <service->ServiceoutParameter.length();ind1++) {
2528         myActiveStudy->setMessage( QString("Type of the out Parameter of this service : ") +
2529                                    (const char *) service->ServiceoutParameter[ind1].Parametertype);
2530         myActiveStudy->setMessage( QString("Name of the out Parameter of this service : ") +
2531                                    (const char *) service->ServiceoutParameter[ind1].Parametername);
2532       }
2533     }
2534   }
2535   return true;
2536 }
2537
2538 typedef bool OneDim(int, QAD_Desktop*);
2539 typedef void (*PTR_FACTORY_FUNCTION)( CORBA::ORB_var &orb, QWidget *parent, const char *name ) ;
2540
2541 /*!
2542  */
2543 void QAD_Desktop::onDispatch()
2544 {
2545   const QObject* obj = sender();
2546
2547   QList<QAD_ListMenuIdAction> MenuList = myActiveMenus->getMenuList();
2548   QAD_ListMenuIdAction* aMenu;
2549   int id = -1;
2550   for(aMenu=MenuList.first();aMenu!=NULL;aMenu=MenuList.next()) {
2551     if (aMenu->getAction()==obj) {
2552       id = aMenu->getId();
2553       break;
2554     }
2555   }
2556   onDispatch(id);
2557 }
2558
2559 /*!
2560  */
2561 void QAD_Desktop::onDispatchTools(int id)
2562 {
2563   /* Open Shared Library */
2564   OSD_SharedLibrary ToolsLibrary = OSD_SharedLibrary();
2565
2566   QString ToolsLib;
2567   QCString dir;
2568   QFileInfo fileInfo ;
2569   bool found = false;
2570
2571   char arg[256] ;
2572   bool libToolsGUI = true;
2573   if( QAD_XmlHandler::_bibmap[ id ].isEmpty() ) 
2574   { 
2575
2576     if ( dir = getenv("SALOME_SITE_DIR"))  {
2577       dir = QAD_Tools::addSlash(dir) ;
2578       dir = dir + "lib" ;
2579       dir = QAD_Tools::addSlash(dir) ;
2580       dir = dir + "salome" ;
2581       dir = QAD_Tools::addSlash(dir) ;
2582 #ifdef WNT
2583       dir = dir + "libToolsGUI.dll" ;
2584 #else
2585       dir = dir + "libToolsGUI.so" ;
2586 #endif
2587       MESSAGE ( " GUI library = " << dir );
2588       fileInfo.setFile(dir) ;
2589       if (fileInfo.exists()) {
2590         ToolsLib = fileInfo.fileName() ;
2591         found = true;
2592       }
2593     }
2594     
2595     if ( (dir = getenv("SALOME_ROOT_DIR")) && !found ) {
2596       dir = QAD_Tools::addSlash(dir) ;
2597       dir = dir + "lib" ;
2598       dir = QAD_Tools::addSlash(dir) ;
2599       dir = dir + "salome" ;
2600       dir = QAD_Tools::addSlash(dir) ;
2601 #ifdef WNT
2602       dir = dir + "libToolsGUI.dll" ;
2603 #else
2604       dir = dir + "libToolsGUI.so" ;
2605 #endif
2606       MESSAGE ( " GUI library = " << dir );
2607       fileInfo.setFile(dir) ;
2608       if (fileInfo.exists()) {
2609         ToolsLib = fileInfo.fileName() ;
2610         found = true;
2611       }
2612     }
2613     
2614     if ( (dir = getenv("KERNEL_ROOT_DIR")) && !found ) {
2615       dir = QAD_Tools::addSlash(dir) ;
2616       dir = dir + "lib" ;
2617       dir = QAD_Tools::addSlash(dir) ;
2618       dir = dir + "salome" ;
2619       dir = QAD_Tools::addSlash(dir) ;
2620 #ifdef WNT
2621       dir = dir + "libToolsGUI.dll" ;
2622 #else
2623       dir = dir + "libToolsGUI.so" ;
2624 #endif
2625       MESSAGE ( " GUI library = " << dir );
2626       fileInfo.setFile(dir) ;
2627       if (fileInfo.exists()) {
2628         ToolsLib = fileInfo.fileName() ;
2629         found = true;
2630       }
2631     }
2632   }
2633   else {
2634     libToolsGUI = false;
2635     SCRUTE( QAD_XmlHandler::_bibmap[ id ] ) ;
2636     if ( dir = getenv("SALOME_SITE_DIR"))  {
2637       dir = QAD_Tools::addSlash(dir) ;
2638       dir = dir + "lib" ;
2639       dir = QAD_Tools::addSlash(dir) ;
2640       dir = dir + "salome" ;
2641       dir = QAD_Tools::addSlash(dir) ;
2642       dir = dir + QAD_XmlHandler::_bibmap[ id ].latin1() ;
2643       MESSAGE ( " GUI library = " << dir );
2644       fileInfo.setFile(dir) ;
2645       if (fileInfo.exists()) {
2646         ToolsLib = fileInfo.fileName() ;
2647         found = true;
2648       }
2649     }
2650     
2651     if ( (dir = getenv("SALOME_ROOT_DIR")) && !found ) {
2652       dir = QAD_Tools::addSlash(dir) ;
2653       dir = dir + "lib" ;
2654       dir = QAD_Tools::addSlash(dir) ;
2655       dir = dir + "salome" ;
2656       dir = QAD_Tools::addSlash(dir) ;
2657       dir = dir + QAD_XmlHandler::_bibmap[ id ].latin1() ;
2658       MESSAGE ( " GUI library = " << dir );
2659       fileInfo.setFile(dir) ;
2660       if (fileInfo.exists()) {
2661         ToolsLib = fileInfo.fileName() ;
2662         found = true;
2663       }
2664     }
2665     
2666     if ( (dir = getenv("KERNEL_ROOT_DIR")) && !found ) {
2667       dir = QAD_Tools::addSlash(dir) ;
2668       dir = dir + "lib" ;
2669       dir = QAD_Tools::addSlash(dir) ;
2670       dir = dir + "salome" ;
2671       dir = QAD_Tools::addSlash(dir) ;
2672       dir = dir + QAD_XmlHandler::_bibmap[ id ].latin1() ;
2673       MESSAGE ( " GUI library = " << dir );
2674       fileInfo.setFile(dir) ;
2675       if (fileInfo.exists()) {
2676         ToolsLib = fileInfo.fileName() ;
2677         found = true;
2678       }
2679     }
2680   }
2681
2682   ToolsLibrary.SetName(TCollection_AsciiString((char*)ToolsLib.latin1()).ToCString());
2683   bool ok = ToolsLibrary.DlOpen(OSD_RTLD_LAZY);
2684   if (ok) {
2685     if ( libToolsGUI ) {
2686       OSD_Function osdF = ToolsLibrary.DlSymb("OnGUIEvent");
2687       OneDim (*f1) = NULL;
2688       f1 = (bool (*) (int, QAD_Desktop*)) osdF;
2689       (*f1)(id,this);
2690     } else {
2691       ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
2692       ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
2693       CORBA::ORB_var &orb = init(0 , 0 ) ;
2694       OSD_Function osdF = ToolsLibrary.DlSymb("OnGUIEvent");
2695       PTR_FACTORY_FUNCTION f1 = NULL;
2696       f1 = (PTR_FACTORY_FUNCTION) osdF;
2697       f1(orb,0,"Registry");
2698     }
2699   } else {
2700     QMessageBox::critical( this,
2701                            tr("ERR_ERROR"),
2702                            tr( ToolsLibrary.DlError() ) );
2703   }
2704 }
2705
2706 /*!
2707  */
2708 void QAD_Desktop::onDispatch(int id)
2709 {
2710   if (!myActiveComp.isEmpty())  {
2711     OSD_Function osdF = mySharedLibrary.DlSymb("OnGUIEvent");
2712     OneDim (*f1) = NULL;
2713     if ( osdF != NULL ) {
2714       f1 = (bool (*) (int, QAD_Desktop*)) osdF;
2715       (*f1)(id,this);
2716     }
2717   }
2718 }
2719
2720 /*!
2721   Returns the component's catalogue
2722 */
2723 SALOME_ModuleCatalog::ModuleCatalog_var QAD_Desktop::getCatalogue()
2724 {
2725   return myCatalogue;
2726 }
2727
2728 /*!
2729  */
2730 void QAD_Desktop::onComboActiveComponent( const QString & component ){
2731   onComboActiveComponent(component,true);
2732 }
2733 void QAD_Desktop::onComboActiveComponent( const QString & component, bool isLoadData)
2734 {
2735   if (myActiveStudy != 0) {
2736     if (myActiveComp.compare(component)!=0) {
2737       if (!myXmlHandler->myIdList.IsEmpty()) clearMenus();
2738       if ( myCombo->currentText() != component )
2739         myCombo->setCurrentText( component );
2740       //NRI if (component.compare(QString("Salome"))!= 0) {
2741       if (component.compare( getComponentUserName( "KERNEL" ) )!= 0) {
2742 //      QApplication::setOverrideCursor( Qt::waitCursor );
2743         myActiveComp = component;
2744
2745         SALOME_Selection* oldSel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2746
2747         for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2748           if ( aButton->textLabel().compare(component)==0)
2749             aButton->setOn(true);
2750           else
2751             aButton->setOn(false);
2752         }
2753
2754         myActiveStudy->Selection( component );
2755         if ( !loadComponent(mapComponentName[component]) ) {
2756           myCombo->setCurrentItem (0);
2757           for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2758             aButton->setOn(false);
2759           }
2760           myActiveComp = "";
2761         }
2762
2763         SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2764         SALOME_ListIteratorOfListIO It( oldSel->StoredIObjects() );
2765         for(;It.More();It.Next()) {
2766           int res = Sel->AddIObject( It.Value() );
2767
2768           if ( res == -1 )
2769             myActiveStudy->highlight( It.Value(), false );
2770           if ( res == 0 )
2771             myActiveStudy->highlight( It.Value(), true );
2772           
2773         }
2774
2775         // Open new component's data in active study if any
2776         if(isLoadData) loadComponentData(mapComponentName[component]);
2777
2778         oldSel->Clear();
2779         myActiveStudy->updateObjBrowser(true);
2780
2781 //      QApplication::restoreOverrideCursor();
2782
2783       } else {  // component == "Salome"
2784         myActiveComp = "";
2785         //NRI   myActiveStudy->Selection( "Salome" );
2786         myActiveStudy->Selection( getComponentUserName( "KERNEL" ) );
2787         SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2788         Sel->ClearIObjects();
2789         for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2790           aButton->setOn(false);
2791         }
2792       }
2793     } else {
2794       for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2795         if ( aButton->textLabel().compare(component)==0)
2796           aButton->setOn(true);
2797       }
2798     }
2799   } else {
2800     QMessageBox::critical( 0,
2801                            tr( "ERR_ERROR" ),
2802                            tr( "WRN_LOAD_COMPONENT" ) );
2803     myCombo->setCurrentItem (0);        
2804     for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2805       aButton->setOn(false);
2806     }
2807   }
2808 }
2809
2810 /*!
2811  */
2812 void QAD_Desktop::activateComponent(const QString& theName, bool isLoadData){
2813   int nbItem = myCombo->count();
2814   int Index = 0;
2815
2816   for (int i = 0; i < nbItem; i++) {
2817     if (myCombo->text(i).compare(theName)==0) {
2818       Index = i;
2819       break;
2820     }
2821   }
2822   myCombo->setCurrentItem (Index);
2823   onComboActiveComponent(theName,isLoadData);
2824 };
2825
2826 void QAD_Desktop::onButtonActiveComponent( )
2827 {
2828   QToolButton* obj = (QToolButton*)sender();
2829   activateComponent(obj->textLabel());
2830 }
2831
2832 /*!
2833   Clears All Resources of current component
2834  */
2835 void QAD_Desktop::clearMenus()
2836 {
2837   onActiveStudyChanged();
2838
2839   /* menus */
2840   myMenusList.clear();
2841   if (myXmlHandler) {
2842     int length = myXmlHandler->myIdList.Length();
2843     for (int k=length; k>0; k--) {
2844       QMenuData* parent;
2845       if ( menuBar()->findItem(myXmlHandler->myIdList.Value(k), &parent) )
2846         parent->removeItem( myXmlHandler->myIdList.Value(k) );
2847     }
2848   }
2849
2850   /* toolbars */
2851   if (myActiveMenus) {
2852     int nbtoolbars = myActiveMenus->getToolBarList().count();
2853     for (int k=0; k<nbtoolbars; k++) {
2854       myActiveMenus->getToolBarList().at(k)->hide();
2855       myActiveMenus->getToolBarList().at(k)->clear();
2856     }
2857     myActiveMenus->clearToolBar();
2858
2859     /* popups */
2860     QList<QAD_ListPopupMenu> PopupList = myActiveMenus->getPopupMenuList();
2861     QAD_ListPopupMenu* aPopup;
2862     for(aPopup=PopupList.first();aPopup!=NULL;aPopup=PopupList.next()){
2863       aPopup->getPopup()->clear();
2864       
2865     }
2866     myActiveMenus->clearPopupMenu();
2867
2868   }
2869   myActiveComp = "";
2870 }
2871
2872 typedef bool TwoDim1(QKeyEvent* pe, QAD_Desktop*, QAD_StudyFrame*);
2873 /*!
2874   Exports Key Events in active component ( GUI Librairy )
2875  */
2876 void QAD_Desktop::onKeyPress( QKeyEvent* pe )
2877 {
2878   //  MESSAGE ( "QAD_Desktop::onKeyPress" )
2879   if (!myActiveComp.isEmpty())  {
2880     OSD_Function osdF = mySharedLibrary.DlSymb("OnKeyPress");
2881     if ( osdF != NULL ) {
2882       TwoDim1 (*f1) = (bool (*) (QKeyEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
2883       (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
2884     }
2885   }
2886 }
2887
2888 typedef bool TwoDim(QMouseEvent* pe, QAD_Desktop*, QAD_StudyFrame*);
2889 /*!
2890   Exports Mouse Press Events in active component ( GUI Librairy )
2891  */
2892 bool QAD_Desktop::onMousePress( QMouseEvent* pe )
2893 {
2894   //  MESSAGE ( "QAD_Desktop::onMousePress" )
2895   if (!myActiveComp.isEmpty())  {
2896     OSD_Function osdF = mySharedLibrary.DlSymb("OnMousePress");
2897     if ( osdF != NULL ) {
2898       TwoDim (*f1) = (bool (*) (QMouseEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
2899       return (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
2900     }
2901   }
2902   return false;
2903 }
2904
2905 /*!
2906   Exports Mouse Move Events in active component ( GUI Librairy )
2907  */
2908 void QAD_Desktop::onMouseMove( QMouseEvent* pe )
2909 {
2910   if (!myActiveComp.isEmpty())  {
2911     OSD_Function osdF = mySharedLibrary.DlSymb("OnMouseMove");
2912     if ( osdF != NULL ) {
2913       TwoDim (*f1) = (bool (*) (QMouseEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
2914       (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
2915     }
2916   }
2917 }
2918
2919 /*!
2920     Returns name of active component
2921 */
2922 const QString& QAD_Desktop::getActiveComponent() const
2923 {
2924   return myActiveComp;
2925 }
2926
2927
2928 typedef bool defineP( QString & theContext, QString & theParent, QString & theObject);
2929
2930 void QAD_Desktop::definePopup(QString & theContext,
2931                               QString & theParent, 
2932                               QString & theObject ) 
2933 {
2934   if (!myActiveComp.isEmpty())  {
2935     OSD_Function osdF = mySharedLibrary.DlSymb("definePopup");
2936     if ( osdF != NULL ) {
2937       defineP (*f1) = (bool (*) (QString &, QString &, QString &)) osdF;
2938       (*f1)(theContext, theParent, theObject);
2939     }
2940   }
2941 }
2942
2943 /*!
2944     Create popup
2945 */
2946 void QAD_Desktop::createPopup(QPopupMenu* popupFather, QPopupMenu* popup,
2947                               QString text, int popupID, bool separator)
2948 {
2949   QMenuItem* item = popup->findItem(popupID);
2950   if (item) {
2951     QPopupMenu* popupChild = item->popup();
2952     if ( popupChild ) {
2953       QPopupMenu* newPopup = new QPopupMenu;
2954       int count = popupChild->count();
2955       // add items at the top of <popupFather>
2956       for (int i = count - 1; i >= 0; i--) {
2957         int j = popupChild->idAt(i);
2958         QString text = popupChild->text(j);
2959         createPopup( newPopup, popupChild, text, j);
2960       }
2961       popupFather->insertItem(popup->text(popupID),
2962                               newPopup, popupID, 0);
2963     } else {
2964       if ( !text.isNull() ) {
2965         popupFather->insertItem(popup->text(popupID),
2966                                 this,
2967                                 SLOT( onDispatch(int) ), 0, popupID, 0);// try adding item at the top
2968       } /*else if ( separator ) 
2969         popupFather->insertTearOffHandle(-1, 0);*/
2970       else
2971         popupFather->insertSeparator(0);
2972     }
2973   }
2974 }
2975
2976 /*!
2977     Create popup
2978 */
2979 void QAD_Desktop::createPopup(QPopupMenu* popup, const QString & theContext,
2980                               const QString & theParent, const QString & theObject )
2981 {
2982   if ( !myActiveComp.isEmpty() && 
2983        getOperatorMenus()->createPopupMenu(theContext,theParent,theObject) != NULL ) {
2984     QPopupMenu* aPopup = getOperatorMenus()->createPopupMenu(theContext,theParent,theObject)->getPopup();
2985     int count = aPopup->count();
2986
2987     //for (int i = 0; i < count; i++) {
2988     for (int i = count - 1; i >= 0; i--) {
2989       int id = aPopup->idAt(i);
2990       QString text = aPopup->text(id);
2991       //QString mes("Inserting popup menu item loaded from XML: ");
2992       //mes += text;
2993       //MESSAGE ( mes.latin1() )
2994       if (i==0)
2995         popup->insertItem(aPopup->text(id),
2996                           this,
2997                           SLOT( onDispatch(int) ), 0, id, 0);// try adding item at the top
2998       else
2999         createPopup( popup, aPopup, text, id);
3000     }
3001   } //else {
3002     //QString mes("Popup does not exist for given (Context = ");
3003     //mes += theContext;
3004     //mes += ", Parent = ";
3005     //mes += theParent;
3006     //mes += ", Object = ";
3007     //mes += theObject;
3008     //MESSAGE (mes.latin1())
3009       //popup->clear();
3010   //}
3011
3012   // IAPP Popup 
3013   // Should be moved to SALOMEGUI_Application::onCreatePopup()...
3014   if ( myActiveComp.isEmpty() ) {
3015     popup->removeItem(QAD_Display_Popup_ID);
3016     popup->removeItem(QAD_DisplayOnly_Popup_ID);
3017     popup->removeItem(QAD_Erase_Popup_ID);
3018     int id = popup->idAt(popup->count()-1); // last item
3019     if (id < 0 && id != -1) popup->removeItem(id); // separator
3020
3021     if ( popup && theParent.compare("ObjectBrowser")==0 ) {
3022       if ( popup->count()>0 ) {
3023         popup->insertItem (tr ("MEN_OPENWITH"), this, SLOT(onOpenWith()), 0, -1, 2);
3024         popup->insertSeparator (3);
3025       }
3026       else {
3027         popup->insertItem (tr ("MEN_OPENWITH"), this, SLOT(onOpenWith()) );
3028       }
3029     } 
3030   }
3031  
3032 }
3033
3034 typedef bool activeStudyChanged(QAD_Desktop*);
3035
3036 void QAD_Desktop::onActiveStudyChanged()
3037 {
3038   if (!myActiveComp.isEmpty())  {
3039     OSD_Function osdF = mySharedLibrary.DlSymb("activeStudyChanged");
3040     if ( osdF != NULL ) {
3041       activeStudyChanged (*f1) = (bool (*) (QAD_Desktop*)) osdF;
3042       (*f1)(this);
3043     }  
3044   }
3045 }
3046
3047 typedef bool customP(QAD_Desktop*, QPopupMenu*, const QString & theContext,
3048                      const QString & theParent, const QString & theObject);
3049 /*!
3050   Custom popup ( GUI Library )
3051 */
3052 void QAD_Desktop::customPopup(QPopupMenu* popup, const QString & theContext,
3053                               const QString & theParent, const QString & theObject)
3054 {
3055   if (!myActiveComp.isEmpty())  {
3056     OSD_Function osdF = mySharedLibrary.DlSymb("customPopup");
3057     if ( osdF != NULL ) {
3058       customP (*f1) = (bool (*) (QAD_Desktop*, QPopupMenu*, const QString &,
3059                                  const QString &, const QString &)) osdF;
3060       (*f1)(this, popup, theContext, theParent, theObject);
3061     }
3062   }
3063 }
3064
3065 void QAD_Desktop::onObjectBrowser()
3066 {
3067   bool checkDiff = false;
3068
3069   bool state  = QAD_CONFIG->getSetting("ObjectBrowser:AddColumn").compare("true") == 0;
3070
3071   if ( myStdActions.at( PrefObjectBrowserEntryId )->isOn() != state )
3072     checkDiff = true;
3073
3074   bool showEntry;
3075   if ( myStdActions.at( PrefObjectBrowserEntryId )->isOn() ) {
3076     showEntry = true;
3077     QAD_CONFIG->addSetting( "ObjectBrowser:AddColumn", "true");
3078   } else {
3079     showEntry = false;
3080     QAD_CONFIG->addSetting( "ObjectBrowser:AddColumn", "false");
3081   }  
3082
3083   bool showValue;
3084   if ( myStdActions.at( PrefObjectBrowserValueId )->isOn() ) {
3085     showValue = true;
3086     QAD_CONFIG->addSetting( "ObjectBrowser:ValueColumn", "true");
3087   } else {
3088     showValue = false;
3089     QAD_CONFIG->addSetting( "ObjectBrowser:ValueColumn", "false");
3090   }  
3091
3092   bool showIAPP;
3093   if ( myStdActions.at( PrefObjectBrowserIAPPId )->isOn() ) {
3094     showIAPP = true;
3095     QAD_CONFIG->addSetting( "ObjectBrowser:IAPP", "true");
3096   } else {
3097     showIAPP = false;
3098     QAD_CONFIG->addSetting( "ObjectBrowser:IAPP", "false");
3099   }  
3100   
3101   /* To sort created object in chrono order or reverse chrono order */
3102   bool showCHRONO_SORT ;
3103   if ( myStdActions.at( PrefObjectBrowserCHRONO_SORTId )->isOn() ) {
3104     showCHRONO_SORT = true;
3105     QAD_CONFIG->addSetting( "ObjectBrowser:CHRONO_SORT", "true");
3106   } else {
3107     showCHRONO_SORT = false;
3108     QAD_CONFIG->addSetting( "ObjectBrowser:CHRONO_SORT", "false");
3109   }
3110
3111   if ( myActiveApp ) {
3112     QList<QAD_Study>& studies = myActiveApp->getStudies();
3113     for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
3114       int nbSf = study->getStudyFramesCount();
3115       for ( int i = 0; i < nbSf; i++ ) {
3116         QAD_StudyFrame* sf = study->getStudyFrame(i);
3117         sf->getLeftFrame()->getObjectBrowser()->setShowInfoColumns( showEntry );
3118         sf->getLeftFrame()->getObjectBrowser()->setShowValueColumn( showValue );
3119         sf->getLeftFrame()->getObjectBrowser()->setEnableChronoSort( showCHRONO_SORT );
3120 //      sf->getLeftFrame()->getObjectBrowser()->setShowIAPP( showIAPP ); // this is done by below updateObjBrowser() call
3121       }
3122       study->updateObjBrowser(true);
3123     }
3124   }
3125 }
3126
3127 void QAD_Desktop::onViewerTrihedron()
3128 {
3129   QString Size = QAD_CONFIG->getSetting("Viewer:TrihedronSize");
3130   float dim;
3131
3132   SALOMEGUI_TrihedronSizeDlg *Dlg = new SALOMEGUI_TrihedronSizeDlg(this);
3133   if (!Size.isEmpty())
3134     Dlg->setTrihedronSize(Size.toInt());
3135   int r = Dlg->exec();
3136   dim = Dlg->getTrihedronSize();
3137   delete Dlg;
3138   
3139   if (r == QDialog::Accepted) {
3140     QAD_CONFIG->addSetting("Viewer:TrihedronSize", dim);
3141
3142     if( myActiveApp ) {
3143       QList<QAD_Study>& studies = myActiveApp->getStudies();
3144       for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
3145         int nbSf = study->getStudyFramesCount();
3146         for ( int i = 0; i < nbSf; i++ ) {
3147           study->getStudyFrame(i)->getRightFrame()->getViewFrame()->SetTrihedronSize((int)dim);
3148         }
3149       }
3150     }
3151   }
3152 }
3153
3154 void QAD_Desktop::onDirList() 
3155 {
3156   // getting dir list from settings
3157   QStringList dirList = QStringList::split(';', QAD_CONFIG->getSetting("FileDlg:QuickDirList"), false);
3158   QAD_DirListDlg* dlg = new QAD_DirListDlg(this);
3159   dlg->setPathList(dirList);
3160   if ( dlg->exec() == QDialog::Accepted) {
3161     dlg->getPathList(dirList);
3162     QAD_CONFIG->addSetting("FileDlg:QuickDirList", dirList.join(";"));
3163   }
3164   delete dlg;
3165 }
3166
3167 void QAD_Desktop::onConsoleFontAction()
3168 {
3169   // getting font from settings
3170   QString fntSet = QAD_CONFIG->getSetting("Viewer:ConsoleFont");
3171   QFont font = QAD_Tools::stringToFont( fntSet );
3172   bool bOk;
3173   font = QFontDialog::getFont( &bOk, font, this );
3174   if ( bOk ) {
3175     fntSet = QAD_Tools::fontToString( font );
3176     QAD_CONFIG->addSetting("Viewer:ConsoleFont", fntSet );
3177
3178     if( myActiveApp ) {
3179       QList<QAD_Study>& studies = myActiveApp->getStudies();
3180       for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
3181         int nbSf = study->getStudyFramesCount();
3182         for ( int i = 0; i < nbSf; i++ ) {
3183           study->getStudyFrame(i)->getRightFrame()->getPyEditor()->setFont( font );
3184           study->getStudyFrame(i)->getRightFrame()->getMessage()->setFont( font );
3185         }
3186       }
3187     }
3188   }
3189 }
3190
3191 void QAD_Desktop::onSavePref()
3192 {
3193   QAD_CONFIG->createConfigFile(true);
3194 }
3195
3196 //VRV: T2.5 - add default viewer
3197 void QAD_Desktop::onDefaultViewer(QActionP * theAction)
3198 {
3199   int type = VIEW_TYPE_MAX;
3200   
3201   QString myValue;
3202   if (myStdActions.at(DefaultViewerOCCId) == theAction)
3203     type = VIEW_OCC;
3204   else if (myStdActions.at(DefaultViewerVTKId) == theAction)
3205     type = VIEW_VTK;
3206   else if (myStdActions.at(DefaultGraphSupervisorId) == theAction)
3207     type = VIEW_GRAPHSUPERV;
3208   else if (myStdActions.at(DefaultPlot2dId) == theAction)
3209     type = VIEW_PLOT2D;
3210   if ( type != VIEW_TYPE_MAX )
3211     QAD_CONFIG->addSetting( "Viewer:DefaultViewer", QString::number( type ) );
3212 }
3213 //VRV: T2.5 - add default viewer
3214
3215 void QAD_Desktop::onViewerOCC()
3216 {
3217   QString BackgroundColorRed   = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorRed");
3218   QString BackgroundColorGreen = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorGreen");
3219   QString BackgroundColorBlue  = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorBlue");
3220   QColor color;
3221
3222   if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3223     color = QColor(BackgroundColorRed.toInt(),
3224                    BackgroundColorGreen.toInt(),
3225                    BackgroundColorBlue.toInt());
3226   else
3227     color = QColor(35, 136, 145);
3228
3229   QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3230
3231   if (c.isValid()) {
3232     if ( myActiveApp ) {
3233       QList<QAD_Study>& studies = myActiveApp->getStudies();
3234       for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
3235         int nbSf = study->getStudyFramesCount();
3236         for ( int i = 0; i < nbSf; i++ ) {
3237           QAD_StudyFrame* sf = study->getStudyFrame(i);
3238           if ( sf->getTypeView() == VIEW_OCC ) {
3239             sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3240           }
3241         }
3242       }
3243     }
3244     QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorRed",   c.red() );
3245     QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorGreen", c.green() );
3246     QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorBlue",  c.blue() );
3247   }
3248 }
3249
3250 void QAD_Desktop::onGraphSupervisor()
3251 {
3252   QString BackgroundColorRed   = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorRed");
3253   QString BackgroundColorGreen = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorGreen");
3254   QString BackgroundColorBlue  = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorBlue");
3255   QColor color;
3256
3257   if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3258     color = QColor(BackgroundColorRed.toInt(),
3259                    BackgroundColorGreen.toInt(),
3260                    BackgroundColorBlue.toInt());
3261   else
3262     color = QColor(35, 136, 145);
3263
3264   QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3265
3266   if (c.isValid()) {
3267     if ( myActiveApp ) {
3268       QList<QAD_Study>& studies = myActiveApp->getStudies();
3269       for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
3270         int nbSf = study->getStudyFramesCount();
3271         for ( int i = 0; i < nbSf; i++ ) {
3272           QAD_StudyFrame* sf = study->getStudyFrame(i);
3273           if ( sf->getTypeView() == VIEW_GRAPHSUPERV ) {
3274             sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3275           }
3276         }
3277       }
3278     }
3279     
3280     QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorRed",   c.red() );
3281     QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorGreen", c.green() );
3282     QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorBlue",  c.blue() );
3283   }
3284 }
3285
3286 void QAD_Desktop::onViewerVTK()
3287 {
3288   QString BackgroundColorRed   = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorRed");
3289   QString BackgroundColorGreen = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorGreen");
3290   QString BackgroundColorBlue  = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorBlue");
3291   QColor color;
3292
3293   if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3294     color = QColor(BackgroundColorRed.toInt(),
3295                    BackgroundColorGreen.toInt(),
3296                    BackgroundColorBlue.toInt());
3297   else
3298     color = QColor(0, 0, 0);
3299
3300   QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3301
3302   if (c.isValid()) {
3303     if ( myActiveApp ) {
3304       QList<QAD_Study>& studies = myActiveApp->getStudies();
3305       for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
3306         int nbSf = study->getStudyFramesCount();
3307         for ( int i = 0; i < nbSf; i++ ) {
3308           QAD_StudyFrame* sf = study->getStudyFrame(i);
3309           if ( sf->getTypeView() == VIEW_VTK ) {
3310             sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3311           }
3312         }
3313       }
3314     }
3315     
3316     QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorRed",   c.red() );
3317     QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorGreen", c.green() );
3318     QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorBlue",  c.blue() );
3319   }
3320 }
3321
3322 void QAD_Desktop::onPlot2d()
3323 {
3324   QColor color;
3325   if ( QAD_CONFIG->hasSetting( "Plot2d:Background" ) ) {
3326     QString bgString = QAD_CONFIG->getSetting( "Plot2d:Background" );                               
3327     QStringList bgData = QStringList::split( ":", bgString, true );
3328     int bgRed = 0, bgGreen = 0, bgBlue = 0;
3329     if ( bgData.count() > 0 ) bgRed   = bgData[ 0 ].toInt();
3330     if ( bgData.count() > 1 ) bgGreen = bgData[ 1 ].toInt();
3331     if ( bgData.count() > 2 ) bgBlue  = bgData[ 2 ].toInt();
3332     color = QColor( bgRed, bgGreen, bgBlue );
3333   }
3334   else {
3335     color = QColor(0, 0, 0);  
3336   }
3337
3338   color = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3339
3340   if ( color.isValid() ) {
3341     if ( myActiveApp ) {
3342       QList<QAD_Study>& studies = myActiveApp->getStudies();
3343       for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
3344         int nbSf = study->getStudyFramesCount();
3345         for ( int i = 0; i < nbSf; i++ ) {
3346           QAD_StudyFrame* sf = study->getStudyFrame(i);
3347           if ( sf->getTypeView() == VIEW_PLOT2D ) {
3348             sf->getRightFrame()->getViewFrame()->setBackgroundColor( color );
3349           }
3350         }
3351       }
3352     }
3353     QStringList bgData; 
3354     bgData.append( QString::number( color.red() ) );
3355     bgData.append( QString::number( color.green() ) );
3356     bgData.append( QString::number( color.blue() ) );
3357     QAD_CONFIG->addSetting( "Plot2d:Background", bgData.join( ":" ) );
3358   }
3359 }
3360
3361 /* Help About */
3362 void QAD_Desktop::helpAbout()
3363 {
3364   SALOMEGUI_AboutDlg* About = new SALOMEGUI_AboutDlg( QAD_Application::getDesktop(), tr("MEN_ABOUT"));
3365   About->exec();
3366   delete About;
3367 }
3368
3369 /* Help Search */
3370 void QAD_Desktop::helpSearch()
3371 {
3372 }
3373
3374 /* Help Contents */
3375 void QAD_Desktop::helpContents()
3376 {
3377   if (myActiveComp == "")
3378     myActiveComp = getComponentUserName( "KERNEL" ); //NRI "Salome";
3379
3380   QCString dir;
3381   QString root;
3382   if (dir = getenv( getComponentName( myActiveComp ) + "_ROOT_DIR")) {
3383     root = QAD_Tools::addSlash( QAD_Tools::addSlash(dir) + QAD_Tools::addSlash("share")  + QAD_Tools::addSlash("salome")  + "doc" );
3384     if ( QFileInfo( root + "index.html" ).exists() ) {
3385       helpContext( root + "index.html", "" );
3386     }
3387     else {
3388       root = QAD_Tools::addSlash( root + "html" );
3389       if ( QFileInfo( root + "index.html" ).exists() ) {
3390         helpContext( root + "index.html", "" );
3391       }
3392       else {
3393         root = QAD_Tools::addSlash( root + "html" );
3394         if ( QFileInfo( root + "index.html" ).exists() ) {
3395           helpContext( root + "index.html", "" );
3396         }
3397       }
3398     }
3399   }
3400   
3401   //NRI getHelpWindow()->contents();
3402   getHelpWindow()->show();
3403   getHelpWindow()->raise();
3404   getHelpWindow()->setActiveWindow();
3405 }
3406
3407 /* Help Context */
3408 void QAD_Desktop::helpContext(const QString& source, const QString& context)
3409 {
3410   getHelpWindow()->context(source, context);
3411   getHelpWindow()->show();
3412   getHelpWindow()->raise();
3413   getHelpWindow()->setActiveWindow();
3414 }
3415
3416 /* Preferences/MultiFile Save */
3417 void QAD_Desktop::onMultiFileSave()
3418 {
3419   if ( myStdActions.at( PrefMultiFileSave )->isOn() )
3420     QAD_CONFIG->addSetting( "Desktop:MultiFileSave", "true");
3421   else
3422     QAD_CONFIG->addSetting( "Desktop:MultiFileSave", "false");
3423 }
3424
3425 /* Preferences/ASCII Save */
3426 void QAD_Desktop::onASCIISave()
3427 {
3428   if ( myStdActions.at( PrefASCIISave )->isOn() )
3429     QAD_CONFIG->addSetting( "Desktop:ASCIISave", "true");
3430   else
3431     QAD_CONFIG->addSetting( "Desktop:ASCIISave", "false");
3432 }
3433
3434 /*********************************************************************
3435 ** Class: AppSelectionDlg
3436 ** Descr: Dialog for the selection of the application when several
3437 **        applications exist in the desktop and new study creation
3438 **        is activated by user.
3439 ** Level: Internal
3440 **********************************************************************/
3441 /*!
3442   \class Desktop_AppSelectionDlg QAD_Desktop.h
3443   \brief Dialog for the selection of the application when several
3444   applications exist in the desktop and new study creation
3445   is activated by user.
3446
3447   Level: Internal.
3448 */
3449
3450 Desktop_AppSelectionDlg::Desktop_AppSelectionDlg( QAD_Desktop* desktop,
3451                                                   QList<QAD_Application>& apps ) :
3452 QDialog( desktop, 0, true ),
3453 myAppId( 0 ),
3454 myApps( apps )
3455 {
3456     QAD_ASSERT_DEBUG_ONLY ( desktop );
3457     setCaption( tr("INF_DESK_DOC_CREATE") );
3458     if ( desktop->icon() )
3459     setIcon( *desktop->icon() );
3460
3461     QBoxLayout* mainLayout = new QVBoxLayout( this, 5 );
3462
3463     /* Create selection buttons */
3464     QVButtonGroup* buttonGrp = new QVButtonGroup ( this );
3465     buttonGrp->setExclusive ( true );
3466     QBoxLayout* vLayout = new QVBoxLayout( mainLayout, 5 );
3467     vLayout->addWidget ( buttonGrp );
3468
3469     /* Create selection button for available app */
3470     unsigned id = 0;
3471     for ( QAD_Application* app = myApps.first(); app; app = myApps.next(), id++ )
3472     {
3473         /* add radio button for application */
3474         buttonGrp->insert( new QRadioButton( app->getStudyDescription() +
3475                            " (*." + app->getStudyExtension() + ")", buttonGrp ), id );
3476     }
3477
3478     /* make the first application selected */
3479     buttonGrp->setButton( 0 );
3480
3481     /* listen to the selection */
3482     QAD_ASSERT ( connect ( buttonGrp, SIGNAL(clicked(int)), this, SLOT(onAppSelected(int)) ));
3483
3484     /* Create OK/Cancel buttons
3485     */
3486     QBoxLayout* hLayout = new QHBoxLayout( mainLayout, 5 );
3487     QPushButton* buttonOK = new QPushButton( tr("BUT_OK"), this );
3488     QPushButton* buttonCancel = new QPushButton( tr("BUT_CANCEL"), this );
3489     QPushButton* buttonHelp = new QPushButton( tr("BUT_HELP"), this );
3490     buttonOK->setDefault( true );
3491
3492     hLayout->addStretch();
3493     hLayout->addWidget( buttonOK );
3494     hLayout->addWidget( buttonCancel );
3495     hLayout->addWidget( buttonHelp );
3496
3497     /* connect buttons */
3498     QAD_ASSERT ( connect( buttonOK, SIGNAL(clicked()), this, SLOT(accept())) );
3499     QAD_ASSERT ( connect( buttonCancel, SIGNAL(clicked()), this, SLOT(reject())) );
3500     QAD_ASSERT ( connect( buttonHelp, SIGNAL(clicked()), this, SLOT(onHelp())) );
3501
3502     /* disable resizing */
3503     setFixedSize( 0, 0 );
3504     setSizePolicy( QSizePolicy ( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
3505 }
3506
3507 Desktop_AppSelectionDlg::~Desktop_AppSelectionDlg()
3508 {
3509 }
3510
3511 QAD_Application* Desktop_AppSelectionDlg::selectedApp() const
3512 {
3513     return myApps.at( myAppId );
3514 }
3515
3516 void Desktop_AppSelectionDlg::resizeEvent( QResizeEvent* e )
3517 {
3518     QAD_Tools::centerWidget( this, parentWidget() );
3519 }
3520
3521 /*
3522  *  Slots
3523 */
3524 void Desktop_AppSelectionDlg::onAppSelected( int id )
3525 {
3526     myAppId = id;
3527 }
3528
3529 void Desktop_AppSelectionDlg::onHelp()
3530 {
3531 }
3532