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 mapComponentName.insert( moduleusername, modulename );
258 resDir = resMgr->findFile(iconfile,modulename) ;
261 MESSAGE ( "resDir" << resDir )
262 //resDir = QAD_Tools::addSlash(resDir) ;
263 //QPixmap Icone(resDir+iconfile) ;
264 QPixmap Icone( QAD_Tools::addSlash( resDir ) + iconfile );
265 QToolButton * toolb =
266 new QToolButton( QIconSet( Icone ), moduleusername, QString::null, this,
267 SLOT( onButtonActiveComponent () ),tbComponent );
268 toolb->setToggleButton( true );
269 myComponentButton.append(toolb);
273 QString errMsg = tr("INF_ICON_RESOURCES").arg(iconfile).arg(modulename) +
275 //QMessageBox::warning( this, tr("WRN_WARNING"), errMsg, tr ("BUT_OK") );
278 if ( !QString(list_composants[ind].modulename).isEmpty() )
279 myCombo->insertItem( strdup(list_composants[ind].moduleusername) );
283 myCombo->adjustSize();
284 connect( myCombo, SIGNAL(activated(const QString&)),
285 this, SLOT( onComboActiveComponent(const QString&) ) );
287 /* new LifeCycleCORBA client, for Engines */
288 myEnginesLifeCycle = new SALOME_LifeCycleCORBA(name_service);
290 /* VSR 13/01/03 : installing global event filter for the application */
291 qApp->installEventFilter( this );
297 QAD_Desktop::~QAD_Desktop ()
299 qApp->removeEventFilter( this );
303 myObjBrowserPopup.clear();
304 //VRV: T2.5 - add default viewer
305 myDefaultViewer.clear();
306 //VRV: T2.5 - add default viewer
307 myViewerPopup.clear();
309 myNewViewPopup.clear();
311 myToolsPopup.clear();
313 myStdActions.clear();
315 myToolBarsPopup.clear();
316 myToolBarAction.clear();
320 myHelpWindow->close();
322 QAD_Application::desktop = 0;
325 const int IdCut = 1001;
326 const int IdCopy = 1002;
327 const int IdPaste = 1003;
328 const int IdSelectAll = 1004;
330 #include <qkeysequence.h>
331 #define ACCEL_KEY(k) "\t" + QString(QKeySequence( Qt::CTRL | Qt::Key_ ## k ))
333 #define ACCEL_KEY(k) "\t" + QString("Ctrl+" #k)
335 #include <qclipboard.h>
337 Global event filter for qapplication (VSR 13/01/03)
339 bool QAD_Desktop::eventFilter( QObject* o, QEvent* e )
341 if ( e->type() == QEvent::ContextMenu ) {
342 QContextMenuEvent* ce = (QContextMenuEvent*)e;
343 if ( o->inherits("QRenameEdit") ) {
346 else if ( o->inherits("QLineEdit") ) {
347 QLineEdit* le = (QLineEdit*)o;
348 if ( le->parentWidget() ) {
349 if ( ( le->parentWidget()->inherits("QSpinBox") ||
350 le->parentWidget()->inherits("QSpinWidget") ||
351 le->parentWidget()->inherits("QAD_SpinBoxDbl") ) &&
353 QPopupMenu* popup = new QPopupMenu( 0, "qt_edit_menu" );
354 popup->insertItem( tr( "EDIT_CUT_CMD" ) + ACCEL_KEY( X ), IdCut );
355 popup->insertItem( tr( "EDIT_COPY_CMD" ) + ACCEL_KEY( C ), IdCopy );
356 popup->insertItem( tr( "EDIT_PASTE_CMD" ) + ACCEL_KEY( V ), IdPaste );
357 popup->insertSeparator();
358 #if defined(Q_WS_X11)
359 popup->insertItem( tr( "EDIT_SELECTALL_CMD" ), IdSelectAll );
361 popup->insertItem( tr( "EDIT_SELECTALL_CMD" ) + ACCEL_KEY( A ), IdSelectAll );
363 bool enableCut = !le->isReadOnly() && le->hasSelectedText();
364 popup->setItemEnabled( IdCut, enableCut );
365 popup->setItemEnabled( IdCopy, le->hasSelectedText() );
366 bool enablePaste = !le->isReadOnly() && !QApplication::clipboard()->text().isEmpty();
367 popup->setItemEnabled( IdPaste, enablePaste );
368 bool allSelected = (le->selectedText() == le->text() );
369 popup->setItemEnabled( IdSelectAll, (bool)(le->text().length()) && !allSelected );
371 QPoint pos = ce->reason() == QContextMenuEvent::Mouse ? ce->globalPos() :
372 le->mapToGlobal( QPoint(ce->pos().x(), 0) ) + QPoint( le->width() / 2, le->height() / 2 );
374 int r = popup->exec( pos );
396 return QMainWindow::eventFilter( o, e );
400 Creates and initializes the standard file operations
401 such as 'New/Open/Save/SaveAs/Close' and 'Help'.
403 void QAD_Desktop::createActions()
406 /* Used for string compare */
407 const QString& aTrueQString = "true" ;
409 /* create 'standard' toolbar */
410 if ( !myStdToolBar ) {
411 myStdToolBar = new QToolBar ( tr("MEN_DESK_VIEW_STDTOOLBAR"), this );
412 myStdToolBar->setCloseMode( QDockWindow::Undocked );
415 if ( !myMainMenu->count() ) {
416 /* Create main menu bar */
417 myMainMenu->insertItem ( tr("MEN_DESK_FILE"), &myFilePopup, 1 ); /* add popup FILE */
418 myMainMenu->insertItem ( tr("MEN_DESK_VIEW"), &myViewPopup, 2 ); /* add popup VIEW */
419 myMainMenu->insertItem ( tr("MEN_DESK_TOOLS"), &myToolsPopup, 5 ); /* add popup TOOLS */
420 myMainMenu->insertItem ( tr("MEN_DESK_PREF"), &myPrefPopup, 4 ); /* add popup PREF */
421 myMainMenu->insertItem ( tr("MEN_DESK_WINDOW"), &myWindowPopup, 6 ); /* add popup WINDOW */
422 myMainMenu->insertItem ( tr("MEN_DESK_HELP"), &myHelpPopup, 7 ); /* add popup HELP */
424 /* Applications will insert their items after 'File' 'Edit' and 'View'
425 ( 'Edit' will be inserted later )
430 /* insert logo picture to menu bar */
431 QHBox* aLogoFrm = new QHBox(this);
432 aLogoFrm->setFrameStyle( QFrame::Plain | QFrame::NoFrame );
433 QPixmap aLogoPixmap ( QAD_Desktop::getResourceManager()->loadPixmap( "CLIENT",
434 tr("ICON_DESK_LOGO") ));
435 QLabel* aLogoLab = new QLabel(aLogoFrm);
436 aLogoLab->setPixmap(aLogoPixmap);
437 aLogoLab->setAlignment(AlignCenter);
438 aLogoLab->setScaledContents(false);
439 myMainMenu->insertItem(aLogoFrm);
441 if ( myStdActions.isEmpty() ) {
442 /* Define standard actions. They should be inserted
443 into the list in order of their IDs.
448 QAD_ResourceMgr* rmgr = QAD_Desktop::getResourceManager();
449 QAction* fileNewAction = new QAction ( tr("TOT_DESK_FILE_NEW"),
450 rmgr->loadPixmap( "QAD", tr("ICON_FILE_NEW") ) ,
451 tr("MEN_DESK_FILE_NEW"), CTRL+Key_N, this );
452 fileNewAction->setStatusTip ( tr("PRP_DESK_FILE_NEW") );
453 fileNewAction->setEnabled ( true );
454 QAD_ASSERT ( connect( fileNewAction, SIGNAL( activated() ), this, SLOT( onNewStudy() )));
455 fileNewAction->addTo( myStdToolBar );
456 fileNewAction->addTo( &myFilePopup );
457 myStdActions.insert ( FileNewId, fileNewAction );
460 QAction* fileOpenAction = new QAction( tr("TOT_DESK_FILE_OPEN"), rmgr->loadPixmap( "QAD", tr("ICON_FILE_OPEN") ),
461 tr("MEN_DESK_FILE_OPEN"), CTRL+Key_O, this );
462 fileOpenAction->setStatusTip ( tr("PRP_DESK_FILE_OPEN") );
463 fileOpenAction->setEnabled ( true );
464 QAD_ASSERT ( connect( fileOpenAction, SIGNAL( activated() ), this, SLOT( onOpenStudy() )));
465 fileOpenAction->addTo( myStdToolBar );
466 fileOpenAction->addTo( &myFilePopup );
467 myStdActions.insert ( FileOpenId, fileOpenAction );
470 QAction* fileLoadAction = new QAction( tr("TOT_DESK_FILE_LOAD"), rmgr->loadPixmap( "QAD", tr("ICON_FILE_LOAD") ),
471 tr("MEN_DESK_FILE_LOAD"), CTRL+Key_L, this );
472 fileLoadAction->setStatusTip ( tr("PRP_DESK_FILE_LOAD") );
473 fileLoadAction->setEnabled ( true );
474 QAD_ASSERT ( connect( fileLoadAction, SIGNAL( activated() ), this, SLOT( onLoadStudy() )));
475 fileLoadAction->addTo( &myFilePopup );
476 myStdActions.insert ( FileLoadId, fileLoadAction );
479 QAction* fileCloseAction = new QAction( "", rmgr->loadPixmap( "QAD", tr("ICON_FILE_CLOSE") ),
480 tr("MEN_DESK_FILE_CLOSE"), CTRL+Key_W, this );
481 fileCloseAction->setStatusTip ( tr("PRP_DESK_FILE_CLOSE") );
482 QAD_ASSERT ( connect( fileCloseAction, SIGNAL( activated() ), this, SLOT( onCloseStudy() )));
483 fileCloseAction->addTo( &myFilePopup );
484 myStdActions.insert ( FileCloseId, fileCloseAction );
487 myFilePopup.insertSeparator();
490 QAction* fileSaveAction = new QAction( tr("TOT_DESK_FILE_SAVE"), rmgr->loadPixmap( "QAD", tr("ICON_FILE_SAVE") ),
491 tr("MEN_DESK_FILE_SAVE"), CTRL+Key_S, this );
492 fileSaveAction->setStatusTip ( tr("PRP_DESK_FILE_SAVE") );
493 QAD_ASSERT ( connect( fileSaveAction, SIGNAL( activated() ), this, SLOT( onSaveStudy() )));
494 fileSaveAction->addTo( myStdToolBar );
495 fileSaveAction->addTo( &myFilePopup );
496 myStdActions.insert ( FileSaveId, fileSaveAction );
499 QAction* fileSaveAsAction = new QAction( "", tr("MEN_DESK_FILE_SAVEAS"), 0, this );
500 fileSaveAsAction->setStatusTip ( tr("PRP_DESK_FILE_SAVEAS") );
501 QAD_ASSERT ( connect( fileSaveAsAction, SIGNAL( activated() ),
502 this, SLOT( onSaveAsStudy() )));
503 fileSaveAsAction->addTo( &myFilePopup );
504 myStdActions.insert ( FileSaveAsId, fileSaveAsAction );
508 myFilePopup.insertSeparator();
511 QAction* filePropsAction = new QAction( "", QPixmap(), tr("MEN_DESK_FILE_PROPERTIES"), 0, this );
512 filePropsAction->setStatusTip ( tr("PRP_DESK_FILE_PROPERTIES") );
513 filePropsAction->setEnabled(false);
514 QAD_ASSERT ( connect( filePropsAction, SIGNAL( activated() ), this, SLOT( onStudyProperties() )));
515 filePropsAction->addTo( &myFilePopup );
516 myStdActions.insert ( FilePropsId, filePropsAction );
519 int id = myFilePopup.insertSeparator();
520 /* keep the position from which an application will insert its items
521 to menu 'File' at the time of customization of the desktop */
523 myFilePos = myFilePopup.indexOf( id ) + 1;
525 /* exit application */
526 QAction* exitAction = new QAction( "", tr("MEN_DESK_FILE_EXIT"),
528 exitAction->setStatusTip ( tr("PRP_DESK_FILE_EXIT") );
529 QAD_ASSERT ( connect( exitAction, SIGNAL( activated() ),
530 this, SLOT( onExit() )));
531 exitAction->addTo( &myFilePopup );
532 myStdActions.insert ( FileExitId, exitAction );
534 /* 'Edit' actions : provided by application only */
538 /* toolbars popup menu */
539 myViewPopup.insertItem( tr("MEN_DESK_VIEW_TOOLBARS"), &myToolBarsPopup );
540 QAD_ASSERT( connect ( &myViewPopup, SIGNAL(aboutToShow()),
541 this, SLOT(onToolBarPopupAboutToShow()) ));
544 QAction* viewStatusBarAction = new QAction( "",
545 tr("MEN_DESK_VIEW_STATUSBAR"),
547 viewStatusBarAction->setStatusTip ( tr("PRP_DESK_VIEW_STATUSBAR") );
548 viewStatusBarAction->setOn( true );
549 QAD_ASSERT(connect( viewStatusBarAction, SIGNAL(activated()), this, SLOT(onViewStatusBar() )));
550 viewStatusBarAction->addTo( &myViewPopup );
551 myStdActions.insert( ViewStatusBarId, viewStatusBarAction );
553 // myViewPopup.insertItem( tr("MEN_DESK_SELECTION_MODE"), &mySelectionModePopup );
555 QAction* SelectionPointAction = new QAction( "", tr("MEN_DESK_SELECTION_POINT"), 0, this, 0, true );
556 QAD_ASSERT(connect( SelectionPointAction, SIGNAL(activated()), this, SLOT(onSelectionMode() )));
557 SelectionPointAction->addTo( &mySelectionModePopup );
558 myStdActions.insert( SelectionPointId, SelectionPointAction );
560 QAction* SelectionEdgeAction = new QAction( "", tr("MEN_DESK_SELECTION_EDGE"), 0, this, 0, true );
561 QAD_ASSERT(connect( SelectionEdgeAction, SIGNAL(activated()), this, SLOT(onSelectionMode() )));
562 SelectionEdgeAction->addTo( &mySelectionModePopup );
563 myStdActions.insert( SelectionEdgeId, SelectionEdgeAction );
565 QAction* SelectionCellAction = new QAction( "", tr("MEN_DESK_SELECTION_CELL"), 0, this, 0, true );
566 QAD_ASSERT(connect( SelectionCellAction, SIGNAL(activated()), this, SLOT(onSelectionMode() )));
567 SelectionCellAction->addTo( &mySelectionModePopup );
568 myStdActions.insert( SelectionCellId, SelectionCellAction );
570 QAction* SelectionActorAction = new QAction( "", tr("MEN_DESK_SELECTION_ACTOR"), 0, this, 0, true );
571 QAD_ASSERT(connect( SelectionActorAction, SIGNAL(activated()), this, SLOT(onSelectionMode() )));
572 SelectionActorAction->addTo( &mySelectionModePopup );
573 myStdActions.insert( SelectionActorId, SelectionActorAction );
574 SelectionActorAction->setOn(true);
576 myViewPos = myViewPopup.count();
579 QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
582 if(!resMgr->loadResources( "ToolsGUI", msg ))
584 //NRI QCString errMsg;
585 // errMsg.sprintf( "Do not load all resources for module ToolsGUI.\n" );
586 QMessageBox::warning( this, tr("WRN_WARNING"), msg, tr ("BUT_OK") );
590 myOperatorMenus = new QAD_OperatorMenus(this);
591 myXmlHandler = new QAD_XmlHandler();
592 ASSERT(myXmlHandler) ;
593 myXmlHandler->setMainWindow(this);
594 if ( myXmlHandler->setComponent( resMgr->resources( "ToolsGUI" ) ) ) {
595 QString language = resMgr->language( "ToolsGUI" );
596 QString ToolsXml = QString( "Tools_" ) + language + QString( ".xml" );
598 //ToolsXml = resMgr->resources("ToolsGUI") ;
599 //ToolsXml = QAD_Tools::addSlash(ToolsXml) ;
600 //ToolsXml = ToolsXml + "Tools_" + language + ".xml" ;
601 ToolsXml = QAD_Tools::addSlash( resMgr->findFile( ToolsXml, "ToolsGUI" ) ) + ToolsXml;
603 QFile file( QAD_Tools::unix2win( ToolsXml ) );
604 if ( file.exists() && file.open( IO_ReadOnly ) ) {
606 QXmlInputSource source( file );
607 QXmlSimpleReader reader;
608 reader.setContentHandler( myXmlHandler );
609 reader.setErrorHandler( myXmlHandler );
610 bool ok = reader.parse( source );
613 QMessageBox::critical( 0,
614 tr( "INF_PARSE_ERROR" ),
615 tr( myXmlHandler->errorProtocol() ) );
617 myMenusList=myXmlHandler->myMenusList;
618 myActiveMenus=myMenusList.at(0);
619 myOperatorMenus->showMenuBar(0);
620 myActiveMenus->showAllToolBars();
626 if ( myToolsPopup.count() == 0 ) {
627 myMainMenu->removeItem(5);
631 /* Viewer BackgroundColor */
632 myPrefPopup.insertItem( tr("MEN_DESK_PREF_VIEWER"), &myViewerPopup );
634 QAction* viewerOCCAction = new QAction( "", tr("MEN_DESK_PREF_VIEWER_OCC"), 0, this );
635 QAD_ASSERT(connect( viewerOCCAction, SIGNAL(activated()), this, SLOT(onViewerOCC() )));
636 viewerOCCAction->addTo( &myViewerPopup );
637 myStdActions.insert( PrefViewerOCCId, viewerOCCAction );
639 QAction* viewerVTKAction = new QAction( "", tr("MEN_DESK_PREF_VIEWER_VTK"), 0, this );
640 QAD_ASSERT(connect( viewerVTKAction, SIGNAL(activated()), this, SLOT(onViewerVTK() )));
641 viewerVTKAction->addTo( &myViewerPopup );
642 myStdActions.insert( PrefViewerVTKId, viewerVTKAction );
644 QAction* graphSupervisorAction = new QAction( "", tr("MEN_DESK_PREF_GRAPH_SUPERVISOR"), 0, this );
645 QAD_ASSERT(connect( graphSupervisorAction, SIGNAL(activated()), this, SLOT(onGraphSupervisor() )));
646 graphSupervisorAction->addTo( &myViewerPopup );
647 myStdActions.insert( PrefGraphSupervisorId, graphSupervisorAction );
649 QAction* viewerPlot2dAction = new QAction( "", tr("MEN_DESK_PREF_VIEWER_PLOT2D"), 0, this );
650 QAD_ASSERT(connect( viewerPlot2dAction, SIGNAL(activated()), this, SLOT(onPlot2d() )));
651 viewerPlot2dAction->addTo( &myViewerPopup );
652 myStdActions.insert( PrefViewerPlot2dId, viewerPlot2dAction );
654 //VRV: T2.5 - add default viewer
655 QString viewerValue = QAD_CONFIG->getSetting( "Viewer:DefaultViewer" );
657 int aViewerValue = viewerValue.toInt( &ok, 10 );
658 if (!ok || aViewerValue < VIEW_OCC || aViewerValue >= VIEW_TYPE_MAX)
659 aViewerValue = VIEW_VTK;
661 myPrefPopup.insertItem( tr("MEN_DESK_PREF_DEFAULT_VIEWER"), &myDefaultViewer );
662 QActionGroup* myQAG = new QActionGroup ( this);
663 QAction* viewerOCCAction1 = new QAction( "", tr("MEN_DESK_PREF_VIEWER_OCC"), 0, this );
664 viewerOCCAction1->setToggleAction ( true);
665 viewerOCCAction1->setOn ( aViewerValue == VIEW_OCC );
666 myQAG->insert( viewerOCCAction1 );
667 myStdActions.insert( DefaultViewerOCCId, viewerOCCAction1 );
669 QAction* viewerVTKAction1 = new QAction( "", tr("MEN_DESK_PREF_VIEWER_VTK"), 0, this );
670 viewerVTKAction1->setToggleAction ( true);
671 viewerVTKAction1->setOn ( aViewerValue == VIEW_VTK );
672 myQAG->insert( viewerVTKAction1 );
673 myStdActions.insert( DefaultViewerVTKId, viewerVTKAction1 );
675 /* Remove Supervisor viewer from setting the background */
676 // QAction* graphSupervisorAction1 = new QAction( "", tr("MEN_DESK_PREF_GRAPH_SUPERVISOR"), 0, this );
677 // graphSupervisorAction1->setToggleAction ( true);
678 // graphSupervisorAction1->setOn ( aViewerValue == VIEW_GRAPHSUPERV );
679 // myQAG->insert( graphSupervisorAction1 );
680 // myStdActions.insert( DefaultGraphSupervisorId, graphSupervisorAction1 );
682 QAction* viewerPlot2dAction1 = new QAction( "", tr("MEN_DESK_PREF_VIEWER_PLOT2D"), 0, this );
683 viewerPlot2dAction1->setToggleAction ( true);
684 viewerPlot2dAction1->setOn ( aViewerValue == VIEW_PLOT2D );
685 myQAG->insert( viewerPlot2dAction1 );
686 myStdActions.insert( DefaultPlot2dId, viewerPlot2dAction1 );
688 myQAG->addTo( &myDefaultViewer );
689 QAD_ASSERT(connect( myQAG, SIGNAL(selected(QAction * )), this, SLOT(onDefaultViewer(QAction *) )));
690 //VRV: T2.5 - add default viewer
692 QAction* viewerTrihedronAction = new QAction( "", tr("MEN_DESK_PREF_VIEWER_TRIHEDRON"), 0, this );
693 QAD_ASSERT(connect( viewerTrihedronAction, SIGNAL(activated()), this, SLOT(onViewerTrihedron() )));
694 viewerTrihedronAction->addTo( &myPrefPopup );
695 myStdActions.insert( PrefViewerTrihedronId, viewerTrihedronAction );
697 QAction* consoleFontAction = new QAction( "", tr("MEN_DESK_PREF_CONSOLE_FONT"), 0, this );
698 QAD_ASSERT(connect( consoleFontAction, SIGNAL(activated()), this, SLOT(onConsoleFontAction() )));
699 consoleFontAction->addTo( &myPrefPopup );
700 myStdActions.insert( PrefConsoleFontId, consoleFontAction );
703 QAction* multiFileSaveAction = new QAction( "", tr("MEN_DESK_PREF_MULTI_FILE_SAVE"), 0, this, 0, true );
704 QAD_ASSERT(connect( multiFileSaveAction, SIGNAL(activated()), this, SLOT(onMultiFileSave() )));
705 multiFileSaveAction->setToggleAction( true );
706 QString MultiSave = QAD_CONFIG->getSetting("Desktop:MultiFileSave");
707 multiFileSaveAction->setOn( MultiSave.compare( aTrueQString ) == 0 );
708 multiFileSaveAction->addTo( &myPrefPopup );
709 myStdActions.insert( PrefMultiFileSave, multiFileSaveAction );
711 myPrefPopup.insertSeparator();
714 myPrefPopup.insertItem( tr("MEN_DESK_PREF_OBJECTBROWSER"), &myObjBrowserPopup );
716 QAction* objectBrowserEntryAction = new QAction( "", tr("MEN_DESK_PREF_OBJECTBROWSER_ENTRY"), 0, this, 0, true );
717 QAD_ASSERT(connect( objectBrowserEntryAction, SIGNAL(activated()), this, SLOT(onObjectBrowser() )));
718 objectBrowserEntryAction->setToggleAction(true);
719 QString AddColumn = QAD_CONFIG->getSetting("ObjectBrowser:AddColumn");
721 if ( AddColumn.compare( aTrueQString ) == 0 )
722 objectBrowserEntryAction->setOn(true);
724 objectBrowserEntryAction->setOn(false);
726 objectBrowserEntryAction->addTo( &myObjBrowserPopup );
727 myStdActions.insert( PrefObjectBrowserEntryId, objectBrowserEntryAction );
729 QAction* objectBrowserValueAction = new QAction( "", tr("MEN_DESK_PREF_OBJECTBROWSER_VALUE"), 0, this, 0, true );
730 QAD_ASSERT(connect( objectBrowserValueAction, SIGNAL(activated()), this, SLOT(onObjectBrowser() )));
731 objectBrowserValueAction->setToggleAction(true);
732 QString ValueColumn = QAD_CONFIG->getSetting("ObjectBrowser:ValueColumn");
734 if ( ValueColumn.compare( aTrueQString ) == 0 )
735 objectBrowserValueAction->setOn(true);
737 objectBrowserValueAction->setOn(false);
739 objectBrowserValueAction->addTo( &myObjBrowserPopup );
740 myStdActions.insert( PrefObjectBrowserValueId, objectBrowserValueAction );
742 QAction* objectBrowserIAPPAction = new QAction( "", tr("MEN_DESK_PREF_OBJECTBROWSER_IAPP"), 0, this, 0, true );
743 QAD_ASSERT(connect( objectBrowserIAPPAction, SIGNAL(activated()), this, SLOT(onObjectBrowser() )));
744 objectBrowserIAPPAction->setToggleAction(true);
745 QString showIAPP = QAD_CONFIG->getSetting("ObjectBrowser:IAPP");
747 if ( showIAPP.compare( aTrueQString ) == 0 )
748 objectBrowserIAPPAction->setOn(true);
750 objectBrowserIAPPAction->setOn(false);
752 objectBrowserIAPPAction->addTo( &myObjBrowserPopup );
753 myStdActions.insert( PrefObjectBrowserIAPPId, objectBrowserIAPPAction );
755 /* Chronological sorting of shapes on the entry creation */
756 QAction* objectBrowserCHRONO_SORTAction = new QAction( "", tr("MEN_DESK_PREF_OBJECTBROWSER_CHRONO_SORT"), 0, this, 0, true );
757 QAD_ASSERT(connect( objectBrowserCHRONO_SORTAction, SIGNAL(activated()), this, SLOT(onObjectBrowser() )));
758 objectBrowserCHRONO_SORTAction->setToggleAction(true);
759 QString showSORT = QAD_CONFIG->getSetting("ObjectBrowser:CHRONO_SORT");
761 if ( showSORT.compare( aTrueQString ) == 0 )
762 objectBrowserCHRONO_SORTAction->setOn(true) ;
764 objectBrowserCHRONO_SORTAction->setOn(false) ;
766 objectBrowserCHRONO_SORTAction->addTo( &myObjBrowserPopup );
767 myStdActions.insert( PrefObjectBrowserCHRONO_SORTId, objectBrowserCHRONO_SORTAction ) ;
769 myPrefPopup.insertSeparator();
771 QAction* dirAction = new QAction( "", tr("MEN_DESK_PREF_DIRICTORIES"), ALT+Key_D, this );
772 QAD_ASSERT(connect( dirAction, SIGNAL(activated()), this, SLOT(onDirList() )));
773 dirAction->addTo( &myPrefPopup );
774 myStdActions.insert( PrefDirsId, dirAction );
776 myPrefPopup.insertSeparator();
778 QAction* saveAction = new QAction( "", tr("MEN_DESK_PREF_SAVE"), 0, this );
779 QAD_ASSERT(connect( saveAction, SIGNAL(activated()), this, SLOT(onSavePref() )));
780 saveAction->addTo( &myPrefPopup );
781 myStdActions.insert( PrefSaveId, saveAction );
783 /* 'Window' actions */
786 myWindowPopup.insertItem( tr("MEN_DESK_WINDOW_NEW3D"), &myNewViewPopup, WindowNew3dId );
788 QAction* viewOCCAction = new QAction( "", tr("MEN_DESK_VIEW_OCC"), ALT+Key_O, this );
789 QAD_ASSERT(connect( viewOCCAction, SIGNAL(activated()), this, SLOT(onNewWindow3d() )));
790 viewOCCAction->addTo( &myNewViewPopup );
791 myStdActions.insert( ViewOCCId, viewOCCAction );
793 QAction* viewVTKAction = new QAction( "", tr("MEN_DESK_VIEW_VTK"), ALT+Key_V, this );
794 QAD_ASSERT(connect( viewVTKAction, SIGNAL(activated()), this, SLOT(onNewWindow3d() )));
795 viewVTKAction->addTo( &myNewViewPopup );
796 myStdActions.insert( ViewVTKId, viewVTKAction );
798 QAction* viewPlot2dAction = new QAction( "", tr("MEN_DESK_VIEW_PLOT2D"), ALT+Key_P, this );
799 QAD_ASSERT(connect( viewPlot2dAction, SIGNAL(activated()), this, SLOT(onNewWindow3d() )));
800 viewPlot2dAction->addTo( &myNewViewPopup );
801 myStdActions.insert( ViewPlot2dId, viewPlot2dAction );
803 // QAction* windowNew3dAction = new QAction( "",/* rmgr->loadPixmap( "QAD", tr("ICON_DESK_WINDOW_NEW3D") ), */
804 /*tr("MEN_DESK_WINDOW_NEW3D"), 0, this );
805 windowNew3dAction->addTo( &myWindowPopup );
806 QAD_ASSERT( connect( windowNew3dAction, SIGNAL(activated()), this ,
807 SLOT( onNewWindow3d() )));
808 myStdActions.insert( WindowNew3dId, windowNew3dAction );
814 QAction* windowCascadeAction = new QAction( "", rmgr->loadPixmap( "QAD", tr("ICON_DESK_WINDOW_CASCADE") ),
815 tr("MEN_DESK_WINDOW_CASCADE"), 0, this );
816 windowCascadeAction->setStatusTip ( tr("PRP_DESK_WINDOW_CASCADE") );
817 QAD_ASSERT( connect( windowCascadeAction, SIGNAL(activated()), this,
818 SLOT( onCascade() )));
819 myStdActions.insert( WindowCascadeId, windowCascadeAction );
822 QAction* windowTileAction = new QAction( "", rmgr->loadPixmap( "QAD", tr("ICON_DESK_WINDOW_TILE") ),
823 tr("MEN_DESK_WINDOW_TILE"), 0, this );
824 windowTileAction->setStatusTip ( tr("PRP_DESK_WINDOW_TILE") );
825 QAD_ASSERT( connect( windowTileAction, SIGNAL(activated()), myWorkspace, SLOT( tile() )));
826 myStdActions.insert( WindowTileId, windowTileAction );
828 QAD_ASSERT( connect ( &myWindowPopup, SIGNAL(aboutToShow()),
829 this, SLOT(onWindowPopupAboutToShow()) ));
833 QAction* helpContentsAction = new QAction( "", tr("MEN_DESK_HELP_CONTENTS"), Key_F1, this );
834 helpContentsAction->setStatusTip ( tr("PRP_DESK_HELP_CONTENTS") );
835 QAD_ASSERT(connect( helpContentsAction, SIGNAL(activated()),
836 this, SLOT( onHelpContents() )));
837 helpContentsAction->addTo( &myHelpPopup );
838 myStdActions.insert( HelpContentsId , helpContentsAction );
841 // QAction* helpSearchAction = new QAction( "", tr("MEN_DESK_HELP_SEARCH"), 0, this );
842 // helpSearchAction->setStatusTip ( tr("PRP_DESK_HELP_SEARCH") );
843 // QAD_ASSERT( connect( helpSearchAction, SIGNAL(activated()), this, SLOT( onHelpSearch() )));
844 // helpSearchAction->addTo( &myHelpPopup );
845 // myStdActions.insert( HelpSearchId, helpSearchAction );
848 // QAction* helpWhatsThisAction = new QAction( "", tr("MEN_DESK_HELP_WHATSTHIS"), SHIFT+Key_F1, this );
849 // helpWhatsThisAction->setStatusTip ( tr("PRP_DESK_HELP_WHATSTHIS" ));
850 // QAD_ASSERT( connect( helpWhatsThisAction, SIGNAL(activated()), this, SLOT( whatsThis() )));
851 // helpWhatsThisAction->addTo( &myHelpPopup );
852 // myStdActions.insert( HelpWhatsThisId, helpWhatsThisAction );
853 // (void)QWhatsThis::whatsThisButton( myStdToolBar );
855 id = myHelpPopup.insertSeparator();
856 myHelpPos = myHelpPopup.indexOf( id );
859 QAction* helpAboutAction = new QAction( "", tr("MEN_DESK_HELP_ABOUT"), 0, this );
860 helpAboutAction->setStatusTip ( tr("PRP_DESK_HELP_ABOUT") );
861 QAD_ASSERT( connect( helpAboutAction, SIGNAL(activated()), this, SLOT( onHelpAbout() )));
862 helpAboutAction->addTo( &myHelpPopup );
863 myStdActions.insert(HelpAboutId, helpAboutAction );
869 Adds the given application into the list of supported applications
871 void QAD_Desktop::addApplication(QAD_Application* app)
873 /* add only if is not already in the list */
874 if ( myApps.findRef( app ) == -1 )
876 myApps.append( app );
878 /* set activation/deactivation listener */
879 QAD_ASSERT ( connect( app, SIGNAL(appActivated(QAD_Application*)),
880 this, SLOT(onActivateApp(QAD_Application*))) );
882 QAD_ASSERT ( connect( app, SIGNAL(appDeactivated(QAD_Application*)),
883 this, SLOT(onDeactivateApp(QAD_Application*))) );
888 Displays the control panel of the application.
889 This function is called when the desktop is shown first time.
891 void QAD_Desktop::showDesktop()
897 Closes Desktop. If <forceClose> is true query for exit will be skipped.
899 void QAD_Desktop::closeDesktop( bool forceClose )
902 myQueryClose = false;
907 Puts the message to the status bar
909 void QAD_Desktop::putInfo ( const QString& msg )
912 myStatusBar->message ( msg );
916 Puts the message to the status bar for ms milli-seconds
918 void QAD_Desktop::putInfo ( const QString& msg, int ms )
921 myStatusBar->message ( msg, ms );
925 Returns the standard toolbar
927 QMenuBar* QAD_Desktop::getMainMenuBar() const
933 Returns the standard toolbar
935 QToolBar* QAD_Desktop::getStdToolBar() const
941 Updates desktop panel (menu, toolbar and status bar) according to current state of
942 the application. Calls update() for the active application.
943 The command { UD_ADD_APP or UD_REMOVE_APP ) specifies the desktop components
944 will be changed according to new active application.
945 This function is called after activating new study, closing current study etc.
947 void QAD_Desktop::updateDesktop( UpdateCommand cmd )
950 updateToolBars( cmd );
951 updateStatusBar( cmd );
956 Updates the desktop caption
958 void QAD_Desktop::updateCaption( UpdateCommand cmd )
960 if ( cmd == ActivateApp )
961 { /* application's icon and title */
962 setIcon( myActiveApp->getApplicationIcon() );
963 setCaption( myActiveApp->getApplicationName() );
966 { /* default icon and title */
967 setIcon( myDefaultIcon );
968 setCaption( myDefaultTitle );
973 Updates status bar when a new application becomes current
975 void QAD_Desktop::updateStatusBar( UpdateCommand cmd )
979 bool activate = ( cmd == ActivateApp );
980 myActiveApp->updateStatusBar ( myStatusBar, activate );
985 Updates toolbars according to current active application.
986 This function is called from updateDesktop().
988 void QAD_Desktop::updateToolBars( UpdateCommand cmd )
992 bool activate = ( cmd == ActivateApp );
993 myActiveApp->updateToolBars ( activate );
998 Updates main menu bar of the application when application is activated
1000 This function is called by updateDesktop()
1002 void QAD_Desktop::updateMenu( UpdateCommand cmd )
1006 bool activate = ( cmd == ActivateApp );
1007 myActiveApp->updateFilePopup( &myFilePopup, activate, myFilePos );
1008 myActiveApp->updateEditPopup( &myEditPopup, activate, myEditPos );
1009 myActiveApp->updateViewPopup( &myViewPopup, activate, myViewPos );
1010 myActiveApp->updateHelpPopup( &myHelpPopup, activate, myHelpPos );
1011 myActiveApp->updateMainMenu( myMainMenu, activate, myMainMenuPos );
1014 Since 'Edit' popup is completely customized by applications
1015 desktop doesn't show it in main menubar without the active
1016 application and we insert/remove this popup from the menubar
1017 when activating/deactivating applications.
1019 We can't have 'Edit' popup be customized by an application
1020 via UpdateMainMenu() method because applications may insert
1021 its items to the menubar only AFTER 'View' item ( this fact
1022 is respected by myMainMenuPos ) and the possibility of an
1023 application to add its items into any arbitrary positions of
1024 the main menubar requires a bit sophisticated implementation,
1025 so we decided to avoid it, sorry :-(.
1027 #if defined( DEBUG )
1029 /* applications MUST clear 'Edit' after themselves */
1030 QAD_ASSERT_DEBUG_ONLY( !myEditPopup.count() );
1033 if ( activate ) /* insert after 'File' item */
1034 myMainMenu->insertItem( tr("MEN_DESK_EDIT"), &myEditPopup, 3, 1 );
1036 myMainMenu->removeItem( 3 );
1041 Returns icon file name used by the application
1043 const QPixmap& QAD_Desktop::getDefaultIcon() const
1045 static QPixmap defaultPixmap( QAD_Desktop::getResourceManager()->loadPixmap( "QAD",
1046 tr("ICON_DESK_DEFAULTICON") ));
1047 return defaultPixmap;
1051 Returns name of the application used as the title of desktop panel
1053 const QString& QAD_Desktop::getDefaultTitle() const
1055 static QString defaultTitle ( tr("DESK_DEFAULTTITLE") );
1056 return defaultTitle;
1060 Returns default name of new studies
1062 const QString& QAD_Desktop::getDefaultStudyName() const
1064 static QString defaultStudyName( tr("DESK_DEFAULTDOC") );
1065 return defaultStudyName;
1069 Returns next name for new study
1071 QString QAD_Desktop::getNewStudyName()
1074 number.sprintf( "%d", ++myCntUntitled );
1075 return ( getDefaultStudyName() + number );
1079 Searches QAD_Study corresponding to <study>, returns NULL if fails
1081 QAD_Study* QAD_Desktop::findStudy( SALOMEDS::Study_ptr theStudy )
1083 for ( QAD_Application* app = myApps.first(); app; app = myApps.next() ) {
1084 QList<QAD_Study> studies;
1085 studies.setAutoDelete( false );
1086 studies = app->getStudies();
1087 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
1088 if ( study->getStudyDocument()->_is_equivalent( theStudy ) )
1096 Returns current active application
1098 QAD_Application* QAD_Desktop::getActiveApp() const
1104 Returns current active study
1106 QAD_Study* QAD_Desktop::getActiveStudy() const
1108 return myActiveStudy;
1114 QWorkspaceP* QAD_Desktop::getMainFrame() const
1120 Find or load Engine, given a container name and an engine name
1122 Engines::Component_var QAD_Desktop::getEngine(const char *containerName,
1123 const char *componentName)
1125 Engines::Component_var eng =
1126 myEnginesLifeCycle->FindOrLoad_Component(containerName,
1131 QString QAD_Desktop::getComponentName(const char *componentUserName)
1133 if ( mapComponentName.contains(componentUserName) )
1134 return mapComponentName[ componentUserName ] ;
1139 QString QAD_Desktop::getComponentUserName(const char *componentName)
1141 QMap<QString,QString>::Iterator it;
1142 for( it = mapComponentName.begin(); it != mapComponentName.end(); ++it )
1143 if (it.data() == componentName )
1149 gets application Help Window (and creates if necessary)
1151 QAD_HelpWindow* QAD_Desktop::getHelpWindow()
1153 if (!myHelpWindow) {
1154 myHelpWindow = new QAD_HelpWindow();
1156 QMap<QString,QString>::Iterator it;
1157 for( it = mapComponentName.begin(); it != mapComponentName.end(); ++it ) {
1161 // look for index.html and set homeDir
1162 // 1. $(MODULE_ROOT_DIR)/doc/index.html
1163 // 2. $(MODULE_ROOT_DIR)/doc/html/index.html
1164 // 3. $(MODULE_ROOT_DIR)/doc/html/html/index.html
1166 if (dir = getenv( QString( it.data() + "_ROOT_DIR")) ) {
1167 root = QAD_Tools::addSlash( QAD_Tools::addSlash(dir) + QAD_Tools::addSlash("share") + QAD_Tools::addSlash("salome") + "doc" );
1168 if ( QFileInfo( root + "index.html" ).exists() ) {
1169 helpContext( root + "index.html", "" );
1172 root = QAD_Tools::addSlash( root + "html" );
1173 if ( QFileInfo( root + "index.html" ).exists() ) {
1174 helpContext( root + "index.html", "" );
1177 root = QAD_Tools::addSlash( root + "html" );
1178 if ( QFileInfo( root + "index.html" ).exists() ) {
1179 helpContext( root + "index.html", "" );
1186 connect(myHelpWindow, SIGNAL(helpWindowClosed()), this, SLOT(onHelpWindowClosed()));
1188 return myHelpWindow;
1192 Called when desktop is closing
1194 void QAD_Desktop::closeEvent ( QCloseEvent* e )
1196 bool doClose = true;
1197 if ( myQueryClose ) {
1198 doClose = QAD_MessageBox::info2 ( this, tr("INF_DESK_EXIT"),
1199 tr("QUE_DESK_EXIT"), tr ("BUT_OK"),
1200 tr ("BUT_CANCEL"), QAD_YES,
1201 QAD_NO, QAD_NO ) == QAD_YES;
1205 for ( QAD_Application* app = myApps.first(); app; app = myApps.next() ) {
1206 QList<QAD_Study>& studies = app->getStudies();
1207 for(QAD_Study* study = studies.first(); study != 0; study = studies.next()) {
1208 if(myQueryClose && study->getStudyDocument()->IsModified()) {
1209 SALOMEGUI_CloseDlg aDlg( this );
1210 switch ( aDlg.exec() ) {
1212 if ( !onSaveStudy( study ) ) {
1213 putInfo( tr("INF_CANCELLED") );
1224 putInfo( tr("INF_CANCELLED") );
1232 myQueryClose = true;
1233 doClose ? e->accept() : e->ignore();
1237 Called when desktop is resized
1239 void QAD_Desktop::resizeEvent( QResizeEvent* e )
1241 QMainWindow::resizeEvent( e );
1242 myWorkspace->setGeometry( 1,1, centralWidget()->width()-2,
1243 centralWidget()->height()-2 );
1248 Terminates the application.
1250 void QAD_Desktop::onExit()
1255 /************************************************************************
1257 *************************************************************************/
1261 If several application are supported it displays dialog window
1262 to choose type of study.
1264 void QAD_Desktop::createStudy(){
1267 void QAD_Desktop::onNewStudy()
1269 unsigned numApps = myApps.count();
1272 onNewStudy ( myApps.at(0) );
1273 else { /* select the type of application for new study */
1274 Desktop_AppSelectionDlg selDlg( this, myApps );
1275 if ( selDlg.exec() == QDialog::Accepted ) {
1276 onNewStudy ( selDlg.selectedApp() );
1279 } else { /* no applications available in desktop */
1280 QAD_MessageBox::error1( this,
1282 tr("ERR_APP_NOAPP"),
1288 Creates new study for the given application.
1289 Calls the respective function of the application class.
1291 void QAD_Desktop::onNewStudy( QAD_Application* app )
1295 /* create new study of the specific app */
1296 putInfo ( tr ("INF_DOC_CREATING") );
1297 QAD_Study* newStudy = app->newStudy();
1300 /* can't create new study */
1301 QAD_MessageBox::error1( this, tr("ERR_ERROR"),
1302 tr("ERR_DOC_CANTCREATE"),
1305 putInfo ( tr("INF_READY") );
1309 Loads the existing study.
1311 void QAD_Desktop::onLoadStudy()
1313 QString name, studyname, ext;
1315 SALOMEGUI_LoadStudiesDlg* aDlg = new SALOMEGUI_LoadStudiesDlg( this, "Load Study", TRUE);
1317 CORBA::Object_var obj = myNameService->Resolve("/myStudyManager");
1318 SALOMEDS::StudyManager_var myStudyMgr = SALOMEDS::StudyManager::_narrow(obj);
1319 ASSERT(! CORBA::is_nil(myStudyMgr));
1320 SALOMEDS::ListOfOpenStudies_var List = myStudyMgr->GetOpenStudies();
1321 for (unsigned int ind = 0; ind < List->length();ind++) {
1322 studyname = List[ind];
1323 aDlg->ListComponent->insertItem( studyname );
1326 int retVal = aDlg->exec();
1327 studyname = aDlg->ListComponent->currentText();
1329 if (retVal == QDialog::Rejected)
1332 if ( studyname.isNull() || studyname.isEmpty() )
1336 name.replace( QRegExp(":"), "/" );
1339 Try to associate an application to the opened study.
1340 Assumed that the association study<->application is unique.
1342 bool appFound = false;
1343 putInfo ( tr("INF_DOC_OPENING") + " " + name );
1344 for ( QAD_Application* app = myApps.first(); app; app = myApps.next() )
1346 /* application found */
1347 if ( app->isStudyOpened( name ) )
1349 /* already opened: prompt for reopen */
1350 if ( QAD_MessageBox::warn2 ( this, tr("WRN_WARNING"),
1351 tr("QUE_DOC_ALREADYOPEN").arg( name ),
1352 tr ("BUT_YES"), tr ("BUT_NO"), QAD_YES, QAD_NO,
1353 QAD_NO ) == QAD_NO )
1355 putInfo ( tr("INF_READY") );
1358 /* now the study is closed to be re-opened */
1359 //don't ask user to remove study permanently
1360 if (app->getStudyByName ( name ) != NULL)
1361 onCloseStudy ( app->getStudyByName ( name ), false );
1362 else if (app->getStudyByName ( QAD_Tools::getFileNameFromPath( name, false )) != NULL)
1363 onCloseStudy ( app->getStudyByName ( QAD_Tools::getFileNameFromPath( name, false )), false );
1367 /* open the study */
1368 QAD_Study* openStudy = app->loadStudy( studyname );
1370 QAD_MessageBox::error1( this,
1372 tr("ERR_DOC_CANTOPEN") + "\n" + name,
1379 QAD_MessageBox::error1( this,
1381 tr("ERR_DOC_UNKNOWNTYPE"),
1384 putInfo ( tr("INF_READY") );
1388 Opens the existing study.
1389 Displays select file dialog and calls corresponding function of
1391 (application is defined according to extension of selected file).
1393 void QAD_Desktop::onOpenStudy()
1397 /* Select a file to open */
1398 name = selectFileName ( true );
1399 if ( name.isNull() || name.isEmpty() )
1402 // Workaround for non-existent files
1404 if (!fi.exists() || !fi.isFile()) {
1405 QAD_MessageBox::error1 ( this, tr("ERR_ERROR"),
1406 tr("ERR_DOC_CANTOPEN") +": " + name,
1411 CORBA::Object_var obj = myNameService->Resolve("/myStudyManager");
1412 SALOMEDS::StudyManager_var myStudyMgr = SALOMEDS::StudyManager::_narrow(obj);
1413 ASSERT(! CORBA::is_nil(myStudyMgr));
1414 SALOMEDS::ListOfOpenStudies_var List = myStudyMgr->GetOpenStudies();
1415 for (unsigned int ind = 0; ind < List->length();ind++) {
1416 QString NameExistingStudy(List[ind]);
1417 QString NameOpeningStudy = QAD_Tools::getFileNameFromPath( name, false );
1419 if ( NameExistingStudy.compare( NameOpeningStudy ) == 0 ) {
1420 if ( QAD_MessageBox::warn2 ( this, tr("WRN_WARNING"),
1421 tr("QUE_DOC_ALREADYEXIST").arg( name ),
1422 tr ("BUT_YES"), tr ("BUT_NO"), QAD_YES, QAD_NO,
1423 QAD_NO ) == QAD_NO )
1425 putInfo ( tr("INF_READY") );
1437 Try to associate an application to the opened study.
1438 Assumed that the association study<->application is unique.
1440 bool appFound = false;
1441 putInfo ( tr("INF_DOC_OPENING") + " " + name );
1442 for ( QAD_Application* app = myApps.first(); app; app = myApps.next() )
1444 QString ext = QAD_Tools::getFileExtensionFromPath ( name );
1445 if ( app->getStudyExtension() == ext )
1447 /* application found */
1448 if ( app->isStudyOpened( name ) )
1450 /* already opened: prompt for reopen */
1451 if ( QAD_MessageBox::warn2 ( this, tr("WRN_WARNING"),
1452 tr("QUE_DOC_ALREADYOPEN").arg( name ),
1453 tr ("BUT_YES"), tr ("BUT_NO"), QAD_YES, QAD_NO,
1454 QAD_NO ) == QAD_NO )
1456 putInfo ( tr("INF_READY") );
1459 /* now the study is closed to be re-opened */
1460 //don't ask user to remove study permanently
1461 if (app->getStudyByName ( name ) != NULL)
1462 onCloseStudy ( app->getStudyByName ( name ), false );
1463 else if (app->getStudyByName ( QAD_Tools::getFileNameFromPath( name, false )) != NULL)
1464 onCloseStudy ( app->getStudyByName ( QAD_Tools::getFileNameFromPath( name, false )), false );
1468 /* open the study */
1469 QAD_Study* openStudy = app->openStudy( name );
1471 QAD_MessageBox::error1( this,
1473 tr("ERR_DOC_CANTOPEN") + "\n" + name,
1475 } else if (myActiveComp != "") {
1476 QApplication::setOverrideCursor( Qt::waitCursor );
1477 loadComponentData(mapComponentName[myActiveComp]);
1478 openStudy->updateObjBrowser(true);
1479 QApplication::restoreOverrideCursor();
1487 QAD_MessageBox::error1( this,
1489 tr("ERR_DOC_UNKNOWNTYPE"),
1492 putInfo ( tr("INF_READY") );
1495 bool QAD_Desktop::loadComponentData( const QString& compName )
1497 // Open component's data in active study if any
1498 MESSAGE("loadComponentData(): Opening " << compName << " component data ")
1499 if (!myActiveStudy) {
1500 MESSAGE("loadComponentData(): No active study exists")
1504 Engines::Component_var comp ;
1505 if ( compName.compare("SUPERV") == 0 ) {
1506 comp = getEngine( "SuperVisionContainer", compName) ;
1509 /* comp = ( compName.compare("Data1") != 0 ) ? getEngine( "FactoryServer", compName) :
1510 getEngine( "FactoryServerPy", compName);
1512 comp = getEngine( "FactoryServer", compName);
1513 if ( comp->_is_nil() )
1514 comp = getEngine( "FactoryServerPy", compName);
1517 SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
1518 SALOMEDS::SComponent_var SCO = SALOMEDS::SComponent::_narrow(aStudy->FindObject( getComponentUserName(compName) ));
1520 if (!SCO->_is_nil()) {
1521 if (!CORBA::is_nil(comp)) {
1522 SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
1523 if (!CORBA::is_nil(driver)) {
1524 SALOMEDS::StudyBuilder_var B = aStudy->NewBuilder();
1525 if (!CORBA::is_nil(B)) {
1526 QAD_Operation* op = new QAD_Operation( myActiveStudy );
1528 B->LoadWith(SCO,driver);
1534 MESSAGE("loadComponentData(): Driver is null");
1538 MESSAGE("loadComponentData(): Engine is null");
1542 MESSAGE("loadComponentData(): SComponent is null");
1550 Saves the active study
1552 bool QAD_Desktop::onSaveStudy()
1554 return onSaveStudy ( myActiveStudy );
1558 Saves the given study
1560 bool QAD_Desktop::onSaveStudy( QAD_Study* study )
1562 if ( !study ) return true;
1564 if ( !study->isSaved() )
1565 return onSaveAsStudy ( study );
1567 /* saving study... */
1568 QAD_Application* app = study->getApp();
1569 QAD_ASSERT_DEBUG_ONLY ( app );
1570 putInfo ( tr("INF_DOC_SAVING") + study->getTitle() );
1571 if ( !app->saveStudy( study ) )
1573 putInfo( tr("INF_CANCELLED") );
1578 putInfo ( tr("INF_DOC_SAVED").arg( "" ) );
1583 Saves the active study under a new name
1585 bool QAD_Desktop::onSaveAsStudy()
1587 return onSaveAsStudy( myActiveStudy );
1591 Saves the given study under a new name
1593 bool QAD_Desktop::onSaveAsStudy( QAD_Study* study )
1595 if ( !study ) return true;
1597 /* Save study in a format supported by its application
1599 QAD_Application* app = study->getApp();
1600 QAD_ASSERT_DEBUG_ONLY ( app );
1602 /* Select a file where to save
1604 QString name = selectFileName ( false );
1605 if ( name.isNull() || name.isEmpty() )
1607 putInfo( tr("INF_CANCELLED") );
1613 putInfo ( tr("INF_DOC_SAVING") + name );
1614 if ( !app->saveAsStudy( study, name ) ) {
1615 /* can't save the file */
1616 QAD_MessageBox::error1( this,
1618 tr("ERR_DOC_CANTWRITE") + "\n" + name,
1621 return false; /* cannot save */
1623 putInfo ( tr("INF_DOC_SAVED").arg( name ) );
1624 return true; /* saved ok */
1628 Closes the active study
1630 bool QAD_Desktop::onCloseStudy()
1632 bool close = this->onCloseStudy ( myActiveStudy, true );
1633 if ( close && !myXmlHandler->myIdList.IsEmpty() ) {
1636 myCombo->setCurrentItem (0);
1637 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
1638 aButton->setOn(false);
1645 Closes the given study and ask user to remove study
1646 from the study manager permanently
1648 bool QAD_Desktop::onCloseStudy( QAD_Study* study )
1650 return onCloseStudy( study, true );
1654 Closes the given study and ask user to remove study
1655 from the study manager permanently if ask is equal true
1657 bool QAD_Desktop::onCloseStudy( QAD_Study* study, bool ask )
1659 bool removePerm = false;
1663 SALOMEGUI_CloseDlg aDlg( this );
1664 int res = aDlg.exec();
1669 //if ( study->isModified() )
1670 if ( !onSaveStudy( study ) ) {
1671 putInfo( tr("INF_CANCELLED") );
1684 putInfo( tr("INF_CANCELLED") );
1688 /* close active component */
1689 if (!myXmlHandler->myIdList.IsEmpty())
1693 myCombo->setCurrentItem (0);
1694 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() )
1695 aButton->setOn(false);
1696 qApp->processEvents();
1698 /* close the study */
1699 return study->getApp()->closeStudy( study, removePerm );
1702 // Displays study properties dialog box
1703 void QAD_Desktop::onStudyProperties()
1705 if (myActiveStudy) {
1707 QAD_Operation* op = new QAD_Operation( myActiveStudy );
1710 SALOMEGUI_StudyPropertiesDlg aDlg(this);
1711 int res = aDlg.exec();
1713 if ( res == QDialog::Accepted && aDlg.isChanged() )
1718 // T2.12 - add the word "locked" to study frame captions if <myActiveStudy> study is locked
1719 myActiveStudy->updateCaptions();
1725 locate all windows in cascade mode
1728 void QAD_Desktop::onCascade()
1730 myWorkspace->cascade();
1731 int w = myWorkspace->width();
1732 int h = myWorkspace->height();
1733 QWidgetList wList = myWorkspace->windowList();
1734 QWidgetListIt it(wList);
1736 for(;it.current(); ++it)
1737 it.current()->resize(0.8*w, 0.8*h);
1741 called when help window closed
1743 void QAD_Desktop::onHelpWindowClosed()
1749 Called when 'view status bar' option
1752 void QAD_Desktop::onViewStatusBar()
1754 bool show = myStdActions.at( ViewStatusBarId )->isOn();
1755 if ( show == myStatusBar->isVisible() )
1758 myStatusBar->show();
1760 myStatusBar->hide();
1764 Called when View/Toolbars popup menu is about to show
1766 void QAD_Desktop::onToolBarPopupAboutToShow()
1768 myToolBarAction.clear();
1769 myToolBarsPopup.clear();
1770 QPtrList<QDockWindow> wlist = dockWindows();
1771 for ( QDockWindow* w = wlist.first(); w; w = wlist.next() ) {
1772 if ( w->inherits( "QToolBar" ) ) {
1773 QToolBar* tb = ( QToolBar* )w;
1774 if ( appropriate( tb ) ) {
1775 ToggleAction* a = new ToggleAction( tb->label(), tb->label(), 0, this, 0, true );
1776 a->setStatusTip ( tr("PRP_DESK_VIEW_TOOLBAR") );
1777 a->setOn( tb->isVisible() );
1778 QAD_ASSERT( connect( a, SIGNAL( toggledOn() ), tb, SLOT( show() ) ) );
1779 QAD_ASSERT( connect( a, SIGNAL( toggledOff() ), tb, SLOT( hide() ) ) );
1780 a->addTo( &myToolBarsPopup );
1781 myToolBarAction.append( a );
1788 Called on 'View\Selection Mode'
1790 void QAD_Desktop::onSelectionMode()
1792 const QAction* obj = (QAction*) sender();
1794 int SelectionMode = 4;
1796 if ( obj == myStdActions.at(SelectionActorId) ) {
1798 if ( obj->isOn() ) {
1799 myStdActions.at(SelectionCellId)->setOn(false);
1800 myStdActions.at(SelectionEdgeId)->setOn(false);
1801 myStdActions.at(SelectionPointId)->setOn(false);
1803 myStdActions.at(SelectionActorId)->setOn(true);
1805 } else if ( obj == myStdActions.at(SelectionCellId) ) {
1807 if ( obj->isOn() ) {
1808 myStdActions.at(SelectionActorId)->setOn(false);
1809 myStdActions.at(SelectionEdgeId)->setOn(false);
1810 myStdActions.at(SelectionPointId)->setOn(false);
1812 myStdActions.at(SelectionActorId)->setOn(true);
1814 } else if ( obj == myStdActions.at(SelectionEdgeId) ) {
1816 if ( obj->isOn() ) {
1817 myStdActions.at(SelectionActorId)->setOn(false);
1818 myStdActions.at(SelectionCellId)->setOn(false);
1819 myStdActions.at(SelectionPointId)->setOn(false);
1821 myStdActions.at(SelectionActorId)->setOn(true);
1823 } else if ( obj == myStdActions.at(SelectionPointId) ) {
1825 if ( obj->isOn() ) {
1826 myStdActions.at(SelectionEdgeId)->setOn(false);
1827 myStdActions.at(SelectionCellId)->setOn(false);
1828 myStdActions.at(SelectionActorId)->setOn(false);
1830 myStdActions.at(SelectionActorId)->setOn(true);
1833 QAD_StudyFrame* sf = myActiveApp->getActiveStudy()->getActiveStudyFrame();
1834 sf->getRightFrame()->getViewFrame()->SetSelectionMode( SelectionMode );
1836 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveApp->getActiveStudy()->getSelection() );
1837 Sel->SetSelectionMode( SelectionMode );
1841 Called on 'View\Selection Mode'
1843 void QAD_Desktop::SetSelectionMode(int mode, bool activeCompOnly)
1848 myStdActions.at(SelectionEdgeId)->setOn(false);
1849 myStdActions.at(SelectionCellId)->setOn(false);
1850 myStdActions.at(SelectionActorId)->setOn(false);
1851 myStdActions.at(SelectionPointId)->setOn(true);
1856 myStdActions.at(SelectionActorId)->setOn(false);
1857 myStdActions.at(SelectionCellId)->setOn(false);
1858 myStdActions.at(SelectionPointId)->setOn(false);
1859 myStdActions.at(SelectionEdgeId)->setOn(true);
1864 myStdActions.at(SelectionActorId)->setOn(false);
1865 myStdActions.at(SelectionEdgeId)->setOn(false);
1866 myStdActions.at(SelectionPointId)->setOn(false);
1867 myStdActions.at(SelectionCellId)->setOn(true);
1872 myStdActions.at(SelectionCellId)->setOn(false);
1873 myStdActions.at(SelectionEdgeId)->setOn(false);
1874 myStdActions.at(SelectionPointId)->setOn(false);
1875 myStdActions.at(SelectionActorId)->setOn(true);
1880 QAD_StudyFrame* sf = myActiveApp->getActiveStudy()->getActiveStudyFrame();
1881 if ( sf->getTypeView() == VIEW_VTK ) {
1882 sf->getRightFrame()->getViewFrame()->SetSelectionMode( mode );
1883 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveApp->getActiveStudy()->getSelection() );
1884 Sel->SetSelectionMode( mode, activeCompOnly );
1890 Called on 'Window\NewWindow3d'
1892 void QAD_Desktop::onNewWindow3d()
1896 //VRV: T2.5 - add default viewer
1897 QApplication::restoreOverrideCursor();
1898 SALOMEGUI_ViewChoiceDlg *choice = new SALOMEGUI_ViewChoiceDlg(this, "", TRUE);
1899 int r = choice->exec();
1902 myActiveApp->getActiveStudy()->newWindow3d(QString(""),(ViewType)(choice->getSelectedViewer()));
1904 //VRV: T2.5 - add default viewer
1906 const QAction* obj = (QAction*) sender();
1907 if ( obj == myStdActions.at(ViewOCCId) ) {
1908 myActiveApp->getActiveStudy()->newWindow3d(QString(""),(ViewType)(0));
1909 } else if ( obj == myStdActions.at(ViewVTKId) ) {
1910 myActiveApp->getActiveStudy()->newWindow3d(QString(""),(ViewType)(1));
1911 } else if ( obj == myStdActions.at(ViewPlot2dId) ) {
1912 myActiveApp->getActiveStudy()->newWindow3d(QString(""),(ViewType)(3));
1918 Called on 'help\contents'
1920 void QAD_Desktop::onHelpContents()
1923 myActiveApp->helpContents();
1929 Called on 'help\search'
1931 void QAD_Desktop::onHelpSearch()
1934 myActiveApp->helpSearch();
1940 Called on 'help\about'
1942 void QAD_Desktop::onHelpAbout()
1945 myActiveApp->helpAbout();
1952 Activates the application and its active study
1954 void QAD_Desktop::onActivateApp( QAD_Application* activeApp )
1956 bool appChanged = ( activeApp != myActiveApp );
1959 updateDesktop( DeactivateApp );
1963 myActiveApp = activeApp;
1964 myActiveStudy = myActiveApp->getActiveStudy();
1974 updateDesktop( ActivateApp );
1975 updateCaption( (activeApp != NULL) ? ActivateApp : DeactivateApp );
1981 Called when the last study is removed from
1982 the application 'app'.
1984 void QAD_Desktop::onDeactivateApp(QAD_Application* app)
1986 if ( app && app == myActiveApp )
1991 Enables/disables standard actions
1993 void QAD_Desktop::updateActions()
1995 myStdActions.at( FileCloseId )->setEnabled ( myActiveStudy != NULL );
1996 myStdActions.at( FileSaveId )->setEnabled ( myActiveStudy != NULL );
1997 myStdActions.at( FileSaveAsId )->setEnabled ( myActiveStudy != NULL );
1998 myStdActions.at( FilePropsId )->setEnabled( myActiveStudy != NULL );
1999 // myStdActions.at( HelpContentsId )->setEnabled ( myActiveApp != NULL );
2000 // myStdActions.at( HelpSearchId )->setEnabled ( myActiveApp != NULL );
2001 // myStdActions.at( HelpWhatsThisId )->setEnabled ( myActiveApp != NULL );
2002 // myStdActions.at( HelpAboutId )->setEnabled ( myActiveApp != NULL );
2004 // myToolsPopup.setEnabled ( myActiveStudy != NULL );
2005 // myPrefPopup.setEnabled ( myActiveStudy != NULL );
2007 mySelectionModePopup.setEnabled ( myActiveStudy != NULL );
2011 Called when 'Window' popup is about to show
2013 void QAD_Desktop::onWindowPopupAboutToShow()
2015 /* add cascade/tile items */
2016 myWindowPopup.clear();
2019 //myStdActions.at( WindowNew3dId )->addTo( &myWindowPopup );
2020 myWindowPopup.insertItem( tr("MEN_DESK_WINDOW_NEW3D"), &myNewViewPopup, WindowNew3dId );
2021 //myStdActions.at( WindowNew3dId )->setEnabled( true );
2022 myWindowPopup.setItemEnabled( WindowNew3dId, true );
2024 myStdActions.at( WindowCascadeId )->addTo( &myWindowPopup );
2025 myStdActions.at( WindowCascadeId )->setEnabled( true );
2026 myStdActions.at( WindowTileId )->addTo( &myWindowPopup );
2027 myStdActions.at( WindowTileId )->setEnabled( true );
2029 /* add names of opened studies */
2030 QWidgetList windows = myWorkspace->windowList();
2031 if ( windows.isEmpty() )
2033 //NRI : SAL2214 myStdActions.at( WindowNew3dId )->setEnabled( false );
2034 myWindowPopup.setItemEnabled( WindowNew3dId, false );
2036 myStdActions.at( WindowCascadeId )->setEnabled( false );
2037 myStdActions.at( WindowTileId )->setEnabled( false );
2041 myWindowPopup.insertSeparator();
2042 for ( int i = 0; i < int(windows.count()); ++i )
2044 int id = myWindowPopup.insertItem( windows.at(i)->caption(),
2045 this, SLOT( onWindowsPopupActivated( int ) ) );
2046 myWindowPopup.setItemParameter( id, i );
2047 myWindowPopup.setItemChecked( id, myWorkspace->activeWindow() == windows.at(i) );
2049 QAD_ASSERT( connect( &myWindowPopup, SIGNAL(highlighted( int )), this,
2050 SLOT(onWindowsPopupStatusText( int )) ));
2055 Called when the item with 'id' of 'Windows' popup
2058 void QAD_Desktop::onWindowsPopupStatusText( int id )
2060 int cascadeId = myWindowPopup.idAt( 0 );
2061 int tileId = myWindowPopup.idAt( 1 );
2062 if ( id == cascadeId || id == tileId )
2064 putInfo( tr("PRP_DESK_WINDOW_ACTIVATE") );
2068 Called when user wants to activate a child window with 'wid'
2071 void QAD_Desktop::onWindowsPopupActivated( int wid )
2073 QWidget* w = myWorkspace->windowList().at( wid );
2074 if ( w ) w->setFocus();
2078 Selects a file name when opening or saving files.
2079 The basic implementation just uses the standard
2081 Please redefine if another behaviour is required.
2083 QString QAD_Desktop::selectFileName ( bool open )
2085 QAD_FileDlg* fd = new QAD_FileDlg( this, open, true, true );
2089 QStringList filters;
2092 // All the file types of the supported applications
2094 for ( QAD_Application* app = myApps.first(); app; app = myApps.next() )
2096 filters += app->getStudyDescription() + " " + tr("DESK_FILES") + " " +
2097 "(*." + app->getStudyExtension() + ")";
2101 QAD_ASSERT_DEBUG_ONLY ( myActiveStudy );
2102 if (myActiveStudy) {
2103 // get file name of active study
2104 name = QAD_Tools::getFileNameFromPath ( myActiveStudy->getTitle() );
2105 // get path to the active study file
2106 dir = QAD_Tools::getDirFromPath ( myActiveStudy->getPath(), false );
2108 QAD_ASSERT_DEBUG_ONLY ( !name.isNull() );
2109 // the file types supported by the active application
2110 filters += myActiveApp->getStudyDescription() + " " + tr("DESK_FILES") + " " +
2111 "(*." + myActiveApp->getStudyExtension() + ")" ;
2113 if (!dir.isEmpty()) {
2114 // when saving document ("Save As" command) - to get dir from active study filename
2115 // for new documents - to use last opened directory
2118 fd->setSelection( name );
2119 fd->setFilters( filters );
2122 QString filename = fd->selectedFile();
2124 qApp->processEvents();
2129 Closes all the studies of 'app'. Returns
2130 'true' if thay are closed OK, 'false' at least
2131 one can't be closed or user cancel the closure.
2133 bool QAD_Desktop::closeAllStudies( QAD_Application* app )
2135 QList<QAD_Study>& studies = app->getStudies();
2136 while ( !studies.isEmpty() )
2138 //don't ask user to remove study permanently
2139 if ( !onCloseStudy( studies.at(0), false ) )
2140 return false; /* user cancelled closing */
2146 Called on Popup item when SComponent representation in Object Browser is selected.
2148 void QAD_Desktop::onOpenWith()
2150 Engines::Component_var comp;
2151 QString ComponentSelected;
2153 SALOMEDS::SObject_var SO;
2154 SALOMEDS::SComponent_var SCO;
2155 SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
2156 SALOMEDS::GenericAttribute_var anAttr;
2157 SALOMEDS::AttributeName_var aName;
2159 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2160 if ( Sel->IObjectCount() == 1 ) {
2161 Handle(SALOME_InteractiveObject) IO = Sel->firstIObject();
2162 SO = aStudy->FindObjectID( IO->getEntry() );
2163 SCO = SO->GetFatherComponent();
2165 if (SCO->FindAttribute(anAttr, "AttributeName")) {
2166 aName = SALOMEDS::AttributeName::_narrow(anAttr);
2167 name = aName->Value();
2168 SALOME_ModuleCatalog::Acomponent_var Comp = myCatalogue->GetComponent( mapComponentName[name] );
2169 if ( !Comp->_is_nil() ) {
2171 SALOME_ModuleCatalog::ListOfComponents_var list_type_composants =
2172 myCatalogue->GetTypedComponentList( Comp->component_type() );
2174 if ( list_type_composants->length() == 1 ) {
2175 ComponentSelected = name;
2176 } else if ( list_type_composants->length() > 1 ) {
2177 SALOMEGUI_OpenWith* aDlg = new SALOMEGUI_OpenWith( this );
2178 for (unsigned int ind = 0; ind < list_type_composants->length();ind++) {
2179 aDlg->addComponent( strdup(list_type_composants[ind]) );
2182 int retVal = aDlg->exec();
2183 ComponentSelected = aDlg->getComponent();
2185 if ( retVal == QDialog::Rejected || ComponentSelected.isEmpty()) {
2189 MESSAGE( "No component with type : " << Comp->component_type() << " exists" );
2194 MESSAGE( "This component not exists in the catalog" );
2198 QApplication::setOverrideCursor( Qt::waitCursor );
2199 Sel->ClearIObjects();
2201 // if (loadComponentData(ComponentSelected)) {
2202 onComboActiveComponent(ComponentSelected);
2203 // int nbItem = myCombo->count();
2205 // for (int i = 0; i < nbItem; i++) {
2206 // if (myCombo->text(i).compare(ComponentSelected)==0) {
2211 // myCombo->setCurrentItem(Index);
2212 // myActiveStudy->updateObjBrowser(true);
2216 QApplication::restoreOverrideCursor();
2219 typedef bool OneDim1(QAD_Desktop*);
2222 Called to define settings of component.
2224 void QAD_Desktop::setSettings()
2226 if (!myActiveComp.isEmpty()) {
2227 OSD_Function osdF = mySharedLibrary.DlSymb("SetSettings");
2228 if ( osdF != NULL ) {
2229 OneDim1 (*f1) = (bool (*) (QAD_Desktop*)) osdF;
2236 Called to load Component : xml resources and GUI librairy.
2238 bool QAD_Desktop::loadComponent(QString Component)
2241 QString resDir("/"); //NRI : Pb under Windows
2243 QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
2246 if (!resMgr->loadResources( Component, msg ))
2248 //NRI QCString errMsg;
2249 // errMsg.sprintf( "Do not load all resources for module %sGUI.\n" ,
2250 // Component.latin1() );
2252 QMessageBox::warning( this, tr("WRN_WARNING"), msg, tr ("BUT_OK") );
2257 /* Parse xml file */
2258 myXmlHandler = new QAD_XmlHandler();
2259 myXmlHandler->setMainWindow(this);
2260 if (!myXmlHandler->setComponent(resMgr->resources( Component ))) return false;
2262 QString language = resMgr->language( Component );
2264 QString ComponentXml = Component + "_" + language + ".xml";
2265 //ComponentXml = resMgr->resources(Component + "GUI") ;
2266 //ComponentXml = QAD_Tools::addSlash(ComponentXml) ;
2267 ComponentXml = QAD_Tools::addSlash( resMgr->findFile( ComponentXml, Component ) ) + ComponentXml;
2268 QFile file( ComponentXml );
2270 if ( !file.exists() || !file.open( IO_ReadOnly ) ) {
2272 errMsg.sprintf( "Cannot open xml file: %s\n.",
2273 (file.name()).latin1() );
2275 QMessageBox::critical( this, tr("ERR_ERROR"), errMsg, tr ("BUT_OK") );
2280 QXmlInputSource source( file );
2281 QXmlSimpleReader reader;
2282 reader.setContentHandler( myXmlHandler );
2283 reader.setErrorHandler( myXmlHandler );
2284 bool ok = reader.parse( source );
2288 QMessageBox::critical( this,
2289 tr( "INF_PARSE_ERROR" ),
2290 tr( myXmlHandler->errorProtocol() ) );
2294 myMenusList=myXmlHandler->myMenusList;
2295 myActiveMenus=myMenusList.at(0);
2296 myOperatorMenus->showMenuBar(0);
2297 myActiveMenus->showAllToolBars();
2299 /* Components toolbars */
2302 nbToolbars = myActiveMenus->getToolBarList().count();
2303 /* Open Shared Library */
2304 mySharedLibrary = OSD_SharedLibrary();
2306 QString ComponentLib;
2308 QFileInfo fileInfo ;
2309 QString fileString ;
2312 if ( libs = getenv("LD_LIBRARY_PATH")) {
2313 MESSAGE ( " LD_LIBRARY_PATH : " << libs )
2314 QStringList dirList = QStringList::split( SEPARATOR, libs, false ); // skip empty entries
2315 for ( int i = dirList.count()-1; i >= 0; i-- ) {
2318 fileString = QAD_Tools::addSlash( dir ) + "lib" + Component + "GUI.dll" ;
2320 fileString = QAD_Tools::addSlash( dir ) + "lib" + Component + "GUI.so" ;
2323 fileInfo.setFile(fileString) ;
2324 if (fileInfo.exists()) {
2325 MESSAGE ( " GUI library = " << fileString )
2326 ComponentLib = fileInfo.fileName() ;
2330 MESSAGE ( " GUI library not found " )
2332 // bool found = false;
2333 // if ( dir = getenv("SALOME_SITE_DIR")) {
2334 // dir = QAD_Tools::addSlash(dir) ;
2335 // dir = dir + "lib" ;
2336 // dir = QAD_Tools::addSlash(dir) ;
2337 // dir = dir + "salome" ;
2338 // dir = QAD_Tools::addSlash(dir) ;
2340 // dir = dir + "lib" + Component.latin1() + "GUI.dll" ;
2342 // dir = dir + "lib" + Component.latin1() + "GUI.so" ;
2344 // MESSAGE ( " GUI library = " << dir )
2345 // fileInfo.setFile(dir) ;
2346 // if (fileInfo.exists()) {
2347 // ComponentLib = fileInfo.fileName() ;
2352 // if ( (dir = getenv("SALOME_ROOT_DIR")) && !found ) {
2353 // dir = QAD_Tools::addSlash(dir) ;
2354 // dir = dir + "lib" ;
2355 // dir = QAD_Tools::addSlash(dir) ;
2356 // dir = dir + "salome" ;
2357 // dir = QAD_Tools::addSlash(dir) ;
2359 // dir = dir + "lib" + Component.latin1() + "GUI.dll" ;
2361 // dir = dir + "lib" + Component.latin1() + "GUI.so" ;
2363 // MESSAGE ( " GUI library = " << dir )
2364 // fileInfo.setFile(dir) ;
2365 // if (fileInfo.exists()) {
2366 // ComponentLib = fileInfo.fileName() ;
2371 mySharedLibrary.SetName(TCollection_AsciiString((char*)ComponentLib.latin1()).ToCString());
2372 ok = mySharedLibrary.DlOpen(OSD_RTLD_LAZY);
2375 QMessageBox::critical( this,
2377 tr( mySharedLibrary.DlError() ) );
2382 OSD_Function osdF = mySharedLibrary.DlSymb("SetSettings");
2383 if ( osdF != NULL ) {
2384 OneDim1 (*f1) = (bool (*) (QAD_Desktop*)) osdF;
2388 /* COMPONENT INTERFACE */
2389 SALOME_ModuleCatalog::Acomponent_ptr aComponent =
2390 myCatalogue->GetComponent(Component.latin1());
2392 if (CORBA::is_nil (aComponent)) {
2393 MESSAGE( "Catalog Error : Component not found in the catalog" )
2397 myActiveStudy->setMessage(QString("Component : ") +
2398 aComponent->componentusername() + " created " );
2399 myActiveStudy->setMessage(QString("Type : ") +
2400 QString::number(aComponent->component_type()));
2401 myActiveStudy->setMessage(QString("Constraint : ") +
2402 aComponent->constraint() );
2404 /* obtain interfaces list of the component */
2405 SALOME_ModuleCatalog::ListOfInterfaces_var _list =
2406 new SALOME_ModuleCatalog::ListOfInterfaces;
2407 _list = aComponent->GetInterfaceList();
2409 if (_list->length() != 0 ) {
2411 for (unsigned int ind = 0; ind < _list->length();ind++)
2412 myActiveStudy->setMessage( QString("Interface name : ") +
2416 /* obtain services list of the component */
2417 SALOME_ModuleCatalog::ListOfServices_var list_services_component =
2418 new SALOME_ModuleCatalog::ListOfServices;
2419 list_services_component = aComponent->GetServiceList(_list[0]);
2421 if (list_services_component->length() != 0 ) {
2423 for (unsigned int ind = 0; ind < list_services_component->length();ind++)
2424 myActiveStudy->setMessage( QString("Service name : ") +
2425 list_services_component[ind] );
2427 // Get a service of the component
2428 SALOME_ModuleCatalog::Service_var service = new SALOME_ModuleCatalog::Service;
2429 service = aComponent->GetService(_list[0],list_services_component[0]) ;
2430 myActiveStudy->setMessage( QString("Service name: ") + service->ServiceName);
2431 for (unsigned int ind1 = 0; ind1 <service->ServiceinParameter.length();ind1++) {
2432 myActiveStudy->setMessage( QString("Type of the in Parameter of this service : ") +
2433 (const char *) service->ServiceinParameter[ind1].Parametertype);
2434 myActiveStudy->setMessage( QString("Name of the in Parameter of this service : ") +
2435 (const char *) service->ServiceinParameter[ind1].Parametername);
2437 for (unsigned int ind1 = 0; ind1 <service->ServiceoutParameter.length();ind1++) {
2438 myActiveStudy->setMessage( QString("Type of the out Parameter of this service : ") +
2439 (const char *) service->ServiceoutParameter[ind1].Parametertype);
2440 myActiveStudy->setMessage( QString("Name of the out Parameter of this service : ") +
2441 (const char *) service->ServiceoutParameter[ind1].Parametername);
2448 typedef bool OneDim(int, QAD_Desktop*);
2449 typedef void (*PTR_FACTORY_FUNCTION)( CORBA::ORB_var &orb, QWidget *parent, const char *name ) ;
2453 void QAD_Desktop::onDispatch()
2455 const QObject* obj = sender();
2457 QList<QAD_ListMenuIdAction> MenuList = myActiveMenus->getMenuList();
2458 QAD_ListMenuIdAction* aMenu;
2460 for(aMenu=MenuList.first();aMenu!=NULL;aMenu=MenuList.next()) {
2461 if (aMenu->getAction()==obj) {
2462 id = aMenu->getId();
2471 void QAD_Desktop::onDispatchTools(int id)
2473 /* Open Shared Library */
2474 OSD_SharedLibrary ToolsLibrary = OSD_SharedLibrary();
2478 QFileInfo fileInfo ;
2482 bool libToolsGUI = true;
2483 if( QAD_XmlHandler::_bibmap[ id ].isEmpty() )
2486 if ( dir = getenv("SALOME_SITE_DIR")) {
2487 dir = QAD_Tools::addSlash(dir) ;
2489 dir = QAD_Tools::addSlash(dir) ;
2490 dir = dir + "salome" ;
2491 dir = QAD_Tools::addSlash(dir) ;
2493 dir = dir + "libToolsGUI.dll" ;
2495 dir = dir + "libToolsGUI.so" ;
2497 MESSAGE ( " GUI library = " << dir );
2498 fileInfo.setFile(dir) ;
2499 if (fileInfo.exists()) {
2500 ToolsLib = fileInfo.fileName() ;
2505 if ( (dir = getenv("SALOME_ROOT_DIR")) && !found ) {
2506 dir = QAD_Tools::addSlash(dir) ;
2508 dir = QAD_Tools::addSlash(dir) ;
2509 dir = dir + "salome" ;
2510 dir = QAD_Tools::addSlash(dir) ;
2512 dir = dir + "libToolsGUI.dll" ;
2514 dir = dir + "libToolsGUI.so" ;
2516 MESSAGE ( " GUI library = " << dir );
2517 fileInfo.setFile(dir) ;
2518 if (fileInfo.exists()) {
2519 ToolsLib = fileInfo.fileName() ;
2524 if ( (dir = getenv("KERNEL_ROOT_DIR")) && !found ) {
2525 dir = QAD_Tools::addSlash(dir) ;
2527 dir = QAD_Tools::addSlash(dir) ;
2528 dir = dir + "salome" ;
2529 dir = QAD_Tools::addSlash(dir) ;
2531 dir = dir + "libToolsGUI.dll" ;
2533 dir = dir + "libToolsGUI.so" ;
2535 MESSAGE ( " GUI library = " << dir );
2536 fileInfo.setFile(dir) ;
2537 if (fileInfo.exists()) {
2538 ToolsLib = fileInfo.fileName() ;
2544 libToolsGUI = false;
2545 SCRUTE( QAD_XmlHandler::_bibmap[ id ] ) ;
2546 if ( dir = getenv("SALOME_SITE_DIR")) {
2547 dir = QAD_Tools::addSlash(dir) ;
2549 dir = QAD_Tools::addSlash(dir) ;
2550 dir = dir + "salome" ;
2551 dir = QAD_Tools::addSlash(dir) ;
2552 dir = dir + QAD_XmlHandler::_bibmap[ id ].latin1() ;
2553 MESSAGE ( " GUI library = " << dir );
2554 fileInfo.setFile(dir) ;
2555 if (fileInfo.exists()) {
2556 ToolsLib = fileInfo.fileName() ;
2561 if ( (dir = getenv("SALOME_ROOT_DIR")) && !found ) {
2562 dir = QAD_Tools::addSlash(dir) ;
2564 dir = QAD_Tools::addSlash(dir) ;
2565 dir = dir + "salome" ;
2566 dir = QAD_Tools::addSlash(dir) ;
2567 dir = dir + QAD_XmlHandler::_bibmap[ id ].latin1() ;
2568 MESSAGE ( " GUI library = " << dir );
2569 fileInfo.setFile(dir) ;
2570 if (fileInfo.exists()) {
2571 ToolsLib = fileInfo.fileName() ;
2576 if ( (dir = getenv("KERNEL_ROOT_DIR")) && !found ) {
2577 dir = QAD_Tools::addSlash(dir) ;
2579 dir = QAD_Tools::addSlash(dir) ;
2580 dir = dir + "salome" ;
2581 dir = QAD_Tools::addSlash(dir) ;
2582 dir = dir + QAD_XmlHandler::_bibmap[ id ].latin1() ;
2583 MESSAGE ( " GUI library = " << dir );
2584 fileInfo.setFile(dir) ;
2585 if (fileInfo.exists()) {
2586 ToolsLib = fileInfo.fileName() ;
2592 ToolsLibrary.SetName(TCollection_AsciiString((char*)ToolsLib.latin1()).ToCString());
2593 bool ok = ToolsLibrary.DlOpen(OSD_RTLD_LAZY);
2595 if ( libToolsGUI ) {
2596 OSD_Function osdF = ToolsLibrary.DlSymb("OnGUIEvent");
2597 OneDim (*f1) = NULL;
2598 f1 = (bool (*) (int, QAD_Desktop*)) osdF;
2601 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
2602 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
2603 CORBA::ORB_var &orb = init(0 , 0 ) ;
2604 OSD_Function osdF = ToolsLibrary.DlSymb("OnGUIEvent");
2605 PTR_FACTORY_FUNCTION f1 = NULL;
2606 f1 = (PTR_FACTORY_FUNCTION) osdF;
2607 f1(orb,0,"Registry");
2610 QMessageBox::critical( this,
2612 tr( ToolsLibrary.DlError() ) );
2618 void QAD_Desktop::onDispatch(int id)
2620 if (!myActiveComp.isEmpty()) {
2621 OSD_Function osdF = mySharedLibrary.DlSymb("OnGUIEvent");
2622 OneDim (*f1) = NULL;
2623 if ( osdF != NULL ) {
2624 f1 = (bool (*) (int, QAD_Desktop*)) osdF;
2631 Returns the component's catalogue
2633 SALOME_ModuleCatalog::ModuleCatalog_var QAD_Desktop::getCatalogue()
2640 void QAD_Desktop::onComboActiveComponent( const QString & component ){
2641 onComboActiveComponent(component,true);
2643 void QAD_Desktop::onComboActiveComponent( const QString & component, bool isLoadData)
2645 if (myActiveStudy != 0) {
2646 if (myActiveComp.compare(component)!=0) {
2647 if (!myXmlHandler->myIdList.IsEmpty()) clearMenus();
2648 if ( myCombo->currentText() != component )
2649 myCombo->setCurrentText( component );
2650 //NRI if (component.compare(QString("Salome"))!= 0) {
2651 if (component.compare( getComponentUserName( "KERNEL" ) )!= 0) {
2652 // QApplication::setOverrideCursor( Qt::waitCursor );
2653 myActiveComp = component;
2655 SALOME_Selection* oldSel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2657 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2658 if ( aButton->textLabel().compare(component)==0)
2659 aButton->setOn(true);
2661 aButton->setOn(false);
2664 myActiveStudy->Selection( component );
2665 if ( !loadComponent(mapComponentName[component]) ) {
2666 myCombo->setCurrentItem (0);
2667 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2668 aButton->setOn(false);
2673 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2674 SALOME_ListIteratorOfListIO It( oldSel->StoredIObjects() );
2675 for(;It.More();It.Next()) {
2676 int res = Sel->AddIObject( It.Value() );
2679 myActiveStudy->highlight( It.Value(), false );
2681 myActiveStudy->highlight( It.Value(), true );
2685 // Open new component's data in active study if any
2686 if(isLoadData) loadComponentData(mapComponentName[component]);
2689 myActiveStudy->updateObjBrowser(true);
2691 // QApplication::restoreOverrideCursor();
2693 } else { // component == "Salome"
2695 //NRI myActiveStudy->Selection( "Salome" );
2696 myActiveStudy->Selection( getComponentUserName( "KERNEL" ) );
2697 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2698 Sel->ClearIObjects();
2699 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2700 aButton->setOn(false);
2704 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2705 if ( aButton->textLabel().compare(component)==0)
2706 aButton->setOn(true);
2710 QMessageBox::critical( 0,
2712 tr( "WRN_LOAD_COMPONENT" ) );
2713 myCombo->setCurrentItem (0);
2714 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2715 aButton->setOn(false);
2722 void QAD_Desktop::activateComponent(const QString& theName, bool isLoadData){
2723 int nbItem = myCombo->count();
2726 for (int i = 0; i < nbItem; i++) {
2727 if (myCombo->text(i).compare(theName)==0) {
2732 myCombo->setCurrentItem (Index);
2733 onComboActiveComponent(theName,isLoadData);
2736 void QAD_Desktop::onButtonActiveComponent( )
2738 QToolButton* obj = (QToolButton*)sender();
2739 activateComponent(obj->textLabel());
2743 Clears All Resources of current component
2745 void QAD_Desktop::clearMenus()
2747 onActiveStudyChanged();
2750 myMenusList.clear();
2752 int length = myXmlHandler->myIdList.Length();
2753 for (int k=length; k>0; k--) {
2755 if ( menuBar()->findItem(myXmlHandler->myIdList.Value(k), &parent) )
2756 parent->removeItem( myXmlHandler->myIdList.Value(k) );
2761 if (myActiveMenus) {
2762 int nbtoolbars = myActiveMenus->getToolBarList().count();
2763 for (int k=0; k<nbtoolbars; k++) {
2764 myActiveMenus->getToolBarList().at(k)->hide();
2765 myActiveMenus->getToolBarList().at(k)->clear();
2767 myActiveMenus->clearToolBar();
2770 QList<QAD_ListPopupMenu> PopupList = myActiveMenus->getPopupMenuList();
2771 QAD_ListPopupMenu* aPopup;
2772 for(aPopup=PopupList.first();aPopup!=NULL;aPopup=PopupList.next()){
2773 aPopup->getPopup()->clear();
2776 myActiveMenus->clearPopupMenu();
2782 typedef bool TwoDim1(QKeyEvent* pe, QAD_Desktop*, QAD_StudyFrame*);
2784 Exports Key Events in active component ( GUI Librairy )
2786 void QAD_Desktop::onKeyPress( QKeyEvent* pe )
2788 // MESSAGE ( "QAD_Desktop::onKeyPress" )
2789 if (!myActiveComp.isEmpty()) {
2790 OSD_Function osdF = mySharedLibrary.DlSymb("OnKeyPress");
2791 if ( osdF != NULL ) {
2792 TwoDim1 (*f1) = (bool (*) (QKeyEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
2793 (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
2798 typedef bool TwoDim(QMouseEvent* pe, QAD_Desktop*, QAD_StudyFrame*);
2800 Exports Mouse Press Events in active component ( GUI Librairy )
2802 bool QAD_Desktop::onMousePress( QMouseEvent* pe )
2804 // MESSAGE ( "QAD_Desktop::onMousePress" )
2805 if (!myActiveComp.isEmpty()) {
2806 OSD_Function osdF = mySharedLibrary.DlSymb("OnMousePress");
2807 if ( osdF != NULL ) {
2808 TwoDim (*f1) = (bool (*) (QMouseEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
2809 return (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
2816 Exports Mouse Move Events in active component ( GUI Librairy )
2818 void QAD_Desktop::onMouseMove( QMouseEvent* pe )
2820 if (!myActiveComp.isEmpty()) {
2821 OSD_Function osdF = mySharedLibrary.DlSymb("OnMouseMove");
2822 if ( osdF != NULL ) {
2823 TwoDim (*f1) = (bool (*) (QMouseEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
2824 (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
2830 Returns name of active component
2832 const QString& QAD_Desktop::getActiveComponent() const
2834 return myActiveComp;
2838 typedef bool defineP( QString & theContext, QString & theParent, QString & theObject);
2840 void QAD_Desktop::definePopup(QString & theContext,
2841 QString & theParent,
2842 QString & theObject )
2844 if (!myActiveComp.isEmpty()) {
2845 OSD_Function osdF = mySharedLibrary.DlSymb("definePopup");
2846 if ( osdF != NULL ) {
2847 defineP (*f1) = (bool (*) (QString &, QString &, QString &)) osdF;
2848 (*f1)(theContext, theParent, theObject);
2856 void QAD_Desktop::createPopup(QPopupMenu* popupFather, QPopupMenu* popup,
2857 QString text, int popupID, bool separator)
2859 QMenuItem* item = popup->findItem(popupID);
2861 QPopupMenu* popupChild = item->popup();
2863 QPopupMenu* newPopup = new QPopupMenu;
2864 int count = popupChild->count();
2865 // add items at the top of <popupFather>
2866 for (int i = count - 1; i >= 0; i--) {
2867 int j = popupChild->idAt(i);
2868 QString text = popupChild->text(j);
2869 createPopup( newPopup, popupChild, text, j);
2871 popupFather->insertItem(popup->text(popupID),
2872 newPopup, popupID, 0);
2874 if ( !text.isNull() ) {
2875 popupFather->insertItem(popup->text(popupID),
2877 SLOT( onDispatch(int) ), 0, popupID, 0);// try adding item at the top
2878 } /*else if ( separator )
2879 popupFather->insertTearOffHandle(-1, 0);*/
2881 popupFather->insertSeparator(0);
2889 void QAD_Desktop::createPopup(QPopupMenu* popup, const QString & theContext,
2890 const QString & theParent, const QString & theObject )
2892 if ( !myActiveComp.isEmpty() &&
2893 getOperatorMenus()->createPopupMenu(theContext,theParent,theObject) != NULL ) {
2894 QPopupMenu* aPopup = getOperatorMenus()->createPopupMenu(theContext,theParent,theObject)->getPopup();
2895 int count = aPopup->count();
2897 //for (int i = 0; i < count; i++) {
2898 for (int i = count - 1; i >= 0; i--) {
2899 int id = aPopup->idAt(i);
2900 QString text = aPopup->text(id);
2901 //QString mes("Inserting popup menu item loaded from XML: ");
2903 //MESSAGE ( mes.latin1() )
2905 popup->insertItem(aPopup->text(id),
2907 SLOT( onDispatch(int) ), 0, id, 0);// try adding item at the top
2909 createPopup( popup, aPopup, text, id);
2912 //QString mes("Popup does not exist for given (Context = ");
2913 //mes += theContext;
2914 //mes += ", Parent = ";
2916 //mes += ", Object = ";
2918 //MESSAGE (mes.latin1())
2923 // Should be moved to SALOMEGUI_Application::onCreatePopup()...
2924 if ( myActiveComp.isEmpty() ) {
2925 popup->removeItem(QAD_Display_Popup_ID);
2926 popup->removeItem(QAD_DisplayOnly_Popup_ID);
2927 popup->removeItem(QAD_Erase_Popup_ID);
2928 int id = popup->idAt(popup->count()-1); // last item
2929 if (id < 0 && id != -1) popup->removeItem(id); // separator
2931 if ( popup && theParent.compare("ObjectBrowser")==0 ) {
2932 if ( popup->count()>0 ) {
2933 popup->insertItem (tr ("MEN_OPENWITH"), this, SLOT(onOpenWith()), 0, -1, 2);
2934 popup->insertSeparator (3);
2937 popup->insertItem (tr ("MEN_OPENWITH"), this, SLOT(onOpenWith()) );
2944 typedef bool activeStudyChanged(QAD_Desktop*);
2946 void QAD_Desktop::onActiveStudyChanged()
2948 if (!myActiveComp.isEmpty()) {
2949 OSD_Function osdF = mySharedLibrary.DlSymb("activeStudyChanged");
2950 if ( osdF != NULL ) {
2951 activeStudyChanged (*f1) = (bool (*) (QAD_Desktop*)) osdF;
2957 typedef bool customP(QAD_Desktop*, QPopupMenu*, const QString & theContext,
2958 const QString & theParent, const QString & theObject);
2960 Custom popup ( GUI Library )
2962 void QAD_Desktop::customPopup(QPopupMenu* popup, const QString & theContext,
2963 const QString & theParent, const QString & theObject)
2965 if (!myActiveComp.isEmpty()) {
2966 OSD_Function osdF = mySharedLibrary.DlSymb("customPopup");
2967 if ( osdF != NULL ) {
2968 customP (*f1) = (bool (*) (QAD_Desktop*, QPopupMenu*, const QString &,
2969 const QString &, const QString &)) osdF;
2970 (*f1)(this, popup, theContext, theParent, theObject);
2975 void QAD_Desktop::onObjectBrowser()
2977 bool checkDiff = false;
2979 bool state = QAD_CONFIG->getSetting("ObjectBrowser:AddColumn").compare("true") == 0;
2981 if ( myStdActions.at( PrefObjectBrowserEntryId )->isOn() != state )
2985 if ( myStdActions.at( PrefObjectBrowserEntryId )->isOn() ) {
2987 QAD_CONFIG->addSetting( "ObjectBrowser:AddColumn", "true");
2990 QAD_CONFIG->addSetting( "ObjectBrowser:AddColumn", "false");
2994 if ( myStdActions.at( PrefObjectBrowserValueId )->isOn() ) {
2996 QAD_CONFIG->addSetting( "ObjectBrowser:ValueColumn", "true");
2999 QAD_CONFIG->addSetting( "ObjectBrowser:ValueColumn", "false");
3003 if ( myStdActions.at( PrefObjectBrowserIAPPId )->isOn() ) {
3005 QAD_CONFIG->addSetting( "ObjectBrowser:IAPP", "true");
3008 QAD_CONFIG->addSetting( "ObjectBrowser:IAPP", "false");
3011 /* To sort created object in chrono order or reverse chrono order */
3012 bool showCHRONO_SORT ;
3013 if ( myStdActions.at( PrefObjectBrowserCHRONO_SORTId )->isOn() ) {
3014 showCHRONO_SORT = true;
3015 QAD_CONFIG->addSetting( "ObjectBrowser:CHRONO_SORT", "true");
3017 showCHRONO_SORT = false;
3018 QAD_CONFIG->addSetting( "ObjectBrowser:CHRONO_SORT", "false");
3021 if ( myActiveApp ) {
3022 QList<QAD_Study>& studies = myActiveApp->getStudies();
3023 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3024 int nbSf = study->getStudyFramesCount();
3025 for ( int i = 0; i < nbSf; i++ ) {
3026 QAD_StudyFrame* sf = study->getStudyFrame(i);
3027 sf->getLeftFrame()->getObjectBrowser()->setShowInfoColumns( showEntry );
3028 sf->getLeftFrame()->getObjectBrowser()->setShowValueColumn( showValue );
3029 sf->getLeftFrame()->getObjectBrowser()->setEnableChronoSort( showCHRONO_SORT );
3030 // sf->getLeftFrame()->getObjectBrowser()->setShowIAPP( showIAPP ); // this is done by below updateObjBrowser() call
3032 study->updateObjBrowser(true);
3037 void QAD_Desktop::onViewerTrihedron()
3039 QString Size = QAD_CONFIG->getSetting("Viewer:TrihedronSize");
3042 SALOMEGUI_TrihedronSizeDlg *Dlg = new SALOMEGUI_TrihedronSizeDlg(this);
3043 if (!Size.isEmpty())
3044 Dlg->setTrihedronSize(Size.toInt());
3045 int r = Dlg->exec();
3046 dim = Dlg->getTrihedronSize();
3049 if (r == QDialog::Accepted) {
3050 QAD_CONFIG->addSetting("Viewer:TrihedronSize", dim);
3053 QList<QAD_Study>& studies = myActiveApp->getStudies();
3054 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3055 int nbSf = study->getStudyFramesCount();
3056 for ( int i = 0; i < nbSf; i++ ) {
3057 study->getStudyFrame(i)->getRightFrame()->getViewFrame()->SetTrihedronSize(dim);
3064 void QAD_Desktop::onDirList()
3066 // getting dir list from settings
3067 QStringList dirList = QStringList::split(';', QAD_CONFIG->getSetting("FileDlg:QuickDirList"), false);
3068 QAD_DirListDlg* dlg = new QAD_DirListDlg(this);
3069 dlg->setPathList(dirList);
3070 if ( dlg->exec() == QDialog::Accepted) {
3071 dlg->getPathList(dirList);
3072 QAD_CONFIG->addSetting("FileDlg:QuickDirList", dirList.join(";"));
3077 void QAD_Desktop::onConsoleFontAction()
3079 // getting font from settings
3080 QString fntSet = QAD_CONFIG->getSetting("Viewer:ConsoleFont");
3081 QFont font = QAD_Tools::stringToFont( fntSet );
3083 font = QFontDialog::getFont( &bOk, font, this );
3085 fntSet = QAD_Tools::fontToString( font );
3086 QAD_CONFIG->addSetting("Viewer:ConsoleFont", fntSet );
3089 QList<QAD_Study>& studies = myActiveApp->getStudies();
3090 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3091 int nbSf = study->getStudyFramesCount();
3092 for ( int i = 0; i < nbSf; i++ ) {
3093 study->getStudyFrame(i)->getRightFrame()->getPyEditor()->setFont( font );
3094 study->getStudyFrame(i)->getRightFrame()->getMessage()->setFont( font );
3101 void QAD_Desktop::onSavePref()
3103 QAD_CONFIG->createConfigFile(true);
3106 //VRV: T2.5 - add default viewer
3107 void QAD_Desktop::onDefaultViewer(QAction * theAction)
3109 int type = VIEW_TYPE_MAX;
3112 if (myStdActions.at(DefaultViewerOCCId) == theAction)
3114 else if (myStdActions.at(DefaultViewerVTKId) == theAction)
3116 else if (myStdActions.at(DefaultGraphSupervisorId) == theAction)
3117 type = VIEW_GRAPHSUPERV;
3118 else if (myStdActions.at(DefaultPlot2dId) == theAction)
3120 if ( type != VIEW_TYPE_MAX )
3121 QAD_CONFIG->addSetting( "Viewer:DefaultViewer", QString::number( type ) );
3123 //VRV: T2.5 - add default viewer
3125 void QAD_Desktop::onViewerOCC()
3127 QString BackgroundColorRed = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorRed");
3128 QString BackgroundColorGreen = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorGreen");
3129 QString BackgroundColorBlue = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorBlue");
3132 if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3133 color = QColor(BackgroundColorRed.toInt(),
3134 BackgroundColorGreen.toInt(),
3135 BackgroundColorBlue.toInt());
3137 color = QColor(35, 136, 145);
3139 QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3142 if ( myActiveApp ) {
3143 QList<QAD_Study>& studies = myActiveApp->getStudies();
3144 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3145 int nbSf = study->getStudyFramesCount();
3146 for ( int i = 0; i < nbSf; i++ ) {
3147 QAD_StudyFrame* sf = study->getStudyFrame(i);
3148 if ( sf->getTypeView() == VIEW_OCC ) {
3149 sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3154 QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorRed", c.red() );
3155 QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorGreen", c.green() );
3156 QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorBlue", c.blue() );
3160 void QAD_Desktop::onGraphSupervisor()
3162 QString BackgroundColorRed = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorRed");
3163 QString BackgroundColorGreen = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorGreen");
3164 QString BackgroundColorBlue = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorBlue");
3167 if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3168 color = QColor(BackgroundColorRed.toInt(),
3169 BackgroundColorGreen.toInt(),
3170 BackgroundColorBlue.toInt());
3172 color = QColor(35, 136, 145);
3174 QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3177 if ( myActiveApp ) {
3178 QList<QAD_Study>& studies = myActiveApp->getStudies();
3179 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3180 int nbSf = study->getStudyFramesCount();
3181 for ( int i = 0; i < nbSf; i++ ) {
3182 QAD_StudyFrame* sf = study->getStudyFrame(i);
3183 if ( sf->getTypeView() == VIEW_GRAPHSUPERV ) {
3184 sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3190 QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorRed", c.red() );
3191 QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorGreen", c.green() );
3192 QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorBlue", c.blue() );
3196 void QAD_Desktop::onViewerVTK()
3198 QString BackgroundColorRed = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorRed");
3199 QString BackgroundColorGreen = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorGreen");
3200 QString BackgroundColorBlue = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorBlue");
3203 if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3204 color = QColor(BackgroundColorRed.toInt(),
3205 BackgroundColorGreen.toInt(),
3206 BackgroundColorBlue.toInt());
3208 color = QColor(0, 0, 0);
3210 QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3213 if ( myActiveApp ) {
3214 QList<QAD_Study>& studies = myActiveApp->getStudies();
3215 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3216 int nbSf = study->getStudyFramesCount();
3217 for ( int i = 0; i < nbSf; i++ ) {
3218 QAD_StudyFrame* sf = study->getStudyFrame(i);
3219 if ( sf->getTypeView() == VIEW_VTK ) {
3220 sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3226 QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorRed", c.red() );
3227 QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorGreen", c.green() );
3228 QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorBlue", c.blue() );
3232 void QAD_Desktop::onPlot2d()
3235 if ( QAD_CONFIG->hasSetting( "Plot2d:Background" ) ) {
3236 QString bgString = QAD_CONFIG->getSetting( "Plot2d:Background" );
3237 QStringList bgData = QStringList::split( ":", bgString, true );
3238 int bgRed = 0, bgGreen = 0, bgBlue = 0;
3239 if ( bgData.count() > 0 ) bgRed = bgData[ 0 ].toInt();
3240 if ( bgData.count() > 1 ) bgGreen = bgData[ 1 ].toInt();
3241 if ( bgData.count() > 2 ) bgBlue = bgData[ 2 ].toInt();
3242 color = QColor( bgRed, bgGreen, bgBlue );
3245 color = QColor(0, 0, 0);
3248 color = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3250 if ( color.isValid() ) {
3251 if ( myActiveApp ) {
3252 QList<QAD_Study>& studies = myActiveApp->getStudies();
3253 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3254 int nbSf = study->getStudyFramesCount();
3255 for ( int i = 0; i < nbSf; i++ ) {
3256 QAD_StudyFrame* sf = study->getStudyFrame(i);
3257 if ( sf->getTypeView() == VIEW_PLOT2D ) {
3258 sf->getRightFrame()->getViewFrame()->setBackgroundColor( color );
3264 bgData.append( QString::number( color.red() ) );
3265 bgData.append( QString::number( color.green() ) );
3266 bgData.append( QString::number( color.blue() ) );
3267 QAD_CONFIG->addSetting( "Plot2d:Background", bgData.join( ":" ) );
3272 void QAD_Desktop::helpAbout()
3274 SALOMEGUI_AboutDlg* About = new SALOMEGUI_AboutDlg( QAD_Application::getDesktop(), tr("MEN_ABOUT"));
3280 void QAD_Desktop::helpSearch()
3285 void QAD_Desktop::helpContents()
3287 if (myActiveComp == "")
3288 myActiveComp = getComponentUserName( "KERNEL" ); //NRI "Salome";
3292 if (dir = getenv( getComponentName( myActiveComp ) + "_ROOT_DIR")) {
3293 root = QAD_Tools::addSlash( QAD_Tools::addSlash(dir) + QAD_Tools::addSlash("share") + QAD_Tools::addSlash("salome") + "doc" );
3294 if ( QFileInfo( root + "index.html" ).exists() ) {
3295 helpContext( root + "index.html", "" );
3298 root = QAD_Tools::addSlash( root + "html" );
3299 if ( QFileInfo( root + "index.html" ).exists() ) {
3300 helpContext( root + "index.html", "" );
3303 root = QAD_Tools::addSlash( root + "html" );
3304 if ( QFileInfo( root + "index.html" ).exists() ) {
3305 helpContext( root + "index.html", "" );
3311 //NRI getHelpWindow()->contents();
3312 getHelpWindow()->show();
3313 getHelpWindow()->raise();
3314 getHelpWindow()->setActiveWindow();
3318 void QAD_Desktop::helpContext(const QString& source, const QString& context)
3320 getHelpWindow()->context(source, context);
3321 getHelpWindow()->show();
3322 getHelpWindow()->raise();
3323 getHelpWindow()->setActiveWindow();
3326 /* Preferences/MultiFile Save */
3327 void QAD_Desktop::onMultiFileSave()
3329 if ( myStdActions.at( PrefMultiFileSave )->isOn() )
3330 QAD_CONFIG->addSetting( "Desktop:MultiFileSave", "true");
3332 QAD_CONFIG->addSetting( "Desktop:MultiFileSave", "false");
3335 /*********************************************************************
3336 ** Class: AppSelectionDlg
3337 ** Descr: Dialog for the selection of the application when several
3338 ** applications exist in the desktop and new study creation
3339 ** is activated by user.
3341 **********************************************************************/
3343 \class Desktop_AppSelectionDlg QAD_Desktop.h
3344 \brief Dialog for the selection of the application when several
3345 applications exist in the desktop and new study creation
3346 is activated by user.
3351 Desktop_AppSelectionDlg::Desktop_AppSelectionDlg( QAD_Desktop* desktop,
3352 QList<QAD_Application>& apps ) :
3353 QDialog( desktop, 0, true ),
3357 QAD_ASSERT_DEBUG_ONLY ( desktop );
3358 setCaption( tr("INF_DESK_DOC_CREATE") );
3359 if ( desktop->icon() )
3360 setIcon( *desktop->icon() );
3362 QBoxLayout* mainLayout = new QVBoxLayout( this, 5 );
3364 /* Create selection buttons */
3365 QVButtonGroup* buttonGrp = new QVButtonGroup ( this );
3366 buttonGrp->setExclusive ( true );
3367 QBoxLayout* vLayout = new QVBoxLayout( mainLayout, 5 );
3368 vLayout->addWidget ( buttonGrp );
3370 /* Create selection button for available app */
3372 for ( QAD_Application* app = myApps.first(); app; app = myApps.next(), id++ )
3374 /* add radio button for application */
3375 buttonGrp->insert( new QRadioButton( app->getStudyDescription() +
3376 " (*." + app->getStudyExtension() + ")", buttonGrp ), id );
3379 /* make the first application selected */
3380 buttonGrp->setButton( 0 );
3382 /* listen to the selection */
3383 QAD_ASSERT ( connect ( buttonGrp, SIGNAL(clicked(int)), this, SLOT(onAppSelected(int)) ));
3385 /* Create OK/Cancel buttons
3387 QBoxLayout* hLayout = new QHBoxLayout( mainLayout, 5 );
3388 QPushButton* buttonOK = new QPushButton( tr("BUT_OK"), this );
3389 QPushButton* buttonCancel = new QPushButton( tr("BUT_CANCEL"), this );
3390 QPushButton* buttonHelp = new QPushButton( tr("BUT_HELP"), this );
3391 buttonOK->setDefault( true );
3393 hLayout->addStretch();
3394 hLayout->addWidget( buttonOK );
3395 hLayout->addWidget( buttonCancel );
3396 hLayout->addWidget( buttonHelp );
3398 /* connect buttons */
3399 QAD_ASSERT ( connect( buttonOK, SIGNAL(clicked()), this, SLOT(accept())) );
3400 QAD_ASSERT ( connect( buttonCancel, SIGNAL(clicked()), this, SLOT(reject())) );
3401 QAD_ASSERT ( connect( buttonHelp, SIGNAL(clicked()), this, SLOT(onHelp())) );
3403 /* disable resizing */
3404 setFixedSize( 0, 0 );
3405 setSizePolicy( QSizePolicy ( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
3408 Desktop_AppSelectionDlg::~Desktop_AppSelectionDlg()
3412 QAD_Application* Desktop_AppSelectionDlg::selectedApp() const
3414 return myApps.at( myAppId );
3417 void Desktop_AppSelectionDlg::resizeEvent( QResizeEvent* e )
3419 QAD_Tools::centerWidget( this, parentWidget() );
3425 void Desktop_AppSelectionDlg::onAppSelected( int id )
3430 void Desktop_AppSelectionDlg::onHelp()