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>
89 QAD_ResourceMgr* QAD_Desktop::resourceMgr = 0;
90 QPalette* QAD_Desktop::palette = 0;
94 Creates the resource manager [ static ]
96 QAD_ResourceMgr* QAD_Desktop::createResourceManager()
99 resourceMgr = new QAD_ResourceMgr;
104 Returns the resource manager [ static ]
106 QAD_ResourceMgr* QAD_Desktop::getResourceManager()
113 Loads the palette from settings [ static ]
115 QPalette* QAD_Desktop::createPalette()
118 palette = new QPalette();
124 Returns the palette [ static ]
126 QPalette* QAD_Desktop::getPalette()
132 Gets window ratio width/heght [ static ]
134 static double myWindowRatio = 1;
135 static double getWindowRatio()
137 return myWindowRatio;
141 Sets window ratio width/heght [ static ]
143 static void setWindowRatio(double aRatio)
145 myWindowRatio = aRatio;
151 QAD_Desktop::QAD_Desktop(SALOME_NamingService* name_service) :
152 QMainWindow(0, 0, WType_TopLevel | WDestructiveClose),
159 myDefaultTitle( tr("DESK_DEFAULTTITLE") ),
162 /* Force reading of user config file */
163 QAD_CONFIG->readConfigFile();
165 /* menubar and status bar */
166 myStatusBar = statusBar();
167 myMainMenu = menuBar();
169 myNameService = name_service;
171 /* default background icon */
172 QPixmap backgroundicon ( QAD_Desktop::getResourceManager()->loadPixmap( "CLIENT",
173 tr("ICON_DESK_BACKGROUNDICON") ));
174 myToolBarAction.setAutoDelete( true );
176 /* default icon and title */
177 QPixmap icon ( QAD_Desktop::getResourceManager()->loadPixmap( "CLIENT",
178 tr("ICON_DESK_DEFAULTICON") ));
179 if ( !icon.isNull() ) {
180 myDefaultIcon = icon;
181 setIcon( myDefaultIcon );
183 setCaption( myDefaultTitle );
185 /* set size as 1/2 of the screen and center it */
186 QWidget* d = QApplication::desktop();
187 resize( 2*d->width()/3, 2*d->height()/3 );
188 QAD_Tools::centerWidget( this, d );
190 /* workspace will manage child frames */
191 QHBox* border = new QHBox ( this );
192 border->setFrameStyle ( QFrame::Panel | QFrame::Sunken );
193 setCentralWidget( border );
194 myWorkspace = new QWorkspaceP( border );
196 QPalette pal = QAD_Application::getPalette();
198 QColorGroup cgA = pal.active();
199 QColorGroup cgI = pal.inactive();
200 QColorGroup cgD = pal.disabled();
201 cgA.setColor( QColorGroup::Background, QColor(192, 192, 192));
202 cgI.setColor( QColorGroup::Background, QColor(192, 192, 192));
203 cgD.setColor( QColorGroup::Background, QColor(192, 192, 192));
204 pal.setActive ( cgA );
205 pal.setInactive( cgI );
206 pal.setDisabled( cgD );
207 myWorkspace->setPalette( pal );
208 if ( !backgroundicon.isNull() ) {
209 MESSAGE("!!!DESKTOP background icon found!!!");
210 myWorkspace->setPaletteBackgroundPixmap(backgroundicon);
213 /* define standard file commands */
216 /* define operator menus for xml */
217 myOperatorMenus = new QAD_OperatorMenus(this);
218 myXmlHandler = new QAD_XmlHandler();
221 CORBA::Object_var objVarN = myNameService->Resolve("/Kernel/ModulCatalog");
222 myCatalogue = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
224 SALOME_ModuleCatalog::ListOfIAPP_Affich_var list_composants =
225 myCatalogue->GetComponentIconeList();
228 QToolBar* tbComponent = new QToolBar( tr("MEN_DESK_COMPONENTTOOLBAR"), this );
229 tbComponent->setCloseMode( QDockWindow::Undocked );
230 addToolBar(tbComponent, tr("MEN_DESK_COMPONENTTOOLBAR"), Bottom, TRUE );
231 setDockEnabled( tbComponent, DockLeft, false );
232 setDockEnabled( tbComponent, DockRight, false );
234 myCombo = new QComboBox( FALSE, tbComponent, "comboBox" );
235 myCombo->setFocusPolicy( NoFocus );
237 tbComponent->addSeparator();
239 // PG : add ResourceManager to get function findFile !!
240 QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
242 for (unsigned int ind = 0; ind < list_composants->length();ind++) {
245 /* find component icon */
246 QString iconfile = strdup(list_composants[ind].moduleicone) ;
247 QString modulename = strdup(list_composants[ind].modulename) ;
248 resDir = resMgr->findFile(iconfile,modulename) ;
251 //resDir = QAD_Tools::addSlash(resDir) ;
252 //QPixmap Icone(resDir+iconfile) ;
253 QPixmap Icone( QAD_Tools::addSlash( resDir ) + iconfile );
254 QToolButton * toolb =
255 new QToolButton( QIconSet( Icone ), modulename, QString::null, this,
256 SLOT( onButtonActiveComponent () ),tbComponent );
257 toolb->setToggleButton( true );
258 myComponentButton.append(toolb);
262 QString errMsg = tr("INF_ICON_RESOURCES").arg(iconfile).arg(modulename) +
264 //QMessageBox::warning( this, tr("WRN_WARNING"), errMsg, tr ("BUT_OK") );
267 if ( !QString(list_composants[ind].modulename).isEmpty() )
268 myCombo->insertItem( strdup(list_composants[ind].modulename) );
272 myCombo->adjustSize();
273 connect( myCombo, SIGNAL(activated(const QString&)),
274 this, SLOT( onComboActiveComponent(const QString&) ) );
276 /* new LifeCycleCORBA client, for Engines */
277 myEnginesLifeCycle = new SALOME_LifeCycleCORBA(name_service);
279 /* VSR 13/01/03 : installing global event filter for the application */
280 qApp->installEventFilter( this );
286 QAD_Desktop::~QAD_Desktop ()
288 qApp->removeEventFilter( this );
292 myObjBrowserPopup.clear();
293 //VRV: T2.5 - add default viewer
294 myDefaultViewer.clear();
295 //VRV: T2.5 - add default viewer
296 myViewerPopup.clear();
298 myNewViewPopup.clear();
300 myToolsPopup.clear();
302 myStdActions.clear();
304 myToolBarsPopup.clear();
305 myToolBarAction.clear();
309 myHelpWindow->close();
311 QAD_Application::desktop = 0;
314 const int IdCut = 1001;
315 const int IdCopy = 1002;
316 const int IdPaste = 1003;
317 const int IdSelectAll = 1004;
319 #include <qkeysequence.h>
320 #define ACCEL_KEY(k) "\t" + QString(QKeySequence( Qt::CTRL | Qt::Key_ ## k ))
322 #define ACCEL_KEY(k) "\t" + QString("Ctrl+" #k)
324 #include <qclipboard.h>
326 Global event filter for qapplication (VSR 13/01/03)
328 bool QAD_Desktop::eventFilter( QObject* o, QEvent* e )
330 if ( e->type() == QEvent::ContextMenu ) {
331 QContextMenuEvent* ce = (QContextMenuEvent*)e;
332 if ( o->inherits("QRenameEdit") ) {
335 else if ( o->inherits("QLineEdit") ) {
336 QLineEdit* le = (QLineEdit*)o;
337 if ( le->parentWidget() ) {
338 if ( ( le->parentWidget()->inherits("QSpinBox") ||
339 le->parentWidget()->inherits("QSpinWidget") ||
340 le->parentWidget()->inherits("QAD_SpinBoxDbl") ) &&
342 QPopupMenu* popup = new QPopupMenu( 0, "qt_edit_menu" );
343 popup->insertItem( tr( "EDIT_CUT_CMD" ) + ACCEL_KEY( X ), IdCut );
344 popup->insertItem( tr( "EDIT_COPY_CMD" ) + ACCEL_KEY( C ), IdCopy );
345 popup->insertItem( tr( "EDIT_PASTE_CMD" ) + ACCEL_KEY( V ), IdPaste );
346 popup->insertSeparator();
347 #if defined(Q_WS_X11)
348 popup->insertItem( tr( "EDIT_SELECTALL_CMD" ), IdSelectAll );
350 popup->insertItem( tr( "EDIT_SELECTALL_CMD" ) + ACCEL_KEY( A ), IdSelectAll );
352 bool enableCut = !le->isReadOnly() && le->hasSelectedText();
353 popup->setItemEnabled( IdCut, enableCut );
354 popup->setItemEnabled( IdCopy, le->hasSelectedText() );
355 bool enablePaste = !le->isReadOnly() && !QApplication::clipboard()->text().isEmpty();
356 popup->setItemEnabled( IdPaste, enablePaste );
357 bool allSelected = (le->selectedText() == le->text() );
358 popup->setItemEnabled( IdSelectAll, (bool)(le->text().length()) && !allSelected );
360 QPoint pos = ce->reason() == QContextMenuEvent::Mouse ? ce->globalPos() :
361 le->mapToGlobal( QPoint(ce->pos().x(), 0) ) + QPoint( le->width() / 2, le->height() / 2 );
363 int r = popup->exec( pos );
385 return QMainWindow::eventFilter( o, e );
389 Creates and initializes the standard file operations
390 such as 'New/Open/Save/SaveAs/Close' and 'Help'.
392 void QAD_Desktop::createActions()
395 /* Used for string compare */
396 const QString& aTrueQString = "true" ;
398 /* create 'standard' toolbar */
399 if ( !myStdToolBar ) {
400 myStdToolBar = new QToolBar ( tr("MEN_DESK_VIEW_STDTOOLBAR"), this );
401 myStdToolBar->setCloseMode( QDockWindow::Undocked );
404 if ( !myMainMenu->count() ) {
405 /* Create main menu bar */
406 myMainMenu->insertItem ( tr("MEN_DESK_FILE"), &myFilePopup, 1 ); /* add popup FILE */
407 myMainMenu->insertItem ( tr("MEN_DESK_VIEW"), &myViewPopup, 2 ); /* add popup VIEW */
408 myMainMenu->insertItem ( tr("MEN_DESK_TOOLS"), &myToolsPopup, 5 ); /* add popup TOOLS */
409 myMainMenu->insertItem ( tr("MEN_DESK_PREF"), &myPrefPopup, 4 ); /* add popup PREF */
410 myMainMenu->insertItem ( tr("MEN_DESK_WINDOW"), &myWindowPopup, 6 ); /* add popup WINDOW */
411 myMainMenu->insertItem ( tr("MEN_DESK_HELP"), &myHelpPopup, 7 ); /* add popup HELP */
413 /* Applications will insert their items after 'File' 'Edit' and 'View'
414 ( 'Edit' will be inserted later )
419 /* insert logo picture to menu bar */
420 QHBox* aLogoFrm = new QHBox(this);
421 aLogoFrm->setFrameStyle( QFrame::Plain | QFrame::NoFrame );
422 QPixmap aLogoPixmap ( QAD_Desktop::getResourceManager()->loadPixmap( "CLIENT",
423 tr("ICON_DESK_LOGO") ));
424 QLabel* aLogoLab = new QLabel(aLogoFrm);
425 aLogoLab->setPixmap(aLogoPixmap);
426 aLogoLab->setAlignment(AlignCenter);
427 aLogoLab->setScaledContents(false);
428 myMainMenu->insertItem(aLogoFrm);
430 if ( myStdActions.isEmpty() ) {
431 /* Define standard actions. They should be inserted
432 into the list in order of their IDs.
437 QAD_ResourceMgr* rmgr = QAD_Desktop::getResourceManager();
438 QAction* fileNewAction = new QAction ( tr("TOT_DESK_FILE_NEW"),
439 rmgr->loadPixmap( "QAD", tr("ICON_FILE_NEW") ) ,
440 tr("MEN_DESK_FILE_NEW"), CTRL+Key_N, this );
441 fileNewAction->setStatusTip ( tr("PRP_DESK_FILE_NEW") );
442 fileNewAction->setEnabled ( true );
443 QAD_ASSERT ( connect( fileNewAction, SIGNAL( activated() ), this, SLOT( onNewStudy() )));
444 fileNewAction->addTo( myStdToolBar );
445 fileNewAction->addTo( &myFilePopup );
446 myStdActions.insert ( FileNewId, fileNewAction );
449 QAction* fileOpenAction = new QAction( tr("TOT_DESK_FILE_OPEN"), rmgr->loadPixmap( "QAD", tr("ICON_FILE_OPEN") ),
450 tr("MEN_DESK_FILE_OPEN"), CTRL+Key_O, this );
451 fileOpenAction->setStatusTip ( tr("PRP_DESK_FILE_OPEN") );
452 fileOpenAction->setEnabled ( true );
453 QAD_ASSERT ( connect( fileOpenAction, SIGNAL( activated() ), this, SLOT( onOpenStudy() )));
454 fileOpenAction->addTo( myStdToolBar );
455 fileOpenAction->addTo( &myFilePopup );
456 myStdActions.insert ( FileOpenId, fileOpenAction );
459 QAction* fileLoadAction = new QAction( tr("TOT_DESK_FILE_LOAD"), rmgr->loadPixmap( "QAD", tr("ICON_FILE_LOAD") ),
460 tr("MEN_DESK_FILE_LOAD"), CTRL+Key_L, this );
461 fileLoadAction->setStatusTip ( tr("PRP_DESK_FILE_LOAD") );
462 fileLoadAction->setEnabled ( true );
463 QAD_ASSERT ( connect( fileLoadAction, SIGNAL( activated() ), this, SLOT( onLoadStudy() )));
464 fileLoadAction->addTo( &myFilePopup );
465 myStdActions.insert ( FileLoadId, fileLoadAction );
468 QAction* fileCloseAction = new QAction( "", rmgr->loadPixmap( "QAD", tr("ICON_FILE_CLOSE") ),
469 tr("MEN_DESK_FILE_CLOSE"), CTRL+Key_W, this );
470 fileCloseAction->setStatusTip ( tr("PRP_DESK_FILE_CLOSE") );
471 QAD_ASSERT ( connect( fileCloseAction, SIGNAL( activated() ), this, SLOT( onCloseStudy() )));
472 fileCloseAction->addTo( &myFilePopup );
473 myStdActions.insert ( FileCloseId, fileCloseAction );
476 myFilePopup.insertSeparator();
479 QAction* fileSaveAction = new QAction( tr("TOT_DESK_FILE_SAVE"), rmgr->loadPixmap( "QAD", tr("ICON_FILE_SAVE") ),
480 tr("MEN_DESK_FILE_SAVE"), CTRL+Key_S, this );
481 fileSaveAction->setStatusTip ( tr("PRP_DESK_FILE_SAVE") );
482 QAD_ASSERT ( connect( fileSaveAction, SIGNAL( activated() ), this, SLOT( onSaveStudy() )));
483 fileSaveAction->addTo( myStdToolBar );
484 fileSaveAction->addTo( &myFilePopup );
485 myStdActions.insert ( FileSaveId, fileSaveAction );
488 QAction* fileSaveAsAction = new QAction( "", tr("MEN_DESK_FILE_SAVEAS"), 0, this );
489 fileSaveAsAction->setStatusTip ( tr("PRP_DESK_FILE_SAVEAS") );
490 QAD_ASSERT ( connect( fileSaveAsAction, SIGNAL( activated() ),
491 this, SLOT( onSaveAsStudy() )));
492 fileSaveAsAction->addTo( &myFilePopup );
493 myStdActions.insert ( FileSaveAsId, fileSaveAsAction );
497 myFilePopup.insertSeparator();
500 QAction* filePropsAction = new QAction( "", QPixmap(), tr("MEN_DESK_FILE_PROPERTIES"), 0, this );
501 filePropsAction->setStatusTip ( tr("PRP_DESK_FILE_PROPERTIES") );
502 filePropsAction->setEnabled(false);
503 QAD_ASSERT ( connect( filePropsAction, SIGNAL( activated() ), this, SLOT( onStudyProperties() )));
504 filePropsAction->addTo( &myFilePopup );
505 myStdActions.insert ( FilePropsId, filePropsAction );
508 int id = myFilePopup.insertSeparator();
509 /* keep the position from which an application will insert its items
510 to menu 'File' at the time of customization of the desktop */
512 myFilePos = myFilePopup.indexOf( id ) + 1;
514 /* exit application */
515 QAction* exitAction = new QAction( "", tr("MEN_DESK_FILE_EXIT"),
517 exitAction->setStatusTip ( tr("PRP_DESK_FILE_EXIT") );
518 QAD_ASSERT ( connect( exitAction, SIGNAL( activated() ),
519 this, SLOT( onExit() )));
520 exitAction->addTo( &myFilePopup );
521 myStdActions.insert ( FileExitId, exitAction );
523 /* 'Edit' actions : provided by application only */
527 /* toolbars popup menu */
528 myViewPopup.insertItem( tr("MEN_DESK_VIEW_TOOLBARS"), &myToolBarsPopup );
529 QAD_ASSERT( connect ( &myViewPopup, SIGNAL(aboutToShow()),
530 this, SLOT(onToolBarPopupAboutToShow()) ));
533 QAction* viewStatusBarAction = new QAction( "",
534 tr("MEN_DESK_VIEW_STATUSBAR"),
536 viewStatusBarAction->setStatusTip ( tr("PRP_DESK_VIEW_STATUSBAR") );
537 viewStatusBarAction->setOn( true );
538 QAD_ASSERT(connect( viewStatusBarAction, SIGNAL(activated()), this, SLOT(onViewStatusBar() )));
539 viewStatusBarAction->addTo( &myViewPopup );
540 myStdActions.insert( ViewStatusBarId, viewStatusBarAction );
542 // myViewPopup.insertItem( tr("MEN_DESK_SELECTION_MODE"), &mySelectionModePopup );
544 QAction* SelectionPointAction = new QAction( "", tr("MEN_DESK_SELECTION_POINT"), 0, this, 0, true );
545 QAD_ASSERT(connect( SelectionPointAction, SIGNAL(activated()), this, SLOT(onSelectionMode() )));
546 SelectionPointAction->addTo( &mySelectionModePopup );
547 myStdActions.insert( SelectionPointId, SelectionPointAction );
549 QAction* SelectionEdgeAction = new QAction( "", tr("MEN_DESK_SELECTION_EDGE"), 0, this, 0, true );
550 QAD_ASSERT(connect( SelectionEdgeAction, SIGNAL(activated()), this, SLOT(onSelectionMode() )));
551 SelectionEdgeAction->addTo( &mySelectionModePopup );
552 myStdActions.insert( SelectionEdgeId, SelectionEdgeAction );
554 QAction* SelectionCellAction = new QAction( "", tr("MEN_DESK_SELECTION_CELL"), 0, this, 0, true );
555 QAD_ASSERT(connect( SelectionCellAction, SIGNAL(activated()), this, SLOT(onSelectionMode() )));
556 SelectionCellAction->addTo( &mySelectionModePopup );
557 myStdActions.insert( SelectionCellId, SelectionCellAction );
559 QAction* SelectionActorAction = new QAction( "", tr("MEN_DESK_SELECTION_ACTOR"), 0, this, 0, true );
560 QAD_ASSERT(connect( SelectionActorAction, SIGNAL(activated()), this, SLOT(onSelectionMode() )));
561 SelectionActorAction->addTo( &mySelectionModePopup );
562 myStdActions.insert( SelectionActorId, SelectionActorAction );
563 SelectionActorAction->setOn(true);
565 myViewPos = myViewPopup.count();
568 QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
571 if(!resMgr->loadResources( "ToolsGUI", msg ))
573 //NRI QCString errMsg;
574 // errMsg.sprintf( "Do not load all resources for module ToolsGUI.\n" );
575 QMessageBox::warning( this, tr("WRN_WARNING"), msg, tr ("BUT_OK") );
579 myOperatorMenus = new QAD_OperatorMenus(this);
580 myXmlHandler = new QAD_XmlHandler();
581 ASSERT(myXmlHandler) ;
582 myXmlHandler->setMainWindow(this);
583 if ( myXmlHandler->setComponent( resMgr->resources( "ToolsGUI" ) ) ) {
584 QString language = resMgr->language( "ToolsGUI" );
585 QString ToolsXml = QString( "Tools_" ) + language + QString( ".xml" );
587 //ToolsXml = resMgr->resources("ToolsGUI") ;
588 //ToolsXml = QAD_Tools::addSlash(ToolsXml) ;
589 //ToolsXml = ToolsXml + "Tools_" + language + ".xml" ;
590 ToolsXml = QAD_Tools::addSlash( resMgr->findFile( ToolsXml, "ToolsGUI" ) ) + ToolsXml;
592 QFile file( QAD_Tools::unix2win( ToolsXml ) );
593 if ( file.exists() && file.open( IO_ReadOnly ) ) {
595 QXmlInputSource source( file );
596 QXmlSimpleReader reader;
597 reader.setContentHandler( myXmlHandler );
598 reader.setErrorHandler( myXmlHandler );
599 bool ok = reader.parse( source );
602 QMessageBox::critical( 0,
603 tr( "INF_PARSE_ERROR" ),
604 tr( myXmlHandler->errorProtocol() ) );
606 myMenusList=myXmlHandler->myMenusList;
607 myActiveMenus=myMenusList.at(0);
608 myOperatorMenus->showMenuBar(0);
609 myActiveMenus->showAllToolBars();
615 if ( myToolsPopup.count() == 0 ) {
616 myMainMenu->removeItem(5);
620 /* Viewer BackgroundColor */
621 myPrefPopup.insertItem( tr("MEN_DESK_PREF_VIEWER"), &myViewerPopup );
623 QAction* viewerOCCAction = new QAction( "", tr("MEN_DESK_PREF_VIEWER_OCC"), 0, this );
624 QAD_ASSERT(connect( viewerOCCAction, SIGNAL(activated()), this, SLOT(onViewerOCC() )));
625 viewerOCCAction->addTo( &myViewerPopup );
626 myStdActions.insert( PrefViewerOCCId, viewerOCCAction );
628 QAction* viewerVTKAction = new QAction( "", tr("MEN_DESK_PREF_VIEWER_VTK"), 0, this );
629 QAD_ASSERT(connect( viewerVTKAction, SIGNAL(activated()), this, SLOT(onViewerVTK() )));
630 viewerVTKAction->addTo( &myViewerPopup );
631 myStdActions.insert( PrefViewerVTKId, viewerVTKAction );
633 QAction* graphSupervisorAction = new QAction( "", tr("MEN_DESK_PREF_GRAPH_SUPERVISOR"), 0, this );
634 QAD_ASSERT(connect( graphSupervisorAction, SIGNAL(activated()), this, SLOT(onGraphSupervisor() )));
635 graphSupervisorAction->addTo( &myViewerPopup );
636 myStdActions.insert( PrefGraphSupervisorId, graphSupervisorAction );
638 QAction* viewerPlot2dAction = new QAction( "", tr("MEN_DESK_PREF_VIEWER_PLOT2D"), 0, this );
639 QAD_ASSERT(connect( viewerPlot2dAction, SIGNAL(activated()), this, SLOT(onPlot2d() )));
640 viewerPlot2dAction->addTo( &myViewerPopup );
641 myStdActions.insert( PrefViewerPlot2dId, viewerPlot2dAction );
643 //VRV: T2.5 - add default viewer
644 QString viewerValue = QAD_CONFIG->getSetting( "Viewer:DefaultViewer" );
646 int aViewerValue = viewerValue.toInt( &ok, 10 );
647 if (!ok || aViewerValue < VIEW_OCC || aViewerValue >= VIEW_TYPE_MAX)
648 aViewerValue = VIEW_VTK;
650 myPrefPopup.insertItem( tr("MEN_DESK_PREF_DEFAULT_VIEWER"), &myDefaultViewer );
651 QActionGroup* myQAG = new QActionGroup ( this);
652 QAction* viewerOCCAction1 = new QAction( "", tr("MEN_DESK_PREF_VIEWER_OCC"), 0, this );
653 viewerOCCAction1->setToggleAction ( true);
654 viewerOCCAction1->setOn ( aViewerValue == VIEW_OCC );
655 myQAG->insert( viewerOCCAction1 );
656 myStdActions.insert( DefaultViewerOCCId, viewerOCCAction1 );
658 QAction* viewerVTKAction1 = new QAction( "", tr("MEN_DESK_PREF_VIEWER_VTK"), 0, this );
659 viewerVTKAction1->setToggleAction ( true);
660 viewerVTKAction1->setOn ( aViewerValue == VIEW_VTK );
661 myQAG->insert( viewerVTKAction1 );
662 myStdActions.insert( DefaultViewerVTKId, viewerVTKAction1 );
664 /* Remove Supervisor viewer from setting the background */
665 // QAction* graphSupervisorAction1 = new QAction( "", tr("MEN_DESK_PREF_GRAPH_SUPERVISOR"), 0, this );
666 // graphSupervisorAction1->setToggleAction ( true);
667 // graphSupervisorAction1->setOn ( aViewerValue == VIEW_GRAPHSUPERV );
668 // myQAG->insert( graphSupervisorAction1 );
669 // myStdActions.insert( DefaultGraphSupervisorId, graphSupervisorAction1 );
671 QAction* viewerPlot2dAction1 = new QAction( "", tr("MEN_DESK_PREF_VIEWER_PLOT2D"), 0, this );
672 viewerPlot2dAction1->setToggleAction ( true);
673 viewerPlot2dAction1->setOn ( aViewerValue == VIEW_PLOT2D );
674 myQAG->insert( viewerPlot2dAction1 );
675 myStdActions.insert( DefaultPlot2dId, viewerPlot2dAction1 );
677 myQAG->addTo( &myDefaultViewer );
678 QAD_ASSERT(connect( myQAG, SIGNAL(selected(QAction * )), this, SLOT(onDefaultViewer(QAction *) )));
679 //VRV: T2.5 - add default viewer
681 QAction* viewerTrihedronAction = new QAction( "", tr("MEN_DESK_PREF_VIEWER_TRIHEDRON"), 0, this );
682 QAD_ASSERT(connect( viewerTrihedronAction, SIGNAL(activated()), this, SLOT(onViewerTrihedron() )));
683 viewerTrihedronAction->addTo( &myPrefPopup );
684 myStdActions.insert( PrefViewerTrihedronId, viewerTrihedronAction );
686 QAction* consoleFontAction = new QAction( "", tr("MEN_DESK_PREF_CONSOLE_FONT"), 0, this );
687 QAD_ASSERT(connect( consoleFontAction, SIGNAL(activated()), this, SLOT(onConsoleFontAction() )));
688 consoleFontAction->addTo( &myPrefPopup );
689 myStdActions.insert( PrefConsoleFontId, consoleFontAction );
692 QAction* multiFileSaveAction = new QAction( "", tr("MEN_DESK_PREF_MULTI_FILE_SAVE"), 0, this, 0, true );
693 QAD_ASSERT(connect( multiFileSaveAction, SIGNAL(activated()), this, SLOT(onMultiFileSave() )));
694 multiFileSaveAction->setToggleAction( true );
695 QString MultiSave = QAD_CONFIG->getSetting("Desktop:MultiFileSave");
696 multiFileSaveAction->setOn( MultiSave.compare( aTrueQString ) == 0 );
697 multiFileSaveAction->addTo( &myPrefPopup );
698 myStdActions.insert( PrefMultiFileSave, multiFileSaveAction );
700 myPrefPopup.insertSeparator();
703 myPrefPopup.insertItem( tr("MEN_DESK_PREF_OBJECTBROWSER"), &myObjBrowserPopup );
705 QAction* objectBrowserEntryAction = new QAction( "", tr("MEN_DESK_PREF_OBJECTBROWSER_ENTRY"), 0, this, 0, true );
706 QAD_ASSERT(connect( objectBrowserEntryAction, SIGNAL(activated()), this, SLOT(onObjectBrowser() )));
707 objectBrowserEntryAction->setToggleAction(true);
708 QString AddColumn = QAD_CONFIG->getSetting("ObjectBrowser:AddColumn");
710 if ( AddColumn.compare( aTrueQString ) == 0 )
711 objectBrowserEntryAction->setOn(true);
713 objectBrowserEntryAction->setOn(false);
715 objectBrowserEntryAction->addTo( &myObjBrowserPopup );
716 myStdActions.insert( PrefObjectBrowserEntryId, objectBrowserEntryAction );
718 QAction* objectBrowserValueAction = new QAction( "", tr("MEN_DESK_PREF_OBJECTBROWSER_VALUE"), 0, this, 0, true );
719 QAD_ASSERT(connect( objectBrowserValueAction, SIGNAL(activated()), this, SLOT(onObjectBrowser() )));
720 objectBrowserValueAction->setToggleAction(true);
721 QString ValueColumn = QAD_CONFIG->getSetting("ObjectBrowser:ValueColumn");
723 if ( ValueColumn.compare( aTrueQString ) == 0 )
724 objectBrowserValueAction->setOn(true);
726 objectBrowserValueAction->setOn(false);
728 objectBrowserValueAction->addTo( &myObjBrowserPopup );
729 myStdActions.insert( PrefObjectBrowserValueId, objectBrowserValueAction );
731 QAction* objectBrowserIAPPAction = new QAction( "", tr("MEN_DESK_PREF_OBJECTBROWSER_IAPP"), 0, this, 0, true );
732 QAD_ASSERT(connect( objectBrowserIAPPAction, SIGNAL(activated()), this, SLOT(onObjectBrowser() )));
733 objectBrowserIAPPAction->setToggleAction(true);
734 QString showIAPP = QAD_CONFIG->getSetting("ObjectBrowser:IAPP");
736 if ( showIAPP.compare( aTrueQString ) == 0 )
737 objectBrowserIAPPAction->setOn(true);
739 objectBrowserIAPPAction->setOn(false);
741 objectBrowserIAPPAction->addTo( &myObjBrowserPopup );
742 myStdActions.insert( PrefObjectBrowserIAPPId, objectBrowserIAPPAction );
744 /* Chronological sorting of shapes on the entry creation */
745 QAction* objectBrowserCHRONO_SORTAction = new QAction( "", tr("MEN_DESK_PREF_OBJECTBROWSER_CHRONO_SORT"), 0, this, 0, true );
746 QAD_ASSERT(connect( objectBrowserCHRONO_SORTAction, SIGNAL(activated()), this, SLOT(onObjectBrowser() )));
747 objectBrowserCHRONO_SORTAction->setToggleAction(true);
748 QString showSORT = QAD_CONFIG->getSetting("ObjectBrowser:CHRONO_SORT");
750 if ( showSORT.compare( aTrueQString ) == 0 )
751 objectBrowserCHRONO_SORTAction->setOn(true) ;
753 objectBrowserCHRONO_SORTAction->setOn(false) ;
755 objectBrowserCHRONO_SORTAction->addTo( &myObjBrowserPopup );
756 myStdActions.insert( PrefObjectBrowserCHRONO_SORTId, objectBrowserCHRONO_SORTAction ) ;
758 myPrefPopup.insertSeparator();
760 QAction* dirAction = new QAction( "", tr("MEN_DESK_PREF_DIRICTORIES"), 0, this );
761 QAD_ASSERT(connect( dirAction, SIGNAL(activated()), this, SLOT(onDirList() )));
762 dirAction->addTo( &myPrefPopup );
763 myStdActions.insert( PrefDirsId, dirAction );
765 myPrefPopup.insertSeparator();
767 QAction* saveAction = new QAction( "", tr("MEN_DESK_PREF_SAVE"), 0, this );
768 QAD_ASSERT(connect( saveAction, SIGNAL(activated()), this, SLOT(onSavePref() )));
769 saveAction->addTo( &myPrefPopup );
770 myStdActions.insert( PrefSaveId, saveAction );
772 /* 'Window' actions */
775 myWindowPopup.insertItem( tr("MEN_DESK_WINDOW_NEW3D"), &myNewViewPopup, WindowNew3dId );
777 QAction* viewOCCAction = new QAction( "", tr("MEN_DESK_VIEW_OCC"), 0, this );
778 QAD_ASSERT(connect( viewOCCAction, SIGNAL(activated()), this, SLOT(onNewWindow3d() )));
779 viewOCCAction->addTo( &myNewViewPopup );
780 myStdActions.insert( ViewOCCId, viewOCCAction );
782 QAction* viewVTKAction = new QAction( "", tr("MEN_DESK_VIEW_VTK"), 0, this );
783 QAD_ASSERT(connect( viewVTKAction, SIGNAL(activated()), this, SLOT(onNewWindow3d() )));
784 viewVTKAction->addTo( &myNewViewPopup );
785 myStdActions.insert( ViewVTKId, viewVTKAction );
787 QAction* viewPlot2dAction = new QAction( "", tr("MEN_DESK_VIEW_PLOT2D"), 0, this );
788 QAD_ASSERT(connect( viewPlot2dAction, SIGNAL(activated()), this, SLOT(onNewWindow3d() )));
789 viewPlot2dAction->addTo( &myNewViewPopup );
790 myStdActions.insert( ViewPlot2dId, viewPlot2dAction );
792 // QAction* windowNew3dAction = new QAction( "",/* rmgr->loadPixmap( "QAD", tr("ICON_DESK_WINDOW_NEW3D") ), */
793 /*tr("MEN_DESK_WINDOW_NEW3D"), 0, this );
794 windowNew3dAction->addTo( &myWindowPopup );
795 QAD_ASSERT( connect( windowNew3dAction, SIGNAL(activated()), this ,
796 SLOT( onNewWindow3d() )));
797 myStdActions.insert( WindowNew3dId, windowNew3dAction );
803 QAction* windowCascadeAction = new QAction( "", rmgr->loadPixmap( "QAD", tr("ICON_DESK_WINDOW_CASCADE") ),
804 tr("MEN_DESK_WINDOW_CASCADE"), 0, this );
805 windowCascadeAction->setStatusTip ( tr("PRP_DESK_WINDOW_CASCADE") );
806 QAD_ASSERT( connect( windowCascadeAction, SIGNAL(activated()), this,
807 SLOT( onCascade() )));
808 myStdActions.insert( WindowCascadeId, windowCascadeAction );
811 QAction* windowTileAction = new QAction( "", rmgr->loadPixmap( "QAD", tr("ICON_DESK_WINDOW_TILE") ),
812 tr("MEN_DESK_WINDOW_TILE"), 0, this );
813 windowTileAction->setStatusTip ( tr("PRP_DESK_WINDOW_TILE") );
814 QAD_ASSERT( connect( windowTileAction, SIGNAL(activated()), myWorkspace, SLOT( tile() )));
815 myStdActions.insert( WindowTileId, windowTileAction );
817 QAD_ASSERT( connect ( &myWindowPopup, SIGNAL(aboutToShow()),
818 this, SLOT(onWindowPopupAboutToShow()) ));
822 QAction* helpContentsAction = new QAction( "", tr("MEN_DESK_HELP_CONTENTS"), 0, this );
823 helpContentsAction->setStatusTip ( tr("PRP_DESK_HELP_CONTENTS") );
824 QAD_ASSERT(connect( helpContentsAction, SIGNAL(activated()),
825 this, SLOT( onHelpContents() )));
826 helpContentsAction->addTo( &myHelpPopup );
827 myStdActions.insert( HelpContentsId , helpContentsAction );
830 // QAction* helpSearchAction = new QAction( "", tr("MEN_DESK_HELP_SEARCH"), 0, this );
831 // helpSearchAction->setStatusTip ( tr("PRP_DESK_HELP_SEARCH") );
832 // QAD_ASSERT( connect( helpSearchAction, SIGNAL(activated()), this, SLOT( onHelpSearch() )));
833 // helpSearchAction->addTo( &myHelpPopup );
834 // myStdActions.insert( HelpSearchId, helpSearchAction );
837 // QAction* helpWhatsThisAction = new QAction( "", tr("MEN_DESK_HELP_WHATSTHIS"), SHIFT+Key_F1, this );
838 // helpWhatsThisAction->setStatusTip ( tr("PRP_DESK_HELP_WHATSTHIS" ));
839 // QAD_ASSERT( connect( helpWhatsThisAction, SIGNAL(activated()), this, SLOT( whatsThis() )));
840 // helpWhatsThisAction->addTo( &myHelpPopup );
841 // myStdActions.insert( HelpWhatsThisId, helpWhatsThisAction );
842 // (void)QWhatsThis::whatsThisButton( myStdToolBar );
844 id = myHelpPopup.insertSeparator();
845 myHelpPos = myHelpPopup.indexOf( id );
848 QAction* helpAboutAction = new QAction( "", tr("MEN_DESK_HELP_ABOUT"), 0, this );
849 helpAboutAction->setStatusTip ( tr("PRP_DESK_HELP_ABOUT") );
850 QAD_ASSERT( connect( helpAboutAction, SIGNAL(activated()), this, SLOT( onHelpAbout() )));
851 helpAboutAction->addTo( &myHelpPopup );
852 myStdActions.insert(HelpAboutId, helpAboutAction );
858 Adds the given application into the list of supported applications
860 void QAD_Desktop::addApplication(QAD_Application* app)
862 /* add only if is not already in the list */
863 if ( myApps.findRef( app ) == -1 )
865 myApps.append( app );
867 /* set activation/deactivation listener */
868 QAD_ASSERT ( connect( app, SIGNAL(appActivated(QAD_Application*)),
869 this, SLOT(onActivateApp(QAD_Application*))) );
871 QAD_ASSERT ( connect( app, SIGNAL(appDeactivated(QAD_Application*)),
872 this, SLOT(onDeactivateApp(QAD_Application*))) );
877 Displays the control panel of the application.
878 This function is called when the desktop is shown first time.
880 void QAD_Desktop::showDesktop()
886 Closes Desktop. If <forceClose> is true query for exit will be skipped.
888 void QAD_Desktop::closeDesktop( bool forceClose )
891 myQueryClose = false;
896 Puts the message to the status bar
898 void QAD_Desktop::putInfo ( const QString& msg )
901 myStatusBar->message ( msg );
905 Puts the message to the status bar for ms milli-seconds
907 void QAD_Desktop::putInfo ( const QString& msg, int ms )
910 myStatusBar->message ( msg, ms );
914 Returns the standard toolbar
916 QMenuBar* QAD_Desktop::getMainMenuBar() const
922 Returns the standard toolbar
924 QToolBar* QAD_Desktop::getStdToolBar() const
930 Updates desktop panel (menu, toolbar and status bar) according to current state of
931 the application. Calls update() for the active application.
932 The command { UD_ADD_APP or UD_REMOVE_APP ) specifies the desktop components
933 will be changed according to new active application.
934 This function is called after activating new study, closing current study etc.
936 void QAD_Desktop::updateDesktop( UpdateCommand cmd )
939 updateToolBars( cmd );
940 updateStatusBar( cmd );
945 Updates the desktop caption
947 void QAD_Desktop::updateCaption( UpdateCommand cmd )
949 if ( cmd == ActivateApp )
950 { /* application's icon and title */
951 setIcon( myActiveApp->getApplicationIcon() );
952 setCaption( myActiveApp->getApplicationName() );
955 { /* default icon and title */
956 setIcon( myDefaultIcon );
957 setCaption( myDefaultTitle );
962 Updates status bar when a new application becomes current
964 void QAD_Desktop::updateStatusBar( UpdateCommand cmd )
968 bool activate = ( cmd == ActivateApp );
969 myActiveApp->updateStatusBar ( myStatusBar, activate );
974 Updates toolbars according to current active application.
975 This function is called from updateDesktop().
977 void QAD_Desktop::updateToolBars( UpdateCommand cmd )
981 bool activate = ( cmd == ActivateApp );
982 myActiveApp->updateToolBars ( activate );
987 Updates main menu bar of the application when application is activated
989 This function is called by updateDesktop()
991 void QAD_Desktop::updateMenu( UpdateCommand cmd )
995 bool activate = ( cmd == ActivateApp );
996 myActiveApp->updateFilePopup( &myFilePopup, activate, myFilePos );
997 myActiveApp->updateEditPopup( &myEditPopup, activate, myEditPos );
998 myActiveApp->updateViewPopup( &myViewPopup, activate, myViewPos );
999 myActiveApp->updateHelpPopup( &myHelpPopup, activate, myHelpPos );
1000 myActiveApp->updateMainMenu( myMainMenu, activate, myMainMenuPos );
1003 Since 'Edit' popup is completely customized by applications
1004 desktop doesn't show it in main menubar without the active
1005 application and we insert/remove this popup from the menubar
1006 when activating/deactivating applications.
1008 We can't have 'Edit' popup be customized by an application
1009 via UpdateMainMenu() method because applications may insert
1010 its items to the menubar only AFTER 'View' item ( this fact
1011 is respected by myMainMenuPos ) and the possibility of an
1012 application to add its items into any arbitrary positions of
1013 the main menubar requires a bit sophisticated implementation,
1014 so we decided to avoid it, sorry :-(.
1016 #if defined( DEBUG )
1018 /* applications MUST clear 'Edit' after themselves */
1019 QAD_ASSERT_DEBUG_ONLY( !myEditPopup.count() );
1022 if ( activate ) /* insert after 'File' item */
1023 myMainMenu->insertItem( tr("MEN_DESK_EDIT"), &myEditPopup, 3, 1 );
1025 myMainMenu->removeItem( 3 );
1030 Returns icon file name used by the application
1032 const QPixmap& QAD_Desktop::getDefaultIcon() const
1034 static QPixmap defaultPixmap( QAD_Desktop::getResourceManager()->loadPixmap( "QAD",
1035 tr("ICON_DESK_DEFAULTICON") ));
1036 return defaultPixmap;
1040 Returns name of the application used as the title of desktop panel
1042 const QString& QAD_Desktop::getDefaultTitle() const
1044 static QString defaultTitle ( tr("DESK_DEFAULTTITLE") );
1045 return defaultTitle;
1049 Returns default name of new studies
1051 const QString& QAD_Desktop::getDefaultStudyName() const
1053 static QString defaultStudyName( tr("DESK_DEFAULTDOC") );
1054 return defaultStudyName;
1058 Returns next name for new study
1060 QString QAD_Desktop::getNewStudyName()
1063 number.sprintf( "%d", ++myCntUntitled );
1064 return ( getDefaultStudyName() + number );
1068 Searches QAD_Study corresponding to <study>, returns NULL if fails
1070 QAD_Study* QAD_Desktop::findStudy( SALOMEDS::Study_ptr theStudy )
1072 for ( QAD_Application* app = myApps.first(); app; app = myApps.next() ) {
1073 QList<QAD_Study> studies;
1074 studies.setAutoDelete( false );
1075 studies = app->getStudies();
1076 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
1077 if ( study->getStudyDocument()->_is_equivalent( theStudy ) )
1085 Returns current active application
1087 QAD_Application* QAD_Desktop::getActiveApp() const
1093 Returns current active study
1095 QAD_Study* QAD_Desktop::getActiveStudy() const
1097 return myActiveStudy;
1103 QWorkspaceP* QAD_Desktop::getMainFrame() const
1109 Find or load Engine, given a container name and an engine name
1111 Engines::Component_var QAD_Desktop::getEngine(const char *containerName,
1112 const char *componentName)
1114 Engines::Component_var eng =
1115 myEnginesLifeCycle->FindOrLoad_Component(containerName,
1121 gets application Help Window (and creates if necessary)
1123 QAD_HelpWindow* QAD_Desktop::getHelpWindow()
1125 if (!myHelpWindow) {
1126 myHelpWindow = new QAD_HelpWindow();
1127 connect(myHelpWindow, SIGNAL(helpWindowClosed()), this, SLOT(onHelpWindowClosed()));
1129 return myHelpWindow;
1133 Called when desktop is closing
1135 void QAD_Desktop::closeEvent ( QCloseEvent* e )
1137 bool doClose = true;
1138 if ( myQueryClose ) {
1139 doClose = QAD_MessageBox::info2 ( this, tr("INF_DESK_EXIT"),
1140 tr("QUE_DESK_EXIT"), tr ("BUT_OK"),
1141 tr ("BUT_CANCEL"), QAD_YES,
1142 QAD_NO, QAD_NO ) == QAD_YES;
1146 for ( QAD_Application* app = myApps.first(); app; app = myApps.next() ) {
1147 QList<QAD_Study>& studies = app->getStudies();
1148 for(QAD_Study* study = studies.first(); study != 0; study = studies.next()) {
1149 if(myQueryClose && study->getStudyDocument()->IsModified()) {
1150 SALOMEGUI_CloseDlg aDlg( this );
1151 switch ( aDlg.exec() ) {
1153 if ( !onSaveStudy( study ) ) {
1154 putInfo( tr("INF_CANCELLED") );
1165 putInfo( tr("INF_CANCELLED") );
1173 myQueryClose = true;
1174 doClose ? e->accept() : e->ignore();
1178 Called when desktop is resized
1180 void QAD_Desktop::resizeEvent( QResizeEvent* e )
1182 QMainWindow::resizeEvent( e );
1183 myWorkspace->setGeometry( 1,1, centralWidget()->width()-2,
1184 centralWidget()->height()-2 );
1189 Terminates the application.
1191 void QAD_Desktop::onExit()
1196 /************************************************************************
1198 *************************************************************************/
1202 If several application are supported it displays dialog window
1203 to choose type of study.
1205 void QAD_Desktop::createStudy(){
1208 void QAD_Desktop::onNewStudy()
1210 unsigned numApps = myApps.count();
1213 onNewStudy ( myApps.at(0) );
1214 else { /* select the type of application for new study */
1215 Desktop_AppSelectionDlg selDlg( this, myApps );
1216 if ( selDlg.exec() == QDialog::Accepted ) {
1217 onNewStudy ( selDlg.selectedApp() );
1220 } else { /* no applications available in desktop */
1221 QAD_MessageBox::error1( this,
1223 tr("ERR_APP_NOAPP"),
1229 Creates new study for the given application.
1230 Calls the respective function of the application class.
1232 void QAD_Desktop::onNewStudy( QAD_Application* app )
1236 /* create new study of the specific app */
1237 putInfo ( tr ("INF_DOC_CREATING") );
1238 QAD_Study* newStudy = app->newStudy();
1241 /* can't create new study */
1242 QAD_MessageBox::error1( this, tr("ERR_ERROR"),
1243 tr("ERR_DOC_CANTCREATE"),
1246 putInfo ( tr("INF_READY") );
1250 Loads the existing study.
1252 void QAD_Desktop::onLoadStudy()
1254 QString name, studyname, ext;
1256 SALOMEGUI_LoadStudiesDlg* aDlg = new SALOMEGUI_LoadStudiesDlg( this, "Load Study", TRUE);
1258 CORBA::Object_var obj = myNameService->Resolve("/myStudyManager");
1259 SALOMEDS::StudyManager_var myStudyMgr = SALOMEDS::StudyManager::_narrow(obj);
1260 ASSERT(! CORBA::is_nil(myStudyMgr));
1261 SALOMEDS::ListOfOpenStudies_var List = myStudyMgr->GetOpenStudies();
1262 for (unsigned int ind = 0; ind < List->length();ind++) {
1263 studyname = List[ind];
1264 aDlg->ListComponent->insertItem( studyname );
1267 int retVal = aDlg->exec();
1268 studyname = aDlg->ListComponent->currentText();
1270 if (retVal == QDialog::Rejected)
1273 if ( studyname.isNull() || studyname.isEmpty() )
1277 name.replace( QRegExp(":"), "/" );
1280 Try to associate an application to the opened study.
1281 Assumed that the association study<->application is unique.
1283 bool appFound = false;
1284 putInfo ( tr("INF_DOC_OPENING") + " " + name );
1285 for ( QAD_Application* app = myApps.first(); app; app = myApps.next() )
1287 /* application found */
1288 if ( app->isStudyOpened( name ) )
1290 /* already opened: prompt for reopen */
1291 if ( QAD_MessageBox::warn2 ( this, tr("WRN_WARNING"),
1292 tr("QUE_DOC_ALREADYOPEN").arg( name ),
1293 tr ("BUT_YES"), tr ("BUT_NO"), QAD_YES, QAD_NO,
1294 QAD_NO ) == QAD_NO )
1296 putInfo ( tr("INF_READY") );
1299 /* now the study is closed to be re-opened */
1300 //don't ask user to remove study permanently
1301 if (app->getStudyByName ( name ) != NULL)
1302 onCloseStudy ( app->getStudyByName ( name ), false );
1303 else if (app->getStudyByName ( QAD_Tools::getFileNameFromPath( name, false )) != NULL)
1304 onCloseStudy ( app->getStudyByName ( QAD_Tools::getFileNameFromPath( name, false )), false );
1308 /* open the study */
1309 QAD_Study* openStudy = app->loadStudy( studyname );
1311 QAD_MessageBox::error1( this,
1313 tr("ERR_DOC_CANTOPEN") + "\n" + name,
1320 QAD_MessageBox::error1( this,
1322 tr("ERR_DOC_UNKNOWNTYPE"),
1325 putInfo ( tr("INF_READY") );
1329 Opens the existing study.
1330 Displays select file dialog and calls corresponding function of
1332 (application is defined according to extension of selected file).
1334 void QAD_Desktop::onOpenStudy()
1338 /* Select a file to open */
1339 name = selectFileName ( true );
1340 if ( name.isNull() || name.isEmpty() )
1343 // Workaround for non-existent files
1345 if (!fi.exists() || !fi.isFile()) {
1346 QAD_MessageBox::error1 ( this, tr("ERR_ERROR"),
1347 tr("ERR_DOC_CANTOPEN") +": " + name,
1352 CORBA::Object_var obj = myNameService->Resolve("/myStudyManager");
1353 SALOMEDS::StudyManager_var myStudyMgr = SALOMEDS::StudyManager::_narrow(obj);
1354 ASSERT(! CORBA::is_nil(myStudyMgr));
1355 SALOMEDS::ListOfOpenStudies_var List = myStudyMgr->GetOpenStudies();
1356 for (unsigned int ind = 0; ind < List->length();ind++) {
1357 QString NameExistingStudy(List[ind]);
1358 QString NameOpeningStudy = QAD_Tools::getFileNameFromPath( name, false );
1360 if ( NameExistingStudy.compare( NameOpeningStudy ) == 0 ) {
1361 if ( QAD_MessageBox::warn2 ( this, tr("WRN_WARNING"),
1362 tr("QUE_DOC_ALREADYEXIST").arg( name ),
1363 tr ("BUT_YES"), tr ("BUT_NO"), QAD_YES, QAD_NO,
1364 QAD_NO ) == QAD_NO )
1366 putInfo ( tr("INF_READY") );
1378 Try to associate an application to the opened study.
1379 Assumed that the association study<->application is unique.
1381 bool appFound = false;
1382 putInfo ( tr("INF_DOC_OPENING") + " " + name );
1383 for ( QAD_Application* app = myApps.first(); app; app = myApps.next() )
1385 QString ext = QAD_Tools::getFileExtensionFromPath ( name );
1386 if ( app->getStudyExtension() == ext )
1388 /* application found */
1389 if ( app->isStudyOpened( name ) )
1391 /* already opened: prompt for reopen */
1392 if ( QAD_MessageBox::warn2 ( this, tr("WRN_WARNING"),
1393 tr("QUE_DOC_ALREADYOPEN").arg( name ),
1394 tr ("BUT_YES"), tr ("BUT_NO"), QAD_YES, QAD_NO,
1395 QAD_NO ) == QAD_NO )
1397 putInfo ( tr("INF_READY") );
1400 /* now the study is closed to be re-opened */
1401 //don't ask user to remove study permanently
1402 if (app->getStudyByName ( name ) != NULL)
1403 onCloseStudy ( app->getStudyByName ( name ), false );
1404 else if (app->getStudyByName ( QAD_Tools::getFileNameFromPath( name, false )) != NULL)
1405 onCloseStudy ( app->getStudyByName ( QAD_Tools::getFileNameFromPath( name, false )), false );
1409 /* open the study */
1410 QAD_Study* openStudy = app->openStudy( name );
1412 QAD_MessageBox::error1( this,
1414 tr("ERR_DOC_CANTOPEN") + "\n" + name,
1416 } else if (myActiveComp != "") {
1417 QApplication::setOverrideCursor( Qt::waitCursor );
1418 loadComponentData(myActiveComp);
1419 openStudy->updateObjBrowser(true);
1420 QApplication::restoreOverrideCursor();
1428 QAD_MessageBox::error1( this,
1430 tr("ERR_DOC_UNKNOWNTYPE"),
1433 putInfo ( tr("INF_READY") );
1436 bool QAD_Desktop::loadComponentData( const QString& compName )
1438 // Open component's data in active study if any
1439 MESSAGE("loadComponentData(): Opening component data")
1440 if (!myActiveStudy) {
1441 MESSAGE("loadComponentData(): No active study exists")
1445 Engines::Component_var comp ;
1446 if ( compName.compare("Supervision") == 0 ) {
1447 comp = getEngine( "SuperVisionContainer", compName) ;
1450 /* comp = ( compName.compare("Data1") != 0 ) ? getEngine( "FactoryServer", compName) :
1451 getEngine( "FactoryServerPy", compName);
1453 comp = getEngine( "FactoryServer", compName);
1454 if ( comp->_is_nil() )
1455 comp = getEngine( "FactoryServerPy", compName);
1458 SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
1459 SALOMEDS::SComponent_var SCO = SALOMEDS::SComponent::_narrow(aStudy->FindObject(compName));
1461 if (!SCO->_is_nil()) {
1462 if (!CORBA::is_nil(comp)) {
1463 SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
1464 if (!CORBA::is_nil(driver)) {
1465 SALOMEDS::StudyBuilder_var B = aStudy->NewBuilder();
1466 if (!CORBA::is_nil(B)) {
1467 QAD_Operation* op = new QAD_Operation( myActiveStudy );
1469 B->LoadWith(SCO,driver);
1475 MESSAGE("loadComponentData(): Driver is null");
1479 MESSAGE("loadComponentData(): Engine is null");
1483 MESSAGE("loadComponentData(): SComponent is null");
1491 Saves the active study
1493 bool QAD_Desktop::onSaveStudy()
1495 return onSaveStudy ( myActiveStudy );
1499 Saves the given study
1501 bool QAD_Desktop::onSaveStudy( QAD_Study* study )
1503 if ( !study ) return true;
1505 if ( !study->isSaved() )
1506 return onSaveAsStudy ( study );
1508 /* saving study... */
1509 QAD_Application* app = study->getApp();
1510 QAD_ASSERT_DEBUG_ONLY ( app );
1511 putInfo ( tr("INF_DOC_SAVING") + study->getTitle() );
1512 if ( !app->saveStudy( study ) )
1514 putInfo( tr("INF_CANCELLED") );
1519 putInfo ( tr("INF_DOC_SAVED").arg( "" ) );
1524 Saves the active study under a new name
1526 bool QAD_Desktop::onSaveAsStudy()
1528 return onSaveAsStudy( myActiveStudy );
1532 Saves the given study under a new name
1534 bool QAD_Desktop::onSaveAsStudy( QAD_Study* study )
1536 if ( !study ) return true;
1538 /* Save study in a format supported by its application
1540 QAD_Application* app = study->getApp();
1541 QAD_ASSERT_DEBUG_ONLY ( app );
1543 /* Select a file where to save
1545 QString name = selectFileName ( false );
1546 if ( name.isNull() || name.isEmpty() )
1548 putInfo( tr("INF_CANCELLED") );
1554 putInfo ( tr("INF_DOC_SAVING") + name );
1555 if ( !app->saveAsStudy( study, name ) ) {
1556 /* can't save the file */
1557 QAD_MessageBox::error1( this,
1559 tr("ERR_DOC_CANTWRITE") + "\n" + name,
1562 return false; /* cannot save */
1564 putInfo ( tr("INF_DOC_SAVED").arg( name ) );
1565 return true; /* saved ok */
1569 Closes the active study
1571 bool QAD_Desktop::onCloseStudy()
1573 bool close = this->onCloseStudy ( myActiveStudy, true );
1574 if ( close && !myXmlHandler->myIdList.IsEmpty() ) {
1577 myCombo->setCurrentItem (0);
1578 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
1579 aButton->setOn(false);
1586 Closes the given study and ask user to remove study
1587 from the study manager permanently
1589 bool QAD_Desktop::onCloseStudy( QAD_Study* study )
1591 return onCloseStudy( study, true );
1595 Closes the given study and ask user to remove study
1596 from the study manager permanently if ask is equal true
1598 bool QAD_Desktop::onCloseStudy( QAD_Study* study, bool ask )
1600 bool removePerm = false;
1604 SALOMEGUI_CloseDlg aDlg( this );
1605 int res = aDlg.exec();
1610 //if ( study->isModified() )
1611 if ( !onSaveStudy( study ) ) {
1612 putInfo( tr("INF_CANCELLED") );
1625 putInfo( tr("INF_CANCELLED") );
1629 /* close active component */
1630 if (!myXmlHandler->myIdList.IsEmpty())
1634 myCombo->setCurrentItem (0);
1635 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() )
1636 aButton->setOn(false);
1637 qApp->processEvents();
1639 /* close the study */
1640 return study->getApp()->closeStudy( study, removePerm );
1643 // Displays study properties dialog box
1644 void QAD_Desktop::onStudyProperties()
1646 if (myActiveStudy) {
1648 QAD_Operation* op = new QAD_Operation( myActiveStudy );
1651 SALOMEGUI_StudyPropertiesDlg aDlg(this);
1652 int res = aDlg.exec();
1654 if ( res == QDialog::Accepted && aDlg.isChanged() )
1659 // T2.12 - add the word "locked" to study frame captions if <myActiveStudy> study is locked
1660 myActiveStudy->updateCaptions();
1666 locate all windows in cascade mode
1669 void QAD_Desktop::onCascade()
1671 myWorkspace->cascade();
1672 int w = myWorkspace->width();
1673 int h = myWorkspace->height();
1674 QWidgetList wList = myWorkspace->windowList();
1675 QWidgetListIt it(wList);
1677 for(;it.current(); ++it)
1678 it.current()->resize(0.8*w, 0.8*h);
1682 called when help window closed
1684 void QAD_Desktop::onHelpWindowClosed()
1690 Called when 'view status bar' option
1693 void QAD_Desktop::onViewStatusBar()
1695 bool show = myStdActions.at( ViewStatusBarId )->isOn();
1696 if ( show == myStatusBar->isVisible() )
1699 myStatusBar->show();
1701 myStatusBar->hide();
1705 Called when View/Toolbars popup menu is about to show
1707 void QAD_Desktop::onToolBarPopupAboutToShow()
1709 myToolBarAction.clear();
1710 myToolBarsPopup.clear();
1711 QPtrList<QDockWindow> wlist = dockWindows();
1712 for ( QDockWindow* w = wlist.first(); w; w = wlist.next() ) {
1713 if ( w->inherits( "QToolBar" ) ) {
1714 QToolBar* tb = ( QToolBar* )w;
1715 if ( appropriate( tb ) ) {
1716 ToggleAction* a = new ToggleAction( tb->label(), tb->label(), 0, this, 0, true );
1717 a->setStatusTip ( tr("PRP_DESK_VIEW_TOOLBAR") );
1718 a->setOn( tb->isVisible() );
1719 QAD_ASSERT( connect( a, SIGNAL( toggledOn() ), tb, SLOT( show() ) ) );
1720 QAD_ASSERT( connect( a, SIGNAL( toggledOff() ), tb, SLOT( hide() ) ) );
1721 a->addTo( &myToolBarsPopup );
1722 myToolBarAction.append( a );
1729 Called on 'View\Selection Mode'
1731 void QAD_Desktop::onSelectionMode()
1733 const QAction* obj = (QAction*) sender();
1735 int SelectionMode = 4;
1737 if ( obj == myStdActions.at(SelectionActorId) ) {
1739 if ( obj->isOn() ) {
1740 myStdActions.at(SelectionCellId)->setOn(false);
1741 myStdActions.at(SelectionEdgeId)->setOn(false);
1742 myStdActions.at(SelectionPointId)->setOn(false);
1744 myStdActions.at(SelectionActorId)->setOn(true);
1746 } else if ( obj == myStdActions.at(SelectionCellId) ) {
1748 if ( obj->isOn() ) {
1749 myStdActions.at(SelectionActorId)->setOn(false);
1750 myStdActions.at(SelectionEdgeId)->setOn(false);
1751 myStdActions.at(SelectionPointId)->setOn(false);
1753 myStdActions.at(SelectionActorId)->setOn(true);
1755 } else if ( obj == myStdActions.at(SelectionEdgeId) ) {
1757 if ( obj->isOn() ) {
1758 myStdActions.at(SelectionActorId)->setOn(false);
1759 myStdActions.at(SelectionCellId)->setOn(false);
1760 myStdActions.at(SelectionPointId)->setOn(false);
1762 myStdActions.at(SelectionActorId)->setOn(true);
1764 } else if ( obj == myStdActions.at(SelectionPointId) ) {
1766 if ( obj->isOn() ) {
1767 myStdActions.at(SelectionEdgeId)->setOn(false);
1768 myStdActions.at(SelectionCellId)->setOn(false);
1769 myStdActions.at(SelectionActorId)->setOn(false);
1771 myStdActions.at(SelectionActorId)->setOn(true);
1774 QAD_StudyFrame* sf = myActiveApp->getActiveStudy()->getActiveStudyFrame();
1775 sf->getRightFrame()->getViewFrame()->SetSelectionMode( SelectionMode );
1777 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveApp->getActiveStudy()->getSelection() );
1778 Sel->SetSelectionMode( SelectionMode );
1782 Called on 'View\Selection Mode'
1784 void QAD_Desktop::SetSelectionMode(int mode, bool activeCompOnly)
1789 myStdActions.at(SelectionEdgeId)->setOn(false);
1790 myStdActions.at(SelectionCellId)->setOn(false);
1791 myStdActions.at(SelectionActorId)->setOn(false);
1792 myStdActions.at(SelectionPointId)->setOn(true);
1797 myStdActions.at(SelectionActorId)->setOn(false);
1798 myStdActions.at(SelectionCellId)->setOn(false);
1799 myStdActions.at(SelectionPointId)->setOn(false);
1800 myStdActions.at(SelectionEdgeId)->setOn(true);
1805 myStdActions.at(SelectionActorId)->setOn(false);
1806 myStdActions.at(SelectionEdgeId)->setOn(false);
1807 myStdActions.at(SelectionPointId)->setOn(false);
1808 myStdActions.at(SelectionCellId)->setOn(true);
1813 myStdActions.at(SelectionCellId)->setOn(false);
1814 myStdActions.at(SelectionEdgeId)->setOn(false);
1815 myStdActions.at(SelectionPointId)->setOn(false);
1816 myStdActions.at(SelectionActorId)->setOn(true);
1821 QAD_StudyFrame* sf = myActiveApp->getActiveStudy()->getActiveStudyFrame();
1822 if ( sf->getTypeView() == VIEW_VTK ) {
1823 sf->getRightFrame()->getViewFrame()->SetSelectionMode( mode );
1824 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveApp->getActiveStudy()->getSelection() );
1825 Sel->SetSelectionMode( mode, activeCompOnly );
1831 Called on 'Window\NewWindow3d'
1833 void QAD_Desktop::onNewWindow3d()
1837 //VRV: T2.5 - add default viewer
1838 QApplication::restoreOverrideCursor();
1839 SALOMEGUI_ViewChoiceDlg *choice = new SALOMEGUI_ViewChoiceDlg(this, "", TRUE);
1840 int r = choice->exec();
1843 myActiveApp->getActiveStudy()->newWindow3d(QString(""),(ViewType)(choice->getSelectedViewer()));
1845 //VRV: T2.5 - add default viewer
1847 const QAction* obj = (QAction*) sender();
1848 if ( obj == myStdActions.at(ViewOCCId) ) {
1849 myActiveApp->getActiveStudy()->newWindow3d(QString(""),(ViewType)(0));
1850 } else if ( obj == myStdActions.at(ViewVTKId) ) {
1851 myActiveApp->getActiveStudy()->newWindow3d(QString(""),(ViewType)(1));
1852 } else if ( obj == myStdActions.at(ViewPlot2dId) ) {
1853 myActiveApp->getActiveStudy()->newWindow3d(QString(""),(ViewType)(3));
1859 Called on 'help\contents'
1861 void QAD_Desktop::onHelpContents()
1864 myActiveApp->helpContents();
1870 Called on 'help\search'
1872 void QAD_Desktop::onHelpSearch()
1875 myActiveApp->helpSearch();
1881 Called on 'help\about'
1883 void QAD_Desktop::onHelpAbout()
1886 myActiveApp->helpAbout();
1893 Activates the application and its active study
1895 void QAD_Desktop::onActivateApp( QAD_Application* activeApp )
1897 bool appChanged = ( activeApp != myActiveApp );
1900 updateDesktop( DeactivateApp );
1904 myActiveApp = activeApp;
1905 myActiveStudy = myActiveApp->getActiveStudy();
1915 updateDesktop( ActivateApp );
1916 updateCaption( (activeApp != NULL) ? ActivateApp : DeactivateApp );
1922 Called when the last study is removed from
1923 the application 'app'.
1925 void QAD_Desktop::onDeactivateApp(QAD_Application* app)
1927 if ( app && app == myActiveApp )
1932 Enables/disables standard actions
1934 void QAD_Desktop::updateActions()
1936 myStdActions.at( FileCloseId )->setEnabled ( myActiveStudy != NULL );
1937 myStdActions.at( FileSaveId )->setEnabled ( myActiveStudy != NULL );
1938 myStdActions.at( FileSaveAsId )->setEnabled ( myActiveStudy != NULL );
1939 myStdActions.at( FilePropsId )->setEnabled( myActiveStudy != NULL );
1940 // myStdActions.at( HelpContentsId )->setEnabled ( myActiveApp != NULL );
1941 // myStdActions.at( HelpSearchId )->setEnabled ( myActiveApp != NULL );
1942 // myStdActions.at( HelpWhatsThisId )->setEnabled ( myActiveApp != NULL );
1943 // myStdActions.at( HelpAboutId )->setEnabled ( myActiveApp != NULL );
1945 // myToolsPopup.setEnabled ( myActiveStudy != NULL );
1946 // myPrefPopup.setEnabled ( myActiveStudy != NULL );
1948 mySelectionModePopup.setEnabled ( myActiveStudy != NULL );
1952 Called when 'Window' popup is about to show
1954 void QAD_Desktop::onWindowPopupAboutToShow()
1956 /* add cascade/tile items */
1957 myWindowPopup.clear();
1960 //myStdActions.at( WindowNew3dId )->addTo( &myWindowPopup );
1961 myWindowPopup.insertItem( tr("MEN_DESK_WINDOW_NEW3D"), &myNewViewPopup, WindowNew3dId );
1962 //myStdActions.at( WindowNew3dId )->setEnabled( true );
1963 myWindowPopup.setItemEnabled( WindowNew3dId, true );
1965 myStdActions.at( WindowCascadeId )->addTo( &myWindowPopup );
1966 myStdActions.at( WindowCascadeId )->setEnabled( true );
1967 myStdActions.at( WindowTileId )->addTo( &myWindowPopup );
1968 myStdActions.at( WindowTileId )->setEnabled( true );
1970 /* add names of opened studies */
1971 QWidgetList windows = myWorkspace->windowList();
1972 if ( windows.isEmpty() )
1974 //NRI : SAL2214 myStdActions.at( WindowNew3dId )->setEnabled( false );
1975 myWindowPopup.setItemEnabled( WindowNew3dId, false );
1977 myStdActions.at( WindowCascadeId )->setEnabled( false );
1978 myStdActions.at( WindowTileId )->setEnabled( false );
1982 myWindowPopup.insertSeparator();
1983 for ( int i = 0; i < int(windows.count()); ++i )
1985 int id = myWindowPopup.insertItem( windows.at(i)->caption(),
1986 this, SLOT( onWindowsPopupActivated( int ) ) );
1987 myWindowPopup.setItemParameter( id, i );
1988 myWindowPopup.setItemChecked( id, myWorkspace->activeWindow() == windows.at(i) );
1990 QAD_ASSERT( connect( &myWindowPopup, SIGNAL(highlighted( int )), this,
1991 SLOT(onWindowsPopupStatusText( int )) ));
1996 Called when the item with 'id' of 'Windows' popup
1999 void QAD_Desktop::onWindowsPopupStatusText( int id )
2001 int cascadeId = myWindowPopup.idAt( 0 );
2002 int tileId = myWindowPopup.idAt( 1 );
2003 if ( id == cascadeId || id == tileId )
2005 putInfo( tr("PRP_DESK_WINDOW_ACTIVATE") );
2009 Called when user wants to activate a child window with 'wid'
2012 void QAD_Desktop::onWindowsPopupActivated( int wid )
2014 QWidget* w = myWorkspace->windowList().at( wid );
2015 if ( w ) w->setFocus();
2019 Selects a file name when opening or saving files.
2020 The basic implementation just uses the standard
2022 Please redefine if another behaviour is required.
2024 QString QAD_Desktop::selectFileName ( bool open )
2026 QAD_FileDlg* fd = new QAD_FileDlg( this, open, true, true );
2030 QStringList filters;
2033 // All the file types of the supported applications
2035 for ( QAD_Application* app = myApps.first(); app; app = myApps.next() )
2037 filters += app->getStudyDescription() + " " + tr("DESK_FILES") + " " +
2038 "(*." + app->getStudyExtension() + ")";
2042 QAD_ASSERT_DEBUG_ONLY ( myActiveStudy );
2043 if (myActiveStudy) {
2044 // get file name of active study
2045 name = QAD_Tools::getFileNameFromPath ( myActiveStudy->getTitle() );
2046 // get path to the active study file
2047 dir = QAD_Tools::getDirFromPath ( myActiveStudy->getPath(), false );
2049 QAD_ASSERT_DEBUG_ONLY ( !name.isNull() );
2050 // the file types supported by the active application
2051 filters += myActiveApp->getStudyDescription() + " " + tr("DESK_FILES") + " " +
2052 "(*." + myActiveApp->getStudyExtension() + ")" ;
2054 if (!dir.isEmpty()) {
2055 // when saving document ("Save As" command) - to get dir from active study filename
2056 // for new documents - to use last opened directory
2059 fd->setSelection( name );
2060 fd->setFilters( filters );
2063 QString filename = fd->selectedFile();
2065 qApp->processEvents();
2070 Closes all the studies of 'app'. Returns
2071 'true' if thay are closed OK, 'false' at least
2072 one can't be closed or user cancel the closure.
2074 bool QAD_Desktop::closeAllStudies( QAD_Application* app )
2076 QList<QAD_Study>& studies = app->getStudies();
2077 while ( !studies.isEmpty() )
2079 //don't ask user to remove study permanently
2080 if ( !onCloseStudy( studies.at(0), false ) )
2081 return false; /* user cancelled closing */
2087 Called on Popup item when SComponent representation in Object Browser is selected.
2089 void QAD_Desktop::onOpenWith()
2091 Engines::Component_var comp;
2092 QString ComponentSelected;
2094 SALOMEDS::SObject_var SO;
2095 SALOMEDS::SComponent_var SCO;
2096 SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
2097 SALOMEDS::GenericAttribute_var anAttr;
2098 SALOMEDS::AttributeName_var aName;
2100 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2101 if ( Sel->IObjectCount() == 1 ) {
2102 Handle(SALOME_InteractiveObject) IO = Sel->firstIObject();
2103 SO = aStudy->FindObjectID( IO->getEntry() );
2104 SCO = SO->GetFatherComponent();
2106 if (SCO->FindAttribute(anAttr, "AttributeName")) {
2107 aName = SALOMEDS::AttributeName::_narrow(anAttr);
2108 name = aName->Value();
2109 SALOME_ModuleCatalog::Acomponent_var Comp = myCatalogue->GetComponent( name );
2110 if ( !Comp->_is_nil() ) {
2112 SALOME_ModuleCatalog::ListOfComponents_var list_type_composants =
2113 myCatalogue->GetTypedComponentList( Comp->component_type() );
2115 if ( list_type_composants->length() == 1 ) {
2116 ComponentSelected = name;
2117 } else if ( list_type_composants->length() > 1 ) {
2118 SALOMEGUI_OpenWith* aDlg = new SALOMEGUI_OpenWith( this );
2119 for (unsigned int ind = 0; ind < list_type_composants->length();ind++) {
2120 aDlg->addComponent( strdup(list_type_composants[ind]) );
2123 int retVal = aDlg->exec();
2124 ComponentSelected = aDlg->getComponent();
2126 if ( retVal == QDialog::Rejected || ComponentSelected.isEmpty()) {
2130 MESSAGE( "No component with type : " << Comp->component_type() << " exists" );
2135 MESSAGE( "This component not exists in the catalog" );
2139 QApplication::setOverrideCursor( Qt::waitCursor );
2140 Sel->ClearIObjects();
2142 // if (loadComponentData(ComponentSelected)) {
2143 onComboActiveComponent(ComponentSelected);
2144 // int nbItem = myCombo->count();
2146 // for (int i = 0; i < nbItem; i++) {
2147 // if (myCombo->text(i).compare(ComponentSelected)==0) {
2152 // myCombo->setCurrentItem(Index);
2153 // myActiveStudy->updateObjBrowser(true);
2157 QApplication::restoreOverrideCursor();
2160 typedef bool OneDim1(QAD_Desktop*);
2163 Called to define settings of component.
2165 void QAD_Desktop::setSettings()
2167 if (!myActiveComp.isEmpty()) {
2168 OSD_Function osdF = mySharedLibrary.DlSymb("SetSettings");
2169 if ( osdF != NULL ) {
2170 OneDim1 (*f1) = (bool (*) (QAD_Desktop*)) osdF;
2177 Called to load Component : xml resources and GUI librairy.
2179 bool QAD_Desktop::loadComponent(QString Component)
2182 QString resDir("/"); //NRI : Pb under Windows
2184 QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
2187 if (!resMgr->loadResources( Component + "GUI", msg ))
2189 //NRI QCString errMsg;
2190 // errMsg.sprintf( "Do not load all resources for module %sGUI.\n" ,
2191 // Component.latin1() );
2193 QMessageBox::warning( this, tr("WRN_WARNING"), msg, tr ("BUT_OK") );
2198 /* Parse xml file */
2199 myXmlHandler = new QAD_XmlHandler();
2200 myXmlHandler->setMainWindow(this);
2201 if (!myXmlHandler->setComponent(resMgr->resources(Component + "GUI"))) return false;
2203 QString language = resMgr->language( Component + "GUI" );
2205 QString ComponentXml = Component + "_" + language + ".xml";
2206 //ComponentXml = resMgr->resources(Component + "GUI") ;
2207 //ComponentXml = QAD_Tools::addSlash(ComponentXml) ;
2208 ComponentXml = QAD_Tools::addSlash( resMgr->findFile( ComponentXml, Component + "GUI" ) ) + ComponentXml;
2209 QFile file( ComponentXml );
2211 if ( !file.exists() || !file.open( IO_ReadOnly ) ) {
2213 errMsg.sprintf( "Cannot open xml file: %s\n.",
2214 (file.name()).latin1() );
2216 QMessageBox::critical( this, tr("ERR_ERROR"), errMsg, tr ("BUT_OK") );
2221 QXmlInputSource source( file );
2222 QXmlSimpleReader reader;
2223 reader.setContentHandler( myXmlHandler );
2224 reader.setErrorHandler( myXmlHandler );
2225 bool ok = reader.parse( source );
2229 QMessageBox::critical( this,
2230 tr( "INF_PARSE_ERROR" ),
2231 tr( myXmlHandler->errorProtocol() ) );
2235 myMenusList=myXmlHandler->myMenusList;
2236 myActiveMenus=myMenusList.at(0);
2237 myOperatorMenus->showMenuBar(0);
2238 myActiveMenus->showAllToolBars();
2240 /* Components toolbars */
2243 nbToolbars = myActiveMenus->getToolBarList().count();
2244 /* Open Shared Library */
2245 mySharedLibrary = OSD_SharedLibrary();
2247 QString ComponentLib;
2249 QFileInfo fileInfo ;
2251 if ( dir = getenv("SALOME_SITE_DIR")) {
2252 dir = QAD_Tools::addSlash(dir) ;
2254 dir = QAD_Tools::addSlash(dir) ;
2256 dir = dir + "lib" + Component.latin1() + "GUI.dll" ;
2258 dir = dir + "lib" + Component.latin1() + "GUI.so" ;
2260 MESSAGE ( " GUI library = " << dir )
2261 fileInfo.setFile(dir) ;
2262 if (fileInfo.exists()) {
2263 ComponentLib = fileInfo.fileName() ;
2268 if ( (dir = getenv("SALOME_ROOT_DIR")) && !found ) {
2269 dir = QAD_Tools::addSlash(dir) ;
2271 dir = QAD_Tools::addSlash(dir) ;
2273 dir = dir + "lib" + Component.latin1() + "GUI.dll" ;
2275 dir = dir + "lib" + Component.latin1() + "GUI.so" ;
2277 MESSAGE ( " GUI library = " << dir )
2278 fileInfo.setFile(dir) ;
2279 if (fileInfo.exists()) {
2280 ComponentLib = fileInfo.fileName() ;
2285 mySharedLibrary.SetName(TCollection_AsciiString((char*)ComponentLib.latin1()).ToCString());
2286 ok = mySharedLibrary.DlOpen(OSD_RTLD_LAZY);
2289 QMessageBox::critical( this,
2291 tr( mySharedLibrary.DlError() ) );
2296 OSD_Function osdF = mySharedLibrary.DlSymb("SetSettings");
2297 if ( osdF != NULL ) {
2298 OneDim1 (*f1) = (bool (*) (QAD_Desktop*)) osdF;
2302 /* COMPONENT INTERFACE */
2303 SALOME_ModuleCatalog::Acomponent_ptr aComponent =
2304 myCatalogue->GetComponent(Component.latin1());
2306 if (CORBA::is_nil (aComponent)) {
2307 MESSAGE( "Catalog Error : Component not found in the catalog" )
2311 myActiveStudy->setMessage(QString("Component : ") +
2312 aComponent->componentname() + " created " );
2313 myActiveStudy->setMessage(QString("Type : ") +
2314 QString::number(aComponent->component_type()));
2315 myActiveStudy->setMessage(QString("Constraint : ") +
2316 aComponent->constraint() );
2318 /* obtain interfaces list of the component */
2319 SALOME_ModuleCatalog::ListOfInterfaces_var _list =
2320 new SALOME_ModuleCatalog::ListOfInterfaces;
2321 _list = aComponent->GetInterfaceList();
2323 if (_list->length() != 0 ) {
2325 for (unsigned int ind = 0; ind < _list->length();ind++)
2326 myActiveStudy->setMessage( QString("Interface name : ") +
2330 /* obtain services list of the component */
2331 SALOME_ModuleCatalog::ListOfServices_var list_services_component =
2332 new SALOME_ModuleCatalog::ListOfServices;
2333 list_services_component = aComponent->GetServiceList(_list[0]);
2335 if (list_services_component->length() != 0 ) {
2337 for (unsigned int ind = 0; ind < list_services_component->length();ind++)
2338 myActiveStudy->setMessage( QString("Service name : ") +
2339 list_services_component[ind] );
2341 // Get a service of the component
2342 SALOME_ModuleCatalog::Service_var service = new SALOME_ModuleCatalog::Service;
2343 service = aComponent->GetService(_list[0],list_services_component[0]) ;
2344 myActiveStudy->setMessage( QString("Service name: ") + service->ServiceName);
2345 for (unsigned int ind1 = 0; ind1 <service->ServiceinParameter.length();ind1++) {
2346 myActiveStudy->setMessage( QString("Type of the in Parameter of this service : ") +
2347 (const char *) service->ServiceinParameter[ind1].Parametertype);
2348 myActiveStudy->setMessage( QString("Name of the in Parameter of this service : ") +
2349 (const char *) service->ServiceinParameter[ind1].Parametername);
2351 for (unsigned int ind1 = 0; ind1 <service->ServiceoutParameter.length();ind1++) {
2352 myActiveStudy->setMessage( QString("Type of the out Parameter of this service : ") +
2353 (const char *) service->ServiceoutParameter[ind1].Parametertype);
2354 myActiveStudy->setMessage( QString("Name of the out Parameter of this service : ") +
2355 (const char *) service->ServiceoutParameter[ind1].Parametername);
2362 typedef bool OneDim(int, QAD_Desktop*);
2363 typedef void (*PTR_FACTORY_FUNCTION)( CORBA::ORB_var &orb, QWidget *parent, const char *name ) ;
2367 void QAD_Desktop::onDispatch()
2369 const QObject* obj = sender();
2371 QList<QAD_ListMenuIdAction> MenuList = myActiveMenus->getMenuList();
2372 QAD_ListMenuIdAction* aMenu;
2374 for(aMenu=MenuList.first();aMenu!=NULL;aMenu=MenuList.next()) {
2375 if (aMenu->getAction()==obj) {
2376 id = aMenu->getId();
2385 void QAD_Desktop::onDispatchTools(int id)
2387 /* Open Shared Library */
2388 OSD_SharedLibrary ToolsLibrary = OSD_SharedLibrary();
2392 QFileInfo fileInfo ;
2396 bool libToolsGUI = true;
2397 if( QAD_XmlHandler::_bibmap[ id ].isEmpty() )
2400 if ( dir = getenv("SALOME_SITE_DIR")) {
2401 dir = QAD_Tools::addSlash(dir) ;
2403 dir = QAD_Tools::addSlash(dir) ;
2405 dir = dir + "libToolsGUI.dll" ;
2407 dir = dir + "libToolsGUI.so" ;
2409 MESSAGE ( " GUI library = " << dir );
2410 fileInfo.setFile(dir) ;
2411 if (fileInfo.exists()) {
2412 ToolsLib = fileInfo.fileName() ;
2417 if ( (dir = getenv("SALOME_ROOT_DIR")) && !found ) {
2418 dir = QAD_Tools::addSlash(dir) ;
2420 dir = QAD_Tools::addSlash(dir) ;
2422 dir = dir + "libToolsGUI.dll" ;
2424 dir = dir + "libToolsGUI.so" ;
2426 MESSAGE ( " GUI library = " << dir );
2427 fileInfo.setFile(dir) ;
2428 if (fileInfo.exists()) {
2429 ToolsLib = fileInfo.fileName() ;
2435 libToolsGUI = false;
2436 SCRUTE( QAD_XmlHandler::_bibmap[ id ] ) ;
2437 if ( dir = getenv("SALOME_SITE_DIR")) {
2438 dir = QAD_Tools::addSlash(dir) ;
2440 dir = QAD_Tools::addSlash(dir) ;
2441 dir = dir + QAD_XmlHandler::_bibmap[ id ].latin1() ;
2442 MESSAGE ( " GUI library = " << dir );
2443 fileInfo.setFile(dir) ;
2444 if (fileInfo.exists()) {
2445 ToolsLib = fileInfo.fileName() ;
2450 if ( (dir = getenv("SALOME_ROOT_DIR")) && !found ) {
2451 dir = QAD_Tools::addSlash(dir) ;
2453 dir = QAD_Tools::addSlash(dir) ;
2454 dir = dir + QAD_XmlHandler::_bibmap[ id ].latin1() ;
2455 MESSAGE ( " GUI library = " << dir );
2456 fileInfo.setFile(dir) ;
2457 if (fileInfo.exists()) {
2458 ToolsLib = fileInfo.fileName() ;
2464 ToolsLibrary.SetName(TCollection_AsciiString((char*)ToolsLib.latin1()).ToCString());
2465 bool ok = ToolsLibrary.DlOpen(OSD_RTLD_LAZY);
2467 if ( libToolsGUI ) {
2468 OSD_Function osdF = ToolsLibrary.DlSymb("OnGUIEvent");
2469 OneDim (*f1) = NULL;
2470 f1 = (bool (*) (int, QAD_Desktop*)) osdF;
2473 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
2474 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
2475 CORBA::ORB_var &orb = init(0 , 0 ) ;
2476 OSD_Function osdF = ToolsLibrary.DlSymb("OnGUIEvent");
2477 PTR_FACTORY_FUNCTION f1 = NULL;
2478 f1 = (PTR_FACTORY_FUNCTION) osdF;
2479 f1(orb,0,"Registry");
2482 QMessageBox::critical( this,
2484 tr( ToolsLibrary.DlError() ) );
2490 void QAD_Desktop::onDispatch(int id)
2492 if (!myActiveComp.isEmpty()) {
2493 OSD_Function osdF = mySharedLibrary.DlSymb("OnGUIEvent");
2494 OneDim (*f1) = NULL;
2495 if ( osdF != NULL ) {
2496 f1 = (bool (*) (int, QAD_Desktop*)) osdF;
2503 Returns the component's catalogue
2505 SALOME_ModuleCatalog::ModuleCatalog_var QAD_Desktop::getCatalogue()
2512 void QAD_Desktop::onComboActiveComponent( const QString & component ){
2513 onComboActiveComponent(component,true);
2515 void QAD_Desktop::onComboActiveComponent( const QString & component, bool isLoadData)
2517 if (myActiveStudy != 0) {
2518 if (myActiveComp.compare(component)!=0) {
2519 if (!myXmlHandler->myIdList.IsEmpty()) clearMenus();
2520 if ( myCombo->currentText() != component )
2521 myCombo->setCurrentText( component );
2522 if (component.compare(QString("Salome"))!= 0) {
2523 // QApplication::setOverrideCursor( Qt::waitCursor );
2524 myActiveComp = component;
2526 SALOME_Selection* oldSel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2528 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2529 if ( aButton->textLabel().compare(component)==0)
2530 aButton->setOn(true);
2532 aButton->setOn(false);
2535 myActiveStudy->Selection( component );
2536 if ( !loadComponent(component) ) {
2537 myCombo->setCurrentItem (0);
2538 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2539 aButton->setOn(false);
2544 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2545 SALOME_ListIteratorOfListIO It( oldSel->StoredIObjects() );
2546 for(;It.More();It.Next()) {
2547 int res = Sel->AddIObject( It.Value() );
2550 myActiveStudy->highlight( It.Value(), false );
2552 myActiveStudy->highlight( It.Value(), true );
2556 // Open new component's data in active study if any
2557 if(isLoadData) loadComponentData(component);
2560 myActiveStudy->updateObjBrowser(true);
2562 // QApplication::restoreOverrideCursor();
2564 } else { // component == "Salome"
2566 myActiveStudy->Selection( "Salome" );
2567 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2568 Sel->ClearIObjects();
2569 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2570 aButton->setOn(false);
2574 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2575 if ( aButton->textLabel().compare(component)==0)
2576 aButton->setOn(true);
2580 QMessageBox::critical( 0,
2582 tr( "WRN_LOAD_COMPONENT" ) );
2583 myCombo->setCurrentItem (0);
2584 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2585 aButton->setOn(false);
2592 void QAD_Desktop::activateComponent(const QString& theName, bool isLoadData){
2593 int nbItem = myCombo->count();
2596 for (int i = 0; i < nbItem; i++) {
2597 if (myCombo->text(i).compare(theName)==0) {
2602 myCombo->setCurrentItem (Index);
2603 onComboActiveComponent(theName,isLoadData);
2606 void QAD_Desktop::onButtonActiveComponent( )
2608 QToolButton* obj = (QToolButton*)sender();
2609 activateComponent(obj->textLabel());
2613 Clears All Resources of current component
2615 void QAD_Desktop::clearMenus()
2617 onActiveStudyChanged();
2620 myMenusList.clear();
2622 int length = myXmlHandler->myIdList.Length();
2623 for (int k=length; k>0; k--) {
2625 if ( menuBar()->findItem(myXmlHandler->myIdList.Value(k), &parent) )
2626 parent->removeItem( myXmlHandler->myIdList.Value(k) );
2631 if (myActiveMenus) {
2632 int nbtoolbars = myActiveMenus->getToolBarList().count();
2633 for (int k=0; k<nbtoolbars; k++) {
2634 myActiveMenus->getToolBarList().at(k)->hide();
2635 myActiveMenus->getToolBarList().at(k)->clear();
2637 myActiveMenus->clearToolBar();
2640 QList<QAD_ListPopupMenu> PopupList = myActiveMenus->getPopupMenuList();
2641 QAD_ListPopupMenu* aPopup;
2642 for(aPopup=PopupList.first();aPopup!=NULL;aPopup=PopupList.next()){
2643 aPopup->getPopup()->clear();
2646 myActiveMenus->clearPopupMenu();
2652 typedef bool TwoDim1(QKeyEvent* pe, QAD_Desktop*, QAD_StudyFrame*);
2654 Exports Key Events in active component ( GUI Librairy )
2656 void QAD_Desktop::onKeyPress( QKeyEvent* pe )
2658 // MESSAGE ( "QAD_Desktop::onKeyPress" )
2659 if (!myActiveComp.isEmpty()) {
2660 OSD_Function osdF = mySharedLibrary.DlSymb("OnKeyPress");
2661 if ( osdF != NULL ) {
2662 TwoDim1 (*f1) = (bool (*) (QKeyEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
2663 (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
2668 typedef bool TwoDim(QMouseEvent* pe, QAD_Desktop*, QAD_StudyFrame*);
2670 Exports Mouse Press Events in active component ( GUI Librairy )
2672 bool QAD_Desktop::onMousePress( QMouseEvent* pe )
2674 // MESSAGE ( "QAD_Desktop::onMousePress" )
2675 if (!myActiveComp.isEmpty()) {
2676 OSD_Function osdF = mySharedLibrary.DlSymb("OnMousePress");
2677 if ( osdF != NULL ) {
2678 TwoDim (*f1) = (bool (*) (QMouseEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
2679 return (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
2686 Exports Mouse Move Events in active component ( GUI Librairy )
2688 void QAD_Desktop::onMouseMove( QMouseEvent* pe )
2690 if (!myActiveComp.isEmpty()) {
2691 OSD_Function osdF = mySharedLibrary.DlSymb("OnMouseMove");
2692 if ( osdF != NULL ) {
2693 TwoDim (*f1) = (bool (*) (QMouseEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
2694 (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
2700 Returns name of active component
2702 const QString& QAD_Desktop::getActiveComponent() const
2704 return myActiveComp;
2708 typedef bool defineP( QString & theContext, QString & theParent, QString & theObject);
2710 void QAD_Desktop::definePopup(QString & theContext,
2711 QString & theParent,
2712 QString & theObject )
2714 if (!myActiveComp.isEmpty()) {
2715 OSD_Function osdF = mySharedLibrary.DlSymb("definePopup");
2716 if ( osdF != NULL ) {
2717 defineP (*f1) = (bool (*) (QString &, QString &, QString &)) osdF;
2718 (*f1)(theContext, theParent, theObject);
2726 void QAD_Desktop::createPopup(QPopupMenu* popupFather, QPopupMenu* popup,
2727 QString text, int popupID, bool separator)
2729 QMenuItem* item = popup->findItem(popupID);
2731 QPopupMenu* popupChild = item->popup();
2733 QPopupMenu* newPopup = new QPopupMenu;
2734 int count = popupChild->count();
2735 // add items at the top of <popupFather>
2736 for (int i = count - 1; i >= 0; i--) {
2737 int j = popupChild->idAt(i);
2738 QString text = popupChild->text(j);
2739 createPopup( newPopup, popupChild, text, j);
2741 popupFather->insertItem(popup->text(popupID),
2742 newPopup, popupID, 0);
2744 if ( !text.isNull() ) {
2745 popupFather->insertItem(popup->text(popupID),
2747 SLOT( onDispatch(int) ), 0, popupID, 0);// try adding item at the top
2748 } /*else if ( separator )
2749 popupFather->insertTearOffHandle(-1, 0);*/
2751 popupFather->insertSeparator(0);
2759 void QAD_Desktop::createPopup(QPopupMenu* popup, const QString & theContext,
2760 const QString & theParent, const QString & theObject )
2762 if ( !myActiveComp.isEmpty() &&
2763 getOperatorMenus()->createPopupMenu(theContext,theParent,theObject) != NULL ) {
2764 QPopupMenu* aPopup = getOperatorMenus()->createPopupMenu(theContext,theParent,theObject)->getPopup();
2765 int count = aPopup->count();
2767 //for (int i = 0; i < count; i++) {
2768 for (int i = count - 1; i >= 0; i--) {
2769 int id = aPopup->idAt(i);
2770 QString text = aPopup->text(id);
2771 //QString mes("Inserting popup menu item loaded from XML: ");
2773 //MESSAGE ( mes.latin1() )
2775 popup->insertItem(aPopup->text(id),
2777 SLOT( onDispatch(int) ), 0, id, 0);// try adding item at the top
2779 createPopup( popup, aPopup, text, id);
2782 //QString mes("Popup does not exist for given (Context = ");
2783 //mes += theContext;
2784 //mes += ", Parent = ";
2786 //mes += ", Object = ";
2788 //MESSAGE (mes.latin1())
2793 // Should be moved to SALOMEGUI_Application::onCreatePopup()...
2794 if ( myActiveComp.isEmpty() ) {
2795 popup->removeItem(QAD_Display_Popup_ID);
2796 popup->removeItem(QAD_DisplayOnly_Popup_ID);
2797 popup->removeItem(QAD_Erase_Popup_ID);
2798 int id = popup->idAt(popup->count()-1); // last item
2799 if (id < 0 && id != -1) popup->removeItem(id); // separator
2801 if ( popup && theParent.compare("ObjectBrowser")==0 ) {
2802 if ( popup->count()>0 ) {
2803 popup->insertItem (tr ("MEN_OPENWITH"), this, SLOT(onOpenWith()), 0, -1, 2);
2804 popup->insertSeparator (3);
2807 popup->insertItem (tr ("MEN_OPENWITH"), this, SLOT(onOpenWith()) );
2814 typedef bool activeStudyChanged(QAD_Desktop*);
2816 void QAD_Desktop::onActiveStudyChanged()
2818 if (!myActiveComp.isEmpty()) {
2819 OSD_Function osdF = mySharedLibrary.DlSymb("activeStudyChanged");
2820 if ( osdF != NULL ) {
2821 activeStudyChanged (*f1) = (bool (*) (QAD_Desktop*)) osdF;
2827 typedef bool customP(QAD_Desktop*, QPopupMenu*, const QString & theContext,
2828 const QString & theParent, const QString & theObject);
2830 Custom popup ( GUI Library )
2832 void QAD_Desktop::customPopup(QPopupMenu* popup, const QString & theContext,
2833 const QString & theParent, const QString & theObject)
2835 if (!myActiveComp.isEmpty()) {
2836 OSD_Function osdF = mySharedLibrary.DlSymb("customPopup");
2837 if ( osdF != NULL ) {
2838 customP (*f1) = (bool (*) (QAD_Desktop*, QPopupMenu*, const QString &,
2839 const QString &, const QString &)) osdF;
2840 (*f1)(this, popup, theContext, theParent, theObject);
2845 void QAD_Desktop::onObjectBrowser()
2847 bool checkDiff = false;
2849 bool state = QAD_CONFIG->getSetting("ObjectBrowser:AddColumn").compare("true") == 0;
2851 if ( myStdActions.at( PrefObjectBrowserEntryId )->isOn() != state )
2855 if ( myStdActions.at( PrefObjectBrowserEntryId )->isOn() ) {
2857 QAD_CONFIG->addSetting( "ObjectBrowser:AddColumn", "true");
2860 QAD_CONFIG->addSetting( "ObjectBrowser:AddColumn", "false");
2864 if ( myStdActions.at( PrefObjectBrowserValueId )->isOn() ) {
2866 QAD_CONFIG->addSetting( "ObjectBrowser:ValueColumn", "true");
2869 QAD_CONFIG->addSetting( "ObjectBrowser:ValueColumn", "false");
2873 if ( myStdActions.at( PrefObjectBrowserIAPPId )->isOn() ) {
2875 QAD_CONFIG->addSetting( "ObjectBrowser:IAPP", "true");
2878 QAD_CONFIG->addSetting( "ObjectBrowser:IAPP", "false");
2881 /* To sort created object in chrono order or reverse chrono order */
2882 bool showCHRONO_SORT ;
2883 if ( myStdActions.at( PrefObjectBrowserCHRONO_SORTId )->isOn() ) {
2884 showCHRONO_SORT = true;
2885 QAD_CONFIG->addSetting( "ObjectBrowser:CHRONO_SORT", "true");
2887 showCHRONO_SORT = false;
2888 QAD_CONFIG->addSetting( "ObjectBrowser:CHRONO_SORT", "false");
2891 if ( myActiveApp ) {
2892 QList<QAD_Study>& studies = myActiveApp->getStudies();
2893 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
2894 int nbSf = study->getStudyFramesCount();
2895 for ( int i = 0; i < nbSf; i++ ) {
2896 QAD_StudyFrame* sf = study->getStudyFrame(i);
2897 sf->getLeftFrame()->getObjectBrowser()->setShowInfoColumns( showEntry );
2898 sf->getLeftFrame()->getObjectBrowser()->setShowValueColumn( showValue );
2899 sf->getLeftFrame()->getObjectBrowser()->setEnableChronoSort( showCHRONO_SORT );
2900 // sf->getLeftFrame()->getObjectBrowser()->setShowIAPP( showIAPP ); // this is done by below updateObjBrowser() call
2902 study->updateObjBrowser(true);
2907 void QAD_Desktop::onViewerTrihedron()
2909 QString Size = QAD_CONFIG->getSetting("Viewer:TrihedronSize");
2912 SALOMEGUI_TrihedronSizeDlg *Dlg = new SALOMEGUI_TrihedronSizeDlg(this);
2913 if (!Size.isEmpty())
2914 Dlg->setTrihedronSize(Size.toInt());
2915 int r = Dlg->exec();
2916 dim = Dlg->getTrihedronSize();
2919 if (r == QDialog::Accepted) {
2920 QAD_CONFIG->addSetting("Viewer:TrihedronSize", dim);
2923 QList<QAD_Study>& studies = myActiveApp->getStudies();
2924 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
2925 int nbSf = study->getStudyFramesCount();
2926 for ( int i = 0; i < nbSf; i++ ) {
2927 study->getStudyFrame(i)->getRightFrame()->getViewFrame()->SetTrihedronSize(dim);
2934 void QAD_Desktop::onDirList()
2936 // getting dir list from settings
2937 QStringList dirList = QStringList::split(';', QAD_CONFIG->getSetting("FileDlg:QuickDirList"), false);
2938 QAD_DirListDlg* dlg = new QAD_DirListDlg(this);
2939 dlg->setPathList(dirList);
2940 if ( dlg->exec() == QDialog::Accepted) {
2941 dlg->getPathList(dirList);
2942 QAD_CONFIG->addSetting("FileDlg:QuickDirList", dirList.join(";"));
2947 void QAD_Desktop::onConsoleFontAction()
2949 // getting font from settings
2950 QString fntSet = QAD_CONFIG->getSetting("Viewer:ConsoleFont");
2951 QFont font = QAD_Tools::stringToFont( fntSet );
2953 font = QFontDialog::getFont( &bOk, font, this );
2955 fntSet = QAD_Tools::fontToString( font );
2956 QAD_CONFIG->addSetting("Viewer:ConsoleFont", fntSet );
2959 QList<QAD_Study>& studies = myActiveApp->getStudies();
2960 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
2961 int nbSf = study->getStudyFramesCount();
2962 for ( int i = 0; i < nbSf; i++ ) {
2963 study->getStudyFrame(i)->getRightFrame()->getPyEditor()->setFont( font );
2964 study->getStudyFrame(i)->getRightFrame()->getMessage()->setFont( font );
2971 void QAD_Desktop::onSavePref()
2973 QAD_CONFIG->createConfigFile(true);
2976 //VRV: T2.5 - add default viewer
2977 void QAD_Desktop::onDefaultViewer(QAction * theAction)
2979 int type = VIEW_TYPE_MAX;
2982 if (myStdActions.at(DefaultViewerOCCId) == theAction)
2984 else if (myStdActions.at(DefaultViewerVTKId) == theAction)
2986 else if (myStdActions.at(DefaultGraphSupervisorId) == theAction)
2987 type = VIEW_GRAPHSUPERV;
2988 else if (myStdActions.at(DefaultPlot2dId) == theAction)
2990 if ( type != VIEW_TYPE_MAX )
2991 QAD_CONFIG->addSetting( "Viewer:DefaultViewer", QString::number( type ) );
2993 //VRV: T2.5 - add default viewer
2995 void QAD_Desktop::onViewerOCC()
2997 QString BackgroundColorRed = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorRed");
2998 QString BackgroundColorGreen = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorGreen");
2999 QString BackgroundColorBlue = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorBlue");
3002 if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3003 color = QColor(BackgroundColorRed.toInt(),
3004 BackgroundColorGreen.toInt(),
3005 BackgroundColorBlue.toInt());
3007 color = QColor(35, 136, 145);
3009 QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3012 if ( myActiveApp ) {
3013 QList<QAD_Study>& studies = myActiveApp->getStudies();
3014 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3015 int nbSf = study->getStudyFramesCount();
3016 for ( int i = 0; i < nbSf; i++ ) {
3017 QAD_StudyFrame* sf = study->getStudyFrame(i);
3018 if ( sf->getTypeView() == VIEW_OCC ) {
3019 sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3024 QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorRed", c.red() );
3025 QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorGreen", c.green() );
3026 QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorBlue", c.blue() );
3030 void QAD_Desktop::onGraphSupervisor()
3032 QString BackgroundColorRed = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorRed");
3033 QString BackgroundColorGreen = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorGreen");
3034 QString BackgroundColorBlue = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorBlue");
3037 if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3038 color = QColor(BackgroundColorRed.toInt(),
3039 BackgroundColorGreen.toInt(),
3040 BackgroundColorBlue.toInt());
3042 color = QColor(35, 136, 145);
3044 QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3047 if ( myActiveApp ) {
3048 QList<QAD_Study>& studies = myActiveApp->getStudies();
3049 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3050 int nbSf = study->getStudyFramesCount();
3051 for ( int i = 0; i < nbSf; i++ ) {
3052 QAD_StudyFrame* sf = study->getStudyFrame(i);
3053 if ( sf->getTypeView() == VIEW_GRAPHSUPERV ) {
3054 sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3060 QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorRed", c.red() );
3061 QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorGreen", c.green() );
3062 QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorBlue", c.blue() );
3066 void QAD_Desktop::onViewerVTK()
3068 QString BackgroundColorRed = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorRed");
3069 QString BackgroundColorGreen = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorGreen");
3070 QString BackgroundColorBlue = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorBlue");
3073 if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3074 color = QColor(BackgroundColorRed.toInt(),
3075 BackgroundColorGreen.toInt(),
3076 BackgroundColorBlue.toInt());
3078 color = QColor(0, 0, 0);
3080 QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3083 if ( myActiveApp ) {
3084 QList<QAD_Study>& studies = myActiveApp->getStudies();
3085 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3086 int nbSf = study->getStudyFramesCount();
3087 for ( int i = 0; i < nbSf; i++ ) {
3088 QAD_StudyFrame* sf = study->getStudyFrame(i);
3089 if ( sf->getTypeView() == VIEW_VTK ) {
3090 sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3096 QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorRed", c.red() );
3097 QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorGreen", c.green() );
3098 QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorBlue", c.blue() );
3102 void QAD_Desktop::onPlot2d()
3105 if ( QAD_CONFIG->hasSetting( "Plot2d:Background" ) ) {
3106 QString bgString = QAD_CONFIG->getSetting( "Plot2d:Background" );
3107 QStringList bgData = QStringList::split( ":", bgString, true );
3108 int bgRed = 0, bgGreen = 0, bgBlue = 0;
3109 if ( bgData.count() > 0 ) bgRed = bgData[ 0 ].toInt();
3110 if ( bgData.count() > 1 ) bgGreen = bgData[ 1 ].toInt();
3111 if ( bgData.count() > 2 ) bgBlue = bgData[ 2 ].toInt();
3112 color = QColor( bgRed, bgGreen, bgBlue );
3115 color = QColor(0, 0, 0);
3118 color = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3120 if ( color.isValid() ) {
3121 if ( myActiveApp ) {
3122 QList<QAD_Study>& studies = myActiveApp->getStudies();
3123 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3124 int nbSf = study->getStudyFramesCount();
3125 for ( int i = 0; i < nbSf; i++ ) {
3126 QAD_StudyFrame* sf = study->getStudyFrame(i);
3127 if ( sf->getTypeView() == VIEW_PLOT2D ) {
3128 sf->getRightFrame()->getViewFrame()->setBackgroundColor( color );
3134 bgData.append( QString::number( color.red() ) );
3135 bgData.append( QString::number( color.green() ) );
3136 bgData.append( QString::number( color.blue() ) );
3137 QAD_CONFIG->addSetting( "Plot2d:Background", bgData.join( ":" ) );
3142 void QAD_Desktop::helpAbout()
3144 SALOMEGUI_AboutDlg* About = new SALOMEGUI_AboutDlg( QAD_Application::getDesktop(), tr("MEN_ABOUT"));
3150 void QAD_Desktop::helpSearch()
3155 void QAD_Desktop::helpContents()
3157 getHelpWindow()->contents();
3158 getHelpWindow()->show();
3159 getHelpWindow()->raise();
3160 getHelpWindow()->setActiveWindow();
3164 void QAD_Desktop::helpContext(const QString& source, const QString& context)
3166 getHelpWindow()->context(source, context);
3167 getHelpWindow()->show();
3168 getHelpWindow()->raise();
3169 getHelpWindow()->setActiveWindow();
3172 /* Preferences/MultiFile Save */
3173 void QAD_Desktop::onMultiFileSave()
3175 if ( myStdActions.at( PrefMultiFileSave )->isOn() )
3176 QAD_CONFIG->addSetting( "Desktop:MultiFileSave", "true");
3178 QAD_CONFIG->addSetting( "Desktop:MultiFileSave", "false");
3181 /*********************************************************************
3182 ** Class: AppSelectionDlg
3183 ** Descr: Dialog for the selection of the application when several
3184 ** applications exist in the desktop and new study creation
3185 ** is activated by user.
3187 **********************************************************************/
3189 \class Desktop_AppSelectionDlg QAD_Desktop.h
3190 \brief Dialog for the selection of the application when several
3191 applications exist in the desktop and new study creation
3192 is activated by user.
3197 Desktop_AppSelectionDlg::Desktop_AppSelectionDlg( QAD_Desktop* desktop,
3198 QList<QAD_Application>& apps ) :
3199 QDialog( desktop, 0, true ),
3203 QAD_ASSERT_DEBUG_ONLY ( desktop );
3204 setCaption( tr("INF_DESK_DOC_CREATE") );
3205 if ( desktop->icon() )
3206 setIcon( *desktop->icon() );
3208 QBoxLayout* mainLayout = new QVBoxLayout( this, 5 );
3210 /* Create selection buttons */
3211 QVButtonGroup* buttonGrp = new QVButtonGroup ( this );
3212 buttonGrp->setExclusive ( true );
3213 QBoxLayout* vLayout = new QVBoxLayout( mainLayout, 5 );
3214 vLayout->addWidget ( buttonGrp );
3216 /* Create selection button for available app */
3218 for ( QAD_Application* app = myApps.first(); app; app = myApps.next(), id++ )
3220 /* add radio button for application */
3221 buttonGrp->insert( new QRadioButton( app->getStudyDescription() +
3222 " (*." + app->getStudyExtension() + ")", buttonGrp ), id );
3225 /* make the first application selected */
3226 buttonGrp->setButton( 0 );
3228 /* listen to the selection */
3229 QAD_ASSERT ( connect ( buttonGrp, SIGNAL(clicked(int)), this, SLOT(onAppSelected(int)) ));
3231 /* Create OK/Cancel buttons
3233 QBoxLayout* hLayout = new QHBoxLayout( mainLayout, 5 );
3234 QPushButton* buttonOK = new QPushButton( tr("BUT_OK"), this );
3235 QPushButton* buttonCancel = new QPushButton( tr("BUT_CANCEL"), this );
3236 QPushButton* buttonHelp = new QPushButton( tr("BUT_HELP"), this );
3237 buttonOK->setDefault( true );
3239 hLayout->addStretch();
3240 hLayout->addWidget( buttonOK );
3241 hLayout->addWidget( buttonCancel );
3242 hLayout->addWidget( buttonHelp );
3244 /* connect buttons */
3245 QAD_ASSERT ( connect( buttonOK, SIGNAL(clicked()), this, SLOT(accept())) );
3246 QAD_ASSERT ( connect( buttonCancel, SIGNAL(clicked()), this, SLOT(reject())) );
3247 QAD_ASSERT ( connect( buttonHelp, SIGNAL(clicked()), this, SLOT(onHelp())) );
3249 /* disable resizing */
3250 setFixedSize( 0, 0 );
3251 setSizePolicy( QSizePolicy ( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
3254 Desktop_AppSelectionDlg::~Desktop_AppSelectionDlg()
3258 QAD_Application* Desktop_AppSelectionDlg::selectedApp() const
3260 return myApps.at( myAppId );
3263 void Desktop_AppSelectionDlg::resizeEvent( QResizeEvent* e )
3265 QAD_Tools::centerWidget( this, parentWidget() );
3271 void Desktop_AppSelectionDlg::onAppSelected( int id )
3276 void Desktop_AppSelectionDlg::onHelp()