1 // File: LightApp_Application.cxx
2 // Created: 6/20/2005 18:39:45 PM
3 // Author: Natalia Donis
4 // Copyright (C) CEA 2005
6 #ifndef DISABLE_PYCONSOLE
7 #include "PythonConsole_PyInterp.h" // WARNING! This include must be the first!
8 #include <PythonConsole_PyConsole.h>
11 #include "LightApp_Application.h"
12 #include "LightApp_WidgetContainer.h"
13 #include "LightApp_Module.h"
14 #include "LightApp_DataModel.h"
15 #include "LightApp_Study.h"
16 #include "LightApp_Preferences.h"
17 #include "LightApp_PreferencesDlg.h"
18 #include "LightApp_ModuleDlg.h"
19 #include "LightApp_AboutDlg.h"
21 #include "LightApp_OBFilter.h"
23 #include "LightApp_OBSelector.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 <OB_ListView.h>
46 #ifndef DISABLE_GLVIEWER
47 #include <GLViewer_Viewer.h>
48 #include <GLViewer_ViewManager.h>
49 #include "LightApp_GLSelector.h"
52 #ifndef DISABLE_PLOT2DVIEWER
53 #include <Plot2d_ViewManager.h>
54 #include <Plot2d_ViewModel.h>
55 #ifndef DISABLE_SALOMEOBJECT
56 #include <SPlot2d_ViewModel.h>
58 #include <Plot2d_ViewModel.h>
62 #ifndef DISABLE_OCCVIEWER
63 #include <OCCViewer_ViewManager.h>
64 #ifndef DISABLE_SALOMEOBJECT
65 #include <SOCC_ViewModel.h>
67 #include <OCCViewer_ViewModel.h>
69 #include "LightApp_OCCSelector.h"
72 #ifndef DISABLE_VTKVIEWER
73 #ifndef DISABLE_SALOMEOBJECT
74 #include <SVTK_ViewModel.h>
75 #include <SVTK_ViewManager.h>
76 #include "LightApp_VTKSelector.h"
78 #include <VTKViewer_ViewModel.h>
79 #include <VTKViewer_ViewManager.h>
81 #include <VTKViewer_ViewModel.h>
84 #ifndef DISABLE_SUPERVGRAPHVIEWER
85 #include <SUPERVGraph_ViewModel.h>
86 #include <SUPERVGraph_ViewFrame.h>
87 #include <SUPERVGraph_ViewManager.h>
90 #include <QtxWorkstack.h>
96 #include <qstringlist.h>
98 #include <qapplication.h>
100 #include <qstatusbar.h>
102 #include <qobjectlist.h>
103 #include <qcombobox.h>
104 #include <qinputdialog.h>
105 #include <qmessagebox.h>
107 #define FIRST_HELP_ID 1000000
109 #ifndef DISABLE_SALOMEOBJECT
110 #include "SALOME_InteractiveObject.hxx"
111 #include "SALOME_ListIO.hxx"
114 static const char* imageEmptyIcon[] = {
117 "....................",
118 "....................",
119 "....................",
120 "....................",
121 "....................",
122 "....................",
123 "....................",
124 "....................",
125 "....................",
126 "....................",
127 "....................",
128 "....................",
129 "....................",
130 "....................",
131 "....................",
132 "....................",
133 "....................",
134 "....................",
135 "....................",
136 "...................."};
138 int LightApp_Application::lastStudyId = 0;
140 int LightApp_Application::studyId()
142 return LightApp_Application::lastStudyId;
145 /*!Create new instance of LightApp_Application.*/
146 extern "C" LIGHTAPP_EXPORT SUIT_Application* createApplication()
148 return new LightApp_Application();
151 LightApp_Preferences* LightApp_Application::_prefs_ = 0;
154 Class : LightApp_Application
155 Description : Application containing LightApp module
159 LightApp_Application::LightApp_Application()
160 : CAM_Application( false ),
163 STD_TabDesktop* desk = new STD_TabDesktop();
167 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
168 QPixmap aLogo = aResMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false );
170 desktop()->setIcon( aLogo );
171 desktop()->setDockableMenuBar( true );
172 desktop()->setDockableStatusBar( false );
174 // base logo (salome itself)
175 desktop()->addLogo( "_app_base", aResMgr->loadPixmap( "LightApp", tr( "APP_BASE_LOGO" ), false ) );
176 // extra logo (salome-based application)
177 desktop()->addLogo( "_app_extra", aResMgr->loadPixmap( "LightApp", tr( "APP_EXTRA_LOGO" ), false ) );
181 mySelMgr = new LightApp_SelectionMgr( this );
183 myAccel = SUIT_Accel::getAccel();
185 #ifndef DISABLE_OCCVIEWER
186 myAccel->setActionKey( SUIT_Accel::PanLeft, CTRL+Key_Left, OCCViewer_Viewer::Type() );
187 myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, OCCViewer_Viewer::Type() );
188 myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, OCCViewer_Viewer::Type() );
189 myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, OCCViewer_Viewer::Type() );
190 myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, OCCViewer_Viewer::Type() );
191 myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, OCCViewer_Viewer::Type() );
192 myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, OCCViewer_Viewer::Type() );
193 myAccel->setActionKey( SUIT_Accel::RotateLeft, ALT+Key_Left, OCCViewer_Viewer::Type() );
194 myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right, OCCViewer_Viewer::Type() );
195 myAccel->setActionKey( SUIT_Accel::RotateUp, ALT+Key_Up, OCCViewer_Viewer::Type() );
196 myAccel->setActionKey( SUIT_Accel::RotateDown, ALT+Key_Down, OCCViewer_Viewer::Type() );
198 #ifndef DISABLE_VTKVIEWER
199 myAccel->setActionKey( SUIT_Accel::PanLeft, CTRL+Key_Left, VTKViewer_Viewer::Type() );
200 myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, VTKViewer_Viewer::Type() );
201 myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, VTKViewer_Viewer::Type() );
202 myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, VTKViewer_Viewer::Type() );
203 myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, VTKViewer_Viewer::Type() );
204 myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, VTKViewer_Viewer::Type() );
205 myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, VTKViewer_Viewer::Type() );
206 myAccel->setActionKey( SUIT_Accel::RotateLeft, ALT+Key_Left, VTKViewer_Viewer::Type() );
207 myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right, VTKViewer_Viewer::Type() );
208 myAccel->setActionKey( SUIT_Accel::RotateUp, ALT+Key_Up, VTKViewer_Viewer::Type() );
209 myAccel->setActionKey( SUIT_Accel::RotateDown, ALT+Key_Down, VTKViewer_Viewer::Type() );
212 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) );
216 *\li Save window geometry.
217 *\li Save desktop geometry.
218 *\li Save resource maneger.
219 *\li Delete selection manager.
221 LightApp_Application::~LightApp_Application()
226 /*!Start application.*/
227 void LightApp_Application::start()
230 desktop()->loadGeometry( resourceMgr(), "desktop" );
232 CAM_Application::start();
234 QAction* a = action( ViewWindowsId );
235 if ( a && a->inherits( "QtxDockAction" ) )
236 ((QtxDockAction*)a)->setAutoPlace( true );
239 updateViewManagers();
242 desktop()->statusBar()->message( "" );
245 /*!Gets application name.*/
246 QString LightApp_Application::applicationName() const
248 return tr( "APP_NAME" );
251 /*!Gets application version.*/
252 QString LightApp_Application::applicationVersion() const
254 static QString _app_version;
256 if ( _app_version.isEmpty() )
258 QString resVersion = tr( "APP_VERSION" );
259 if ( resVersion != "APP_VERSION" )
261 _app_version = resVersion;
265 QString path( ::getenv( "GUI_ROOT_DIR" ) );
266 if ( !path.isEmpty() )
267 path += QDir::separator();
268 path += QString( "bin/salome/VERSION" );
271 if ( vf.open( IO_ReadOnly ) )
274 vf.readLine( line, 1024 );
277 if ( !line.isEmpty() )
279 while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
280 line.remove( line.length() - 1, 1 );
282 int idx = line.findRev( ":" );
284 _app_version = line.mid( idx + 1 ).stripWhiteSpace();
292 /*!Load module by \a name.*/
293 CAM_Module* LightApp_Application::loadModule( const QString& name )
295 CAM_Module* mod = CAM_Application::loadModule( name );
298 connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) );
299 connect( this, SIGNAL( studySaved() ), mod, SLOT( onModelSaved() ) );
300 connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) );
305 /*!Activate module by \a modName*/
306 bool LightApp_Application::activateModule( const QString& modName )
309 CAM_Module* prevMod = activeModule();
312 actName = prevMod->moduleName();
314 if ( actName == modName )
317 putInfo( tr( "ACTIVATING_MODULE" ).arg( modName ) );
319 saveWindowsGeometry();
321 bool status = CAM_Application::activateModule( modName );
323 updateModuleActions();
331 updateViewManagers();
336 bool LightApp_Application::useStudy(const QString& theName)
339 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>(activeStudy());
342 res = aStudy->loadDocument( theName );
343 updateDesktopTitle();
344 updateCommandsStatus();
348 /*!Gets selection manager.*/
349 LightApp_SelectionMgr* LightApp_Application::selectionMgr() const
354 /*!Creat action "New window" for certain type of viewer:*/
355 void LightApp_Application::createActionForViewer( const int id,
357 const QString& suffix,
360 QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( suffix ) ), QIconSet(),
361 tr( QString( "NEW_WINDOW_%1" ).arg( suffix ) ),
362 tr( QString( "NEW_WINDOW_%1" ).arg( suffix ) ),
363 accel, desktop(), false, this, SLOT( onNewWindow() ) );
364 createMenu( a, parentId, -1 );
368 void LightApp_Application::createActions()
370 STD_Application::createActions();
372 SUIT_Desktop* desk = desktop();
373 SUIT_ResourceMgr* resMgr = resourceMgr();
376 createAction( PreferencesId, tr( "TOT_DESK_PREFERENCES" ), QIconSet(),
377 tr( "MEN_DESK_PREFERENCES" ), tr( "PRP_DESK_PREFERENCES" ),
378 CTRL+Key_F, desk, false, this, SLOT( onPreferences() ) );
381 int helpMenu = createMenu( tr( "MEN_DESK_HELP" ), -1, -1, 1000 );
382 int helpModuleMenu = createMenu( tr( "MEN_DESK_MODULE_HELP" ), helpMenu, -1, 0 );
383 createMenu( separator(), helpMenu, -1, 1 );
385 QStringList aModuleList;
386 modules( aModuleList, false );
388 int id = LightApp_Application::UserID + FIRST_HELP_ID;
389 // help for KERNEL and GUI
394 if (dir = getenv("GUI_ROOT_DIR")) {
395 aFileName = "GUI_index_v3.1.0.html";
396 root = Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("doc") + Qtx::addSlash("salome") );
397 if ( QFileInfo( root + aFileName ).exists() ) {
398 a = createAction( id, tr( QString("Kernel & GUI Help") ), QIconSet(),
399 tr( QString("Kernel && GUI Help") ),
400 tr( QString("Kernel & GUI Help") ),
401 0, desk, false, this, SLOT( onHelpContentsModule() ) );
402 a->setName( QString("GUI") );
403 createMenu( a, helpModuleMenu, -1 );
407 // help for other existing modules
408 QStringList::Iterator it;
409 for ( it = aModuleList.begin(); it != aModuleList.end(); ++it )
411 if ( (*it).isEmpty() )
414 QString modName = moduleName( *it );
415 aFileName = modName + "_index_v3.1.0.html";
417 if (dir = getenv( modName + "_ROOT_DIR")) {
418 root = Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("doc") + Qtx::addSlash("salome") );
419 if ( QFileInfo( root + aFileName ).exists() ) {
421 QAction* a = createAction( id, tr( moduleTitle(modName) + QString(" Help") ), QIconSet(),
422 tr( moduleTitle(modName) + QString(" Help") ),
423 tr( moduleTitle(modName) + QString(" Help") ),
424 0, desk, false, this, SLOT( onHelpContentsModule() ) );
425 a->setName( modName );
426 createMenu( a, helpModuleMenu, -1 );
433 QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), desk );
434 connect( mru, SIGNAL( activated( QString ) ), this, SLOT( onMRUActivated( QString ) ) );
435 registerAction( MRUId, mru );
437 // default icon for neutral point ('SALOME' module)
438 QPixmap defIcon = resMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false );
439 if ( defIcon.isNull() )
440 defIcon = QPixmap( imageEmptyIcon );
442 //! default icon for any module
443 QPixmap modIcon = resMgr->loadPixmap( "LightApp", tr( "APP_MODULE_ICO" ), false );
444 if ( modIcon.isNull() )
445 modIcon = QPixmap( imageEmptyIcon );
447 QToolBar* modTBar = new QtxToolBar( true, desk );
448 modTBar->setLabel( tr( "INF_TOOLBAR_MODULES" ) );
450 QActionGroup* modGroup = new QActionGroup( this );
451 modGroup->setExclusive( true );
452 modGroup->setUsesDropDown( true );
454 a = createAction( -1, tr( "APP_NAME" ), defIcon, tr( "APP_NAME" ),
455 tr( "PRP_APP_MODULE" ), 0, desk, true );
457 myActions.insert( QString(), a );
459 QMap<QString, QString> iconMap;
460 moduleIconNames( iconMap );
462 const int iconSize = 20;
464 modGroup->addTo( modTBar );
465 QObjectList *l = modTBar->queryList( "QComboBox" );
466 QObjectListIt oit( *l );
467 while ( QObject* obj = oit.current() ) {
468 QComboBox* cb = (QComboBox*)obj;
469 if ( cb ) cb->setFocusPolicy( QWidget::NoFocus );
474 modTBar->addSeparator();
477 modules( modList, false );
479 for ( it = modList.begin(); it != modList.end(); ++it )
481 if ( !isLibExists( *it ) )
485 if ( iconMap.contains( *it ) )
486 iconName = iconMap[*it];
488 QString modName = moduleName( *it );
490 QPixmap icon = resMgr->loadPixmap( modName, iconName, false );
494 icon.convertFromImage( icon.convertToImage().smoothScale( iconSize, iconSize, QImage::ScaleMin ) );
496 QAction* a = createAction( -1, *it, icon, *it, tr( "PRP_MODULE" ).arg( *it ), 0, desk, true );
500 myActions.insert( *it, a );
503 SUIT_Tools::simplifySeparators( modTBar );
506 int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, MenuWindowId, 100 );
507 int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
508 createMenu( separator(), windowMenu, -1, 1 );
511 #ifndef DISABLE_GLVIEWER
512 createActionForViewer( NewGLViewId, newWinMenu, QString::number( 0 ), ALT+Key_G );
514 #ifndef DISABLE_PLOT2DVIEWER
515 createActionForViewer( NewPlot2dId, newWinMenu, QString::number( 1 ), ALT+Key_P );
517 #ifndef DISABLE_OCCVIEWER
518 createActionForViewer( NewOCCViewId, newWinMenu, QString::number( 2 ), ALT+Key_O );
520 #ifndef DISABLE_VTKVIEWER
521 createActionForViewer( NewVTKViewId, newWinMenu, QString::number( 3 ), ALT+Key_K );
525 createAction( RenameId, tr( "TOT_RENAME" ), QIconSet(), tr( "MEN_DESK_RENAME" ), tr( "PRP_RENAME" ),
526 SHIFT+Key_R, desk, false, this, SLOT( onRenameWindow() ) );
527 createMenu( RenameId, windowMenu, -1 );
529 connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) );
531 int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
532 createMenu( PreferencesId, fileMenu, 15, -1 );
533 createMenu( separator(), fileMenu, -1, 15, -1 );
536 createMenu( separator(), fileMenu, -1, 100, -1 );
537 createMenu( MRUId, fileMenu, 100, -1 );
538 createMenu( separator(), fileMenu, -1, 100, -1 );
542 /*!On module activation action.*/
543 void LightApp_Application::onModuleActivation( QAction* a )
548 QString modName = a->menuText();
549 if ( modName == tr( "APP_NAME" ) )
550 modName = QString::null;
552 // Force user to create/open a study before module activation
553 QMap<QString, QString> iconMap;
554 moduleIconNames( iconMap );
555 QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ], false );
557 icon = resourceMgr()->loadPixmap( "LightApp", tr( "APP_MODULE_BIG_ICO" ), false ); // default icon for any module
559 bool cancelled = false;
560 while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
561 LightApp_ModuleDlg aDlg( desktop(), modName, icon );
562 int res = aDlg.exec();
576 putInfo( tr("INF_CANCELLED") );
577 myActions[QString()]->setOn( true );
583 activateModule( modName );
586 /*!Default module activation.*/
587 QString LightApp_Application::defaultModule() const
589 QStringList aModuleNames;
590 modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration
591 //! If there's the one and only module --> activate it automatically
592 //! TODO: Possible improvement - default module can be taken from preferences
593 return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" );
596 /*!On new window slot.*/
597 void LightApp_Application::onNewWindow()
599 const QObject* obj = sender();
600 if ( !obj || !obj->inherits( "QAction" ) )
604 int id = actionId( (QAction*)obj );
607 #ifndef DISABLE_GLVIEWER
609 type = GLViewer_Viewer::Type();
612 #ifndef DISABLE_PLOT2DVIEWER
614 type = Plot2d_Viewer::Type();
617 #ifndef DISABLE_OCCVIEWER
619 type = OCCViewer_Viewer::Type();
622 #ifndef DISABLE_VTKVIEWER
624 type = VTKViewer_Viewer::Type();
629 if ( !type.isEmpty() )
630 createViewManager( type );
633 //=======================================================================
635 /*! Purpose : SLOT. Create new document*/
636 //=======================================================================
637 void LightApp_Application::onNewDoc()
639 SUIT_Study* study = activeStudy();
641 saveWindowsGeometry();
643 CAM_Application::onNewDoc();
645 if ( !study ) // new study will be create in THIS application
648 updateViewManagers();
652 //=======================================================================
654 /*! Purpose : SLOT. Open new document*/
655 //=======================================================================
656 void LightApp_Application::onOpenDoc()
658 SUIT_Study* study = activeStudy();
659 saveWindowsGeometry();
661 CAM_Application::onOpenDoc();
663 if ( !study ) // new study will be create in THIS application
666 updateViewManagers();
670 #include "SUIT_MessageBox.h"
671 /*! Purpose : SLOT. Open new document with \a aName.*/
672 bool LightApp_Application::onOpenDoc( const QString& aName )
674 bool isAlreadyOpen = false;
676 // Look among opened studies
677 if (activeStudy()) { // at least one study is opened
678 SUIT_Session* aSession = SUIT_Session::session();
679 QPtrList<SUIT_Application> aAppList = aSession->applications();
680 QPtrListIterator<SUIT_Application> it (aAppList);
681 SUIT_Application* aApp = 0;
682 // iterate on all applications
683 for (; (aApp = it.current()) && !isAlreadyOpen; ++it) {
684 if (aApp->activeStudy()->studyName() == aName) {
685 isAlreadyOpen = true; // Already opened, ask user what to do
687 // The document ... is already open.
688 // Do you want to reload it?
689 int aAnswer = SUIT_MessageBox::warn2(desktop(), tr("WRN_WARNING"),
690 tr("QUE_DOC_ALREADYOPEN").arg(aName),
691 tr("BUT_YES"), tr("BUT_NO"), 1, 2, 2);
692 if (aAnswer == 1) { // reload
693 if (activeStudy()->studyName() == aName && aAppList.count() > 1) {
694 // Opened in THIS (active) application.
695 STD_Application* app1 = (STD_Application*)aAppList.at(0);
696 STD_Application* app2 = (STD_Application*)aAppList.at(1);
697 if (!app1 || !app2) {
701 if (app1->activeStudy()->studyName() == aName) {
702 // app1 is this application, we need another one
705 // Close document of this application. This application will be destroyed.
706 onCloseDoc(/*ask = */false);
707 // Open the file with another application, as this one will be destroyed.
708 return app1->onOpenDoc(aName);
710 // Opened in another application.
711 STD_Application* app = (STD_Application*)aApp;
713 app->onCloseDoc(/*ask = */false);
715 } else { // do not reload
716 // OK, the study will not be reloaded, but we call
717 // CAM_Application::onOpenDoc( aName ) all the same.
718 // It will activate a desktop of the study <aName>.
724 bool res = CAM_Application::onOpenDoc( aName );
726 QAction* a = action( MRUId );
727 if ( a && a->inherits( "QtxMRUAction" ) )
729 QtxMRUAction* mru = (QtxMRUAction*)a;
731 mru->insert( aName );
733 mru->remove( aName );
738 //=======================================================================
739 // name : onHelpAbout
740 /*! Purpose : SLOT. Display "About" message box*/
741 //=======================================================================
742 void LightApp_Application::onHelpAbout()
744 LightApp_AboutDlg* dlg = new LightApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
749 /*!SLOT. Load document with \a aName.*/
750 bool LightApp_Application::onLoadDoc( const QString& aName )
752 bool res = CAM_Application::onLoadDoc( aName );
754 /*jfa tmp:QAction* a = action( MRUId );
755 if ( a && a->inherits( "QtxMRUAction" ) )
757 QtxMRUAction* mru = (QtxMRUAction*)a;
759 mru->insert( aName );
761 mru->remove( aName );
766 /*!Private SLOT. Selection.*/
767 void LightApp_Application::onSelection()
769 onSelectionChanged();
771 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
772 ((LightApp_Module*)activeModule())->selectionChanged();
776 *\param study - SUIT_Study.
778 void LightApp_Application::setActiveStudy( SUIT_Study* study )
780 CAM_Application::setActiveStudy( study );
785 //=======================================================================
786 // name : updateCommandsStatus
787 /*! Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu*/
788 //=======================================================================
789 void LightApp_Application::updateCommandsStatus()
791 CAM_Application::updateCommandsStatus();
794 #ifndef DISABLE_GLVIEWER
795 a = action( NewGLViewId );
797 a->setEnabled( activeStudy() );
800 #ifndef DISABLE_PLOT2DVIEWER
801 a = action( NewPlot2dId );
803 a->setEnabled( activeStudy() );
806 #ifndef DISABLE_OCCVIEWER
807 a = action( NewOCCViewId );
809 a->setEnabled( activeStudy() );
812 #ifndef DISABLE_VTKVIEWER
813 a = action( NewVTKViewId );
815 a->setEnabled( activeStudy() );
819 // Helps to execute command
820 class RunBrowser: public QThread {
823 RunBrowser(QString theApp, QString theParams, QString theHelpFile, QString theContext=NULL):
824 myApp(theApp), myParams(theParams),
826 myHelpFile("file://" + theHelpFile + theContext),
828 myHelpFile("file:" + theHelpFile + theContext),
836 if ( !myApp.isEmpty())
838 aCommand.sprintf("%s %s %s",myApp.latin1(),myParams.latin1(),myHelpFile.latin1());
839 myStatus = system(aCommand);
842 QCustomEvent* ce2000 = new QCustomEvent (2000);
843 postEvent (qApp, ce2000);
849 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
850 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").arg(myApp).arg(myHelpFile),
851 QObject::tr("BUT_OK"));
864 //=======================================================================
865 // name : onHelpContentsModule
866 /*! Purpose : SLOT. Display help contents for choosen module*/
867 //=======================================================================
868 void LightApp_Application::onHelpContentsModule()
870 const QAction* obj = (QAction*) sender();
872 QString aComponentName = obj->name();
873 QString aFileName = aComponentName + "_index_v3.1.0.html";
875 QCString dir = getenv( aComponentName + "_ROOT_DIR");
876 QString homeDir = Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("doc") + Qtx::addSlash("salome") );
878 QString helpFile = QFileInfo( homeDir + aFileName ).absFilePath();
879 SUIT_ResourceMgr* resMgr = resourceMgr();
880 QString anApp = resMgr->stringValue("ExternalBrowser", "application");
881 QString aParams = resMgr->stringValue("ExternalBrowser", "parameters");
883 if (!anApp.isEmpty()) {
884 RunBrowser* rs = new RunBrowser(anApp, aParams, helpFile);
888 SUIT_MessageBox::warn1(desktop(), tr("WRN_WARNING"),
889 tr("DEFINE_EXTERNAL_BROWSER"),
894 /*!Sets enable or disable some actions on selection changed.*/
895 void LightApp_Application::onSelectionChanged()
900 *\param flag - key for window
901 *\param studyId - study id
902 * Flag used how identificator of window in windows list.
904 QWidget* LightApp_Application::window( const int flag, const int studyId ) const
911 if ( !activeStudy() )
914 sId = activeStudy()->id();
917 if ( myWindows.contains( flag ) )
918 wid = myWindows[flag]->widget( sId );
923 /*!Adds window to application.
924 *\param wid - QWidget
925 *\param flag - key wor window
926 *\param studyId - study id
927 * Flag used how identificator of window in windows list.
929 void LightApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
937 if ( !activeStudy() )
940 sId = activeStudy()->id();
943 if ( !myWindows.contains( flag ) )
945 QMap<int, int> winMap;
946 currentWindows( winMap );
948 LightApp_WidgetContainer* newWC = new LightApp_WidgetContainer( flag, desktop() );
949 connect( newWC, SIGNAL( destroyed ( QObject* ) ), this, SLOT( onWCDestroyed( QObject* ) ) );
950 myWindows.insert( flag, newWC );
951 if ( winMap.contains( flag ) )
952 desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
954 myWindows[flag]->setResizeEnabled( true );
955 myWindows[flag]->setCloseMode( QDockWindow::Always );
956 myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
957 myWindows[flag]->setFixedExtentWidth( wid->width() );
958 myWindows[flag]->setFixedExtentHeight( wid->height() );
962 #ifndef DISABLE_PYCONSOLE
963 if( wid->inherits( "PythonConsole" ) )
965 if( resourceMgr()->hasValue( "PyConsole", "font" ) )
966 f = resourceMgr()->fontValue( "PyConsole", "font" );
969 f = ( ( PythonConsole* )wid )->font();
970 resourceMgr()->setValue( "PyConsole", "font", f );
977 myWindows[flag]->insert( sId, wid );
980 setWindowShown( flag, !myWindows[flag]->isEmpty() );
983 /*!Remove window from application.
984 *\param flag - key wor window
985 *\param studyId - study id
986 * Flag used how identificator of window in windows list.
988 void LightApp_Application::removeWindow( const int flag, const int studyId )
990 if ( !myWindows.contains( flag ) )
996 if ( !activeStudy() )
999 sId = activeStudy()->id();
1002 QWidget* wid = myWindows[flag]->widget( sId );
1003 myWindows[flag]->remove( sId );
1006 setWindowShown( flag, !myWindows[flag]->isEmpty() );
1010 *\param flag - key wor window
1011 *\param studyId - study id
1012 * Flag used how identificator of window in windows list.
1014 QWidget* LightApp_Application::getWindow( const int flag, const int studyId )
1016 QWidget* wid = window( flag, studyId );
1018 addWindow( wid = createWindow( flag ), flag, studyId );
1023 /*!Check is window visible?(with identificator \a type)*/
1024 bool LightApp_Application::isWindowVisible( const int type ) const
1027 if ( myWindows.contains( type ) )
1029 SUIT_Desktop* desk = ((LightApp_Application*)this)->desktop();
1030 res = desk && desk->appropriate( myWindows[type] );
1035 /*!Sets window show or hide.
1036 *\param type - window identificator.
1037 *\param on - true/false (window show/hide)
1039 void LightApp_Application::setWindowShown( const int type, const bool on )
1041 if ( !desktop() || !myWindows.contains( type ) )
1044 QDockWindow* dw = myWindows[type];
1045 desktop()->setAppropriate( dw, on );
1046 on ? dw->show() : dw->hide();
1049 /*!Gets "ObjectBrowser".*/
1050 OB_Browser* LightApp_Application::objectBrowser()
1053 QWidget* wid = window( WT_ObjectBrowser );
1054 if ( wid && wid->inherits( "OB_Browser" ) )
1055 ob = (OB_Browser*)wid;
1059 /*!Gets "LogWindow".*/
1060 LogWindow* LightApp_Application::logWindow()
1063 QWidget* wid = getWindow( WT_LogWindow );
1064 if ( wid->inherits( "LogWindow" ) )
1065 lw = (LogWindow*)wid;
1069 #ifndef DISABLE_PYCONSOLE
1070 /*!Get "PythonConsole"*/
1071 PythonConsole* LightApp_Application::pythonConsole()
1073 PythonConsole* console = 0;
1074 QWidget* wid = getWindow( WT_PyConsole );
1075 if ( wid->inherits( "PythonConsole" ) )
1076 console = (PythonConsole*)wid;
1081 /*!Update obect browser*/
1082 void LightApp_Application::updateObjectBrowser( const bool updateModels )
1084 // update existing data models
1087 LightApp_Study* study = dynamic_cast<LightApp_Study*>(activeStudy());
1089 CAM_Study::ModelList dm_list;
1090 study->dataModels( dm_list );
1091 for ( CAM_Study::ModelListIterator it( dm_list ); it.current(); ++it ) {
1092 CAM_DataModel* camDM = it.current();
1093 if ( camDM && camDM->inherits( "LightApp_DataModel" ) )
1094 ((LightApp_DataModel*)camDM)->update();
1098 if ( objectBrowser() )
1100 objectBrowser()->updateGeometry();
1101 objectBrowser()->updateTree( 0, false );
1105 /*!Gets preferences.*/
1106 LightApp_Preferences* LightApp_Application::preferences() const
1108 return preferences( false );
1111 /*!Gets view manager*/
1112 SUIT_ViewManager* LightApp_Application::getViewManager( const QString& vmType, const bool create )
1114 SUIT_ViewManager* aVM = viewManager( vmType );
1115 SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
1117 if ( anActiveVM && anActiveVM->getType() == vmType )
1120 if ( aVM && create )
1122 if ( !aVM->getActiveView() )
1125 aVM->getActiveView()->setFocus();
1128 aVM = createViewManager( vmType );
1133 /*!Create view manager.*/
1134 SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType )
1136 SUIT_ResourceMgr* resMgr = resourceMgr();
1138 SUIT_ViewManager* viewMgr = 0;
1139 #ifndef DISABLE_GLVIEWER
1140 if( vmType == GLViewer_Viewer::Type() )
1142 viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
1143 new LightApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
1146 #ifndef DISABLE_PLOT2DVIEWER
1147 if( vmType == Plot2d_Viewer::Type() )
1149 viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
1151 #ifndef DISABLE_SALOMEOBJECT
1152 vm = new SPlot2d_Viewer();
1154 vm = new Plot2d_Viewer();
1156 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1157 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( viewMgr->getActiveView() );
1160 Plot2d_ViewFrame* frame = wnd->getViewFrame();
1161 frame->setBackgroundColor( resMgr->colorValue( "Plot2d", "Background", frame->backgroundColor() ) );
1165 #ifndef DISABLE_SUPERVGRAPHVIEWER
1166 if( vmType == SUPERVGraph_Viewer::Type() )
1168 viewMgr = new SUPERVGraph_ViewManager( activeStudy(), desktop() );
1169 SUPERVGraph_Viewer* vm = new SUPERVGraph_Viewer();
1170 SUPERVGraph_ViewFrame* view = dynamic_cast<SUPERVGraph_ViewFrame*>( vm->getViewManager()->getActiveView() );
1172 view->setBackgroundColor( resMgr->colorValue( "SUPERVGraph", "Background", view->backgroundColor() ) );
1175 #ifndef DISABLE_OCCVIEWER
1176 if( vmType == OCCViewer_Viewer::Type() )
1178 viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
1179 OCCViewer_Viewer* vm;
1180 #ifndef DISABLE_SALOMEOBJECT
1181 vm = new SOCC_Viewer();
1183 vm = new OCCViewer_Viewer();
1185 vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
1186 vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
1189 u = resMgr->integerValue( "OCCViewer", "iso_number_u", u );
1190 v = resMgr->integerValue( "OCCViewer", "iso_number_v", v );
1191 vm->setIsos( u, v );
1192 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1193 new LightApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
1196 #ifndef DISABLE_VTKVIEWER
1197 #ifndef DISABLE_SALOMEOBJECT
1198 if ( vmType == SVTK_Viewer::Type() )
1200 if ( vmType == VTKViewer_Viewer::Type() )
1203 #ifndef DISABLE_SALOMEOBJECT
1204 viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
1205 SVTK_Viewer* vm = dynamic_cast<SVTK_Viewer*>( viewMgr->getViewModel() );
1208 vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
1209 vm->setTrihedronSize( resMgr->integerValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ),
1210 resMgr->booleanValue( "VTKViewer", "relative_size", vm->trihedronRelative() ) );
1211 new LightApp_VTKSelector( vm, mySelMgr );
1214 viewMgr = new VTKViewer_ViewManager( activeStudy(), desktop() );
1215 VTKViewer_Viewer* vm = dynamic_cast<VTKViewer_Viewer*>( viewMgr->getViewModel() );
1217 vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
1225 addViewManager( viewMgr );
1226 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
1228 if ( viewWin && desktop() )
1229 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
1231 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1232 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
1237 //=======================================================================
1238 // name : onCloseView
1239 /*! Purpose : SLOT. Remove view manager from application*/
1240 //=======================================================================
1241 void LightApp_Application::onCloseView( SUIT_ViewManager* theVM )
1243 removeViewManager( theVM );
1246 /*!Protected SLOT. On study created.*/
1247 void LightApp_Application::onStudyCreated( SUIT_Study* theStudy )
1249 SUIT_DataObject* aRoot = 0;
1250 if ( theStudy && theStudy->root() )
1252 aRoot = theStudy->root();
1253 //aRoot->setName( tr( "DATA_MODELS" ) );
1255 getWindow( WT_ObjectBrowser );
1256 if ( objectBrowser() != 0 )
1257 objectBrowser()->setRootObject( aRoot );
1259 activateModule( defaultModule() );
1264 /*!Protected SLOT. On study opened.*/
1265 void LightApp_Application::onStudyOpened( SUIT_Study* theStudy )
1267 SUIT_DataObject* aRoot = 0;
1268 if ( theStudy && theStudy->root() )
1270 aRoot = theStudy->root();
1273 getWindow( WT_ObjectBrowser );
1274 if ( objectBrowser() != 0 ) {
1275 objectBrowser()->setRootObject( aRoot );
1278 activateModule( defaultModule() );
1285 /*!Protected SLOT. On study saved.*/
1286 void LightApp_Application::onStudySaved( SUIT_Study* )
1291 /*!Protected SLOT. On study closed.*/
1292 void LightApp_Application::onStudyClosed( SUIT_Study* )
1296 // Bug 10396: clear selection
1297 mySelMgr->clearSelected();
1299 activateModule( "" );
1301 saveWindowsGeometry();
1304 /*!Protected SLOT.On desktop activated.*/
1305 void LightApp_Application::onDesktopActivated()
1307 CAM_Application::onDesktopActivated();
1308 LightApp_Module* aModule = dynamic_cast<LightApp_Module*>(activeModule());
1310 aModule->studyActivated();
1313 /*!Gets file filter.
1314 *\retval QString "(*.bin)"
1316 QString LightApp_Application::getFileFilter() const
1323 /*! Gets file name*/
1324 QString LightApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1325 const QString& caption, QWidget* parent )
1329 QStringList fls = QStringList::split( ";;", filters, false );
1330 return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1333 /*! Gets directory*/
1334 QString LightApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1338 return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1341 /*! Get open file names*/
1342 QStringList LightApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
1343 const QString& caption, QWidget* parent )
1347 QStringList fls = QStringList::split( ";;", filters, false );
1348 return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1351 /*!Private SLOT. Update object browser.*/
1352 void LightApp_Application::onRefresh()
1354 updateObjectBrowser( true );
1357 /*!Private SLOT. On preferences.*/
1358 void LightApp_Application::onPreferences()
1360 QApplication::setOverrideCursor( Qt::waitCursor );
1362 LightApp_PreferencesDlg* prefDlg = new LightApp_PreferencesDlg( preferences( true ), desktop());
1364 QApplication::restoreOverrideCursor();
1369 if ( ( prefDlg->exec() == QDialog::Accepted || prefDlg->isSaved() ) && resourceMgr() ) {
1371 desktop()->saveGeometry( resourceMgr(), "desktop" );
1372 resourceMgr()->save();
1378 /*!Protected SLOT. On preferences changed.*/
1379 void LightApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1381 LightApp_Module* sMod = 0;
1382 CAM_Module* mod = module( modName );
1383 if ( mod && mod->inherits( "LightApp_Module" ) )
1384 sMod = (LightApp_Module*)mod;
1387 sMod->preferencesChanged( section, param );
1389 preferencesChanged( section, param );
1392 /*!Private SLOT. On open document with name \a aName.*/
1393 void LightApp_Application::onMRUActivated( QString aName )
1398 /*!Remove all windows from study.*/
1399 void LightApp_Application::beforeCloseDoc( SUIT_Study* s )
1401 CAM_Application::beforeCloseDoc( s );
1403 for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1404 removeWindow( itr.key(), s->id() );
1407 /*!Update actions.*/
1408 void LightApp_Application::updateActions()
1410 updateCommandsStatus();
1413 //=======================================================================
1414 // name : createNewStudy
1415 /*! Purpose : Create new study*/
1416 //=======================================================================
1417 SUIT_Study* LightApp_Application::createNewStudy()
1419 LightApp_Application::lastStudyId++;
1421 LightApp_Study* aStudy = new LightApp_Study( this );
1423 // Set up processing of major study-related events
1424 connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
1425 connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
1426 connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );
1427 connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
1433 QWidget* LightApp_Application::createWindow( const int flag )
1436 if ( flag == WT_ObjectBrowser )
1438 OB_Browser* ob = new OB_Browser( desktop() );
1439 ob->setAutoUpdate( true );
1440 //ob->setAutoOpenLevel( 1 ); // commented by ASV as a fix to bug IPAL10107
1441 ob->setCaption( tr( "OBJECT_BROWSER" ) );
1443 OB_ListView* ob_list = dynamic_cast<OB_ListView*>( const_cast<QListView*>( ob->listView() ) );
1445 ob_list->setColumnMaxWidth( 0, desktop()->width()/4 );
1447 ob->setFilter( new LightApp_OBFilter( selectionMgr() ) );
1448 ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1450 // Create OBSelector
1451 new LightApp_OBSelector( ob, mySelMgr );
1455 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1457 #ifndef DISABLE_PYCONSOLE
1458 else if ( flag == WT_PyConsole )
1460 PythonConsole* pyCons = new PythonConsole( desktop() );
1461 pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1463 // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1466 else if ( flag == WT_LogWindow )
1468 LogWindow* logWin = new LogWindow( desktop() );
1469 logWin->setCaption( tr( "LOG_WINDOW" ) );
1471 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1476 /*!Default windows(Object Browser, Python Console).
1477 * Adds to map \a aMap.
1479 void LightApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1481 aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1482 #ifndef DISABLE_PYCONSOLE
1483 aMap.insert( WT_PyConsole, Qt::DockBottom );
1485 // aMap.insert( WT_LogWindow, Qt::DockBottom );
1488 /*!Default view manager.*/
1489 void LightApp_Application::defaultViewManagers( QStringList& ) const
1494 /*!Gets preferences.
1495 * Create preferences, if \a crt = true.
1497 LightApp_Preferences* LightApp_Application::preferences( const bool crt ) const
1502 LightApp_Application* that = (LightApp_Application*)this;
1504 bool toCreate = !_prefs_ && crt;
1507 _prefs_ = new LightApp_Preferences( resourceMgr() );
1508 that->createPreferences( _prefs_ );
1511 that->myPrefs = _prefs_;
1513 QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1514 for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1516 if ( !appIt.current()->inherits( "LightApp_Application" ) )
1519 LightApp_Application* app = (LightApp_Application*)appIt.current();
1521 QStringList modNameList;
1522 app->modules( modNameList, false );
1523 for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1525 int id = _prefs_->addPreference( *it );
1526 _prefs_->setItemProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1530 app->modules( modList );
1531 for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1533 LightApp_Module* mod = 0;
1534 if ( itr.current()->inherits( "LightApp_Module" ) )
1535 mod = (LightApp_Module*)itr.current();
1537 if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1539 int modCat = _prefs_->addPreference( mod->moduleName() );
1540 _prefs_->setItemProperty( modCat, "info", QString::null );
1542 mod->createPreferences();
1547 connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1548 this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1553 /*!Add new module to application.*/
1554 void LightApp_Application::moduleAdded( CAM_Module* mod )
1556 CAM_Application::moduleAdded( mod );
1558 LightApp_Module* lightMod = 0;
1559 if ( mod && mod->inherits( "LightApp_Module" ) )
1560 lightMod = (LightApp_Module*)mod;
1562 if ( myPrefs && lightMod && !myPrefs->hasModule( lightMod->moduleName() ))
1564 int modCat = myPrefs->addPreference( mod->moduleName() );
1565 myPrefs->setItemProperty( modCat, "info", QString::null );
1566 lightMod->createPreferences();
1570 /*!Create preferences.*/
1571 void LightApp_Application::createPreferences( LightApp_Preferences* pref )
1576 int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1578 int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1579 int studyGroup = pref->addPreference( tr( "PREF_GROUP_STUDY" ), genTab );
1580 pref->setItemProperty( studyGroup, "columns", 1 );
1582 pref->addPreference( tr( "PREF_MULTI_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "multi_file" );
1583 pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "ascii_file" );
1584 int undoPref = pref->addPreference( tr( "PREF_UNDO_LEVEL" ), studyGroup, LightApp_Preferences::IntSpin, "Study", "undo_level" );
1585 pref->setItemProperty( undoPref, "min", 1 );
1586 pref->setItemProperty( undoPref, "max", 100 );
1587 pref->addPreference( tr( "PREF_STORE_POS" ), studyGroup, LightApp_Preferences::Bool, "Study", "store_positions" );
1589 int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab );
1590 pref->setItemProperty( extgroup, "columns", 1 );
1591 int apppref = pref->addPreference( tr( "PREF_APP" ), extgroup, LightApp_Preferences::File, "ExternalBrowser", "application" );
1592 pref->setItemProperty( apppref, "existing", true );
1593 pref->setItemProperty( apppref, "flags", QFileInfo::ExeUser );
1594 pref->setItemProperty( apppref, "readOnly", false );
1596 pref->addPreference( tr( "PREF_PARAM" ), extgroup, LightApp_Preferences::String, "ExternalBrowser", "parameters" );
1598 int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab );
1599 pref->setItemProperty( pythonConsoleGroup, "columns", 1 );
1600 pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, LightApp_Preferences::Font, "PyConsole", "font" );
1602 int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1604 int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1606 int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1608 int plot2dGroup = pref->addPreference( tr( "PREF_GROUP_PLOT2DVIEWER" ), viewTab );
1610 int supervGroup = pref->addPreference( tr( "PREF_GROUP_SUPERV" ), viewTab );
1612 pref->setItemProperty( occGroup, "columns", 1 );
1613 pref->setItemProperty( vtkGroup, "columns", 1 );
1614 pref->setItemProperty( plot2dGroup, "columns", 1 );
1616 int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1617 LightApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1618 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1619 LightApp_Preferences::Color, "OCCViewer", "background" );
1621 pref->setItemProperty( occTS, "min", 1 );
1622 pref->setItemProperty( occTS, "max", 150 );
1624 int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
1625 LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
1626 int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
1627 LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
1629 pref->setItemProperty( isoU, "min", 0 );
1630 pref->setItemProperty( isoU, "max", 100000 );
1632 pref->setItemProperty( isoV, "min", 0 );
1633 pref->setItemProperty( isoV, "max", 100000 );
1635 int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1636 LightApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1637 pref->addPreference( tr( "PREF_RELATIVE_SIZE" ), vtkGroup, LightApp_Preferences::Bool, "VTKViewer", "relative_size" );
1638 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1639 LightApp_Preferences::Color, "VTKViewer", "background" );
1641 pref->setItemProperty( vtkTS, "min", 1 );
1642 pref->setItemProperty( vtkTS, "max", 150 );
1644 pref->addPreference( tr( "PREF_SHOW_LEGEND" ), plot2dGroup,
1645 LightApp_Preferences::Bool, "Plot2d", "ShowLegend" );
1647 int legendPosition = pref->addPreference( tr( "PREF_LEGEND_POSITION" ), plot2dGroup,
1648 LightApp_Preferences::Selector, "Plot2d", "LegendPos" );
1649 QStringList aLegendPosList;
1650 aLegendPosList.append( tr("PREF_LEFT") );
1651 aLegendPosList.append( tr("PREF_RIGHT") );
1652 aLegendPosList.append( tr("PREF_TOP") );
1653 aLegendPosList.append( tr("PREF_BOTTOM") );
1655 QValueList<QVariant> anIndexesList;
1656 anIndexesList.append(0);
1657 anIndexesList.append(1);
1658 anIndexesList.append(2);
1659 anIndexesList.append(3);
1661 pref->setItemProperty( legendPosition, "strings", aLegendPosList );
1662 pref->setItemProperty( legendPosition, "indexes", anIndexesList );
1664 int curveType = pref->addPreference( tr( "PREF_CURVE_TYPE" ), plot2dGroup,
1665 LightApp_Preferences::Selector, "Plot2d", "CurveType" );
1666 QStringList aCurveTypesList;
1667 aCurveTypesList.append( tr("PREF_POINTS") );
1668 aCurveTypesList.append( tr("PREF_LINES") );
1669 aCurveTypesList.append( tr("PREF_SPLINE") );
1671 anIndexesList.clear();
1672 anIndexesList.append(0);
1673 anIndexesList.append(1);
1674 anIndexesList.append(2);
1676 pref->setItemProperty( curveType, "strings", aCurveTypesList );
1677 pref->setItemProperty( curveType, "indexes", anIndexesList );
1679 int markerSize = pref->addPreference( tr( "PREF_MARKER_SIZE" ), plot2dGroup,
1680 LightApp_Preferences::IntSpin, "Plot2d", "MarkerSize" );
1682 pref->setItemProperty( markerSize, "min", 0 );
1683 pref->setItemProperty( markerSize, "max", 100 );
1685 QStringList aScaleModesList;
1686 aScaleModesList.append( tr("PREF_LINEAR") );
1687 aScaleModesList.append( tr("PREF_LOGARITHMIC") );
1689 anIndexesList.clear();
1690 anIndexesList.append(0);
1691 anIndexesList.append(1);
1693 int horScale = pref->addPreference( tr( "PREF_HOR_AXIS_SCALE" ), plot2dGroup,
1694 LightApp_Preferences::Selector, "Plot2d", "HorScaleMode" );
1696 pref->setItemProperty( horScale, "strings", aScaleModesList );
1697 pref->setItemProperty( horScale, "indexes", anIndexesList );
1699 int verScale = pref->addPreference( tr( "PREF_VERT_AXIS_SCALE" ), plot2dGroup,
1700 LightApp_Preferences::Selector, "Plot2d", "VerScaleMode" );
1702 pref->setItemProperty( verScale, "strings", aScaleModesList );
1703 pref->setItemProperty( verScale, "indexes", anIndexesList );
1705 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), plot2dGroup,
1706 LightApp_Preferences::Color, "Plot2d", "Background" );
1708 int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat );
1709 int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab );
1710 pref->setItemProperty( dirGroup, "columns", 1 );
1711 pref->addPreference( tr( "" ), dirGroup,
1712 LightApp_Preferences::DirList, "FileDlg", "QuickDirList" );
1714 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), supervGroup,
1715 LightApp_Preferences::Color, "SUPERVGraph", "Background" );
1716 pref->addPreference( tr( "PREF_SUPERV_TITLE_COLOR" ), supervGroup,
1717 LightApp_Preferences::Color, "SUPERVGraph", "Title" );
1718 // pref->addPreference( tr( "PREF_SUPERV_CTRL_COLOR" ), supervGroup,
1719 // LightApp_Preferences::Color, "SUPERVGraph", "Ctrl" );
1721 int obTab = pref->addPreference( tr( "PREF_TAB_OBJBROWSER" ), salomeCat );
1722 int objSetGroup = pref->addPreference( tr( "PREF_OBJ_BROWSER_SETTINGS" ), obTab );
1723 pref->addPreference( tr( "PREF_AUTO_SIZE_FIRST" ), objSetGroup, LightApp_Preferences::Bool,
1724 "ObjectBrowser", "auto_size_first" );
1725 pref->addPreference( tr( "PREF_AUTO_SIZE" ), objSetGroup, LightApp_Preferences::Bool,
1726 "ObjectBrowser", "auto_size" );
1729 /*!Changed preferences */
1730 void LightApp_Application::preferencesChanged( const QString& sec, const QString& param )
1732 SUIT_ResourceMgr* resMgr = resourceMgr();
1736 #ifndef DISABLE_OCCVIEWER
1737 if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1739 int sz = resMgr->integerValue( sec, param, -1 );
1740 QPtrList<SUIT_ViewManager> lst;
1741 viewManagers( OCCViewer_Viewer::Type(), lst );
1742 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1744 SUIT_ViewModel* vm = it.current()->getViewModel();
1745 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1748 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1749 occVM->setTrihedronSize( sz );
1750 occVM->getAISContext()->UpdateCurrentViewer();
1755 #ifndef DISABLE_VTKVIEWER
1756 if ( sec == QString( "VTKViewer" ) && (param == QString( "trihedron_size" ) || param == QString( "relative_size" )) )
1758 int sz = resMgr->integerValue( "VTKViewer", "trihedron_size", -1 );
1759 bool isRelative = resMgr->booleanValue( "VTKViewer", "relative_size", true );
1760 QPtrList<SUIT_ViewManager> lst;
1761 #ifndef DISABLE_SALOMEOBJECT
1762 viewManagers( SVTK_Viewer::Type(), lst );
1763 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1765 SUIT_ViewModel* vm = it.current()->getViewModel();
1766 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
1769 SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
1772 vtkVM->setTrihedronSize( sz, isRelative );
1780 #ifndef DISABLE_OCCVIEWER
1781 if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
1783 QPtrList<SUIT_ViewManager> lst;
1784 viewManagers( OCCViewer_Viewer::Type(), lst );
1785 int u = resMgr->integerValue( sec, "iso_number_u" );
1786 int v = resMgr->integerValue( sec, "iso_number_v" );
1787 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
1789 OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>( it.current() );
1790 if( mgr && mgr->getOCCViewer() )
1791 mgr->getOCCViewer()->setIsos( u, v );
1796 if( sec=="ObjectBrowser" )
1798 if( param=="auto_size" || param=="auto_size_first" )
1800 OB_Browser* ob = objectBrowser();
1804 bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false ),
1805 autoSizeFirst = resMgr->booleanValue( "ObjectBrowser", "auto_size_first", true );
1806 ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1807 ob->listView()->setColumnWidthMode( 0, autoSizeFirst ? QListView::Maximum : QListView::Manual );
1808 updateObjectBrowser( false );
1814 if( param=="store_positions" )
1818 #ifndef DISABLE_PYCONSOLE
1819 if( sec=="PyConsole" )
1822 if( pythonConsole() )
1823 pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1828 /*!Save preferences */
1829 void LightApp_Application::savePreferences()
1831 saveWindowsGeometry();
1833 if ( resourceMgr() )
1836 desktop()->saveGeometry( resourceMgr(), "desktop" );
1837 resourceMgr()->save();
1841 /*!Update desktop title.*/
1842 void LightApp_Application::updateDesktopTitle() {
1843 QString aTitle = applicationName();
1844 QString aVer = applicationVersion();
1845 if ( !aVer.isEmpty() )
1846 aTitle += QString( " " ) + aVer;
1848 if ( activeStudy() ) {
1849 QString sName = SUIT_Tools::file( activeStudy()->studyName().stripWhiteSpace(), false );
1850 aTitle += QString( " - [%1]" ).arg( sName );
1853 desktop()->setCaption( aTitle );
1856 /*!Update windows after close document.*/
1857 void LightApp_Application::afterCloseDoc()
1861 CAM_Application::afterCloseDoc();
1864 /*!Update module action.*/
1865 void LightApp_Application::updateModuleActions()
1868 if ( activeModule() )
1869 modName = activeModule()->moduleName();
1871 if ( myActions.contains( modName ) )
1872 myActions[modName]->setOn( true );
1875 /*!Gets current windows.
1876 *\param winMap - output current windows map.
1878 void LightApp_Application::currentWindows( QMap<int, int>& winMap ) const
1881 if ( !activeStudy() )
1884 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
1885 ((LightApp_Module*)activeModule())->windows( winMap );
1887 defaultWindows( winMap );
1890 /*!Gets current view managers.
1891 *\param lst - output current view managers list.
1893 void LightApp_Application::currentViewManagers( QStringList& lst ) const
1896 if ( !activeStudy() )
1899 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
1900 ((LightApp_Module*)activeModule())->viewManagers( lst );
1902 defaultViewManagers( lst );
1905 /*!Update windows.*/
1906 void LightApp_Application::updateWindows()
1908 QMap<int, int> winMap;
1909 currentWindows( winMap );
1911 if ( activeStudy() ) {
1912 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1913 getWindow( it.key() );
1915 loadWindowsGeometry();
1918 // setWindowShown should be done even if no study is active (open). in this case all open windows
1919 // will be hidden, which is neccessary in this case.
1920 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1921 setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1924 /*!Update view managers.*/
1925 void LightApp_Application::updateViewManagers()
1928 currentViewManagers( lst );
1930 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1931 getViewManager( *it, true );
1934 /*!Load windows geometry.*/
1935 void LightApp_Application::loadWindowsGeometry()
1937 bool store = resourceMgr()->booleanValue( "Study", "store_positions", true );
1941 QtxDockAction* dockMgr = 0;
1943 QAction* a = action( ViewWindowsId );
1944 if ( a && a->inherits( "QtxDockAction" ) )
1945 dockMgr = (QtxDockAction*)a;
1951 if ( activeModule() )
1952 modName = activeModule()->name("");
1954 QString section = QString( "windows_geometry" );
1955 if ( !modName.isEmpty() )
1956 section += QString( "." ) + modName;
1958 dockMgr->loadGeometry( resourceMgr(), section, false );
1959 dockMgr->restoreGeometry();
1962 /*!Save windows geometry.*/
1963 void LightApp_Application::saveWindowsGeometry()
1965 bool store = resourceMgr()->booleanValue( "Study", "store_positions", true );
1969 QtxDockAction* dockMgr = 0;
1971 QAction* a = action( ViewWindowsId );
1972 if ( a && a->inherits( "QtxDockAction" ) )
1973 dockMgr = (QtxDockAction*)a;
1979 if ( activeModule() )
1980 modName = activeModule()->name("");
1982 QString section = QString( "windows_geometry" );
1983 if ( !modName.isEmpty() )
1984 section += QString( "." ) + modName;
1986 dockMgr->storeGeometry();
1987 dockMgr->saveGeometry( resourceMgr(), section, false );
1990 /*!Activate windows.*/
1991 void LightApp_Application::activateWindows()
1993 if ( activeStudy() )
1995 for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1996 itr.data()->activate( activeStudy()->id() );
2000 /*!Adds icon names for modules.*/
2001 void LightApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
2005 SUIT_ResourceMgr* resMgr = resourceMgr();
2009 QStringList modList;
2010 modules( modList, false );
2012 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
2014 QString modName = *it;
2015 QString modIntr = moduleName( modName );
2016 QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
2018 if ( modIcon.isEmpty() )
2021 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
2022 modIcon += QString( ".png" );
2024 iconMap.insert( modName, modIcon );
2028 /*!Insert items in popup, which necessary for current application*/
2029 void LightApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
2031 CAM_Application::contextMenuPopup( type, thePopup, title );
2033 OB_Browser* ob = objectBrowser();
2034 if ( !ob || type != ob->popupClientType() )
2037 thePopup->insertSeparator();
2038 thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
2041 /*!Create empty study.*/
2042 void LightApp_Application::createEmptyStudy()
2044 CAM_Application::createEmptyStudy();
2045 if ( objectBrowser() )
2046 objectBrowser()->updateTree();
2049 /*!Activate module \a mod.*/
2050 bool LightApp_Application::activateModule( CAM_Module* mod )
2052 bool res = CAM_Application::activateModule( mod );
2053 if ( objectBrowser() )
2054 objectBrowser()->updateTree();
2058 /*!return keyborad accelerators manager object */
2059 SUIT_Accel* LightApp_Application::accel() const
2064 /*! remove dead widget container from map */
2065 void LightApp_Application::onWCDestroyed( QObject* ob )
2067 // remove destroyed widget container from windows map
2068 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
2070 if ( itr.data() != ob )
2073 int key = itr.key();
2074 myWindows.remove( key );
2079 /*! redefined to remove view manager from memory */
2080 void LightApp_Application::removeViewManager( SUIT_ViewManager* vm )
2082 disconnect( vm, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
2083 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
2084 STD_Application::removeViewManager( vm );
2088 /*! rename active window of desktop */
2089 void LightApp_Application::onRenameWindow()
2094 QWidget* w = desktop()->activeWindow();
2099 QString name = QInputDialog::getText( tr( "TOT_RENAME" ), tr( "PRP_RENAME" ), QLineEdit::Normal, w->caption(), &ok, w );
2100 if( ok && !name.isEmpty() )
2101 w->setCaption( name );
2104 bool LightApp_Application::isLibExists( const QString& moduleTitle ) const
2106 if( moduleTitle.isEmpty() )
2109 QString lib = moduleLibrary( moduleTitle );
2112 paths = QStringList::split( ";", ::getenv( "PATH" ) );
2114 paths = QStringList::split( ":", ::getenv( "LD_LIBRARY_PATH" ) );
2117 QStringList::const_iterator anIt = paths.begin(), aLast = paths.end();
2118 for( ; anIt!=aLast; anIt++ )
2120 QFileInfo inf( Qtx::addSlash( *anIt ) + lib );
2127 /*! default name for an active study */
2128 void LightApp_Application::setDefaultStudyName( const QString& theName )
2130 QStringList anInfoList;
2131 modules( anInfoList, false );
2133 LightApp_Study* aStudy = (LightApp_Study*)activeStudy();
2134 if( anInfoList.count() == 1 && // to avoid a conflict between different modules
2135 !aStudy->isSaved() )
2137 aStudy->setStudyName( theName );
2138 updateDesktopTitle();