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