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>
64 #include <QtxWorkstack.h>
70 #include <qstringlist.h>
72 #include <qapplication.h>
74 #include <qstatusbar.h>
76 #include <qobjectlist.h>
77 #include <qcombobox.h>
78 #include <qinputdialog.h>
80 #define OBJECT_BROWSER_WIDTH 300
81 #define OBJECT_COLUMN_WIDTH 150
84 #define DEFAULT_BROWSER "start iexplore.exe"
86 #define DEFAULT_BROWSER "mozilla"
89 #define FIRST_HELP_ID 1000000
91 #include "SALOME_InteractiveObject.hxx"
92 #include "SALOME_ListIO.hxx"
94 static const char* imageEmptyIcon[] = {
97 "....................",
98 "....................",
99 "....................",
100 "....................",
101 "....................",
102 "....................",
103 "....................",
104 "....................",
105 "....................",
106 "....................",
107 "....................",
108 "....................",
109 "....................",
110 "....................",
111 "....................",
112 "....................",
113 "....................",
114 "....................",
115 "....................",
116 "...................."};
118 /*!Create new instance of LightApp_Application.*/
119 extern "C" LIGHTAPP_EXPORT SUIT_Application* createApplication()
121 return new LightApp_Application();
124 LightApp_Preferences* LightApp_Application::_prefs_ = 0;
127 Class : LightApp_Application
128 Description : Application containing LightApp module
132 LightApp_Application::LightApp_Application()
133 : CAM_Application( false ),
136 STD_TabDesktop* desk = new STD_TabDesktop();
140 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
141 QPixmap aLogo = aResMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false );
143 desktop()->setIcon( aLogo );
144 desktop()->setDockableMenuBar( true );
145 desktop()->setDockableStatusBar( false );
147 // base logo (salome itself)
148 desktop()->addLogo( "_app_base", aResMgr->loadPixmap( "LightApp", tr( "APP_BASE_LOGO" ), false ) );
149 // extra logo (salome-based application)
150 desktop()->addLogo( "_app_extra", aResMgr->loadPixmap( "LightApp", tr( "APP_EXTRA_LOGO" ), false ) );
154 mySelMgr = new LightApp_SelectionMgr( this );
156 myAccel = new SUIT_Accel( desktop() );
157 myAccel->setActionKey( SUIT_Accel::PanLeft, CTRL+Key_Left, OCCViewer_Viewer::Type() );
158 myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, OCCViewer_Viewer::Type() );
159 myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, OCCViewer_Viewer::Type() );
160 myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, OCCViewer_Viewer::Type() );
161 myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, OCCViewer_Viewer::Type() );
162 myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, OCCViewer_Viewer::Type() );
163 myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, OCCViewer_Viewer::Type() );
164 myAccel->setActionKey( SUIT_Accel::RotateLeft, ALT+Key_Left, OCCViewer_Viewer::Type() );
165 myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right, OCCViewer_Viewer::Type() );
166 myAccel->setActionKey( SUIT_Accel::RotateUp, ALT+Key_Up, OCCViewer_Viewer::Type() );
167 myAccel->setActionKey( SUIT_Accel::RotateDown, ALT+Key_Down, OCCViewer_Viewer::Type() );
168 myAccel->setActionKey( SUIT_Accel::PanLeft, CTRL+Key_Left, VTKViewer_Viewer::Type() );
169 myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, VTKViewer_Viewer::Type() );
170 myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, VTKViewer_Viewer::Type() );
171 myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, VTKViewer_Viewer::Type() );
172 myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, VTKViewer_Viewer::Type() );
173 myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, VTKViewer_Viewer::Type() );
174 myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, VTKViewer_Viewer::Type() );
175 myAccel->setActionKey( SUIT_Accel::RotateLeft, ALT+Key_Left, VTKViewer_Viewer::Type() );
176 myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right, VTKViewer_Viewer::Type() );
177 myAccel->setActionKey( SUIT_Accel::RotateUp, ALT+Key_Up, VTKViewer_Viewer::Type() );
178 myAccel->setActionKey( SUIT_Accel::RotateDown, ALT+Key_Down, VTKViewer_Viewer::Type() );
180 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) );
184 *\li Save window geometry.
185 *\li Save desktop geometry.
186 *\li Save resource maneger.
187 *\li Delete selection manager.
189 LightApp_Application::~LightApp_Application()
191 saveWindowsGeometry();
196 desktop()->saveGeometry( resourceMgr(), "desktop" );
197 resourceMgr()->save();
202 /*!Start application.*/
203 void LightApp_Application::start()
206 desktop()->loadGeometry( resourceMgr(), "desktop" );
208 CAM_Application::start();
210 QAction* a = action( ViewWindowsId );
211 if ( a && a->inherits( "QtxDockAction" ) )
212 ((QtxDockAction*)a)->setAutoPlace( true );
215 updateViewManagers();
218 desktop()->statusBar()->message( "" );
221 /*!Gets application name.*/
222 QString LightApp_Application::applicationName() const
224 return tr( "APP_NAME" );
227 /*!Gets application version.*/
228 QString LightApp_Application::applicationVersion() const
230 static QString _app_version;
232 if ( _app_version.isEmpty() )
234 QString resVersion = tr( "APP_VERSION" );
235 if ( resVersion != "APP_VERSION" )
237 _app_version = resVersion;
241 QString path( ::getenv( "GUI_ROOT_DIR" ) );
242 if ( !path.isEmpty() )
243 path += QDir::separator();
244 path += QString( "bin/salome/VERSION" );
247 if ( vf.open( IO_ReadOnly ) )
250 vf.readLine( line, 1024 );
253 if ( !line.isEmpty() )
255 while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
256 line.remove( line.length() - 1, 1 );
258 int idx = line.findRev( ":" );
260 _app_version = line.mid( idx + 1 ).stripWhiteSpace();
268 /*!Load module by \a name.*/
269 CAM_Module* LightApp_Application::loadModule( const QString& name )
271 CAM_Module* mod = CAM_Application::loadModule( name );
274 connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) );
275 connect( this, SIGNAL( studySaved() ), mod, SLOT( onModelSaved() ) );
276 connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) );
281 /*!Activate module by \a modName*/
282 bool LightApp_Application::activateModule( const QString& modName )
285 CAM_Module* prevMod = activeModule();
288 actName = prevMod->moduleName();
290 if ( actName == modName )
293 putInfo( tr( "ACTIVATING_MODULE" ).arg( modName ) );
295 saveWindowsGeometry();
297 bool status = CAM_Application::activateModule( modName );
299 updateModuleActions();
307 updateViewManagers();
312 bool LightApp_Application::useStudy(const QString& theName)
315 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>(activeStudy());
318 res = aStudy->loadDocument( theName );
319 updateDesktopTitle();
320 updateCommandsStatus();
324 /*!Gets selection manager.*/
325 LightApp_SelectionMgr* LightApp_Application::selectionMgr() const
331 void LightApp_Application::createActions()
333 STD_Application::createActions();
335 SUIT_Desktop* desk = desktop();
336 SUIT_ResourceMgr* resMgr = resourceMgr();
339 createAction( PreferencesId, tr( "TOT_DESK_PREFERENCES" ), QIconSet(),
340 tr( "MEN_DESK_PREFERENCES" ), tr( "PRP_DESK_PREFERENCES" ),
341 CTRL+Key_P, desk, false, this, SLOT( onPreferences() ) );
344 int helpMenu = createMenu( tr( "MEN_DESK_HELP" ), -1, -1, 1000 );
345 int helpModuleMenu = createMenu( tr( "MEN_DESK_MODULE_HELP" ), helpMenu, -1, 0 );
346 createMenu( separator(), helpMenu, -1, 1 );
348 QStringList aModuleList;
349 modules( aModuleList, false );
351 int id = LightApp_Application::UserID + FIRST_HELP_ID;
352 // help for KERNEL and GUI
357 if (dir = getenv("GUI_ROOT_DIR")) {
358 aFileName = "GUI_index_v3.1.0.html";
359 root = Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("doc") + Qtx::addSlash("salome") );
360 if ( QFileInfo( root + aFileName ).exists() ) {
361 a = createAction( id, tr( QString("Kernel & GUI Help") ), QIconSet(),
362 tr( QString("Kernel && GUI Help") ),
363 tr( QString("Kernel & GUI Help") ),
364 0, desk, false, this, SLOT( onHelpContentsModule() ) );
365 a->setName( QString("GUI") );
366 createMenu( a, helpModuleMenu, -1 );
370 // help for other existing modules
371 QStringList::Iterator it;
372 for ( it = aModuleList.begin(); it != aModuleList.end(); ++it )
374 if ( (*it).isEmpty() )
377 QString modName = moduleName( *it );
378 aFileName = modName + "_index_v3.1.0.html";
380 if (dir = getenv( modName + "_ROOT_DIR")) {
381 root = Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("doc") + Qtx::addSlash("salome") );
382 if ( QFileInfo( root + aFileName ).exists() ) {
384 QAction* a = createAction( id, tr( moduleTitle(modName) + QString(" Help") ), QIconSet(),
385 tr( moduleTitle(modName) + QString(" Help") ),
386 tr( moduleTitle(modName) + QString(" Help") ),
387 0, desk, false, this, SLOT( onHelpContentsModule() ) );
388 a->setName( modName );
389 createMenu( a, helpModuleMenu, -1 );
396 QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), desk );
397 connect( mru, SIGNAL( activated( QString ) ), this, SLOT( onMRUActivated( QString ) ) );
398 registerAction( MRUId, mru );
400 // default icon for neutral point ('SALOME' module)
401 QPixmap defIcon = resMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false );
402 if ( defIcon.isNull() )
403 defIcon = QPixmap( imageEmptyIcon );
405 //! default icon for any module
406 QPixmap modIcon = resMgr->loadPixmap( "LightApp", tr( "APP_MODULE_ICO" ), false );
407 if ( modIcon.isNull() )
408 modIcon = QPixmap( imageEmptyIcon );
410 QToolBar* modTBar = new QtxToolBar( true, desk );
411 modTBar->setLabel( tr( "INF_TOOLBAR_MODULES" ) );
413 QActionGroup* modGroup = new QActionGroup( this );
414 modGroup->setExclusive( true );
415 modGroup->setUsesDropDown( true );
417 a = createAction( -1, tr( "APP_NAME" ), defIcon, tr( "APP_NAME" ),
418 tr( "PRP_APP_MODULE" ), 0, desk, true );
420 myActions.insert( QString(), a );
422 QMap<QString, QString> iconMap;
423 moduleIconNames( iconMap );
425 const int iconSize = 20;
427 modGroup->addTo( modTBar );
428 QObjectList *l = modTBar->queryList( "QComboBox" );
429 QObjectListIt oit( *l );
430 while ( QObject* obj = oit.current() ) {
431 QComboBox* cb = (QComboBox*)obj;
432 if ( cb ) cb->setFocusPolicy( QWidget::NoFocus );
437 modTBar->addSeparator();
440 modules( modList, false );
442 for ( it = modList.begin(); it != modList.end(); ++it )
444 if ( (*it).isEmpty() )
448 if ( iconMap.contains( *it ) )
449 iconName = iconMap[*it];
451 QString modName = moduleName( *it );
453 QPixmap icon = resMgr->loadPixmap( modName, iconName, false );
457 icon.convertFromImage( icon.convertToImage().smoothScale( iconSize, iconSize, QImage::ScaleMin ) );
459 QAction* a = createAction( -1, *it, icon, *it, tr( "PRP_MODULE" ).arg( *it ), 0, desk, true );
463 myActions.insert( *it, a );
466 SUIT_Tools::simplifySeparators( modTBar );
469 int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 );
470 int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
471 createMenu( separator(), windowMenu, -1, 1 );
473 QMap<int, int> accelMap;
474 accelMap[NewGLViewId] = ALT+Key_G;
475 accelMap[NewPlot2dId] = ALT+Key_P;
476 accelMap[NewOCCViewId] = ALT+Key_O;
477 accelMap[NewVTKViewId] = ALT+Key_K;
479 for ( id = NewGLViewId; id <= NewVTKViewId; id++ )
481 QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), QIconSet(),
482 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
483 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
484 accelMap.contains( id ) ? accelMap[id] : 0, desk, false, this, SLOT( onNewWindow() ) );
485 createMenu( a, newWinMenu, -1 );
488 createAction( RenameId, tr( "TOT_RENAME" ), QIconSet(), tr( "MEN_RENAME" ), tr( "PRP_RENAME" ),
489 0, desk, false, this, SLOT( onRenameWindow() ) );
490 createMenu( RenameId, windowMenu, -1 );
492 connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) );
494 int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
495 createMenu( PreferencesId, fileMenu, 15, -1 );
496 createMenu( separator(), fileMenu, -1, 15, -1 );
499 createMenu( separator(), fileMenu, -1, 100, -1 );
500 createMenu( MRUId, fileMenu, 100, -1 );
501 createMenu( separator(), fileMenu, -1, 100, -1 );
505 /*!On module activation action.*/
506 void LightApp_Application::onModuleActivation( QAction* a )
511 QString modName = a->menuText();
512 if ( modName == tr( "APP_NAME" ) )
513 modName = QString::null;
515 // Force user to create/open a study before module activation
516 QMap<QString, QString> iconMap;
517 moduleIconNames( iconMap );
518 QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ], false );
520 icon = resourceMgr()->loadPixmap( "LightApp", tr( "APP_MODULE_BIG_ICO" ), false ); // default icon for any module
522 bool cancelled = false;
523 while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
524 LightApp_ModuleDlg aDlg( desktop(), modName, icon );
525 int res = aDlg.exec();
539 putInfo( tr("INF_CANCELLED") );
540 myActions[QString()]->setOn( true );
546 activateModule( modName );
549 /*!Default module activation.*/
550 QString LightApp_Application::defaultModule() const
552 QStringList aModuleNames;
553 modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration
554 //! If there's the one and only module --> activate it automatically
555 //! TODO: Possible improvement - default module can be taken from preferences
556 return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" );
559 /*!On new window slot.*/
560 void LightApp_Application::onNewWindow()
562 const QObject* obj = sender();
563 if ( !obj || !obj->inherits( "QAction" ) )
567 int id = actionId( (QAction*)obj );
571 type = GLViewer_Viewer::Type();
574 type = Plot2d_Viewer::Type();
577 type = OCCViewer_Viewer::Type();
580 type = VTKViewer_Viewer::Type();
584 if ( !type.isEmpty() )
585 createViewManager( type );
588 //=======================================================================
590 /*! Purpose : SLOT. Create new document*/
591 //=======================================================================
592 void LightApp_Application::onNewDoc()
594 SUIT_Study* study = activeStudy();
596 saveWindowsGeometry();
598 CAM_Application::onNewDoc();
600 if ( !study ) // new study will be create in THIS application
603 updateViewManagers();
607 //=======================================================================
609 /*! Purpose : SLOT. Open new document*/
610 //=======================================================================
611 void LightApp_Application::onOpenDoc()
613 SUIT_Study* study = activeStudy();
614 saveWindowsGeometry();
616 CAM_Application::onOpenDoc();
618 if ( !study ) // new study will be create in THIS application
621 updateViewManagers();
625 #include "SUIT_MessageBox.h"
626 /*! Purpose : SLOT. Open new document with \a aName.*/
627 bool LightApp_Application::onOpenDoc( const QString& aName )
629 bool isAlreadyOpen = false;
631 // Look among opened studies
632 if (activeStudy()) { // at least one study is opened
633 SUIT_Session* aSession = SUIT_Session::session();
634 QPtrList<SUIT_Application> aAppList = aSession->applications();
635 QPtrListIterator<SUIT_Application> it (aAppList);
636 SUIT_Application* aApp = 0;
637 // iterate on all applications
638 for (; (aApp = it.current()) && !isAlreadyOpen; ++it) {
639 if (aApp->activeStudy()->studyName() == aName) {
640 isAlreadyOpen = true; // Already opened, ask user what to do
642 // The document ... is already open.
643 // Do you want to reload it?
644 int aAnswer = SUIT_MessageBox::warn2(desktop(), tr("WRN_WARNING"),
645 tr("QUE_DOC_ALREADYOPEN").arg(aName),
646 tr("BUT_YES"), tr("BUT_NO"), 1, 2, 2);
647 if (aAnswer == 1) { // reload
648 if (activeStudy()->studyName() == aName && aAppList.count() > 1) {
649 // Opened in THIS (active) application.
650 STD_Application* app1 = (STD_Application*)aAppList.at(0);
651 STD_Application* app2 = (STD_Application*)aAppList.at(1);
652 if (!app1 || !app2) {
656 if (app1->activeStudy()->studyName() == aName) {
657 // app1 is this application, we need another one
660 // Close document of this application. This application will be destroyed.
661 onCloseDoc(/*ask = */false);
662 // Open the file with another application, as this one will be destroyed.
663 return app1->onOpenDoc(aName);
665 // Opened in another application.
666 STD_Application* app = (STD_Application*)aApp;
668 app->onCloseDoc(/*ask = */false);
670 } else { // do not reload
671 // OK, the study will not be reloaded, but we call
672 // CAM_Application::onOpenDoc( aName ) all the same.
673 // It will activate a desktop of the study <aName>.
679 bool res = CAM_Application::onOpenDoc( aName );
681 QAction* a = action( MRUId );
682 if ( a && a->inherits( "QtxMRUAction" ) )
684 QtxMRUAction* mru = (QtxMRUAction*)a;
686 mru->insert( aName );
688 mru->remove( aName );
693 //=======================================================================
694 // name : onHelpAbout
695 /*! Purpose : SLOT. Display "About" message box*/
696 //=======================================================================
697 void LightApp_Application::onHelpAbout()
699 LightApp_AboutDlg* dlg = new LightApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
704 /*!SLOT. Load document with \a aName.*/
705 bool LightApp_Application::onLoadDoc( const QString& aName )
707 bool res = CAM_Application::onLoadDoc( aName );
709 /*jfa tmp:QAction* a = action( MRUId );
710 if ( a && a->inherits( "QtxMRUAction" ) )
712 QtxMRUAction* mru = (QtxMRUAction*)a;
714 mru->insert( aName );
716 mru->remove( aName );
721 /*!Private SLOT. Selection.*/
722 void LightApp_Application::onSelection()
724 onSelectionChanged();
726 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
727 ((LightApp_Module*)activeModule())->selectionChanged();
731 *\param study - SUIT_Study.
733 void LightApp_Application::setActiveStudy( SUIT_Study* study )
735 CAM_Application::setActiveStudy( study );
740 //=======================================================================
741 // name : updateCommandsStatus
742 /*! Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu*/
743 //=======================================================================
744 void LightApp_Application::updateCommandsStatus()
746 CAM_Application::updateCommandsStatus();
748 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
750 QAction* a = action( id );
752 a->setEnabled( activeStudy() );
756 // Helps to execute command
757 class RunBrowser: public QThread {
760 RunBrowser(QString theApp, QString theParams, QString theHelpFile, QString theContext=NULL):
761 myApp(theApp), myParams(theParams),
763 myHelpFile("file://" + theHelpFile + theContext),
765 myHelpFile("file:" + theHelpFile + theContext),
773 if ( !myApp.isEmpty())
775 aCommand.sprintf("%s %s %s",myApp.latin1(),myParams.latin1(),myHelpFile.latin1());
776 myStatus = system(aCommand);
779 QCustomEvent* ce2000 = new QCustomEvent (2000);
780 postEvent (qApp, ce2000);
784 if( myStatus != 0 || myApp.isEmpty())
787 aCommand.sprintf("%s %s %s", QString(DEFAULT_BROWSER).latin1(),myParams.latin1(), myHelpFile.latin1());
788 myStatus = system(aCommand);
791 QCustomEvent* ce2001 = new QCustomEvent (2001);
792 postEvent (qApp, ce2001);
805 //=======================================================================
806 // name : onHelpContentsModule
807 /*! Purpose : SLOT. Display help contents for choosen module*/
808 //=======================================================================
809 void LightApp_Application::onHelpContentsModule()
811 const QAction* obj = (QAction*) sender();
813 QString aComponentName = obj->name();
814 QString aFileName = aComponentName + "_index_v3.1.0.html";
816 QCString dir = getenv( aComponentName + "_ROOT_DIR");
817 QString homeDir = Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("doc") + Qtx::addSlash("salome") );
819 QString helpFile = QFileInfo( homeDir + aFileName ).absFilePath();
820 SUIT_ResourceMgr* resMgr = resourceMgr();
821 QString anApp = resMgr->stringValue("ExternalBrowser", "application");
822 QString aParams = resMgr->stringValue("ExternalBrowser", "parameters");
824 RunBrowser* rs = new RunBrowser(anApp, aParams, helpFile);
828 /*!Sets enable or disable some actions on selection changed.*/
829 void LightApp_Application::onSelectionChanged()
834 *\param flag - key for window
835 *\param studyId - study id
836 * Flag used how identificator of window in windows list.
838 QWidget* LightApp_Application::window( const int flag, const int studyId ) const
845 if ( !activeStudy() )
848 sId = activeStudy()->id();
851 if ( myWindows.contains( flag ) )
852 wid = myWindows[flag]->widget( sId );
857 /*!Adds window to application.
858 *\param wid - QWidget
859 *\param flag - key wor window
860 *\param studyId - study id
861 * Flag used how identificator of window in windows list.
863 void LightApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
871 if ( !activeStudy() )
874 sId = activeStudy()->id();
877 if ( !myWindows.contains( flag ) )
879 QMap<int, int> winMap;
880 currentWindows( winMap );
882 LightApp_WidgetContainer* newWC = new LightApp_WidgetContainer( flag, desktop() );
883 connect( newWC, SIGNAL( destroyed ( QObject* ) ), this, SLOT( onWCDestroyed( QObject* ) ) );
884 myWindows.insert( flag, newWC );
885 if ( winMap.contains( flag ) )
886 desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
888 myWindows[flag]->setResizeEnabled( true );
889 myWindows[flag]->setCloseMode( QDockWindow::Always );
890 myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
894 if( wid->inherits( "PythonConsole" ) )
895 f = ( ( PythonConsole* )wid )->font();
899 myWindows[flag]->insert( sId, wid );
902 setWindowShown( flag, !myWindows[flag]->isEmpty() );
905 /*!Remove window from application.
906 *\param flag - key wor window
907 *\param studyId - study id
908 * Flag used how identificator of window in windows list.
910 void LightApp_Application::removeWindow( const int flag, const int studyId )
912 if ( !myWindows.contains( flag ) )
918 if ( !activeStudy() )
921 sId = activeStudy()->id();
924 QWidget* wid = myWindows[flag]->widget( sId );
925 myWindows[flag]->remove( sId );
928 setWindowShown( flag, !myWindows[flag]->isEmpty() );
932 *\param flag - key wor window
933 *\param studyId - study id
934 * Flag used how identificator of window in windows list.
936 QWidget* LightApp_Application::getWindow( const int flag, const int studyId )
938 QWidget* wid = window( flag, studyId );
940 addWindow( wid = createWindow( flag ), flag, studyId );
945 /*!Check is window visible?(with identificator \a type)*/
946 bool LightApp_Application::isWindowVisible( const int type ) const
949 if ( myWindows.contains( type ) )
951 SUIT_Desktop* desk = ((LightApp_Application*)this)->desktop();
952 res = desk && desk->appropriate( myWindows[type] );
957 /*!Sets window show or hide.
958 *\param type - window identificator.
959 *\param on - true/false (window show/hide)
961 void LightApp_Application::setWindowShown( const int type, const bool on )
963 if ( !desktop() || !myWindows.contains( type ) )
966 QDockWindow* dw = myWindows[type];
967 desktop()->setAppropriate( dw, on );
968 on ? dw->show() : dw->hide();
971 /*!Gets "ObjectBrowser".*/
972 OB_Browser* LightApp_Application::objectBrowser()
975 QWidget* wid = window( WT_ObjectBrowser );
976 if ( wid && wid->inherits( "OB_Browser" ) )
977 ob = (OB_Browser*)wid;
981 /*!Gets "LogWindow".*/
982 LogWindow* LightApp_Application::logWindow()
985 QWidget* wid = getWindow( WT_LogWindow );
986 if ( wid->inherits( "LogWindow" ) )
987 lw = (LogWindow*)wid;
991 /*!Get "PythonConsole"*/
992 PythonConsole* LightApp_Application::pythonConsole()
994 PythonConsole* console = 0;
995 QWidget* wid = getWindow( WT_PyConsole );
996 if ( wid->inherits( "PythonConsole" ) )
997 console = (PythonConsole*)wid;
1001 /*!Update obect browser*/
1002 void LightApp_Application::updateObjectBrowser( const bool updateModels )
1004 // update existing data models
1007 LightApp_Study* study = dynamic_cast<LightApp_Study*>(activeStudy());
1009 CAM_Study::ModelList dm_list;
1010 study->dataModels( dm_list );
1011 for ( CAM_Study::ModelListIterator it( dm_list ); it.current(); ++it ) {
1012 CAM_DataModel* camDM = it.current();
1013 if ( camDM && camDM->inherits( "LightApp_DataModel" ) )
1014 ((LightApp_DataModel*)camDM)->update();
1018 if ( objectBrowser() )
1020 objectBrowser()->updateGeometry();
1021 objectBrowser()->updateTree();
1025 /*!Gets preferences.*/
1026 LightApp_Preferences* LightApp_Application::preferences() const
1028 return preferences( false );
1031 /*!Gets view manager*/
1032 SUIT_ViewManager* LightApp_Application::getViewManager( const QString& vmType, const bool create )
1034 SUIT_ViewManager* aVM = viewManager( vmType );
1035 SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
1037 if ( anActiveVM && anActiveVM->getType() == vmType )
1040 if ( aVM && create )
1042 if ( !aVM->getActiveView() )
1045 aVM->getActiveView()->setFocus();
1048 aVM = createViewManager( vmType );
1053 /*!Create view manager.*/
1054 SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType )
1056 SUIT_ResourceMgr* resMgr = resourceMgr();
1058 SUIT_ViewManager* viewMgr = 0;
1059 if( vmType == GLViewer_Viewer::Type() )
1061 viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
1062 new LightApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
1064 else if( vmType == Plot2d_Viewer::Type() )
1066 viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
1067 SPlot2d_Viewer* vm = new SPlot2d_Viewer();
1068 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1069 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( viewMgr->getActiveView() );
1072 Plot2d_ViewFrame* frame = wnd->getViewFrame();
1073 frame->setBackgroundColor( resMgr->colorValue( "Plot2d", "Background", frame->backgroundColor() ) );
1076 else if( vmType == SUPERVGraph_Viewer::Type() )
1078 viewMgr = new SUPERVGraph_ViewManager( activeStudy(), desktop() );
1079 SUPERVGraph_Viewer* vm = new SUPERVGraph_Viewer();
1080 SUPERVGraph_ViewFrame* view = dynamic_cast<SUPERVGraph_ViewFrame*>( vm->getViewManager()->getActiveView() );
1082 view->setBackgroundColor( resMgr->colorValue( "SUPERVGraph", "Background", view->backgroundColor() ) );
1084 else if( vmType == OCCViewer_Viewer::Type() )
1086 viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
1087 SOCC_Viewer* vm = new SOCC_Viewer();
1088 vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
1089 vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
1092 u = resMgr->integerValue( "OCCViewer", "iso_number_u", u );
1093 v = resMgr->integerValue( "OCCViewer", "iso_number_v", v );
1094 vm->setIsos( u, v );
1095 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1096 new LightApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
1098 else if ( vmType == SVTK_Viewer::Type() )
1100 viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
1101 SVTK_Viewer* vm = dynamic_cast<SVTK_Viewer*>( viewMgr->getViewModel() );
1104 vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
1105 vm->setTrihedronSize( resMgr->integerValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ) );
1106 new LightApp_VTKSelector( vm, mySelMgr );
1113 addViewManager( viewMgr );
1114 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
1116 if ( viewWin && desktop() )
1117 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
1119 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1120 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
1125 //=======================================================================
1126 // name : onCloseView
1127 /*! Purpose : SLOT. Remove view manager from application*/
1128 //=======================================================================
1129 void LightApp_Application::onCloseView( SUIT_ViewManager* theVM )
1131 removeViewManager( theVM );
1134 /*!Protected SLOT. On study created.*/
1135 void LightApp_Application::onStudyCreated( SUIT_Study* theStudy )
1137 SUIT_DataObject* aRoot = 0;
1138 if ( theStudy && theStudy->root() )
1140 aRoot = theStudy->root();
1141 //aRoot->setName( tr( "DATA_MODELS" ) );
1143 getWindow( WT_ObjectBrowser );
1144 if ( objectBrowser() != 0 )
1145 objectBrowser()->setRootObject( aRoot );
1147 activateModule( defaultModule() );
1152 /*!Protected SLOT. On study opened.*/
1153 void LightApp_Application::onStudyOpened( SUIT_Study* theStudy )
1155 SUIT_DataObject* aRoot = 0;
1156 if ( theStudy && theStudy->root() )
1158 aRoot = theStudy->root();
1161 getWindow( WT_ObjectBrowser );
1162 if ( objectBrowser() != 0 ) {
1163 objectBrowser()->setRootObject( aRoot );
1166 activateModule( defaultModule() );
1173 /*!Protected SLOT. On study saved.*/
1174 void LightApp_Application::onStudySaved( SUIT_Study* )
1179 /*!Protected SLOT. On study closed.*/
1180 void LightApp_Application::onStudyClosed( SUIT_Study* )
1184 // Bug 10396: clear selection
1185 mySelMgr->clearSelected();
1187 activateModule( "" );
1189 saveWindowsGeometry();
1192 /*!Protected SLOT.On desktop activated.*/
1193 void LightApp_Application::onDesktopActivated()
1195 CAM_Application::onDesktopActivated();
1196 LightApp_Module* aModule = dynamic_cast<LightApp_Module*>(activeModule());
1198 aModule->studyActivated();
1201 /*!Gets file filter.
1202 *\retval QString "(*.bin)"
1204 QString LightApp_Application::getFileFilter() const
1209 /*! Gets file name*/
1210 QString LightApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1211 const QString& caption, QWidget* parent )
1215 QStringList fls = QStringList::split( ";;", filters, false );
1216 return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1219 /*! Gets directory*/
1220 QString LightApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1224 return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1227 /*! Get open file names*/
1228 QStringList LightApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
1229 const QString& caption, QWidget* parent )
1233 QStringList fls = QStringList::split( ";;", filters, false );
1234 return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1237 /*!Private SLOT. Update object browser.*/
1238 void LightApp_Application::onRefresh()
1240 updateObjectBrowser( true );
1243 /*!Private SLOT. On preferences.*/
1244 void LightApp_Application::onPreferences()
1246 QApplication::setOverrideCursor( Qt::waitCursor );
1248 LightApp_PreferencesDlg* prefDlg = new LightApp_PreferencesDlg( preferences( true ), desktop());
1250 QApplication::restoreOverrideCursor();
1260 /*!Protected SLOT. On preferences changed.*/
1261 void LightApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1263 LightApp_Module* sMod = 0;
1264 CAM_Module* mod = module( modName );
1265 if ( mod && mod->inherits( "LightApp_Module" ) )
1266 sMod = (LightApp_Module*)mod;
1269 sMod->preferencesChanged( section, param );
1271 preferencesChanged( section, param );
1274 /*!Private SLOT. On open document with name \a aName.*/
1275 void LightApp_Application::onMRUActivated( QString aName )
1280 /*!Remove all windows from study.*/
1281 void LightApp_Application::beforeCloseDoc( SUIT_Study* s )
1283 CAM_Application::beforeCloseDoc( s );
1285 for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1286 removeWindow( itr.key(), s->id() );
1289 /*!Update actions.*/
1290 void LightApp_Application::updateActions()
1292 updateCommandsStatus();
1295 //=======================================================================
1296 // name : createNewStudy
1297 /*! Purpose : Create new study*/
1298 //=======================================================================
1299 SUIT_Study* LightApp_Application::createNewStudy()
1301 LightApp_Study* aStudy = new LightApp_Study( this );
1303 // Set up processing of major study-related events
1304 connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
1305 connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
1306 connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );
1307 connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
1313 QWidget* LightApp_Application::createWindow( const int flag )
1316 if ( flag == WT_ObjectBrowser )
1318 OB_Browser* ob = new OB_Browser( desktop() );
1319 ob->setAutoUpdate( true );
1320 ob->setAutoOpenLevel( 1 );
1321 ob->setCaption( tr( "OBJECT_BROWSER" ) );
1322 ob->listView()->setColumnWidth( 0, OBJECT_COLUMN_WIDTH );
1323 ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
1324 ob->setFilter( new LightApp_OBFilter( selectionMgr() ) );
1326 ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1328 // Create OBSelector
1329 new LightApp_OBSelector( ob, mySelMgr );
1333 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1335 else if ( flag == WT_PyConsole )
1337 PythonConsole* pyCons = new PythonConsole( desktop() );
1338 pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1340 // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1342 else if ( flag == WT_LogWindow )
1344 LogWindow* logWin = new LogWindow( desktop() );
1345 logWin->setCaption( tr( "LOG_WINDOW" ) );
1347 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1352 /*!Default windows(Object Browser, Python Console).
1353 * Adds to map \a aMap.
1355 void LightApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1357 aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1358 aMap.insert( WT_PyConsole, Qt::DockBottom );
1359 // aMap.insert( WT_LogWindow, Qt::DockBottom );
1362 /*!Default view manager.*/
1363 void LightApp_Application::defaultViewManagers( QStringList& ) const
1368 /*!Gets preferences.
1369 * Create preferences, if \a crt = true.
1371 LightApp_Preferences* LightApp_Application::preferences( const bool crt ) const
1376 LightApp_Application* that = (LightApp_Application*)this;
1378 if ( !_prefs_ && crt )
1380 _prefs_ = new LightApp_Preferences( resourceMgr() );
1381 that->createPreferences( _prefs_ );
1384 that->myPrefs = _prefs_;
1386 QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1387 for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1389 if ( !appIt.current()->inherits( "LightApp_Application" ) )
1392 LightApp_Application* app = (LightApp_Application*)appIt.current();
1394 QStringList modNameList;
1395 app->modules( modNameList, false );
1396 for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1398 int id = _prefs_->addPreference( *it );
1399 _prefs_->setItemProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1403 app->modules( modList );
1404 for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1406 LightApp_Module* mod = 0;
1407 if ( itr.current()->inherits( "LightApp_Module" ) )
1408 mod = (LightApp_Module*)itr.current();
1410 if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1412 int modCat = _prefs_->addPreference( mod->moduleName() );
1413 _prefs_->setItemProperty( modCat, "info", QString::null );
1414 mod->createPreferences();
1419 connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1420 this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1425 /*!Add new module to application.*/
1426 void LightApp_Application::moduleAdded( CAM_Module* mod )
1428 CAM_Application::moduleAdded( mod );
1430 LightApp_Module* lightMod = 0;
1431 if ( mod && mod->inherits( "LightApp_Module" ) )
1432 lightMod = (LightApp_Module*)mod;
1434 if ( myPrefs && lightMod && !myPrefs->hasModule( lightMod->moduleName() ))
1436 int modCat = myPrefs->addPreference( mod->moduleName() );
1437 myPrefs->setItemProperty( modCat, "info", QString::null );
1438 lightMod->createPreferences();
1442 /*!Create preferences.*/
1443 void LightApp_Application::createPreferences( LightApp_Preferences* pref )
1448 int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1450 int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1451 int studyGroup = pref->addPreference( tr( "PREF_GROUP_STUDY" ), genTab );
1452 pref->setItemProperty( studyGroup, "columns", 1 );
1454 pref->addPreference( tr( "PREF_MULTI_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "multi_file" );
1455 pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "ascii_file" );
1456 int undoPref = pref->addPreference( tr( "PREF_UNDO_LEVEL" ), studyGroup, LightApp_Preferences::IntSpin, "Study", "undo_level" );
1457 pref->setItemProperty( undoPref, "min", 1 );
1458 pref->setItemProperty( undoPref, "max", 100 );
1460 int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab );
1461 pref->setItemProperty( extgroup, "columns", 1 );
1462 int apppref = pref->addPreference( tr( "PREF_APP" ), extgroup, LightApp_Preferences::File, "ExternalBrowser", "application" );
1463 pref->setItemProperty( apppref, "existing", true );
1464 pref->setItemProperty( apppref, "flags", QFileInfo::ExeUser );
1466 pref->addPreference( tr( "PREF_PARAM" ), extgroup, LightApp_Preferences::String, "ExternalBrowser", "parameters" );
1468 int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab );
1469 pref->setItemProperty( pythonConsoleGroup, "columns", 1 );
1470 pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, LightApp_Preferences::Font, "PyConsole", "font" );
1472 int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1474 int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1476 int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1478 int plot2dGroup = pref->addPreference( tr( "PREF_GROUP_PLOT2DVIEWER" ), viewTab );
1480 int supervGroup = pref->addPreference( tr( "PREF_GROUP_SUPERV" ), viewTab );
1482 pref->setItemProperty( occGroup, "columns", 1 );
1483 pref->setItemProperty( vtkGroup, "columns", 1 );
1484 pref->setItemProperty( plot2dGroup, "columns", 1 );
1486 int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1487 LightApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1488 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1489 LightApp_Preferences::Color, "OCCViewer", "background" );
1491 pref->setItemProperty( occTS, "min", 1 );
1492 pref->setItemProperty( occTS, "max", 150 );
1494 int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
1495 LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
1496 int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
1497 LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
1499 pref->setItemProperty( isoU, "min", 0 );
1500 pref->setItemProperty( isoU, "max", 100000 );
1502 pref->setItemProperty( isoV, "min", 0 );
1503 pref->setItemProperty( isoV, "max", 100000 );
1505 int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1506 LightApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1507 pref->addPreference( tr( "PREF_RELATIVE_SIZE" ), vtkGroup, LightApp_Preferences::Bool, "VTKViewer", "relative_size" );
1508 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1509 LightApp_Preferences::Color, "VTKViewer", "background" );
1511 pref->setItemProperty( vtkTS, "min", 1 );
1512 pref->setItemProperty( vtkTS, "max", 150 );
1514 pref->addPreference( tr( "PREF_SHOW_LEGEND" ), plot2dGroup,
1515 LightApp_Preferences::Bool, "Plot2d", "ShowLegend" );
1517 int legendPosition = pref->addPreference( tr( "PREF_LEGEND_POSITION" ), plot2dGroup,
1518 LightApp_Preferences::Selector, "Plot2d", "LegendPos" );
1519 QStringList aLegendPosList;
1520 aLegendPosList.append( tr("PREF_LEFT") );
1521 aLegendPosList.append( tr("PREF_RIGHT") );
1522 aLegendPosList.append( tr("PREF_TOP") );
1523 aLegendPosList.append( tr("PREF_BOTTOM") );
1525 QValueList<QVariant> anIndexesList;
1526 anIndexesList.append(0);
1527 anIndexesList.append(1);
1528 anIndexesList.append(2);
1529 anIndexesList.append(3);
1531 pref->setItemProperty( legendPosition, "strings", aLegendPosList );
1532 pref->setItemProperty( legendPosition, "indexes", anIndexesList );
1534 int curveType = pref->addPreference( tr( "PREF_CURVE_TYPE" ), plot2dGroup,
1535 LightApp_Preferences::Selector, "Plot2d", "CurveType" );
1536 QStringList aCurveTypesList;
1537 aCurveTypesList.append( tr("PREF_POINTS") );
1538 aCurveTypesList.append( tr("PREF_LINES") );
1539 aCurveTypesList.append( tr("PREF_SPLINE") );
1541 anIndexesList.clear();
1542 anIndexesList.append(0);
1543 anIndexesList.append(1);
1544 anIndexesList.append(2);
1546 pref->setItemProperty( curveType, "strings", aCurveTypesList );
1547 pref->setItemProperty( curveType, "indexes", anIndexesList );
1549 int markerSize = pref->addPreference( tr( "PREF_MARKER_SIZE" ), plot2dGroup,
1550 LightApp_Preferences::IntSpin, "Plot2d", "MarkerSize" );
1552 pref->setItemProperty( markerSize, "min", 0 );
1553 pref->setItemProperty( markerSize, "max", 100 );
1555 QStringList aScaleModesList;
1556 aScaleModesList.append( tr("PREF_LINEAR") );
1557 aScaleModesList.append( tr("PREF_LOGARITHMIC") );
1559 anIndexesList.clear();
1560 anIndexesList.append(0);
1561 anIndexesList.append(1);
1563 int horScale = pref->addPreference( tr( "PREF_HOR_AXIS_SCALE" ), plot2dGroup,
1564 LightApp_Preferences::Selector, "Plot2d", "HorScaleMode" );
1566 pref->setItemProperty( horScale, "strings", aScaleModesList );
1567 pref->setItemProperty( horScale, "indexes", anIndexesList );
1569 int verScale = pref->addPreference( tr( "PREF_VERT_AXIS_SCALE" ), plot2dGroup,
1570 LightApp_Preferences::Selector, "Plot2d", "VerScaleMode" );
1572 pref->setItemProperty( verScale, "strings", aScaleModesList );
1573 pref->setItemProperty( verScale, "indexes", anIndexesList );
1575 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), plot2dGroup,
1576 LightApp_Preferences::Color, "Plot2d", "Background" );
1578 int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat );
1579 int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab );
1580 pref->setItemProperty( dirGroup, "columns", 1 );
1581 pref->addPreference( tr( "" ), dirGroup,
1582 LightApp_Preferences::DirList, "FileDlg", "QuickDirList" );
1584 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), supervGroup,
1585 LightApp_Preferences::Color, "SUPERVGraph", "Background" );
1586 pref->addPreference( tr( "PREF_SUPERV_TITLE_COLOR" ), supervGroup,
1587 LightApp_Preferences::Color, "SUPERVGraph", "Title" );
1588 // pref->addPreference( tr( "PREF_SUPERV_CTRL_COLOR" ), supervGroup,
1589 // LightApp_Preferences::Color, "SUPERVGraph", "Ctrl" );
1592 /*!Changed preferences */
1593 void LightApp_Application::preferencesChanged( const QString& sec, const QString& param )
1595 SUIT_ResourceMgr* resMgr = resourceMgr();
1599 if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1601 int sz = resMgr->integerValue( sec, param, -1 );
1602 QPtrList<SUIT_ViewManager> lst;
1603 viewManagers( OCCViewer_Viewer::Type(), lst );
1604 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1606 SUIT_ViewModel* vm = it.current()->getViewModel();
1607 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1610 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1611 occVM->setTrihedronSize( sz );
1612 occVM->getAISContext()->UpdateCurrentViewer();
1616 if ( sec == QString( "VTKViewer" ) && (param == QString( "trihedron_size" ) || param == QString( "relative_size" )) )
1618 int sz = resMgr->integerValue( "VTKViewer", "trihedron_size", -1 );
1619 QPtrList<SUIT_ViewManager> lst;
1620 viewManagers( SVTK_Viewer::Type(), lst );
1621 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1623 SUIT_ViewModel* vm = it.current()->getViewModel();
1624 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
1627 SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
1630 vtkVM->setTrihedronSize( sz );
1636 if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
1638 QPtrList<SUIT_ViewManager> lst;
1639 viewManagers( OCCViewer_Viewer::Type(), lst );
1640 int u = resMgr->integerValue( sec, "iso_number_u" );
1641 int v = resMgr->integerValue( sec, "iso_number_v" );
1642 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
1644 OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>( it.current() );
1645 if( mgr && mgr->getOCCViewer() )
1646 mgr->getOCCViewer()->setIsos( u, v );
1650 if( sec=="ObjectBrowser" )
1652 if( param=="auto_size" )
1654 OB_Browser* ob = objectBrowser();
1658 bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
1659 ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1661 updateObjectBrowser( false );
1665 if( sec=="PyConsole" )
1668 if( pythonConsole() )
1669 pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1673 /*!Update desktop title.*/
1674 void LightApp_Application::updateDesktopTitle() {
1675 QString aTitle = applicationName();
1676 QString aVer = applicationVersion();
1677 if ( !aVer.isEmpty() )
1678 aTitle += QString( " " ) + aVer;
1680 desktop()->setCaption( aTitle );
1683 /*!Update windows after close document.*/
1684 void LightApp_Application::afterCloseDoc()
1688 CAM_Application::afterCloseDoc();
1691 /*!Update module action.*/
1692 void LightApp_Application::updateModuleActions()
1695 if ( activeModule() )
1696 modName = activeModule()->moduleName();
1698 if ( myActions.contains( modName ) )
1699 myActions[modName]->setOn( true );
1702 /*!Gets current windows.
1703 *\param winMap - output current windows map.
1705 void LightApp_Application::currentWindows( QMap<int, int>& winMap ) const
1708 if ( !activeStudy() )
1711 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
1712 ((LightApp_Module*)activeModule())->windows( winMap );
1714 defaultWindows( winMap );
1717 /*!Gets current view managers.
1718 *\param lst - output current view managers list.
1720 void LightApp_Application::currentViewManagers( QStringList& lst ) const
1723 if ( !activeStudy() )
1726 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
1727 ((LightApp_Module*)activeModule())->viewManagers( lst );
1729 defaultViewManagers( lst );
1732 /*!Update windows.*/
1733 void LightApp_Application::updateWindows()
1735 QMap<int, int> winMap;
1736 currentWindows( winMap );
1738 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1739 getWindow( it.key() );
1741 loadWindowsGeometry();
1743 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1744 setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1747 /*!Update view managers.*/
1748 void LightApp_Application::updateViewManagers()
1751 currentViewManagers( lst );
1753 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1754 getViewManager( *it, true );
1757 /*!Load windows geometry.*/
1758 void LightApp_Application::loadWindowsGeometry()
1760 QtxDockAction* dockMgr = 0;
1762 QAction* a = action( ViewWindowsId );
1763 if ( a && a->inherits( "QtxDockAction" ) )
1764 dockMgr = (QtxDockAction*)a;
1770 if ( activeModule() )
1771 modName = activeModule()->name("");
1773 QString section = QString( "windows_geometry" );
1774 if ( !modName.isEmpty() )
1775 section += QString( "." ) + modName;
1777 dockMgr->loadGeometry( resourceMgr(), section, false );
1778 dockMgr->restoreGeometry();
1781 /*!Save windows geometry.*/
1782 void LightApp_Application::saveWindowsGeometry()
1784 QtxDockAction* dockMgr = 0;
1786 QAction* a = action( ViewWindowsId );
1787 if ( a && a->inherits( "QtxDockAction" ) )
1788 dockMgr = (QtxDockAction*)a;
1794 if ( activeModule() )
1795 modName = activeModule()->name("");
1797 QString section = QString( "windows_geometry" );
1798 if ( !modName.isEmpty() )
1799 section += QString( "." ) + modName;
1801 dockMgr->storeGeometry();
1802 dockMgr->saveGeometry( resourceMgr(), section, false );
1805 /*!Activate windows.*/
1806 void LightApp_Application::activateWindows()
1808 if ( activeStudy() )
1810 for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1811 itr.data()->activate( activeStudy()->id() );
1815 /*!Adds icon names for modules.*/
1816 void LightApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
1820 SUIT_ResourceMgr* resMgr = resourceMgr();
1824 QStringList modList;
1825 modules( modList, false );
1827 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
1829 QString modName = *it;
1830 QString modIntr = moduleName( modName );
1831 QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
1833 if ( modIcon.isEmpty() )
1836 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
1837 modIcon += QString( ".png" );
1839 iconMap.insert( modName, modIcon );
1843 /*!Insert items in popup, which necessary for current application*/
1844 void LightApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
1846 CAM_Application::contextMenuPopup( type, thePopup, title );
1848 OB_Browser* ob = objectBrowser();
1849 if ( !ob || type != ob->popupClientType() )
1852 thePopup->insertSeparator();
1853 thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
1856 /*!Create empty study.*/
1857 void LightApp_Application::createEmptyStudy()
1859 CAM_Application::createEmptyStudy();
1860 if ( objectBrowser() )
1861 objectBrowser()->updateTree();
1864 /*!Activate module \a mod.*/
1865 bool LightApp_Application::activateModule( CAM_Module* mod )
1867 bool res = CAM_Application::activateModule( mod );
1868 if ( objectBrowser() )
1869 objectBrowser()->updateTree();
1873 /*!return keyborad accelerators manager object */
1874 SUIT_Accel* LightApp_Application::accel() const
1879 /*! remove dead widget container from map */
1880 void LightApp_Application::onWCDestroyed( QObject* ob )
1882 // remove destroyed widget container from windows map
1883 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1885 if ( itr.data() != ob )
1888 int key = itr.key();
1889 myWindows.remove( key );
1894 /*! redefined to remove view manager from memory */
1895 void LightApp_Application::removeViewManager( SUIT_ViewManager* vm )
1897 disconnect( vm, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1898 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
1899 STD_Application::removeViewManager( vm );
1903 /*! rename active window of desktop */
1904 void LightApp_Application::onRenameWindow()
1909 QWidget* w = desktop()->activeWindow();
1914 QString name = QInputDialog::getText( tr( "TOT_RENAME" ), tr( "PRP_RENAME" ), QLineEdit::Normal, w->caption(), &ok, w );
1915 if( ok && !name.isEmpty() )
1916 w->setCaption( name );