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