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