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() ;
2525 libToolsGUI = false;
2526 SCRUTE( QAD_XmlHandler::_bibmap[ id ] ) ;
2527 if ( dir = getenv("SALOME_SITE_DIR")) {
2528 dir = QAD_Tools::addSlash(dir) ;
2530 dir = QAD_Tools::addSlash(dir) ;
2531 dir = dir + "salome" ;
2532 dir = QAD_Tools::addSlash(dir) ;
2533 dir = dir + QAD_XmlHandler::_bibmap[ id ].latin1() ;
2534 MESSAGE ( " GUI library = " << dir );
2535 fileInfo.setFile(dir) ;
2536 if (fileInfo.exists()) {
2537 ToolsLib = fileInfo.fileName() ;
2542 if ( (dir = getenv("SALOME_ROOT_DIR")) && !found ) {
2543 dir = QAD_Tools::addSlash(dir) ;
2545 dir = QAD_Tools::addSlash(dir) ;
2546 dir = dir + "salome" ;
2547 dir = QAD_Tools::addSlash(dir) ;
2548 dir = dir + QAD_XmlHandler::_bibmap[ id ].latin1() ;
2549 MESSAGE ( " GUI library = " << dir );
2550 fileInfo.setFile(dir) ;
2551 if (fileInfo.exists()) {
2552 ToolsLib = fileInfo.fileName() ;
2558 ToolsLibrary.SetName(TCollection_AsciiString((char*)ToolsLib.latin1()).ToCString());
2559 bool ok = ToolsLibrary.DlOpen(OSD_RTLD_LAZY);
2561 if ( libToolsGUI ) {
2562 OSD_Function osdF = ToolsLibrary.DlSymb("OnGUIEvent");
2563 OneDim (*f1) = NULL;
2564 f1 = (bool (*) (int, QAD_Desktop*)) osdF;
2567 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
2568 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
2569 CORBA::ORB_var &orb = init(0 , 0 ) ;
2570 OSD_Function osdF = ToolsLibrary.DlSymb("OnGUIEvent");
2571 PTR_FACTORY_FUNCTION f1 = NULL;
2572 f1 = (PTR_FACTORY_FUNCTION) osdF;
2573 f1(orb,0,"Registry");
2576 QMessageBox::critical( this,
2578 tr( ToolsLibrary.DlError() ) );
2584 void QAD_Desktop::onDispatch(int id)
2586 if (!myActiveComp.isEmpty()) {
2587 OSD_Function osdF = mySharedLibrary.DlSymb("OnGUIEvent");
2588 OneDim (*f1) = NULL;
2589 if ( osdF != NULL ) {
2590 f1 = (bool (*) (int, QAD_Desktop*)) osdF;
2597 Returns the component's catalogue
2599 SALOME_ModuleCatalog::ModuleCatalog_var QAD_Desktop::getCatalogue()
2606 void QAD_Desktop::onComboActiveComponent( const QString & component ){
2607 onComboActiveComponent(component,true);
2609 void QAD_Desktop::onComboActiveComponent( const QString & component, bool isLoadData)
2611 if (myActiveStudy != 0) {
2612 if (myActiveComp.compare(component)!=0) {
2613 if (!myXmlHandler->myIdList.IsEmpty()) clearMenus();
2614 if ( myCombo->currentText() != component )
2615 myCombo->setCurrentText( component );
2616 if (component.compare(QString("Salome"))!= 0) {
2617 // QApplication::setOverrideCursor( Qt::waitCursor );
2618 myActiveComp = component;
2620 SALOME_Selection* oldSel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2622 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2623 if ( aButton->textLabel().compare(component)==0)
2624 aButton->setOn(true);
2626 aButton->setOn(false);
2629 myActiveStudy->Selection( component );
2630 if ( !loadComponent(mapComponentName[component]) ) {
2631 myCombo->setCurrentItem (0);
2632 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2633 aButton->setOn(false);
2638 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2639 SALOME_ListIteratorOfListIO It( oldSel->StoredIObjects() );
2640 for(;It.More();It.Next()) {
2641 int res = Sel->AddIObject( It.Value() );
2644 myActiveStudy->highlight( It.Value(), false );
2646 myActiveStudy->highlight( It.Value(), true );
2650 // Open new component's data in active study if any
2651 if(isLoadData) loadComponentData(mapComponentName[component]);
2654 myActiveStudy->updateObjBrowser(true);
2656 // QApplication::restoreOverrideCursor();
2658 } else { // component == "Salome"
2660 myActiveStudy->Selection( "Salome" );
2661 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2662 Sel->ClearIObjects();
2663 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2664 aButton->setOn(false);
2668 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2669 if ( aButton->textLabel().compare(component)==0)
2670 aButton->setOn(true);
2674 QMessageBox::critical( 0,
2676 tr( "WRN_LOAD_COMPONENT" ) );
2677 myCombo->setCurrentItem (0);
2678 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2679 aButton->setOn(false);
2686 void QAD_Desktop::activateComponent(const QString& theName, bool isLoadData){
2687 int nbItem = myCombo->count();
2690 for (int i = 0; i < nbItem; i++) {
2691 if (myCombo->text(i).compare(theName)==0) {
2696 myCombo->setCurrentItem (Index);
2697 onComboActiveComponent(theName,isLoadData);
2700 void QAD_Desktop::onButtonActiveComponent( )
2702 QToolButton* obj = (QToolButton*)sender();
2703 activateComponent(obj->textLabel());
2707 Clears All Resources of current component
2709 void QAD_Desktop::clearMenus()
2711 onActiveStudyChanged();
2714 myMenusList.clear();
2716 int length = myXmlHandler->myIdList.Length();
2717 for (int k=length; k>0; k--) {
2719 if ( menuBar()->findItem(myXmlHandler->myIdList.Value(k), &parent) )
2720 parent->removeItem( myXmlHandler->myIdList.Value(k) );
2725 if (myActiveMenus) {
2726 int nbtoolbars = myActiveMenus->getToolBarList().count();
2727 for (int k=0; k<nbtoolbars; k++) {
2728 myActiveMenus->getToolBarList().at(k)->hide();
2729 myActiveMenus->getToolBarList().at(k)->clear();
2731 myActiveMenus->clearToolBar();
2734 QList<QAD_ListPopupMenu> PopupList = myActiveMenus->getPopupMenuList();
2735 QAD_ListPopupMenu* aPopup;
2736 for(aPopup=PopupList.first();aPopup!=NULL;aPopup=PopupList.next()){
2737 aPopup->getPopup()->clear();
2740 myActiveMenus->clearPopupMenu();
2746 typedef bool TwoDim1(QKeyEvent* pe, QAD_Desktop*, QAD_StudyFrame*);
2748 Exports Key Events in active component ( GUI Librairy )
2750 void QAD_Desktop::onKeyPress( QKeyEvent* pe )
2752 // MESSAGE ( "QAD_Desktop::onKeyPress" )
2753 if (!myActiveComp.isEmpty()) {
2754 OSD_Function osdF = mySharedLibrary.DlSymb("OnKeyPress");
2755 if ( osdF != NULL ) {
2756 TwoDim1 (*f1) = (bool (*) (QKeyEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
2757 (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
2762 typedef bool TwoDim(QMouseEvent* pe, QAD_Desktop*, QAD_StudyFrame*);
2764 Exports Mouse Press Events in active component ( GUI Librairy )
2766 bool QAD_Desktop::onMousePress( QMouseEvent* pe )
2768 // MESSAGE ( "QAD_Desktop::onMousePress" )
2769 if (!myActiveComp.isEmpty()) {
2770 OSD_Function osdF = mySharedLibrary.DlSymb("OnMousePress");
2771 if ( osdF != NULL ) {
2772 TwoDim (*f1) = (bool (*) (QMouseEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
2773 return (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
2780 Exports Mouse Move Events in active component ( GUI Librairy )
2782 void QAD_Desktop::onMouseMove( QMouseEvent* pe )
2784 if (!myActiveComp.isEmpty()) {
2785 OSD_Function osdF = mySharedLibrary.DlSymb("OnMouseMove");
2786 if ( osdF != NULL ) {
2787 TwoDim (*f1) = (bool (*) (QMouseEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
2788 (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
2794 Returns name of active component
2796 const QString& QAD_Desktop::getActiveComponent() const
2798 return myActiveComp;
2802 typedef bool defineP( QString & theContext, QString & theParent, QString & theObject);
2804 void QAD_Desktop::definePopup(QString & theContext,
2805 QString & theParent,
2806 QString & theObject )
2808 if (!myActiveComp.isEmpty()) {
2809 OSD_Function osdF = mySharedLibrary.DlSymb("definePopup");
2810 if ( osdF != NULL ) {
2811 defineP (*f1) = (bool (*) (QString &, QString &, QString &)) osdF;
2812 (*f1)(theContext, theParent, theObject);
2820 void QAD_Desktop::createPopup(QPopupMenu* popupFather, QPopupMenu* popup,
2821 QString text, int popupID, bool separator)
2823 QMenuItem* item = popup->findItem(popupID);
2825 QPopupMenu* popupChild = item->popup();
2827 QPopupMenu* newPopup = new QPopupMenu;
2828 int count = popupChild->count();
2829 // add items at the top of <popupFather>
2830 for (int i = count - 1; i >= 0; i--) {
2831 int j = popupChild->idAt(i);
2832 QString text = popupChild->text(j);
2833 createPopup( newPopup, popupChild, text, j);
2835 popupFather->insertItem(popup->text(popupID),
2836 newPopup, popupID, 0);
2838 if ( !text.isNull() ) {
2839 popupFather->insertItem(popup->text(popupID),
2841 SLOT( onDispatch(int) ), 0, popupID, 0);// try adding item at the top
2842 } /*else if ( separator )
2843 popupFather->insertTearOffHandle(-1, 0);*/
2845 popupFather->insertSeparator(0);
2853 void QAD_Desktop::createPopup(QPopupMenu* popup, const QString & theContext,
2854 const QString & theParent, const QString & theObject )
2856 if ( !myActiveComp.isEmpty() &&
2857 getOperatorMenus()->createPopupMenu(theContext,theParent,theObject) != NULL ) {
2858 QPopupMenu* aPopup = getOperatorMenus()->createPopupMenu(theContext,theParent,theObject)->getPopup();
2859 int count = aPopup->count();
2861 //for (int i = 0; i < count; i++) {
2862 for (int i = count - 1; i >= 0; i--) {
2863 int id = aPopup->idAt(i);
2864 QString text = aPopup->text(id);
2865 //QString mes("Inserting popup menu item loaded from XML: ");
2867 //MESSAGE ( mes.latin1() )
2869 popup->insertItem(aPopup->text(id),
2871 SLOT( onDispatch(int) ), 0, id, 0);// try adding item at the top
2873 createPopup( popup, aPopup, text, id);
2876 //QString mes("Popup does not exist for given (Context = ");
2877 //mes += theContext;
2878 //mes += ", Parent = ";
2880 //mes += ", Object = ";
2882 //MESSAGE (mes.latin1())
2887 // Should be moved to SALOMEGUI_Application::onCreatePopup()...
2888 if ( myActiveComp.isEmpty() ) {
2889 popup->removeItem(QAD_Display_Popup_ID);
2890 popup->removeItem(QAD_DisplayOnly_Popup_ID);
2891 popup->removeItem(QAD_Erase_Popup_ID);
2892 int id = popup->idAt(popup->count()-1); // last item
2893 if (id < 0 && id != -1) popup->removeItem(id); // separator
2895 if ( popup && theParent.compare("ObjectBrowser")==0 ) {
2896 if ( popup->count()>0 ) {
2897 popup->insertItem (tr ("MEN_OPENWITH"), this, SLOT(onOpenWith()), 0, -1, 2);
2898 popup->insertSeparator (3);
2901 popup->insertItem (tr ("MEN_OPENWITH"), this, SLOT(onOpenWith()) );
2908 typedef bool activeStudyChanged(QAD_Desktop*);
2910 void QAD_Desktop::onActiveStudyChanged()
2912 if (!myActiveComp.isEmpty()) {
2913 OSD_Function osdF = mySharedLibrary.DlSymb("activeStudyChanged");
2914 if ( osdF != NULL ) {
2915 activeStudyChanged (*f1) = (bool (*) (QAD_Desktop*)) osdF;
2921 typedef bool customP(QAD_Desktop*, QPopupMenu*, const QString & theContext,
2922 const QString & theParent, const QString & theObject);
2924 Custom popup ( GUI Library )
2926 void QAD_Desktop::customPopup(QPopupMenu* popup, const QString & theContext,
2927 const QString & theParent, const QString & theObject)
2929 if (!myActiveComp.isEmpty()) {
2930 OSD_Function osdF = mySharedLibrary.DlSymb("customPopup");
2931 if ( osdF != NULL ) {
2932 customP (*f1) = (bool (*) (QAD_Desktop*, QPopupMenu*, const QString &,
2933 const QString &, const QString &)) osdF;
2934 (*f1)(this, popup, theContext, theParent, theObject);
2939 void QAD_Desktop::onObjectBrowser()
2941 bool checkDiff = false;
2943 bool state = QAD_CONFIG->getSetting("ObjectBrowser:AddColumn").compare("true") == 0;
2945 if ( myStdActions.at( PrefObjectBrowserEntryId )->isOn() != state )
2949 if ( myStdActions.at( PrefObjectBrowserEntryId )->isOn() ) {
2951 QAD_CONFIG->addSetting( "ObjectBrowser:AddColumn", "true");
2954 QAD_CONFIG->addSetting( "ObjectBrowser:AddColumn", "false");
2958 if ( myStdActions.at( PrefObjectBrowserValueId )->isOn() ) {
2960 QAD_CONFIG->addSetting( "ObjectBrowser:ValueColumn", "true");
2963 QAD_CONFIG->addSetting( "ObjectBrowser:ValueColumn", "false");
2967 if ( myStdActions.at( PrefObjectBrowserIAPPId )->isOn() ) {
2969 QAD_CONFIG->addSetting( "ObjectBrowser:IAPP", "true");
2972 QAD_CONFIG->addSetting( "ObjectBrowser:IAPP", "false");
2975 /* To sort created object in chrono order or reverse chrono order */
2976 bool showCHRONO_SORT ;
2977 if ( myStdActions.at( PrefObjectBrowserCHRONO_SORTId )->isOn() ) {
2978 showCHRONO_SORT = true;
2979 QAD_CONFIG->addSetting( "ObjectBrowser:CHRONO_SORT", "true");
2981 showCHRONO_SORT = false;
2982 QAD_CONFIG->addSetting( "ObjectBrowser:CHRONO_SORT", "false");
2985 if ( myActiveApp ) {
2986 QList<QAD_Study>& studies = myActiveApp->getStudies();
2987 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
2988 int nbSf = study->getStudyFramesCount();
2989 for ( int i = 0; i < nbSf; i++ ) {
2990 QAD_StudyFrame* sf = study->getStudyFrame(i);
2991 sf->getLeftFrame()->getObjectBrowser()->setShowInfoColumns( showEntry );
2992 sf->getLeftFrame()->getObjectBrowser()->setShowValueColumn( showValue );
2993 sf->getLeftFrame()->getObjectBrowser()->setEnableChronoSort( showCHRONO_SORT );
2994 // sf->getLeftFrame()->getObjectBrowser()->setShowIAPP( showIAPP ); // this is done by below updateObjBrowser() call
2996 study->updateObjBrowser(true);
3001 void QAD_Desktop::onViewerTrihedron()
3003 QString Size = QAD_CONFIG->getSetting("Viewer:TrihedronSize");
3006 SALOMEGUI_TrihedronSizeDlg *Dlg = new SALOMEGUI_TrihedronSizeDlg(this);
3007 if (!Size.isEmpty())
3008 Dlg->setTrihedronSize(Size.toInt());
3009 int r = Dlg->exec();
3010 dim = Dlg->getTrihedronSize();
3013 if (r == QDialog::Accepted) {
3014 QAD_CONFIG->addSetting("Viewer:TrihedronSize", dim);
3017 QList<QAD_Study>& studies = myActiveApp->getStudies();
3018 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3019 int nbSf = study->getStudyFramesCount();
3020 for ( int i = 0; i < nbSf; i++ ) {
3021 study->getStudyFrame(i)->getRightFrame()->getViewFrame()->SetTrihedronSize(dim);
3028 void QAD_Desktop::onDirList()
3030 // getting dir list from settings
3031 QStringList dirList = QStringList::split(';', QAD_CONFIG->getSetting("FileDlg:QuickDirList"), false);
3032 QAD_DirListDlg* dlg = new QAD_DirListDlg(this);
3033 dlg->setPathList(dirList);
3034 if ( dlg->exec() == QDialog::Accepted) {
3035 dlg->getPathList(dirList);
3036 QAD_CONFIG->addSetting("FileDlg:QuickDirList", dirList.join(";"));
3041 void QAD_Desktop::onConsoleFontAction()
3043 // getting font from settings
3044 QString fntSet = QAD_CONFIG->getSetting("Viewer:ConsoleFont");
3045 QFont font = QAD_Tools::stringToFont( fntSet );
3047 font = QFontDialog::getFont( &bOk, font, this );
3049 fntSet = QAD_Tools::fontToString( font );
3050 QAD_CONFIG->addSetting("Viewer:ConsoleFont", fntSet );
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()->getPyEditor()->setFont( font );
3058 study->getStudyFrame(i)->getRightFrame()->getMessage()->setFont( font );
3065 void QAD_Desktop::onSavePref()
3067 QAD_CONFIG->createConfigFile(true);
3070 //VRV: T2.5 - add default viewer
3071 void QAD_Desktop::onDefaultViewer(QAction * theAction)
3073 int type = VIEW_TYPE_MAX;
3076 if (myStdActions.at(DefaultViewerOCCId) == theAction)
3078 else if (myStdActions.at(DefaultViewerVTKId) == theAction)
3080 else if (myStdActions.at(DefaultGraphSupervisorId) == theAction)
3081 type = VIEW_GRAPHSUPERV;
3082 else if (myStdActions.at(DefaultPlot2dId) == theAction)
3084 if ( type != VIEW_TYPE_MAX )
3085 QAD_CONFIG->addSetting( "Viewer:DefaultViewer", QString::number( type ) );
3087 //VRV: T2.5 - add default viewer
3089 void QAD_Desktop::onViewerOCC()
3091 QString BackgroundColorRed = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorRed");
3092 QString BackgroundColorGreen = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorGreen");
3093 QString BackgroundColorBlue = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorBlue");
3096 if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3097 color = QColor(BackgroundColorRed.toInt(),
3098 BackgroundColorGreen.toInt(),
3099 BackgroundColorBlue.toInt());
3101 color = QColor(35, 136, 145);
3103 QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3106 if ( myActiveApp ) {
3107 QList<QAD_Study>& studies = myActiveApp->getStudies();
3108 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3109 int nbSf = study->getStudyFramesCount();
3110 for ( int i = 0; i < nbSf; i++ ) {
3111 QAD_StudyFrame* sf = study->getStudyFrame(i);
3112 if ( sf->getTypeView() == VIEW_OCC ) {
3113 sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3118 QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorRed", c.red() );
3119 QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorGreen", c.green() );
3120 QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorBlue", c.blue() );
3124 void QAD_Desktop::onGraphSupervisor()
3126 QString BackgroundColorRed = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorRed");
3127 QString BackgroundColorGreen = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorGreen");
3128 QString BackgroundColorBlue = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorBlue");
3131 if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3132 color = QColor(BackgroundColorRed.toInt(),
3133 BackgroundColorGreen.toInt(),
3134 BackgroundColorBlue.toInt());
3136 color = QColor(35, 136, 145);
3138 QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3141 if ( myActiveApp ) {
3142 QList<QAD_Study>& studies = myActiveApp->getStudies();
3143 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3144 int nbSf = study->getStudyFramesCount();
3145 for ( int i = 0; i < nbSf; i++ ) {
3146 QAD_StudyFrame* sf = study->getStudyFrame(i);
3147 if ( sf->getTypeView() == VIEW_GRAPHSUPERV ) {
3148 sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3154 QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorRed", c.red() );
3155 QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorGreen", c.green() );
3156 QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorBlue", c.blue() );
3160 void QAD_Desktop::onViewerVTK()
3162 QString BackgroundColorRed = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorRed");
3163 QString BackgroundColorGreen = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorGreen");
3164 QString BackgroundColorBlue = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorBlue");
3167 if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3168 color = QColor(BackgroundColorRed.toInt(),
3169 BackgroundColorGreen.toInt(),
3170 BackgroundColorBlue.toInt());
3172 color = QColor(0, 0, 0);
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_VTK ) {
3184 sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3190 QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorRed", c.red() );
3191 QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorGreen", c.green() );
3192 QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorBlue", c.blue() );
3196 void QAD_Desktop::onPlot2d()
3199 if ( QAD_CONFIG->hasSetting( "Plot2d:Background" ) ) {
3200 QString bgString = QAD_CONFIG->getSetting( "Plot2d:Background" );
3201 QStringList bgData = QStringList::split( ":", bgString, true );
3202 int bgRed = 0, bgGreen = 0, bgBlue = 0;
3203 if ( bgData.count() > 0 ) bgRed = bgData[ 0 ].toInt();
3204 if ( bgData.count() > 1 ) bgGreen = bgData[ 1 ].toInt();
3205 if ( bgData.count() > 2 ) bgBlue = bgData[ 2 ].toInt();
3206 color = QColor( bgRed, bgGreen, bgBlue );
3209 color = QColor(0, 0, 0);
3212 color = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3214 if ( color.isValid() ) {
3215 if ( myActiveApp ) {
3216 QList<QAD_Study>& studies = myActiveApp->getStudies();
3217 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3218 int nbSf = study->getStudyFramesCount();
3219 for ( int i = 0; i < nbSf; i++ ) {
3220 QAD_StudyFrame* sf = study->getStudyFrame(i);
3221 if ( sf->getTypeView() == VIEW_PLOT2D ) {
3222 sf->getRightFrame()->getViewFrame()->setBackgroundColor( color );
3228 bgData.append( QString::number( color.red() ) );
3229 bgData.append( QString::number( color.green() ) );
3230 bgData.append( QString::number( color.blue() ) );
3231 QAD_CONFIG->addSetting( "Plot2d:Background", bgData.join( ":" ) );
3236 void QAD_Desktop::helpAbout()
3238 SALOMEGUI_AboutDlg* About = new SALOMEGUI_AboutDlg( QAD_Application::getDesktop(), tr("MEN_ABOUT"));
3244 void QAD_Desktop::helpSearch()
3249 void QAD_Desktop::helpContents()
3251 if (myActiveComp == "")
3252 myActiveComp = "Salome";
3256 if (dir = getenv( getComponentName( myActiveComp ) + "_ROOT_DIR")) {
3257 root = QAD_Tools::addSlash( QAD_Tools::addSlash(dir) + QAD_Tools::addSlash("share") + QAD_Tools::addSlash("salome") + "doc" );
3258 if ( QFileInfo( root + "index.html" ).exists() ) {
3259 helpContext( root + "index.html", "" );
3262 root = QAD_Tools::addSlash( root + "html" );
3263 if ( QFileInfo( root + "index.html" ).exists() ) {
3264 helpContext( root + "index.html", "" );
3267 root = QAD_Tools::addSlash( root + "html" );
3268 if ( QFileInfo( root + "index.html" ).exists() ) {
3269 helpContext( root + "index.html", "" );
3275 //NRI getHelpWindow()->contents();
3276 getHelpWindow()->show();
3277 getHelpWindow()->raise();
3278 getHelpWindow()->setActiveWindow();
3282 void QAD_Desktop::helpContext(const QString& source, const QString& context)
3284 getHelpWindow()->context(source, context);
3285 getHelpWindow()->show();
3286 getHelpWindow()->raise();
3287 getHelpWindow()->setActiveWindow();
3290 /* Preferences/MultiFile Save */
3291 void QAD_Desktop::onMultiFileSave()
3293 if ( myStdActions.at( PrefMultiFileSave )->isOn() )
3294 QAD_CONFIG->addSetting( "Desktop:MultiFileSave", "true");
3296 QAD_CONFIG->addSetting( "Desktop:MultiFileSave", "false");
3299 /*********************************************************************
3300 ** Class: AppSelectionDlg
3301 ** Descr: Dialog for the selection of the application when several
3302 ** applications exist in the desktop and new study creation
3303 ** is activated by user.
3305 **********************************************************************/
3307 \class Desktop_AppSelectionDlg QAD_Desktop.h
3308 \brief Dialog for the selection of the application when several
3309 applications exist in the desktop and new study creation
3310 is activated by user.
3315 Desktop_AppSelectionDlg::Desktop_AppSelectionDlg( QAD_Desktop* desktop,
3316 QList<QAD_Application>& apps ) :
3317 QDialog( desktop, 0, true ),
3321 QAD_ASSERT_DEBUG_ONLY ( desktop );
3322 setCaption( tr("INF_DESK_DOC_CREATE") );
3323 if ( desktop->icon() )
3324 setIcon( *desktop->icon() );
3326 QBoxLayout* mainLayout = new QVBoxLayout( this, 5 );
3328 /* Create selection buttons */
3329 QVButtonGroup* buttonGrp = new QVButtonGroup ( this );
3330 buttonGrp->setExclusive ( true );
3331 QBoxLayout* vLayout = new QVBoxLayout( mainLayout, 5 );
3332 vLayout->addWidget ( buttonGrp );
3334 /* Create selection button for available app */
3336 for ( QAD_Application* app = myApps.first(); app; app = myApps.next(), id++ )
3338 /* add radio button for application */
3339 buttonGrp->insert( new QRadioButton( app->getStudyDescription() +
3340 " (*." + app->getStudyExtension() + ")", buttonGrp ), id );
3343 /* make the first application selected */
3344 buttonGrp->setButton( 0 );
3346 /* listen to the selection */
3347 QAD_ASSERT ( connect ( buttonGrp, SIGNAL(clicked(int)), this, SLOT(onAppSelected(int)) ));
3349 /* Create OK/Cancel buttons
3351 QBoxLayout* hLayout = new QHBoxLayout( mainLayout, 5 );
3352 QPushButton* buttonOK = new QPushButton( tr("BUT_OK"), this );
3353 QPushButton* buttonCancel = new QPushButton( tr("BUT_CANCEL"), this );
3354 QPushButton* buttonHelp = new QPushButton( tr("BUT_HELP"), this );
3355 buttonOK->setDefault( true );
3357 hLayout->addStretch();
3358 hLayout->addWidget( buttonOK );
3359 hLayout->addWidget( buttonCancel );
3360 hLayout->addWidget( buttonHelp );
3362 /* connect buttons */
3363 QAD_ASSERT ( connect( buttonOK, SIGNAL(clicked()), this, SLOT(accept())) );
3364 QAD_ASSERT ( connect( buttonCancel, SIGNAL(clicked()), this, SLOT(reject())) );
3365 QAD_ASSERT ( connect( buttonHelp, SIGNAL(clicked()), this, SLOT(onHelp())) );
3367 /* disable resizing */
3368 setFixedSize( 0, 0 );
3369 setSizePolicy( QSizePolicy ( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
3372 Desktop_AppSelectionDlg::~Desktop_AppSelectionDlg()
3376 QAD_Application* Desktop_AppSelectionDlg::selectedApp() const
3378 return myApps.at( myAppId );
3381 void Desktop_AppSelectionDlg::resizeEvent( QResizeEvent* e )
3383 QAD_Tools::centerWidget( this, parentWidget() );
3389 void Desktop_AppSelectionDlg::onAppSelected( int id )
3394 void Desktop_AppSelectionDlg::onHelp()