]> SALOME platform Git repositories - modules/kernel.git/blob - src/SALOMEGUI/QAD_Desktop.cxx
Salome HOME
PR: Generic C++ for PyQt GUI
[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 typedef bool OneDim2(QAD_Desktop*, char*);
2225
2226 /*!
2227   Called to define settings of component.
2228 */
2229 void QAD_Desktop::setSettings()
2230 {
2231   if (!myActiveComp.isEmpty())  {
2232     OSD_Function osdF = mySharedLibrary.DlSymb("SetSettings");
2233     if ( osdF != NULL )
2234       if (_islibso)
2235         {
2236           OneDim1 (*f1) = (bool (*) (QAD_Desktop*)) osdF;
2237           (*f1)(this);
2238         }
2239       else
2240         {
2241           QString Component =mapComponentName[myActiveComp];
2242           OneDim2 (*f1) = (bool (*) (QAD_Desktop*, char*)) osdF;
2243           (*f1)(this, (char*)Component.latin1());
2244         }
2245   }
2246 }
2247
2248 /*!
2249   Called to load Component : xml resources and GUI librairy.
2250 */
2251 bool QAD_Desktop::loadComponent(QString Component)
2252 {
2253   QAD_WaitCursor wc;
2254   QString resDir("/");  //NRI : Pb under Windows
2255
2256   QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
2257   if ( resMgr ) {
2258     QString msg;
2259     if (!resMgr->loadResources( Component, msg ))
2260       {
2261         //NRI   QCString errMsg;
2262         //      errMsg.sprintf( "Do not load all resources for module %sGUI.\n" ,
2263         //              Component.latin1() );
2264         wc.stop();
2265         QMessageBox::warning( this, tr("WRN_WARNING"), msg, tr ("BUT_OK") );
2266         return false;
2267       }
2268   }
2269     
2270   /* Parse xml file */
2271   myXmlHandler = new QAD_XmlHandler();
2272   myXmlHandler->setMainWindow(this);
2273   if (!myXmlHandler->setComponent(resMgr->resources( Component ))) return false;
2274
2275   QString language = resMgr->language( Component );
2276
2277   QString ComponentXml = Component + "_" + language + ".xml";
2278   //ComponentXml = resMgr->resources(Component + "GUI") ;
2279   //ComponentXml = QAD_Tools::addSlash(ComponentXml) ;
2280   ComponentXml = QAD_Tools::addSlash( resMgr->findFile( ComponentXml, Component ) ) + ComponentXml;
2281   QFile file( ComponentXml );
2282
2283   if ( !file.exists() || !file.open( IO_ReadOnly ) )  {
2284     QString errMsg;
2285     errMsg.sprintf( "Cannot open xml file: %s\n.",
2286                     (file.name()).latin1() );
2287     wc.stop();
2288     QMessageBox::critical( this, tr("ERR_ERROR"), errMsg, tr ("BUT_OK") );
2289     return false;
2290   }
2291   file.close();
2292
2293   QXmlInputSource source( file );
2294   QXmlSimpleReader reader;
2295   reader.setContentHandler( myXmlHandler );
2296   reader.setErrorHandler( myXmlHandler );
2297   bool ok = reader.parse( source );
2298   file.close();
2299   if ( !ok ) {
2300     wc.stop();
2301     QMessageBox::critical( this,
2302                            tr( "INF_PARSE_ERROR" ),
2303                            tr( myXmlHandler->errorProtocol() ) );
2304     return false;
2305   }
2306
2307   myMenusList=myXmlHandler->myMenusList;
2308   myActiveMenus=myMenusList.at(0);
2309   myOperatorMenus->showMenuBar(0);
2310   myActiveMenus->showAllToolBars();
2311
2312   /* Components toolbars */
2313   int nbToolbars = 0;
2314   if (myActiveMenus)
2315     nbToolbars = myActiveMenus->getToolBarList().count();
2316   /* Open Shared Library */
2317   mySharedLibrary = OSD_SharedLibrary();
2318   _islibso = false;
2319
2320   QString ComponentLib;
2321   QCString libs;
2322   QFileInfo fileInfo ;
2323   QString fileString ;
2324   QString dir;
2325
2326   if ( libs = getenv("LD_LIBRARY_PATH")) {
2327     //    MESSAGE ( " LD_LIBRARY_PATH : " << libs );
2328     QStringList dirList = QStringList::split( SEPARATOR, libs, false ); // skip empty entries
2329     for ( int i = dirList.count()-1; i >= 0; i-- ) {
2330       dir = dirList[ i ];
2331 #ifdef WNT
2332       fileString = QAD_Tools::addSlash( dir ) + "lib" + Component + "GUI.dll" ;
2333 #else
2334       fileString = QAD_Tools::addSlash( dir ) + "lib" + Component + "GUI.so" ;
2335 #endif
2336     
2337       fileInfo.setFile(fileString) ;
2338       if (fileInfo.exists()) {
2339         //      MESSAGE ( " GUI library = " << fileString );
2340         ComponentLib = fileInfo.fileName() ;
2341         _islibso = true;
2342         break;
2343       }
2344     }
2345   }
2346
2347   if (!_islibso) // component GUI could be in PyQt, use generic library
2348     {
2349       MESSAGE("GUI library not found, trying generic library for PyQt GUI");
2350       bool found = false;
2351       if (dir = getenv("KERNEL_ROOT_DIR"))
2352         {
2353           dir = QAD_Tools::addSlash(dir) ;
2354           dir = dir + "lib" ;
2355           dir = QAD_Tools::addSlash(dir) ;
2356           dir = dir + "salome" ;
2357           dir = QAD_Tools::addSlash(dir) ;
2358 #ifdef WNT
2359           dir = dir + "libSalomePyQtcmodule.dll" ;
2360 #else
2361           dir = dir + "libSalomePyQtcmodule.so" ;
2362 #endif
2363           MESSAGE ( " GUI library = " << dir );
2364           fileInfo.setFile(dir) ;
2365           if (fileInfo.exists())
2366             {
2367               ComponentLib = fileInfo.fileName() ;
2368               found = true;
2369             }
2370         }
2371       if ( !found )
2372         {
2373           QMessageBox::critical( this,
2374                                  tr("ERR_ERROR"),
2375                                  tr("ERR_LIBGUI" ).arg(Component) );
2376           return false;
2377         }
2378     }
2379
2380   mySharedLibrary.SetName(TCollection_AsciiString((char*)ComponentLib.latin1()).ToCString());
2381   ok = mySharedLibrary.DlOpen(OSD_RTLD_LAZY);
2382   if (!ok) {
2383     wc.stop();
2384     QMessageBox::critical( this,
2385                            tr("ERR_ERROR"),
2386                            tr( mySharedLibrary.DlError() ) );
2387     return false;
2388   }
2389
2390   /* SETTINGS */
2391   OSD_Function osdF = mySharedLibrary.DlSymb("SetSettings");
2392   if ( osdF != NULL )
2393     if (_islibso)
2394       {
2395         OneDim1 (*f1) = (bool (*) (QAD_Desktop*)) osdF;
2396         (*f1)(this);
2397       }
2398     else
2399       {
2400         OneDim2 (*f1) = (bool (*) (QAD_Desktop*, char*)) osdF;
2401         (*f1)(this, (char*)Component.latin1());
2402       }
2403
2404   
2405
2406   /* COMPONENT INTERFACE */
2407   SALOME_ModuleCatalog::Acomponent_ptr aComponent =
2408     myCatalogue->GetComponent(Component.latin1());
2409
2410   if (CORBA::is_nil (aComponent)) {
2411     MESSAGE( "Catalog Error : Component not found in the catalog" )
2412     return false;
2413   }
2414
2415   myActiveStudy->setMessage(QString("Component : ") +
2416                             aComponent->componentusername() + " created " );
2417   myActiveStudy->setMessage(QString("Type : ") +
2418                             QString::number(aComponent->component_type()));
2419   myActiveStudy->setMessage(QString("Constraint : ") +
2420                             aComponent->constraint() );
2421
2422   /* obtain interfaces list of the component */
2423   SALOME_ModuleCatalog::ListOfInterfaces_var _list =
2424     new SALOME_ModuleCatalog::ListOfInterfaces;
2425   _list = aComponent->GetInterfaceList();
2426
2427   if (_list->length() != 0 ) {
2428
2429     for (unsigned int ind = 0; ind < _list->length();ind++)
2430       myActiveStudy->setMessage( QString("Interface name : ") +
2431                                  _list[ind] );
2432
2433
2434     /* obtain services list of the component */
2435     SALOME_ModuleCatalog::ListOfServices_var list_services_component =
2436       new SALOME_ModuleCatalog::ListOfServices;
2437     list_services_component = aComponent->GetServiceList(_list[0]);
2438
2439     if (list_services_component->length() != 0 ) {
2440
2441       for (unsigned int ind = 0; ind < list_services_component->length();ind++)
2442         myActiveStudy->setMessage( QString("Service name : ") +
2443                                    list_services_component[ind] );
2444
2445       // Get a service of the component
2446       SALOME_ModuleCatalog::Service_var service = new SALOME_ModuleCatalog::Service;
2447       service  = aComponent->GetService(_list[0],list_services_component[0]) ;
2448       myActiveStudy->setMessage( QString("Service name: ") + service->ServiceName);
2449       for (unsigned int ind1 = 0; ind1 <service->ServiceinParameter.length();ind1++) {
2450         myActiveStudy->setMessage( QString("Type of the in Parameter of this service : ") +
2451                                    (const char *) service->ServiceinParameter[ind1].Parametertype);
2452         myActiveStudy->setMessage( QString("Name of the in Parameter of this service : ") +
2453                                    (const char *) service->ServiceinParameter[ind1].Parametername);
2454       }
2455       for (unsigned int ind1 = 0; ind1 <service->ServiceoutParameter.length();ind1++) {
2456         myActiveStudy->setMessage( QString("Type of the out Parameter of this service : ") +
2457                                    (const char *) service->ServiceoutParameter[ind1].Parametertype);
2458         myActiveStudy->setMessage( QString("Name of the out Parameter of this service : ") +
2459                                    (const char *) service->ServiceoutParameter[ind1].Parametername);
2460       }
2461     }
2462   }
2463   return true;
2464 }
2465
2466 typedef bool OneDim(int, QAD_Desktop*);
2467 typedef void (*PTR_FACTORY_FUNCTION)( CORBA::ORB_var &orb, QWidget *parent, const char *name ) ;
2468
2469 /*!
2470  */
2471 void QAD_Desktop::onDispatch()
2472 {
2473   const QObject* obj = sender();
2474
2475   QList<QAD_ListMenuIdAction> MenuList = myActiveMenus->getMenuList();
2476   QAD_ListMenuIdAction* aMenu;
2477   int id = -1;
2478   for(aMenu=MenuList.first();aMenu!=NULL;aMenu=MenuList.next()) {
2479     if (aMenu->getAction()==obj) {
2480       id = aMenu->getId();
2481       break;
2482     }
2483   }
2484   onDispatch(id);
2485 }
2486
2487 /*!
2488  */
2489 void QAD_Desktop::onDispatchTools(int id)
2490 {
2491   /* Open Shared Library */
2492   OSD_SharedLibrary ToolsLibrary = OSD_SharedLibrary();
2493
2494   QString ToolsLib;
2495   QCString dir;
2496   QFileInfo fileInfo ;
2497   bool found = false;
2498
2499   char arg[256] ;
2500   bool libToolsGUI = true;
2501   if( QAD_XmlHandler::_bibmap[ id ].isEmpty() ) 
2502   { 
2503
2504     if ( dir = getenv("SALOME_SITE_DIR"))  {
2505       dir = QAD_Tools::addSlash(dir) ;
2506       dir = dir + "lib" ;
2507       dir = QAD_Tools::addSlash(dir) ;
2508       dir = dir + "salome" ;
2509       dir = QAD_Tools::addSlash(dir) ;
2510 #ifdef WNT
2511       dir = dir + "libToolsGUI.dll" ;
2512 #else
2513       dir = dir + "libToolsGUI.so" ;
2514 #endif
2515       MESSAGE ( " GUI library = " << dir );
2516       fileInfo.setFile(dir) ;
2517       if (fileInfo.exists()) {
2518         ToolsLib = fileInfo.fileName() ;
2519         found = true;
2520       }
2521     }
2522     
2523     if ( (dir = getenv("SALOME_ROOT_DIR")) && !found ) {
2524       dir = QAD_Tools::addSlash(dir) ;
2525       dir = dir + "lib" ;
2526       dir = QAD_Tools::addSlash(dir) ;
2527       dir = dir + "salome" ;
2528       dir = QAD_Tools::addSlash(dir) ;
2529 #ifdef WNT
2530       dir = dir + "libToolsGUI.dll" ;
2531 #else
2532       dir = dir + "libToolsGUI.so" ;
2533 #endif
2534       MESSAGE ( " GUI library = " << dir );
2535       fileInfo.setFile(dir) ;
2536       if (fileInfo.exists()) {
2537         ToolsLib = fileInfo.fileName() ;
2538         found = true;
2539       }
2540     }
2541     
2542     if ( (dir = getenv("KERNEL_ROOT_DIR")) && !found ) {
2543       dir = QAD_Tools::addSlash(dir) ;
2544       dir = dir + "lib" ;
2545       dir = QAD_Tools::addSlash(dir) ;
2546       dir = dir + "salome" ;
2547       dir = QAD_Tools::addSlash(dir) ;
2548 #ifdef WNT
2549       dir = dir + "libToolsGUI.dll" ;
2550 #else
2551       dir = dir + "libToolsGUI.so" ;
2552 #endif
2553       MESSAGE ( " GUI library = " << dir );
2554       fileInfo.setFile(dir) ;
2555       if (fileInfo.exists()) {
2556         ToolsLib = fileInfo.fileName() ;
2557         found = true;
2558       }
2559     }
2560   }
2561   else {
2562     libToolsGUI = false;
2563     SCRUTE( QAD_XmlHandler::_bibmap[ id ] ) ;
2564     if ( dir = getenv("SALOME_SITE_DIR"))  {
2565       dir = QAD_Tools::addSlash(dir) ;
2566       dir = dir + "lib" ;
2567       dir = QAD_Tools::addSlash(dir) ;
2568       dir = dir + "salome" ;
2569       dir = QAD_Tools::addSlash(dir) ;
2570       dir = dir + QAD_XmlHandler::_bibmap[ id ].latin1() ;
2571       MESSAGE ( " GUI library = " << dir );
2572       fileInfo.setFile(dir) ;
2573       if (fileInfo.exists()) {
2574         ToolsLib = fileInfo.fileName() ;
2575         found = true;
2576       }
2577     }
2578     
2579     if ( (dir = getenv("SALOME_ROOT_DIR")) && !found ) {
2580       dir = QAD_Tools::addSlash(dir) ;
2581       dir = dir + "lib" ;
2582       dir = QAD_Tools::addSlash(dir) ;
2583       dir = dir + "salome" ;
2584       dir = QAD_Tools::addSlash(dir) ;
2585       dir = dir + QAD_XmlHandler::_bibmap[ id ].latin1() ;
2586       MESSAGE ( " GUI library = " << dir );
2587       fileInfo.setFile(dir) ;
2588       if (fileInfo.exists()) {
2589         ToolsLib = fileInfo.fileName() ;
2590         found = true;
2591       }
2592     }
2593     
2594     if ( (dir = getenv("KERNEL_ROOT_DIR")) && !found ) {
2595       dir = QAD_Tools::addSlash(dir) ;
2596       dir = dir + "lib" ;
2597       dir = QAD_Tools::addSlash(dir) ;
2598       dir = dir + "salome" ;
2599       dir = QAD_Tools::addSlash(dir) ;
2600       dir = dir + QAD_XmlHandler::_bibmap[ id ].latin1() ;
2601       MESSAGE ( " GUI library = " << dir );
2602       fileInfo.setFile(dir) ;
2603       if (fileInfo.exists()) {
2604         ToolsLib = fileInfo.fileName() ;
2605         found = true;
2606       }
2607     }
2608   }
2609
2610   ToolsLibrary.SetName(TCollection_AsciiString((char*)ToolsLib.latin1()).ToCString());
2611   bool ok = ToolsLibrary.DlOpen(OSD_RTLD_LAZY);
2612   if (ok) {
2613     if ( libToolsGUI ) {
2614       OSD_Function osdF = ToolsLibrary.DlSymb("OnGUIEvent");
2615       OneDim (*f1) = NULL;
2616       f1 = (bool (*) (int, QAD_Desktop*)) osdF;
2617       (*f1)(id,this);
2618     } else {
2619       ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
2620       ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
2621       CORBA::ORB_var &orb = init(0 , 0 ) ;
2622       OSD_Function osdF = ToolsLibrary.DlSymb("OnGUIEvent");
2623       PTR_FACTORY_FUNCTION f1 = NULL;
2624       f1 = (PTR_FACTORY_FUNCTION) osdF;
2625       f1(orb,0,"Registry");
2626     }
2627   } else {
2628     QMessageBox::critical( this,
2629                            tr("ERR_ERROR"),
2630                            tr( ToolsLibrary.DlError() ) );
2631   }
2632 }
2633
2634 /*!
2635  */
2636 void QAD_Desktop::onDispatch(int id)
2637 {
2638   if (!myActiveComp.isEmpty())  {
2639     OSD_Function osdF = mySharedLibrary.DlSymb("OnGUIEvent");
2640     OneDim (*f1) = NULL;
2641     if ( osdF != NULL ) {
2642       f1 = (bool (*) (int, QAD_Desktop*)) osdF;
2643       (*f1)(id,this);
2644     }
2645   }
2646 }
2647
2648 /*!
2649   Returns the component's catalogue
2650 */
2651 SALOME_ModuleCatalog::ModuleCatalog_var QAD_Desktop::getCatalogue()
2652 {
2653   return myCatalogue;
2654 }
2655
2656 /*!
2657  */
2658 void QAD_Desktop::onComboActiveComponent( const QString & component ){
2659   onComboActiveComponent(component,true);
2660 }
2661 void QAD_Desktop::onComboActiveComponent( const QString & component, bool isLoadData)
2662 {
2663   if (myActiveStudy != 0) {
2664     if (myActiveComp.compare(component)!=0) {
2665       if (!myXmlHandler->myIdList.IsEmpty()) clearMenus();
2666       if ( myCombo->currentText() != component )
2667         myCombo->setCurrentText( component );
2668       //NRI if (component.compare(QString("Salome"))!= 0) {
2669       if (component.compare( getComponentUserName( "KERNEL" ) )!= 0) {
2670 //      QApplication::setOverrideCursor( Qt::waitCursor );
2671         myActiveComp = component;
2672
2673         SALOME_Selection* oldSel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2674
2675         for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2676           if ( aButton->textLabel().compare(component)==0)
2677             aButton->setOn(true);
2678           else
2679             aButton->setOn(false);
2680         }
2681
2682         myActiveStudy->Selection( component );
2683         if ( !loadComponent(mapComponentName[component]) ) {
2684           myCombo->setCurrentItem (0);
2685           for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2686             aButton->setOn(false);
2687           }
2688           myActiveComp = "";
2689         }
2690
2691         SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2692         SALOME_ListIteratorOfListIO It( oldSel->StoredIObjects() );
2693         for(;It.More();It.Next()) {
2694           int res = Sel->AddIObject( It.Value() );
2695
2696           if ( res == -1 )
2697             myActiveStudy->highlight( It.Value(), false );
2698           if ( res == 0 )
2699             myActiveStudy->highlight( It.Value(), true );
2700           
2701         }
2702
2703         // Open new component's data in active study if any
2704         if(isLoadData) loadComponentData(mapComponentName[component]);
2705
2706         oldSel->Clear();
2707         myActiveStudy->updateObjBrowser(true);
2708
2709 //      QApplication::restoreOverrideCursor();
2710
2711       } else {  // component == "Salome"
2712         myActiveComp = "";
2713         //NRI   myActiveStudy->Selection( "Salome" );
2714         myActiveStudy->Selection( getComponentUserName( "KERNEL" ) );
2715         SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2716         Sel->ClearIObjects();
2717         for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2718           aButton->setOn(false);
2719         }
2720       }
2721     } else {
2722       for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2723         if ( aButton->textLabel().compare(component)==0)
2724           aButton->setOn(true);
2725       }
2726     }
2727   } else {
2728     QMessageBox::critical( 0,
2729                            tr( "ERR_ERROR" ),
2730                            tr( "WRN_LOAD_COMPONENT" ) );
2731     myCombo->setCurrentItem (0);        
2732     for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2733       aButton->setOn(false);
2734     }
2735   }
2736 }
2737
2738 /*!
2739  */
2740 void QAD_Desktop::activateComponent(const QString& theName, bool isLoadData){
2741   int nbItem = myCombo->count();
2742   int Index = 0;
2743
2744   for (int i = 0; i < nbItem; i++) {
2745     if (myCombo->text(i).compare(theName)==0) {
2746       Index = i;
2747       break;
2748     }
2749   }
2750   myCombo->setCurrentItem (Index);
2751   onComboActiveComponent(theName,isLoadData);
2752 };
2753
2754 void QAD_Desktop::onButtonActiveComponent( )
2755 {
2756   QToolButton* obj = (QToolButton*)sender();
2757   activateComponent(obj->textLabel());
2758 }
2759
2760 /*!
2761   Clears All Resources of current component
2762  */
2763 void QAD_Desktop::clearMenus()
2764 {
2765   onActiveStudyChanged();
2766
2767   /* menus */
2768   myMenusList.clear();
2769   if (myXmlHandler) {
2770     int length = myXmlHandler->myIdList.Length();
2771     for (int k=length; k>0; k--) {
2772       QMenuData* parent;
2773       if ( menuBar()->findItem(myXmlHandler->myIdList.Value(k), &parent) )
2774         parent->removeItem( myXmlHandler->myIdList.Value(k) );
2775     }
2776   }
2777
2778   /* toolbars */
2779   if (myActiveMenus) {
2780     int nbtoolbars = myActiveMenus->getToolBarList().count();
2781     for (int k=0; k<nbtoolbars; k++) {
2782       myActiveMenus->getToolBarList().at(k)->hide();
2783       myActiveMenus->getToolBarList().at(k)->clear();
2784     }
2785     myActiveMenus->clearToolBar();
2786
2787     /* popups */
2788     QList<QAD_ListPopupMenu> PopupList = myActiveMenus->getPopupMenuList();
2789     QAD_ListPopupMenu* aPopup;
2790     for(aPopup=PopupList.first();aPopup!=NULL;aPopup=PopupList.next()){
2791       aPopup->getPopup()->clear();
2792       
2793     }
2794     myActiveMenus->clearPopupMenu();
2795
2796   }
2797   myActiveComp = "";
2798 }
2799
2800 typedef bool TwoDim1(QKeyEvent* pe, QAD_Desktop*, QAD_StudyFrame*);
2801 /*!
2802   Exports Key Events in active component ( GUI Librairy )
2803  */
2804 void QAD_Desktop::onKeyPress( QKeyEvent* pe )
2805 {
2806   //  MESSAGE ( "QAD_Desktop::onKeyPress" )
2807   if (!myActiveComp.isEmpty())  {
2808     OSD_Function osdF = mySharedLibrary.DlSymb("OnKeyPress");
2809     if ( osdF != NULL ) {
2810       TwoDim1 (*f1) = (bool (*) (QKeyEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
2811       (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
2812     }
2813   }
2814 }
2815
2816 typedef bool TwoDim(QMouseEvent* pe, QAD_Desktop*, QAD_StudyFrame*);
2817 /*!
2818   Exports Mouse Press Events in active component ( GUI Librairy )
2819  */
2820 bool QAD_Desktop::onMousePress( QMouseEvent* pe )
2821 {
2822   //  MESSAGE ( "QAD_Desktop::onMousePress" )
2823   if (!myActiveComp.isEmpty())  {
2824     OSD_Function osdF = mySharedLibrary.DlSymb("OnMousePress");
2825     if ( osdF != NULL ) {
2826       TwoDim (*f1) = (bool (*) (QMouseEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
2827       return (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
2828     }
2829   }
2830   return false;
2831 }
2832
2833 /*!
2834   Exports Mouse Move Events in active component ( GUI Librairy )
2835  */
2836 void QAD_Desktop::onMouseMove( QMouseEvent* pe )
2837 {
2838   if (!myActiveComp.isEmpty())  {
2839     OSD_Function osdF = mySharedLibrary.DlSymb("OnMouseMove");
2840     if ( osdF != NULL ) {
2841       TwoDim (*f1) = (bool (*) (QMouseEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
2842       (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
2843     }
2844   }
2845 }
2846
2847 /*!
2848     Returns name of active component
2849 */
2850 const QString& QAD_Desktop::getActiveComponent() const
2851 {
2852   return myActiveComp;
2853 }
2854
2855
2856 typedef bool defineP( QString & theContext, QString & theParent, QString & theObject);
2857
2858 void QAD_Desktop::definePopup(QString & theContext,
2859                               QString & theParent, 
2860                               QString & theObject ) 
2861 {
2862   if (!myActiveComp.isEmpty())  {
2863     OSD_Function osdF = mySharedLibrary.DlSymb("definePopup");
2864     if ( osdF != NULL ) {
2865       defineP (*f1) = (bool (*) (QString &, QString &, QString &)) osdF;
2866       (*f1)(theContext, theParent, theObject);
2867     }
2868   }
2869 }
2870
2871 /*!
2872     Create popup
2873 */
2874 void QAD_Desktop::createPopup(QPopupMenu* popupFather, QPopupMenu* popup,
2875                               QString text, int popupID, bool separator)
2876 {
2877   QMenuItem* item = popup->findItem(popupID);
2878   if (item) {
2879     QPopupMenu* popupChild = item->popup();
2880     if ( popupChild ) {
2881       QPopupMenu* newPopup = new QPopupMenu;
2882       int count = popupChild->count();
2883       // add items at the top of <popupFather>
2884       for (int i = count - 1; i >= 0; i--) {
2885         int j = popupChild->idAt(i);
2886         QString text = popupChild->text(j);
2887         createPopup( newPopup, popupChild, text, j);
2888       }
2889       popupFather->insertItem(popup->text(popupID),
2890                               newPopup, popupID, 0);
2891     } else {
2892       if ( !text.isNull() ) {
2893         popupFather->insertItem(popup->text(popupID),
2894                                 this,
2895                                 SLOT( onDispatch(int) ), 0, popupID, 0);// try adding item at the top
2896       } /*else if ( separator ) 
2897         popupFather->insertTearOffHandle(-1, 0);*/
2898       else
2899         popupFather->insertSeparator(0);
2900     }
2901   }
2902 }
2903
2904 /*!
2905     Create popup
2906 */
2907 void QAD_Desktop::createPopup(QPopupMenu* popup, const QString & theContext,
2908                               const QString & theParent, const QString & theObject )
2909 {
2910   if ( !myActiveComp.isEmpty() && 
2911        getOperatorMenus()->createPopupMenu(theContext,theParent,theObject) != NULL ) {
2912     QPopupMenu* aPopup = getOperatorMenus()->createPopupMenu(theContext,theParent,theObject)->getPopup();
2913     int count = aPopup->count();
2914
2915     //for (int i = 0; i < count; i++) {
2916     for (int i = count - 1; i >= 0; i--) {
2917       int id = aPopup->idAt(i);
2918       QString text = aPopup->text(id);
2919       //QString mes("Inserting popup menu item loaded from XML: ");
2920       //mes += text;
2921       //MESSAGE ( mes.latin1() )
2922       if (i==0)
2923         popup->insertItem(aPopup->text(id),
2924                           this,
2925                           SLOT( onDispatch(int) ), 0, id, 0);// try adding item at the top
2926       else
2927         createPopup( popup, aPopup, text, id);
2928     }
2929   } //else {
2930     //QString mes("Popup does not exist for given (Context = ");
2931     //mes += theContext;
2932     //mes += ", Parent = ";
2933     //mes += theParent;
2934     //mes += ", Object = ";
2935     //mes += theObject;
2936     //MESSAGE (mes.latin1())
2937       //popup->clear();
2938   //}
2939
2940   // IAPP Popup 
2941   // Should be moved to SALOMEGUI_Application::onCreatePopup()...
2942   if ( myActiveComp.isEmpty() ) {
2943     popup->removeItem(QAD_Display_Popup_ID);
2944     popup->removeItem(QAD_DisplayOnly_Popup_ID);
2945     popup->removeItem(QAD_Erase_Popup_ID);
2946     int id = popup->idAt(popup->count()-1); // last item
2947     if (id < 0 && id != -1) popup->removeItem(id); // separator
2948
2949     if ( popup && theParent.compare("ObjectBrowser")==0 ) {
2950       if ( popup->count()>0 ) {
2951         popup->insertItem (tr ("MEN_OPENWITH"), this, SLOT(onOpenWith()), 0, -1, 2);
2952         popup->insertSeparator (3);
2953       }
2954       else {
2955         popup->insertItem (tr ("MEN_OPENWITH"), this, SLOT(onOpenWith()) );
2956       }
2957     } 
2958   }
2959  
2960 }
2961
2962 typedef bool activeStudyChanged(QAD_Desktop*);
2963
2964 void QAD_Desktop::onActiveStudyChanged()
2965 {
2966   if (!myActiveComp.isEmpty())  {
2967     OSD_Function osdF = mySharedLibrary.DlSymb("activeStudyChanged");
2968     if ( osdF != NULL ) {
2969       activeStudyChanged (*f1) = (bool (*) (QAD_Desktop*)) osdF;
2970       (*f1)(this);
2971     }  
2972   }
2973 }
2974
2975 typedef bool customP(QAD_Desktop*, QPopupMenu*, const QString & theContext,
2976                      const QString & theParent, const QString & theObject);
2977 /*!
2978   Custom popup ( GUI Library )
2979 */
2980 void QAD_Desktop::customPopup(QPopupMenu* popup, const QString & theContext,
2981                               const QString & theParent, const QString & theObject)
2982 {
2983   if (!myActiveComp.isEmpty())  {
2984     OSD_Function osdF = mySharedLibrary.DlSymb("customPopup");
2985     if ( osdF != NULL ) {
2986       customP (*f1) = (bool (*) (QAD_Desktop*, QPopupMenu*, const QString &,
2987                                  const QString &, const QString &)) osdF;
2988       (*f1)(this, popup, theContext, theParent, theObject);
2989     }
2990   }
2991 }
2992
2993 void QAD_Desktop::onObjectBrowser()
2994 {
2995   bool checkDiff = false;
2996
2997   bool state  = QAD_CONFIG->getSetting("ObjectBrowser:AddColumn").compare("true") == 0;
2998
2999   if ( myStdActions.at( PrefObjectBrowserEntryId )->isOn() != state )
3000     checkDiff = true;
3001
3002   bool showEntry;
3003   if ( myStdActions.at( PrefObjectBrowserEntryId )->isOn() ) {
3004     showEntry = true;
3005     QAD_CONFIG->addSetting( "ObjectBrowser:AddColumn", "true");
3006   } else {
3007     showEntry = false;
3008     QAD_CONFIG->addSetting( "ObjectBrowser:AddColumn", "false");
3009   }  
3010
3011   bool showValue;
3012   if ( myStdActions.at( PrefObjectBrowserValueId )->isOn() ) {
3013     showValue = true;
3014     QAD_CONFIG->addSetting( "ObjectBrowser:ValueColumn", "true");
3015   } else {
3016     showValue = false;
3017     QAD_CONFIG->addSetting( "ObjectBrowser:ValueColumn", "false");
3018   }  
3019
3020   bool showIAPP;
3021   if ( myStdActions.at( PrefObjectBrowserIAPPId )->isOn() ) {
3022     showIAPP = true;
3023     QAD_CONFIG->addSetting( "ObjectBrowser:IAPP", "true");
3024   } else {
3025     showIAPP = false;
3026     QAD_CONFIG->addSetting( "ObjectBrowser:IAPP", "false");
3027   }  
3028   
3029   /* To sort created object in chrono order or reverse chrono order */
3030   bool showCHRONO_SORT ;
3031   if ( myStdActions.at( PrefObjectBrowserCHRONO_SORTId )->isOn() ) {
3032     showCHRONO_SORT = true;
3033     QAD_CONFIG->addSetting( "ObjectBrowser:CHRONO_SORT", "true");
3034   } else {
3035     showCHRONO_SORT = false;
3036     QAD_CONFIG->addSetting( "ObjectBrowser:CHRONO_SORT", "false");
3037   }
3038
3039   if ( myActiveApp ) {
3040     QList<QAD_Study>& studies = myActiveApp->getStudies();
3041     for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
3042       int nbSf = study->getStudyFramesCount();
3043       for ( int i = 0; i < nbSf; i++ ) {
3044         QAD_StudyFrame* sf = study->getStudyFrame(i);
3045         sf->getLeftFrame()->getObjectBrowser()->setShowInfoColumns( showEntry );
3046         sf->getLeftFrame()->getObjectBrowser()->setShowValueColumn( showValue );
3047         sf->getLeftFrame()->getObjectBrowser()->setEnableChronoSort( showCHRONO_SORT );
3048 //      sf->getLeftFrame()->getObjectBrowser()->setShowIAPP( showIAPP ); // this is done by below updateObjBrowser() call
3049       }
3050       study->updateObjBrowser(true);
3051     }
3052   }
3053 }
3054
3055 void QAD_Desktop::onViewerTrihedron()
3056 {
3057   QString Size = QAD_CONFIG->getSetting("Viewer:TrihedronSize");
3058   float dim;
3059
3060   SALOMEGUI_TrihedronSizeDlg *Dlg = new SALOMEGUI_TrihedronSizeDlg(this);
3061   if (!Size.isEmpty())
3062     Dlg->setTrihedronSize(Size.toInt());
3063   int r = Dlg->exec();
3064   dim = Dlg->getTrihedronSize();
3065   delete Dlg;
3066   
3067   if (r == QDialog::Accepted) {
3068     QAD_CONFIG->addSetting("Viewer:TrihedronSize", dim);
3069
3070     if( myActiveApp ) {
3071       QList<QAD_Study>& studies = myActiveApp->getStudies();
3072       for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
3073         int nbSf = study->getStudyFramesCount();
3074         for ( int i = 0; i < nbSf; i++ ) {
3075           study->getStudyFrame(i)->getRightFrame()->getViewFrame()->SetTrihedronSize(dim);
3076         }
3077       }
3078     }
3079   }
3080 }
3081
3082 void QAD_Desktop::onDirList() 
3083 {
3084   // getting dir list from settings
3085   QStringList dirList = QStringList::split(';', QAD_CONFIG->getSetting("FileDlg:QuickDirList"), false);
3086   QAD_DirListDlg* dlg = new QAD_DirListDlg(this);
3087   dlg->setPathList(dirList);
3088   if ( dlg->exec() == QDialog::Accepted) {
3089     dlg->getPathList(dirList);
3090     QAD_CONFIG->addSetting("FileDlg:QuickDirList", dirList.join(";"));
3091   }
3092   delete dlg;
3093 }
3094
3095 void QAD_Desktop::onConsoleFontAction()
3096 {
3097   // getting font from settings
3098   QString fntSet = QAD_CONFIG->getSetting("Viewer:ConsoleFont");
3099   QFont font = QAD_Tools::stringToFont( fntSet );
3100   bool bOk;
3101   font = QFontDialog::getFont( &bOk, font, this );
3102   if ( bOk ) {
3103     fntSet = QAD_Tools::fontToString( font );
3104     QAD_CONFIG->addSetting("Viewer:ConsoleFont", fntSet );
3105
3106     if( myActiveApp ) {
3107       QList<QAD_Study>& studies = myActiveApp->getStudies();
3108       for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
3109         int nbSf = study->getStudyFramesCount();
3110         for ( int i = 0; i < nbSf; i++ ) {
3111           study->getStudyFrame(i)->getRightFrame()->getPyEditor()->setFont( font );
3112           study->getStudyFrame(i)->getRightFrame()->getMessage()->setFont( font );
3113         }
3114       }
3115     }
3116   }
3117 }
3118
3119 void QAD_Desktop::onSavePref()
3120 {
3121   QAD_CONFIG->createConfigFile(true);
3122 }
3123
3124 //VRV: T2.5 - add default viewer
3125 void QAD_Desktop::onDefaultViewer(QAction * theAction)
3126 {
3127   int type = VIEW_TYPE_MAX;
3128   
3129   QString myValue;
3130   if (myStdActions.at(DefaultViewerOCCId) == theAction)
3131     type = VIEW_OCC;
3132   else if (myStdActions.at(DefaultViewerVTKId) == theAction)
3133     type = VIEW_VTK;
3134   else if (myStdActions.at(DefaultGraphSupervisorId) == theAction)
3135     type = VIEW_GRAPHSUPERV;
3136   else if (myStdActions.at(DefaultPlot2dId) == theAction)
3137     type = VIEW_PLOT2D;
3138   if ( type != VIEW_TYPE_MAX )
3139     QAD_CONFIG->addSetting( "Viewer:DefaultViewer", QString::number( type ) );
3140 }
3141 //VRV: T2.5 - add default viewer
3142
3143 void QAD_Desktop::onViewerOCC()
3144 {
3145   QString BackgroundColorRed   = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorRed");
3146   QString BackgroundColorGreen = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorGreen");
3147   QString BackgroundColorBlue  = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorBlue");
3148   QColor color;
3149
3150   if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3151     color = QColor(BackgroundColorRed.toInt(),
3152                    BackgroundColorGreen.toInt(),
3153                    BackgroundColorBlue.toInt());
3154   else
3155     color = QColor(35, 136, 145);
3156
3157   QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3158
3159   if (c.isValid()) {
3160     if ( myActiveApp ) {
3161       QList<QAD_Study>& studies = myActiveApp->getStudies();
3162       for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
3163         int nbSf = study->getStudyFramesCount();
3164         for ( int i = 0; i < nbSf; i++ ) {
3165           QAD_StudyFrame* sf = study->getStudyFrame(i);
3166           if ( sf->getTypeView() == VIEW_OCC ) {
3167             sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3168           }
3169         }
3170       }
3171     }
3172     QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorRed",   c.red() );
3173     QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorGreen", c.green() );
3174     QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorBlue",  c.blue() );
3175   }
3176 }
3177
3178 void QAD_Desktop::onGraphSupervisor()
3179 {
3180   QString BackgroundColorRed   = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorRed");
3181   QString BackgroundColorGreen = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorGreen");
3182   QString BackgroundColorBlue  = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorBlue");
3183   QColor color;
3184
3185   if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3186     color = QColor(BackgroundColorRed.toInt(),
3187                    BackgroundColorGreen.toInt(),
3188                    BackgroundColorBlue.toInt());
3189   else
3190     color = QColor(35, 136, 145);
3191
3192   QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3193
3194   if (c.isValid()) {
3195     if ( myActiveApp ) {
3196       QList<QAD_Study>& studies = myActiveApp->getStudies();
3197       for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
3198         int nbSf = study->getStudyFramesCount();
3199         for ( int i = 0; i < nbSf; i++ ) {
3200           QAD_StudyFrame* sf = study->getStudyFrame(i);
3201           if ( sf->getTypeView() == VIEW_GRAPHSUPERV ) {
3202             sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3203           }
3204         }
3205       }
3206     }
3207     
3208     QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorRed",   c.red() );
3209     QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorGreen", c.green() );
3210     QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorBlue",  c.blue() );
3211   }
3212 }
3213
3214 void QAD_Desktop::onViewerVTK()
3215 {
3216   QString BackgroundColorRed   = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorRed");
3217   QString BackgroundColorGreen = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorGreen");
3218   QString BackgroundColorBlue  = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorBlue");
3219   QColor color;
3220
3221   if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3222     color = QColor(BackgroundColorRed.toInt(),
3223                    BackgroundColorGreen.toInt(),
3224                    BackgroundColorBlue.toInt());
3225   else
3226     color = QColor(0, 0, 0);
3227
3228   QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3229
3230   if (c.isValid()) {
3231     if ( myActiveApp ) {
3232       QList<QAD_Study>& studies = myActiveApp->getStudies();
3233       for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
3234         int nbSf = study->getStudyFramesCount();
3235         for ( int i = 0; i < nbSf; i++ ) {
3236           QAD_StudyFrame* sf = study->getStudyFrame(i);
3237           if ( sf->getTypeView() == VIEW_VTK ) {
3238             sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3239           }
3240         }
3241       }
3242     }
3243     
3244     QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorRed",   c.red() );
3245     QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorGreen", c.green() );
3246     QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorBlue",  c.blue() );
3247   }
3248 }
3249
3250 void QAD_Desktop::onPlot2d()
3251 {
3252   QColor color;
3253   if ( QAD_CONFIG->hasSetting( "Plot2d:Background" ) ) {
3254     QString bgString = QAD_CONFIG->getSetting( "Plot2d:Background" );                               
3255     QStringList bgData = QStringList::split( ":", bgString, true );
3256     int bgRed = 0, bgGreen = 0, bgBlue = 0;
3257     if ( bgData.count() > 0 ) bgRed   = bgData[ 0 ].toInt();
3258     if ( bgData.count() > 1 ) bgGreen = bgData[ 1 ].toInt();
3259     if ( bgData.count() > 2 ) bgBlue  = bgData[ 2 ].toInt();
3260     color = QColor( bgRed, bgGreen, bgBlue );
3261   }
3262   else {
3263     color = QColor(0, 0, 0);  
3264   }
3265
3266   color = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3267
3268   if ( color.isValid() ) {
3269     if ( myActiveApp ) {
3270       QList<QAD_Study>& studies = myActiveApp->getStudies();
3271       for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
3272         int nbSf = study->getStudyFramesCount();
3273         for ( int i = 0; i < nbSf; i++ ) {
3274           QAD_StudyFrame* sf = study->getStudyFrame(i);
3275           if ( sf->getTypeView() == VIEW_PLOT2D ) {
3276             sf->getRightFrame()->getViewFrame()->setBackgroundColor( color );
3277           }
3278         }
3279       }
3280     }
3281     QStringList bgData; 
3282     bgData.append( QString::number( color.red() ) );
3283     bgData.append( QString::number( color.green() ) );
3284     bgData.append( QString::number( color.blue() ) );
3285     QAD_CONFIG->addSetting( "Plot2d:Background", bgData.join( ":" ) );
3286   }
3287 }
3288
3289 /* Help About */
3290 void QAD_Desktop::helpAbout()
3291 {
3292   SALOMEGUI_AboutDlg* About = new SALOMEGUI_AboutDlg( QAD_Application::getDesktop(), tr("MEN_ABOUT"));
3293   About->exec();
3294   delete About;
3295 }
3296
3297 /* Help Search */
3298 void QAD_Desktop::helpSearch()
3299 {
3300 }
3301
3302 /* Help Contents */
3303 void QAD_Desktop::helpContents()
3304 {
3305   if (myActiveComp == "")
3306     myActiveComp = getComponentUserName( "KERNEL" ); //NRI "Salome";
3307
3308   QCString dir;
3309   QString root;
3310   if (dir = getenv( getComponentName( myActiveComp ) + "_ROOT_DIR")) {
3311     root = QAD_Tools::addSlash( QAD_Tools::addSlash(dir) + QAD_Tools::addSlash("share")  + QAD_Tools::addSlash("salome")  + "doc" );
3312     if ( QFileInfo( root + "index.html" ).exists() ) {
3313       helpContext( root + "index.html", "" );
3314     }
3315     else {
3316       root = QAD_Tools::addSlash( root + "html" );
3317       if ( QFileInfo( root + "index.html" ).exists() ) {
3318         helpContext( root + "index.html", "" );
3319       }
3320       else {
3321         root = QAD_Tools::addSlash( root + "html" );
3322         if ( QFileInfo( root + "index.html" ).exists() ) {
3323           helpContext( root + "index.html", "" );
3324         }
3325       }
3326     }
3327   }
3328   
3329   //NRI getHelpWindow()->contents();
3330   getHelpWindow()->show();
3331   getHelpWindow()->raise();
3332   getHelpWindow()->setActiveWindow();
3333 }
3334
3335 /* Help Context */
3336 void QAD_Desktop::helpContext(const QString& source, const QString& context)
3337 {
3338   getHelpWindow()->context(source, context);
3339   getHelpWindow()->show();
3340   getHelpWindow()->raise();
3341   getHelpWindow()->setActiveWindow();
3342 }
3343
3344 /* Preferences/MultiFile Save */
3345 void QAD_Desktop::onMultiFileSave()
3346 {
3347   if ( myStdActions.at( PrefMultiFileSave )->isOn() )
3348     QAD_CONFIG->addSetting( "Desktop:MultiFileSave", "true");
3349   else
3350     QAD_CONFIG->addSetting( "Desktop:MultiFileSave", "false");
3351 }
3352
3353 /*********************************************************************
3354 ** Class: AppSelectionDlg
3355 ** Descr: Dialog for the selection of the application when several
3356 **        applications exist in the desktop and new study creation
3357 **        is activated by user.
3358 ** Level: Internal
3359 **********************************************************************/
3360 /*!
3361   \class Desktop_AppSelectionDlg QAD_Desktop.h
3362   \brief Dialog for the selection of the application when several
3363   applications exist in the desktop and new study creation
3364   is activated by user.
3365
3366   Level: Internal.
3367 */
3368
3369 Desktop_AppSelectionDlg::Desktop_AppSelectionDlg( QAD_Desktop* desktop,
3370                                                   QList<QAD_Application>& apps ) :
3371 QDialog( desktop, 0, true ),
3372 myAppId( 0 ),
3373 myApps( apps )
3374 {
3375     QAD_ASSERT_DEBUG_ONLY ( desktop );
3376     setCaption( tr("INF_DESK_DOC_CREATE") );
3377     if ( desktop->icon() )
3378     setIcon( *desktop->icon() );
3379
3380     QBoxLayout* mainLayout = new QVBoxLayout( this, 5 );
3381
3382     /* Create selection buttons */
3383     QVButtonGroup* buttonGrp = new QVButtonGroup ( this );
3384     buttonGrp->setExclusive ( true );
3385     QBoxLayout* vLayout = new QVBoxLayout( mainLayout, 5 );
3386     vLayout->addWidget ( buttonGrp );
3387
3388     /* Create selection button for available app */
3389     unsigned id = 0;
3390     for ( QAD_Application* app = myApps.first(); app; app = myApps.next(), id++ )
3391     {
3392         /* add radio button for application */
3393         buttonGrp->insert( new QRadioButton( app->getStudyDescription() +
3394                            " (*." + app->getStudyExtension() + ")", buttonGrp ), id );
3395     }
3396
3397     /* make the first application selected */
3398     buttonGrp->setButton( 0 );
3399
3400     /* listen to the selection */
3401     QAD_ASSERT ( connect ( buttonGrp, SIGNAL(clicked(int)), this, SLOT(onAppSelected(int)) ));
3402
3403     /* Create OK/Cancel buttons
3404     */
3405     QBoxLayout* hLayout = new QHBoxLayout( mainLayout, 5 );
3406     QPushButton* buttonOK = new QPushButton( tr("BUT_OK"), this );
3407     QPushButton* buttonCancel = new QPushButton( tr("BUT_CANCEL"), this );
3408     QPushButton* buttonHelp = new QPushButton( tr("BUT_HELP"), this );
3409     buttonOK->setDefault( true );
3410
3411     hLayout->addStretch();
3412     hLayout->addWidget( buttonOK );
3413     hLayout->addWidget( buttonCancel );
3414     hLayout->addWidget( buttonHelp );
3415
3416     /* connect buttons */
3417     QAD_ASSERT ( connect( buttonOK, SIGNAL(clicked()), this, SLOT(accept())) );
3418     QAD_ASSERT ( connect( buttonCancel, SIGNAL(clicked()), this, SLOT(reject())) );
3419     QAD_ASSERT ( connect( buttonHelp, SIGNAL(clicked()), this, SLOT(onHelp())) );
3420
3421     /* disable resizing */
3422     setFixedSize( 0, 0 );
3423     setSizePolicy( QSizePolicy ( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
3424 }
3425
3426 Desktop_AppSelectionDlg::~Desktop_AppSelectionDlg()
3427 {
3428 }
3429
3430 QAD_Application* Desktop_AppSelectionDlg::selectedApp() const
3431 {
3432     return myApps.at( myAppId );
3433 }
3434
3435 void Desktop_AppSelectionDlg::resizeEvent( QResizeEvent* e )
3436 {
3437     QAD_Tools::centerWidget( this, parentWidget() );
3438 }
3439
3440 /*
3441  *  Slots
3442 */
3443 void Desktop_AppSelectionDlg::onAppSelected( int id )
3444 {
3445     myAppId = id;
3446 }
3447
3448 void Desktop_AppSelectionDlg::onHelp()
3449 {
3450 }
3451