1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // File: LightApp_Application.cxx
20 // Created: 6/20/2005 18:39:45 PM
21 // Author: Natalia Donis
22 // Copyright (C) CEA 2005
24 #ifndef DISABLE_PYCONSOLE
25 #include "PythonConsole_PyInterp.h" // WARNING! This include must be the first!
26 #include <PythonConsole_PyConsole.h>
29 #include "LightApp_Application.h"
30 #include "LightApp_WidgetContainer.h"
31 #include "LightApp_Module.h"
32 #include "LightApp_DataModel.h"
33 #include "LightApp_Study.h"
34 #include "LightApp_Preferences.h"
35 #include "LightApp_PreferencesDlg.h"
36 #include "LightApp_ModuleDlg.h"
37 #include "LightApp_AboutDlg.h"
39 #include "LightApp_OBFilter.h"
41 #include "LightApp_EventFilter.h"
43 #include "LightApp_OBSelector.h"
44 #include "LightApp_SelectionMgr.h"
45 #include "LightApp_DataObject.h"
47 #include <CAM_Module.h>
48 #include <CAM_DataModel.h>
49 #include <CAM_Study.h>
50 #include <STD_TabDesktop.h>
52 #include <SUIT_Session.h>
53 #include <SUIT_Study.h>
54 #include <SUIT_FileDlg.h>
55 #include <SUIT_ResourceMgr.h>
56 #include <SUIT_Tools.h>
57 #include <SUIT_Accel.h>
59 #include <QtxMRUAction.h>
60 #include <QtxDockAction.h>
61 #include <QtxToolBar.h>
64 #include <LogWindow.h>
65 #include <OB_Browser.h>
66 #include <OB_ListView.h>
67 #include <OB_ObjSearch.h>
69 #ifndef DISABLE_GLVIEWER
70 #include <GLViewer_Viewer.h>
71 #include <GLViewer_ViewManager.h>
72 #include "LightApp_GLSelector.h"
75 #ifndef DISABLE_PLOT2DVIEWER
76 #include <Plot2d_ViewManager.h>
77 #include <Plot2d_ViewModel.h>
78 #ifndef DISABLE_SALOMEOBJECT
79 #include <SPlot2d_ViewModel.h>
81 #include <Plot2d_ViewModel.h>
85 #ifndef DISABLE_OCCVIEWER
86 #include <OCCViewer_ViewManager.h>
87 #ifndef DISABLE_SALOMEOBJECT
88 #include <SOCC_ViewModel.h>
90 #include <OCCViewer_ViewModel.h>
92 #include "LightApp_OCCSelector.h"
95 #ifndef DISABLE_VTKVIEWER
96 #ifndef DISABLE_SALOMEOBJECT
97 #include <SVTK_ViewModel.h>
98 #include <SVTK_ViewManager.h>
99 #include "LightApp_VTKSelector.h"
101 #include <VTKViewer_ViewModel.h>
102 #include <VTKViewer_ViewManager.h>
104 #include <VTKViewer_ViewModel.h>
107 //#ifndef DISABLE_SUPERVGRAPHVIEWER
108 // #include <SUPERVGraph_ViewModel.h>
109 // #include <SUPERVGraph_ViewFrame.h>
110 // #include <SUPERVGraph_ViewManager.h>
113 #ifndef DISABLE_QXGRAPHVIEWER
114 #include <QxGraph_ViewModel.h>
115 #include <QxGraph_ViewWindow.h>
116 #include <QxGraph_ViewManager.h>
119 #include <QtxWorkstack.h>
125 #include <qstringlist.h>
127 #include <qapplication.h>
129 #include <qstatusbar.h>
131 #include <qobjectlist.h>
132 #include <qcombobox.h>
133 #include <qinputdialog.h>
134 #include <qmessagebox.h>
135 #include <qfontdatabase.h>
137 #define FIRST_HELP_ID 1000000
139 #ifndef DISABLE_SALOMEOBJECT
140 #include "SALOME_InteractiveObject.hxx"
141 #include "SALOME_ListIO.hxx"
144 static const char* imageEmptyIcon[] = {
147 "....................",
148 "....................",
149 "....................",
150 "....................",
151 "....................",
152 "....................",
153 "....................",
154 "....................",
155 "....................",
156 "....................",
157 "....................",
158 "....................",
159 "....................",
160 "....................",
161 "....................",
162 "....................",
163 "....................",
164 "....................",
165 "....................",
166 "...................."};
168 int LightApp_Application::lastStudyId = 0;
171 \return last global id of study
173 int LightApp_Application::studyId()
175 return LightApp_Application::lastStudyId;
178 /*!Create new instance of LightApp_Application.*/
179 extern "C" LIGHTAPP_EXPORT SUIT_Application* createApplication()
181 return new LightApp_Application();
184 /*! \var global preferences of LightApp */
185 LightApp_Preferences* LightApp_Application::_prefs_ = 0;
188 \class LightApp_Application
189 Application containing LightApp module
193 LightApp_Application::LightApp_Application()
194 : CAM_Application( false ),
197 STD_TabDesktop* desk = new STD_TabDesktop();
201 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
202 QPixmap aLogo = aResMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false );
204 desktop()->setIcon( aLogo );
205 desktop()->setDockableMenuBar( true );
206 desktop()->setDockableStatusBar( false );
208 // base logo (salome itself)
209 desktop()->addLogo( "_app_base", aResMgr->loadPixmap( "LightApp", tr( "APP_BASE_LOGO" ), false ) );
210 // extra logo (salome-based application)
211 desktop()->addLogo( "_app_extra", aResMgr->loadPixmap( "LightApp", tr( "APP_EXTRA_LOGO" ), false ) );
215 mySelMgr = new LightApp_SelectionMgr( this );
217 myAccel = SUIT_Accel::getAccel();
219 #ifndef DISABLE_OCCVIEWER
220 myAccel->setActionKey( SUIT_Accel::PanLeft, CTRL+Key_Left, OCCViewer_Viewer::Type() );
221 myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, OCCViewer_Viewer::Type() );
222 myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, OCCViewer_Viewer::Type() );
223 myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, OCCViewer_Viewer::Type() );
224 myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, OCCViewer_Viewer::Type() );
225 myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, OCCViewer_Viewer::Type() );
226 myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, OCCViewer_Viewer::Type() );
227 myAccel->setActionKey( SUIT_Accel::RotateLeft, ALT+Key_Left, OCCViewer_Viewer::Type() );
228 myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right, OCCViewer_Viewer::Type() );
229 myAccel->setActionKey( SUIT_Accel::RotateUp, ALT+Key_Up, OCCViewer_Viewer::Type() );
230 myAccel->setActionKey( SUIT_Accel::RotateDown, ALT+Key_Down, OCCViewer_Viewer::Type() );
232 #ifndef DISABLE_VTKVIEWER
233 myAccel->setActionKey( SUIT_Accel::PanLeft, CTRL+Key_Left, VTKViewer_Viewer::Type() );
234 myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, VTKViewer_Viewer::Type() );
235 myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, VTKViewer_Viewer::Type() );
236 myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, VTKViewer_Viewer::Type() );
237 myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, VTKViewer_Viewer::Type() );
238 myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, VTKViewer_Viewer::Type() );
239 myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, VTKViewer_Viewer::Type() );
240 myAccel->setActionKey( SUIT_Accel::RotateLeft, ALT+Key_Left, VTKViewer_Viewer::Type() );
241 myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right, VTKViewer_Viewer::Type() );
242 myAccel->setActionKey( SUIT_Accel::RotateUp, ALT+Key_Up, VTKViewer_Viewer::Type() );
243 myAccel->setActionKey( SUIT_Accel::RotateDown, ALT+Key_Down, VTKViewer_Viewer::Type() );
245 #ifndef DISABLE_PLOT2DVIEWER
246 myAccel->setActionKey( SUIT_Accel::PanLeft, CTRL+Key_Left, Plot2d_Viewer::Type() );
247 myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, Plot2d_Viewer::Type() );
248 myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, Plot2d_Viewer::Type() );
249 myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, Plot2d_Viewer::Type() );
250 myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, Plot2d_Viewer::Type() );
251 myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, Plot2d_Viewer::Type() );
252 myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, Plot2d_Viewer::Type() );
255 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) );
257 // Set existing font for the python console in resources
258 if( !aResMgr->hasValue( "PyConsole", "font" ) )
261 QFont f = aResMgr->fontValue( "PyConsole", "font" );
263 QStringList famdb = fdb.families();
265 if ( famdb.contains(f.family()) || !aResMgr->hasValue( "PyConsole", "additional_families" ) )
268 QStringList anAddFamilies = QStringList::split( ";", aResMgr->stringValue( "PyConsole", "additional_families" ) );
270 for ( QStringList::Iterator it = anAddFamilies.begin(); it != anAddFamilies.end(); ++it )
273 if ( famdb.contains(aFamily) )
275 f.setFamily( aFamily );
276 aResMgr->setValue( "PyConsole", "font", f );
283 *\li Save window geometry.
284 *\li Save desktop geometry.
285 *\li Save resource maneger.
286 *\li Delete selection manager.
288 LightApp_Application::~LightApp_Application()
293 /*!Start application.*/
294 void LightApp_Application::start()
297 desktop()->loadGeometry( resourceMgr(), "desktop" );
299 CAM_Application::start();
301 QAction* a = action( ViewWindowsId );
302 if ( a && a->inherits( "QtxDockAction" ) )
303 ((QtxDockAction*)a)->setAutoPlace( true );
306 updateViewManagers();
309 desktop()->statusBar()->message( "" );
311 LightApp_EventFilter::Init();
314 /*!Gets application name.*/
315 QString LightApp_Application::applicationName() const
317 return tr( "APP_NAME" );
320 /*!Gets application version.*/
321 QString LightApp_Application::applicationVersion() const
323 static QString _app_version;
325 if ( _app_version.isEmpty() )
327 QString resVersion = tr( "APP_VERSION" );
328 if ( resVersion != "APP_VERSION" )
330 _app_version = resVersion;
334 QString path( ::getenv( "GUI_ROOT_DIR" ) );
335 if ( !path.isEmpty() )
336 path += QDir::separator();
337 path += QString( "bin/salome/VERSION" );
340 if ( vf.open( IO_ReadOnly ) )
343 vf.readLine( line, 1024 );
346 if ( !line.isEmpty() )
348 while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
349 line.remove( line.length() - 1, 1 );
351 int idx = line.findRev( ":" );
353 _app_version = line.mid( idx + 1 ).stripWhiteSpace();
361 /*!Load module by \a name.*/
362 CAM_Module* LightApp_Application::loadModule( const QString& name )
364 CAM_Module* mod = CAM_Application::loadModule( name );
367 connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) );
368 connect( this, SIGNAL( studySaved() ), mod, SLOT( onModelSaved() ) );
369 connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) );
374 /*!Activate module by \a modName*/
375 bool LightApp_Application::activateModule( const QString& modName )
378 CAM_Module* prevMod = activeModule();
381 actName = prevMod->moduleName();
383 if ( actName == modName )
386 putInfo( tr( "ACTIVATING_MODULE" ).arg( modName ) );
388 saveWindowsGeometry();
390 bool status = CAM_Application::activateModule( modName );
392 updateModuleActions();
400 updateViewManagers();
406 Opens other study into active Study. If Study is empty - creates it.
407 \param theName - name of study
409 bool LightApp_Application::useStudy(const QString& theName)
412 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>(activeStudy());
415 res = aStudy->loadDocument( theName );
416 updateDesktopTitle();
417 updateCommandsStatus();
421 /*!Gets selection manager.*/
422 LightApp_SelectionMgr* LightApp_Application::selectionMgr() const
427 /*!Creat action "New window" for certain type of viewer:*/
428 void LightApp_Application::createActionForViewer( const int id,
430 const QString& suffix,
433 QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( suffix ) ), QIconSet(),
434 tr( QString( "NEW_WINDOW_%1" ).arg( suffix ) ),
435 tr( QString( "NEW_WINDOW_%1" ).arg( suffix ) ),
436 accel, desktop(), false, this, SLOT( onNewWindow() ) );
437 createMenu( a, parentId, -1 );
441 void LightApp_Application::createActions()
443 STD_Application::createActions();
445 SUIT_Desktop* desk = desktop();
446 SUIT_ResourceMgr* resMgr = resourceMgr();
449 createAction( PreferencesId, tr( "TOT_DESK_PREFERENCES" ), QIconSet(),
450 tr( "MEN_DESK_PREFERENCES" ), tr( "PRP_DESK_PREFERENCES" ),
451 CTRL+Key_F, desk, false, this, SLOT( onPreferences() ) );
454 int helpMenu = createMenu( tr( "MEN_DESK_HELP" ), -1, -1, 1000 );
455 int helpModuleMenu = createMenu( tr( "MEN_DESK_MODULE_HELP" ), helpMenu, -1, 0 );
456 createMenu( separator(), helpMenu, -1, 1 );
458 QStringList aModuleList;
459 modules( aModuleList, false );
461 int id = LightApp_Application::UserID + FIRST_HELP_ID;
462 // help for KERNEL and GUI
464 QString aFileName = "index.html";
467 if (dir = getenv("GUI_ROOT_DIR")) {
468 root = Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("share") + Qtx::addSlash("doc") +
469 Qtx::addSlash("salome") + Qtx::addSlash("gui") + Qtx::addSlash("GUI") );
470 if ( QFileInfo( root + aFileName ).exists() ) {
471 a = createAction( id, tr( QString("GUI Help") ), QIconSet(),
472 tr( QString("GUI Help") ),
473 tr( QString("GUI Help") ),
474 0, desk, false, this, SLOT( onHelpContentsModule() ) );
475 a->setName( QString("GUI") );
476 createMenu( a, helpModuleMenu, -1 );
480 if (dir = getenv("KERNEL_ROOT_DIR")) {
481 root = Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("share") + Qtx::addSlash("doc") +
482 Qtx::addSlash("salome") );
483 if ( QFileInfo( root + aFileName ).exists() ) {
484 a = createAction( id, tr( QString("KERNEL Help") ), QIconSet(),
485 tr( QString("KERNEL Help") ),
486 tr( QString("KERNEL Help") ),
487 0, desk, false, this, SLOT( onHelpContentsModule() ) );
488 a->setName( QString("KERNEL") );
489 createMenu( a, helpModuleMenu, -1 );
493 // help for other existing modules
494 QStringList::Iterator it;
495 for ( it = aModuleList.begin(); it != aModuleList.end(); ++it )
497 if ( (*it).isEmpty() )
500 QString modName = moduleName( *it );
502 if (dir = getenv( modName + "_ROOT_DIR")) {
503 root = Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("share") + Qtx::addSlash("doc") +
504 Qtx::addSlash("salome") + Qtx::addSlash("gui") + Qtx::addSlash(modName) );
505 if ( QFileInfo( root + aFileName ).exists() ) {
507 QAction* a = createAction( id, tr( moduleTitle(modName) + QString(" Help") ), QIconSet(),
508 tr( moduleTitle(modName) + QString(" Help") ),
509 tr( moduleTitle(modName) + QString(" Help") ),
510 0, desk, false, this, SLOT( onHelpContentsModule() ) );
511 a->setName( modName );
512 createMenu( a, helpModuleMenu, -1 );
519 QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), desk );
520 connect( mru, SIGNAL( activated( QString ) ), this, SLOT( onMRUActivated( QString ) ) );
521 registerAction( MRUId, mru );
523 // default icon for neutral point ('SALOME' module)
524 QPixmap defIcon = resMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false );
525 if ( defIcon.isNull() )
526 defIcon = QPixmap( imageEmptyIcon );
528 //! default icon for any module
529 QPixmap modIcon = resMgr->loadPixmap( "LightApp", tr( "APP_MODULE_ICO" ), false );
530 if ( modIcon.isNull() )
531 modIcon = QPixmap( imageEmptyIcon );
534 modules( modList, false );
536 if( modList.count()>1 )
538 QToolBar* modTBar = new QtxToolBar( true, desk );
539 modTBar->setLabel( tr( "INF_TOOLBAR_MODULES" ) );
541 QActionGroup* modGroup = new QActionGroup( this );
542 modGroup->setExclusive( true );
543 modGroup->setUsesDropDown( true );
545 a = createAction( -1, tr( "APP_NAME" ), defIcon, tr( "APP_NAME" ),
546 tr( "PRP_APP_MODULE" ), 0, desk, true );
548 myActions.insert( QString(), a );
550 QMap<QString, QString> iconMap;
551 moduleIconNames( iconMap );
553 const int iconSize = 20;
555 modGroup->addTo( modTBar );
556 QObjectList *l = modTBar->queryList( "QComboBox" );
557 QObjectListIt oit( *l );
558 while ( QObject* obj = oit.current() ) {
559 QComboBox* cb = (QComboBox*)obj;
560 if ( cb ) cb->setFocusPolicy( QWidget::NoFocus );
565 modTBar->addSeparator();
567 for ( it = modList.begin(); it != modList.end(); ++it )
569 if ( !isLibExists( *it ) )
573 if ( iconMap.contains( *it ) )
574 iconName = iconMap[*it];
576 QString modName = moduleName( *it );
578 QPixmap icon = resMgr->loadPixmap( modName, iconName, false );
582 printf( "****************************************************************\n" );
583 printf( "* Icon for %s not found. Using the default one.\n", (*it).latin1() );
584 printf( "****************************************************************\n" );
587 icon.convertFromImage( icon.convertToImage().smoothScale( iconSize, iconSize, QImage::ScaleMin ) );
589 QAction* a = createAction( -1, *it, icon, *it, tr( "PRP_MODULE" ).arg( *it ), 0, desk, true );
593 myActions.insert( *it, a );
596 SUIT_Tools::simplifySeparators( modTBar );
597 connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) );
601 int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, MenuWindowId, 100 );
602 int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
603 createMenu( separator(), windowMenu, -1, 1 );
606 #ifndef DISABLE_GLVIEWER
607 createActionForViewer( NewGLViewId, newWinMenu, QString::number( 0 ), ALT+Key_G );
609 #ifndef DISABLE_PLOT2DVIEWER
610 createActionForViewer( NewPlot2dId, newWinMenu, QString::number( 1 ), ALT+Key_P );
612 #ifndef DISABLE_OCCVIEWER
613 createActionForViewer( NewOCCViewId, newWinMenu, QString::number( 2 ), ALT+Key_O );
615 #ifndef DISABLE_VTKVIEWER
616 createActionForViewer( NewVTKViewId, newWinMenu, QString::number( 3 ), ALT+Key_K );
618 #ifndef DISABLE_QXGRAPHVIEWER
619 createActionForViewer( NewQxGraphViewId, newWinMenu, QString::number( 4 ), ALT+Key_C );
623 createAction( RenameId, tr( "TOT_RENAME" ), QIconSet(), tr( "MEN_DESK_RENAME" ), tr( "PRP_RENAME" ),
624 SHIFT+Key_R, desk, false, this, SLOT( onRenameWindow() ) );
625 createMenu( RenameId, windowMenu, -1 );
627 int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
628 createMenu( PreferencesId, fileMenu, 15, -1 );
629 createMenu( separator(), fileMenu, -1, 15, -1 );
632 createMenu( separator(), fileMenu, -1, 100, -1 );
633 createMenu( MRUId, fileMenu, 100, -1 );
634 createMenu( separator(), fileMenu, -1, 100, -1 );
638 /*!On module activation action.*/
639 void LightApp_Application::onModuleActivation( QAction* a )
644 QString modName = a->menuText();
645 if ( modName == tr( "APP_NAME" ) )
646 modName = QString::null;
648 // Force user to create/open a study before module activation
649 QMap<QString, QString> iconMap;
650 moduleIconNames( iconMap );
651 QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ], false );
653 icon = resourceMgr()->loadPixmap( "LightApp", tr( "APP_MODULE_BIG_ICO" ), false ); // default icon for any module
655 bool cancelled = false;
656 while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
657 LightApp_ModuleDlg aDlg( desktop(), modName, icon );
658 QMap<int, QString> opmap = activateModuleActions();
659 for ( QMap<int, QString>::ConstIterator it = opmap.begin(); it != opmap.end(); ++it )
660 aDlg.addButton( it.data(), it.key() );
662 int res = aDlg.exec();
663 if ( res != QDialog::Rejected ) {
664 // some operation is selected
665 moduleActionSelected( res );
668 putInfo( tr("INF_CANCELLED") );
669 myActions[QString()]->setOn( true );
675 activateModule( modName );
678 /*!Default module activation.*/
679 QString LightApp_Application::defaultModule() const
681 QStringList aModuleNames;
682 modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration
683 //! If there's the one and only module --> activate it automatically
684 //! TODO: Possible improvement - default module can be taken from preferences
685 return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" );
688 /*!On new window slot.*/
689 void LightApp_Application::onNewWindow()
691 const QObject* obj = sender();
692 if ( !obj || !obj->inherits( "QAction" ) )
696 int id = actionId( (QAction*)obj );
699 #ifndef DISABLE_GLVIEWER
701 type = GLViewer_Viewer::Type();
704 #ifndef DISABLE_PLOT2DVIEWER
706 type = Plot2d_Viewer::Type();
709 #ifndef DISABLE_OCCVIEWER
711 type = OCCViewer_Viewer::Type();
714 #ifndef DISABLE_VTKVIEWER
716 type = VTKViewer_Viewer::Type();
719 #ifndef DISABLE_QXGRAPHVIEWER
720 case NewQxGraphViewId:
721 type = QxGraph_Viewer::Type();
726 if ( !type.isEmpty() )
727 createViewManager( type );
731 SLOT: Creates new document
733 void LightApp_Application::onNewDoc()
735 SUIT_Study* study = activeStudy();
737 saveWindowsGeometry();
739 CAM_Application::onNewDoc();
741 if ( !study ) // new study will be create in THIS application
744 updateViewManagers();
749 SLOT: Opens new document
751 void LightApp_Application::onOpenDoc()
753 SUIT_Study* study = activeStudy();
754 saveWindowsGeometry();
756 CAM_Application::onOpenDoc();
758 if ( !study ) // new study will be create in THIS application
761 updateViewManagers();
765 #include "SUIT_MessageBox.h"
768 SLOT: Opens new document.
769 \param aName - name of file
771 bool LightApp_Application::onOpenDoc( const QString& aName )
773 bool isAlreadyOpen = false;
775 // Look among opened studies
776 if (activeStudy()) { // at least one study is opened
777 SUIT_Session* aSession = SUIT_Session::session();
778 QPtrList<SUIT_Application> aAppList = aSession->applications();
779 QPtrListIterator<SUIT_Application> it (aAppList);
780 SUIT_Application* aApp = 0;
781 // iterate on all applications
782 for (; (aApp = it.current()) && !isAlreadyOpen; ++it) {
783 if (aApp->activeStudy()->studyName() == aName) {
784 isAlreadyOpen = true; // Already opened, ask user what to do
786 // The document ... is already open.
787 // Do you want to reload it?
788 int aAnswer = SUIT_MessageBox::warn2(desktop(), tr("WRN_WARNING"),
789 tr("QUE_DOC_ALREADYOPEN").arg(aName),
790 tr("BUT_YES"), tr("BUT_NO"), 1, 2, 2);
791 if (aAnswer == 1) { // reload
792 if (activeStudy()->studyName() == aName && aAppList.count() > 1) {
793 // Opened in THIS (active) application.
794 STD_Application* app1 = (STD_Application*)aAppList.at(0);
795 STD_Application* app2 = (STD_Application*)aAppList.at(1);
796 if (!app1 || !app2) {
800 if (app1->activeStudy()->studyName() == aName) {
801 // app1 is this application, we need another one
804 // Close document of this application. This application will be destroyed.
805 onCloseDoc(/*ask = */false);
806 // Open the file with another application, as this one will be destroyed.
807 return app1->onOpenDoc(aName);
809 // Opened in another application.
810 STD_Application* app = (STD_Application*)aApp;
812 app->onCloseDoc(/*ask = */false);
814 } else { // do not reload
815 // OK, the study will not be reloaded, but we call
816 // CAM_Application::onOpenDoc( aName ) all the same.
817 // It will activate a desktop of the study <aName>.
823 bool res = CAM_Application::onOpenDoc( aName );
825 QAction* a = action( MRUId );
826 if ( a && a->inherits( "QtxMRUAction" ) )
828 QtxMRUAction* mru = (QtxMRUAction*)a;
830 mru->insert( aName );
832 mru->remove( aName );
838 SLOT: Displays "About" message box
840 void LightApp_Application::onHelpAbout()
842 LightApp_AboutDlg* dlg = new LightApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
849 \param aName - name of document
851 bool LightApp_Application::onLoadDoc( const QString& aName )
853 bool res = CAM_Application::onLoadDoc( aName );
855 /*jfa tmp:QAction* a = action( MRUId );
856 if ( a && a->inherits( "QtxMRUAction" ) )
858 QtxMRUAction* mru = (QtxMRUAction*)a;
860 mru->insert( aName );
862 mru->remove( aName );
868 Private SLOT: Called on selection is changed
869 Dispatchs active module that selection is changed
871 void LightApp_Application::onSelection()
873 onSelectionChanged();
875 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
876 ((LightApp_Module*)activeModule())->selectionChanged();
881 \param study - SUIT_Study.
883 void LightApp_Application::setActiveStudy( SUIT_Study* study )
885 CAM_Application::setActiveStudy( study );
891 Enables/Disables menu items and toolbar buttons. Rebuild menu
893 void LightApp_Application::updateCommandsStatus()
895 CAM_Application::updateCommandsStatus();
898 #ifndef DISABLE_GLVIEWER
899 a = action( NewGLViewId );
901 a->setEnabled( activeStudy() );
904 #ifndef DISABLE_PLOT2DVIEWER
905 a = action( NewPlot2dId );
907 a->setEnabled( activeStudy() );
910 #ifndef DISABLE_OCCVIEWER
911 a = action( NewOCCViewId );
913 a->setEnabled( activeStudy() );
916 #ifndef DISABLE_VTKVIEWER
917 a = action( NewVTKViewId );
919 a->setEnabled( activeStudy() );
922 #ifndef DISABLE_QXGRAPHVIEWER
923 a = action( NewQxGraphViewId );
925 a->setEnabled( activeStudy() );
931 Runs system command in separate thread
933 class RunBrowser: public QThread
936 RunBrowser (LightApp_Application* app, QString theApp, QString theParams,
937 QString theHelpFile, QString theContext=NULL)
938 : myApp(theApp), myParams(theParams),
940 myHelpFile("file://" + theHelpFile + theContext),
942 myHelpFile("file:" + theHelpFile + theContext),
953 if (!myApp.isEmpty())
955 //aCommand.sprintf("%s %s %s",myApp.latin1(),myParams.latin1(),myHelpFile.latin1());
957 //QProcess* proc = new QProcess();
958 //proc->addArgument( aCommand );
960 QProcess* proc = new QProcess();
961 proc->addArgument( myApp );
962 if (!myParams.isEmpty()) proc->addArgument( myParams );
963 proc->addArgument( myHelpFile );
964 //myStatus = system(aCommand);
969 QCustomEvent* ce2000 = new QCustomEvent( 2000 );
970 QString* msg = new QString( QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").arg(myApp).arg(myHelpFile) );
971 ce2000->setData( msg );
972 postEvent( myLApp, ce2000 );
982 LightApp_Application* myLApp;
986 SLOT: Displays help contents for choosen module
988 void LightApp_Application::onHelpContentsModule()
990 const QAction* obj = (QAction*) sender();
992 QString aComponentName = obj->name();
993 QString aFileName = "index.html";
995 QCString dir = getenv( aComponentName + "_ROOT_DIR");
996 QString homeDir = !aComponentName.compare(QString("KERNEL")) ?
997 Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("share") + Qtx::addSlash("doc") + Qtx::addSlash("salome") ) :
998 Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("share") + Qtx::addSlash("doc") + Qtx::addSlash("salome") + Qtx::addSlash("gui") + Qtx::addSlash(aComponentName) );
1000 QString helpFile = QFileInfo( homeDir + aFileName ).absFilePath();
1001 SUIT_ResourceMgr* resMgr = resourceMgr();
1004 platform = "winapplication";
1006 platform = "application";
1008 QString anApp = resMgr->stringValue("ExternalBrowser", platform);
1010 QString quote("\"");
1011 anApp.prepend( quote );
1012 anApp.append( quote );
1014 QString aParams = resMgr->stringValue("ExternalBrowser", "parameters");
1016 if (!anApp.isEmpty()) {
1017 RunBrowser* rs = new RunBrowser( this, anApp, aParams, helpFile );
1021 if( SUIT_MessageBox::warn2(desktop(), tr("WRN_WARNING"),
1022 tr("DEFINE_EXTERNAL_BROWSER"),
1023 tr("BUT_OK"),tr("BUT_CANCEL"),0,1,0 )==0 )
1029 SLOT: Displays help contents for choosen dialog
1031 void LightApp_Application::onHelpContextModule(const QString& theComponentName, const QString& theFileName)
1033 QCString dir = getenv( theComponentName + "_ROOT_DIR");
1034 QString homeDir = Qtx::addSlash(Qtx::addSlash(dir)+Qtx::addSlash("share")+Qtx::addSlash("doc")+Qtx::addSlash("salome")+Qtx::addSlash("gui")+Qtx::addSlash(theComponentName));
1036 QString helpFile = QFileInfo( homeDir + theFileName ).absFilePath();
1037 SUIT_ResourceMgr* resMgr = resourceMgr();
1040 platform = "winapplication";
1042 platform = "application";
1044 QString anApp = resMgr->stringValue("ExternalBrowser", platform);
1046 QString quote("\"");
1047 anApp.prepend( quote );
1048 anApp.append( quote );
1050 QString aParams = resMgr->stringValue("ExternalBrowser", "parameters");
1052 if (!anApp.isEmpty()) {
1053 RunBrowser* rs = new RunBrowser( this, anApp, aParams, helpFile );
1057 if( SUIT_MessageBox::warn2(desktop(), tr("WRN_WARNING"),
1058 tr("DEFINE_EXTERNAL_BROWSER"),
1059 tr("BUT_OK"), tr("BUT_CANCEL"),0,1,0)==0 )
1065 Sets enable or disable some actions on selection changed.
1067 void LightApp_Application::onSelectionChanged()
1072 \return window by key
1073 \param flag - key for window
1074 \param studyId - study id
1075 Flag used how identificator of window in windows list.
1077 QWidget* LightApp_Application::window( const int flag, const int studyId ) const
1084 if ( !activeStudy() )
1087 sId = activeStudy()->id();
1090 if ( myWindows.contains( flag ) )
1091 wid = myWindows[flag]->widget( sId );
1097 Adds window to application.
1098 \param wid - QWidget
1099 \param flag - key for window
1100 \param studyId - study id
1101 Flag used how identificator of window in windows list.
1103 void LightApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
1111 if ( !activeStudy() )
1114 sId = activeStudy()->id();
1117 if ( !myWindows.contains( flag ) )
1119 QMap<int, int> winMap;
1120 currentWindows( winMap );
1122 LightApp_WidgetContainer* newWC = new LightApp_WidgetContainer( flag, desktop() );
1123 connect( newWC, SIGNAL( destroyed ( QObject* ) ), this, SLOT( onWCDestroyed( QObject* ) ) );
1124 // asv: connecting a slot for storing visibility flag of a window
1125 connect( newWC, SIGNAL( visibilityChanged ( bool ) ), SLOT( onVisibilityChanged( bool ) ) );
1126 myWindows.insert( flag, newWC );
1127 if ( winMap.contains( flag ) )
1128 desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
1130 myWindows[flag]->setResizeEnabled( true );
1131 myWindows[flag]->setCloseMode( QDockWindow::Always );
1132 myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
1133 myWindows[flag]->setFixedExtentWidth( wid->width() );
1134 myWindows[flag]->setFixedExtentHeight( wid->height() );
1138 #ifndef DISABLE_PYCONSOLE
1139 if( wid->inherits( "PythonConsole" ) )
1141 if( resourceMgr()->hasValue( "PyConsole", "font" ) )
1142 f = resourceMgr()->fontValue( "PyConsole", "font" );
1145 f = ( ( PythonConsole* )wid )->font();
1146 resourceMgr()->setValue( "PyConsole", "font", f );
1153 myWindows[flag]->insert( sId, wid );
1156 setWindowShown( flag, !myWindows[flag]->isEmpty() );
1160 Removes window from application.
1161 \param flag - key for window
1162 \param studyId - study id
1163 Flag used how identificator of window in windows list.
1165 void LightApp_Application::removeWindow( const int flag, const int studyId )
1167 if ( !myWindows.contains( flag ) )
1173 if ( !activeStudy() )
1176 sId = activeStudy()->id();
1179 bool anIsEmpty = !myWindows[flag]->isEmpty();
1180 QWidget* wid = myWindows[flag]->widget( sId );
1181 myWindows[flag]->remove( sId );
1184 //setWindowShown( flag, !myWindows[flag]->isEmpty() );
1185 setWindowShown( flag, anIsEmpty );
1190 \param flag - key for window
1191 \param studyId - study id
1192 Flag used how identificator of window in windows list.
1194 QWidget* LightApp_Application::getWindow( const int flag, const int studyId )
1196 QWidget* wid = window( flag, studyId );
1198 addWindow( wid = createWindow( flag ), flag, studyId );
1204 \return is window visible
1205 \param type - flag of window
1207 bool LightApp_Application::isWindowVisible( const int type ) const
1210 if ( myWindows.contains( type ) )
1212 SUIT_Desktop* desk = ((LightApp_Application*)this)->desktop();
1213 res = desk && desk->appropriate( myWindows[type] );
1219 Sets window show or hide.
1220 \param type - window identificator.
1221 \param on - true/false (window show/hide)
1223 void LightApp_Application::setWindowShown( const int type, const bool on )
1225 if ( !desktop() || !myWindows.contains( type ) )
1228 QDockWindow* dw = myWindows[type];
1229 desktop()->setAppropriate( dw, on );
1232 else if( dw->isShown() )
1235 myWindowsVisible[ type ] = true;
1240 \return Object Browser
1242 OB_Browser* LightApp_Application::objectBrowser()
1245 QWidget* wid = window( WT_ObjectBrowser );
1246 if ( wid && wid->inherits( "OB_Browser" ) )
1247 ob = (OB_Browser*)wid;
1254 LogWindow* LightApp_Application::logWindow()
1257 QWidget* wid = getWindow( WT_LogWindow );
1258 if ( wid->inherits( "LogWindow" ) )
1259 lw = (LogWindow*)wid;
1263 #ifndef DISABLE_PYCONSOLE
1265 \return Python Console
1267 PythonConsole* LightApp_Application::pythonConsole()
1269 PythonConsole* console = 0;
1270 QWidget* wid = getWindow( WT_PyConsole );
1271 if ( wid->inherits( "PythonConsole" ) )
1272 console = (PythonConsole*)wid;
1278 Updates object browser and maybe data models
1279 \param updateModels - if it is true, then data models are updated
1281 void LightApp_Application::updateObjectBrowser( const bool updateModels )
1283 // update existing data models
1286 const bool isAutoUpdate = objectBrowser() ? objectBrowser()->isAutoUpdate() : true;
1287 if( objectBrowser() )
1288 objectBrowser()->setAutoUpdate( false );
1290 LightApp_Study* study = dynamic_cast<LightApp_Study*>(activeStudy());
1292 CAM_Study::ModelList dm_list;
1293 study->dataModels( dm_list );
1294 for ( CAM_Study::ModelListIterator it( dm_list ); it.current(); ++it ) {
1295 CAM_DataModel* camDM = it.current();
1296 if ( camDM && camDM->inherits( "LightApp_DataModel" ) )
1297 ((LightApp_DataModel*)camDM)->update();
1301 if( objectBrowser() )
1302 objectBrowser()->setAutoUpdate( isAutoUpdate );
1304 if ( objectBrowser() )
1306 objectBrowser()->updateGeometry();
1307 objectBrowser()->updateTree( 0, false );
1314 LightApp_Preferences* LightApp_Application::preferences() const
1316 return preferences( false );
1320 \return first view manager of some type
1321 \param vmType - type of view manager
1322 \param create - is it necessary to create view manager in case, when there is no manager of such type
1324 SUIT_ViewManager* LightApp_Application::getViewManager( const QString& vmType, const bool create )
1326 SUIT_ViewManager* aVM = viewManager( vmType );
1327 SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
1329 if ( anActiveVM && anActiveVM->getType() == vmType )
1332 if ( aVM && create )
1334 if ( !aVM->getActiveView() )
1337 aVM->getActiveView()->setFocus();
1340 aVM = createViewManager( vmType );
1346 Creates view manager of some type
1347 \param vmType - type of view manager
1349 SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType )
1351 SUIT_ResourceMgr* resMgr = resourceMgr();
1353 SUIT_ViewManager* viewMgr = 0;
1354 #ifndef DISABLE_GLVIEWER
1355 if( vmType == GLViewer_Viewer::Type() )
1357 viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
1358 new LightApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
1361 #ifndef DISABLE_PLOT2DVIEWER
1362 if( vmType == Plot2d_Viewer::Type() )
1364 viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
1366 #ifndef DISABLE_SALOMEOBJECT
1367 vm = new SPlot2d_Viewer();
1369 vm = new Plot2d_Viewer();
1371 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1372 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( viewMgr->getActiveView() );
1375 Plot2d_ViewFrame* frame = wnd->getViewFrame();
1376 frame->setBackgroundColor( resMgr->colorValue( "Plot2d", "Background", frame->backgroundColor() ) );
1380 //#ifndef DISABLE_SUPERVGRAPHVIEWER
1381 // if( vmType == SUPERVGraph_Viewer::Type() )
1383 // viewMgr = new SUPERVGraph_ViewManager( activeStudy(), desktop(), new SUPERVGraph_Viewer() );
1386 #ifndef DISABLE_QXGRAPHVIEWER
1387 if( vmType == QxGraph_Viewer::Type() )
1389 viewMgr = new QxGraph_ViewManager( activeStudy(), desktop(), new QxGraph_Viewer() );
1392 #ifndef DISABLE_OCCVIEWER
1393 if( vmType == OCCViewer_Viewer::Type() )
1395 viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
1396 OCCViewer_Viewer* vm;
1397 #ifndef DISABLE_SALOMEOBJECT
1398 vm = new SOCC_Viewer();
1400 vm = new OCCViewer_Viewer();
1402 vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
1403 vm->setTrihedronSize( resMgr->doubleValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
1406 u = resMgr->integerValue( "OCCViewer", "iso_number_u", u );
1407 v = resMgr->integerValue( "OCCViewer", "iso_number_v", v );
1408 vm->setIsos( u, v );
1409 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1410 new LightApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
1413 #ifndef DISABLE_VTKVIEWER
1414 #ifndef DISABLE_SALOMEOBJECT
1415 if ( vmType == SVTK_Viewer::Type() )
1417 if ( vmType == VTKViewer_Viewer::Type() )
1420 #ifndef DISABLE_SALOMEOBJECT
1421 viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
1422 SVTK_Viewer* vm = dynamic_cast<SVTK_Viewer*>( viewMgr->getViewModel() );
1425 vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
1426 vm->setTrihedronSize( resMgr->doubleValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ),
1427 resMgr->booleanValue( "VTKViewer", "relative_size", vm->trihedronRelative() ) );
1428 new LightApp_VTKSelector( vm, mySelMgr );
1431 viewMgr = new VTKViewer_ViewManager( activeStudy(), desktop() );
1432 VTKViewer_Viewer* vm = dynamic_cast<VTKViewer_Viewer*>( viewMgr->getViewModel() );
1434 vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
1442 addViewManager( viewMgr );
1443 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
1445 if ( viewWin && desktop() )
1446 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
1452 SLOT: Removes view manager from application
1454 void LightApp_Application::onCloseView( SUIT_ViewManager* theVM )
1456 removeViewManager( theVM );
1460 Protected SLOT: On study created.
1461 \param theStudy - just created study
1463 void LightApp_Application::onStudyCreated( SUIT_Study* theStudy )
1465 SUIT_DataObject* aRoot = 0;
1466 if ( theStudy && theStudy->root() )
1468 aRoot = theStudy->root();
1469 //aRoot->setName( tr( "DATA_MODELS" ) );
1471 getWindow( WT_ObjectBrowser );
1472 if ( objectBrowser() != 0 )
1473 objectBrowser()->setRootObject( aRoot );
1475 activateModule( defaultModule() );
1477 if ( objectBrowser() )
1478 objectBrowser()->openLevels();
1484 Protected SLOT: On study opened.
1485 \param theStudy - just opened study
1487 void LightApp_Application::onStudyOpened( SUIT_Study* theStudy )
1489 SUIT_DataObject* aRoot = 0;
1490 if ( theStudy && theStudy->root() )
1492 aRoot = theStudy->root();
1495 getWindow( WT_ObjectBrowser );
1496 if ( objectBrowser() )
1497 objectBrowser()->setRootObject( aRoot );
1499 activateModule( defaultModule() );
1501 if ( objectBrowser() )
1502 objectBrowser()->openLevels();
1509 /*!Protected SLOT. On study saved.*/
1510 void LightApp_Application::onStudySaved( SUIT_Study* )
1515 /*!Protected SLOT. On study closed.*/
1516 void LightApp_Application::onStudyClosed( SUIT_Study* s )
1518 // Bug 10396: clear selection
1519 mySelMgr->clearSelected();
1521 // Bug 12944: emit signal only after clear selection
1524 activateModule( "" );
1526 for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1527 removeWindow( itr.key(), s->id() );
1530 /*!Protected SLOT.On desktop activated.*/
1531 void LightApp_Application::onDesktopActivated()
1533 CAM_Application::onDesktopActivated();
1534 LightApp_Module* aModule = dynamic_cast<LightApp_Module*>(activeModule());
1536 aModule->studyActivated();
1539 /*!Gets file filter.
1540 *\retval QString "(*.bin)"
1542 QString LightApp_Application::getFileFilter() const
1550 Shows file dialog and return user selected file name
1552 QString LightApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1553 const QString& caption, QWidget* parent )
1557 QStringList fls = QStringList::split( ";;", filters, false );
1558 return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1561 /*! Gets directory*/
1562 QString LightApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1566 return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1569 /*! Get open file names*/
1570 QStringList LightApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
1571 const QString& caption, QWidget* parent )
1575 QStringList fls = QStringList::split( ";;", filters, false );
1576 return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1579 /*!Private SLOT. Update object browser.*/
1580 void LightApp_Application::onRefresh()
1582 updateObjectBrowser( true );
1585 /*!Private SLOT. On preferences.*/
1586 void LightApp_Application::onPreferences()
1588 QApplication::setOverrideCursor( Qt::waitCursor );
1590 LightApp_PreferencesDlg* prefDlg = new LightApp_PreferencesDlg( preferences( true ), desktop());
1592 QApplication::restoreOverrideCursor();
1597 if ( ( prefDlg->exec() == QDialog::Accepted || prefDlg->isSaved() ) && resourceMgr() ) {
1599 desktop()->saveGeometry( resourceMgr(), "desktop" );
1600 resourceMgr()->save();
1606 /*!Protected SLOT. On preferences changed.*/
1607 void LightApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1609 LightApp_Module* sMod = 0;
1610 CAM_Module* mod = module( modName );
1611 if ( mod && mod->inherits( "LightApp_Module" ) )
1612 sMod = (LightApp_Module*)mod;
1615 sMod->preferencesChanged( section, param );
1617 preferencesChanged( section, param );
1618 // emit signal to allow additional preferences changing processing
1619 emit preferenceChanged( modName, section, param );
1622 /*!Private SLOT. On open document with name \a aName.*/
1623 void LightApp_Application::onMRUActivated( QString aName )
1628 /*!Remove all windows from study.*/
1629 void LightApp_Application::beforeCloseDoc( SUIT_Study* s )
1631 CAM_Application::beforeCloseDoc( s );
1634 /*!Update actions.*/
1635 void LightApp_Application::updateActions()
1637 updateCommandsStatus();
1643 SUIT_Study* LightApp_Application::createNewStudy()
1645 LightApp_Application::lastStudyId++;
1647 LightApp_Study* aStudy = new LightApp_Study( this );
1649 // Set up processing of major study-related events
1650 connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
1651 connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
1652 connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );
1653 connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
1659 Creates window by flag.
1660 \param flag - identificator of window type
1662 QWidget* LightApp_Application::createWindow( const int flag )
1665 if ( flag == WT_ObjectBrowser )
1667 OB_Browser* ob = new OB_Browser( desktop() );
1668 ob->setSearch( new OB_ObjSearch( ob ) );
1669 ob->setAutoUpdate( true );
1670 //ob->setAutoOpenLevel( 1 ); // commented by ASV as a fix to bug IPAL10107
1671 ob->setCaption( tr( "OBJECT_BROWSER" ) );
1673 OB_ListView* ob_list = dynamic_cast<OB_ListView*>( const_cast<QListView*>( ob->listView() ) );
1675 ob_list->setColumnMaxWidth( 0, desktop()->width()/4 );
1677 ob->setFilter( new LightApp_OBFilter( selectionMgr() ) );
1678 ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1680 // Create OBSelector
1681 new LightApp_OBSelector( ob, mySelMgr );
1685 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1687 #ifndef DISABLE_PYCONSOLE
1688 else if ( flag == WT_PyConsole )
1690 PythonConsole* pyCons = new PythonConsole( desktop() );
1691 pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1693 // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1696 else if ( flag == WT_LogWindow )
1698 LogWindow* logWin = new LogWindow( desktop() );
1699 logWin->setCaption( tr( "LOG_WINDOW" ) );
1701 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1707 \return default windows( Object Browser, Python Console )
1708 Adds to map \a aMap.
1710 void LightApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1712 aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1713 #ifndef DISABLE_PYCONSOLE
1714 aMap.insert( WT_PyConsole, Qt::DockBottom );
1716 // aMap.insert( WT_LogWindow, Qt::DockBottom );
1719 /*!Default view managers*/
1720 void LightApp_Application::defaultViewManagers( QStringList& ) const
1726 \return preferences.
1727 Create preferences, if \a crt = true.
1729 LightApp_Preferences* LightApp_Application::preferences( const bool crt ) const
1734 LightApp_Application* that = (LightApp_Application*)this;
1736 bool toCreate = !_prefs_ && crt;
1739 _prefs_ = new LightApp_Preferences( resourceMgr() );
1740 that->createPreferences( _prefs_ );
1743 that->myPrefs = _prefs_;
1745 QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1746 for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1748 if ( !appIt.current()->inherits( "LightApp_Application" ) )
1751 LightApp_Application* app = (LightApp_Application*)appIt.current();
1753 QStringList modNameList;
1754 app->modules( modNameList, false );
1755 for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1757 int id = _prefs_->addPreference( *it );
1758 _prefs_->setItemProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1762 app->modules( modList );
1763 for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1765 LightApp_Module* mod = 0;
1766 if ( itr.current()->inherits( "LightApp_Module" ) )
1767 mod = (LightApp_Module*)itr.current();
1769 if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1771 int modCat = _prefs_->addPreference( mod->moduleName() );
1772 _prefs_->setItemProperty( modCat, "info", QString::null );
1774 mod->createPreferences();
1779 connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1780 this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1786 Adds new module to application
1788 void LightApp_Application::moduleAdded( CAM_Module* mod )
1790 CAM_Application::moduleAdded( mod );
1792 LightApp_Module* lightMod = 0;
1793 if ( mod && mod->inherits( "LightApp_Module" ) )
1794 lightMod = (LightApp_Module*)mod;
1796 if ( myPrefs && lightMod && !myPrefs->hasModule( lightMod->moduleName() ))
1798 int modCat = myPrefs->addPreference( mod->moduleName() );
1799 myPrefs->setItemProperty( modCat, "info", QString::null );
1800 lightMod->createPreferences();
1807 void LightApp_Application::createPreferences( LightApp_Preferences* pref )
1812 int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1814 int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1815 int studyGroup = pref->addPreference( tr( "PREF_GROUP_STUDY" ), genTab );
1816 pref->setItemProperty( studyGroup, "columns", 1 );
1818 pref->addPreference( tr( "PREF_MULTI_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "multi_file" );
1819 pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "ascii_file" );
1820 pref->addPreference( tr( "PREF_STORE_POS" ), studyGroup, LightApp_Preferences::Bool, "Study", "store_positions" );
1822 int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab );
1823 pref->setItemProperty( extgroup, "columns", 1 );
1826 platform = "winapplication";
1828 platform = "application";
1830 int apppref = pref->addPreference( tr( "PREF_APP" ), extgroup, LightApp_Preferences::File, "ExternalBrowser", platform );
1831 pref->setItemProperty( apppref, "existing", true );
1832 pref->setItemProperty( apppref, "flags", QFileInfo::ExeUser );
1833 pref->setItemProperty( apppref, "readOnly", false );
1835 pref->addPreference( tr( "PREF_PARAM" ), extgroup, LightApp_Preferences::String, "ExternalBrowser", "parameters" );
1837 int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab );
1838 pref->setItemProperty( pythonConsoleGroup, "columns", 1 );
1839 pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, LightApp_Preferences::Font, "PyConsole", "font" );
1841 int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1843 int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1845 int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1847 int plot2dGroup = pref->addPreference( tr( "PREF_GROUP_PLOT2DVIEWER" ), viewTab );
1849 int supervGroup = pref->addPreference( tr( "PREF_GROUP_SUPERV" ), viewTab );
1851 pref->setItemProperty( occGroup, "columns", 1 );
1852 pref->setItemProperty( vtkGroup, "columns", 1 );
1853 pref->setItemProperty( plot2dGroup, "columns", 1 );
1855 int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1856 LightApp_Preferences::DblSpin, "OCCViewer", "trihedron_size" );
1857 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1858 LightApp_Preferences::Color, "OCCViewer", "background" );
1860 pref->setItemProperty( occTS, "min", 1.0E-06 );
1861 pref->setItemProperty( occTS, "max", 1000 );
1863 int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
1864 LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
1865 int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
1866 LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
1868 pref->setItemProperty( isoU, "min", 0 );
1869 pref->setItemProperty( isoU, "max", 100000 );
1871 pref->setItemProperty( isoV, "min", 0 );
1872 pref->setItemProperty( isoV, "max", 100000 );
1874 int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1875 LightApp_Preferences::DblSpin, "VTKViewer", "trihedron_size" );
1876 pref->addPreference( tr( "PREF_RELATIVE_SIZE" ), vtkGroup, LightApp_Preferences::Bool, "VTKViewer", "relative_size" );
1877 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1878 LightApp_Preferences::Color, "VTKViewer", "background" );
1880 pref->setItemProperty( vtkTS, "min", 1.0E-06 );
1881 pref->setItemProperty( vtkTS, "max", 150 );
1883 pref->addPreference( tr( "PREF_SHOW_LEGEND" ), plot2dGroup,
1884 LightApp_Preferences::Bool, "Plot2d", "ShowLegend" );
1886 int legendPosition = pref->addPreference( tr( "PREF_LEGEND_POSITION" ), plot2dGroup,
1887 LightApp_Preferences::Selector, "Plot2d", "LegendPos" );
1888 QStringList aLegendPosList;
1889 aLegendPosList.append( tr("PREF_LEFT") );
1890 aLegendPosList.append( tr("PREF_RIGHT") );
1891 aLegendPosList.append( tr("PREF_TOP") );
1892 aLegendPosList.append( tr("PREF_BOTTOM") );
1894 QValueList<QVariant> anIndexesList;
1895 anIndexesList.append(0);
1896 anIndexesList.append(1);
1897 anIndexesList.append(2);
1898 anIndexesList.append(3);
1900 pref->setItemProperty( legendPosition, "strings", aLegendPosList );
1901 pref->setItemProperty( legendPosition, "indexes", anIndexesList );
1903 int curveType = pref->addPreference( tr( "PREF_CURVE_TYPE" ), plot2dGroup,
1904 LightApp_Preferences::Selector, "Plot2d", "CurveType" );
1905 QStringList aCurveTypesList;
1906 aCurveTypesList.append( tr("PREF_POINTS") );
1907 aCurveTypesList.append( tr("PREF_LINES") );
1908 aCurveTypesList.append( tr("PREF_SPLINE") );
1910 anIndexesList.clear();
1911 anIndexesList.append(0);
1912 anIndexesList.append(1);
1913 anIndexesList.append(2);
1915 pref->setItemProperty( curveType, "strings", aCurveTypesList );
1916 pref->setItemProperty( curveType, "indexes", anIndexesList );
1918 int markerSize = pref->addPreference( tr( "PREF_MARKER_SIZE" ), plot2dGroup,
1919 LightApp_Preferences::IntSpin, "Plot2d", "MarkerSize" );
1921 pref->setItemProperty( markerSize, "min", 0 );
1922 pref->setItemProperty( markerSize, "max", 100 );
1924 QStringList aScaleModesList;
1925 aScaleModesList.append( tr("PREF_LINEAR") );
1926 aScaleModesList.append( tr("PREF_LOGARITHMIC") );
1928 anIndexesList.clear();
1929 anIndexesList.append(0);
1930 anIndexesList.append(1);
1932 int horScale = pref->addPreference( tr( "PREF_HOR_AXIS_SCALE" ), plot2dGroup,
1933 LightApp_Preferences::Selector, "Plot2d", "HorScaleMode" );
1935 pref->setItemProperty( horScale, "strings", aScaleModesList );
1936 pref->setItemProperty( horScale, "indexes", anIndexesList );
1938 int verScale = pref->addPreference( tr( "PREF_VERT_AXIS_SCALE" ), plot2dGroup,
1939 LightApp_Preferences::Selector, "Plot2d", "VerScaleMode" );
1941 pref->setItemProperty( verScale, "strings", aScaleModesList );
1942 pref->setItemProperty( verScale, "indexes", anIndexesList );
1944 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), plot2dGroup,
1945 LightApp_Preferences::Color, "Plot2d", "Background" );
1947 int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat );
1948 int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab );
1949 pref->setItemProperty( dirGroup, "columns", 1 );
1950 pref->addPreference( tr( "" ), dirGroup,
1951 LightApp_Preferences::DirList, "FileDlg", "QuickDirList" );
1953 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), supervGroup,
1954 LightApp_Preferences::Color, "SUPERVGraph", "Background" );
1955 pref->addPreference( tr( "PREF_SUPERV_TITLE_COLOR" ), supervGroup,
1956 LightApp_Preferences::Color, "SUPERVGraph", "Title" );
1957 // pref->addPreference( tr( "PREF_SUPERV_CTRL_COLOR" ), supervGroup,
1958 // LightApp_Preferences::Color, "SUPERVGraph", "Ctrl" );
1960 int obTab = pref->addPreference( tr( "PREF_TAB_OBJBROWSER" ), salomeCat );
1961 int objSetGroup = pref->addPreference( tr( "PREF_OBJ_BROWSER_SETTINGS" ), obTab );
1962 pref->addPreference( tr( "PREF_AUTO_SIZE_FIRST" ), objSetGroup, LightApp_Preferences::Bool,
1963 "ObjectBrowser", "auto_size_first" );
1964 pref->addPreference( tr( "PREF_AUTO_SIZE" ), objSetGroup, LightApp_Preferences::Bool,
1965 "ObjectBrowser", "auto_size" );
1969 Changes appearance of application according to changed preferences
1970 \param sec - section
1971 \param param - name of changed parameter
1973 void LightApp_Application::preferencesChanged( const QString& sec, const QString& param )
1975 SUIT_ResourceMgr* resMgr = resourceMgr();
1979 #ifndef DISABLE_OCCVIEWER
1980 if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1982 double sz = resMgr->doubleValue( sec, param, -1 );
1983 QPtrList<SUIT_ViewManager> lst;
1984 viewManagers( OCCViewer_Viewer::Type(), lst );
1985 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1987 SUIT_ViewModel* vm = it.current()->getViewModel();
1988 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1991 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1992 occVM->setTrihedronSize( sz );
1993 occVM->getAISContext()->UpdateCurrentViewer();
1998 #ifndef DISABLE_VTKVIEWER
1999 if ( sec == QString( "VTKViewer" ) && (param == QString( "trihedron_size" ) || param == QString( "relative_size" )) )
2001 double sz = resMgr->doubleValue( "VTKViewer", "trihedron_size", -1 );
2002 bool isRelative = resMgr->booleanValue( "VTKViewer", "relative_size", true );
2003 QPtrList<SUIT_ViewManager> lst;
2004 #ifndef DISABLE_SALOMEOBJECT
2005 viewManagers( SVTK_Viewer::Type(), lst );
2006 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
2008 SUIT_ViewModel* vm = it.current()->getViewModel();
2009 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
2012 SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
2015 vtkVM->setTrihedronSize( sz, isRelative );
2023 #ifndef DISABLE_OCCVIEWER
2024 if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
2026 QPtrList<SUIT_ViewManager> lst;
2027 viewManagers( OCCViewer_Viewer::Type(), lst );
2028 int u = resMgr->integerValue( sec, "iso_number_u" );
2029 int v = resMgr->integerValue( sec, "iso_number_v" );
2030 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
2032 OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>( it.current() );
2033 if( mgr && mgr->getOCCViewer() )
2034 mgr->getOCCViewer()->setIsos( u, v );
2039 if( sec=="ObjectBrowser" )
2041 if( param=="auto_size" || param=="auto_size_first" )
2043 OB_Browser* ob = objectBrowser();
2047 bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false ),
2048 autoSizeFirst = resMgr->booleanValue( "ObjectBrowser", "auto_size_first", true );
2049 ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
2050 ob->listView()->setColumnWidthMode( 0, autoSizeFirst ? QListView::Maximum : QListView::Manual );
2052 for( int i=1; i<ob->listView()->columns(); i++ )
2053 if( ob->listView()->columnWidth( i )>0 )
2054 ob->listView()->adjustColumn( i );
2055 updateObjectBrowser( false );
2061 if( param=="store_positions" )
2065 #ifndef DISABLE_PYCONSOLE
2066 if( sec=="PyConsole" )
2069 if( pythonConsole() )
2070 pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) );
2078 void LightApp_Application::savePreferences()
2080 saveWindowsGeometry();
2082 if ( resourceMgr() )
2085 desktop()->saveGeometry( resourceMgr(), "desktop" );
2086 resourceMgr()->save();
2091 Updates desktop title
2093 void LightApp_Application::updateDesktopTitle() {
2094 QString aTitle = applicationName();
2095 QString aVer = applicationVersion();
2096 if ( !aVer.isEmpty() )
2097 aTitle += QString( " " ) + aVer;
2099 if ( activeStudy() ) {
2100 QString sName = SUIT_Tools::file( activeStudy()->studyName().stripWhiteSpace(), false );
2101 aTitle += QString( " - [%1]" ).arg( sName );
2104 desktop()->setCaption( aTitle );
2108 \brief Get module activation actions
2109 \return map <action_id><action_name> where
2110 - action_id is unique non-zero action identifier
2111 - action_name is action title
2112 \sa moduleActionSelected()
2114 QMap<int, QString> LightApp_Application::activateModuleActions() const
2116 QMap<int, QString> opmap;
2117 opmap.insert( NewStudyId, tr( "ACTIVATE_MODULE_OP_NEW" ) );
2118 opmap.insert( OpenStudyId, tr( "ACTIVATE_MODULE_OP_OPEN" ) );
2123 \brief Process module activation action.
2124 \param id action identifier
2125 \sa activateModuleActions()
2127 void LightApp_Application::moduleActionSelected( const int id )
2141 Updates windows after close document
2143 void LightApp_Application::afterCloseDoc()
2147 CAM_Application::afterCloseDoc();
2151 Updates actions of active module
2153 void LightApp_Application::updateModuleActions()
2156 if ( activeModule() )
2157 modName = activeModule()->moduleName();
2159 if ( myActions.contains( modName ) )
2160 myActions[modName]->setOn( true );
2164 Gets current windows.
2165 \param winMap - output current windows map.
2167 void LightApp_Application::currentWindows( QMap<int, int>& winMap ) const
2170 if ( !activeStudy() )
2173 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
2174 ((LightApp_Module*)activeModule())->windows( winMap );
2176 defaultWindows( winMap );
2180 Gets current view managers.
2181 \param lst - output current view managers list.
2183 void LightApp_Application::currentViewManagers( QStringList& lst ) const
2186 if ( !activeStudy() )
2189 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
2190 ((LightApp_Module*)activeModule())->viewManagers( lst );
2192 defaultViewManagers( lst );
2198 void LightApp_Application::updateWindows()
2200 QMap<int, int> winMap;
2201 currentWindows( winMap );
2203 if ( activeStudy() ) {
2204 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it ) {
2205 getWindow( it.key() );
2207 Dock dock; int index, extraOffset; bool nl;
2208 if ( desktop()->getLocation( myWindows[it.key()], dock, index, nl, extraOffset )
2210 dock != (Dock)it.data() )
2211 desktop()->moveDockWindow( myWindows[it.key()], (Dock)it.data() );
2214 loadWindowsGeometry();
2217 // setWindowShown should be done even if no study is active (open). in this case all open windows
2218 // will be hidden, which is neccessary in this case.
2219 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr ) {
2221 if ( myWindowsVisible.contains( itr.key() ) &&
2222 !myWindowsVisible[ itr.key() ] )
2225 setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
2230 Updates view managers
2232 void LightApp_Application::updateViewManagers()
2235 currentViewManagers( lst );
2237 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
2238 getViewManager( *it, true );
2242 Loads windows geometry
2244 void LightApp_Application::loadWindowsGeometry()
2246 bool store = resourceMgr()->booleanValue( "Study", "store_positions", true );
2250 QtxDockAction* dockMgr = 0;
2252 QAction* a = action( ViewWindowsId );
2253 if ( a && a->inherits( "QtxDockAction" ) )
2254 dockMgr = (QtxDockAction*)a;
2260 if ( activeModule() )
2261 modName = activeModule()->name("");
2263 QString section = QString( "windows_geometry" );
2264 if ( !modName.isEmpty() )
2265 section += QString( "." ) + modName;
2267 dockMgr->loadGeometry( resourceMgr(), section, false );
2268 dockMgr->restoreGeometry();
2272 Saves windows geometry
2274 void LightApp_Application::saveWindowsGeometry()
2276 bool store = resourceMgr()->booleanValue( "Study", "store_positions", true );
2280 QtxDockAction* dockMgr = 0;
2282 QAction* a = action( ViewWindowsId );
2283 if ( a && a->inherits( "QtxDockAction" ) )
2284 dockMgr = (QtxDockAction*)a;
2290 if ( activeModule() )
2291 modName = activeModule()->name("");
2293 QString section = QString( "windows_geometry" );
2294 if ( !modName.isEmpty() )
2295 section += QString( "." ) + modName;
2297 dockMgr->storeGeometry();
2298 dockMgr->saveGeometry( resourceMgr(), section, false );
2304 void LightApp_Application::activateWindows()
2306 if ( activeStudy() )
2308 for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
2309 itr.data()->activate( activeStudy()->id() );
2314 Adds icon names for modules
2316 void LightApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
2320 SUIT_ResourceMgr* resMgr = resourceMgr();
2324 QStringList modList;
2325 modules( modList, false );
2327 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
2329 QString modName = *it;
2330 QString modIntr = moduleName( modName );
2331 QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
2333 if ( modIcon.isEmpty() )
2336 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
2337 modIcon += QString( ".png" );
2339 iconMap.insert( modName, modIcon );
2344 Inserts items in popup, which necessary for current application
2346 void LightApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
2348 CAM_Application::contextMenuPopup( type, thePopup, title );
2350 OB_Browser* ob = objectBrowser();
2351 if ( !ob || type != ob->popupClientType() )
2354 thePopup->insertSeparator();
2355 thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
2356 thePopup->insertItem( tr( "MEN_FIND" ), this, SLOT( onFind() ) );
2362 void LightApp_Application::createEmptyStudy()
2364 CAM_Application::createEmptyStudy();
2365 if ( objectBrowser() )
2366 objectBrowser()->updateTree();
2371 \param mod - module to be activated
2373 bool LightApp_Application::activateModule( CAM_Module* mod )
2375 bool res = CAM_Application::activateModule( mod );
2376 if ( objectBrowser() )
2377 objectBrowser()->updateTree();
2382 \return keyborad accelerators manager object
2384 SUIT_Accel* LightApp_Application::accel() const
2390 Removes dead widget container from map
2392 void LightApp_Application::onWCDestroyed( QObject* ob )
2394 // remove destroyed widget container from windows map
2395 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
2397 if ( itr.data() != ob )
2400 int key = itr.key();
2401 myWindows.remove( key );
2407 Connects just added view manager
2409 void LightApp_Application::addViewManager( SUIT_ViewManager* vm )
2411 connect( vm, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
2412 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
2413 STD_Application::addViewManager( vm );
2417 Remove view manager from memory
2419 void LightApp_Application::removeViewManager( SUIT_ViewManager* vm )
2421 disconnect( vm, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
2422 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
2423 STD_Application::removeViewManager( vm );
2428 Renames active window of desktop
2430 void LightApp_Application::onRenameWindow()
2435 QWidget* w = desktop()->activeWindow();
2440 QString name = QInputDialog::getText( tr( "TOT_RENAME" ), tr( "PRP_RENAME" ), QLineEdit::Normal, w->caption(), &ok, w );
2441 if( ok && !name.isEmpty() )
2442 w->setCaption( name );
2446 \return if the library of module exists
2447 \param moduleTitle - title of module
2449 bool LightApp_Application::isLibExists( const QString& moduleTitle ) const
2451 if( moduleTitle.isEmpty() )
2454 QString lib = moduleLibrary( moduleTitle );
2456 //abd: changed libSalomePyQtGUI to SalomePyQtGUI for WIN32
2457 bool isPythonModule = lib.contains("SalomePyQtGUI");
2461 paths = QStringList::split( ";", ::getenv( "PATH" ) );
2463 paths = QStringList::split( ":", ::getenv( "LD_LIBRARY_PATH" ) );
2466 bool isLibFound = false;
2467 QStringList::const_iterator anIt = paths.begin(), aLast = paths.end();
2468 for( ; anIt!=aLast; anIt++ )
2470 QFileInfo inf( Qtx::addSlash( *anIt ) + lib );
2481 printf( "****************************************************************\n" );
2482 printf( "* Warning: library %s cannot be found\n", lib.latin1() );
2483 printf( "* Module %s will not be available in GUI mode\n", moduleTitle.latin1() );
2484 printf( "****************************************************************\n" );
2486 else if ( !isPythonModule )
2489 if ( isPythonModule )
2491 QString pylib = moduleName( moduleTitle ) + QString(".py");
2492 QString pylibgui = moduleName( moduleTitle ) + QString("GUI.py");
2494 // Check the python library
2496 paths = QStringList::split( ";", ::getenv( "PATH" ) );
2498 paths = QStringList::split( ":", ::getenv( "PYTHONPATH" ) );
2500 bool isPyLib = false, isPyGuiLib = false;
2501 QStringList::const_iterator anIt = paths.begin(), aLast = paths.end();
2502 for( ; anIt!=aLast; anIt++ )
2504 QFileInfo inf( Qtx::addSlash( *anIt ) + pylib );
2505 QFileInfo infgui( Qtx::addSlash( *anIt ) + pylibgui );
2507 if( !isPyLib && inf.exists() )
2510 if( !isPyGuiLib && infgui.exists() )
2513 if ( isPyLib && isPyGuiLib && isLibFound)
2517 printf( "****************************************************************\n" );
2518 printf( "* Warning: python library for %s cannot be found:\n", moduleTitle.latin1() );
2520 printf( "* No module named %s\n", moduleName( moduleTitle ).latin1() );
2522 printf( "* No module named %s\n", (moduleName( moduleTitle ) + QString("GUI")).latin1() );
2523 printf( "****************************************************************\n" );
2530 \return default name for an active study
2532 void LightApp_Application::setDefaultStudyName( const QString& theName )
2534 QStringList anInfoList;
2535 modules( anInfoList, false );
2537 LightApp_Study* aStudy = (LightApp_Study*)activeStudy();
2538 if( anInfoList.count() == 1 && // to avoid a conflict between different modules
2539 !aStudy->isSaved() )
2541 aStudy->setStudyName( theName );
2542 updateDesktopTitle();
2546 /*! slot, called on show/hide of a dock window */
2547 void LightApp_Application::onVisibilityChanged( bool visible )
2549 const QObject* win = sender();
2551 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
2552 if ( itr.data() == win )
2554 myWindowsVisible[ itr.key() ] = visible;
2560 Custom event handler
2562 bool LightApp_Application::event( QEvent* e )
2564 if( e && e->type()==2000 )
2566 QCustomEvent* ce = ( QCustomEvent* )e;
2567 QString* d = ( QString* )ce->data();
2568 if( SUIT_MessageBox::warn2(0, tr("WRN_WARNING"),
2570 tr("BUT_OK"), tr("BUT_CANCEL"), 0, 1, 0 )==0 )
2576 return CAM_Application::event( e );
2579 /*! Check data object */
2580 bool LightApp_Application::checkDataObject(LightApp_DataObject* theObj)
2584 bool isSuitable = !theObj->entry().isEmpty() &&
2585 !theObj->componentDataType().isEmpty() &&
2586 !theObj->name().isEmpty();
2593 void LightApp_Application::onFind()
2595 objectBrowser()->enableSearch( true );