1 // File: LightApp_Application.cxx
2 // Created: 6/20/2005 18:39:45 PM
3 // Author: Natalia Donis
4 // Copyright (C) CEA 2005
6 #include "PythonConsole_PyInterp.h" // WARNING! This include must be the first!
8 #include "LightApp_Application.h"
9 #include "LightApp_WidgetContainer.h"
10 #include "LightApp_Module.h"
11 #include "LightApp_DataModel.h"
12 #include "LightApp_Study.h"
13 #include "LightApp_Preferences.h"
14 #include "LightApp_PreferencesDlg.h"
15 #include "LightApp_ModuleDlg.h"
16 #include "LightApp_AboutDlg.h"
18 #include "LightApp_OBFilter.h"
20 #include "LightApp_GLSelector.h"
21 #include "LightApp_OBSelector.h"
22 #include "LightApp_OCCSelector.h"
23 #include "LightApp_VTKSelector.h"
24 #include "LightApp_SelectionMgr.h"
26 #include <CAM_Module.h>
27 #include <CAM_DataModel.h>
28 #include <CAM_Study.h>
29 #include <STD_TabDesktop.h>
31 #include <SUIT_Session.h>
32 #include <SUIT_Study.h>
33 #include <SUIT_FileDlg.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_Tools.h>
36 #include <SUIT_Accel.h>
38 #include <QtxMRUAction.h>
39 #include <QtxDockAction.h>
40 #include <QtxToolBar.h>
42 #include <LogWindow.h>
43 #include <OB_Browser.h>
44 #include <PythonConsole_PyConsole.h>
46 #include <GLViewer_Viewer.h>
47 #include <GLViewer_ViewManager.h>
49 #include <Plot2d_ViewManager.h>
50 #include <Plot2d_ViewModel.h>
51 #include <SPlot2d_ViewModel.h>
53 #include <OCCViewer_ViewManager.h>
54 #include <SOCC_ViewModel.h>
56 #include <SVTK_ViewModel.h>
57 #include <SVTK_ViewManager.h>
58 #include <VTKViewer_ViewModel.h>
60 #include <SUPERVGraph_ViewModel.h>
61 #include <SUPERVGraph_ViewFrame.h>
62 #include <SUPERVGraph_ViewManager.h>
68 #include <qstringlist.h>
70 #include <qapplication.h>
72 #include <qstatusbar.h>
75 #define OBJECT_BROWSER_WIDTH 300
76 #define OBJECT_COLUMN_WIDTH 150
78 #define DEFAULT_BROWSER "mozilla"
80 #define FIRST_HELP_ID 1000000
82 #include "SALOME_InteractiveObject.hxx"
83 #include "SALOME_ListIO.hxx"
85 static const char* imageEmptyIcon[] = {
88 "....................",
89 "....................",
90 "....................",
91 "....................",
92 "....................",
93 "....................",
94 "....................",
95 "....................",
96 "....................",
97 "....................",
98 "....................",
99 "....................",
100 "....................",
101 "....................",
102 "....................",
103 "....................",
104 "....................",
105 "....................",
106 "....................",
107 "...................."};
109 /*!Create new instance of LightApp_Application.*/
110 extern "C" LIGHTAPP_EXPORT SUIT_Application* createApplication()
112 return new LightApp_Application();
115 LightApp_Preferences* LightApp_Application::_prefs_ = 0;
118 Class : LightApp_Application
119 Description : Application containing LightApp module
123 LightApp_Application::LightApp_Application()
124 : CAM_Application( false ),
127 STD_TabDesktop* desk = new STD_TabDesktop();
131 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
132 QPixmap aLogo = aResMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false );
134 desktop()->setIcon( aLogo );
135 desktop()->setDockableMenuBar( true );
136 desktop()->setDockableStatusBar( false );
138 // base logo (salome itself)
139 desktop()->addLogo( "_app_base", aResMgr->loadPixmap( "LightApp", tr( "APP_BASE_LOGO" ), false ) );
140 // extra logo (salome-based application)
141 desktop()->addLogo( "_app_extra", aResMgr->loadPixmap( "LightApp", tr( "APP_EXTRA_LOGO" ), false ) );
145 mySelMgr = new LightApp_SelectionMgr( this );
147 myAccel = new SUIT_Accel( desktop() );
148 myAccel->setActionKey( SUIT_Accel::PanLeft, CTRL+Key_Left, OCCViewer_Viewer::Type() );
149 myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, OCCViewer_Viewer::Type() );
150 myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, OCCViewer_Viewer::Type() );
151 myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, OCCViewer_Viewer::Type() );
152 myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, OCCViewer_Viewer::Type() );
153 myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, OCCViewer_Viewer::Type() );
154 myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, OCCViewer_Viewer::Type() );
155 myAccel->setActionKey( SUIT_Accel::RotateLeft, ALT+Key_Left, OCCViewer_Viewer::Type() );
156 myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right, OCCViewer_Viewer::Type() );
157 myAccel->setActionKey( SUIT_Accel::RotateUp, ALT+Key_Up, OCCViewer_Viewer::Type() );
158 myAccel->setActionKey( SUIT_Accel::RotateDown, ALT+Key_Down, OCCViewer_Viewer::Type() );
159 myAccel->setActionKey( SUIT_Accel::PanLeft, CTRL+Key_Left, VTKViewer_Viewer::Type() );
160 myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, VTKViewer_Viewer::Type() );
161 myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, VTKViewer_Viewer::Type() );
162 myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, VTKViewer_Viewer::Type() );
163 myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, VTKViewer_Viewer::Type() );
164 myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, VTKViewer_Viewer::Type() );
165 myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, VTKViewer_Viewer::Type() );
166 myAccel->setActionKey( SUIT_Accel::RotateLeft, ALT+Key_Left, VTKViewer_Viewer::Type() );
167 myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right, VTKViewer_Viewer::Type() );
168 myAccel->setActionKey( SUIT_Accel::RotateUp, ALT+Key_Up, VTKViewer_Viewer::Type() );
169 myAccel->setActionKey( SUIT_Accel::RotateDown, ALT+Key_Down, VTKViewer_Viewer::Type() );
171 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) );
175 *\li Save window geometry.
176 *\li Save desktop geometry.
177 *\li Save resource maneger.
178 *\li Delete selection manager.
180 LightApp_Application::~LightApp_Application()
182 saveWindowsGeometry();
187 desktop()->saveGeometry( resourceMgr(), "desktop" );
188 resourceMgr()->save();
193 /*!Start application.*/
194 void LightApp_Application::start()
197 desktop()->loadGeometry( resourceMgr(), "desktop" );
199 CAM_Application::start();
201 QAction* a = action( ViewWindowsId );
202 if ( a && a->inherits( "QtxDockAction" ) )
203 ((QtxDockAction*)a)->setAutoPlace( true );
206 updateViewManagers();
209 desktop()->statusBar()->message( "" );
212 /*!Gets application name.*/
213 QString LightApp_Application::applicationName() const
215 return tr( "APP_NAME" );
218 /*!Gets application version.*/
219 QString LightApp_Application::applicationVersion() const
221 static QString _app_version;
223 if ( _app_version.isEmpty() )
225 QString resVersion = tr( "APP_VERSION" );
226 if ( resVersion != "APP_VERSION" )
228 _app_version = resVersion;
232 QString path( ::getenv( "GUI_ROOT_DIR" ) );
233 if ( !path.isEmpty() )
234 path += QDir::separator();
235 path += QString( "bin/salome/VERSION" );
238 if ( vf.open( IO_ReadOnly ) )
241 vf.readLine( line, 1024 );
244 if ( !line.isEmpty() )
246 while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
247 line.remove( line.length() - 1, 1 );
249 int idx = line.findRev( ":" );
251 _app_version = line.mid( idx + 1 ).stripWhiteSpace();
259 /*!Load module by \a name.*/
260 CAM_Module* LightApp_Application::loadModule( const QString& name )
262 CAM_Module* mod = CAM_Application::loadModule( name );
265 connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) );
266 connect( this, SIGNAL( studySaved() ), mod, SLOT( onModelSaved() ) );
267 connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) );
272 /*!Activate module by \a modName*/
273 bool LightApp_Application::activateModule( const QString& modName )
276 CAM_Module* prevMod = activeModule();
279 actName = prevMod->moduleName();
281 if ( actName == modName )
284 putInfo( tr( "ACTIVATING_MODULE" ).arg( modName ) );
286 saveWindowsGeometry();
288 bool status = CAM_Application::activateModule( modName );
290 updateModuleActions();
298 updateViewManagers();
303 bool LightApp_Application::useStudy(const QString& theName)
306 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>(activeStudy());
309 res = aStudy->loadDocument( theName );
310 updateDesktopTitle();
311 updateCommandsStatus();
315 /*!Gets selection manager.*/
316 LightApp_SelectionMgr* LightApp_Application::selectionMgr() const
322 void LightApp_Application::createActions()
324 STD_Application::createActions();
326 SUIT_Desktop* desk = desktop();
327 SUIT_ResourceMgr* resMgr = resourceMgr();
330 createAction( PreferencesId, tr( "TOT_DESK_PREFERENCES" ), QIconSet(),
331 tr( "MEN_DESK_PREFERENCES" ), tr( "PRP_DESK_PREFERENCES" ),
332 CTRL+Key_P, desk, false, this, SLOT( onPreferences() ) );
335 int helpMenu = createMenu( tr( "MEN_DESK_HELP" ), -1, -1, 1000 );
336 int helpModuleMenu = createMenu( tr( "MEN_DESK_MODULE_HELP" ), helpMenu, -1, 0 );
337 createMenu( separator(), helpMenu, -1, 1 );
339 QStringList aModuleList;
340 modules( aModuleList, false );
342 int id = LightApp_Application::UserID + FIRST_HELP_ID;
343 // help for KERNEL and GUI
346 if (dir = getenv("GUI_ROOT_DIR")) {
347 a = createAction( id, tr( QString("Kernel & GUI Help") ), QIconSet(),
348 tr( QString("Kernel && GUI Help") ),
349 tr( QString("Kernel & GUI Help") ),
350 0, desk, false, this, SLOT( onHelpContentsModule() ) );
351 a->setName( QString("GUI") );
352 createMenu( a, helpModuleMenu, -1 );
355 // help for other existing modules
356 for ( QStringList::Iterator it = aModuleList.begin(); it != aModuleList.end(); ++it )
358 if ( (*it).isEmpty() )
361 QString modName = moduleName( *it );
362 if ( modName.compare("GEOM") == 0 ) { // to be removed when documentation for other modules will be done
363 QAction* a = createAction( id, tr( moduleTitle(modName) + QString(" Help") ), QIconSet(),
364 tr( moduleTitle(modName) + QString(" Help") ),
365 tr( moduleTitle(modName) + QString(" Help") ),
366 0, desk, false, this, SLOT( onHelpContentsModule() ) );
367 a->setName( modName );
368 createMenu( a, helpModuleMenu, -1 );
374 QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), desk );
375 connect( mru, SIGNAL( activated( QString ) ), this, SLOT( onMRUActivated( QString ) ) );
376 registerAction( MRUId, mru );
378 // default icon for neutral point ('SALOME' module)
379 QPixmap defIcon = resMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false );
380 if ( defIcon.isNull() )
381 defIcon = QPixmap( imageEmptyIcon );
383 //! default icon for any module
384 QPixmap modIcon = resMgr->loadPixmap( "LightApp", tr( "APP_MODULE_ICO" ), false );
385 if ( modIcon.isNull() )
386 modIcon = QPixmap( imageEmptyIcon );
388 QToolBar* modTBar = new QtxToolBar( true, desk );
389 modTBar->setLabel( tr( "INF_TOOLBAR_MODULES" ) );
391 QActionGroup* modGroup = new QActionGroup( this );
392 modGroup->setExclusive( true );
393 modGroup->setUsesDropDown( true );
395 a = createAction( -1, tr( "APP_NAME" ), defIcon, tr( "APP_NAME" ),
396 tr( "PRP_APP_MODULE" ), 0, desk, true );
398 myActions.insert( QString(), a );
400 QMap<QString, QString> iconMap;
401 moduleIconNames( iconMap );
403 const int iconSize = 20;
405 modGroup->addTo( modTBar );
406 modTBar->addSeparator();
409 modules( modList, false );
411 for ( QStringList::Iterator it = modList.begin(); it != modList.end(); ++it )
413 if ( (*it).isEmpty() )
417 if ( iconMap.contains( *it ) )
418 iconName = iconMap[*it];
420 QString modName = moduleName( *it );
422 QPixmap icon = resMgr->loadPixmap( modName, iconName, false );
426 icon.convertFromImage( icon.convertToImage().smoothScale( iconSize, iconSize, QImage::ScaleMin ) );
428 QAction* a = createAction( -1, *it, icon, *it, tr( "PRP_MODULE" ).arg( *it ), 0, desk, true );
432 myActions.insert( *it, a );
435 SUIT_Tools::simplifySeparators( modTBar );
438 int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 );
439 int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
440 createMenu( separator(), windowMenu, -1, 1 );
442 QMap<int, int> accelMap;
443 accelMap[NewGLViewId] = ALT+Key_G;
444 accelMap[NewPlot2dId] = ALT+Key_P;
445 accelMap[NewOCCViewId] = ALT+Key_O;
446 accelMap[NewVTKViewId] = ALT+Key_K;
448 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
450 QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), QIconSet(),
451 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
452 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
453 accelMap.contains( id ) ? accelMap[id] : 0, desk, false, this, SLOT( onNewWindow() ) );
454 createMenu( a, newWinMenu, -1 );
457 connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) );
459 int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
460 createMenu( PreferencesId, fileMenu, 15, -1 );
461 createMenu( separator(), fileMenu, -1, 15, -1 );
464 createMenu( separator(), fileMenu, -1, 100, -1 );
465 createMenu( MRUId, fileMenu, 100, -1 );
466 createMenu( separator(), fileMenu, -1, 100, -1 );
470 /*!On module activation action.*/
471 void LightApp_Application::onModuleActivation( QAction* a )
476 QString modName = a->menuText();
477 if ( modName == tr( "APP_NAME" ) )
478 modName = QString::null;
480 // Force user to create/open a study before module activation
481 QMap<QString, QString> iconMap;
482 moduleIconNames( iconMap );
483 QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ], false );
485 icon = resourceMgr()->loadPixmap( "LightApp", tr( "APP_MODULE_BIG_ICO" ), false ); // default icon for any module
487 bool cancelled = false;
488 while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
489 LightApp_ModuleDlg aDlg( desktop(), modName, icon );
490 int res = aDlg.exec();
504 putInfo( tr("INF_CANCELLED") );
505 myActions[QString()]->setOn( true );
511 activateModule( modName );
514 /*!Default module activation.*/
515 QString LightApp_Application::defaultModule() const
517 QStringList aModuleNames;
518 modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration
519 //! If there's the one and only module --> activate it automatically
520 //! TODO: Possible improvement - default module can be taken from preferences
521 return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" );
524 /*!On new window slot.*/
525 void LightApp_Application::onNewWindow()
527 const QObject* obj = sender();
528 if ( !obj || !obj->inherits( "QAction" ) )
532 int id = actionId( (QAction*)obj );
536 type = GLViewer_Viewer::Type();
539 type = Plot2d_Viewer::Type();
542 type = OCCViewer_Viewer::Type();
545 type = VTKViewer_Viewer::Type();
549 if ( !type.isEmpty() )
550 createViewManager( type );
553 //=======================================================================
555 /*! Purpose : SLOT. Create new document*/
556 //=======================================================================
557 void LightApp_Application::onNewDoc()
559 SUIT_Study* study = activeStudy();
561 saveWindowsGeometry();
563 CAM_Application::onNewDoc();
565 if ( !study ) // new study will be create in THIS application
568 updateViewManagers();
572 //=======================================================================
574 /*! Purpose : SLOT. Open new document*/
575 //=======================================================================
576 void LightApp_Application::onOpenDoc()
578 SUIT_Study* study = activeStudy();
579 saveWindowsGeometry();
581 CAM_Application::onOpenDoc();
583 if ( !study ) // new study will be create in THIS application
586 updateViewManagers();
590 #include "SUIT_MessageBox.h"
591 /*! Purpose : SLOT. Open new document with \a aName.*/
592 bool LightApp_Application::onOpenDoc( const QString& aName )
594 bool isAlreadyOpen = false;
596 // Look among opened studies
597 if (activeStudy()) { // at least one study is opened
598 SUIT_Session* aSession = SUIT_Session::session();
599 QPtrList<SUIT_Application> aAppList = aSession->applications();
600 QPtrListIterator<SUIT_Application> it (aAppList);
601 SUIT_Application* aApp = 0;
602 // iterate on all applications
603 for (; (aApp = it.current()) && !isAlreadyOpen; ++it) {
604 if (aApp->activeStudy()->studyName() == aName) {
605 isAlreadyOpen = true; // Already opened, ask user what to do
607 // The document ... is already open.
608 // Do you want to reload it?
609 int aAnswer = SUIT_MessageBox::warn2(desktop(), tr("WRN_WARNING"),
610 tr("QUE_DOC_ALREADYOPEN").arg(aName),
611 tr("BUT_YES"), tr("BUT_NO"), 1, 2, 2);
612 if (aAnswer == 1) { // reload
613 if (activeStudy()->studyName() == aName && aAppList.count() > 1) {
614 // Opened in THIS (active) application.
615 STD_Application* app1 = (STD_Application*)aAppList.at(0);
616 STD_Application* app2 = (STD_Application*)aAppList.at(1);
617 if (!app1 || !app2) {
621 if (app1->activeStudy()->studyName() == aName) {
622 // app1 is this application, we need another one
625 // Close document of this application. This application will be destroyed.
626 onCloseDoc(/*ask = */false);
627 // Open the file with another application, as this one will be destroyed.
628 return app1->onOpenDoc(aName);
630 // Opened in another application.
631 STD_Application* app = (STD_Application*)aApp;
633 app->onCloseDoc(/*ask = */false);
635 } else { // do not reload
636 // OK, the study will not be reloaded, but we call
637 // CAM_Application::onOpenDoc( aName ) all the same.
638 // It will activate a desktop of the study <aName>.
644 bool res = CAM_Application::onOpenDoc( aName );
646 QAction* a = action( MRUId );
647 if ( a && a->inherits( "QtxMRUAction" ) )
649 QtxMRUAction* mru = (QtxMRUAction*)a;
651 mru->insert( aName );
653 mru->remove( aName );
658 //=======================================================================
659 // name : onHelpAbout
660 /*! Purpose : SLOT. Display "About" message box*/
661 //=======================================================================
662 void LightApp_Application::onHelpAbout()
664 LightApp_AboutDlg* dlg = new LightApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
669 /*!SLOT. Load document with \a aName.*/
670 bool LightApp_Application::onLoadDoc( const QString& aName )
672 bool res = CAM_Application::onLoadDoc( aName );
674 /*jfa tmp:QAction* a = action( MRUId );
675 if ( a && a->inherits( "QtxMRUAction" ) )
677 QtxMRUAction* mru = (QtxMRUAction*)a;
679 mru->insert( aName );
681 mru->remove( aName );
686 /*!Private SLOT. Selection.*/
687 void LightApp_Application::onSelection()
689 onSelectionChanged();
691 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
692 ((LightApp_Module*)activeModule())->selectionChanged();
696 *\param study - SUIT_Study.
698 void LightApp_Application::setActiveStudy( SUIT_Study* study )
700 CAM_Application::setActiveStudy( study );
705 //=======================================================================
706 // name : updateCommandsStatus
707 /*! Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu*/
708 //=======================================================================
709 void LightApp_Application::updateCommandsStatus()
711 CAM_Application::updateCommandsStatus();
713 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
715 QAction* a = action( id );
717 a->setEnabled( activeStudy() );
721 // Helps to execute command
722 class RunBrowser: public QThread {
725 RunBrowser(QString theApp, QString theParams, QString theHelpFile, QString theContext=NULL):
726 myApp(theApp), myParams(theParams), myHelpFile("file:" + theHelpFile + theContext), myStatus(0) {};
732 if ( !myApp.isEmpty())
734 aCommand.sprintf("%s %s %s",myApp.latin1(),myParams.latin1(),myHelpFile.latin1());
735 myStatus = system(aCommand);
738 QCustomEvent* ce2000 = new QCustomEvent (2000);
739 postEvent (qApp, ce2000);
743 if( myStatus != 0 || myApp.isEmpty())
746 aCommand.sprintf("%s %s %s", QString(DEFAULT_BROWSER).latin1(),myParams.latin1(), myHelpFile.latin1());
747 myStatus = system(aCommand);
750 QCustomEvent* ce2001 = new QCustomEvent (2001);
751 postEvent (qApp, ce2001);
764 //=======================================================================
765 // name : onHelpContentsModule
766 /*! Purpose : SLOT. Display help contents for choosen module*/
767 //=======================================================================
768 void LightApp_Application::onHelpContentsModule()
770 const QAction* obj = (QAction*) sender();
772 QString aComponentName = obj->name();
773 QString aFileName = aComponentName.lower() + ".htm";
778 if (dir = getenv( aComponentName + "_ROOT_DIR")) {
779 root = Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("doc") + Qtx::addSlash("salome") + Qtx::addSlash(aComponentName));
780 if ( QFileInfo( root + aFileName ).exists() ) {
783 SUIT_MessageBox::warn1( desktop(), tr("WRN_WARNING"),
784 QString( "%1"+ aFileName + " doesn't exist." ).arg(root), tr ("BUT_OK") );
789 QString helpFile = QFileInfo( homeDir + aFileName ).absFilePath();
790 SUIT_ResourceMgr* resMgr = resourceMgr();
791 QString anApp = resMgr->stringValue("ExternalBrowser", "application");
792 QString aParams = resMgr->stringValue("ExternalBrowser", "parameters");
794 RunBrowser* rs = new RunBrowser(anApp, aParams, helpFile);
798 /*!Sets enable or disable some actions on selection changed.*/
799 void LightApp_Application::onSelectionChanged()
804 *\param flag - key for window
805 *\param studyId - study id
806 * Flag used how identificator of window in windows list.
808 QWidget* LightApp_Application::window( const int flag, const int studyId ) const
815 if ( !activeStudy() )
818 sId = activeStudy()->id();
821 if ( myWindows.contains( flag ) )
822 wid = myWindows[flag]->widget( sId );
827 /*!Adds window to application.
828 *\param wid - QWidget
829 *\param flag - key wor window
830 *\param studyId - study id
831 * Flag used how identificator of window in windows list.
833 void LightApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
841 if ( !activeStudy() )
844 sId = activeStudy()->id();
847 if ( !myWindows.contains( flag ) )
849 QMap<int, int> winMap;
850 currentWindows( winMap );
852 myWindows.insert( flag, new LightApp_WidgetContainer( flag, desktop() ) );
853 if ( winMap.contains( flag ) )
854 desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
856 myWindows[flag]->setResizeEnabled( true );
857 myWindows[flag]->setCloseMode( QDockWindow::Always );
858 myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
862 if( wid->inherits( "PythonConsole" ) )
863 f = ( ( PythonConsole* )wid )->font();
867 myWindows[flag]->insert( sId, wid );
870 setWindowShown( flag, !myWindows[flag]->isEmpty() );
873 /*!Remove window from application.
874 *\param flag - key wor window
875 *\param studyId - study id
876 * Flag used how identificator of window in windows list.
878 void LightApp_Application::removeWindow( const int flag, const int studyId )
880 if ( !myWindows.contains( flag ) )
886 if ( !activeStudy() )
889 sId = activeStudy()->id();
892 QWidget* wid = myWindows[flag]->widget( sId );
893 myWindows[flag]->remove( sId );
896 setWindowShown( flag, !myWindows[flag]->isEmpty() );
900 *\param flag - key wor window
901 *\param studyId - study id
902 * Flag used how identificator of window in windows list.
904 QWidget* LightApp_Application::getWindow( const int flag, const int studyId )
906 QWidget* wid = window( flag, studyId );
908 addWindow( wid = createWindow( flag ), flag, studyId );
913 /*!Check is window visible?(with identificator \a type)*/
914 bool LightApp_Application::isWindowVisible( const int type ) const
917 if ( myWindows.contains( type ) )
919 SUIT_Desktop* desk = ((LightApp_Application*)this)->desktop();
920 res = desk && desk->appropriate( myWindows[type] );
925 /*!Sets window show or hide.
926 *\param type - window identificator.
927 *\param on - true/false (window show/hide)
929 void LightApp_Application::setWindowShown( const int type, const bool on )
931 if ( !desktop() || !myWindows.contains( type ) )
934 QDockWindow* dw = myWindows[type];
935 desktop()->setAppropriate( dw, on );
936 on ? dw->show() : dw->hide();
939 /*!Gets "ObjectBrowser".*/
940 OB_Browser* LightApp_Application::objectBrowser()
943 QWidget* wid = getWindow( WT_ObjectBrowser );
944 if ( wid->inherits( "OB_Browser" ) )
945 ob = (OB_Browser*)wid;
949 /*!Gets "LogWindow".*/
950 LogWindow* LightApp_Application::logWindow()
953 QWidget* wid = getWindow( WT_LogWindow );
954 if ( wid->inherits( "LogWindow" ) )
955 lw = (LogWindow*)wid;
959 /*!Get "PythonConsole"*/
960 PythonConsole* LightApp_Application::pythonConsole()
962 PythonConsole* console = 0;
963 QWidget* wid = getWindow( WT_PyConsole );
964 if ( wid->inherits( "PythonConsole" ) )
965 console = (PythonConsole*)wid;
969 /*!Update obect browser*/
970 void LightApp_Application::updateObjectBrowser( const bool updateModels )
972 // update existing data models
975 LightApp_Study* study = dynamic_cast<LightApp_Study*>(activeStudy());
977 CAM_Study::ModelList dm_list;
978 study->dataModels( dm_list );
979 for ( CAM_Study::ModelListIterator it( dm_list ); it.current(); ++it ) {
980 CAM_DataModel* camDM = it.current();
981 if ( camDM && camDM->inherits( "LightApp_DataModel" ) )
982 ((LightApp_DataModel*)camDM)->update();
986 if ( objectBrowser() )
988 objectBrowser()->updateGeometry();
989 objectBrowser()->updateTree();
993 /*!Gets preferences.*/
994 LightApp_Preferences* LightApp_Application::preferences() const
996 return preferences( false );
999 /*!Gets view manager*/
1000 SUIT_ViewManager* LightApp_Application::getViewManager( const QString& vmType, const bool create )
1002 SUIT_ViewManager* aVM = viewManager( vmType );
1003 SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
1005 if ( anActiveVM && anActiveVM->getType() == vmType )
1008 if ( aVM && create )
1010 if ( !aVM->getActiveView() )
1013 aVM->getActiveView()->setFocus();
1016 aVM = createViewManager( vmType );
1021 /*!Create view manager.*/
1022 SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType )
1024 SUIT_ResourceMgr* resMgr = resourceMgr();
1026 SUIT_ViewManager* viewMgr = 0;
1027 if( vmType == GLViewer_Viewer::Type() )
1029 viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
1030 new LightApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
1032 else if( vmType == Plot2d_Viewer::Type() )
1034 viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
1035 SPlot2d_Viewer* vm = new SPlot2d_Viewer();
1036 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1037 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( viewMgr->getActiveView() );
1040 Plot2d_ViewFrame* frame = wnd->getViewFrame();
1041 frame->setBackgroundColor( resMgr->colorValue( "Plot2d", "Background", frame->backgroundColor() ) );
1044 else if( vmType == SUPERVGraph_Viewer::Type() )
1046 viewMgr = new SUPERVGraph_ViewManager( activeStudy(), desktop() );
1047 SUPERVGraph_Viewer* vm = new SUPERVGraph_Viewer();
1048 SUPERVGraph_ViewFrame* view = dynamic_cast<SUPERVGraph_ViewFrame*>( vm->getViewManager()->getActiveView() );
1050 view->setBackgroundColor( resMgr->colorValue( "SUPERVGraph", "Background", view->backgroundColor() ) );
1052 else if( vmType == OCCViewer_Viewer::Type() )
1054 viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
1055 SOCC_Viewer* vm = new SOCC_Viewer();
1056 vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
1057 vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
1060 u = resMgr->integerValue( "OCCViewer", "iso_number_u", u );
1061 v = resMgr->integerValue( "OCCViewer", "iso_number_v", v );
1062 vm->setIsos( u, v );
1063 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1064 new LightApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
1066 else if ( vmType == SVTK_Viewer::Type() )
1068 viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
1069 SVTK_Viewer* vm = dynamic_cast<SVTK_Viewer*>( viewMgr->getViewModel() );
1072 vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
1073 vm->setTrihedronSize( resMgr->integerValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ) );
1074 new LightApp_VTKSelector( vm, mySelMgr );
1081 addViewManager( viewMgr );
1082 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
1084 if ( viewWin && desktop() )
1085 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
1087 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1088 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
1093 //=======================================================================
1094 // name : onCloseView
1095 /*! Purpose : SLOT. Remove view manager from application*/
1096 //=======================================================================
1097 void LightApp_Application::onCloseView( SUIT_ViewManager* theVM )
1099 removeViewManager( theVM );
1102 /*!Protected SLOT. On study created.*/
1103 void LightApp_Application::onStudyCreated( SUIT_Study* theStudy )
1105 SUIT_DataObject* aRoot = 0;
1106 if ( theStudy && theStudy->root() )
1108 aRoot = theStudy->root();
1109 //aRoot->setName( tr( "DATA_MODELS" ) );
1111 if ( objectBrowser() != 0 )
1112 objectBrowser()->setRootObject( aRoot );
1114 activateModule( defaultModule() );
1119 /*!Protected SLOT. On study opened.*/
1120 void LightApp_Application::onStudyOpened( SUIT_Study* theStudy )
1122 SUIT_DataObject* aRoot = 0;
1123 if ( theStudy && theStudy->root() )
1125 aRoot = theStudy->root();
1128 if ( objectBrowser() != 0 ) {
1129 objectBrowser()->setRootObject( aRoot );
1132 activateModule( defaultModule() );
1139 /*!Protected SLOT. On study saved.*/
1140 void LightApp_Application::onStudySaved( SUIT_Study* )
1145 /*!Protected SLOT. On study closed.*/
1146 void LightApp_Application::onStudyClosed( SUIT_Study* )
1150 activateModule( "" );
1152 // Bug 10396: remove all selectors
1154 mySelMgr = new LightApp_SelectionMgr( this );
1156 saveWindowsGeometry();
1159 /*!Protected SLOT.On desktop activated.*/
1160 void LightApp_Application::onDesktopActivated()
1162 CAM_Application::onDesktopActivated();
1163 LightApp_Module* aModule = dynamic_cast<LightApp_Module*>(activeModule());
1165 aModule->studyActivated();
1168 /*!Gets file filter.
1169 *\retval QString "(*.bin)"
1171 QString LightApp_Application::getFileFilter() const
1176 /*! Gets file name*/
1177 QString LightApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1178 const QString& caption, QWidget* parent )
1182 QStringList fls = QStringList::split( ";;", filters, false );
1183 return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1186 /*! Gets directory*/
1187 QString LightApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1191 return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1194 /*! Get open file names*/
1195 QStringList LightApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
1196 const QString& caption, QWidget* parent )
1200 QStringList fls = QStringList::split( ";;", filters, false );
1201 return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1204 /*!Private SLOT. Update object browser.*/
1205 void LightApp_Application::onRefresh()
1207 updateObjectBrowser( true );
1210 /*!Private SLOT. On preferences.*/
1211 void LightApp_Application::onPreferences()
1213 QApplication::setOverrideCursor( Qt::waitCursor );
1215 LightApp_PreferencesDlg* prefDlg = new LightApp_PreferencesDlg( preferences( true ), desktop());
1217 QApplication::restoreOverrideCursor();
1227 /*!Protected SLOT. On preferences changed.*/
1228 void LightApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1230 LightApp_Module* sMod = 0;
1231 CAM_Module* mod = module( modName );
1232 if ( mod && mod->inherits( "LightApp_Module" ) )
1233 sMod = (LightApp_Module*)mod;
1236 sMod->preferencesChanged( section, param );
1238 preferencesChanged( section, param );
1241 /*!Private SLOT. On open document with name \a aName.*/
1242 void LightApp_Application::onMRUActivated( QString aName )
1247 /*!Remove all windows from study.*/
1248 void LightApp_Application::beforeCloseDoc( SUIT_Study* s )
1250 CAM_Application::beforeCloseDoc( s );
1252 for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1253 removeWindow( itr.key(), s->id() );
1256 /*!Update actions.*/
1257 void LightApp_Application::updateActions()
1259 updateCommandsStatus();
1262 //=======================================================================
1263 // name : createNewStudy
1264 /*! Purpose : Create new study*/
1265 //=======================================================================
1266 SUIT_Study* LightApp_Application::createNewStudy()
1268 LightApp_Study* aStudy = new LightApp_Study( this );
1270 // Set up processing of major study-related events
1271 connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
1272 connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
1273 connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );
1274 connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
1280 QWidget* LightApp_Application::createWindow( const int flag )
1283 if ( flag == WT_ObjectBrowser )
1285 OB_Browser* ob = new OB_Browser( desktop() );
1286 ob->setAutoUpdate( true );
1287 ob->setAutoOpenLevel( 1 );
1288 ob->setCaption( tr( "OBJECT_BROWSER" ) );
1289 ob->listView()->setColumnWidth( 0, OBJECT_COLUMN_WIDTH );
1290 ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
1291 ob->setFilter( new LightApp_OBFilter( selectionMgr() ) );
1293 ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1295 // Create OBSelector
1296 new LightApp_OBSelector( ob, mySelMgr );
1300 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1302 else if ( flag == WT_PyConsole )
1304 PythonConsole* pyCons = new PythonConsole( desktop() );
1305 pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1307 // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1309 else if ( flag == WT_LogWindow )
1311 LogWindow* logWin = new LogWindow( desktop() );
1312 logWin->setCaption( tr( "LOG_WINDOW" ) );
1314 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1319 /*!Default windows(Object Browser, Python Console).
1320 * Adds to map \a aMap.
1322 void LightApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1324 aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1325 aMap.insert( WT_PyConsole, Qt::DockBottom );
1326 // aMap.insert( WT_LogWindow, Qt::DockBottom );
1329 /*!Default view manager.*/
1330 void LightApp_Application::defaultViewManagers( QStringList& ) const
1335 /*!Gets preferences.
1336 * Create preferences, if \a crt = true.
1338 LightApp_Preferences* LightApp_Application::preferences( const bool crt ) const
1343 LightApp_Application* that = (LightApp_Application*)this;
1345 if ( !_prefs_ && crt )
1347 _prefs_ = new LightApp_Preferences( resourceMgr() );
1348 that->createPreferences( _prefs_ );
1351 that->myPrefs = _prefs_;
1353 QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1354 for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1356 if ( !appIt.current()->inherits( "LightApp_Application" ) )
1359 LightApp_Application* app = (LightApp_Application*)appIt.current();
1361 QStringList modNameList;
1362 app->modules( modNameList, false );
1363 for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1365 int id = _prefs_->addPreference( *it );
1366 _prefs_->setItemProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1370 app->modules( modList );
1371 for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1373 LightApp_Module* mod = 0;
1374 if ( itr.current()->inherits( "LightApp_Module" ) )
1375 mod = (LightApp_Module*)itr.current();
1377 if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1379 int modCat = _prefs_->addPreference( mod->moduleName() );
1380 _prefs_->setItemProperty( modCat, "info", QString::null );
1381 mod->createPreferences();
1386 connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1387 this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1392 /*!Add new module to application.*/
1393 void LightApp_Application::moduleAdded( CAM_Module* mod )
1395 CAM_Application::moduleAdded( mod );
1397 LightApp_Module* lightMod = 0;
1398 if ( mod && mod->inherits( "LightApp_Module" ) )
1399 lightMod = (LightApp_Module*)mod;
1401 if ( myPrefs && lightMod && !myPrefs->hasModule( lightMod->moduleName() ))
1403 int modCat = myPrefs->addPreference( mod->moduleName() );
1404 myPrefs->setItemProperty( modCat, "info", QString::null );
1405 lightMod->createPreferences();
1409 /*!Create preferences.*/
1410 void LightApp_Application::createPreferences( LightApp_Preferences* pref )
1415 int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1417 int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1418 int studyGroup = pref->addPreference( tr( "PREF_GROUP_STUDY" ), genTab );
1419 pref->setItemProperty( studyGroup, "columns", 1 );
1421 pref->addPreference( tr( "PREF_MULTI_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "multi_file" );
1422 pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "ascii_file" );
1423 int undoPref = pref->addPreference( tr( "PREF_UNDO_LEVEL" ), studyGroup, LightApp_Preferences::IntSpin, "Study", "undo_level" );
1424 pref->setItemProperty( undoPref, "min", 1 );
1425 pref->setItemProperty( undoPref, "max", 100 );
1427 int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab );
1428 pref->setItemProperty( extgroup, "columns", 1 );
1429 int apppref = pref->addPreference( tr( "PREF_APP" ), extgroup, LightApp_Preferences::File, "ExternalBrowser", "application" );
1430 pref->setItemProperty( apppref, "existing", true );
1431 pref->setItemProperty( apppref, "flags", QFileInfo::ExeUser );
1433 pref->addPreference( tr( "PREF_PARAM" ), extgroup, LightApp_Preferences::String, "ExternalBrowser", "parameters" );
1435 int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab );
1436 pref->setItemProperty( pythonConsoleGroup, "columns", 1 );
1437 pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, LightApp_Preferences::Font, "PyConsole", "font" );
1439 int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1441 int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1443 int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1445 int plot2dGroup = pref->addPreference( tr( "PREF_GROUP_PLOT2DVIEWER" ), viewTab );
1447 int supervGroup = pref->addPreference( tr( "PREF_GROUP_SUPERV" ), viewTab );
1449 pref->setItemProperty( occGroup, "columns", 1 );
1450 pref->setItemProperty( vtkGroup, "columns", 1 );
1451 pref->setItemProperty( plot2dGroup, "columns", 1 );
1453 int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1454 LightApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1455 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1456 LightApp_Preferences::Color, "OCCViewer", "background" );
1458 pref->setItemProperty( occTS, "min", 1 );
1459 pref->setItemProperty( occTS, "max", 150 );
1461 int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
1462 LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
1463 int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
1464 LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
1466 pref->setItemProperty( isoU, "min", 0 );
1467 pref->setItemProperty( isoU, "max", 100000 );
1469 pref->setItemProperty( isoV, "min", 0 );
1470 pref->setItemProperty( isoV, "max", 100000 );
1472 int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1473 LightApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1474 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1475 LightApp_Preferences::Color, "VTKViewer", "background" );
1477 pref->setItemProperty( vtkTS, "min", 1 );
1478 pref->setItemProperty( vtkTS, "max", 150 );
1480 pref->addPreference( tr( "PREF_SHOW_LEGEND" ), plot2dGroup,
1481 LightApp_Preferences::Bool, "Plot2d", "ShowLegend" );
1483 int legendPosition = pref->addPreference( tr( "PREF_LEGEND_POSITION" ), plot2dGroup,
1484 LightApp_Preferences::Selector, "Plot2d", "LegendPos" );
1485 QStringList aLegendPosList;
1486 aLegendPosList.append( tr("PREF_LEFT") );
1487 aLegendPosList.append( tr("PREF_RIGHT") );
1488 aLegendPosList.append( tr("PREF_TOP") );
1489 aLegendPosList.append( tr("PREF_BOTTOM") );
1491 QValueList<QVariant> anIndexesList;
1492 anIndexesList.append(0);
1493 anIndexesList.append(1);
1494 anIndexesList.append(2);
1495 anIndexesList.append(3);
1497 pref->setItemProperty( legendPosition, "strings", aLegendPosList );
1498 pref->setItemProperty( legendPosition, "indexes", anIndexesList );
1500 int curveType = pref->addPreference( tr( "PREF_CURVE_TYPE" ), plot2dGroup,
1501 LightApp_Preferences::Selector, "Plot2d", "CurveType" );
1502 QStringList aCurveTypesList;
1503 aCurveTypesList.append( tr("PREF_POINTS") );
1504 aCurveTypesList.append( tr("PREF_LINES") );
1505 aCurveTypesList.append( tr("PREF_SPLINE") );
1507 anIndexesList.clear();
1508 anIndexesList.append(0);
1509 anIndexesList.append(1);
1510 anIndexesList.append(2);
1512 pref->setItemProperty( curveType, "strings", aCurveTypesList );
1513 pref->setItemProperty( curveType, "indexes", anIndexesList );
1515 int markerSize = pref->addPreference( tr( "PREF_MARKER_SIZE" ), plot2dGroup,
1516 LightApp_Preferences::IntSpin, "Plot2d", "MarkerSize" );
1518 pref->setItemProperty( markerSize, "min", 0 );
1519 pref->setItemProperty( markerSize, "max", 100 );
1521 QStringList aScaleModesList;
1522 aScaleModesList.append( tr("PREF_LINEAR") );
1523 aScaleModesList.append( tr("PREF_LOGARITHMIC") );
1525 anIndexesList.clear();
1526 anIndexesList.append(0);
1527 anIndexesList.append(1);
1529 int horScale = pref->addPreference( tr( "PREF_HOR_AXIS_SCALE" ), plot2dGroup,
1530 LightApp_Preferences::Selector, "Plot2d", "HorScaleMode" );
1532 pref->setItemProperty( horScale, "strings", aScaleModesList );
1533 pref->setItemProperty( horScale, "indexes", anIndexesList );
1535 int verScale = pref->addPreference( tr( "PREF_VERT_AXIS_SCALE" ), plot2dGroup,
1536 LightApp_Preferences::Selector, "Plot2d", "VerScaleMode" );
1538 pref->setItemProperty( verScale, "strings", aScaleModesList );
1539 pref->setItemProperty( verScale, "indexes", anIndexesList );
1541 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), plot2dGroup,
1542 LightApp_Preferences::Color, "Plot2d", "Background" );
1544 int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat );
1545 int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab );
1546 pref->setItemProperty( dirGroup, "columns", 1 );
1547 pref->addPreference( tr( "" ), dirGroup,
1548 LightApp_Preferences::DirList, "FileDlg", "QuickDirList" );
1550 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), supervGroup,
1551 LightApp_Preferences::Color, "SUPERVGraph", "Background" );
1552 pref->addPreference( tr( "PREF_SUPERV_TITLE_COLOR" ), supervGroup,
1553 LightApp_Preferences::Color, "SUPERVGraph", "Title" );
1554 // pref->addPreference( tr( "PREF_SUPERV_CTRL_COLOR" ), supervGroup,
1555 // LightApp_Preferences::Color, "SUPERVGraph", "Ctrl" );
1558 /*!Changed preferences */
1559 void LightApp_Application::preferencesChanged( const QString& sec, const QString& param )
1561 SUIT_ResourceMgr* resMgr = resourceMgr();
1565 if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1567 int sz = resMgr->integerValue( sec, param, -1 );
1568 QPtrList<SUIT_ViewManager> lst;
1569 viewManagers( OCCViewer_Viewer::Type(), lst );
1570 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1572 SUIT_ViewModel* vm = it.current()->getViewModel();
1573 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1576 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1577 occVM->setTrihedronSize( sz );
1578 occVM->getAISContext()->UpdateCurrentViewer();
1582 if ( sec == QString( "VTKViewer" ) && param == QString( "trihedron_size" ) )
1584 int sz = resMgr->integerValue( sec, param, -1 );
1585 QPtrList<SUIT_ViewManager> lst;
1586 viewManagers( SVTK_Viewer::Type(), lst );
1587 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1589 SUIT_ViewModel* vm = it.current()->getViewModel();
1590 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
1593 SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
1596 vtkVM->setTrihedronSize( sz );
1602 if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
1604 QPtrList<SUIT_ViewManager> lst;
1605 viewManagers( OCCViewer_Viewer::Type(), lst );
1606 int u = resMgr->integerValue( sec, "iso_number_u" );
1607 int v = resMgr->integerValue( sec, "iso_number_v" );
1608 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
1609 ((OCCViewer_Viewer*)it.current())->setIsos( u, v );
1612 if( sec=="ObjectBrowser" )
1614 if( param=="auto_size" )
1616 OB_Browser* ob = objectBrowser();
1620 bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
1621 ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1623 updateObjectBrowser( false );
1627 if( sec=="PyConsole" )
1630 if( pythonConsole() )
1631 pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1635 /*!Update desktop title.*/
1636 void LightApp_Application::updateDesktopTitle() {
1637 QString aTitle = applicationName();
1638 QString aVer = applicationVersion();
1639 if ( !aVer.isEmpty() )
1640 aTitle += QString( " " ) + aVer;
1642 desktop()->setCaption( aTitle );
1645 /*!Update windows after close document.*/
1646 void LightApp_Application::afterCloseDoc()
1650 CAM_Application::afterCloseDoc();
1653 /*!Update module action.*/
1654 void LightApp_Application::updateModuleActions()
1657 if ( activeModule() )
1658 modName = activeModule()->moduleName();
1660 if ( myActions.contains( modName ) )
1661 myActions[modName]->setOn( true );
1664 /*!Gets current windows.
1665 *\param winMap - output current windows map.
1667 void LightApp_Application::currentWindows( QMap<int, int>& winMap ) const
1670 if ( !activeStudy() )
1673 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
1674 ((LightApp_Module*)activeModule())->windows( winMap );
1676 defaultWindows( winMap );
1679 /*!Gets current view managers.
1680 *\param lst - output current view managers list.
1682 void LightApp_Application::currentViewManagers( QStringList& lst ) const
1685 if ( !activeStudy() )
1688 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
1689 ((LightApp_Module*)activeModule())->viewManagers( lst );
1691 defaultViewManagers( lst );
1694 /*!Update windows.*/
1695 void LightApp_Application::updateWindows()
1697 QMap<int, int> winMap;
1698 currentWindows( winMap );
1700 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1701 getWindow( it.key() );
1703 loadWindowsGeometry();
1705 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1706 setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1709 /*!Update view managers.*/
1710 void LightApp_Application::updateViewManagers()
1713 currentViewManagers( lst );
1715 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1716 getViewManager( *it, true );
1719 /*!Load windows geometry.*/
1720 void LightApp_Application::loadWindowsGeometry()
1722 QtxDockAction* dockMgr = 0;
1724 QAction* a = action( ViewWindowsId );
1725 if ( a && a->inherits( "QtxDockAction" ) )
1726 dockMgr = (QtxDockAction*)a;
1732 if ( activeModule() )
1733 modName = activeModule()->name("");
1735 QString section = QString( "windows_geometry" );
1736 if ( !modName.isEmpty() )
1737 section += QString( "." ) + modName;
1739 dockMgr->loadGeometry( resourceMgr(), section, false );
1740 dockMgr->restoreGeometry();
1743 /*!Save windows geometry.*/
1744 void LightApp_Application::saveWindowsGeometry()
1746 QtxDockAction* dockMgr = 0;
1748 QAction* a = action( ViewWindowsId );
1749 if ( a && a->inherits( "QtxDockAction" ) )
1750 dockMgr = (QtxDockAction*)a;
1756 if ( activeModule() )
1757 modName = activeModule()->name("");
1759 QString section = QString( "windows_geometry" );
1760 if ( !modName.isEmpty() )
1761 section += QString( "." ) + modName;
1763 dockMgr->storeGeometry();
1764 dockMgr->saveGeometry( resourceMgr(), section, false );
1767 /*!Activate windows.*/
1768 void LightApp_Application::activateWindows()
1770 if ( activeStudy() )
1772 for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1773 itr.data()->activate( activeStudy()->id() );
1777 /*!Adds icon names for modules.*/
1778 void LightApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
1782 SUIT_ResourceMgr* resMgr = resourceMgr();
1786 QStringList modList;
1787 modules( modList, false );
1789 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
1791 QString modName = *it;
1792 QString modIntr = moduleName( modName );
1793 QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
1795 if ( modIcon.isEmpty() )
1798 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
1799 modIcon += QString( ".png" );
1801 iconMap.insert( modName, modIcon );
1805 /*!Insert items in popup, which necessary for current application*/
1806 void LightApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
1808 CAM_Application::contextMenuPopup( type, thePopup, title );
1810 OB_Browser* ob = objectBrowser();
1811 if ( !ob || type != ob->popupClientType() )
1814 thePopup->insertSeparator();
1815 thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
1818 /*!Create empty study.*/
1819 void LightApp_Application::createEmptyStudy()
1821 CAM_Application::createEmptyStudy();
1822 if ( objectBrowser() )
1823 objectBrowser()->updateTree();
1826 /*!Activate module \a mod.*/
1827 bool LightApp_Application::activateModule( CAM_Module* mod )
1829 bool res = CAM_Application::activateModule( mod );
1830 if ( objectBrowser() )
1831 objectBrowser()->updateTree();
1835 /*!return keyborad accelerators manager object */
1836 SUIT_Accel* LightApp_Application::accel() const