Salome HOME
NRI : Temporary modification for reading catalog of modules.
[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     connect(myHelpWindow, SIGNAL(helpWindowClosed()), this, SLOT(onHelpWindowClosed()));
1156   }
1157   return myHelpWindow;
1158 }
1159
1160 /*!
1161     Called when desktop is closing
1162 */
1163 void QAD_Desktop::closeEvent ( QCloseEvent* e )
1164 {
1165   bool doClose = true;
1166   if  ( myQueryClose ) {
1167     doClose = QAD_MessageBox::info2 ( this, tr("INF_DESK_EXIT"),
1168                                       tr("QUE_DESK_EXIT"), tr ("BUT_OK"),
1169                                       tr ("BUT_CANCEL"), QAD_YES,
1170                                       QAD_NO, QAD_NO ) == QAD_YES;
1171   }
1172
1173   if ( doClose ) { 
1174     for ( QAD_Application* app = myApps.first(); app; app = myApps.next() ) { 
1175       QList<QAD_Study>& studies = app->getStudies();
1176       for(QAD_Study* study = studies.first(); study != 0; study = studies.next()) {
1177         if(myQueryClose && study->getStudyDocument()->IsModified()) {
1178           SALOMEGUI_CloseDlg aDlg( this );
1179           switch ( aDlg.exec() ) {
1180           case 1:
1181             if ( !onSaveStudy( study ) ) {
1182               putInfo( tr("INF_CANCELLED") );
1183               e->ignore();
1184               return;
1185             }
1186             break;
1187           case 2:
1188           case 3:
1189             break;
1190           case 0:
1191           default: 
1192             e->ignore();
1193             putInfo( tr("INF_CANCELLED") );
1194             return;
1195           }
1196         }
1197         study->close();
1198       }
1199     }
1200   }
1201   myQueryClose = true;
1202   doClose ? e->accept() : e->ignore();
1203 }
1204
1205 /*!
1206     Called when desktop is resized
1207 */
1208 void QAD_Desktop::resizeEvent( QResizeEvent* e )
1209 {
1210     QMainWindow::resizeEvent( e );
1211     myWorkspace->setGeometry( 1,1, centralWidget()->width()-2,
1212                               centralWidget()->height()-2 );
1213 }
1214
1215
1216 /*!
1217     Terminates the application.
1218 */
1219 void QAD_Desktop::onExit()
1220 {
1221   close();
1222 }
1223
1224 /************************************************************************
1225 **                      Study operations
1226 *************************************************************************/
1227
1228 /*!
1229     Creates new study.
1230     If several application are supported it displays dialog window
1231     to choose type of study.
1232 */
1233 void QAD_Desktop::createStudy(){
1234   onNewStudy();
1235 }
1236 void QAD_Desktop::onNewStudy()
1237 {
1238   unsigned numApps = myApps.count();
1239   if ( numApps ) {
1240     if ( numApps == 1 )
1241       onNewStudy ( myApps.at(0) );
1242     else  {   /* select the type of application for new study */
1243       Desktop_AppSelectionDlg selDlg( this, myApps );
1244       if ( selDlg.exec() == QDialog::Accepted ) {
1245         onNewStudy ( selDlg.selectedApp() );
1246       }
1247     }
1248   } else  {   /* no applications available in desktop */
1249     QAD_MessageBox::error1( this, 
1250                             tr("ERR_ERROR"),
1251                             tr("ERR_APP_NOAPP"), 
1252                             tr("BUT_OK") );
1253   }
1254 }
1255
1256 /*!
1257     Creates new study for the given application.
1258     Calls the respective function of the application class.
1259 */
1260 void QAD_Desktop::onNewStudy( QAD_Application* app )
1261 {
1262   if ( !app ) return;
1263
1264   /* create new study of the specific app */
1265   putInfo ( tr ("INF_DOC_CREATING") );
1266   QAD_Study* newStudy = app->newStudy();
1267
1268   if ( !newStudy ) {
1269     /* can't create new study */
1270     QAD_MessageBox::error1( this, tr("ERR_ERROR"),
1271                             tr("ERR_DOC_CANTCREATE"), 
1272                             tr("BUT_OK") );
1273   }
1274   putInfo ( tr("INF_READY") );
1275 }
1276
1277 /*!
1278     Loads the existing study.
1279 */
1280 void QAD_Desktop::onLoadStudy()
1281 {
1282   QString name, studyname, ext;
1283
1284   SALOMEGUI_LoadStudiesDlg* aDlg = new SALOMEGUI_LoadStudiesDlg( this, "Load Study", TRUE);
1285
1286   CORBA::Object_var obj = myNameService->Resolve("/myStudyManager");
1287   SALOMEDS::StudyManager_var myStudyMgr = SALOMEDS::StudyManager::_narrow(obj);
1288   ASSERT(! CORBA::is_nil(myStudyMgr));
1289   SALOMEDS::ListOfOpenStudies_var List = myStudyMgr->GetOpenStudies();
1290   for (unsigned int ind = 0; ind < List->length();ind++) {
1291     studyname = List[ind];
1292     aDlg->ListComponent->insertItem( studyname );
1293   }
1294   
1295   int retVal = aDlg->exec();
1296   studyname = aDlg->ListComponent->currentText();
1297   delete aDlg;
1298   if (retVal == QDialog::Rejected) 
1299     return;
1300
1301   if ( studyname.isNull() || studyname.isEmpty() )
1302     return;
1303   
1304   name = studyname;
1305   name.replace( QRegExp(":"), "/" );
1306   
1307   /*
1308     Try to associate an application to the opened study.
1309     Assumed that the association study<->application is unique.
1310   */
1311   bool appFound = false;
1312   putInfo ( tr("INF_DOC_OPENING") + " " + name );
1313   for ( QAD_Application* app = myApps.first(); app; app = myApps.next() )
1314     {
1315       /* application found */
1316       if ( app->isStudyOpened( name ) )
1317         {
1318           /* already opened: prompt for reopen */
1319           if ( QAD_MessageBox::warn2 ( this, tr("WRN_WARNING"),
1320                                        tr("QUE_DOC_ALREADYOPEN").arg( name ),
1321                                        tr ("BUT_YES"), tr ("BUT_NO"), QAD_YES, QAD_NO,
1322                                        QAD_NO ) == QAD_NO )
1323             {
1324               putInfo ( tr("INF_READY") );
1325               return;
1326             }
1327           /* now the study is closed to be re-opened */
1328           //don't ask user to remove study permanently
1329           if (app->getStudyByName ( name ) != NULL)
1330             onCloseStudy ( app->getStudyByName ( name ), false );
1331           else if (app->getStudyByName ( QAD_Tools::getFileNameFromPath( name, false )) != NULL)
1332             onCloseStudy ( app->getStudyByName ( QAD_Tools::getFileNameFromPath( name, false )), false );
1333         }
1334       appFound = true;
1335       
1336       /* open the study */
1337       QAD_Study* openStudy = app->loadStudy( studyname );
1338       if ( !openStudy ) {
1339         QAD_MessageBox::error1( this, 
1340                                 tr("ERR_ERROR"),
1341                                 tr("ERR_DOC_CANTOPEN") + "\n" + name,
1342                                 tr("BUT_OK") );
1343       }
1344       break;
1345     }
1346   
1347   if ( !appFound ) {
1348     QAD_MessageBox::error1( this, 
1349                             tr("ERR_ERROR"), 
1350                             tr("ERR_DOC_UNKNOWNTYPE"), 
1351                             tr("BUT_OK") );
1352   }
1353   putInfo ( tr("INF_READY") );
1354 }
1355
1356 /*!
1357     Opens the existing study.
1358     Displays select file dialog and calls corresponding function of
1359     application class
1360     (application is defined according to extension of selected file).
1361 */
1362 void QAD_Desktop::onOpenStudy()
1363 {
1364     QString name, ext;
1365
1366     /* Select a file to open  */
1367     name = selectFileName ( true );
1368     if ( name.isNull() || name.isEmpty() )
1369         return;
1370     
1371     // Workaround for non-existent files
1372     QFileInfo fi(name);
1373     if (!fi.exists() || !fi.isFile()) {
1374       QAD_MessageBox::error1 ( this, tr("ERR_ERROR"),
1375                                      tr("ERR_DOC_CANTOPEN") +": " +  name,
1376                                      tr("BUT_OK") );
1377       return;
1378     }
1379
1380     CORBA::Object_var obj = myNameService->Resolve("/myStudyManager");
1381     SALOMEDS::StudyManager_var myStudyMgr = SALOMEDS::StudyManager::_narrow(obj);
1382     ASSERT(! CORBA::is_nil(myStudyMgr));
1383     SALOMEDS::ListOfOpenStudies_var List = myStudyMgr->GetOpenStudies();
1384     for (unsigned int ind = 0; ind < List->length();ind++) {
1385       QString NameExistingStudy(List[ind]);
1386       QString NameOpeningStudy = QAD_Tools::getFileNameFromPath( name, false );
1387      
1388       if ( NameExistingStudy.compare( NameOpeningStudy ) == 0 ) {
1389         if ( QAD_MessageBox::warn2 ( this, tr("WRN_WARNING"),
1390                                      tr("QUE_DOC_ALREADYEXIST").arg( name ),
1391                                      tr ("BUT_YES"), tr ("BUT_NO"), QAD_YES, QAD_NO,
1392                                      QAD_NO ) == QAD_NO )
1393           {
1394             putInfo ( tr("INF_READY") );
1395             return;
1396           }
1397 //      else 
1398 //        {
1399 //          onLoadStudy();
1400 //          return;
1401 //        }
1402       }
1403     }
1404
1405     /*
1406         Try to associate an application to the opened study.
1407         Assumed that the association study<->application is unique.
1408     */
1409     bool appFound = false;
1410     putInfo ( tr("INF_DOC_OPENING") + " " + name );
1411     for ( QAD_Application* app = myApps.first(); app; app = myApps.next() )
1412     {
1413         QString ext = QAD_Tools::getFileExtensionFromPath ( name );
1414         if ( app->getStudyExtension() == ext )
1415         {
1416             /* application found */
1417             if ( app->isStudyOpened( name ) )
1418             {
1419                 /* already opened: prompt for reopen */
1420                 if ( QAD_MessageBox::warn2 ( this, tr("WRN_WARNING"),
1421                                              tr("QUE_DOC_ALREADYOPEN").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                 /* now the study is closed to be re-opened */
1429                 //don't ask user to remove study permanently
1430                 if (app->getStudyByName ( name ) != NULL)
1431                   onCloseStudy ( app->getStudyByName ( name ), false );
1432                 else if (app->getStudyByName ( QAD_Tools::getFileNameFromPath( name, false )) != NULL)
1433                   onCloseStudy ( app->getStudyByName ( QAD_Tools::getFileNameFromPath( name, false )), false );
1434             }
1435             appFound = true;
1436
1437             /* open the study */
1438             QAD_Study* openStudy = app->openStudy( name );
1439             if ( !openStudy ) {
1440               QAD_MessageBox::error1( this, 
1441                                       tr("ERR_ERROR"),
1442                                       tr("ERR_DOC_CANTOPEN") + "\n" + name,
1443                                       tr("BUT_OK") );
1444             } else if (myActiveComp != "") {
1445               QApplication::setOverrideCursor( Qt::waitCursor );
1446               loadComponentData(mapComponentName[myActiveComp]);
1447               openStudy->updateObjBrowser(true);
1448               QApplication::restoreOverrideCursor();
1449             }
1450             break;
1451         }
1452     }
1453
1454     if ( !appFound )
1455     {
1456       QAD_MessageBox::error1( this, 
1457                               tr("ERR_ERROR"), 
1458                               tr("ERR_DOC_UNKNOWNTYPE"), 
1459                               tr("BUT_OK"));
1460     }
1461     putInfo ( tr("INF_READY") );
1462 }
1463
1464 bool QAD_Desktop::loadComponentData( const QString& compName )
1465 {
1466   // Open component's data in active study if any
1467   MESSAGE("loadComponentData(): Opening component data")
1468   if (!myActiveStudy) {
1469     MESSAGE("loadComponentData(): No active study exists")
1470     return false;
1471   }
1472
1473   Engines::Component_var comp ;
1474   if ( compName.compare("Supervision") == 0 ) {
1475     comp = getEngine( "SuperVisionContainer", compName) ;
1476   }
1477   else {
1478     /*    comp = ( compName.compare("Data1") != 0 ) ? getEngine( "FactoryServer", compName) :
1479                                                 getEngine( "FactoryServerPy", compName);
1480     */
1481     comp = getEngine( "FactoryServer", compName);
1482     if ( comp->_is_nil() )
1483       comp = getEngine( "FactoryServerPy", compName);
1484   }
1485
1486   SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
1487   SALOMEDS::SComponent_var SCO = SALOMEDS::SComponent::_narrow(aStudy->FindObject(compName));
1488            
1489   if (!SCO->_is_nil()) {
1490     if (!CORBA::is_nil(comp)) {
1491       SALOMEDS::Driver_var   driver = SALOMEDS::Driver::_narrow(comp);
1492       if (!CORBA::is_nil(driver)) {
1493         SALOMEDS::StudyBuilder_var  B = aStudy->NewBuilder();
1494         if (!CORBA::is_nil(B)) {
1495           QAD_Operation* op = new QAD_Operation( myActiveStudy );
1496           op->start();
1497           B->LoadWith(SCO,driver);
1498           op->finish();
1499         } else {
1500           return false;
1501         }
1502       } else {
1503         MESSAGE("loadComponentData(): Driver is null");
1504         return false;
1505       }
1506     } else {
1507       MESSAGE("loadComponentData(): Engine is null");
1508       return false;
1509     }
1510   } else {
1511     MESSAGE("loadComponentData(): SComponent is null");
1512     return false;
1513   }
1514
1515   return true;
1516 }
1517
1518 /*!
1519     Saves the active study
1520 */
1521 bool QAD_Desktop::onSaveStudy()
1522 {
1523     return onSaveStudy ( myActiveStudy );
1524 }
1525
1526 /*!
1527     Saves the given study
1528 */
1529 bool QAD_Desktop::onSaveStudy( QAD_Study* study )
1530 {
1531     if ( !study ) return true;
1532
1533     if ( !study->isSaved() )
1534         return onSaveAsStudy ( study );
1535
1536     /* saving study... */
1537     QAD_Application* app = study->getApp();
1538     QAD_ASSERT_DEBUG_ONLY ( app );
1539     putInfo ( tr("INF_DOC_SAVING") + study->getTitle() );
1540     if ( !app->saveStudy( study ) )
1541     {
1542         putInfo( tr("INF_CANCELLED") );
1543         return false;
1544     }
1545
1546     /* saved ok */
1547     putInfo ( tr("INF_DOC_SAVED").arg( "" ) );
1548     return true;
1549 }
1550
1551 /*!
1552     Saves the active study under a new name
1553 */
1554 bool QAD_Desktop::onSaveAsStudy()
1555 {
1556     return onSaveAsStudy( myActiveStudy );
1557 }
1558
1559 /*!
1560     Saves the given study under a new name
1561 */
1562 bool QAD_Desktop::onSaveAsStudy( QAD_Study* study )
1563 {
1564     if ( !study ) return true;
1565
1566     /* Save study in a format supported by its application
1567     */
1568     QAD_Application* app = study->getApp();
1569     QAD_ASSERT_DEBUG_ONLY ( app );
1570
1571     /*  Select a file where to save
1572     */
1573     QString name = selectFileName ( false );
1574     if ( name.isNull() || name.isEmpty() )
1575     {
1576         putInfo( tr("INF_CANCELLED") );
1577         return false;
1578     }
1579
1580     /*  Saving study
1581     */
1582     putInfo ( tr("INF_DOC_SAVING") + name );
1583     if ( !app->saveAsStudy( study, name ) ) {
1584       /* can't save the file */
1585       QAD_MessageBox::error1( this, 
1586                               tr("ERR_ERROR"), 
1587                               tr("ERR_DOC_CANTWRITE") + "\n" + name,
1588                               tr("BUT_OK") );
1589       putInfo("");
1590       return false;     /* cannot save */
1591     }
1592     putInfo ( tr("INF_DOC_SAVED").arg( name ) );
1593     return true;        /* saved ok */
1594 }
1595
1596 /*!
1597     Closes the active study
1598 */
1599 bool QAD_Desktop::onCloseStudy()
1600 {
1601   bool close = this->onCloseStudy ( myActiveStudy, true );
1602   if ( close && !myXmlHandler->myIdList.IsEmpty() ) {
1603     clearMenus();
1604     myActiveComp = "";
1605     myCombo->setCurrentItem (0);
1606     for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
1607       aButton->setOn(false);
1608     }
1609   }
1610   return close;
1611 }
1612
1613 /*!
1614     Closes the given study and ask user to remove study
1615     from the study manager permanently
1616 */
1617 bool QAD_Desktop::onCloseStudy( QAD_Study* study )
1618 {
1619   return onCloseStudy( study, true );
1620 }
1621
1622 /*!
1623     Closes the given study and ask user to remove study
1624     from the study manager permanently if ask is equal true
1625 */
1626 bool QAD_Desktop::onCloseStudy( QAD_Study* study, bool ask ) 
1627 {
1628   bool removePerm = false;
1629
1630   if ( ask )
1631     {
1632       SALOMEGUI_CloseDlg aDlg( this );
1633       int res = aDlg.exec();
1634       
1635       switch ( res )
1636         {
1637         case 1:
1638           //if ( study->isModified() )
1639           if ( !onSaveStudy( study ) ) {
1640             putInfo( tr("INF_CANCELLED") );
1641             return false;
1642           }
1643           removePerm = true;
1644           break;
1645         case 2:
1646           removePerm = true;
1647           break;
1648         case 3:
1649           removePerm = false;
1650           break;
1651         case 0:
1652         default:
1653           putInfo( tr("INF_CANCELLED") );
1654           return false;
1655         }
1656     }
1657   /* close active component */
1658   if (!myXmlHandler->myIdList.IsEmpty())
1659     {
1660       clearMenus();
1661       myActiveComp="";
1662       myCombo->setCurrentItem (0);
1663       for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() )
1664         aButton->setOn(false);
1665       qApp->processEvents();
1666     }
1667   /* close the study */
1668   return study->getApp()->closeStudy( study, removePerm );
1669 }
1670
1671 // Displays study properties dialog box
1672 void QAD_Desktop::onStudyProperties()
1673 {
1674   if (myActiveStudy) {
1675     // open transaction
1676     QAD_Operation* op = new QAD_Operation( myActiveStudy );
1677     op->start();
1678
1679     SALOMEGUI_StudyPropertiesDlg aDlg(this);
1680     int res = aDlg.exec();
1681
1682     if ( res == QDialog::Accepted && aDlg.isChanged() )
1683       op->finish();
1684     else
1685       op->abort(); 
1686
1687     // T2.12 - add the word "locked" to study frame captions if <myActiveStudy> study is locked
1688     myActiveStudy->updateCaptions();
1689   }
1690 }
1691
1692
1693 /*!
1694   locate all windows in cascade mode
1695   and resize them
1696 */
1697 void QAD_Desktop::onCascade()
1698 {
1699   myWorkspace->cascade();
1700   int w = myWorkspace->width();
1701   int h = myWorkspace->height();
1702   QWidgetList wList = myWorkspace->windowList();
1703   QWidgetListIt it(wList);
1704
1705   for(;it.current(); ++it)
1706       it.current()->resize(0.8*w, 0.8*h);
1707 }
1708
1709 /*!
1710   called when help window closed
1711 */
1712 void QAD_Desktop::onHelpWindowClosed()
1713 {
1714   myHelpWindow = 0;
1715 }
1716
1717 /*!
1718     Called when 'view status bar' option
1719     is switched on/off.
1720 */
1721 void QAD_Desktop::onViewStatusBar()
1722 {
1723     bool show = myStdActions.at( ViewStatusBarId )->isOn();
1724     if ( show == myStatusBar->isVisible() )
1725         return;
1726     if ( show )
1727         myStatusBar->show();
1728     else
1729         myStatusBar->hide();
1730 }
1731
1732 /*!
1733   Called when View/Toolbars popup menu is about to show
1734 */
1735 void QAD_Desktop::onToolBarPopupAboutToShow()
1736 {
1737   myToolBarAction.clear();
1738   myToolBarsPopup.clear();
1739   QPtrList<QDockWindow> wlist = dockWindows();
1740   for ( QDockWindow* w = wlist.first(); w; w = wlist.next() ) {
1741     if ( w->inherits( "QToolBar" ) ) {
1742       QToolBar* tb = ( QToolBar* )w;
1743       if ( appropriate( tb ) ) { 
1744         ToggleAction* a = new ToggleAction( tb->label(), tb->label(), 0, this, 0, true );
1745         a->setStatusTip ( tr("PRP_DESK_VIEW_TOOLBAR") );
1746         a->setOn( tb->isVisible() );
1747         QAD_ASSERT( connect( a, SIGNAL( toggledOn()  ), tb, SLOT( show() ) ) );
1748         QAD_ASSERT( connect( a, SIGNAL( toggledOff() ), tb, SLOT( hide() ) ) );
1749         a->addTo( &myToolBarsPopup );
1750         myToolBarAction.append( a );
1751       }
1752     }
1753   }
1754 }
1755
1756 /*!
1757     Called on 'View\Selection Mode'
1758 */
1759 void QAD_Desktop::onSelectionMode()
1760 {
1761   const QAction* obj = (QAction*) sender();
1762   
1763   int SelectionMode = 4;
1764
1765   if ( obj == myStdActions.at(SelectionActorId) ) {
1766     SelectionMode = 4;
1767     if ( obj->isOn() ) {
1768       myStdActions.at(SelectionCellId)->setOn(false);
1769       myStdActions.at(SelectionEdgeId)->setOn(false);
1770       myStdActions.at(SelectionPointId)->setOn(false);
1771     } else
1772       myStdActions.at(SelectionActorId)->setOn(true);
1773
1774   } else if ( obj == myStdActions.at(SelectionCellId) ) {
1775     SelectionMode = 3; 
1776     if ( obj->isOn() ) {
1777       myStdActions.at(SelectionActorId)->setOn(false);
1778       myStdActions.at(SelectionEdgeId)->setOn(false);
1779       myStdActions.at(SelectionPointId)->setOn(false);
1780     } else
1781       myStdActions.at(SelectionActorId)->setOn(true);
1782       
1783   } else if ( obj == myStdActions.at(SelectionEdgeId) ) {
1784     SelectionMode = 2;    
1785     if ( obj->isOn() ) {
1786       myStdActions.at(SelectionActorId)->setOn(false);
1787       myStdActions.at(SelectionCellId)->setOn(false);
1788       myStdActions.at(SelectionPointId)->setOn(false);
1789     } else
1790       myStdActions.at(SelectionActorId)->setOn(true);
1791       
1792   } else if ( obj == myStdActions.at(SelectionPointId) ) {
1793     SelectionMode = 1;
1794     if ( obj->isOn() ) {
1795       myStdActions.at(SelectionEdgeId)->setOn(false);
1796       myStdActions.at(SelectionCellId)->setOn(false);
1797       myStdActions.at(SelectionActorId)->setOn(false);
1798     } else
1799       myStdActions.at(SelectionActorId)->setOn(true);
1800   }
1801
1802   QAD_StudyFrame* sf = myActiveApp->getActiveStudy()->getActiveStudyFrame();
1803   sf->getRightFrame()->getViewFrame()->SetSelectionMode( SelectionMode );
1804   
1805   SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveApp->getActiveStudy()->getSelection() );
1806   Sel->SetSelectionMode( SelectionMode );
1807 }
1808
1809 /*!
1810     Called on 'View\Selection Mode'
1811 */
1812 void QAD_Desktop::SetSelectionMode(int mode, bool activeCompOnly)
1813 {
1814   switch (mode) {
1815   case 1:
1816     {
1817       myStdActions.at(SelectionEdgeId)->setOn(false);
1818       myStdActions.at(SelectionCellId)->setOn(false);
1819       myStdActions.at(SelectionActorId)->setOn(false);
1820       myStdActions.at(SelectionPointId)->setOn(true);
1821       break;
1822     }
1823   case 2:
1824     {
1825       myStdActions.at(SelectionActorId)->setOn(false);
1826       myStdActions.at(SelectionCellId)->setOn(false);
1827       myStdActions.at(SelectionPointId)->setOn(false);
1828       myStdActions.at(SelectionEdgeId)->setOn(true);
1829       break;
1830     }
1831   case 3:
1832     {
1833       myStdActions.at(SelectionActorId)->setOn(false);
1834       myStdActions.at(SelectionEdgeId)->setOn(false);
1835       myStdActions.at(SelectionPointId)->setOn(false);
1836       myStdActions.at(SelectionCellId)->setOn(true);
1837       break;
1838     }
1839   case 4:
1840     {
1841       myStdActions.at(SelectionCellId)->setOn(false);
1842       myStdActions.at(SelectionEdgeId)->setOn(false);
1843       myStdActions.at(SelectionPointId)->setOn(false);
1844       myStdActions.at(SelectionActorId)->setOn(true);
1845       break;
1846     }
1847   }
1848
1849   QAD_StudyFrame* sf = myActiveApp->getActiveStudy()->getActiveStudyFrame();
1850   if ( sf->getTypeView() == VIEW_VTK ) {
1851     sf->getRightFrame()->getViewFrame()->SetSelectionMode( mode );
1852     SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveApp->getActiveStudy()->getSelection() );
1853     Sel->SetSelectionMode( mode, activeCompOnly );
1854   } else {
1855   }
1856 }
1857
1858 /*!
1859     Called on 'Window\NewWindow3d'
1860 */
1861 void QAD_Desktop::onNewWindow3d()
1862 {
1863   //NRI : SAL2214
1864   /*
1865     //VRV: T2.5 - add default viewer
1866     QApplication::restoreOverrideCursor();
1867     SALOMEGUI_ViewChoiceDlg *choice = new SALOMEGUI_ViewChoiceDlg(this, "", TRUE);
1868     int r = choice->exec();
1869     if (r) 
1870     {
1871     myActiveApp->getActiveStudy()->newWindow3d(QString(""),(ViewType)(choice->getSelectedViewer()));
1872     }
1873     //VRV: T2.5 - add default viewer
1874   */
1875   const QAction* obj = (QAction*) sender();
1876   if ( obj == myStdActions.at(ViewOCCId) ) {
1877     myActiveApp->getActiveStudy()->newWindow3d(QString(""),(ViewType)(0));
1878   } else if ( obj == myStdActions.at(ViewVTKId) ) {
1879     myActiveApp->getActiveStudy()->newWindow3d(QString(""),(ViewType)(1));
1880   } else if ( obj == myStdActions.at(ViewPlot2dId) ) {
1881     myActiveApp->getActiveStudy()->newWindow3d(QString(""),(ViewType)(3));
1882   }
1883   //NRI : SAL2214
1884 }
1885
1886 /*!
1887     Called on 'help\contents'
1888 */
1889 void QAD_Desktop::onHelpContents()
1890 {
1891   if (myActiveApp)
1892     myActiveApp->helpContents();
1893   else
1894     helpContents();
1895 }
1896
1897 /*!
1898     Called on 'help\search'
1899 */
1900 void QAD_Desktop::onHelpSearch()
1901 {
1902   if (myActiveApp)
1903     myActiveApp->helpSearch();
1904   else
1905     helpSearch();
1906 }
1907
1908 /*!
1909     Called on 'help\about'
1910 */
1911 void QAD_Desktop::onHelpAbout()
1912 {
1913   if (myActiveApp)
1914     myActiveApp->helpAbout();
1915   else
1916     helpAbout();
1917 }
1918
1919
1920 /*!
1921     Activates the application and its active study
1922 */
1923 void QAD_Desktop::onActivateApp( QAD_Application* activeApp )
1924 {
1925   bool appChanged = ( activeApp != myActiveApp );
1926   if ( appChanged )
1927     {
1928       updateDesktop( DeactivateApp );
1929     }
1930   if ( activeApp )
1931     {
1932       myActiveApp = activeApp;
1933       myActiveStudy = myActiveApp->getActiveStudy();
1934     }
1935   else
1936     {
1937       myActiveApp = 0;
1938       myActiveStudy = 0;
1939     }
1940
1941   if ( appChanged )
1942     {
1943       updateDesktop( ActivateApp );
1944       updateCaption( (activeApp != NULL) ? ActivateApp : DeactivateApp );
1945     }
1946   updateActions();
1947 }
1948
1949 /*!
1950     Called when the last study is removed from
1951     the application 'app'.
1952 */
1953 void QAD_Desktop::onDeactivateApp(QAD_Application* app)
1954 {
1955   if ( app && app == myActiveApp )
1956     onActivateApp( 0 );
1957 }
1958
1959 /*!
1960     Enables/disables standard actions
1961 */
1962 void QAD_Desktop::updateActions()
1963 {
1964     myStdActions.at( FileCloseId )->setEnabled ( myActiveStudy != NULL );
1965     myStdActions.at( FileSaveId )->setEnabled ( myActiveStudy != NULL );
1966     myStdActions.at( FileSaveAsId )->setEnabled ( myActiveStudy != NULL );
1967     myStdActions.at( FilePropsId )->setEnabled( myActiveStudy != NULL );
1968 //    myStdActions.at( HelpContentsId )->setEnabled ( myActiveApp != NULL );
1969 //    myStdActions.at( HelpSearchId )->setEnabled ( myActiveApp != NULL );
1970 //    myStdActions.at( HelpWhatsThisId )->setEnabled ( myActiveApp != NULL );
1971 //    myStdActions.at( HelpAboutId )->setEnabled ( myActiveApp != NULL );
1972
1973 //    myToolsPopup.setEnabled ( myActiveStudy != NULL );
1974 //    myPrefPopup.setEnabled ( myActiveStudy != NULL );
1975
1976     mySelectionModePopup.setEnabled ( myActiveStudy != NULL );
1977 }
1978
1979 /*!
1980     Called when 'Window' popup is about to show
1981 */
1982 void QAD_Desktop::onWindowPopupAboutToShow()
1983 {
1984     /* add cascade/tile items */
1985     myWindowPopup.clear();
1986
1987     //NRI : SAL2214
1988     //myStdActions.at( WindowNew3dId )->addTo( &myWindowPopup );
1989     myWindowPopup.insertItem( tr("MEN_DESK_WINDOW_NEW3D"), &myNewViewPopup, WindowNew3dId );
1990     //myStdActions.at( WindowNew3dId )->setEnabled( true );
1991     myWindowPopup.setItemEnabled( WindowNew3dId, true );
1992     //NRI : SAL2214
1993     myStdActions.at( WindowCascadeId )->addTo( &myWindowPopup );
1994     myStdActions.at( WindowCascadeId )->setEnabled( true );
1995     myStdActions.at( WindowTileId )->addTo( &myWindowPopup );
1996     myStdActions.at( WindowTileId )->setEnabled( true );
1997
1998     /* add names of opened studies */
1999     QWidgetList windows = myWorkspace->windowList();
2000     if ( windows.isEmpty() )
2001     {
2002       //NRI : SAL2214 myStdActions.at( WindowNew3dId )->setEnabled( false );
2003       myWindowPopup.setItemEnabled( WindowNew3dId, false );
2004       //NRI : SAL2214
2005       myStdActions.at( WindowCascadeId )->setEnabled( false );
2006       myStdActions.at( WindowTileId )->setEnabled( false );
2007     }
2008     else
2009       {
2010         myWindowPopup.insertSeparator();
2011         for ( int i = 0; i < int(windows.count()); ++i )
2012           {
2013             int id = myWindowPopup.insertItem( windows.at(i)->caption(),
2014                                                this, SLOT( onWindowsPopupActivated( int ) ) );
2015             myWindowPopup.setItemParameter( id, i );
2016             myWindowPopup.setItemChecked( id, myWorkspace->activeWindow() == windows.at(i) );
2017           }
2018         QAD_ASSERT( connect( &myWindowPopup, SIGNAL(highlighted( int )), this,
2019                              SLOT(onWindowsPopupStatusText( int )) ));
2020     }
2021 }
2022
2023 /*!
2024     Called when the item with 'id' of 'Windows' popup
2025     is highlighted
2026 */
2027 void QAD_Desktop::onWindowsPopupStatusText( int id )
2028 {
2029     int cascadeId = myWindowPopup.idAt( 0 );
2030     int tileId = myWindowPopup.idAt( 1 );
2031     if ( id == cascadeId || id == tileId )
2032         return;
2033     putInfo( tr("PRP_DESK_WINDOW_ACTIVATE") );
2034 }
2035
2036 /*!
2037     Called when user wants to activate a child  window with 'wid'
2038     in the main frame
2039 */
2040 void QAD_Desktop::onWindowsPopupActivated( int wid )
2041 {
2042     QWidget* w = myWorkspace->windowList().at( wid );
2043     if ( w ) w->setFocus();
2044 }
2045
2046 /*!
2047     Selects a file name when opening or saving files.
2048     The basic implementation just uses the standard
2049     Open/Save dialogs.
2050     Please redefine if another behaviour is required.
2051 */
2052 QString QAD_Desktop::selectFileName ( bool open )
2053 {
2054   QAD_FileDlg* fd = new QAD_FileDlg( this, open, true, true );    
2055
2056   QString name = "";
2057   QString dir  = "";
2058   QStringList filters;
2059
2060   if (open) {
2061     //  All the file types of the supported applications
2062     //    can be opened 
2063     for ( QAD_Application* app = myApps.first(); app; app = myApps.next() )
2064       {
2065         filters += app->getStudyDescription() + " " + tr("DESK_FILES") + " " +
2066                                  "(*." + app->getStudyExtension() + ")";
2067       }
2068   }
2069   else {
2070     QAD_ASSERT_DEBUG_ONLY ( myActiveStudy );
2071     if (myActiveStudy) {
2072       // get file name of active study
2073       name = QAD_Tools::getFileNameFromPath ( myActiveStudy->getTitle() );
2074       // get path to the active study file
2075       dir = QAD_Tools::getDirFromPath ( myActiveStudy->getPath(), false );
2076     }
2077     QAD_ASSERT_DEBUG_ONLY ( !name.isNull() );
2078     // the file types supported by the active application
2079     filters += myActiveApp->getStudyDescription() + " " + tr("DESK_FILES") + " " +
2080                                  "(*." + myActiveApp->getStudyExtension() + ")" ;
2081   }
2082   if (!dir.isEmpty()) {
2083     // when saving document ("Save As" command) - to get dir from active study filename
2084     // for new documents - to use last opened directory
2085     fd->setDir( dir );
2086   }
2087   fd->setSelection( name );
2088   fd->setFilters( filters );
2089    
2090   fd->exec();
2091   QString filename = fd->selectedFile();
2092   delete fd;
2093   qApp->processEvents();
2094   return filename;
2095 }
2096
2097 /*!
2098     Closes all the studies of 'app'. Returns
2099     'true' if thay are closed OK, 'false' at least
2100     one can't be closed or user cancel the closure.
2101 */
2102 bool QAD_Desktop::closeAllStudies( QAD_Application* app )
2103 {
2104     QList<QAD_Study>& studies = app->getStudies();
2105     while ( !studies.isEmpty() )
2106     {
2107       //don't ask user to remove study permanently
2108       if ( !onCloseStudy( studies.at(0), false ) )
2109             return false;   /* user cancelled closing */
2110     }
2111     return true;
2112 }
2113
2114 /*!
2115   Called on Popup item when SComponent representation in Object Browser is selected.
2116 */
2117 void QAD_Desktop::onOpenWith()
2118 {
2119   Engines::Component_var comp;
2120   QString ComponentSelected;
2121
2122   SALOMEDS::SObject_var SO;
2123   SALOMEDS::SComponent_var SCO;
2124   SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
2125   SALOMEDS::GenericAttribute_var anAttr;
2126   SALOMEDS::AttributeName_var aName;
2127
2128   SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2129   if ( Sel->IObjectCount() == 1 ) {
2130     Handle(SALOME_InteractiveObject) IO = Sel->firstIObject();
2131     SO = aStudy->FindObjectID( IO->getEntry() );
2132     SCO = SO->GetFatherComponent();
2133     char* name;
2134     if (SCO->FindAttribute(anAttr, "AttributeName")) {
2135       aName = SALOMEDS::AttributeName::_narrow(anAttr);
2136       name = aName->Value();
2137       SALOME_ModuleCatalog::Acomponent_var Comp = myCatalogue->GetComponent( mapComponentName[name] );
2138       if ( !Comp->_is_nil() ) {
2139         
2140         SALOME_ModuleCatalog::ListOfComponents_var list_type_composants =
2141           myCatalogue->GetTypedComponentList( Comp->component_type() );
2142         
2143         if ( list_type_composants->length() == 1 ) {
2144           ComponentSelected = name;
2145         } else if ( list_type_composants->length() > 1 ) {
2146           SALOMEGUI_OpenWith* aDlg = new SALOMEGUI_OpenWith( this );
2147           for (unsigned int ind = 0; ind < list_type_composants->length();ind++) {
2148             aDlg->addComponent( strdup(list_type_composants[ind]) );
2149           }
2150           
2151           int retVal = aDlg->exec();
2152           ComponentSelected = aDlg->getComponent();
2153           delete aDlg;
2154           if ( retVal == QDialog::Rejected || ComponentSelected.isEmpty()) {
2155             return;
2156           }
2157         } else {
2158           MESSAGE( "No component with type : " << Comp->component_type() << " exists" );
2159           return;
2160         }
2161         
2162       } else {
2163         MESSAGE( "This component not exists in the catalog" );
2164         return;
2165       }
2166       
2167       QApplication::setOverrideCursor( Qt::waitCursor );
2168       Sel->ClearIObjects();
2169       
2170 //      if (loadComponentData(ComponentSelected)) {
2171         onComboActiveComponent(ComponentSelected);
2172 //      int nbItem = myCombo->count();
2173 //      int Index = 0;
2174 //      for (int i = 0; i < nbItem; i++) {
2175 //        if (myCombo->text(i).compare(ComponentSelected)==0) {
2176 //          Index = i;
2177 //          break;
2178 //        }
2179 //      }
2180 //      myCombo->setCurrentItem(Index);
2181 //      myActiveStudy->updateObjBrowser(true);
2182 //      }
2183     }
2184   }
2185   QApplication::restoreOverrideCursor();
2186 }
2187
2188 typedef bool OneDim1(QAD_Desktop*);
2189
2190 /*!
2191   Called to define settings of component.
2192 */
2193 void QAD_Desktop::setSettings()
2194 {
2195   if (!myActiveComp.isEmpty())  {
2196     OSD_Function osdF = mySharedLibrary.DlSymb("SetSettings");
2197     if ( osdF != NULL ) {
2198       OneDim1 (*f1) = (bool (*) (QAD_Desktop*)) osdF;
2199       (*f1)(this);
2200     }
2201   }
2202 }
2203
2204 /*!
2205   Called to load Component : xml resources and GUI librairy.
2206 */
2207 bool QAD_Desktop::loadComponent(QString Component)
2208 {
2209   QAD_WaitCursor wc;
2210   QString resDir("/");  //NRI : Pb under Windows
2211
2212   QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
2213   if ( resMgr ) {
2214     QString msg;
2215     if (!resMgr->loadResources( Component, msg ))
2216       {
2217         //NRI   QCString errMsg;
2218         //      errMsg.sprintf( "Do not load all resources for module %sGUI.\n" ,
2219         //              Component.latin1() );
2220         wc.stop();
2221         QMessageBox::warning( this, tr("WRN_WARNING"), msg, tr ("BUT_OK") );
2222         return false;
2223       }
2224   }
2225     
2226   /* Parse xml file */
2227   myXmlHandler = new QAD_XmlHandler();
2228   myXmlHandler->setMainWindow(this);
2229   if (!myXmlHandler->setComponent(resMgr->resources( Component ))) return false;
2230
2231   QString language = resMgr->language( Component );
2232
2233   QString ComponentXml = Component + "_" + language + ".xml";
2234   //ComponentXml = resMgr->resources(Component + "GUI") ;
2235   //ComponentXml = QAD_Tools::addSlash(ComponentXml) ;
2236   ComponentXml = QAD_Tools::addSlash( resMgr->findFile( ComponentXml, Component ) ) + ComponentXml;
2237   QFile file( ComponentXml );
2238
2239   if ( !file.exists() || !file.open( IO_ReadOnly ) )  {
2240     QString errMsg;
2241     errMsg.sprintf( "Cannot open xml file: %s\n.",
2242                     (file.name()).latin1() );
2243     wc.stop();
2244     QMessageBox::critical( this, tr("ERR_ERROR"), errMsg, tr ("BUT_OK") );
2245     return false;
2246   }
2247   file.close();
2248
2249   QXmlInputSource source( file );
2250   QXmlSimpleReader reader;
2251   reader.setContentHandler( myXmlHandler );
2252   reader.setErrorHandler( myXmlHandler );
2253   bool ok = reader.parse( source );
2254   file.close();
2255   if ( !ok ) {
2256     wc.stop();
2257     QMessageBox::critical( this,
2258                            tr( "INF_PARSE_ERROR" ),
2259                            tr( myXmlHandler->errorProtocol() ) );
2260     return false;
2261   }
2262
2263   myMenusList=myXmlHandler->myMenusList;
2264   myActiveMenus=myMenusList.at(0);
2265   myOperatorMenus->showMenuBar(0);
2266   myActiveMenus->showAllToolBars();
2267
2268   /* Components toolbars */
2269   int nbToolbars = 0;
2270   if (myActiveMenus)
2271     nbToolbars = myActiveMenus->getToolBarList().count();
2272   /* Open Shared Library */
2273   mySharedLibrary = OSD_SharedLibrary();
2274
2275   QString ComponentLib;
2276   QCString libs;
2277   QFileInfo fileInfo ;
2278   QString fileString ;
2279   QString dir;
2280
2281   if ( libs = getenv("LD_LIBRARY_PATH")) {
2282     MESSAGE ( " LD_LIBRARY_PATH : " << libs )
2283     QStringList dirList = QStringList::split( SEPARATOR, libs, false ); // skip empty entries
2284     for ( int i = dirList.count()-1; i >= 0; i-- ) {
2285       dir = dirList[ i ];
2286 #ifdef WNT
2287       fileString = QAD_Tools::addSlash( dir ) + "lib" + Component + "GUI.dll" ;
2288 #else
2289       fileString = QAD_Tools::addSlash( dir ) + "lib" + Component + "GUI.so" ;
2290 #endif
2291     
2292       fileInfo.setFile(fileString) ;
2293       if (fileInfo.exists()) {
2294         MESSAGE ( " GUI library = " << fileString )
2295         ComponentLib = fileInfo.fileName() ;
2296         break;
2297       }
2298     }
2299     MESSAGE ( " GUI library not found " )
2300   }
2301 //    bool found = false;
2302 //    if ( dir = getenv("SALOME_SITE_DIR")) {
2303 //      dir = QAD_Tools::addSlash(dir) ;
2304 //      dir = dir + "lib" ;
2305 //      dir = QAD_Tools::addSlash(dir) ;
2306 //      dir = dir + "salome" ;
2307 //      dir = QAD_Tools::addSlash(dir) ;
2308 //  #ifdef WNT
2309 //      dir = dir + "lib" + Component.latin1() + "GUI.dll" ;
2310 //  #else
2311 //      dir = dir + "lib" + Component.latin1() + "GUI.so" ;
2312 //  #endif
2313 //      MESSAGE ( " GUI library = " << dir )
2314 //      fileInfo.setFile(dir) ;
2315 //      if (fileInfo.exists()) {
2316 //        ComponentLib = fileInfo.fileName() ;
2317 //        found = true;
2318 //      }
2319 //    }
2320   
2321 //    if ( (dir = getenv("SALOME_ROOT_DIR")) && !found ) {
2322 //      dir = QAD_Tools::addSlash(dir) ;
2323 //      dir = dir + "lib" ;
2324 //      dir = QAD_Tools::addSlash(dir) ;
2325 //      dir = dir + "salome" ;
2326 //      dir = QAD_Tools::addSlash(dir) ;
2327 //  #ifdef WNT
2328 //      dir = dir + "lib" + Component.latin1() + "GUI.dll" ;
2329 //  #else
2330 //      dir = dir + "lib" + Component.latin1() + "GUI.so" ;
2331 //  #endif
2332 //      MESSAGE ( " GUI library = " << dir )
2333 //      fileInfo.setFile(dir) ;
2334 //      if (fileInfo.exists()) {
2335 //        ComponentLib = fileInfo.fileName() ;
2336 //        found = true;
2337 //      }
2338 //    }
2339
2340   mySharedLibrary.SetName(TCollection_AsciiString((char*)ComponentLib.latin1()).ToCString());
2341   ok = mySharedLibrary.DlOpen(OSD_RTLD_LAZY);
2342   if (!ok) {
2343     wc.stop();
2344     QMessageBox::critical( this,
2345                            tr("ERR_ERROR"),
2346                            tr( mySharedLibrary.DlError() ) );
2347     return false;
2348   }
2349
2350   /* SETTINGS */
2351   OSD_Function osdF = mySharedLibrary.DlSymb("SetSettings");
2352   if ( osdF != NULL ) {
2353     OneDim1 (*f1) = (bool (*) (QAD_Desktop*)) osdF;
2354     (*f1)(this);
2355   }
2356
2357   /* COMPONENT INTERFACE */
2358   SALOME_ModuleCatalog::Acomponent_ptr aComponent =
2359     myCatalogue->GetComponent(Component.latin1());
2360
2361   if (CORBA::is_nil (aComponent)) {
2362     MESSAGE( "Catalog Error : Component not found in the catalog" )
2363     return false;
2364   }
2365
2366   myActiveStudy->setMessage(QString("Component : ") +
2367                             aComponent->componentusername() + " created " );
2368   myActiveStudy->setMessage(QString("Type : ") +
2369                             QString::number(aComponent->component_type()));
2370   myActiveStudy->setMessage(QString("Constraint : ") +
2371                             aComponent->constraint() );
2372
2373   /* obtain interfaces list of the component */
2374   SALOME_ModuleCatalog::ListOfInterfaces_var _list =
2375     new SALOME_ModuleCatalog::ListOfInterfaces;
2376   _list = aComponent->GetInterfaceList();
2377
2378   if (_list->length() != 0 ) {
2379
2380     for (unsigned int ind = 0; ind < _list->length();ind++)
2381       myActiveStudy->setMessage( QString("Interface name : ") +
2382                                  _list[ind] );
2383
2384
2385     /* obtain services list of the component */
2386     SALOME_ModuleCatalog::ListOfServices_var list_services_component =
2387       new SALOME_ModuleCatalog::ListOfServices;
2388     list_services_component = aComponent->GetServiceList(_list[0]);
2389
2390     if (list_services_component->length() != 0 ) {
2391
2392       for (unsigned int ind = 0; ind < list_services_component->length();ind++)
2393         myActiveStudy->setMessage( QString("Service name : ") +
2394                                    list_services_component[ind] );
2395
2396       // Get a service of the component
2397       SALOME_ModuleCatalog::Service_var service = new SALOME_ModuleCatalog::Service;
2398       service  = aComponent->GetService(_list[0],list_services_component[0]) ;
2399       myActiveStudy->setMessage( QString("Service name: ") + service->ServiceName);
2400       for (unsigned int ind1 = 0; ind1 <service->ServiceinParameter.length();ind1++) {
2401         myActiveStudy->setMessage( QString("Type of the in Parameter of this service : ") +
2402                                    (const char *) service->ServiceinParameter[ind1].Parametertype);
2403         myActiveStudy->setMessage( QString("Name of the in Parameter of this service : ") +
2404                                    (const char *) service->ServiceinParameter[ind1].Parametername);
2405       }
2406       for (unsigned int ind1 = 0; ind1 <service->ServiceoutParameter.length();ind1++) {
2407         myActiveStudy->setMessage( QString("Type of the out Parameter of this service : ") +
2408                                    (const char *) service->ServiceoutParameter[ind1].Parametertype);
2409         myActiveStudy->setMessage( QString("Name of the out Parameter of this service : ") +
2410                                    (const char *) service->ServiceoutParameter[ind1].Parametername);
2411       }
2412     }
2413   }
2414   return true;
2415 }
2416
2417 typedef bool OneDim(int, QAD_Desktop*);
2418 typedef void (*PTR_FACTORY_FUNCTION)( CORBA::ORB_var &orb, QWidget *parent, const char *name ) ;
2419
2420 /*!
2421  */
2422 void QAD_Desktop::onDispatch()
2423 {
2424   const QObject* obj = sender();
2425
2426   QList<QAD_ListMenuIdAction> MenuList = myActiveMenus->getMenuList();
2427   QAD_ListMenuIdAction* aMenu;
2428   int id = -1;
2429   for(aMenu=MenuList.first();aMenu!=NULL;aMenu=MenuList.next()) {
2430     if (aMenu->getAction()==obj) {
2431       id = aMenu->getId();
2432       break;
2433     }
2434   }
2435   onDispatch(id);
2436 }
2437
2438 /*!
2439  */
2440 void QAD_Desktop::onDispatchTools(int id)
2441 {
2442   /* Open Shared Library */
2443   OSD_SharedLibrary ToolsLibrary = OSD_SharedLibrary();
2444
2445   QString ToolsLib;
2446   QCString dir;
2447   QFileInfo fileInfo ;
2448   bool found = false;
2449
2450   char arg[256] ;
2451   bool libToolsGUI = true;
2452   if( QAD_XmlHandler::_bibmap[ id ].isEmpty() ) 
2453   { 
2454
2455     if ( dir = getenv("SALOME_SITE_DIR"))  {
2456       dir = QAD_Tools::addSlash(dir) ;
2457       dir = dir + "lib" ;
2458       dir = QAD_Tools::addSlash(dir) ;
2459       dir = dir + "salome" ;
2460       dir = QAD_Tools::addSlash(dir) ;
2461 #ifdef WNT
2462       dir = dir + "libToolsGUI.dll" ;
2463 #else
2464       dir = dir + "libToolsGUI.so" ;
2465 #endif
2466       MESSAGE ( " GUI library = " << dir );
2467       fileInfo.setFile(dir) ;
2468       if (fileInfo.exists()) {
2469         ToolsLib = fileInfo.fileName() ;
2470         found = true;
2471       }
2472     }
2473     
2474     if ( (dir = getenv("SALOME_ROOT_DIR")) && !found ) {
2475       dir = QAD_Tools::addSlash(dir) ;
2476       dir = dir + "lib" ;
2477       dir = QAD_Tools::addSlash(dir) ;
2478       dir = dir + "salome" ;
2479       dir = QAD_Tools::addSlash(dir) ;
2480 #ifdef WNT
2481       dir = dir + "libToolsGUI.dll" ;
2482 #else
2483       dir = dir + "libToolsGUI.so" ;
2484 #endif
2485       MESSAGE ( " GUI library = " << dir );
2486       fileInfo.setFile(dir) ;
2487       if (fileInfo.exists()) {
2488         ToolsLib = fileInfo.fileName() ;
2489         found = true;
2490       }
2491     }
2492   }
2493   else {
2494     libToolsGUI = false;
2495     SCRUTE( QAD_XmlHandler::_bibmap[ id ] ) ;
2496     if ( dir = getenv("SALOME_SITE_DIR"))  {
2497       dir = QAD_Tools::addSlash(dir) ;
2498       dir = dir + "lib" ;
2499       dir = QAD_Tools::addSlash(dir) ;
2500       dir = dir + "salome" ;
2501       dir = QAD_Tools::addSlash(dir) ;
2502       dir = dir + QAD_XmlHandler::_bibmap[ id ].latin1() ;
2503       MESSAGE ( " GUI library = " << dir );
2504       fileInfo.setFile(dir) ;
2505       if (fileInfo.exists()) {
2506         ToolsLib = fileInfo.fileName() ;
2507         found = true;
2508       }
2509     }
2510     
2511     if ( (dir = getenv("SALOME_ROOT_DIR")) && !found ) {
2512       dir = QAD_Tools::addSlash(dir) ;
2513       dir = dir + "lib" ;
2514       dir = QAD_Tools::addSlash(dir) ;
2515       dir = dir + "salome" ;
2516       dir = QAD_Tools::addSlash(dir) ;
2517       dir = dir + QAD_XmlHandler::_bibmap[ id ].latin1() ;
2518       MESSAGE ( " GUI library = " << dir );
2519       fileInfo.setFile(dir) ;
2520       if (fileInfo.exists()) {
2521         ToolsLib = fileInfo.fileName() ;
2522         found = true;
2523       }
2524     }
2525   }
2526
2527   ToolsLibrary.SetName(TCollection_AsciiString((char*)ToolsLib.latin1()).ToCString());
2528   bool ok = ToolsLibrary.DlOpen(OSD_RTLD_LAZY);
2529   if (ok) {
2530     if ( libToolsGUI ) {
2531       OSD_Function osdF = ToolsLibrary.DlSymb("OnGUIEvent");
2532       OneDim (*f1) = NULL;
2533       f1 = (bool (*) (int, QAD_Desktop*)) osdF;
2534       (*f1)(id,this);
2535     } else {
2536       ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
2537       ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
2538       CORBA::ORB_var &orb = init(0 , 0 ) ;
2539       OSD_Function osdF = ToolsLibrary.DlSymb("OnGUIEvent");
2540       PTR_FACTORY_FUNCTION f1 = NULL;
2541       f1 = (PTR_FACTORY_FUNCTION) osdF;
2542       f1(orb,0,"Registry");
2543     }
2544   } else {
2545     QMessageBox::critical( this,
2546                            tr("ERR_ERROR"),
2547                            tr( ToolsLibrary.DlError() ) );
2548   }
2549 }
2550
2551 /*!
2552  */
2553 void QAD_Desktop::onDispatch(int id)
2554 {
2555   if (!myActiveComp.isEmpty())  {
2556     OSD_Function osdF = mySharedLibrary.DlSymb("OnGUIEvent");
2557     OneDim (*f1) = NULL;
2558     if ( osdF != NULL ) {
2559       f1 = (bool (*) (int, QAD_Desktop*)) osdF;
2560       (*f1)(id,this);
2561     }
2562   }
2563 }
2564
2565 /*!
2566   Returns the component's catalogue
2567 */
2568 SALOME_ModuleCatalog::ModuleCatalog_var QAD_Desktop::getCatalogue()
2569 {
2570   return myCatalogue;
2571 }
2572
2573 /*!
2574  */
2575 void QAD_Desktop::onComboActiveComponent( const QString & component ){
2576   onComboActiveComponent(component,true);
2577 }
2578 void QAD_Desktop::onComboActiveComponent( const QString & component, bool isLoadData)
2579 {
2580   if (myActiveStudy != 0) {
2581     if (myActiveComp.compare(component)!=0) {
2582       if (!myXmlHandler->myIdList.IsEmpty()) clearMenus();
2583       if ( myCombo->currentText() != component )
2584         myCombo->setCurrentText( component );
2585       if (component.compare(QString("Salome"))!= 0) {
2586 //      QApplication::setOverrideCursor( Qt::waitCursor );
2587         myActiveComp = component;
2588
2589         SALOME_Selection* oldSel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2590
2591         for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2592           if ( aButton->textLabel().compare(component)==0)
2593             aButton->setOn(true);
2594           else
2595             aButton->setOn(false);
2596         }
2597
2598         myActiveStudy->Selection( component );
2599         if ( !loadComponent(mapComponentName[component]) ) {
2600           myCombo->setCurrentItem (0);
2601           for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2602             aButton->setOn(false);
2603           }
2604           myActiveComp = "";
2605         }
2606
2607         SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2608         SALOME_ListIteratorOfListIO It( oldSel->StoredIObjects() );
2609         for(;It.More();It.Next()) {
2610           int res = Sel->AddIObject( It.Value() );
2611
2612           if ( res == -1 )
2613             myActiveStudy->highlight( It.Value(), false );
2614           if ( res == 0 )
2615             myActiveStudy->highlight( It.Value(), true );
2616           
2617         }
2618
2619         // Open new component's data in active study if any
2620         if(isLoadData) loadComponentData(mapComponentName[component]);
2621
2622         oldSel->Clear();
2623         myActiveStudy->updateObjBrowser(true);
2624
2625 //      QApplication::restoreOverrideCursor();
2626
2627       } else {  // component == "Salome"
2628         myActiveComp = "";
2629         myActiveStudy->Selection( "Salome" );
2630         SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2631         Sel->ClearIObjects();
2632         for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2633           aButton->setOn(false);
2634         }
2635       }
2636     } else {
2637       for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2638         if ( aButton->textLabel().compare(component)==0)
2639           aButton->setOn(true);
2640       }
2641     }
2642   } else {
2643     QMessageBox::critical( 0,
2644                            tr( "ERR_ERROR" ),
2645                            tr( "WRN_LOAD_COMPONENT" ) );
2646     myCombo->setCurrentItem (0);        
2647     for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2648       aButton->setOn(false);
2649     }
2650   }
2651 }
2652
2653 /*!
2654  */
2655 void QAD_Desktop::activateComponent(const QString& theName, bool isLoadData){
2656   int nbItem = myCombo->count();
2657   int Index = 0;
2658
2659   for (int i = 0; i < nbItem; i++) {
2660     if (myCombo->text(i).compare(theName)==0) {
2661       Index = i;
2662       break;
2663     }
2664   }
2665   myCombo->setCurrentItem (Index);
2666   onComboActiveComponent(theName,isLoadData);
2667 };
2668
2669 void QAD_Desktop::onButtonActiveComponent( )
2670 {
2671   QToolButton* obj = (QToolButton*)sender();
2672   activateComponent(obj->textLabel());
2673 }
2674
2675 /*!
2676   Clears All Resources of current component
2677  */
2678 void QAD_Desktop::clearMenus()
2679 {
2680   onActiveStudyChanged();
2681
2682   /* menus */
2683   myMenusList.clear();
2684   if (myXmlHandler) {
2685     int length = myXmlHandler->myIdList.Length();
2686     for (int k=length; k>0; k--) {
2687       QMenuData* parent;
2688       if ( menuBar()->findItem(myXmlHandler->myIdList.Value(k), &parent) )
2689         parent->removeItem( myXmlHandler->myIdList.Value(k) );
2690     }
2691   }
2692
2693   /* toolbars */
2694   if (myActiveMenus) {
2695     int nbtoolbars = myActiveMenus->getToolBarList().count();
2696     for (int k=0; k<nbtoolbars; k++) {
2697       myActiveMenus->getToolBarList().at(k)->hide();
2698       myActiveMenus->getToolBarList().at(k)->clear();
2699     }
2700     myActiveMenus->clearToolBar();
2701
2702     /* popups */
2703     QList<QAD_ListPopupMenu> PopupList = myActiveMenus->getPopupMenuList();
2704     QAD_ListPopupMenu* aPopup;
2705     for(aPopup=PopupList.first();aPopup!=NULL;aPopup=PopupList.next()){
2706       aPopup->getPopup()->clear();
2707       
2708     }
2709     myActiveMenus->clearPopupMenu();
2710
2711   }
2712   myActiveComp = "";
2713 }
2714
2715 typedef bool TwoDim1(QKeyEvent* pe, QAD_Desktop*, QAD_StudyFrame*);
2716 /*!
2717   Exports Key Events in active component ( GUI Librairy )
2718  */
2719 void QAD_Desktop::onKeyPress( QKeyEvent* pe )
2720 {
2721   //  MESSAGE ( "QAD_Desktop::onKeyPress" )
2722   if (!myActiveComp.isEmpty())  {
2723     OSD_Function osdF = mySharedLibrary.DlSymb("OnKeyPress");
2724     if ( osdF != NULL ) {
2725       TwoDim1 (*f1) = (bool (*) (QKeyEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
2726       (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
2727     }
2728   }
2729 }
2730
2731 typedef bool TwoDim(QMouseEvent* pe, QAD_Desktop*, QAD_StudyFrame*);
2732 /*!
2733   Exports Mouse Press Events in active component ( GUI Librairy )
2734  */
2735 bool QAD_Desktop::onMousePress( QMouseEvent* pe )
2736 {
2737   //  MESSAGE ( "QAD_Desktop::onMousePress" )
2738   if (!myActiveComp.isEmpty())  {
2739     OSD_Function osdF = mySharedLibrary.DlSymb("OnMousePress");
2740     if ( osdF != NULL ) {
2741       TwoDim (*f1) = (bool (*) (QMouseEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
2742       return (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
2743     }
2744   }
2745   return false;
2746 }
2747
2748 /*!
2749   Exports Mouse Move Events in active component ( GUI Librairy )
2750  */
2751 void QAD_Desktop::onMouseMove( QMouseEvent* pe )
2752 {
2753   if (!myActiveComp.isEmpty())  {
2754     OSD_Function osdF = mySharedLibrary.DlSymb("OnMouseMove");
2755     if ( osdF != NULL ) {
2756       TwoDim (*f1) = (bool (*) (QMouseEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
2757       (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
2758     }
2759   }
2760 }
2761
2762 /*!
2763     Returns name of active component
2764 */
2765 const QString& QAD_Desktop::getActiveComponent() const
2766 {
2767   return myActiveComp;
2768 }
2769
2770
2771 typedef bool defineP( QString & theContext, QString & theParent, QString & theObject);
2772
2773 void QAD_Desktop::definePopup(QString & theContext,
2774                               QString & theParent, 
2775                               QString & theObject ) 
2776 {
2777   if (!myActiveComp.isEmpty())  {
2778     OSD_Function osdF = mySharedLibrary.DlSymb("definePopup");
2779     if ( osdF != NULL ) {
2780       defineP (*f1) = (bool (*) (QString &, QString &, QString &)) osdF;
2781       (*f1)(theContext, theParent, theObject);
2782     }
2783   }
2784 }
2785
2786 /*!
2787     Create popup
2788 */
2789 void QAD_Desktop::createPopup(QPopupMenu* popupFather, QPopupMenu* popup,
2790                               QString text, int popupID, bool separator)
2791 {
2792   QMenuItem* item = popup->findItem(popupID);
2793   if (item) {
2794     QPopupMenu* popupChild = item->popup();
2795     if ( popupChild ) {
2796       QPopupMenu* newPopup = new QPopupMenu;
2797       int count = popupChild->count();
2798       // add items at the top of <popupFather>
2799       for (int i = count - 1; i >= 0; i--) {
2800         int j = popupChild->idAt(i);
2801         QString text = popupChild->text(j);
2802         createPopup( newPopup, popupChild, text, j);
2803       }
2804       popupFather->insertItem(popup->text(popupID),
2805                               newPopup, popupID, 0);
2806     } else {
2807       if ( !text.isNull() ) {
2808         popupFather->insertItem(popup->text(popupID),
2809                                 this,
2810                                 SLOT( onDispatch(int) ), 0, popupID, 0);// try adding item at the top
2811       } /*else if ( separator ) 
2812         popupFather->insertTearOffHandle(-1, 0);*/
2813       else
2814         popupFather->insertSeparator(0);
2815     }
2816   }
2817 }
2818
2819 /*!
2820     Create popup
2821 */
2822 void QAD_Desktop::createPopup(QPopupMenu* popup, const QString & theContext,
2823                               const QString & theParent, const QString & theObject )
2824 {
2825   if ( !myActiveComp.isEmpty() && 
2826        getOperatorMenus()->createPopupMenu(theContext,theParent,theObject) != NULL ) {
2827     QPopupMenu* aPopup = getOperatorMenus()->createPopupMenu(theContext,theParent,theObject)->getPopup();
2828     int count = aPopup->count();
2829
2830     //for (int i = 0; i < count; i++) {
2831     for (int i = count - 1; i >= 0; i--) {
2832       int id = aPopup->idAt(i);
2833       QString text = aPopup->text(id);
2834       //QString mes("Inserting popup menu item loaded from XML: ");
2835       //mes += text;
2836       //MESSAGE ( mes.latin1() )
2837       if (i==0)
2838         popup->insertItem(aPopup->text(id),
2839                           this,
2840                           SLOT( onDispatch(int) ), 0, id, 0);// try adding item at the top
2841       else
2842         createPopup( popup, aPopup, text, id);
2843     }
2844   } //else {
2845     //QString mes("Popup does not exist for given (Context = ");
2846     //mes += theContext;
2847     //mes += ", Parent = ";
2848     //mes += theParent;
2849     //mes += ", Object = ";
2850     //mes += theObject;
2851     //MESSAGE (mes.latin1())
2852       //popup->clear();
2853   //}
2854
2855   // IAPP Popup 
2856   // Should be moved to SALOMEGUI_Application::onCreatePopup()...
2857   if ( myActiveComp.isEmpty() ) {
2858     popup->removeItem(QAD_Display_Popup_ID);
2859     popup->removeItem(QAD_DisplayOnly_Popup_ID);
2860     popup->removeItem(QAD_Erase_Popup_ID);
2861     int id = popup->idAt(popup->count()-1); // last item
2862     if (id < 0 && id != -1) popup->removeItem(id); // separator
2863
2864     if ( popup && theParent.compare("ObjectBrowser")==0 ) {
2865       if ( popup->count()>0 ) {
2866         popup->insertItem (tr ("MEN_OPENWITH"), this, SLOT(onOpenWith()), 0, -1, 2);
2867         popup->insertSeparator (3);
2868       }
2869       else {
2870         popup->insertItem (tr ("MEN_OPENWITH"), this, SLOT(onOpenWith()) );
2871       }
2872     } 
2873   }
2874  
2875 }
2876
2877 typedef bool activeStudyChanged(QAD_Desktop*);
2878
2879 void QAD_Desktop::onActiveStudyChanged()
2880 {
2881   if (!myActiveComp.isEmpty())  {
2882     OSD_Function osdF = mySharedLibrary.DlSymb("activeStudyChanged");
2883     if ( osdF != NULL ) {
2884       activeStudyChanged (*f1) = (bool (*) (QAD_Desktop*)) osdF;
2885       (*f1)(this);
2886     }  
2887   }
2888 }
2889
2890 typedef bool customP(QAD_Desktop*, QPopupMenu*, const QString & theContext,
2891                      const QString & theParent, const QString & theObject);
2892 /*!
2893   Custom popup ( GUI Library )
2894 */
2895 void QAD_Desktop::customPopup(QPopupMenu* popup, const QString & theContext,
2896                               const QString & theParent, const QString & theObject)
2897 {
2898   if (!myActiveComp.isEmpty())  {
2899     OSD_Function osdF = mySharedLibrary.DlSymb("customPopup");
2900     if ( osdF != NULL ) {
2901       customP (*f1) = (bool (*) (QAD_Desktop*, QPopupMenu*, const QString &,
2902                                  const QString &, const QString &)) osdF;
2903       (*f1)(this, popup, theContext, theParent, theObject);
2904     }
2905   }
2906 }
2907
2908 void QAD_Desktop::onObjectBrowser()
2909 {
2910   bool checkDiff = false;
2911
2912   bool state  = QAD_CONFIG->getSetting("ObjectBrowser:AddColumn").compare("true") == 0;
2913
2914   if ( myStdActions.at( PrefObjectBrowserEntryId )->isOn() != state )
2915     checkDiff = true;
2916
2917   bool showEntry;
2918   if ( myStdActions.at( PrefObjectBrowserEntryId )->isOn() ) {
2919     showEntry = true;
2920     QAD_CONFIG->addSetting( "ObjectBrowser:AddColumn", "true");
2921   } else {
2922     showEntry = false;
2923     QAD_CONFIG->addSetting( "ObjectBrowser:AddColumn", "false");
2924   }  
2925
2926   bool showValue;
2927   if ( myStdActions.at( PrefObjectBrowserValueId )->isOn() ) {
2928     showValue = true;
2929     QAD_CONFIG->addSetting( "ObjectBrowser:ValueColumn", "true");
2930   } else {
2931     showValue = false;
2932     QAD_CONFIG->addSetting( "ObjectBrowser:ValueColumn", "false");
2933   }  
2934
2935   bool showIAPP;
2936   if ( myStdActions.at( PrefObjectBrowserIAPPId )->isOn() ) {
2937     showIAPP = true;
2938     QAD_CONFIG->addSetting( "ObjectBrowser:IAPP", "true");
2939   } else {
2940     showIAPP = false;
2941     QAD_CONFIG->addSetting( "ObjectBrowser:IAPP", "false");
2942   }  
2943   
2944   /* To sort created object in chrono order or reverse chrono order */
2945   bool showCHRONO_SORT ;
2946   if ( myStdActions.at( PrefObjectBrowserCHRONO_SORTId )->isOn() ) {
2947     showCHRONO_SORT = true;
2948     QAD_CONFIG->addSetting( "ObjectBrowser:CHRONO_SORT", "true");
2949   } else {
2950     showCHRONO_SORT = false;
2951     QAD_CONFIG->addSetting( "ObjectBrowser:CHRONO_SORT", "false");
2952   }
2953
2954   if ( myActiveApp ) {
2955     QList<QAD_Study>& studies = myActiveApp->getStudies();
2956     for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
2957       int nbSf = study->getStudyFramesCount();
2958       for ( int i = 0; i < nbSf; i++ ) {
2959         QAD_StudyFrame* sf = study->getStudyFrame(i);
2960         sf->getLeftFrame()->getObjectBrowser()->setShowInfoColumns( showEntry );
2961         sf->getLeftFrame()->getObjectBrowser()->setShowValueColumn( showValue );
2962         sf->getLeftFrame()->getObjectBrowser()->setEnableChronoSort( showCHRONO_SORT );
2963 //      sf->getLeftFrame()->getObjectBrowser()->setShowIAPP( showIAPP ); // this is done by below updateObjBrowser() call
2964       }
2965       study->updateObjBrowser(true);
2966     }
2967   }
2968 }
2969
2970 void QAD_Desktop::onViewerTrihedron()
2971 {
2972   QString Size = QAD_CONFIG->getSetting("Viewer:TrihedronSize");
2973   float dim;
2974
2975   SALOMEGUI_TrihedronSizeDlg *Dlg = new SALOMEGUI_TrihedronSizeDlg(this);
2976   if (!Size.isEmpty())
2977     Dlg->setTrihedronSize(Size.toInt());
2978   int r = Dlg->exec();
2979   dim = Dlg->getTrihedronSize();
2980   delete Dlg;
2981   
2982   if (r == QDialog::Accepted) {
2983     QAD_CONFIG->addSetting("Viewer:TrihedronSize", dim);
2984
2985     if( myActiveApp ) {
2986       QList<QAD_Study>& studies = myActiveApp->getStudies();
2987       for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
2988         int nbSf = study->getStudyFramesCount();
2989         for ( int i = 0; i < nbSf; i++ ) {
2990           study->getStudyFrame(i)->getRightFrame()->getViewFrame()->SetTrihedronSize(dim);
2991         }
2992       }
2993     }
2994   }
2995 }
2996
2997 void QAD_Desktop::onDirList() 
2998 {
2999   // getting dir list from settings
3000   QStringList dirList = QStringList::split(';', QAD_CONFIG->getSetting("FileDlg:QuickDirList"), false);
3001   QAD_DirListDlg* dlg = new QAD_DirListDlg(this);
3002   dlg->setPathList(dirList);
3003   if ( dlg->exec() == QDialog::Accepted) {
3004     dlg->getPathList(dirList);
3005     QAD_CONFIG->addSetting("FileDlg:QuickDirList", dirList.join(";"));
3006   }
3007   delete dlg;
3008 }
3009
3010 void QAD_Desktop::onConsoleFontAction()
3011 {
3012   // getting font from settings
3013   QString fntSet = QAD_CONFIG->getSetting("Viewer:ConsoleFont");
3014   QFont font = QAD_Tools::stringToFont( fntSet );
3015   bool bOk;
3016   font = QFontDialog::getFont( &bOk, font, this );
3017   if ( bOk ) {
3018     fntSet = QAD_Tools::fontToString( font );
3019     QAD_CONFIG->addSetting("Viewer:ConsoleFont", fntSet );
3020
3021     if( myActiveApp ) {
3022       QList<QAD_Study>& studies = myActiveApp->getStudies();
3023       for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
3024         int nbSf = study->getStudyFramesCount();
3025         for ( int i = 0; i < nbSf; i++ ) {
3026           study->getStudyFrame(i)->getRightFrame()->getPyEditor()->setFont( font );
3027           study->getStudyFrame(i)->getRightFrame()->getMessage()->setFont( font );
3028         }
3029       }
3030     }
3031   }
3032 }
3033
3034 void QAD_Desktop::onSavePref()
3035 {
3036   QAD_CONFIG->createConfigFile(true);
3037 }
3038
3039 //VRV: T2.5 - add default viewer
3040 void QAD_Desktop::onDefaultViewer(QAction * theAction)
3041 {
3042   int type = VIEW_TYPE_MAX;
3043   
3044   QString myValue;
3045   if (myStdActions.at(DefaultViewerOCCId) == theAction)
3046     type = VIEW_OCC;
3047   else if (myStdActions.at(DefaultViewerVTKId) == theAction)
3048     type = VIEW_VTK;
3049   else if (myStdActions.at(DefaultGraphSupervisorId) == theAction)
3050     type = VIEW_GRAPHSUPERV;
3051   else if (myStdActions.at(DefaultPlot2dId) == theAction)
3052     type = VIEW_PLOT2D;
3053   if ( type != VIEW_TYPE_MAX )
3054     QAD_CONFIG->addSetting( "Viewer:DefaultViewer", QString::number( type ) );
3055 }
3056 //VRV: T2.5 - add default viewer
3057
3058 void QAD_Desktop::onViewerOCC()
3059 {
3060   QString BackgroundColorRed   = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorRed");
3061   QString BackgroundColorGreen = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorGreen");
3062   QString BackgroundColorBlue  = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorBlue");
3063   QColor color;
3064
3065   if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3066     color = QColor(BackgroundColorRed.toInt(),
3067                    BackgroundColorGreen.toInt(),
3068                    BackgroundColorBlue.toInt());
3069   else
3070     color = QColor(35, 136, 145);
3071
3072   QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3073
3074   if (c.isValid()) {
3075     if ( myActiveApp ) {
3076       QList<QAD_Study>& studies = myActiveApp->getStudies();
3077       for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
3078         int nbSf = study->getStudyFramesCount();
3079         for ( int i = 0; i < nbSf; i++ ) {
3080           QAD_StudyFrame* sf = study->getStudyFrame(i);
3081           if ( sf->getTypeView() == VIEW_OCC ) {
3082             sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3083           }
3084         }
3085       }
3086     }
3087     QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorRed",   c.red() );
3088     QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorGreen", c.green() );
3089     QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorBlue",  c.blue() );
3090   }
3091 }
3092
3093 void QAD_Desktop::onGraphSupervisor()
3094 {
3095   QString BackgroundColorRed   = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorRed");
3096   QString BackgroundColorGreen = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorGreen");
3097   QString BackgroundColorBlue  = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorBlue");
3098   QColor color;
3099
3100   if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3101     color = QColor(BackgroundColorRed.toInt(),
3102                    BackgroundColorGreen.toInt(),
3103                    BackgroundColorBlue.toInt());
3104   else
3105     color = QColor(35, 136, 145);
3106
3107   QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3108
3109   if (c.isValid()) {
3110     if ( myActiveApp ) {
3111       QList<QAD_Study>& studies = myActiveApp->getStudies();
3112       for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
3113         int nbSf = study->getStudyFramesCount();
3114         for ( int i = 0; i < nbSf; i++ ) {
3115           QAD_StudyFrame* sf = study->getStudyFrame(i);
3116           if ( sf->getTypeView() == VIEW_GRAPHSUPERV ) {
3117             sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3118           }
3119         }
3120       }
3121     }
3122     
3123     QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorRed",   c.red() );
3124     QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorGreen", c.green() );
3125     QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorBlue",  c.blue() );
3126   }
3127 }
3128
3129 void QAD_Desktop::onViewerVTK()
3130 {
3131   QString BackgroundColorRed   = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorRed");
3132   QString BackgroundColorGreen = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorGreen");
3133   QString BackgroundColorBlue  = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorBlue");
3134   QColor color;
3135
3136   if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3137     color = QColor(BackgroundColorRed.toInt(),
3138                    BackgroundColorGreen.toInt(),
3139                    BackgroundColorBlue.toInt());
3140   else
3141     color = QColor(0, 0, 0);
3142
3143   QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3144
3145   if (c.isValid()) {
3146     if ( myActiveApp ) {
3147       QList<QAD_Study>& studies = myActiveApp->getStudies();
3148       for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
3149         int nbSf = study->getStudyFramesCount();
3150         for ( int i = 0; i < nbSf; i++ ) {
3151           QAD_StudyFrame* sf = study->getStudyFrame(i);
3152           if ( sf->getTypeView() == VIEW_VTK ) {
3153             sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3154           }
3155         }
3156       }
3157     }
3158     
3159     QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorRed",   c.red() );
3160     QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorGreen", c.green() );
3161     QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorBlue",  c.blue() );
3162   }
3163 }
3164
3165 void QAD_Desktop::onPlot2d()
3166 {
3167   QColor color;
3168   if ( QAD_CONFIG->hasSetting( "Plot2d:Background" ) ) {
3169     QString bgString = QAD_CONFIG->getSetting( "Plot2d:Background" );                               
3170     QStringList bgData = QStringList::split( ":", bgString, true );
3171     int bgRed = 0, bgGreen = 0, bgBlue = 0;
3172     if ( bgData.count() > 0 ) bgRed   = bgData[ 0 ].toInt();
3173     if ( bgData.count() > 1 ) bgGreen = bgData[ 1 ].toInt();
3174     if ( bgData.count() > 2 ) bgBlue  = bgData[ 2 ].toInt();
3175     color = QColor( bgRed, bgGreen, bgBlue );
3176   }
3177   else {
3178     color = QColor(0, 0, 0);  
3179   }
3180
3181   color = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3182
3183   if ( color.isValid() ) {
3184     if ( myActiveApp ) {
3185       QList<QAD_Study>& studies = myActiveApp->getStudies();
3186       for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
3187         int nbSf = study->getStudyFramesCount();
3188         for ( int i = 0; i < nbSf; i++ ) {
3189           QAD_StudyFrame* sf = study->getStudyFrame(i);
3190           if ( sf->getTypeView() == VIEW_PLOT2D ) {
3191             sf->getRightFrame()->getViewFrame()->setBackgroundColor( color );
3192           }
3193         }
3194       }
3195     }
3196     QStringList bgData; 
3197     bgData.append( QString::number( color.red() ) );
3198     bgData.append( QString::number( color.green() ) );
3199     bgData.append( QString::number( color.blue() ) );
3200     QAD_CONFIG->addSetting( "Plot2d:Background", bgData.join( ":" ) );
3201   }
3202 }
3203
3204 /* Help About */
3205 void QAD_Desktop::helpAbout()
3206 {
3207   SALOMEGUI_AboutDlg* About = new SALOMEGUI_AboutDlg( QAD_Application::getDesktop(), tr("MEN_ABOUT"));
3208   About->exec();
3209   delete About;
3210 }
3211
3212 /* Help Search */
3213 void QAD_Desktop::helpSearch()
3214 {
3215 }
3216
3217 /* Help Contents */
3218 void QAD_Desktop::helpContents()
3219 {
3220   getHelpWindow()->contents();
3221   getHelpWindow()->show();
3222   getHelpWindow()->raise();
3223   getHelpWindow()->setActiveWindow();
3224 }
3225
3226 /* Help Context */
3227 void QAD_Desktop::helpContext(const QString& source, const QString& context)
3228 {
3229   getHelpWindow()->context(source, context);
3230   getHelpWindow()->show();
3231   getHelpWindow()->raise();
3232   getHelpWindow()->setActiveWindow();
3233 }
3234
3235 /* Preferences/MultiFile Save */
3236 void QAD_Desktop::onMultiFileSave()
3237 {
3238   if ( myStdActions.at( PrefMultiFileSave )->isOn() )
3239     QAD_CONFIG->addSetting( "Desktop:MultiFileSave", "true");
3240   else
3241     QAD_CONFIG->addSetting( "Desktop:MultiFileSave", "false");
3242 }
3243
3244 /*********************************************************************
3245 ** Class: AppSelectionDlg
3246 ** Descr: Dialog for the selection of the application when several
3247 **        applications exist in the desktop and new study creation
3248 **        is activated by user.
3249 ** Level: Internal
3250 **********************************************************************/
3251 /*!
3252   \class Desktop_AppSelectionDlg QAD_Desktop.h
3253   \brief Dialog for the selection of the application when several
3254   applications exist in the desktop and new study creation
3255   is activated by user.
3256
3257   Level: Internal.
3258 */
3259
3260 Desktop_AppSelectionDlg::Desktop_AppSelectionDlg( QAD_Desktop* desktop,
3261                                                   QList<QAD_Application>& apps ) :
3262 QDialog( desktop, 0, true ),
3263 myAppId( 0 ),
3264 myApps( apps )
3265 {
3266     QAD_ASSERT_DEBUG_ONLY ( desktop );
3267     setCaption( tr("INF_DESK_DOC_CREATE") );
3268     if ( desktop->icon() )
3269     setIcon( *desktop->icon() );
3270
3271     QBoxLayout* mainLayout = new QVBoxLayout( this, 5 );
3272
3273     /* Create selection buttons */
3274     QVButtonGroup* buttonGrp = new QVButtonGroup ( this );
3275     buttonGrp->setExclusive ( true );
3276     QBoxLayout* vLayout = new QVBoxLayout( mainLayout, 5 );
3277     vLayout->addWidget ( buttonGrp );
3278
3279     /* Create selection button for available app */
3280     unsigned id = 0;
3281     for ( QAD_Application* app = myApps.first(); app; app = myApps.next(), id++ )
3282     {
3283         /* add radio button for application */
3284         buttonGrp->insert( new QRadioButton( app->getStudyDescription() +
3285                            " (*." + app->getStudyExtension() + ")", buttonGrp ), id );
3286     }
3287
3288     /* make the first application selected */
3289     buttonGrp->setButton( 0 );
3290
3291     /* listen to the selection */
3292     QAD_ASSERT ( connect ( buttonGrp, SIGNAL(clicked(int)), this, SLOT(onAppSelected(int)) ));
3293
3294     /* Create OK/Cancel buttons
3295     */
3296     QBoxLayout* hLayout = new QHBoxLayout( mainLayout, 5 );
3297     QPushButton* buttonOK = new QPushButton( tr("BUT_OK"), this );
3298     QPushButton* buttonCancel = new QPushButton( tr("BUT_CANCEL"), this );
3299     QPushButton* buttonHelp = new QPushButton( tr("BUT_HELP"), this );
3300     buttonOK->setDefault( true );
3301
3302     hLayout->addStretch();
3303     hLayout->addWidget( buttonOK );
3304     hLayout->addWidget( buttonCancel );
3305     hLayout->addWidget( buttonHelp );
3306
3307     /* connect buttons */
3308     QAD_ASSERT ( connect( buttonOK, SIGNAL(clicked()), this, SLOT(accept())) );
3309     QAD_ASSERT ( connect( buttonCancel, SIGNAL(clicked()), this, SLOT(reject())) );
3310     QAD_ASSERT ( connect( buttonHelp, SIGNAL(clicked()), this, SLOT(onHelp())) );
3311
3312     /* disable resizing */
3313     setFixedSize( 0, 0 );
3314     setSizePolicy( QSizePolicy ( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
3315 }
3316
3317 Desktop_AppSelectionDlg::~Desktop_AppSelectionDlg()
3318 {
3319 }
3320
3321 QAD_Application* Desktop_AppSelectionDlg::selectedApp() const
3322 {
3323     return myApps.at( myAppId );
3324 }
3325
3326 void Desktop_AppSelectionDlg::resizeEvent( QResizeEvent* e )
3327 {
3328     QAD_Tools::centerWidget( this, parentWidget() );
3329 }
3330
3331 /*
3332  *  Slots
3333 */
3334 void Desktop_AppSelectionDlg::onAppSelected( int id )
3335 {
3336     myAppId = id;
3337 }
3338
3339 void Desktop_AppSelectionDlg::onHelp()
3340 {
3341 }
3342