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