]> SALOME platform Git repositories - modules/kernel.git/blob - src/SALOMEGUI/QAD_Desktop.cxx
Salome HOME
PR: mergefrom_PAL_OCC_21Oct04
[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 myWindowRatio = 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   char arg[256] ;
2928   bool libToolsGUI = true;
2929   if( QAD_XmlHandler::_bibmap[ id ].isEmpty() ) 
2930   { 
2931     if ( (dir = getenv("KERNEL_ROOT_DIR")) && !found ) {
2932       dir = QAD_Tools::addSlash(dir) ;
2933       dir = dir + "lib" ;
2934       dir = QAD_Tools::addSlash(dir) ;
2935       dir = dir + "salome" ;
2936       dir = QAD_Tools::addSlash(dir) ;
2937 #ifdef WNT
2938       dir = dir + "libToolsGUI.dll" ;
2939 #else
2940       dir = dir + "libToolsGUI.so" ;
2941 #endif
2942       MESSAGE ( " GUI library = " << dir );
2943       fileInfo.setFile(dir) ;
2944       if (fileInfo.exists()) {
2945         ToolsLib = fileInfo.fileName() ;
2946         found = true;
2947       }
2948     }
2949   }
2950   else {
2951     libToolsGUI = false;
2952     SCRUTE( QAD_XmlHandler::_bibmap[ id ] ) ;
2953     if ( (dir = getenv("KERNEL_ROOT_DIR")) && !found ) {
2954       dir = QAD_Tools::addSlash(dir) ;
2955       dir = dir + "lib" ;
2956       dir = QAD_Tools::addSlash(dir) ;
2957       dir = dir + "salome" ;
2958       dir = QAD_Tools::addSlash(dir) ;
2959       dir = dir + QAD_XmlHandler::_bibmap[ id ].latin1() ;
2960       MESSAGE ( " GUI library = " << dir );
2961       fileInfo.setFile(dir) ;
2962       if (fileInfo.exists()) {
2963         ToolsLib = fileInfo.fileName() ;
2964         found = true;
2965       }
2966     }
2967   }
2968
2969   ToolsLibrary.SetName(TCollection_AsciiString((char*)ToolsLib.latin1()).ToCString());
2970   bool ok = ToolsLibrary.DlOpen(OSD_RTLD_LAZY);
2971   if (ok) {
2972     if ( libToolsGUI ) {
2973       OSD_Function osdF = ToolsLibrary.DlSymb("OnGUIEvent");
2974       OneDim (*f1) = NULL;
2975       f1 = (bool (*) (int, QAD_Desktop*)) osdF;
2976       (*f1)(id,this);
2977     } else {
2978       ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
2979       ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
2980       CORBA::ORB_var &orb = init(0 , 0 ) ;
2981       OSD_Function osdF = ToolsLibrary.DlSymb("OnGUIEvent");
2982       PTR_FACTORY_FUNCTION f1 = NULL;
2983       f1 = (PTR_FACTORY_FUNCTION) osdF;
2984       f1(orb,0,"Registry");
2985     }
2986   } else {
2987     QMessageBox::critical( this,
2988                            tr("ERR_ERROR"),
2989                            tr( ToolsLibrary.DlError() ) );
2990   }
2991 }
2992
2993 /*!
2994  */
2995 void QAD_Desktop::onDispatch(int id)
2996 {
2997   SALOMEGUI* anActiveGUI = getActiveGUI();
2998   if ( anActiveGUI ) 
2999     anActiveGUI->OnGUIEvent(id,this);
3000 }
3001
3002 /*!
3003   Returns the component's catalogue
3004 */
3005 SALOME_ModuleCatalog::ModuleCatalog_var QAD_Desktop::getCatalogue()
3006 {
3007   return myCatalogue;
3008 }
3009
3010 /*!
3011  */
3012 void QAD_Desktop::onComboActiveComponent( const QString & component ){
3013   onComboActiveComponent(component,true);
3014 }
3015 void QAD_Desktop::onComboActiveComponent( const QString & component, bool isLoadData)
3016 {
3017   if (myActiveStudy != 0) {
3018     if (myActiveComp.compare(component)!=0) {
3019       // deactivate previous component
3020       deactivateComponent();
3021
3022       if (!myXmlHandler->myIdList.IsEmpty()) clearMenus();
3023       if ( myCombo->currentText() != component )
3024         myCombo->setCurrentText( component );
3025       //NRI if (component.compare(QString("Salome"))!= 0) {
3026       if (component.compare( getComponentUserName( "KERNEL" ) )!= 0) {
3027 //      QApplication::setOverrideCursor( Qt::waitCursor );
3028         bool isOk = ( !isLoadData || loadComponentData( getComponentName(component) ) );
3029         if ( !isOk ) {
3030           QAD_MessageBox::error1( this, 
3031                                  tr("ERR_ERROR"),
3032                                  tr("ERR_COMP_DATA_NOT_LOADED").arg( component ), 
3033                                  tr("BUT_OK") );          
3034         }
3035
3036         if ( !isOk || !loadComponent( getComponentName(component) ) ) {
3037           myCombo->setCurrentItem (0);
3038           for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
3039             aButton->setOn(false);
3040           }
3041           myActiveComp = "";
3042           return;
3043         }
3044
3045         myActiveComp = component;
3046
3047         SALOME_Selection* oldSel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
3048
3049         for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
3050           if ( aButton->textLabel().compare(component)==0)
3051             aButton->setOn(true);
3052           else
3053             aButton->setOn(false);
3054         }
3055
3056         myActiveStudy->Selection( component );
3057
3058         SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
3059         SALOME_ListIteratorOfListIO It( oldSel->StoredIObjects() );
3060         for(;It.More();It.Next()) {
3061           int res = Sel->AddIObject( It.Value() );
3062
3063           if ( res == -1 )
3064             myActiveStudy->highlight( It.Value(), false );
3065           if ( res == 0 )
3066             myActiveStudy->highlight( It.Value(), true );
3067           
3068         }
3069
3070         oldSel->Clear();
3071
3072         /* SETTINGS */
3073         // IMPORTANT: SetSettings() should be called AFTER SALOME_Selection
3074         // has been created for a newly activated component
3075         getComponentGUI(component)->SetSettings( this, (char*)getComponentName(component).latin1() );
3076
3077         myActiveStudy->updateObjBrowser(true);
3078
3079 //      QApplication::restoreOverrideCursor();
3080
3081       } else {  // component == "Salome"
3082         myActiveComp = "";
3083         //NRI   myActiveStudy->Selection( "Salome" );
3084         myActiveStudy->Selection( getComponentUserName( "KERNEL" ) );
3085         SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
3086         Sel->ClearIObjects();
3087         for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
3088           aButton->setOn(false);
3089         }
3090       }
3091     } else {
3092       for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
3093         if ( aButton->textLabel().compare(component)==0)
3094           aButton->setOn(true);
3095       }
3096     }
3097   } else if (component.compare(QString("Salome"))!= 0) {
3098
3099       QPixmap pm;
3100       for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
3101         if ( aButton->textLabel().compare( component ) == 0 )
3102           pm = aButton->iconSet().pixmap();
3103       }
3104       SALOMEGUI_ActivateComponentDlg aDlg( this, component, pm );
3105       int res = aDlg.exec();
3106       
3107       switch ( res )
3108         {
3109         case 1:
3110           onNewStudy();
3111           onComboActiveComponent(component,true);                 
3112           break;
3113         case 2:
3114           onOpenStudy();        
3115           onComboActiveComponent(component,true);
3116           break;
3117         case 3:
3118           onLoadStudy();
3119           onComboActiveComponent(component,true);;
3120           break;
3121         case 0:
3122         default:
3123           putInfo( tr("INF_CANCELLED") );
3124           myCombo->setCurrentItem (0);  
3125           for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
3126           aButton->setOn(false);
3127           // return;
3128           }
3129         }
3130       }
3131 }
3132
3133 /*!
3134  */
3135 void QAD_Desktop::activateComponent(const QString& theName, bool isLoadData){
3136   
3137   int nbItem = myCombo->count();
3138   int Index = 0;
3139
3140   for (int i = 0; i < nbItem; i++) {
3141     if (myCombo->text(i).compare(theName)==0) {
3142       Index = i;
3143       break;
3144     }
3145   }
3146   myCombo->setCurrentItem (Index);
3147   onComboActiveComponent(theName,isLoadData);
3148 };
3149
3150 void QAD_Desktop::onButtonActiveComponent( )
3151 {
3152   QToolButton* obj = (QToolButton*)sender();
3153   activateComponent(obj->textLabel());
3154 }
3155
3156 /*!
3157   Clears All Resources of current component
3158  */
3159 void QAD_Desktop::clearMenus()
3160 {
3161   // san - commented as presumably obsolete
3162   //  onActiveStudyChanged();
3163
3164   /* menus */
3165   myMenusList.clear();
3166   if (myXmlHandler) {
3167     int length = myXmlHandler->myIdList.Length();
3168     for (int k=length; k>0; k--) {
3169       QMenuData* parent;
3170       if ( menuBar()->findItem(myXmlHandler->myIdList.Value(k), &parent) )
3171         parent->removeItem( myXmlHandler->myIdList.Value(k) );
3172     }
3173   }
3174
3175   /* toolbars */
3176   if (myActiveMenus) {
3177     int nbtoolbars = myActiveMenus->getToolBarList().count();
3178     for (int k=0; k<nbtoolbars; k++) {
3179       myActiveMenus->getToolBarList().at(k)->hide();
3180       myActiveMenus->getToolBarList().at(k)->clear();
3181     }
3182     myActiveMenus->clearToolBar();
3183
3184     /* popups */
3185     QList<QAD_ListPopupMenu> PopupList = myActiveMenus->getPopupMenuList();
3186     QAD_ListPopupMenu* aPopup;
3187     for(aPopup=PopupList.first();aPopup!=NULL;aPopup=PopupList.next()){
3188       aPopup->getPopup()->clear();
3189       
3190     }
3191     myActiveMenus->clearPopupMenu();
3192
3193   }
3194   myActiveComp = "";
3195 }
3196
3197 typedef bool TwoDim1(QKeyEvent* pe, QAD_Desktop*, QAD_StudyFrame*);
3198 /*!
3199   Exports Key Events in active component ( GUI Librairy )
3200  */
3201 void QAD_Desktop::onKeyPress( QKeyEvent* pe )
3202 {
3203   //  MESSAGE ( "QAD_Desktop::onKeyPress" )
3204   SALOMEGUI* anActiveGUI = getActiveGUI();
3205   if ( anActiveGUI ) 
3206     anActiveGUI->OnKeyPress(pe,this,myActiveStudy->getActiveStudyFrame());
3207 }
3208
3209 typedef bool TwoDim(QMouseEvent* pe, QAD_Desktop*, QAD_StudyFrame*);
3210 /*!
3211   Exports Mouse Press Events in active component ( GUI Librairy )
3212  */
3213 bool QAD_Desktop::onMousePress( QMouseEvent* pe )
3214 {
3215   //  MESSAGE ( "QAD_Desktop::onMousePress" )
3216   SALOMEGUI* anActiveGUI = getActiveGUI();
3217   if ( anActiveGUI ) 
3218     return anActiveGUI->OnMousePress(pe,this,myActiveStudy->getActiveStudyFrame());
3219   return false;
3220 }
3221
3222 /*!
3223   Exports Mouse Move Events in active component ( GUI Librairy )
3224  */
3225 void QAD_Desktop::onMouseMove( QMouseEvent* pe )
3226 {
3227   SALOMEGUI* anActiveGUI = getActiveGUI();
3228   if ( anActiveGUI ) 
3229     anActiveGUI->OnMouseMove(pe,this,myActiveStudy->getActiveStudyFrame());
3230 }
3231
3232 /*!
3233     Returns name of active component
3234 */
3235 const QString& QAD_Desktop::getActiveComponent() const
3236 {
3237   return myActiveComp;
3238 }
3239
3240 SALOMEGUI* QAD_Desktop::getActiveGUI()
3241 {
3242   SALOMEGUI* anActiveGUI = 0;
3243   if ( myComponents.find( myActiveComp ) != myComponents.end() )
3244     anActiveGUI = myComponents[myActiveComp];
3245   return anActiveGUI;
3246 }
3247
3248 typedef SALOMEGUI* (*ComponentGUI)();
3249
3250 SALOMEGUI* QAD_Desktop::getComponentGUI( const QString& component )
3251 {
3252   SALOMEGUI* aCompGUI = 0;
3253   if ( component.isEmpty() || getComponentName( component ).isEmpty() )
3254     return aCompGUI;
3255   
3256   // Load component GUI if requested for the first time
3257   if ( myComponents.find( component ) == myComponents.end() ) {
3258     OSD_SharedLibrary aSharedLibrary;
3259     QString ComponentLib;
3260     QCString libs;
3261     QFileInfo fileInfo ;
3262     QString fileString ;
3263     QString dir;
3264
3265     QAD_WaitCursor wc;
3266     
3267     _islibso= false;
3268
3269     if ( libs = getenv("LD_LIBRARY_PATH")) {
3270       //    MESSAGE ( " LD_LIBRARY_PATH : " << libs );
3271       QStringList dirList = QStringList::split( SEPARATOR, libs, false ); // skip empty entries
3272       for ( int i = dirList.count()-1; i >= 0; i-- ) {
3273         dir = dirList[ i ];
3274 #ifdef WNT
3275         fileString = QAD_Tools::addSlash( dir ) + "lib" + getComponentName( component ) + "GUI.dll" ;
3276 #else
3277         fileString = QAD_Tools::addSlash( dir ) + "lib" + getComponentName( component ) + "GUI.so" ;
3278 #endif
3279
3280         fileInfo.setFile(fileString) ;
3281         if (fileInfo.exists()) {
3282           // MESSAGE( " GUI library = " << fileString.latin1() );
3283           ComponentLib = fileInfo.fileName() ;
3284           _islibso = true;
3285           break;
3286         }
3287       }
3288     }
3289
3290     if (!_islibso) // component GUI could be in PyQt, use generic library
3291     {
3292       MESSAGE("GUI library not found, trying generic library for PyQt GUI");
3293       bool found = false;
3294       if (dir = getenv("KERNEL_ROOT_DIR"))
3295       {
3296         dir = QAD_Tools::addSlash(dir) ;
3297         dir = dir + "lib" ;
3298         dir = QAD_Tools::addSlash(dir) ;
3299         dir = dir + "salome" ;
3300         dir = QAD_Tools::addSlash(dir) ;
3301 #ifdef WNT
3302         dir = dir + "libSalomePyQtcmodule.dll" ;
3303 #else
3304         dir = dir + "libSalomePyQtcmodule.so" ;
3305 #endif
3306         MESSAGE ( " GUI library = " << dir );
3307         fileInfo.setFile(dir) ;
3308         if (fileInfo.exists())
3309         {
3310           ComponentLib = fileInfo.fileName() ;
3311           found = true;
3312         }
3313       }
3314       if ( !found )
3315       {
3316         QMessageBox::critical( this,
3317                               tr("ERR_ERROR"),
3318                               tr("ERR_LIBGUI" ).arg(component) );
3319         return aCompGUI;
3320       }
3321     }
3322
3323     aSharedLibrary.SetName(TCollection_AsciiString((char*)ComponentLib.latin1()).ToCString());
3324     bool ok = aSharedLibrary.DlOpen(OSD_RTLD_LAZY);
3325     if (!ok) {
3326       wc.stop();
3327       QMessageBox::critical( this,
3328                             tr("ERR_ERROR"),
3329                             tr( aSharedLibrary.DlError() ) );
3330       return aCompGUI;
3331     }
3332
3333     OSD_Function osdF = aSharedLibrary.DlSymb("GetComponentGUI");
3334     if ( osdF != NULL ) {
3335       ComponentGUI f1 = (SALOMEGUI* (*) ()) osdF;
3336       SALOMEGUI* aCompGUI = (*f1)();
3337       if ( aCompGUI )
3338         myComponents.insert( component, aCompGUI );
3339       else {
3340         wc.stop();
3341         QMessageBox::critical( this,
3342                               tr("ERR_ERROR"),
3343                               tr("ERR_GET_GUI_FAILED" ).arg(component) );
3344         return aCompGUI;
3345       }
3346     }
3347     else {
3348       wc.stop();
3349       QMessageBox::critical( this,
3350                             tr("ERR_ERROR"),
3351                             tr("ERR_GET_GUI_NOT_FOUND" ).arg(ComponentLib) );
3352       return aCompGUI;
3353     }
3354   }
3355   aCompGUI = myComponents[component];
3356   return aCompGUI;
3357 }
3358
3359
3360 /*!
3361     Returns name of active component
3362 */
3363 QString QAD_Desktop::getComponentDataType() const
3364 {
3365   using namespace SALOMEDS;
3366   Study_var aStudy = getActiveStudy()->getStudyDocument();
3367   SObject_var aSObject = aStudy->FindObject(myActiveComp.latin1());
3368   SComponent_var aComponent = SComponent::_narrow(aSObject);
3369   if(!aComponent->_is_nil()){
3370     CORBA::String_var aString = aComponent->ComponentDataType();
3371     return aString.in();
3372   }
3373   return "";
3374 }
3375
3376 void QAD_Desktop::definePopup(QString & theContext,
3377                               QString & theParent, 
3378                               QString & theObject ) 
3379 {
3380   SALOMEGUI* anActiveGUI = getActiveGUI();
3381   if ( anActiveGUI ) 
3382     anActiveGUI->DefinePopup(theContext, theParent, theObject);
3383 }
3384
3385
3386 /*!
3387     Copy popup menu [ static ]
3388 */
3389 static void makePopup( QPopupMenu* popup, QPopupMenu* fromPopup, QAD_Desktop* receiver ) 
3390 {
3391   // safe check
3392   if ( !popup || !fromPopup ) 
3393     return;
3394   // iterator through all popup items
3395   for ( int i = fromPopup->count()-1; i >= 0; i-- ) {
3396     int cmdId = fromPopup->idAt( i );
3397     QMenuItem* item = fromPopup->findItem( cmdId );
3398     if ( item ) {
3399       // if item is a separator
3400       if ( item->isSeparator() ) {
3401         popup->insertSeparator( 0 );
3402       }
3403       else {
3404         QIconSet* iconSet = item->iconSet();
3405         QKeySequence accel = fromPopup->accel( cmdId );
3406
3407         QPopupMenu* popupChild = item->popup();
3408         // if item is a popup
3409         if ( popupChild && popupChild != fromPopup ) {
3410           QPopupMenu* newPopup = new QPopupMenu( popup );
3411           if ( iconSet ) 
3412             popup->insertItem( *iconSet, item->text(), newPopup, cmdId, 0 );
3413           else
3414             popup->insertItem( item->text(), newPopup, cmdId, 0 );
3415           makePopup( newPopup, popupChild, receiver );
3416         }
3417         // if item is a command
3418         else {
3419           if ( iconSet ) 
3420             popup->insertItem( *iconSet, item->text(), cmdId, 0 );
3421           else
3422             popup->insertItem( item->text(), cmdId, 0 );
3423           popup->connectItem( cmdId, receiver, SLOT( onDispatch( int ) ) );
3424         }
3425         popup->setAccel( accel, cmdId );
3426       }
3427     }
3428   }
3429 }
3430     
3431 /*!
3432     Create popup
3433 */
3434 void QAD_Desktop::createPopup(QPopupMenu* popup, const QString & theContext,
3435                               const QString & theParent, const QString & theObject )
3436 {
3437   if ( !myActiveComp.isEmpty() && 
3438        getOperatorMenus()->createPopupMenu(theContext,theParent,theObject) != NULL ) {
3439     makePopup( popup, getOperatorMenus()->createPopupMenu(theContext,theParent,theObject)->getPopup(), this );
3440   }
3441   // IAPP Popup 
3442   // Should be moved to SALOMEGUI_Application::onCreatePopup()...
3443   if ( myActiveComp.isEmpty() ) {
3444     popup->removeItem(QAD_Display_Popup_ID);
3445     popup->removeItem(QAD_DisplayOnly_Popup_ID);
3446     popup->removeItem(QAD_Erase_Popup_ID);
3447     int id = popup->idAt(popup->count()-1); // last item
3448     if (id < 0 && id != -1) popup->removeItem(id); // separator
3449
3450     if ( popup && theParent.compare("ObjectBrowser")==0 ) {
3451       if ( popup->count()>0 ) {
3452         popup->insertItem (tr ("MEN_OPENWITH"), this, SLOT(onOpenWith()), 0, -1, 2);
3453         popup->insertSeparator (3);
3454       }
3455       else {
3456         popup->insertItem (tr ("MEN_OPENWITH"), this, SLOT(onOpenWith()) );
3457       }
3458     } 
3459   }
3460
3461 }
3462
3463 void QAD_Desktop::onActiveStudyChanged()
3464 {
3465   // Avoid recursive calls caused by QAD_MessageBox
3466   static bool isRecursion = false;
3467   if ( isRecursion || myAboutToClose )
3468     return;
3469
3470   if (myActiveComp != "") {
3471     // Try to load active component's data in the activated study
3472     if ( !loadComponentData(mapComponentName[myActiveComp]) ) {
3473       isRecursion = true;
3474       QAD_MessageBox::error1( this, 
3475                              tr("ERR_ERROR"),
3476                              tr("ERR_COMP_DATA_NOT_LOADED").arg( myActiveComp ), 
3477                              tr("BUT_OK") );
3478       // Error while loading component's data -> deactivate it
3479       deactivateComponent();
3480       if (!myXmlHandler->myIdList.IsEmpty()) clearMenus();
3481       myCombo->setCurrentItem (0);
3482       for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
3483         aButton->setOn(false);
3484       }
3485       myActiveComp = "";
3486       isRecursion = false;
3487       return;
3488     }
3489     else
3490       myActiveStudy->updateObjBrowser(true);
3491   }
3492
3493   SALOMEGUI* anActiveGUI = getActiveGUI();
3494   if ( anActiveGUI ) 
3495     anActiveGUI->ActiveStudyChanged(this);
3496 }
3497
3498 void QAD_Desktop::deactivateComponent()
3499 {
3500   SALOMEGUI* anActiveGUI = getActiveGUI();
3501   if ( anActiveGUI ) 
3502     anActiveGUI->Deactivate();
3503 }
3504
3505 /*!
3506   Custom popup ( GUI Library )
3507 */
3508 void QAD_Desktop::customPopup(QPopupMenu* popup, const QString & theContext,
3509                               const QString & theParent, const QString & theObject)
3510 {
3511   SALOMEGUI* anActiveGUI = getActiveGUI();
3512   if ( anActiveGUI ) 
3513     anActiveGUI->CustomPopup(this, popup, theContext, theParent, theObject);
3514 }
3515
3516 void QAD_Desktop::onObjectBrowser()
3517 {
3518   bool checkDiff = false;
3519
3520   bool state  = QAD_CONFIG->getSetting("ObjectBrowser:AddColumn").compare("true") == 0;
3521
3522   if ( myStdActions.at( PrefObjectBrowserEntryId )->isOn() != state )
3523     checkDiff = true;
3524
3525   bool showEntry;
3526   if ( myStdActions.at( PrefObjectBrowserEntryId )->isOn() ) {
3527     showEntry = true;
3528     QAD_CONFIG->addSetting( "ObjectBrowser:AddColumn", "true");
3529   } else {
3530     showEntry = false;
3531     QAD_CONFIG->addSetting( "ObjectBrowser:AddColumn", "false");
3532   }  
3533
3534   bool showValue;
3535   if ( myStdActions.at( PrefObjectBrowserValueId )->isOn() ) {
3536     showValue = true;
3537     QAD_CONFIG->addSetting( "ObjectBrowser:ValueColumn", "true");
3538   } else {
3539     showValue = false;
3540     QAD_CONFIG->addSetting( "ObjectBrowser:ValueColumn", "false");
3541   }  
3542
3543   bool showIAPP;
3544   if ( myStdActions.at( PrefObjectBrowserIAPPId )->isOn() ) {
3545     showIAPP = true;
3546     QAD_CONFIG->addSetting( "ObjectBrowser:IAPP", "true");
3547   } else {
3548     showIAPP = false;
3549     QAD_CONFIG->addSetting( "ObjectBrowser:IAPP", "false");
3550   }  
3551   
3552   /* To sort created object in chrono order or reverse chrono order */
3553   bool showCHRONO_SORT ;
3554   if ( myStdActions.at( PrefObjectBrowserCHRONO_SORTId )->isOn() ) {
3555     showCHRONO_SORT = true;
3556     QAD_CONFIG->addSetting( "ObjectBrowser:ChronologicalSort", "true");
3557   } else {
3558     showCHRONO_SORT = false;
3559     QAD_CONFIG->addSetting( "ObjectBrowser:ChronologicalSort", "false");
3560   }
3561
3562   /* To show or not to show UseCase browser */
3563   bool showUseCase;
3564   if ( myStdActions.at( PrefObjectBrowserShowUseCaseId )->isOn() ) {
3565     showUseCase = true;
3566     QAD_CONFIG->addSetting( "ObjectBrowser:ShowUseCaseBrowser", "true");
3567   } else {
3568     showUseCase = false;
3569     QAD_CONFIG->addSetting( "ObjectBrowser:ShowUseCaseBrowser", "false");
3570   }
3571
3572   /* Resize or don't resize columns automatically */
3573   bool autoSize;
3574   if ( myStdActions.at( PrefObjectBrowserNoAutoSizeColumnsId )->isOn() ) {
3575     autoSize = false;
3576     QAD_CONFIG->addSetting( "ObjectBrowser:NoAutoSizeColumns", "true");
3577   } else {
3578     autoSize = true;
3579     QAD_CONFIG->addSetting( "ObjectBrowser:NoAutoSizeColumns", "false");
3580   }
3581
3582   if ( myActiveApp ) {
3583     QList<QAD_Study>& studies = myActiveApp->getStudies();
3584     for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
3585       int nbSf = study->getStudyFramesCount();
3586       for ( int i = 0; i < nbSf; i++ ) {
3587         QAD_StudyFrame* sf = study->getStudyFrame(i);
3588         sf->getLeftFrame()->getObjectBrowser()->setShowInfoColumns( showEntry );
3589         sf->getLeftFrame()->getObjectBrowser()->setShowValueColumn( showValue );
3590         sf->getLeftFrame()->getObjectBrowser()->setEnableChronoSort( showCHRONO_SORT );
3591 //      sf->getLeftFrame()->getObjectBrowser()->setShowIAPP( showIAPP ); // this is done by below updateObjBrowser() call
3592         sf->getLeftFrame()->getObjectBrowser()->showUseCaseBrowser( showUseCase );
3593         sf->getLeftFrame()->getObjectBrowser()->autoSizeColumns( autoSize );
3594       }
3595       study->updateObjBrowser(true);
3596     }
3597   }
3598 }
3599
3600 void QAD_Desktop::onViewerTrihedron()
3601 {
3602   QString Size = QAD_CONFIG->getSetting("Viewer:TrihedronSize");
3603   float dim;
3604
3605   SALOMEGUI_TrihedronSizeDlg *Dlg = new SALOMEGUI_TrihedronSizeDlg(this);
3606   if (!Size.isEmpty())
3607     Dlg->setTrihedronSize(Size.toInt());
3608   int r = Dlg->exec();
3609   dim = Dlg->getTrihedronSize();
3610   delete Dlg;
3611   
3612   if (r == QDialog::Accepted) {
3613     QAD_CONFIG->addSetting("Viewer:TrihedronSize", dim);
3614
3615     if( myActiveApp ) {
3616       QList<QAD_Study>& studies = myActiveApp->getStudies();
3617       for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
3618         int nbSf = study->getStudyFramesCount();
3619         for ( int i = 0; i < nbSf; i++ ) {
3620           study->getStudyFrame(i)->getRightFrame()->getViewFrame()->onAdjustTrihedron();
3621         }
3622       }
3623     }
3624   }
3625 }
3626
3627 void QAD_Desktop::onExternalBrowser()
3628 {
3629  
3630   QString theApp = QAD_CONFIG->getSetting("ExternalBrowser:Application");
3631   QString theParams = QAD_CONFIG->getSetting("ExternalBrowser:Parameters");
3632    
3633   SALOMEGUI_ExternalBrowserDlg *Dlg = new SALOMEGUI_ExternalBrowserDlg(this);
3634   
3635   if (!theApp.isEmpty())
3636     {
3637       QString theParams = QAD_CONFIG->getSetting("ExternalBrowser:Parameters");
3638       Dlg->setSettings(theApp, theParams);
3639     }
3640   int r = Dlg->exec();
3641   QString theAppFromDialog = Dlg->getApp();
3642   QString theParamsFromDialog = Dlg->getParams();
3643   delete Dlg;
3644   
3645   if (r == QDialog::Accepted) 
3646     {
3647       QAD_CONFIG->addSetting("ExternalBrowser:Application", theAppFromDialog );
3648       QAD_CONFIG->addSetting("ExternalBrowser:Parameters", theParamsFromDialog );
3649     }
3650   
3651 }
3652
3653
3654 void QAD_Desktop::onDirList() 
3655 {
3656   // getting dir list from settings
3657   QStringList dirList = QStringList::split(';', QAD_CONFIG->getSetting("FileDlg:QuickDirList"), false);
3658   QAD_DirListDlg* dlg = new QAD_DirListDlg(this);
3659   dlg->setPathList(dirList);
3660   if ( dlg->exec() == QDialog::Accepted) {
3661     dlg->getPathList(dirList);
3662     QAD_CONFIG->addSetting("FileDlg:QuickDirList", dirList.join(";"));
3663   }
3664   delete dlg;
3665 }
3666
3667 void QAD_Desktop::onConsoleFontAction()
3668 {
3669   // getting font from settings
3670   QString fntSet = QAD_CONFIG->getSetting("Viewer:ConsoleFont");
3671   QFont font = QAD_Tools::stringToFont( fntSet );
3672   bool bOk;
3673   font = QFontDialog::getFont( &bOk, font, this );
3674   if ( bOk ) {
3675     fntSet = QAD_Tools::fontToString( font );
3676     QAD_CONFIG->addSetting("Viewer:ConsoleFont", fntSet );
3677
3678     if( myActiveApp ) {
3679       QList<QAD_Study>& studies = myActiveApp->getStudies();
3680       for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
3681         int nbSf = study->getStudyFramesCount();
3682         for ( int i = 0; i < nbSf; i++ ) {
3683           study->getStudyFrame(i)->getRightFrame()->getPyEditor()->setFont( font );
3684           study->getStudyFrame(i)->getRightFrame()->getMessage()->setFont( font );
3685         }
3686       }
3687     }
3688   }
3689 }
3690
3691 void QAD_Desktop::onSavePref()
3692 {
3693   QAD_CONFIG->createConfigFile(true);
3694 }
3695
3696 //VRV: T2.5 - add default viewer
3697 void QAD_Desktop::onDefaultViewer(QActionP * theAction)
3698 {
3699   int type = VIEW_TYPE_MAX;
3700   
3701   QString myValue;
3702   if (myStdActions.at(DefaultViewerOCCId) == theAction)
3703     type = VIEW_OCC;
3704   else if (myStdActions.at(DefaultViewerVTKId) == theAction)
3705     type = VIEW_VTK;
3706   else if (myStdActions.at(DefaultGraphSupervisorId) == theAction)
3707     type = VIEW_GRAPHSUPERV;
3708   else if (myStdActions.at(DefaultPlot2dId) == theAction)
3709     type = VIEW_PLOT2D;
3710   if ( type != VIEW_TYPE_MAX )
3711     QAD_CONFIG->addSetting( "Viewer:DefaultViewer", QString::number( type ) );
3712 }
3713 //VRV: T2.5 - add default viewer
3714
3715 void QAD_Desktop::onViewerOCC()
3716 {
3717   QString BackgroundColorRed   = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorRed");
3718   QString BackgroundColorGreen = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorGreen");
3719   QString BackgroundColorBlue  = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorBlue");
3720   QColor color;
3721
3722   if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3723     color = QColor(BackgroundColorRed.toInt(),
3724                    BackgroundColorGreen.toInt(),
3725                    BackgroundColorBlue.toInt());
3726   else
3727     color = QColor(35, 136, 145);
3728
3729   QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3730
3731   if (c.isValid()) {
3732     /* VSR : PAL5420 ---------------------------------------------------
3733     if ( myActiveApp ) {
3734       QList<QAD_Study>& studies = myActiveApp->getStudies();
3735       for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
3736         int nbSf = study->getStudyFramesCount();
3737         for ( int i = 0; i < nbSf; i++ ) {
3738           QAD_StudyFrame* sf = study->getStudyFrame(i);
3739           if ( sf->getTypeView() == VIEW_OCC ) {
3740             sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3741           }
3742         }
3743       }
3744     }
3745     VSR : PAL5420 --------------------------------------------------- */
3746     QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorRed",   c.red() );
3747     QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorGreen", c.green() );
3748     QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorBlue",  c.blue() );
3749   }
3750 }
3751
3752 void QAD_Desktop::onGraphSupervisor()
3753 {
3754   QString BackgroundColorRed   = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorRed");
3755   QString BackgroundColorGreen = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorGreen");
3756   QString BackgroundColorBlue  = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorBlue");
3757   QColor color;
3758
3759   if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3760     color = QColor(BackgroundColorRed.toInt(),
3761                    BackgroundColorGreen.toInt(),
3762                    BackgroundColorBlue.toInt());
3763   else
3764     color = QColor(35, 136, 145);
3765
3766   QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3767
3768   if (c.isValid()) {
3769     /* VSR : PAL5420 ---------------------------------------------------
3770     if ( myActiveApp ) {
3771       QList<QAD_Study>& studies = myActiveApp->getStudies();
3772       for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
3773         int nbSf = study->getStudyFramesCount();
3774         for ( int i = 0; i < nbSf; i++ ) {
3775           QAD_StudyFrame* sf = study->getStudyFrame(i);
3776           if ( sf->getTypeView() == VIEW_GRAPHSUPERV ) {
3777             sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3778           }
3779         }
3780       }
3781     }
3782     VSR : PAL5420 --------------------------------------------------- */
3783     QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorRed",   c.red() );
3784     QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorGreen", c.green() );
3785     QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorBlue",  c.blue() );
3786   }
3787 }
3788
3789 void QAD_Desktop::onViewerVTK()
3790 {
3791   QString BackgroundColorRed   = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorRed");
3792   QString BackgroundColorGreen = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorGreen");
3793   QString BackgroundColorBlue  = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorBlue");
3794   QColor color;
3795
3796   if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3797     color = QColor(BackgroundColorRed.toInt(),
3798                    BackgroundColorGreen.toInt(),
3799                    BackgroundColorBlue.toInt());
3800   else
3801     color = QColor(0, 0, 0);
3802
3803   QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3804
3805   if (c.isValid()) {
3806     /* VSR : PAL5420 ---------------------------------------------------
3807     if ( myActiveApp ) {
3808       QList<QAD_Study>& studies = myActiveApp->getStudies();
3809       for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
3810         int nbSf = study->getStudyFramesCount();
3811         for ( int i = 0; i < nbSf; i++ ) {
3812           QAD_StudyFrame* sf = study->getStudyFrame(i);
3813           if ( sf->getTypeView() == VIEW_VTK ) {
3814             sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3815           }
3816         }
3817       }
3818     }
3819     VSR : PAL5420 --------------------------------------------------- */
3820     QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorRed",   c.red() );
3821     QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorGreen", c.green() );
3822     QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorBlue",  c.blue() );
3823   }
3824 }
3825
3826 void QAD_Desktop::onPlot2d()
3827 {
3828   QColor color;
3829   if ( QAD_CONFIG->hasSetting( "Plot2d:Background" ) ) {
3830     QString bgString = QAD_CONFIG->getSetting( "Plot2d:Background" );                               
3831     QStringList bgData = QStringList::split( ":", bgString, true );
3832     int bgRed = 0, bgGreen = 0, bgBlue = 0;
3833     if ( bgData.count() > 0 ) bgRed   = bgData[ 0 ].toInt();
3834     if ( bgData.count() > 1 ) bgGreen = bgData[ 1 ].toInt();
3835     if ( bgData.count() > 2 ) bgBlue  = bgData[ 2 ].toInt();
3836     color = QColor( bgRed, bgGreen, bgBlue );
3837   }
3838   else {
3839     color = QColor(255, 255, 255);  
3840   }
3841
3842   color = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3843
3844   if ( color.isValid() ) {
3845     /* VSR : PAL5420 ---------------------------------------------------
3846     if ( myActiveApp ) {
3847       QList<QAD_Study>& studies = myActiveApp->getStudies();
3848       for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
3849         int nbSf = study->getStudyFramesCount();
3850         for ( int i = 0; i < nbSf; i++ ) {
3851           QAD_StudyFrame* sf = study->getStudyFrame(i);
3852           if ( sf->getTypeView() == VIEW_PLOT2D ) {
3853             sf->getRightFrame()->getViewFrame()->setBackgroundColor( color );
3854           }
3855         }
3856       }
3857     }
3858     VSR : PAL5420 --------------------------------------------------- */
3859     QStringList bgData; 
3860     bgData.append( QString::number( color.red() ) );
3861     bgData.append( QString::number( color.green() ) );
3862     bgData.append( QString::number( color.blue() ) );
3863     QAD_CONFIG->addSetting( "Plot2d:Background", bgData.join( ":" ) );
3864   }
3865 }
3866
3867 /* Help About */
3868 void QAD_Desktop::helpAbout()
3869 {
3870   SALOMEGUI_AboutDlg* About = new SALOMEGUI_AboutDlg( QAD_Application::getDesktop(), tr("MEN_ABOUT"));
3871   About->exec();
3872   delete About;
3873 }
3874
3875 // /* Help Search */
3876 // void QAD_Desktop::helpSearch()
3877 // {
3878 // }
3879
3880 // /* Help Contents */
3881 // void QAD_Desktop::helpContents()
3882 // {
3883 //   if (myActiveComp == "")
3884 //     myActiveComp = getComponentUserName( "KERNEL" ); //NRI "Salome";
3885
3886 //   QCString dir;
3887 //   QString root;
3888 //   if (dir = getenv( getComponentName( myActiveComp ) + "_ROOT_DIR")) {
3889 //     root = QAD_Tools::addSlash( QAD_Tools::addSlash(dir) + QAD_Tools::addSlash("share")  + QAD_Tools::addSlash("salome")  + "doc" );
3890 //     if ( QFileInfo( root + "index.html" ).exists() ) {
3891 //       helpContext( root + "index.html", "" );
3892 //     }
3893 //     else {
3894 //       root = QAD_Tools::addSlash( root + "html" );
3895 //       if ( QFileInfo( root + "index.html" ).exists() ) {
3896 //      helpContext( root + "index.html", "" );
3897 //       }
3898 //       else {
3899 //      root = QAD_Tools::addSlash( root + "html" );
3900 //      if ( QFileInfo( root + "index.html" ).exists() ) {
3901 //        helpContext( root + "index.html", "" );
3902 //      }
3903 //       }
3904 //     }
3905 //   }
3906   
3907 // //   //NRI getHelpWindow()->contents();
3908 // //   getHelpWindow()->show();
3909 // //   getHelpWindow()->raise();
3910 // //   getHelpWindow()->setActiveWindow();
3911 // }
3912
3913 /* Help Context */
3914 //void QAD_Desktop::helpContext(const QString& source, const QString& context)
3915 //{
3916 //  //getHelpWindow()->context(source, context);   //implemented in QAD_HelpWindow::context( const QString& _source, const QString& _context)
3917 //  //getHelpWindow()->show();                     //from QMainWindow class
3918 //  //getHelpWindow()->raise();                    //from QMainWindow class
3919 //  //getHelpWindow()->setActiveWindow();          //from QMainWindow class
3920
3921 //  QString anApp = QAD_CONFIG->getSetting("ExternalBrowser:Application");
3922 //  QString aParams = QAD_CONFIG->getSetting("ExternalBrowser:Parameters");
3923    
3924 //  RunBrowser* rs = new RunBrowser(anApp, aParams, source, context);
3925 //  rs->start();
3926 //}
3927
3928 /* Preferences/MultiFile Save */
3929 void QAD_Desktop::onMultiFileSave()
3930 {
3931   if ( myStdActions.at( PrefMultiFileSave )->isOn() )
3932     QAD_CONFIG->addSetting( "Desktop:MultiFileSave", "true");
3933   else
3934     QAD_CONFIG->addSetting( "Desktop:MultiFileSave", "false");
3935 }
3936
3937 /* Preferences/ASCII Save */
3938 void QAD_Desktop::onASCIISave()
3939 {
3940   if ( myStdActions.at( PrefASCIISave )->isOn() )
3941     QAD_CONFIG->addSetting( "Desktop:ASCIISave", "true");
3942   else
3943     QAD_CONFIG->addSetting( "Desktop:ASCIISave", "false");
3944 }
3945
3946 /* Preferences / Undo Level */
3947 void QAD_Desktop::onUndoLevel()
3948 {
3949   static int MAX_UNDO_LEVEL = 1000;
3950   bool isAccepted = false;
3951   static QString aLabel = QString("Level value (%1 ... %2) : ").
3952     arg(1).arg(MAX_UNDO_LEVEL);
3953   int anUndoLevel = 
3954     SALOMEGUI_SetValueDlg::getInteger("Undo Level",aLabel,
3955                                       1,MAX_UNDO_LEVEL,getUndoLevel(),
3956                                       &isAccepted);
3957   if(!isAccepted) return;
3958   QAD_CONFIG->addSetting("Desktop:UndoLevel", anUndoLevel);
3959   if(!myActiveApp) return;
3960   QList<QAD_Study>& studies = myActiveApp->getStudies();
3961   int aWasWarning = 0;
3962   for(QAD_Study* study = studies.first(); study; study = studies.next()){
3963     SALOMEDS::Study_var aStudyDoc = study->getStudyDocument();
3964     SALOMEDS::StudyBuilder_var aStudyBuilder = aStudyDoc->NewBuilder();
3965     if (!aStudyDoc->GetProperties()->IsLocked()) {
3966       aStudyBuilder->UndoLimit(anUndoLevel);
3967     } else  {
3968       if (!aWasWarning) {
3969         QAD_MessageBox::warn1 ((QWidget*)QAD_Application::getDesktop(),
3970                                QObject::tr("WRN_WARNING"), 
3971                                QObject::tr("WRN_STUDY_LOCKED"),
3972                                QObject::tr("BUT_OK"));
3973         aWasWarning = 1;
3974       }
3975     }
3976   }
3977 }
3978
3979 /* Update status bar for File menu items */
3980 void QAD_Desktop::onFilePopupStatusText( int id )
3981 {
3982   QString component = getActiveComponent();
3983   
3984   if (component != "") {
3985     //one of the modules is active now
3986     int importId = myFilePopup.idAt(8);
3987     int exportId = myFilePopup.idAt(9);
3988     int importTableId = myFilePopup.idAt(10);
3989    
3990     if (component == getComponentUserName("SMESH") || component == getComponentUserName("GEOM")) {
3991       if (id == importId)
3992         putInfo( tr("PRP_DESK_FILE_IMPORT") );
3993       if (id == exportId)
3994         putInfo( tr("PRP_DESK_FILE_EXPORT") );
3995     }
3996     if (component == getComponentUserName("VISU")) {
3997       if (id == importId)
3998         putInfo( tr("PRP_DESK_FILE_IMPORTMED") );
3999       if (id == importTableId)
4000         putInfo( tr("PRP_DESK_FILE_IMPORTTABLE") );
4001       if (id == exportId)
4002         putInfo( tr("PRP_DESK_FILE_EXPLOREMEDFILE") );
4003     }
4004     if (component == getComponentUserName("SUPERV")) {
4005       if (id == importId)
4006         putInfo( tr("PRP_DESK_FILE_IMPORTDF") );
4007       if (id == exportId)
4008         putInfo( tr("PRP_DESK_FILE_EXPORTDF") );
4009     }
4010   }
4011 }
4012
4013 /* Update status bar for Edit menu items */
4014 void QAD_Desktop::onEditPopupStatusText( int id )
4015 {
4016   QString component = getActiveComponent();
4017   
4018   if (component != "") {
4019     //one of the modules is active now
4020    
4021     if (component == getComponentUserName("SMESH") || component == getComponentUserName("GEOM") ) {
4022       int deleteId = myEditPopup.idAt(5);
4023       if (id == deleteId)
4024         putInfo( tr("PRP_DESK_EDIT_DELETE") );
4025     }
4026     if (component == getComponentUserName("SUPERV") ) {
4027       int newDFId = myEditPopup.idAt(5);
4028       int modifyDFId = myEditPopup.idAt(6);
4029       if (id == newDFId)
4030         putInfo( tr("PRP_DESK_EDIT_NEWDF") );
4031       if (id == modifyDFId)
4032         putInfo( tr("PRP_DESK_EDIT_MODIFYDF") );
4033     }
4034   }
4035 }
4036
4037 /* Update status bar for View menu items */
4038 void QAD_Desktop::onViewPopupStatusText( int id )
4039 {
4040   QString component = getActiveComponent();
4041   
4042   if (component != "") {
4043     //one of the modules is active now
4044     int DispModeId = myViewPopup.idAt(2);
4045     
4046     if (component == getComponentUserName("GEOM")) {
4047       if (id == DispModeId)
4048         putInfo( tr("PRP_DESK_VIEW_DISPLAYMODE") );
4049     }
4050     if (component == getComponentUserName("SMESH")) {
4051       int updateId = myViewPopup.idAt(3);
4052
4053       if (id == DispModeId)
4054         putInfo( tr("PRP_DESK_VIEW_DISPLAYMODE") );
4055       if (id == updateId)
4056         putInfo( tr("PRP_DESK_VIEW_UPDATE") );
4057     }
4058   }
4059 }
4060
4061 /*********************************************************************
4062 ** Class: AppSelectionDlg
4063 ** Descr: Dialog for the selection of the application when several
4064 **        applications exist in the desktop and new study creation
4065 **        is activated by user.
4066 ** Level: Internal
4067 **********************************************************************/
4068 /*!
4069   \class Desktop_AppSelectionDlg QAD_Desktop.h
4070   \brief Dialog for the selection of the application when several
4071   applications exist in the desktop and new study creation
4072   is activated by user.
4073
4074   Level: Internal.
4075 */
4076
4077 Desktop_AppSelectionDlg::Desktop_AppSelectionDlg( QAD_Desktop* desktop,
4078                                                   QList<QAD_Application>& apps ) :
4079 QDialog( desktop, 0, true ),
4080 myAppId( 0 ),
4081 myApps( apps )
4082 {
4083     QAD_ASSERT_DEBUG_ONLY ( desktop );
4084     setCaption( tr("INF_DESK_DOC_CREATE") );
4085     if ( desktop->icon() )
4086     setIcon( *desktop->icon() );
4087
4088     QBoxLayout* mainLayout = new QVBoxLayout( this, 5 );
4089
4090     /* Create selection buttons */
4091     QVButtonGroup* buttonGrp = new QVButtonGroup ( this );
4092     buttonGrp->setExclusive ( true );
4093     QBoxLayout* vLayout = new QVBoxLayout( mainLayout, 5 );
4094     vLayout->addWidget ( buttonGrp );
4095
4096     /* Create selection button for available app */
4097     unsigned id = 0;
4098     for ( QAD_Application* app = myApps.first(); app; app = myApps.next(), id++ )
4099     {
4100         /* add radio button for application */
4101         buttonGrp->insert( new QRadioButton( app->getStudyDescription() +
4102                            " (*." + app->getStudyExtension() + ")", buttonGrp ), id );
4103     }
4104
4105     /* make the first application selected */
4106     buttonGrp->setButton( 0 );
4107
4108     /* listen to the selection */
4109     QAD_ASSERT ( connect ( buttonGrp, SIGNAL(clicked(int)), this, SLOT(onAppSelected(int)) ));
4110
4111     /* Create OK/Cancel buttons
4112     */
4113     QBoxLayout* hLayout = new QHBoxLayout( mainLayout, 5 );
4114     QPushButton* buttonOK = new QPushButton( tr("BUT_OK"), this );
4115     QPushButton* buttonCancel = new QPushButton( tr("BUT_CANCEL"), this );
4116     QPushButton* buttonHelp = new QPushButton( tr("BUT_HELP"), this );
4117     buttonOK->setDefault( true );
4118
4119     hLayout->addStretch();
4120     hLayout->addWidget( buttonOK );
4121     hLayout->addWidget( buttonCancel );
4122     hLayout->addWidget( buttonHelp );
4123
4124     /* connect buttons */
4125     QAD_ASSERT ( connect( buttonOK, SIGNAL(clicked()), this, SLOT(accept())) );
4126     QAD_ASSERT ( connect( buttonCancel, SIGNAL(clicked()), this, SLOT(reject())) );
4127     QAD_ASSERT ( connect( buttonHelp, SIGNAL(clicked()), this, SLOT(onHelp())) );
4128
4129     /* disable resizing */
4130     setFixedSize( 0, 0 );
4131     setSizePolicy( QSizePolicy ( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
4132 }
4133
4134 Desktop_AppSelectionDlg::~Desktop_AppSelectionDlg()
4135 {
4136 }
4137
4138 QAD_Application* Desktop_AppSelectionDlg::selectedApp() const
4139 {
4140     return myApps.at( myAppId );
4141 }
4142
4143 void Desktop_AppSelectionDlg::resizeEvent( QResizeEvent* e )
4144 {
4145     QAD_Tools::centerWidget( this, parentWidget() );
4146 }
4147
4148 /*
4149  *  Slots
4150 */
4151 void Desktop_AppSelectionDlg::onAppSelected( int id )
4152 {
4153     myAppId = id;
4154 }
4155
4156 void Desktop_AppSelectionDlg::onHelp()
4157 {
4158 }
4159