1 // SALOME SALOMEGUI : implementation of desktop and GUI kernel
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : QAD_Desktop.cxx
25 // Author : Nicolas REJNERI
30 \class QAD_Desktop QAD_Desktop.h
31 \brief Main desktop of QAD-based application.
34 # include "Utils_ORB_INIT.hxx"
35 # include "Utils_SINGLETON.hxx"
37 #define INCLUDE_MENUITEM_DEF
41 #include "QAD_Tools.h"
42 #include "QAD_Desktop.h"
43 #include "QAD_LeftFrame.h"
44 #include "QAD_RightFrame.h"
45 #include "QAD_Operation.h"
46 #include "QAD_XmlHandler.h"
47 #include "QAD_MessageBox.h"
48 #include "QAD_Application.h"
49 #include "QAD_Settings.h"
50 #include "QAD_Config.h"
51 #include "QAD_ObjectBrowser.h"
52 #include "QAD_Resource.h"
53 #include "QAD_FileDlg.h"
54 #include "QAD_HelpWindow.h"
55 #include "QAD_DirListDlg.h"
56 #include "QAD_WaitCursor.h"
57 #include "SALOMEGUI_OpenWith.h"
58 #include "SALOMEGUI_StudyPropertiesDlg.h"
59 #include "SALOMEGUI_TrihedronSizeDlg.h"
60 #include "SALOMEGUI_LoadStudiesDlg.h"
61 #include "SALOME_Selection.h"
62 #include "SALOME_InteractiveObject.hxx"
63 #include "SALOME_ListIteratorOfListIO.hxx"
64 #include "SALOMEGUI_AboutDlg.h"
65 #include "SALOMEGUI_ViewChoiceDlg.h"
66 #include "utilities.h"
68 #include "SALOMEGUI_CloseDlg.h"
73 #include <qmessagebox.h>
74 #include <qcolordialog.h>
75 #include <qradiobutton.h>
76 #include <qapplication.h>
77 #include <qvbuttongroup.h>
79 #include <qmessagebox.h>
82 #include <qpopupmenu.h>
83 #include <qlistview.h>
87 #include <qfontdialog.h>
88 #include <qlineedit.h>
89 #include <qdatetime.h>
96 // Open CASCADE Includes
97 #include <OSD_LoadMode.hxx>
98 #include <OSD_Function.hxx>
99 #include <TCollection_AsciiString.hxx>
106 QAD_ResourceMgr* QAD_Desktop::resourceMgr = 0;
107 QPalette* QAD_Desktop::palette = 0;
111 Creates the resource manager [ static ]
113 QAD_ResourceMgr* QAD_Desktop::createResourceManager()
116 resourceMgr = new QAD_ResourceMgr;
121 Returns the resource manager [ static ]
123 QAD_ResourceMgr* QAD_Desktop::getResourceManager()
130 Loads the palette from settings [ static ]
132 QPalette* QAD_Desktop::createPalette()
135 palette = new QPalette();
141 Returns the palette [ static ]
143 QPalette* QAD_Desktop::getPalette()
149 Gets window ratio width/heght [ static ]
151 static double myWindowRatio = 1;
152 static double getWindowRatio()
154 return myWindowRatio;
158 Sets window ratio width/heght [ static ]
160 static void setWindowRatio(double aRatio)
162 myWindowRatio = aRatio;
168 QAD_Desktop::QAD_Desktop(SALOME_NamingService* name_service) :
169 QMainWindow(0, 0, WType_TopLevel | WDestructiveClose),
176 myDefaultTitle( tr("DESK_DEFAULTTITLE") ),
179 /* Force reading of user config file */
180 QAD_CONFIG->readConfigFile();
182 /* menubar and status bar */
183 myStatusBar = statusBar();
184 myMainMenu = menuBar();
186 myNameService = name_service;
188 /* default background icon */
189 QPixmap backgroundicon ( QAD_Desktop::getResourceManager()->loadPixmap( "CLIENT",
190 tr("ICON_DESK_BACKGROUNDICON") ));
191 //myToolBarAction.setAutoDelete( true );
193 /* default icon and title */
194 QPixmap icon ( QAD_Desktop::getResourceManager()->loadPixmap( "CLIENT",
195 tr("ICON_DESK_DEFAULTICON") ));
196 if ( !icon.isNull() ) {
197 myDefaultIcon = icon;
198 setIcon( myDefaultIcon );
200 setCaption( myDefaultTitle );
202 /* set size as 1/2 of the screen and center it */
203 QWidget* d = QApplication::desktop();
204 resize( 2*d->width()/3, 2*d->height()/3 );
205 QAD_Tools::centerWidget( this, d );
207 /* workspace will manage child frames */
208 QHBox* border = new QHBox ( this );
209 border->setFrameStyle ( QFrame::Panel | QFrame::Sunken );
210 setCentralWidget( border );
211 myWorkspace = new QWorkspaceP( border );
213 QPalette pal = QAD_Application::getPalette();
215 QColorGroup cgA = pal.active();
216 QColorGroup cgI = pal.inactive();
217 QColorGroup cgD = pal.disabled();
218 cgA.setColor( QColorGroup::Background, QColor(192, 192, 192));
219 cgI.setColor( QColorGroup::Background, QColor(192, 192, 192));
220 cgD.setColor( QColorGroup::Background, QColor(192, 192, 192));
221 pal.setActive ( cgA );
222 pal.setInactive( cgI );
223 pal.setDisabled( cgD );
224 myWorkspace->setPalette( pal );
225 if ( !backgroundicon.isNull() ) {
226 MESSAGE("!!!DESKTOP background icon found!!!");
227 myWorkspace->setPaletteBackgroundPixmap(backgroundicon);
230 /* define standard file commands */
233 /* define operator menus for xml */
234 myOperatorMenus = new QAD_OperatorMenus(this);
235 myXmlHandler = new QAD_XmlHandler();
238 CORBA::Object_var objVarN = myNameService->Resolve("/Kernel/ModulCatalog");
239 myCatalogue = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
241 SALOME_ModuleCatalog::ListOfIAPP_Affich_var list_composants =
242 myCatalogue->GetComponentIconeList();
245 QToolBar* tbComponent = new QToolBar( tr("MEN_DESK_COMPONENTTOOLBAR"), this );
246 tbComponent->setCloseMode( QDockWindow::Undocked );
247 addToolBar(tbComponent, tr("MEN_DESK_COMPONENTTOOLBAR"), Bottom, TRUE );
248 setDockEnabled( tbComponent, DockLeft, false );
249 setDockEnabled( tbComponent, DockRight, false );
251 myCombo = new QComboBox( FALSE, tbComponent, "comboBox" );
252 myCombo->setFocusPolicy( NoFocus );
254 tbComponent->addSeparator();
256 // PG : add ResourceManager to get function findFile !!
257 QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
259 for (unsigned int ind = 0; ind < list_composants->length();ind++) {
262 /* find component icon */
263 QString iconfile = strdup(list_composants[ind].moduleicone) ;
264 QString modulename = strdup(list_composants[ind].modulename) ;
265 resDir = resMgr->findFile(iconfile,modulename) ;
268 //resDir = QAD_Tools::addSlash(resDir) ;
269 //QPixmap Icone(resDir+iconfile) ;
270 QPixmap Icone( QAD_Tools::addSlash( resDir ) + iconfile );
271 QToolButton * toolb =
272 new QToolButton( QIconSet( Icone ), modulename, QString::null, this,
273 SLOT( onButtonActiveComponent () ),tbComponent );
274 toolb->setToggleButton( true );
275 myComponentButton.append(toolb);
279 QString errMsg = tr("INF_ICON_RESOURCES").arg(iconfile).arg(modulename) +
281 //QMessageBox::warning( this, tr("WRN_WARNING"), errMsg, tr ("BUT_OK") );
284 if ( !QString(list_composants[ind].modulename).isEmpty() )
285 myCombo->insertItem( strdup(list_composants[ind].modulename) );
289 myCombo->adjustSize();
290 connect( myCombo, SIGNAL(activated(const QString&)),
291 this, SLOT( onComboActiveComponent(const QString&) ) );
293 /* new LifeCycleCORBA client, for Engines */
294 myEnginesLifeCycle = new SALOME_LifeCycleCORBA(name_service);
296 /* VSR 13/01/03 : installing global event filter for the application */
297 qApp->installEventFilter( this );
299 /* init pseudo random numbers generator */
300 QTime cTime = QTime::currentTime();
301 int secs = cTime.second() + 1;
302 for ( int s = 0; s < secs; s++ ) random();
308 QAD_Desktop::~QAD_Desktop ()
310 qApp->removeEventFilter( this );
314 myObjBrowserPopup.clear();
315 //VRV: T2.5 - add default viewer
316 myDefaultViewer.clear();
317 //VRV: T2.5 - add default viewer
318 myViewerPopup.clear();
320 myNewViewPopup.clear();
322 myToolsPopup.clear();
324 myStdActions.clear();
326 myToolBarsPopup.clear();
327 myToolBarAction.clear();
331 myHelpWindow->close();
333 QAD_Application::desktop = 0;
336 const int IdCut = 1001;
337 const int IdCopy = 1002;
338 const int IdPaste = 1003;
339 const int IdSelectAll = 1004;
341 #include <qkeysequence.h>
342 #define ACCEL_KEY(k) "\t" + QString(QKeySequence( Qt::CTRL | Qt::Key_ ## k ))
344 #define ACCEL_KEY(k) "\t" + QString("Ctrl+" #k)
346 #include <qclipboard.h>
348 Global event filter for qapplication (VSR 13/01/03)
350 bool QAD_Desktop::eventFilter( QObject* o, QEvent* e )
352 if ( e->type() == QEvent::ContextMenu ) {
353 QContextMenuEvent* ce = (QContextMenuEvent*)e;
354 if ( o->inherits("QRenameEdit") ) {
357 else if ( o->inherits("QLineEdit") ) {
358 QLineEdit* le = (QLineEdit*)o;
359 if ( le->parentWidget() ) {
360 if ( ( le->parentWidget()->inherits("QSpinBox") ||
361 le->parentWidget()->inherits("QSpinWidget") ||
362 le->parentWidget()->inherits("QAD_SpinBoxDbl") ) &&
364 QPopupMenu* popup = new QPopupMenu( 0, "qt_edit_menu" );
365 popup->insertItem( tr( "EDIT_CUT_CMD" ) + ACCEL_KEY( X ), IdCut );
366 popup->insertItem( tr( "EDIT_COPY_CMD" ) + ACCEL_KEY( C ), IdCopy );
367 popup->insertItem( tr( "EDIT_PASTE_CMD" ) + ACCEL_KEY( V ), IdPaste );
368 popup->insertSeparator();
369 #if defined(Q_WS_X11)
370 popup->insertItem( tr( "EDIT_SELECTALL_CMD" ), IdSelectAll );
372 popup->insertItem( tr( "EDIT_SELECTALL_CMD" ) + ACCEL_KEY( A ), IdSelectAll );
374 bool enableCut = !le->isReadOnly() && le->hasSelectedText();
375 popup->setItemEnabled( IdCut, enableCut );
376 popup->setItemEnabled( IdCopy, le->hasSelectedText() );
377 bool enablePaste = !le->isReadOnly() && !QApplication::clipboard()->text().isEmpty();
378 popup->setItemEnabled( IdPaste, enablePaste );
379 bool allSelected = (le->selectedText() == le->text() );
380 popup->setItemEnabled( IdSelectAll, (bool)(le->text().length()) && !allSelected );
382 QPoint pos = ce->reason() == QContextMenuEvent::Mouse ? ce->globalPos() :
383 le->mapToGlobal( QPoint(ce->pos().x(), 0) ) + QPoint( le->width() / 2, le->height() / 2 );
385 int r = popup->exec( pos );
407 return QMainWindow::eventFilter( o, e );
411 Creates and initializes the standard file operations
412 such as 'New/Open/Save/SaveAs/Close' and 'Help'.
414 void QAD_Desktop::createActions()
417 /* Used for string compare */
418 const QString& aTrueQString = "true" ;
420 /* create 'standard' toolbar */
421 if ( !myStdToolBar ) {
422 myStdToolBar = new QToolBar ( tr("MEN_DESK_VIEW_STDTOOLBAR"), this );
423 myStdToolBar->setCloseMode( QDockWindow::Undocked );
426 if ( !myMainMenu->count() ) {
427 /* Create main menu bar */
428 myMainMenu->insertItem ( tr("MEN_DESK_FILE"), &myFilePopup, 1 ); /* add popup FILE */
429 myMainMenu->insertItem ( tr("MEN_DESK_VIEW"), &myViewPopup, 2 ); /* add popup VIEW */
430 myMainMenu->insertItem ( tr("MEN_DESK_TOOLS"), &myToolsPopup, 5 ); /* add popup TOOLS */
431 myMainMenu->insertItem ( tr("MEN_DESK_PREF"), &myPrefPopup, 4 ); /* add popup PREF */
432 myMainMenu->insertItem ( tr("MEN_DESK_WINDOW"), &myWindowPopup, 6 ); /* add popup WINDOW */
433 myMainMenu->insertItem ( tr("MEN_DESK_HELP"), &myHelpPopup, 7 ); /* add popup HELP */
435 /* Applications will insert their items after 'File' 'Edit' and 'View'
436 ( 'Edit' will be inserted later )
441 /* insert logo picture to menu bar */
442 QHBox* aLogoFrm = new QHBox(this);
443 aLogoFrm->setFrameStyle( QFrame::Plain | QFrame::NoFrame );
444 QPixmap aLogoPixmap ( QAD_Desktop::getResourceManager()->loadPixmap( "CLIENT",
445 tr("ICON_DESK_LOGO") ));
446 QLabel* aLogoLab = new QLabel(aLogoFrm);
447 aLogoLab->setPixmap(aLogoPixmap);
448 aLogoLab->setAlignment(AlignCenter);
449 aLogoLab->setScaledContents(false);
450 myMainMenu->insertItem(aLogoFrm);
452 if ( myStdActions.isEmpty() ) {
453 /* Define standard actions. They should be inserted
454 into the list in order of their IDs.
459 QAD_ResourceMgr* rmgr = QAD_Desktop::getResourceManager();
460 QActionP* fileNewAction = new QActionP ( tr("TOT_DESK_FILE_NEW"),
461 rmgr->loadPixmap( "QAD", tr("ICON_FILE_NEW") ) ,
462 tr("MEN_DESK_FILE_NEW"), CTRL+Key_N, this );
463 fileNewAction->setStatusTip ( tr("PRP_DESK_FILE_NEW") );
464 fileNewAction->setEnabled ( true );
465 QAD_ASSERT ( connect( fileNewAction, SIGNAL( activated() ), this, SLOT( onNewStudy() )));
466 fileNewAction->addTo( myStdToolBar );
467 fileNewAction->addTo( &myFilePopup );
468 myStdActions.insert ( FileNewId, fileNewAction );
471 QActionP* fileOpenAction = new QActionP( tr("TOT_DESK_FILE_OPEN"), rmgr->loadPixmap( "QAD", tr("ICON_FILE_OPEN") ),
472 tr("MEN_DESK_FILE_OPEN"), CTRL+Key_O, this );
473 fileOpenAction->setStatusTip ( tr("PRP_DESK_FILE_OPEN") );
474 fileOpenAction->setEnabled ( true );
475 QAD_ASSERT ( connect( fileOpenAction, SIGNAL( activated() ), this, SLOT( onOpenStudy() )));
476 fileOpenAction->addTo( myStdToolBar );
477 fileOpenAction->addTo( &myFilePopup );
478 myStdActions.insert ( FileOpenId, fileOpenAction );
481 QActionP* fileLoadAction = new QActionP( tr("TOT_DESK_FILE_LOAD"), rmgr->loadPixmap( "QAD", tr("ICON_FILE_LOAD") ),
482 tr("MEN_DESK_FILE_LOAD"), CTRL+Key_L, this );
483 fileLoadAction->setStatusTip ( tr("PRP_DESK_FILE_LOAD") );
484 fileLoadAction->setEnabled ( true );
485 QAD_ASSERT ( connect( fileLoadAction, SIGNAL( activated() ), this, SLOT( onLoadStudy() )));
486 fileLoadAction->addTo( &myFilePopup );
487 myStdActions.insert ( FileLoadId, fileLoadAction );
490 QActionP* fileCloseAction = new QActionP( "", rmgr->loadPixmap( "QAD", tr("ICON_FILE_CLOSE") ),
491 tr("MEN_DESK_FILE_CLOSE"), CTRL+Key_W, this );
492 fileCloseAction->setStatusTip ( tr("PRP_DESK_FILE_CLOSE") );
493 QAD_ASSERT ( connect( fileCloseAction, SIGNAL( activated() ), this, SLOT( onCloseStudy() )));
494 fileCloseAction->addTo( &myFilePopup );
495 myStdActions.insert ( FileCloseId, fileCloseAction );
498 myFilePopup.insertSeparator();
501 QActionP* fileSaveAction = new QActionP( tr("TOT_DESK_FILE_SAVE"), rmgr->loadPixmap( "QAD", tr("ICON_FILE_SAVE") ),
502 tr("MEN_DESK_FILE_SAVE"), CTRL+Key_S, this );
503 fileSaveAction->setStatusTip ( tr("PRP_DESK_FILE_SAVE") );
504 QAD_ASSERT ( connect( fileSaveAction, SIGNAL( activated() ), this, SLOT( onSaveStudy() )));
505 fileSaveAction->addTo( myStdToolBar );
506 fileSaveAction->addTo( &myFilePopup );
507 myStdActions.insert ( FileSaveId, fileSaveAction );
510 QActionP* fileSaveAsAction = new QActionP( "", tr("MEN_DESK_FILE_SAVEAS"), 0, this );
511 fileSaveAsAction->setStatusTip ( tr("PRP_DESK_FILE_SAVEAS") );
512 QAD_ASSERT ( connect( fileSaveAsAction, SIGNAL( activated() ),
513 this, SLOT( onSaveAsStudy() )));
514 fileSaveAsAction->addTo( &myFilePopup );
515 myStdActions.insert ( FileSaveAsId, fileSaveAsAction );
519 myFilePopup.insertSeparator();
522 QActionP* filePropsAction = new QActionP( "", QPixmap(), tr("MEN_DESK_FILE_PROPERTIES"), 0, this );
523 filePropsAction->setStatusTip ( tr("PRP_DESK_FILE_PROPERTIES") );
524 filePropsAction->setEnabled(false);
525 QAD_ASSERT ( connect( filePropsAction, SIGNAL( activated() ), this, SLOT( onStudyProperties() )));
526 filePropsAction->addTo( &myFilePopup );
527 myStdActions.insert ( FilePropsId, filePropsAction );
530 int id = myFilePopup.insertSeparator();
531 /* keep the position from which an application will insert its items
532 to menu 'File' at the time of customization of the desktop */
534 myFilePos = myFilePopup.indexOf( id ) + 1;
536 /* exit application */
537 QActionP* exitAction = new QActionP( "", tr("MEN_DESK_FILE_EXIT"),
539 exitAction->setStatusTip ( tr("PRP_DESK_FILE_EXIT") );
540 QAD_ASSERT ( connect( exitAction, SIGNAL( activated() ),
541 this, SLOT( onExit() )));
542 exitAction->addTo( &myFilePopup );
543 myStdActions.insert ( FileExitId, exitAction );
545 /* 'Edit' actions : provided by application only */
549 /* toolbars popup menu */
550 myViewPopup.insertItem( tr("MEN_DESK_VIEW_TOOLBARS"), &myToolBarsPopup );
551 QAD_ASSERT( connect ( &myViewPopup, SIGNAL(aboutToShow()),
552 this, SLOT(onToolBarPopupAboutToShow()) ));
555 QActionP* viewStatusBarAction = new QActionP( "",
556 tr("MEN_DESK_VIEW_STATUSBAR"),
558 viewStatusBarAction->setStatusTip ( tr("PRP_DESK_VIEW_STATUSBAR") );
559 viewStatusBarAction->setOn( true );
560 QAD_ASSERT(connect( viewStatusBarAction, SIGNAL(activated()), this, SLOT(onViewStatusBar() )));
561 viewStatusBarAction->addTo( &myViewPopup );
562 myStdActions.insert( ViewStatusBarId, viewStatusBarAction );
564 // myViewPopup.insertItem( tr("MEN_DESK_SELECTION_MODE"), &mySelectionModePopup );
566 QActionP* SelectionPointAction = new QActionP( "", tr("MEN_DESK_SELECTION_POINT"), 0, this, 0, true );
567 QAD_ASSERT(connect( SelectionPointAction, SIGNAL(activated()), this, SLOT(onSelectionMode() )));
568 SelectionPointAction->addTo( &mySelectionModePopup );
569 myStdActions.insert( SelectionPointId, SelectionPointAction );
571 QActionP* SelectionEdgeAction = new QActionP( "", tr("MEN_DESK_SELECTION_EDGE"), 0, this, 0, true );
572 QAD_ASSERT(connect( SelectionEdgeAction, SIGNAL(activated()), this, SLOT(onSelectionMode() )));
573 SelectionEdgeAction->addTo( &mySelectionModePopup );
574 myStdActions.insert( SelectionEdgeId, SelectionEdgeAction );
576 QActionP* SelectionCellAction = new QActionP( "", tr("MEN_DESK_SELECTION_CELL"), 0, this, 0, true );
577 QAD_ASSERT(connect( SelectionCellAction, SIGNAL(activated()), this, SLOT(onSelectionMode() )));
578 SelectionCellAction->addTo( &mySelectionModePopup );
579 myStdActions.insert( SelectionCellId, SelectionCellAction );
581 QActionP* SelectionActorAction = new QActionP( "", tr("MEN_DESK_SELECTION_ACTOR"), 0, this, 0, true );
582 QAD_ASSERT(connect( SelectionActorAction, SIGNAL(activated()), this, SLOT(onSelectionMode() )));
583 SelectionActorAction->addTo( &mySelectionModePopup );
584 myStdActions.insert( SelectionActorId, SelectionActorAction );
585 SelectionActorAction->setOn(true);
587 myViewPos = myViewPopup.count();
590 QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
593 if(!resMgr->loadResources( "ToolsGUI", msg ))
595 //NRI QCString errMsg;
596 // errMsg.sprintf( "Do not load all resources for module ToolsGUI.\n" );
597 QMessageBox::warning( this, tr("WRN_WARNING"), msg, tr ("BUT_OK") );
601 myOperatorMenus = new QAD_OperatorMenus(this);
602 myXmlHandler = new QAD_XmlHandler();
603 ASSERT(myXmlHandler) ;
604 myXmlHandler->setMainWindow(this);
605 if ( myXmlHandler->setComponent( resMgr->resources( "ToolsGUI" ) ) ) {
606 QString language = resMgr->language( "ToolsGUI" );
607 QString ToolsXml = QString( "Tools_" ) + language + QString( ".xml" );
609 //ToolsXml = resMgr->resources("ToolsGUI") ;
610 //ToolsXml = QAD_Tools::addSlash(ToolsXml) ;
611 //ToolsXml = ToolsXml + "Tools_" + language + ".xml" ;
612 ToolsXml = QAD_Tools::addSlash( resMgr->findFile( ToolsXml, "ToolsGUI" ) ) + ToolsXml;
614 QFile file( QAD_Tools::unix2win( ToolsXml ) );
615 if ( file.exists() && file.open( IO_ReadOnly ) ) {
617 QXmlInputSource source( file );
618 QXmlSimpleReader reader;
619 reader.setContentHandler( myXmlHandler );
620 reader.setErrorHandler( myXmlHandler );
621 bool ok = reader.parse( source );
624 QMessageBox::critical( 0,
625 tr( "INF_PARSE_ERROR" ),
626 tr( myXmlHandler->errorProtocol() ) );
628 myMenusList=myXmlHandler->myMenusList;
629 myActiveMenus=myMenusList.at(0);
630 myOperatorMenus->showMenuBar(0);
631 myActiveMenus->showAllToolBars();
637 if ( myToolsPopup.count() == 0 ) {
638 myMainMenu->removeItem(5);
642 /* Viewer BackgroundColor */
643 myPrefPopup.insertItem( tr("MEN_DESK_PREF_VIEWER"), &myViewerPopup );
645 QActionP* viewerOCCAction = new QActionP( "", tr("MEN_DESK_PREF_VIEWER_OCC"), 0, this );
646 QAD_ASSERT(connect( viewerOCCAction, SIGNAL(activated()), this, SLOT(onViewerOCC() )));
647 viewerOCCAction->addTo( &myViewerPopup );
648 myStdActions.insert( PrefViewerOCCId, viewerOCCAction );
650 QActionP* viewerVTKAction = new QActionP( "", tr("MEN_DESK_PREF_VIEWER_VTK"), 0, this );
651 QAD_ASSERT(connect( viewerVTKAction, SIGNAL(activated()), this, SLOT(onViewerVTK() )));
652 viewerVTKAction->addTo( &myViewerPopup );
653 myStdActions.insert( PrefViewerVTKId, viewerVTKAction );
655 QActionP* graphSupervisorAction = new QActionP( "", tr("MEN_DESK_PREF_GRAPH_SUPERVISOR"), 0, this );
656 QAD_ASSERT(connect( graphSupervisorAction, SIGNAL(activated()), this, SLOT(onGraphSupervisor() )));
657 graphSupervisorAction->addTo( &myViewerPopup );
658 myStdActions.insert( PrefGraphSupervisorId, graphSupervisorAction );
660 QActionP* viewerPlot2dAction = new QActionP( "", tr("MEN_DESK_PREF_VIEWER_PLOT2D"), 0, this );
661 QAD_ASSERT(connect( viewerPlot2dAction, SIGNAL(activated()), this, SLOT(onPlot2d() )));
662 viewerPlot2dAction->addTo( &myViewerPopup );
663 myStdActions.insert( PrefViewerPlot2dId, viewerPlot2dAction );
665 //VRV: T2.5 - add default viewer
666 QString viewerValue = QAD_CONFIG->getSetting( "Viewer:DefaultViewer" );
668 int aViewerValue = viewerValue.toInt( &ok, 10 );
669 if (!ok || aViewerValue < VIEW_OCC || aViewerValue >= VIEW_TYPE_MAX)
670 aViewerValue = VIEW_VTK;
672 myPrefPopup.insertItem( tr("MEN_DESK_PREF_DEFAULT_VIEWER"), &myDefaultViewer );
673 QActionPGroup* myQAG = new QActionPGroup ( this);
674 QActionP* viewerOCCAction1 = new QActionP( "", tr("MEN_DESK_PREF_VIEWER_OCC"), 0, this );
675 viewerOCCAction1->setToggleAction ( true);
676 viewerOCCAction1->setOn ( aViewerValue == VIEW_OCC );
677 myQAG->insert( viewerOCCAction1 );
678 myStdActions.insert( DefaultViewerOCCId, viewerOCCAction1 );
680 QActionP* viewerVTKAction1 = new QActionP( "", tr("MEN_DESK_PREF_VIEWER_VTK"), 0, this );
681 viewerVTKAction1->setToggleAction ( true);
682 viewerVTKAction1->setOn ( aViewerValue == VIEW_VTK );
683 myQAG->insert( viewerVTKAction1 );
684 myStdActions.insert( DefaultViewerVTKId, viewerVTKAction1 );
686 /* Remove Supervisor viewer from setting the background */
687 // QActionP* graphSupervisorAction1 = new QActionP( "", tr("MEN_DESK_PREF_GRAPH_SUPERVISOR"), 0, this );
688 // graphSupervisorAction1->setToggleAction ( true);
689 // graphSupervisorAction1->setOn ( aViewerValue == VIEW_GRAPHSUPERV );
690 // myQAG->insert( graphSupervisorAction1 );
691 // myStdActions.insert( DefaultGraphSupervisorId, graphSupervisorAction1 );
693 QActionP* viewerPlot2dAction1 = new QActionP( "", tr("MEN_DESK_PREF_VIEWER_PLOT2D"), 0, this );
694 viewerPlot2dAction1->setToggleAction ( true);
695 viewerPlot2dAction1->setOn ( aViewerValue == VIEW_PLOT2D );
696 myQAG->insert( viewerPlot2dAction1 );
697 myStdActions.insert( DefaultPlot2dId, viewerPlot2dAction1 );
699 myQAG->addTo( &myDefaultViewer );
700 QAD_ASSERT(connect( myQAG, SIGNAL(selected(QActionP * )), this, SLOT(onDefaultViewer(QActionP *) )));
701 //VRV: T2.5 - add default viewer
703 QActionP* viewerTrihedronAction = new QActionP( "", tr("MEN_DESK_PREF_VIEWER_TRIHEDRON"), 0, this );
704 QAD_ASSERT(connect( viewerTrihedronAction, SIGNAL(activated()), this, SLOT(onViewerTrihedron() )));
705 viewerTrihedronAction->addTo( &myPrefPopup );
706 myStdActions.insert( PrefViewerTrihedronId, viewerTrihedronAction );
708 QActionP* consoleFontAction = new QActionP( "", tr("MEN_DESK_PREF_CONSOLE_FONT"), 0, this );
709 QAD_ASSERT(connect( consoleFontAction, SIGNAL(activated()), this, SLOT(onConsoleFontAction() )));
710 consoleFontAction->addTo( &myPrefPopup );
711 myStdActions.insert( PrefConsoleFontId, consoleFontAction );
714 QActionP* multiFileSaveAction = new QActionP( "", tr("MEN_DESK_PREF_MULTI_FILE_SAVE"), 0, this, 0, true );
715 QAD_ASSERT(connect( multiFileSaveAction, SIGNAL(activated()), this, SLOT(onMultiFileSave() )));
716 multiFileSaveAction->setToggleAction( true );
717 QString MultiSave = QAD_CONFIG->getSetting("Desktop:MultiFileSave");
718 multiFileSaveAction->setOn( MultiSave.compare( aTrueQString ) == 0 );
719 multiFileSaveAction->addTo( &myPrefPopup );
720 myStdActions.insert( PrefMultiFileSave, multiFileSaveAction );
723 QActionP* ASCIISaveAction = new QActionP( "", tr("MEN_DESK_PREF_ASCII_SAVE"), 0, this, 0, true );
724 QAD_ASSERT(connect( ASCIISaveAction, SIGNAL(activated()), this, SLOT(onASCIISave() )));
725 ASCIISaveAction->setToggleAction( true );
726 QString ASCIISave = QAD_CONFIG->getSetting("Desktop:ASCIISave");
727 ASCIISaveAction->setOn( ASCIISave.compare( aTrueQString ) == 0 );
728 ASCIISaveAction->addTo( &myPrefPopup );
729 myStdActions.insert( PrefASCIISave, ASCIISaveAction );
731 myPrefPopup.insertSeparator();
734 myPrefPopup.insertItem( tr("MEN_DESK_PREF_OBJECTBROWSER"), &myObjBrowserPopup );
736 QActionP* objectBrowserEntryAction = new QActionP( "", tr("MEN_DESK_PREF_OBJECTBROWSER_ENTRY"), 0, this, 0, true );
737 QAD_ASSERT(connect( objectBrowserEntryAction, SIGNAL(activated()), this, SLOT(onObjectBrowser() )));
738 objectBrowserEntryAction->setToggleAction(true);
739 QString AddColumn = QAD_CONFIG->getSetting("ObjectBrowser:AddColumn");
741 if ( AddColumn.compare( aTrueQString ) == 0 )
742 objectBrowserEntryAction->setOn(true);
744 objectBrowserEntryAction->setOn(false);
746 objectBrowserEntryAction->addTo( &myObjBrowserPopup );
747 myStdActions.insert( PrefObjectBrowserEntryId, objectBrowserEntryAction );
749 QActionP* objectBrowserValueAction = new QActionP( "", tr("MEN_DESK_PREF_OBJECTBROWSER_VALUE"), 0, this, 0, true );
750 QAD_ASSERT(connect( objectBrowserValueAction, SIGNAL(activated()), this, SLOT(onObjectBrowser() )));
751 objectBrowserValueAction->setToggleAction(true);
752 QString ValueColumn = QAD_CONFIG->getSetting("ObjectBrowser:ValueColumn");
754 if ( ValueColumn.compare( aTrueQString ) == 0 )
755 objectBrowserValueAction->setOn(true);
757 objectBrowserValueAction->setOn(false);
759 objectBrowserValueAction->addTo( &myObjBrowserPopup );
760 myStdActions.insert( PrefObjectBrowserValueId, objectBrowserValueAction );
762 QActionP* objectBrowserIAPPAction = new QActionP( "", tr("MEN_DESK_PREF_OBJECTBROWSER_IAPP"), 0, this, 0, true );
763 QAD_ASSERT(connect( objectBrowserIAPPAction, SIGNAL(activated()), this, SLOT(onObjectBrowser() )));
764 objectBrowserIAPPAction->setToggleAction(true);
765 QString showIAPP = QAD_CONFIG->getSetting("ObjectBrowser:IAPP");
767 if ( showIAPP.compare( aTrueQString ) == 0 )
768 objectBrowserIAPPAction->setOn(true);
770 objectBrowserIAPPAction->setOn(false);
772 objectBrowserIAPPAction->addTo( &myObjBrowserPopup );
773 myStdActions.insert( PrefObjectBrowserIAPPId, objectBrowserIAPPAction );
775 /* Chronological sorting of shapes on the entry creation */
776 QActionP* objectBrowserCHRONO_SORTAction = new QActionP( "", tr("MEN_DESK_PREF_OBJECTBROWSER_CHRONO_SORT"), 0, this, 0, true );
777 QAD_ASSERT(connect( objectBrowserCHRONO_SORTAction, SIGNAL(activated()), this, SLOT(onObjectBrowser() )));
778 objectBrowserCHRONO_SORTAction->setToggleAction(true);
779 QString showSORT = QAD_CONFIG->getSetting("ObjectBrowser:CHRONO_SORT");
781 if ( showSORT.compare( aTrueQString ) == 0 )
782 objectBrowserCHRONO_SORTAction->setOn(true) ;
784 objectBrowserCHRONO_SORTAction->setOn(false) ;
786 objectBrowserCHRONO_SORTAction->addTo( &myObjBrowserPopup );
787 myStdActions.insert( PrefObjectBrowserCHRONO_SORTId, objectBrowserCHRONO_SORTAction ) ;
789 myPrefPopup.insertSeparator();
791 QActionP* dirAction = new QActionP( "", tr("MEN_DESK_PREF_DIRICTORIES"), ALT+Key_D, this );
792 QAD_ASSERT(connect( dirAction, SIGNAL(activated()), this, SLOT(onDirList() )));
793 dirAction->addTo( &myPrefPopup );
794 myStdActions.insert( PrefDirsId, dirAction );
796 myPrefPopup.insertSeparator();
798 QActionP* saveAction = new QActionP( "", tr("MEN_DESK_PREF_SAVE"), 0, this );
799 QAD_ASSERT(connect( saveAction, SIGNAL(activated()), this, SLOT(onSavePref() )));
800 saveAction->addTo( &myPrefPopup );
801 myStdActions.insert( PrefSaveId, saveAction );
803 /* 'Window' actions */
806 myWindowPopup.insertItem( tr("MEN_DESK_WINDOW_NEW3D"), &myNewViewPopup, WindowNew3dId );
808 QActionP* viewOCCAction = new QActionP( "", tr("MEN_DESK_VIEW_OCC"), ALT+Key_O, this );
809 QAD_ASSERT(connect( viewOCCAction, SIGNAL(activated()), this, SLOT(onNewWindow3d() )));
810 viewOCCAction->addTo( &myNewViewPopup );
811 myStdActions.insert( ViewOCCId, viewOCCAction );
813 QActionP* viewVTKAction = new QActionP( "", tr("MEN_DESK_VIEW_VTK"), ALT+Key_K, this );
814 QAD_ASSERT(connect( viewVTKAction, SIGNAL(activated()), this, SLOT(onNewWindow3d() )));
815 viewVTKAction->addTo( &myNewViewPopup );
816 myStdActions.insert( ViewVTKId, viewVTKAction );
818 QActionP* viewPlot2dAction = new QActionP( "", tr("MEN_DESK_VIEW_PLOT2D"), ALT+Key_P, this );
819 QAD_ASSERT(connect( viewPlot2dAction, SIGNAL(activated()), this, SLOT(onNewWindow3d() )));
820 viewPlot2dAction->addTo( &myNewViewPopup );
821 myStdActions.insert( ViewPlot2dId, viewPlot2dAction );
823 // QActionP* windowNew3dAction = new QActionP( "",/* rmgr->loadPixmap( "QAD", tr("ICON_DESK_WINDOW_NEW3D") ), */
824 /*tr("MEN_DESK_WINDOW_NEW3D"), 0, this );
825 windowNew3dAction->addTo( &myWindowPopup );
826 QAD_ASSERT( connect( windowNew3dAction, SIGNAL(activated()), this ,
827 SLOT( onNewWindow3d() )));
828 myStdActions.insert( WindowNew3dId, windowNew3dAction );
834 QActionP* windowCascadeAction = new QActionP( "", rmgr->loadPixmap( "QAD", tr("ICON_DESK_WINDOW_CASCADE") ),
835 tr("MEN_DESK_WINDOW_CASCADE"), 0, this );
836 windowCascadeAction->setStatusTip ( tr("PRP_DESK_WINDOW_CASCADE") );
837 QAD_ASSERT( connect( windowCascadeAction, SIGNAL(activated()), this,
838 SLOT( onCascade() )));
839 myStdActions.insert( WindowCascadeId, windowCascadeAction );
842 QActionP* windowTileAction = new QActionP( "", rmgr->loadPixmap( "QAD", tr("ICON_DESK_WINDOW_TILE") ),
843 tr("MEN_DESK_WINDOW_TILE"), 0, this );
844 windowTileAction->setStatusTip ( tr("PRP_DESK_WINDOW_TILE") );
845 QAD_ASSERT( connect( windowTileAction, SIGNAL(activated()), myWorkspace, SLOT( tile() )));
846 myStdActions.insert( WindowTileId, windowTileAction );
848 QAD_ASSERT( connect ( &myWindowPopup, SIGNAL(aboutToShow()),
849 this, SLOT(onWindowPopupAboutToShow()) ));
853 QActionP* helpContentsAction = new QActionP( "", tr("MEN_DESK_HELP_CONTENTS"), Key_F1, this );
854 helpContentsAction->setStatusTip ( tr("PRP_DESK_HELP_CONTENTS") );
855 QAD_ASSERT(connect( helpContentsAction, SIGNAL(activated()),
856 this, SLOT( onHelpContents() )));
857 helpContentsAction->addTo( &myHelpPopup );
858 myStdActions.insert( HelpContentsId , helpContentsAction );
861 // QActionP* helpSearchAction = new QActionP( "", tr("MEN_DESK_HELP_SEARCH"), 0, this );
862 // helpSearchAction->setStatusTip ( tr("PRP_DESK_HELP_SEARCH") );
863 // QAD_ASSERT( connect( helpSearchAction, SIGNAL(activated()), this, SLOT( onHelpSearch() )));
864 // helpSearchAction->addTo( &myHelpPopup );
865 // myStdActions.insert( HelpSearchId, helpSearchAction );
868 // QActionP* helpWhatsThisAction = new QActionP( "", tr("MEN_DESK_HELP_WHATSTHIS"), SHIFT+Key_F1, this );
869 // helpWhatsThisAction->setStatusTip ( tr("PRP_DESK_HELP_WHATSTHIS" ));
870 // QAD_ASSERT( connect( helpWhatsThisAction, SIGNAL(activated()), this, SLOT( whatsThis() )));
871 // helpWhatsThisAction->addTo( &myHelpPopup );
872 // myStdActions.insert( HelpWhatsThisId, helpWhatsThisAction );
873 // (void)QWhatsThis::whatsThisButton( myStdToolBar );
875 id = myHelpPopup.insertSeparator();
876 myHelpPos = myHelpPopup.indexOf( id );
879 QActionP* helpAboutAction = new QActionP( "", tr("MEN_DESK_HELP_ABOUT"), 0, this );
880 helpAboutAction->setStatusTip ( tr("PRP_DESK_HELP_ABOUT") );
881 QAD_ASSERT( connect( helpAboutAction, SIGNAL(activated()), this, SLOT( onHelpAbout() )));
882 helpAboutAction->addTo( &myHelpPopup );
883 myStdActions.insert(HelpAboutId, helpAboutAction );
889 Adds the given application into the list of supported applications
891 void QAD_Desktop::addApplication(QAD_Application* app)
893 /* add only if is not already in the list */
894 if ( myApps.findRef( app ) == -1 )
896 myApps.append( app );
898 /* set activation/deactivation listener */
899 QAD_ASSERT ( connect( app, SIGNAL(appActivated(QAD_Application*)),
900 this, SLOT(onActivateApp(QAD_Application*))) );
902 QAD_ASSERT ( connect( app, SIGNAL(appDeactivated(QAD_Application*)),
903 this, SLOT(onDeactivateApp(QAD_Application*))) );
908 Displays the control panel of the application.
909 This function is called when the desktop is shown first time.
911 void QAD_Desktop::showDesktop()
917 Closes Desktop. If <forceClose> is true query for exit will be skipped.
919 void QAD_Desktop::closeDesktop( bool forceClose )
922 myQueryClose = false;
927 Puts the message to the status bar
929 void QAD_Desktop::putInfo ( const QString& msg )
932 //NRI : bug 1209. message is now displayed during 3000 ms
933 myStatusBar->message ( msg, 3000 );
937 Puts the message to the status bar for ms milli-seconds
939 void QAD_Desktop::putInfo ( const QString& msg, int ms )
942 myStatusBar->message ( msg, ms );
946 Returns the standard toolbar
948 QMenuBar* QAD_Desktop::getMainMenuBar() const
954 Returns the standard toolbar
956 QToolBar* QAD_Desktop::getStdToolBar() const
962 Updates desktop panel (menu, toolbar and status bar) according to current state of
963 the application. Calls update() for the active application.
964 The command { UD_ADD_APP or UD_REMOVE_APP ) specifies the desktop components
965 will be changed according to new active application.
966 This function is called after activating new study, closing current study etc.
968 void QAD_Desktop::updateDesktop( UpdateCommand cmd )
971 updateToolBars( cmd );
972 updateStatusBar( cmd );
977 Updates the desktop caption
979 void QAD_Desktop::updateCaption( UpdateCommand cmd )
981 if ( cmd == ActivateApp )
982 { /* application's icon and title */
983 setIcon( myActiveApp->getApplicationIcon() );
984 setCaption( myActiveApp->getApplicationName() );
987 { /* default icon and title */
988 setIcon( myDefaultIcon );
989 setCaption( myDefaultTitle );
994 Updates status bar when a new application becomes current
996 void QAD_Desktop::updateStatusBar( UpdateCommand cmd )
1000 bool activate = ( cmd == ActivateApp );
1001 myActiveApp->updateStatusBar ( myStatusBar, activate );
1006 Updates toolbars according to current active application.
1007 This function is called from updateDesktop().
1009 void QAD_Desktop::updateToolBars( UpdateCommand cmd )
1013 bool activate = ( cmd == ActivateApp );
1014 myActiveApp->updateToolBars ( activate );
1019 Updates main menu bar of the application when application is activated
1021 This function is called by updateDesktop()
1023 void QAD_Desktop::updateMenu( UpdateCommand cmd )
1027 bool activate = ( cmd == ActivateApp );
1028 myActiveApp->updateFilePopup( &myFilePopup, activate, myFilePos );
1029 myActiveApp->updateEditPopup( &myEditPopup, activate, myEditPos );
1030 myActiveApp->updateViewPopup( &myViewPopup, activate, myViewPos );
1031 myActiveApp->updateHelpPopup( &myHelpPopup, activate, myHelpPos );
1032 myActiveApp->updateMainMenu( myMainMenu, activate, myMainMenuPos );
1035 Since 'Edit' popup is completely customized by applications
1036 desktop doesn't show it in main menubar without the active
1037 application and we insert/remove this popup from the menubar
1038 when activating/deactivating applications.
1040 We can't have 'Edit' popup be customized by an application
1041 via UpdateMainMenu() method because applications may insert
1042 its items to the menubar only AFTER 'View' item ( this fact
1043 is respected by myMainMenuPos ) and the possibility of an
1044 application to add its items into any arbitrary positions of
1045 the main menubar requires a bit sophisticated implementation,
1046 so we decided to avoid it, sorry :-(.
1048 #if defined( DEBUG )
1050 /* applications MUST clear 'Edit' after themselves */
1051 QAD_ASSERT_DEBUG_ONLY( !myEditPopup.count() );
1054 if ( activate ) /* insert after 'File' item */
1055 myMainMenu->insertItem( tr("MEN_DESK_EDIT"), &myEditPopup, 3, 1 );
1057 myMainMenu->removeItem( 3 );
1062 Returns icon file name used by the application
1064 const QPixmap& QAD_Desktop::getDefaultIcon() const
1066 static QPixmap defaultPixmap( QAD_Desktop::getResourceManager()->loadPixmap( "QAD",
1067 tr("ICON_DESK_DEFAULTICON") ));
1068 return defaultPixmap;
1072 Returns name of the application used as the title of desktop panel
1074 const QString& QAD_Desktop::getDefaultTitle() const
1076 static QString defaultTitle ( tr("DESK_DEFAULTTITLE") );
1077 return defaultTitle;
1081 Returns default name of new studies
1083 const QString& QAD_Desktop::getDefaultStudyName() const
1085 static QString defaultStudyName( tr("DESK_DEFAULTDOC") );
1086 return defaultStudyName;
1090 Returns next name for new study
1092 QString QAD_Desktop::getNewStudyName()
1095 number.sprintf( "%d", ++myCntUntitled );
1096 return ( getDefaultStudyName() + number );
1100 Searches QAD_Study corresponding to <study>, returns NULL if fails
1102 QAD_Study* QAD_Desktop::findStudy( SALOMEDS::Study_ptr theStudy )
1104 for ( QAD_Application* app = myApps.first(); app; app = myApps.next() ) {
1105 QList<QAD_Study> studies;
1106 studies.setAutoDelete( false );
1107 studies = app->getStudies();
1108 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
1109 if ( study->getStudyDocument()->_is_equivalent( theStudy ) )
1117 Returns current active application
1119 QAD_Application* QAD_Desktop::getActiveApp() const
1125 Returns current active study
1127 QAD_Study* QAD_Desktop::getActiveStudy() const
1129 return myActiveStudy;
1135 QWorkspaceP* QAD_Desktop::getMainFrame() const
1141 Find or load Engine, given a container name and an engine name
1143 Engines::Component_var QAD_Desktop::getEngine(const char *containerName,
1144 const char *componentName)
1146 Engines::Component_var eng =
1147 myEnginesLifeCycle->FindOrLoad_Component(containerName,
1153 gets application Help Window (and creates if necessary)
1155 QAD_HelpWindow* QAD_Desktop::getHelpWindow()
1157 if (!myHelpWindow) {
1158 myHelpWindow = new QAD_HelpWindow();
1159 connect(myHelpWindow, SIGNAL(helpWindowClosed()), this, SLOT(onHelpWindowClosed()));
1161 return myHelpWindow;
1165 Called when desktop is closing
1167 void QAD_Desktop::closeEvent ( QCloseEvent* e )
1169 bool doClose = true;
1170 if ( myQueryClose ) {
1171 doClose = QAD_MessageBox::info2 ( this, tr("INF_DESK_EXIT"),
1172 tr("QUE_DESK_EXIT"), tr ("BUT_OK"),
1173 tr ("BUT_CANCEL"), QAD_YES,
1174 QAD_NO, QAD_NO ) == QAD_YES;
1178 for ( QAD_Application* app = myApps.first(); app; app = myApps.next() ) {
1179 QList<QAD_Study>& studies = app->getStudies();
1180 for(QAD_Study* study = studies.first(); study != 0; study = studies.next()) {
1181 if(myQueryClose && study->getStudyDocument()->IsModified()) {
1182 SALOMEGUI_CloseDlg aDlg( this );
1183 switch ( aDlg.exec() ) {
1185 if ( !onSaveStudy( study ) ) {
1186 putInfo( tr("INF_CANCELLED") );
1197 putInfo( tr("INF_CANCELLED") );
1205 myQueryClose = true;
1206 doClose ? e->accept() : e->ignore();
1210 Called when desktop is resized
1212 void QAD_Desktop::resizeEvent( QResizeEvent* e )
1214 QMainWindow::resizeEvent( e );
1215 myWorkspace->setGeometry( 1,1, centralWidget()->width()-2,
1216 centralWidget()->height()-2 );
1221 Terminates the application.
1223 void QAD_Desktop::onExit()
1228 /************************************************************************
1230 *************************************************************************/
1234 If several application are supported it displays dialog window
1235 to choose type of study.
1237 void QAD_Desktop::createStudy(){
1240 void QAD_Desktop::onNewStudy()
1242 unsigned numApps = myApps.count();
1245 onNewStudy ( myApps.at(0) );
1246 else { /* select the type of application for new study */
1247 Desktop_AppSelectionDlg selDlg( this, myApps );
1248 if ( selDlg.exec() == QDialog::Accepted ) {
1249 onNewStudy ( selDlg.selectedApp() );
1252 } else { /* no applications available in desktop */
1253 QAD_MessageBox::error1( this,
1255 tr("ERR_APP_NOAPP"),
1261 Creates new study for the given application.
1262 Calls the respective function of the application class.
1264 void QAD_Desktop::onNewStudy( QAD_Application* app )
1268 /* create new study of the specific app */
1269 putInfo ( tr ("INF_DOC_CREATING") );
1270 QAD_Study* newStudy = app->newStudy();
1273 /* can't create new study */
1274 QAD_MessageBox::error1( this, tr("ERR_ERROR"),
1275 tr("ERR_DOC_CANTCREATE"),
1278 putInfo ( tr("INF_READY") );
1282 Loads the existing study.
1284 void QAD_Desktop::onLoadStudy()
1286 QString name, studyname, ext;
1288 SALOMEGUI_LoadStudiesDlg* aDlg = new SALOMEGUI_LoadStudiesDlg( this, "Load Study", TRUE);
1290 CORBA::Object_var obj = myNameService->Resolve("/myStudyManager");
1291 SALOMEDS::StudyManager_var myStudyMgr = SALOMEDS::StudyManager::_narrow(obj);
1292 ASSERT(! CORBA::is_nil(myStudyMgr));
1293 SALOMEDS::ListOfOpenStudies_var List = myStudyMgr->GetOpenStudies();
1294 for (unsigned int ind = 0; ind < List->length();ind++) {
1295 studyname = List[ind];
1296 aDlg->ListComponent->insertItem( studyname );
1299 int retVal = aDlg->exec();
1300 studyname = aDlg->ListComponent->currentText();
1302 if (retVal == QDialog::Rejected)
1305 if ( studyname.isNull() || studyname.isEmpty() )
1309 name.replace( QRegExp(":"), "/" );
1312 Try to associate an application to the opened study.
1313 Assumed that the association study<->application is unique.
1315 bool appFound = false;
1316 putInfo ( tr("INF_DOC_OPENING") + " " + name );
1317 for ( QAD_Application* app = myApps.first(); app; app = myApps.next() )
1319 /* application found */
1320 if ( app->isStudyOpened( name ) )
1322 /* already opened: prompt for reopen */
1323 if ( QAD_MessageBox::warn2 ( this, tr("WRN_WARNING"),
1324 tr("QUE_DOC_ALREADYOPEN").arg( name ),
1325 tr ("BUT_YES"), tr ("BUT_NO"), QAD_YES, QAD_NO,
1326 QAD_NO ) == QAD_NO )
1328 putInfo ( tr("INF_READY") );
1331 /* now the study is closed to be re-opened */
1332 //don't ask user to remove study permanently
1333 if (app->getStudyByName ( name ) != NULL)
1334 onCloseStudy ( app->getStudyByName ( name ), false );
1335 else if (app->getStudyByName ( QAD_Tools::getFileNameFromPath( name, false )) != NULL)
1336 onCloseStudy ( app->getStudyByName ( QAD_Tools::getFileNameFromPath( name, false )), false );
1340 /* open the study */
1341 QAD_Study* openStudy = app->loadStudy( studyname );
1343 QAD_MessageBox::error1( this,
1345 tr("ERR_DOC_CANTOPEN") + "\n" + name,
1352 QAD_MessageBox::error1( this,
1354 tr("ERR_DOC_UNKNOWNTYPE"),
1357 putInfo ( tr("INF_READY") );
1362 QAD_Study* QAD_Desktop::loadStudy(QString theStudyName) {
1363 QString studyname("");
1365 CORBA::Object_var obj = myNameService->Resolve("/myStudyManager");
1366 SALOMEDS::StudyManager_var myStudyMgr = SALOMEDS::StudyManager::_narrow(obj);
1367 ASSERT(! CORBA::is_nil(myStudyMgr));
1369 SALOMEDS::ListOfOpenStudies_var List = myStudyMgr->GetOpenStudies();
1370 for (unsigned int ind = 0; ind < List->length();ind++) {
1371 if (theStudyName == QString(List[ind])) {
1372 studyname = theStudyName;
1376 if (studyname == "") {
1379 bool appFound = false;
1380 for ( QAD_Application* app = myApps.first(); app; app = myApps.next() ) {
1382 QAD_Study* openStudy = app->loadStudy( studyname );
1384 // if (myActiveApp == 0)
1385 //myActiveApp = app;
1395 Opens the existing study.
1396 Displays select file dialog and calls corresponding function of
1398 (application is defined according to extension of selected file).
1400 void QAD_Desktop::onOpenStudy()
1404 /* Select a file to open */
1405 name = selectFileName ( true );
1406 if ( name.isNull() || name.isEmpty() )
1409 // Workaround for non-existent files
1411 if (!fi.exists() || !fi.isFile()) {
1412 QAD_MessageBox::error1 ( this, tr("ERR_ERROR"),
1413 tr("ERR_DOC_CANTOPEN") +": " + name,
1418 CORBA::Object_var obj = myNameService->Resolve("/myStudyManager");
1419 SALOMEDS::StudyManager_var myStudyMgr = SALOMEDS::StudyManager::_narrow(obj);
1420 ASSERT(! CORBA::is_nil(myStudyMgr));
1421 SALOMEDS::ListOfOpenStudies_var List = myStudyMgr->GetOpenStudies();
1422 for (unsigned int ind = 0; ind < List->length();ind++) {
1423 QString NameExistingStudy(List[ind]);
1424 QString NameOpeningStudy = QAD_Tools::getFileNameFromPath( name, false );
1426 if ( NameExistingStudy.compare( NameOpeningStudy ) == 0 ) {
1427 if ( QAD_MessageBox::warn2 ( this, tr("WRN_WARNING"),
1428 tr("QUE_DOC_ALREADYEXIST").arg( name ),
1429 tr ("BUT_YES"), tr ("BUT_NO"), QAD_YES, QAD_NO,
1430 QAD_NO ) == QAD_NO )
1432 putInfo ( tr("INF_READY") );
1444 Try to associate an application to the opened study.
1445 Assumed that the association study<->application is unique.
1447 bool appFound = false;
1448 putInfo ( tr("INF_DOC_OPENING") + " " + name );
1449 for ( QAD_Application* app = myApps.first(); app; app = myApps.next() )
1451 QString ext = QAD_Tools::getFileExtensionFromPath ( name );
1452 if ( app->getStudyExtension() == ext )
1454 /* application found */
1455 if ( app->isStudyOpened( name ) )
1457 /* already opened: prompt for reopen */
1458 if ( QAD_MessageBox::warn2 ( this, tr("WRN_WARNING"),
1459 tr("QUE_DOC_ALREADYOPEN").arg( name ),
1460 tr ("BUT_YES"), tr ("BUT_NO"), QAD_YES, QAD_NO,
1461 QAD_NO ) == QAD_NO )
1463 putInfo ( tr("INF_READY") );
1466 /* now the study is closed to be re-opened */
1467 //don't ask user to remove study permanently
1468 if (app->getStudyByName ( name ) != NULL)
1469 onCloseStudy ( app->getStudyByName ( name ), false );
1470 else if (app->getStudyByName ( QAD_Tools::getFileNameFromPath( name, false )) != NULL)
1471 onCloseStudy ( app->getStudyByName ( QAD_Tools::getFileNameFromPath( name, false )), false );
1475 /* open the study */
1476 QAD_Study* openStudy = app->openStudy( name );
1478 QAD_MessageBox::error1( this,
1480 tr("ERR_DOC_CANTOPEN") + "\n" + name,
1482 } else if (myActiveComp != "") {
1483 QApplication::setOverrideCursor( Qt::waitCursor );
1484 loadComponentData(myActiveComp);
1485 openStudy->updateObjBrowser(true);
1486 QApplication::restoreOverrideCursor();
1494 QAD_MessageBox::error1( this,
1496 tr("ERR_DOC_UNKNOWNTYPE"),
1499 putInfo ( tr("INF_READY") );
1502 bool QAD_Desktop::loadComponentData( const QString& compName )
1504 // Open component's data in active study if any
1505 MESSAGE("loadComponentData(): Opening component data")
1506 if (!myActiveStudy) {
1507 MESSAGE("loadComponentData(): No active study exists")
1511 Engines::Component_var comp ;
1512 if ( compName.compare("Supervision") == 0 ) {
1513 comp = getEngine( "SuperVisionContainer", compName) ;
1516 /* comp = ( compName.compare("Data1") != 0 ) ? getEngine( "FactoryServer", compName) :
1517 getEngine( "FactoryServerPy", compName);
1519 comp = getEngine( "FactoryServer", compName);
1520 if ( comp->_is_nil() )
1521 comp = getEngine( "FactoryServerPy", compName);
1524 SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
1525 SALOMEDS::SComponent_var SCO = SALOMEDS::SComponent::_narrow(aStudy->FindObject(compName));
1527 if (!SCO->_is_nil()) {
1528 if (!CORBA::is_nil(comp)) {
1529 SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
1530 if (!CORBA::is_nil(driver)) {
1531 SALOMEDS::StudyBuilder_var B = aStudy->NewBuilder();
1532 if (!CORBA::is_nil(B)) {
1533 QAD_Operation* op = new QAD_Operation( myActiveStudy );
1535 B->LoadWith(SCO,driver);
1541 MESSAGE("loadComponentData(): Driver is null");
1545 MESSAGE("loadComponentData(): Engine is null");
1549 MESSAGE("loadComponentData(): SComponent is null");
1557 Saves the active study
1559 bool QAD_Desktop::onSaveStudy()
1561 return onSaveStudy ( myActiveStudy );
1565 Saves the given study
1567 bool QAD_Desktop::onSaveStudy( QAD_Study* study )
1569 if ( !study ) return true;
1571 if ( !study->isSaved() )
1572 return onSaveAsStudy ( study );
1574 /* saving study... */
1575 QAD_Application* app = study->getApp();
1576 QAD_ASSERT_DEBUG_ONLY ( app );
1577 putInfo ( tr("INF_DOC_SAVING") + study->getTitle() );
1578 if ( !app->saveStudy( study ) )
1580 putInfo( tr("INF_CANCELLED") );
1585 putInfo ( tr("INF_DOC_SAVED").arg( "" ) );
1590 Saves the active study under a new name
1592 bool QAD_Desktop::onSaveAsStudy()
1594 return onSaveAsStudy( myActiveStudy );
1598 Saves the given study under a new name
1600 bool QAD_Desktop::onSaveAsStudy( QAD_Study* study )
1602 if ( !study ) return true;
1604 /* Save study in a format supported by its application
1606 QAD_Application* app = study->getApp();
1607 QAD_ASSERT_DEBUG_ONLY ( app );
1609 /* Select a file where to save
1611 QString name = selectFileName ( false );
1612 if ( name.isNull() || name.isEmpty() )
1614 putInfo( tr("INF_CANCELLED") );
1620 putInfo ( tr("INF_DOC_SAVING") + name );
1621 if ( !app->saveAsStudy( study, name ) ) {
1622 /* can't save the file */
1623 QAD_MessageBox::error1( this,
1625 tr("ERR_DOC_CANTWRITE") + "\n" + name,
1628 return false; /* cannot save */
1630 putInfo ( tr("INF_DOC_SAVED").arg( name ) );
1631 return true; /* saved ok */
1635 Closes the active study
1637 bool QAD_Desktop::onCloseStudy()
1639 bool close = this->onCloseStudy ( myActiveStudy, true );
1640 if ( close && !myXmlHandler->myIdList.IsEmpty() ) {
1643 myCombo->setCurrentItem (0);
1644 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
1645 aButton->setOn(false);
1652 Closes the given study and ask user to remove study
1653 from the study manager permanently
1655 bool QAD_Desktop::onCloseStudy( QAD_Study* study )
1657 return onCloseStudy( study, true );
1661 Closes the given study and ask user to remove study
1662 from the study manager permanently if ask is equal true
1664 bool QAD_Desktop::onCloseStudy( QAD_Study* study, bool ask )
1666 bool removePerm = false;
1670 SALOMEGUI_CloseDlg aDlg( this );
1671 int res = aDlg.exec();
1676 //if ( study->isModified() )
1677 if ( !onSaveStudy( study ) ) {
1678 putInfo( tr("INF_CANCELLED") );
1691 putInfo( tr("INF_CANCELLED") );
1695 /* close active component */
1696 if (!myXmlHandler->myIdList.IsEmpty())
1700 myCombo->setCurrentItem (0);
1701 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() )
1702 aButton->setOn(false);
1703 qApp->processEvents();
1705 /* close the study */
1706 return study->getApp()->closeStudy( study, removePerm );
1709 // Displays study properties dialog box
1710 void QAD_Desktop::onStudyProperties()
1712 if (myActiveStudy) {
1714 QAD_Operation* op = new QAD_Operation( myActiveStudy );
1717 SALOMEGUI_StudyPropertiesDlg aDlg(this);
1718 int res = aDlg.exec();
1720 if ( res == QDialog::Accepted && aDlg.isChanged() )
1725 // T2.12 - add the word "locked" to study frame captions if <myActiveStudy> study is locked
1726 myActiveStudy->updateCaptions();
1732 locate all windows in cascade mode
1735 void QAD_Desktop::onCascade()
1737 myWorkspace->cascade();
1738 int w = myWorkspace->width();
1739 int h = myWorkspace->height();
1740 QWidgetList wList = myWorkspace->windowList();
1741 QWidgetListIt it(wList);
1743 for(;it.current(); ++it)
1744 it.current()->resize((int)(0.8*w), (int)(0.8*h));
1748 called when help window closed
1750 void QAD_Desktop::onHelpWindowClosed()
1756 Called when 'view status bar' option
1759 void QAD_Desktop::onViewStatusBar()
1761 bool show = myStdActions.at( ViewStatusBarId )->isOn();
1762 if ( show == myStatusBar->isVisible() )
1765 myStatusBar->show();
1767 myStatusBar->hide();
1771 Called when View/Toolbars popup menu is about to show
1773 void QAD_Desktop::onToolBarPopupAboutToShow()
1775 myToolBarAction.clear();
1776 myToolBarsPopup.clear();
1777 QPtrList<QDockWindow> wlist = dockWindows();
1778 for ( QDockWindow* w = wlist.first(); w; w = wlist.next() ) {
1779 if ( w->inherits( "QToolBar" ) ) {
1780 QToolBar* tb = ( QToolBar* )w;
1781 if ( appropriate( tb ) ) {
1782 ToggleAction* a = new ToggleAction( tb->label(), tb->label(), 0, this, 0, true );
1783 a->setStatusTip ( tr("PRP_DESK_VIEW_TOOLBAR") );
1784 a->setOn( tb->isVisible() );
1785 QAD_ASSERT( connect( a, SIGNAL( toggledOn() ), tb, SLOT( show() ) ) );
1786 QAD_ASSERT( connect( a, SIGNAL( toggledOff() ), tb, SLOT( hide() ) ) );
1787 a->addTo( &myToolBarsPopup );
1788 myToolBarAction.append( a );
1795 Called on 'View\Selection Mode'
1797 void QAD_Desktop::onSelectionMode()
1799 const QActionP* obj = (QActionP*) sender();
1801 int SelectionMode = 4;
1803 if ( obj == myStdActions.at(SelectionActorId) ) {
1805 if ( obj->isOn() ) {
1806 myStdActions.at(SelectionCellId)->setOn(false);
1807 myStdActions.at(SelectionEdgeId)->setOn(false);
1808 myStdActions.at(SelectionPointId)->setOn(false);
1810 myStdActions.at(SelectionActorId)->setOn(true);
1812 } else if ( obj == myStdActions.at(SelectionCellId) ) {
1814 if ( obj->isOn() ) {
1815 myStdActions.at(SelectionActorId)->setOn(false);
1816 myStdActions.at(SelectionEdgeId)->setOn(false);
1817 myStdActions.at(SelectionPointId)->setOn(false);
1819 myStdActions.at(SelectionActorId)->setOn(true);
1821 } else if ( obj == myStdActions.at(SelectionEdgeId) ) {
1823 if ( obj->isOn() ) {
1824 myStdActions.at(SelectionActorId)->setOn(false);
1825 myStdActions.at(SelectionCellId)->setOn(false);
1826 myStdActions.at(SelectionPointId)->setOn(false);
1828 myStdActions.at(SelectionActorId)->setOn(true);
1830 } else if ( obj == myStdActions.at(SelectionPointId) ) {
1832 if ( obj->isOn() ) {
1833 myStdActions.at(SelectionEdgeId)->setOn(false);
1834 myStdActions.at(SelectionCellId)->setOn(false);
1835 myStdActions.at(SelectionActorId)->setOn(false);
1837 myStdActions.at(SelectionActorId)->setOn(true);
1840 QAD_StudyFrame* sf = myActiveApp->getActiveStudy()->getActiveStudyFrame();
1841 sf->getRightFrame()->getViewFrame()->SetSelectionMode( SelectionMode );
1843 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveApp->getActiveStudy()->getSelection() );
1844 Sel->SetSelectionMode( SelectionMode );
1848 Called on 'View\Selection Mode'
1850 void QAD_Desktop::SetSelectionMode(int mode, bool activeCompOnly)
1855 myStdActions.at(SelectionEdgeId)->setOn(false);
1856 myStdActions.at(SelectionCellId)->setOn(false);
1857 myStdActions.at(SelectionActorId)->setOn(false);
1858 myStdActions.at(SelectionPointId)->setOn(true);
1863 myStdActions.at(SelectionActorId)->setOn(false);
1864 myStdActions.at(SelectionCellId)->setOn(false);
1865 myStdActions.at(SelectionPointId)->setOn(false);
1866 myStdActions.at(SelectionEdgeId)->setOn(true);
1871 myStdActions.at(SelectionActorId)->setOn(false);
1872 myStdActions.at(SelectionEdgeId)->setOn(false);
1873 myStdActions.at(SelectionPointId)->setOn(false);
1874 myStdActions.at(SelectionCellId)->setOn(true);
1879 myStdActions.at(SelectionCellId)->setOn(false);
1880 myStdActions.at(SelectionEdgeId)->setOn(false);
1881 myStdActions.at(SelectionPointId)->setOn(false);
1882 myStdActions.at(SelectionActorId)->setOn(true);
1887 QAD_StudyFrame* sf = myActiveApp->getActiveStudy()->getActiveStudyFrame();
1888 if ( sf->getTypeView() == VIEW_VTK ) {
1889 sf->getRightFrame()->getViewFrame()->SetSelectionMode( mode );
1890 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveApp->getActiveStudy()->getSelection() );
1891 Sel->SetSelectionMode( mode, activeCompOnly );
1897 Called on 'Window\NewWindow3d'
1899 void QAD_Desktop::onNewWindow3d()
1903 //VRV: T2.5 - add default viewer
1904 QApplication::restoreOverrideCursor();
1905 SALOMEGUI_ViewChoiceDlg *choice = new SALOMEGUI_ViewChoiceDlg(this, "", TRUE);
1906 int r = choice->exec();
1909 myActiveApp->getActiveStudy()->newWindow3d(QString(""),(ViewType)(choice->getSelectedViewer()));
1911 //VRV: T2.5 - add default viewer
1913 const QActionP* obj = (QActionP*) sender();
1914 if ( obj == myStdActions.at(ViewOCCId) ) {
1915 myActiveApp->getActiveStudy()->newWindow3d(QString(""),(ViewType)(0));
1916 } else if ( obj == myStdActions.at(ViewVTKId) ) {
1917 myActiveApp->getActiveStudy()->newWindow3d(QString(""),(ViewType)(1));
1918 } else if ( obj == myStdActions.at(ViewPlot2dId) ) {
1919 myActiveApp->getActiveStudy()->newWindow3d(QString(""),(ViewType)(3));
1925 Called on 'help\contents'
1927 void QAD_Desktop::onHelpContents()
1930 myActiveApp->helpContents();
1936 Called on 'help\search'
1938 void QAD_Desktop::onHelpSearch()
1941 myActiveApp->helpSearch();
1947 Called on 'help\about'
1949 void QAD_Desktop::onHelpAbout()
1952 myActiveApp->helpAbout();
1959 Activates the application and its active study
1961 void QAD_Desktop::onActivateApp( QAD_Application* activeApp )
1963 bool appChanged = ( activeApp != myActiveApp );
1966 updateDesktop( DeactivateApp );
1970 myActiveApp = activeApp;
1971 myActiveStudy = myActiveApp->getActiveStudy();
1981 updateDesktop( ActivateApp );
1982 updateCaption( (activeApp != NULL) ? ActivateApp : DeactivateApp );
1988 Called when the last study is removed from
1989 the application 'app'.
1991 void QAD_Desktop::onDeactivateApp(QAD_Application* app)
1993 if ( app && app == myActiveApp )
1998 Enables/disables standard actions
2000 void QAD_Desktop::updateActions()
2002 myStdActions.at( FileCloseId )->setEnabled ( myActiveStudy != NULL );
2003 myStdActions.at( FileSaveId )->setEnabled ( myActiveStudy != NULL );
2004 myStdActions.at( FileSaveAsId )->setEnabled ( myActiveStudy != NULL );
2005 myStdActions.at( FilePropsId )->setEnabled( myActiveStudy != NULL );
2006 // myStdActions.at( HelpContentsId )->setEnabled ( myActiveApp != NULL );
2007 // myStdActions.at( HelpSearchId )->setEnabled ( myActiveApp != NULL );
2008 // myStdActions.at( HelpWhatsThisId )->setEnabled ( myActiveApp != NULL );
2009 // myStdActions.at( HelpAboutId )->setEnabled ( myActiveApp != NULL );
2011 // myToolsPopup.setEnabled ( myActiveStudy != NULL );
2012 // myPrefPopup.setEnabled ( myActiveStudy != NULL );
2014 mySelectionModePopup.setEnabled ( myActiveStudy != NULL );
2017 myStdActions.at( ViewOCCId )->setEnabled( myActiveStudy != NULL );
2018 myStdActions.at( ViewVTKId )->setEnabled( myActiveStudy != NULL );
2019 myStdActions.at( ViewPlot2dId )->setEnabled( myActiveStudy != NULL );
2024 Called when 'Window' popup is about to show
2026 void QAD_Desktop::onWindowPopupAboutToShow()
2028 /* add cascade/tile items */
2029 myWindowPopup.clear();
2032 //myStdActions.at( WindowNew3dId )->addTo( &myWindowPopup );
2033 myWindowPopup.insertItem( tr("MEN_DESK_WINDOW_NEW3D"), &myNewViewPopup, WindowNew3dId );
2034 //myStdActions.at( WindowNew3dId )->setEnabled( true );
2035 myWindowPopup.setItemEnabled( WindowNew3dId, true );
2037 myStdActions.at( WindowCascadeId )->addTo( &myWindowPopup );
2038 myStdActions.at( WindowCascadeId )->setEnabled( true );
2039 myStdActions.at( WindowTileId )->addTo( &myWindowPopup );
2040 myStdActions.at( WindowTileId )->setEnabled( true );
2042 /* add names of opened studies */
2043 QWidgetList windows = myWorkspace->windowList();
2044 if ( windows.isEmpty() )
2046 //NRI : SAL2214 myStdActions.at( WindowNew3dId )->setEnabled( false );
2047 myWindowPopup.setItemEnabled( WindowNew3dId, false );
2049 myStdActions.at( WindowCascadeId )->setEnabled( false );
2050 myStdActions.at( WindowTileId )->setEnabled( false );
2054 myWindowPopup.insertSeparator();
2055 for ( int i = 0; i < int(windows.count()); ++i )
2057 int id = myWindowPopup.insertItem( windows.at(i)->caption(),
2058 this, SLOT( onWindowsPopupActivated( int ) ) );
2059 myWindowPopup.setItemParameter( id, i );
2060 myWindowPopup.setItemChecked( id, myWorkspace->activeWindow() == windows.at(i) );
2062 QAD_ASSERT( connect( &myWindowPopup, SIGNAL(highlighted( int )), this,
2063 SLOT(onWindowsPopupStatusText( int )) ));
2068 Called when the item with 'id' of 'Windows' popup
2071 void QAD_Desktop::onWindowsPopupStatusText( int id )
2073 int cascadeId = myWindowPopup.idAt( 0 );
2074 int tileId = myWindowPopup.idAt( 1 );
2075 if ( id == cascadeId || id == tileId )
2077 putInfo( tr("PRP_DESK_WINDOW_ACTIVATE") );
2081 Called when user wants to activate a child window with 'wid'
2084 void QAD_Desktop::onWindowsPopupActivated( int wid )
2086 QWidget* w = myWorkspace->windowList().at( wid );
2087 if ( w ) w->setFocus();
2091 Selects a file name when opening or saving files.
2092 The basic implementation just uses the standard
2094 Please redefine if another behaviour is required.
2096 QString QAD_Desktop::selectFileName ( bool open )
2098 QAD_FileDlg* fd = new QAD_FileDlg( this, open, true, true );
2102 QStringList filters;
2105 // All the file types of the supported applications
2107 for ( QAD_Application* app = myApps.first(); app; app = myApps.next() )
2109 filters += app->getStudyDescription() + " " + tr("DESK_FILES") + " " +
2110 "(*." + app->getStudyExtension() + ")";
2114 QAD_ASSERT_DEBUG_ONLY ( myActiveStudy );
2115 if (myActiveStudy) {
2116 // get file name of active study
2117 name = QAD_Tools::getFileNameFromPath ( myActiveStudy->getTitle() );
2118 // get path to the active study file
2119 dir = QAD_Tools::getDirFromPath ( myActiveStudy->getPath(), false );
2121 QAD_ASSERT_DEBUG_ONLY ( !name.isNull() );
2122 // the file types supported by the active application
2123 filters += myActiveApp->getStudyDescription() + " " + tr("DESK_FILES") + " " +
2124 "(*." + myActiveApp->getStudyExtension() + ")" ;
2126 if (!dir.isEmpty()) {
2127 // when saving document ("Save As" command) - to get dir from active study filename
2128 // for new documents - to use last opened directory
2131 fd->setSelection( name );
2132 fd->setFilters( filters );
2135 QString filename = fd->selectedFile();
2137 qApp->processEvents();
2142 Closes all the studies of 'app'. Returns
2143 'true' if thay are closed OK, 'false' at least
2144 one can't be closed or user cancel the closure.
2146 bool QAD_Desktop::closeAllStudies( QAD_Application* app )
2148 QList<QAD_Study>& studies = app->getStudies();
2149 while ( !studies.isEmpty() )
2151 //don't ask user to remove study permanently
2152 if ( !onCloseStudy( studies.at(0), false ) )
2153 return false; /* user cancelled closing */
2159 Called on Popup item when SComponent representation in Object Browser is selected.
2161 void QAD_Desktop::onOpenWith()
2163 Engines::Component_var comp;
2164 QString ComponentSelected;
2166 SALOMEDS::SObject_var SO;
2167 SALOMEDS::SComponent_var SCO;
2168 SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
2169 SALOMEDS::GenericAttribute_var anAttr;
2170 SALOMEDS::AttributeName_var aName;
2172 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2173 if ( Sel->IObjectCount() == 1 ) {
2174 Handle(SALOME_InteractiveObject) IO = Sel->firstIObject();
2175 SO = aStudy->FindObjectID( IO->getEntry() );
2176 SCO = SO->GetFatherComponent();
2178 if (SCO->FindAttribute(anAttr, "AttributeName")) {
2179 aName = SALOMEDS::AttributeName::_narrow(anAttr);
2180 name = aName->Value();
2181 SALOME_ModuleCatalog::Acomponent_var Comp = myCatalogue->GetComponent( name );
2182 if ( !Comp->_is_nil() ) {
2184 SALOME_ModuleCatalog::ListOfComponents_var list_type_composants =
2185 myCatalogue->GetTypedComponentList( Comp->component_type() );
2187 if ( list_type_composants->length() == 1 ) {
2188 ComponentSelected = name;
2189 } else if ( list_type_composants->length() > 1 ) {
2190 SALOMEGUI_OpenWith* aDlg = new SALOMEGUI_OpenWith( this );
2191 for (unsigned int ind = 0; ind < list_type_composants->length();ind++) {
2192 aDlg->addComponent( strdup(list_type_composants[ind]) );
2195 int retVal = aDlg->exec();
2196 ComponentSelected = aDlg->getComponent();
2198 if ( retVal == QDialog::Rejected || ComponentSelected.isEmpty()) {
2202 MESSAGE( "No component with type : " << Comp->component_type() << " exists" );
2207 MESSAGE( "This component not exists in the catalog" );
2211 QApplication::setOverrideCursor( Qt::waitCursor );
2212 Sel->ClearIObjects();
2214 // if (loadComponentData(ComponentSelected)) {
2215 onComboActiveComponent(ComponentSelected);
2216 // int nbItem = myCombo->count();
2218 // for (int i = 0; i < nbItem; i++) {
2219 // if (myCombo->text(i).compare(ComponentSelected)==0) {
2224 // myCombo->setCurrentItem(Index);
2225 // myActiveStudy->updateObjBrowser(true);
2229 QApplication::restoreOverrideCursor();
2232 typedef bool OneDim1(QAD_Desktop*);
2235 Called to define settings of component.
2237 void QAD_Desktop::setSettings()
2239 if (!myActiveComp.isEmpty()) {
2240 OSD_Function osdF = mySharedLibrary.DlSymb("SetSettings");
2241 if ( osdF != NULL ) {
2242 OneDim1 (*f1) = (bool (*) (QAD_Desktop*)) osdF;
2249 Called to load Component : xml resources and GUI librairy.
2251 bool QAD_Desktop::loadComponent(QString Component)
2254 QString resDir("/"); //NRI : Pb under Windows
2256 QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
2259 if (!resMgr->loadResources( Component + "GUI", msg ))
2261 //NRI QCString errMsg;
2262 // errMsg.sprintf( "Do not load all resources for module %sGUI.\n" ,
2263 // Component.latin1() );
2265 QMessageBox::warning( this, tr("WRN_WARNING"), msg, tr ("BUT_OK") );
2270 /* Parse xml file */
2271 myXmlHandler = new QAD_XmlHandler();
2272 myXmlHandler->setMainWindow(this);
2273 if (!myXmlHandler->setComponent(resMgr->resources(Component + "GUI"))) return false;
2275 QString language = resMgr->language( Component + "GUI" );
2277 QString ComponentXml = Component + "_" + language + ".xml";
2278 //ComponentXml = resMgr->resources(Component + "GUI") ;
2279 //ComponentXml = QAD_Tools::addSlash(ComponentXml) ;
2280 ComponentXml = QAD_Tools::addSlash( resMgr->findFile( ComponentXml, Component + "GUI" ) ) + ComponentXml;
2281 QFile file( ComponentXml );
2283 if ( !file.exists() || !file.open( IO_ReadOnly ) ) {
2285 errMsg.sprintf( "Cannot open xml file: %s\n.",
2286 (file.name()).latin1() );
2288 QMessageBox::critical( this, tr("ERR_ERROR"), errMsg, tr ("BUT_OK") );
2293 QXmlInputSource source( file );
2294 QXmlSimpleReader reader;
2295 reader.setContentHandler( myXmlHandler );
2296 reader.setErrorHandler( myXmlHandler );
2297 bool ok = reader.parse( source );
2301 QMessageBox::critical( this,
2302 tr( "INF_PARSE_ERROR" ),
2303 tr( myXmlHandler->errorProtocol() ) );
2307 myMenusList=myXmlHandler->myMenusList;
2308 myActiveMenus=myMenusList.at(0);
2309 myOperatorMenus->showMenuBar(0);
2310 myActiveMenus->showAllToolBars();
2312 /* Components toolbars */
2315 nbToolbars = myActiveMenus->getToolBarList().count();
2316 /* Open Shared Library */
2317 mySharedLibrary = OSD_SharedLibrary();
2319 QString ComponentLib;
2321 QFileInfo fileInfo ;
2323 if ( dir = getenv("SALOME_SITE_DIR")) {
2324 dir = QAD_Tools::addSlash(dir) ;
2326 dir = QAD_Tools::addSlash(dir) ;
2328 dir = dir + "lib" + Component.latin1() + "GUI.dll" ;
2330 dir = dir + "lib" + Component.latin1() + "GUI.so" ;
2332 MESSAGE ( " GUI library = " << dir )
2333 fileInfo.setFile(dir) ;
2334 if (fileInfo.exists()) {
2335 ComponentLib = fileInfo.fileName() ;
2340 if ( (dir = getenv("SALOME_ROOT_DIR")) && !found ) {
2341 dir = QAD_Tools::addSlash(dir) ;
2343 dir = QAD_Tools::addSlash(dir) ;
2345 dir = dir + "lib" + Component.latin1() + "GUI.dll" ;
2347 dir = dir + "lib" + Component.latin1() + "GUI.so" ;
2349 MESSAGE ( " GUI library = " << dir )
2350 fileInfo.setFile(dir) ;
2351 if (fileInfo.exists()) {
2352 ComponentLib = fileInfo.fileName() ;
2357 mySharedLibrary.SetName(TCollection_AsciiString((char*)ComponentLib.latin1()).ToCString());
2358 ok = mySharedLibrary.DlOpen(OSD_RTLD_LAZY);
2361 QMessageBox::critical( this,
2363 tr( mySharedLibrary.DlError() ) );
2368 OSD_Function osdF = mySharedLibrary.DlSymb("SetSettings");
2369 if ( osdF != NULL ) {
2370 OneDim1 (*f1) = (bool (*) (QAD_Desktop*)) osdF;
2374 /* COMPONENT INTERFACE */
2375 SALOME_ModuleCatalog::Acomponent_ptr aComponent =
2376 myCatalogue->GetComponent(Component.latin1());
2378 if (CORBA::is_nil (aComponent)) {
2379 MESSAGE( "Catalog Error : Component not found in the catalog" )
2383 myActiveStudy->setMessage(QString("Component : ") +
2384 aComponent->componentname() + " created " );
2385 myActiveStudy->setMessage(QString("Type : ") +
2386 QString::number(aComponent->component_type()));
2387 myActiveStudy->setMessage(QString("Constraint : ") +
2388 aComponent->constraint() );
2390 /* obtain interfaces list of the component */
2391 SALOME_ModuleCatalog::ListOfInterfaces_var _list =
2392 new SALOME_ModuleCatalog::ListOfInterfaces;
2393 _list = aComponent->GetInterfaceList();
2395 if (_list->length() != 0 ) {
2397 for (unsigned int ind = 0; ind < _list->length();ind++)
2398 myActiveStudy->setMessage( QString("Interface name : ") +
2402 /* obtain services list of the component */
2403 SALOME_ModuleCatalog::ListOfServices_var list_services_component =
2404 new SALOME_ModuleCatalog::ListOfServices;
2405 list_services_component = aComponent->GetServiceList(_list[0]);
2407 if (list_services_component->length() != 0 ) {
2409 for (unsigned int ind = 0; ind < list_services_component->length();ind++)
2410 myActiveStudy->setMessage( QString("Service name : ") +
2411 list_services_component[ind] );
2413 // Get a service of the component
2414 SALOME_ModuleCatalog::Service_var service = new SALOME_ModuleCatalog::Service;
2415 service = aComponent->GetService(_list[0],list_services_component[0]) ;
2416 myActiveStudy->setMessage( QString("Service name: ") + service->ServiceName);
2417 for (unsigned int ind1 = 0; ind1 <service->ServiceinParameter.length();ind1++) {
2418 myActiveStudy->setMessage( QString("Type of the in Parameter of this service : ") +
2419 (const char *) service->ServiceinParameter[ind1].Parametertype);
2420 myActiveStudy->setMessage( QString("Name of the in Parameter of this service : ") +
2421 (const char *) service->ServiceinParameter[ind1].Parametername);
2423 for (unsigned int ind1 = 0; ind1 <service->ServiceoutParameter.length();ind1++) {
2424 myActiveStudy->setMessage( QString("Type of the out Parameter of this service : ") +
2425 (const char *) service->ServiceoutParameter[ind1].Parametertype);
2426 myActiveStudy->setMessage( QString("Name of the out Parameter of this service : ") +
2427 (const char *) service->ServiceoutParameter[ind1].Parametername);
2434 typedef bool OneDim(int, QAD_Desktop*);
2435 typedef void (*PTR_FACTORY_FUNCTION)( CORBA::ORB_var &orb, QWidget *parent, const char *name ) ;
2439 void QAD_Desktop::onDispatch()
2441 const QObject* obj = sender();
2443 QList<QAD_ListMenuIdAction> MenuList = myActiveMenus->getMenuList();
2444 QAD_ListMenuIdAction* aMenu;
2446 for(aMenu=MenuList.first();aMenu!=NULL;aMenu=MenuList.next()) {
2447 if (aMenu->getAction()==obj) {
2448 id = aMenu->getId();
2457 void QAD_Desktop::onDispatchTools(int id)
2459 /* Open Shared Library */
2460 OSD_SharedLibrary ToolsLibrary = OSD_SharedLibrary();
2464 QFileInfo fileInfo ;
2468 bool libToolsGUI = true;
2469 if( QAD_XmlHandler::_bibmap[ id ].isEmpty() )
2472 if ( dir = getenv("SALOME_SITE_DIR")) {
2473 dir = QAD_Tools::addSlash(dir) ;
2475 dir = QAD_Tools::addSlash(dir) ;
2477 dir = dir + "libToolsGUI.dll" ;
2479 dir = dir + "libToolsGUI.so" ;
2481 MESSAGE ( " GUI library = " << dir );
2482 fileInfo.setFile(dir) ;
2483 if (fileInfo.exists()) {
2484 ToolsLib = fileInfo.fileName() ;
2489 if ( (dir = getenv("SALOME_ROOT_DIR")) && !found ) {
2490 dir = QAD_Tools::addSlash(dir) ;
2492 dir = QAD_Tools::addSlash(dir) ;
2494 dir = dir + "libToolsGUI.dll" ;
2496 dir = dir + "libToolsGUI.so" ;
2498 MESSAGE ( " GUI library = " << dir );
2499 fileInfo.setFile(dir) ;
2500 if (fileInfo.exists()) {
2501 ToolsLib = fileInfo.fileName() ;
2507 libToolsGUI = false;
2508 SCRUTE( QAD_XmlHandler::_bibmap[ id ] ) ;
2509 if ( dir = getenv("SALOME_SITE_DIR")) {
2510 dir = QAD_Tools::addSlash(dir) ;
2512 dir = QAD_Tools::addSlash(dir) ;
2513 dir = dir + QAD_XmlHandler::_bibmap[ id ].latin1() ;
2514 MESSAGE ( " GUI library = " << dir );
2515 fileInfo.setFile(dir) ;
2516 if (fileInfo.exists()) {
2517 ToolsLib = fileInfo.fileName() ;
2522 if ( (dir = getenv("SALOME_ROOT_DIR")) && !found ) {
2523 dir = QAD_Tools::addSlash(dir) ;
2525 dir = QAD_Tools::addSlash(dir) ;
2526 dir = dir + QAD_XmlHandler::_bibmap[ id ].latin1() ;
2527 MESSAGE ( " GUI library = " << dir );
2528 fileInfo.setFile(dir) ;
2529 if (fileInfo.exists()) {
2530 ToolsLib = fileInfo.fileName() ;
2536 ToolsLibrary.SetName(TCollection_AsciiString((char*)ToolsLib.latin1()).ToCString());
2537 bool ok = ToolsLibrary.DlOpen(OSD_RTLD_LAZY);
2539 if ( libToolsGUI ) {
2540 OSD_Function osdF = ToolsLibrary.DlSymb("OnGUIEvent");
2541 OneDim (*f1) = NULL;
2542 f1 = (bool (*) (int, QAD_Desktop*)) osdF;
2545 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
2546 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
2547 CORBA::ORB_var &orb = init(0 , 0 ) ;
2548 OSD_Function osdF = ToolsLibrary.DlSymb("OnGUIEvent");
2549 PTR_FACTORY_FUNCTION f1 = NULL;
2550 f1 = (PTR_FACTORY_FUNCTION) osdF;
2551 f1(orb,0,"Registry");
2554 QMessageBox::critical( this,
2556 tr( ToolsLibrary.DlError() ) );
2562 void QAD_Desktop::onDispatch(int id)
2564 if (!myActiveComp.isEmpty()) {
2565 OSD_Function osdF = mySharedLibrary.DlSymb("OnGUIEvent");
2566 OneDim (*f1) = NULL;
2567 if ( osdF != NULL ) {
2568 f1 = (bool (*) (int, QAD_Desktop*)) osdF;
2575 Returns the component's catalogue
2577 SALOME_ModuleCatalog::ModuleCatalog_var QAD_Desktop::getCatalogue()
2584 void QAD_Desktop::onComboActiveComponent( const QString & component ){
2585 onComboActiveComponent(component,true);
2587 void QAD_Desktop::onComboActiveComponent( const QString & component, bool isLoadData)
2589 if (myActiveStudy != 0) {
2590 if (myActiveComp.compare(component)!=0) {
2591 if (!myXmlHandler->myIdList.IsEmpty()) clearMenus();
2592 if ( myCombo->currentText() != component )
2593 myCombo->setCurrentText( component );
2594 if (component.compare(QString("Salome"))!= 0) {
2595 // QApplication::setOverrideCursor( Qt::waitCursor );
2596 myActiveComp = component;
2598 SALOME_Selection* oldSel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2600 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2601 if ( aButton->textLabel().compare(component)==0)
2602 aButton->setOn(true);
2604 aButton->setOn(false);
2607 myActiveStudy->Selection( component );
2608 if ( !loadComponent(component) ) {
2609 myCombo->setCurrentItem (0);
2610 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2611 aButton->setOn(false);
2616 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2617 SALOME_ListIteratorOfListIO It( oldSel->StoredIObjects() );
2618 for(;It.More();It.Next()) {
2619 int res = Sel->AddIObject( It.Value() );
2622 myActiveStudy->highlight( It.Value(), false );
2624 myActiveStudy->highlight( It.Value(), true );
2628 // Open new component's data in active study if any
2629 if(isLoadData) loadComponentData(component);
2632 myActiveStudy->updateObjBrowser(true);
2634 // QApplication::restoreOverrideCursor();
2636 } else { // component == "Salome"
2638 myActiveStudy->Selection( "Salome" );
2639 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
2640 Sel->ClearIObjects();
2641 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2642 aButton->setOn(false);
2646 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2647 if ( aButton->textLabel().compare(component)==0)
2648 aButton->setOn(true);
2652 QMessageBox::critical( 0,
2654 tr( "WRN_LOAD_COMPONENT" ) );
2655 myCombo->setCurrentItem (0);
2656 for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
2657 aButton->setOn(false);
2664 void QAD_Desktop::activateComponent(const QString& theName, bool isLoadData){
2665 int nbItem = myCombo->count();
2668 for (int i = 0; i < nbItem; i++) {
2669 if (myCombo->text(i).compare(theName)==0) {
2674 myCombo->setCurrentItem (Index);
2675 onComboActiveComponent(theName,isLoadData);
2678 void QAD_Desktop::onButtonActiveComponent( )
2680 QToolButton* obj = (QToolButton*)sender();
2681 activateComponent(obj->textLabel());
2685 Clears All Resources of current component
2687 void QAD_Desktop::clearMenus()
2689 onActiveStudyChanged();
2692 myMenusList.clear();
2694 int length = myXmlHandler->myIdList.Length();
2695 for (int k=length; k>0; k--) {
2697 if ( menuBar()->findItem(myXmlHandler->myIdList.Value(k), &parent) )
2698 parent->removeItem( myXmlHandler->myIdList.Value(k) );
2703 if (myActiveMenus) {
2704 int nbtoolbars = myActiveMenus->getToolBarList().count();
2705 for (int k=0; k<nbtoolbars; k++) {
2706 myActiveMenus->getToolBarList().at(k)->hide();
2707 myActiveMenus->getToolBarList().at(k)->clear();
2709 myActiveMenus->clearToolBar();
2712 QList<QAD_ListPopupMenu> PopupList = myActiveMenus->getPopupMenuList();
2713 QAD_ListPopupMenu* aPopup;
2714 for(aPopup=PopupList.first();aPopup!=NULL;aPopup=PopupList.next()){
2715 aPopup->getPopup()->clear();
2718 myActiveMenus->clearPopupMenu();
2724 typedef bool TwoDim1(QKeyEvent* pe, QAD_Desktop*, QAD_StudyFrame*);
2726 Exports Key Events in active component ( GUI Librairy )
2728 void QAD_Desktop::onKeyPress( QKeyEvent* pe )
2730 // MESSAGE ( "QAD_Desktop::onKeyPress" )
2731 if (!myActiveComp.isEmpty()) {
2732 OSD_Function osdF = mySharedLibrary.DlSymb("OnKeyPress");
2733 if ( osdF != NULL ) {
2734 TwoDim1 (*f1) = (bool (*) (QKeyEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
2735 (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
2740 typedef bool TwoDim(QMouseEvent* pe, QAD_Desktop*, QAD_StudyFrame*);
2742 Exports Mouse Press Events in active component ( GUI Librairy )
2744 bool QAD_Desktop::onMousePress( QMouseEvent* pe )
2746 // MESSAGE ( "QAD_Desktop::onMousePress" )
2747 if (!myActiveComp.isEmpty()) {
2748 OSD_Function osdF = mySharedLibrary.DlSymb("OnMousePress");
2749 if ( osdF != NULL ) {
2750 TwoDim (*f1) = (bool (*) (QMouseEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
2751 return (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
2758 Exports Mouse Move Events in active component ( GUI Librairy )
2760 void QAD_Desktop::onMouseMove( QMouseEvent* pe )
2762 if (!myActiveComp.isEmpty()) {
2763 OSD_Function osdF = mySharedLibrary.DlSymb("OnMouseMove");
2764 if ( osdF != NULL ) {
2765 TwoDim (*f1) = (bool (*) (QMouseEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
2766 (*f1)(pe,this,myActiveStudy->getActiveStudyFrame());
2772 Returns name of active component
2774 const QString& QAD_Desktop::getActiveComponent() const
2776 return myActiveComp;
2780 typedef bool defineP( QString & theContext, QString & theParent, QString & theObject);
2782 void QAD_Desktop::definePopup(QString & theContext,
2783 QString & theParent,
2784 QString & theObject )
2786 if (!myActiveComp.isEmpty()) {
2787 OSD_Function osdF = mySharedLibrary.DlSymb("definePopup");
2788 if ( osdF != NULL ) {
2789 defineP (*f1) = (bool (*) (QString &, QString &, QString &)) osdF;
2790 (*f1)(theContext, theParent, theObject);
2798 void QAD_Desktop::createPopup(QPopupMenu* popupFather, QPopupMenu* popup,
2799 QString text, int popupID, bool separator)
2801 QMenuItem* item = popup->findItem(popupID);
2803 QPopupMenu* popupChild = item->popup();
2805 QPopupMenu* newPopup = new QPopupMenu;
2806 int count = popupChild->count();
2807 // add items at the top of <popupFather>
2808 for (int i = count - 1; i >= 0; i--) {
2809 int j = popupChild->idAt(i);
2810 QString text = popupChild->text(j);
2811 createPopup( newPopup, popupChild, text, j);
2813 popupFather->insertItem(popup->text(popupID),
2814 newPopup, popupID, 0);
2816 if ( !text.isNull() ) {
2817 popupFather->insertItem(popup->text(popupID),
2819 SLOT( onDispatch(int) ), 0, popupID, 0);// try adding item at the top
2820 } /*else if ( separator )
2821 popupFather->insertTearOffHandle(-1, 0);*/
2823 popupFather->insertSeparator(0);
2831 void QAD_Desktop::createPopup(QPopupMenu* popup, const QString & theContext,
2832 const QString & theParent, const QString & theObject )
2834 if ( !myActiveComp.isEmpty() &&
2835 getOperatorMenus()->createPopupMenu(theContext,theParent,theObject) != NULL ) {
2836 QPopupMenu* aPopup = getOperatorMenus()->createPopupMenu(theContext,theParent,theObject)->getPopup();
2837 int count = aPopup->count();
2839 //for (int i = 0; i < count; i++) {
2840 for (int i = count - 1; i >= 0; i--) {
2841 int id = aPopup->idAt(i);
2842 QString text = aPopup->text(id);
2843 //QString mes("Inserting popup menu item loaded from XML: ");
2845 //MESSAGE ( mes.latin1() )
2847 popup->insertItem(aPopup->text(id),
2849 SLOT( onDispatch(int) ), 0, id, 0);// try adding item at the top
2851 createPopup( popup, aPopup, text, id);
2854 //QString mes("Popup does not exist for given (Context = ");
2855 //mes += theContext;
2856 //mes += ", Parent = ";
2858 //mes += ", Object = ";
2860 //MESSAGE (mes.latin1())
2865 // Should be moved to SALOMEGUI_Application::onCreatePopup()...
2866 if ( myActiveComp.isEmpty() ) {
2867 popup->removeItem(QAD_Display_Popup_ID);
2868 popup->removeItem(QAD_DisplayOnly_Popup_ID);
2869 popup->removeItem(QAD_Erase_Popup_ID);
2870 int id = popup->idAt(popup->count()-1); // last item
2871 if (id < 0 && id != -1) popup->removeItem(id); // separator
2873 if ( popup && theParent.compare("ObjectBrowser")==0 ) {
2874 if ( popup->count()>0 ) {
2875 popup->insertItem (tr ("MEN_OPENWITH"), this, SLOT(onOpenWith()), 0, -1, 2);
2876 popup->insertSeparator (3);
2879 popup->insertItem (tr ("MEN_OPENWITH"), this, SLOT(onOpenWith()) );
2886 typedef bool activeStudyChanged(QAD_Desktop*);
2888 void QAD_Desktop::onActiveStudyChanged()
2890 if (!myActiveComp.isEmpty()) {
2891 OSD_Function osdF = mySharedLibrary.DlSymb("activeStudyChanged");
2892 if ( osdF != NULL ) {
2893 activeStudyChanged (*f1) = (bool (*) (QAD_Desktop*)) osdF;
2899 typedef bool customP(QAD_Desktop*, QPopupMenu*, const QString & theContext,
2900 const QString & theParent, const QString & theObject);
2902 Custom popup ( GUI Library )
2904 void QAD_Desktop::customPopup(QPopupMenu* popup, const QString & theContext,
2905 const QString & theParent, const QString & theObject)
2907 if (!myActiveComp.isEmpty()) {
2908 OSD_Function osdF = mySharedLibrary.DlSymb("customPopup");
2909 if ( osdF != NULL ) {
2910 customP (*f1) = (bool (*) (QAD_Desktop*, QPopupMenu*, const QString &,
2911 const QString &, const QString &)) osdF;
2912 (*f1)(this, popup, theContext, theParent, theObject);
2917 void QAD_Desktop::onObjectBrowser()
2919 bool checkDiff = false;
2921 bool state = QAD_CONFIG->getSetting("ObjectBrowser:AddColumn").compare("true") == 0;
2923 if ( myStdActions.at( PrefObjectBrowserEntryId )->isOn() != state )
2927 if ( myStdActions.at( PrefObjectBrowserEntryId )->isOn() ) {
2929 QAD_CONFIG->addSetting( "ObjectBrowser:AddColumn", "true");
2932 QAD_CONFIG->addSetting( "ObjectBrowser:AddColumn", "false");
2936 if ( myStdActions.at( PrefObjectBrowserValueId )->isOn() ) {
2938 QAD_CONFIG->addSetting( "ObjectBrowser:ValueColumn", "true");
2941 QAD_CONFIG->addSetting( "ObjectBrowser:ValueColumn", "false");
2945 if ( myStdActions.at( PrefObjectBrowserIAPPId )->isOn() ) {
2947 QAD_CONFIG->addSetting( "ObjectBrowser:IAPP", "true");
2950 QAD_CONFIG->addSetting( "ObjectBrowser:IAPP", "false");
2953 /* To sort created object in chrono order or reverse chrono order */
2954 bool showCHRONO_SORT ;
2955 if ( myStdActions.at( PrefObjectBrowserCHRONO_SORTId )->isOn() ) {
2956 showCHRONO_SORT = true;
2957 QAD_CONFIG->addSetting( "ObjectBrowser:CHRONO_SORT", "true");
2959 showCHRONO_SORT = false;
2960 QAD_CONFIG->addSetting( "ObjectBrowser:CHRONO_SORT", "false");
2963 if ( myActiveApp ) {
2964 QList<QAD_Study>& studies = myActiveApp->getStudies();
2965 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
2966 int nbSf = study->getStudyFramesCount();
2967 for ( int i = 0; i < nbSf; i++ ) {
2968 QAD_StudyFrame* sf = study->getStudyFrame(i);
2969 sf->getLeftFrame()->getObjectBrowser()->setShowInfoColumns( showEntry );
2970 sf->getLeftFrame()->getObjectBrowser()->setShowValueColumn( showValue );
2971 sf->getLeftFrame()->getObjectBrowser()->setEnableChronoSort( showCHRONO_SORT );
2972 // sf->getLeftFrame()->getObjectBrowser()->setShowIAPP( showIAPP ); // this is done by below updateObjBrowser() call
2974 study->updateObjBrowser(true);
2979 void QAD_Desktop::onViewerTrihedron()
2981 QString Size = QAD_CONFIG->getSetting("Viewer:TrihedronSize");
2984 SALOMEGUI_TrihedronSizeDlg *Dlg = new SALOMEGUI_TrihedronSizeDlg(this);
2985 if (!Size.isEmpty())
2986 Dlg->setTrihedronSize(Size.toInt());
2987 int r = Dlg->exec();
2988 dim = Dlg->getTrihedronSize();
2991 if (r == QDialog::Accepted) {
2992 QAD_CONFIG->addSetting("Viewer:TrihedronSize", dim);
2995 QList<QAD_Study>& studies = myActiveApp->getStudies();
2996 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
2997 int nbSf = study->getStudyFramesCount();
2998 for ( int i = 0; i < nbSf; i++ ) {
2999 study->getStudyFrame(i)->getRightFrame()->getViewFrame()->SetTrihedronSize((int)dim);
3006 void QAD_Desktop::onDirList()
3008 // getting dir list from settings
3009 QStringList dirList = QStringList::split(';', QAD_CONFIG->getSetting("FileDlg:QuickDirList"), false);
3010 QAD_DirListDlg* dlg = new QAD_DirListDlg(this);
3011 dlg->setPathList(dirList);
3012 if ( dlg->exec() == QDialog::Accepted) {
3013 dlg->getPathList(dirList);
3014 QAD_CONFIG->addSetting("FileDlg:QuickDirList", dirList.join(";"));
3019 void QAD_Desktop::onConsoleFontAction()
3021 // getting font from settings
3022 QString fntSet = QAD_CONFIG->getSetting("Viewer:ConsoleFont");
3023 QFont font = QAD_Tools::stringToFont( fntSet );
3025 font = QFontDialog::getFont( &bOk, font, this );
3027 fntSet = QAD_Tools::fontToString( font );
3028 QAD_CONFIG->addSetting("Viewer:ConsoleFont", fntSet );
3031 QList<QAD_Study>& studies = myActiveApp->getStudies();
3032 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3033 int nbSf = study->getStudyFramesCount();
3034 for ( int i = 0; i < nbSf; i++ ) {
3035 study->getStudyFrame(i)->getRightFrame()->getPyEditor()->setFont( font );
3036 study->getStudyFrame(i)->getRightFrame()->getMessage()->setFont( font );
3043 void QAD_Desktop::onSavePref()
3045 QAD_CONFIG->createConfigFile(true);
3048 //VRV: T2.5 - add default viewer
3049 void QAD_Desktop::onDefaultViewer(QActionP * theAction)
3051 int type = VIEW_TYPE_MAX;
3054 if (myStdActions.at(DefaultViewerOCCId) == theAction)
3056 else if (myStdActions.at(DefaultViewerVTKId) == theAction)
3058 else if (myStdActions.at(DefaultGraphSupervisorId) == theAction)
3059 type = VIEW_GRAPHSUPERV;
3060 else if (myStdActions.at(DefaultPlot2dId) == theAction)
3062 if ( type != VIEW_TYPE_MAX )
3063 QAD_CONFIG->addSetting( "Viewer:DefaultViewer", QString::number( type ) );
3065 //VRV: T2.5 - add default viewer
3067 void QAD_Desktop::onViewerOCC()
3069 QString BackgroundColorRed = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorRed");
3070 QString BackgroundColorGreen = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorGreen");
3071 QString BackgroundColorBlue = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorBlue");
3074 if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3075 color = QColor(BackgroundColorRed.toInt(),
3076 BackgroundColorGreen.toInt(),
3077 BackgroundColorBlue.toInt());
3079 color = QColor(35, 136, 145);
3081 QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3084 if ( myActiveApp ) {
3085 QList<QAD_Study>& studies = myActiveApp->getStudies();
3086 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3087 int nbSf = study->getStudyFramesCount();
3088 for ( int i = 0; i < nbSf; i++ ) {
3089 QAD_StudyFrame* sf = study->getStudyFrame(i);
3090 if ( sf->getTypeView() == VIEW_OCC ) {
3091 sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3096 QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorRed", c.red() );
3097 QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorGreen", c.green() );
3098 QAD_CONFIG->addSetting( "OCCViewer:BackgroundColorBlue", c.blue() );
3102 void QAD_Desktop::onGraphSupervisor()
3104 QString BackgroundColorRed = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorRed");
3105 QString BackgroundColorGreen = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorGreen");
3106 QString BackgroundColorBlue = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorBlue");
3109 if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3110 color = QColor(BackgroundColorRed.toInt(),
3111 BackgroundColorGreen.toInt(),
3112 BackgroundColorBlue.toInt());
3114 color = QColor(35, 136, 145);
3116 QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3119 if ( myActiveApp ) {
3120 QList<QAD_Study>& studies = myActiveApp->getStudies();
3121 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3122 int nbSf = study->getStudyFramesCount();
3123 for ( int i = 0; i < nbSf; i++ ) {
3124 QAD_StudyFrame* sf = study->getStudyFrame(i);
3125 if ( sf->getTypeView() == VIEW_GRAPHSUPERV ) {
3126 sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3132 QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorRed", c.red() );
3133 QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorGreen", c.green() );
3134 QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorBlue", c.blue() );
3138 void QAD_Desktop::onViewerVTK()
3140 QString BackgroundColorRed = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorRed");
3141 QString BackgroundColorGreen = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorGreen");
3142 QString BackgroundColorBlue = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorBlue");
3145 if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
3146 color = QColor(BackgroundColorRed.toInt(),
3147 BackgroundColorGreen.toInt(),
3148 BackgroundColorBlue.toInt());
3150 color = QColor(0, 0, 0);
3152 QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3155 if ( myActiveApp ) {
3156 QList<QAD_Study>& studies = myActiveApp->getStudies();
3157 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3158 int nbSf = study->getStudyFramesCount();
3159 for ( int i = 0; i < nbSf; i++ ) {
3160 QAD_StudyFrame* sf = study->getStudyFrame(i);
3161 if ( sf->getTypeView() == VIEW_VTK ) {
3162 sf->getRightFrame()->getViewFrame()->setBackgroundColor( c );
3168 QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorRed", c.red() );
3169 QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorGreen", c.green() );
3170 QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorBlue", c.blue() );
3174 void QAD_Desktop::onPlot2d()
3177 if ( QAD_CONFIG->hasSetting( "Plot2d:Background" ) ) {
3178 QString bgString = QAD_CONFIG->getSetting( "Plot2d:Background" );
3179 QStringList bgData = QStringList::split( ":", bgString, true );
3180 int bgRed = 0, bgGreen = 0, bgBlue = 0;
3181 if ( bgData.count() > 0 ) bgRed = bgData[ 0 ].toInt();
3182 if ( bgData.count() > 1 ) bgGreen = bgData[ 1 ].toInt();
3183 if ( bgData.count() > 2 ) bgBlue = bgData[ 2 ].toInt();
3184 color = QColor( bgRed, bgGreen, bgBlue );
3187 color = QColor(0, 0, 0);
3190 color = QColorDialog::getColor( color, QAD_Application::getDesktop() );
3192 if ( color.isValid() ) {
3193 if ( myActiveApp ) {
3194 QList<QAD_Study>& studies = myActiveApp->getStudies();
3195 for ( QAD_Study* study = studies.first(); study; study = studies.next() ) {
3196 int nbSf = study->getStudyFramesCount();
3197 for ( int i = 0; i < nbSf; i++ ) {
3198 QAD_StudyFrame* sf = study->getStudyFrame(i);
3199 if ( sf->getTypeView() == VIEW_PLOT2D ) {
3200 sf->getRightFrame()->getViewFrame()->setBackgroundColor( color );
3206 bgData.append( QString::number( color.red() ) );
3207 bgData.append( QString::number( color.green() ) );
3208 bgData.append( QString::number( color.blue() ) );
3209 QAD_CONFIG->addSetting( "Plot2d:Background", bgData.join( ":" ) );
3214 void QAD_Desktop::helpAbout()
3216 SALOMEGUI_AboutDlg* About = new SALOMEGUI_AboutDlg( QAD_Application::getDesktop(), tr("MEN_ABOUT"));
3222 void QAD_Desktop::helpSearch()
3227 void QAD_Desktop::helpContents()
3229 getHelpWindow()->contents();
3230 getHelpWindow()->show();
3231 getHelpWindow()->raise();
3232 getHelpWindow()->setActiveWindow();
3236 void QAD_Desktop::helpContext(const QString& source, const QString& context)
3238 getHelpWindow()->context(source, context);
3239 getHelpWindow()->show();
3240 getHelpWindow()->raise();
3241 getHelpWindow()->setActiveWindow();
3244 /* Preferences/MultiFile Save */
3245 void QAD_Desktop::onMultiFileSave()
3247 if ( myStdActions.at( PrefMultiFileSave )->isOn() )
3248 QAD_CONFIG->addSetting( "Desktop:MultiFileSave", "true");
3250 QAD_CONFIG->addSetting( "Desktop:MultiFileSave", "false");
3253 /* Preferences/ASCII Save */
3254 void QAD_Desktop::onASCIISave()
3256 if ( myStdActions.at( PrefASCIISave )->isOn() )
3257 QAD_CONFIG->addSetting( "Desktop:ASCIISave", "true");
3259 QAD_CONFIG->addSetting( "Desktop:ASCIISave", "false");
3262 /*********************************************************************
3263 ** Class: AppSelectionDlg
3264 ** Descr: Dialog for the selection of the application when several
3265 ** applications exist in the desktop and new study creation
3266 ** is activated by user.
3268 **********************************************************************/
3270 \class Desktop_AppSelectionDlg QAD_Desktop.h
3271 \brief Dialog for the selection of the application when several
3272 applications exist in the desktop and new study creation
3273 is activated by user.
3278 Desktop_AppSelectionDlg::Desktop_AppSelectionDlg( QAD_Desktop* desktop,
3279 QList<QAD_Application>& apps ) :
3280 QDialog( desktop, 0, true ),
3284 QAD_ASSERT_DEBUG_ONLY ( desktop );
3285 setCaption( tr("INF_DESK_DOC_CREATE") );
3286 if ( desktop->icon() )
3287 setIcon( *desktop->icon() );
3289 QBoxLayout* mainLayout = new QVBoxLayout( this, 5 );
3291 /* Create selection buttons */
3292 QVButtonGroup* buttonGrp = new QVButtonGroup ( this );
3293 buttonGrp->setExclusive ( true );
3294 QBoxLayout* vLayout = new QVBoxLayout( mainLayout, 5 );
3295 vLayout->addWidget ( buttonGrp );
3297 /* Create selection button for available app */
3299 for ( QAD_Application* app = myApps.first(); app; app = myApps.next(), id++ )
3301 /* add radio button for application */
3302 buttonGrp->insert( new QRadioButton( app->getStudyDescription() +
3303 " (*." + app->getStudyExtension() + ")", buttonGrp ), id );
3306 /* make the first application selected */
3307 buttonGrp->setButton( 0 );
3309 /* listen to the selection */
3310 QAD_ASSERT ( connect ( buttonGrp, SIGNAL(clicked(int)), this, SLOT(onAppSelected(int)) ));
3312 /* Create OK/Cancel buttons
3314 QBoxLayout* hLayout = new QHBoxLayout( mainLayout, 5 );
3315 QPushButton* buttonOK = new QPushButton( tr("BUT_OK"), this );
3316 QPushButton* buttonCancel = new QPushButton( tr("BUT_CANCEL"), this );
3317 QPushButton* buttonHelp = new QPushButton( tr("BUT_HELP"), this );
3318 buttonOK->setDefault( true );
3320 hLayout->addStretch();
3321 hLayout->addWidget( buttonOK );
3322 hLayout->addWidget( buttonCancel );
3323 hLayout->addWidget( buttonHelp );
3325 /* connect buttons */
3326 QAD_ASSERT ( connect( buttonOK, SIGNAL(clicked()), this, SLOT(accept())) );
3327 QAD_ASSERT ( connect( buttonCancel, SIGNAL(clicked()), this, SLOT(reject())) );
3328 QAD_ASSERT ( connect( buttonHelp, SIGNAL(clicked()), this, SLOT(onHelp())) );
3330 /* disable resizing */
3331 setFixedSize( 0, 0 );
3332 setSizePolicy( QSizePolicy ( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
3335 Desktop_AppSelectionDlg::~Desktop_AppSelectionDlg()
3339 QAD_Application* Desktop_AppSelectionDlg::selectedApp() const
3341 return myApps.at( myAppId );
3344 void Desktop_AppSelectionDlg::resizeEvent( QResizeEvent* e )
3346 QAD_Tools::centerWidget( this, parentWidget() );
3352 void Desktop_AppSelectionDlg::onAppSelected( int id )
3357 void Desktop_AppSelectionDlg::onHelp()