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 QStringList::Iterator it;
357 for ( it = aModuleList.begin(); it != aModuleList.end(); ++it )
359 if ( (*it).isEmpty() )
362 QString modName = moduleName( *it );
363 if ( modName.compare("GEOM") == 0 ) { // to be removed when documentation for other modules will be done
364 QAction* a = createAction( id, tr( moduleTitle(modName) + QString(" Help") ), QIconSet(),
365 tr( moduleTitle(modName) + QString(" Help") ),
366 tr( moduleTitle(modName) + QString(" Help") ),
367 0, desk, false, this, SLOT( onHelpContentsModule() ) );
368 a->setName( modName );
369 createMenu( a, helpModuleMenu, -1 );
375 QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), desk );
376 connect( mru, SIGNAL( activated( QString ) ), this, SLOT( onMRUActivated( QString ) ) );
377 registerAction( MRUId, mru );
379 // default icon for neutral point ('SALOME' module)
380 QPixmap defIcon = resMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false );
381 if ( defIcon.isNull() )
382 defIcon = QPixmap( imageEmptyIcon );
384 //! default icon for any module
385 QPixmap modIcon = resMgr->loadPixmap( "LightApp", tr( "APP_MODULE_ICO" ), false );
386 if ( modIcon.isNull() )
387 modIcon = QPixmap( imageEmptyIcon );
389 QToolBar* modTBar = new QtxToolBar( true, desk );
390 modTBar->setLabel( tr( "INF_TOOLBAR_MODULES" ) );
392 QActionGroup* modGroup = new QActionGroup( this );
393 modGroup->setExclusive( true );
394 modGroup->setUsesDropDown( true );
396 a = createAction( -1, tr( "APP_NAME" ), defIcon, tr( "APP_NAME" ),
397 tr( "PRP_APP_MODULE" ), 0, desk, true );
399 myActions.insert( QString(), a );
401 QMap<QString, QString> iconMap;
402 moduleIconNames( iconMap );
404 const int iconSize = 20;
406 modGroup->addTo( modTBar );
407 modTBar->addSeparator();
410 modules( modList, false );
412 for ( it = modList.begin(); it != modList.end(); ++it )
414 if ( (*it).isEmpty() )
418 if ( iconMap.contains( *it ) )
419 iconName = iconMap[*it];
421 QString modName = moduleName( *it );
423 QPixmap icon = resMgr->loadPixmap( modName, iconName, false );
427 icon.convertFromImage( icon.convertToImage().smoothScale( iconSize, iconSize, QImage::ScaleMin ) );
429 QAction* a = createAction( -1, *it, icon, *it, tr( "PRP_MODULE" ).arg( *it ), 0, desk, true );
433 myActions.insert( *it, a );
436 SUIT_Tools::simplifySeparators( modTBar );
439 int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 );
440 int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
441 createMenu( separator(), windowMenu, -1, 1 );
443 QMap<int, int> accelMap;
444 accelMap[NewGLViewId] = ALT+Key_G;
445 accelMap[NewPlot2dId] = ALT+Key_P;
446 accelMap[NewOCCViewId] = ALT+Key_O;
447 accelMap[NewVTKViewId] = ALT+Key_K;
449 for ( id = NewGLViewId; id <= NewVTKViewId; id++ )
451 QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), QIconSet(),
452 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
453 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
454 accelMap.contains( id ) ? accelMap[id] : 0, desk, false, this, SLOT( onNewWindow() ) );
455 createMenu( a, newWinMenu, -1 );
458 connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) );
460 int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
461 createMenu( PreferencesId, fileMenu, 15, -1 );
462 createMenu( separator(), fileMenu, -1, 15, -1 );
465 createMenu( separator(), fileMenu, -1, 100, -1 );
466 createMenu( MRUId, fileMenu, 100, -1 );
467 createMenu( separator(), fileMenu, -1, 100, -1 );
471 /*!On module activation action.*/
472 void LightApp_Application::onModuleActivation( QAction* a )
477 QString modName = a->menuText();
478 if ( modName == tr( "APP_NAME" ) )
479 modName = QString::null;
481 // Force user to create/open a study before module activation
482 QMap<QString, QString> iconMap;
483 moduleIconNames( iconMap );
484 QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ], false );
486 icon = resourceMgr()->loadPixmap( "LightApp", tr( "APP_MODULE_BIG_ICO" ), false ); // default icon for any module
488 bool cancelled = false;
489 while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
490 LightApp_ModuleDlg aDlg( desktop(), modName, icon );
491 int res = aDlg.exec();
505 putInfo( tr("INF_CANCELLED") );
506 myActions[QString()]->setOn( true );
512 activateModule( modName );
515 /*!Default module activation.*/
516 QString LightApp_Application::defaultModule() const
518 QStringList aModuleNames;
519 modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration
520 //! If there's the one and only module --> activate it automatically
521 //! TODO: Possible improvement - default module can be taken from preferences
522 return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" );
525 /*!On new window slot.*/
526 void LightApp_Application::onNewWindow()
528 const QObject* obj = sender();
529 if ( !obj || !obj->inherits( "QAction" ) )
533 int id = actionId( (QAction*)obj );
537 type = GLViewer_Viewer::Type();
540 type = Plot2d_Viewer::Type();
543 type = OCCViewer_Viewer::Type();
546 type = VTKViewer_Viewer::Type();
550 if ( !type.isEmpty() )
551 createViewManager( type );
554 //=======================================================================
556 /*! Purpose : SLOT. Create new document*/
557 //=======================================================================
558 void LightApp_Application::onNewDoc()
560 SUIT_Study* study = activeStudy();
562 saveWindowsGeometry();
564 CAM_Application::onNewDoc();
566 if ( !study ) // new study will be create in THIS application
569 updateViewManagers();
573 //=======================================================================
575 /*! Purpose : SLOT. Open new document*/
576 //=======================================================================
577 void LightApp_Application::onOpenDoc()
579 SUIT_Study* study = activeStudy();
580 saveWindowsGeometry();
582 CAM_Application::onOpenDoc();
584 if ( !study ) // new study will be create in THIS application
587 updateViewManagers();
591 #include "SUIT_MessageBox.h"
592 /*! Purpose : SLOT. Open new document with \a aName.*/
593 bool LightApp_Application::onOpenDoc( const QString& aName )
595 bool isAlreadyOpen = false;
597 // Look among opened studies
598 if (activeStudy()) { // at least one study is opened
599 SUIT_Session* aSession = SUIT_Session::session();
600 QPtrList<SUIT_Application> aAppList = aSession->applications();
601 QPtrListIterator<SUIT_Application> it (aAppList);
602 SUIT_Application* aApp = 0;
603 // iterate on all applications
604 for (; (aApp = it.current()) && !isAlreadyOpen; ++it) {
605 if (aApp->activeStudy()->studyName() == aName) {
606 isAlreadyOpen = true; // Already opened, ask user what to do
608 // The document ... is already open.
609 // Do you want to reload it?
610 int aAnswer = SUIT_MessageBox::warn2(desktop(), tr("WRN_WARNING"),
611 tr("QUE_DOC_ALREADYOPEN").arg(aName),
612 tr("BUT_YES"), tr("BUT_NO"), 1, 2, 2);
613 if (aAnswer == 1) { // reload
614 if (activeStudy()->studyName() == aName && aAppList.count() > 1) {
615 // Opened in THIS (active) application.
616 STD_Application* app1 = (STD_Application*)aAppList.at(0);
617 STD_Application* app2 = (STD_Application*)aAppList.at(1);
618 if (!app1 || !app2) {
622 if (app1->activeStudy()->studyName() == aName) {
623 // app1 is this application, we need another one
626 // Close document of this application. This application will be destroyed.
627 onCloseDoc(/*ask = */false);
628 // Open the file with another application, as this one will be destroyed.
629 return app1->onOpenDoc(aName);
631 // Opened in another application.
632 STD_Application* app = (STD_Application*)aApp;
634 app->onCloseDoc(/*ask = */false);
636 } else { // do not reload
637 // OK, the study will not be reloaded, but we call
638 // CAM_Application::onOpenDoc( aName ) all the same.
639 // It will activate a desktop of the study <aName>.
645 bool res = CAM_Application::onOpenDoc( aName );
647 QAction* a = action( MRUId );
648 if ( a && a->inherits( "QtxMRUAction" ) )
650 QtxMRUAction* mru = (QtxMRUAction*)a;
652 mru->insert( aName );
654 mru->remove( aName );
659 //=======================================================================
660 // name : onHelpAbout
661 /*! Purpose : SLOT. Display "About" message box*/
662 //=======================================================================
663 void LightApp_Application::onHelpAbout()
665 LightApp_AboutDlg* dlg = new LightApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
670 /*!SLOT. Load document with \a aName.*/
671 bool LightApp_Application::onLoadDoc( const QString& aName )
673 bool res = CAM_Application::onLoadDoc( aName );
675 /*jfa tmp:QAction* a = action( MRUId );
676 if ( a && a->inherits( "QtxMRUAction" ) )
678 QtxMRUAction* mru = (QtxMRUAction*)a;
680 mru->insert( aName );
682 mru->remove( aName );
687 /*!Private SLOT. Selection.*/
688 void LightApp_Application::onSelection()
690 onSelectionChanged();
692 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
693 ((LightApp_Module*)activeModule())->selectionChanged();
697 *\param study - SUIT_Study.
699 void LightApp_Application::setActiveStudy( SUIT_Study* study )
701 CAM_Application::setActiveStudy( study );
706 //=======================================================================
707 // name : updateCommandsStatus
708 /*! Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu*/
709 //=======================================================================
710 void LightApp_Application::updateCommandsStatus()
712 CAM_Application::updateCommandsStatus();
714 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
716 QAction* a = action( id );
718 a->setEnabled( activeStudy() );
722 // Helps to execute command
723 class RunBrowser: public QThread {
726 RunBrowser(QString theApp, QString theParams, QString theHelpFile, QString theContext=NULL):
727 myApp(theApp), myParams(theParams), myHelpFile("file:" + theHelpFile + theContext), myStatus(0) {};
733 if ( !myApp.isEmpty())
735 aCommand.sprintf("%s %s %s",myApp.latin1(),myParams.latin1(),myHelpFile.latin1());
736 myStatus = system(aCommand);
739 QCustomEvent* ce2000 = new QCustomEvent (2000);
740 postEvent (qApp, ce2000);
744 if( myStatus != 0 || myApp.isEmpty())
747 aCommand.sprintf("%s %s %s", QString(DEFAULT_BROWSER).latin1(),myParams.latin1(), myHelpFile.latin1());
748 myStatus = system(aCommand);
751 QCustomEvent* ce2001 = new QCustomEvent (2001);
752 postEvent (qApp, ce2001);
765 //=======================================================================
766 // name : onHelpContentsModule
767 /*! Purpose : SLOT. Display help contents for choosen module*/
768 //=======================================================================
769 void LightApp_Application::onHelpContentsModule()
771 const QAction* obj = (QAction*) sender();
773 QString aComponentName = obj->name();
774 QString aFileName = aComponentName.lower() + ".htm";
779 if (dir = getenv( aComponentName + "_ROOT_DIR")) {
780 root = Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("doc") + Qtx::addSlash("salome") + Qtx::addSlash(aComponentName));
781 if ( QFileInfo( root + aFileName ).exists() ) {
784 SUIT_MessageBox::warn1( desktop(), tr("WRN_WARNING"),
785 QString( "%1"+ aFileName + " doesn't exist." ).arg(root), tr ("BUT_OK") );
790 QString helpFile = QFileInfo( homeDir + aFileName ).absFilePath();
791 SUIT_ResourceMgr* resMgr = resourceMgr();
792 QString anApp = resMgr->stringValue("ExternalBrowser", "application");
793 QString aParams = resMgr->stringValue("ExternalBrowser", "parameters");
795 RunBrowser* rs = new RunBrowser(anApp, aParams, helpFile);
799 /*!Sets enable or disable some actions on selection changed.*/
800 void LightApp_Application::onSelectionChanged()
805 *\param flag - key for window
806 *\param studyId - study id
807 * Flag used how identificator of window in windows list.
809 QWidget* LightApp_Application::window( const int flag, const int studyId ) const
816 if ( !activeStudy() )
819 sId = activeStudy()->id();
822 if ( myWindows.contains( flag ) )
823 wid = myWindows[flag]->widget( sId );
828 /*!Adds window to application.
829 *\param wid - QWidget
830 *\param flag - key wor window
831 *\param studyId - study id
832 * Flag used how identificator of window in windows list.
834 void LightApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
842 if ( !activeStudy() )
845 sId = activeStudy()->id();
848 if ( !myWindows.contains( flag ) )
850 QMap<int, int> winMap;
851 currentWindows( winMap );
853 myWindows.insert( flag, new LightApp_WidgetContainer( flag, desktop() ) );
854 if ( winMap.contains( flag ) )
855 desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
857 myWindows[flag]->setResizeEnabled( true );
858 myWindows[flag]->setCloseMode( QDockWindow::Always );
859 myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
863 if( wid->inherits( "PythonConsole" ) )
864 f = ( ( PythonConsole* )wid )->font();
868 myWindows[flag]->insert( sId, wid );
871 setWindowShown( flag, !myWindows[flag]->isEmpty() );
874 /*!Remove window from application.
875 *\param flag - key wor window
876 *\param studyId - study id
877 * Flag used how identificator of window in windows list.
879 void LightApp_Application::removeWindow( const int flag, const int studyId )
881 if ( !myWindows.contains( flag ) )
887 if ( !activeStudy() )
890 sId = activeStudy()->id();
893 QWidget* wid = myWindows[flag]->widget( sId );
894 myWindows[flag]->remove( sId );
897 setWindowShown( flag, !myWindows[flag]->isEmpty() );
901 *\param flag - key wor window
902 *\param studyId - study id
903 * Flag used how identificator of window in windows list.
905 QWidget* LightApp_Application::getWindow( const int flag, const int studyId )
907 QWidget* wid = window( flag, studyId );
909 addWindow( wid = createWindow( flag ), flag, studyId );
914 /*!Check is window visible?(with identificator \a type)*/
915 bool LightApp_Application::isWindowVisible( const int type ) const
918 if ( myWindows.contains( type ) )
920 SUIT_Desktop* desk = ((LightApp_Application*)this)->desktop();
921 res = desk && desk->appropriate( myWindows[type] );
926 /*!Sets window show or hide.
927 *\param type - window identificator.
928 *\param on - true/false (window show/hide)
930 void LightApp_Application::setWindowShown( const int type, const bool on )
932 if ( !desktop() || !myWindows.contains( type ) )
935 QDockWindow* dw = myWindows[type];
936 desktop()->setAppropriate( dw, on );
937 on ? dw->show() : dw->hide();
940 /*!Gets "ObjectBrowser".*/
941 OB_Browser* LightApp_Application::objectBrowser()
944 QWidget* wid = getWindow( WT_ObjectBrowser );
945 if ( wid->inherits( "OB_Browser" ) )
946 ob = (OB_Browser*)wid;
950 /*!Gets "LogWindow".*/
951 LogWindow* LightApp_Application::logWindow()
954 QWidget* wid = getWindow( WT_LogWindow );
955 if ( wid->inherits( "LogWindow" ) )
956 lw = (LogWindow*)wid;
960 /*!Get "PythonConsole"*/
961 PythonConsole* LightApp_Application::pythonConsole()
963 PythonConsole* console = 0;
964 QWidget* wid = getWindow( WT_PyConsole );
965 if ( wid->inherits( "PythonConsole" ) )
966 console = (PythonConsole*)wid;
970 /*!Update obect browser*/
971 void LightApp_Application::updateObjectBrowser( const bool updateModels )
973 // update existing data models
976 LightApp_Study* study = dynamic_cast<LightApp_Study*>(activeStudy());
978 CAM_Study::ModelList dm_list;
979 study->dataModels( dm_list );
980 for ( CAM_Study::ModelListIterator it( dm_list ); it.current(); ++it ) {
981 CAM_DataModel* camDM = it.current();
982 if ( camDM && camDM->inherits( "LightApp_DataModel" ) )
983 ((LightApp_DataModel*)camDM)->update();
987 if ( objectBrowser() )
989 objectBrowser()->updateGeometry();
990 objectBrowser()->updateTree();
994 /*!Gets preferences.*/
995 LightApp_Preferences* LightApp_Application::preferences() const
997 return preferences( false );
1000 /*!Gets view manager*/
1001 SUIT_ViewManager* LightApp_Application::getViewManager( const QString& vmType, const bool create )
1003 SUIT_ViewManager* aVM = viewManager( vmType );
1004 SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
1006 if ( anActiveVM && anActiveVM->getType() == vmType )
1009 if ( aVM && create )
1011 if ( !aVM->getActiveView() )
1014 aVM->getActiveView()->setFocus();
1017 aVM = createViewManager( vmType );
1022 /*!Create view manager.*/
1023 SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType )
1025 SUIT_ResourceMgr* resMgr = resourceMgr();
1027 SUIT_ViewManager* viewMgr = 0;
1028 if( vmType == GLViewer_Viewer::Type() )
1030 viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
1031 new LightApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
1033 else if( vmType == Plot2d_Viewer::Type() )
1035 viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
1036 SPlot2d_Viewer* vm = new SPlot2d_Viewer();
1037 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1038 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( viewMgr->getActiveView() );
1041 Plot2d_ViewFrame* frame = wnd->getViewFrame();
1042 frame->setBackgroundColor( resMgr->colorValue( "Plot2d", "Background", frame->backgroundColor() ) );
1045 else if( vmType == SUPERVGraph_Viewer::Type() )
1047 viewMgr = new SUPERVGraph_ViewManager( activeStudy(), desktop() );
1048 SUPERVGraph_Viewer* vm = new SUPERVGraph_Viewer();
1049 SUPERVGraph_ViewFrame* view = dynamic_cast<SUPERVGraph_ViewFrame*>( vm->getViewManager()->getActiveView() );
1051 view->setBackgroundColor( resMgr->colorValue( "SUPERVGraph", "Background", view->backgroundColor() ) );
1053 else if( vmType == OCCViewer_Viewer::Type() )
1055 viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
1056 SOCC_Viewer* vm = new SOCC_Viewer();
1057 vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
1058 vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
1061 u = resMgr->integerValue( "OCCViewer", "iso_number_u", u );
1062 v = resMgr->integerValue( "OCCViewer", "iso_number_v", v );
1063 vm->setIsos( u, v );
1064 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1065 new LightApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
1067 else if ( vmType == SVTK_Viewer::Type() )
1069 viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
1070 SVTK_Viewer* vm = dynamic_cast<SVTK_Viewer*>( viewMgr->getViewModel() );
1073 vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
1074 vm->setTrihedronSize( resMgr->integerValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ) );
1075 new LightApp_VTKSelector( vm, mySelMgr );
1082 addViewManager( viewMgr );
1083 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
1085 if ( viewWin && desktop() )
1086 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
1088 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1089 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
1094 //=======================================================================
1095 // name : onCloseView
1096 /*! Purpose : SLOT. Remove view manager from application*/
1097 //=======================================================================
1098 void LightApp_Application::onCloseView( SUIT_ViewManager* theVM )
1100 removeViewManager( theVM );
1103 /*!Protected SLOT. On study created.*/
1104 void LightApp_Application::onStudyCreated( SUIT_Study* theStudy )
1106 SUIT_DataObject* aRoot = 0;
1107 if ( theStudy && theStudy->root() )
1109 aRoot = theStudy->root();
1110 //aRoot->setName( tr( "DATA_MODELS" ) );
1112 if ( objectBrowser() != 0 )
1113 objectBrowser()->setRootObject( aRoot );
1115 activateModule( defaultModule() );
1120 /*!Protected SLOT. On study opened.*/
1121 void LightApp_Application::onStudyOpened( SUIT_Study* theStudy )
1123 SUIT_DataObject* aRoot = 0;
1124 if ( theStudy && theStudy->root() )
1126 aRoot = theStudy->root();
1129 if ( objectBrowser() != 0 ) {
1130 objectBrowser()->setRootObject( aRoot );
1133 activateModule( defaultModule() );
1140 /*!Protected SLOT. On study saved.*/
1141 void LightApp_Application::onStudySaved( SUIT_Study* )
1146 /*!Protected SLOT. On study closed.*/
1147 void LightApp_Application::onStudyClosed( SUIT_Study* )
1151 activateModule( "" );
1153 // Bug 10396: remove all selectors
1155 mySelMgr = new LightApp_SelectionMgr( this );
1157 saveWindowsGeometry();
1160 /*!Protected SLOT.On desktop activated.*/
1161 void LightApp_Application::onDesktopActivated()
1163 CAM_Application::onDesktopActivated();
1164 LightApp_Module* aModule = dynamic_cast<LightApp_Module*>(activeModule());
1166 aModule->studyActivated();
1169 /*!Gets file filter.
1170 *\retval QString "(*.bin)"
1172 QString LightApp_Application::getFileFilter() const
1177 /*! Gets file name*/
1178 QString LightApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1179 const QString& caption, QWidget* parent )
1183 QStringList fls = QStringList::split( ";;", filters, false );
1184 return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1187 /*! Gets directory*/
1188 QString LightApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1192 return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1195 /*! Get open file names*/
1196 QStringList LightApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
1197 const QString& caption, QWidget* parent )
1201 QStringList fls = QStringList::split( ";;", filters, false );
1202 return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1205 /*!Private SLOT. Update object browser.*/
1206 void LightApp_Application::onRefresh()
1208 updateObjectBrowser( true );
1211 /*!Private SLOT. On preferences.*/
1212 void LightApp_Application::onPreferences()
1214 QApplication::setOverrideCursor( Qt::waitCursor );
1216 LightApp_PreferencesDlg* prefDlg = new LightApp_PreferencesDlg( preferences( true ), desktop());
1218 QApplication::restoreOverrideCursor();
1228 /*!Protected SLOT. On preferences changed.*/
1229 void LightApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1231 LightApp_Module* sMod = 0;
1232 CAM_Module* mod = module( modName );
1233 if ( mod && mod->inherits( "LightApp_Module" ) )
1234 sMod = (LightApp_Module*)mod;
1237 sMod->preferencesChanged( section, param );
1239 preferencesChanged( section, param );
1242 /*!Private SLOT. On open document with name \a aName.*/
1243 void LightApp_Application::onMRUActivated( QString aName )
1248 /*!Remove all windows from study.*/
1249 void LightApp_Application::beforeCloseDoc( SUIT_Study* s )
1251 CAM_Application::beforeCloseDoc( s );
1253 for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1254 removeWindow( itr.key(), s->id() );
1257 /*!Update actions.*/
1258 void LightApp_Application::updateActions()
1260 updateCommandsStatus();
1263 //=======================================================================
1264 // name : createNewStudy
1265 /*! Purpose : Create new study*/
1266 //=======================================================================
1267 SUIT_Study* LightApp_Application::createNewStudy()
1269 LightApp_Study* aStudy = new LightApp_Study( this );
1271 // Set up processing of major study-related events
1272 connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
1273 connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
1274 connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );
1275 connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
1281 QWidget* LightApp_Application::createWindow( const int flag )
1284 if ( flag == WT_ObjectBrowser )
1286 OB_Browser* ob = new OB_Browser( desktop() );
1287 ob->setAutoUpdate( true );
1288 ob->setAutoOpenLevel( 1 );
1289 ob->setCaption( tr( "OBJECT_BROWSER" ) );
1290 ob->listView()->setColumnWidth( 0, OBJECT_COLUMN_WIDTH );
1291 ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
1292 ob->setFilter( new LightApp_OBFilter( selectionMgr() ) );
1294 ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1296 // Create OBSelector
1297 new LightApp_OBSelector( ob, mySelMgr );
1301 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1303 else if ( flag == WT_PyConsole )
1305 PythonConsole* pyCons = new PythonConsole( desktop() );
1306 pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1308 // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1310 else if ( flag == WT_LogWindow )
1312 LogWindow* logWin = new LogWindow( desktop() );
1313 logWin->setCaption( tr( "LOG_WINDOW" ) );
1315 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1320 /*!Default windows(Object Browser, Python Console).
1321 * Adds to map \a aMap.
1323 void LightApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1325 aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1326 aMap.insert( WT_PyConsole, Qt::DockBottom );
1327 // aMap.insert( WT_LogWindow, Qt::DockBottom );
1330 /*!Default view manager.*/
1331 void LightApp_Application::defaultViewManagers( QStringList& ) const
1336 /*!Gets preferences.
1337 * Create preferences, if \a crt = true.
1339 LightApp_Preferences* LightApp_Application::preferences( const bool crt ) const
1344 LightApp_Application* that = (LightApp_Application*)this;
1346 if ( !_prefs_ && crt )
1348 _prefs_ = new LightApp_Preferences( resourceMgr() );
1349 that->createPreferences( _prefs_ );
1352 that->myPrefs = _prefs_;
1354 QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1355 for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1357 if ( !appIt.current()->inherits( "LightApp_Application" ) )
1360 LightApp_Application* app = (LightApp_Application*)appIt.current();
1362 QStringList modNameList;
1363 app->modules( modNameList, false );
1364 for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1366 int id = _prefs_->addPreference( *it );
1367 _prefs_->setItemProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1371 app->modules( modList );
1372 for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1374 LightApp_Module* mod = 0;
1375 if ( itr.current()->inherits( "LightApp_Module" ) )
1376 mod = (LightApp_Module*)itr.current();
1378 if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1380 int modCat = _prefs_->addPreference( mod->moduleName() );
1381 _prefs_->setItemProperty( modCat, "info", QString::null );
1382 mod->createPreferences();
1387 connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1388 this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1393 /*!Add new module to application.*/
1394 void LightApp_Application::moduleAdded( CAM_Module* mod )
1396 CAM_Application::moduleAdded( mod );
1398 LightApp_Module* lightMod = 0;
1399 if ( mod && mod->inherits( "LightApp_Module" ) )
1400 lightMod = (LightApp_Module*)mod;
1402 if ( myPrefs && lightMod && !myPrefs->hasModule( lightMod->moduleName() ))
1404 int modCat = myPrefs->addPreference( mod->moduleName() );
1405 myPrefs->setItemProperty( modCat, "info", QString::null );
1406 lightMod->createPreferences();
1410 /*!Create preferences.*/
1411 void LightApp_Application::createPreferences( LightApp_Preferences* pref )
1416 int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1418 int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1419 int studyGroup = pref->addPreference( tr( "PREF_GROUP_STUDY" ), genTab );
1420 pref->setItemProperty( studyGroup, "columns", 1 );
1422 pref->addPreference( tr( "PREF_MULTI_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "multi_file" );
1423 pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "ascii_file" );
1424 int undoPref = pref->addPreference( tr( "PREF_UNDO_LEVEL" ), studyGroup, LightApp_Preferences::IntSpin, "Study", "undo_level" );
1425 pref->setItemProperty( undoPref, "min", 1 );
1426 pref->setItemProperty( undoPref, "max", 100 );
1428 int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab );
1429 pref->setItemProperty( extgroup, "columns", 1 );
1430 int apppref = pref->addPreference( tr( "PREF_APP" ), extgroup, LightApp_Preferences::File, "ExternalBrowser", "application" );
1431 pref->setItemProperty( apppref, "existing", true );
1432 pref->setItemProperty( apppref, "flags", QFileInfo::ExeUser );
1434 pref->addPreference( tr( "PREF_PARAM" ), extgroup, LightApp_Preferences::String, "ExternalBrowser", "parameters" );
1436 int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab );
1437 pref->setItemProperty( pythonConsoleGroup, "columns", 1 );
1438 pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, LightApp_Preferences::Font, "PyConsole", "font" );
1440 int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1442 int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1444 int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1446 int plot2dGroup = pref->addPreference( tr( "PREF_GROUP_PLOT2DVIEWER" ), viewTab );
1448 int supervGroup = pref->addPreference( tr( "PREF_GROUP_SUPERV" ), viewTab );
1450 pref->setItemProperty( occGroup, "columns", 1 );
1451 pref->setItemProperty( vtkGroup, "columns", 1 );
1452 pref->setItemProperty( plot2dGroup, "columns", 1 );
1454 int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1455 LightApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1456 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1457 LightApp_Preferences::Color, "OCCViewer", "background" );
1459 pref->setItemProperty( occTS, "min", 1 );
1460 pref->setItemProperty( occTS, "max", 150 );
1462 int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
1463 LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
1464 int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
1465 LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
1467 pref->setItemProperty( isoU, "min", 0 );
1468 pref->setItemProperty( isoU, "max", 100000 );
1470 pref->setItemProperty( isoV, "min", 0 );
1471 pref->setItemProperty( isoV, "max", 100000 );
1473 int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1474 LightApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1475 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1476 LightApp_Preferences::Color, "VTKViewer", "background" );
1478 pref->setItemProperty( vtkTS, "min", 1 );
1479 pref->setItemProperty( vtkTS, "max", 150 );
1481 pref->addPreference( tr( "PREF_SHOW_LEGEND" ), plot2dGroup,
1482 LightApp_Preferences::Bool, "Plot2d", "ShowLegend" );
1484 int legendPosition = pref->addPreference( tr( "PREF_LEGEND_POSITION" ), plot2dGroup,
1485 LightApp_Preferences::Selector, "Plot2d", "LegendPos" );
1486 QStringList aLegendPosList;
1487 aLegendPosList.append( tr("PREF_LEFT") );
1488 aLegendPosList.append( tr("PREF_RIGHT") );
1489 aLegendPosList.append( tr("PREF_TOP") );
1490 aLegendPosList.append( tr("PREF_BOTTOM") );
1492 QValueList<QVariant> anIndexesList;
1493 anIndexesList.append(0);
1494 anIndexesList.append(1);
1495 anIndexesList.append(2);
1496 anIndexesList.append(3);
1498 pref->setItemProperty( legendPosition, "strings", aLegendPosList );
1499 pref->setItemProperty( legendPosition, "indexes", anIndexesList );
1501 int curveType = pref->addPreference( tr( "PREF_CURVE_TYPE" ), plot2dGroup,
1502 LightApp_Preferences::Selector, "Plot2d", "CurveType" );
1503 QStringList aCurveTypesList;
1504 aCurveTypesList.append( tr("PREF_POINTS") );
1505 aCurveTypesList.append( tr("PREF_LINES") );
1506 aCurveTypesList.append( tr("PREF_SPLINE") );
1508 anIndexesList.clear();
1509 anIndexesList.append(0);
1510 anIndexesList.append(1);
1511 anIndexesList.append(2);
1513 pref->setItemProperty( curveType, "strings", aCurveTypesList );
1514 pref->setItemProperty( curveType, "indexes", anIndexesList );
1516 int markerSize = pref->addPreference( tr( "PREF_MARKER_SIZE" ), plot2dGroup,
1517 LightApp_Preferences::IntSpin, "Plot2d", "MarkerSize" );
1519 pref->setItemProperty( markerSize, "min", 0 );
1520 pref->setItemProperty( markerSize, "max", 100 );
1522 QStringList aScaleModesList;
1523 aScaleModesList.append( tr("PREF_LINEAR") );
1524 aScaleModesList.append( tr("PREF_LOGARITHMIC") );
1526 anIndexesList.clear();
1527 anIndexesList.append(0);
1528 anIndexesList.append(1);
1530 int horScale = pref->addPreference( tr( "PREF_HOR_AXIS_SCALE" ), plot2dGroup,
1531 LightApp_Preferences::Selector, "Plot2d", "HorScaleMode" );
1533 pref->setItemProperty( horScale, "strings", aScaleModesList );
1534 pref->setItemProperty( horScale, "indexes", anIndexesList );
1536 int verScale = pref->addPreference( tr( "PREF_VERT_AXIS_SCALE" ), plot2dGroup,
1537 LightApp_Preferences::Selector, "Plot2d", "VerScaleMode" );
1539 pref->setItemProperty( verScale, "strings", aScaleModesList );
1540 pref->setItemProperty( verScale, "indexes", anIndexesList );
1542 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), plot2dGroup,
1543 LightApp_Preferences::Color, "Plot2d", "Background" );
1545 int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat );
1546 int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab );
1547 pref->setItemProperty( dirGroup, "columns", 1 );
1548 pref->addPreference( tr( "" ), dirGroup,
1549 LightApp_Preferences::DirList, "FileDlg", "QuickDirList" );
1551 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), supervGroup,
1552 LightApp_Preferences::Color, "SUPERVGraph", "Background" );
1553 pref->addPreference( tr( "PREF_SUPERV_TITLE_COLOR" ), supervGroup,
1554 LightApp_Preferences::Color, "SUPERVGraph", "Title" );
1555 // pref->addPreference( tr( "PREF_SUPERV_CTRL_COLOR" ), supervGroup,
1556 // LightApp_Preferences::Color, "SUPERVGraph", "Ctrl" );
1559 /*!Changed preferences */
1560 void LightApp_Application::preferencesChanged( const QString& sec, const QString& param )
1562 SUIT_ResourceMgr* resMgr = resourceMgr();
1566 if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1568 int sz = resMgr->integerValue( sec, param, -1 );
1569 QPtrList<SUIT_ViewManager> lst;
1570 viewManagers( OCCViewer_Viewer::Type(), lst );
1571 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1573 SUIT_ViewModel* vm = it.current()->getViewModel();
1574 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1577 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1578 occVM->setTrihedronSize( sz );
1579 occVM->getAISContext()->UpdateCurrentViewer();
1583 if ( sec == QString( "VTKViewer" ) && param == QString( "trihedron_size" ) )
1585 int sz = resMgr->integerValue( sec, param, -1 );
1586 QPtrList<SUIT_ViewManager> lst;
1587 viewManagers( SVTK_Viewer::Type(), lst );
1588 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1590 SUIT_ViewModel* vm = it.current()->getViewModel();
1591 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
1594 SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
1597 vtkVM->setTrihedronSize( sz );
1603 if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
1605 QPtrList<SUIT_ViewManager> lst;
1606 viewManagers( OCCViewer_Viewer::Type(), lst );
1607 int u = resMgr->integerValue( sec, "iso_number_u" );
1608 int v = resMgr->integerValue( sec, "iso_number_v" );
1609 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
1610 ((OCCViewer_Viewer*)it.current())->setIsos( u, v );
1613 if( sec=="ObjectBrowser" )
1615 if( param=="auto_size" )
1617 OB_Browser* ob = objectBrowser();
1621 bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
1622 ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1624 updateObjectBrowser( false );
1628 if( sec=="PyConsole" )
1631 if( pythonConsole() )
1632 pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1636 /*!Update desktop title.*/
1637 void LightApp_Application::updateDesktopTitle() {
1638 QString aTitle = applicationName();
1639 QString aVer = applicationVersion();
1640 if ( !aVer.isEmpty() )
1641 aTitle += QString( " " ) + aVer;
1643 desktop()->setCaption( aTitle );
1646 /*!Update windows after close document.*/
1647 void LightApp_Application::afterCloseDoc()
1651 CAM_Application::afterCloseDoc();
1654 /*!Update module action.*/
1655 void LightApp_Application::updateModuleActions()
1658 if ( activeModule() )
1659 modName = activeModule()->moduleName();
1661 if ( myActions.contains( modName ) )
1662 myActions[modName]->setOn( true );
1665 /*!Gets current windows.
1666 *\param winMap - output current windows map.
1668 void LightApp_Application::currentWindows( QMap<int, int>& winMap ) const
1671 if ( !activeStudy() )
1674 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
1675 ((LightApp_Module*)activeModule())->windows( winMap );
1677 defaultWindows( winMap );
1680 /*!Gets current view managers.
1681 *\param lst - output current view managers list.
1683 void LightApp_Application::currentViewManagers( QStringList& lst ) const
1686 if ( !activeStudy() )
1689 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
1690 ((LightApp_Module*)activeModule())->viewManagers( lst );
1692 defaultViewManagers( lst );
1695 /*!Update windows.*/
1696 void LightApp_Application::updateWindows()
1698 QMap<int, int> winMap;
1699 currentWindows( winMap );
1701 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1702 getWindow( it.key() );
1704 loadWindowsGeometry();
1706 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1707 setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1710 /*!Update view managers.*/
1711 void LightApp_Application::updateViewManagers()
1714 currentViewManagers( lst );
1716 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1717 getViewManager( *it, true );
1720 /*!Load windows geometry.*/
1721 void LightApp_Application::loadWindowsGeometry()
1723 QtxDockAction* dockMgr = 0;
1725 QAction* a = action( ViewWindowsId );
1726 if ( a && a->inherits( "QtxDockAction" ) )
1727 dockMgr = (QtxDockAction*)a;
1733 if ( activeModule() )
1734 modName = activeModule()->name("");
1736 QString section = QString( "windows_geometry" );
1737 if ( !modName.isEmpty() )
1738 section += QString( "." ) + modName;
1740 dockMgr->loadGeometry( resourceMgr(), section, false );
1741 dockMgr->restoreGeometry();
1744 /*!Save windows geometry.*/
1745 void LightApp_Application::saveWindowsGeometry()
1747 QtxDockAction* dockMgr = 0;
1749 QAction* a = action( ViewWindowsId );
1750 if ( a && a->inherits( "QtxDockAction" ) )
1751 dockMgr = (QtxDockAction*)a;
1757 if ( activeModule() )
1758 modName = activeModule()->name("");
1760 QString section = QString( "windows_geometry" );
1761 if ( !modName.isEmpty() )
1762 section += QString( "." ) + modName;
1764 dockMgr->storeGeometry();
1765 dockMgr->saveGeometry( resourceMgr(), section, false );
1768 /*!Activate windows.*/
1769 void LightApp_Application::activateWindows()
1771 if ( activeStudy() )
1773 for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1774 itr.data()->activate( activeStudy()->id() );
1778 /*!Adds icon names for modules.*/
1779 void LightApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
1783 SUIT_ResourceMgr* resMgr = resourceMgr();
1787 QStringList modList;
1788 modules( modList, false );
1790 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
1792 QString modName = *it;
1793 QString modIntr = moduleName( modName );
1794 QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
1796 if ( modIcon.isEmpty() )
1799 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
1800 modIcon += QString( ".png" );
1802 iconMap.insert( modName, modIcon );
1806 /*!Insert items in popup, which necessary for current application*/
1807 void LightApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
1809 CAM_Application::contextMenuPopup( type, thePopup, title );
1811 OB_Browser* ob = objectBrowser();
1812 if ( !ob || type != ob->popupClientType() )
1815 thePopup->insertSeparator();
1816 thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
1819 /*!Create empty study.*/
1820 void LightApp_Application::createEmptyStudy()
1822 CAM_Application::createEmptyStudy();
1823 if ( objectBrowser() )
1824 objectBrowser()->updateTree();
1827 /*!Activate module \a mod.*/
1828 bool LightApp_Application::activateModule( CAM_Module* mod )
1830 bool res = CAM_Application::activateModule( mod );
1831 if ( objectBrowser() )
1832 objectBrowser()->updateTree();
1836 /*!return keyborad accelerators manager object */
1837 SUIT_Accel* LightApp_Application::accel() const