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