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