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