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();
1155 connect(myHelpWindow, SIGNAL(helpWindowClosed()), this, SLOT(onHelpWindowClosed()));
1157 return myHelpWindow;
1161 Called when desktop is closing
1163 void QAD_Desktop::closeEvent ( QCloseEvent* e )
1165 bool doClose = true;
1166 if ( myQueryClose ) {
1167 doClose = QAD_MessageBox::info2 ( this, tr("INF_DESK_EXIT"),
1168 tr("QUE_DESK_EXIT"), tr ("BUT_OK"),
1169 tr ("BUT_CANCEL"), QAD_YES,
1170 QAD_NO, QAD_NO ) == QAD_YES;
1174 for ( QAD_Application* app = myApps.first(); app; app = myApps.next() ) {
1175 QList<QAD_Study>& studies = app->getStudies();
1176 for(QAD_Study* study = studies.first(); study != 0; study = studies.next()) {
1177 if(myQueryClose && study->getStudyDocument()->IsModified()) {
1178 SALOMEGUI_CloseDlg aDlg( this );
1179 switch ( aDlg.exec() ) {
1181 if ( !onSaveStudy( study ) ) {
1182 putInfo( tr("INF_CANCELLED") );
1193 putInfo( tr("INF_CANCELLED") );
1201 myQueryClose = true;
1202 doClose ? e->accept() : e->ignore();
1206 Called when desktop is resized
1208 void QAD_Desktop::resizeEvent( QResizeEvent* e )
1210 QMainWindow::resizeEvent( e );
1211 myWorkspace->setGeometry( 1,1, centralWidget()->width()-2,
1212 centralWidget()->height()-2 );
1217 Terminates the application.
1219 void QAD_Desktop::onExit()
1224 /************************************************************************
1226 *************************************************************************/
1230 If several application are supported it displays dialog window
1231 to choose type of study.
1233 void QAD_Desktop::createStudy(){
1236 void QAD_Desktop::onNewStudy()
1238 unsigned numApps = myApps.count();
1241 onNewStudy ( myApps.at(0) );
1242 else { /* select the type of application for new study */
1243 Desktop_AppSelectionDlg selDlg( this, myApps );
1244 if ( selDlg.exec() == QDialog::Accepted ) {
1245 onNewStudy ( selDlg.selectedApp() );
1248 } else { /* no applications available in desktop */
1249 QAD_MessageBox::error1( this,
1251 tr("ERR_APP_NOAPP"),
1257 Creates new study for the given application.
1258 Calls the respective function of the application class.
1260 void QAD_Desktop::onNewStudy( QAD_Application* app )
1264 /* create new study of the specific app */
1265 putInfo ( tr ("INF_DOC_CREATING") );
1266 QAD_Study* newStudy = app->newStudy();
1269 /* can't create new study */
1270 QAD_MessageBox::error1( this, tr("ERR_ERROR"),
1271 tr("ERR_DOC_CANTCREATE"),
1274 putInfo ( tr("INF_READY") );
1278 Loads the existing study.
1280 void QAD_Desktop::onLoadStudy()
1282 QString name, studyname, ext;
1284 SALOMEGUI_LoadStudiesDlg* aDlg = new SALOMEGUI_LoadStudiesDlg( this, "Load Study", TRUE);
1286 CORBA::Object_var obj = myNameService->Resolve("/myStudyManager");
1287 SALOMEDS::StudyManager_var myStudyMgr = SALOMEDS::StudyManager::_narrow(obj);
1288 ASSERT(! CORBA::is_nil(myStudyMgr));
1289 SALOMEDS::ListOfOpenStudies_var List = myStudyMgr->GetOpenStudies();
1290 for (unsigned int ind = 0; ind < List->length();ind++) {
1291 studyname = List[ind];
1292 aDlg->ListComponent->insertItem( studyname );
1295 int retVal = aDlg->exec();
1296 studyname = aDlg->ListComponent->currentText();
1298 if (retVal == QDialog::Rejected)
1301 if ( studyname.isNull() || studyname.isEmpty() )
1305 name.replace( QRegExp(":"), "/" );
1308 Try to associate an application to the opened study.
1309 Assumed that the association study<->application is unique.
1311 bool appFound = false;
1312 putInfo ( tr("INF_DOC_OPENING") + " " + name );
1313 for ( QAD_Application* app = myApps.first(); app; app = myApps.next() )
1315 /* application found */
1316 if ( app->isStudyOpened( name ) )
1318 /* already opened: prompt for reopen */
1319 if ( QAD_MessageBox::warn2 ( this, tr("WRN_WARNING"),
1320 tr("QUE_DOC_ALREADYOPEN").arg( name ),
1321 tr ("BUT_YES"), tr ("BUT_NO"), QAD_YES, QAD_NO,
1322 QAD_NO ) == QAD_NO )
1324 putInfo ( tr("INF_READY") );
1327 /* now the study is closed to be re-opened */
1328 //don't ask user to remove study permanently
1329 if (app->getStudyByName ( name ) != NULL)
1330 onCloseStudy ( app->getStudyByName ( name ), false );
1331 else if (app->getStudyByName ( QAD_Tools::getFileNameFromPath( name, false )) != NULL)
1332 onCloseStudy ( app->getStudyByName ( QAD_Tools::getFileNameFromPath( name, false )), false );
1336 /* open the study */
1337 QAD_Study* openStudy = app->loadStudy( studyname );
1339 QAD_MessageBox::error1( this,
1341 tr("ERR_DOC_CANTOPEN") + "\n" + name,
1348 QAD_MessageBox::error1( this,
1350 tr("ERR_DOC_UNKNOWNTYPE"),
1353 putInfo ( tr("INF_READY") );
1357 Opens the existing study.
1358 Displays select file dialog and calls corresponding function of
1360 (application is defined according to extension of selected file).
1362 void QAD_Desktop::onOpenStudy()
1366 /* Select a file to open */
1367 name = selectFileName ( true );
1368 if ( name.isNull() || name.isEmpty() )
1371 // Workaround for non-existent files
1373 if (!fi.exists() || !fi.isFile()) {
1374 QAD_MessageBox::error1 ( this, tr("ERR_ERROR"),
1375 tr("ERR_DOC_CANTOPEN") +": " + name,
1380 CORBA::Object_var obj = myNameService->Resolve("/myStudyManager");
1381 SALOMEDS::StudyManager_var myStudyMgr = SALOMEDS::StudyManager::_narrow(obj);
1382 ASSERT(! CORBA::is_nil(myStudyMgr));
1383 SALOMEDS::ListOfOpenStudies_var List = myStudyMgr->GetOpenStudies();
1384 for (unsigned int ind = 0; ind < List->length();ind++) {
1385 QString NameExistingStudy(List[ind]);
1386 QString NameOpeningStudy = QAD_Tools::getFileNameFromPath( name, false );
1388 if ( NameExistingStudy.compare( NameOpeningStudy ) == 0 ) {
1389 if ( QAD_MessageBox::warn2 ( this, tr("WRN_WARNING"),
1390 tr("QUE_DOC_ALREADYEXIST").arg( name ),
1391 tr ("BUT_YES"), tr ("BUT_NO"), QAD_YES, QAD_NO,
1392 QAD_NO ) == QAD_NO )
1394 putInfo ( tr("INF_READY") );
1406 Try to associate an application to the opened study.
1407 Assumed that the association study<->application is unique.
1409 bool appFound = false;
1410 putInfo ( tr("INF_DOC_OPENING") + " " + name );
1411 for ( QAD_Application* app = myApps.first(); app; app = myApps.next() )
1413 QString ext = QAD_Tools::getFileExtensionFromPath ( name );
1414 if ( app->getStudyExtension() == ext )
1416 /* application found */
1417 if ( app->isStudyOpened( name ) )
1419 /* already opened: prompt for reopen */
1420 if ( QAD_MessageBox::warn2 ( this, tr("WRN_WARNING"),
1421 tr("QUE_DOC_ALREADYOPEN").arg( name ),
1422 tr ("BUT_YES"), tr ("BUT_NO"), QAD_YES, QAD_NO,
1423 QAD_NO ) == QAD_NO )
1425 putInfo ( tr("INF_READY") );
1428 /* now the study is closed to be re-opened */
1429 //don't ask user to remove study permanently
1430 if (app->getStudyByName ( name ) != NULL)
1431 onCloseStudy ( app->getStudyByName ( name ), false );
1432 else if (app->getStudyByName ( QAD_Tools::getFileNameFromPath( name, false )) != NULL)
1433 onCloseStudy ( app->getStudyByName ( QAD_Tools::getFileNameFromPath( name, false )), false );
1437 /* open the study */
1438 QAD_Study* openStudy = app->openStudy( name );
1440 QAD_MessageBox::error1( this,
1442 tr("ERR_DOC_CANTOPEN") + "\n" + name,
1444 } else if (myActiveComp != "") {
1445 QApplication::setOverrideCursor( Qt::waitCursor );
1446 loadComponentData(mapComponentName[myActiveComp]);
1447 openStudy->updateObjBrowser(true);
1448 QApplication::restoreOverrideCursor();
1456 QAD_MessageBox::error1( this,
1458 tr("ERR_DOC_UNKNOWNTYPE"),
1461 putInfo ( tr("INF_READY") );
1464 bool QAD_Desktop::loadComponentData( const QString& compName )
1466 // Open component's data in active study if any
1467 MESSAGE("loadComponentData(): Opening component data")
1468 if (!myActiveStudy) {
1469 MESSAGE("loadComponentData(): No active study exists")
1473 Engines::Component_var comp ;
1474 if ( compName.compare("Supervision") == 0 ) {
1475 comp = getEngine( "SuperVisionContainer", compName) ;
1478 /* comp = ( compName.compare("Data1") != 0 ) ? getEngine( "FactoryServer", compName) :
1479 getEngine( "FactoryServerPy", compName);
1481 comp = getEngine( "FactoryServer", compName);
1482 if ( comp->_is_nil() )
1483 comp = getEngine( "FactoryServerPy", compName);
1486 SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
1487 SALOMEDS::SComponent_var SCO = SALOMEDS::SComponent::_narrow(aStudy->FindObject(compName));
1489 if (!SCO->_is_nil()) {
1490 if (!CORBA::is_nil(comp)) {
1491 SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
1492 if (!CORBA::is_nil(driver)) {
1493 SALOMEDS::StudyBuilder_var B = aStudy->NewBuilder();
1494 if (!CORBA::is_nil(B)) {
1495 QAD_Operation* op = new QAD_Operation( myActiveStudy );
1497 B->LoadWith(SCO,driver);
1503 MESSAGE("loadComponentData(): Driver is null");
1507 MESSAGE("loadComponentData(): Engine is null");
1511 MESSAGE("loadComponentData(): SComponent is null");
1519 Saves the active study
1521 bool QAD_Desktop::onSaveStudy()
1523 return onSaveStudy ( myActiveStudy );
1527 Saves the given study
1529 bool QAD_Desktop::onSaveStudy( QAD_Study* study )
1531 if ( !study ) return true;
1533 if ( !study->isSaved() )
1534 return onSaveAsStudy ( study );
1536 /* saving study... */
1537 QAD_Application* app = study->getApp();
1538 QAD_ASSERT_DEBUG_ONLY ( app );
1539 putInfo ( tr("INF_DOC_SAVING") + study->getTitle() );
1540 if ( !app->saveStudy( study ) )
1542 putInfo( tr("INF_CANCELLED") );
1547 putInfo ( tr("INF_DOC_SAVED").arg( "" ) );
1552 Saves the active study under a new name
1554 bool QAD_Desktop::onSaveAsStudy()
1556 return onSaveAsStudy( myActiveStudy );
1560 Saves the given study under a new name
1562 bool QAD_Desktop::onSaveAsStudy( QAD_Study* study )
1564 if ( !study ) return true;
1566 /* Save study in a format supported by its application
1568 QAD_Application* app = study->getApp();
1569 QAD_ASSERT_DEBUG_ONLY ( app );
1571 /* Select a file where to save
1573 QString name = selectFileName ( false );
1574 if ( name.isNull() || name.isEmpty() )
1576 putInfo( tr("INF_CANCELLED") );
1582 putInfo ( tr("INF_DOC_SAVING") + name );
1583 if ( !app->saveAsStudy( study, name ) ) {
1584 /* can't save the file */
1585 QAD_MessageBox::error1( this,
1587 tr("ERR_DOC_CANTWRITE") + "\n" + name,
1590 return false; /* cannot save */
1592 putInfo ( tr("INF_DOC_SAVED").arg( name ) );
1593 return true; /* saved ok */
1597 Closes the active study
1599 bool QAD_Desktop::onCloseStudy()
1601 bool close = this->onCloseStudy ( myActiveStudy, true );
1602 if ( close && !myXmlHandler->myIdList.IsEmpty() ) {
1605 myCombo->setCurrentItem (0);
1606 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
1607 aButton->setOn(false);
1614 Closes the given study and ask user to remove study
1615 from the study manager permanently
1617 bool QAD_Desktop::onCloseStudy( QAD_Study* study )
1619 return onCloseStudy( study, true );
1623 Closes the given study and ask user to remove study
1624 from the study manager permanently if ask is equal true
1626 bool QAD_Desktop::onCloseStudy( QAD_Study* study, bool ask )
1628 bool removePerm = false;
1632 SALOMEGUI_CloseDlg aDlg( this );
1633 int res = aDlg.exec();
1638 //if ( study->isModified() )
1639 if ( !onSaveStudy( study ) ) {
1640 putInfo( tr("INF_CANCELLED") );
1653 putInfo( tr("INF_CANCELLED") );
1657 /* close active component */
1658 if (!myXmlHandler->myIdList.IsEmpty())
1662 myCombo->setCurrentItem (0);
1663 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() )
1664 aButton->setOn(false);
1665 qApp->processEvents();
1667 /* close the study */
1668 return study->getApp()->closeStudy( study, removePerm );
1671 // Displays study properties dialog box
1672 void QAD_Desktop::onStudyProperties()
1674 if (myActiveStudy) {
1676 QAD_Operation* op = new QAD_Operation( myActiveStudy );
1679 SALOMEGUI_StudyPropertiesDlg aDlg(this);
1680 int res = aDlg.exec();
1682 if ( res == QDialog::Accepted && aDlg.isChanged() )
1687 // T2.12 - add the word "locked" to study frame captions if <myActiveStudy> study is locked
1688 myActiveStudy->updateCaptions();
1694 locate all windows in cascade mode
1697 void QAD_Desktop::onCascade()
1699 myWorkspace->cascade();
1700 int w = myWorkspace->width();
1701 int h = myWorkspace->height();
1702 QWidgetList wList = myWorkspace->windowList();
1703 QWidgetListIt it(wList);
1705 for(;it.current(); ++it)
1706 it.current()->resize(0.8*w, 0.8*h);
1710 called when help window closed
1712 void QAD_Desktop::onHelpWindowClosed()
1718 Called when 'view status bar' option
1721 void QAD_Desktop::onViewStatusBar()
1723 bool show = myStdActions.at( ViewStatusBarId )->isOn();
1724 if ( show == myStatusBar->isVisible() )
1727 myStatusBar->show();
1729 myStatusBar->hide();
1733 Called when View/Toolbars popup menu is about to show
1735 void QAD_Desktop::onToolBarPopupAboutToShow()
1737 myToolBarAction.clear();
1738 myToolBarsPopup.clear();
1739 QPtrList<QDockWindow> wlist = dockWindows();
1740 for ( QDockWindow* w = wlist.first(); w; w = wlist.next() ) {
1741 if ( w->inherits( "QToolBar" ) ) {
1742 QToolBar* tb = ( QToolBar* )w;
1743 if ( appropriate( tb ) ) {
1744 ToggleAction* a = new ToggleAction( tb->label(), tb->label(), 0, this, 0, true );
1745 a->setStatusTip ( tr("PRP_DESK_VIEW_TOOLBAR") );
1746 a->setOn( tb->isVisible() );
1747 QAD_ASSERT( connect( a, SIGNAL( toggledOn() ), tb, SLOT( show() ) ) );
1748 QAD_ASSERT( connect( a, SIGNAL( toggledOff() ), tb, SLOT( hide() ) ) );
1749 a->addTo( &myToolBarsPopup );
1750 myToolBarAction.append( a );
1757 Called on 'View\Selection Mode'
1759 void QAD_Desktop::onSelectionMode()
1761 const QAction* obj = (QAction*) sender();
1763 int SelectionMode = 4;
1765 if ( obj == myStdActions.at(SelectionActorId) ) {
1767 if ( obj->isOn() ) {
1768 myStdActions.at(SelectionCellId)->setOn(false);
1769 myStdActions.at(SelectionEdgeId)->setOn(false);
1770 myStdActions.at(SelectionPointId)->setOn(false);
1772 myStdActions.at(SelectionActorId)->setOn(true);
1774 } else if ( obj == myStdActions.at(SelectionCellId) ) {
1776 if ( obj->isOn() ) {
1777 myStdActions.at(SelectionActorId)->setOn(false);
1778 myStdActions.at(SelectionEdgeId)->setOn(false);
1779 myStdActions.at(SelectionPointId)->setOn(false);
1781 myStdActions.at(SelectionActorId)->setOn(true);
1783 } else if ( obj == myStdActions.at(SelectionEdgeId) ) {
1785 if ( obj->isOn() ) {
1786 myStdActions.at(SelectionActorId)->setOn(false);
1787 myStdActions.at(SelectionCellId)->setOn(false);
1788 myStdActions.at(SelectionPointId)->setOn(false);
1790 myStdActions.at(SelectionActorId)->setOn(true);
1792 } else if ( obj == myStdActions.at(SelectionPointId) ) {
1794 if ( obj->isOn() ) {
1795 myStdActions.at(SelectionEdgeId)->setOn(false);
1796 myStdActions.at(SelectionCellId)->setOn(false);
1797 myStdActions.at(SelectionActorId)->setOn(false);
1799 myStdActions.at(SelectionActorId)->setOn(true);
1802 QAD_StudyFrame* sf = myActiveApp->getActiveStudy()->getActiveStudyFrame();
1803 sf->getRightFrame()->getViewFrame()->SetSelectionMode( SelectionMode );
1805 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveApp->getActiveStudy()->getSelection() );
1806 Sel->SetSelectionMode( SelectionMode );
1810 Called on 'View\Selection Mode'
1812 void QAD_Desktop::SetSelectionMode(int mode, bool activeCompOnly)
1817 myStdActions.at(SelectionEdgeId)->setOn(false);
1818 myStdActions.at(SelectionCellId)->setOn(false);
1819 myStdActions.at(SelectionActorId)->setOn(false);
1820 myStdActions.at(SelectionPointId)->setOn(true);
1825 myStdActions.at(SelectionActorId)->setOn(false);
1826 myStdActions.at(SelectionCellId)->setOn(false);
1827 myStdActions.at(SelectionPointId)->setOn(false);
1828 myStdActions.at(SelectionEdgeId)->setOn(true);
1833 myStdActions.at(SelectionActorId)->setOn(false);
1834 myStdActions.at(SelectionEdgeId)->setOn(false);
1835 myStdActions.at(SelectionPointId)->setOn(false);
1836 myStdActions.at(SelectionCellId)->setOn(true);
1841 myStdActions.at(SelectionCellId)->setOn(false);
1842 myStdActions.at(SelectionEdgeId)->setOn(false);
1843 myStdActions.at(SelectionPointId)->setOn(false);
1844 myStdActions.at(SelectionActorId)->setOn(true);
1849 QAD_StudyFrame* sf = myActiveApp->getActiveStudy()->getActiveStudyFrame();
1850 if ( sf->getTypeView() == VIEW_VTK ) {
1851 sf->getRightFrame()->getViewFrame()->SetSelectionMode( mode );
1852 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveApp->getActiveStudy()->getSelection() );
1853 Sel->SetSelectionMode( mode, activeCompOnly );
1859 Called on 'Window\NewWindow3d'
1861 void QAD_Desktop::onNewWindow3d()
1865 //VRV: T2.5 - add default viewer
1866 QApplication::restoreOverrideCursor();
1867 SALOMEGUI_ViewChoiceDlg *choice = new SALOMEGUI_ViewChoiceDlg(this, "", TRUE);
1868 int r = choice->exec();
1871 myActiveApp->getActiveStudy()->newWindow3d(QString(""),(ViewType)(choice->getSelectedViewer()));
1873 //VRV: T2.5 - add default viewer
1875 const QAction* obj = (QAction*) sender();
1876 if ( obj == myStdActions.at(ViewOCCId) ) {
1877 myActiveApp->getActiveStudy()->newWindow3d(QString(""),(ViewType)(0));
1878 } else if ( obj == myStdActions.at(ViewVTKId) ) {
1879 myActiveApp->getActiveStudy()->newWindow3d(QString(""),(ViewType)(1));
1880 } else if ( obj == myStdActions.at(ViewPlot2dId) ) {
1881 myActiveApp->getActiveStudy()->newWindow3d(QString(""),(ViewType)(3));
1887 Called on 'help\contents'
1889 void QAD_Desktop::onHelpContents()
1892 myActiveApp->helpContents();
1898 Called on 'help\search'
1900 void QAD_Desktop::onHelpSearch()
1903 myActiveApp->helpSearch();
1909 Called on 'help\about'
1911 void QAD_Desktop::onHelpAbout()
1914 myActiveApp->helpAbout();
1921 Activates the application and its active study
1923 void QAD_Desktop::onActivateApp( QAD_Application* activeApp )
1925 bool appChanged = ( activeApp != myActiveApp );
1928 updateDesktop( DeactivateApp );
1932 myActiveApp = activeApp;
1933 myActiveStudy = myActiveApp->getActiveStudy();
1943 updateDesktop( ActivateApp );
1944 updateCaption( (activeApp != NULL) ? ActivateApp : DeactivateApp );
1950 Called when the last study is removed from
1951 the application 'app'.
1953 void QAD_Desktop::onDeactivateApp(QAD_Application* app)
1955 if ( app && app == myActiveApp )
1960 Enables/disables standard actions
1962 void QAD_Desktop::updateActions()
1964 myStdActions.at( FileCloseId )->setEnabled ( myActiveStudy != NULL );
1965 myStdActions.at( FileSaveId )->setEnabled ( myActiveStudy != NULL );
1966 myStdActions.at( FileSaveAsId )->setEnabled ( myActiveStudy != NULL );
1967 myStdActions.at( FilePropsId )->setEnabled( myActiveStudy != NULL );
1968 // myStdActions.at( HelpContentsId )->setEnabled ( myActiveApp != NULL );
1969 // myStdActions.at( HelpSearchId )->setEnabled ( myActiveApp != NULL );
1970 // myStdActions.at( HelpWhatsThisId )->setEnabled ( myActiveApp != NULL );
1971 // myStdActions.at( HelpAboutId )->setEnabled ( myActiveApp != NULL );
1973 // myToolsPopup.setEnabled ( myActiveStudy != NULL );
1974 // myPrefPopup.setEnabled ( myActiveStudy != NULL );
1976 mySelectionModePopup.setEnabled ( myActiveStudy != NULL );
1980 Called when 'Window' popup is about to show
1982 void QAD_Desktop::onWindowPopupAboutToShow()
1984 /* add cascade/tile items */
1985 myWindowPopup.clear();
1988 //myStdActions.at( WindowNew3dId )->addTo( &myWindowPopup );
1989 myWindowPopup.insertItem( tr("MEN_DESK_WINDOW_NEW3D"), &myNewViewPopup, WindowNew3dId );
1990 //myStdActions.at( WindowNew3dId )->setEnabled( true );
1991 myWindowPopup.setItemEnabled( WindowNew3dId, true );
1993 myStdActions.at( WindowCascadeId )->addTo( &myWindowPopup );
1994 myStdActions.at( WindowCascadeId )->setEnabled( true );
1995 myStdActions.at( WindowTileId )->addTo( &myWindowPopup );
1996 myStdActions.at( WindowTileId )->setEnabled( true );
1998 /* add names of opened studies */
1999 QWidgetList windows = myWorkspace->windowList();
2000 if ( windows.isEmpty() )
2002 //NRI : SAL2214 myStdActions.at( WindowNew3dId )->setEnabled( false );
2003 myWindowPopup.setItemEnabled( WindowNew3dId, false );
2005 myStdActions.at( WindowCascadeId )->setEnabled( false );
2006 myStdActions.at( WindowTileId )->setEnabled( false );
2010 myWindowPopup.insertSeparator();
2011 for ( int i = 0; i < int(windows.count()); ++i )
2013 int id = myWindowPopup.insertItem( windows.at(i)->caption(),
2014 this, SLOT( onWindowsPopupActivated( int ) ) );
2015 myWindowPopup.setItemParameter( id, i );
2016 myWindowPopup.setItemChecked( id, myWorkspace->activeWindow() == windows.at(i) );
2018 QAD_ASSERT( connect( &myWindowPopup, SIGNAL(highlighted( int )), this,
2019 SLOT(onWindowsPopupStatusText( int )) ));
2024 Called when the item with 'id' of 'Windows' popup
2027 void QAD_Desktop::onWindowsPopupStatusText( int id )
2029 int cascadeId = myWindowPopup.idAt( 0 );
2030 int tileId = myWindowPopup.idAt( 1 );
2031 if ( id == cascadeId || id == tileId )
2033 putInfo( tr("PRP_DESK_WINDOW_ACTIVATE") );
2037 Called when user wants to activate a child window with 'wid'
2040 void QAD_Desktop::onWindowsPopupActivated( int wid )
2042 QWidget* w = myWorkspace->windowList().at( wid );
2043 if ( w ) w->setFocus();
2047 Selects a file name when opening or saving files.
2048 The basic implementation just uses the standard
2050 Please redefine if another behaviour is required.
2052 QString QAD_Desktop::selectFileName ( bool open )
2054 QAD_FileDlg* fd = new QAD_FileDlg( this, open, true, true );
2058 QStringList filters;
2061 // All the file types of the supported applications
2063 for ( QAD_Application* app = myApps.first(); app; app = myApps.next() )
2065 filters += app->getStudyDescription() + " " + tr("DESK_FILES") + " " +
2066 "(*." + app->getStudyExtension() + ")";
2070 QAD_ASSERT_DEBUG_ONLY ( myActiveStudy );
2071 if (myActiveStudy) {
2072 // get file name of active study
2073 name = QAD_Tools::getFileNameFromPath ( myActiveStudy->getTitle() );
2074 // get path to the active study file
2075 dir = QAD_Tools::getDirFromPath ( myActiveStudy->getPath(), false );
2077 QAD_ASSERT_DEBUG_ONLY ( !name.isNull() );
2078 // the file types supported by the active application
2079 filters += myActiveApp->getStudyDescription() + " " + tr("DESK_FILES") + " " +
2080 "(*." + myActiveApp->getStudyExtension() + ")" ;
2082 if (!dir.isEmpty()) {
2083 // when saving document ("Save As" command) - to get dir from active study filename
2084 // for new documents - to use last opened directory
2087 fd->setSelection( name );
2088 fd->setFilters( filters );
2091 QString filename = fd->selectedFile();
2093 qApp->processEvents();
2098 Closes all the studies of 'app'. Returns
2099 'true' if thay are closed OK, 'false' at least
2100 one can't be closed or user cancel the closure.
2102 bool QAD_Desktop::closeAllStudies( QAD_Application* app )
2104 QList<QAD_Study>& studies = app->getStudies();
2105 while ( !studies.isEmpty() )
2107 //don't ask user to remove study permanently
2108 if ( !onCloseStudy( studies.at(0), false ) )
2109 return false; /* user cancelled closing */
2115 Called on Popup item when SComponent representation in Object Browser is selected.
2117 void QAD_Desktop::onOpenWith()
2119 Engines::Component_var comp;
2120 QString ComponentSelected;
2122 SALOMEDS::SObject_var SO;
2123 SALOMEDS::SComponent_var SCO;
2124 SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
2125 SALOMEDS::GenericAttribute_var anAttr;
2126 SALOMEDS::AttributeName_var aName;
2128 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2129 if ( Sel->IObjectCount() == 1 ) {
2130 Handle(SALOME_InteractiveObject) IO = Sel->firstIObject();
2131 SO = aStudy->FindObjectID( IO->getEntry() );
2132 SCO = SO->GetFatherComponent();
2134 if (SCO->FindAttribute(anAttr, "AttributeName")) {
2135 aName = SALOMEDS::AttributeName::_narrow(anAttr);
2136 name = aName->Value();
2137 SALOME_ModuleCatalog::Acomponent_var Comp = myCatalogue->GetComponent( mapComponentName[name] );
2138 if ( !Comp->_is_nil() ) {
2140 SALOME_ModuleCatalog::ListOfComponents_var list_type_composants =
2141 myCatalogue->GetTypedComponentList( Comp->component_type() );
2143 if ( list_type_composants->length() == 1 ) {
2144 ComponentSelected = name;
2145 } else if ( list_type_composants->length() > 1 ) {
2146 SALOMEGUI_OpenWith* aDlg = new SALOMEGUI_OpenWith( this );
2147 for (unsigned int ind = 0; ind < list_type_composants->length();ind++) {
2148 aDlg->addComponent( strdup(list_type_composants[ind]) );
2151 int retVal = aDlg->exec();
2152 ComponentSelected = aDlg->getComponent();
2154 if ( retVal == QDialog::Rejected || ComponentSelected.isEmpty()) {
2158 MESSAGE( "No component with type : " << Comp->component_type() << " exists" );
2163 MESSAGE( "This component not exists in the catalog" );
2167 QApplication::setOverrideCursor( Qt::waitCursor );
2168 Sel->ClearIObjects();
2170 // if (loadComponentData(ComponentSelected)) {
2171 onComboActiveComponent(ComponentSelected);
2172 // int nbItem = myCombo->count();
2174 // for (int i = 0; i < nbItem; i++) {
2175 // if (myCombo->text(i).compare(ComponentSelected)==0) {
2180 // myCombo->setCurrentItem(Index);
2181 // myActiveStudy->updateObjBrowser(true);
2185 QApplication::restoreOverrideCursor();
2188 typedef bool OneDim1(QAD_Desktop*);
2191 Called to define settings of component.
2193 void QAD_Desktop::setSettings()
2195 if (!myActiveComp.isEmpty()) {
2196 OSD_Function osdF = mySharedLibrary.DlSymb("SetSettings");
2197 if ( osdF != NULL ) {
2198 OneDim1 (*f1) = (bool (*) (QAD_Desktop*)) osdF;
2205 Called to load Component : xml resources and GUI librairy.
2207 bool QAD_Desktop::loadComponent(QString Component)
2210 QString resDir("/"); //NRI : Pb under Windows
2212 QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
2215 if (!resMgr->loadResources( Component, msg ))
2217 //NRI QCString errMsg;
2218 // errMsg.sprintf( "Do not load all resources for module %sGUI.\n" ,
2219 // Component.latin1() );
2221 QMessageBox::warning( this, tr("WRN_WARNING"), msg, tr ("BUT_OK") );
2226 /* Parse xml file */
2227 myXmlHandler = new QAD_XmlHandler();
2228 myXmlHandler->setMainWindow(this);
2229 if (!myXmlHandler->setComponent(resMgr->resources( Component ))) return false;
2231 QString language = resMgr->language( Component );
2233 QString ComponentXml = Component + "_" + language + ".xml";
2234 //ComponentXml = resMgr->resources(Component + "GUI") ;
2235 //ComponentXml = QAD_Tools::addSlash(ComponentXml) ;
2236 ComponentXml = QAD_Tools::addSlash( resMgr->findFile( ComponentXml, Component ) ) + ComponentXml;
2237 QFile file( ComponentXml );
2239 if ( !file.exists() || !file.open( IO_ReadOnly ) ) {
2241 errMsg.sprintf( "Cannot open xml file: %s\n.",
2242 (file.name()).latin1() );
2244 QMessageBox::critical( this, tr("ERR_ERROR"), errMsg, tr ("BUT_OK") );
2249 QXmlInputSource source( file );
2250 QXmlSimpleReader reader;
2251 reader.setContentHandler( myXmlHandler );
2252 reader.setErrorHandler( myXmlHandler );
2253 bool ok = reader.parse( source );
2257 QMessageBox::critical( this,
2258 tr( "INF_PARSE_ERROR" ),
2259 tr( myXmlHandler->errorProtocol() ) );
2263 myMenusList=myXmlHandler->myMenusList;
2264 myActiveMenus=myMenusList.at(0);
2265 myOperatorMenus->showMenuBar(0);
2266 myActiveMenus->showAllToolBars();
2268 /* Components toolbars */
2271 nbToolbars = myActiveMenus->getToolBarList().count();
2272 /* Open Shared Library */
2273 mySharedLibrary = OSD_SharedLibrary();
2275 QString ComponentLib;
2277 QFileInfo fileInfo ;
2278 QString fileString ;
2281 if ( libs = getenv("LD_LIBRARY_PATH")) {
2282 MESSAGE ( " LD_LIBRARY_PATH : " << libs )
2283 QStringList dirList = QStringList::split( SEPARATOR, libs, false ); // skip empty entries
2284 for ( int i = dirList.count()-1; i >= 0; i-- ) {
2287 fileString = QAD_Tools::addSlash( dir ) + "lib" + Component + "GUI.dll" ;
2289 fileString = QAD_Tools::addSlash( dir ) + "lib" + Component + "GUI.so" ;
2292 fileInfo.setFile(fileString) ;
2293 if (fileInfo.exists()) {
2294 MESSAGE ( " GUI library = " << fileString )
2295 ComponentLib = fileInfo.fileName() ;
2299 MESSAGE ( " GUI library not found " )
2301 // bool found = false;
2302 // if ( dir = getenv("SALOME_SITE_DIR")) {
2303 // dir = QAD_Tools::addSlash(dir) ;
2304 // dir = dir + "lib" ;
2305 // dir = QAD_Tools::addSlash(dir) ;
2306 // dir = dir + "salome" ;
2307 // dir = QAD_Tools::addSlash(dir) ;
2309 // dir = dir + "lib" + Component.latin1() + "GUI.dll" ;
2311 // dir = dir + "lib" + Component.latin1() + "GUI.so" ;
2313 // MESSAGE ( " GUI library = " << dir )
2314 // fileInfo.setFile(dir) ;
2315 // if (fileInfo.exists()) {
2316 // ComponentLib = fileInfo.fileName() ;
2321 // if ( (dir = getenv("SALOME_ROOT_DIR")) && !found ) {
2322 // dir = QAD_Tools::addSlash(dir) ;
2323 // dir = dir + "lib" ;
2324 // dir = QAD_Tools::addSlash(dir) ;
2325 // dir = dir + "salome" ;
2326 // dir = QAD_Tools::addSlash(dir) ;
2328 // dir = dir + "lib" + Component.latin1() + "GUI.dll" ;
2330 // dir = dir + "lib" + Component.latin1() + "GUI.so" ;
2332 // MESSAGE ( " GUI library = " << dir )
2333 // fileInfo.setFile(dir) ;
2334 // if (fileInfo.exists()) {
2335 // ComponentLib = fileInfo.fileName() ;
2340 mySharedLibrary.SetName(TCollection_AsciiString((char*)ComponentLib.latin1()).ToCString());
2341 ok = mySharedLibrary.DlOpen(OSD_RTLD_LAZY);
2344 QMessageBox::critical( this,
2346 tr( mySharedLibrary.DlError() ) );
2351 OSD_Function osdF = mySharedLibrary.DlSymb("SetSettings");
2352 if ( osdF != NULL ) {
2353 OneDim1 (*f1) = (bool (*) (QAD_Desktop*)) osdF;
2357 /* COMPONENT INTERFACE */
2358 SALOME_ModuleCatalog::Acomponent_ptr aComponent =
2359 myCatalogue->GetComponent(Component.latin1());
2361 if (CORBA::is_nil (aComponent)) {
2362 MESSAGE( "Catalog Error : Component not found in the catalog" )
2366 myActiveStudy->setMessage(QString("Component : ") +
2367 aComponent->componentusername() + " created " );
2368 myActiveStudy->setMessage(QString("Type : ") +
2369 QString::number(aComponent->component_type()));
2370 myActiveStudy->setMessage(QString("Constraint : ") +
2371 aComponent->constraint() );
2373 /* obtain interfaces list of the component */
2374 SALOME_ModuleCatalog::ListOfInterfaces_var _list =
2375 new SALOME_ModuleCatalog::ListOfInterfaces;
2376 _list = aComponent->GetInterfaceList();
2378 if (_list->length() != 0 ) {
2380 for (unsigned int ind = 0; ind < _list->length();ind++)
2381 myActiveStudy->setMessage( QString("Interface name : ") +
2385 /* obtain services list of the component */
2386 SALOME_ModuleCatalog::ListOfServices_var list_services_component =
2387 new SALOME_ModuleCatalog::ListOfServices;
2388 list_services_component = aComponent->GetServiceList(_list[0]);
2390 if (list_services_component->length() != 0 ) {
2392 for (unsigned int ind = 0; ind < list_services_component->length();ind++)
2393 myActiveStudy->setMessage( QString("Service name : ") +
2394 list_services_component[ind] );
2396 // Get a service of the component
2397 SALOME_ModuleCatalog::Service_var service = new SALOME_ModuleCatalog::Service;
2398 service = aComponent->GetService(_list[0],list_services_component[0]) ;
2399 myActiveStudy->setMessage( QString("Service name: ") + service->ServiceName);
2400 for (unsigned int ind1 = 0; ind1 <service->ServiceinParameter.length();ind1++) {
2401 myActiveStudy->setMessage( QString("Type of the in Parameter of this service : ") +
2402 (const char *) service->ServiceinParameter[ind1].Parametertype);
2403 myActiveStudy->setMessage( QString("Name of the in Parameter of this service : ") +
2404 (const char *) service->ServiceinParameter[ind1].Parametername);
2406 for (unsigned int ind1 = 0; ind1 <service->ServiceoutParameter.length();ind1++) {
2407 myActiveStudy->setMessage( QString("Type of the out Parameter of this service : ") +
2408 (const char *) service->ServiceoutParameter[ind1].Parametertype);
2409 myActiveStudy->setMessage( QString("Name of the out Parameter of this service : ") +
2410 (const char *) service->ServiceoutParameter[ind1].Parametername);
2417 typedef bool OneDim(int, QAD_Desktop*);
2418 typedef void (*PTR_FACTORY_FUNCTION)( CORBA::ORB_var &orb, QWidget *parent, const char *name ) ;
2422 void QAD_Desktop::onDispatch()
2424 const QObject* obj = sender();
2426 QList<QAD_ListMenuIdAction> MenuList = myActiveMenus->getMenuList();
2427 QAD_ListMenuIdAction* aMenu;
2429 for(aMenu=MenuList.first();aMenu!=NULL;aMenu=MenuList.next()) {
2430 if (aMenu->getAction()==obj) {
2431 id = aMenu->getId();
2440 void QAD_Desktop::onDispatchTools(int id)
2442 /* Open Shared Library */
2443 OSD_SharedLibrary ToolsLibrary = OSD_SharedLibrary();
2447 QFileInfo fileInfo ;
2451 bool libToolsGUI = true;
2452 if( QAD_XmlHandler::_bibmap[ id ].isEmpty() )
2455 if ( dir = getenv("SALOME_SITE_DIR")) {
2456 dir = QAD_Tools::addSlash(dir) ;
2458 dir = QAD_Tools::addSlash(dir) ;
2459 dir = dir + "salome" ;
2460 dir = QAD_Tools::addSlash(dir) ;
2462 dir = dir + "libToolsGUI.dll" ;
2464 dir = dir + "libToolsGUI.so" ;
2466 MESSAGE ( " GUI library = " << dir );
2467 fileInfo.setFile(dir) ;
2468 if (fileInfo.exists()) {
2469 ToolsLib = fileInfo.fileName() ;
2474 if ( (dir = getenv("SALOME_ROOT_DIR")) && !found ) {
2475 dir = QAD_Tools::addSlash(dir) ;
2477 dir = QAD_Tools::addSlash(dir) ;
2478 dir = dir + "salome" ;
2479 dir = QAD_Tools::addSlash(dir) ;
2481 dir = dir + "libToolsGUI.dll" ;
2483 dir = dir + "libToolsGUI.so" ;
2485 MESSAGE ( " GUI library = " << dir );
2486 fileInfo.setFile(dir) ;
2487 if (fileInfo.exists()) {
2488 ToolsLib = fileInfo.fileName() ;
2494 libToolsGUI = false;
2495 SCRUTE( QAD_XmlHandler::_bibmap[ id ] ) ;
2496 if ( dir = getenv("SALOME_SITE_DIR")) {
2497 dir = QAD_Tools::addSlash(dir) ;
2499 dir = QAD_Tools::addSlash(dir) ;
2500 dir = dir + "salome" ;
2501 dir = QAD_Tools::addSlash(dir) ;
2502 dir = dir + QAD_XmlHandler::_bibmap[ id ].latin1() ;
2503 MESSAGE ( " GUI library = " << dir );
2504 fileInfo.setFile(dir) ;
2505 if (fileInfo.exists()) {
2506 ToolsLib = fileInfo.fileName() ;
2511 if ( (dir = getenv("SALOME_ROOT_DIR")) && !found ) {
2512 dir = QAD_Tools::addSlash(dir) ;
2514 dir = QAD_Tools::addSlash(dir) ;
2515 dir = dir + "salome" ;
2516 dir = QAD_Tools::addSlash(dir) ;
2517 dir = dir + QAD_XmlHandler::_bibmap[ id ].latin1() ;
2518 MESSAGE ( " GUI library = " << dir );
2519 fileInfo.setFile(dir) ;
2520 if (fileInfo.exists()) {
2521 ToolsLib = fileInfo.fileName() ;
2527 ToolsLibrary.SetName(TCollection_AsciiString((char*)ToolsLib.latin1()).ToCString());
2528 bool ok = ToolsLibrary.DlOpen(OSD_RTLD_LAZY);
2530 if ( libToolsGUI ) {
2531 OSD_Function osdF = ToolsLibrary.DlSymb("OnGUIEvent");
2532 OneDim (*f1) = NULL;
2533 f1 = (bool (*) (int, QAD_Desktop*)) osdF;
2536 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
2537 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
2538 CORBA::ORB_var &orb = init(0 , 0 ) ;
2539 OSD_Function osdF = ToolsLibrary.DlSymb("OnGUIEvent");
2540 PTR_FACTORY_FUNCTION f1 = NULL;
2541 f1 = (PTR_FACTORY_FUNCTION) osdF;
2542 f1(orb,0,"Registry");
2545 QMessageBox::critical( this,
2547 tr( ToolsLibrary.DlError() ) );
2553 void QAD_Desktop::onDispatch(int id)
2555 if (!myActiveComp.isEmpty()) {
2556 OSD_Function osdF = mySharedLibrary.DlSymb("OnGUIEvent");
2557 OneDim (*f1) = NULL;
2558 if ( osdF != NULL ) {
2559 f1 = (bool (*) (int, QAD_Desktop*)) osdF;
2566 Returns the component's catalogue
2568 SALOME_ModuleCatalog::ModuleCatalog_var QAD_Desktop::getCatalogue()
2575 void QAD_Desktop::onComboActiveComponent( const QString & component ){
2576 onComboActiveComponent(component,true);
2578 void QAD_Desktop::onComboActiveComponent( const QString & component, bool isLoadData)
2580 if (myActiveStudy != 0) {
2581 if (myActiveComp.compare(component)!=0) {
2582 if (!myXmlHandler->myIdList.IsEmpty()) clearMenus();
2583 if ( myCombo->currentText() != component )
2584 myCombo->setCurrentText( component );
2585 if (component.compare(QString("Salome"))!= 0) {
2586 // QApplication::setOverrideCursor( Qt::waitCursor );
2587 myActiveComp = component;
2589 SALOME_Selection* oldSel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2591 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2592 if ( aButton->textLabel().compare(component)==0)
2593 aButton->setOn(true);
2595 aButton->setOn(false);
2598 myActiveStudy->Selection( component );
2599 if ( !loadComponent(mapComponentName[component]) ) {
2600 myCombo->setCurrentItem (0);
2601 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2602 aButton->setOn(false);
2607 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2608 SALOME_ListIteratorOfListIO It( oldSel->StoredIObjects() );
2609 for(;It.More();It.Next()) {
2610 int res = Sel->AddIObject( It.Value() );
2613 myActiveStudy->highlight( It.Value(), false );
2615 myActiveStudy->highlight( It.Value(), true );
2619 // Open new component's data in active study if any
2620 if(isLoadData) loadComponentData(mapComponentName[component]);
2623 myActiveStudy->updateObjBrowser(true);
2625 // QApplication::restoreOverrideCursor();
2627 } else { // component == "Salome"
2629 myActiveStudy->Selection( "Salome" );
2630 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2631 Sel->ClearIObjects();
2632 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2633 aButton->setOn(false);
2637 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2638 if ( aButton->textLabel().compare(component)==0)
2639 aButton->setOn(true);
2643 QMessageBox::critical( 0,
2645 tr( "WRN_LOAD_COMPONENT" ) );
2646 myCombo->setCurrentItem (0);
2647 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2648 aButton->setOn(false);
2655 void QAD_Desktop::activateComponent(const QString& theName, bool isLoadData){
2656 int nbItem = myCombo->count();
2659 for (int i = 0; i < nbItem; i++) {
2660 if (myCombo->text(i).compare(theName)==0) {
2665 myCombo->setCurrentItem (Index);
2666 onComboActiveComponent(theName,isLoadData);
2669 void QAD_Desktop::onButtonActiveComponent( )
2671 QToolButton* obj = (QToolButton*)sender();
2672 activateComponent(obj->textLabel());
2676 Clears All Resources of current component
2678 void QAD_Desktop::clearMenus()
2680 onActiveStudyChanged();
2683 myMenusList.clear();
2685 int length = myXmlHandler->myIdList.Length();
2686 for (int k=length; k>0; k--) {
2688 if ( menuBar()->findItem(myXmlHandler->myIdList.Value(k), &parent) )
2689 parent->removeItem( myXmlHandler->myIdList.Value(k) );
2694 if (myActiveMenus) {
2695 int nbtoolbars = myActiveMenus->getToolBarList().count();
2696 for (int k=0; k<nbtoolbars; k++) {
2697 myActiveMenus->getToolBarList().at(k)->hide();
2698 myActiveMenus->getToolBarList().at(k)->clear();
2700 myActiveMenus->clearToolBar();
2703 QList<QAD_ListPopupMenu> PopupList = myActiveMenus->getPopupMenuList();
2704 QAD_ListPopupMenu* aPopup;
2705 for(aPopup=PopupList.first();aPopup!=NULL;aPopup=PopupList.next()){
2706 aPopup->getPopup()->clear();
2709 myActiveMenus->clearPopupMenu();
2715 typedef bool TwoDim1(QKeyEvent* pe, QAD_Desktop*, QAD_StudyFrame*);
2717 Exports Key Events in active component ( GUI Librairy )
2719 void QAD_Desktop::onKeyPress( QKeyEvent* pe )
2721 // MESSAGE ( "QAD_Desktop::onKeyPress" )
2722 if (!myActiveComp.isEmpty()) {
2723 OSD_Function osdF = mySharedLibrary.DlSymb("OnKeyPress");
2724 if ( osdF != NULL ) {
2725 TwoDim1 (*f1) = (bool (*) (QKeyEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
2726 (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
2731 typedef bool TwoDim(QMouseEvent* pe, QAD_Desktop*, QAD_StudyFrame*);
2733 Exports Mouse Press Events in active component ( GUI Librairy )
2735 bool QAD_Desktop::onMousePress( QMouseEvent* pe )
2737 // MESSAGE ( "QAD_Desktop::onMousePress" )
2738 if (!myActiveComp.isEmpty()) {
2739 OSD_Function osdF = mySharedLibrary.DlSymb("OnMousePress");
2740 if ( osdF != NULL ) {
2741 TwoDim (*f1) = (bool (*) (QMouseEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
2742 return (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
2749 Exports Mouse Move Events in active component ( GUI Librairy )
2751 void QAD_Desktop::onMouseMove( QMouseEvent* pe )
2753 if (!myActiveComp.isEmpty()) {
2754 OSD_Function osdF = mySharedLibrary.DlSymb("OnMouseMove");
2755 if ( osdF != NULL ) {
2756 TwoDim (*f1) = (bool (*) (QMouseEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
2757 (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
2763 Returns name of active component
2765 const QString& QAD_Desktop::getActiveComponent() const
2767 return myActiveComp;
2771 typedef bool defineP( QString & theContext, QString & theParent, QString & theObject);
2773 void QAD_Desktop::definePopup(QString & theContext,
2774 QString & theParent,
2775 QString & theObject )
2777 if (!myActiveComp.isEmpty()) {
2778 OSD_Function osdF = mySharedLibrary.DlSymb("definePopup");
2779 if ( osdF != NULL ) {
2780 defineP (*f1) = (bool (*) (QString &, QString &, QString &)) osdF;
2781 (*f1)(theContext, theParent, theObject);
2789 void QAD_Desktop::createPopup(QPopupMenu* popupFather, QPopupMenu* popup,
2790 QString text, int popupID, bool separator)
2792 QMenuItem* item = popup->findItem(popupID);
2794 QPopupMenu* popupChild = item->popup();
2796 QPopupMenu* newPopup = new QPopupMenu;
2797 int count = popupChild->count();
2798 // add items at the top of <popupFather>
2799 for (int i = count - 1; i >= 0; i--) {
2800 int j = popupChild->idAt(i);
2801 QString text = popupChild->text(j);
2802 createPopup( newPopup, popupChild, text, j);
2804 popupFather->insertItem(popup->text(popupID),
2805 newPopup, popupID, 0);
2807 if ( !text.isNull() ) {
2808 popupFather->insertItem(popup->text(popupID),
2810 SLOT( onDispatch(int) ), 0, popupID, 0);// try adding item at the top
2811 } /*else if ( separator )
2812 popupFather->insertTearOffHandle(-1, 0);*/
2814 popupFather->insertSeparator(0);
2822 void QAD_Desktop::createPopup(QPopupMenu* popup, const QString & theContext,
2823 const QString & theParent, const QString & theObject )
2825 if ( !myActiveComp.isEmpty() &&
2826 getOperatorMenus()->createPopupMenu(theContext,theParent,theObject) != NULL ) {
2827 QPopupMenu* aPopup = getOperatorMenus()->createPopupMenu(theContext,theParent,theObject)->getPopup();
2828 int count = aPopup->count();
2830 //for (int i = 0; i < count; i++) {
2831 for (int i = count - 1; i >= 0; i--) {
2832 int id = aPopup->idAt(i);
2833 QString text = aPopup->text(id);
2834 //QString mes("Inserting popup menu item loaded from XML: ");
2836 //MESSAGE ( mes.latin1() )
2838 popup->insertItem(aPopup->text(id),
2840 SLOT( onDispatch(int) ), 0, id, 0);// try adding item at the top
2842 createPopup( popup, aPopup, text, id);
2845 //QString mes("Popup does not exist for given (Context = ");
2846 //mes += theContext;
2847 //mes += ", Parent = ";
2849 //mes += ", Object = ";
2851 //MESSAGE (mes.latin1())
2856 // Should be moved to SALOMEGUI_Application::onCreatePopup()...
2857 if ( myActiveComp.isEmpty() ) {
2858 popup->removeItem(QAD_Display_Popup_ID);
2859 popup->removeItem(QAD_DisplayOnly_Popup_ID);
2860 popup->removeItem(QAD_Erase_Popup_ID);
2861 int id = popup->idAt(popup->count()-1); // last item
2862 if (id < 0 && id != -1) popup->removeItem(id); // separator
2864 if ( popup && theParent.compare("ObjectBrowser")==0 ) {
2865 if ( popup->count()>0 ) {
2866 popup->insertItem (tr ("MEN_OPENWITH"), this, SLOT(onOpenWith()), 0, -1, 2);
2867 popup->insertSeparator (3);
2870 popup->insertItem (tr ("MEN_OPENWITH"), this, SLOT(onOpenWith()) );
2877 typedef bool activeStudyChanged(QAD_Desktop*);
2879 void QAD_Desktop::onActiveStudyChanged()
2881 if (!myActiveComp.isEmpty()) {
2882 OSD_Function osdF = mySharedLibrary.DlSymb("activeStudyChanged");
2883 if ( osdF != NULL ) {
2884 activeStudyChanged (*f1) = (bool (*) (QAD_Desktop*)) osdF;
2890 typedef bool customP(QAD_Desktop*, QPopupMenu*, const QString & theContext,
2891 const QString & theParent, const QString & theObject);
2893 Custom popup ( GUI Library )
2895 void QAD_Desktop::customPopup(QPopupMenu* popup, const QString & theContext,
2896 const QString & theParent, const QString & theObject)
2898 if (!myActiveComp.isEmpty()) {
2899 OSD_Function osdF = mySharedLibrary.DlSymb("customPopup");
2900 if ( osdF != NULL ) {
2901 customP (*f1) = (bool (*) (QAD_Desktop*, QPopupMenu*, const QString &,
2902 const QString &, const QString &)) osdF;
2903 (*f1)(this, popup, theContext, theParent, theObject);
2908 void QAD_Desktop::onObjectBrowser()
2910 bool checkDiff = false;
2912 bool state = QAD_CONFIG->getSetting("ObjectBrowser:AddColumn").compare("true") == 0;
2914 if ( myStdActions.at( PrefObjectBrowserEntryId )->isOn() != state )
2918 if ( myStdActions.at( PrefObjectBrowserEntryId )->isOn() ) {
2920 QAD_CONFIG->addSetting( "ObjectBrowser:AddColumn", "true");
2923 QAD_CONFIG->addSetting( "ObjectBrowser:AddColumn", "false");
2927 if ( myStdActions.at( PrefObjectBrowserValueId )->isOn() ) {
2929 QAD_CONFIG->addSetting( "ObjectBrowser:ValueColumn", "true");
2932 QAD_CONFIG->addSetting( "ObjectBrowser:ValueColumn", "false");
2936 if ( myStdActions.at( PrefObjectBrowserIAPPId )->isOn() ) {
2938 QAD_CONFIG->addSetting( "ObjectBrowser:IAPP", "true");
2941 QAD_CONFIG->addSetting( "ObjectBrowser:IAPP", "false");
2944 /* To sort created object in chrono order or reverse chrono order */
2945 bool showCHRONO_SORT ;
2946 if ( myStdActions.at( PrefObjectBrowserCHRONO_SORTId )->isOn() ) {
2947 showCHRONO_SORT = true;
2948 QAD_CONFIG->addSetting( "ObjectBrowser:CHRONO_SORT", "true");
2950 showCHRONO_SORT = false;
2951 QAD_CONFIG->addSetting( "ObjectBrowser:CHRONO_SORT", "false");
2954 if ( myActiveApp ) {
2955 QList<QAD_Study>& studies = myActiveApp->getStudies();
2956 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
2957 int nbSf = study->getStudyFramesCount();
2958 for ( int i = 0; i < nbSf; i++ ) {
2959 QAD_StudyFrame* sf = study->getStudyFrame(i);
2960 sf->getLeftFrame()->getObjectBrowser()->setShowInfoColumns( showEntry );
2961 sf->getLeftFrame()->getObjectBrowser()->setShowValueColumn( showValue );
2962 sf->getLeftFrame()->getObjectBrowser()->setEnableChronoSort( showCHRONO_SORT );
2963 // sf->getLeftFrame()->getObjectBrowser()->setShowIAPP( showIAPP ); // this is done by below updateObjBrowser() call
2965 study->updateObjBrowser(true);
2970 void QAD_Desktop::onViewerTrihedron()
2972 QString Size = QAD_CONFIG->getSetting("Viewer:TrihedronSize");
2975 SALOMEGUI_TrihedronSizeDlg *Dlg = new SALOMEGUI_TrihedronSizeDlg(this);
2976 if (!Size.isEmpty())
2977 Dlg->setTrihedronSize(Size.toInt());
2978 int r = Dlg->exec();
2979 dim = Dlg->getTrihedronSize();
2982 if (r == QDialog::Accepted) {
2983 QAD_CONFIG->addSetting("Viewer:TrihedronSize", dim);
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 study->getStudyFrame(i)->getRightFrame()->getViewFrame()->SetTrihedronSize(dim);
2997 void QAD_Desktop::onDirList()
2999 // getting dir list from settings
3000 QStringList dirList = QStringList::split(';', QAD_CONFIG->getSetting("FileDlg:QuickDirList"), false);
3001 QAD_DirListDlg* dlg = new QAD_DirListDlg(this);
3002 dlg->setPathList(dirList);
3003 if ( dlg->exec() == QDialog::Accepted) {
3004 dlg->getPathList(dirList);
3005 QAD_CONFIG->addSetting("FileDlg:QuickDirList", dirList.join(";"));
3010 void QAD_Desktop::onConsoleFontAction()
3012 // getting font from settings
3013 QString fntSet = QAD_CONFIG->getSetting("Viewer:ConsoleFont");
3014 QFont font = QAD_Tools::stringToFont( fntSet );
3016 font = QFontDialog::getFont( &bOk, font, this );
3018 fntSet = QAD_Tools::fontToString( font );
3019 QAD_CONFIG->addSetting("Viewer:ConsoleFont", fntSet );
3022 QList<QAD_Study>& studies = myActiveApp->getStudies();
3023 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3024 int nbSf = study->getStudyFramesCount();
3025 for ( int i = 0; i < nbSf; i++ ) {
3026 study->getStudyFrame(i)->getRightFrame()->getPyEditor()->setFont( font );
3027 study->getStudyFrame(i)->getRightFrame()->getMessage()->setFont( font );
3034 void QAD_Desktop::onSavePref()
3036 QAD_CONFIG->createConfigFile(true);
3039 //VRV: T2.5 - add default viewer
3040 void QAD_Desktop::onDefaultViewer(QAction * theAction)
3042 int type = VIEW_TYPE_MAX;
3045 if (myStdActions.at(DefaultViewerOCCId) == theAction)
3047 else if (myStdActions.at(DefaultViewerVTKId) == theAction)
3049 else if (myStdActions.at(DefaultGraphSupervisorId) == theAction)
3050 type = VIEW_GRAPHSUPERV;
3051 else if (myStdActions.at(DefaultPlot2dId) == theAction)
3053 if ( type != VIEW_TYPE_MAX )
3054 QAD_CONFIG->addSetting( "Viewer:DefaultViewer", QString::number( type ) );
3056 //VRV: T2.5 - add default viewer
3058 void QAD_Desktop::onViewerOCC()
3060 QString BackgroundColorRed = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorRed");
3061 QString BackgroundColorGreen = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorGreen");
3062 QString BackgroundColorBlue = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorBlue");
3065 if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3066 color = QColor(BackgroundColorRed.toInt(),
3067 BackgroundColorGreen.toInt(),
3068 BackgroundColorBlue.toInt());
3070 color = QColor(35, 136, 145);
3072 QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3075 if ( myActiveApp ) {
3076 QList<QAD_Study>& studies = myActiveApp->getStudies();
3077 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3078 int nbSf = study->getStudyFramesCount();
3079 for ( int i = 0; i < nbSf; i++ ) {
3080 QAD_StudyFrame* sf = study->getStudyFrame(i);
3081 if ( sf->getTypeView() == VIEW_OCC ) {
3082 sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3087 QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorRed", c.red() );
3088 QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorGreen", c.green() );
3089 QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorBlue", c.blue() );
3093 void QAD_Desktop::onGraphSupervisor()
3095 QString BackgroundColorRed = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorRed");
3096 QString BackgroundColorGreen = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorGreen");
3097 QString BackgroundColorBlue = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorBlue");
3100 if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3101 color = QColor(BackgroundColorRed.toInt(),
3102 BackgroundColorGreen.toInt(),
3103 BackgroundColorBlue.toInt());
3105 color = QColor(35, 136, 145);
3107 QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3110 if ( myActiveApp ) {
3111 QList<QAD_Study>& studies = myActiveApp->getStudies();
3112 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3113 int nbSf = study->getStudyFramesCount();
3114 for ( int i = 0; i < nbSf; i++ ) {
3115 QAD_StudyFrame* sf = study->getStudyFrame(i);
3116 if ( sf->getTypeView() == VIEW_GRAPHSUPERV ) {
3117 sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3123 QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorRed", c.red() );
3124 QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorGreen", c.green() );
3125 QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorBlue", c.blue() );
3129 void QAD_Desktop::onViewerVTK()
3131 QString BackgroundColorRed = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorRed");
3132 QString BackgroundColorGreen = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorGreen");
3133 QString BackgroundColorBlue = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorBlue");
3136 if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3137 color = QColor(BackgroundColorRed.toInt(),
3138 BackgroundColorGreen.toInt(),
3139 BackgroundColorBlue.toInt());
3141 color = QColor(0, 0, 0);
3143 QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3146 if ( myActiveApp ) {
3147 QList<QAD_Study>& studies = myActiveApp->getStudies();
3148 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3149 int nbSf = study->getStudyFramesCount();
3150 for ( int i = 0; i < nbSf; i++ ) {
3151 QAD_StudyFrame* sf = study->getStudyFrame(i);
3152 if ( sf->getTypeView() == VIEW_VTK ) {
3153 sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3159 QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorRed", c.red() );
3160 QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorGreen", c.green() );
3161 QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorBlue", c.blue() );
3165 void QAD_Desktop::onPlot2d()
3168 if ( QAD_CONFIG->hasSetting( "Plot2d:Background" ) ) {
3169 QString bgString = QAD_CONFIG->getSetting( "Plot2d:Background" );
3170 QStringList bgData = QStringList::split( ":", bgString, true );
3171 int bgRed = 0, bgGreen = 0, bgBlue = 0;
3172 if ( bgData.count() > 0 ) bgRed = bgData[ 0 ].toInt();
3173 if ( bgData.count() > 1 ) bgGreen = bgData[ 1 ].toInt();
3174 if ( bgData.count() > 2 ) bgBlue = bgData[ 2 ].toInt();
3175 color = QColor( bgRed, bgGreen, bgBlue );
3178 color = QColor(0, 0, 0);
3181 color = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3183 if ( color.isValid() ) {
3184 if ( myActiveApp ) {
3185 QList<QAD_Study>& studies = myActiveApp->getStudies();
3186 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3187 int nbSf = study->getStudyFramesCount();
3188 for ( int i = 0; i < nbSf; i++ ) {
3189 QAD_StudyFrame* sf = study->getStudyFrame(i);
3190 if ( sf->getTypeView() == VIEW_PLOT2D ) {
3191 sf->getRightFrame()->getViewFrame()->setBackgroundColor( color );
3197 bgData.append( QString::number( color.red() ) );
3198 bgData.append( QString::number( color.green() ) );
3199 bgData.append( QString::number( color.blue() ) );
3200 QAD_CONFIG->addSetting( "Plot2d:Background", bgData.join( ":" ) );
3205 void QAD_Desktop::helpAbout()
3207 SALOMEGUI_AboutDlg* About = new SALOMEGUI_AboutDlg( QAD_Application::getDesktop(), tr("MEN_ABOUT"));
3213 void QAD_Desktop::helpSearch()
3218 void QAD_Desktop::helpContents()
3220 getHelpWindow()->contents();
3221 getHelpWindow()->show();
3222 getHelpWindow()->raise();
3223 getHelpWindow()->setActiveWindow();
3227 void QAD_Desktop::helpContext(const QString& source, const QString& context)
3229 getHelpWindow()->context(source, context);
3230 getHelpWindow()->show();
3231 getHelpWindow()->raise();
3232 getHelpWindow()->setActiveWindow();
3235 /* Preferences/MultiFile Save */
3236 void QAD_Desktop::onMultiFileSave()
3238 if ( myStdActions.at( PrefMultiFileSave )->isOn() )
3239 QAD_CONFIG->addSetting( "Desktop:MultiFileSave", "true");
3241 QAD_CONFIG->addSetting( "Desktop:MultiFileSave", "false");
3244 /*********************************************************************
3245 ** Class: AppSelectionDlg
3246 ** Descr: Dialog for the selection of the application when several
3247 ** applications exist in the desktop and new study creation
3248 ** is activated by user.
3250 **********************************************************************/
3252 \class Desktop_AppSelectionDlg QAD_Desktop.h
3253 \brief Dialog for the selection of the application when several
3254 applications exist in the desktop and new study creation
3255 is activated by user.
3260 Desktop_AppSelectionDlg::Desktop_AppSelectionDlg( QAD_Desktop* desktop,
3261 QList<QAD_Application>& apps ) :
3262 QDialog( desktop, 0, true ),
3266 QAD_ASSERT_DEBUG_ONLY ( desktop );
3267 setCaption( tr("INF_DESK_DOC_CREATE") );
3268 if ( desktop->icon() )
3269 setIcon( *desktop->icon() );
3271 QBoxLayout* mainLayout = new QVBoxLayout( this, 5 );
3273 /* Create selection buttons */
3274 QVButtonGroup* buttonGrp = new QVButtonGroup ( this );
3275 buttonGrp->setExclusive ( true );
3276 QBoxLayout* vLayout = new QVBoxLayout( mainLayout, 5 );
3277 vLayout->addWidget ( buttonGrp );
3279 /* Create selection button for available app */
3281 for ( QAD_Application* app = myApps.first(); app; app = myApps.next(), id++ )
3283 /* add radio button for application */
3284 buttonGrp->insert( new QRadioButton( app->getStudyDescription() +
3285 " (*." + app->getStudyExtension() + ")", buttonGrp ), id );
3288 /* make the first application selected */
3289 buttonGrp->setButton( 0 );
3291 /* listen to the selection */
3292 QAD_ASSERT ( connect ( buttonGrp, SIGNAL(clicked(int)), this, SLOT(onAppSelected(int)) ));
3294 /* Create OK/Cancel buttons
3296 QBoxLayout* hLayout = new QHBoxLayout( mainLayout, 5 );
3297 QPushButton* buttonOK = new QPushButton( tr("BUT_OK"), this );
3298 QPushButton* buttonCancel = new QPushButton( tr("BUT_CANCEL"), this );
3299 QPushButton* buttonHelp = new QPushButton( tr("BUT_HELP"), this );
3300 buttonOK->setDefault( true );
3302 hLayout->addStretch();
3303 hLayout->addWidget( buttonOK );
3304 hLayout->addWidget( buttonCancel );
3305 hLayout->addWidget( buttonHelp );
3307 /* connect buttons */
3308 QAD_ASSERT ( connect( buttonOK, SIGNAL(clicked()), this, SLOT(accept())) );
3309 QAD_ASSERT ( connect( buttonCancel, SIGNAL(clicked()), this, SLOT(reject())) );
3310 QAD_ASSERT ( connect( buttonHelp, SIGNAL(clicked()), this, SLOT(onHelp())) );
3312 /* disable resizing */
3313 setFixedSize( 0, 0 );
3314 setSizePolicy( QSizePolicy ( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
3317 Desktop_AppSelectionDlg::~Desktop_AppSelectionDlg()
3321 QAD_Application* Desktop_AppSelectionDlg::selectedApp() const
3323 return myApps.at( myAppId );
3326 void Desktop_AppSelectionDlg::resizeEvent( QResizeEvent* e )
3328 QAD_Tools::centerWidget( this, parentWidget() );
3334 void Desktop_AppSelectionDlg::onAppSelected( int id )
3339 void Desktop_AppSelectionDlg::onHelp()