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 + "_index.html";
779 if (dir = getenv( aComponentName + "_ROOT_DIR")) {
780 root = Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("doc") + Qtx::addSlash("salome") );
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 LightApp_WidgetContainer* newWC = new LightApp_WidgetContainer( flag, desktop() );
854 connect( newWC, SIGNAL( destroyed ( QObject* ) ), this, SLOT( onWCDestroyed( QObject* ) ) );
855 myWindows.insert( flag, newWC );
856 if ( winMap.contains( flag ) )
857 desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
859 myWindows[flag]->setResizeEnabled( true );
860 myWindows[flag]->setCloseMode( QDockWindow::Always );
861 myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
865 if( wid->inherits( "PythonConsole" ) )
866 f = ( ( PythonConsole* )wid )->font();
870 myWindows[flag]->insert( sId, wid );
873 setWindowShown( flag, !myWindows[flag]->isEmpty() );
876 /*!Remove window from application.
877 *\param flag - key wor window
878 *\param studyId - study id
879 * Flag used how identificator of window in windows list.
881 void LightApp_Application::removeWindow( const int flag, const int studyId )
883 if ( !myWindows.contains( flag ) )
889 if ( !activeStudy() )
892 sId = activeStudy()->id();
895 QWidget* wid = myWindows[flag]->widget( sId );
896 myWindows[flag]->remove( sId );
899 setWindowShown( flag, !myWindows[flag]->isEmpty() );
903 *\param flag - key wor window
904 *\param studyId - study id
905 * Flag used how identificator of window in windows list.
907 QWidget* LightApp_Application::getWindow( const int flag, const int studyId )
909 QWidget* wid = window( flag, studyId );
911 addWindow( wid = createWindow( flag ), flag, studyId );
916 /*!Check is window visible?(with identificator \a type)*/
917 bool LightApp_Application::isWindowVisible( const int type ) const
920 if ( myWindows.contains( type ) )
922 SUIT_Desktop* desk = ((LightApp_Application*)this)->desktop();
923 res = desk && desk->appropriate( myWindows[type] );
928 /*!Sets window show or hide.
929 *\param type - window identificator.
930 *\param on - true/false (window show/hide)
932 void LightApp_Application::setWindowShown( const int type, const bool on )
934 if ( !desktop() || !myWindows.contains( type ) )
937 QDockWindow* dw = myWindows[type];
938 desktop()->setAppropriate( dw, on );
939 on ? dw->show() : dw->hide();
942 /*!Gets "ObjectBrowser".*/
943 OB_Browser* LightApp_Application::objectBrowser()
946 QWidget* wid = getWindow( WT_ObjectBrowser );
947 if ( wid->inherits( "OB_Browser" ) )
948 ob = (OB_Browser*)wid;
952 /*!Gets "LogWindow".*/
953 LogWindow* LightApp_Application::logWindow()
956 QWidget* wid = getWindow( WT_LogWindow );
957 if ( wid->inherits( "LogWindow" ) )
958 lw = (LogWindow*)wid;
962 /*!Get "PythonConsole"*/
963 PythonConsole* LightApp_Application::pythonConsole()
965 PythonConsole* console = 0;
966 QWidget* wid = getWindow( WT_PyConsole );
967 if ( wid->inherits( "PythonConsole" ) )
968 console = (PythonConsole*)wid;
972 /*!Update obect browser*/
973 void LightApp_Application::updateObjectBrowser( const bool updateModels )
975 // update existing data models
978 LightApp_Study* study = dynamic_cast<LightApp_Study*>(activeStudy());
980 CAM_Study::ModelList dm_list;
981 study->dataModels( dm_list );
982 for ( CAM_Study::ModelListIterator it( dm_list ); it.current(); ++it ) {
983 CAM_DataModel* camDM = it.current();
984 if ( camDM && camDM->inherits( "LightApp_DataModel" ) )
985 ((LightApp_DataModel*)camDM)->update();
989 if ( objectBrowser() )
991 objectBrowser()->updateGeometry();
992 objectBrowser()->updateTree();
996 /*!Gets preferences.*/
997 LightApp_Preferences* LightApp_Application::preferences() const
999 return preferences( false );
1002 /*!Gets view manager*/
1003 SUIT_ViewManager* LightApp_Application::getViewManager( const QString& vmType, const bool create )
1005 SUIT_ViewManager* aVM = viewManager( vmType );
1006 SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
1008 if ( anActiveVM && anActiveVM->getType() == vmType )
1011 if ( aVM && create )
1013 if ( !aVM->getActiveView() )
1016 aVM->getActiveView()->setFocus();
1019 aVM = createViewManager( vmType );
1024 /*!Create view manager.*/
1025 SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType )
1027 SUIT_ResourceMgr* resMgr = resourceMgr();
1029 SUIT_ViewManager* viewMgr = 0;
1030 if( vmType == GLViewer_Viewer::Type() )
1032 viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
1033 new LightApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
1035 else if( vmType == Plot2d_Viewer::Type() )
1037 viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
1038 SPlot2d_Viewer* vm = new SPlot2d_Viewer();
1039 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1040 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( viewMgr->getActiveView() );
1043 Plot2d_ViewFrame* frame = wnd->getViewFrame();
1044 frame->setBackgroundColor( resMgr->colorValue( "Plot2d", "Background", frame->backgroundColor() ) );
1047 else if( vmType == SUPERVGraph_Viewer::Type() )
1049 viewMgr = new SUPERVGraph_ViewManager( activeStudy(), desktop() );
1050 SUPERVGraph_Viewer* vm = new SUPERVGraph_Viewer();
1051 SUPERVGraph_ViewFrame* view = dynamic_cast<SUPERVGraph_ViewFrame*>( vm->getViewManager()->getActiveView() );
1053 view->setBackgroundColor( resMgr->colorValue( "SUPERVGraph", "Background", view->backgroundColor() ) );
1055 else if( vmType == OCCViewer_Viewer::Type() )
1057 viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
1058 SOCC_Viewer* vm = new SOCC_Viewer();
1059 vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
1060 vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
1063 u = resMgr->integerValue( "OCCViewer", "iso_number_u", u );
1064 v = resMgr->integerValue( "OCCViewer", "iso_number_v", v );
1065 vm->setIsos( u, v );
1066 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1067 new LightApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
1069 else if ( vmType == SVTK_Viewer::Type() )
1071 viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
1072 SVTK_Viewer* vm = dynamic_cast<SVTK_Viewer*>( viewMgr->getViewModel() );
1075 vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
1076 vm->setTrihedronSize( resMgr->integerValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ) );
1077 new LightApp_VTKSelector( vm, mySelMgr );
1084 addViewManager( viewMgr );
1085 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
1087 if ( viewWin && desktop() )
1088 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
1090 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1091 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
1096 //=======================================================================
1097 // name : onCloseView
1098 /*! Purpose : SLOT. Remove view manager from application*/
1099 //=======================================================================
1100 void LightApp_Application::onCloseView( SUIT_ViewManager* theVM )
1102 removeViewManager( theVM );
1105 /*!Protected SLOT. On study created.*/
1106 void LightApp_Application::onStudyCreated( SUIT_Study* theStudy )
1108 SUIT_DataObject* aRoot = 0;
1109 if ( theStudy && theStudy->root() )
1111 aRoot = theStudy->root();
1112 //aRoot->setName( tr( "DATA_MODELS" ) );
1114 if ( objectBrowser() != 0 )
1115 objectBrowser()->setRootObject( aRoot );
1117 activateModule( defaultModule() );
1122 /*!Protected SLOT. On study opened.*/
1123 void LightApp_Application::onStudyOpened( SUIT_Study* theStudy )
1125 SUIT_DataObject* aRoot = 0;
1126 if ( theStudy && theStudy->root() )
1128 aRoot = theStudy->root();
1131 if ( objectBrowser() != 0 ) {
1132 objectBrowser()->setRootObject( aRoot );
1135 activateModule( defaultModule() );
1142 /*!Protected SLOT. On study saved.*/
1143 void LightApp_Application::onStudySaved( SUIT_Study* )
1148 /*!Protected SLOT. On study closed.*/
1149 void LightApp_Application::onStudyClosed( SUIT_Study* )
1153 // Bug 10396: clear selection
1154 mySelMgr->clearSelected();
1156 activateModule( "" );
1158 saveWindowsGeometry();
1161 /*!Protected SLOT.On desktop activated.*/
1162 void LightApp_Application::onDesktopActivated()
1164 CAM_Application::onDesktopActivated();
1165 LightApp_Module* aModule = dynamic_cast<LightApp_Module*>(activeModule());
1167 aModule->studyActivated();
1170 /*!Gets file filter.
1171 *\retval QString "(*.bin)"
1173 QString LightApp_Application::getFileFilter() const
1178 /*! Gets file name*/
1179 QString LightApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1180 const QString& caption, QWidget* parent )
1184 QStringList fls = QStringList::split( ";;", filters, false );
1185 return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1188 /*! Gets directory*/
1189 QString LightApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1193 return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1196 /*! Get open file names*/
1197 QStringList LightApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
1198 const QString& caption, QWidget* parent )
1202 QStringList fls = QStringList::split( ";;", filters, false );
1203 return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1206 /*!Private SLOT. Update object browser.*/
1207 void LightApp_Application::onRefresh()
1209 updateObjectBrowser( true );
1212 /*!Private SLOT. On preferences.*/
1213 void LightApp_Application::onPreferences()
1215 QApplication::setOverrideCursor( Qt::waitCursor );
1217 LightApp_PreferencesDlg* prefDlg = new LightApp_PreferencesDlg( preferences( true ), desktop());
1219 QApplication::restoreOverrideCursor();
1229 /*!Protected SLOT. On preferences changed.*/
1230 void LightApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1232 LightApp_Module* sMod = 0;
1233 CAM_Module* mod = module( modName );
1234 if ( mod && mod->inherits( "LightApp_Module" ) )
1235 sMod = (LightApp_Module*)mod;
1238 sMod->preferencesChanged( section, param );
1240 preferencesChanged( section, param );
1243 /*!Private SLOT. On open document with name \a aName.*/
1244 void LightApp_Application::onMRUActivated( QString aName )
1249 /*!Remove all windows from study.*/
1250 void LightApp_Application::beforeCloseDoc( SUIT_Study* s )
1252 CAM_Application::beforeCloseDoc( s );
1254 for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1255 removeWindow( itr.key(), s->id() );
1258 /*!Update actions.*/
1259 void LightApp_Application::updateActions()
1261 updateCommandsStatus();
1264 //=======================================================================
1265 // name : createNewStudy
1266 /*! Purpose : Create new study*/
1267 //=======================================================================
1268 SUIT_Study* LightApp_Application::createNewStudy()
1270 LightApp_Study* aStudy = new LightApp_Study( this );
1272 // Set up processing of major study-related events
1273 connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
1274 connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
1275 connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );
1276 connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
1282 QWidget* LightApp_Application::createWindow( const int flag )
1285 if ( flag == WT_ObjectBrowser )
1287 OB_Browser* ob = new OB_Browser( desktop() );
1288 ob->setAutoUpdate( true );
1289 ob->setAutoOpenLevel( 1 );
1290 ob->setCaption( tr( "OBJECT_BROWSER" ) );
1291 ob->listView()->setColumnWidth( 0, OBJECT_COLUMN_WIDTH );
1292 ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
1293 ob->setFilter( new LightApp_OBFilter( selectionMgr() ) );
1295 ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1297 // Create OBSelector
1298 new LightApp_OBSelector( ob, mySelMgr );
1302 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1304 else if ( flag == WT_PyConsole )
1306 PythonConsole* pyCons = new PythonConsole( desktop() );
1307 pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1309 // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1311 else if ( flag == WT_LogWindow )
1313 LogWindow* logWin = new LogWindow( desktop() );
1314 logWin->setCaption( tr( "LOG_WINDOW" ) );
1316 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1321 /*!Default windows(Object Browser, Python Console).
1322 * Adds to map \a aMap.
1324 void LightApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1326 aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1327 aMap.insert( WT_PyConsole, Qt::DockBottom );
1328 // aMap.insert( WT_LogWindow, Qt::DockBottom );
1331 /*!Default view manager.*/
1332 void LightApp_Application::defaultViewManagers( QStringList& ) const
1337 /*!Gets preferences.
1338 * Create preferences, if \a crt = true.
1340 LightApp_Preferences* LightApp_Application::preferences( const bool crt ) const
1345 LightApp_Application* that = (LightApp_Application*)this;
1347 if ( !_prefs_ && crt )
1349 _prefs_ = new LightApp_Preferences( resourceMgr() );
1350 that->createPreferences( _prefs_ );
1353 that->myPrefs = _prefs_;
1355 QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1356 for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1358 if ( !appIt.current()->inherits( "LightApp_Application" ) )
1361 LightApp_Application* app = (LightApp_Application*)appIt.current();
1363 QStringList modNameList;
1364 app->modules( modNameList, false );
1365 for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1367 int id = _prefs_->addPreference( *it );
1368 _prefs_->setItemProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1372 app->modules( modList );
1373 for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1375 LightApp_Module* mod = 0;
1376 if ( itr.current()->inherits( "LightApp_Module" ) )
1377 mod = (LightApp_Module*)itr.current();
1379 if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1381 int modCat = _prefs_->addPreference( mod->moduleName() );
1382 _prefs_->setItemProperty( modCat, "info", QString::null );
1383 mod->createPreferences();
1388 connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1389 this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1394 /*!Add new module to application.*/
1395 void LightApp_Application::moduleAdded( CAM_Module* mod )
1397 CAM_Application::moduleAdded( mod );
1399 LightApp_Module* lightMod = 0;
1400 if ( mod && mod->inherits( "LightApp_Module" ) )
1401 lightMod = (LightApp_Module*)mod;
1403 if ( myPrefs && lightMod && !myPrefs->hasModule( lightMod->moduleName() ))
1405 int modCat = myPrefs->addPreference( mod->moduleName() );
1406 myPrefs->setItemProperty( modCat, "info", QString::null );
1407 lightMod->createPreferences();
1411 /*!Create preferences.*/
1412 void LightApp_Application::createPreferences( LightApp_Preferences* pref )
1417 int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1419 int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1420 int studyGroup = pref->addPreference( tr( "PREF_GROUP_STUDY" ), genTab );
1421 pref->setItemProperty( studyGroup, "columns", 1 );
1423 pref->addPreference( tr( "PREF_MULTI_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "multi_file" );
1424 pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "ascii_file" );
1425 int undoPref = pref->addPreference( tr( "PREF_UNDO_LEVEL" ), studyGroup, LightApp_Preferences::IntSpin, "Study", "undo_level" );
1426 pref->setItemProperty( undoPref, "min", 1 );
1427 pref->setItemProperty( undoPref, "max", 100 );
1429 int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab );
1430 pref->setItemProperty( extgroup, "columns", 1 );
1431 int apppref = pref->addPreference( tr( "PREF_APP" ), extgroup, LightApp_Preferences::File, "ExternalBrowser", "application" );
1432 pref->setItemProperty( apppref, "existing", true );
1433 pref->setItemProperty( apppref, "flags", QFileInfo::ExeUser );
1435 pref->addPreference( tr( "PREF_PARAM" ), extgroup, LightApp_Preferences::String, "ExternalBrowser", "parameters" );
1437 int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab );
1438 pref->setItemProperty( pythonConsoleGroup, "columns", 1 );
1439 pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, LightApp_Preferences::Font, "PyConsole", "font" );
1441 int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1443 int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1445 int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1447 int plot2dGroup = pref->addPreference( tr( "PREF_GROUP_PLOT2DVIEWER" ), viewTab );
1449 int supervGroup = pref->addPreference( tr( "PREF_GROUP_SUPERV" ), viewTab );
1451 pref->setItemProperty( occGroup, "columns", 1 );
1452 pref->setItemProperty( vtkGroup, "columns", 1 );
1453 pref->setItemProperty( plot2dGroup, "columns", 1 );
1455 int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1456 LightApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1457 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1458 LightApp_Preferences::Color, "OCCViewer", "background" );
1460 pref->setItemProperty( occTS, "min", 1 );
1461 pref->setItemProperty( occTS, "max", 150 );
1463 int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
1464 LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
1465 int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
1466 LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
1468 pref->setItemProperty( isoU, "min", 0 );
1469 pref->setItemProperty( isoU, "max", 100000 );
1471 pref->setItemProperty( isoV, "min", 0 );
1472 pref->setItemProperty( isoV, "max", 100000 );
1474 int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1475 LightApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1476 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1477 LightApp_Preferences::Color, "VTKViewer", "background" );
1479 pref->setItemProperty( vtkTS, "min", 1 );
1480 pref->setItemProperty( vtkTS, "max", 150 );
1482 pref->addPreference( tr( "PREF_SHOW_LEGEND" ), plot2dGroup,
1483 LightApp_Preferences::Bool, "Plot2d", "ShowLegend" );
1485 int legendPosition = pref->addPreference( tr( "PREF_LEGEND_POSITION" ), plot2dGroup,
1486 LightApp_Preferences::Selector, "Plot2d", "LegendPos" );
1487 QStringList aLegendPosList;
1488 aLegendPosList.append( tr("PREF_LEFT") );
1489 aLegendPosList.append( tr("PREF_RIGHT") );
1490 aLegendPosList.append( tr("PREF_TOP") );
1491 aLegendPosList.append( tr("PREF_BOTTOM") );
1493 QValueList<QVariant> anIndexesList;
1494 anIndexesList.append(0);
1495 anIndexesList.append(1);
1496 anIndexesList.append(2);
1497 anIndexesList.append(3);
1499 pref->setItemProperty( legendPosition, "strings", aLegendPosList );
1500 pref->setItemProperty( legendPosition, "indexes", anIndexesList );
1502 int curveType = pref->addPreference( tr( "PREF_CURVE_TYPE" ), plot2dGroup,
1503 LightApp_Preferences::Selector, "Plot2d", "CurveType" );
1504 QStringList aCurveTypesList;
1505 aCurveTypesList.append( tr("PREF_POINTS") );
1506 aCurveTypesList.append( tr("PREF_LINES") );
1507 aCurveTypesList.append( tr("PREF_SPLINE") );
1509 anIndexesList.clear();
1510 anIndexesList.append(0);
1511 anIndexesList.append(1);
1512 anIndexesList.append(2);
1514 pref->setItemProperty( curveType, "strings", aCurveTypesList );
1515 pref->setItemProperty( curveType, "indexes", anIndexesList );
1517 int markerSize = pref->addPreference( tr( "PREF_MARKER_SIZE" ), plot2dGroup,
1518 LightApp_Preferences::IntSpin, "Plot2d", "MarkerSize" );
1520 pref->setItemProperty( markerSize, "min", 0 );
1521 pref->setItemProperty( markerSize, "max", 100 );
1523 QStringList aScaleModesList;
1524 aScaleModesList.append( tr("PREF_LINEAR") );
1525 aScaleModesList.append( tr("PREF_LOGARITHMIC") );
1527 anIndexesList.clear();
1528 anIndexesList.append(0);
1529 anIndexesList.append(1);
1531 int horScale = pref->addPreference( tr( "PREF_HOR_AXIS_SCALE" ), plot2dGroup,
1532 LightApp_Preferences::Selector, "Plot2d", "HorScaleMode" );
1534 pref->setItemProperty( horScale, "strings", aScaleModesList );
1535 pref->setItemProperty( horScale, "indexes", anIndexesList );
1537 int verScale = pref->addPreference( tr( "PREF_VERT_AXIS_SCALE" ), plot2dGroup,
1538 LightApp_Preferences::Selector, "Plot2d", "VerScaleMode" );
1540 pref->setItemProperty( verScale, "strings", aScaleModesList );
1541 pref->setItemProperty( verScale, "indexes", anIndexesList );
1543 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), plot2dGroup,
1544 LightApp_Preferences::Color, "Plot2d", "Background" );
1546 int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat );
1547 int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab );
1548 pref->setItemProperty( dirGroup, "columns", 1 );
1549 pref->addPreference( tr( "" ), dirGroup,
1550 LightApp_Preferences::DirList, "FileDlg", "QuickDirList" );
1552 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), supervGroup,
1553 LightApp_Preferences::Color, "SUPERVGraph", "Background" );
1554 pref->addPreference( tr( "PREF_SUPERV_TITLE_COLOR" ), supervGroup,
1555 LightApp_Preferences::Color, "SUPERVGraph", "Title" );
1556 // pref->addPreference( tr( "PREF_SUPERV_CTRL_COLOR" ), supervGroup,
1557 // LightApp_Preferences::Color, "SUPERVGraph", "Ctrl" );
1560 /*!Changed preferences */
1561 void LightApp_Application::preferencesChanged( const QString& sec, const QString& param )
1563 SUIT_ResourceMgr* resMgr = resourceMgr();
1567 if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1569 int sz = resMgr->integerValue( sec, param, -1 );
1570 QPtrList<SUIT_ViewManager> lst;
1571 viewManagers( OCCViewer_Viewer::Type(), lst );
1572 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1574 SUIT_ViewModel* vm = it.current()->getViewModel();
1575 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1578 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1579 occVM->setTrihedronSize( sz );
1580 occVM->getAISContext()->UpdateCurrentViewer();
1584 if ( sec == QString( "VTKViewer" ) && param == QString( "trihedron_size" ) )
1586 int sz = resMgr->integerValue( sec, param, -1 );
1587 QPtrList<SUIT_ViewManager> lst;
1588 viewManagers( SVTK_Viewer::Type(), lst );
1589 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1591 SUIT_ViewModel* vm = it.current()->getViewModel();
1592 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
1595 SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
1598 vtkVM->setTrihedronSize( sz );
1604 if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
1606 QPtrList<SUIT_ViewManager> lst;
1607 viewManagers( OCCViewer_Viewer::Type(), lst );
1608 int u = resMgr->integerValue( sec, "iso_number_u" );
1609 int v = resMgr->integerValue( sec, "iso_number_v" );
1610 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
1612 OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>( it.current() );
1613 if( mgr && mgr->getOCCViewer() )
1614 mgr->getOCCViewer()->setIsos( u, v );
1618 if( sec=="ObjectBrowser" )
1620 if( param=="auto_size" )
1622 OB_Browser* ob = objectBrowser();
1626 bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
1627 ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1629 updateObjectBrowser( false );
1633 if( sec=="PyConsole" )
1636 if( pythonConsole() )
1637 pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1641 /*!Update desktop title.*/
1642 void LightApp_Application::updateDesktopTitle() {
1643 QString aTitle = applicationName();
1644 QString aVer = applicationVersion();
1645 if ( !aVer.isEmpty() )
1646 aTitle += QString( " " ) + aVer;
1648 desktop()->setCaption( aTitle );
1651 /*!Update windows after close document.*/
1652 void LightApp_Application::afterCloseDoc()
1656 CAM_Application::afterCloseDoc();
1659 /*!Update module action.*/
1660 void LightApp_Application::updateModuleActions()
1663 if ( activeModule() )
1664 modName = activeModule()->moduleName();
1666 if ( myActions.contains( modName ) )
1667 myActions[modName]->setOn( true );
1670 /*!Gets current windows.
1671 *\param winMap - output current windows map.
1673 void LightApp_Application::currentWindows( QMap<int, int>& winMap ) const
1676 if ( !activeStudy() )
1679 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
1680 ((LightApp_Module*)activeModule())->windows( winMap );
1682 defaultWindows( winMap );
1685 /*!Gets current view managers.
1686 *\param lst - output current view managers list.
1688 void LightApp_Application::currentViewManagers( QStringList& lst ) const
1691 if ( !activeStudy() )
1694 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
1695 ((LightApp_Module*)activeModule())->viewManagers( lst );
1697 defaultViewManagers( lst );
1700 /*!Update windows.*/
1701 void LightApp_Application::updateWindows()
1703 QMap<int, int> winMap;
1704 currentWindows( winMap );
1706 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1707 getWindow( it.key() );
1709 loadWindowsGeometry();
1711 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1712 setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1715 /*!Update view managers.*/
1716 void LightApp_Application::updateViewManagers()
1719 currentViewManagers( lst );
1721 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1722 getViewManager( *it, true );
1725 /*!Load windows geometry.*/
1726 void LightApp_Application::loadWindowsGeometry()
1728 QtxDockAction* dockMgr = 0;
1730 QAction* a = action( ViewWindowsId );
1731 if ( a && a->inherits( "QtxDockAction" ) )
1732 dockMgr = (QtxDockAction*)a;
1738 if ( activeModule() )
1739 modName = activeModule()->name("");
1741 QString section = QString( "windows_geometry" );
1742 if ( !modName.isEmpty() )
1743 section += QString( "." ) + modName;
1745 dockMgr->loadGeometry( resourceMgr(), section, false );
1746 dockMgr->restoreGeometry();
1749 /*!Save windows geometry.*/
1750 void LightApp_Application::saveWindowsGeometry()
1752 QtxDockAction* dockMgr = 0;
1754 QAction* a = action( ViewWindowsId );
1755 if ( a && a->inherits( "QtxDockAction" ) )
1756 dockMgr = (QtxDockAction*)a;
1762 if ( activeModule() )
1763 modName = activeModule()->name("");
1765 QString section = QString( "windows_geometry" );
1766 if ( !modName.isEmpty() )
1767 section += QString( "." ) + modName;
1769 dockMgr->storeGeometry();
1770 dockMgr->saveGeometry( resourceMgr(), section, false );
1773 /*!Activate windows.*/
1774 void LightApp_Application::activateWindows()
1776 if ( activeStudy() )
1778 for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1779 itr.data()->activate( activeStudy()->id() );
1783 /*!Adds icon names for modules.*/
1784 void LightApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
1788 SUIT_ResourceMgr* resMgr = resourceMgr();
1792 QStringList modList;
1793 modules( modList, false );
1795 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
1797 QString modName = *it;
1798 QString modIntr = moduleName( modName );
1799 QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
1801 if ( modIcon.isEmpty() )
1804 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
1805 modIcon += QString( ".png" );
1807 iconMap.insert( modName, modIcon );
1811 /*!Insert items in popup, which necessary for current application*/
1812 void LightApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
1814 CAM_Application::contextMenuPopup( type, thePopup, title );
1816 OB_Browser* ob = objectBrowser();
1817 if ( !ob || type != ob->popupClientType() )
1820 thePopup->insertSeparator();
1821 thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
1824 /*!Create empty study.*/
1825 void LightApp_Application::createEmptyStudy()
1827 CAM_Application::createEmptyStudy();
1828 if ( objectBrowser() )
1829 objectBrowser()->updateTree();
1832 /*!Activate module \a mod.*/
1833 bool LightApp_Application::activateModule( CAM_Module* mod )
1835 bool res = CAM_Application::activateModule( mod );
1836 if ( objectBrowser() )
1837 objectBrowser()->updateTree();
1841 /*!return keyborad accelerators manager object */
1842 SUIT_Accel* LightApp_Application::accel() const
1847 /*! remove dead widget container from map */
1848 void LightApp_Application::onWCDestroyed( QObject* ob )
1850 // remove destroyed widget container from windows map
1851 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1853 if ( itr.data() != ob )
1856 int key = itr.key();
1857 myWindows.remove( key );
1862 /*! redefined to remove view manager from memory */
1863 void LightApp_Application::removeViewManager( SUIT_ViewManager* vm )
1865 disconnect( vm, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1866 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
1867 STD_Application::removeViewManager( vm );