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 <qinputdialog.h>
78 #define OBJECT_BROWSER_WIDTH 300
79 #define OBJECT_COLUMN_WIDTH 150
81 #define DEFAULT_BROWSER "mozilla"
83 #define FIRST_HELP_ID 1000000
85 #include "SALOME_InteractiveObject.hxx"
86 #include "SALOME_ListIO.hxx"
88 static const char* imageEmptyIcon[] = {
91 "....................",
92 "....................",
93 "....................",
94 "....................",
95 "....................",
96 "....................",
97 "....................",
98 "....................",
99 "....................",
100 "....................",
101 "....................",
102 "....................",
103 "....................",
104 "....................",
105 "....................",
106 "....................",
107 "....................",
108 "....................",
109 "....................",
110 "...................."};
112 /*!Create new instance of LightApp_Application.*/
113 extern "C" LIGHTAPP_EXPORT SUIT_Application* createApplication()
115 return new LightApp_Application();
118 LightApp_Preferences* LightApp_Application::_prefs_ = 0;
121 Class : LightApp_Application
122 Description : Application containing LightApp module
126 LightApp_Application::LightApp_Application()
127 : CAM_Application( false ),
130 STD_TabDesktop* desk = new STD_TabDesktop();
134 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
135 QPixmap aLogo = aResMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false );
137 desktop()->setIcon( aLogo );
138 desktop()->setDockableMenuBar( true );
139 desktop()->setDockableStatusBar( false );
141 // base logo (salome itself)
142 desktop()->addLogo( "_app_base", aResMgr->loadPixmap( "LightApp", tr( "APP_BASE_LOGO" ), false ) );
143 // extra logo (salome-based application)
144 desktop()->addLogo( "_app_extra", aResMgr->loadPixmap( "LightApp", tr( "APP_EXTRA_LOGO" ), false ) );
148 mySelMgr = new LightApp_SelectionMgr( this );
150 myAccel = new SUIT_Accel( desktop() );
151 myAccel->setActionKey( SUIT_Accel::PanLeft, CTRL+Key_Left, OCCViewer_Viewer::Type() );
152 myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, OCCViewer_Viewer::Type() );
153 myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, OCCViewer_Viewer::Type() );
154 myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, OCCViewer_Viewer::Type() );
155 myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, OCCViewer_Viewer::Type() );
156 myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, OCCViewer_Viewer::Type() );
157 myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, OCCViewer_Viewer::Type() );
158 myAccel->setActionKey( SUIT_Accel::RotateLeft, ALT+Key_Left, OCCViewer_Viewer::Type() );
159 myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right, OCCViewer_Viewer::Type() );
160 myAccel->setActionKey( SUIT_Accel::RotateUp, ALT+Key_Up, OCCViewer_Viewer::Type() );
161 myAccel->setActionKey( SUIT_Accel::RotateDown, ALT+Key_Down, OCCViewer_Viewer::Type() );
162 myAccel->setActionKey( SUIT_Accel::PanLeft, CTRL+Key_Left, VTKViewer_Viewer::Type() );
163 myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, VTKViewer_Viewer::Type() );
164 myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, VTKViewer_Viewer::Type() );
165 myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, VTKViewer_Viewer::Type() );
166 myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, VTKViewer_Viewer::Type() );
167 myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, VTKViewer_Viewer::Type() );
168 myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, VTKViewer_Viewer::Type() );
169 myAccel->setActionKey( SUIT_Accel::RotateLeft, ALT+Key_Left, VTKViewer_Viewer::Type() );
170 myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right, VTKViewer_Viewer::Type() );
171 myAccel->setActionKey( SUIT_Accel::RotateUp, ALT+Key_Up, VTKViewer_Viewer::Type() );
172 myAccel->setActionKey( SUIT_Accel::RotateDown, ALT+Key_Down, VTKViewer_Viewer::Type() );
174 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) );
178 *\li Save window geometry.
179 *\li Save desktop geometry.
180 *\li Save resource maneger.
181 *\li Delete selection manager.
183 LightApp_Application::~LightApp_Application()
185 saveWindowsGeometry();
190 desktop()->saveGeometry( resourceMgr(), "desktop" );
191 resourceMgr()->save();
196 /*!Start application.*/
197 void LightApp_Application::start()
200 desktop()->loadGeometry( resourceMgr(), "desktop" );
202 CAM_Application::start();
204 QAction* a = action( ViewWindowsId );
205 if ( a && a->inherits( "QtxDockAction" ) )
206 ((QtxDockAction*)a)->setAutoPlace( true );
209 updateViewManagers();
212 desktop()->statusBar()->message( "" );
215 /*!Gets application name.*/
216 QString LightApp_Application::applicationName() const
218 return tr( "APP_NAME" );
221 /*!Gets application version.*/
222 QString LightApp_Application::applicationVersion() const
224 static QString _app_version;
226 if ( _app_version.isEmpty() )
228 QString resVersion = tr( "APP_VERSION" );
229 if ( resVersion != "APP_VERSION" )
231 _app_version = resVersion;
235 QString path( ::getenv( "GUI_ROOT_DIR" ) );
236 if ( !path.isEmpty() )
237 path += QDir::separator();
238 path += QString( "bin/salome/VERSION" );
241 if ( vf.open( IO_ReadOnly ) )
244 vf.readLine( line, 1024 );
247 if ( !line.isEmpty() )
249 while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
250 line.remove( line.length() - 1, 1 );
252 int idx = line.findRev( ":" );
254 _app_version = line.mid( idx + 1 ).stripWhiteSpace();
262 /*!Load module by \a name.*/
263 CAM_Module* LightApp_Application::loadModule( const QString& name )
265 CAM_Module* mod = CAM_Application::loadModule( name );
268 connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) );
269 connect( this, SIGNAL( studySaved() ), mod, SLOT( onModelSaved() ) );
270 connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) );
275 /*!Activate module by \a modName*/
276 bool LightApp_Application::activateModule( const QString& modName )
279 CAM_Module* prevMod = activeModule();
282 actName = prevMod->moduleName();
284 if ( actName == modName )
287 putInfo( tr( "ACTIVATING_MODULE" ).arg( modName ) );
289 saveWindowsGeometry();
291 bool status = CAM_Application::activateModule( modName );
293 updateModuleActions();
301 updateViewManagers();
306 bool LightApp_Application::useStudy(const QString& theName)
309 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>(activeStudy());
312 res = aStudy->loadDocument( theName );
313 updateDesktopTitle();
314 updateCommandsStatus();
318 /*!Gets selection manager.*/
319 LightApp_SelectionMgr* LightApp_Application::selectionMgr() const
325 void LightApp_Application::createActions()
327 STD_Application::createActions();
329 SUIT_Desktop* desk = desktop();
330 SUIT_ResourceMgr* resMgr = resourceMgr();
333 createAction( PreferencesId, tr( "TOT_DESK_PREFERENCES" ), QIconSet(),
334 tr( "MEN_DESK_PREFERENCES" ), tr( "PRP_DESK_PREFERENCES" ),
335 CTRL+Key_P, desk, false, this, SLOT( onPreferences() ) );
338 int helpMenu = createMenu( tr( "MEN_DESK_HELP" ), -1, -1, 1000 );
339 int helpModuleMenu = createMenu( tr( "MEN_DESK_MODULE_HELP" ), helpMenu, -1, 0 );
340 createMenu( separator(), helpMenu, -1, 1 );
342 QStringList aModuleList;
343 modules( aModuleList, false );
345 int id = LightApp_Application::UserID + FIRST_HELP_ID;
346 // help for KERNEL and GUI
349 if (dir = getenv("GUI_ROOT_DIR")) {
350 a = createAction( id, tr( QString("Kernel & GUI Help") ), QIconSet(),
351 tr( QString("Kernel && GUI Help") ),
352 tr( QString("Kernel & GUI Help") ),
353 0, desk, false, this, SLOT( onHelpContentsModule() ) );
354 a->setName( QString("GUI") );
355 createMenu( a, helpModuleMenu, -1 );
358 // help for other existing modules
359 QStringList::Iterator it;
360 for ( it = aModuleList.begin(); it != aModuleList.end(); ++it )
362 if ( (*it).isEmpty() )
365 QString modName = moduleName( *it );
366 if ( modName.compare("GEOM") == 0 || modName.compare("SMESH") == 0 ) { // to be removed when documentation for other modules will be done
367 QAction* a = createAction( id, tr( moduleTitle(modName) + QString(" Help") ), QIconSet(),
368 tr( moduleTitle(modName) + QString(" Help") ),
369 tr( moduleTitle(modName) + QString(" Help") ),
370 0, desk, false, this, SLOT( onHelpContentsModule() ) );
371 a->setName( modName );
372 createMenu( a, helpModuleMenu, -1 );
378 QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), desk );
379 connect( mru, SIGNAL( activated( QString ) ), this, SLOT( onMRUActivated( QString ) ) );
380 registerAction( MRUId, mru );
382 // default icon for neutral point ('SALOME' module)
383 QPixmap defIcon = resMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false );
384 if ( defIcon.isNull() )
385 defIcon = QPixmap( imageEmptyIcon );
387 //! default icon for any module
388 QPixmap modIcon = resMgr->loadPixmap( "LightApp", tr( "APP_MODULE_ICO" ), false );
389 if ( modIcon.isNull() )
390 modIcon = QPixmap( imageEmptyIcon );
392 QToolBar* modTBar = new QtxToolBar( true, desk );
393 modTBar->setLabel( tr( "INF_TOOLBAR_MODULES" ) );
395 QActionGroup* modGroup = new QActionGroup( this );
396 modGroup->setExclusive( true );
397 modGroup->setUsesDropDown( true );
399 a = createAction( -1, tr( "APP_NAME" ), defIcon, tr( "APP_NAME" ),
400 tr( "PRP_APP_MODULE" ), 0, desk, true );
402 myActions.insert( QString(), a );
404 QMap<QString, QString> iconMap;
405 moduleIconNames( iconMap );
407 const int iconSize = 20;
409 modGroup->addTo( modTBar );
410 modTBar->addSeparator();
413 modules( modList, false );
415 for ( it = modList.begin(); it != modList.end(); ++it )
417 if ( (*it).isEmpty() )
421 if ( iconMap.contains( *it ) )
422 iconName = iconMap[*it];
424 QString modName = moduleName( *it );
426 QPixmap icon = resMgr->loadPixmap( modName, iconName, false );
430 icon.convertFromImage( icon.convertToImage().smoothScale( iconSize, iconSize, QImage::ScaleMin ) );
432 QAction* a = createAction( -1, *it, icon, *it, tr( "PRP_MODULE" ).arg( *it ), 0, desk, true );
436 myActions.insert( *it, a );
439 SUIT_Tools::simplifySeparators( modTBar );
442 int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 );
443 int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
444 createMenu( separator(), windowMenu, -1, 1 );
446 QMap<int, int> accelMap;
447 accelMap[NewGLViewId] = ALT+Key_G;
448 accelMap[NewPlot2dId] = ALT+Key_P;
449 accelMap[NewOCCViewId] = ALT+Key_O;
450 accelMap[NewVTKViewId] = ALT+Key_K;
452 for ( id = NewGLViewId; id <= NewVTKViewId; id++ )
454 QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), QIconSet(),
455 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
456 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
457 accelMap.contains( id ) ? accelMap[id] : 0, desk, false, this, SLOT( onNewWindow() ) );
458 createMenu( a, newWinMenu, -1 );
461 createAction( RenameId, tr( "TOT_RENAME" ), QIconSet(), tr( "MEN_RENAME" ), tr( "PRP_RENAME" ),
462 0, desk, false, this, SLOT( onRenameWindow() ) );
463 createMenu( RenameId, windowMenu, -1 );
465 connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) );
467 int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
468 createMenu( PreferencesId, fileMenu, 15, -1 );
469 createMenu( separator(), fileMenu, -1, 15, -1 );
472 createMenu( separator(), fileMenu, -1, 100, -1 );
473 createMenu( MRUId, fileMenu, 100, -1 );
474 createMenu( separator(), fileMenu, -1, 100, -1 );
478 /*!On module activation action.*/
479 void LightApp_Application::onModuleActivation( QAction* a )
484 QString modName = a->menuText();
485 if ( modName == tr( "APP_NAME" ) )
486 modName = QString::null;
488 // Force user to create/open a study before module activation
489 QMap<QString, QString> iconMap;
490 moduleIconNames( iconMap );
491 QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ], false );
493 icon = resourceMgr()->loadPixmap( "LightApp", tr( "APP_MODULE_BIG_ICO" ), false ); // default icon for any module
495 bool cancelled = false;
496 while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
497 LightApp_ModuleDlg aDlg( desktop(), modName, icon );
498 int res = aDlg.exec();
512 putInfo( tr("INF_CANCELLED") );
513 myActions[QString()]->setOn( true );
519 activateModule( modName );
522 /*!Default module activation.*/
523 QString LightApp_Application::defaultModule() const
525 QStringList aModuleNames;
526 modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration
527 //! If there's the one and only module --> activate it automatically
528 //! TODO: Possible improvement - default module can be taken from preferences
529 return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" );
532 /*!On new window slot.*/
533 void LightApp_Application::onNewWindow()
535 const QObject* obj = sender();
536 if ( !obj || !obj->inherits( "QAction" ) )
540 int id = actionId( (QAction*)obj );
544 type = GLViewer_Viewer::Type();
547 type = Plot2d_Viewer::Type();
550 type = OCCViewer_Viewer::Type();
553 type = VTKViewer_Viewer::Type();
557 if ( !type.isEmpty() )
558 createViewManager( type );
561 //=======================================================================
563 /*! Purpose : SLOT. Create new document*/
564 //=======================================================================
565 void LightApp_Application::onNewDoc()
567 SUIT_Study* study = activeStudy();
569 saveWindowsGeometry();
571 CAM_Application::onNewDoc();
573 if ( !study ) // new study will be create in THIS application
576 updateViewManagers();
580 //=======================================================================
582 /*! Purpose : SLOT. Open new document*/
583 //=======================================================================
584 void LightApp_Application::onOpenDoc()
586 SUIT_Study* study = activeStudy();
587 saveWindowsGeometry();
589 CAM_Application::onOpenDoc();
591 if ( !study ) // new study will be create in THIS application
594 updateViewManagers();
598 #include "SUIT_MessageBox.h"
599 /*! Purpose : SLOT. Open new document with \a aName.*/
600 bool LightApp_Application::onOpenDoc( const QString& aName )
602 bool isAlreadyOpen = false;
604 // Look among opened studies
605 if (activeStudy()) { // at least one study is opened
606 SUIT_Session* aSession = SUIT_Session::session();
607 QPtrList<SUIT_Application> aAppList = aSession->applications();
608 QPtrListIterator<SUIT_Application> it (aAppList);
609 SUIT_Application* aApp = 0;
610 // iterate on all applications
611 for (; (aApp = it.current()) && !isAlreadyOpen; ++it) {
612 if (aApp->activeStudy()->studyName() == aName) {
613 isAlreadyOpen = true; // Already opened, ask user what to do
615 // The document ... is already open.
616 // Do you want to reload it?
617 int aAnswer = SUIT_MessageBox::warn2(desktop(), tr("WRN_WARNING"),
618 tr("QUE_DOC_ALREADYOPEN").arg(aName),
619 tr("BUT_YES"), tr("BUT_NO"), 1, 2, 2);
620 if (aAnswer == 1) { // reload
621 if (activeStudy()->studyName() == aName && aAppList.count() > 1) {
622 // Opened in THIS (active) application.
623 STD_Application* app1 = (STD_Application*)aAppList.at(0);
624 STD_Application* app2 = (STD_Application*)aAppList.at(1);
625 if (!app1 || !app2) {
629 if (app1->activeStudy()->studyName() == aName) {
630 // app1 is this application, we need another one
633 // Close document of this application. This application will be destroyed.
634 onCloseDoc(/*ask = */false);
635 // Open the file with another application, as this one will be destroyed.
636 return app1->onOpenDoc(aName);
638 // Opened in another application.
639 STD_Application* app = (STD_Application*)aApp;
641 app->onCloseDoc(/*ask = */false);
643 } else { // do not reload
644 // OK, the study will not be reloaded, but we call
645 // CAM_Application::onOpenDoc( aName ) all the same.
646 // It will activate a desktop of the study <aName>.
652 bool res = CAM_Application::onOpenDoc( aName );
654 QAction* a = action( MRUId );
655 if ( a && a->inherits( "QtxMRUAction" ) )
657 QtxMRUAction* mru = (QtxMRUAction*)a;
659 mru->insert( aName );
661 mru->remove( aName );
666 //=======================================================================
667 // name : onHelpAbout
668 /*! Purpose : SLOT. Display "About" message box*/
669 //=======================================================================
670 void LightApp_Application::onHelpAbout()
672 LightApp_AboutDlg* dlg = new LightApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
677 /*!SLOT. Load document with \a aName.*/
678 bool LightApp_Application::onLoadDoc( const QString& aName )
680 bool res = CAM_Application::onLoadDoc( aName );
682 /*jfa tmp:QAction* a = action( MRUId );
683 if ( a && a->inherits( "QtxMRUAction" ) )
685 QtxMRUAction* mru = (QtxMRUAction*)a;
687 mru->insert( aName );
689 mru->remove( aName );
694 /*!Private SLOT. Selection.*/
695 void LightApp_Application::onSelection()
697 onSelectionChanged();
699 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
700 ((LightApp_Module*)activeModule())->selectionChanged();
704 *\param study - SUIT_Study.
706 void LightApp_Application::setActiveStudy( SUIT_Study* study )
708 CAM_Application::setActiveStudy( study );
713 //=======================================================================
714 // name : updateCommandsStatus
715 /*! Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu*/
716 //=======================================================================
717 void LightApp_Application::updateCommandsStatus()
719 CAM_Application::updateCommandsStatus();
721 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
723 QAction* a = action( id );
725 a->setEnabled( activeStudy() );
729 // Helps to execute command
730 class RunBrowser: public QThread {
733 RunBrowser(QString theApp, QString theParams, QString theHelpFile, QString theContext=NULL):
734 myApp(theApp), myParams(theParams), myHelpFile("file:" + theHelpFile + theContext), myStatus(0) {};
740 if ( !myApp.isEmpty())
742 aCommand.sprintf("%s %s %s",myApp.latin1(),myParams.latin1(),myHelpFile.latin1());
743 myStatus = system(aCommand);
746 QCustomEvent* ce2000 = new QCustomEvent (2000);
747 postEvent (qApp, ce2000);
751 if( myStatus != 0 || myApp.isEmpty())
754 aCommand.sprintf("%s %s %s", QString(DEFAULT_BROWSER).latin1(),myParams.latin1(), myHelpFile.latin1());
755 myStatus = system(aCommand);
758 QCustomEvent* ce2001 = new QCustomEvent (2001);
759 postEvent (qApp, ce2001);
772 //=======================================================================
773 // name : onHelpContentsModule
774 /*! Purpose : SLOT. Display help contents for choosen module*/
775 //=======================================================================
776 void LightApp_Application::onHelpContentsModule()
778 const QAction* obj = (QAction*) sender();
780 QString aComponentName = obj->name();
781 QString aFileName = aComponentName + "_index.html";
786 if (dir = getenv( aComponentName + "_ROOT_DIR")) {
787 root = Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("doc") + Qtx::addSlash("salome") );
788 if ( QFileInfo( root + aFileName ).exists() ) {
791 SUIT_MessageBox::warn1( desktop(), tr("WRN_WARNING"),
792 QString( "%1"+ aFileName + " doesn't exist." ).arg(root), tr ("BUT_OK") );
797 QString helpFile = QFileInfo( homeDir + aFileName ).absFilePath();
798 SUIT_ResourceMgr* resMgr = resourceMgr();
799 QString anApp = resMgr->stringValue("ExternalBrowser", "application");
800 QString aParams = resMgr->stringValue("ExternalBrowser", "parameters");
802 RunBrowser* rs = new RunBrowser(anApp, aParams, helpFile);
806 /*!Sets enable or disable some actions on selection changed.*/
807 void LightApp_Application::onSelectionChanged()
812 *\param flag - key for window
813 *\param studyId - study id
814 * Flag used how identificator of window in windows list.
816 QWidget* LightApp_Application::window( const int flag, const int studyId ) const
823 if ( !activeStudy() )
826 sId = activeStudy()->id();
829 if ( myWindows.contains( flag ) )
830 wid = myWindows[flag]->widget( sId );
835 /*!Adds window to application.
836 *\param wid - QWidget
837 *\param flag - key wor window
838 *\param studyId - study id
839 * Flag used how identificator of window in windows list.
841 void LightApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
849 if ( !activeStudy() )
852 sId = activeStudy()->id();
855 if ( !myWindows.contains( flag ) )
857 QMap<int, int> winMap;
858 currentWindows( winMap );
860 LightApp_WidgetContainer* newWC = new LightApp_WidgetContainer( flag, desktop() );
861 connect( newWC, SIGNAL( destroyed ( QObject* ) ), this, SLOT( onWCDestroyed( QObject* ) ) );
862 myWindows.insert( flag, newWC );
863 if ( winMap.contains( flag ) )
864 desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
866 myWindows[flag]->setResizeEnabled( true );
867 myWindows[flag]->setCloseMode( QDockWindow::Always );
868 myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
872 if( wid->inherits( "PythonConsole" ) )
873 f = ( ( PythonConsole* )wid )->font();
877 myWindows[flag]->insert( sId, wid );
880 setWindowShown( flag, !myWindows[flag]->isEmpty() );
883 /*!Remove window from application.
884 *\param flag - key wor window
885 *\param studyId - study id
886 * Flag used how identificator of window in windows list.
888 void LightApp_Application::removeWindow( const int flag, const int studyId )
890 if ( !myWindows.contains( flag ) )
896 if ( !activeStudy() )
899 sId = activeStudy()->id();
902 QWidget* wid = myWindows[flag]->widget( sId );
903 myWindows[flag]->remove( sId );
906 setWindowShown( flag, !myWindows[flag]->isEmpty() );
910 *\param flag - key wor window
911 *\param studyId - study id
912 * Flag used how identificator of window in windows list.
914 QWidget* LightApp_Application::getWindow( const int flag, const int studyId )
916 QWidget* wid = window( flag, studyId );
918 addWindow( wid = createWindow( flag ), flag, studyId );
923 /*!Check is window visible?(with identificator \a type)*/
924 bool LightApp_Application::isWindowVisible( const int type ) const
927 if ( myWindows.contains( type ) )
929 SUIT_Desktop* desk = ((LightApp_Application*)this)->desktop();
930 res = desk && desk->appropriate( myWindows[type] );
935 /*!Sets window show or hide.
936 *\param type - window identificator.
937 *\param on - true/false (window show/hide)
939 void LightApp_Application::setWindowShown( const int type, const bool on )
941 if ( !desktop() || !myWindows.contains( type ) )
944 QDockWindow* dw = myWindows[type];
945 desktop()->setAppropriate( dw, on );
946 on ? dw->show() : dw->hide();
949 /*!Gets "ObjectBrowser".*/
950 OB_Browser* LightApp_Application::objectBrowser()
953 QWidget* wid = getWindow( WT_ObjectBrowser );
954 if ( wid->inherits( "OB_Browser" ) )
955 ob = (OB_Browser*)wid;
959 /*!Gets "LogWindow".*/
960 LogWindow* LightApp_Application::logWindow()
963 QWidget* wid = getWindow( WT_LogWindow );
964 if ( wid->inherits( "LogWindow" ) )
965 lw = (LogWindow*)wid;
969 /*!Get "PythonConsole"*/
970 PythonConsole* LightApp_Application::pythonConsole()
972 PythonConsole* console = 0;
973 QWidget* wid = getWindow( WT_PyConsole );
974 if ( wid->inherits( "PythonConsole" ) )
975 console = (PythonConsole*)wid;
979 /*!Update obect browser*/
980 void LightApp_Application::updateObjectBrowser( const bool updateModels )
982 // update existing data models
985 LightApp_Study* study = dynamic_cast<LightApp_Study*>(activeStudy());
987 CAM_Study::ModelList dm_list;
988 study->dataModels( dm_list );
989 for ( CAM_Study::ModelListIterator it( dm_list ); it.current(); ++it ) {
990 CAM_DataModel* camDM = it.current();
991 if ( camDM && camDM->inherits( "LightApp_DataModel" ) )
992 ((LightApp_DataModel*)camDM)->update();
996 if ( objectBrowser() )
998 objectBrowser()->updateGeometry();
999 objectBrowser()->updateTree();
1003 /*!Gets preferences.*/
1004 LightApp_Preferences* LightApp_Application::preferences() const
1006 return preferences( false );
1009 /*!Gets view manager*/
1010 SUIT_ViewManager* LightApp_Application::getViewManager( const QString& vmType, const bool create )
1012 SUIT_ViewManager* aVM = viewManager( vmType );
1013 SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
1015 if ( anActiveVM && anActiveVM->getType() == vmType )
1018 if ( aVM && create )
1020 if ( !aVM->getActiveView() )
1023 aVM->getActiveView()->setFocus();
1026 aVM = createViewManager( vmType );
1031 /*!Create view manager.*/
1032 SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType )
1034 SUIT_ResourceMgr* resMgr = resourceMgr();
1036 SUIT_ViewManager* viewMgr = 0;
1037 if( vmType == GLViewer_Viewer::Type() )
1039 viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
1040 new LightApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
1042 else if( vmType == Plot2d_Viewer::Type() )
1044 viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
1045 SPlot2d_Viewer* vm = new SPlot2d_Viewer();
1046 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1047 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( viewMgr->getActiveView() );
1050 Plot2d_ViewFrame* frame = wnd->getViewFrame();
1051 frame->setBackgroundColor( resMgr->colorValue( "Plot2d", "Background", frame->backgroundColor() ) );
1054 else if( vmType == SUPERVGraph_Viewer::Type() )
1056 viewMgr = new SUPERVGraph_ViewManager( activeStudy(), desktop() );
1057 SUPERVGraph_Viewer* vm = new SUPERVGraph_Viewer();
1058 SUPERVGraph_ViewFrame* view = dynamic_cast<SUPERVGraph_ViewFrame*>( vm->getViewManager()->getActiveView() );
1060 view->setBackgroundColor( resMgr->colorValue( "SUPERVGraph", "Background", view->backgroundColor() ) );
1062 else if( vmType == OCCViewer_Viewer::Type() )
1064 viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
1065 SOCC_Viewer* vm = new SOCC_Viewer();
1066 vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
1067 vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
1070 u = resMgr->integerValue( "OCCViewer", "iso_number_u", u );
1071 v = resMgr->integerValue( "OCCViewer", "iso_number_v", v );
1072 vm->setIsos( u, v );
1073 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1074 new LightApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
1076 else if ( vmType == SVTK_Viewer::Type() )
1078 viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
1079 SVTK_Viewer* vm = dynamic_cast<SVTK_Viewer*>( viewMgr->getViewModel() );
1082 vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
1083 vm->setTrihedronSize( resMgr->integerValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ) );
1084 new LightApp_VTKSelector( vm, mySelMgr );
1091 addViewManager( viewMgr );
1092 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
1094 if ( viewWin && desktop() )
1095 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
1097 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1098 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
1103 //=======================================================================
1104 // name : onCloseView
1105 /*! Purpose : SLOT. Remove view manager from application*/
1106 //=======================================================================
1107 void LightApp_Application::onCloseView( SUIT_ViewManager* theVM )
1109 removeViewManager( theVM );
1112 /*!Protected SLOT. On study created.*/
1113 void LightApp_Application::onStudyCreated( SUIT_Study* theStudy )
1115 SUIT_DataObject* aRoot = 0;
1116 if ( theStudy && theStudy->root() )
1118 aRoot = theStudy->root();
1119 //aRoot->setName( tr( "DATA_MODELS" ) );
1121 if ( objectBrowser() != 0 )
1122 objectBrowser()->setRootObject( aRoot );
1124 activateModule( defaultModule() );
1129 /*!Protected SLOT. On study opened.*/
1130 void LightApp_Application::onStudyOpened( SUIT_Study* theStudy )
1132 SUIT_DataObject* aRoot = 0;
1133 if ( theStudy && theStudy->root() )
1135 aRoot = theStudy->root();
1138 if ( objectBrowser() != 0 ) {
1139 objectBrowser()->setRootObject( aRoot );
1142 activateModule( defaultModule() );
1149 /*!Protected SLOT. On study saved.*/
1150 void LightApp_Application::onStudySaved( SUIT_Study* )
1155 /*!Protected SLOT. On study closed.*/
1156 void LightApp_Application::onStudyClosed( SUIT_Study* )
1160 // Bug 10396: clear selection
1161 mySelMgr->clearSelected();
1163 activateModule( "" );
1165 saveWindowsGeometry();
1168 /*!Protected SLOT.On desktop activated.*/
1169 void LightApp_Application::onDesktopActivated()
1171 CAM_Application::onDesktopActivated();
1172 LightApp_Module* aModule = dynamic_cast<LightApp_Module*>(activeModule());
1174 aModule->studyActivated();
1177 /*!Gets file filter.
1178 *\retval QString "(*.bin)"
1180 QString LightApp_Application::getFileFilter() const
1185 /*! Gets file name*/
1186 QString LightApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1187 const QString& caption, QWidget* parent )
1191 QStringList fls = QStringList::split( ";;", filters, false );
1192 return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1195 /*! Gets directory*/
1196 QString LightApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1200 return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1203 /*! Get open file names*/
1204 QStringList LightApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
1205 const QString& caption, QWidget* parent )
1209 QStringList fls = QStringList::split( ";;", filters, false );
1210 return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1213 /*!Private SLOT. Update object browser.*/
1214 void LightApp_Application::onRefresh()
1216 updateObjectBrowser( true );
1219 /*!Private SLOT. On preferences.*/
1220 void LightApp_Application::onPreferences()
1222 QApplication::setOverrideCursor( Qt::waitCursor );
1224 LightApp_PreferencesDlg* prefDlg = new LightApp_PreferencesDlg( preferences( true ), desktop());
1226 QApplication::restoreOverrideCursor();
1236 /*!Protected SLOT. On preferences changed.*/
1237 void LightApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1239 LightApp_Module* sMod = 0;
1240 CAM_Module* mod = module( modName );
1241 if ( mod && mod->inherits( "LightApp_Module" ) )
1242 sMod = (LightApp_Module*)mod;
1245 sMod->preferencesChanged( section, param );
1247 preferencesChanged( section, param );
1250 /*!Private SLOT. On open document with name \a aName.*/
1251 void LightApp_Application::onMRUActivated( QString aName )
1256 /*!Remove all windows from study.*/
1257 void LightApp_Application::beforeCloseDoc( SUIT_Study* s )
1259 CAM_Application::beforeCloseDoc( s );
1261 for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1262 removeWindow( itr.key(), s->id() );
1265 /*!Update actions.*/
1266 void LightApp_Application::updateActions()
1268 updateCommandsStatus();
1271 //=======================================================================
1272 // name : createNewStudy
1273 /*! Purpose : Create new study*/
1274 //=======================================================================
1275 SUIT_Study* LightApp_Application::createNewStudy()
1277 LightApp_Study* aStudy = new LightApp_Study( this );
1279 // Set up processing of major study-related events
1280 connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
1281 connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
1282 connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );
1283 connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
1289 QWidget* LightApp_Application::createWindow( const int flag )
1292 if ( flag == WT_ObjectBrowser )
1294 OB_Browser* ob = new OB_Browser( desktop() );
1295 ob->setAutoUpdate( true );
1296 ob->setAutoOpenLevel( 1 );
1297 ob->setCaption( tr( "OBJECT_BROWSER" ) );
1298 ob->listView()->setColumnWidth( 0, OBJECT_COLUMN_WIDTH );
1299 ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
1300 ob->setFilter( new LightApp_OBFilter( selectionMgr() ) );
1302 ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1304 // Create OBSelector
1305 new LightApp_OBSelector( ob, mySelMgr );
1309 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1311 else if ( flag == WT_PyConsole )
1313 PythonConsole* pyCons = new PythonConsole( desktop() );
1314 pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1316 // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1318 else if ( flag == WT_LogWindow )
1320 LogWindow* logWin = new LogWindow( desktop() );
1321 logWin->setCaption( tr( "LOG_WINDOW" ) );
1323 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1328 /*!Default windows(Object Browser, Python Console).
1329 * Adds to map \a aMap.
1331 void LightApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1333 aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1334 aMap.insert( WT_PyConsole, Qt::DockBottom );
1335 // aMap.insert( WT_LogWindow, Qt::DockBottom );
1338 /*!Default view manager.*/
1339 void LightApp_Application::defaultViewManagers( QStringList& ) const
1344 /*!Gets preferences.
1345 * Create preferences, if \a crt = true.
1347 LightApp_Preferences* LightApp_Application::preferences( const bool crt ) const
1352 LightApp_Application* that = (LightApp_Application*)this;
1354 if ( !_prefs_ && crt )
1356 _prefs_ = new LightApp_Preferences( resourceMgr() );
1357 that->createPreferences( _prefs_ );
1360 that->myPrefs = _prefs_;
1362 QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1363 for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1365 if ( !appIt.current()->inherits( "LightApp_Application" ) )
1368 LightApp_Application* app = (LightApp_Application*)appIt.current();
1370 QStringList modNameList;
1371 app->modules( modNameList, false );
1372 for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1374 int id = _prefs_->addPreference( *it );
1375 _prefs_->setItemProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1379 app->modules( modList );
1380 for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1382 LightApp_Module* mod = 0;
1383 if ( itr.current()->inherits( "LightApp_Module" ) )
1384 mod = (LightApp_Module*)itr.current();
1386 if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1388 int modCat = _prefs_->addPreference( mod->moduleName() );
1389 _prefs_->setItemProperty( modCat, "info", QString::null );
1390 mod->createPreferences();
1395 connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1396 this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1401 /*!Add new module to application.*/
1402 void LightApp_Application::moduleAdded( CAM_Module* mod )
1404 CAM_Application::moduleAdded( mod );
1406 LightApp_Module* lightMod = 0;
1407 if ( mod && mod->inherits( "LightApp_Module" ) )
1408 lightMod = (LightApp_Module*)mod;
1410 if ( myPrefs && lightMod && !myPrefs->hasModule( lightMod->moduleName() ))
1412 int modCat = myPrefs->addPreference( mod->moduleName() );
1413 myPrefs->setItemProperty( modCat, "info", QString::null );
1414 lightMod->createPreferences();
1418 /*!Create preferences.*/
1419 void LightApp_Application::createPreferences( LightApp_Preferences* pref )
1424 int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1426 int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1427 int studyGroup = pref->addPreference( tr( "PREF_GROUP_STUDY" ), genTab );
1428 pref->setItemProperty( studyGroup, "columns", 1 );
1430 pref->addPreference( tr( "PREF_MULTI_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "multi_file" );
1431 pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "ascii_file" );
1432 int undoPref = pref->addPreference( tr( "PREF_UNDO_LEVEL" ), studyGroup, LightApp_Preferences::IntSpin, "Study", "undo_level" );
1433 pref->setItemProperty( undoPref, "min", 1 );
1434 pref->setItemProperty( undoPref, "max", 100 );
1436 int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab );
1437 pref->setItemProperty( extgroup, "columns", 1 );
1438 int apppref = pref->addPreference( tr( "PREF_APP" ), extgroup, LightApp_Preferences::File, "ExternalBrowser", "application" );
1439 pref->setItemProperty( apppref, "existing", true );
1440 pref->setItemProperty( apppref, "flags", QFileInfo::ExeUser );
1442 pref->addPreference( tr( "PREF_PARAM" ), extgroup, LightApp_Preferences::String, "ExternalBrowser", "parameters" );
1444 int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab );
1445 pref->setItemProperty( pythonConsoleGroup, "columns", 1 );
1446 pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, LightApp_Preferences::Font, "PyConsole", "font" );
1448 int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1450 int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1452 int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1454 int plot2dGroup = pref->addPreference( tr( "PREF_GROUP_PLOT2DVIEWER" ), viewTab );
1456 int supervGroup = pref->addPreference( tr( "PREF_GROUP_SUPERV" ), viewTab );
1458 pref->setItemProperty( occGroup, "columns", 1 );
1459 pref->setItemProperty( vtkGroup, "columns", 1 );
1460 pref->setItemProperty( plot2dGroup, "columns", 1 );
1462 int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1463 LightApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1464 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1465 LightApp_Preferences::Color, "OCCViewer", "background" );
1467 pref->setItemProperty( occTS, "min", 1 );
1468 pref->setItemProperty( occTS, "max", 150 );
1470 int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
1471 LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
1472 int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
1473 LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
1475 pref->setItemProperty( isoU, "min", 0 );
1476 pref->setItemProperty( isoU, "max", 100000 );
1478 pref->setItemProperty( isoV, "min", 0 );
1479 pref->setItemProperty( isoV, "max", 100000 );
1481 int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1482 LightApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1483 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1484 LightApp_Preferences::Color, "VTKViewer", "background" );
1486 pref->setItemProperty( vtkTS, "min", 1 );
1487 pref->setItemProperty( vtkTS, "max", 150 );
1489 pref->addPreference( tr( "PREF_SHOW_LEGEND" ), plot2dGroup,
1490 LightApp_Preferences::Bool, "Plot2d", "ShowLegend" );
1492 int legendPosition = pref->addPreference( tr( "PREF_LEGEND_POSITION" ), plot2dGroup,
1493 LightApp_Preferences::Selector, "Plot2d", "LegendPos" );
1494 QStringList aLegendPosList;
1495 aLegendPosList.append( tr("PREF_LEFT") );
1496 aLegendPosList.append( tr("PREF_RIGHT") );
1497 aLegendPosList.append( tr("PREF_TOP") );
1498 aLegendPosList.append( tr("PREF_BOTTOM") );
1500 QValueList<QVariant> anIndexesList;
1501 anIndexesList.append(0);
1502 anIndexesList.append(1);
1503 anIndexesList.append(2);
1504 anIndexesList.append(3);
1506 pref->setItemProperty( legendPosition, "strings", aLegendPosList );
1507 pref->setItemProperty( legendPosition, "indexes", anIndexesList );
1509 int curveType = pref->addPreference( tr( "PREF_CURVE_TYPE" ), plot2dGroup,
1510 LightApp_Preferences::Selector, "Plot2d", "CurveType" );
1511 QStringList aCurveTypesList;
1512 aCurveTypesList.append( tr("PREF_POINTS") );
1513 aCurveTypesList.append( tr("PREF_LINES") );
1514 aCurveTypesList.append( tr("PREF_SPLINE") );
1516 anIndexesList.clear();
1517 anIndexesList.append(0);
1518 anIndexesList.append(1);
1519 anIndexesList.append(2);
1521 pref->setItemProperty( curveType, "strings", aCurveTypesList );
1522 pref->setItemProperty( curveType, "indexes", anIndexesList );
1524 int markerSize = pref->addPreference( tr( "PREF_MARKER_SIZE" ), plot2dGroup,
1525 LightApp_Preferences::IntSpin, "Plot2d", "MarkerSize" );
1527 pref->setItemProperty( markerSize, "min", 0 );
1528 pref->setItemProperty( markerSize, "max", 100 );
1530 QStringList aScaleModesList;
1531 aScaleModesList.append( tr("PREF_LINEAR") );
1532 aScaleModesList.append( tr("PREF_LOGARITHMIC") );
1534 anIndexesList.clear();
1535 anIndexesList.append(0);
1536 anIndexesList.append(1);
1538 int horScale = pref->addPreference( tr( "PREF_HOR_AXIS_SCALE" ), plot2dGroup,
1539 LightApp_Preferences::Selector, "Plot2d", "HorScaleMode" );
1541 pref->setItemProperty( horScale, "strings", aScaleModesList );
1542 pref->setItemProperty( horScale, "indexes", anIndexesList );
1544 int verScale = pref->addPreference( tr( "PREF_VERT_AXIS_SCALE" ), plot2dGroup,
1545 LightApp_Preferences::Selector, "Plot2d", "VerScaleMode" );
1547 pref->setItemProperty( verScale, "strings", aScaleModesList );
1548 pref->setItemProperty( verScale, "indexes", anIndexesList );
1550 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), plot2dGroup,
1551 LightApp_Preferences::Color, "Plot2d", "Background" );
1553 int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat );
1554 int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab );
1555 pref->setItemProperty( dirGroup, "columns", 1 );
1556 pref->addPreference( tr( "" ), dirGroup,
1557 LightApp_Preferences::DirList, "FileDlg", "QuickDirList" );
1559 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), supervGroup,
1560 LightApp_Preferences::Color, "SUPERVGraph", "Background" );
1561 pref->addPreference( tr( "PREF_SUPERV_TITLE_COLOR" ), supervGroup,
1562 LightApp_Preferences::Color, "SUPERVGraph", "Title" );
1563 // pref->addPreference( tr( "PREF_SUPERV_CTRL_COLOR" ), supervGroup,
1564 // LightApp_Preferences::Color, "SUPERVGraph", "Ctrl" );
1567 /*!Changed preferences */
1568 void LightApp_Application::preferencesChanged( const QString& sec, const QString& param )
1570 SUIT_ResourceMgr* resMgr = resourceMgr();
1574 if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1576 int sz = resMgr->integerValue( sec, param, -1 );
1577 QPtrList<SUIT_ViewManager> lst;
1578 viewManagers( OCCViewer_Viewer::Type(), lst );
1579 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1581 SUIT_ViewModel* vm = it.current()->getViewModel();
1582 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1585 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1586 occVM->setTrihedronSize( sz );
1587 occVM->getAISContext()->UpdateCurrentViewer();
1591 if ( sec == QString( "VTKViewer" ) && param == QString( "trihedron_size" ) )
1593 int sz = resMgr->integerValue( sec, param, -1 );
1594 QPtrList<SUIT_ViewManager> lst;
1595 viewManagers( SVTK_Viewer::Type(), lst );
1596 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1598 SUIT_ViewModel* vm = it.current()->getViewModel();
1599 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
1602 SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
1605 vtkVM->setTrihedronSize( sz );
1611 if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
1613 QPtrList<SUIT_ViewManager> lst;
1614 viewManagers( OCCViewer_Viewer::Type(), lst );
1615 int u = resMgr->integerValue( sec, "iso_number_u" );
1616 int v = resMgr->integerValue( sec, "iso_number_v" );
1617 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
1619 OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>( it.current() );
1620 if( mgr && mgr->getOCCViewer() )
1621 mgr->getOCCViewer()->setIsos( u, v );
1625 if( sec=="ObjectBrowser" )
1627 if( param=="auto_size" )
1629 OB_Browser* ob = objectBrowser();
1633 bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
1634 ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1636 updateObjectBrowser( false );
1640 if( sec=="PyConsole" )
1643 if( pythonConsole() )
1644 pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1648 /*!Update desktop title.*/
1649 void LightApp_Application::updateDesktopTitle() {
1650 QString aTitle = applicationName();
1651 QString aVer = applicationVersion();
1652 if ( !aVer.isEmpty() )
1653 aTitle += QString( " " ) + aVer;
1655 desktop()->setCaption( aTitle );
1658 /*!Update windows after close document.*/
1659 void LightApp_Application::afterCloseDoc()
1663 CAM_Application::afterCloseDoc();
1666 /*!Update module action.*/
1667 void LightApp_Application::updateModuleActions()
1670 if ( activeModule() )
1671 modName = activeModule()->moduleName();
1673 if ( myActions.contains( modName ) )
1674 myActions[modName]->setOn( true );
1677 /*!Gets current windows.
1678 *\param winMap - output current windows map.
1680 void LightApp_Application::currentWindows( QMap<int, int>& winMap ) const
1683 if ( !activeStudy() )
1686 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
1687 ((LightApp_Module*)activeModule())->windows( winMap );
1689 defaultWindows( winMap );
1692 /*!Gets current view managers.
1693 *\param lst - output current view managers list.
1695 void LightApp_Application::currentViewManagers( QStringList& lst ) const
1698 if ( !activeStudy() )
1701 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
1702 ((LightApp_Module*)activeModule())->viewManagers( lst );
1704 defaultViewManagers( lst );
1707 /*!Update windows.*/
1708 void LightApp_Application::updateWindows()
1710 QMap<int, int> winMap;
1711 currentWindows( winMap );
1713 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1714 getWindow( it.key() );
1716 loadWindowsGeometry();
1718 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1719 setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1722 /*!Update view managers.*/
1723 void LightApp_Application::updateViewManagers()
1726 currentViewManagers( lst );
1728 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1729 getViewManager( *it, true );
1732 /*!Load windows geometry.*/
1733 void LightApp_Application::loadWindowsGeometry()
1735 QtxDockAction* dockMgr = 0;
1737 QAction* a = action( ViewWindowsId );
1738 if ( a && a->inherits( "QtxDockAction" ) )
1739 dockMgr = (QtxDockAction*)a;
1745 if ( activeModule() )
1746 modName = activeModule()->name("");
1748 QString section = QString( "windows_geometry" );
1749 if ( !modName.isEmpty() )
1750 section += QString( "." ) + modName;
1752 dockMgr->loadGeometry( resourceMgr(), section, false );
1753 dockMgr->restoreGeometry();
1756 /*!Save windows geometry.*/
1757 void LightApp_Application::saveWindowsGeometry()
1759 QtxDockAction* dockMgr = 0;
1761 QAction* a = action( ViewWindowsId );
1762 if ( a && a->inherits( "QtxDockAction" ) )
1763 dockMgr = (QtxDockAction*)a;
1769 if ( activeModule() )
1770 modName = activeModule()->name("");
1772 QString section = QString( "windows_geometry" );
1773 if ( !modName.isEmpty() )
1774 section += QString( "." ) + modName;
1776 dockMgr->storeGeometry();
1777 dockMgr->saveGeometry( resourceMgr(), section, false );
1780 /*!Activate windows.*/
1781 void LightApp_Application::activateWindows()
1783 if ( activeStudy() )
1785 for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1786 itr.data()->activate( activeStudy()->id() );
1790 /*!Adds icon names for modules.*/
1791 void LightApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
1795 SUIT_ResourceMgr* resMgr = resourceMgr();
1799 QStringList modList;
1800 modules( modList, false );
1802 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
1804 QString modName = *it;
1805 QString modIntr = moduleName( modName );
1806 QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
1808 if ( modIcon.isEmpty() )
1811 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
1812 modIcon += QString( ".png" );
1814 iconMap.insert( modName, modIcon );
1818 /*!Insert items in popup, which necessary for current application*/
1819 void LightApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
1821 CAM_Application::contextMenuPopup( type, thePopup, title );
1823 OB_Browser* ob = objectBrowser();
1824 if ( !ob || type != ob->popupClientType() )
1827 thePopup->insertSeparator();
1828 thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
1831 /*!Create empty study.*/
1832 void LightApp_Application::createEmptyStudy()
1834 CAM_Application::createEmptyStudy();
1835 if ( objectBrowser() )
1836 objectBrowser()->updateTree();
1839 /*!Activate module \a mod.*/
1840 bool LightApp_Application::activateModule( CAM_Module* mod )
1842 bool res = CAM_Application::activateModule( mod );
1843 if ( objectBrowser() )
1844 objectBrowser()->updateTree();
1848 /*!return keyborad accelerators manager object */
1849 SUIT_Accel* LightApp_Application::accel() const
1854 /*! remove dead widget container from map */
1855 void LightApp_Application::onWCDestroyed( QObject* ob )
1857 // remove destroyed widget container from windows map
1858 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1860 if ( itr.data() != ob )
1863 int key = itr.key();
1864 myWindows.remove( key );
1869 /*! redefined to remove view manager from memory */
1870 void LightApp_Application::removeViewManager( SUIT_ViewManager* vm )
1872 disconnect( vm, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1873 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
1874 STD_Application::removeViewManager( vm );
1878 /*! rename active window of desktop */
1879 void LightApp_Application::onRenameWindow()
1884 QWidget* w = desktop()->activeWindow();
1889 QString name = QInputDialog::getText( tr( "TOT_RENAME" ), tr( "PRP_RENAME" ), QLineEdit::Normal, w->caption(), &ok, w );
1890 if( ok && !name.isEmpty() )
1891 w->setCaption( name );