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 = getWindow( WT_ObjectBrowser );
976 if ( 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 if ( objectBrowser() != 0 )
1144 objectBrowser()->setRootObject( aRoot );
1146 activateModule( defaultModule() );
1151 /*!Protected SLOT. On study opened.*/
1152 void LightApp_Application::onStudyOpened( SUIT_Study* theStudy )
1154 SUIT_DataObject* aRoot = 0;
1155 if ( theStudy && theStudy->root() )
1157 aRoot = theStudy->root();
1160 if ( objectBrowser() != 0 ) {
1161 objectBrowser()->setRootObject( aRoot );
1164 activateModule( defaultModule() );
1171 /*!Protected SLOT. On study saved.*/
1172 void LightApp_Application::onStudySaved( SUIT_Study* )
1177 /*!Protected SLOT. On study closed.*/
1178 void LightApp_Application::onStudyClosed( SUIT_Study* )
1182 // Bug 10396: clear selection
1183 mySelMgr->clearSelected();
1185 activateModule( "" );
1187 saveWindowsGeometry();
1190 /*!Protected SLOT.On desktop activated.*/
1191 void LightApp_Application::onDesktopActivated()
1193 CAM_Application::onDesktopActivated();
1194 LightApp_Module* aModule = dynamic_cast<LightApp_Module*>(activeModule());
1196 aModule->studyActivated();
1199 /*!Gets file filter.
1200 *\retval QString "(*.bin)"
1202 QString LightApp_Application::getFileFilter() const
1207 /*! Gets file name*/
1208 QString LightApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1209 const QString& caption, QWidget* parent )
1213 QStringList fls = QStringList::split( ";;", filters, false );
1214 return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1217 /*! Gets directory*/
1218 QString LightApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1222 return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1225 /*! Get open file names*/
1226 QStringList LightApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
1227 const QString& caption, QWidget* parent )
1231 QStringList fls = QStringList::split( ";;", filters, false );
1232 return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1235 /*!Private SLOT. Update object browser.*/
1236 void LightApp_Application::onRefresh()
1238 updateObjectBrowser( true );
1241 /*!Private SLOT. On preferences.*/
1242 void LightApp_Application::onPreferences()
1244 QApplication::setOverrideCursor( Qt::waitCursor );
1246 LightApp_PreferencesDlg* prefDlg = new LightApp_PreferencesDlg( preferences( true ), desktop());
1248 QApplication::restoreOverrideCursor();
1258 /*!Protected SLOT. On preferences changed.*/
1259 void LightApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1261 LightApp_Module* sMod = 0;
1262 CAM_Module* mod = module( modName );
1263 if ( mod && mod->inherits( "LightApp_Module" ) )
1264 sMod = (LightApp_Module*)mod;
1267 sMod->preferencesChanged( section, param );
1269 preferencesChanged( section, param );
1272 /*!Private SLOT. On open document with name \a aName.*/
1273 void LightApp_Application::onMRUActivated( QString aName )
1278 /*!Remove all windows from study.*/
1279 void LightApp_Application::beforeCloseDoc( SUIT_Study* s )
1281 CAM_Application::beforeCloseDoc( s );
1283 for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1284 removeWindow( itr.key(), s->id() );
1287 /*!Update actions.*/
1288 void LightApp_Application::updateActions()
1290 updateCommandsStatus();
1293 //=======================================================================
1294 // name : createNewStudy
1295 /*! Purpose : Create new study*/
1296 //=======================================================================
1297 SUIT_Study* LightApp_Application::createNewStudy()
1299 LightApp_Study* aStudy = new LightApp_Study( this );
1301 // Set up processing of major study-related events
1302 connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
1303 connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
1304 connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );
1305 connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
1311 QWidget* LightApp_Application::createWindow( const int flag )
1314 if ( flag == WT_ObjectBrowser )
1316 OB_Browser* ob = new OB_Browser( desktop() );
1317 ob->setAutoUpdate( true );
1318 ob->setAutoOpenLevel( 1 );
1319 ob->setCaption( tr( "OBJECT_BROWSER" ) );
1320 ob->listView()->setColumnWidth( 0, OBJECT_COLUMN_WIDTH );
1321 ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
1322 ob->setFilter( new LightApp_OBFilter( selectionMgr() ) );
1324 ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1326 // Create OBSelector
1327 new LightApp_OBSelector( ob, mySelMgr );
1331 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1333 else if ( flag == WT_PyConsole )
1335 PythonConsole* pyCons = new PythonConsole( desktop() );
1336 pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1338 // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1340 else if ( flag == WT_LogWindow )
1342 LogWindow* logWin = new LogWindow( desktop() );
1343 logWin->setCaption( tr( "LOG_WINDOW" ) );
1345 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1350 /*!Default windows(Object Browser, Python Console).
1351 * Adds to map \a aMap.
1353 void LightApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1355 aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1356 aMap.insert( WT_PyConsole, Qt::DockBottom );
1357 // aMap.insert( WT_LogWindow, Qt::DockBottom );
1360 /*!Default view manager.*/
1361 void LightApp_Application::defaultViewManagers( QStringList& ) const
1366 /*!Gets preferences.
1367 * Create preferences, if \a crt = true.
1369 LightApp_Preferences* LightApp_Application::preferences( const bool crt ) const
1374 LightApp_Application* that = (LightApp_Application*)this;
1376 if ( !_prefs_ && crt )
1378 _prefs_ = new LightApp_Preferences( resourceMgr() );
1379 that->createPreferences( _prefs_ );
1382 that->myPrefs = _prefs_;
1384 QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1385 for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1387 if ( !appIt.current()->inherits( "LightApp_Application" ) )
1390 LightApp_Application* app = (LightApp_Application*)appIt.current();
1392 QStringList modNameList;
1393 app->modules( modNameList, false );
1394 for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1396 int id = _prefs_->addPreference( *it );
1397 _prefs_->setItemProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1401 app->modules( modList );
1402 for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1404 LightApp_Module* mod = 0;
1405 if ( itr.current()->inherits( "LightApp_Module" ) )
1406 mod = (LightApp_Module*)itr.current();
1408 if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1410 int modCat = _prefs_->addPreference( mod->moduleName() );
1411 _prefs_->setItemProperty( modCat, "info", QString::null );
1412 mod->createPreferences();
1417 connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1418 this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1423 /*!Add new module to application.*/
1424 void LightApp_Application::moduleAdded( CAM_Module* mod )
1426 CAM_Application::moduleAdded( mod );
1428 LightApp_Module* lightMod = 0;
1429 if ( mod && mod->inherits( "LightApp_Module" ) )
1430 lightMod = (LightApp_Module*)mod;
1432 if ( myPrefs && lightMod && !myPrefs->hasModule( lightMod->moduleName() ))
1434 int modCat = myPrefs->addPreference( mod->moduleName() );
1435 myPrefs->setItemProperty( modCat, "info", QString::null );
1436 lightMod->createPreferences();
1440 /*!Create preferences.*/
1441 void LightApp_Application::createPreferences( LightApp_Preferences* pref )
1446 int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1448 int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1449 int studyGroup = pref->addPreference( tr( "PREF_GROUP_STUDY" ), genTab );
1450 pref->setItemProperty( studyGroup, "columns", 1 );
1452 pref->addPreference( tr( "PREF_MULTI_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "multi_file" );
1453 pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "ascii_file" );
1454 int undoPref = pref->addPreference( tr( "PREF_UNDO_LEVEL" ), studyGroup, LightApp_Preferences::IntSpin, "Study", "undo_level" );
1455 pref->setItemProperty( undoPref, "min", 1 );
1456 pref->setItemProperty( undoPref, "max", 100 );
1458 int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab );
1459 pref->setItemProperty( extgroup, "columns", 1 );
1460 int apppref = pref->addPreference( tr( "PREF_APP" ), extgroup, LightApp_Preferences::File, "ExternalBrowser", "application" );
1461 pref->setItemProperty( apppref, "existing", true );
1462 pref->setItemProperty( apppref, "flags", QFileInfo::ExeUser );
1464 pref->addPreference( tr( "PREF_PARAM" ), extgroup, LightApp_Preferences::String, "ExternalBrowser", "parameters" );
1466 int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab );
1467 pref->setItemProperty( pythonConsoleGroup, "columns", 1 );
1468 pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, LightApp_Preferences::Font, "PyConsole", "font" );
1470 int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1472 int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1474 int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1476 int plot2dGroup = pref->addPreference( tr( "PREF_GROUP_PLOT2DVIEWER" ), viewTab );
1478 int supervGroup = pref->addPreference( tr( "PREF_GROUP_SUPERV" ), viewTab );
1480 pref->setItemProperty( occGroup, "columns", 1 );
1481 pref->setItemProperty( vtkGroup, "columns", 1 );
1482 pref->setItemProperty( plot2dGroup, "columns", 1 );
1484 int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1485 LightApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1486 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1487 LightApp_Preferences::Color, "OCCViewer", "background" );
1489 pref->setItemProperty( occTS, "min", 1 );
1490 pref->setItemProperty( occTS, "max", 150 );
1492 int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
1493 LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
1494 int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
1495 LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
1497 pref->setItemProperty( isoU, "min", 0 );
1498 pref->setItemProperty( isoU, "max", 100000 );
1500 pref->setItemProperty( isoV, "min", 0 );
1501 pref->setItemProperty( isoV, "max", 100000 );
1503 int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1504 LightApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1505 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1506 LightApp_Preferences::Color, "VTKViewer", "background" );
1508 pref->setItemProperty( vtkTS, "min", 1 );
1509 pref->setItemProperty( vtkTS, "max", 150 );
1511 pref->addPreference( tr( "PREF_SHOW_LEGEND" ), plot2dGroup,
1512 LightApp_Preferences::Bool, "Plot2d", "ShowLegend" );
1514 int legendPosition = pref->addPreference( tr( "PREF_LEGEND_POSITION" ), plot2dGroup,
1515 LightApp_Preferences::Selector, "Plot2d", "LegendPos" );
1516 QStringList aLegendPosList;
1517 aLegendPosList.append( tr("PREF_LEFT") );
1518 aLegendPosList.append( tr("PREF_RIGHT") );
1519 aLegendPosList.append( tr("PREF_TOP") );
1520 aLegendPosList.append( tr("PREF_BOTTOM") );
1522 QValueList<QVariant> anIndexesList;
1523 anIndexesList.append(0);
1524 anIndexesList.append(1);
1525 anIndexesList.append(2);
1526 anIndexesList.append(3);
1528 pref->setItemProperty( legendPosition, "strings", aLegendPosList );
1529 pref->setItemProperty( legendPosition, "indexes", anIndexesList );
1531 int curveType = pref->addPreference( tr( "PREF_CURVE_TYPE" ), plot2dGroup,
1532 LightApp_Preferences::Selector, "Plot2d", "CurveType" );
1533 QStringList aCurveTypesList;
1534 aCurveTypesList.append( tr("PREF_POINTS") );
1535 aCurveTypesList.append( tr("PREF_LINES") );
1536 aCurveTypesList.append( tr("PREF_SPLINE") );
1538 anIndexesList.clear();
1539 anIndexesList.append(0);
1540 anIndexesList.append(1);
1541 anIndexesList.append(2);
1543 pref->setItemProperty( curveType, "strings", aCurveTypesList );
1544 pref->setItemProperty( curveType, "indexes", anIndexesList );
1546 int markerSize = pref->addPreference( tr( "PREF_MARKER_SIZE" ), plot2dGroup,
1547 LightApp_Preferences::IntSpin, "Plot2d", "MarkerSize" );
1549 pref->setItemProperty( markerSize, "min", 0 );
1550 pref->setItemProperty( markerSize, "max", 100 );
1552 QStringList aScaleModesList;
1553 aScaleModesList.append( tr("PREF_LINEAR") );
1554 aScaleModesList.append( tr("PREF_LOGARITHMIC") );
1556 anIndexesList.clear();
1557 anIndexesList.append(0);
1558 anIndexesList.append(1);
1560 int horScale = pref->addPreference( tr( "PREF_HOR_AXIS_SCALE" ), plot2dGroup,
1561 LightApp_Preferences::Selector, "Plot2d", "HorScaleMode" );
1563 pref->setItemProperty( horScale, "strings", aScaleModesList );
1564 pref->setItemProperty( horScale, "indexes", anIndexesList );
1566 int verScale = pref->addPreference( tr( "PREF_VERT_AXIS_SCALE" ), plot2dGroup,
1567 LightApp_Preferences::Selector, "Plot2d", "VerScaleMode" );
1569 pref->setItemProperty( verScale, "strings", aScaleModesList );
1570 pref->setItemProperty( verScale, "indexes", anIndexesList );
1572 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), plot2dGroup,
1573 LightApp_Preferences::Color, "Plot2d", "Background" );
1575 int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat );
1576 int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab );
1577 pref->setItemProperty( dirGroup, "columns", 1 );
1578 pref->addPreference( tr( "" ), dirGroup,
1579 LightApp_Preferences::DirList, "FileDlg", "QuickDirList" );
1581 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), supervGroup,
1582 LightApp_Preferences::Color, "SUPERVGraph", "Background" );
1583 pref->addPreference( tr( "PREF_SUPERV_TITLE_COLOR" ), supervGroup,
1584 LightApp_Preferences::Color, "SUPERVGraph", "Title" );
1585 // pref->addPreference( tr( "PREF_SUPERV_CTRL_COLOR" ), supervGroup,
1586 // LightApp_Preferences::Color, "SUPERVGraph", "Ctrl" );
1589 /*!Changed preferences */
1590 void LightApp_Application::preferencesChanged( const QString& sec, const QString& param )
1592 SUIT_ResourceMgr* resMgr = resourceMgr();
1596 if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1598 int sz = resMgr->integerValue( sec, param, -1 );
1599 QPtrList<SUIT_ViewManager> lst;
1600 viewManagers( OCCViewer_Viewer::Type(), lst );
1601 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1603 SUIT_ViewModel* vm = it.current()->getViewModel();
1604 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1607 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1608 occVM->setTrihedronSize( sz );
1609 occVM->getAISContext()->UpdateCurrentViewer();
1613 if ( sec == QString( "VTKViewer" ) && param == QString( "trihedron_size" ) )
1615 int sz = resMgr->integerValue( sec, param, -1 );
1616 QPtrList<SUIT_ViewManager> lst;
1617 viewManagers( SVTK_Viewer::Type(), lst );
1618 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1620 SUIT_ViewModel* vm = it.current()->getViewModel();
1621 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
1624 SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
1627 vtkVM->setTrihedronSize( sz );
1633 if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
1635 QPtrList<SUIT_ViewManager> lst;
1636 viewManagers( OCCViewer_Viewer::Type(), lst );
1637 int u = resMgr->integerValue( sec, "iso_number_u" );
1638 int v = resMgr->integerValue( sec, "iso_number_v" );
1639 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
1641 OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>( it.current() );
1642 if( mgr && mgr->getOCCViewer() )
1643 mgr->getOCCViewer()->setIsos( u, v );
1647 if( sec=="ObjectBrowser" )
1649 if( param=="auto_size" )
1651 OB_Browser* ob = objectBrowser();
1655 bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
1656 ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1658 updateObjectBrowser( false );
1662 if( sec=="PyConsole" )
1665 if( pythonConsole() )
1666 pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1670 /*!Update desktop title.*/
1671 void LightApp_Application::updateDesktopTitle() {
1672 QString aTitle = applicationName();
1673 QString aVer = applicationVersion();
1674 if ( !aVer.isEmpty() )
1675 aTitle += QString( " " ) + aVer;
1677 desktop()->setCaption( aTitle );
1680 /*!Update windows after close document.*/
1681 void LightApp_Application::afterCloseDoc()
1685 CAM_Application::afterCloseDoc();
1688 /*!Update module action.*/
1689 void LightApp_Application::updateModuleActions()
1692 if ( activeModule() )
1693 modName = activeModule()->moduleName();
1695 if ( myActions.contains( modName ) )
1696 myActions[modName]->setOn( true );
1699 /*!Gets current windows.
1700 *\param winMap - output current windows map.
1702 void LightApp_Application::currentWindows( QMap<int, int>& winMap ) const
1705 if ( !activeStudy() )
1708 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
1709 ((LightApp_Module*)activeModule())->windows( winMap );
1711 defaultWindows( winMap );
1714 /*!Gets current view managers.
1715 *\param lst - output current view managers list.
1717 void LightApp_Application::currentViewManagers( QStringList& lst ) const
1720 if ( !activeStudy() )
1723 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
1724 ((LightApp_Module*)activeModule())->viewManagers( lst );
1726 defaultViewManagers( lst );
1729 /*!Update windows.*/
1730 void LightApp_Application::updateWindows()
1732 QMap<int, int> winMap;
1733 currentWindows( winMap );
1735 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1736 getWindow( it.key() );
1738 loadWindowsGeometry();
1740 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1741 setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1744 /*!Update view managers.*/
1745 void LightApp_Application::updateViewManagers()
1748 currentViewManagers( lst );
1750 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1751 getViewManager( *it, true );
1754 /*!Load windows geometry.*/
1755 void LightApp_Application::loadWindowsGeometry()
1757 QtxDockAction* dockMgr = 0;
1759 QAction* a = action( ViewWindowsId );
1760 if ( a && a->inherits( "QtxDockAction" ) )
1761 dockMgr = (QtxDockAction*)a;
1767 if ( activeModule() )
1768 modName = activeModule()->name("");
1770 QString section = QString( "windows_geometry" );
1771 if ( !modName.isEmpty() )
1772 section += QString( "." ) + modName;
1774 dockMgr->loadGeometry( resourceMgr(), section, false );
1775 dockMgr->restoreGeometry();
1778 /*!Save windows geometry.*/
1779 void LightApp_Application::saveWindowsGeometry()
1781 QtxDockAction* dockMgr = 0;
1783 QAction* a = action( ViewWindowsId );
1784 if ( a && a->inherits( "QtxDockAction" ) )
1785 dockMgr = (QtxDockAction*)a;
1791 if ( activeModule() )
1792 modName = activeModule()->name("");
1794 QString section = QString( "windows_geometry" );
1795 if ( !modName.isEmpty() )
1796 section += QString( "." ) + modName;
1798 dockMgr->storeGeometry();
1799 dockMgr->saveGeometry( resourceMgr(), section, false );
1802 /*!Activate windows.*/
1803 void LightApp_Application::activateWindows()
1805 if ( activeStudy() )
1807 for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1808 itr.data()->activate( activeStudy()->id() );
1812 /*!Adds icon names for modules.*/
1813 void LightApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
1817 SUIT_ResourceMgr* resMgr = resourceMgr();
1821 QStringList modList;
1822 modules( modList, false );
1824 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
1826 QString modName = *it;
1827 QString modIntr = moduleName( modName );
1828 QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
1830 if ( modIcon.isEmpty() )
1833 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
1834 modIcon += QString( ".png" );
1836 iconMap.insert( modName, modIcon );
1840 /*!Insert items in popup, which necessary for current application*/
1841 void LightApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
1843 CAM_Application::contextMenuPopup( type, thePopup, title );
1845 OB_Browser* ob = objectBrowser();
1846 if ( !ob || type != ob->popupClientType() )
1849 thePopup->insertSeparator();
1850 thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
1853 /*!Create empty study.*/
1854 void LightApp_Application::createEmptyStudy()
1856 CAM_Application::createEmptyStudy();
1857 if ( objectBrowser() )
1858 objectBrowser()->updateTree();
1861 /*!Activate module \a mod.*/
1862 bool LightApp_Application::activateModule( CAM_Module* mod )
1864 bool res = CAM_Application::activateModule( mod );
1865 if ( objectBrowser() )
1866 objectBrowser()->updateTree();
1870 /*!return keyborad accelerators manager object */
1871 SUIT_Accel* LightApp_Application::accel() const
1876 /*! remove dead widget container from map */
1877 void LightApp_Application::onWCDestroyed( QObject* ob )
1879 // remove destroyed widget container from windows map
1880 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1882 if ( itr.data() != ob )
1885 int key = itr.key();
1886 myWindows.remove( key );
1891 /*! redefined to remove view manager from memory */
1892 void LightApp_Application::removeViewManager( SUIT_ViewManager* vm )
1894 disconnect( vm, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1895 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
1896 STD_Application::removeViewManager( vm );
1900 /*! rename active window of desktop */
1901 void LightApp_Application::onRenameWindow()
1906 QWidget* w = desktop()->activeWindow();
1911 QString name = QInputDialog::getText( tr( "TOT_RENAME" ), tr( "PRP_RENAME" ), QLineEdit::Normal, w->caption(), &ok, w );
1912 if( ok && !name.isEmpty() )
1913 w->setCaption( name );