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