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