1 // File: LightApp_Application.cxx
2 // Created: 6/20/2005 18:39:45 PM
3 // Author: Natalia Donis
4 // Copyright (C) CEA 2005
6 #include "PythonConsole_PyInterp.h" // WARNING! This include must be the first!
8 #include "LightApp_Application.h"
9 #include "LightApp_WidgetContainer.h"
10 #include "LightApp_Module.h"
11 #include "LightApp_DataModel.h"
12 #include "LightApp_Study.h"
13 #include "LightApp_Preferences.h"
14 #include "LightApp_PreferencesDlg.h"
15 #include "LightApp_ModuleDlg.h"
16 #include "LightApp_AboutDlg.h"
18 #include "LightApp_OBFilter.h"
20 #include "LightApp_GLSelector.h"
21 #include "LightApp_OBSelector.h"
22 #include "LightApp_OCCSelector.h"
23 #include "LightApp_VTKSelector.h"
24 #include "LightApp_SelectionMgr.h"
26 #include <CAM_Module.h>
27 #include <CAM_DataModel.h>
28 #include <CAM_Study.h>
29 #include <STD_TabDesktop.h>
31 #include <SUIT_Session.h>
32 #include <SUIT_Study.h>
33 #include <SUIT_FileDlg.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_Tools.h>
36 #include <SUIT_Accel.h>
38 #include <QtxMRUAction.h>
39 #include <QtxDockAction.h>
40 #include <QtxToolBar.h>
42 #include <LogWindow.h>
43 #include <OB_Browser.h>
44 #include <OB_ListView.h>
45 #include <PythonConsole_PyConsole.h>
47 #include <GLViewer_Viewer.h>
48 #include <GLViewer_ViewManager.h>
50 #include <Plot2d_ViewManager.h>
51 #include <Plot2d_ViewModel.h>
52 #include <SPlot2d_ViewModel.h>
54 #include <OCCViewer_ViewManager.h>
55 #include <SOCC_ViewModel.h>
57 #include <SVTK_ViewModel.h>
58 #include <SVTK_ViewManager.h>
59 #include <VTKViewer_ViewModel.h>
61 #include <SUPERVGraph_ViewModel.h>
62 #include <SUPERVGraph_ViewFrame.h>
63 #include <SUPERVGraph_ViewManager.h>
65 #include <QtxWorkstack.h>
71 #include <qstringlist.h>
73 #include <qapplication.h>
75 #include <qstatusbar.h>
77 #include <qobjectlist.h>
78 #include <qcombobox.h>
79 #include <qinputdialog.h>
80 #include <qmessagebox.h>
82 #define FIRST_HELP_ID 1000000
84 #include "SALOME_InteractiveObject.hxx"
85 #include "SALOME_ListIO.hxx"
87 static const char* imageEmptyIcon[] = {
90 "....................",
91 "....................",
92 "....................",
93 "....................",
94 "....................",
95 "....................",
96 "....................",
97 "....................",
98 "....................",
99 "....................",
100 "....................",
101 "....................",
102 "....................",
103 "....................",
104 "....................",
105 "....................",
106 "....................",
107 "....................",
108 "....................",
109 "...................."};
111 /*!Create new instance of LightApp_Application.*/
112 extern "C" LIGHTAPP_EXPORT SUIT_Application* createApplication()
114 return new LightApp_Application();
117 LightApp_Preferences* LightApp_Application::_prefs_ = 0;
120 Class : LightApp_Application
121 Description : Application containing LightApp module
125 LightApp_Application::LightApp_Application()
126 : CAM_Application( false ),
129 STD_TabDesktop* desk = new STD_TabDesktop();
133 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
134 QPixmap aLogo = aResMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false );
136 desktop()->setIcon( aLogo );
137 desktop()->setDockableMenuBar( true );
138 desktop()->setDockableStatusBar( false );
140 // base logo (salome itself)
141 desktop()->addLogo( "_app_base", aResMgr->loadPixmap( "LightApp", tr( "APP_BASE_LOGO" ), false ) );
142 // extra logo (salome-based application)
143 desktop()->addLogo( "_app_extra", aResMgr->loadPixmap( "LightApp", tr( "APP_EXTRA_LOGO" ), false ) );
147 mySelMgr = new LightApp_SelectionMgr( this );
149 myAccel = new SUIT_Accel( desktop() );
150 myAccel->setActionKey( SUIT_Accel::PanLeft, CTRL+Key_Left, OCCViewer_Viewer::Type() );
151 myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, OCCViewer_Viewer::Type() );
152 myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, OCCViewer_Viewer::Type() );
153 myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, OCCViewer_Viewer::Type() );
154 myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, OCCViewer_Viewer::Type() );
155 myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, OCCViewer_Viewer::Type() );
156 myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, OCCViewer_Viewer::Type() );
157 myAccel->setActionKey( SUIT_Accel::RotateLeft, ALT+Key_Left, OCCViewer_Viewer::Type() );
158 myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right, OCCViewer_Viewer::Type() );
159 myAccel->setActionKey( SUIT_Accel::RotateUp, ALT+Key_Up, OCCViewer_Viewer::Type() );
160 myAccel->setActionKey( SUIT_Accel::RotateDown, ALT+Key_Down, OCCViewer_Viewer::Type() );
161 myAccel->setActionKey( SUIT_Accel::PanLeft, CTRL+Key_Left, VTKViewer_Viewer::Type() );
162 myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, VTKViewer_Viewer::Type() );
163 myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, VTKViewer_Viewer::Type() );
164 myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, VTKViewer_Viewer::Type() );
165 myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, VTKViewer_Viewer::Type() );
166 myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, VTKViewer_Viewer::Type() );
167 myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, VTKViewer_Viewer::Type() );
168 myAccel->setActionKey( SUIT_Accel::RotateLeft, ALT+Key_Left, VTKViewer_Viewer::Type() );
169 myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right, VTKViewer_Viewer::Type() );
170 myAccel->setActionKey( SUIT_Accel::RotateUp, ALT+Key_Up, VTKViewer_Viewer::Type() );
171 myAccel->setActionKey( SUIT_Accel::RotateDown, ALT+Key_Down, VTKViewer_Viewer::Type() );
173 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) );
177 *\li Save window geometry.
178 *\li Save desktop geometry.
179 *\li Save resource maneger.
180 *\li Delete selection manager.
182 LightApp_Application::~LightApp_Application()
184 saveWindowsGeometry();
189 desktop()->saveGeometry( resourceMgr(), "desktop" );
190 resourceMgr()->save();
195 /*!Start application.*/
196 void LightApp_Application::start()
199 desktop()->loadGeometry( resourceMgr(), "desktop" );
201 CAM_Application::start();
203 QAction* a = action( ViewWindowsId );
204 if ( a && a->inherits( "QtxDockAction" ) )
205 ((QtxDockAction*)a)->setAutoPlace( true );
208 updateViewManagers();
211 desktop()->statusBar()->message( "" );
214 /*!Gets application name.*/
215 QString LightApp_Application::applicationName() const
217 return tr( "APP_NAME" );
220 /*!Gets application version.*/
221 QString LightApp_Application::applicationVersion() const
223 static QString _app_version;
225 if ( _app_version.isEmpty() )
227 QString resVersion = tr( "APP_VERSION" );
228 if ( resVersion != "APP_VERSION" )
230 _app_version = resVersion;
234 QString path( ::getenv( "GUI_ROOT_DIR" ) );
235 if ( !path.isEmpty() )
236 path += QDir::separator();
237 path += QString( "bin/salome/VERSION" );
240 if ( vf.open( IO_ReadOnly ) )
243 vf.readLine( line, 1024 );
246 if ( !line.isEmpty() )
248 while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
249 line.remove( line.length() - 1, 1 );
251 int idx = line.findRev( ":" );
253 _app_version = line.mid( idx + 1 ).stripWhiteSpace();
261 /*!Load module by \a name.*/
262 CAM_Module* LightApp_Application::loadModule( const QString& name )
264 CAM_Module* mod = CAM_Application::loadModule( name );
267 connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) );
268 connect( this, SIGNAL( studySaved() ), mod, SLOT( onModelSaved() ) );
269 connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) );
274 /*!Activate module by \a modName*/
275 bool LightApp_Application::activateModule( const QString& modName )
278 CAM_Module* prevMod = activeModule();
281 actName = prevMod->moduleName();
283 if ( actName == modName )
286 putInfo( tr( "ACTIVATING_MODULE" ).arg( modName ) );
288 saveWindowsGeometry();
290 bool status = CAM_Application::activateModule( modName );
292 updateModuleActions();
300 updateViewManagers();
305 bool LightApp_Application::useStudy(const QString& theName)
308 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>(activeStudy());
311 res = aStudy->loadDocument( theName );
312 updateDesktopTitle();
313 updateCommandsStatus();
317 /*!Gets selection manager.*/
318 LightApp_SelectionMgr* LightApp_Application::selectionMgr() const
324 void LightApp_Application::createActions()
326 STD_Application::createActions();
328 SUIT_Desktop* desk = desktop();
329 SUIT_ResourceMgr* resMgr = resourceMgr();
332 createAction( PreferencesId, tr( "TOT_DESK_PREFERENCES" ), QIconSet(),
333 tr( "MEN_DESK_PREFERENCES" ), tr( "PRP_DESK_PREFERENCES" ),
334 CTRL+Key_F, desk, false, this, SLOT( onPreferences() ) );
337 int helpMenu = createMenu( tr( "MEN_DESK_HELP" ), -1, -1, 1000 );
338 int helpModuleMenu = createMenu( tr( "MEN_DESK_MODULE_HELP" ), helpMenu, -1, 0 );
339 createMenu( separator(), helpMenu, -1, 1 );
341 QStringList aModuleList;
342 modules( aModuleList, false );
344 int id = LightApp_Application::UserID + FIRST_HELP_ID;
345 // help for KERNEL and GUI
350 if (dir = getenv("GUI_ROOT_DIR")) {
351 aFileName = "GUI_index_v3.1.0.html";
352 root = Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("doc") + Qtx::addSlash("salome") );
353 if ( QFileInfo( root + aFileName ).exists() ) {
354 a = createAction( id, tr( QString("Kernel & GUI Help") ), QIconSet(),
355 tr( QString("Kernel && GUI Help") ),
356 tr( QString("Kernel & GUI Help") ),
357 0, desk, false, this, SLOT( onHelpContentsModule() ) );
358 a->setName( QString("GUI") );
359 createMenu( a, helpModuleMenu, -1 );
363 // help for other existing modules
364 QStringList::Iterator it;
365 for ( it = aModuleList.begin(); it != aModuleList.end(); ++it )
367 if ( (*it).isEmpty() )
370 QString modName = moduleName( *it );
371 aFileName = modName + "_index_v3.1.0.html";
373 if (dir = getenv( modName + "_ROOT_DIR")) {
374 root = Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("doc") + Qtx::addSlash("salome") );
375 if ( QFileInfo( root + aFileName ).exists() ) {
377 QAction* a = createAction( id, tr( moduleTitle(modName) + QString(" Help") ), QIconSet(),
378 tr( moduleTitle(modName) + QString(" Help") ),
379 tr( moduleTitle(modName) + QString(" Help") ),
380 0, desk, false, this, SLOT( onHelpContentsModule() ) );
381 a->setName( modName );
382 createMenu( a, helpModuleMenu, -1 );
389 QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), desk );
390 connect( mru, SIGNAL( activated( QString ) ), this, SLOT( onMRUActivated( QString ) ) );
391 registerAction( MRUId, mru );
393 // default icon for neutral point ('SALOME' module)
394 QPixmap defIcon = resMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false );
395 if ( defIcon.isNull() )
396 defIcon = QPixmap( imageEmptyIcon );
398 //! default icon for any module
399 QPixmap modIcon = resMgr->loadPixmap( "LightApp", tr( "APP_MODULE_ICO" ), false );
400 if ( modIcon.isNull() )
401 modIcon = QPixmap( imageEmptyIcon );
403 QToolBar* modTBar = new QtxToolBar( true, desk );
404 modTBar->setLabel( tr( "INF_TOOLBAR_MODULES" ) );
406 QActionGroup* modGroup = new QActionGroup( this );
407 modGroup->setExclusive( true );
408 modGroup->setUsesDropDown( true );
410 a = createAction( -1, tr( "APP_NAME" ), defIcon, tr( "APP_NAME" ),
411 tr( "PRP_APP_MODULE" ), 0, desk, true );
413 myActions.insert( QString(), a );
415 QMap<QString, QString> iconMap;
416 moduleIconNames( iconMap );
418 const int iconSize = 20;
420 modGroup->addTo( modTBar );
421 QObjectList *l = modTBar->queryList( "QComboBox" );
422 QObjectListIt oit( *l );
423 while ( QObject* obj = oit.current() ) {
424 QComboBox* cb = (QComboBox*)obj;
425 if ( cb ) cb->setFocusPolicy( QWidget::NoFocus );
430 modTBar->addSeparator();
433 modules( modList, false );
435 for ( it = modList.begin(); it != modList.end(); ++it )
437 if ( (*it).isEmpty() )
441 if ( iconMap.contains( *it ) )
442 iconName = iconMap[*it];
444 QString modName = moduleName( *it );
446 QPixmap icon = resMgr->loadPixmap( modName, iconName, false );
450 icon.convertFromImage( icon.convertToImage().smoothScale( iconSize, iconSize, QImage::ScaleMin ) );
452 QAction* a = createAction( -1, *it, icon, *it, tr( "PRP_MODULE" ).arg( *it ), 0, desk, true );
456 myActions.insert( *it, a );
459 SUIT_Tools::simplifySeparators( modTBar );
462 int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 );
463 int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
464 createMenu( separator(), windowMenu, -1, 1 );
466 QMap<int, int> accelMap;
467 accelMap[NewGLViewId] = ALT+Key_G;
468 accelMap[NewPlot2dId] = ALT+Key_P;
469 accelMap[NewOCCViewId] = ALT+Key_O;
470 accelMap[NewVTKViewId] = ALT+Key_K;
472 for ( id = NewGLViewId; id <= NewVTKViewId; id++ )
474 QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), QIconSet(),
475 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
476 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
477 accelMap.contains( id ) ? accelMap[id] : 0, desk, false, this, SLOT( onNewWindow() ) );
478 createMenu( a, newWinMenu, -1 );
481 createAction( RenameId, tr( "TOT_RENAME" ), QIconSet(), tr( "MEN_DESK_RENAME" ), tr( "PRP_RENAME" ),
482 SHIFT+Key_R, desk, false, this, SLOT( onRenameWindow() ) );
483 createMenu( RenameId, windowMenu, -1 );
485 connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) );
487 int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
488 createMenu( PreferencesId, fileMenu, 15, -1 );
489 createMenu( separator(), fileMenu, -1, 15, -1 );
492 createMenu( separator(), fileMenu, -1, 100, -1 );
493 createMenu( MRUId, fileMenu, 100, -1 );
494 createMenu( separator(), fileMenu, -1, 100, -1 );
498 /*!On module activation action.*/
499 void LightApp_Application::onModuleActivation( QAction* a )
504 QString modName = a->menuText();
505 if ( modName == tr( "APP_NAME" ) )
506 modName = QString::null;
508 // Force user to create/open a study before module activation
509 QMap<QString, QString> iconMap;
510 moduleIconNames( iconMap );
511 QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ], false );
513 icon = resourceMgr()->loadPixmap( "LightApp", tr( "APP_MODULE_BIG_ICO" ), false ); // default icon for any module
515 bool cancelled = false;
516 while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
517 LightApp_ModuleDlg aDlg( desktop(), modName, icon );
518 int res = aDlg.exec();
532 putInfo( tr("INF_CANCELLED") );
533 myActions[QString()]->setOn( true );
539 activateModule( modName );
542 /*!Default module activation.*/
543 QString LightApp_Application::defaultModule() const
545 QStringList aModuleNames;
546 modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration
547 //! If there's the one and only module --> activate it automatically
548 //! TODO: Possible improvement - default module can be taken from preferences
549 return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" );
552 /*!On new window slot.*/
553 void LightApp_Application::onNewWindow()
555 const QObject* obj = sender();
556 if ( !obj || !obj->inherits( "QAction" ) )
560 int id = actionId( (QAction*)obj );
564 type = GLViewer_Viewer::Type();
567 type = Plot2d_Viewer::Type();
570 type = OCCViewer_Viewer::Type();
573 type = VTKViewer_Viewer::Type();
577 if ( !type.isEmpty() )
578 createViewManager( type );
581 //=======================================================================
583 /*! Purpose : SLOT. Create new document*/
584 //=======================================================================
585 void LightApp_Application::onNewDoc()
587 SUIT_Study* study = activeStudy();
589 saveWindowsGeometry();
591 CAM_Application::onNewDoc();
593 if ( !study ) // new study will be create in THIS application
596 updateViewManagers();
600 //=======================================================================
602 /*! Purpose : SLOT. Open new document*/
603 //=======================================================================
604 void LightApp_Application::onOpenDoc()
606 SUIT_Study* study = activeStudy();
607 saveWindowsGeometry();
609 CAM_Application::onOpenDoc();
611 if ( !study ) // new study will be create in THIS application
614 updateViewManagers();
618 #include "SUIT_MessageBox.h"
619 /*! Purpose : SLOT. Open new document with \a aName.*/
620 bool LightApp_Application::onOpenDoc( const QString& aName )
622 bool isAlreadyOpen = false;
624 // Look among opened studies
625 if (activeStudy()) { // at least one study is opened
626 SUIT_Session* aSession = SUIT_Session::session();
627 QPtrList<SUIT_Application> aAppList = aSession->applications();
628 QPtrListIterator<SUIT_Application> it (aAppList);
629 SUIT_Application* aApp = 0;
630 // iterate on all applications
631 for (; (aApp = it.current()) && !isAlreadyOpen; ++it) {
632 if (aApp->activeStudy()->studyName() == aName) {
633 isAlreadyOpen = true; // Already opened, ask user what to do
635 // The document ... is already open.
636 // Do you want to reload it?
637 int aAnswer = SUIT_MessageBox::warn2(desktop(), tr("WRN_WARNING"),
638 tr("QUE_DOC_ALREADYOPEN").arg(aName),
639 tr("BUT_YES"), tr("BUT_NO"), 1, 2, 2);
640 if (aAnswer == 1) { // reload
641 if (activeStudy()->studyName() == aName && aAppList.count() > 1) {
642 // Opened in THIS (active) application.
643 STD_Application* app1 = (STD_Application*)aAppList.at(0);
644 STD_Application* app2 = (STD_Application*)aAppList.at(1);
645 if (!app1 || !app2) {
649 if (app1->activeStudy()->studyName() == aName) {
650 // app1 is this application, we need another one
653 // Close document of this application. This application will be destroyed.
654 onCloseDoc(/*ask = */false);
655 // Open the file with another application, as this one will be destroyed.
656 return app1->onOpenDoc(aName);
658 // Opened in another application.
659 STD_Application* app = (STD_Application*)aApp;
661 app->onCloseDoc(/*ask = */false);
663 } else { // do not reload
664 // OK, the study will not be reloaded, but we call
665 // CAM_Application::onOpenDoc( aName ) all the same.
666 // It will activate a desktop of the study <aName>.
672 bool res = CAM_Application::onOpenDoc( aName );
674 QAction* a = action( MRUId );
675 if ( a && a->inherits( "QtxMRUAction" ) )
677 QtxMRUAction* mru = (QtxMRUAction*)a;
679 mru->insert( aName );
681 mru->remove( aName );
686 //=======================================================================
687 // name : onHelpAbout
688 /*! Purpose : SLOT. Display "About" message box*/
689 //=======================================================================
690 void LightApp_Application::onHelpAbout()
692 LightApp_AboutDlg* dlg = new LightApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
697 /*!SLOT. Load document with \a aName.*/
698 bool LightApp_Application::onLoadDoc( const QString& aName )
700 bool res = CAM_Application::onLoadDoc( aName );
702 /*jfa tmp:QAction* a = action( MRUId );
703 if ( a && a->inherits( "QtxMRUAction" ) )
705 QtxMRUAction* mru = (QtxMRUAction*)a;
707 mru->insert( aName );
709 mru->remove( aName );
714 /*!Private SLOT. Selection.*/
715 void LightApp_Application::onSelection()
717 onSelectionChanged();
719 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
720 ((LightApp_Module*)activeModule())->selectionChanged();
724 *\param study - SUIT_Study.
726 void LightApp_Application::setActiveStudy( SUIT_Study* study )
728 CAM_Application::setActiveStudy( study );
733 //=======================================================================
734 // name : updateCommandsStatus
735 /*! Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu*/
736 //=======================================================================
737 void LightApp_Application::updateCommandsStatus()
739 CAM_Application::updateCommandsStatus();
741 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
743 QAction* a = action( id );
745 a->setEnabled( activeStudy() );
749 // Helps to execute command
750 class RunBrowser: public QThread {
753 RunBrowser(QString theApp, QString theParams, QString theHelpFile, QString theContext=NULL):
754 myApp(theApp), myParams(theParams),
756 myHelpFile("file://" + theHelpFile + theContext),
758 myHelpFile("file:" + theHelpFile + theContext),
766 if ( !myApp.isEmpty())
768 aCommand.sprintf("%s %s %s",myApp.latin1(),myParams.latin1(),myHelpFile.latin1());
769 myStatus = system(aCommand);
772 QCustomEvent* ce2000 = new QCustomEvent (2000);
773 postEvent (qApp, ce2000);
779 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
780 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").arg(myApp).arg(myHelpFile),
781 QObject::tr("BUT_OK"));
794 //=======================================================================
795 // name : onHelpContentsModule
796 /*! Purpose : SLOT. Display help contents for choosen module*/
797 //=======================================================================
798 void LightApp_Application::onHelpContentsModule()
800 const QAction* obj = (QAction*) sender();
802 QString aComponentName = obj->name();
803 QString aFileName = aComponentName + "_index_v3.1.0.html";
805 QCString dir = getenv( aComponentName + "_ROOT_DIR");
806 QString homeDir = Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("doc") + Qtx::addSlash("salome") );
808 QString helpFile = QFileInfo( homeDir + aFileName ).absFilePath();
809 SUIT_ResourceMgr* resMgr = resourceMgr();
810 QString anApp = resMgr->stringValue("ExternalBrowser", "application");
811 QString aParams = resMgr->stringValue("ExternalBrowser", "parameters");
813 if (!anApp.isEmpty()) {
814 RunBrowser* rs = new RunBrowser(anApp, aParams, helpFile);
818 SUIT_MessageBox::warn1(desktop(), tr("WRN_WARNING"),
819 tr("DEFINE_EXTERNAL_BROWSER"),
824 /*!Sets enable or disable some actions on selection changed.*/
825 void LightApp_Application::onSelectionChanged()
830 *\param flag - key for window
831 *\param studyId - study id
832 * Flag used how identificator of window in windows list.
834 QWidget* LightApp_Application::window( const int flag, const int studyId ) const
841 if ( !activeStudy() )
844 sId = activeStudy()->id();
847 if ( myWindows.contains( flag ) )
848 wid = myWindows[flag]->widget( sId );
853 /*!Adds window to application.
854 *\param wid - QWidget
855 *\param flag - key wor window
856 *\param studyId - study id
857 * Flag used how identificator of window in windows list.
859 void LightApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
867 if ( !activeStudy() )
870 sId = activeStudy()->id();
873 if ( !myWindows.contains( flag ) )
875 QMap<int, int> winMap;
876 currentWindows( winMap );
878 LightApp_WidgetContainer* newWC = new LightApp_WidgetContainer( flag, desktop() );
879 connect( newWC, SIGNAL( destroyed ( QObject* ) ), this, SLOT( onWCDestroyed( QObject* ) ) );
880 myWindows.insert( flag, newWC );
881 if ( winMap.contains( flag ) )
882 desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
884 myWindows[flag]->setResizeEnabled( true );
885 myWindows[flag]->setCloseMode( QDockWindow::Always );
886 myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
887 myWindows[flag]->setFixedExtentWidth( wid->width() );
888 myWindows[flag]->setFixedExtentHeight( wid->height() );
892 if( wid->inherits( "PythonConsole" ) )
894 if( resourceMgr()->hasValue( "PyConsole", "font" ) )
895 f = resourceMgr()->fontValue( "PyConsole", "font" );
898 f = ( ( PythonConsole* )wid )->font();
899 resourceMgr()->setValue( "PyConsole", "font", f );
905 myWindows[flag]->insert( sId, wid );
908 setWindowShown( flag, !myWindows[flag]->isEmpty() );
911 /*!Remove window from application.
912 *\param flag - key wor window
913 *\param studyId - study id
914 * Flag used how identificator of window in windows list.
916 void LightApp_Application::removeWindow( const int flag, const int studyId )
918 if ( !myWindows.contains( flag ) )
924 if ( !activeStudy() )
927 sId = activeStudy()->id();
930 QWidget* wid = myWindows[flag]->widget( sId );
931 myWindows[flag]->remove( sId );
934 setWindowShown( flag, !myWindows[flag]->isEmpty() );
938 *\param flag - key wor window
939 *\param studyId - study id
940 * Flag used how identificator of window in windows list.
942 QWidget* LightApp_Application::getWindow( const int flag, const int studyId )
944 QWidget* wid = window( flag, studyId );
946 addWindow( wid = createWindow( flag ), flag, studyId );
951 /*!Check is window visible?(with identificator \a type)*/
952 bool LightApp_Application::isWindowVisible( const int type ) const
955 if ( myWindows.contains( type ) )
957 SUIT_Desktop* desk = ((LightApp_Application*)this)->desktop();
958 res = desk && desk->appropriate( myWindows[type] );
963 /*!Sets window show or hide.
964 *\param type - window identificator.
965 *\param on - true/false (window show/hide)
967 void LightApp_Application::setWindowShown( const int type, const bool on )
969 if ( !desktop() || !myWindows.contains( type ) )
972 QDockWindow* dw = myWindows[type];
973 desktop()->setAppropriate( dw, on );
974 on ? dw->show() : dw->hide();
977 /*!Gets "ObjectBrowser".*/
978 OB_Browser* LightApp_Application::objectBrowser()
981 QWidget* wid = window( WT_ObjectBrowser );
982 if ( wid && wid->inherits( "OB_Browser" ) )
983 ob = (OB_Browser*)wid;
987 /*!Gets "LogWindow".*/
988 LogWindow* LightApp_Application::logWindow()
991 QWidget* wid = getWindow( WT_LogWindow );
992 if ( wid->inherits( "LogWindow" ) )
993 lw = (LogWindow*)wid;
997 /*!Get "PythonConsole"*/
998 PythonConsole* LightApp_Application::pythonConsole()
1000 PythonConsole* console = 0;
1001 QWidget* wid = getWindow( WT_PyConsole );
1002 if ( wid->inherits( "PythonConsole" ) )
1003 console = (PythonConsole*)wid;
1007 /*!Update obect browser*/
1008 void LightApp_Application::updateObjectBrowser( const bool updateModels )
1010 // update existing data models
1013 LightApp_Study* study = dynamic_cast<LightApp_Study*>(activeStudy());
1015 CAM_Study::ModelList dm_list;
1016 study->dataModels( dm_list );
1017 for ( CAM_Study::ModelListIterator it( dm_list ); it.current(); ++it ) {
1018 CAM_DataModel* camDM = it.current();
1019 if ( camDM && camDM->inherits( "LightApp_DataModel" ) )
1020 ((LightApp_DataModel*)camDM)->update();
1024 if ( objectBrowser() )
1026 objectBrowser()->updateGeometry();
1027 objectBrowser()->updateTree( 0, false );
1031 /*!Gets preferences.*/
1032 LightApp_Preferences* LightApp_Application::preferences() const
1034 return preferences( false );
1037 /*!Gets view manager*/
1038 SUIT_ViewManager* LightApp_Application::getViewManager( const QString& vmType, const bool create )
1040 SUIT_ViewManager* aVM = viewManager( vmType );
1041 SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
1043 if ( anActiveVM && anActiveVM->getType() == vmType )
1046 if ( aVM && create )
1048 if ( !aVM->getActiveView() )
1051 aVM->getActiveView()->setFocus();
1054 aVM = createViewManager( vmType );
1059 /*!Create view manager.*/
1060 SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType )
1062 SUIT_ResourceMgr* resMgr = resourceMgr();
1064 SUIT_ViewManager* viewMgr = 0;
1065 if( vmType == GLViewer_Viewer::Type() )
1067 viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
1068 new LightApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
1070 else if( vmType == Plot2d_Viewer::Type() )
1072 viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
1073 SPlot2d_Viewer* vm = new SPlot2d_Viewer();
1074 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1075 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( viewMgr->getActiveView() );
1078 Plot2d_ViewFrame* frame = wnd->getViewFrame();
1079 frame->setBackgroundColor( resMgr->colorValue( "Plot2d", "Background", frame->backgroundColor() ) );
1082 else if( vmType == SUPERVGraph_Viewer::Type() )
1084 viewMgr = new SUPERVGraph_ViewManager( activeStudy(), desktop() );
1085 SUPERVGraph_Viewer* vm = new SUPERVGraph_Viewer();
1086 SUPERVGraph_ViewFrame* view = dynamic_cast<SUPERVGraph_ViewFrame*>( vm->getViewManager()->getActiveView() );
1088 view->setBackgroundColor( resMgr->colorValue( "SUPERVGraph", "Background", view->backgroundColor() ) );
1090 else if( vmType == OCCViewer_Viewer::Type() )
1092 viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
1093 SOCC_Viewer* vm = new SOCC_Viewer();
1094 vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
1095 vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
1098 u = resMgr->integerValue( "OCCViewer", "iso_number_u", u );
1099 v = resMgr->integerValue( "OCCViewer", "iso_number_v", v );
1100 vm->setIsos( u, v );
1101 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1102 new LightApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
1104 else if ( vmType == SVTK_Viewer::Type() )
1106 viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
1107 SVTK_Viewer* vm = dynamic_cast<SVTK_Viewer*>( viewMgr->getViewModel() );
1110 vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
1111 vm->setTrihedronSize( resMgr->integerValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ) );
1112 new LightApp_VTKSelector( vm, mySelMgr );
1119 addViewManager( viewMgr );
1120 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
1122 if ( viewWin && desktop() )
1123 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
1125 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1126 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
1131 //=======================================================================
1132 // name : onCloseView
1133 /*! Purpose : SLOT. Remove view manager from application*/
1134 //=======================================================================
1135 void LightApp_Application::onCloseView( SUIT_ViewManager* theVM )
1137 removeViewManager( theVM );
1140 /*!Protected SLOT. On study created.*/
1141 void LightApp_Application::onStudyCreated( SUIT_Study* theStudy )
1143 SUIT_DataObject* aRoot = 0;
1144 if ( theStudy && theStudy->root() )
1146 aRoot = theStudy->root();
1147 //aRoot->setName( tr( "DATA_MODELS" ) );
1149 getWindow( WT_ObjectBrowser );
1150 if ( objectBrowser() != 0 )
1151 objectBrowser()->setRootObject( aRoot );
1153 activateModule( defaultModule() );
1158 /*!Protected SLOT. On study opened.*/
1159 void LightApp_Application::onStudyOpened( SUIT_Study* theStudy )
1161 SUIT_DataObject* aRoot = 0;
1162 if ( theStudy && theStudy->root() )
1164 aRoot = theStudy->root();
1167 getWindow( WT_ObjectBrowser );
1168 if ( objectBrowser() != 0 ) {
1169 objectBrowser()->setRootObject( aRoot );
1172 activateModule( defaultModule() );
1179 /*!Protected SLOT. On study saved.*/
1180 void LightApp_Application::onStudySaved( SUIT_Study* )
1185 /*!Protected SLOT. On study closed.*/
1186 void LightApp_Application::onStudyClosed( SUIT_Study* )
1190 // Bug 10396: clear selection
1191 mySelMgr->clearSelected();
1193 activateModule( "" );
1195 saveWindowsGeometry();
1198 /*!Protected SLOT.On desktop activated.*/
1199 void LightApp_Application::onDesktopActivated()
1201 CAM_Application::onDesktopActivated();
1202 LightApp_Module* aModule = dynamic_cast<LightApp_Module*>(activeModule());
1204 aModule->studyActivated();
1207 /*!Gets file filter.
1208 *\retval QString "(*.bin)"
1210 QString LightApp_Application::getFileFilter() const
1215 /*! Gets file name*/
1216 QString LightApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1217 const QString& caption, QWidget* parent )
1221 QStringList fls = QStringList::split( ";;", filters, false );
1222 return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1225 /*! Gets directory*/
1226 QString LightApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1230 return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1233 /*! Get open file names*/
1234 QStringList LightApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
1235 const QString& caption, QWidget* parent )
1239 QStringList fls = QStringList::split( ";;", filters, false );
1240 return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1243 /*!Private SLOT. Update object browser.*/
1244 void LightApp_Application::onRefresh()
1246 updateObjectBrowser( true );
1249 /*!Private SLOT. On preferences.*/
1250 void LightApp_Application::onPreferences()
1252 QApplication::setOverrideCursor( Qt::waitCursor );
1254 LightApp_PreferencesDlg* prefDlg = new LightApp_PreferencesDlg( preferences( true ), desktop());
1256 QApplication::restoreOverrideCursor();
1261 if ( ( prefDlg->exec() == QDialog::Accepted || prefDlg->isSaved() ) && resourceMgr() ) {
1263 desktop()->saveGeometry( resourceMgr(), "desktop" );
1264 resourceMgr()->save();
1270 /*!Protected SLOT. On preferences changed.*/
1271 void LightApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1273 LightApp_Module* sMod = 0;
1274 CAM_Module* mod = module( modName );
1275 if ( mod && mod->inherits( "LightApp_Module" ) )
1276 sMod = (LightApp_Module*)mod;
1279 sMod->preferencesChanged( section, param );
1281 preferencesChanged( section, param );
1284 /*!Private SLOT. On open document with name \a aName.*/
1285 void LightApp_Application::onMRUActivated( QString aName )
1290 /*!Remove all windows from study.*/
1291 void LightApp_Application::beforeCloseDoc( SUIT_Study* s )
1293 CAM_Application::beforeCloseDoc( s );
1295 for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1296 removeWindow( itr.key(), s->id() );
1299 /*!Update actions.*/
1300 void LightApp_Application::updateActions()
1302 updateCommandsStatus();
1305 //=======================================================================
1306 // name : createNewStudy
1307 /*! Purpose : Create new study*/
1308 //=======================================================================
1309 SUIT_Study* LightApp_Application::createNewStudy()
1311 LightApp_Study* aStudy = new LightApp_Study( this );
1313 // Set up processing of major study-related events
1314 connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
1315 connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
1316 connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );
1317 connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
1323 QWidget* LightApp_Application::createWindow( const int flag )
1326 if ( flag == WT_ObjectBrowser )
1328 OB_Browser* ob = new OB_Browser( desktop() );
1329 ob->setAutoUpdate( true );
1330 ob->setAutoOpenLevel( 1 );
1331 ob->setCaption( tr( "OBJECT_BROWSER" ) );
1333 OB_ListView* ob_list = dynamic_cast<OB_ListView*>( const_cast<QListView*>( ob->listView() ) );
1335 ob_list->setColumnMaxWidth( 0, desktop()->width()/4 );
1337 ob->setFilter( new LightApp_OBFilter( selectionMgr() ) );
1338 ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1340 // Create OBSelector
1341 new LightApp_OBSelector( ob, mySelMgr );
1345 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1347 else if ( flag == WT_PyConsole )
1349 PythonConsole* pyCons = new PythonConsole( desktop() );
1350 pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1352 // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1354 else if ( flag == WT_LogWindow )
1356 LogWindow* logWin = new LogWindow( desktop() );
1357 logWin->setCaption( tr( "LOG_WINDOW" ) );
1359 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1364 /*!Default windows(Object Browser, Python Console).
1365 * Adds to map \a aMap.
1367 void LightApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1369 aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1370 aMap.insert( WT_PyConsole, Qt::DockBottom );
1371 // aMap.insert( WT_LogWindow, Qt::DockBottom );
1374 /*!Default view manager.*/
1375 void LightApp_Application::defaultViewManagers( QStringList& ) const
1380 /*!Gets preferences.
1381 * Create preferences, if \a crt = true.
1383 LightApp_Preferences* LightApp_Application::preferences( const bool crt ) const
1388 LightApp_Application* that = (LightApp_Application*)this;
1390 bool toCreate = !_prefs_ && crt;
1393 _prefs_ = new LightApp_Preferences( resourceMgr() );
1394 that->createPreferences( _prefs_ );
1397 that->myPrefs = _prefs_;
1399 QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1400 for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1402 if ( !appIt.current()->inherits( "LightApp_Application" ) )
1405 LightApp_Application* app = (LightApp_Application*)appIt.current();
1407 QStringList modNameList;
1408 app->modules( modNameList, false );
1409 for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1411 int id = _prefs_->addPreference( *it );
1412 _prefs_->setItemProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1416 app->modules( modList );
1417 for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1419 LightApp_Module* mod = 0;
1420 if ( itr.current()->inherits( "LightApp_Module" ) )
1421 mod = (LightApp_Module*)itr.current();
1423 if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1425 int modCat = _prefs_->addPreference( mod->moduleName() );
1426 _prefs_->setItemProperty( modCat, "info", QString::null );
1428 mod->createPreferences();
1433 connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1434 this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1439 /*!Add new module to application.*/
1440 void LightApp_Application::moduleAdded( CAM_Module* mod )
1442 CAM_Application::moduleAdded( mod );
1444 LightApp_Module* lightMod = 0;
1445 if ( mod && mod->inherits( "LightApp_Module" ) )
1446 lightMod = (LightApp_Module*)mod;
1448 if ( myPrefs && lightMod && !myPrefs->hasModule( lightMod->moduleName() ))
1450 int modCat = myPrefs->addPreference( mod->moduleName() );
1451 myPrefs->setItemProperty( modCat, "info", QString::null );
1452 lightMod->createPreferences();
1456 /*!Create preferences.*/
1457 void LightApp_Application::createPreferences( LightApp_Preferences* pref )
1462 int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1464 int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1465 int studyGroup = pref->addPreference( tr( "PREF_GROUP_STUDY" ), genTab );
1466 pref->setItemProperty( studyGroup, "columns", 1 );
1468 pref->addPreference( tr( "PREF_MULTI_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "multi_file" );
1469 pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "ascii_file" );
1470 int undoPref = pref->addPreference( tr( "PREF_UNDO_LEVEL" ), studyGroup, LightApp_Preferences::IntSpin, "Study", "undo_level" );
1471 pref->setItemProperty( undoPref, "min", 1 );
1472 pref->setItemProperty( undoPref, "max", 100 );
1473 pref->addPreference( tr( "PREF_STORE_POS" ), studyGroup, LightApp_Preferences::Bool, "Study", "store_positions" );
1475 int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab );
1476 pref->setItemProperty( extgroup, "columns", 1 );
1477 int apppref = pref->addPreference( tr( "PREF_APP" ), extgroup, LightApp_Preferences::File, "ExternalBrowser", "application" );
1478 pref->setItemProperty( apppref, "existing", true );
1479 pref->setItemProperty( apppref, "flags", QFileInfo::ExeUser );
1480 pref->setItemProperty( apppref, "readOnly", false );
1482 pref->addPreference( tr( "PREF_PARAM" ), extgroup, LightApp_Preferences::String, "ExternalBrowser", "parameters" );
1484 int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab );
1485 pref->setItemProperty( pythonConsoleGroup, "columns", 1 );
1486 pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, LightApp_Preferences::Font, "PyConsole", "font" );
1488 int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1490 int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1492 int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1494 int plot2dGroup = pref->addPreference( tr( "PREF_GROUP_PLOT2DVIEWER" ), viewTab );
1496 int supervGroup = pref->addPreference( tr( "PREF_GROUP_SUPERV" ), viewTab );
1498 pref->setItemProperty( occGroup, "columns", 1 );
1499 pref->setItemProperty( vtkGroup, "columns", 1 );
1500 pref->setItemProperty( plot2dGroup, "columns", 1 );
1502 int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1503 LightApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1504 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1505 LightApp_Preferences::Color, "OCCViewer", "background" );
1507 pref->setItemProperty( occTS, "min", 1 );
1508 pref->setItemProperty( occTS, "max", 150 );
1510 int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
1511 LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
1512 int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
1513 LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
1515 pref->setItemProperty( isoU, "min", 0 );
1516 pref->setItemProperty( isoU, "max", 100000 );
1518 pref->setItemProperty( isoV, "min", 0 );
1519 pref->setItemProperty( isoV, "max", 100000 );
1521 int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1522 LightApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1523 pref->addPreference( tr( "PREF_RELATIVE_SIZE" ), vtkGroup, LightApp_Preferences::Bool, "VTKViewer", "relative_size" );
1524 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1525 LightApp_Preferences::Color, "VTKViewer", "background" );
1527 pref->setItemProperty( vtkTS, "min", 1 );
1528 pref->setItemProperty( vtkTS, "max", 150 );
1530 pref->addPreference( tr( "PREF_SHOW_LEGEND" ), plot2dGroup,
1531 LightApp_Preferences::Bool, "Plot2d", "ShowLegend" );
1533 int legendPosition = pref->addPreference( tr( "PREF_LEGEND_POSITION" ), plot2dGroup,
1534 LightApp_Preferences::Selector, "Plot2d", "LegendPos" );
1535 QStringList aLegendPosList;
1536 aLegendPosList.append( tr("PREF_LEFT") );
1537 aLegendPosList.append( tr("PREF_RIGHT") );
1538 aLegendPosList.append( tr("PREF_TOP") );
1539 aLegendPosList.append( tr("PREF_BOTTOM") );
1541 QValueList<QVariant> anIndexesList;
1542 anIndexesList.append(0);
1543 anIndexesList.append(1);
1544 anIndexesList.append(2);
1545 anIndexesList.append(3);
1547 pref->setItemProperty( legendPosition, "strings", aLegendPosList );
1548 pref->setItemProperty( legendPosition, "indexes", anIndexesList );
1550 int curveType = pref->addPreference( tr( "PREF_CURVE_TYPE" ), plot2dGroup,
1551 LightApp_Preferences::Selector, "Plot2d", "CurveType" );
1552 QStringList aCurveTypesList;
1553 aCurveTypesList.append( tr("PREF_POINTS") );
1554 aCurveTypesList.append( tr("PREF_LINES") );
1555 aCurveTypesList.append( tr("PREF_SPLINE") );
1557 anIndexesList.clear();
1558 anIndexesList.append(0);
1559 anIndexesList.append(1);
1560 anIndexesList.append(2);
1562 pref->setItemProperty( curveType, "strings", aCurveTypesList );
1563 pref->setItemProperty( curveType, "indexes", anIndexesList );
1565 int markerSize = pref->addPreference( tr( "PREF_MARKER_SIZE" ), plot2dGroup,
1566 LightApp_Preferences::IntSpin, "Plot2d", "MarkerSize" );
1568 pref->setItemProperty( markerSize, "min", 0 );
1569 pref->setItemProperty( markerSize, "max", 100 );
1571 QStringList aScaleModesList;
1572 aScaleModesList.append( tr("PREF_LINEAR") );
1573 aScaleModesList.append( tr("PREF_LOGARITHMIC") );
1575 anIndexesList.clear();
1576 anIndexesList.append(0);
1577 anIndexesList.append(1);
1579 int horScale = pref->addPreference( tr( "PREF_HOR_AXIS_SCALE" ), plot2dGroup,
1580 LightApp_Preferences::Selector, "Plot2d", "HorScaleMode" );
1582 pref->setItemProperty( horScale, "strings", aScaleModesList );
1583 pref->setItemProperty( horScale, "indexes", anIndexesList );
1585 int verScale = pref->addPreference( tr( "PREF_VERT_AXIS_SCALE" ), plot2dGroup,
1586 LightApp_Preferences::Selector, "Plot2d", "VerScaleMode" );
1588 pref->setItemProperty( verScale, "strings", aScaleModesList );
1589 pref->setItemProperty( verScale, "indexes", anIndexesList );
1591 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), plot2dGroup,
1592 LightApp_Preferences::Color, "Plot2d", "Background" );
1594 int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat );
1595 int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab );
1596 pref->setItemProperty( dirGroup, "columns", 1 );
1597 pref->addPreference( tr( "" ), dirGroup,
1598 LightApp_Preferences::DirList, "FileDlg", "QuickDirList" );
1600 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), supervGroup,
1601 LightApp_Preferences::Color, "SUPERVGraph", "Background" );
1602 pref->addPreference( tr( "PREF_SUPERV_TITLE_COLOR" ), supervGroup,
1603 LightApp_Preferences::Color, "SUPERVGraph", "Title" );
1604 // pref->addPreference( tr( "PREF_SUPERV_CTRL_COLOR" ), supervGroup,
1605 // LightApp_Preferences::Color, "SUPERVGraph", "Ctrl" );
1607 int obTab = pref->addPreference( tr( "PREF_TAB_OBJBROWSER" ), salomeCat );
1608 int objSetGroup = pref->addPreference( tr( "PREF_OBJ_BROWSER_SETTINGS" ), obTab );
1609 pref->addPreference( tr( "PREF_AUTO_SIZE_FIRST" ), objSetGroup, LightApp_Preferences::Bool,
1610 "ObjectBrowser", "auto_size_first" );
1611 pref->addPreference( tr( "PREF_AUTO_SIZE" ), objSetGroup, LightApp_Preferences::Bool,
1612 "ObjectBrowser", "auto_size" );
1615 /*!Changed preferences */
1616 void LightApp_Application::preferencesChanged( const QString& sec, const QString& param )
1618 SUIT_ResourceMgr* resMgr = resourceMgr();
1622 if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1624 int sz = resMgr->integerValue( sec, param, -1 );
1625 QPtrList<SUIT_ViewManager> lst;
1626 viewManagers( OCCViewer_Viewer::Type(), lst );
1627 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1629 SUIT_ViewModel* vm = it.current()->getViewModel();
1630 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1633 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1634 occVM->setTrihedronSize( sz );
1635 occVM->getAISContext()->UpdateCurrentViewer();
1639 if ( sec == QString( "VTKViewer" ) && (param == QString( "trihedron_size" ) || param == QString( "relative_size" )) )
1641 int sz = resMgr->integerValue( "VTKViewer", "trihedron_size", -1 );
1642 QPtrList<SUIT_ViewManager> lst;
1643 viewManagers( SVTK_Viewer::Type(), lst );
1644 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1646 SUIT_ViewModel* vm = it.current()->getViewModel();
1647 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
1650 SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
1653 vtkVM->setTrihedronSize( sz );
1659 if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
1661 QPtrList<SUIT_ViewManager> lst;
1662 viewManagers( OCCViewer_Viewer::Type(), lst );
1663 int u = resMgr->integerValue( sec, "iso_number_u" );
1664 int v = resMgr->integerValue( sec, "iso_number_v" );
1665 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
1667 OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>( it.current() );
1668 if( mgr && mgr->getOCCViewer() )
1669 mgr->getOCCViewer()->setIsos( u, v );
1673 if( sec=="ObjectBrowser" )
1675 if( param=="auto_size" || param=="auto_size_first" )
1677 OB_Browser* ob = objectBrowser();
1681 bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false ),
1682 autoSizeFirst = resMgr->booleanValue( "ObjectBrowser", "auto_size_first", true );
1683 ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1684 ob->listView()->setColumnWidthMode( 0, autoSizeFirst ? QListView::Maximum : QListView::Manual );
1685 updateObjectBrowser( false );
1691 if( param=="store_positions" )
1695 if( sec=="PyConsole" )
1698 if( pythonConsole() )
1699 pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1703 /*!Update desktop title.*/
1704 void LightApp_Application::updateDesktopTitle() {
1705 QString aTitle = applicationName();
1706 QString aVer = applicationVersion();
1707 if ( !aVer.isEmpty() )
1708 aTitle += QString( " " ) + aVer;
1710 desktop()->setCaption( aTitle );
1713 /*!Update windows after close document.*/
1714 void LightApp_Application::afterCloseDoc()
1718 CAM_Application::afterCloseDoc();
1721 /*!Update module action.*/
1722 void LightApp_Application::updateModuleActions()
1725 if ( activeModule() )
1726 modName = activeModule()->moduleName();
1728 if ( myActions.contains( modName ) )
1729 myActions[modName]->setOn( true );
1732 /*!Gets current windows.
1733 *\param winMap - output current windows map.
1735 void LightApp_Application::currentWindows( QMap<int, int>& winMap ) const
1738 if ( !activeStudy() )
1741 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
1742 ((LightApp_Module*)activeModule())->windows( winMap );
1744 defaultWindows( winMap );
1747 /*!Gets current view managers.
1748 *\param lst - output current view managers list.
1750 void LightApp_Application::currentViewManagers( QStringList& lst ) const
1753 if ( !activeStudy() )
1756 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
1757 ((LightApp_Module*)activeModule())->viewManagers( lst );
1759 defaultViewManagers( lst );
1762 /*!Update windows.*/
1763 void LightApp_Application::updateWindows()
1765 QMap<int, int> winMap;
1766 currentWindows( winMap );
1768 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1769 getWindow( it.key() );
1771 loadWindowsGeometry();
1773 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1774 setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1777 /*!Update view managers.*/
1778 void LightApp_Application::updateViewManagers()
1781 currentViewManagers( lst );
1783 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1784 getViewManager( *it, true );
1787 /*!Load windows geometry.*/
1788 void LightApp_Application::loadWindowsGeometry()
1790 bool store = resourceMgr()->booleanValue( "Study", "store_positions", true );
1794 QtxDockAction* dockMgr = 0;
1796 QAction* a = action( ViewWindowsId );
1797 if ( a && a->inherits( "QtxDockAction" ) )
1798 dockMgr = (QtxDockAction*)a;
1804 if ( activeModule() )
1805 modName = activeModule()->name("");
1807 QString section = QString( "windows_geometry" );
1808 if ( !modName.isEmpty() )
1809 section += QString( "." ) + modName;
1811 dockMgr->loadGeometry( resourceMgr(), section, false );
1812 dockMgr->restoreGeometry();
1815 /*!Save windows geometry.*/
1816 void LightApp_Application::saveWindowsGeometry()
1818 bool store = resourceMgr()->booleanValue( "Study", "store_positions", true );
1822 QtxDockAction* dockMgr = 0;
1824 QAction* a = action( ViewWindowsId );
1825 if ( a && a->inherits( "QtxDockAction" ) )
1826 dockMgr = (QtxDockAction*)a;
1832 if ( activeModule() )
1833 modName = activeModule()->name("");
1835 QString section = QString( "windows_geometry" );
1836 if ( !modName.isEmpty() )
1837 section += QString( "." ) + modName;
1839 dockMgr->storeGeometry();
1840 dockMgr->saveGeometry( resourceMgr(), section, false );
1843 /*!Activate windows.*/
1844 void LightApp_Application::activateWindows()
1846 if ( activeStudy() )
1848 for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1849 itr.data()->activate( activeStudy()->id() );
1853 /*!Adds icon names for modules.*/
1854 void LightApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
1858 SUIT_ResourceMgr* resMgr = resourceMgr();
1862 QStringList modList;
1863 modules( modList, false );
1865 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
1867 QString modName = *it;
1868 QString modIntr = moduleName( modName );
1869 QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
1871 if ( modIcon.isEmpty() )
1874 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
1875 modIcon += QString( ".png" );
1877 iconMap.insert( modName, modIcon );
1881 /*!Insert items in popup, which necessary for current application*/
1882 void LightApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
1884 CAM_Application::contextMenuPopup( type, thePopup, title );
1886 OB_Browser* ob = objectBrowser();
1887 if ( !ob || type != ob->popupClientType() )
1890 thePopup->insertSeparator();
1891 thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
1894 /*!Create empty study.*/
1895 void LightApp_Application::createEmptyStudy()
1897 CAM_Application::createEmptyStudy();
1898 if ( objectBrowser() )
1899 objectBrowser()->updateTree();
1902 /*!Activate module \a mod.*/
1903 bool LightApp_Application::activateModule( CAM_Module* mod )
1905 bool res = CAM_Application::activateModule( mod );
1906 if ( objectBrowser() )
1907 objectBrowser()->updateTree();
1911 /*!return keyborad accelerators manager object */
1912 SUIT_Accel* LightApp_Application::accel() const
1917 /*! remove dead widget container from map */
1918 void LightApp_Application::onWCDestroyed( QObject* ob )
1920 // remove destroyed widget container from windows map
1921 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1923 if ( itr.data() != ob )
1926 int key = itr.key();
1927 myWindows.remove( key );
1932 /*! redefined to remove view manager from memory */
1933 void LightApp_Application::removeViewManager( SUIT_ViewManager* vm )
1935 disconnect( vm, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1936 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
1937 STD_Application::removeViewManager( vm );
1941 /*! rename active window of desktop */
1942 void LightApp_Application::onRenameWindow()
1947 QWidget* w = desktop()->activeWindow();
1952 QString name = QInputDialog::getText( tr( "TOT_RENAME" ), tr( "PRP_RENAME" ), QLineEdit::Normal, w->caption(), &ok, w );
1953 if( ok && !name.isEmpty() )
1954 w->setCaption( name );