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*);
2226 Called to define settings of component.
2228 void QAD_Desktop::setSettings()
2230 if (!myActiveComp.isEmpty()) {
2231 OSD_Function osdF = mySharedLibrary.DlSymb("SetSettings");
2232 if ( osdF != NULL ) {
2233 OneDim1 (*f1) = (bool (*) (QAD_Desktop*)) osdF;
2240 Called to load Component : xml resources and GUI librairy.
2242 bool QAD_Desktop::loadComponent(QString Component)
2245 QString resDir("/"); //NRI : Pb under Windows
2247 QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
2250 if (!resMgr->loadResources( Component, msg ))
2252 //NRI QCString errMsg;
2253 // errMsg.sprintf( "Do not load all resources for module %sGUI.\n" ,
2254 // Component.latin1() );
2256 QMessageBox::warning( this, tr("WRN_WARNING"), msg, tr ("BUT_OK") );
2261 /* Parse xml file */
2262 myXmlHandler = new QAD_XmlHandler();
2263 myXmlHandler->setMainWindow(this);
2264 if (!myXmlHandler->setComponent(resMgr->resources( Component ))) return false;
2266 QString language = resMgr->language( Component );
2268 QString ComponentXml = Component + "_" + language + ".xml";
2269 //ComponentXml = resMgr->resources(Component + "GUI") ;
2270 //ComponentXml = QAD_Tools::addSlash(ComponentXml) ;
2271 ComponentXml = QAD_Tools::addSlash( resMgr->findFile( ComponentXml, Component ) ) + ComponentXml;
2272 QFile file( ComponentXml );
2274 if ( !file.exists() || !file.open( IO_ReadOnly ) ) {
2276 errMsg.sprintf( "Cannot open xml file: %s\n.",
2277 (file.name()).latin1() );
2279 QMessageBox::critical( this, tr("ERR_ERROR"), errMsg, tr ("BUT_OK") );
2284 QXmlInputSource source( file );
2285 QXmlSimpleReader reader;
2286 reader.setContentHandler( myXmlHandler );
2287 reader.setErrorHandler( myXmlHandler );
2288 bool ok = reader.parse( source );
2292 QMessageBox::critical( this,
2293 tr( "INF_PARSE_ERROR" ),
2294 tr( myXmlHandler->errorProtocol() ) );
2298 myMenusList=myXmlHandler->myMenusList;
2299 myActiveMenus=myMenusList.at(0);
2300 myOperatorMenus->showMenuBar(0);
2301 myActiveMenus->showAllToolBars();
2303 /* Components toolbars */
2306 nbToolbars = myActiveMenus->getToolBarList().count();
2307 /* Open Shared Library */
2308 mySharedLibrary = OSD_SharedLibrary();
2310 QString ComponentLib;
2312 QFileInfo fileInfo ;
2313 QString fileString ;
2316 if ( libs = getenv("LD_LIBRARY_PATH")) {
2317 // MESSAGE ( " LD_LIBRARY_PATH : " << libs )
2318 QStringList dirList = QStringList::split( SEPARATOR, libs, false ); // skip empty entries
2320 for ( int i = dirList.count()-1; i >= 0; i-- ) {
2323 fileString = QAD_Tools::addSlash( dir ) + "lib" + Component + "GUI.dll" ;
2325 fileString = QAD_Tools::addSlash( dir ) + "lib" + Component + "GUI.so" ;
2328 fileInfo.setFile(fileString) ;
2329 if (fileInfo.exists()) {
2330 // MESSAGE ( " GUI library = " << fileString )
2331 ComponentLib = fileInfo.fileName() ;
2337 QMessageBox::critical( this,
2339 tr("ERR_LIBGUI" ).arg(Component) );
2344 mySharedLibrary.SetName(TCollection_AsciiString((char*)ComponentLib.latin1()).ToCString());
2345 ok = mySharedLibrary.DlOpen(OSD_RTLD_LAZY);
2348 QMessageBox::critical( this,
2350 tr( mySharedLibrary.DlError() ) );
2355 OSD_Function osdF = mySharedLibrary.DlSymb("SetSettings");
2356 if ( osdF != NULL ) {
2357 OneDim1 (*f1) = (bool (*) (QAD_Desktop*)) osdF;
2361 /* COMPONENT INTERFACE */
2362 SALOME_ModuleCatalog::Acomponent_ptr aComponent =
2363 myCatalogue->GetComponent(Component.latin1());
2365 if (CORBA::is_nil (aComponent)) {
2366 MESSAGE( "Catalog Error : Component not found in the catalog" )
2370 myActiveStudy->setMessage(QString("Component : ") +
2371 aComponent->componentusername() + " created " );
2372 myActiveStudy->setMessage(QString("Type : ") +
2373 QString::number(aComponent->component_type()));
2374 myActiveStudy->setMessage(QString("Constraint : ") +
2375 aComponent->constraint() );
2377 /* obtain interfaces list of the component */
2378 SALOME_ModuleCatalog::ListOfInterfaces_var _list =
2379 new SALOME_ModuleCatalog::ListOfInterfaces;
2380 _list = aComponent->GetInterfaceList();
2382 if (_list->length() != 0 ) {
2384 for (unsigned int ind = 0; ind < _list->length();ind++)
2385 myActiveStudy->setMessage( QString("Interface name : ") +
2389 /* obtain services list of the component */
2390 SALOME_ModuleCatalog::ListOfServices_var list_services_component =
2391 new SALOME_ModuleCatalog::ListOfServices;
2392 list_services_component = aComponent->GetServiceList(_list[0]);
2394 if (list_services_component->length() != 0 ) {
2396 for (unsigned int ind = 0; ind < list_services_component->length();ind++)
2397 myActiveStudy->setMessage( QString("Service name : ") +
2398 list_services_component[ind] );
2400 // Get a service of the component
2401 SALOME_ModuleCatalog::Service_var service = new SALOME_ModuleCatalog::Service;
2402 service = aComponent->GetService(_list[0],list_services_component[0]) ;
2403 myActiveStudy->setMessage( QString("Service name: ") + service->ServiceName);
2404 for (unsigned int ind1 = 0; ind1 <service->ServiceinParameter.length();ind1++) {
2405 myActiveStudy->setMessage( QString("Type of the in Parameter of this service : ") +
2406 (const char *) service->ServiceinParameter[ind1].Parametertype);
2407 myActiveStudy->setMessage( QString("Name of the in Parameter of this service : ") +
2408 (const char *) service->ServiceinParameter[ind1].Parametername);
2410 for (unsigned int ind1 = 0; ind1 <service->ServiceoutParameter.length();ind1++) {
2411 myActiveStudy->setMessage( QString("Type of the out Parameter of this service : ") +
2412 (const char *) service->ServiceoutParameter[ind1].Parametertype);
2413 myActiveStudy->setMessage( QString("Name of the out Parameter of this service : ") +
2414 (const char *) service->ServiceoutParameter[ind1].Parametername);
2421 typedef bool OneDim(int, QAD_Desktop*);
2422 typedef void (*PTR_FACTORY_FUNCTION)( CORBA::ORB_var &orb, QWidget *parent, const char *name ) ;
2426 void QAD_Desktop::onDispatch()
2428 const QObject* obj = sender();
2430 QList<QAD_ListMenuIdAction> MenuList = myActiveMenus->getMenuList();
2431 QAD_ListMenuIdAction* aMenu;
2433 for(aMenu=MenuList.first();aMenu!=NULL;aMenu=MenuList.next()) {
2434 if (aMenu->getAction()==obj) {
2435 id = aMenu->getId();
2444 void QAD_Desktop::onDispatchTools(int id)
2446 /* Open Shared Library */
2447 OSD_SharedLibrary ToolsLibrary = OSD_SharedLibrary();
2451 QFileInfo fileInfo ;
2455 bool libToolsGUI = true;
2456 if( QAD_XmlHandler::_bibmap[ id ].isEmpty() )
2459 if ( dir = getenv("SALOME_SITE_DIR")) {
2460 dir = QAD_Tools::addSlash(dir) ;
2462 dir = QAD_Tools::addSlash(dir) ;
2463 dir = dir + "salome" ;
2464 dir = QAD_Tools::addSlash(dir) ;
2466 dir = dir + "libToolsGUI.dll" ;
2468 dir = dir + "libToolsGUI.so" ;
2470 MESSAGE ( " GUI library = " << dir );
2471 fileInfo.setFile(dir) ;
2472 if (fileInfo.exists()) {
2473 ToolsLib = fileInfo.fileName() ;
2478 if ( (dir = getenv("SALOME_ROOT_DIR")) && !found ) {
2479 dir = QAD_Tools::addSlash(dir) ;
2481 dir = QAD_Tools::addSlash(dir) ;
2482 dir = dir + "salome" ;
2483 dir = QAD_Tools::addSlash(dir) ;
2485 dir = dir + "libToolsGUI.dll" ;
2487 dir = dir + "libToolsGUI.so" ;
2489 MESSAGE ( " GUI library = " << dir );
2490 fileInfo.setFile(dir) ;
2491 if (fileInfo.exists()) {
2492 ToolsLib = fileInfo.fileName() ;
2497 if ( (dir = getenv("KERNEL_ROOT_DIR")) && !found ) {
2498 dir = QAD_Tools::addSlash(dir) ;
2500 dir = QAD_Tools::addSlash(dir) ;
2501 dir = dir + "salome" ;
2502 dir = QAD_Tools::addSlash(dir) ;
2504 dir = dir + "libToolsGUI.dll" ;
2506 dir = dir + "libToolsGUI.so" ;
2508 MESSAGE ( " GUI library = " << dir );
2509 fileInfo.setFile(dir) ;
2510 if (fileInfo.exists()) {
2511 ToolsLib = fileInfo.fileName() ;
2517 libToolsGUI = false;
2518 SCRUTE( QAD_XmlHandler::_bibmap[ id ] ) ;
2519 if ( dir = getenv("SALOME_SITE_DIR")) {
2520 dir = QAD_Tools::addSlash(dir) ;
2522 dir = QAD_Tools::addSlash(dir) ;
2523 dir = dir + "salome" ;
2524 dir = QAD_Tools::addSlash(dir) ;
2525 dir = dir + QAD_XmlHandler::_bibmap[ id ].latin1() ;
2526 MESSAGE ( " GUI library = " << dir );
2527 fileInfo.setFile(dir) ;
2528 if (fileInfo.exists()) {
2529 ToolsLib = fileInfo.fileName() ;
2534 if ( (dir = getenv("SALOME_ROOT_DIR")) && !found ) {
2535 dir = QAD_Tools::addSlash(dir) ;
2537 dir = QAD_Tools::addSlash(dir) ;
2538 dir = dir + "salome" ;
2539 dir = QAD_Tools::addSlash(dir) ;
2540 dir = dir + QAD_XmlHandler::_bibmap[ id ].latin1() ;
2541 MESSAGE ( " GUI library = " << dir );
2542 fileInfo.setFile(dir) ;
2543 if (fileInfo.exists()) {
2544 ToolsLib = fileInfo.fileName() ;
2549 if ( (dir = getenv("KERNEL_ROOT_DIR")) && !found ) {
2550 dir = QAD_Tools::addSlash(dir) ;
2552 dir = QAD_Tools::addSlash(dir) ;
2553 dir = dir + "salome" ;
2554 dir = QAD_Tools::addSlash(dir) ;
2555 dir = dir + QAD_XmlHandler::_bibmap[ id ].latin1() ;
2556 MESSAGE ( " GUI library = " << dir );
2557 fileInfo.setFile(dir) ;
2558 if (fileInfo.exists()) {
2559 ToolsLib = fileInfo.fileName() ;
2565 ToolsLibrary.SetName(TCollection_AsciiString((char*)ToolsLib.latin1()).ToCString());
2566 bool ok = ToolsLibrary.DlOpen(OSD_RTLD_LAZY);
2568 if ( libToolsGUI ) {
2569 OSD_Function osdF = ToolsLibrary.DlSymb("OnGUIEvent");
2570 OneDim (*f1) = NULL;
2571 f1 = (bool (*) (int, QAD_Desktop*)) osdF;
2574 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
2575 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
2576 CORBA::ORB_var &orb = init(0 , 0 ) ;
2577 OSD_Function osdF = ToolsLibrary.DlSymb("OnGUIEvent");
2578 PTR_FACTORY_FUNCTION f1 = NULL;
2579 f1 = (PTR_FACTORY_FUNCTION) osdF;
2580 f1(orb,0,"Registry");
2583 QMessageBox::critical( this,
2585 tr( ToolsLibrary.DlError() ) );
2591 void QAD_Desktop::onDispatch(int id)
2593 if (!myActiveComp.isEmpty()) {
2594 OSD_Function osdF = mySharedLibrary.DlSymb("OnGUIEvent");
2595 OneDim (*f1) = NULL;
2596 if ( osdF != NULL ) {
2597 f1 = (bool (*) (int, QAD_Desktop*)) osdF;
2604 Returns the component's catalogue
2606 SALOME_ModuleCatalog::ModuleCatalog_var QAD_Desktop::getCatalogue()
2613 void QAD_Desktop::onComboActiveComponent( const QString & component ){
2614 onComboActiveComponent(component,true);
2616 void QAD_Desktop::onComboActiveComponent( const QString & component, bool isLoadData)
2618 if (myActiveStudy != 0) {
2619 if (myActiveComp.compare(component)!=0) {
2620 if (!myXmlHandler->myIdList.IsEmpty()) clearMenus();
2621 if ( myCombo->currentText() != component )
2622 myCombo->setCurrentText( component );
2623 //NRI if (component.compare(QString("Salome"))!= 0) {
2624 if (component.compare( getComponentUserName( "KERNEL" ) )!= 0) {
2625 // QApplication::setOverrideCursor( Qt::waitCursor );
2626 myActiveComp = component;
2628 SALOME_Selection* oldSel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2630 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2631 if ( aButton->textLabel().compare(component)==0)
2632 aButton->setOn(true);
2634 aButton->setOn(false);
2637 myActiveStudy->Selection( component );
2638 if ( !loadComponent(mapComponentName[component]) ) {
2639 myCombo->setCurrentItem (0);
2640 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2641 aButton->setOn(false);
2646 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2647 SALOME_ListIteratorOfListIO It( oldSel->StoredIObjects() );
2648 for(;It.More();It.Next()) {
2649 int res = Sel->AddIObject( It.Value() );
2652 myActiveStudy->highlight( It.Value(), false );
2654 myActiveStudy->highlight( It.Value(), true );
2658 // Open new component's data in active study if any
2659 if(isLoadData) loadComponentData(mapComponentName[component]);
2662 myActiveStudy->updateObjBrowser(true);
2664 // QApplication::restoreOverrideCursor();
2666 } else { // component == "Salome"
2668 //NRI myActiveStudy->Selection( "Salome" );
2669 myActiveStudy->Selection( getComponentUserName( "KERNEL" ) );
2670 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2671 Sel->ClearIObjects();
2672 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2673 aButton->setOn(false);
2677 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2678 if ( aButton->textLabel().compare(component)==0)
2679 aButton->setOn(true);
2683 QMessageBox::critical( 0,
2685 tr( "WRN_LOAD_COMPONENT" ) );
2686 myCombo->setCurrentItem (0);
2687 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2688 aButton->setOn(false);
2695 void QAD_Desktop::activateComponent(const QString& theName, bool isLoadData){
2696 int nbItem = myCombo->count();
2699 for (int i = 0; i < nbItem; i++) {
2700 if (myCombo->text(i).compare(theName)==0) {
2705 myCombo->setCurrentItem (Index);
2706 onComboActiveComponent(theName,isLoadData);
2709 void QAD_Desktop::onButtonActiveComponent( )
2711 QToolButton* obj = (QToolButton*)sender();
2712 activateComponent(obj->textLabel());
2716 Clears All Resources of current component
2718 void QAD_Desktop::clearMenus()
2720 onActiveStudyChanged();
2723 myMenusList.clear();
2725 int length = myXmlHandler->myIdList.Length();
2726 for (int k=length; k>0; k--) {
2728 if ( menuBar()->findItem(myXmlHandler->myIdList.Value(k), &parent) )
2729 parent->removeItem( myXmlHandler->myIdList.Value(k) );
2734 if (myActiveMenus) {
2735 int nbtoolbars = myActiveMenus->getToolBarList().count();
2736 for (int k=0; k<nbtoolbars; k++) {
2737 myActiveMenus->getToolBarList().at(k)->hide();
2738 myActiveMenus->getToolBarList().at(k)->clear();
2740 myActiveMenus->clearToolBar();
2743 QList<QAD_ListPopupMenu> PopupList = myActiveMenus->getPopupMenuList();
2744 QAD_ListPopupMenu* aPopup;
2745 for(aPopup=PopupList.first();aPopup!=NULL;aPopup=PopupList.next()){
2746 aPopup->getPopup()->clear();
2749 myActiveMenus->clearPopupMenu();
2755 typedef bool TwoDim1(QKeyEvent* pe, QAD_Desktop*, QAD_StudyFrame*);
2757 Exports Key Events in active component ( GUI Librairy )
2759 void QAD_Desktop::onKeyPress( QKeyEvent* pe )
2761 // MESSAGE ( "QAD_Desktop::onKeyPress" )
2762 if (!myActiveComp.isEmpty()) {
2763 OSD_Function osdF = mySharedLibrary.DlSymb("OnKeyPress");
2764 if ( osdF != NULL ) {
2765 TwoDim1 (*f1) = (bool (*) (QKeyEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
2766 (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
2771 typedef bool TwoDim(QMouseEvent* pe, QAD_Desktop*, QAD_StudyFrame*);
2773 Exports Mouse Press Events in active component ( GUI Librairy )
2775 bool QAD_Desktop::onMousePress( QMouseEvent* pe )
2777 // MESSAGE ( "QAD_Desktop::onMousePress" )
2778 if (!myActiveComp.isEmpty()) {
2779 OSD_Function osdF = mySharedLibrary.DlSymb("OnMousePress");
2780 if ( osdF != NULL ) {
2781 TwoDim (*f1) = (bool (*) (QMouseEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
2782 return (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
2789 Exports Mouse Move Events in active component ( GUI Librairy )
2791 void QAD_Desktop::onMouseMove( QMouseEvent* pe )
2793 if (!myActiveComp.isEmpty()) {
2794 OSD_Function osdF = mySharedLibrary.DlSymb("OnMouseMove");
2795 if ( osdF != NULL ) {
2796 TwoDim (*f1) = (bool (*) (QMouseEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
2797 (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
2803 Returns name of active component
2805 const QString& QAD_Desktop::getActiveComponent() const
2807 return myActiveComp;
2811 typedef bool defineP( QString & theContext, QString & theParent, QString & theObject);
2813 void QAD_Desktop::definePopup(QString & theContext,
2814 QString & theParent,
2815 QString & theObject )
2817 if (!myActiveComp.isEmpty()) {
2818 OSD_Function osdF = mySharedLibrary.DlSymb("definePopup");
2819 if ( osdF != NULL ) {
2820 defineP (*f1) = (bool (*) (QString &, QString &, QString &)) osdF;
2821 (*f1)(theContext, theParent, theObject);
2829 void QAD_Desktop::createPopup(QPopupMenu* popupFather, QPopupMenu* popup,
2830 QString text, int popupID, bool separator)
2832 QMenuItem* item = popup->findItem(popupID);
2834 QPopupMenu* popupChild = item->popup();
2836 QPopupMenu* newPopup = new QPopupMenu;
2837 int count = popupChild->count();
2838 // add items at the top of <popupFather>
2839 for (int i = count - 1; i >= 0; i--) {
2840 int j = popupChild->idAt(i);
2841 QString text = popupChild->text(j);
2842 createPopup( newPopup, popupChild, text, j);
2844 popupFather->insertItem(popup->text(popupID),
2845 newPopup, popupID, 0);
2847 if ( !text.isNull() ) {
2848 popupFather->insertItem(popup->text(popupID),
2850 SLOT( onDispatch(int) ), 0, popupID, 0);// try adding item at the top
2851 } /*else if ( separator )
2852 popupFather->insertTearOffHandle(-1, 0);*/
2854 popupFather->insertSeparator(0);
2862 void QAD_Desktop::createPopup(QPopupMenu* popup, const QString & theContext,
2863 const QString & theParent, const QString & theObject )
2865 if ( !myActiveComp.isEmpty() &&
2866 getOperatorMenus()->createPopupMenu(theContext,theParent,theObject) != NULL ) {
2867 QPopupMenu* aPopup = getOperatorMenus()->createPopupMenu(theContext,theParent,theObject)->getPopup();
2868 int count = aPopup->count();
2870 //for (int i = 0; i < count; i++) {
2871 for (int i = count - 1; i >= 0; i--) {
2872 int id = aPopup->idAt(i);
2873 QString text = aPopup->text(id);
2874 //QString mes("Inserting popup menu item loaded from XML: ");
2876 //MESSAGE ( mes.latin1() )
2878 popup->insertItem(aPopup->text(id),
2880 SLOT( onDispatch(int) ), 0, id, 0);// try adding item at the top
2882 createPopup( popup, aPopup, text, id);
2885 //QString mes("Popup does not exist for given (Context = ");
2886 //mes += theContext;
2887 //mes += ", Parent = ";
2889 //mes += ", Object = ";
2891 //MESSAGE (mes.latin1())
2896 // Should be moved to SALOMEGUI_Application::onCreatePopup()...
2897 if ( myActiveComp.isEmpty() ) {
2898 popup->removeItem(QAD_Display_Popup_ID);
2899 popup->removeItem(QAD_DisplayOnly_Popup_ID);
2900 popup->removeItem(QAD_Erase_Popup_ID);
2901 int id = popup->idAt(popup->count()-1); // last item
2902 if (id < 0 && id != -1) popup->removeItem(id); // separator
2904 if ( popup && theParent.compare("ObjectBrowser")==0 ) {
2905 if ( popup->count()>0 ) {
2906 popup->insertItem (tr ("MEN_OPENWITH"), this, SLOT(onOpenWith()), 0, -1, 2);
2907 popup->insertSeparator (3);
2910 popup->insertItem (tr ("MEN_OPENWITH"), this, SLOT(onOpenWith()) );
2917 typedef bool activeStudyChanged(QAD_Desktop*);
2919 void QAD_Desktop::onActiveStudyChanged()
2921 if (!myActiveComp.isEmpty()) {
2922 OSD_Function osdF = mySharedLibrary.DlSymb("activeStudyChanged");
2923 if ( osdF != NULL ) {
2924 activeStudyChanged (*f1) = (bool (*) (QAD_Desktop*)) osdF;
2930 typedef bool customP(QAD_Desktop*, QPopupMenu*, const QString & theContext,
2931 const QString & theParent, const QString & theObject);
2933 Custom popup ( GUI Library )
2935 void QAD_Desktop::customPopup(QPopupMenu* popup, const QString & theContext,
2936 const QString & theParent, const QString & theObject)
2938 if (!myActiveComp.isEmpty()) {
2939 OSD_Function osdF = mySharedLibrary.DlSymb("customPopup");
2940 if ( osdF != NULL ) {
2941 customP (*f1) = (bool (*) (QAD_Desktop*, QPopupMenu*, const QString &,
2942 const QString &, const QString &)) osdF;
2943 (*f1)(this, popup, theContext, theParent, theObject);
2948 void QAD_Desktop::onObjectBrowser()
2950 bool checkDiff = false;
2952 bool state = QAD_CONFIG->getSetting("ObjectBrowser:AddColumn").compare("true") == 0;
2954 if ( myStdActions.at( PrefObjectBrowserEntryId )->isOn() != state )
2958 if ( myStdActions.at( PrefObjectBrowserEntryId )->isOn() ) {
2960 QAD_CONFIG->addSetting( "ObjectBrowser:AddColumn", "true");
2963 QAD_CONFIG->addSetting( "ObjectBrowser:AddColumn", "false");
2967 if ( myStdActions.at( PrefObjectBrowserValueId )->isOn() ) {
2969 QAD_CONFIG->addSetting( "ObjectBrowser:ValueColumn", "true");
2972 QAD_CONFIG->addSetting( "ObjectBrowser:ValueColumn", "false");
2976 if ( myStdActions.at( PrefObjectBrowserIAPPId )->isOn() ) {
2978 QAD_CONFIG->addSetting( "ObjectBrowser:IAPP", "true");
2981 QAD_CONFIG->addSetting( "ObjectBrowser:IAPP", "false");
2984 /* To sort created object in chrono order or reverse chrono order */
2985 bool showCHRONO_SORT ;
2986 if ( myStdActions.at( PrefObjectBrowserCHRONO_SORTId )->isOn() ) {
2987 showCHRONO_SORT = true;
2988 QAD_CONFIG->addSetting( "ObjectBrowser:CHRONO_SORT", "true");
2990 showCHRONO_SORT = false;
2991 QAD_CONFIG->addSetting( "ObjectBrowser:CHRONO_SORT", "false");
2994 if ( myActiveApp ) {
2995 QList<QAD_Study>& studies = myActiveApp->getStudies();
2996 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
2997 int nbSf = study->getStudyFramesCount();
2998 for ( int i = 0; i < nbSf; i++ ) {
2999 QAD_StudyFrame* sf = study->getStudyFrame(i);
3000 sf->getLeftFrame()->getObjectBrowser()->setShowInfoColumns( showEntry );
3001 sf->getLeftFrame()->getObjectBrowser()->setShowValueColumn( showValue );
3002 sf->getLeftFrame()->getObjectBrowser()->setEnableChronoSort( showCHRONO_SORT );
3003 // sf->getLeftFrame()->getObjectBrowser()->setShowIAPP( showIAPP ); // this is done by below updateObjBrowser() call
3005 study->updateObjBrowser(true);
3010 void QAD_Desktop::onViewerTrihedron()
3012 QString Size = QAD_CONFIG->getSetting("Viewer:TrihedronSize");
3015 SALOMEGUI_TrihedronSizeDlg *Dlg = new SALOMEGUI_TrihedronSizeDlg(this);
3016 if (!Size.isEmpty())
3017 Dlg->setTrihedronSize(Size.toInt());
3018 int r = Dlg->exec();
3019 dim = Dlg->getTrihedronSize();
3022 if (r == QDialog::Accepted) {
3023 QAD_CONFIG->addSetting("Viewer:TrihedronSize", dim);
3026 QList<QAD_Study>& studies = myActiveApp->getStudies();
3027 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3028 int nbSf = study->getStudyFramesCount();
3029 for ( int i = 0; i < nbSf; i++ ) {
3030 study->getStudyFrame(i)->getRightFrame()->getViewFrame()->SetTrihedronSize(dim);
3037 void QAD_Desktop::onDirList()
3039 // getting dir list from settings
3040 QStringList dirList = QStringList::split(';', QAD_CONFIG->getSetting("FileDlg:QuickDirList"), false);
3041 QAD_DirListDlg* dlg = new QAD_DirListDlg(this);
3042 dlg->setPathList(dirList);
3043 if ( dlg->exec() == QDialog::Accepted) {
3044 dlg->getPathList(dirList);
3045 QAD_CONFIG->addSetting("FileDlg:QuickDirList", dirList.join(";"));
3050 void QAD_Desktop::onConsoleFontAction()
3052 // getting font from settings
3053 QString fntSet = QAD_CONFIG->getSetting("Viewer:ConsoleFont");
3054 QFont font = QAD_Tools::stringToFont( fntSet );
3056 font = QFontDialog::getFont( &bOk, font, this );
3058 fntSet = QAD_Tools::fontToString( font );
3059 QAD_CONFIG->addSetting("Viewer:ConsoleFont", fntSet );
3062 QList<QAD_Study>& studies = myActiveApp->getStudies();
3063 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3064 int nbSf = study->getStudyFramesCount();
3065 for ( int i = 0; i < nbSf; i++ ) {
3066 study->getStudyFrame(i)->getRightFrame()->getPyEditor()->setFont( font );
3067 study->getStudyFrame(i)->getRightFrame()->getMessage()->setFont( font );
3074 void QAD_Desktop::onSavePref()
3076 QAD_CONFIG->createConfigFile(true);
3079 //VRV: T2.5 - add default viewer
3080 void QAD_Desktop::onDefaultViewer(QAction * theAction)
3082 int type = VIEW_TYPE_MAX;
3085 if (myStdActions.at(DefaultViewerOCCId) == theAction)
3087 else if (myStdActions.at(DefaultViewerVTKId) == theAction)
3089 else if (myStdActions.at(DefaultGraphSupervisorId) == theAction)
3090 type = VIEW_GRAPHSUPERV;
3091 else if (myStdActions.at(DefaultPlot2dId) == theAction)
3093 if ( type != VIEW_TYPE_MAX )
3094 QAD_CONFIG->addSetting( "Viewer:DefaultViewer", QString::number( type ) );
3096 //VRV: T2.5 - add default viewer
3098 void QAD_Desktop::onViewerOCC()
3100 QString BackgroundColorRed = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorRed");
3101 QString BackgroundColorGreen = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorGreen");
3102 QString BackgroundColorBlue = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorBlue");
3105 if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3106 color = QColor(BackgroundColorRed.toInt(),
3107 BackgroundColorGreen.toInt(),
3108 BackgroundColorBlue.toInt());
3110 color = QColor(35, 136, 145);
3112 QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3115 if ( myActiveApp ) {
3116 QList<QAD_Study>& studies = myActiveApp->getStudies();
3117 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3118 int nbSf = study->getStudyFramesCount();
3119 for ( int i = 0; i < nbSf; i++ ) {
3120 QAD_StudyFrame* sf = study->getStudyFrame(i);
3121 if ( sf->getTypeView() == VIEW_OCC ) {
3122 sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3127 QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorRed", c.red() );
3128 QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorGreen", c.green() );
3129 QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorBlue", c.blue() );
3133 void QAD_Desktop::onGraphSupervisor()
3135 QString BackgroundColorRed = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorRed");
3136 QString BackgroundColorGreen = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorGreen");
3137 QString BackgroundColorBlue = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorBlue");
3140 if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3141 color = QColor(BackgroundColorRed.toInt(),
3142 BackgroundColorGreen.toInt(),
3143 BackgroundColorBlue.toInt());
3145 color = QColor(35, 136, 145);
3147 QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3150 if ( myActiveApp ) {
3151 QList<QAD_Study>& studies = myActiveApp->getStudies();
3152 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3153 int nbSf = study->getStudyFramesCount();
3154 for ( int i = 0; i < nbSf; i++ ) {
3155 QAD_StudyFrame* sf = study->getStudyFrame(i);
3156 if ( sf->getTypeView() == VIEW_GRAPHSUPERV ) {
3157 sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3163 QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorRed", c.red() );
3164 QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorGreen", c.green() );
3165 QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorBlue", c.blue() );
3169 void QAD_Desktop::onViewerVTK()
3171 QString BackgroundColorRed = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorRed");
3172 QString BackgroundColorGreen = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorGreen");
3173 QString BackgroundColorBlue = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorBlue");
3176 if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3177 color = QColor(BackgroundColorRed.toInt(),
3178 BackgroundColorGreen.toInt(),
3179 BackgroundColorBlue.toInt());
3181 color = QColor(0, 0, 0);
3183 QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3186 if ( myActiveApp ) {
3187 QList<QAD_Study>& studies = myActiveApp->getStudies();
3188 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3189 int nbSf = study->getStudyFramesCount();
3190 for ( int i = 0; i < nbSf; i++ ) {
3191 QAD_StudyFrame* sf = study->getStudyFrame(i);
3192 if ( sf->getTypeView() == VIEW_VTK ) {
3193 sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3199 QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorRed", c.red() );
3200 QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorGreen", c.green() );
3201 QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorBlue", c.blue() );
3205 void QAD_Desktop::onPlot2d()
3208 if ( QAD_CONFIG->hasSetting( "Plot2d:Background" ) ) {
3209 QString bgString = QAD_CONFIG->getSetting( "Plot2d:Background" );
3210 QStringList bgData = QStringList::split( ":", bgString, true );
3211 int bgRed = 0, bgGreen = 0, bgBlue = 0;
3212 if ( bgData.count() > 0 ) bgRed = bgData[ 0 ].toInt();
3213 if ( bgData.count() > 1 ) bgGreen = bgData[ 1 ].toInt();
3214 if ( bgData.count() > 2 ) bgBlue = bgData[ 2 ].toInt();
3215 color = QColor( bgRed, bgGreen, bgBlue );
3218 color = QColor(0, 0, 0);
3221 color = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3223 if ( color.isValid() ) {
3224 if ( myActiveApp ) {
3225 QList<QAD_Study>& studies = myActiveApp->getStudies();
3226 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3227 int nbSf = study->getStudyFramesCount();
3228 for ( int i = 0; i < nbSf; i++ ) {
3229 QAD_StudyFrame* sf = study->getStudyFrame(i);
3230 if ( sf->getTypeView() == VIEW_PLOT2D ) {
3231 sf->getRightFrame()->getViewFrame()->setBackgroundColor( color );
3237 bgData.append( QString::number( color.red() ) );
3238 bgData.append( QString::number( color.green() ) );
3239 bgData.append( QString::number( color.blue() ) );
3240 QAD_CONFIG->addSetting( "Plot2d:Background", bgData.join( ":" ) );
3245 void QAD_Desktop::helpAbout()
3247 SALOMEGUI_AboutDlg* About = new SALOMEGUI_AboutDlg( QAD_Application::getDesktop(), tr("MEN_ABOUT"));
3253 void QAD_Desktop::helpSearch()
3258 void QAD_Desktop::helpContents()
3260 if (myActiveComp == "")
3261 myActiveComp = getComponentUserName( "KERNEL" ); //NRI "Salome";
3265 if (dir = getenv( getComponentName( myActiveComp ) + "_ROOT_DIR")) {
3266 root = QAD_Tools::addSlash( QAD_Tools::addSlash(dir) + QAD_Tools::addSlash("share") + QAD_Tools::addSlash("salome") + "doc" );
3267 if ( QFileInfo( root + "index.html" ).exists() ) {
3268 helpContext( root + "index.html", "" );
3271 root = QAD_Tools::addSlash( root + "html" );
3272 if ( QFileInfo( root + "index.html" ).exists() ) {
3273 helpContext( root + "index.html", "" );
3276 root = QAD_Tools::addSlash( root + "html" );
3277 if ( QFileInfo( root + "index.html" ).exists() ) {
3278 helpContext( root + "index.html", "" );
3284 //NRI getHelpWindow()->contents();
3285 getHelpWindow()->show();
3286 getHelpWindow()->raise();
3287 getHelpWindow()->setActiveWindow();
3291 void QAD_Desktop::helpContext(const QString& source, const QString& context)
3293 getHelpWindow()->context(source, context);
3294 getHelpWindow()->show();
3295 getHelpWindow()->raise();
3296 getHelpWindow()->setActiveWindow();
3299 /* Preferences/MultiFile Save */
3300 void QAD_Desktop::onMultiFileSave()
3302 if ( myStdActions.at( PrefMultiFileSave )->isOn() )
3303 QAD_CONFIG->addSetting( "Desktop:MultiFileSave", "true");
3305 QAD_CONFIG->addSetting( "Desktop:MultiFileSave", "false");
3308 /*********************************************************************
3309 ** Class: AppSelectionDlg
3310 ** Descr: Dialog for the selection of the application when several
3311 ** applications exist in the desktop and new study creation
3312 ** is activated by user.
3314 **********************************************************************/
3316 \class Desktop_AppSelectionDlg QAD_Desktop.h
3317 \brief Dialog for the selection of the application when several
3318 applications exist in the desktop and new study creation
3319 is activated by user.
3324 Desktop_AppSelectionDlg::Desktop_AppSelectionDlg( QAD_Desktop* desktop,
3325 QList<QAD_Application>& apps ) :
3326 QDialog( desktop, 0, true ),
3330 QAD_ASSERT_DEBUG_ONLY ( desktop );
3331 setCaption( tr("INF_DESK_DOC_CREATE") );
3332 if ( desktop->icon() )
3333 setIcon( *desktop->icon() );
3335 QBoxLayout* mainLayout = new QVBoxLayout( this, 5 );
3337 /* Create selection buttons */
3338 QVButtonGroup* buttonGrp = new QVButtonGroup ( this );
3339 buttonGrp->setExclusive ( true );
3340 QBoxLayout* vLayout = new QVBoxLayout( mainLayout, 5 );
3341 vLayout->addWidget ( buttonGrp );
3343 /* Create selection button for available app */
3345 for ( QAD_Application* app = myApps.first(); app; app = myApps.next(), id++ )
3347 /* add radio button for application */
3348 buttonGrp->insert( new QRadioButton( app->getStudyDescription() +
3349 " (*." + app->getStudyExtension() + ")", buttonGrp ), id );
3352 /* make the first application selected */
3353 buttonGrp->setButton( 0 );
3355 /* listen to the selection */
3356 QAD_ASSERT ( connect ( buttonGrp, SIGNAL(clicked(int)), this, SLOT(onAppSelected(int)) ));
3358 /* Create OK/Cancel buttons
3360 QBoxLayout* hLayout = new QHBoxLayout( mainLayout, 5 );
3361 QPushButton* buttonOK = new QPushButton( tr("BUT_OK"), this );
3362 QPushButton* buttonCancel = new QPushButton( tr("BUT_CANCEL"), this );
3363 QPushButton* buttonHelp = new QPushButton( tr("BUT_HELP"), this );
3364 buttonOK->setDefault( true );
3366 hLayout->addStretch();
3367 hLayout->addWidget( buttonOK );
3368 hLayout->addWidget( buttonCancel );
3369 hLayout->addWidget( buttonHelp );
3371 /* connect buttons */
3372 QAD_ASSERT ( connect( buttonOK, SIGNAL(clicked()), this, SLOT(accept())) );
3373 QAD_ASSERT ( connect( buttonCancel, SIGNAL(clicked()), this, SLOT(reject())) );
3374 QAD_ASSERT ( connect( buttonHelp, SIGNAL(clicked()), this, SLOT(onHelp())) );
3376 /* disable resizing */
3377 setFixedSize( 0, 0 );
3378 setSizePolicy( QSizePolicy ( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
3381 Desktop_AppSelectionDlg::~Desktop_AppSelectionDlg()
3385 QAD_Application* Desktop_AppSelectionDlg::selectedApp() const
3387 return myApps.at( myAppId );
3390 void Desktop_AppSelectionDlg::resizeEvent( QResizeEvent* e )
3392 QAD_Tools::centerWidget( this, parentWidget() );
3398 void Desktop_AppSelectionDlg::onAppSelected( int id )
3403 void Desktop_AppSelectionDlg::onHelp()