2 // File : QAD_Desktop.cxx
3 // Created : UI team, 02.10.00
4 // Descr : Main desktop of QAD-based application
6 // Modified : Mon Dec 03 13:40:28 2001
7 // Author : Nicolas REJNERI
10 // Copyright : Open CASCADE 2001
14 \class QAD_Desktop QAD_Desktop.h
15 \brief Main desktop of QAD-based application.
18 # include "Utils_ORB_INIT.hxx"
19 # include "Utils_SINGLETON.hxx"
21 #define INCLUDE_MENUITEM_DEF
25 #include "QAD_Tools.h"
26 #include "QAD_Desktop.h"
27 #include "QAD_LeftFrame.h"
28 #include "QAD_RightFrame.h"
29 #include "QAD_Operation.h"
30 #include "QAD_XmlHandler.h"
31 #include "QAD_MessageBox.h"
32 #include "QAD_Application.h"
33 #include "QAD_Settings.h"
34 #include "QAD_Config.h"
35 #include "QAD_ObjectBrowser.h"
36 #include "QAD_Resource.h"
37 #include "QAD_FileDlg.h"
38 #include "QAD_HelpWindow.h"
39 #include "QAD_DirListDlg.h"
40 #include "QAD_WaitCursor.h"
41 #include "SALOMEGUI_OpenWith.h"
42 #include "SALOMEGUI_StudyPropertiesDlg.h"
43 #include "SALOMEGUI_TrihedronSizeDlg.h"
44 #include "SALOMEGUI_LoadStudiesDlg.h"
45 #include "SALOME_Selection.h"
46 #include "SALOME_InteractiveObject.hxx"
47 #include "SALOME_ListIteratorOfListIO.hxx"
48 #include "SALOMEGUI_AboutDlg.h"
49 #include "SALOMEGUI_ViewChoiceDlg.h"
50 #include "utilities.h"
52 #include "SALOMEGUI_CloseDlg.h"
57 #include <qmessagebox.h>
58 #include <qcolordialog.h>
59 #include <qradiobutton.h>
60 #include <qapplication.h>
61 #include <qvbuttongroup.h>
63 #include <qmessagebox.h>
66 #include <qpopupmenu.h>
67 #include <qlistview.h>
71 #include <qfontdialog.h>
72 #include <qlineedit.h>
79 // Open CASCADE Includes
80 #include <OSD_LoadMode.hxx>
81 #include <OSD_Function.hxx>
82 #include <TCollection_AsciiString.hxx>
84 static const char* SEPARATOR = ":";
91 QAD_ResourceMgr* QAD_Desktop::resourceMgr = 0;
92 QPalette* QAD_Desktop::palette = 0;
96 Creates the resource manager [ static ]
98 QAD_ResourceMgr* QAD_Desktop::createResourceManager()
101 resourceMgr = new QAD_ResourceMgr;
106 Returns the resource manager [ static ]
108 QAD_ResourceMgr* QAD_Desktop::getResourceManager()
115 Loads the palette from settings [ static ]
117 QPalette* QAD_Desktop::createPalette()
120 palette = new QPalette();
126 Returns the palette [ static ]
128 QPalette* QAD_Desktop::getPalette()
134 Gets window ratio width/heght [ static ]
136 static double myWindowRatio = 1;
137 static double getWindowRatio()
139 return myWindowRatio;
143 Sets window ratio width/heght [ static ]
145 static void setWindowRatio(double aRatio)
147 myWindowRatio = aRatio;
153 QAD_Desktop::QAD_Desktop(SALOME_NamingService* name_service) :
154 QMainWindow(0, 0, WType_TopLevel | WDestructiveClose),
161 myDefaultTitle( tr("DESK_DEFAULTTITLE") ),
164 /* Force reading of user config file */
165 QAD_CONFIG->readConfigFile();
167 /* menubar and status bar */
168 myStatusBar = statusBar();
169 myMainMenu = menuBar();
171 myNameService = name_service;
173 /* default background icon */
174 QPixmap backgroundicon ( QAD_Desktop::getResourceManager()->loadPixmap( "CLIENT",
175 tr("ICON_DESK_BACKGROUNDICON") ));
176 myToolBarAction.setAutoDelete( true );
178 /* default icon and title */
179 QPixmap icon ( QAD_Desktop::getResourceManager()->loadPixmap( "CLIENT",
180 tr("ICON_DESK_DEFAULTICON") ));
181 if ( !icon.isNull() ) {
182 myDefaultIcon = icon;
183 setIcon( myDefaultIcon );
185 setCaption( myDefaultTitle );
187 /* set size as 1/2 of the screen and center it */
188 QWidget* d = QApplication::desktop();
189 resize( 2*d->width()/3, 2*d->height()/3 );
190 QAD_Tools::centerWidget( this, d );
192 /* workspace will manage child frames */
193 QHBox* border = new QHBox ( this );
194 border->setFrameStyle ( QFrame::Panel | QFrame::Sunken );
195 setCentralWidget( border );
196 myWorkspace = new QWorkspaceP( border );
198 QPalette pal = QAD_Application::getPalette();
200 QColorGroup cgA = pal.active();
201 QColorGroup cgI = pal.inactive();
202 QColorGroup cgD = pal.disabled();
203 cgA.setColor( QColorGroup::Background, QColor(192, 192, 192));
204 cgI.setColor( QColorGroup::Background, QColor(192, 192, 192));
205 cgD.setColor( QColorGroup::Background, QColor(192, 192, 192));
206 pal.setActive ( cgA );
207 pal.setInactive( cgI );
208 pal.setDisabled( cgD );
209 myWorkspace->setPalette( pal );
210 if ( !backgroundicon.isNull() ) {
211 MESSAGE("!!!DESKTOP background icon found!!!");
212 myWorkspace->setPaletteBackgroundPixmap(backgroundicon);
215 /* define standard file commands */
218 /* define operator menus for xml */
219 myOperatorMenus = new QAD_OperatorMenus(this);
220 myXmlHandler = new QAD_XmlHandler();
223 CORBA::Object_var objVarN = myNameService->Resolve("/Kernel/ModulCatalog");
224 myCatalogue = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
226 SALOME_ModuleCatalog::ListOfIAPP_Affich_var list_composants =
227 myCatalogue->GetComponentIconeList();
230 QToolBar* tbComponent = new QToolBar( tr("MEN_DESK_COMPONENTTOOLBAR"), this );
231 tbComponent->setCloseMode( QDockWindow::Undocked );
232 addToolBar(tbComponent, tr("MEN_DESK_COMPONENTTOOLBAR"), Bottom, TRUE );
233 setDockEnabled( tbComponent, DockLeft, false );
234 setDockEnabled( tbComponent, DockRight, false );
236 myCombo = new QComboBox( FALSE, tbComponent, "comboBox" );
237 myCombo->setFocusPolicy( NoFocus );
239 tbComponent->addSeparator();
241 // PG : add ResourceManager to get function findFile !!
242 QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
244 for (unsigned int ind = 0; ind < list_composants->length();ind++) {
247 /* find component icon */
248 QString iconfile = strdup(list_composants[ind].moduleicone) ;
249 QString modulename = strdup(list_composants[ind].modulename) ;
250 QString moduleusername = strdup(list_composants[ind].moduleusername) ;
252 // MESSAGE ( " MODULE = " << modulename )
253 // MESSAGE ( " MODULE icon = " << iconfile )
254 // MESSAGE ( " MODULE username = " << moduleusername )
256 if ( mapComponentName.contains( moduleusername ) ) {
257 QMessageBox::warning( this, tr("WRN_WARNING"), QString( moduleusername + " is already associated with " + mapComponentName[moduleusername] + ".\nPlease, change the component username of " + modulename) , tr ("BUT_OK") );
260 mapComponentName.insert( moduleusername, modulename );
262 resDir = resMgr->findFile(iconfile,modulename) ;
265 MESSAGE ( "resDir" << resDir )
266 //resDir = QAD_Tools::addSlash(resDir) ;
267 //QPixmap Icone(resDir+iconfile) ;
268 QPixmap Icone( QAD_Tools::addSlash( resDir ) + iconfile );
269 QToolButton * toolb =
270 new QToolButton( QIconSet( Icone ), moduleusername, QString::null, this,
271 SLOT( onButtonActiveComponent () ),tbComponent );
272 toolb->setToggleButton( true );
273 myComponentButton.append(toolb);
277 QString errMsg = tr("INF_ICON_RESOURCES").arg(iconfile).arg(modulename) +
279 //QMessageBox::warning( this, tr("WRN_WARNING"), errMsg, tr ("BUT_OK") );
282 if ( !QString(list_composants[ind].modulename).isEmpty() )
283 myCombo->insertItem( strdup(list_composants[ind].moduleusername) );
287 myCombo->adjustSize();
288 connect( myCombo, SIGNAL(activated(const QString&)),
289 this, SLOT( onComboActiveComponent(const QString&) ) );
291 /* new LifeCycleCORBA client, for Engines */
292 myEnginesLifeCycle = new SALOME_LifeCycleCORBA(name_service);
294 /* VSR 13/01/03 : installing global event filter for the application */
295 qApp->installEventFilter( this );
301 QAD_Desktop::~QAD_Desktop ()
303 qApp->removeEventFilter( this );
307 myObjBrowserPopup.clear();
308 //VRV: T2.5 - add default viewer
309 myDefaultViewer.clear();
310 //VRV: T2.5 - add default viewer
311 myViewerPopup.clear();
313 myNewViewPopup.clear();
315 myToolsPopup.clear();
317 myStdActions.clear();
319 myToolBarsPopup.clear();
320 myToolBarAction.clear();
324 myHelpWindow->close();
326 QAD_Application::desktop = 0;
329 const int IdCut = 1001;
330 const int IdCopy = 1002;
331 const int IdPaste = 1003;
332 const int IdSelectAll = 1004;
334 #include <qkeysequence.h>
335 #define ACCEL_KEY(k) "\t" + QString(QKeySequence( Qt::CTRL | Qt::Key_ ## k ))
337 #define ACCEL_KEY(k) "\t" + QString("Ctrl+" #k)
339 #include <qclipboard.h>
341 Global event filter for qapplication (VSR 13/01/03)
343 bool QAD_Desktop::eventFilter( QObject* o, QEvent* e )
345 if ( e->type() == QEvent::ContextMenu ) {
346 QContextMenuEvent* ce = (QContextMenuEvent*)e;
347 if ( o->inherits("QRenameEdit") ) {
350 else if ( o->inherits("QLineEdit") ) {
351 QLineEdit* le = (QLineEdit*)o;
352 if ( le->parentWidget() ) {
353 if ( ( le->parentWidget()->inherits("QSpinBox") ||
354 le->parentWidget()->inherits("QSpinWidget") ||
355 le->parentWidget()->inherits("QAD_SpinBoxDbl") ) &&
357 QPopupMenu* popup = new QPopupMenu( 0, "qt_edit_menu" );
358 popup->insertItem( tr( "EDIT_CUT_CMD" ) + ACCEL_KEY( X ), IdCut );
359 popup->insertItem( tr( "EDIT_COPY_CMD" ) + ACCEL_KEY( C ), IdCopy );
360 popup->insertItem( tr( "EDIT_PASTE_CMD" ) + ACCEL_KEY( V ), IdPaste );
361 popup->insertSeparator();
362 #if defined(Q_WS_X11)
363 popup->insertItem( tr( "EDIT_SELECTALL_CMD" ), IdSelectAll );
365 popup->insertItem( tr( "EDIT_SELECTALL_CMD" ) + ACCEL_KEY( A ), IdSelectAll );
367 bool enableCut = !le->isReadOnly() && le->hasSelectedText();
368 popup->setItemEnabled( IdCut, enableCut );
369 popup->setItemEnabled( IdCopy, le->hasSelectedText() );
370 bool enablePaste = !le->isReadOnly() && !QApplication::clipboard()->text().isEmpty();
371 popup->setItemEnabled( IdPaste, enablePaste );
372 bool allSelected = (le->selectedText() == le->text() );
373 popup->setItemEnabled( IdSelectAll, (bool)(le->text().length()) && !allSelected );
375 QPoint pos = ce->reason() == QContextMenuEvent::Mouse ? ce->globalPos() :
376 le->mapToGlobal( QPoint(ce->pos().x(), 0) ) + QPoint( le->width() / 2, le->height() / 2 );
378 int r = popup->exec( pos );
400 return QMainWindow::eventFilter( o, e );
404 Creates and initializes the standard file operations
405 such as 'New/Open/Save/SaveAs/Close' and 'Help'.
407 void QAD_Desktop::createActions()
410 /* Used for string compare */
411 const QString& aTrueQString = "true" ;
413 /* create 'standard' toolbar */
414 if ( !myStdToolBar ) {
415 myStdToolBar = new QToolBar ( tr("MEN_DESK_VIEW_STDTOOLBAR"), this );
416 myStdToolBar->setCloseMode( QDockWindow::Undocked );
419 if ( !myMainMenu->count() ) {
420 /* Create main menu bar */
421 myMainMenu->insertItem ( tr("MEN_DESK_FILE"), &myFilePopup, 1 ); /* add popup FILE */
422 myMainMenu->insertItem ( tr("MEN_DESK_VIEW"), &myViewPopup, 2 ); /* add popup VIEW */
423 myMainMenu->insertItem ( tr("MEN_DESK_TOOLS"), &myToolsPopup, 5 ); /* add popup TOOLS */
424 myMainMenu->insertItem ( tr("MEN_DESK_PREF"), &myPrefPopup, 4 ); /* add popup PREF */
425 myMainMenu->insertItem ( tr("MEN_DESK_WINDOW"), &myWindowPopup, 6 ); /* add popup WINDOW */
426 myMainMenu->insertItem ( tr("MEN_DESK_HELP"), &myHelpPopup, 7 ); /* add popup HELP */
428 /* Applications will insert their items after 'File' 'Edit' and 'View'
429 ( 'Edit' will be inserted later )
434 /* insert logo picture to menu bar */
435 QHBox* aLogoFrm = new QHBox(this);
436 aLogoFrm->setFrameStyle( QFrame::Plain | QFrame::NoFrame );
437 QPixmap aLogoPixmap ( QAD_Desktop::getResourceManager()->loadPixmap( "CLIENT",
438 tr("ICON_DESK_LOGO") ));
439 QLabel* aLogoLab = new QLabel(aLogoFrm);
440 aLogoLab->setPixmap(aLogoPixmap);
441 aLogoLab->setAlignment(AlignCenter);
442 aLogoLab->setScaledContents(false);
443 myMainMenu->insertItem(aLogoFrm);
445 if ( myStdActions.isEmpty() ) {
446 /* Define standard actions. They should be inserted
447 into the list in order of their IDs.
452 QAD_ResourceMgr* rmgr = QAD_Desktop::getResourceManager();
453 QAction* fileNewAction = new QAction ( tr("TOT_DESK_FILE_NEW"),
454 rmgr->loadPixmap( "QAD", tr("ICON_FILE_NEW") ) ,
455 tr("MEN_DESK_FILE_NEW"), CTRL+Key_N, this );
456 fileNewAction->setStatusTip ( tr("PRP_DESK_FILE_NEW") );
457 fileNewAction->setEnabled ( true );
458 QAD_ASSERT ( connect( fileNewAction, SIGNAL( activated() ), this, SLOT( onNewStudy() )));
459 fileNewAction->addTo( myStdToolBar );
460 fileNewAction->addTo( &myFilePopup );
461 myStdActions.insert ( FileNewId, fileNewAction );
464 QAction* fileOpenAction = new QAction( tr("TOT_DESK_FILE_OPEN"), rmgr->loadPixmap( "QAD", tr("ICON_FILE_OPEN") ),
465 tr("MEN_DESK_FILE_OPEN"), CTRL+Key_O, this );
466 fileOpenAction->setStatusTip ( tr("PRP_DESK_FILE_OPEN") );
467 fileOpenAction->setEnabled ( true );
468 QAD_ASSERT ( connect( fileOpenAction, SIGNAL( activated() ), this, SLOT( onOpenStudy() )));
469 fileOpenAction->addTo( myStdToolBar );
470 fileOpenAction->addTo( &myFilePopup );
471 myStdActions.insert ( FileOpenId, fileOpenAction );
474 QAction* fileLoadAction = new QAction( tr("TOT_DESK_FILE_LOAD"), rmgr->loadPixmap( "QAD", tr("ICON_FILE_LOAD") ),
475 tr("MEN_DESK_FILE_LOAD"), CTRL+Key_L, this );
476 fileLoadAction->setStatusTip ( tr("PRP_DESK_FILE_LOAD") );
477 fileLoadAction->setEnabled ( true );
478 QAD_ASSERT ( connect( fileLoadAction, SIGNAL( activated() ), this, SLOT( onLoadStudy() )));
479 fileLoadAction->addTo( &myFilePopup );
480 myStdActions.insert ( FileLoadId, fileLoadAction );
483 QAction* fileCloseAction = new QAction( "", rmgr->loadPixmap( "QAD", tr("ICON_FILE_CLOSE") ),
484 tr("MEN_DESK_FILE_CLOSE"), CTRL+Key_W, this );
485 fileCloseAction->setStatusTip ( tr("PRP_DESK_FILE_CLOSE") );
486 QAD_ASSERT ( connect( fileCloseAction, SIGNAL( activated() ), this, SLOT( onCloseStudy() )));
487 fileCloseAction->addTo( &myFilePopup );
488 myStdActions.insert ( FileCloseId, fileCloseAction );
491 myFilePopup.insertSeparator();
494 QAction* fileSaveAction = new QAction( tr("TOT_DESK_FILE_SAVE"), rmgr->loadPixmap( "QAD", tr("ICON_FILE_SAVE") ),
495 tr("MEN_DESK_FILE_SAVE"), CTRL+Key_S, this );
496 fileSaveAction->setStatusTip ( tr("PRP_DESK_FILE_SAVE") );
497 QAD_ASSERT ( connect( fileSaveAction, SIGNAL( activated() ), this, SLOT( onSaveStudy() )));
498 fileSaveAction->addTo( myStdToolBar );
499 fileSaveAction->addTo( &myFilePopup );
500 myStdActions.insert ( FileSaveId, fileSaveAction );
503 QAction* fileSaveAsAction = new QAction( "", tr("MEN_DESK_FILE_SAVEAS"), 0, this );
504 fileSaveAsAction->setStatusTip ( tr("PRP_DESK_FILE_SAVEAS") );
505 QAD_ASSERT ( connect( fileSaveAsAction, SIGNAL( activated() ),
506 this, SLOT( onSaveAsStudy() )));
507 fileSaveAsAction->addTo( &myFilePopup );
508 myStdActions.insert ( FileSaveAsId, fileSaveAsAction );
512 myFilePopup.insertSeparator();
515 QAction* filePropsAction = new QAction( "", QPixmap(), tr("MEN_DESK_FILE_PROPERTIES"), 0, this );
516 filePropsAction->setStatusTip ( tr("PRP_DESK_FILE_PROPERTIES") );
517 filePropsAction->setEnabled(false);
518 QAD_ASSERT ( connect( filePropsAction, SIGNAL( activated() ), this, SLOT( onStudyProperties() )));
519 filePropsAction->addTo( &myFilePopup );
520 myStdActions.insert ( FilePropsId, filePropsAction );
523 int id = myFilePopup.insertSeparator();
524 /* keep the position from which an application will insert its items
525 to menu 'File' at the time of customization of the desktop */
527 myFilePos = myFilePopup.indexOf( id ) + 1;
529 /* exit application */
530 QAction* exitAction = new QAction( "", tr("MEN_DESK_FILE_EXIT"),
532 exitAction->setStatusTip ( tr("PRP_DESK_FILE_EXIT") );
533 QAD_ASSERT ( connect( exitAction, SIGNAL( activated() ),
534 this, SLOT( onExit() )));
535 exitAction->addTo( &myFilePopup );
536 myStdActions.insert ( FileExitId, exitAction );
538 /* 'Edit' actions : provided by application only */
542 /* toolbars popup menu */
543 myViewPopup.insertItem( tr("MEN_DESK_VIEW_TOOLBARS"), &myToolBarsPopup );
544 QAD_ASSERT( connect ( &myViewPopup, SIGNAL(aboutToShow()),
545 this, SLOT(onToolBarPopupAboutToShow()) ));
548 QAction* viewStatusBarAction = new QAction( "",
549 tr("MEN_DESK_VIEW_STATUSBAR"),
551 viewStatusBarAction->setStatusTip ( tr("PRP_DESK_VIEW_STATUSBAR") );
552 viewStatusBarAction->setOn( true );
553 QAD_ASSERT(connect( viewStatusBarAction, SIGNAL(activated()), this, SLOT(onViewStatusBar() )));
554 viewStatusBarAction->addTo( &myViewPopup );
555 myStdActions.insert( ViewStatusBarId, viewStatusBarAction );
557 // myViewPopup.insertItem( tr("MEN_DESK_SELECTION_MODE"), &mySelectionModePopup );
559 QAction* SelectionPointAction = new QAction( "", tr("MEN_DESK_SELECTION_POINT"), 0, this, 0, true );
560 QAD_ASSERT(connect( SelectionPointAction, SIGNAL(activated()), this, SLOT(onSelectionMode() )));
561 SelectionPointAction->addTo( &mySelectionModePopup );
562 myStdActions.insert( SelectionPointId, SelectionPointAction );
564 QAction* SelectionEdgeAction = new QAction( "", tr("MEN_DESK_SELECTION_EDGE"), 0, this, 0, true );
565 QAD_ASSERT(connect( SelectionEdgeAction, SIGNAL(activated()), this, SLOT(onSelectionMode() )));
566 SelectionEdgeAction->addTo( &mySelectionModePopup );
567 myStdActions.insert( SelectionEdgeId, SelectionEdgeAction );
569 QAction* SelectionCellAction = new QAction( "", tr("MEN_DESK_SELECTION_CELL"), 0, this, 0, true );
570 QAD_ASSERT(connect( SelectionCellAction, SIGNAL(activated()), this, SLOT(onSelectionMode() )));
571 SelectionCellAction->addTo( &mySelectionModePopup );
572 myStdActions.insert( SelectionCellId, SelectionCellAction );
574 QAction* SelectionActorAction = new QAction( "", tr("MEN_DESK_SELECTION_ACTOR"), 0, this, 0, true );
575 QAD_ASSERT(connect( SelectionActorAction, SIGNAL(activated()), this, SLOT(onSelectionMode() )));
576 SelectionActorAction->addTo( &mySelectionModePopup );
577 myStdActions.insert( SelectionActorId, SelectionActorAction );
578 SelectionActorAction->setOn(true);
580 myViewPos = myViewPopup.count();
583 QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
586 if(!resMgr->loadResources( "ToolsGUI", msg ))
588 //NRI QCString errMsg;
589 // errMsg.sprintf( "Do not load all resources for module ToolsGUI.\n" );
590 QMessageBox::warning( this, tr("WRN_WARNING"), msg, tr ("BUT_OK") );
594 myOperatorMenus = new QAD_OperatorMenus(this);
595 myXmlHandler = new QAD_XmlHandler();
596 ASSERT(myXmlHandler) ;
597 myXmlHandler->setMainWindow(this);
598 if ( myXmlHandler->setComponent( resMgr->resources( "ToolsGUI" ) ) ) {
599 QString language = resMgr->language( "ToolsGUI" );
600 QString ToolsXml = QString( "Tools_" ) + language + QString( ".xml" );
602 //ToolsXml = resMgr->resources("ToolsGUI") ;
603 //ToolsXml = QAD_Tools::addSlash(ToolsXml) ;
604 //ToolsXml = ToolsXml + "Tools_" + language + ".xml" ;
605 ToolsXml = QAD_Tools::addSlash( resMgr->findFile( ToolsXml, "ToolsGUI" ) ) + ToolsXml;
607 QFile file( QAD_Tools::unix2win( ToolsXml ) );
608 if ( file.exists() && file.open( IO_ReadOnly ) ) {
610 QXmlInputSource source( file );
611 QXmlSimpleReader reader;
612 reader.setContentHandler( myXmlHandler );
613 reader.setErrorHandler( myXmlHandler );
614 bool ok = reader.parse( source );
617 QMessageBox::critical( 0,
618 tr( "INF_PARSE_ERROR" ),
619 tr( myXmlHandler->errorProtocol() ) );
621 myMenusList=myXmlHandler->myMenusList;
622 myActiveMenus=myMenusList.at(0);
623 myOperatorMenus->showMenuBar(0);
624 myActiveMenus->showAllToolBars();
630 if ( myToolsPopup.count() == 0 ) {
631 myMainMenu->removeItem(5);
635 /* Viewer BackgroundColor */
636 myPrefPopup.insertItem( tr("MEN_DESK_PREF_VIEWER"), &myViewerPopup );
638 QAction* viewerOCCAction = new QAction( "", tr("MEN_DESK_PREF_VIEWER_OCC"), 0, this );
639 QAD_ASSERT(connect( viewerOCCAction, SIGNAL(activated()), this, SLOT(onViewerOCC() )));
640 viewerOCCAction->addTo( &myViewerPopup );
641 myStdActions.insert( PrefViewerOCCId, viewerOCCAction );
643 QAction* viewerVTKAction = new QAction( "", tr("MEN_DESK_PREF_VIEWER_VTK"), 0, this );
644 QAD_ASSERT(connect( viewerVTKAction, SIGNAL(activated()), this, SLOT(onViewerVTK() )));
645 viewerVTKAction->addTo( &myViewerPopup );
646 myStdActions.insert( PrefViewerVTKId, viewerVTKAction );
648 QAction* graphSupervisorAction = new QAction( "", tr("MEN_DESK_PREF_GRAPH_SUPERVISOR"), 0, this );
649 QAD_ASSERT(connect( graphSupervisorAction, SIGNAL(activated()), this, SLOT(onGraphSupervisor() )));
650 graphSupervisorAction->addTo( &myViewerPopup );
651 myStdActions.insert( PrefGraphSupervisorId, graphSupervisorAction );
653 QAction* viewerPlot2dAction = new QAction( "", tr("MEN_DESK_PREF_VIEWER_PLOT2D"), 0, this );
654 QAD_ASSERT(connect( viewerPlot2dAction, SIGNAL(activated()), this, SLOT(onPlot2d() )));
655 viewerPlot2dAction->addTo( &myViewerPopup );
656 myStdActions.insert( PrefViewerPlot2dId, viewerPlot2dAction );
658 //VRV: T2.5 - add default viewer
659 QString viewerValue = QAD_CONFIG->getSetting( "Viewer:DefaultViewer" );
661 int aViewerValue = viewerValue.toInt( &ok, 10 );
662 if (!ok || aViewerValue < VIEW_OCC || aViewerValue >= VIEW_TYPE_MAX)
663 aViewerValue = VIEW_VTK;
665 myPrefPopup.insertItem( tr("MEN_DESK_PREF_DEFAULT_VIEWER"), &myDefaultViewer );
666 QActionGroup* myQAG = new QActionGroup ( this);
667 QAction* viewerOCCAction1 = new QAction( "", tr("MEN_DESK_PREF_VIEWER_OCC"), 0, this );
668 viewerOCCAction1->setToggleAction ( true);
669 viewerOCCAction1->setOn ( aViewerValue == VIEW_OCC );
670 myQAG->insert( viewerOCCAction1 );
671 myStdActions.insert( DefaultViewerOCCId, viewerOCCAction1 );
673 QAction* viewerVTKAction1 = new QAction( "", tr("MEN_DESK_PREF_VIEWER_VTK"), 0, this );
674 viewerVTKAction1->setToggleAction ( true);
675 viewerVTKAction1->setOn ( aViewerValue == VIEW_VTK );
676 myQAG->insert( viewerVTKAction1 );
677 myStdActions.insert( DefaultViewerVTKId, viewerVTKAction1 );
679 /* Remove Supervisor viewer from setting the background */
680 // QAction* graphSupervisorAction1 = new QAction( "", tr("MEN_DESK_PREF_GRAPH_SUPERVISOR"), 0, this );
681 // graphSupervisorAction1->setToggleAction ( true);
682 // graphSupervisorAction1->setOn ( aViewerValue == VIEW_GRAPHSUPERV );
683 // myQAG->insert( graphSupervisorAction1 );
684 // myStdActions.insert( DefaultGraphSupervisorId, graphSupervisorAction1 );
686 QAction* viewerPlot2dAction1 = new QAction( "", tr("MEN_DESK_PREF_VIEWER_PLOT2D"), 0, this );
687 viewerPlot2dAction1->setToggleAction ( true);
688 viewerPlot2dAction1->setOn ( aViewerValue == VIEW_PLOT2D );
689 myQAG->insert( viewerPlot2dAction1 );
690 myStdActions.insert( DefaultPlot2dId, viewerPlot2dAction1 );
692 myQAG->addTo( &myDefaultViewer );
693 QAD_ASSERT(connect( myQAG, SIGNAL(selected(QAction * )), this, SLOT(onDefaultViewer(QAction *) )));
694 //VRV: T2.5 - add default viewer
696 QAction* viewerTrihedronAction = new QAction( "", tr("MEN_DESK_PREF_VIEWER_TRIHEDRON"), 0, this );
697 QAD_ASSERT(connect( viewerTrihedronAction, SIGNAL(activated()), this, SLOT(onViewerTrihedron() )));
698 viewerTrihedronAction->addTo( &myPrefPopup );
699 myStdActions.insert( PrefViewerTrihedronId, viewerTrihedronAction );
701 QAction* consoleFontAction = new QAction( "", tr("MEN_DESK_PREF_CONSOLE_FONT"), 0, this );
702 QAD_ASSERT(connect( consoleFontAction, SIGNAL(activated()), this, SLOT(onConsoleFontAction() )));
703 consoleFontAction->addTo( &myPrefPopup );
704 myStdActions.insert( PrefConsoleFontId, consoleFontAction );
707 QAction* multiFileSaveAction = new QAction( "", tr("MEN_DESK_PREF_MULTI_FILE_SAVE"), 0, this, 0, true );
708 QAD_ASSERT(connect( multiFileSaveAction, SIGNAL(activated()), this, SLOT(onMultiFileSave() )));
709 multiFileSaveAction->setToggleAction( true );
710 QString MultiSave = QAD_CONFIG->getSetting("Desktop:MultiFileSave");
711 multiFileSaveAction->setOn( MultiSave.compare( aTrueQString ) == 0 );
712 multiFileSaveAction->addTo( &myPrefPopup );
713 myStdActions.insert( PrefMultiFileSave, multiFileSaveAction );
715 myPrefPopup.insertSeparator();
718 myPrefPopup.insertItem( tr("MEN_DESK_PREF_OBJECTBROWSER"), &myObjBrowserPopup );
720 QAction* objectBrowserEntryAction = new QAction( "", tr("MEN_DESK_PREF_OBJECTBROWSER_ENTRY"), 0, this, 0, true );
721 QAD_ASSERT(connect( objectBrowserEntryAction, SIGNAL(activated()), this, SLOT(onObjectBrowser() )));
722 objectBrowserEntryAction->setToggleAction(true);
723 QString AddColumn = QAD_CONFIG->getSetting("ObjectBrowser:AddColumn");
725 if ( AddColumn.compare( aTrueQString ) == 0 )
726 objectBrowserEntryAction->setOn(true);
728 objectBrowserEntryAction->setOn(false);
730 objectBrowserEntryAction->addTo( &myObjBrowserPopup );
731 myStdActions.insert( PrefObjectBrowserEntryId, objectBrowserEntryAction );
733 QAction* objectBrowserValueAction = new QAction( "", tr("MEN_DESK_PREF_OBJECTBROWSER_VALUE"), 0, this, 0, true );
734 QAD_ASSERT(connect( objectBrowserValueAction, SIGNAL(activated()), this, SLOT(onObjectBrowser() )));
735 objectBrowserValueAction->setToggleAction(true);
736 QString ValueColumn = QAD_CONFIG->getSetting("ObjectBrowser:ValueColumn");
738 if ( ValueColumn.compare( aTrueQString ) == 0 )
739 objectBrowserValueAction->setOn(true);
741 objectBrowserValueAction->setOn(false);
743 objectBrowserValueAction->addTo( &myObjBrowserPopup );
744 myStdActions.insert( PrefObjectBrowserValueId, objectBrowserValueAction );
746 QAction* objectBrowserIAPPAction = new QAction( "", tr("MEN_DESK_PREF_OBJECTBROWSER_IAPP"), 0, this, 0, true );
747 QAD_ASSERT(connect( objectBrowserIAPPAction, SIGNAL(activated()), this, SLOT(onObjectBrowser() )));
748 objectBrowserIAPPAction->setToggleAction(true);
749 QString showIAPP = QAD_CONFIG->getSetting("ObjectBrowser:IAPP");
751 if ( showIAPP.compare( aTrueQString ) == 0 )
752 objectBrowserIAPPAction->setOn(true);
754 objectBrowserIAPPAction->setOn(false);
756 objectBrowserIAPPAction->addTo( &myObjBrowserPopup );
757 myStdActions.insert( PrefObjectBrowserIAPPId, objectBrowserIAPPAction );
759 /* Chronological sorting of shapes on the entry creation */
760 QAction* objectBrowserCHRONO_SORTAction = new QAction( "", tr("MEN_DESK_PREF_OBJECTBROWSER_CHRONO_SORT"), 0, this, 0, true );
761 QAD_ASSERT(connect( objectBrowserCHRONO_SORTAction, SIGNAL(activated()), this, SLOT(onObjectBrowser() )));
762 objectBrowserCHRONO_SORTAction->setToggleAction(true);
763 QString showSORT = QAD_CONFIG->getSetting("ObjectBrowser:CHRONO_SORT");
765 if ( showSORT.compare( aTrueQString ) == 0 )
766 objectBrowserCHRONO_SORTAction->setOn(true) ;
768 objectBrowserCHRONO_SORTAction->setOn(false) ;
770 objectBrowserCHRONO_SORTAction->addTo( &myObjBrowserPopup );
771 myStdActions.insert( PrefObjectBrowserCHRONO_SORTId, objectBrowserCHRONO_SORTAction ) ;
773 myPrefPopup.insertSeparator();
775 QAction* dirAction = new QAction( "", tr("MEN_DESK_PREF_DIRICTORIES"), ALT+Key_D, this );
776 QAD_ASSERT(connect( dirAction, SIGNAL(activated()), this, SLOT(onDirList() )));
777 dirAction->addTo( &myPrefPopup );
778 myStdActions.insert( PrefDirsId, dirAction );
780 myPrefPopup.insertSeparator();
782 QAction* saveAction = new QAction( "", tr("MEN_DESK_PREF_SAVE"), 0, this );
783 QAD_ASSERT(connect( saveAction, SIGNAL(activated()), this, SLOT(onSavePref() )));
784 saveAction->addTo( &myPrefPopup );
785 myStdActions.insert( PrefSaveId, saveAction );
787 /* 'Window' actions */
790 myWindowPopup.insertItem( tr("MEN_DESK_WINDOW_NEW3D"), &myNewViewPopup, WindowNew3dId );
792 QAction* viewOCCAction = new QAction( "", tr("MEN_DESK_VIEW_OCC"), ALT+Key_O, this );
793 QAD_ASSERT(connect( viewOCCAction, SIGNAL(activated()), this, SLOT(onNewWindow3d() )));
794 viewOCCAction->addTo( &myNewViewPopup );
795 myStdActions.insert( ViewOCCId, viewOCCAction );
797 QAction* viewVTKAction = new QAction( "", tr("MEN_DESK_VIEW_VTK"), ALT+Key_V, this );
798 QAD_ASSERT(connect( viewVTKAction, SIGNAL(activated()), this, SLOT(onNewWindow3d() )));
799 viewVTKAction->addTo( &myNewViewPopup );
800 myStdActions.insert( ViewVTKId, viewVTKAction );
802 QAction* viewPlot2dAction = new QAction( "", tr("MEN_DESK_VIEW_PLOT2D"), ALT+Key_P, this );
803 QAD_ASSERT(connect( viewPlot2dAction, SIGNAL(activated()), this, SLOT(onNewWindow3d() )));
804 viewPlot2dAction->addTo( &myNewViewPopup );
805 myStdActions.insert( ViewPlot2dId, viewPlot2dAction );
807 // QAction* windowNew3dAction = new QAction( "",/* rmgr->loadPixmap( "QAD", tr("ICON_DESK_WINDOW_NEW3D") ), */
808 /*tr("MEN_DESK_WINDOW_NEW3D"), 0, this );
809 windowNew3dAction->addTo( &myWindowPopup );
810 QAD_ASSERT( connect( windowNew3dAction, SIGNAL(activated()), this ,
811 SLOT( onNewWindow3d() )));
812 myStdActions.insert( WindowNew3dId, windowNew3dAction );
818 QAction* windowCascadeAction = new QAction( "", rmgr->loadPixmap( "QAD", tr("ICON_DESK_WINDOW_CASCADE") ),
819 tr("MEN_DESK_WINDOW_CASCADE"), 0, this );
820 windowCascadeAction->setStatusTip ( tr("PRP_DESK_WINDOW_CASCADE") );
821 QAD_ASSERT( connect( windowCascadeAction, SIGNAL(activated()), this,
822 SLOT( onCascade() )));
823 myStdActions.insert( WindowCascadeId, windowCascadeAction );
826 QAction* windowTileAction = new QAction( "", rmgr->loadPixmap( "QAD", tr("ICON_DESK_WINDOW_TILE") ),
827 tr("MEN_DESK_WINDOW_TILE"), 0, this );
828 windowTileAction->setStatusTip ( tr("PRP_DESK_WINDOW_TILE") );
829 QAD_ASSERT( connect( windowTileAction, SIGNAL(activated()), myWorkspace, SLOT( tile() )));
830 myStdActions.insert( WindowTileId, windowTileAction );
832 QAD_ASSERT( connect ( &myWindowPopup, SIGNAL(aboutToShow()),
833 this, SLOT(onWindowPopupAboutToShow()) ));
837 QAction* helpContentsAction = new QAction( "", tr("MEN_DESK_HELP_CONTENTS"), Key_F1, this );
838 helpContentsAction->setStatusTip ( tr("PRP_DESK_HELP_CONTENTS") );
839 QAD_ASSERT(connect( helpContentsAction, SIGNAL(activated()),
840 this, SLOT( onHelpContents() )));
841 helpContentsAction->addTo( &myHelpPopup );
842 myStdActions.insert( HelpContentsId , helpContentsAction );
845 // QAction* helpSearchAction = new QAction( "", tr("MEN_DESK_HELP_SEARCH"), 0, this );
846 // helpSearchAction->setStatusTip ( tr("PRP_DESK_HELP_SEARCH") );
847 // QAD_ASSERT( connect( helpSearchAction, SIGNAL(activated()), this, SLOT( onHelpSearch() )));
848 // helpSearchAction->addTo( &myHelpPopup );
849 // myStdActions.insert( HelpSearchId, helpSearchAction );
852 // QAction* helpWhatsThisAction = new QAction( "", tr("MEN_DESK_HELP_WHATSTHIS"), SHIFT+Key_F1, this );
853 // helpWhatsThisAction->setStatusTip ( tr("PRP_DESK_HELP_WHATSTHIS" ));
854 // QAD_ASSERT( connect( helpWhatsThisAction, SIGNAL(activated()), this, SLOT( whatsThis() )));
855 // helpWhatsThisAction->addTo( &myHelpPopup );
856 // myStdActions.insert( HelpWhatsThisId, helpWhatsThisAction );
857 // (void)QWhatsThis::whatsThisButton( myStdToolBar );
859 id = myHelpPopup.insertSeparator();
860 myHelpPos = myHelpPopup.indexOf( id );
863 QAction* helpAboutAction = new QAction( "", tr("MEN_DESK_HELP_ABOUT"), 0, this );
864 helpAboutAction->setStatusTip ( tr("PRP_DESK_HELP_ABOUT") );
865 QAD_ASSERT( connect( helpAboutAction, SIGNAL(activated()), this, SLOT( onHelpAbout() )));
866 helpAboutAction->addTo( &myHelpPopup );
867 myStdActions.insert(HelpAboutId, helpAboutAction );
873 Adds the given application into the list of supported applications
875 void QAD_Desktop::addApplication(QAD_Application* app)
877 /* add only if is not already in the list */
878 if ( myApps.findRef( app ) == -1 )
880 myApps.append( app );
882 /* set activation/deactivation listener */
883 QAD_ASSERT ( connect( app, SIGNAL(appActivated(QAD_Application*)),
884 this, SLOT(onActivateApp(QAD_Application*))) );
886 QAD_ASSERT ( connect( app, SIGNAL(appDeactivated(QAD_Application*)),
887 this, SLOT(onDeactivateApp(QAD_Application*))) );
892 Displays the control panel of the application.
893 This function is called when the desktop is shown first time.
895 void QAD_Desktop::showDesktop()
901 Closes Desktop. If <forceClose> is true query for exit will be skipped.
903 void QAD_Desktop::closeDesktop( bool forceClose )
906 myQueryClose = false;
911 Puts the message to the status bar
913 void QAD_Desktop::putInfo ( const QString& msg )
916 myStatusBar->message ( msg );
920 Puts the message to the status bar for ms milli-seconds
922 void QAD_Desktop::putInfo ( const QString& msg, int ms )
925 myStatusBar->message ( msg, ms );
929 Returns the standard toolbar
931 QMenuBar* QAD_Desktop::getMainMenuBar() const
937 Returns the standard toolbar
939 QToolBar* QAD_Desktop::getStdToolBar() const
945 Updates desktop panel (menu, toolbar and status bar) according to current state of
946 the application. Calls update() for the active application.
947 The command { UD_ADD_APP or UD_REMOVE_APP ) specifies the desktop components
948 will be changed according to new active application.
949 This function is called after activating new study, closing current study etc.
951 void QAD_Desktop::updateDesktop( UpdateCommand cmd )
954 updateToolBars( cmd );
955 updateStatusBar( cmd );
960 Updates the desktop caption
962 void QAD_Desktop::updateCaption( UpdateCommand cmd )
964 if ( cmd == ActivateApp )
965 { /* application's icon and title */
966 setIcon( myActiveApp->getApplicationIcon() );
967 setCaption( myActiveApp->getApplicationName() );
970 { /* default icon and title */
971 setIcon( myDefaultIcon );
972 setCaption( myDefaultTitle );
977 Updates status bar when a new application becomes current
979 void QAD_Desktop::updateStatusBar( UpdateCommand cmd )
983 bool activate = ( cmd == ActivateApp );
984 myActiveApp->updateStatusBar ( myStatusBar, activate );
989 Updates toolbars according to current active application.
990 This function is called from updateDesktop().
992 void QAD_Desktop::updateToolBars( UpdateCommand cmd )
996 bool activate = ( cmd == ActivateApp );
997 myActiveApp->updateToolBars ( activate );
1002 Updates main menu bar of the application when application is activated
1004 This function is called by updateDesktop()
1006 void QAD_Desktop::updateMenu( UpdateCommand cmd )
1010 bool activate = ( cmd == ActivateApp );
1011 myActiveApp->updateFilePopup( &myFilePopup, activate, myFilePos );
1012 myActiveApp->updateEditPopup( &myEditPopup, activate, myEditPos );
1013 myActiveApp->updateViewPopup( &myViewPopup, activate, myViewPos );
1014 myActiveApp->updateHelpPopup( &myHelpPopup, activate, myHelpPos );
1015 myActiveApp->updateMainMenu( myMainMenu, activate, myMainMenuPos );
1018 Since 'Edit' popup is completely customized by applications
1019 desktop doesn't show it in main menubar without the active
1020 application and we insert/remove this popup from the menubar
1021 when activating/deactivating applications.
1023 We can't have 'Edit' popup be customized by an application
1024 via UpdateMainMenu() method because applications may insert
1025 its items to the menubar only AFTER 'View' item ( this fact
1026 is respected by myMainMenuPos ) and the possibility of an
1027 application to add its items into any arbitrary positions of
1028 the main menubar requires a bit sophisticated implementation,
1029 so we decided to avoid it, sorry :-(.
1031 #if defined( DEBUG )
1033 /* applications MUST clear 'Edit' after themselves */
1034 QAD_ASSERT_DEBUG_ONLY( !myEditPopup.count() );
1037 if ( activate ) /* insert after 'File' item */
1038 myMainMenu->insertItem( tr("MEN_DESK_EDIT"), &myEditPopup, 3, 1 );
1040 myMainMenu->removeItem( 3 );
1045 Returns icon file name used by the application
1047 const QPixmap& QAD_Desktop::getDefaultIcon() const
1049 static QPixmap defaultPixmap( QAD_Desktop::getResourceManager()->loadPixmap( "QAD",
1050 tr("ICON_DESK_DEFAULTICON") ));
1051 return defaultPixmap;
1055 Returns name of the application used as the title of desktop panel
1057 const QString& QAD_Desktop::getDefaultTitle() const
1059 static QString defaultTitle ( tr("DESK_DEFAULTTITLE") );
1060 return defaultTitle;
1064 Returns default name of new studies
1066 const QString& QAD_Desktop::getDefaultStudyName() const
1068 static QString defaultStudyName( tr("DESK_DEFAULTDOC") );
1069 return defaultStudyName;
1073 Returns next name for new study
1075 QString QAD_Desktop::getNewStudyName()
1078 number.sprintf( "%d", ++myCntUntitled );
1079 return ( getDefaultStudyName() + number );
1083 Searches QAD_Study corresponding to <study>, returns NULL if fails
1085 QAD_Study* QAD_Desktop::findStudy( SALOMEDS::Study_ptr theStudy )
1087 for ( QAD_Application* app = myApps.first(); app; app = myApps.next() ) {
1088 QList<QAD_Study> studies;
1089 studies.setAutoDelete( false );
1090 studies = app->getStudies();
1091 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
1092 if ( study->getStudyDocument()->_is_equivalent( theStudy ) )
1100 Returns current active application
1102 QAD_Application* QAD_Desktop::getActiveApp() const
1108 Returns current active study
1110 QAD_Study* QAD_Desktop::getActiveStudy() const
1112 return myActiveStudy;
1118 QWorkspaceP* QAD_Desktop::getMainFrame() const
1124 Find or load Engine, given a container name and an engine name
1126 Engines::Component_var QAD_Desktop::getEngine(const char *containerName,
1127 const char *componentName)
1129 Engines::Component_var eng =
1130 myEnginesLifeCycle->FindOrLoad_Component(containerName,
1135 QString QAD_Desktop::getComponentName(const char *componentUserName)
1137 if ( mapComponentName.contains(componentUserName) )
1138 return mapComponentName[ componentUserName ] ;
1143 QString QAD_Desktop::getComponentUserName(const char *componentName)
1145 QMap<QString,QString>::Iterator it;
1146 for( it = mapComponentName.begin(); it != mapComponentName.end(); ++it )
1147 if (it.data() == componentName )
1153 gets application Help Window (and creates if necessary)
1155 QAD_HelpWindow* QAD_Desktop::getHelpWindow()
1157 if (!myHelpWindow) {
1158 myHelpWindow = new QAD_HelpWindow();
1160 QMap<QString,QString>::Iterator it;
1161 for( it = mapComponentName.begin(); it != mapComponentName.end(); ++it ) {
1165 // look for index.html and set homeDir
1166 // 1. $(MODULE_ROOT_DIR)/doc/index.html
1167 // 2. $(MODULE_ROOT_DIR)/doc/html/index.html
1168 // 3. $(MODULE_ROOT_DIR)/doc/html/html/index.html
1170 if (dir = getenv( QString( it.data() + "_ROOT_DIR")) ) {
1171 root = QAD_Tools::addSlash( QAD_Tools::addSlash(dir) + QAD_Tools::addSlash("share") + QAD_Tools::addSlash("salome") + "doc" );
1172 if ( QFileInfo( root + "index.html" ).exists() ) {
1173 helpContext( root + "index.html", "" );
1176 root = QAD_Tools::addSlash( root + "html" );
1177 if ( QFileInfo( root + "index.html" ).exists() ) {
1178 helpContext( root + "index.html", "" );
1181 root = QAD_Tools::addSlash( root + "html" );
1182 if ( QFileInfo( root + "index.html" ).exists() ) {
1183 helpContext( root + "index.html", "" );
1190 connect(myHelpWindow, SIGNAL(helpWindowClosed()), this, SLOT(onHelpWindowClosed()));
1192 return myHelpWindow;
1196 Called when desktop is closing
1198 void QAD_Desktop::closeEvent ( QCloseEvent* e )
1200 bool doClose = true;
1201 if ( myQueryClose ) {
1202 doClose = QAD_MessageBox::info2 ( this, tr("INF_DESK_EXIT"),
1203 tr("QUE_DESK_EXIT"), tr ("BUT_OK"),
1204 tr ("BUT_CANCEL"), QAD_YES,
1205 QAD_NO, QAD_NO ) == QAD_YES;
1209 for ( QAD_Application* app = myApps.first(); app; app = myApps.next() ) {
1210 QList<QAD_Study>& studies = app->getStudies();
1211 for(QAD_Study* study = studies.first(); study != 0; study = studies.next()) {
1212 if(myQueryClose && study->getStudyDocument()->IsModified()) {
1213 SALOMEGUI_CloseDlg aDlg( this );
1214 switch ( aDlg.exec() ) {
1216 if ( !onSaveStudy( study ) ) {
1217 putInfo( tr("INF_CANCELLED") );
1228 putInfo( tr("INF_CANCELLED") );
1236 myQueryClose = true;
1237 doClose ? e->accept() : e->ignore();
1241 Called when desktop is resized
1243 void QAD_Desktop::resizeEvent( QResizeEvent* e )
1245 QMainWindow::resizeEvent( e );
1246 myWorkspace->setGeometry( 1,1, centralWidget()->width()-2,
1247 centralWidget()->height()-2 );
1252 Terminates the application.
1254 void QAD_Desktop::onExit()
1259 /************************************************************************
1261 *************************************************************************/
1265 If several application are supported it displays dialog window
1266 to choose type of study.
1268 void QAD_Desktop::createStudy(){
1271 void QAD_Desktop::onNewStudy()
1273 unsigned numApps = myApps.count();
1276 onNewStudy ( myApps.at(0) );
1277 else { /* select the type of application for new study */
1278 Desktop_AppSelectionDlg selDlg( this, myApps );
1279 if ( selDlg.exec() == QDialog::Accepted ) {
1280 onNewStudy ( selDlg.selectedApp() );
1283 } else { /* no applications available in desktop */
1284 QAD_MessageBox::error1( this,
1286 tr("ERR_APP_NOAPP"),
1292 Creates new study for the given application.
1293 Calls the respective function of the application class.
1295 void QAD_Desktop::onNewStudy( QAD_Application* app )
1299 /* create new study of the specific app */
1300 putInfo ( tr ("INF_DOC_CREATING") );
1301 QAD_Study* newStudy = app->newStudy();
1304 /* can't create new study */
1305 QAD_MessageBox::error1( this, tr("ERR_ERROR"),
1306 tr("ERR_DOC_CANTCREATE"),
1309 putInfo ( tr("INF_READY") );
1313 Loads the existing study.
1315 void QAD_Desktop::onLoadStudy()
1317 QString name, studyname, ext;
1319 SALOMEGUI_LoadStudiesDlg* aDlg = new SALOMEGUI_LoadStudiesDlg( this, "Load Study", TRUE);
1321 CORBA::Object_var obj = myNameService->Resolve("/myStudyManager");
1322 SALOMEDS::StudyManager_var myStudyMgr = SALOMEDS::StudyManager::_narrow(obj);
1323 ASSERT(! CORBA::is_nil(myStudyMgr));
1324 SALOMEDS::ListOfOpenStudies_var List = myStudyMgr->GetOpenStudies();
1325 for (unsigned int ind = 0; ind < List->length();ind++) {
1326 studyname = List[ind];
1327 aDlg->ListComponent->insertItem( studyname );
1330 int retVal = aDlg->exec();
1331 studyname = aDlg->ListComponent->currentText();
1333 if (retVal == QDialog::Rejected)
1336 if ( studyname.isNull() || studyname.isEmpty() )
1340 name.replace( QRegExp(":"), "/" );
1343 Try to associate an application to the opened study.
1344 Assumed that the association study<->application is unique.
1346 bool appFound = false;
1347 putInfo ( tr("INF_DOC_OPENING") + " " + name );
1348 for ( QAD_Application* app = myApps.first(); app; app = myApps.next() )
1350 /* application found */
1351 if ( app->isStudyOpened( name ) )
1353 /* already opened: prompt for reopen */
1354 if ( QAD_MessageBox::warn2 ( this, tr("WRN_WARNING"),
1355 tr("QUE_DOC_ALREADYOPEN").arg( name ),
1356 tr ("BUT_YES"), tr ("BUT_NO"), QAD_YES, QAD_NO,
1357 QAD_NO ) == QAD_NO )
1359 putInfo ( tr("INF_READY") );
1362 /* now the study is closed to be re-opened */
1363 //don't ask user to remove study permanently
1364 if (app->getStudyByName ( name ) != NULL)
1365 onCloseStudy ( app->getStudyByName ( name ), false );
1366 else if (app->getStudyByName ( QAD_Tools::getFileNameFromPath( name, false )) != NULL)
1367 onCloseStudy ( app->getStudyByName ( QAD_Tools::getFileNameFromPath( name, false )), false );
1371 /* open the study */
1372 QAD_Study* openStudy = app->loadStudy( studyname );
1374 QAD_MessageBox::error1( this,
1376 tr("ERR_DOC_CANTOPEN") + "\n" + name,
1383 QAD_MessageBox::error1( this,
1385 tr("ERR_DOC_UNKNOWNTYPE"),
1388 putInfo ( tr("INF_READY") );
1392 Opens the existing study.
1393 Displays select file dialog and calls corresponding function of
1395 (application is defined according to extension of selected file).
1397 void QAD_Desktop::onOpenStudy()
1401 /* Select a file to open */
1402 name = selectFileName ( true );
1403 if ( name.isNull() || name.isEmpty() )
1406 // Workaround for non-existent files
1408 if (!fi.exists() || !fi.isFile()) {
1409 QAD_MessageBox::error1 ( this, tr("ERR_ERROR"),
1410 tr("ERR_DOC_CANTOPEN") +": " + name,
1415 CORBA::Object_var obj = myNameService->Resolve("/myStudyManager");
1416 SALOMEDS::StudyManager_var myStudyMgr = SALOMEDS::StudyManager::_narrow(obj);
1417 ASSERT(! CORBA::is_nil(myStudyMgr));
1418 SALOMEDS::ListOfOpenStudies_var List = myStudyMgr->GetOpenStudies();
1419 for (unsigned int ind = 0; ind < List->length();ind++) {
1420 QString NameExistingStudy(List[ind]);
1421 QString NameOpeningStudy = QAD_Tools::getFileNameFromPath( name, false );
1423 if ( NameExistingStudy.compare( NameOpeningStudy ) == 0 ) {
1424 if ( QAD_MessageBox::warn2 ( this, tr("WRN_WARNING"),
1425 tr("QUE_DOC_ALREADYEXIST").arg( name ),
1426 tr ("BUT_YES"), tr ("BUT_NO"), QAD_YES, QAD_NO,
1427 QAD_NO ) == QAD_NO )
1429 putInfo ( tr("INF_READY") );
1441 Try to associate an application to the opened study.
1442 Assumed that the association study<->application is unique.
1444 bool appFound = false;
1445 putInfo ( tr("INF_DOC_OPENING") + " " + name );
1446 for ( QAD_Application* app = myApps.first(); app; app = myApps.next() )
1448 QString ext = QAD_Tools::getFileExtensionFromPath ( name );
1449 if ( app->getStudyExtension() == ext )
1451 /* application found */
1452 if ( app->isStudyOpened( name ) )
1454 /* already opened: prompt for reopen */
1455 if ( QAD_MessageBox::warn2 ( this, tr("WRN_WARNING"),
1456 tr("QUE_DOC_ALREADYOPEN").arg( name ),
1457 tr ("BUT_YES"), tr ("BUT_NO"), QAD_YES, QAD_NO,
1458 QAD_NO ) == QAD_NO )
1460 putInfo ( tr("INF_READY") );
1463 /* now the study is closed to be re-opened */
1464 //don't ask user to remove study permanently
1465 if (app->getStudyByName ( name ) != NULL)
1466 onCloseStudy ( app->getStudyByName ( name ), false );
1467 else if (app->getStudyByName ( QAD_Tools::getFileNameFromPath( name, false )) != NULL)
1468 onCloseStudy ( app->getStudyByName ( QAD_Tools::getFileNameFromPath( name, false )), false );
1472 /* open the study */
1473 QAD_Study* openStudy = app->openStudy( name );
1475 QAD_MessageBox::error1( this,
1477 tr("ERR_DOC_CANTOPEN") + "\n" + name,
1479 } else if (myActiveComp != "") {
1480 QApplication::setOverrideCursor( Qt::waitCursor );
1481 loadComponentData(mapComponentName[myActiveComp]);
1482 openStudy->updateObjBrowser(true);
1483 QApplication::restoreOverrideCursor();
1491 QAD_MessageBox::error1( this,
1493 tr("ERR_DOC_UNKNOWNTYPE"),
1496 putInfo ( tr("INF_READY") );
1499 bool QAD_Desktop::loadComponentData( const QString& compName )
1501 // Open component's data in active study if any
1502 MESSAGE("loadComponentData(): Opening " << compName << " component data ")
1503 if (!myActiveStudy) {
1504 MESSAGE("loadComponentData(): No active study exists")
1508 Engines::Component_var comp ;
1509 if ( compName.compare("SUPERV") == 0 ) {
1510 comp = getEngine( "SuperVisionContainer", compName) ;
1513 /* comp = ( compName.compare("Data1") != 0 ) ? getEngine( "FactoryServer", compName) :
1514 getEngine( "FactoryServerPy", compName);
1516 comp = getEngine( "FactoryServer", compName);
1517 if ( comp->_is_nil() )
1518 comp = getEngine( "FactoryServerPy", compName);
1521 SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
1522 SALOMEDS::SComponent_var SCO = SALOMEDS::SComponent::_narrow(aStudy->FindObject( getComponentUserName(compName) ));
1524 if (!SCO->_is_nil()) {
1525 if (!CORBA::is_nil(comp)) {
1526 SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
1527 if (!CORBA::is_nil(driver)) {
1528 SALOMEDS::StudyBuilder_var B = aStudy->NewBuilder();
1529 if (!CORBA::is_nil(B)) {
1530 QAD_Operation* op = new QAD_Operation( myActiveStudy );
1532 B->LoadWith(SCO,driver);
1538 MESSAGE("loadComponentData(): Driver is null");
1542 MESSAGE("loadComponentData(): Engine is null");
1546 MESSAGE("loadComponentData(): SComponent is null");
1554 Saves the active study
1556 bool QAD_Desktop::onSaveStudy()
1558 return onSaveStudy ( myActiveStudy );
1562 Saves the given study
1564 bool QAD_Desktop::onSaveStudy( QAD_Study* study )
1566 if ( !study ) return true;
1568 if ( !study->isSaved() )
1569 return onSaveAsStudy ( study );
1571 /* saving study... */
1572 QAD_Application* app = study->getApp();
1573 QAD_ASSERT_DEBUG_ONLY ( app );
1574 putInfo ( tr("INF_DOC_SAVING") + study->getTitle() );
1575 if ( !app->saveStudy( study ) )
1577 putInfo( tr("INF_CANCELLED") );
1582 putInfo ( tr("INF_DOC_SAVED").arg( "" ) );
1587 Saves the active study under a new name
1589 bool QAD_Desktop::onSaveAsStudy()
1591 return onSaveAsStudy( myActiveStudy );
1595 Saves the given study under a new name
1597 bool QAD_Desktop::onSaveAsStudy( QAD_Study* study )
1599 if ( !study ) return true;
1601 /* Save study in a format supported by its application
1603 QAD_Application* app = study->getApp();
1604 QAD_ASSERT_DEBUG_ONLY ( app );
1606 /* Select a file where to save
1608 QString name = selectFileName ( false );
1609 if ( name.isNull() || name.isEmpty() )
1611 putInfo( tr("INF_CANCELLED") );
1617 putInfo ( tr("INF_DOC_SAVING") + name );
1618 if ( !app->saveAsStudy( study, name ) ) {
1619 /* can't save the file */
1620 QAD_MessageBox::error1( this,
1622 tr("ERR_DOC_CANTWRITE") + "\n" + name,
1625 return false; /* cannot save */
1627 putInfo ( tr("INF_DOC_SAVED").arg( name ) );
1628 return true; /* saved ok */
1632 Closes the active study
1634 bool QAD_Desktop::onCloseStudy()
1636 bool close = this->onCloseStudy ( myActiveStudy, true );
1637 if ( close && !myXmlHandler->myIdList.IsEmpty() ) {
1640 myCombo->setCurrentItem (0);
1641 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
1642 aButton->setOn(false);
1649 Closes the given study and ask user to remove study
1650 from the study manager permanently
1652 bool QAD_Desktop::onCloseStudy( QAD_Study* study )
1654 return onCloseStudy( study, true );
1658 Closes the given study and ask user to remove study
1659 from the study manager permanently if ask is equal true
1661 bool QAD_Desktop::onCloseStudy( QAD_Study* study, bool ask )
1663 bool removePerm = false;
1667 SALOMEGUI_CloseDlg aDlg( this );
1668 int res = aDlg.exec();
1673 //if ( study->isModified() )
1674 if ( !onSaveStudy( study ) ) {
1675 putInfo( tr("INF_CANCELLED") );
1688 putInfo( tr("INF_CANCELLED") );
1692 /* close active component */
1693 if (!myXmlHandler->myIdList.IsEmpty())
1697 myCombo->setCurrentItem (0);
1698 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() )
1699 aButton->setOn(false);
1700 qApp->processEvents();
1702 /* close the study */
1703 return study->getApp()->closeStudy( study, removePerm );
1706 // Displays study properties dialog box
1707 void QAD_Desktop::onStudyProperties()
1709 if (myActiveStudy) {
1711 QAD_Operation* op = new QAD_Operation( myActiveStudy );
1714 SALOMEGUI_StudyPropertiesDlg aDlg(this);
1715 int res = aDlg.exec();
1717 if ( res == QDialog::Accepted && aDlg.isChanged() )
1722 // T2.12 - add the word "locked" to study frame captions if <myActiveStudy> study is locked
1723 myActiveStudy->updateCaptions();
1729 locate all windows in cascade mode
1732 void QAD_Desktop::onCascade()
1734 myWorkspace->cascade();
1735 int w = myWorkspace->width();
1736 int h = myWorkspace->height();
1737 QWidgetList wList = myWorkspace->windowList();
1738 QWidgetListIt it(wList);
1740 for(;it.current(); ++it)
1741 it.current()->resize(0.8*w, 0.8*h);
1745 called when help window closed
1747 void QAD_Desktop::onHelpWindowClosed()
1753 Called when 'view status bar' option
1756 void QAD_Desktop::onViewStatusBar()
1758 bool show = myStdActions.at( ViewStatusBarId )->isOn();
1759 if ( show == myStatusBar->isVisible() )
1762 myStatusBar->show();
1764 myStatusBar->hide();
1768 Called when View/Toolbars popup menu is about to show
1770 void QAD_Desktop::onToolBarPopupAboutToShow()
1772 myToolBarAction.clear();
1773 myToolBarsPopup.clear();
1774 QPtrList<QDockWindow> wlist = dockWindows();
1775 for ( QDockWindow* w = wlist.first(); w; w = wlist.next() ) {
1776 if ( w->inherits( "QToolBar" ) ) {
1777 QToolBar* tb = ( QToolBar* )w;
1778 if ( appropriate( tb ) ) {
1779 ToggleAction* a = new ToggleAction( tb->label(), tb->label(), 0, this, 0, true );
1780 a->setStatusTip ( tr("PRP_DESK_VIEW_TOOLBAR") );
1781 a->setOn( tb->isVisible() );
1782 QAD_ASSERT( connect( a, SIGNAL( toggledOn() ), tb, SLOT( show() ) ) );
1783 QAD_ASSERT( connect( a, SIGNAL( toggledOff() ), tb, SLOT( hide() ) ) );
1784 a->addTo( &myToolBarsPopup );
1785 myToolBarAction.append( a );
1792 Called on 'View\Selection Mode'
1794 void QAD_Desktop::onSelectionMode()
1796 const QAction* obj = (QAction*) sender();
1798 int SelectionMode = 4;
1800 if ( obj == myStdActions.at(SelectionActorId) ) {
1802 if ( obj->isOn() ) {
1803 myStdActions.at(SelectionCellId)->setOn(false);
1804 myStdActions.at(SelectionEdgeId)->setOn(false);
1805 myStdActions.at(SelectionPointId)->setOn(false);
1807 myStdActions.at(SelectionActorId)->setOn(true);
1809 } else if ( obj == myStdActions.at(SelectionCellId) ) {
1811 if ( obj->isOn() ) {
1812 myStdActions.at(SelectionActorId)->setOn(false);
1813 myStdActions.at(SelectionEdgeId)->setOn(false);
1814 myStdActions.at(SelectionPointId)->setOn(false);
1816 myStdActions.at(SelectionActorId)->setOn(true);
1818 } else if ( obj == myStdActions.at(SelectionEdgeId) ) {
1820 if ( obj->isOn() ) {
1821 myStdActions.at(SelectionActorId)->setOn(false);
1822 myStdActions.at(SelectionCellId)->setOn(false);
1823 myStdActions.at(SelectionPointId)->setOn(false);
1825 myStdActions.at(SelectionActorId)->setOn(true);
1827 } else if ( obj == myStdActions.at(SelectionPointId) ) {
1829 if ( obj->isOn() ) {
1830 myStdActions.at(SelectionEdgeId)->setOn(false);
1831 myStdActions.at(SelectionCellId)->setOn(false);
1832 myStdActions.at(SelectionActorId)->setOn(false);
1834 myStdActions.at(SelectionActorId)->setOn(true);
1837 QAD_StudyFrame* sf = myActiveApp->getActiveStudy()->getActiveStudyFrame();
1838 sf->getRightFrame()->getViewFrame()->SetSelectionMode( SelectionMode );
1840 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveApp->getActiveStudy()->getSelection() );
1841 Sel->SetSelectionMode( SelectionMode );
1845 Called on 'View\Selection Mode'
1847 void QAD_Desktop::SetSelectionMode(int mode, bool activeCompOnly)
1852 myStdActions.at(SelectionEdgeId)->setOn(false);
1853 myStdActions.at(SelectionCellId)->setOn(false);
1854 myStdActions.at(SelectionActorId)->setOn(false);
1855 myStdActions.at(SelectionPointId)->setOn(true);
1860 myStdActions.at(SelectionActorId)->setOn(false);
1861 myStdActions.at(SelectionCellId)->setOn(false);
1862 myStdActions.at(SelectionPointId)->setOn(false);
1863 myStdActions.at(SelectionEdgeId)->setOn(true);
1868 myStdActions.at(SelectionActorId)->setOn(false);
1869 myStdActions.at(SelectionEdgeId)->setOn(false);
1870 myStdActions.at(SelectionPointId)->setOn(false);
1871 myStdActions.at(SelectionCellId)->setOn(true);
1876 myStdActions.at(SelectionCellId)->setOn(false);
1877 myStdActions.at(SelectionEdgeId)->setOn(false);
1878 myStdActions.at(SelectionPointId)->setOn(false);
1879 myStdActions.at(SelectionActorId)->setOn(true);
1884 QAD_StudyFrame* sf = myActiveApp->getActiveStudy()->getActiveStudyFrame();
1885 if ( sf->getTypeView() == VIEW_VTK ) {
1886 sf->getRightFrame()->getViewFrame()->SetSelectionMode( mode );
1887 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveApp->getActiveStudy()->getSelection() );
1888 Sel->SetSelectionMode( mode, activeCompOnly );
1894 Called on 'Window\NewWindow3d'
1896 void QAD_Desktop::onNewWindow3d()
1900 //VRV: T2.5 - add default viewer
1901 QApplication::restoreOverrideCursor();
1902 SALOMEGUI_ViewChoiceDlg *choice = new SALOMEGUI_ViewChoiceDlg(this, "", TRUE);
1903 int r = choice->exec();
1906 myActiveApp->getActiveStudy()->newWindow3d(QString(""),(ViewType)(choice->getSelectedViewer()));
1908 //VRV: T2.5 - add default viewer
1910 const QAction* obj = (QAction*) sender();
1911 if ( obj == myStdActions.at(ViewOCCId) ) {
1912 myActiveApp->getActiveStudy()->newWindow3d(QString(""),(ViewType)(0));
1913 } else if ( obj == myStdActions.at(ViewVTKId) ) {
1914 myActiveApp->getActiveStudy()->newWindow3d(QString(""),(ViewType)(1));
1915 } else if ( obj == myStdActions.at(ViewPlot2dId) ) {
1916 myActiveApp->getActiveStudy()->newWindow3d(QString(""),(ViewType)(3));
1922 Called on 'help\contents'
1924 void QAD_Desktop::onHelpContents()
1927 myActiveApp->helpContents();
1933 Called on 'help\search'
1935 void QAD_Desktop::onHelpSearch()
1938 myActiveApp->helpSearch();
1944 Called on 'help\about'
1946 void QAD_Desktop::onHelpAbout()
1949 myActiveApp->helpAbout();
1956 Activates the application and its active study
1958 void QAD_Desktop::onActivateApp( QAD_Application* activeApp )
1960 bool appChanged = ( activeApp != myActiveApp );
1963 updateDesktop( DeactivateApp );
1967 myActiveApp = activeApp;
1968 myActiveStudy = myActiveApp->getActiveStudy();
1978 updateDesktop( ActivateApp );
1979 updateCaption( (activeApp != NULL) ? ActivateApp : DeactivateApp );
1985 Called when the last study is removed from
1986 the application 'app'.
1988 void QAD_Desktop::onDeactivateApp(QAD_Application* app)
1990 if ( app && app == myActiveApp )
1995 Enables/disables standard actions
1997 void QAD_Desktop::updateActions()
1999 myStdActions.at( FileCloseId )->setEnabled ( myActiveStudy != NULL );
2000 myStdActions.at( FileSaveId )->setEnabled ( myActiveStudy != NULL );
2001 myStdActions.at( FileSaveAsId )->setEnabled ( myActiveStudy != NULL );
2002 myStdActions.at( FilePropsId )->setEnabled( myActiveStudy != NULL );
2003 // myStdActions.at( HelpContentsId )->setEnabled ( myActiveApp != NULL );
2004 // myStdActions.at( HelpSearchId )->setEnabled ( myActiveApp != NULL );
2005 // myStdActions.at( HelpWhatsThisId )->setEnabled ( myActiveApp != NULL );
2006 // myStdActions.at( HelpAboutId )->setEnabled ( myActiveApp != NULL );
2008 // myToolsPopup.setEnabled ( myActiveStudy != NULL );
2009 // myPrefPopup.setEnabled ( myActiveStudy != NULL );
2011 mySelectionModePopup.setEnabled ( myActiveStudy != NULL );
2015 Called when 'Window' popup is about to show
2017 void QAD_Desktop::onWindowPopupAboutToShow()
2019 /* add cascade/tile items */
2020 myWindowPopup.clear();
2023 //myStdActions.at( WindowNew3dId )->addTo( &myWindowPopup );
2024 myWindowPopup.insertItem( tr("MEN_DESK_WINDOW_NEW3D"), &myNewViewPopup, WindowNew3dId );
2025 //myStdActions.at( WindowNew3dId )->setEnabled( true );
2026 myWindowPopup.setItemEnabled( WindowNew3dId, true );
2028 myStdActions.at( WindowCascadeId )->addTo( &myWindowPopup );
2029 myStdActions.at( WindowCascadeId )->setEnabled( true );
2030 myStdActions.at( WindowTileId )->addTo( &myWindowPopup );
2031 myStdActions.at( WindowTileId )->setEnabled( true );
2033 /* add names of opened studies */
2034 QWidgetList windows = myWorkspace->windowList();
2035 if ( windows.isEmpty() )
2037 //NRI : SAL2214 myStdActions.at( WindowNew3dId )->setEnabled( false );
2038 myWindowPopup.setItemEnabled( WindowNew3dId, false );
2040 myStdActions.at( WindowCascadeId )->setEnabled( false );
2041 myStdActions.at( WindowTileId )->setEnabled( false );
2045 myWindowPopup.insertSeparator();
2046 for ( int i = 0; i < int(windows.count()); ++i )
2048 int id = myWindowPopup.insertItem( windows.at(i)->caption(),
2049 this, SLOT( onWindowsPopupActivated( int ) ) );
2050 myWindowPopup.setItemParameter( id, i );
2051 myWindowPopup.setItemChecked( id, myWorkspace->activeWindow() == windows.at(i) );
2053 QAD_ASSERT( connect( &myWindowPopup, SIGNAL(highlighted( int )), this,
2054 SLOT(onWindowsPopupStatusText( int )) ));
2059 Called when the item with 'id' of 'Windows' popup
2062 void QAD_Desktop::onWindowsPopupStatusText( int id )
2064 int cascadeId = myWindowPopup.idAt( 0 );
2065 int tileId = myWindowPopup.idAt( 1 );
2066 if ( id == cascadeId || id == tileId )
2068 putInfo( tr("PRP_DESK_WINDOW_ACTIVATE") );
2072 Called when user wants to activate a child window with 'wid'
2075 void QAD_Desktop::onWindowsPopupActivated( int wid )
2077 QWidget* w = myWorkspace->windowList().at( wid );
2078 if ( w ) w->setFocus();
2082 Selects a file name when opening or saving files.
2083 The basic implementation just uses the standard
2085 Please redefine if another behaviour is required.
2087 QString QAD_Desktop::selectFileName ( bool open )
2089 QAD_FileDlg* fd = new QAD_FileDlg( this, open, true, true );
2093 QStringList filters;
2096 // All the file types of the supported applications
2098 for ( QAD_Application* app = myApps.first(); app; app = myApps.next() )
2100 filters += app->getStudyDescription() + " " + tr("DESK_FILES") + " " +
2101 "(*." + app->getStudyExtension() + ")";
2105 QAD_ASSERT_DEBUG_ONLY ( myActiveStudy );
2106 if (myActiveStudy) {
2107 // get file name of active study
2108 name = QAD_Tools::getFileNameFromPath ( myActiveStudy->getTitle() );
2109 // get path to the active study file
2110 dir = QAD_Tools::getDirFromPath ( myActiveStudy->getPath(), false );
2112 QAD_ASSERT_DEBUG_ONLY ( !name.isNull() );
2113 // the file types supported by the active application
2114 filters += myActiveApp->getStudyDescription() + " " + tr("DESK_FILES") + " " +
2115 "(*." + myActiveApp->getStudyExtension() + ")" ;
2117 if (!dir.isEmpty()) {
2118 // when saving document ("Save As" command) - to get dir from active study filename
2119 // for new documents - to use last opened directory
2122 fd->setSelection( name );
2123 fd->setFilters( filters );
2126 QString filename = fd->selectedFile();
2128 qApp->processEvents();
2133 Closes all the studies of 'app'. Returns
2134 'true' if thay are closed OK, 'false' at least
2135 one can't be closed or user cancel the closure.
2137 bool QAD_Desktop::closeAllStudies( QAD_Application* app )
2139 QList<QAD_Study>& studies = app->getStudies();
2140 while ( !studies.isEmpty() )
2142 //don't ask user to remove study permanently
2143 if ( !onCloseStudy( studies.at(0), false ) )
2144 return false; /* user cancelled closing */
2150 Called on Popup item when SComponent representation in Object Browser is selected.
2152 void QAD_Desktop::onOpenWith()
2154 Engines::Component_var comp;
2155 QString ComponentSelected;
2157 SALOMEDS::SObject_var SO;
2158 SALOMEDS::SComponent_var SCO;
2159 SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
2160 SALOMEDS::GenericAttribute_var anAttr;
2161 SALOMEDS::AttributeName_var aName;
2163 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2164 if ( Sel->IObjectCount() == 1 ) {
2165 Handle(SALOME_InteractiveObject) IO = Sel->firstIObject();
2166 SO = aStudy->FindObjectID( IO->getEntry() );
2167 SCO = SO->GetFatherComponent();
2169 if (SCO->FindAttribute(anAttr, "AttributeName")) {
2170 aName = SALOMEDS::AttributeName::_narrow(anAttr);
2171 name = aName->Value();
2172 SALOME_ModuleCatalog::Acomponent_var Comp = myCatalogue->GetComponent( mapComponentName[name] );
2173 if ( !Comp->_is_nil() ) {
2175 SALOME_ModuleCatalog::ListOfComponents_var list_type_composants =
2176 myCatalogue->GetTypedComponentList( Comp->component_type() );
2178 if ( list_type_composants->length() == 1 ) {
2179 ComponentSelected = name;
2180 } else if ( list_type_composants->length() > 1 ) {
2181 SALOMEGUI_OpenWith* aDlg = new SALOMEGUI_OpenWith( this );
2182 for (unsigned int ind = 0; ind < list_type_composants->length();ind++) {
2183 aDlg->addComponent( strdup(list_type_composants[ind]) );
2186 int retVal = aDlg->exec();
2187 ComponentSelected = aDlg->getComponent();
2189 if ( retVal == QDialog::Rejected || ComponentSelected.isEmpty()) {
2193 MESSAGE( "No component with type : " << Comp->component_type() << " exists" );
2198 MESSAGE( "This component not exists in the catalog" );
2202 QApplication::setOverrideCursor( Qt::waitCursor );
2203 Sel->ClearIObjects();
2205 // if (loadComponentData(ComponentSelected)) {
2206 onComboActiveComponent(ComponentSelected);
2207 // int nbItem = myCombo->count();
2209 // for (int i = 0; i < nbItem; i++) {
2210 // if (myCombo->text(i).compare(ComponentSelected)==0) {
2215 // myCombo->setCurrentItem(Index);
2216 // myActiveStudy->updateObjBrowser(true);
2220 QApplication::restoreOverrideCursor();
2223 typedef bool OneDim1(QAD_Desktop*);
2224 typedef bool OneDim2(QAD_Desktop*, char*);
2227 Called to define settings of component.
2229 void QAD_Desktop::setSettings()
2231 if (!myActiveComp.isEmpty()) {
2232 OSD_Function osdF = mySharedLibrary.DlSymb("SetSettings");
2236 OneDim1 (*f1) = (bool (*) (QAD_Desktop*)) osdF;
2241 QString Component =mapComponentName[myActiveComp];
2242 OneDim2 (*f1) = (bool (*) (QAD_Desktop*, char*)) osdF;
2243 (*f1)(this, (char*)Component.latin1());
2249 Called to load Component : xml resources and GUI librairy.
2251 bool QAD_Desktop::loadComponent(QString Component)
2254 QString resDir("/"); //NRI : Pb under Windows
2256 QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
2259 if (!resMgr->loadResources( Component, msg ))
2261 //NRI QCString errMsg;
2262 // errMsg.sprintf( "Do not load all resources for module %sGUI.\n" ,
2263 // Component.latin1() );
2265 QMessageBox::warning( this, tr("WRN_WARNING"), msg, tr ("BUT_OK") );
2270 /* Parse xml file */
2271 myXmlHandler = new QAD_XmlHandler();
2272 myXmlHandler->setMainWindow(this);
2273 if (!myXmlHandler->setComponent(resMgr->resources( Component ))) return false;
2275 QString language = resMgr->language( Component );
2277 QString ComponentXml = Component + "_" + language + ".xml";
2278 //ComponentXml = resMgr->resources(Component + "GUI") ;
2279 //ComponentXml = QAD_Tools::addSlash(ComponentXml) ;
2280 ComponentXml = QAD_Tools::addSlash( resMgr->findFile( ComponentXml, Component ) ) + ComponentXml;
2281 QFile file( ComponentXml );
2283 if ( !file.exists() || !file.open( IO_ReadOnly ) ) {
2285 errMsg.sprintf( "Cannot open xml file: %s\n.",
2286 (file.name()).latin1() );
2288 QMessageBox::critical( this, tr("ERR_ERROR"), errMsg, tr ("BUT_OK") );
2293 QXmlInputSource source( file );
2294 QXmlSimpleReader reader;
2295 reader.setContentHandler( myXmlHandler );
2296 reader.setErrorHandler( myXmlHandler );
2297 bool ok = reader.parse( source );
2301 QMessageBox::critical( this,
2302 tr( "INF_PARSE_ERROR" ),
2303 tr( myXmlHandler->errorProtocol() ) );
2307 myMenusList=myXmlHandler->myMenusList;
2308 myActiveMenus=myMenusList.at(0);
2309 myOperatorMenus->showMenuBar(0);
2310 myActiveMenus->showAllToolBars();
2312 /* Components toolbars */
2315 nbToolbars = myActiveMenus->getToolBarList().count();
2316 /* Open Shared Library */
2317 mySharedLibrary = OSD_SharedLibrary();
2320 QString ComponentLib;
2322 QFileInfo fileInfo ;
2323 QString fileString ;
2326 if ( libs = getenv("LD_LIBRARY_PATH")) {
2327 // MESSAGE ( " LD_LIBRARY_PATH : " << libs );
2328 QStringList dirList = QStringList::split( SEPARATOR, libs, false ); // skip empty entries
2329 for ( int i = dirList.count()-1; i >= 0; i-- ) {
2332 fileString = QAD_Tools::addSlash( dir ) + "lib" + Component + "GUI.dll" ;
2334 fileString = QAD_Tools::addSlash( dir ) + "lib" + Component + "GUI.so" ;
2337 fileInfo.setFile(fileString) ;
2338 if (fileInfo.exists()) {
2339 // MESSAGE ( " GUI library = " << fileString );
2340 ComponentLib = fileInfo.fileName() ;
2347 if (!_islibso) // component GUI could be in PyQt, use generic library
2349 MESSAGE("GUI library not found, trying generic library for PyQt GUI");
2351 if (dir = getenv("KERNEL_ROOT_DIR"))
2353 dir = QAD_Tools::addSlash(dir) ;
2355 dir = QAD_Tools::addSlash(dir) ;
2356 dir = dir + "salome" ;
2357 dir = QAD_Tools::addSlash(dir) ;
2359 dir = dir + "libSalomePyQtcmodule.dll" ;
2361 dir = dir + "libSalomePyQtcmodule.so" ;
2363 MESSAGE ( " GUI library = " << dir );
2364 fileInfo.setFile(dir) ;
2365 if (fileInfo.exists())
2367 ComponentLib = fileInfo.fileName() ;
2373 QMessageBox::critical( this,
2375 tr("ERR_LIBGUI" ).arg(Component) );
2380 mySharedLibrary.SetName(TCollection_AsciiString((char*)ComponentLib.latin1()).ToCString());
2381 ok = mySharedLibrary.DlOpen(OSD_RTLD_LAZY);
2384 QMessageBox::critical( this,
2386 tr( mySharedLibrary.DlError() ) );
2391 OSD_Function osdF = mySharedLibrary.DlSymb("SetSettings");
2395 OneDim1 (*f1) = (bool (*) (QAD_Desktop*)) osdF;
2400 OneDim2 (*f1) = (bool (*) (QAD_Desktop*, char*)) osdF;
2401 (*f1)(this, (char*)Component.latin1());
2406 /* COMPONENT INTERFACE */
2407 SALOME_ModuleCatalog::Acomponent_ptr aComponent =
2408 myCatalogue->GetComponent(Component.latin1());
2410 if (CORBA::is_nil (aComponent)) {
2411 MESSAGE( "Catalog Error : Component not found in the catalog" )
2415 myActiveStudy->setMessage(QString("Component : ") +
2416 aComponent->componentusername() + " created " );
2417 myActiveStudy->setMessage(QString("Type : ") +
2418 QString::number(aComponent->component_type()));
2419 myActiveStudy->setMessage(QString("Constraint : ") +
2420 aComponent->constraint() );
2422 /* obtain interfaces list of the component */
2423 SALOME_ModuleCatalog::ListOfInterfaces_var _list =
2424 new SALOME_ModuleCatalog::ListOfInterfaces;
2425 _list = aComponent->GetInterfaceList();
2427 if (_list->length() != 0 ) {
2429 for (unsigned int ind = 0; ind < _list->length();ind++)
2430 myActiveStudy->setMessage( QString("Interface name : ") +
2434 /* obtain services list of the component */
2435 SALOME_ModuleCatalog::ListOfServices_var list_services_component =
2436 new SALOME_ModuleCatalog::ListOfServices;
2437 list_services_component = aComponent->GetServiceList(_list[0]);
2439 if (list_services_component->length() != 0 ) {
2441 for (unsigned int ind = 0; ind < list_services_component->length();ind++)
2442 myActiveStudy->setMessage( QString("Service name : ") +
2443 list_services_component[ind] );
2445 // Get a service of the component
2446 SALOME_ModuleCatalog::Service_var service = new SALOME_ModuleCatalog::Service;
2447 service = aComponent->GetService(_list[0],list_services_component[0]) ;
2448 myActiveStudy->setMessage( QString("Service name: ") + service->ServiceName);
2449 for (unsigned int ind1 = 0; ind1 <service->ServiceinParameter.length();ind1++) {
2450 myActiveStudy->setMessage( QString("Type of the in Parameter of this service : ") +
2451 (const char *) service->ServiceinParameter[ind1].Parametertype);
2452 myActiveStudy->setMessage( QString("Name of the in Parameter of this service : ") +
2453 (const char *) service->ServiceinParameter[ind1].Parametername);
2455 for (unsigned int ind1 = 0; ind1 <service->ServiceoutParameter.length();ind1++) {
2456 myActiveStudy->setMessage( QString("Type of the out Parameter of this service : ") +
2457 (const char *) service->ServiceoutParameter[ind1].Parametertype);
2458 myActiveStudy->setMessage( QString("Name of the out Parameter of this service : ") +
2459 (const char *) service->ServiceoutParameter[ind1].Parametername);
2466 typedef bool OneDim(int, QAD_Desktop*);
2467 typedef void (*PTR_FACTORY_FUNCTION)( CORBA::ORB_var &orb, QWidget *parent, const char *name ) ;
2471 void QAD_Desktop::onDispatch()
2473 const QObject* obj = sender();
2475 QList<QAD_ListMenuIdAction> MenuList = myActiveMenus->getMenuList();
2476 QAD_ListMenuIdAction* aMenu;
2478 for(aMenu=MenuList.first();aMenu!=NULL;aMenu=MenuList.next()) {
2479 if (aMenu->getAction()==obj) {
2480 id = aMenu->getId();
2489 void QAD_Desktop::onDispatchTools(int id)
2491 /* Open Shared Library */
2492 OSD_SharedLibrary ToolsLibrary = OSD_SharedLibrary();
2496 QFileInfo fileInfo ;
2500 bool libToolsGUI = true;
2501 if( QAD_XmlHandler::_bibmap[ id ].isEmpty() )
2504 if ( dir = getenv("SALOME_SITE_DIR")) {
2505 dir = QAD_Tools::addSlash(dir) ;
2507 dir = QAD_Tools::addSlash(dir) ;
2508 dir = dir + "salome" ;
2509 dir = QAD_Tools::addSlash(dir) ;
2511 dir = dir + "libToolsGUI.dll" ;
2513 dir = dir + "libToolsGUI.so" ;
2515 MESSAGE ( " GUI library = " << dir );
2516 fileInfo.setFile(dir) ;
2517 if (fileInfo.exists()) {
2518 ToolsLib = fileInfo.fileName() ;
2523 if ( (dir = getenv("SALOME_ROOT_DIR")) && !found ) {
2524 dir = QAD_Tools::addSlash(dir) ;
2526 dir = QAD_Tools::addSlash(dir) ;
2527 dir = dir + "salome" ;
2528 dir = QAD_Tools::addSlash(dir) ;
2530 dir = dir + "libToolsGUI.dll" ;
2532 dir = dir + "libToolsGUI.so" ;
2534 MESSAGE ( " GUI library = " << dir );
2535 fileInfo.setFile(dir) ;
2536 if (fileInfo.exists()) {
2537 ToolsLib = fileInfo.fileName() ;
2542 if ( (dir = getenv("KERNEL_ROOT_DIR")) && !found ) {
2543 dir = QAD_Tools::addSlash(dir) ;
2545 dir = QAD_Tools::addSlash(dir) ;
2546 dir = dir + "salome" ;
2547 dir = QAD_Tools::addSlash(dir) ;
2549 dir = dir + "libToolsGUI.dll" ;
2551 dir = dir + "libToolsGUI.so" ;
2553 MESSAGE ( " GUI library = " << dir );
2554 fileInfo.setFile(dir) ;
2555 if (fileInfo.exists()) {
2556 ToolsLib = fileInfo.fileName() ;
2562 libToolsGUI = false;
2563 SCRUTE( QAD_XmlHandler::_bibmap[ id ] ) ;
2564 if ( dir = getenv("SALOME_SITE_DIR")) {
2565 dir = QAD_Tools::addSlash(dir) ;
2567 dir = QAD_Tools::addSlash(dir) ;
2568 dir = dir + "salome" ;
2569 dir = QAD_Tools::addSlash(dir) ;
2570 dir = dir + QAD_XmlHandler::_bibmap[ id ].latin1() ;
2571 MESSAGE ( " GUI library = " << dir );
2572 fileInfo.setFile(dir) ;
2573 if (fileInfo.exists()) {
2574 ToolsLib = fileInfo.fileName() ;
2579 if ( (dir = getenv("SALOME_ROOT_DIR")) && !found ) {
2580 dir = QAD_Tools::addSlash(dir) ;
2582 dir = QAD_Tools::addSlash(dir) ;
2583 dir = dir + "salome" ;
2584 dir = QAD_Tools::addSlash(dir) ;
2585 dir = dir + QAD_XmlHandler::_bibmap[ id ].latin1() ;
2586 MESSAGE ( " GUI library = " << dir );
2587 fileInfo.setFile(dir) ;
2588 if (fileInfo.exists()) {
2589 ToolsLib = fileInfo.fileName() ;
2594 if ( (dir = getenv("KERNEL_ROOT_DIR")) && !found ) {
2595 dir = QAD_Tools::addSlash(dir) ;
2597 dir = QAD_Tools::addSlash(dir) ;
2598 dir = dir + "salome" ;
2599 dir = QAD_Tools::addSlash(dir) ;
2600 dir = dir + QAD_XmlHandler::_bibmap[ id ].latin1() ;
2601 MESSAGE ( " GUI library = " << dir );
2602 fileInfo.setFile(dir) ;
2603 if (fileInfo.exists()) {
2604 ToolsLib = fileInfo.fileName() ;
2610 ToolsLibrary.SetName(TCollection_AsciiString((char*)ToolsLib.latin1()).ToCString());
2611 bool ok = ToolsLibrary.DlOpen(OSD_RTLD_LAZY);
2613 if ( libToolsGUI ) {
2614 OSD_Function osdF = ToolsLibrary.DlSymb("OnGUIEvent");
2615 OneDim (*f1) = NULL;
2616 f1 = (bool (*) (int, QAD_Desktop*)) osdF;
2619 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
2620 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
2621 CORBA::ORB_var &orb = init(0 , 0 ) ;
2622 OSD_Function osdF = ToolsLibrary.DlSymb("OnGUIEvent");
2623 PTR_FACTORY_FUNCTION f1 = NULL;
2624 f1 = (PTR_FACTORY_FUNCTION) osdF;
2625 f1(orb,0,"Registry");
2628 QMessageBox::critical( this,
2630 tr( ToolsLibrary.DlError() ) );
2636 void QAD_Desktop::onDispatch(int id)
2638 if (!myActiveComp.isEmpty()) {
2639 OSD_Function osdF = mySharedLibrary.DlSymb("OnGUIEvent");
2640 OneDim (*f1) = NULL;
2641 if ( osdF != NULL ) {
2642 f1 = (bool (*) (int, QAD_Desktop*)) osdF;
2649 Returns the component's catalogue
2651 SALOME_ModuleCatalog::ModuleCatalog_var QAD_Desktop::getCatalogue()
2658 void QAD_Desktop::onComboActiveComponent( const QString & component ){
2659 onComboActiveComponent(component,true);
2661 void QAD_Desktop::onComboActiveComponent( const QString & component, bool isLoadData)
2663 if (myActiveStudy != 0) {
2664 if (myActiveComp.compare(component)!=0) {
2665 if (!myXmlHandler->myIdList.IsEmpty()) clearMenus();
2666 if ( myCombo->currentText() != component )
2667 myCombo->setCurrentText( component );
2668 //NRI if (component.compare(QString("Salome"))!= 0) {
2669 if (component.compare( getComponentUserName( "KERNEL" ) )!= 0) {
2670 // QApplication::setOverrideCursor( Qt::waitCursor );
2671 myActiveComp = component;
2673 SALOME_Selection* oldSel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2675 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2676 if ( aButton->textLabel().compare(component)==0)
2677 aButton->setOn(true);
2679 aButton->setOn(false);
2682 myActiveStudy->Selection( component );
2683 if ( !loadComponent(mapComponentName[component]) ) {
2684 myCombo->setCurrentItem (0);
2685 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2686 aButton->setOn(false);
2691 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2692 SALOME_ListIteratorOfListIO It( oldSel->StoredIObjects() );
2693 for(;It.More();It.Next()) {
2694 int res = Sel->AddIObject( It.Value() );
2697 myActiveStudy->highlight( It.Value(), false );
2699 myActiveStudy->highlight( It.Value(), true );
2703 // Open new component's data in active study if any
2704 if(isLoadData) loadComponentData(mapComponentName[component]);
2707 myActiveStudy->updateObjBrowser(true);
2709 // QApplication::restoreOverrideCursor();
2711 } else { // component == "Salome"
2713 //NRI myActiveStudy->Selection( "Salome" );
2714 myActiveStudy->Selection( getComponentUserName( "KERNEL" ) );
2715 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2716 Sel->ClearIObjects();
2717 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2718 aButton->setOn(false);
2722 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2723 if ( aButton->textLabel().compare(component)==0)
2724 aButton->setOn(true);
2728 QMessageBox::critical( 0,
2730 tr( "WRN_LOAD_COMPONENT" ) );
2731 myCombo->setCurrentItem (0);
2732 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2733 aButton->setOn(false);
2740 void QAD_Desktop::activateComponent(const QString& theName, bool isLoadData){
2741 int nbItem = myCombo->count();
2744 for (int i = 0; i < nbItem; i++) {
2745 if (myCombo->text(i).compare(theName)==0) {
2750 myCombo->setCurrentItem (Index);
2751 onComboActiveComponent(theName,isLoadData);
2754 void QAD_Desktop::onButtonActiveComponent( )
2756 QToolButton* obj = (QToolButton*)sender();
2757 activateComponent(obj->textLabel());
2761 Clears All Resources of current component
2763 void QAD_Desktop::clearMenus()
2765 onActiveStudyChanged();
2768 myMenusList.clear();
2770 int length = myXmlHandler->myIdList.Length();
2771 for (int k=length; k>0; k--) {
2773 if ( menuBar()->findItem(myXmlHandler->myIdList.Value(k), &parent) )
2774 parent->removeItem( myXmlHandler->myIdList.Value(k) );
2779 if (myActiveMenus) {
2780 int nbtoolbars = myActiveMenus->getToolBarList().count();
2781 for (int k=0; k<nbtoolbars; k++) {
2782 myActiveMenus->getToolBarList().at(k)->hide();
2783 myActiveMenus->getToolBarList().at(k)->clear();
2785 myActiveMenus->clearToolBar();
2788 QList<QAD_ListPopupMenu> PopupList = myActiveMenus->getPopupMenuList();
2789 QAD_ListPopupMenu* aPopup;
2790 for(aPopup=PopupList.first();aPopup!=NULL;aPopup=PopupList.next()){
2791 aPopup->getPopup()->clear();
2794 myActiveMenus->clearPopupMenu();
2800 typedef bool TwoDim1(QKeyEvent* pe, QAD_Desktop*, QAD_StudyFrame*);
2802 Exports Key Events in active component ( GUI Librairy )
2804 void QAD_Desktop::onKeyPress( QKeyEvent* pe )
2806 // MESSAGE ( "QAD_Desktop::onKeyPress" )
2807 if (!myActiveComp.isEmpty()) {
2808 OSD_Function osdF = mySharedLibrary.DlSymb("OnKeyPress");
2809 if ( osdF != NULL ) {
2810 TwoDim1 (*f1) = (bool (*) (QKeyEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
2811 (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
2816 typedef bool TwoDim(QMouseEvent* pe, QAD_Desktop*, QAD_StudyFrame*);
2818 Exports Mouse Press Events in active component ( GUI Librairy )
2820 bool QAD_Desktop::onMousePress( QMouseEvent* pe )
2822 // MESSAGE ( "QAD_Desktop::onMousePress" )
2823 if (!myActiveComp.isEmpty()) {
2824 OSD_Function osdF = mySharedLibrary.DlSymb("OnMousePress");
2825 if ( osdF != NULL ) {
2826 TwoDim (*f1) = (bool (*) (QMouseEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
2827 return (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
2834 Exports Mouse Move Events in active component ( GUI Librairy )
2836 void QAD_Desktop::onMouseMove( QMouseEvent* pe )
2838 if (!myActiveComp.isEmpty()) {
2839 OSD_Function osdF = mySharedLibrary.DlSymb("OnMouseMove");
2840 if ( osdF != NULL ) {
2841 TwoDim (*f1) = (bool (*) (QMouseEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
2842 (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
2848 Returns name of active component
2850 const QString& QAD_Desktop::getActiveComponent() const
2852 return myActiveComp;
2856 typedef bool defineP( QString & theContext, QString & theParent, QString & theObject);
2858 void QAD_Desktop::definePopup(QString & theContext,
2859 QString & theParent,
2860 QString & theObject )
2862 if (!myActiveComp.isEmpty()) {
2863 OSD_Function osdF = mySharedLibrary.DlSymb("definePopup");
2864 if ( osdF != NULL ) {
2865 defineP (*f1) = (bool (*) (QString &, QString &, QString &)) osdF;
2866 (*f1)(theContext, theParent, theObject);
2874 void QAD_Desktop::createPopup(QPopupMenu* popupFather, QPopupMenu* popup,
2875 QString text, int popupID, bool separator)
2877 QMenuItem* item = popup->findItem(popupID);
2879 QPopupMenu* popupChild = item->popup();
2881 QPopupMenu* newPopup = new QPopupMenu;
2882 int count = popupChild->count();
2883 // add items at the top of <popupFather>
2884 for (int i = count - 1; i >= 0; i--) {
2885 int j = popupChild->idAt(i);
2886 QString text = popupChild->text(j);
2887 createPopup( newPopup, popupChild, text, j);
2889 popupFather->insertItem(popup->text(popupID),
2890 newPopup, popupID, 0);
2892 if ( !text.isNull() ) {
2893 popupFather->insertItem(popup->text(popupID),
2895 SLOT( onDispatch(int) ), 0, popupID, 0);// try adding item at the top
2896 } /*else if ( separator )
2897 popupFather->insertTearOffHandle(-1, 0);*/
2899 popupFather->insertSeparator(0);
2907 void QAD_Desktop::createPopup(QPopupMenu* popup, const QString & theContext,
2908 const QString & theParent, const QString & theObject )
2910 if ( !myActiveComp.isEmpty() &&
2911 getOperatorMenus()->createPopupMenu(theContext,theParent,theObject) != NULL ) {
2912 QPopupMenu* aPopup = getOperatorMenus()->createPopupMenu(theContext,theParent,theObject)->getPopup();
2913 int count = aPopup->count();
2915 //for (int i = 0; i < count; i++) {
2916 for (int i = count - 1; i >= 0; i--) {
2917 int id = aPopup->idAt(i);
2918 QString text = aPopup->text(id);
2919 //QString mes("Inserting popup menu item loaded from XML: ");
2921 //MESSAGE ( mes.latin1() )
2923 popup->insertItem(aPopup->text(id),
2925 SLOT( onDispatch(int) ), 0, id, 0);// try adding item at the top
2927 createPopup( popup, aPopup, text, id);
2930 //QString mes("Popup does not exist for given (Context = ");
2931 //mes += theContext;
2932 //mes += ", Parent = ";
2934 //mes += ", Object = ";
2936 //MESSAGE (mes.latin1())
2941 // Should be moved to SALOMEGUI_Application::onCreatePopup()...
2942 if ( myActiveComp.isEmpty() ) {
2943 popup->removeItem(QAD_Display_Popup_ID);
2944 popup->removeItem(QAD_DisplayOnly_Popup_ID);
2945 popup->removeItem(QAD_Erase_Popup_ID);
2946 int id = popup->idAt(popup->count()-1); // last item
2947 if (id < 0 && id != -1) popup->removeItem(id); // separator
2949 if ( popup && theParent.compare("ObjectBrowser")==0 ) {
2950 if ( popup->count()>0 ) {
2951 popup->insertItem (tr ("MEN_OPENWITH"), this, SLOT(onOpenWith()), 0, -1, 2);
2952 popup->insertSeparator (3);
2955 popup->insertItem (tr ("MEN_OPENWITH"), this, SLOT(onOpenWith()) );
2962 typedef bool activeStudyChanged(QAD_Desktop*);
2964 void QAD_Desktop::onActiveStudyChanged()
2966 if (!myActiveComp.isEmpty()) {
2967 OSD_Function osdF = mySharedLibrary.DlSymb("activeStudyChanged");
2968 if ( osdF != NULL ) {
2969 activeStudyChanged (*f1) = (bool (*) (QAD_Desktop*)) osdF;
2975 typedef bool customP(QAD_Desktop*, QPopupMenu*, const QString & theContext,
2976 const QString & theParent, const QString & theObject);
2978 Custom popup ( GUI Library )
2980 void QAD_Desktop::customPopup(QPopupMenu* popup, const QString & theContext,
2981 const QString & theParent, const QString & theObject)
2983 if (!myActiveComp.isEmpty()) {
2984 OSD_Function osdF = mySharedLibrary.DlSymb("customPopup");
2985 if ( osdF != NULL ) {
2986 customP (*f1) = (bool (*) (QAD_Desktop*, QPopupMenu*, const QString &,
2987 const QString &, const QString &)) osdF;
2988 (*f1)(this, popup, theContext, theParent, theObject);
2993 void QAD_Desktop::onObjectBrowser()
2995 bool checkDiff = false;
2997 bool state = QAD_CONFIG->getSetting("ObjectBrowser:AddColumn").compare("true") == 0;
2999 if ( myStdActions.at( PrefObjectBrowserEntryId )->isOn() != state )
3003 if ( myStdActions.at( PrefObjectBrowserEntryId )->isOn() ) {
3005 QAD_CONFIG->addSetting( "ObjectBrowser:AddColumn", "true");
3008 QAD_CONFIG->addSetting( "ObjectBrowser:AddColumn", "false");
3012 if ( myStdActions.at( PrefObjectBrowserValueId )->isOn() ) {
3014 QAD_CONFIG->addSetting( "ObjectBrowser:ValueColumn", "true");
3017 QAD_CONFIG->addSetting( "ObjectBrowser:ValueColumn", "false");
3021 if ( myStdActions.at( PrefObjectBrowserIAPPId )->isOn() ) {
3023 QAD_CONFIG->addSetting( "ObjectBrowser:IAPP", "true");
3026 QAD_CONFIG->addSetting( "ObjectBrowser:IAPP", "false");
3029 /* To sort created object in chrono order or reverse chrono order */
3030 bool showCHRONO_SORT ;
3031 if ( myStdActions.at( PrefObjectBrowserCHRONO_SORTId )->isOn() ) {
3032 showCHRONO_SORT = true;
3033 QAD_CONFIG->addSetting( "ObjectBrowser:CHRONO_SORT", "true");
3035 showCHRONO_SORT = false;
3036 QAD_CONFIG->addSetting( "ObjectBrowser:CHRONO_SORT", "false");
3039 if ( myActiveApp ) {
3040 QList<QAD_Study>& studies = myActiveApp->getStudies();
3041 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3042 int nbSf = study->getStudyFramesCount();
3043 for ( int i = 0; i < nbSf; i++ ) {
3044 QAD_StudyFrame* sf = study->getStudyFrame(i);
3045 sf->getLeftFrame()->getObjectBrowser()->setShowInfoColumns( showEntry );
3046 sf->getLeftFrame()->getObjectBrowser()->setShowValueColumn( showValue );
3047 sf->getLeftFrame()->getObjectBrowser()->setEnableChronoSort( showCHRONO_SORT );
3048 // sf->getLeftFrame()->getObjectBrowser()->setShowIAPP( showIAPP ); // this is done by below updateObjBrowser() call
3050 study->updateObjBrowser(true);
3055 void QAD_Desktop::onViewerTrihedron()
3057 QString Size = QAD_CONFIG->getSetting("Viewer:TrihedronSize");
3060 SALOMEGUI_TrihedronSizeDlg *Dlg = new SALOMEGUI_TrihedronSizeDlg(this);
3061 if (!Size.isEmpty())
3062 Dlg->setTrihedronSize(Size.toInt());
3063 int r = Dlg->exec();
3064 dim = Dlg->getTrihedronSize();
3067 if (r == QDialog::Accepted) {
3068 QAD_CONFIG->addSetting("Viewer:TrihedronSize", dim);
3071 QList<QAD_Study>& studies = myActiveApp->getStudies();
3072 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3073 int nbSf = study->getStudyFramesCount();
3074 for ( int i = 0; i < nbSf; i++ ) {
3075 study->getStudyFrame(i)->getRightFrame()->getViewFrame()->SetTrihedronSize(dim);
3082 void QAD_Desktop::onDirList()
3084 // getting dir list from settings
3085 QStringList dirList = QStringList::split(';', QAD_CONFIG->getSetting("FileDlg:QuickDirList"), false);
3086 QAD_DirListDlg* dlg = new QAD_DirListDlg(this);
3087 dlg->setPathList(dirList);
3088 if ( dlg->exec() == QDialog::Accepted) {
3089 dlg->getPathList(dirList);
3090 QAD_CONFIG->addSetting("FileDlg:QuickDirList", dirList.join(";"));
3095 void QAD_Desktop::onConsoleFontAction()
3097 // getting font from settings
3098 QString fntSet = QAD_CONFIG->getSetting("Viewer:ConsoleFont");
3099 QFont font = QAD_Tools::stringToFont( fntSet );
3101 font = QFontDialog::getFont( &bOk, font, this );
3103 fntSet = QAD_Tools::fontToString( font );
3104 QAD_CONFIG->addSetting("Viewer:ConsoleFont", fntSet );
3107 QList<QAD_Study>& studies = myActiveApp->getStudies();
3108 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3109 int nbSf = study->getStudyFramesCount();
3110 for ( int i = 0; i < nbSf; i++ ) {
3111 study->getStudyFrame(i)->getRightFrame()->getPyEditor()->setFont( font );
3112 study->getStudyFrame(i)->getRightFrame()->getMessage()->setFont( font );
3119 void QAD_Desktop::onSavePref()
3121 QAD_CONFIG->createConfigFile(true);
3124 //VRV: T2.5 - add default viewer
3125 void QAD_Desktop::onDefaultViewer(QAction * theAction)
3127 int type = VIEW_TYPE_MAX;
3130 if (myStdActions.at(DefaultViewerOCCId) == theAction)
3132 else if (myStdActions.at(DefaultViewerVTKId) == theAction)
3134 else if (myStdActions.at(DefaultGraphSupervisorId) == theAction)
3135 type = VIEW_GRAPHSUPERV;
3136 else if (myStdActions.at(DefaultPlot2dId) == theAction)
3138 if ( type != VIEW_TYPE_MAX )
3139 QAD_CONFIG->addSetting( "Viewer:DefaultViewer", QString::number( type ) );
3141 //VRV: T2.5 - add default viewer
3143 void QAD_Desktop::onViewerOCC()
3145 QString BackgroundColorRed = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorRed");
3146 QString BackgroundColorGreen = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorGreen");
3147 QString BackgroundColorBlue = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorBlue");
3150 if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3151 color = QColor(BackgroundColorRed.toInt(),
3152 BackgroundColorGreen.toInt(),
3153 BackgroundColorBlue.toInt());
3155 color = QColor(35, 136, 145);
3157 QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3160 if ( myActiveApp ) {
3161 QList<QAD_Study>& studies = myActiveApp->getStudies();
3162 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3163 int nbSf = study->getStudyFramesCount();
3164 for ( int i = 0; i < nbSf; i++ ) {
3165 QAD_StudyFrame* sf = study->getStudyFrame(i);
3166 if ( sf->getTypeView() == VIEW_OCC ) {
3167 sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3172 QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorRed", c.red() );
3173 QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorGreen", c.green() );
3174 QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorBlue", c.blue() );
3178 void QAD_Desktop::onGraphSupervisor()
3180 QString BackgroundColorRed = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorRed");
3181 QString BackgroundColorGreen = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorGreen");
3182 QString BackgroundColorBlue = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorBlue");
3185 if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3186 color = QColor(BackgroundColorRed.toInt(),
3187 BackgroundColorGreen.toInt(),
3188 BackgroundColorBlue.toInt());
3190 color = QColor(35, 136, 145);
3192 QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3195 if ( myActiveApp ) {
3196 QList<QAD_Study>& studies = myActiveApp->getStudies();
3197 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3198 int nbSf = study->getStudyFramesCount();
3199 for ( int i = 0; i < nbSf; i++ ) {
3200 QAD_StudyFrame* sf = study->getStudyFrame(i);
3201 if ( sf->getTypeView() == VIEW_GRAPHSUPERV ) {
3202 sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3208 QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorRed", c.red() );
3209 QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorGreen", c.green() );
3210 QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorBlue", c.blue() );
3214 void QAD_Desktop::onViewerVTK()
3216 QString BackgroundColorRed = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorRed");
3217 QString BackgroundColorGreen = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorGreen");
3218 QString BackgroundColorBlue = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorBlue");
3221 if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3222 color = QColor(BackgroundColorRed.toInt(),
3223 BackgroundColorGreen.toInt(),
3224 BackgroundColorBlue.toInt());
3226 color = QColor(0, 0, 0);
3228 QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3231 if ( myActiveApp ) {
3232 QList<QAD_Study>& studies = myActiveApp->getStudies();
3233 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3234 int nbSf = study->getStudyFramesCount();
3235 for ( int i = 0; i < nbSf; i++ ) {
3236 QAD_StudyFrame* sf = study->getStudyFrame(i);
3237 if ( sf->getTypeView() == VIEW_VTK ) {
3238 sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3244 QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorRed", c.red() );
3245 QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorGreen", c.green() );
3246 QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorBlue", c.blue() );
3250 void QAD_Desktop::onPlot2d()
3253 if ( QAD_CONFIG->hasSetting( "Plot2d:Background" ) ) {
3254 QString bgString = QAD_CONFIG->getSetting( "Plot2d:Background" );
3255 QStringList bgData = QStringList::split( ":", bgString, true );
3256 int bgRed = 0, bgGreen = 0, bgBlue = 0;
3257 if ( bgData.count() > 0 ) bgRed = bgData[ 0 ].toInt();
3258 if ( bgData.count() > 1 ) bgGreen = bgData[ 1 ].toInt();
3259 if ( bgData.count() > 2 ) bgBlue = bgData[ 2 ].toInt();
3260 color = QColor( bgRed, bgGreen, bgBlue );
3263 color = QColor(0, 0, 0);
3266 color = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3268 if ( color.isValid() ) {
3269 if ( myActiveApp ) {
3270 QList<QAD_Study>& studies = myActiveApp->getStudies();
3271 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3272 int nbSf = study->getStudyFramesCount();
3273 for ( int i = 0; i < nbSf; i++ ) {
3274 QAD_StudyFrame* sf = study->getStudyFrame(i);
3275 if ( sf->getTypeView() == VIEW_PLOT2D ) {
3276 sf->getRightFrame()->getViewFrame()->setBackgroundColor( color );
3282 bgData.append( QString::number( color.red() ) );
3283 bgData.append( QString::number( color.green() ) );
3284 bgData.append( QString::number( color.blue() ) );
3285 QAD_CONFIG->addSetting( "Plot2d:Background", bgData.join( ":" ) );
3290 void QAD_Desktop::helpAbout()
3292 SALOMEGUI_AboutDlg* About = new SALOMEGUI_AboutDlg( QAD_Application::getDesktop(), tr("MEN_ABOUT"));
3298 void QAD_Desktop::helpSearch()
3303 void QAD_Desktop::helpContents()
3305 if (myActiveComp == "")
3306 myActiveComp = getComponentUserName( "KERNEL" ); //NRI "Salome";
3310 if (dir = getenv( getComponentName( myActiveComp ) + "_ROOT_DIR")) {
3311 root = QAD_Tools::addSlash( QAD_Tools::addSlash(dir) + QAD_Tools::addSlash("share") + QAD_Tools::addSlash("salome") + "doc" );
3312 if ( QFileInfo( root + "index.html" ).exists() ) {
3313 helpContext( root + "index.html", "" );
3316 root = QAD_Tools::addSlash( root + "html" );
3317 if ( QFileInfo( root + "index.html" ).exists() ) {
3318 helpContext( root + "index.html", "" );
3321 root = QAD_Tools::addSlash( root + "html" );
3322 if ( QFileInfo( root + "index.html" ).exists() ) {
3323 helpContext( root + "index.html", "" );
3329 //NRI getHelpWindow()->contents();
3330 getHelpWindow()->show();
3331 getHelpWindow()->raise();
3332 getHelpWindow()->setActiveWindow();
3336 void QAD_Desktop::helpContext(const QString& source, const QString& context)
3338 getHelpWindow()->context(source, context);
3339 getHelpWindow()->show();
3340 getHelpWindow()->raise();
3341 getHelpWindow()->setActiveWindow();
3344 /* Preferences/MultiFile Save */
3345 void QAD_Desktop::onMultiFileSave()
3347 if ( myStdActions.at( PrefMultiFileSave )->isOn() )
3348 QAD_CONFIG->addSetting( "Desktop:MultiFileSave", "true");
3350 QAD_CONFIG->addSetting( "Desktop:MultiFileSave", "false");
3353 /*********************************************************************
3354 ** Class: AppSelectionDlg
3355 ** Descr: Dialog for the selection of the application when several
3356 ** applications exist in the desktop and new study creation
3357 ** is activated by user.
3359 **********************************************************************/
3361 \class Desktop_AppSelectionDlg QAD_Desktop.h
3362 \brief Dialog for the selection of the application when several
3363 applications exist in the desktop and new study creation
3364 is activated by user.
3369 Desktop_AppSelectionDlg::Desktop_AppSelectionDlg( QAD_Desktop* desktop,
3370 QList<QAD_Application>& apps ) :
3371 QDialog( desktop, 0, true ),
3375 QAD_ASSERT_DEBUG_ONLY ( desktop );
3376 setCaption( tr("INF_DESK_DOC_CREATE") );
3377 if ( desktop->icon() )
3378 setIcon( *desktop->icon() );
3380 QBoxLayout* mainLayout = new QVBoxLayout( this, 5 );
3382 /* Create selection buttons */
3383 QVButtonGroup* buttonGrp = new QVButtonGroup ( this );
3384 buttonGrp->setExclusive ( true );
3385 QBoxLayout* vLayout = new QVBoxLayout( mainLayout, 5 );
3386 vLayout->addWidget ( buttonGrp );
3388 /* Create selection button for available app */
3390 for ( QAD_Application* app = myApps.first(); app; app = myApps.next(), id++ )
3392 /* add radio button for application */
3393 buttonGrp->insert( new QRadioButton( app->getStudyDescription() +
3394 " (*." + app->getStudyExtension() + ")", buttonGrp ), id );
3397 /* make the first application selected */
3398 buttonGrp->setButton( 0 );
3400 /* listen to the selection */
3401 QAD_ASSERT ( connect ( buttonGrp, SIGNAL(clicked(int)), this, SLOT(onAppSelected(int)) ));
3403 /* Create OK/Cancel buttons
3405 QBoxLayout* hLayout = new QHBoxLayout( mainLayout, 5 );
3406 QPushButton* buttonOK = new QPushButton( tr("BUT_OK"), this );
3407 QPushButton* buttonCancel = new QPushButton( tr("BUT_CANCEL"), this );
3408 QPushButton* buttonHelp = new QPushButton( tr("BUT_HELP"), this );
3409 buttonOK->setDefault( true );
3411 hLayout->addStretch();
3412 hLayout->addWidget( buttonOK );
3413 hLayout->addWidget( buttonCancel );
3414 hLayout->addWidget( buttonHelp );
3416 /* connect buttons */
3417 QAD_ASSERT ( connect( buttonOK, SIGNAL(clicked()), this, SLOT(accept())) );
3418 QAD_ASSERT ( connect( buttonCancel, SIGNAL(clicked()), this, SLOT(reject())) );
3419 QAD_ASSERT ( connect( buttonHelp, SIGNAL(clicked()), this, SLOT(onHelp())) );
3421 /* disable resizing */
3422 setFixedSize( 0, 0 );
3423 setSizePolicy( QSizePolicy ( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
3426 Desktop_AppSelectionDlg::~Desktop_AppSelectionDlg()
3430 QAD_Application* Desktop_AppSelectionDlg::selectedApp() const
3432 return myApps.at( myAppId );
3435 void Desktop_AppSelectionDlg::resizeEvent( QResizeEvent* e )
3437 QAD_Tools::centerWidget( this, parentWidget() );
3443 void Desktop_AppSelectionDlg::onAppSelected( int id )
3448 void Desktop_AppSelectionDlg::onHelp()