1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File: LightApp_Application.cxx
24 // Created: 6/20/2005 18:39:45 PM
25 // Author: Natalia Donis
28 // E.A. : On windows with python 2.6, there is a conflict
29 // E.A. : between pymath.h and Standard_math.h which define
30 // E.A. : some same symbols : acosh, asinh, ...
31 #include <Standard_math.hxx>
32 #ifndef DISABLE_PYCONSOLE
37 #ifndef DISABLE_PYCONSOLE
38 #include "LightApp_PyInterp.h" // WARNING! This include must be the first!
39 #include <PyConsole_Console.h>
42 #include "LightApp_Application.h"
43 #include "LightApp_Module.h"
44 #include "LightApp_DataModel.h"
45 #include "LightApp_DataOwner.h"
46 #include "LightApp_Study.h"
47 #include "LightApp_Preferences.h"
48 #include "LightApp_PreferencesDlg.h"
49 #include "LightApp_ModuleDlg.h"
50 #include "LightApp_AboutDlg.h"
51 #include "LightApp_ModuleAction.h"
52 // temporary commented
53 #include "LightApp_EventFilter.h"
54 #include "LightApp_OBSelector.h"
55 #include "LightApp_SelectionMgr.h"
56 #include "LightApp_DataObject.h"
57 #include "LightApp_WgViewModel.h"
58 #include "LightApp_FullScreenHelper.h"
61 #include <GUI_version.h>
62 #include <Basics_OCCTVersion.hxx>
64 #include <SALOME_Event.h>
66 #include <Style_Salome.h>
67 #include <Style_PrefDlg.h>
69 #include <CAM_Module.h>
70 #include <CAM_DataModel.h>
71 #include <CAM_Study.h>
72 #include <STD_TabDesktop.h>
74 #include <SUIT_DataBrowser.h>
75 #include <SUIT_Session.h>
76 #include <SUIT_Study.h>
77 #include <SUIT_FileDlg.h>
78 #include <SUIT_ResourceMgr.h>
79 #include <SUIT_ShortcutMgr.h>
80 #include <SUIT_Tools.h>
81 #include <SUIT_Accel.h>
82 #include <SUIT_MessageBox.h>
83 #include <SUIT_ViewWindow.h>
86 #include <QtxToolBar.h>
87 #include <QtxTreeView.h>
88 #include <QtxMRUAction.h>
89 #include <QtxDockAction.h>
90 #include <QtxDockWidget.h>
91 #include <QtxActionToolMgr.h>
92 #include <QtxSearchTool.h>
93 #include <QtxWorkstack.h>
95 #include <QtxWebBrowser.h>
97 #include <LogWindow.h>
99 #ifndef DISABLE_GLVIEWER
100 #include <GLViewer_Viewer.h>
101 #include <GLViewer_ViewManager.h>
102 #include "LightApp_GLSelector.h"
105 #ifndef DISABLE_PLOT2DVIEWER
106 #include <Plot2d_ViewManager.h>
107 #include <Plot2d_ViewModel.h>
108 #include <Plot2d_ViewWindow.h>
109 #include <Plot2d_ViewFrame.h>
110 #include "LightApp_Plot2dSelector.h"
111 #ifndef DISABLE_SALOMEOBJECT
112 #include <SPlot2d_ViewModel.h>
114 #include <Plot2d_ViewModel.h>
118 #ifndef DISABLE_OCCVIEWER
119 #include <OCCViewer_ViewManager.h>
120 #include <OCCViewer_ViewFrame.h>
121 #ifndef DISABLE_SALOMEOBJECT
122 #include <SOCC_ViewModel.h>
124 #include <OCCViewer_ViewModel.h>
126 #include "LightApp_OCCSelector.h"
129 #ifndef DISABLE_VTKVIEWER
130 #ifndef DISABLE_SALOMEOBJECT
131 #include <SVTK_ViewModel.h>
132 #include <SVTK_ViewManager.h>
133 #include "LightApp_VTKSelector.h"
135 #include <VTKViewer_ViewModel.h>
136 #include <VTKViewer_ViewManager.h>
138 #include <VTKViewer_ViewModel.h>
141 #ifndef DISABLE_QXGRAPHVIEWER
142 #include <QxScene_ViewManager.h>
143 #include <QxScene_ViewModel.h>
144 #include <QxScene_ViewWindow.h>
147 #ifndef DISABLE_GRAPHICSVIEW
148 #include "GraphicsView_Viewer.h"
149 #include "GraphicsView_ViewManager.h"
150 #include "LightApp_GVSelector.h"
153 #define VISIBILITY_COLUMN_WIDTH 25
159 #include <QStringList>
161 #include <QApplication>
163 #include <QStatusBar>
165 #include <QObjectList>
167 #include <QInputDialog>
168 #include <QFontDatabase>
170 #include <QByteArray>
174 #include <QHeaderView>
179 #include <utilities.h>
181 #define FIRST_HELP_ID 1000000
183 #ifndef DISABLE_SALOMEOBJECT
184 #include <SALOME_InteractiveObject.hxx>
185 #include <SALOME_ListIO.hxx>
188 #include <Standard_Version.hxx>
190 #define ToolBarMarker 0
191 #define DockWidgetMarker 1
193 static const char* imageEmptyIcon[] = {
196 "....................",
197 "....................",
198 "....................",
199 "....................",
200 "....................",
201 "....................",
202 "....................",
203 "....................",
204 "....................",
205 "....................",
206 "....................",
207 "....................",
208 "....................",
209 "....................",
210 "....................",
211 "....................",
212 "....................",
213 "....................",
214 "....................",
215 "...................."};
217 int LightApp_Application::lastStudyId = 0;
220 // Markers used to parse array with dockable windows and toolbars state.
221 // For more details please see the qdockarealayout.cpp && qtoolbararealayout.cpp
222 // in the Qt source code.
224 #define QDockWidgetMarker 0xfd // = DockWidgetStateMarker
225 #define QToolBarMarker 0xfc // = ToolBarStateMarkerEx
227 // Format of the Byte array with the windows and toolbar state is:
228 // VersionMarker|version|DockWidgetStateMarker|nbDockWidgetLines|...DocWidgetData...|ToolBarStateMarkerEx|nbToolBarLines|...ToolBarData...
230 //Find toolbar marker position in the array in the following way:
231 //since the 'toolbar marker' is not unique, find index of first occurrence of the
232 //'toolbar marker' in the array and check that next string is name of the toolbar
234 int getToolbarMarkerIndex(QByteArray input, const QStringList& aFlags) {
235 int aResult = -1,tmp = 0;
236 int inputLen = input.length();
237 QDataStream anInputData(&input, QIODevice::ReadOnly);
238 while(tmp < inputLen) {
239 tmp = input.indexOf(QToolBarMarker, tmp + 1);
242 anInputData.device()->seek(tmp);
246 anInputData >> lines;
248 if(lines == 0 && anInputData.atEnd()){
249 //Case then array doesn't contain information about toolbars,
260 if(aFlags.contains(str)) {
269 \return last global id of study
271 int LightApp_Application::studyId()
273 return LightApp_Application::lastStudyId;
276 /*!Create new instance of LightApp_Application.*/
277 extern "C" LIGHTAPP_EXPORT SUIT_Application* createApplication()
279 return new LightApp_Application();
282 /*! \var global preferences of LightApp */
283 LightApp_Preferences* LightApp_Application::_prefs_ = 0;
287 \class LightApp_Application
288 Application containing LightApp module
292 LightApp_Application::LightApp_Application()
293 : CAM_Application( false ),
295 myScreenHelper(new LightApp_FullScreenHelper())
297 Q_INIT_RESOURCE( LightApp );
299 STD_TabDesktop* desk = new STD_TabDesktop();
300 desk->setFullScreenAllowed(false);
301 desk->setMinimizeAllowed(false);
305 // initialize auto save timer
306 myAutoSaveTimer = new QTimer( this );
307 myAutoSaveTimer->setSingleShot( true );
308 connect( myAutoSaveTimer, SIGNAL( timeout() ), this, SLOT( onSaveDoc() ) );
310 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
311 QPixmap aLogo = aResMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false );
313 QtxWebBrowser::setResourceManager( aResMgr );
314 QtxWebBrowser::setData("browser:icon", aResMgr->loadPixmap( "LightApp", tr( "BROWSER_ICON" ) ) );
315 QtxWebBrowser::setData("browser:title", tr( "BROWSER_TITLE" ) );
316 QtxWebBrowser::setData("toolbar:title", tr( "BROWSER_TOOLBAR_TITLE" ) );
317 QtxWebBrowser::setData("menu:file:title", tr( "BROWSER_FILEMENU" ) );
318 QtxWebBrowser::setData("action:close:title", tr( "BROWSER_CLOSE" ) );
319 QtxWebBrowser::setData("action:close:icon", aResMgr->loadPixmap( "LightApp", tr( "BROWSER_CLOSE_ICON" ) ) );
320 QtxWebBrowser::setData("action:back:title", tr( "BROWSER_BACK" ) );
321 QtxWebBrowser::setData("action:forward:title", tr( "BROWSER_FORWARD" ) );
322 QtxWebBrowser::setData("action:find:title", tr( "BROWSER_FIND" ) );
323 QtxWebBrowser::setData("action:findnext:title", tr( "BROWSER_FINDNEXT" ) );
324 QtxWebBrowser::setData("action:findprev:title", tr( "BROWSER_FINDPREV" ) );
326 desktop()->setWindowIcon( aLogo );
327 desktop()->setDockableMenuBar( false );
328 desktop()->setDockableStatusBar( false );
330 // base logo (salome itself)
331 desktop()->logoInsert( "_app_base", aResMgr->loadPixmap( "LightApp", tr( "APP_BASE_LOGO" ), false ) );
332 // extra logo (salome-based application)
333 desktop()->logoInsert( "_app_extra", aResMgr->loadPixmap( "LightApp", tr( "APP_EXTRA_LOGO" ), false ) );
337 mySelMgr = new LightApp_SelectionMgr( this );
339 myAccel = SUIT_Accel::getAccel();
341 #ifndef DISABLE_OCCVIEWER
342 myAccel->setActionKey( SUIT_Accel::PanLeft, Qt::CTRL+Qt::Key_Left, OCCViewer_Viewer::Type() );
343 myAccel->setActionKey( SUIT_Accel::PanRight, Qt::CTRL+Qt::Key_Right, OCCViewer_Viewer::Type() );
344 myAccel->setActionKey( SUIT_Accel::PanUp, Qt::CTRL+Qt::Key_Up, OCCViewer_Viewer::Type() );
345 myAccel->setActionKey( SUIT_Accel::PanDown, Qt::CTRL+Qt::Key_Down, OCCViewer_Viewer::Type() );
346 myAccel->setActionKey( SUIT_Accel::ZoomIn, Qt::CTRL+Qt::Key_Plus, OCCViewer_Viewer::Type() );
347 myAccel->setActionKey( SUIT_Accel::ZoomOut, Qt::CTRL+Qt::Key_Minus, OCCViewer_Viewer::Type() );
348 myAccel->setActionKey( SUIT_Accel::ZoomFit, Qt::CTRL+Qt::Key_Asterisk, OCCViewer_Viewer::Type() );
349 myAccel->setActionKey( SUIT_Accel::ZoomFit, Qt::Key_Space, OCCViewer_Viewer::Type() );
350 myAccel->setActionKey( SUIT_Accel::RotateLeft, Qt::ALT+Qt::Key_Left, OCCViewer_Viewer::Type() );
351 myAccel->setActionKey( SUIT_Accel::RotateRight, Qt::ALT+Qt::Key_Right, OCCViewer_Viewer::Type() );
352 myAccel->setActionKey( SUIT_Accel::RotateUp, Qt::ALT+Qt::Key_Up, OCCViewer_Viewer::Type() );
353 myAccel->setActionKey( SUIT_Accel::RotateDown, Qt::ALT+Qt::Key_Down, OCCViewer_Viewer::Type() );
355 #ifndef DISABLE_VTKVIEWER
356 myAccel->setActionKey( SUIT_Accel::PanLeft, Qt::CTRL+Qt::Key_Left, VTKViewer_Viewer::Type() );
357 myAccel->setActionKey( SUIT_Accel::PanRight, Qt::CTRL+Qt::Key_Right, VTKViewer_Viewer::Type() );
358 myAccel->setActionKey( SUIT_Accel::PanUp, Qt::CTRL+Qt::Key_Up, VTKViewer_Viewer::Type() );
359 myAccel->setActionKey( SUIT_Accel::PanDown, Qt::CTRL+Qt::Key_Down, VTKViewer_Viewer::Type() );
360 myAccel->setActionKey( SUIT_Accel::ZoomIn, Qt::CTRL+Qt::Key_Plus, VTKViewer_Viewer::Type() );
361 myAccel->setActionKey( SUIT_Accel::ZoomOut, Qt::CTRL+Qt::Key_Minus, VTKViewer_Viewer::Type() );
362 myAccel->setActionKey( SUIT_Accel::ZoomFit, Qt::CTRL+Qt::Key_Asterisk, VTKViewer_Viewer::Type() );
363 myAccel->setActionKey( SUIT_Accel::ZoomFit, Qt::Key_Space, VTKViewer_Viewer::Type() );
364 myAccel->setActionKey( SUIT_Accel::RotateLeft, Qt::ALT+Qt::Key_Left, VTKViewer_Viewer::Type() );
365 myAccel->setActionKey( SUIT_Accel::RotateRight, Qt::ALT+Qt::Key_Right, VTKViewer_Viewer::Type() );
366 myAccel->setActionKey( SUIT_Accel::RotateUp, Qt::ALT+Qt::Key_Up, VTKViewer_Viewer::Type() );
367 myAccel->setActionKey( SUIT_Accel::RotateDown, Qt::ALT+Qt::Key_Down, VTKViewer_Viewer::Type() );
369 #ifndef DISABLE_PLOT2DVIEWER
370 myAccel->setActionKey( SUIT_Accel::PanLeft, Qt::CTRL+Qt::Key_Left, Plot2d_Viewer::Type() );
371 myAccel->setActionKey( SUIT_Accel::PanRight, Qt::CTRL+Qt::Key_Right, Plot2d_Viewer::Type() );
372 myAccel->setActionKey( SUIT_Accel::PanUp, Qt::CTRL+Qt::Key_Up, Plot2d_Viewer::Type() );
373 myAccel->setActionKey( SUIT_Accel::PanDown, Qt::CTRL+Qt::Key_Down, Plot2d_Viewer::Type() );
374 myAccel->setActionKey( SUIT_Accel::ZoomIn, Qt::CTRL+Qt::Key_Plus, Plot2d_Viewer::Type() );
375 myAccel->setActionKey( SUIT_Accel::ZoomOut, Qt::CTRL+Qt::Key_Minus, Plot2d_Viewer::Type() );
376 myAccel->setActionKey( SUIT_Accel::ZoomFit, Qt::CTRL+Qt::Key_Asterisk, Plot2d_Viewer::Type() );
377 myAccel->setActionKey( SUIT_Accel::ZoomFit, Qt::Key_Space, Plot2d_Viewer::Type() );
380 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) );
382 // Set existing font for the python console in resources
383 if( !aResMgr->hasValue( "PyConsole", "font" ) )
386 QFont f = aResMgr->fontValue( "PyConsole", "font" );
388 QStringList famdb = fdb.families();
390 if ( famdb.contains(f.family()) || !aResMgr->hasValue( "PyConsole", "additional_families" ) )
393 QStringList anAddFamilies = aResMgr->stringValue( "PyConsole", "additional_families" ).split( ";", QString::SkipEmptyParts );
395 for ( QStringList::Iterator it = anAddFamilies.begin(); it != anAddFamilies.end(); ++it )
398 if ( famdb.contains(aFamily) )
400 f.setFamily( aFamily );
401 aResMgr->setValue( "PyConsole", "font", f );
408 *\li Save window geometry.
409 *\li Save desktop geometry.
410 *\li Save resource maneger.
411 *\li Delete selection manager.
413 LightApp_Application::~LightApp_Application()
416 delete myScreenHelper;
419 /*!Start application.*/
420 void LightApp_Application::start()
422 CAM_Application::start();
425 updateViewManagers();
428 desktop()->statusBar()->showMessage( "" );
430 LightApp_EventFilter::Init();
433 /*!Gets application name.*/
434 QString LightApp_Application::applicationName() const
436 static QString _app_name;
437 if ( _app_name.isEmpty() )
438 _app_name = tr( "APP_NAME" );
442 /*!Gets application version.*/
443 QString LightApp_Application::applicationVersion() const
445 static QString _app_version;
447 if ( _app_version.isEmpty() )
449 QString resVersion = tr( "APP_VERSION" );
450 if ( resVersion != "APP_VERSION" )
452 _app_version = resVersion;
456 _app_version = GUI_VERSION_STR;
462 /*!Load module by \a name.*/
463 CAM_Module* LightApp_Application::loadModule( const QString& name, const bool showMsg )
465 CAM_Module* mod = CAM_Application::loadModule( name, showMsg );
468 connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) );
469 connect( this, SIGNAL( studySaved() ), mod, SLOT( onModelSaved() ) );
470 connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) );
475 /*!Activate module by \a modName*/
476 bool LightApp_Application::activateModule( const QString& modName )
479 CAM_Module* prevMod = activeModule();
482 actName = prevMod->moduleName();
484 if ( actName == modName )
487 putInfo( tr( "ACTIVATING_MODULE" ).arg( modName ) );
489 saveDockWindowsState();
491 bool status = CAM_Application::activateModule( modName );
493 updateModuleActions();
501 updateViewManagers();
506 /*!Gets selection manager.*/
507 LightApp_SelectionMgr* LightApp_Application::selectionMgr() const
512 /*!Creat action "New window" for certain type of viewer:*/
513 void LightApp_Application::createActionForViewer( const int id,
515 const QString& suffix,
518 QString vtlt = tr( QString( "NEW_WINDOW_%1" ).arg( suffix ).toLatin1().constData() );
519 QString tip = tr( "CREATING_NEW_WINDOW" ).arg( vtlt.remove( "&" ) );
520 QAction* a = createAction( id, // menu action id
527 false, // toggle flag
529 SLOT( onNewWindow() ) ); // slot
530 createMenu( a, parentId, -1 );
535 void LightApp_Application::createActions()
537 CAM_Application::createActions();
539 SUIT_Desktop* desk = desktop();
540 SUIT_ResourceMgr* resMgr = resourceMgr();
543 createAction( PreferencesId, tr( "TOT_DESK_PREFERENCES" ), QIcon(),
544 tr( "MEN_DESK_PREFERENCES" ), tr( "PRP_DESK_PREFERENCES" ),
545 Qt::CTRL+Qt::Key_R, desk, false, this, SLOT( onPreferences() ) );
549 // - Help for modules
551 int helpMenu = createMenu( tr( "MEN_DESK_HELP" ), -1, -1, 1000 );
552 createMenu( separator(), helpMenu, -1, 10 );
553 QStringList aModuleList;
554 modules( aModuleList, false );
555 aModuleList.prepend( "GUI" );
556 aModuleList.prepend( "KERNEL" );
558 int id = LightApp_Application::UserID + FIRST_HELP_ID;
561 foreach( aModule, aModuleList ) {
562 if ( aModule.isEmpty() ) // module title (user name)
564 IMap <QString, QString> helpData; // list of help files for the module
565 QString helpSubMenu; // help submenu name (empty if not needed)
566 QString modName = moduleName( aModule ); // module name
567 if ( modName.isEmpty() ) modName = aModule; // for KERNEL and GUI
568 QString rootDir = QString( "%1_ROOT_DIR" ).arg( modName ); // module root dir variable
569 QString modDir = getenv( rootDir.toLatin1().constData() ); // module root dir
571 if (resMgr->hasValue( modName, "documentation" ) )
572 docSection = resMgr->stringValue(modName, "documentation");
573 else if ( resMgr->hasSection( modName + "_documentation" ) )
574 docSection = modName + "_documentation";
575 if ( !docSection.isEmpty() ) {
576 helpSubMenu = resMgr->stringValue( docSection, "sub_menu", "" ).arg( aModule );
577 QStringList listOfParam = resMgr->parameters( docSection );
578 foreach( QString paramName, listOfParam ) {
579 QString valueStr = resMgr->stringValue( docSection, paramName );
580 if ( !valueStr.isEmpty() ) {
581 QFileInfo fi( valueStr );
582 if ( fi.isRelative() && !modDir.isEmpty() )
583 valueStr = Qtx::addSlash( modDir ) + valueStr;
584 if ( QFile::exists( valueStr ) )
585 helpData.insert( paramName.arg( aModule ), valueStr );
590 if ( helpData.isEmpty() && !modDir.isEmpty() ) {
591 QStringList idxLst = QStringList() << modDir << "share" << "doc" << "salome" << "gui" << modName << "index.html";
592 QString indexFile = idxLst.join( QDir::separator() ); // index file
593 if ( QFile::exists( indexFile ) )
594 helpData.insert( tr( "%1 module Users's Guide" ).arg( aModule ), indexFile );
597 IMapConstIterator<QString, QString > fileIt;
598 for ( fileIt = helpData.begin(); fileIt != helpData.end(); fileIt++ ) {
599 QString helpFileName = fileIt.key();
600 // remove all '//' occurances
601 while ( helpFileName.contains( "//" ) )
602 helpFileName.replace( "//", "" );
603 // obtain submenus hierarchy if given
604 QStringList smenus = helpFileName.split( "/" );
605 helpFileName = smenus.last();
607 QAction* a = createAction( id, helpFileName,
608 resMgr->loadPixmap( "STD", tr( "ICON_HELP" ), false ),
609 helpFileName, helpFileName,
610 0, desk, false, this, SLOT( onHelpContentsModule() ) );
611 a->setData( fileIt.value() );
612 if ( !helpSubMenu.isEmpty() ) {
613 smenus.prepend( helpSubMenu );
615 // create sub-menus hierarchy
616 int menuId = helpMenu;
617 foreach ( QString subMenu, smenus ) {
618 menuId = createMenu( subMenu, menuId, -1, 0 );
620 createMenu( a, menuId, -1, 0 );
625 // - Additional help items
627 createMenu( separator(), helpMenu, -1, 5 );
629 QStringList addHelpItems = resMgr->parameters( "add_help" );
630 foreach ( QString addHelpItem, addHelpItems ) {
631 QString valueStr = resMgr->stringValue( "add_help", addHelpItem );
632 if ( !valueStr.isEmpty() && QFile::exists( valueStr ) ) {
633 QAction* a = createAction( id, addHelpItem,
634 resMgr->loadPixmap( "STD", tr( "ICON_HELP" ), false ),
635 addHelpItem, addHelpItem,
636 0, desk, false, this, SLOT( onHelpContentsModule() ) );
637 a->setData( valueStr );
638 createMenu( a, helpMenu, -1, 5 );
644 static QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), 0 );
645 connect( mru, SIGNAL( activated( const QString& ) ), this, SLOT( onMRUActivated( const QString& ) ) );
646 registerAction( MRUId, mru );
648 // default icon for neutral point ('SALOME' module)
649 QPixmap defIcon = resMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false );
650 if ( defIcon.isNull() )
651 defIcon = QPixmap( imageEmptyIcon );
653 //! default icon for any module
654 QPixmap modIcon = resMgr->loadPixmap( "LightApp", tr( "APP_MODULE_ICO" ), false );
655 if ( modIcon.isNull() )
656 modIcon = QPixmap( imageEmptyIcon );
659 modules( modList, false );
661 if ( modList.count() > 1 )
663 LightApp_ModuleAction* moduleAction =
664 new LightApp_ModuleAction( tr( "APP_NAME" ), defIcon, desk );
666 QMap<QString, QString> iconMap;
667 moduleIconNames( iconMap );
669 const int iconSize = 20;
671 QStringList::Iterator it;
672 for ( it = modList.begin(); it != modList.end(); ++it )
674 if ( !isLibExists( *it ) )
677 QString modName = moduleName( *it );
679 if ( !isModuleAccessible( *it ) )
683 if ( iconMap.contains( *it ) )
684 iconName = iconMap[*it];
686 QPixmap icon = resMgr->loadPixmap( modName, iconName, false );
690 INFOS ( "\n****************************************************************" << std::endl
691 << "* Icon for " << (*it).toLatin1().constData()
692 << " not found. Using the default one." << std::endl
693 << "****************************************************************" << std::endl );
696 icon = Qtx::scaleIcon( icon, iconSize );
698 moduleAction->insertModule( *it, icon );
701 connect( moduleAction, SIGNAL( moduleActivated( const QString& ) ),
702 this, SLOT( onModuleActivation( const QString& ) ) );
703 registerAction( ModulesListId, moduleAction );
707 int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, MenuWindowId, 100 );
708 int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
710 createAction( CloseId, tr( "TOT_CLOSE" ), QIcon(), tr( "MEN_DESK_CLOSE" ), tr( "PRP_CLOSE" ),
711 Qt::CTRL+Qt::Key_F4, desk, false, this, SLOT( onCloseWindow() ) );
712 createAction( CloseAllId, tr( "TOT_CLOSE_ALL" ), QIcon(), tr( "MEN_DESK_CLOSE_ALL" ), tr( "PRP_CLOSE_ALL" ),
713 0, desk, false, this, SLOT( onCloseAllWindow() ) );
714 createAction( GroupAllId, tr( "TOT_GROUP_ALL" ), QIcon(), tr( "MEN_DESK_GROUP_ALL" ), tr( "PRP_GROUP_ALL" ),
715 0, desk, false, this, SLOT( onGroupAllWindow() ) );
717 createMenu( CloseId, windowMenu, 0, -1 );
718 createMenu( CloseAllId, windowMenu, 0, -1 );
719 createMenu( GroupAllId, windowMenu, 0, -1 );
720 createMenu( separator(), windowMenu, -1, 0 );
722 #ifndef DISABLE_GLVIEWER
723 createActionForViewer( NewGLViewId, newWinMenu, QString::number( 0 ), Qt::ALT+Qt::Key_G );
725 #ifndef DISABLE_PLOT2DVIEWER
726 createActionForViewer( NewPlot2dId, newWinMenu, QString::number( 1 ), Qt::ALT+Qt::Key_P );
728 #ifndef DISABLE_OCCVIEWER
729 createActionForViewer( NewOCCViewId, newWinMenu, QString::number( 2 ), Qt::ALT+Qt::Key_O );
731 #ifndef DISABLE_VTKVIEWER
732 createActionForViewer( NewVTKViewId, newWinMenu, QString::number( 3 ), Qt::ALT+Qt::Key_K );
734 #ifndef DISABLE_QXGRAPHVIEWER
735 createActionForViewer( NewQxSceneViewId, newWinMenu, QString::number( 4 ), Qt::ALT+Qt::Key_S );
737 #ifndef DISABLE_GRAPHICSVIEW
738 createActionForViewer( NewGraphicsViewId, newWinMenu, QString::number( 5 ), Qt::ALT+Qt::Key_R );
741 createAction( RenameId, tr( "TOT_RENAME" ), QIcon(), tr( "MEN_DESK_RENAME" ), tr( "PRP_RENAME" ),
742 Qt::ALT+Qt::SHIFT+Qt::Key_R, desk, false, this, SLOT( onRenameWindow() ) );
743 createMenu( RenameId, windowMenu, -1 );
745 int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
746 createMenu( PreferencesId, fileMenu, 50, -1 );
747 createMenu( separator(), fileMenu, -1, 50, -1 );
749 createMenu( separator(), fileMenu, -1, 100, -1 );
750 createMenu( MRUId, fileMenu, 100, -1 );
751 createMenu( separator(), fileMenu, -1, 100, -1 );
753 createAction( StyleId, tr( "TOT_THEME" ), QIcon(), tr( "MEN_DESK_THEME" ), tr( "PRP_THEME" ),
754 0, desk, false, this, SLOT( onStylePreferences() ) );
756 createAction( FullScreenId, tr( "TOT_FULLSCREEN" ), QIcon(), tr( "MEN_DESK_FULLSCREEN" ), tr( "PRP_FULLSCREEN" ),
757 Qt::Key_F11, desk, false, this, SLOT( onFullScreen() ) );
760 int viewMenu = createMenu( tr( "MEN_DESK_VIEW" ), -1 );
761 createMenu( separator(), viewMenu, -1, 20, -1 );
762 createMenu( StyleId, viewMenu, 20, -1 );
763 createMenu( FullScreenId, viewMenu, 20, -1 );
765 int modTBar = createTool( tr( "INF_TOOLBAR_MODULES" ) );
766 createTool( ModulesListId, modTBar );
769 /*!On module activation action.*/
770 void LightApp_Application::onModuleActivation( const QString& modName )
772 // Force user to create/open a study before module activation
773 QMap<QString, QString> iconMap;
774 moduleIconNames( iconMap );
775 QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ], false );
777 icon = resourceMgr()->loadPixmap( "LightApp", tr( "APP_MODULE_BIG_ICO" ), false ); // default icon for any module
779 bool cancelled = false;
781 while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
782 LightApp_ModuleDlg aDlg( desktop(), modName, icon );
783 QMap<int, QString> opmap = activateModuleActions();
784 for ( QMap<int, QString>::ConstIterator it = opmap.begin(); it != opmap.end(); ++it )
785 aDlg.addButton( it.value(), it.key() );
787 int res = aDlg.exec();
789 // some operation is selected
790 moduleActionSelected( res );
794 putInfo( tr("INF_CANCELLED") );
796 LightApp_ModuleAction* moduleAction =
797 qobject_cast<LightApp_ModuleAction*>( action( ModulesListId ) );
799 moduleAction->setActiveModule( QString() );
805 activateModule( modName );
808 /*!Default module activation.*/
809 QString LightApp_Application::defaultModule() const
811 QStringList aModuleNames;
812 modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration
813 //! If there's the one and only module --> activate it automatically
814 //! TODO: Possible improvement - default module can be taken from preferences
815 return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" );
818 /*!On new window slot.*/
819 void LightApp_Application::onNewWindow()
821 const QObject* obj = sender();
822 if ( !obj || !obj->inherits( "QAction" ) )
826 int id = actionId( (QAction*)obj );
829 #ifndef DISABLE_GLVIEWER
831 type = GLViewer_Viewer::Type();
834 #ifndef DISABLE_PLOT2DVIEWER
836 type = Plot2d_Viewer::Type();
839 #ifndef DISABLE_OCCVIEWER
841 type = OCCViewer_Viewer::Type();
844 #ifndef DISABLE_VTKVIEWER
846 type = VTKViewer_Viewer::Type();
849 #ifndef DISABLE_QXGRAPHVIEWER
850 case NewQxSceneViewId:
851 type = QxScene_Viewer::Type();
854 #ifndef DISABLE_GRAPHICSVIEW
855 case NewGraphicsViewId:
856 type = GraphicsView_Viewer::Type();
861 if ( !type.isEmpty() )
862 createViewManager( type );
866 SLOT: Creates new document
868 void LightApp_Application::onNewDoc()
870 //asl: fix for 0020515
872 saveDockWindowsState();
874 CAM_Application::onNewDoc();
878 SLOT: Opens new document
880 void LightApp_Application::onOpenDoc()
882 SUIT_Study* study = activeStudy();
883 saveDockWindowsState();
885 CAM_Application::onOpenDoc();
887 if ( !study ) // new study will be create in THIS application
890 updateViewManagers();
895 SLOT: Opens new document.
896 \param aName - name of file
898 bool LightApp_Application::onOpenDoc( const QString& aName )
900 // We should take mru action first because this application instance can be deleted later.
901 QtxMRUAction* mru = ::qobject_cast<QtxMRUAction*>( action( MRUId ) );
903 bool res = CAM_Application::onOpenDoc( aName );
908 mru->insert( aName );
910 mru->remove( aName );
916 SLOT: Displays "About" message box
918 void LightApp_Application::onHelpAbout()
920 LightApp_AboutDlg dlg( applicationName(), applicationVersion(), desktop() );
925 Private SLOT: Called on selection is changed
926 Dispatchs active module that selection is changed
928 void LightApp_Application::onSelection()
930 onSelectionChanged();
932 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
933 ((LightApp_Module*)activeModule())->selectionChanged();
938 \param study - SUIT_Study.
940 void LightApp_Application::setActiveStudy( SUIT_Study* study )
942 CAM_Application::setActiveStudy( study );
946 Enables/Disables menu items and toolbar buttons. Rebuild menu
948 void LightApp_Application::updateCommandsStatus()
950 CAM_Application::updateCommandsStatus();
953 #ifndef DISABLE_GLVIEWER
954 a = action( NewGLViewId );
956 a->setEnabled( activeStudy() );
959 #ifndef DISABLE_PLOT2DVIEWER
960 a = action( NewPlot2dId );
962 a->setEnabled( activeStudy() );
965 #ifndef DISABLE_OCCVIEWER
966 a = action( NewOCCViewId );
968 a->setEnabled( activeStudy() );
971 #ifndef DISABLE_VTKVIEWER
972 a = action( NewVTKViewId );
974 a->setEnabled( activeStudy() );
977 #ifndef DISABLE_QXGRAPHVIEWER
978 a = action( NewQxSceneViewId );
980 a->setEnabled( activeStudy() );
983 #ifndef DISABLE_GRAPHICSVIEW
984 a = action( NewGraphicsViewId );
986 a->setEnabled( activeStudy() );
992 Runs system command in separate thread
994 class RunBrowser: public QThread
997 RunBrowser( LightApp_Application* app,
998 const QString& theApp,
999 const QString& theParams,
1000 const QString& theHelpFile,
1001 const QString& theContext = QString() )
1003 myParams( theParams ),
1004 myContext( theContext ),
1008 //For the external browser always specify 'file://' protocol,
1009 //because some WEB browsers (for example Mozilla Firefox) can't open local file without protocol.
1010 myHelpFile = QString("file://%1").arg( QFileInfo( theHelpFile ).canonicalFilePath() );
1015 if ( !myApp.isEmpty() && !myHelpFile.isEmpty()) {
1016 QString aCommand = QString( "%1 %2 \"%3%4\"" ).arg( myApp, myParams, myHelpFile, myContext.isEmpty() ? QString("") : QString( "#%1" ).arg( myContext ) );
1018 QProcess* proc = new QProcess();
1020 proc->start( aCommand );
1021 if ( !proc->waitForStarted() ) {
1022 SALOME_CustomEvent* ce2000 = new SALOME_CustomEvent( 2000 );
1023 QString* msg = new QString( QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).arg( myApp, myHelpFile ) );
1024 ce2000->setData( msg );
1025 QApplication::postEvent( myLApp, ce2000 );
1036 LightApp_Application* myLApp;
1040 SLOT: Displays help contents for choosen module
1042 void LightApp_Application::onHelpContentsModule()
1044 const QAction* a = (QAction*) sender();
1045 QString helpFile = a->data().toString();
1046 if ( helpFile.isEmpty() ) return;
1048 SUIT_ResourceMgr* resMgr = resourceMgr();
1051 platform = "winapplication";
1053 platform = "application";
1055 QString anApp = resMgr->stringValue("ExternalBrowser", platform);
1057 QString quote("\"");
1058 anApp.prepend( quote );
1059 anApp.append( quote );
1061 QString aParams = resMgr->stringValue("ExternalBrowser", "parameters");
1062 bool useExtBrowser = resMgr->booleanValue("ExternalBrowser", "use_external_browser", false );
1064 if( useExtBrowser ) {
1065 if ( !anApp.isEmpty() ) {
1066 RunBrowser* rs = new RunBrowser( this, anApp, aParams, helpFile );
1070 if ( SUIT_MessageBox::question( desktop(), tr( "WRN_WARNING" ), tr( "DEFINE_EXTERNAL_BROWSER" ),
1071 SUIT_MessageBox::Yes | SUIT_MessageBox::No,
1072 SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes )
1074 showPreferences( tr( "PREF_APP" ) );
1079 // On Win32 platform QWebKit of the Qt 4.6.3 hang up in case 'file://' protocol
1080 // is defined. On Linux platform QWebKit doesn't work correctly without 'file://' protocol.
1081 QtxWebBrowser::loadUrl(helpFile);
1083 QtxWebBrowser::loadUrl(QString("file://%1").arg(helpFile));
1089 SLOT: Displays help contents for choosen dialog
1091 void LightApp_Application::onHelpContextModule( const QString& theComponentName,
1092 const QString& theFileName,
1093 const QString& theContext )
1095 QString fileName = theFileName;
1096 QString context = theContext;
1097 if ( !QFile::exists( fileName ) && theContext.isEmpty() ) {
1098 // context might be passed within theFileName argument
1099 QStringList comps = fileName.split("#");
1100 if ( comps.count() > 1 ) {
1101 context = comps.last();
1103 fileName = comps.join("#");
1107 QString homeDir = "";
1108 if ( !theComponentName.isEmpty() ) {
1109 QString dir = getenv( ( theComponentName + "_ROOT_DIR" ).toLatin1().constData() );
1110 if ( !dir.isEmpty() )
1111 homeDir = Qtx::addSlash( Qtx::addSlash( dir ) +
1112 Qtx::addSlash( "share" ) +
1113 Qtx::addSlash( "doc" ) +
1114 Qtx::addSlash( "salome" ) +
1115 Qtx::addSlash( "gui" ) +
1116 Qtx::addSlash( theComponentName ) );
1119 QString helpFile = QFileInfo( homeDir + fileName ).absoluteFilePath();
1120 SUIT_ResourceMgr* resMgr = resourceMgr();
1123 platform = "winapplication";
1125 platform = "application";
1127 QString anApp = resMgr->stringValue("ExternalBrowser", platform);
1129 QString quote("\"");
1130 anApp.prepend( quote );
1131 anApp.append( quote );
1134 bool useExtBrowser = resMgr->booleanValue("ExternalBrowser", "use_external_browser", false );
1137 QString aParams = resMgr->stringValue("ExternalBrowser", "parameters");
1139 if ( !anApp.isEmpty() ) {
1140 RunBrowser* rs = new RunBrowser( this, anApp, aParams, helpFile, context );
1144 if ( SUIT_MessageBox::question( desktop(), tr( "WRN_WARNING" ), tr( "DEFINE_EXTERNAL_BROWSER" ),
1145 SUIT_MessageBox::Yes | SUIT_MessageBox::No,
1146 SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes )
1147 showPreferences( tr( "PREF_APP" ) );
1152 // On Win32 platform QWebKit of the Qt 4.6.3 hang up in case 'file://' protocol
1153 // is defined. On Linux platform QWebKit doesn't work correctly without 'file://' protocol.
1154 QtxWebBrowser::loadUrl(helpFile, context);
1156 QtxWebBrowser::loadUrl(QString("file://%1").arg(helpFile), context);
1163 Sets enable or disable some actions on selection changed.
1165 void LightApp_Application::onSelectionChanged()
1167 LightApp_Module* m = dynamic_cast<LightApp_Module*>( activeModule() );
1168 bool canCopy = m ? m->canCopy() : false;
1169 bool canPaste = m ? m->canPaste() : false;
1171 action( EditCopyId )->setEnabled(canCopy);
1172 action( EditPasteId )->setEnabled(canPaste);
1176 Adds window to application.
1177 \param wid - QWidget
1178 \param flag - key for window
1179 \param studyId - study id
1180 Flag used how identificator of window in windows list.
1183 void LightApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
1191 if ( !activeStudy() )
1194 sId = activeStudy()->id();
1197 if ( !myWindows.contains( flag ) )
1199 QMap<int, int> winMap;
1200 currentWindows( winMap );
1202 LightApp_WidgetContainer* newWC = new LightApp_WidgetContainer( flag, desktop() );
1203 connect( newWC, SIGNAL( destroyed ( QObject* ) ), this, SLOT( onWCDestroyed( QObject* ) ) );
1204 // asv: connecting a slot for storing visibility flag of a window
1205 connect( newWC, SIGNAL( visibilityChanged ( bool ) ), SLOT( onVisibilityChanged( bool ) ) );
1206 myWindows.insert( flag, newWC );
1207 if ( winMap.contains( flag ) ) {
1208 //desktop()->removeDockWidget( myWindows[flag] );
1209 desktop()->addDockWidget( (Qt::DockWidgetArea)winMap[flag], myWindows[flag] );
1212 //myWindows[flag]->setResizeEnabled( true );
1213 myWindows[flag]->setFeatures( QDockWidget::AllDockWidgetFeatures );
1214 myWindows[flag]->setObjectName( QString( "dock_window_%1" ).arg( flag ) );
1215 //myWindows[flag]->setFixedExtentWidth( wid->width() );
1216 //myWindows[flag]->setFixedExtentHeight( wid->height() );
1217 myWindows[flag]->resize( wid->width(), wid->height() );
1221 #ifndef DISABLE_PYCONSOLE
1222 if( wid->inherits( "PyConsole_Console" ) )
1224 if( resourceMgr()->hasValue( "PyConsole", "font" ) )
1225 f = resourceMgr()->fontValue( "PyConsole", "font" );
1228 f = ( ( PyConsole_Console* )wid )->font();
1229 resourceMgr()->setValue( "PyConsole", "font", f );
1236 myWindows[flag]->insert( sId, wid );
1239 setWindowShown( flag, !myWindows[flag]->isEmpty() );
1243 QWidget* LightApp_Application::dockWindow( const int id ) const
1246 if ( myWin.contains( id ) )
1251 QDockWidget* LightApp_Application::windowDock( QWidget* wid ) const
1256 QDockWidget* dock = 0;
1257 QWidget* w = wid->parentWidget();
1258 while ( w && !dock )
1260 dock = ::qobject_cast<QDockWidget*>( w );
1261 w = w->parentWidget();
1266 void LightApp_Application::insertDockWindow( const int id, QWidget* wid )
1271 if ( wid != dockWindow( id ) )
1272 removeDockWindow( id );
1274 myWin.insert( id, wid );
1276 QtxDockWidget* dock = new QtxDockWidget( true, desktop() );
1277 connect( dock, SIGNAL( destroyed( QObject* ) ), this, SLOT( onWCDestroyed( QObject* ) ) );
1279 dock->setFeatures( QDockWidget::AllDockWidgetFeatures );
1280 dock->setObjectName( QString( "window_%1" ).arg( id ) );
1281 dock->setWidget( wid );
1283 QKeySequence accel = wid->property( "shortcut" ).value<QKeySequence>();
1284 if ( !accel.isEmpty() )
1285 dock->toggleViewAction()->setShortcut( accel );
1290 void LightApp_Application::removeDockWindow( const int id )
1292 QWidget* wid = dockWindow( id );
1298 QDockWidget* dock = windowDock( wid );
1302 dock->setWidget( 0 );
1303 wid->setParent( 0 );
1304 wid->setVisible( false );
1308 void LightApp_Application::placeDockWindow( const int id, Qt::DockWidgetArea place )
1310 QDockWidget* dock = windowDock( dockWindow( id ) );
1311 if ( dock && desktop() ) {
1312 desktop()->addDockWidget( place, dock );
1313 QtxDockAction* a = qobject_cast<QtxDockAction*>( action( ViewWindowsId ) );
1314 if ( a ) a->update();
1320 \param flag - key for window
1321 \param studyId - study id
1322 Flag used how identificator of window in windows list.
1324 QWidget* LightApp_Application::getWindow( const int flag, const int )
1326 QWidget* wid = dockWindow( flag );
1328 insertDockWindow( flag, wid = createWindow( flag ) );
1330 QMap<int, int> winMap;
1331 currentWindows( winMap );
1332 if ( winMap.contains( flag ) )
1333 placeDockWindow( flag, (Qt::DockWidgetArea)winMap[flag] );
1339 \return Object Browser
1341 SUIT_DataBrowser* LightApp_Application::objectBrowser()
1343 return qobject_cast<SUIT_DataBrowser*>( dockWindow( WT_ObjectBrowser ) );
1349 LogWindow* LightApp_Application::logWindow()
1351 return qobject_cast<LogWindow*>( dockWindow( WT_LogWindow ) );
1354 #ifndef DISABLE_PYCONSOLE
1356 This returns the python console integrated to the GUI. Depending
1357 when you request the python console, this function could return
1358 null. Then the optional parameter force (default to false) can be
1359 set to force the creation of the python console if it is not done
1361 \param force - if true, the pythonConsole is created if it does not exist yet
1362 \return Python Console
1364 PyConsole_Console* LightApp_Application::pythonConsole(const bool force)
1366 QWidget* wid = dockWindow( WT_PyConsole );
1367 if ( !wid && force==true) {
1368 wid = getWindow(WT_PyConsole);
1370 return qobject_cast<PyConsole_Console*>( wid );
1375 Updates object browser and maybe data models
1376 \param updateModels - if it is true, then data models are updated
1378 void LightApp_Application::updateObjectBrowser( const bool updateModels )
1380 // update existing data models
1383 const bool isAutoUpdate = objectBrowser() ? objectBrowser()->autoUpdate() : true;
1384 if ( objectBrowser() )
1385 objectBrowser()->setAutoUpdate( false );
1387 LightApp_Study* study = dynamic_cast<LightApp_Study*>(activeStudy());
1389 CAM_Study::ModelList dm_list;
1390 study->dataModels( dm_list );
1391 QListIterator<CAM_DataModel*> it( dm_list );
1392 while ( it.hasNext() ) {
1393 CAM_DataModel* camDM = it.next();
1394 if ( camDM && camDM->inherits( "LightApp_DataModel" ) )
1395 ((LightApp_DataModel*)camDM)->update();
1399 if( objectBrowser() )
1400 objectBrowser()->setAutoUpdate( isAutoUpdate );
1403 if ( objectBrowser() ) {
1404 objectBrowser()->updateGeometry();
1405 objectBrowser()->updateTree( 0, false );
1412 LightApp_Preferences* LightApp_Application::preferences() const
1414 return preferences( false );
1418 \return first view manager of some type
1419 \param vmType - type of view manager
1420 \param create - is it necessary to create view manager in case, when there is no manager of such type
1422 SUIT_ViewManager* LightApp_Application::getViewManager( const QString& vmType, const bool create )
1424 SUIT_ViewManager* aVM = viewManager( vmType );
1425 SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
1427 if ( anActiveVM && anActiveVM->getType() == vmType )
1430 if ( aVM && create )
1432 if ( !aVM->getActiveView() )
1435 aVM->getActiveView()->setFocus();
1438 aVM = createViewManager( vmType );
1444 Creates view manager of some type
1445 \param vmType - type of view manager
1447 SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType )
1449 SUIT_ResourceMgr* resMgr = resourceMgr();
1451 SUIT_ViewManager* viewMgr = 0;
1452 #ifndef DISABLE_GLVIEWER
1453 if( vmType == GLViewer_Viewer::Type() )
1455 viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
1456 new LightApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
1459 #ifndef DISABLE_PLOT2DVIEWER
1460 if( vmType == Plot2d_Viewer::Type() )
1462 viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
1464 #ifndef DISABLE_SALOMEOBJECT
1465 SPlot2d_Viewer* v = new SPlot2d_Viewer();
1467 new LightApp_Plot2dSelector( v, mySelMgr );
1469 vm = new Plot2d_Viewer();
1471 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1472 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( viewMgr->getActiveView() );
1475 Plot2d_ViewFrame* frame = wnd->getViewFrame();
1476 frame->setBackgroundColor( resMgr->colorValue( "Plot2d", "Background", frame->backgroundColor() ) );
1480 #ifndef DISABLE_QXGRAPHVIEWER
1481 if( vmType == QxScene_Viewer::Type() )
1483 viewMgr = new QxScene_ViewManager( activeStudy(), desktop() );
1484 QxScene_Viewer* vm = new QxScene_Viewer();
1485 viewMgr->setViewModel( vm );
1486 //QxScene_ViewWindow* wnd = dynamic_cast<QxScene_ViewWindow*>( viewMgr->getActiveView() );
1489 #ifndef DISABLE_GRAPHICSVIEW
1490 if( vmType == GraphicsView_Viewer::Type() )
1492 viewMgr = new GraphicsView_ViewManager( activeStudy(), desktop() );
1493 new LightApp_GVSelector( (GraphicsView_Viewer*)viewMgr->getViewModel(), mySelMgr );
1496 #ifndef DISABLE_OCCVIEWER
1497 if( vmType == OCCViewer_Viewer::Type() )
1499 viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
1500 OCCViewer_Viewer* vm;
1501 #ifndef DISABLE_SALOMEOBJECT
1502 vm = new SOCC_Viewer();
1504 vm = new OCCViewer_Viewer( true );
1506 vm->setBackground( OCCViewer_ViewFrame::TOP_LEFT,
1507 resMgr->backgroundValue( "OCCViewer", "xz_background", vm->background(OCCViewer_ViewFrame::TOP_LEFT) ) );
1508 vm->setBackground( OCCViewer_ViewFrame::TOP_RIGHT,
1509 resMgr->backgroundValue( "OCCViewer", "yz_background", vm->background(OCCViewer_ViewFrame::TOP_RIGHT) ) );
1510 vm->setBackground( OCCViewer_ViewFrame::BOTTOM_LEFT,
1511 resMgr->backgroundValue( "OCCViewer", "xy_background", vm->background(OCCViewer_ViewFrame::BOTTOM_LEFT) ) );
1512 vm->setBackground( OCCViewer_ViewFrame::BOTTOM_RIGHT,
1513 resMgr->backgroundValue( "OCCViewer", "background", vm->background(OCCViewer_ViewFrame::MAIN_VIEW) ) );
1515 vm->setTrihedronSize( resMgr->doubleValue( "3DViewer", "trihedron_size", vm->trihedronSize() ),
1516 resMgr->booleanValue( "3DViewer", "relative_size", vm->trihedronRelative() ));
1517 vm->setInteractionStyle( resMgr->integerValue( "3DViewer", "navigation_mode", vm->interactionStyle() ) );
1518 vm->setZoomingStyle( resMgr->integerValue( "3DViewer", "zooming_mode", vm->zoomingStyle() ) );
1519 vm->enablePreselection( resMgr->booleanValue( "OCCViewer", "enable_preselection", vm->isPreselectionEnabled() ) );
1520 vm->enableSelection( resMgr->booleanValue( "OCCViewer", "enable_selection", vm->isSelectionEnabled() ) );
1522 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1523 new LightApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
1526 #ifndef DISABLE_VTKVIEWER
1527 #ifndef DISABLE_SALOMEOBJECT
1528 if ( vmType == SVTK_Viewer::Type() )
1530 if ( vmType == VTKViewer_Viewer::Type() )
1533 #ifndef DISABLE_SALOMEOBJECT
1534 viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
1535 SVTK_Viewer* vm = dynamic_cast<SVTK_Viewer*>( viewMgr->getViewModel() );
1538 vm->setProjectionMode( resMgr->integerValue( "VTKViewer", "projection_mode", vm->projectionMode() ) );
1539 vm->setBackground( resMgr->backgroundValue( "VTKViewer", "background", vm->background() ) );
1540 vm->setTrihedronSize( resMgr->doubleValue( "3DViewer", "trihedron_size", vm->trihedronSize() ),
1541 resMgr->booleanValue( "3DViewer", "relative_size", vm->trihedronRelative() ) );
1542 vm->setStaticTrihedronVisible( resMgr->booleanValue( "3DViewer", "show_static_trihedron", vm->isStaticTrihedronVisible() ) );
1543 vm->setInteractionStyle( resMgr->integerValue( "3DViewer", "navigation_mode", vm->interactionStyle() ) );
1544 vm->setZoomingStyle( resMgr->integerValue( "3DViewer", "zooming_mode", vm->zoomingStyle() ) );
1545 vm->setPreSelectionMode(resMgr->integerValue( "VTKViewer", "preselection", vm->preSelectionMode() ) );
1546 vm->enableSelection( resMgr->booleanValue( "VTKViewer", "enable_selection", vm->isSelectionEnabled() ) );
1547 vm->setIncrementalSpeed( resMgr->integerValue( "VTKViewer", "speed_value", vm->incrementalSpeed() ),
1548 resMgr->integerValue( "VTKViewer", "speed_mode", vm->incrementalSpeedMode() ) );
1549 vm->setSpacemouseButtons( resMgr->integerValue( "VTKViewer", "spacemouse_func1_btn", vm->spacemouseBtn(1) ),
1550 resMgr->integerValue( "VTKViewer", "spacemouse_func2_btn", vm->spacemouseBtn(2) ),
1551 resMgr->integerValue( "VTKViewer", "spacemouse_func5_btn", vm->spacemouseBtn(3) ) );
1552 new LightApp_VTKSelector( vm, mySelMgr );
1555 viewMgr = new VTKViewer_ViewManager( activeStudy(), desktop() );
1556 VTKViewer_Viewer* vm = dynamic_cast<VTKViewer_Viewer*>( viewMgr->getViewModel() );
1558 vm->setBackground( resMgr->backgroundValue( "VTKViewer", "background", vm->background() ) );
1566 addViewManager( viewMgr );
1567 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
1569 if ( viewWin && desktop() ) {
1570 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
1571 viewWin->setDropDownButtons( resMgr->booleanValue( "viewers", "drop_down_buttons", true ) );
1577 SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType, QWidget* w )
1579 SUIT_ResourceMgr* resMgr = resourceMgr();
1581 SUIT_ViewManager* vm = new SUIT_ViewManager( activeStudy(),
1583 new LightApp_WgViewModel( vmType, w ) );
1584 vm->setTitle( QString( "%1: %M - viewer %V" ).arg( vmType ) );
1586 addViewManager( vm );
1587 SUIT_ViewWindow* vw = vm->createViewWindow();
1588 if ( vw && desktop() ) {
1589 vw->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
1590 vw->setDropDownButtons( resMgr->booleanValue( "viewers", "drop_down_buttons", true ) );
1593 if ( !vmType.isEmpty() && !myUserWmTypes.contains( vmType ) )
1594 myUserWmTypes << vmType;
1600 SLOT: Removes view manager from application
1602 void LightApp_Application::onCloseView( SUIT_ViewManager* theVM )
1604 removeViewManager( theVM );
1608 Protected SLOT: On study created.
1609 \param theStudy - just created study
1611 void LightApp_Application::onStudyCreated( SUIT_Study* theStudy )
1613 SUIT_DataObject* aRoot = 0;
1614 if ( theStudy && theStudy->root() )
1616 aRoot = theStudy->root();
1617 //aRoot->setName( tr( "DATA_MODELS" ) );
1620 getWindow( WT_ObjectBrowser );
1622 loadDockWindowsState();
1624 if ( objectBrowser() )
1625 objectBrowser()->setRoot( aRoot );
1627 activateModule( defaultModule() );
1629 if ( objectBrowser() )
1630 objectBrowser()->openLevels();
1634 Protected SLOT: On study opened.
1635 \param theStudy - just opened study
1637 void LightApp_Application::onStudyOpened( SUIT_Study* theStudy )
1639 SUIT_DataObject* aRoot = 0;
1640 if ( theStudy && theStudy->root() )
1642 aRoot = theStudy->root();
1646 getWindow( WT_ObjectBrowser );
1648 loadDockWindowsState();
1650 if ( objectBrowser() )
1651 objectBrowser()->setRoot( aRoot );
1653 activateModule( defaultModule() );
1655 if ( objectBrowser() )
1656 objectBrowser()->openLevels();
1661 /*!Protected SLOT. On study saved.*/
1662 void LightApp_Application::onStudySaved( SUIT_Study* s )
1664 QtxMRUAction* mru = ::qobject_cast<QtxMRUAction*>( action( MRUId ) );
1666 mru->insert( s->studyName() );
1671 /*!Protected SLOT. On study closed.*/
1672 void LightApp_Application::onStudyClosed( SUIT_Study* s )
1674 // stop auto-save timer
1675 myAutoSaveTimer->stop();
1677 // Bug 10396: clear selection
1678 mySelMgr->clearSelected();
1680 // Bug 12944: emit signal only after clear selection
1683 activateModule( "" );
1686 /*!Protected SLOT.On desktop activated.*/
1687 void LightApp_Application::onDesktopActivated()
1689 CAM_Application::onDesktopActivated();
1690 LightApp_Module* aModule = dynamic_cast<LightApp_Module*>(activeModule());
1692 aModule->studyActivated();
1695 void LightApp_Application::studyOpened( SUIT_Study* s )
1697 CAM_Application::studyOpened( s );
1700 updateViewManagers();
1703 void LightApp_Application::studySaved( SUIT_Study* s )
1705 CAM_Application::studyOpened( s );
1706 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1707 if ( aResMgr && activeStudy() ) {
1708 int autoSaveInterval = aResMgr->integerValue( "Study", "auto_save_interval", 0 );
1709 if ( autoSaveInterval > 0 ) myAutoSaveTimer->start( autoSaveInterval*60000 );
1713 void LightApp_Application::studyCreated( SUIT_Study* s )
1715 CAM_Application::studyCreated( s );
1718 updateViewManagers();
1721 /*!Gets file filter.
1722 *\retval QString "(*.bin)"
1724 QString LightApp_Application::getFileFilter() const
1732 Shows file dialog and return user selected file name
1734 QString LightApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1735 const QString& caption, QWidget* parent )
1739 QStringList fls = filters.split( ";;", QString::SkipEmptyParts );
1740 return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1743 /*! Gets directory*/
1744 QString LightApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1748 return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1751 /*! Get open file names*/
1752 QStringList LightApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
1753 const QString& caption, QWidget* parent )
1757 QStringList fls = filters.split( ";;", QString::SkipEmptyParts );
1758 return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1761 /*!Private SLOT. Update object browser.*/
1762 void LightApp_Application::onRefresh()
1764 updateObjectBrowser( true );
1767 /*!Private SLOT. Support drag-and-drop operation.*/
1768 void LightApp_Application::onDropped( const QList<SUIT_DataObject*>& objects, SUIT_DataObject* parent, int row, Qt::DropAction action )
1770 LightApp_DataObject* parentObj = dynamic_cast<LightApp_DataObject*>( parent );
1774 LightApp_Module* aModule = dynamic_cast<LightApp_Module*>( parentObj->module() );
1776 aModule->dropObjects( objects, parentObj, row, action );
1779 /*!Private SLOT. On preferences.*/
1780 void LightApp_Application::onPreferences()
1782 showPreferences( activeModule() ? activeModule()->moduleName() : tr( "PREF_CATEGORY_SALOME" ) );
1785 /*!Private SLOT. On preferences.*/
1786 void LightApp_Application::showPreferences( const QString& itemText )
1788 QApplication::setOverrideCursor( Qt::WaitCursor );
1790 LightApp_PreferencesDlg* prefDlg = new LightApp_PreferencesDlg( preferences( true ), desktop());
1792 QApplication::restoreOverrideCursor();
1797 preferences()->activateItem( itemText );
1799 if ( ( prefDlg->exec() == QDialog::Accepted || prefDlg->isSaved() ) && resourceMgr() )
1802 resourceMgr()->setValue( "desktop", "geometry", desktop()->storeGeometry() );
1803 resourceMgr()->save();
1806 shortcutMgr()->updateShortcuts();
1812 /*!Protected SLOT. On preferences changed.*/
1813 void LightApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1815 LightApp_Module* sMod = 0;
1816 CAM_Module* mod = module( modName );
1817 if ( mod && mod->inherits( "LightApp_Module" ) )
1818 sMod = (LightApp_Module*)mod;
1821 sMod->preferencesChanged( section, param );
1823 preferencesChanged( section, param );
1824 // emit signal to allow additional preferences changing processing
1825 emit preferenceChanged( modName, section, param );
1828 /*!Remove all windows from study.*/
1829 void LightApp_Application::beforeCloseDoc( SUIT_Study* s )
1831 if ( SUIT_DataBrowser* ob = objectBrowser() )
1834 CAM_Application::beforeCloseDoc( s );
1837 /*!Update actions.*/
1838 void LightApp_Application::updateActions()
1840 updateCommandsStatus();
1846 SUIT_Study* LightApp_Application::createNewStudy()
1848 LightApp_Application::lastStudyId++;
1850 LightApp_Study* aStudy = new LightApp_Study( this );
1852 // Set up processing of major study-related events
1853 connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
1854 connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
1855 connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );
1856 connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
1862 Creates window by flag.
1863 \param flag - identificator of window type
1865 QWidget* LightApp_Application::createWindow( const int flag )
1869 SUIT_ResourceMgr* resMgr = resourceMgr();
1871 if ( flag == WT_ObjectBrowser )
1873 SUIT_DataBrowser* ob = new SUIT_DataBrowser( new LightApp_DataObject(), desktop() );
1874 ob->setSortMenuEnabled( true );
1875 ob->setAutoUpdate( true );
1876 if ( resMgr->hasValue( "ObjectBrowser", "auto_hide_search_tool" ) )
1877 ob->searchTool()->enableAutoHide( resMgr->booleanValue( "ObjectBrowser", "auto_hide_search_tool" ) );
1879 //ob->setAutoOpenLevel( 1 ); // commented by ASV as a fix to bug IPAL10107
1880 ob->setWindowTitle( tr( "OBJECT_BROWSER" ) );
1881 connect( ob, SIGNAL( requestUpdate() ), this, SLOT( onRefresh() ) );
1883 QString EntryCol = QObject::tr( "ENTRY_COLUMN" );
1884 SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( ob->model() );
1885 treeModel->setSearcher( this );
1886 treeModel->registerColumn( 0, EntryCol, LightApp_DataObject::EntryId );
1887 treeModel->setAppropriate( EntryCol, Qtx::Toggled );
1889 // Mantis issue 0020136: Drag&Drop in OB
1890 SUIT_ProxyModel* proxyModel = dynamic_cast<SUIT_ProxyModel*>(treeModel);
1892 connect( proxyModel, SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
1893 this, SLOT( onDropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
1896 // temporary commented
1898 OB_ListView* ob_list = dynamic_cast<OB_ListView*>( const_cast<QListView*>( ob->listView() ) );
1900 ob_list->setColumnMaxWidth( 0, desktop()->width()/4 );
1903 // Create OBSelector
1904 new LightApp_OBSelector( ob, mySelMgr );
1906 ob->treeView()->header()->setResizeMode(SUIT_DataObject::VisibilityId, QHeaderView::Fixed);
1907 ob->treeView()->header()->moveSection(SUIT_DataObject::NameId,SUIT_DataObject::VisibilityId);
1908 ob->treeView()->setColumnWidth(SUIT_DataObject::VisibilityId, VISIBILITY_COLUMN_WIDTH);
1909 ob->setProperty( "shortcut", QKeySequence( "Alt+Shift+O" ) );
1911 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1913 #ifndef DISABLE_PYCONSOLE
1914 else if ( flag == WT_PyConsole )
1916 PyConsole_Console* pyCons = new PyConsole_EnhConsole( desktop(),new LightApp_PyInterp());
1917 pyCons->setWindowTitle( tr( "PYTHON_CONSOLE" ) );
1918 pyCons->setFont(resourceMgr()->fontValue( "PyConsole", "font" ));
1919 pyCons->setIsShowBanner(resourceMgr()->booleanValue( "PyConsole", "show_banner", true ));
1920 pyCons->setProperty( "shortcut", QKeySequence( "Alt+Shift+P" ) );
1923 pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1926 else if ( flag == WT_LogWindow )
1928 LogWindow* logWin = new LogWindow( desktop() );
1929 logWin->setWindowTitle( tr( "LOG_WINDOW" ) );
1930 logWin->setProperty( "shortcut", QKeySequence( "Alt+Shift+L" ) );
1932 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1938 \return default windows( Object Browser, Python Console )
1939 Adds to map \a aMap.
1941 void LightApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1943 aMap.insert( WT_ObjectBrowser, Qt::LeftDockWidgetArea );
1944 #ifndef DISABLE_PYCONSOLE
1945 aMap.insert( WT_PyConsole, Qt::BottomDockWidgetArea );
1947 // aMap.insert( WT_LogWindow, Qt::DockBottom );
1950 /*!Default view managers*/
1951 void LightApp_Application::defaultViewManagers( QStringList& ) const
1957 \return preferences.
1958 Create preferences, if \a crt = true.
1960 LightApp_Preferences* LightApp_Application::preferences( const bool crt ) const
1965 LightApp_Application* that = (LightApp_Application*)this;
1967 bool toCreate = !_prefs_ && crt;
1970 _prefs_ = new LightApp_Preferences( resourceMgr() );
1971 that->createPreferences( _prefs_ );
1974 that->myPrefs = _prefs_;
1976 connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1977 this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1982 SUIT_ResourceMgr* resMgr = resourceMgr();
1984 QList<SUIT_Application*> appList = SUIT_Session::session()->applications();
1985 for ( QList<SUIT_Application*>::iterator appIt = appList.begin(); appIt != appList.end(); ++appIt )
1987 LightApp_Application* app = ::qobject_cast<LightApp_Application*>( *appIt );
1991 QStringList modNameList;
1992 app->modules( modNameList, false );
1994 QMap<QString, QString> iconMap;
1995 app->moduleIconNames( iconMap );
1997 for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1999 if ( !app->isLibExists( *it ) || _prefs_->hasModule( *it ) )
2002 int modId = _prefs_->addPreference( *it );
2003 if ( iconMap.contains( *it ) )
2004 _prefs_->setItemIcon( modId, Qtx::scaleIcon( resMgr->loadPixmap( moduleName( *it ), iconMap[*it], false ), 20 ) );
2008 app->modules( modList );
2009 QListIterator<CAM_Module*> itr( modList );
2010 while ( itr.hasNext() )
2012 LightApp_Module* mod = 0;
2014 CAM_Module* anItem = itr.next();
2015 if ( anItem->inherits( "LightApp_Module" ) )
2016 mod = (LightApp_Module*)anItem;
2018 if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
2020 _prefs_->addPreference( mod->moduleName() );
2021 mod->createPreferences();
2022 that->emptyPreferences( mod->moduleName() );
2026 _prefs_->setItemProperty( "info", tr( "PREFERENCES_NOT_LOADED" ) );
2032 Adds new module to application
2034 void LightApp_Application::moduleAdded( CAM_Module* mod )
2036 CAM_Application::moduleAdded( mod );
2038 LightApp_Module* lightMod = 0;
2039 if ( mod && mod->inherits( "LightApp_Module" ) )
2040 lightMod = (LightApp_Module*)mod;
2042 if ( myPrefs && lightMod && !myPrefs->hasModule( lightMod->moduleName() ))
2044 myPrefs->addPreference( mod->moduleName() );
2045 lightMod->createPreferences();
2046 emptyPreferences( mod->moduleName() );
2050 void LightApp_Application::emptyPreferences( const QString& modName )
2052 QtxPreferenceItem* item = myPrefs->findItem( modName, true );
2053 if ( !item || !item->isEmpty() )
2056 // printf( "---------------------> Modify for empty module.\n" );
2058 QtxPagePrefFrameItem* frm = new QtxPagePrefFrameItem( item->title(), item->parentItem() );
2059 frm->setIcon( item->icon() );
2060 frm->setStretch( false );
2061 item->parentItem()->insertItem( frm, item );
2062 new QtxPagePrefLabelItem( Qt::AlignCenter, tr( "PREFERENCES_NOT_SUPPORTED" ).arg( modName ), frm );
2069 void LightApp_Application::createPreferences( LightApp_Preferences* pref )
2074 QStringList aValuesList;
2075 QList<QVariant> anIndicesList;
2079 // . Top-level "SALOME" preferences group <<start>>
2080 int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
2081 pref->setItemIcon( salomeCat, Qtx::scaleIcon( resourceMgr()->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false ), 20 ) );
2083 // .. "General" preferences tab <<start>>
2084 int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
2086 // ... "Language" group <<start>>
2087 int langGroup = pref->addPreference( tr( "PREF_GROUP_LANGUAGE" ), genTab );
2088 pref->setItemProperty( "columns", 2, langGroup );
2089 // .... -> application language
2090 int curLang = pref->addPreference( tr( "PREF_CURRENT_LANGUAGE" ), langGroup,
2091 LightApp_Preferences::Selector, "language", "language" );
2092 QStringList aLangs = SUIT_Session::session()->resourceMgr()->stringValue( "language", "languages", "en" ).split( "," );
2093 QList<QVariant> aIcons;
2094 foreach ( QString aLang, aLangs ) {
2095 aIcons << QPixmap( QString( ":/images/%1" ).arg( aLang ) );
2097 pref->setItemProperty( "strings", aLangs, curLang );
2098 pref->setItemProperty( "icons", aIcons, curLang );
2099 // ... "Language" group <<end>>
2101 // ... "Look and feel" group <<start>>
2102 int lookGroup = pref->addPreference( tr( "PREF_GROUP_LOOK_AND_FEEL" ), genTab );
2103 pref->setItemProperty( "columns", 2, lookGroup );
2104 // .... -> show splash-screen
2105 pref->addPreference( tr( "PREF_SHOW_SPLASH" ), lookGroup, LightApp_Preferences::Bool, "launch", "splash" );
2106 // .... -> opaque resize
2107 pref->addPreference( tr( "PREF_OPAQUE_RESIZE" ), lookGroup, LightApp_Preferences::Bool, "desktop", "opaque_resize" );
2108 // .... -> drop-down buttons
2109 pref->addPreference( tr( "PREF_DROP_DOWN_BUTTONS" ), lookGroup, LightApp_Preferences::Bool, "viewers", "drop_down_buttons" );
2110 // ... "Look and feel" group <<end>>
2112 // ... "Study properties" group <<start>>
2113 int studyGroup = pref->addPreference( tr( "PREF_GROUP_STUDY" ), genTab );
2114 pref->setItemProperty( "columns", 2, studyGroup );
2115 // .... -> multi-file save
2116 pref->addPreference( tr( "PREF_MULTI_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "multi_file" );
2117 // .... -> ascii save mode
2118 pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "ascii_file" );
2119 // .... -> store windows geometry
2120 pref->addPreference( tr( "PREF_STORE_POS" ), studyGroup, LightApp_Preferences::Bool, "Study", "store_positions" );
2121 pref->addPreference( "", studyGroup, LightApp_Preferences::Space );
2122 pref->addPreference( tr( "PREF_STORE_TOOL_POS" ), studyGroup, LightApp_Preferences::Bool, "Study", "store_tool_positions" );
2123 // .... -> auto-save
2124 int autoSaveInterval = pref->addPreference( tr( "PREF_AUTO_SAVE" ), studyGroup,
2125 LightApp_Preferences::IntSpin, "Study", "auto_save_interval" );
2126 pref->setItemProperty( "min", 0, autoSaveInterval );
2127 pref->setItemProperty( "max", 1440, autoSaveInterval );
2128 pref->setItemProperty( "special", tr( "PREF_AUTO_SAVE_DISABLED" ), autoSaveInterval );
2129 // ... "Study properties" group <<end>>
2131 // ... "Help browser" group <<start>>
2132 int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab, LightApp_Preferences::Auto, "ExternalBrowser", "use_external_browser");
2134 QString platform = "winapplication";
2136 QString platform = "application";
2138 // .... -> browser application
2139 int apppref = pref->addPreference( tr( "PREF_APP" ), extgroup, LightApp_Preferences::File, "ExternalBrowser", platform );
2140 pref->setItemProperty( "mode", Qtx::PT_OpenFile, apppref );
2141 // .... -> browser parameters
2142 pref->addPreference( tr( "PREF_PARAM" ), extgroup, LightApp_Preferences::String, "ExternalBrowser", "parameters" );
2143 // ... "Help browser" group <<end>>
2145 // ... "Python console properties" group <<start>>
2146 int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab );
2148 pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, LightApp_Preferences::Font, "PyConsole", "font" );
2149 // .... -> show banner
2150 pref->addPreference( tr( "PREF_SHOW_BANNER" ), pythonConsoleGroup, LightApp_Preferences::Bool, "PyConsole", "show_banner" );
2151 // ... "Python console properties" group <<end>>
2153 // ... "MRU" preferences group <<start>>
2154 int mruGroup = pref->addPreference( tr( "PREF_GROUP_MRU" ), genTab, LightApp_Preferences::Auto, "MRU", "show_mru" );
2155 pref->setItemProperty( "columns", 4, mruGroup );
2156 // number of MRU items
2157 int mruVisCount = pref->addPreference( tr( "PREF_MRU_VISIBLE_COUNT" ), mruGroup, LightApp_Preferences::IntSpin,
2158 "MRU", "visible_count" );
2159 pref->setItemProperty( "min", 0, mruVisCount );
2160 pref->setItemProperty( "max", 100, mruVisCount );
2162 int mruLinkType = pref->addPreference( tr( "PREF_MRU_LINK_TYPE" ), mruGroup, LightApp_Preferences::Selector,
2163 "MRU", "link_type" );
2164 aValuesList.clear();
2165 anIndicesList.clear();
2166 aValuesList << tr("PREF_MRU_LINK_AUTO") << tr("PREF_MRU_LINK_SHORT") << tr("PREF_MRU_LINK_FULL");
2167 anIndicesList << 0 << 1 << 2 ;
2168 pref->setItemProperty( "strings", aValuesList, mruLinkType );
2169 pref->setItemProperty( "indexes", anIndicesList, mruLinkType );
2170 // ... "MRU" preferences group <<end>>
2171 // .. "General" preferences tab <<end>>
2173 // .. "3D viewer" group <<start>>
2174 int Viewer3DGroup = pref->addPreference( tr( "PREF_GROUP_3DVIEWER" ), salomeCat );
2175 // ... -> navigation mode
2176 int vtkStyleMode = pref->addPreference( tr( "PREF_NAVIGATION" ), Viewer3DGroup,
2177 LightApp_Preferences::Selector, "3DViewer", "navigation_mode" );
2178 aValuesList.clear();
2179 anIndicesList.clear();
2180 aValuesList << tr("PREF_STANDARD_STYLE") << tr("PREF_KEYFREE_STYLE");
2181 anIndicesList << 0 << 1;
2182 pref->setItemProperty( "strings", aValuesList, vtkStyleMode );
2183 pref->setItemProperty( "indexes", anIndicesList, vtkStyleMode );
2184 // ... -> zooming mode
2185 #if OCC_VERSION_LARGE > 0x0603000A // available only with OCC-6.3-sp11 and higher version
2186 int occZoomingStyleMode = pref->addPreference( tr( "PREF_ZOOMING" ), Viewer3DGroup,
2187 LightApp_Preferences::Selector, "3DViewer", "zooming_mode" );
2188 aValuesList.clear();
2189 anIndicesList.clear();
2190 aValuesList << tr("PREF_ZOOMING_AT_CENTER") << tr("PREF_ZOOMING_AT_CURSOR");
2191 anIndicesList << 0 << 1;
2192 pref->setItemProperty( "strings", aValuesList, occZoomingStyleMode );
2193 pref->setItemProperty( "indexes", anIndicesList, occZoomingStyleMode );
2195 // ... "Trihedron" group <<start>>
2196 int occTriGroup = pref->addPreference( tr( "PREF_TRIHEDRON" ), Viewer3DGroup );
2197 pref->setItemProperty( "columns", 2, occTriGroup );
2198 // .... -> trihedron size
2199 int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occTriGroup,
2200 LightApp_Preferences::DblSpin, "3DViewer", "trihedron_size" );
2201 pref->setItemProperty( "min", 1.0E-06, occTS );
2202 pref->setItemProperty( "max", 1000, occTS );
2203 // .... -> relative size of trihedron
2204 pref->addPreference( tr( "PREF_RELATIVE_SIZE" ), occTriGroup, LightApp_Preferences::Bool, "3DViewer", "relative_size" );
2205 // .... -> show static trihedron
2206 pref->addPreference( tr( "PREF_SHOW_STATIC_TRIHEDRON" ), occTriGroup, LightApp_Preferences::Bool, "3DViewer", "show_static_trihedron" );
2207 // ... "Trihedron" group <<end>>
2208 // .. "3D viewer" group <<end>>
2212 #ifndef DISABLE_OCCVIEWER
2213 // .. "OCC viewer" group <<start>>
2214 int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), salomeCat );
2216 // ... "Background" group <<start>>
2217 int bgGroup = pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup );
2218 // pref->setItemProperty( "columns", 2, bgGroup );
2219 aValuesList.clear();
2220 anIndicesList.clear();
2222 formats = OCCViewer_Viewer::backgroundData( aValuesList, idList, txtList );
2223 foreach( int gid, idList ) anIndicesList << gid;
2224 // .... -> 3D viewer background
2225 bgId = pref->addPreference( tr( "PREF_3DVIEWER_BACKGROUND" ), bgGroup,
2226 LightApp_Preferences::Background, "OCCViewer", "background" );
2227 pref->setItemProperty( "gradient_names", aValuesList, bgId );
2228 pref->setItemProperty( "gradient_ids", anIndicesList, bgId );
2229 pref->setItemProperty( "texture_enabled", !txtList.isEmpty(), bgId );
2230 pref->setItemProperty( "texture_center_enabled", (bool)txtList.contains( Qtx::CenterTexture ), bgId );
2231 pref->setItemProperty( "texture_tile_enabled", (bool)txtList.contains( Qtx::TileTexture ), bgId );
2232 pref->setItemProperty( "texture_stretch_enabled", (bool)txtList.contains( Qtx::StretchTexture ), bgId );
2233 pref->setItemProperty( "custom_enabled", false, bgId );
2234 pref->setItemProperty( "image_formats", formats, bgId );
2235 // .... -> XZ viewer background
2236 bgId = pref->addPreference( tr( "PREF_XZVIEWER_BACKGROUND" ), bgGroup,
2237 LightApp_Preferences::Background, "OCCViewer", "xz_background" );
2238 pref->setItemProperty( "gradient_names", aValuesList, bgId );
2239 pref->setItemProperty( "gradient_ids", anIndicesList, bgId );
2240 pref->setItemProperty( "texture_enabled", !txtList.isEmpty(), bgId );
2241 pref->setItemProperty( "texture_center_enabled", (bool)txtList.contains( Qtx::CenterTexture ), bgId );
2242 pref->setItemProperty( "texture_tile_enabled", (bool)txtList.contains( Qtx::TileTexture ), bgId );
2243 pref->setItemProperty( "texture_stretch_enabled", (bool)txtList.contains( Qtx::StretchTexture ), bgId );
2244 pref->setItemProperty( "custom_enabled", false, bgId );
2245 pref->setItemProperty( "image_formats", formats, bgId );
2246 // .... -> YZ viewer background
2247 bgId = pref->addPreference( tr( "PREF_YZVIEWER_BACKGROUND" ), bgGroup,
2248 LightApp_Preferences::Background, "OCCViewer", "yz_background" );
2249 pref->setItemProperty( "gradient_names", aValuesList, bgId );
2250 pref->setItemProperty( "gradient_ids", anIndicesList, bgId );
2251 pref->setItemProperty( "texture_enabled", !txtList.isEmpty(), bgId );
2252 pref->setItemProperty( "texture_center_enabled", (bool)txtList.contains( Qtx::CenterTexture ), bgId );
2253 pref->setItemProperty( "texture_tile_enabled", (bool)txtList.contains( Qtx::TileTexture ), bgId );
2254 pref->setItemProperty( "texture_stretch_enabled", (bool)txtList.contains( Qtx::StretchTexture ), bgId );
2255 pref->setItemProperty( "custom_enabled", false, bgId );
2256 pref->setItemProperty( "image_formats", formats, bgId );
2257 // .... -> XY viewer background
2258 bgId = pref->addPreference( tr( "PREF_XYVIEWER_BACKGROUND" ), bgGroup,
2259 LightApp_Preferences::Background, "OCCViewer", "xy_background" );
2260 pref->setItemProperty( "gradient_names", aValuesList, bgId );
2261 pref->setItemProperty( "gradient_ids", anIndicesList, bgId );
2262 pref->setItemProperty( "texture_enabled", !txtList.isEmpty(), bgId );
2263 pref->setItemProperty( "texture_center_enabled", (bool)txtList.contains( Qtx::CenterTexture ), bgId );
2264 pref->setItemProperty( "texture_tile_enabled", (bool)txtList.contains( Qtx::TileTexture ), bgId );
2265 pref->setItemProperty( "texture_stretch_enabled", (bool)txtList.contains( Qtx::StretchTexture ), bgId );
2266 pref->setItemProperty( "custom_enabled", false, bgId );
2267 pref->setItemProperty( "image_formats", formats, bgId );
2268 // ... "Background" group <<end>>
2271 // ... "Selection" group <<start>>
2272 int occSelectionGroup = pref->addPreference( tr( "PREF_GROUP_SELECTION" ), occGroup );
2273 pref->setItemProperty( "columns", 2, occSelectionGroup );
2274 // .... -> enable preselection
2275 pref->addPreference( tr( "PREF_ENABLE_PRESELECTION" ), occSelectionGroup,
2276 LightApp_Preferences::Bool, "OCCViewer", "enable_preselection" );
2277 // .... -> enable selection
2278 pref->addPreference( tr( "PREF_ENABLE_SELECTION" ), occSelectionGroup,
2279 LightApp_Preferences::Bool, "OCCViewer", "enable_selection" );
2280 // ... "Selection" group <<end>>
2282 // ... -> empty frame (for layout) <<start>>
2283 int occGen = pref->addPreference( "", occGroup, LightApp_Preferences::Frame );
2284 pref->setItemProperty( "margin", 0, occGen );
2285 pref->setItemProperty( "columns", 2, occGen );
2286 // ... -> empty frame (for layout) <<end>>
2287 // .. "OCC viewer" group <<end>>
2290 #ifndef DISABLE_VTKVIEWER
2291 // .. "VTK viewer" group <<start>>
2292 int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), salomeCat ); //viewTab
2294 // ... -> empty frame (for layout) <<start>>
2295 int vtkGen = pref->addPreference( "", vtkGroup, LightApp_Preferences::Frame );
2296 //pref->setItemProperty( "columns", 2, vtkGen );
2297 // .... -> projection mode
2298 int vtkProjMode = pref->addPreference( tr( "PREF_PROJECTION_MODE" ), vtkGen,
2299 LightApp_Preferences::Selector, "VTKViewer", "projection_mode" );
2300 aValuesList.clear();
2301 anIndicesList.clear();
2302 aValuesList << tr("PREF_ORTHOGRAPHIC") << tr("PREF_PERSPECTIVE");
2303 anIndicesList << 0 << 1;
2304 pref->setItemProperty( "strings", aValuesList, vtkProjMode );
2305 pref->setItemProperty( "indexes", anIndicesList, vtkProjMode );
2306 // .... -> background
2307 aValuesList.clear();
2308 anIndicesList.clear();
2310 #ifndef DISABLE_SALOMEOBJECT
2311 formats = SVTK_Viewer::backgroundData( aValuesList, idList, txtList );
2313 foreach( int gid, idList ) anIndicesList << gid;
2314 bgId = pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGen,
2315 LightApp_Preferences::Background, "VTKViewer", "background" );
2316 pref->setItemProperty( "gradient_names", aValuesList, bgId );
2317 pref->setItemProperty( "gradient_ids", anIndicesList, bgId );
2318 pref->setItemProperty( "texture_enabled", !txtList.isEmpty(), bgId );
2319 pref->setItemProperty( "texture_center_enabled", (bool)txtList.contains( Qtx::CenterTexture ), bgId );
2320 pref->setItemProperty( "texture_tile_enabled", (bool)txtList.contains( Qtx::TileTexture ), bgId );
2321 pref->setItemProperty( "texture_stretch_enabled", (bool)txtList.contains( Qtx::StretchTexture ), bgId );
2322 pref->setItemProperty( "custom_enabled", false, bgId );
2323 #ifndef DISABLE_SALOMEOBJECT
2324 pref->setItemProperty( "image_formats", formats, bgId );
2326 // .... -> speed increment
2327 int vtkSpeed = pref->addPreference( tr( "PREF_INCREMENTAL_SPEED" ), vtkGen,
2328 LightApp_Preferences::IntSpin, "VTKViewer", "speed_value" );
2329 pref->setItemProperty( "min", 1, vtkSpeed );
2330 pref->setItemProperty( "max", 1000, vtkSpeed );
2331 // .... -> speed mode
2332 int vtkSpeedMode = pref->addPreference( tr( "PREF_INCREMENTAL_SPEED_MODE" ), vtkGen,
2333 LightApp_Preferences::Selector, "VTKViewer", "speed_mode" );
2334 aValuesList.clear();
2335 anIndicesList.clear();
2336 aValuesList << tr("PREF_ARITHMETIC") << tr("PREF_GEOMETRICAL");
2337 anIndicesList << 0 << 1;
2338 pref->setItemProperty( "strings", aValuesList, vtkSpeedMode );
2339 pref->setItemProperty( "indexes", anIndicesList, vtkSpeedMode );
2341 // ... "Selection" group <<start>>
2342 int vtkSelectionGroup = pref->addPreference( tr( "PREF_GROUP_SELECTION" ), vtkGroup );
2343 pref->setItemProperty( "columns", 2, vtkSelectionGroup );
2344 // .... -> preselection
2345 int vtkPreselection = pref->addPreference( tr( "PREF_PRESELECTION" ), vtkSelectionGroup,
2346 LightApp_Preferences::Selector, "VTKViewer", "preselection" );
2347 aValuesList.clear();
2348 anIndicesList.clear();
2349 aValuesList << tr("PREF_PRESELECTION_STANDARD") << tr("PREF_PRESELECTION_DYNAMIC") << tr("PREF_PRESELECTION_DISABLED");
2350 anIndicesList << 0 << 1 << 2;
2351 pref->setItemProperty( "strings", aValuesList, vtkPreselection );
2352 pref->setItemProperty( "indexes", anIndicesList, vtkPreselection );
2353 // .... -> enable selection
2354 pref->addPreference( tr( "PREF_ENABLE_SELECTION" ), vtkSelectionGroup, LightApp_Preferences::Bool, "VTKViewer", "enable_selection" );
2355 // ... "Selection" group <<end>>
2357 // ... -> empty frame (for layout) <<end>>
2359 // ... space mouse sub-group <<start>>
2360 int vtkSM = pref->addPreference( tr( "PREF_FRAME_SPACEMOUSE" ), vtkGroup, LightApp_Preferences::GroupBox );
2361 //pref->setItemProperty( "columns", 2, vtkSM );
2362 // .... -> decrease speed increment
2363 int spacemousePref1 = pref->addPreference( tr( "PREF_SPACEMOUSE_FUNC_1" ), vtkSM,
2364 LightApp_Preferences::Selector, "VTKViewer",
2365 "spacemouse_func1_btn" );
2366 // .... -> increase speed increment
2367 int spacemousePref2 = pref->addPreference( tr( "PREF_SPACEMOUSE_FUNC_2" ), vtkSM,
2368 LightApp_Preferences::Selector, "VTKViewer",
2369 "spacemouse_func2_btn" );
2370 // .... -> dominant / combined switch
2371 int spacemousePref3 = pref->addPreference( tr( "PREF_SPACEMOUSE_FUNC_3" ), vtkSM,
2372 LightApp_Preferences::Selector, "VTKViewer",
2373 "spacemouse_func5_btn" ); //
2374 aValuesList.clear();
2375 anIndicesList.clear();
2376 aValuesList << tr( "PREF_SPACEMOUSE_BTN_1" ) << tr( "PREF_SPACEMOUSE_BTN_2" ) << tr( "PREF_SPACEMOUSE_BTN_3" );
2377 aValuesList << tr( "PREF_SPACEMOUSE_BTN_4" ) << tr( "PREF_SPACEMOUSE_BTN_5" ) << tr( "PREF_SPACEMOUSE_BTN_6" );
2378 aValuesList << tr( "PREF_SPACEMOUSE_BTN_7" ) << tr( "PREF_SPACEMOUSE_BTN_8" ) << tr( "PREF_SPACEMOUSE_BTN_*" );
2379 aValuesList << tr( "PREF_SPACEMOUSE_BTN_10" ) << tr( "PREF_SPACEMOUSE_BTN_11" );
2380 anIndicesList << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11;
2381 pref->setItemProperty( "strings", aValuesList, spacemousePref1 );
2382 pref->setItemProperty( "indexes", anIndicesList, spacemousePref1 );
2383 pref->setItemProperty( "strings", aValuesList, spacemousePref2 );
2384 pref->setItemProperty( "indexes", anIndicesList, spacemousePref2 );
2385 pref->setItemProperty( "strings", aValuesList, spacemousePref3 );
2386 pref->setItemProperty( "indexes", anIndicesList, spacemousePref3 );
2387 // ... space mouse sub-group <<end>>
2389 // ... avi recording sub-group <<start>>
2390 int vtkRec = pref->addPreference( tr( "PREF_FRAME_RECORDING" ), vtkGroup, LightApp_Preferences::GroupBox );
2391 pref->setItemProperty( "columns", 2, vtkRec );
2392 // .... -> recording mode
2393 int modePref = pref->addPreference( tr( "PREF_RECORDING_MODE" ), vtkRec,
2394 LightApp_Preferences::Selector, "VTKViewer", "recorder_mode" );
2395 aValuesList.clear();
2396 anIndicesList.clear();
2397 aValuesList << tr( "PREF_SKIPPED_FRAMES" ) << tr( "PREF_ALL_DISLPAYED_FRAMES" );
2398 anIndicesList << 0 << 1;
2399 pref->setItemProperty( "strings", aValuesList, modePref );
2400 pref->setItemProperty( "indexes", anIndicesList, modePref );
2402 int fpsPref = pref->addPreference( tr( "PREF_FPS" ), vtkRec,
2403 LightApp_Preferences::DblSpin, "VTKViewer", "recorder_fps" );
2404 pref->setItemProperty( "min", 0.1, fpsPref );
2405 pref->setItemProperty( "max", 100, fpsPref );
2407 int qualityPref = pref->addPreference( tr( "PREF_QUALITY" ), vtkRec,
2408 LightApp_Preferences::IntSpin, "VTKViewer", "recorder_quality" );
2409 pref->setItemProperty( "min", 1, qualityPref );
2410 pref->setItemProperty( "max", 100, qualityPref );
2411 // .... -> progressive mode
2412 pref->addPreference( tr( "PREF_PROGRESSIVE" ), vtkRec,
2413 LightApp_Preferences::Bool, "VTKViewer", "recorder_progressive" );
2414 // ... avi recording sub-group <<end>>
2416 // ... group names sub-group <<start>>
2417 int vtkGN = pref->addPreference( tr( "PREF_FRAME_GROUP_NAMES" ), vtkGroup,
2418 LightApp_Preferences::GroupBox, "VTKViewer", "show_group_names" );
2419 pref->setItemProperty( "columns", 2, vtkGN );
2420 // .... -> text color
2421 pref->addPreference( tr( "PREF_GROUP_NAMES_TEXT_COLOR" ), vtkGN,
2422 LightApp_Preferences::Color, "VTKViewer", "group_names_text_color" );
2423 // .... -> transparency
2424 int transPref = pref->addPreference( tr( "PREF_GROUP_NAMES_TRANSPARENCY" ), vtkGN,
2425 LightApp_Preferences::DblSpin, "VTKViewer", "group_names_transparency" );
2426 pref->setItemProperty( "min", 0.0, transPref );
2427 pref->setItemProperty( "max", 1.0, transPref );
2428 pref->setItemProperty( "step", 0.1, transPref );
2429 // ... -> group names sub-group <<end>>
2430 // .. "VTK viewer" group <<end>>
2433 // .. "Plot2d viewer" group <<start>>
2434 int plot2dGroup = pref->addPreference( tr( "PREF_GROUP_PLOT2DVIEWER" ), salomeCat ); //viewTab
2435 //pref->setItemProperty( "columns", 2, plot2dGroup );
2437 // ... -> show legend
2438 pref->addPreference( tr( "PREF_SHOW_LEGEND" ), plot2dGroup,
2439 LightApp_Preferences::Bool, "Plot2d", "ShowLegend" );
2440 // ... -> legend position
2441 int legendPosition = pref->addPreference( tr( "PREF_LEGEND_POSITION" ), plot2dGroup,
2442 LightApp_Preferences::Selector, "Plot2d", "LegendPos" );
2443 aValuesList.clear();
2444 anIndicesList.clear();
2445 aValuesList << tr("PREF_LEFT") << tr("PREF_RIGHT") << tr("PREF_TOP") << tr("PREF_BOTTOM");
2446 anIndicesList << 0 << 1 << 2 << 3 ;
2447 pref->setItemProperty( "strings", aValuesList, legendPosition );
2448 pref->setItemProperty( "indexes", anIndicesList, legendPosition );
2449 // ... -> legend font
2450 pref->addPreference( tr( "PREF_LEGEND_FONT" ), plot2dGroup, LightApp_Preferences::Font, "Plot2d", "LegendFont" );
2451 // ... -> curve type
2452 int curveType = pref->addPreference( tr( "PREF_CURVE_TYPE" ), plot2dGroup,
2453 LightApp_Preferences::Selector, "Plot2d", "CurveType" );
2454 aValuesList.clear();
2455 anIndicesList.clear();
2456 aValuesList << tr("PREF_POINTS") << tr("PREF_LINES") << tr("PREF_SPLINE");
2457 anIndicesList << 0 << 1 << 2 ;
2458 pref->setItemProperty( "strings", aValuesList, curveType );
2459 pref->setItemProperty( "indexes", anIndicesList, curveType );
2460 // ... -> marker size
2461 int markerSize = pref->addPreference( tr( "PREF_MARKER_SIZE" ), plot2dGroup,
2462 LightApp_Preferences::IntSpin, "Plot2d", "MarkerSize" );
2463 pref->setItemProperty( "min", 0, markerSize );
2464 pref->setItemProperty( "max", 100, markerSize );
2465 // ... -> horizontal scaling mode
2466 int horScale = pref->addPreference( tr( "PREF_HOR_AXIS_SCALE" ), plot2dGroup,
2467 LightApp_Preferences::Selector, "Plot2d", "HorScaleMode" );
2468 aValuesList.clear();
2469 anIndicesList.clear();
2470 aValuesList << tr("PREF_LINEAR") << tr("PREF_LOGARITHMIC");
2471 anIndicesList << 0 << 1 ;
2472 pref->setItemProperty( "strings", aValuesList, horScale );
2473 pref->setItemProperty( "indexes", anIndicesList, horScale );
2474 // ... -> vertical scaling mode
2475 int verScale = pref->addPreference( tr( "PREF_VERT_AXIS_SCALE" ), plot2dGroup,
2476 LightApp_Preferences::Selector, "Plot2d", "VerScaleMode" );
2477 pref->setItemProperty( "strings", aValuesList, verScale );
2478 pref->setItemProperty( "indexes", anIndicesList, verScale );
2479 // ... -> background
2480 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND_COLOR" ), plot2dGroup,
2481 LightApp_Preferences::Color, "Plot2d", "Background" );
2482 // ... -> font color
2483 pref->addPreference( tr( "PREF_FONT_COLOR" ), plot2dGroup, LightApp_Preferences::Color, "Plot2d", "LegendFontColor" );
2484 // ... -> selection font color
2485 pref->addPreference( tr( "PREF_SELECTED_FONT_COLOR" ), plot2dGroup, LightApp_Preferences::Color, "Plot2d", "SelectedLegendFontColor" );
2486 // ... -> selection color
2487 pref->addPreference( tr( "PREF_VIEWER_SELECTION" ), plot2dGroup,
2488 LightApp_Preferences::Color, "Plot2d", "SelectionColor" );
2489 // ... -> errors/deviation colot
2490 pref->addPreference( tr( "PREF_DEVIATION_COLOR" ), plot2dGroup,
2491 LightApp_Preferences::Color, "Plot2d", "DeviationMarkerColor" );
2492 // ... -> deviation markers line size
2493 int deviationMarkerLw = pref->addPreference( tr( "PREF_DEVIATION_MARKER_LW" ), plot2dGroup,
2494 LightApp_Preferences::IntSpin, "Plot2d", "DeviationMarkerLineWidth" );
2495 pref->setItemProperty( "min", 1, deviationMarkerLw );
2496 pref->setItemProperty( "max", 5, deviationMarkerLw );
2497 // ... -> deviation markers tick mark size
2498 int deviationMarkerTs = pref->addPreference( tr( "PREF_DEVIATION_MARKER_TS" ), plot2dGroup,
2499 LightApp_Preferences::IntSpin, "Plot2d", "DeviationMarkerTickSize" );
2500 pref->setItemProperty( "min", 1, deviationMarkerTs );
2501 pref->setItemProperty( "max", 5, deviationMarkerTs );
2502 // .. "Plot2d viewer" group <<end>>
2504 // .. "Directories" preferences tab <<start>>
2505 int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat );
2506 // ... --> quick directories list
2507 int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab );
2508 pref->addPreference( tr( "" ), dirGroup,
2509 LightApp_Preferences::DirList, "FileDlg", "QuickDirList" );
2510 // .. "Directories" preferences tab <<end>>
2512 // .. "Object browser" preferences tab <<start>>
2513 int obTab = pref->addPreference( tr( "PREF_TAB_OBJBROWSER" ), salomeCat );
2515 // ... "Search tool" group <<start>>
2516 int stGroup = pref->addPreference( tr( "PREF_OBJ_BROWSER_SEARCH_TOOL" ), obTab );
2517 // .... --> auto-hide
2518 pref->addPreference( tr( "PREF_AUTO_HIDE_SEARCH_TOOL" ), stGroup, LightApp_Preferences::Bool,
2519 "ObjectBrowser", "auto_hide_search_tool" );
2520 // ... "Search tool" group <<end>>
2522 // ... "Object browser settings" group <<start>>
2523 int objSetGroup = pref->addPreference( tr( "PREF_GROUP_LOOK_AND_FEEL" ), obTab );
2524 pref->setItemProperty( "columns", 2, objSetGroup );
2525 // .... -> auto size first column
2526 pref->addPreference( tr( "PREF_AUTO_SIZE_FIRST" ), objSetGroup, LightApp_Preferences::Bool,
2527 "ObjectBrowser", "auto_size_first" );
2528 // .... -> auto size other columns
2529 pref->addPreference( tr( "PREF_AUTO_SIZE" ), objSetGroup, LightApp_Preferences::Bool,
2530 "ObjectBrowser", "auto_size" );
2531 // .... -> resize columns on expand item
2532 pref->addPreference( tr( "PREF_RESIZE_ON_EXPAND_ITEM" ), objSetGroup, LightApp_Preferences::Bool,
2533 "ObjectBrowser", "resize_on_expand_item" );
2534 // .... -> browse to published object
2535 int browsePublished = pref->addPreference( tr( "PREF_BROWSE_TO_THE_PUBLISHED_OBJECT" ), objSetGroup, LightApp_Preferences::Selector,
2536 "ObjectBrowser", "browse_published_object" );
2537 aValuesList.clear();
2538 anIndicesList.clear();
2539 aValuesList << tr( "PREF_BROWSE_NEVER" ) << tr( "PREF_BROWSE_AFTER_APPLY_AND_CLOSE_ONLY" ) << tr( "PREF_BROWSE_ALWAYS" );
2540 anIndicesList << BP_Never << BP_ApplyAndClose << BP_Always;
2541 pref->setItemProperty( "strings", aValuesList, browsePublished );
2542 pref->setItemProperty( "indexes", anIndicesList, browsePublished );
2543 // ... "Object browser settings" group <<end>>
2544 // .. "Object browser" preferences tab <<end>>
2546 // .. "Shortcuts" preferences tab <<start>>
2547 int shortcutTab = pref->addPreference( tr( "PREF_TAB_SHORTCUTS" ), salomeCat );
2548 // ... "Shortcuts settings" group <<start>>
2549 int shortcutGroup = pref->addPreference( tr( "PREF_GROUP_SHORTCUTS" ), shortcutTab );
2550 pref->addPreference( tr( "" ), shortcutGroup,
2551 LightApp_Preferences::ShortcutTree, "shortcuts" );
2552 // ... "Shortcuts settings" group <<end>>
2553 // .. "Shortcuts" preferences tab <<end>>
2554 // . Top-level "SALOME" preferences group <<end>>
2560 Changes appearance of application according to changed preferences
2561 \param sec - section
2562 \param param - name of changed parameter
2564 void LightApp_Application::preferencesChanged( const QString& sec, const QString& param )
2566 SUIT_ResourceMgr* resMgr = resourceMgr();
2570 if ( sec == "viewers" && param == "drop_down_buttons" )
2572 ViewManagerList vmlist = viewManagers();
2573 foreach( SUIT_ViewManager* vm, vmlist )
2575 QVector<SUIT_ViewWindow*> vwlist = vm->getViews();
2576 foreach( SUIT_ViewWindow* vw, vwlist )
2577 if ( vw ) vw->setDropDownButtons( resMgr->booleanValue( "viewers", "drop_down_buttons", true ) );
2581 if ( sec == QString( "3DViewer" ) && (param == QString( "trihedron_size" ) || param == QString( "relative_size" )))
2583 double sz = resMgr->doubleValue( sec, "trihedron_size", -1 );
2584 bool relative = resMgr->booleanValue( sec, "relative_size", true );
2585 QList<SUIT_ViewManager*> lst;
2586 #ifndef DISABLE_OCCVIEWER
2587 viewManagers( OCCViewer_Viewer::Type(), lst );
2588 QListIterator<SUIT_ViewManager*> itOCC( lst );
2589 while ( itOCC.hasNext() && sz >= 0 )
2591 SUIT_ViewModel* vm = itOCC.next()->getViewModel();
2592 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
2595 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
2596 occVM->setTrihedronSize( sz, relative );
2597 occVM->getAISContext()->UpdateCurrentViewer();
2600 #ifndef DISABLE_VTKVIEWER
2601 #ifndef DISABLE_SALOMEOBJECT
2602 viewManagers( SVTK_Viewer::Type(), lst );
2603 QListIterator<SUIT_ViewManager*> itVTK( lst );
2604 while ( itVTK.hasNext() && sz >= 0 )
2606 SUIT_ViewModel* vm = itVTK.next()->getViewModel();
2607 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
2610 SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
2613 vtkVM->setTrihedronSize( sz, relative );
2621 if ( sec == QString( "3DViewer" ) && param == QString( "show_static_trihedron" ) )
2623 bool isVisible = resMgr->booleanValue( "3DViewer", "show_static_trihedron", true );
2624 QList<SUIT_ViewManager*> lst;
2625 #ifndef DISABLE_OCCVIEWER
2626 viewManagers( OCCViewer_Viewer::Type(), lst );
2627 QListIterator<SUIT_ViewManager*> itOCC( lst );
2628 while ( itOCC.hasNext() )
2630 SUIT_ViewModel* vm = itOCC.next()->getViewModel();
2631 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
2634 OCCViewer_Viewer* occVM = dynamic_cast<OCCViewer_Viewer*>( vm );
2637 occVM->setStaticTrihedronDisplayed( isVisible );
2641 #ifndef DISABLE_VTKVIEWER
2642 #ifndef DISABLE_SALOMEOBJECT
2643 viewManagers( SVTK_Viewer::Type(), lst );
2644 QListIterator<SUIT_ViewManager*> itVTK( lst );
2645 while ( itVTK.hasNext() )
2647 SUIT_ViewModel* vm = itVTK.next()->getViewModel();
2648 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
2651 SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
2654 vtkVM->setStaticTrihedronVisible( isVisible );
2662 if ( sec == QString( "3DViewer" ) && param == QString( "navigation_mode" ) )
2664 int mode = resMgr->integerValue( "3DViewer", "navigation_mode", 0 );
2665 QList<SUIT_ViewManager*> lst;
2666 #ifndef DISABLE_OCCVIEWER
2667 viewManagers( OCCViewer_Viewer::Type(), lst );
2668 QListIterator<SUIT_ViewManager*> itOCC( lst );
2669 while ( itOCC.hasNext() )
2671 SUIT_ViewModel* vm = itOCC.next()->getViewModel();
2672 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
2675 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
2676 occVM->setInteractionStyle( mode );
2679 #ifndef DISABLE_VTKVIEWER
2680 #ifndef DISABLE_SALOMEOBJECT
2681 viewManagers( SVTK_Viewer::Type(), lst );
2682 QListIterator<SUIT_ViewManager*> itVTK( lst );
2683 while ( itVTK.hasNext() )
2685 SUIT_ViewModel* vm = itVTK.next()->getViewModel();
2686 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
2689 SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
2690 if( vtkVM ) vtkVM->setInteractionStyle( mode );
2696 #ifndef DISABLE_OCCVIEWER
2697 if ( sec == QString( "OCCViewer" ) && param == QString( "enable_preselection" ) )
2699 bool isToEnablePreselection = resMgr->booleanValue( "OCCViewer", "enable_preselection", true );
2700 QList<SUIT_ViewManager*> lst;
2701 viewManagers( OCCViewer_Viewer::Type(), lst );
2702 QListIterator<SUIT_ViewManager*> it( lst );
2703 while ( it.hasNext() )
2705 SUIT_ViewModel* vm = it.next()->getViewModel();
2706 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
2709 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
2710 occVM->enablePreselection( isToEnablePreselection );
2715 #ifndef DISABLE_OCCVIEWER
2716 if ( sec == QString( "OCCViewer" ) && param == QString( "enable_selection" ) )
2718 bool isToEnableSelection = resMgr->booleanValue( "OCCViewer", "enable_selection", true );
2719 QList<SUIT_ViewManager*> lst;
2720 viewManagers( OCCViewer_Viewer::Type(), lst );
2721 QListIterator<SUIT_ViewManager*> it( lst );
2722 while ( it.hasNext() )
2724 SUIT_ViewModel* vm = it.next()->getViewModel();
2725 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
2728 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
2729 occVM->enableSelection( isToEnableSelection );
2734 if ( sec == QString( "3DViewer" ) && param == QString( "zooming_mode" ) )
2736 int mode = resMgr->integerValue( "3DViewer", "zooming_mode", 0 );
2737 QList<SUIT_ViewManager*> lst;
2738 #ifndef DISABLE_OCCVIEWER
2739 viewManagers( OCCViewer_Viewer::Type(), lst );
2740 QListIterator<SUIT_ViewManager*> itOCC( lst );
2741 while ( itOCC.hasNext() )
2743 SUIT_ViewModel* vm = itOCC.next()->getViewModel();
2744 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
2747 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
2748 occVM->setZoomingStyle( mode );
2751 #ifndef DISABLE_VTKVIEWER
2752 #ifndef DISABLE_SALOMEOBJECT
2753 viewManagers( SVTK_Viewer::Type(), lst );
2754 QListIterator<SUIT_ViewManager*> itVTK( lst );
2755 while ( itVTK.hasNext() )
2757 SUIT_ViewModel* vm = itVTK.next()->getViewModel();
2758 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
2761 SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
2762 if( vtkVM ) vtkVM->setZoomingStyle( mode );
2768 #ifndef DISABLE_VTKVIEWER
2769 if ( sec == QString( "VTKViewer" ) && (param == QString( "speed_value" ) || param == QString( "speed_mode" )) )
2771 int speed = resMgr->integerValue( "VTKViewer", "speed_value", 10 );
2772 int mode = resMgr->integerValue( "VTKViewer", "speed_mode", 0 );
2773 QList<SUIT_ViewManager*> lst;
2774 #ifndef DISABLE_SALOMEOBJECT
2775 viewManagers( SVTK_Viewer::Type(), lst );
2776 QListIterator<SUIT_ViewManager*> it( lst );
2777 while ( it.hasNext() )
2779 SUIT_ViewModel* vm = it.next()->getViewModel();
2780 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
2783 SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
2784 if( vtkVM ) vtkVM->setIncrementalSpeed( speed, mode );
2790 #ifndef DISABLE_VTKVIEWER
2791 if ( sec == QString( "VTKViewer" ) && param == QString( "projection_mode" ) )
2793 int mode = resMgr->integerValue( "VTKViewer", "projection_mode", 0 );
2794 QList<SUIT_ViewManager*> lst;
2795 #ifndef DISABLE_SALOMEOBJECT
2796 viewManagers( SVTK_Viewer::Type(), lst );
2797 QListIterator<SUIT_ViewManager*> it( lst );
2798 while ( it.hasNext() )
2800 SUIT_ViewModel* vm = it.next()->getViewModel();
2801 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
2804 SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
2805 if( vtkVM ) vtkVM->setProjectionMode( mode );
2811 #ifndef DISABLE_VTKVIEWER
2812 if ( sec == QString( "VTKViewer" ) && param == QString( "preselection" ) )
2814 int mode = resMgr->integerValue( "VTKViewer", "preselection", 0 );
2815 QList<SUIT_ViewManager*> lst;
2816 #ifndef DISABLE_SALOMEOBJECT
2817 viewManagers( SVTK_Viewer::Type(), lst );
2818 QListIterator<SUIT_ViewManager*> it( lst );
2819 while ( it.hasNext() )
2821 SUIT_ViewModel* vm = it.next()->getViewModel();
2822 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
2825 SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
2826 if( vtkVM ) vtkVM->setPreSelectionMode( mode );
2832 #ifndef DISABLE_VTKVIEWER
2833 if ( sec == QString( "VTKViewer" ) && param == QString( "enable_selection" ) )
2835 bool isToEnableSelection = resMgr->booleanValue( "VTKViewer", "enable_selection", true );
2836 QList<SUIT_ViewManager*> lst;
2837 #ifndef DISABLE_SALOMEOBJECT
2838 viewManagers( SVTK_Viewer::Type(), lst );
2839 QListIterator<SUIT_ViewManager*> it( lst );
2840 while ( it.hasNext() )
2842 SUIT_ViewModel* vm = it.next()->getViewModel();
2843 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
2846 SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
2847 if( vtkVM ) vtkVM->enableSelection( isToEnableSelection );
2853 #ifndef DISABLE_VTKVIEWER
2854 if ( sec == QString( "VTKViewer" ) && (param == QString( "spacemouse_func1_btn" ) ||
2855 param == QString( "spacemouse_func2_btn" ) ||
2856 param == QString( "spacemouse_func5_btn" ) ) )
2858 int btn1 = resMgr->integerValue( "VTKViewer", "spacemouse_func1_btn", 1 );
2859 int btn2 = resMgr->integerValue( "VTKViewer", "spacemouse_func2_btn", 2 );
2860 int btn3 = resMgr->integerValue( "VTKViewer", "spacemouse_func5_btn", 9 );
2861 QList<SUIT_ViewManager*> lst;
2862 #ifndef DISABLE_SALOMEOBJECT
2863 viewManagers( SVTK_Viewer::Type(), lst );
2864 QListIterator<SUIT_ViewManager*> it( lst );
2865 while ( it.hasNext() )
2867 SUIT_ViewModel* vm = it.next()->getViewModel();
2868 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
2871 SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
2872 if( vtkVM ) vtkVM->setSpacemouseButtons( btn1, btn2, btn3 );
2877 if( sec=="ObjectBrowser" )
2879 SUIT_DataBrowser* ob = objectBrowser();
2883 if ( param=="auto_size_first" )
2885 bool autoSizeFirst = resMgr->booleanValue( "ObjectBrowser", "auto_size_first", true );
2886 ob->setAutoSizeFirstColumn( autoSizeFirst );
2887 if ( autoSizeFirst )
2888 ob->adjustFirstColumnWidth();
2890 else if ( param=="auto_size" ) {
2891 bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
2892 ob->setAutoSizeColumns(autoSize);
2894 ob->adjustColumnsWidth();
2896 else if ( param=="resize_on_expand_item" ) {
2897 bool resizeOnExpandItem = resMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
2898 ob->setResizeOnExpandItem(resizeOnExpandItem);
2900 else if ( param == "auto_hide_search_tool" ) {
2901 ob->searchTool()->enableAutoHide( resMgr->booleanValue( "ObjectBrowser", "auto_hide_search_tool" ) );
2907 if( param=="auto_save_interval" ) {
2908 myAutoSaveTimer->stop();
2909 int autoSaveInterval = resMgr->integerValue( "Study", "auto_save_interval", 0 );
2910 if ( activeStudy() && autoSaveInterval > 0 ) myAutoSaveTimer->start( autoSaveInterval*60000 );
2914 #ifndef DISABLE_PYCONSOLE
2915 if( sec=="PyConsole" && pythonConsole() )
2917 if ( param=="font" ) {
2918 pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) );
2920 else if ( param=="show_banner" ) {
2921 pythonConsole()->setIsShowBanner( resMgr->booleanValue( "PyConsole", "show_banner", true ) );
2928 QtxMRUAction* mru = ::qobject_cast<QtxMRUAction*>( action( MRUId ) );
2930 if ( param == "visible_count" )
2931 mru->setVisibleCount( resMgr->integerValue( "MRU", "visible_count", 5 ) ); // 5 MRU items by default
2932 else if ( param == "max_count" )
2933 mru->setHistoryCount( resMgr->integerValue( "MRU", "max_count", -1 ) ); // unlimited history by default
2934 else if ( param == "insert_mode" )
2935 mru->setInsertMode( resMgr->integerValue( "MRU", "insert_mode", 0 ) ); // QtxMRUAction::MoveFirst by default
2936 else if ( param == "link_type" )
2937 mru->setLinkType( resMgr->integerValue( "MRU", "link_type", 0 ) ); // QtxMRUAction::LinkAuto by default
2938 else if ( param == "show_clear" )
2939 mru->setClearPossible( resMgr->booleanValue( "MRU", "show_clear", false ) ); // do not show "Clear" item by default
2940 else if ( param == "show_mru" )
2941 mru->setVisible( resMgr->booleanValue( "MRU", "show_mru", false ) ); // do not show MRU menu item by default
2944 if ( sec == "language" && param == "language" )
2946 SUIT_MessageBox::information( desktop(), tr( "WRN_WARNING" ), tr( "LANG_CHANGED" ) );
2948 if ( sec == "desktop" && param == "opaque_resize" ) {
2949 bool opaqueResize = resMgr->booleanValue( "desktop", "opaque_resize", false );
2950 QMainWindow::DockOptions dopts = desktop()->dockOptions();
2951 if ( opaqueResize ) dopts |= QMainWindow::AnimatedDocks;
2952 else dopts &= ~QMainWindow::AnimatedDocks;
2953 desktop()->setDockOptions( dopts );
2954 desktop()->setOpaqueResize( opaqueResize );
2955 if ( dynamic_cast<STD_TabDesktop*>( desktop() ) )
2956 dynamic_cast<STD_TabDesktop*>( desktop() )->workstack()->setOpaqueResize( opaqueResize );
2959 if ( sec == "ExternalBrowser" && param == "use_external_browser" ) {
2960 if ( resMgr->booleanValue("ExternalBrowser", "use_external_browser", false ) )
2962 QtxWebBrowser::shutdown();
2966 #ifndef DISABLE_PLOT2DVIEWER
2967 if ( sec == "Plot2d" ) {
2968 if( param == "SelectionColor" ) {
2969 QColor c = resMgr->colorValue( sec, param );
2970 Plot2d_Object::setSelectionColor(c);
2972 else if (param == "SelectedLegendFontColor") {
2973 QColor c = resMgr->colorValue( sec, param );
2974 Plot2d_Object::setHighlightedLegendTextColor(c);
2983 void LightApp_Application::loadPreferences()
2985 CAM_Application::loadPreferences();
2987 SUIT_ResourceMgr* aResMgr = resourceMgr();
2992 static bool mru_load = true;
2995 QtxMRUAction* mru = ::qobject_cast<QtxMRUAction*>( action( MRUId ) );
2997 mru->setVisible( aResMgr->booleanValue( "MRU", "show_mru", false ) ); // do not show MRU menu item by default
2998 mru->setVisibleCount( aResMgr->integerValue( "MRU", "visible_count", 5 ) ); // 5 MRU items by default
2999 mru->setHistoryCount( aResMgr->integerValue( "MRU", "max_count", -1 ) ); // unlimited history by default
3000 mru->setInsertMode( aResMgr->integerValue( "MRU", "insert_mode", 0 ) ); // QtxMRUAction::MoveFirst by default
3001 mru->setLinkType( aResMgr->integerValue( "MRU", "link_type", 0 ) ); // QtxMRUAction::LinkAuto by default
3002 mru->setClearPossible( aResMgr->booleanValue( "MRU", "show_clear", false ) ); // do not show "Clear" item by default
3003 mru->loadLinks( aResMgr, "MRU" );
3009 QStringList mods = aResMgr->parameters( "windows_visibility" );
3010 for ( QStringList::const_iterator itr = mods.begin(); itr != mods.end(); ++itr )
3013 if ( aResMgr->value( "windows_visibility", *itr, arr ) )
3014 myWinVis.insert( *itr, arr );
3018 desktop()->retrieveGeometry( aResMgr->stringValue( "desktop", "geometry" ) );
3019 bool opaqueResize = aResMgr->booleanValue( "desktop", "opaque_resize", false );
3020 QMainWindow::DockOptions dopts = desktop()->dockOptions();
3021 if ( opaqueResize ) dopts |= QMainWindow::AnimatedDocks;
3022 else dopts &= ~QMainWindow::AnimatedDocks;
3023 desktop()->setDockOptions( dopts );
3024 desktop()->setOpaqueResize( opaqueResize );
3025 if ( dynamic_cast<STD_TabDesktop*>( desktop() ) )
3026 dynamic_cast<STD_TabDesktop*>( desktop() )->workstack()->setOpaqueResize( opaqueResize );
3033 void LightApp_Application::savePreferences()
3035 CAM_Application::savePreferences();
3037 saveDockWindowsState();
3039 SUIT_ResourceMgr* aResMgr = resourceMgr();
3044 QtxMRUAction* mru = ::qobject_cast<QtxMRUAction*>( action( MRUId ) );
3046 mru->saveLinks( aResMgr, "MRU" );
3048 for ( WinVis::const_iterator itr = myWinVis.begin(); itr != myWinVis.end(); ++itr )
3049 aResMgr->setValue( "windows_visibility", itr.key(), itr.value() );
3052 aResMgr->setValue( "desktop", "geometry", desktop()->storeGeometry() );
3058 Updates desktop title
3060 void LightApp_Application::updateDesktopTitle()
3062 QString aTitle = applicationName();
3063 QString aVer = applicationVersion();
3064 if ( !aVer.isEmpty() )
3065 aTitle += QString( " " ) + aVer;
3067 if ( activeStudy() ) {
3068 QString sName = SUIT_Tools::file( activeStudy()->studyName().trimmed(), false );
3069 aTitle += QString( " - [%1]" ).arg( sName );
3072 desktop()->setWindowTitle( aTitle );
3076 \brief Get map of the operations which can be performed
3077 on the module activation.
3079 The method should return the map of the kind \c {<id>:<name>}
3080 where \c <id> is an integer identifier of the operation and
3081 \c <name> is a title for the button to be added to the
3082 dialog box. After user selects the required operation by the
3083 clicking the corresponding button in the dialog box, its identifier
3084 is passed to the moduleActionSelected() method to process
3087 \return map of the operations
3088 \sa moduleActionSelected()
3090 QMap<int, QString> LightApp_Application::activateModuleActions() const
3092 QMap<int, QString> opmap;
3093 opmap.insert( NewStudyId, tr( "ACTIVATE_MODULE_OP_NEW" ) );
3094 opmap.insert( OpenStudyId, tr( "ACTIVATE_MODULE_OP_OPEN" ) );
3099 \brief Called when the used selectes required operation chosen
3100 from "Activate module" dialog box.
3102 Performs the required operation according to the user choice.
3104 \param id operation identifier
3105 \sa activateModuleActions()
3107 void LightApp_Application::moduleActionSelected( const int id )
3122 Updates windows after close document
3124 void LightApp_Application::afterCloseDoc()
3128 CAM_Application::afterCloseDoc();
3132 Updates actions of active module
3134 void LightApp_Application::updateModuleActions()
3137 if ( activeModule() ) {
3138 modName = activeModule()->moduleName();
3139 if ( !isModuleAccessible( modName ) ) {
3140 QList<SUIT_Application*> apps = SUIT_Session::session()->applications();
3141 foreach( SUIT_Application* app, apps ) {
3142 LightApp_Application* lapp = dynamic_cast<LightApp_Application*>( app );
3143 if ( lapp && lapp != this )
3144 lapp->removeModuleAction( modName );
3149 LightApp_ModuleAction* moduleAction =
3150 qobject_cast<LightApp_ModuleAction*>( action( ModulesListId ) );
3152 moduleAction->setActiveModule( modName );
3155 void LightApp_Application::removeModuleAction( const QString& modName )
3157 LightApp_ModuleAction* moduleAction =
3158 qobject_cast<LightApp_ModuleAction*>( action( ModulesListId ) );
3160 moduleAction->removeModule( modName );
3164 Gets current windows.
3165 \param winMap - output current windows map.
3167 void LightApp_Application::currentWindows( QMap<int, int>& winMap ) const
3170 if ( !activeStudy() )
3173 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
3174 ((LightApp_Module*)activeModule())->windows( winMap );
3176 defaultWindows( winMap );
3180 Gets current view managers.
3181 \param lst - output current view managers list.
3183 void LightApp_Application::currentViewManagers( QStringList& lst ) const
3186 if ( !activeStudy() )
3189 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
3190 ((LightApp_Module*)activeModule())->viewManagers( lst );
3192 defaultViewManagers( lst );
3198 void LightApp_Application::updateWindows()
3200 QMap<int, int> winMap;
3201 currentWindows( winMap );
3203 if ( activeStudy() )
3205 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
3207 if ( !dockWindow( it.key() ) )
3208 getWindow( it.key() );
3212 for ( WinMap::ConstIterator it = myWin.begin(); it != myWin.end(); ++it )
3214 QWidget* wid = it.value();
3215 if ( activeStudy() )
3216 wid->setVisible( winMap.contains( it.key() ) );
3221 if ( activeStudy() )
3222 loadDockWindowsState();
3228 Updates view managers
3230 void LightApp_Application::updateViewManagers()
3233 currentViewManagers( lst );
3235 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
3236 getViewManager( *it, true );
3240 Loads windows geometry
3242 void LightApp_Application::loadDockWindowsState()
3246 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
3247 bool storeWin = aResMgr->booleanValue( "Study", "store_positions", true );
3248 bool storeTb = aResMgr->booleanValue( "Study", "store_tool_positions", true );
3251 if ( activeModule() )
3252 modName = activeModule()->name();
3254 QtxResourceMgr::WorkingMode prevMode = aResMgr->workingMode();
3255 aResMgr->setWorkingMode(QtxResourceMgr::IgnoreUserValues);
3256 QByteArray aDefaultState;
3257 aResMgr->value("windows_geometry", modName , aDefaultState );
3258 QByteArray aDefaultVisibility;
3259 aResMgr->value("windows_visibility", modName , aDefaultVisibility );
3260 bool hasDefaultVisibility = !aDefaultVisibility.isEmpty();
3261 aResMgr->setWorkingMode(prevMode);
3263 if( !storeWin && !storeTb && aDefaultState.isEmpty() && !hasDefaultVisibility)
3266 if ( aResMgr->hasValue("windows_geometry" ,modName ) ) {
3268 aResMgr->value("windows_geometry", modName , arr );
3269 QByteArray aTargetArray = processState(arr, storeWin, storeTb, true, aDefaultState);
3270 desktop()->restoreState( aTargetArray );
3273 if ( !myWinVis.contains( modName ) && aDefaultVisibility.isEmpty())
3276 QMap<QString, bool> *tbMap = 0;
3277 QMap<QString, bool> *dwMap = 0;
3279 QMap<QString, bool> userTbMap, userDwMap;
3280 dockWindowsState( myWinVis[modName], userTbMap, userDwMap );
3282 QMap<QString, bool> defaultTbMap, defaultDwMap;
3283 if(hasDefaultVisibility) {
3284 dockWindowsState( aDefaultVisibility, defaultTbMap, defaultDwMap);
3290 if(hasDefaultVisibility){
3291 tbMap = &defaultTbMap;
3298 if(hasDefaultVisibility){
3299 dwMap = &defaultDwMap;
3304 QList<QToolBar*> tbList = findToolBars();
3305 for ( QList<QToolBar*>::iterator tit = tbList.begin(); tit != tbList.end(); ++tit )
3307 QToolBar* tb = *tit;
3308 if ( tbMap->contains( tb->objectName() ) ) {
3309 tb->setVisible( (*tbMap)[tb->objectName()] );
3315 QList<QDockWidget*> dwList = qFindChildren<QDockWidget*>( desktop() );
3316 for ( QList<QDockWidget*>::iterator dit = dwList.begin(); dit != dwList.end(); ++dit )
3318 QDockWidget* dw = *dit;
3320 QObject* po = Qtx::findParent( dw, "QMainWindow" );
3321 if ( po != desktop() )
3324 if ( dwMap->contains( dw->objectName() ) )
3325 dw->setVisible( (*dwMap)[dw->objectName()] );
3332 Saves windows geometry
3334 void LightApp_Application::saveDockWindowsState()
3339 bool storeWin = resourceMgr()->booleanValue( "Study", "store_positions", true );
3340 bool storeTb = resourceMgr()->booleanValue( "Study", "store_tool_positions", true );
3342 if( !storeWin && !storeTb )
3346 if ( activeModule() )
3347 modName = activeModule()->name();
3349 QByteArray arr = desktop()->saveState();
3350 resourceMgr()->setValue( "windows_geometry", modName, processState(arr, storeWin, storeTb, false) );
3353 if ( myWinVis.contains( modName ) )
3354 visArr = myWinVis[modName];
3356 QMap<QString, bool> tbMap, dwMap;
3357 dockWindowsState( visArr, tbMap, dwMap );
3359 QList<QToolBar*> tbList = qFindChildren<QToolBar*>( desktop() );
3360 for ( QList<QToolBar*>::iterator it = tbList.begin(); it != tbList.end(); ++it )
3363 tbMap.insert( tb->objectName(), tb->toggleViewAction()->isChecked() );
3366 QList<QDockWidget*> dwList = qFindChildren<QDockWidget*>( desktop() );
3367 for ( QList<QDockWidget*>::iterator it = dwList.begin(); it != dwList.end(); ++it )
3369 QDockWidget* wid = *it;
3370 dwMap.insert( wid->objectName(), wid->toggleViewAction()->isChecked() );
3373 visArr = dockWindowsState( tbMap, dwMap );
3375 myWinVis.insert( modName, visArr );
3378 QByteArray LightApp_Application::dockWindowsState( const QMap<QString, bool>& tb, const QMap<QString, bool>& dw ) const
3381 QDataStream stream( &visArr, QIODevice::WriteOnly );
3383 stream << (uchar)ToolBarMarker;
3384 stream << tb.size();
3385 for ( QMap<QString, bool>::const_iterator tit = tb.begin(); tit != tb.end(); ++tit )
3387 stream << tit.key();
3388 stream << (uchar)( tit.value() ? 1 : 0 );
3391 stream << (uchar)DockWidgetMarker;
3392 stream << dw.size();
3393 for ( QMap<QString, bool>::const_iterator wit = dw.begin(); wit != dw.end(); ++wit )
3395 stream << wit.key();
3396 stream << (uchar)( wit.value() ? 1 : 0 );
3402 void LightApp_Application::dockWindowsState( const QByteArray& arr, QMap<QString, bool>& tb, QMap<QString, bool>& dw ) const
3407 QByteArray visArr = arr;
3408 QDataStream stream( &visArr, QIODevice::ReadOnly );
3412 if ( marker != ToolBarMarker )
3417 for ( int i = 0; i < lines; ++i )
3420 stream >> objectName;
3423 tb.insert( objectName, shown );
3427 if ( marker != DockWidgetMarker )
3431 for ( int j = 0; j < lines; ++j )
3434 stream >> objectName;
3437 dw.insert( objectName, shown );
3442 Adds icon names for modules
3444 void LightApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
3448 SUIT_ResourceMgr* resMgr = resourceMgr();
3452 QStringList modList;
3453 modules( modList, false );
3455 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
3457 QString modName = *it;
3458 QString modIntr = moduleName( modName );
3459 QString modIcon = resMgr->stringValue( modIntr, "icon", QString() );
3461 if ( modIcon.isEmpty() )
3464 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
3465 modIcon += QString( ".png" );
3467 iconMap.insert( modName, modIcon );
3472 Inserts items in popup, which necessary for current application
3474 void LightApp_Application::contextMenuPopup( const QString& type, QMenu* thePopup, QString& title )
3477 LightApp_SelectionMgr* selMgr = LightApp_Application::selectionMgr();
3478 bool cacheIsOn = selMgr->isSelectionCacheEnabled();
3479 selMgr->setSelectionCacheEnabled( true );
3481 SUIT_DataBrowser* ob = objectBrowser();
3483 CAM_Application::contextMenuPopup( type, thePopup, title );
3485 if ( ob && type == ob->popupClientType() ) {
3486 thePopup->addSeparator();
3487 QAction* a = thePopup->addAction( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
3488 if ( ob->shortcutKey(SUIT_DataBrowser::UpdateShortcut) )
3489 a->setShortcut( ob->shortcutKey(SUIT_DataBrowser::UpdateShortcut) );
3492 #ifndef DISABLE_SALOMEOBJECT
3493 if ( selMgr && ob ) {
3494 SALOME_ListIO selected;
3495 selMgr->selectedObjects( selected );
3496 if(selected.Extent() == 1){
3497 Handle(SALOME_InteractiveObject) anIObject = selected.First();
3498 SUIT_DataObject* obj = findObject(anIObject->getEntry());
3499 if(obj && obj->renameAllowed()) {
3500 QAction* a = new QAction(tr("MEN_RENAME_OBJ"), thePopup);
3501 connect( a, SIGNAL( triggered(bool) ), ob, SLOT( onStartEditing() ) );
3502 if ( ob->shortcutKey(SUIT_DataBrowser::RenameShortcut) )
3503 a->setShortcut( ob->shortcutKey(SUIT_DataBrowser::RenameShortcut) );
3505 QList<QAction*> acts = thePopup->actions();
3506 QAction* firstAction = acts.count() > 0 ? acts.first() : 0;
3507 thePopup->insertAction(firstAction,a);
3513 selMgr->setSelectionCacheEnabled( cacheIsOn );
3519 void LightApp_Application::createEmptyStudy()
3521 CAM_Application::createEmptyStudy();
3523 if ( objectBrowser() )
3524 objectBrowser()->updateTree();
3526 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
3527 if ( aResMgr && activeStudy() ) {
3528 int autoSaveInterval = aResMgr->integerValue( "Study", "auto_save_interval", 0 );
3529 if ( autoSaveInterval > 0 ) myAutoSaveTimer->start( autoSaveInterval*60000 );
3534 void LightApp_Application::setDesktop( SUIT_Desktop* desk )
3536 CAM_Application::setDesktop( desk );
3539 connect( desk, SIGNAL( message( const QString& ) ),
3540 this, SLOT( onDesktopMessage( const QString& ) ), Qt::UniqueConnection );
3546 \param mod - module to be activated
3548 bool LightApp_Application::activateModule( CAM_Module* mod )
3550 bool res = CAM_Application::activateModule( mod );
3552 if ( objectBrowser() )
3553 objectBrowser()->updateTree();
3559 \return keyborad accelerators manager object
3561 SUIT_Accel* LightApp_Application::accel() const
3567 Removes dead widget container from map
3569 void LightApp_Application::onWCDestroyed( QObject* ob )
3571 // remove destroyed widget container from windows map
3572 for ( WinMap::ConstIterator itr = myWin.begin(); itr != myWin.end(); ++itr )
3574 if ( itr.value() != ob )
3577 int key = itr.key();
3578 myWin.remove( key );
3583 void LightApp_Application::onMRUActivated( const QString& name )
3585 SUIT_Session* s = SUIT_Session::session();
3586 if ( s && s->activeApplication() == this )
3590 void LightApp_Application::onStylePreferences()
3592 Style_PrefDlg dlg( desktop() );
3595 resourceMgr()->setValue( "Style", "use_salome_style", Style_Salome::isActive() );
3598 void LightApp_Application::onFullScreen(){
3599 if(myScreenHelper) {
3600 if(desktop()->isFullScreen())
3601 myScreenHelper->switchToNormalScreen();
3603 myScreenHelper->switchToFullScreen();
3608 Connects just added view manager
3610 void LightApp_Application::addViewManager( SUIT_ViewManager* vm )
3612 connect( vm, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
3613 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
3614 CAM_Application::addViewManager( vm );
3618 Remove view manager from memory
3620 void LightApp_Application::removeViewManager( SUIT_ViewManager* vm )
3622 disconnect( vm, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
3623 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
3624 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>(activeStudy());
3626 aStudy->removeViewMgr(vm->getGlobalId());
3628 CAM_Application::removeViewManager( vm );
3630 LightApp_SelectionMgr* selMgr = selectionMgr();
3631 QList<SUIT_Selector*> selectors;
3632 selMgr->selectors( selectors );
3633 foreach( SUIT_Selector* selector, selectors ) {
3634 if ( selector->owner() == vm->getViewModel() ) {
3639 // IPAL22894: Crash on closing OCC view
3645 Renames active window of desktop
3647 void LightApp_Application::onRenameWindow()
3652 QWidget* w = desktop()->activeWindow();
3657 QString name = QInputDialog::getText( w, tr( "TOT_RENAME" ), tr( "PRP_RENAME" ), QLineEdit::Normal, w->windowTitle(), &ok );
3658 if( ok && !name.isEmpty() )
3659 w->setWindowTitle( name );
3663 Closes active window of desktop
3665 void LightApp_Application::onCloseWindow()
3670 QWidget* w = desktop()->activeWindow();
3678 Closes all windows of desktop
3680 void LightApp_Application::onCloseAllWindow()
3682 STD_TabDesktop* desk = dynamic_cast<STD_TabDesktop*>( desktop() );
3686 QList<SUIT_ViewWindow*> wndList = desk->windows();
3687 SUIT_ViewWindow* wnd;
3688 foreach( wnd, wndList )
3696 Groups all windows of desktop
3698 void LightApp_Application::onGroupAllWindow()
3700 STD_TabDesktop* desk = dynamic_cast<STD_TabDesktop*>( desktop() );
3704 QtxWorkstack* wgStack = desk->workstack();
3710 \return if the library of module exists
3711 \param moduleTitle - title of module
3713 bool LightApp_Application::isLibExists( const QString& moduleTitle ) const
3715 if( moduleTitle.isEmpty() )
3718 QString lib = moduleLibrary( moduleTitle );
3720 //abd: changed libSalomePyQtGUI to SalomePyQtGUI for WIN32
3721 bool isPythonModule = lib.contains("SalomePyQtGUI");
3722 bool isPythonLightModule = lib.contains("SalomePyQtGUILight");
3726 paths = QString(::getenv( "PATH" )).split( ";", QString::SkipEmptyParts );
3728 paths = QString(::getenv( "LD_LIBRARY_PATH" )).split( ":", QString::SkipEmptyParts );
3731 bool isLibFound = false;
3732 QStringList::const_iterator anIt = paths.begin(), aLast = paths.end();
3733 for( ; anIt!=aLast; anIt++ )
3735 QFileInfo inf( Qtx::addSlash( *anIt ) + lib );
3746 INFOS( "\n****************************************************************" << std::endl
3747 << "* Warning: library " << lib.toLatin1().constData() << " cannot be found" << std::endl
3748 << "* Module " << moduleTitle.toLatin1().constData() << " will not be available in GUI mode" << std::endl
3749 << "****************************************************************" << std::endl );
3751 else if ( !isPythonModule && !isPythonLightModule)
3754 if ( isPythonModule || isPythonLightModule)
3756 QString pylib = moduleName( moduleTitle ) + QString(".py");
3757 QString pylibgui = moduleName( moduleTitle ) + QString("GUI.py");
3759 // Check the python library
3761 // paths = QString(::getenv( "PATH" )).split( ";", QString::SkipEmptyParts );
3763 paths = QString(::getenv( "PYTHONPATH" )).split( ":", QString::SkipEmptyParts );
3765 bool isPyLib = false, isPyGuiLib = false;
3766 QStringList::const_iterator anIt = paths.begin(), aLast = paths.end();
3767 for( ; anIt!=aLast; anIt++ )
3769 QFileInfo inf( Qtx::addSlash( *anIt ) + pylib );
3770 QFileInfo infgui( Qtx::addSlash( *anIt ) + pylibgui );
3772 if(!isPythonLightModule)
3773 if( !isPyLib && inf.exists() )
3776 if( !isPyGuiLib && infgui.exists() )
3779 if ((isPyLib || isPythonLightModule ) && isPyGuiLib && isLibFound)
3783 printf( "\n****************************************************************\n" );
3784 printf( "* Warning: python library for %s cannot be found:\n", moduleTitle.toLatin1().constData() );
3786 printf( "* No module named %s\n", moduleName( moduleTitle ).toLatin1().constData() );
3788 printf( "* No module named %s\n", (moduleName( moduleTitle ) + QString("GUI")).toLatin1().constData() );
3789 printf( "****************************************************************\n" );
3796 \return default name for an active study
3798 void LightApp_Application::setDefaultStudyName( const QString& theName )
3800 QStringList anInfoList;
3801 modules( anInfoList, false );
3803 LightApp_Study* aStudy = (LightApp_Study*)activeStudy();
3804 if( anInfoList.count() == 1 && // to avoid a conflict between different modules
3805 !aStudy->isSaved() )
3807 aStudy->setStudyName( theName );
3808 updateDesktopTitle();
3813 Custom event handler
3815 bool LightApp_Application::event( QEvent* e )
3817 if( e && e->type()==2000 )
3819 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
3820 QString* d = ( QString* )ce->data();
3821 if( SUIT_MessageBox::question(0, tr("WRN_WARNING"),
3823 SUIT_MessageBox::Yes | SUIT_MessageBox::No,
3824 SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes )
3825 showPreferences( tr( "PREF_APP" ) );
3830 return CAM_Application::event( e );
3833 /*! Check data object */
3834 bool LightApp_Application::checkDataObject(LightApp_DataObject* theObj)
3838 bool isSuitable = !theObj->entry().isEmpty() &&
3839 !theObj->componentDataType().isEmpty() &&
3840 !theObj->name().isEmpty();
3847 int LightApp_Application::openChoice( const QString& aName )
3849 int choice = CAM_Application::openChoice( aName );
3851 if ( choice == OpenExist ) // The document is already open.
3853 // Do you want to reload it?
3854 if ( SUIT_MessageBox::question( desktop(), tr( "WRN_WARNING" ), tr( "QUE_DOC_ALREADYOPEN" ).arg( aName ),
3855 SUIT_MessageBox::Yes | SUIT_MessageBox::No, SUIT_MessageBox::No ) == SUIT_MessageBox::Yes )
3856 choice = OpenReload;
3862 bool LightApp_Application::openAction( const int choice, const QString& aName )
3869 STD_Application* app = 0;
3870 SUIT_Session* session = SUIT_Session::session();
3871 QList<SUIT_Application*> appList = session->applications();
3872 for ( QList<SUIT_Application*>::iterator it = appList.begin(); it != appList.end() && !app; ++it )
3874 if ( (*it)->activeStudy() && (*it)->activeStudy()->studyName() == aName )
3875 app = ::qobject_cast<STD_Application*>( *it );
3880 app->onCloseDoc( false );
3881 appList = session->applications();
3882 STD_Application* other = 0;
3883 for ( QList<SUIT_Application*>::iterator it = appList.begin(); it != appList.end() && !other; ++it )
3884 other = ::qobject_cast<STD_Application*>( *it );
3887 res = other->onOpenDoc( aName );
3892 res = CAM_Application::openAction( choice, aName );
3899 QStringList LightApp_Application::viewManagersTypes() const
3901 QStringList aTypesList;
3902 aTypesList += myUserWmTypes;
3903 #ifndef DISABLE_GLVIEWER
3904 aTypesList<<GLViewer_Viewer::Type();
3906 #ifndef DISABLE_PLOT2DVIEWER
3907 aTypesList<<Plot2d_Viewer::Type();
3909 #ifndef DISABLE_QXGRAPHVIEWER
3910 aTypesList<<QxScene_Viewer::Type();
3912 #ifndef DISABLE_OCCVIEWER
3913 aTypesList<<OCCViewer_Viewer::Type();
3915 #ifndef DISABLE_VTKVIEWER
3916 #ifndef DISABLE_SALOMEOBJECT
3917 aTypesList<<SVTK_Viewer::Type();
3919 aTypesList<<VTKViewer_Viewer::Type();
3925 * Removes all view managers of known types
3926 * Other view managers are ignored
3928 void LightApp_Application::clearKnownViewManagers()
3930 QStringList aTypesList = viewManagersTypes();
3931 QList<SUIT_ViewManager*> aMgrList;
3932 viewManagers( aMgrList );
3933 foreach (SUIT_ViewManager* aMgr, aMgrList) {
3934 if (aTypesList.contains(aMgr->getType()))
3935 removeViewManager(aMgr);
3940 Copy of current selection
3942 void LightApp_Application::onCopy()
3944 LightApp_Module* m = dynamic_cast<LightApp_Module*>( activeModule() );
3950 Paste of current data in clipboard
3952 void LightApp_Application::onPaste()
3954 LightApp_Module* m = dynamic_cast<LightApp_Module*>( activeModule() );
3960 Browse (i.e. set focus on) the published objects
3961 \param theIsApplyAndClose - flag indicating that the dialog for creating objects
3962 has been accepted by Ok (or Apply & Close) button
3963 \param theIsOptimizedBrowsing - flag switching to optimized browsing mode
3964 (to select the first published object only)
3965 \return entry of the selected object
3967 QString LightApp_Application::browseObjects( const QStringList& theEntryList,
3968 const bool theIsApplyAndClose,
3969 const bool theIsOptimizedBrowsing )
3972 if( SUIT_ResourceMgr* aResourceMgr = resourceMgr() )
3974 int aBrowsePolicy = aResourceMgr->integerValue( "ObjectBrowser", "browse_published_object", (int)BP_Never );
3975 switch( aBrowsePolicy )
3979 case BP_ApplyAndClose:
3980 if( !theIsApplyAndClose )
3988 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( activeStudy() );
3992 SUIT_DataBrowser* anOB = objectBrowser();
3996 SUIT_AbstractModel* aModel = dynamic_cast<SUIT_AbstractModel*>( anOB->model() );
4000 QStringListIterator anIter( theEntryList );
4001 if( theIsOptimizedBrowsing )
4003 // go to the last entry
4005 if( anIter.hasPrevious() )
4009 // scroll to each entry in the list
4010 // (in optimized mode - to the last entry only)
4012 LightApp_DataObject* anObject = 0;
4013 while( anIter.hasNext() )
4015 anEntry = anIter.next();
4016 if( !anEntry.isEmpty() )
4018 anObject = aStudy->findObjectByEntry( anEntry );
4021 QModelIndex anIndex = aModel->index( anObject );
4022 anOB->treeView()->scrollTo( anIndex );
4027 // always select the last object
4028 if( anObject && !anEntry.isEmpty() )
4030 QList<SUIT_Selector*> aSelectorList;
4031 selectionMgr()->selectors( "ObjectBrowser", aSelectorList );
4032 if( !aSelectorList.isEmpty() )
4034 if( LightApp_OBSelector* aSelector = dynamic_cast<LightApp_OBSelector*>( aSelectorList.first() ) )
4036 bool anIsAutoBlock = aSelector->autoBlock();
4038 // temporarily disable auto block, to emit LightApp_SelectionMgr::currentSelectionChanged() signal
4039 aSelector->setAutoBlock( false );
4041 SUIT_DataOwnerPtrList aList;
4042 #ifndef DISABLE_SALOMEOBJECT
4043 Handle(SALOME_InteractiveObject) aSObj = new SALOME_InteractiveObject
4044 ( anObject->entry().toLatin1().constData(),
4045 anObject->componentDataType().toLatin1().constData(),
4046 anObject->name().toLatin1().constData() );
4047 LightApp_DataOwner* owner = new LightApp_DataOwner( aSObj );
4049 LightApp_DataOwner* owner = new LightApp_DataOwner( anEntry );
4052 aList.append( owner );
4053 selectionMgr()->setSelected( aList );
4056 // restore auto block flag
4057 aSelector->setAutoBlock( anIsAutoBlock );
4065 SUIT_DataObject* LightApp_Application::findObject( const QString& id ) const
4067 LightApp_Study* study = dynamic_cast<LightApp_Study*>( activeStudy() );
4068 return study ? study->findObjectByEntry( id ) : 0;
4072 Checks that an object can be renamed.
4073 \param entry entry of the object
4074 \brief Return \c true if object can be renamed
4076 bool LightApp_Application::renameAllowed( const QString& /*entry*/) const {
4081 Rename object by entry.
4082 \param entry entry of the object
4083 \param name new name of the object
4084 \brief Return \c true if rename operation finished successfully, \c false otherwise.
4086 bool LightApp_Application::renameObject( const QString& entry, const QString& ) {
4090 /*! Process standard messages from desktop */
4091 void LightApp_Application::onDesktopMessage( const QString& message )
4093 const QString sectionSeparator = "/";
4095 if ( message.toLower() == "updateobjectbrowser" ||
4096 message.toLower() == "updateobjbrowser" ) {
4097 // update object browser
4098 updateObjectBrowser();
4101 QStringList data = message.split( sectionSeparator );
4102 if ( data.count() > 1 ) {
4103 QString msgType = data[0].trimmed();
4104 LightApp_Module* sMod = 0;
4105 CAM_Module* mod = module( msgType );
4107 mod = module( moduleTitle( msgType ) );
4108 if ( mod && mod->inherits( "LightApp_Module" ) )
4109 sMod = (LightApp_Module*)mod;
4111 if ( msgType.toLower() == "preferences" ) {
4112 // requested preferences change: should be given as "preferences/<section>/<name>/<value>"
4113 // for example "preferences/Study/multi_file_dump/true"
4114 if ( data.count() > 3 ) {
4115 QString section = data[1].trimmed();
4116 QString param = data[2].trimmed();
4117 QString value = QStringList( data.mid(3) ).join( sectionSeparator );
4118 resourceMgr()->setValue( section, param, value );
4122 // received message for the module
4123 QString msg = QStringList( data.mid(1) ).join( sectionSeparator );
4124 sMod->message( msg );
4132 Returns all top level toolbars.
4133 Note : Result list contains only main window toolbars, not including toolbars from viewers.
4135 QList<QToolBar*> LightApp_Application::findToolBars() {
4136 QList<QToolBar*> aResult;
4137 QList<QToolBar*> tbList = qFindChildren<QToolBar*>( desktop() );
4138 for ( QList<QToolBar*>::iterator tit = tbList.begin(); tit != tbList.end(); ++tit ) {
4139 QToolBar* tb = *tit;
4140 QObject* po = Qtx::findParent( tb, "QMainWindow" );
4141 if ( po != desktop() )
4149 Internal method to parse toolbars and dockable windows state.
4151 QByteArray LightApp_Application::processState(QByteArray& input,
4152 const bool processWin,
4153 const bool processTb,
4154 const bool isRestoring,
4155 QByteArray defaultState) {
4158 bool hasDefaultState = !defaultState.isEmpty();
4159 bool isDockWinWriten = false;
4161 //Write date from users settings
4163 QDataStream tmpInputData(&input, QIODevice::ReadOnly);
4164 int marker, version;
4166 tmpInputData >> marker;
4167 tmpInputData >> version;
4168 tmpInputData >> dockmarker;
4169 tmpInputData >> nbDocWin;
4171 if(processWin && processTb && !isRestoring) {
4173 } else if(!processWin && !processTb ) {
4175 aRes = defaultState;
4177 QDataStream aData(&aRes, QIODevice::WriteOnly);
4178 QList<QToolBar*> aToolBars = findToolBars();
4181 for ( QList<QToolBar*>::iterator tit = aToolBars.begin(); tit != aToolBars.end(); ++tit ) {
4182 QToolBar* tb = *tit;
4183 aNames.append(tb->objectName());
4186 int toolBarMarkerIndex = getToolbarMarkerIndex(input,aNames);
4187 QDataStream anInputData(&input, QIODevice::ReadOnly);
4188 if(toolBarMarkerIndex < 0)
4191 int toolBarMarkerIndexDef;
4192 if(hasDefaultState) {
4193 toolBarMarkerIndexDef = getToolbarMarkerIndex(defaultState, aNames);
4194 if(toolBarMarkerIndexDef < 0)
4197 QDataStream anInputDataDef(&defaultState, QIODevice::ReadOnly);
4199 QDataStream* aTargetData = 0;
4200 int aTargetIndex = -1;
4202 QByteArray currentArr = desktop()->saveState();
4203 QDataStream anInputDataCur(¤tArr, QIODevice::ReadOnly);
4204 bool useInputData = !isRestoring || (isRestoring && nbDocWin > 0);
4205 if(processWin && useInputData) {
4206 aTargetData = &anInputData;
4207 aTargetIndex = toolBarMarkerIndex;
4209 //Write date from default settings
4210 if(hasDefaultState) {
4211 aTargetData = &anInputDataDef;
4212 aTargetIndex = toolBarMarkerIndexDef;
4214 //If no default state, write current snapshot of the dockable windows
4216 aTargetData = &anInputDataCur;
4217 int toolBarMarkerIndexCur = getToolbarMarkerIndex(currentArr, aNames);
4218 aTargetIndex = toolBarMarkerIndexCur;
4223 if(aTargetData && aTargetIndex >= 0 ) {
4224 aTargetData->device()->seek(0);
4225 while( aTargetData->device()->pos() < aTargetIndex ) {
4230 isDockWinWriten = true;
4237 aTargetData = &anInputData;
4238 aTargetIndex = toolBarMarkerIndex;
4240 if(hasDefaultState) {
4241 aTargetData = &anInputDataDef;
4242 aTargetIndex = toolBarMarkerIndexDef;
4246 if(aTargetData && aTargetIndex >= 0) {
4248 if(!isDockWinWriten ) {
4249 //Write version marker
4250 int marker, version;
4251 aTargetData->device()->seek(0);
4252 *aTargetData >> marker;
4253 *aTargetData >> version;
4256 aData << (uchar) QDockWidgetMarker;
4258 int shift = 4*sizeof(int) + sizeof(QSize);
4259 index = aTargetIndex - shift;
4261 index = aTargetIndex;
4264 aTargetData->device()->seek(index);
4265 while(!aTargetData->atEnd()) {
4270 } else { // Not treat toolbars
4271 aData << (uchar) QToolBarMarker;
4272 aData << (int) 0; //Nb toolbars = 0
4279 \brief Emits operationFinished signal.
4280 \param theModuleName the name of the module which perfomed the operation
4281 \param theOperationName the operation name
4282 \param theEntryList the list of the created objects entries
4284 void LightApp_Application::emitOperationFinished( const QString& theModuleName,
4285 const QString& theOperationName,
4286 const QStringList& theEntryList )
4288 emit operationFinished( theModuleName, theOperationName, theEntryList );