Salome HOME
PR : KERNEL 5165
[modules/yacs.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             QString compusername = getComponentUserName(strdup(list_type_composants[ind]));
2482             if ( compusername.compare("") != 0 )
2483               aDlg->addComponent( compusername );
2484           }
2485           
2486           int retVal = aDlg->exec();
2487           ComponentSelected = aDlg->getComponent();
2488           delete aDlg;
2489           if ( retVal == QDialog::Rejected || ComponentSelected.isEmpty()) {
2490             return;
2491           }
2492         } else {
2493           MESSAGE( "No component with type : " << Comp->component_type() << " exists" );
2494           return;
2495         }
2496         
2497       } else {
2498         MESSAGE( "This component not exists in the catalog" );
2499         return;
2500       }
2501       
2502       QApplication::setOverrideCursor( Qt::waitCursor );
2503       Sel->ClearIObjects();
2504       
2505 //      if (loadComponentData(ComponentSelected)) {
2506         onComboActiveComponent(ComponentSelected);
2507 //      int nbItem = myCombo->count();
2508 //      int Index = 0;
2509 //      for (int i = 0; i < nbItem; i++) {
2510 //        if (myCombo->text(i).compare(ComponentSelected)==0) {
2511 //          Index = i;
2512 //          break;
2513 //        }
2514 //      }
2515 //      myCombo->setCurrentItem(Index);
2516 //      myActiveStudy->updateObjBrowser(true);
2517 //      }
2518     }
2519   }
2520   QApplication::restoreOverrideCursor();
2521 }
2522
2523 typedef bool OneDim1(QAD_Desktop*);
2524 typedef bool OneDim2(QAD_Desktop*, char*);
2525
2526 /*!
2527   Called to define settings of component.
2528 */
2529 void QAD_Desktop::setSettings()
2530 {
2531   if (!myActiveComp.isEmpty())  {
2532     OSD_Function osdF = mySharedLibrary.DlSymb("SetSettings");
2533     if ( osdF != NULL )
2534       if (_islibso)
2535         {
2536           OneDim1 (*f1) = (bool (*) (QAD_Desktop*)) osdF;
2537           (*f1)(this);
2538         }
2539       else
2540         {
2541           QString Component =mapComponentName[myActiveComp];
2542           OneDim2 (*f1) = (bool (*) (QAD_Desktop*, char*)) osdF;
2543           (*f1)(this, (char*)Component.latin1());
2544         }
2545   }
2546 }
2547
2548 /*!
2549   Called to load Component : xml resources and GUI librairy.
2550 */
2551 bool QAD_Desktop::loadComponent(QString Component)
2552 {
2553   QAD_WaitCursor wc;
2554   QString resDir("/");  //NRI : Pb under Windows
2555
2556   QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
2557   if ( resMgr ) {
2558     QString msg;
2559     if (!resMgr->loadResources( Component, msg ))
2560       {
2561         //NRI   QCString errMsg;
2562         //      errMsg.sprintf( "Do not load all resources for module %sGUI.\n" ,
2563         //              Component.latin1() );
2564         wc.stop();
2565         QMessageBox::warning( this, tr("WRN_WARNING"), msg, tr ("BUT_OK") );
2566         return false;
2567       }
2568   }
2569     
2570   /* Parse xml file */
2571   myXmlHandler = new QAD_XmlHandler();
2572   myXmlHandler->setMainWindow(this);
2573   if (!myXmlHandler->setComponent(resMgr->resources( Component ))) return false;
2574
2575   QString language = resMgr->language( Component );
2576
2577   QString ComponentXml = Component + "_" + language + ".xml";
2578   //ComponentXml = resMgr->resources(Component + "GUI") ;
2579   //ComponentXml = QAD_Tools::addSlash(ComponentXml) ;
2580   ComponentXml = QAD_Tools::addSlash( resMgr->findFile( ComponentXml, Component ) ) + ComponentXml;
2581   QFile file( ComponentXml );
2582
2583   if ( !file.exists() || !file.open( IO_ReadOnly ) )  {
2584     QString errMsg;
2585     errMsg.sprintf( "Cannot open xml file: %s\n.",
2586                     (file.name()).latin1() );
2587     wc.stop();
2588     QMessageBox::critical( this, tr("ERR_ERROR"), errMsg, tr ("BUT_OK") );
2589     return false;
2590   }
2591   file.close();
2592
2593   QXmlInputSource source( file );
2594   QXmlSimpleReader reader;
2595   reader.setContentHandler( myXmlHandler );
2596   reader.setErrorHandler( myXmlHandler );
2597
2598   bool IsMaxActStudy = myActiveStudy->getActiveStudyFrame()->isMaximized();
2599   if (IsMaxActStudy) {
2600     QString aSourceData = source.data();
2601     aSourceData = changeXmlInputSourceData( aSourceData, Component );
2602     source.setData(aSourceData);
2603   }
2604
2605   bool ok = reader.parse( source );
2606   file.close();
2607   if ( !ok ) {
2608     wc.stop();
2609     QMessageBox::critical( this,
2610                            tr( "INF_PARSE_ERROR" ),
2611                            tr( myXmlHandler->errorProtocol() ) );
2612     return false;
2613   }
2614
2615   myMenusList=myXmlHandler->myMenusList;
2616   myActiveMenus=myMenusList.at(0);
2617   myOperatorMenus->showMenuBar(0);
2618   myActiveMenus->showAllToolBars();
2619
2620   /* Components toolbars */
2621   int nbToolbars = 0;
2622   if (myActiveMenus)
2623     nbToolbars = myActiveMenus->getToolBarList().count();
2624   /* Open Shared Library */
2625   mySharedLibrary = OSD_SharedLibrary();
2626   _islibso = false;
2627
2628   QString ComponentLib;
2629   QCString libs;
2630   QFileInfo fileInfo ;
2631   QString fileString ;
2632   QString dir;
2633
2634   if ( libs = getenv("LD_LIBRARY_PATH")) {
2635     //    MESSAGE ( " LD_LIBRARY_PATH : " << libs );
2636     QStringList dirList = QStringList::split( SEPARATOR, libs, false ); // skip empty entries
2637     for ( int i = dirList.count()-1; i >= 0; i-- ) {
2638       dir = dirList[ i ];
2639 #ifdef WNT
2640       fileString = QAD_Tools::addSlash( dir ) + "lib" + Component + "GUI.dll" ;
2641 #else
2642       fileString = QAD_Tools::addSlash( dir ) + "lib" + Component + "GUI.so" ;
2643 #endif
2644     
2645       fileInfo.setFile(fileString) ;
2646       if (fileInfo.exists()) {
2647         //      MESSAGE ( " GUI library = " << fileString );
2648         ComponentLib = fileInfo.fileName() ;
2649         _islibso = true;
2650         break;
2651       }
2652     }
2653   }
2654
2655   if (!_islibso) // component GUI could be in PyQt, use generic library
2656     {
2657       MESSAGE("GUI library not found, trying generic library for PyQt GUI");
2658       bool found = false;
2659       if (dir = getenv("KERNEL_ROOT_DIR"))
2660         {
2661           dir = QAD_Tools::addSlash(dir) ;
2662           dir = dir + "lib" ;
2663           dir = QAD_Tools::addSlash(dir) ;
2664           dir = dir + "salome" ;
2665           dir = QAD_Tools::addSlash(dir) ;
2666 #ifdef WNT
2667           dir = dir + "libSalomePyQtcmodule.dll" ;
2668 #else
2669           dir = dir + "libSalomePyQtcmodule.so" ;
2670 #endif
2671           MESSAGE ( " GUI library = " << dir );
2672           fileInfo.setFile(dir) ;
2673           if (fileInfo.exists())
2674             {
2675               ComponentLib = fileInfo.fileName() ;
2676               found = true;
2677             }
2678         }
2679       if ( !found )
2680         {
2681           QMessageBox::critical( this,
2682                                  tr("ERR_ERROR"),
2683                                  tr("ERR_LIBGUI" ).arg(Component) );
2684           return false;
2685         }
2686     }
2687
2688   mySharedLibrary.SetName(TCollection_AsciiString((char*)ComponentLib.latin1()).ToCString());
2689   ok = mySharedLibrary.DlOpen(OSD_RTLD_LAZY);
2690   if (!ok) {
2691     wc.stop();
2692     QMessageBox::critical( this,
2693                            tr("ERR_ERROR"),
2694                            tr( mySharedLibrary.DlError() ) );
2695     return false;
2696   }
2697
2698   /* SETTINGS */
2699   OSD_Function osdF = mySharedLibrary.DlSymb("SetSettings");
2700   if ( osdF != NULL )
2701     if (_islibso)
2702       {
2703         OneDim1 (*f1) = (bool (*) (QAD_Desktop*)) osdF;
2704         (*f1)(this);
2705       }
2706     else
2707       {
2708         OneDim2 (*f1) = (bool (*) (QAD_Desktop*, char*)) osdF;
2709         (*f1)(this, (char*)Component.latin1());
2710       }
2711
2712   
2713
2714   /* COMPONENT INTERFACE */
2715   SALOME_ModuleCatalog::Acomponent_ptr aComponent =
2716     myCatalogue->GetComponent(Component.latin1());
2717
2718   if (CORBA::is_nil (aComponent)) {
2719     MESSAGE( "Catalog Error : Component not found in the catalog" )
2720     return false;
2721   }
2722
2723   myActiveStudy->setMessage(QString("Component : ") +
2724                             aComponent->componentusername() + " created " );
2725   myActiveStudy->setMessage(QString("Type : ") +
2726                             QString::number(aComponent->component_type()));
2727   myActiveStudy->setMessage(QString("Constraint : ") +
2728                             aComponent->constraint() );
2729
2730   /* obtain interfaces list of the component */
2731   SALOME_ModuleCatalog::ListOfInterfaces_var _list =
2732     new SALOME_ModuleCatalog::ListOfInterfaces;
2733   _list = aComponent->GetInterfaceList();
2734
2735   if (_list->length() != 0 ) {
2736
2737     for (unsigned int ind = 0; ind < _list->length();ind++)
2738       myActiveStudy->setMessage( QString("Interface name : ") +
2739                                  _list[ind] );
2740
2741
2742     /* obtain services list of the component */
2743     SALOME_ModuleCatalog::ListOfServices_var list_services_component =
2744       new SALOME_ModuleCatalog::ListOfServices;
2745     list_services_component = aComponent->GetServiceList(_list[0]);
2746
2747     if (list_services_component->length() != 0 ) {
2748
2749       for (unsigned int ind = 0; ind < list_services_component->length();ind++)
2750         myActiveStudy->setMessage( QString("Service name : ") +
2751                                    list_services_component[ind] );
2752
2753       // Get a service of the component
2754       SALOME_ModuleCatalog::Service_var service = new SALOME_ModuleCatalog::Service;
2755       service  = aComponent->GetService(_list[0],list_services_component[0]) ;
2756       myActiveStudy->setMessage( QString("Service name: ") + service->ServiceName);
2757       for (unsigned int ind1 = 0; ind1 <service->ServiceinParameter.length();ind1++) {
2758         myActiveStudy->setMessage( QString("Type of the in Parameter of this service : ") +
2759                                    (const char *) service->ServiceinParameter[ind1].Parametertype);
2760         myActiveStudy->setMessage( QString("Name of the in Parameter of this service : ") +
2761                                    (const char *) service->ServiceinParameter[ind1].Parametername);
2762       }
2763       for (unsigned int ind1 = 0; ind1 <service->ServiceoutParameter.length();ind1++) {
2764         myActiveStudy->setMessage( QString("Type of the out Parameter of this service : ") +
2765                                    (const char *) service->ServiceoutParameter[ind1].Parametertype);
2766         myActiveStudy->setMessage( QString("Name of the out Parameter of this service : ") +
2767                                    (const char *) service->ServiceoutParameter[ind1].Parametername);
2768       }
2769     }
2770   }
2771   return true;
2772 }
2773
2774 QString QAD_Desktop::changeXmlInputSourceData(QString theData, QString theComponent) 
2775 {
2776   if ( theComponent=="Supervision" ) {
2777     //Supervision main menu item
2778     int aItemId = 300;
2779     int aPosId = 3;
2780     QString aStrOld = createString( aItemId, aPosId );
2781     QString aStrNew = createString( aItemId, aPosId+1 );
2782     theData = theData.replace( QRegExp(aStrOld), aStrNew );
2783   }
2784   
2785   if ( theComponent == "Visu" ) {
2786     //Visualization main menu item
2787     int aItemId = 401;
2788     int aPosId = 3;
2789     QString aStrOld = createString( aItemId, aPosId );
2790     QString aStrNew = createString( aItemId, aPosId+1 );
2791     theData = theData.replace( QRegExp(aStrOld), aStrNew );
2792
2793     //Selection main menu item
2794     aItemId = 41;
2795     aPosId = 4;
2796     aStrOld = createString( aItemId, aPosId );
2797     aStrNew = createString( aItemId, aPosId+1 );
2798     theData = theData.replace( QRegExp(aStrOld), aStrNew );
2799         
2800     //Representation main menu item
2801     aItemId = 42;
2802     aPosId = 5;
2803     aStrOld = createString( aItemId, aPosId );
2804     aStrNew = createString( aItemId, aPosId+1 );
2805     theData = theData.replace( QRegExp(aStrOld), aStrNew );
2806   }
2807
2808   if ( theComponent == "SMESH" ) {
2809     //Hypotheses main menu item
2810     int aItemId = 50;
2811     int aPosId = 3;
2812     QString aStrOld = createString( aItemId, aPosId );
2813     QString aStrNew = createString( aItemId, aPosId+1 );
2814     theData = theData.replace( QRegExp(aStrOld), aStrNew );
2815
2816     //Mesh main menu item
2817     aItemId = 70;
2818     aPosId = 4;
2819     aStrOld = createString( aItemId, aPosId );
2820     aStrNew = createString( aItemId, aPosId+1 );
2821     theData = theData.replace( QRegExp(aStrOld), aStrNew );
2822
2823     //Controls main menu item
2824     aItemId = 60;
2825     aPosId = 5;
2826     aStrOld = createString( aItemId, aPosId );
2827     aStrNew = createString( aItemId, aPosId+1 );
2828     theData = theData.replace( QRegExp(aStrOld), aStrNew );
2829
2830     //Modification main menu item
2831     aItemId = 40;
2832     aPosId = 6;
2833     aStrOld = createString( aItemId, aPosId );
2834     aStrNew = createString( aItemId, aPosId+1 );
2835     theData = theData.replace( QRegExp(aStrOld), aStrNew );
2836
2837     //Numbering main menu item
2838     aItemId = 80;
2839     aPosId = 7;
2840     aStrOld = createString( aItemId, aPosId );
2841     aStrNew = createString( aItemId, aPosId+1 );
2842     theData = theData.replace( QRegExp(aStrOld), aStrNew );
2843   }
2844   
2845   if ( theComponent == "Geometry" ) {
2846     //New Entity main menu item
2847     int aItemId = 70;
2848     int aPosId = 3;
2849     QString aStrOld = createString( aItemId, aPosId );
2850     QString aStrNew = createString( aItemId, aPosId+1 );
2851     theData = theData.replace( QRegExp(aStrOld), aStrNew );
2852
2853     //Operations main menu item
2854     aItemId = 40;
2855     aPosId = 4;
2856     aStrOld = createString( aItemId, aPosId );
2857     aStrNew = createString( aItemId, aPosId+1 );
2858     theData = theData.replace( QRegExp(aStrOld), aStrNew );
2859
2860     //Repair main menu item
2861     aItemId = 50;
2862     aPosId = 5;
2863     aStrOld = createString( aItemId, aPosId );
2864     aStrNew = createString( aItemId, aPosId+1 );
2865     theData = theData.replace( QRegExp(aStrOld), aStrNew );
2866
2867     //Measures main menu item
2868     aItemId = 60;
2869     aPosId = 6;
2870     aStrOld = createString( aItemId, aPosId );
2871     aStrNew = createString( aItemId, aPosId+1 );
2872     theData = theData.replace( QRegExp(aStrOld), aStrNew );
2873   }
2874
2875   if ( theComponent == "Med" ) {
2876     //MED main menu item
2877     int aItemId = 90;
2878     int aPosId = 3;
2879     QString aStrOld = createString( aItemId, aPosId );
2880     QString aStrNew = createString( aItemId, aPosId+1 );
2881     theData = theData.replace( QRegExp(aStrOld), aStrNew );
2882   }
2883   
2884   return theData;
2885 }
2886
2887 typedef bool OneDim(int, QAD_Desktop*);
2888 typedef void (*PTR_FACTORY_FUNCTION)( CORBA::ORB_var &orb, QWidget *parent, const char *name ) ;
2889
2890 /*!
2891  */
2892 void QAD_Desktop::onDispatch()
2893 {
2894   const QObject* obj = sender();
2895
2896   QList<QAD_ListMenuIdAction> MenuList = myActiveMenus->getMenuList();
2897   QAD_ListMenuIdAction* aMenu;
2898   int id = -1;
2899   for(aMenu=MenuList.first();aMenu!=NULL;aMenu=MenuList.next()) {
2900     if (aMenu->getAction()==obj) {
2901       id = aMenu->getId();
2902       break;
2903     }
2904   }
2905   onDispatch(id);
2906 }
2907
2908 /*!
2909  */
2910 void QAD_Desktop::onDispatchTools(int id)
2911 {
2912   /* Open Shared Library */
2913   OSD_SharedLibrary ToolsLibrary = OSD_SharedLibrary();
2914
2915   QString ToolsLib;
2916   QCString dir;
2917   QFileInfo fileInfo ;
2918   bool found = false;
2919
2920   char arg[256] ;
2921   bool libToolsGUI = true;
2922   if( QAD_XmlHandler::_bibmap[ id ].isEmpty() ) 
2923   { 
2924     if ( (dir = getenv("KERNEL_ROOT_DIR")) && !found ) {
2925       dir = QAD_Tools::addSlash(dir) ;
2926       dir = dir + "lib" ;
2927       dir = QAD_Tools::addSlash(dir) ;
2928       dir = dir + "salome" ;
2929       dir = QAD_Tools::addSlash(dir) ;
2930 #ifdef WNT
2931       dir = dir + "libToolsGUI.dll" ;
2932 #else
2933       dir = dir + "libToolsGUI.so" ;
2934 #endif
2935       MESSAGE ( " GUI library = " << dir );
2936       fileInfo.setFile(dir) ;
2937       if (fileInfo.exists()) {
2938         ToolsLib = fileInfo.fileName() ;
2939         found = true;
2940       }
2941     }
2942   }
2943   else {
2944     libToolsGUI = false;
2945     SCRUTE( QAD_XmlHandler::_bibmap[ id ] ) ;
2946     if ( (dir = getenv("KERNEL_ROOT_DIR")) && !found ) {
2947       dir = QAD_Tools::addSlash(dir) ;
2948       dir = dir + "lib" ;
2949       dir = QAD_Tools::addSlash(dir) ;
2950       dir = dir + "salome" ;
2951       dir = QAD_Tools::addSlash(dir) ;
2952       dir = dir + QAD_XmlHandler::_bibmap[ id ].latin1() ;
2953       MESSAGE ( " GUI library = " << dir );
2954       fileInfo.setFile(dir) ;
2955       if (fileInfo.exists()) {
2956         ToolsLib = fileInfo.fileName() ;
2957         found = true;
2958       }
2959     }
2960   }
2961
2962   ToolsLibrary.SetName(TCollection_AsciiString((char*)ToolsLib.latin1()).ToCString());
2963   bool ok = ToolsLibrary.DlOpen(OSD_RTLD_LAZY);
2964   if (ok) {
2965     if ( libToolsGUI ) {
2966       OSD_Function osdF = ToolsLibrary.DlSymb("OnGUIEvent");
2967       OneDim (*f1) = NULL;
2968       f1 = (bool (*) (int, QAD_Desktop*)) osdF;
2969       (*f1)(id,this);
2970     } else {
2971       ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
2972       ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
2973       CORBA::ORB_var &orb = init(0 , 0 ) ;
2974       OSD_Function osdF = ToolsLibrary.DlSymb("OnGUIEvent");
2975       PTR_FACTORY_FUNCTION f1 = NULL;
2976       f1 = (PTR_FACTORY_FUNCTION) osdF;
2977       f1(orb,0,"Registry");
2978     }
2979   } else {
2980     QMessageBox::critical( this,
2981                            tr("ERR_ERROR"),
2982                            tr( ToolsLibrary.DlError() ) );
2983   }
2984 }
2985
2986 /*!
2987  */
2988 void QAD_Desktop::onDispatch(int id)
2989 {
2990   if (!myActiveComp.isEmpty())  {
2991     OSD_Function osdF = mySharedLibrary.DlSymb("OnGUIEvent");
2992     OneDim (*f1) = NULL;
2993     if ( osdF != NULL ) {
2994       f1 = (bool (*) (int, QAD_Desktop*)) osdF;
2995       (*f1)(id,this);
2996     }
2997   }
2998 }
2999
3000 /*!
3001   Returns the component's catalogue
3002 */
3003 SALOME_ModuleCatalog::ModuleCatalog_var QAD_Desktop::getCatalogue()
3004 {
3005   return myCatalogue;
3006 }
3007
3008 /*!
3009  */
3010 void QAD_Desktop::onComboActiveComponent( const QString & component ){
3011   onComboActiveComponent(component,true);
3012 }
3013 void QAD_Desktop::onComboActiveComponent( const QString & component, bool isLoadData)
3014 {
3015   if (myActiveStudy != 0) {
3016     if (myActiveComp.compare(component)!=0) {
3017       if (!myXmlHandler->myIdList.IsEmpty()) clearMenus();
3018       if ( myCombo->currentText() != component )
3019         myCombo->setCurrentText( component );
3020       //NRI if (component.compare(QString("Salome"))!= 0) {
3021       if (component.compare( getComponentUserName( "KERNEL" ) )!= 0) {
3022 //      QApplication::setOverrideCursor( Qt::waitCursor );
3023         myActiveComp = component;
3024
3025         SALOME_Selection* oldSel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
3026
3027         for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
3028           if ( aButton->textLabel().compare(component)==0)
3029             aButton->setOn(true);
3030           else
3031             aButton->setOn(false);
3032         }
3033
3034         myActiveStudy->Selection( component );
3035         if ( !loadComponent(mapComponentName[component]) ) {
3036           myCombo->setCurrentItem (0);
3037           for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
3038             aButton->setOn(false);
3039           }
3040           myActiveComp = "";
3041         }
3042
3043         SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
3044         SALOME_ListIteratorOfListIO It( oldSel->StoredIObjects() );
3045         for(;It.More();It.Next()) {
3046           int res = Sel->AddIObject( It.Value() );
3047
3048           if ( res == -1 )
3049             myActiveStudy->highlight( It.Value(), false );
3050           if ( res == 0 )
3051             myActiveStudy->highlight( It.Value(), true );
3052           
3053         }
3054
3055         // Open new component's data in active study if any
3056         if(isLoadData) loadComponentData(mapComponentName[component]);
3057
3058         oldSel->Clear();
3059         myActiveStudy->updateObjBrowser(true);
3060
3061 //      QApplication::restoreOverrideCursor();
3062
3063       } else {  // component == "Salome"
3064         myActiveComp = "";
3065         //NRI   myActiveStudy->Selection( "Salome" );
3066         myActiveStudy->Selection( getComponentUserName( "KERNEL" ) );
3067         SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
3068         Sel->ClearIObjects();
3069         for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
3070           aButton->setOn(false);
3071         }
3072       }
3073     } else {
3074       for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
3075         if ( aButton->textLabel().compare(component)==0)
3076           aButton->setOn(true);
3077       }
3078     }
3079   } else if (component.compare(QString("Salome"))!= 0) {
3080   
3081       SALOMEGUI_ActivateComponentDlg aDlg( this );
3082       int res = aDlg.exec();
3083       
3084       switch ( res )
3085         {
3086         case 1:
3087           onNewStudy();
3088           onComboActiveComponent(component,true);                 
3089           break;
3090         case 2:
3091           onOpenStudy();        
3092           onComboActiveComponent(component,true);
3093           break;
3094         case 3:
3095           onLoadStudy();
3096           onComboActiveComponent(component,true);;
3097           break;
3098         case 0:
3099         default:
3100           putInfo( tr("INF_CANCELLED") );
3101           myCombo->setCurrentItem (0);  
3102           for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
3103           aButton->setOn(false);
3104           // return;
3105           }
3106         }
3107       }
3108 }
3109
3110 /*!
3111  */
3112 void QAD_Desktop::activateComponent(const QString& theName, bool isLoadData){
3113   
3114   int nbItem = myCombo->count();
3115   int Index = 0;
3116
3117   for (int i = 0; i < nbItem; i++) {
3118     if (myCombo->text(i).compare(theName)==0) {
3119       Index = i;
3120       break;
3121     }
3122   }
3123   myCombo->setCurrentItem (Index);
3124   onComboActiveComponent(theName,isLoadData);
3125 };
3126
3127 void QAD_Desktop::onButtonActiveComponent( )
3128 {
3129   QToolButton* obj = (QToolButton*)sender();
3130   activateComponent(obj->textLabel());
3131 }
3132
3133 /*!
3134   Clears All Resources of current component
3135  */
3136 void QAD_Desktop::clearMenus()
3137 {
3138   onActiveStudyChanged();
3139
3140   /* menus */
3141   myMenusList.clear();
3142   if (myXmlHandler) {
3143     int length = myXmlHandler->myIdList.Length();
3144     for (int k=length; k>0; k--) {
3145       QMenuData* parent;
3146       if ( menuBar()->findItem(myXmlHandler->myIdList.Value(k), &parent) )
3147         parent->removeItem( myXmlHandler->myIdList.Value(k) );
3148     }
3149   }
3150
3151   /* toolbars */
3152   if (myActiveMenus) {
3153     int nbtoolbars = myActiveMenus->getToolBarList().count();
3154     for (int k=0; k<nbtoolbars; k++) {
3155       myActiveMenus->getToolBarList().at(k)->hide();
3156       myActiveMenus->getToolBarList().at(k)->clear();
3157     }
3158     myActiveMenus->clearToolBar();
3159
3160     /* popups */
3161     QList<QAD_ListPopupMenu> PopupList = myActiveMenus->getPopupMenuList();
3162     QAD_ListPopupMenu* aPopup;
3163     for(aPopup=PopupList.first();aPopup!=NULL;aPopup=PopupList.next()){
3164       aPopup->getPopup()->clear();
3165       
3166     }
3167     myActiveMenus->clearPopupMenu();
3168
3169   }
3170   myActiveComp = "";
3171 }
3172
3173 typedef bool TwoDim1(QKeyEvent* pe, QAD_Desktop*, QAD_StudyFrame*);
3174 /*!
3175   Exports Key Events in active component ( GUI Librairy )
3176  */
3177 void QAD_Desktop::onKeyPress( QKeyEvent* pe )
3178 {
3179   //  MESSAGE ( "QAD_Desktop::onKeyPress" )
3180   if (!myActiveComp.isEmpty())  {
3181     OSD_Function osdF = mySharedLibrary.DlSymb("OnKeyPress");
3182     if ( osdF != NULL ) {
3183       TwoDim1 (*f1) = (bool (*) (QKeyEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
3184       (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
3185     }
3186   }
3187 }
3188
3189 typedef bool TwoDim(QMouseEvent* pe, QAD_Desktop*, QAD_StudyFrame*);
3190 /*!
3191   Exports Mouse Press Events in active component ( GUI Librairy )
3192  */
3193 bool QAD_Desktop::onMousePress( QMouseEvent* pe )
3194 {
3195   //  MESSAGE ( "QAD_Desktop::onMousePress" )
3196   if (!myActiveComp.isEmpty())  {
3197     OSD_Function osdF = mySharedLibrary.DlSymb("OnMousePress");
3198     if ( osdF != NULL ) {
3199       TwoDim (*f1) = (bool (*) (QMouseEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
3200       return (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
3201     }
3202   }
3203   return false;
3204 }
3205
3206 /*!
3207   Exports Mouse Move Events in active component ( GUI Librairy )
3208  */
3209 void QAD_Desktop::onMouseMove( QMouseEvent* pe )
3210 {
3211   if (!myActiveComp.isEmpty())  {
3212     OSD_Function osdF = mySharedLibrary.DlSymb("OnMouseMove");
3213     if ( osdF != NULL ) {
3214       TwoDim (*f1) = (bool (*) (QMouseEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
3215       (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
3216     }
3217   }
3218 }
3219
3220 /*!
3221     Returns name of active component
3222 */
3223 const QString& QAD_Desktop::getActiveComponent() const
3224 {
3225   return myActiveComp;
3226 }
3227
3228
3229 typedef bool defineP( QString & theContext, QString & theParent, QString & theObject);
3230
3231 void QAD_Desktop::definePopup(QString & theContext,
3232                               QString & theParent, 
3233                               QString & theObject ) 
3234 {
3235   if (!myActiveComp.isEmpty())  {
3236     OSD_Function osdF = mySharedLibrary.DlSymb("definePopup");
3237     if ( osdF != NULL ) {
3238       defineP (*f1) = (bool (*) (QString &, QString &, QString &)) osdF;
3239       (*f1)(theContext, theParent, theObject);
3240     }
3241   }
3242 }
3243
3244 /*!
3245     Create popup
3246 */
3247 void QAD_Desktop::createPopup(QPopupMenu* popupFather, QPopupMenu* popup,
3248                               QString text, int popupID, bool separator)
3249 {
3250   QMenuItem* item = popup->findItem(popupID);
3251   if (item) {
3252     QPopupMenu* popupChild = item->popup();
3253     if ( popupChild ) {
3254       QPopupMenu* newPopup = new QPopupMenu;
3255       int count = popupChild->count();
3256       // add items at the top of <popupFather>
3257       for (int i = count - 1; i >= 0; i--) {
3258         int j = popupChild->idAt(i);
3259         QString text = popupChild->text(j);
3260         createPopup( newPopup, popupChild, text, j);
3261       }
3262       popupFather->insertItem(popup->text(popupID),
3263                               newPopup, popupID, 0);
3264     } else {
3265       if ( !text.isNull() ) {
3266         popupFather->insertItem(popup->text(popupID),
3267                                 this,
3268                                 SLOT( onDispatch(int) ), 0, popupID, 0);// try adding item at the top
3269       } /*else if ( separator ) 
3270         popupFather->insertTearOffHandle(-1, 0);*/
3271       else
3272         popupFather->insertSeparator(0);
3273     }
3274   }
3275 }
3276
3277 /*!
3278     Create popup
3279 */
3280 void QAD_Desktop::createPopup(QPopupMenu* popup, const QString & theContext,
3281                               const QString & theParent, const QString & theObject )
3282 {
3283   if ( !myActiveComp.isEmpty() && 
3284        getOperatorMenus()->createPopupMenu(theContext,theParent,theObject) != NULL ) {
3285     QPopupMenu* aPopup = getOperatorMenus()->createPopupMenu(theContext,theParent,theObject)->getPopup();
3286     int count = aPopup->count();
3287
3288     //for (int i = 0; i < count; i++) {
3289     for (int i = count - 1; i >= 0; i--) {
3290       int id = aPopup->idAt(i);
3291       QString text = aPopup->text(id);
3292       //QString mes("Inserting popup menu item loaded from XML: ");
3293       //mes += text;
3294       //MESSAGE ( mes.latin1() )
3295       if (i==0)
3296         popup->insertItem(aPopup->text(id),
3297                           this,
3298                           SLOT( onDispatch(int) ), 0, id, 0);// try adding item at the top
3299       else
3300         createPopup( popup, aPopup, text, id);
3301     }
3302   } //else {
3303     //QString mes("Popup does not exist for given (Context = ");
3304     //mes += theContext;
3305     //mes += ", Parent = ";
3306     //mes += theParent;
3307     //mes += ", Object = ";
3308     //mes += theObject;
3309     //MESSAGE (mes.latin1())
3310       //popup->clear();
3311   //}
3312
3313   // IAPP Popup 
3314   // Should be moved to SALOMEGUI_Application::onCreatePopup()...
3315   if ( myActiveComp.isEmpty() ) {
3316     popup->removeItem(QAD_Display_Popup_ID);
3317     popup->removeItem(QAD_DisplayOnly_Popup_ID);
3318     popup->removeItem(QAD_Erase_Popup_ID);
3319     int id = popup->idAt(popup->count()-1); // last item
3320     if (id < 0 && id != -1) popup->removeItem(id); // separator
3321
3322     if ( popup && theParent.compare("ObjectBrowser")==0 ) {
3323       if ( popup->count()>0 ) {
3324         popup->insertItem (tr ("MEN_OPENWITH"), this, SLOT(onOpenWith()), 0, -1, 2);
3325         popup->insertSeparator (3);
3326       }
3327       else {
3328         popup->insertItem (tr ("MEN_OPENWITH"), this, SLOT(onOpenWith()) );
3329       }
3330     } 
3331   }
3332  
3333 }
3334
3335 typedef bool activeStudyChanged(QAD_Desktop*);
3336
3337 void QAD_Desktop::onActiveStudyChanged()
3338 {
3339   if (!myActiveComp.isEmpty())  {
3340     OSD_Function osdF = mySharedLibrary.DlSymb("activeStudyChanged");
3341     if ( osdF != NULL ) {
3342       activeStudyChanged (*f1) = (bool (*) (QAD_Desktop*)) osdF;
3343       (*f1)(this);
3344     }  
3345   }
3346 }
3347
3348 typedef bool customP(QAD_Desktop*, QPopupMenu*, const QString & theContext,
3349                      const QString & theParent, const QString & theObject);
3350 /*!
3351   Custom popup ( GUI Library )
3352 */
3353 void QAD_Desktop::customPopup(QPopupMenu* popup, const QString & theContext,
3354                               const QString & theParent, const QString & theObject)
3355 {
3356   if (!myActiveComp.isEmpty())  {
3357     OSD_Function osdF = mySharedLibrary.DlSymb("customPopup");
3358     if ( osdF != NULL ) {
3359       customP (*f1) = (bool (*) (QAD_Desktop*, QPopupMenu*, const QString &,
3360                                  const QString &, const QString &)) osdF;
3361       (*f1)(this, popup, theContext, theParent, theObject);
3362     }
3363   }
3364 }
3365
3366 void QAD_Desktop::onObjectBrowser()
3367 {
3368   bool checkDiff = false;
3369
3370   bool state  = QAD_CONFIG->getSetting("ObjectBrowser:AddColumn").compare("true") == 0;
3371
3372   if ( myStdActions.at( PrefObjectBrowserEntryId )->isOn() != state )
3373     checkDiff = true;
3374
3375   bool showEntry;
3376   if ( myStdActions.at( PrefObjectBrowserEntryId )->isOn() ) {
3377     showEntry = true;
3378     QAD_CONFIG->addSetting( "ObjectBrowser:AddColumn", "true");
3379   } else {
3380     showEntry = false;
3381     QAD_CONFIG->addSetting( "ObjectBrowser:AddColumn", "false");
3382   }  
3383
3384   bool showValue;
3385   if ( myStdActions.at( PrefObjectBrowserValueId )->isOn() ) {
3386     showValue = true;
3387     QAD_CONFIG->addSetting( "ObjectBrowser:ValueColumn", "true");
3388   } else {
3389     showValue = false;
3390     QAD_CONFIG->addSetting( "ObjectBrowser:ValueColumn", "false");
3391   }  
3392
3393   bool showIAPP;
3394   if ( myStdActions.at( PrefObjectBrowserIAPPId )->isOn() ) {
3395     showIAPP = true;
3396     QAD_CONFIG->addSetting( "ObjectBrowser:IAPP", "true");
3397   } else {
3398     showIAPP = false;
3399     QAD_CONFIG->addSetting( "ObjectBrowser:IAPP", "false");
3400   }  
3401   
3402   /* To sort created object in chrono order or reverse chrono order */
3403   bool showCHRONO_SORT ;
3404   if ( myStdActions.at( PrefObjectBrowserCHRONO_SORTId )->isOn() ) {
3405     showCHRONO_SORT = true;
3406     QAD_CONFIG->addSetting( "ObjectBrowser:ChronologicalSort", "true");
3407   } else {
3408     showCHRONO_SORT = false;
3409     QAD_CONFIG->addSetting( "ObjectBrowser:ChronologicalSort", "false");
3410   }
3411
3412   /* To show or not to show UseCase browser */
3413   bool showUseCase;
3414   if ( myStdActions.at( PrefObjectBrowserShowUseCaseId )->isOn() ) {
3415     showUseCase = true;
3416     QAD_CONFIG->addSetting( "ObjectBrowser:ShowUseCaseBrowser", "true");
3417   } else {
3418     showUseCase = false;
3419     QAD_CONFIG->addSetting( "ObjectBrowser:ShowUseCaseBrowser", "false");
3420   }
3421
3422   /* Resize or don't resize columns automatically */
3423   bool autoSize;
3424   if ( myStdActions.at( PrefObjectBrowserNoAutoSizeColumnsId )->isOn() ) {
3425     autoSize = false;
3426     QAD_CONFIG->addSetting( "ObjectBrowser:NoAutoSizeColumns", "true");
3427   } else {
3428     autoSize = true;
3429     QAD_CONFIG->addSetting( "ObjectBrowser:NoAutoSizeColumns", "false");
3430   }
3431
3432   if ( myActiveApp ) {
3433     QList<QAD_Study>& studies = myActiveApp->getStudies();
3434     for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
3435       int nbSf = study->getStudyFramesCount();
3436       for ( int i = 0; i < nbSf; i++ ) {
3437         QAD_StudyFrame* sf = study->getStudyFrame(i);
3438         sf->getLeftFrame()->getObjectBrowser()->setShowInfoColumns( showEntry );
3439         sf->getLeftFrame()->getObjectBrowser()->setShowValueColumn( showValue );
3440         sf->getLeftFrame()->getObjectBrowser()->setEnableChronoSort( showCHRONO_SORT );
3441 //      sf->getLeftFrame()->getObjectBrowser()->setShowIAPP( showIAPP ); // this is done by below updateObjBrowser() call
3442         sf->getLeftFrame()->getObjectBrowser()->showUseCaseBrowser( showUseCase );
3443         sf->getLeftFrame()->getObjectBrowser()->autoSizeColumns( autoSize );
3444       }
3445       study->updateObjBrowser(true);
3446     }
3447   }
3448 }
3449
3450 void QAD_Desktop::onViewerTrihedron()
3451 {
3452   QString Size = QAD_CONFIG->getSetting("Viewer:TrihedronSize");
3453   float dim;
3454
3455   SALOMEGUI_TrihedronSizeDlg *Dlg = new SALOMEGUI_TrihedronSizeDlg(this);
3456   if (!Size.isEmpty())
3457     Dlg->setTrihedronSize(Size.toInt());
3458   int r = Dlg->exec();
3459   dim = Dlg->getTrihedronSize();
3460   delete Dlg;
3461   
3462   if (r == QDialog::Accepted) {
3463     QAD_CONFIG->addSetting("Viewer:TrihedronSize", dim);
3464
3465     if( myActiveApp ) {
3466       QList<QAD_Study>& studies = myActiveApp->getStudies();
3467       for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
3468         int nbSf = study->getStudyFramesCount();
3469         for ( int i = 0; i < nbSf; i++ ) {
3470           study->getStudyFrame(i)->getRightFrame()->getViewFrame()->onAdjustTrihedron();
3471         }
3472       }
3473     }
3474   }
3475 }
3476
3477 void QAD_Desktop::onExternalBrowser()
3478 {
3479  
3480   QString theApp = QAD_CONFIG->getSetting("ExternalBrowser:Application");
3481   QString theParams = QAD_CONFIG->getSetting("ExternalBrowser:Parameters");
3482    
3483   SALOMEGUI_ExternalBrowserDlg *Dlg = new SALOMEGUI_ExternalBrowserDlg(this);
3484   
3485   if (!theApp.isEmpty())
3486     {
3487       QString theParams = QAD_CONFIG->getSetting("ExternalBrowser:Parameters");
3488       Dlg->setSettings(theApp, theParams);
3489     }
3490   int r = Dlg->exec();
3491   QString theAppFromDialog = Dlg->getApp();
3492   QString theParamsFromDialog = Dlg->getParams();
3493   delete Dlg;
3494   
3495   if (r == QDialog::Accepted) 
3496     {
3497       QAD_CONFIG->addSetting("ExternalBrowser:Application", theAppFromDialog );
3498       QAD_CONFIG->addSetting("ExternalBrowser:Parameters", theParamsFromDialog );
3499     }
3500   
3501 }
3502
3503
3504 void QAD_Desktop::onDirList() 
3505 {
3506   // getting dir list from settings
3507   QStringList dirList = QStringList::split(';', QAD_CONFIG->getSetting("FileDlg:QuickDirList"), false);
3508   QAD_DirListDlg* dlg = new QAD_DirListDlg(this);
3509   dlg->setPathList(dirList);
3510   if ( dlg->exec() == QDialog::Accepted) {
3511     dlg->getPathList(dirList);
3512     QAD_CONFIG->addSetting("FileDlg:QuickDirList", dirList.join(";"));
3513   }
3514   delete dlg;
3515 }
3516
3517 void QAD_Desktop::onConsoleFontAction()
3518 {
3519   // getting font from settings
3520   QString fntSet = QAD_CONFIG->getSetting("Viewer:ConsoleFont");
3521   QFont font = QAD_Tools::stringToFont( fntSet );
3522   bool bOk;
3523   font = QFontDialog::getFont( &bOk, font, this );
3524   if ( bOk ) {
3525     fntSet = QAD_Tools::fontToString( font );
3526     QAD_CONFIG->addSetting("Viewer:ConsoleFont", fntSet );
3527
3528     if( myActiveApp ) {
3529       QList<QAD_Study>& studies = myActiveApp->getStudies();
3530       for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
3531         int nbSf = study->getStudyFramesCount();
3532         for ( int i = 0; i < nbSf; i++ ) {
3533           study->getStudyFrame(i)->getRightFrame()->getPyEditor()->setFont( font );
3534           study->getStudyFrame(i)->getRightFrame()->getMessage()->setFont( font );
3535         }
3536       }
3537     }
3538   }
3539 }
3540
3541 void QAD_Desktop::onSavePref()
3542 {
3543   QAD_CONFIG->createConfigFile(true);
3544 }
3545
3546 //VRV: T2.5 - add default viewer
3547 void QAD_Desktop::onDefaultViewer(QActionP * theAction)
3548 {
3549   int type = VIEW_TYPE_MAX;
3550   
3551   QString myValue;
3552   if (myStdActions.at(DefaultViewerOCCId) == theAction)
3553     type = VIEW_OCC;
3554   else if (myStdActions.at(DefaultViewerVTKId) == theAction)
3555     type = VIEW_VTK;
3556   else if (myStdActions.at(DefaultGraphSupervisorId) == theAction)
3557     type = VIEW_GRAPHSUPERV;
3558   else if (myStdActions.at(DefaultPlot2dId) == theAction)
3559     type = VIEW_PLOT2D;
3560   if ( type != VIEW_TYPE_MAX )
3561     QAD_CONFIG->addSetting( "Viewer:DefaultViewer", QString::number( type ) );
3562 }
3563 //VRV: T2.5 - add default viewer
3564
3565 void QAD_Desktop::onViewerOCC()
3566 {
3567   QString BackgroundColorRed   = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorRed");
3568   QString BackgroundColorGreen = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorGreen");
3569   QString BackgroundColorBlue  = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorBlue");
3570   QColor color;
3571
3572   if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3573     color = QColor(BackgroundColorRed.toInt(),
3574                    BackgroundColorGreen.toInt(),
3575                    BackgroundColorBlue.toInt());
3576   else
3577     color = QColor(35, 136, 145);
3578
3579   QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3580
3581   if (c.isValid()) {
3582     if ( myActiveApp ) {
3583       QList<QAD_Study>& studies = myActiveApp->getStudies();
3584       for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
3585         int nbSf = study->getStudyFramesCount();
3586         for ( int i = 0; i < nbSf; i++ ) {
3587           QAD_StudyFrame* sf = study->getStudyFrame(i);
3588           if ( sf->getTypeView() == VIEW_OCC ) {
3589             sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3590           }
3591         }
3592       }
3593     }
3594     QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorRed",   c.red() );
3595     QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorGreen", c.green() );
3596     QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorBlue",  c.blue() );
3597   }
3598 }
3599
3600 void QAD_Desktop::onGraphSupervisor()
3601 {
3602   QString BackgroundColorRed   = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorRed");
3603   QString BackgroundColorGreen = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorGreen");
3604   QString BackgroundColorBlue  = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorBlue");
3605   QColor color;
3606
3607   if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3608     color = QColor(BackgroundColorRed.toInt(),
3609                    BackgroundColorGreen.toInt(),
3610                    BackgroundColorBlue.toInt());
3611   else
3612     color = QColor(35, 136, 145);
3613
3614   QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3615
3616   if (c.isValid()) {
3617     if ( myActiveApp ) {
3618       QList<QAD_Study>& studies = myActiveApp->getStudies();
3619       for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
3620         int nbSf = study->getStudyFramesCount();
3621         for ( int i = 0; i < nbSf; i++ ) {
3622           QAD_StudyFrame* sf = study->getStudyFrame(i);
3623           if ( sf->getTypeView() == VIEW_GRAPHSUPERV ) {
3624             sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3625           }
3626         }
3627       }
3628     }
3629     
3630     QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorRed",   c.red() );
3631     QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorGreen", c.green() );
3632     QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorBlue",  c.blue() );
3633   }
3634 }
3635
3636 void QAD_Desktop::onViewerVTK()
3637 {
3638   QString BackgroundColorRed   = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorRed");
3639   QString BackgroundColorGreen = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorGreen");
3640   QString BackgroundColorBlue  = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorBlue");
3641   QColor color;
3642
3643   if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3644     color = QColor(BackgroundColorRed.toInt(),
3645                    BackgroundColorGreen.toInt(),
3646                    BackgroundColorBlue.toInt());
3647   else
3648     color = QColor(0, 0, 0);
3649
3650   QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3651
3652   if (c.isValid()) {
3653     if ( myActiveApp ) {
3654       QList<QAD_Study>& studies = myActiveApp->getStudies();
3655       for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
3656         int nbSf = study->getStudyFramesCount();
3657         for ( int i = 0; i < nbSf; i++ ) {
3658           QAD_StudyFrame* sf = study->getStudyFrame(i);
3659           if ( sf->getTypeView() == VIEW_VTK ) {
3660             sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3661           }
3662         }
3663       }
3664     }
3665     
3666     QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorRed",   c.red() );
3667     QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorGreen", c.green() );
3668     QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorBlue",  c.blue() );
3669   }
3670 }
3671
3672 void QAD_Desktop::onPlot2d()
3673 {
3674   QColor color;
3675   if ( QAD_CONFIG->hasSetting( "Plot2d:Background" ) ) {
3676     QString bgString = QAD_CONFIG->getSetting( "Plot2d:Background" );                               
3677     QStringList bgData = QStringList::split( ":", bgString, true );
3678     int bgRed = 0, bgGreen = 0, bgBlue = 0;
3679     if ( bgData.count() > 0 ) bgRed   = bgData[ 0 ].toInt();
3680     if ( bgData.count() > 1 ) bgGreen = bgData[ 1 ].toInt();
3681     if ( bgData.count() > 2 ) bgBlue  = bgData[ 2 ].toInt();
3682     color = QColor( bgRed, bgGreen, bgBlue );
3683   }
3684   else {
3685     color = QColor(0, 0, 0);  
3686   }
3687
3688   color = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3689
3690   if ( color.isValid() ) {
3691     if ( myActiveApp ) {
3692       QList<QAD_Study>& studies = myActiveApp->getStudies();
3693       for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
3694         int nbSf = study->getStudyFramesCount();
3695         for ( int i = 0; i < nbSf; i++ ) {
3696           QAD_StudyFrame* sf = study->getStudyFrame(i);
3697           if ( sf->getTypeView() == VIEW_PLOT2D ) {
3698             sf->getRightFrame()->getViewFrame()->setBackgroundColor( color );
3699           }
3700         }
3701       }
3702     }
3703     QStringList bgData; 
3704     bgData.append( QString::number( color.red() ) );
3705     bgData.append( QString::number( color.green() ) );
3706     bgData.append( QString::number( color.blue() ) );
3707     QAD_CONFIG->addSetting( "Plot2d:Background", bgData.join( ":" ) );
3708   }
3709 }
3710
3711 /* Help About */
3712 void QAD_Desktop::helpAbout()
3713 {
3714   SALOMEGUI_AboutDlg* About = new SALOMEGUI_AboutDlg( QAD_Application::getDesktop(), tr("MEN_ABOUT"));
3715   About->exec();
3716   delete About;
3717 }
3718
3719 // /* Help Search */
3720 // void QAD_Desktop::helpSearch()
3721 // {
3722 // }
3723
3724 // /* Help Contents */
3725 // void QAD_Desktop::helpContents()
3726 // {
3727 //   if (myActiveComp == "")
3728 //     myActiveComp = getComponentUserName( "KERNEL" ); //NRI "Salome";
3729
3730 //   QCString dir;
3731 //   QString root;
3732 //   if (dir = getenv( getComponentName( myActiveComp ) + "_ROOT_DIR")) {
3733 //     root = QAD_Tools::addSlash( QAD_Tools::addSlash(dir) + QAD_Tools::addSlash("share")  + QAD_Tools::addSlash("salome")  + "doc" );
3734 //     if ( QFileInfo( root + "index.html" ).exists() ) {
3735 //       helpContext( root + "index.html", "" );
3736 //     }
3737 //     else {
3738 //       root = QAD_Tools::addSlash( root + "html" );
3739 //       if ( QFileInfo( root + "index.html" ).exists() ) {
3740 //      helpContext( root + "index.html", "" );
3741 //       }
3742 //       else {
3743 //      root = QAD_Tools::addSlash( root + "html" );
3744 //      if ( QFileInfo( root + "index.html" ).exists() ) {
3745 //        helpContext( root + "index.html", "" );
3746 //      }
3747 //       }
3748 //     }
3749 //   }
3750   
3751 // //   //NRI getHelpWindow()->contents();
3752 // //   getHelpWindow()->show();
3753 // //   getHelpWindow()->raise();
3754 // //   getHelpWindow()->setActiveWindow();
3755 // }
3756
3757 /* Help Context */
3758 //void QAD_Desktop::helpContext(const QString& source, const QString& context)
3759 //{
3760 //  //getHelpWindow()->context(source, context);   //implemented in QAD_HelpWindow::context( const QString& _source, const QString& _context)
3761 //  //getHelpWindow()->show();                     //from QMainWindow class
3762 //  //getHelpWindow()->raise();                    //from QMainWindow class
3763 //  //getHelpWindow()->setActiveWindow();          //from QMainWindow class
3764
3765 //  QString anApp = QAD_CONFIG->getSetting("ExternalBrowser:Application");
3766 //  QString aParams = QAD_CONFIG->getSetting("ExternalBrowser:Parameters");
3767    
3768 //  RunBrowser* rs = new RunBrowser(anApp, aParams, source, context);
3769 //  rs->start();
3770 //}
3771
3772 /* Preferences/MultiFile Save */
3773 void QAD_Desktop::onMultiFileSave()
3774 {
3775   if ( myStdActions.at( PrefMultiFileSave )->isOn() )
3776     QAD_CONFIG->addSetting( "Desktop:MultiFileSave", "true");
3777   else
3778     QAD_CONFIG->addSetting( "Desktop:MultiFileSave", "false");
3779 }
3780
3781 /* Preferences/ASCII Save */
3782 void QAD_Desktop::onASCIISave()
3783 {
3784   if ( myStdActions.at( PrefASCIISave )->isOn() )
3785     QAD_CONFIG->addSetting( "Desktop:ASCIISave", "true");
3786   else
3787     QAD_CONFIG->addSetting( "Desktop:ASCIISave", "false");
3788 }
3789
3790 /* Preferences / Undo Level */
3791 void QAD_Desktop::onUndoLevel()
3792 {
3793   static int MAX_UNDO_LEVEL = 1000;
3794   bool isAccepted = false;
3795   static QString aLabel = QString("Level value (%1 ... %2) : ").
3796     arg(1).arg(MAX_UNDO_LEVEL);
3797   int anUndoLevel = 
3798     SALOMEGUI_SetValueDlg::getInteger("Undo Level",aLabel,
3799                                       1,MAX_UNDO_LEVEL,getUndoLevel(),
3800                                       &isAccepted);
3801   if(!isAccepted) return;
3802   QAD_CONFIG->addSetting("Desktop:UndoLevel", anUndoLevel);
3803   if(!myActiveApp) return;
3804   QList<QAD_Study>& studies = myActiveApp->getStudies();
3805   int aWasWarning = 0;
3806   for(QAD_Study* study = studies.first(); study; study = studies.next()){
3807     SALOMEDS::Study_var aStudyDoc = study->getStudyDocument();
3808     SALOMEDS::StudyBuilder_var aStudyBuilder = aStudyDoc->NewBuilder();
3809     if (!aStudyDoc->GetProperties()->IsLocked()) {
3810       aStudyBuilder->UndoLimit(anUndoLevel);
3811     } else  {
3812       if (!aWasWarning) {
3813         QAD_MessageBox::warn1 ((QWidget*)QAD_Application::getDesktop(),
3814                                QObject::tr("WRN_WARNING"), 
3815                                QObject::tr("WRN_STUDY_LOCKED"),
3816                                QObject::tr("BUT_OK"));
3817         aWasWarning = 1;
3818       }
3819     }
3820   }
3821 }
3822
3823 /*********************************************************************
3824 ** Class: AppSelectionDlg
3825 ** Descr: Dialog for the selection of the application when several
3826 **        applications exist in the desktop and new study creation
3827 **        is activated by user.
3828 ** Level: Internal
3829 **********************************************************************/
3830 /*!
3831   \class Desktop_AppSelectionDlg QAD_Desktop.h
3832   \brief Dialog for the selection of the application when several
3833   applications exist in the desktop and new study creation
3834   is activated by user.
3835
3836   Level: Internal.
3837 */
3838
3839 Desktop_AppSelectionDlg::Desktop_AppSelectionDlg( QAD_Desktop* desktop,
3840                                                   QList<QAD_Application>& apps ) :
3841 QDialog( desktop, 0, true ),
3842 myAppId( 0 ),
3843 myApps( apps )
3844 {
3845     QAD_ASSERT_DEBUG_ONLY ( desktop );
3846     setCaption( tr("INF_DESK_DOC_CREATE") );
3847     if ( desktop->icon() )
3848     setIcon( *desktop->icon() );
3849
3850     QBoxLayout* mainLayout = new QVBoxLayout( this, 5 );
3851
3852     /* Create selection buttons */
3853     QVButtonGroup* buttonGrp = new QVButtonGroup ( this );
3854     buttonGrp->setExclusive ( true );
3855     QBoxLayout* vLayout = new QVBoxLayout( mainLayout, 5 );
3856     vLayout->addWidget ( buttonGrp );
3857
3858     /* Create selection button for available app */
3859     unsigned id = 0;
3860     for ( QAD_Application* app = myApps.first(); app; app = myApps.next(), id++ )
3861     {
3862         /* add radio button for application */
3863         buttonGrp->insert( new QRadioButton( app->getStudyDescription() +
3864                            " (*." + app->getStudyExtension() + ")", buttonGrp ), id );
3865     }
3866
3867     /* make the first application selected */
3868     buttonGrp->setButton( 0 );
3869
3870     /* listen to the selection */
3871     QAD_ASSERT ( connect ( buttonGrp, SIGNAL(clicked(int)), this, SLOT(onAppSelected(int)) ));
3872
3873     /* Create OK/Cancel buttons
3874     */
3875     QBoxLayout* hLayout = new QHBoxLayout( mainLayout, 5 );
3876     QPushButton* buttonOK = new QPushButton( tr("BUT_OK"), this );
3877     QPushButton* buttonCancel = new QPushButton( tr("BUT_CANCEL"), this );
3878     QPushButton* buttonHelp = new QPushButton( tr("BUT_HELP"), this );
3879     buttonOK->setDefault( true );
3880
3881     hLayout->addStretch();
3882     hLayout->addWidget( buttonOK );
3883     hLayout->addWidget( buttonCancel );
3884     hLayout->addWidget( buttonHelp );
3885
3886     /* connect buttons */
3887     QAD_ASSERT ( connect( buttonOK, SIGNAL(clicked()), this, SLOT(accept())) );
3888     QAD_ASSERT ( connect( buttonCancel, SIGNAL(clicked()), this, SLOT(reject())) );
3889     QAD_ASSERT ( connect( buttonHelp, SIGNAL(clicked()), this, SLOT(onHelp())) );
3890
3891     /* disable resizing */
3892     setFixedSize( 0, 0 );
3893     setSizePolicy( QSizePolicy ( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
3894 }
3895
3896 Desktop_AppSelectionDlg::~Desktop_AppSelectionDlg()
3897 {
3898 }
3899
3900 QAD_Application* Desktop_AppSelectionDlg::selectedApp() const
3901 {
3902     return myApps.at( myAppId );
3903 }
3904
3905 void Desktop_AppSelectionDlg::resizeEvent( QResizeEvent* e )
3906 {
3907     QAD_Tools::centerWidget( this, parentWidget() );
3908 }
3909
3910 /*
3911  *  Slots
3912 */
3913 void Desktop_AppSelectionDlg::onAppSelected( int id )
3914 {
3915     myAppId = id;
3916 }
3917
3918 void Desktop_AppSelectionDlg::onHelp()
3919 {
3920 }
3921