1 // File: LightApp_Application.cxx
2 // Created: 6/20/2005 18:39:45 PM
3 // Author: Natalia Donis
4 // Copyright (C) CEA 2005
6 #include "PythonConsole_PyInterp.h" // WARNING! This include must be the first!
8 #include "LightApp_Application.h"
9 #include "LightApp_WidgetContainer.h"
10 #include "LightApp_Module.h"
11 #include "LightApp_DataModel.h"
12 #include "LightApp_Study.h"
13 #include "LightApp_Preferences.h"
14 #include "LightApp_PreferencesDlg.h"
15 #include "LightApp_ModuleDlg.h"
16 #include "LightApp_AboutDlg.h"
18 #include "LightApp_OBFilter.h"
20 #include "LightApp_GLSelector.h"
21 #include "LightApp_OBSelector.h"
22 #include "LightApp_OCCSelector.h"
23 #include "LightApp_VTKSelector.h"
24 #include "LightApp_SelectionMgr.h"
26 #include <CAM_Module.h>
27 #include <CAM_DataModel.h>
28 #include <CAM_Study.h>
29 #include <STD_TabDesktop.h>
31 #include <SUIT_Session.h>
32 #include <SUIT_Study.h>
33 #include <SUIT_FileDlg.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_Tools.h>
36 #include <SUIT_Accel.h>
38 #include <QtxMRUAction.h>
39 #include <QtxDockAction.h>
40 #include <QtxToolBar.h>
42 #include <LogWindow.h>
43 #include <OB_Browser.h>
44 #include <PythonConsole_PyConsole.h>
46 #include <GLViewer_Viewer.h>
47 #include <GLViewer_ViewManager.h>
49 #include <Plot2d_ViewManager.h>
50 #include <Plot2d_ViewModel.h>
51 #include <SPlot2d_ViewModel.h>
53 #include <OCCViewer_ViewManager.h>
54 #include <SOCC_ViewModel.h>
56 #include <SVTK_ViewModel.h>
57 #include <SVTK_ViewManager.h>
58 #include <VTKViewer_ViewModel.h>
60 #include <SUPERVGraph_ViewModel.h>
61 #include <SUPERVGraph_ViewFrame.h>
62 #include <SUPERVGraph_ViewManager.h>
64 #include <QtxWorkstack.h>
70 #include <qstringlist.h>
72 #include <qapplication.h>
74 #include <qstatusbar.h>
76 #include <qobjectlist.h>
77 #include <qcombobox.h>
78 #include <qinputdialog.h>
80 #define OBJECT_BROWSER_WIDTH 300
81 #define OBJECT_COLUMN_WIDTH 150
83 #define DEFAULT_BROWSER "mozilla"
85 #define FIRST_HELP_ID 1000000
87 #include "SALOME_InteractiveObject.hxx"
88 #include "SALOME_ListIO.hxx"
90 static const char* imageEmptyIcon[] = {
93 "....................",
94 "....................",
95 "....................",
96 "....................",
97 "....................",
98 "....................",
99 "....................",
100 "....................",
101 "....................",
102 "....................",
103 "....................",
104 "....................",
105 "....................",
106 "....................",
107 "....................",
108 "....................",
109 "....................",
110 "....................",
111 "....................",
112 "...................."};
114 /*!Create new instance of LightApp_Application.*/
115 extern "C" LIGHTAPP_EXPORT SUIT_Application* createApplication()
117 return new LightApp_Application();
120 LightApp_Preferences* LightApp_Application::_prefs_ = 0;
123 Class : LightApp_Application
124 Description : Application containing LightApp module
128 LightApp_Application::LightApp_Application()
129 : CAM_Application( false ),
132 STD_TabDesktop* desk = new STD_TabDesktop();
136 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
137 QPixmap aLogo = aResMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false );
139 desktop()->setIcon( aLogo );
140 desktop()->setDockableMenuBar( true );
141 desktop()->setDockableStatusBar( false );
143 // base logo (salome itself)
144 desktop()->addLogo( "_app_base", aResMgr->loadPixmap( "LightApp", tr( "APP_BASE_LOGO" ), false ) );
145 // extra logo (salome-based application)
146 desktop()->addLogo( "_app_extra", aResMgr->loadPixmap( "LightApp", tr( "APP_EXTRA_LOGO" ), false ) );
150 mySelMgr = new LightApp_SelectionMgr( this );
152 myAccel = new SUIT_Accel( desktop() );
153 myAccel->setActionKey( SUIT_Accel::PanLeft, CTRL+Key_Left, OCCViewer_Viewer::Type() );
154 myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, OCCViewer_Viewer::Type() );
155 myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, OCCViewer_Viewer::Type() );
156 myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, OCCViewer_Viewer::Type() );
157 myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, OCCViewer_Viewer::Type() );
158 myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, OCCViewer_Viewer::Type() );
159 myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, OCCViewer_Viewer::Type() );
160 myAccel->setActionKey( SUIT_Accel::RotateLeft, ALT+Key_Left, OCCViewer_Viewer::Type() );
161 myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right, OCCViewer_Viewer::Type() );
162 myAccel->setActionKey( SUIT_Accel::RotateUp, ALT+Key_Up, OCCViewer_Viewer::Type() );
163 myAccel->setActionKey( SUIT_Accel::RotateDown, ALT+Key_Down, OCCViewer_Viewer::Type() );
164 myAccel->setActionKey( SUIT_Accel::PanLeft, CTRL+Key_Left, VTKViewer_Viewer::Type() );
165 myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, VTKViewer_Viewer::Type() );
166 myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, VTKViewer_Viewer::Type() );
167 myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, VTKViewer_Viewer::Type() );
168 myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, VTKViewer_Viewer::Type() );
169 myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, VTKViewer_Viewer::Type() );
170 myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, VTKViewer_Viewer::Type() );
171 myAccel->setActionKey( SUIT_Accel::RotateLeft, ALT+Key_Left, VTKViewer_Viewer::Type() );
172 myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right, VTKViewer_Viewer::Type() );
173 myAccel->setActionKey( SUIT_Accel::RotateUp, ALT+Key_Up, VTKViewer_Viewer::Type() );
174 myAccel->setActionKey( SUIT_Accel::RotateDown, ALT+Key_Down, VTKViewer_Viewer::Type() );
176 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) );
180 *\li Save window geometry.
181 *\li Save desktop geometry.
182 *\li Save resource maneger.
183 *\li Delete selection manager.
185 LightApp_Application::~LightApp_Application()
187 saveWindowsGeometry();
192 desktop()->saveGeometry( resourceMgr(), "desktop" );
193 resourceMgr()->save();
198 /*!Start application.*/
199 void LightApp_Application::start()
202 desktop()->loadGeometry( resourceMgr(), "desktop" );
204 CAM_Application::start();
206 QAction* a = action( ViewWindowsId );
207 if ( a && a->inherits( "QtxDockAction" ) )
208 ((QtxDockAction*)a)->setAutoPlace( true );
211 updateViewManagers();
214 desktop()->statusBar()->message( "" );
217 /*!Gets application name.*/
218 QString LightApp_Application::applicationName() const
220 return tr( "APP_NAME" );
223 /*!Gets application version.*/
224 QString LightApp_Application::applicationVersion() const
226 static QString _app_version;
228 if ( _app_version.isEmpty() )
230 QString resVersion = tr( "APP_VERSION" );
231 if ( resVersion != "APP_VERSION" )
233 _app_version = resVersion;
237 QString path( ::getenv( "GUI_ROOT_DIR" ) );
238 if ( !path.isEmpty() )
239 path += QDir::separator();
240 path += QString( "bin/salome/VERSION" );
243 if ( vf.open( IO_ReadOnly ) )
246 vf.readLine( line, 1024 );
249 if ( !line.isEmpty() )
251 while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
252 line.remove( line.length() - 1, 1 );
254 int idx = line.findRev( ":" );
256 _app_version = line.mid( idx + 1 ).stripWhiteSpace();
264 /*!Load module by \a name.*/
265 CAM_Module* LightApp_Application::loadModule( const QString& name )
267 CAM_Module* mod = CAM_Application::loadModule( name );
270 connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) );
271 connect( this, SIGNAL( studySaved() ), mod, SLOT( onModelSaved() ) );
272 connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) );
277 /*!Activate module by \a modName*/
278 bool LightApp_Application::activateModule( const QString& modName )
281 CAM_Module* prevMod = activeModule();
284 actName = prevMod->moduleName();
286 if ( actName == modName )
289 putInfo( tr( "ACTIVATING_MODULE" ).arg( modName ) );
291 saveWindowsGeometry();
293 bool status = CAM_Application::activateModule( modName );
295 updateModuleActions();
303 updateViewManagers();
308 bool LightApp_Application::useStudy(const QString& theName)
311 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>(activeStudy());
314 res = aStudy->loadDocument( theName );
315 updateDesktopTitle();
316 updateCommandsStatus();
320 /*!Gets selection manager.*/
321 LightApp_SelectionMgr* LightApp_Application::selectionMgr() const
327 void LightApp_Application::createActions()
329 STD_Application::createActions();
331 SUIT_Desktop* desk = desktop();
332 SUIT_ResourceMgr* resMgr = resourceMgr();
335 createAction( PreferencesId, tr( "TOT_DESK_PREFERENCES" ), QIconSet(),
336 tr( "MEN_DESK_PREFERENCES" ), tr( "PRP_DESK_PREFERENCES" ),
337 CTRL+Key_P, desk, false, this, SLOT( onPreferences() ) );
340 int helpMenu = createMenu( tr( "MEN_DESK_HELP" ), -1, -1, 1000 );
341 int helpModuleMenu = createMenu( tr( "MEN_DESK_MODULE_HELP" ), helpMenu, -1, 0 );
342 createMenu( separator(), helpMenu, -1, 1 );
344 QStringList aModuleList;
345 modules( aModuleList, false );
347 int id = LightApp_Application::UserID + FIRST_HELP_ID;
348 // help for KERNEL and GUI
353 if (dir = getenv("GUI_ROOT_DIR")) {
354 aFileName = "GUI_index_v3.1.0.html";
355 root = Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("doc") + Qtx::addSlash("salome") );
356 if ( QFileInfo( root + aFileName ).exists() ) {
357 a = createAction( id, tr( QString("Kernel & GUI Help") ), QIconSet(),
358 tr( QString("Kernel && GUI Help") ),
359 tr( QString("Kernel & GUI Help") ),
360 0, desk, false, this, SLOT( onHelpContentsModule() ) );
361 a->setName( QString("GUI") );
362 createMenu( a, helpModuleMenu, -1 );
366 // help for other existing modules
367 QStringList::Iterator it;
368 for ( it = aModuleList.begin(); it != aModuleList.end(); ++it )
370 if ( (*it).isEmpty() )
373 QString modName = moduleName( *it );
374 aFileName = modName + "_index_v3.1.0.html";
376 if (dir = getenv( modName + "_ROOT_DIR")) {
377 root = Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("doc") + Qtx::addSlash("salome") );
378 if ( QFileInfo( root + aFileName ).exists() ) {
380 QAction* a = createAction( id, tr( moduleTitle(modName) + QString(" Help") ), QIconSet(),
381 tr( moduleTitle(modName) + QString(" Help") ),
382 tr( moduleTitle(modName) + QString(" Help") ),
383 0, desk, false, this, SLOT( onHelpContentsModule() ) );
384 a->setName( modName );
385 createMenu( a, helpModuleMenu, -1 );
392 QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), desk );
393 connect( mru, SIGNAL( activated( QString ) ), this, SLOT( onMRUActivated( QString ) ) );
394 registerAction( MRUId, mru );
396 // default icon for neutral point ('SALOME' module)
397 QPixmap defIcon = resMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false );
398 if ( defIcon.isNull() )
399 defIcon = QPixmap( imageEmptyIcon );
401 //! default icon for any module
402 QPixmap modIcon = resMgr->loadPixmap( "LightApp", tr( "APP_MODULE_ICO" ), false );
403 if ( modIcon.isNull() )
404 modIcon = QPixmap( imageEmptyIcon );
406 QToolBar* modTBar = new QtxToolBar( true, desk );
407 modTBar->setLabel( tr( "INF_TOOLBAR_MODULES" ) );
409 QActionGroup* modGroup = new QActionGroup( this );
410 modGroup->setExclusive( true );
411 modGroup->setUsesDropDown( true );
413 a = createAction( -1, tr( "APP_NAME" ), defIcon, tr( "APP_NAME" ),
414 tr( "PRP_APP_MODULE" ), 0, desk, true );
416 myActions.insert( QString(), a );
418 QMap<QString, QString> iconMap;
419 moduleIconNames( iconMap );
421 const int iconSize = 20;
423 modGroup->addTo( modTBar );
424 QObjectList *l = modTBar->queryList( "QComboBox" );
425 QObjectListIt oit( *l );
426 while ( QObject* obj = oit.current() ) {
427 QComboBox* cb = (QComboBox*)obj;
428 if ( cb ) cb->setFocusPolicy( QWidget::NoFocus );
433 modTBar->addSeparator();
436 modules( modList, false );
438 for ( it = modList.begin(); it != modList.end(); ++it )
440 if ( (*it).isEmpty() )
444 if ( iconMap.contains( *it ) )
445 iconName = iconMap[*it];
447 QString modName = moduleName( *it );
449 QPixmap icon = resMgr->loadPixmap( modName, iconName, false );
453 icon.convertFromImage( icon.convertToImage().smoothScale( iconSize, iconSize, QImage::ScaleMin ) );
455 QAction* a = createAction( -1, *it, icon, *it, tr( "PRP_MODULE" ).arg( *it ), 0, desk, true );
459 myActions.insert( *it, a );
462 SUIT_Tools::simplifySeparators( modTBar );
465 int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 );
466 int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
467 createMenu( separator(), windowMenu, -1, 1 );
469 QMap<int, int> accelMap;
470 accelMap[NewGLViewId] = ALT+Key_G;
471 accelMap[NewPlot2dId] = ALT+Key_P;
472 accelMap[NewOCCViewId] = ALT+Key_O;
473 accelMap[NewVTKViewId] = ALT+Key_K;
475 for ( id = NewGLViewId; id <= NewVTKViewId; id++ )
477 QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), QIconSet(),
478 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
479 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
480 accelMap.contains( id ) ? accelMap[id] : 0, desk, false, this, SLOT( onNewWindow() ) );
481 createMenu( a, newWinMenu, -1 );
484 createAction( RenameId, tr( "TOT_RENAME" ), QIconSet(), tr( "MEN_RENAME" ), tr( "PRP_RENAME" ),
485 0, desk, false, this, SLOT( onRenameWindow() ) );
486 createMenu( RenameId, windowMenu, -1 );
488 connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) );
490 int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
491 createMenu( PreferencesId, fileMenu, 15, -1 );
492 createMenu( separator(), fileMenu, -1, 15, -1 );
495 createMenu( separator(), fileMenu, -1, 100, -1 );
496 createMenu( MRUId, fileMenu, 100, -1 );
497 createMenu( separator(), fileMenu, -1, 100, -1 );
501 /*!On module activation action.*/
502 void LightApp_Application::onModuleActivation( QAction* a )
507 QString modName = a->menuText();
508 if ( modName == tr( "APP_NAME" ) )
509 modName = QString::null;
511 // Force user to create/open a study before module activation
512 QMap<QString, QString> iconMap;
513 moduleIconNames( iconMap );
514 QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ], false );
516 icon = resourceMgr()->loadPixmap( "LightApp", tr( "APP_MODULE_BIG_ICO" ), false ); // default icon for any module
518 bool cancelled = false;
519 while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
520 LightApp_ModuleDlg aDlg( desktop(), modName, icon );
521 int res = aDlg.exec();
535 putInfo( tr("INF_CANCELLED") );
536 myActions[QString()]->setOn( true );
542 activateModule( modName );
545 /*!Default module activation.*/
546 QString LightApp_Application::defaultModule() const
548 QStringList aModuleNames;
549 modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration
550 //! If there's the one and only module --> activate it automatically
551 //! TODO: Possible improvement - default module can be taken from preferences
552 return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" );
555 /*!On new window slot.*/
556 void LightApp_Application::onNewWindow()
558 const QObject* obj = sender();
559 if ( !obj || !obj->inherits( "QAction" ) )
563 int id = actionId( (QAction*)obj );
567 type = GLViewer_Viewer::Type();
570 type = Plot2d_Viewer::Type();
573 type = OCCViewer_Viewer::Type();
576 type = VTKViewer_Viewer::Type();
580 if ( !type.isEmpty() )
581 createViewManager( type );
584 //=======================================================================
586 /*! Purpose : SLOT. Create new document*/
587 //=======================================================================
588 void LightApp_Application::onNewDoc()
590 SUIT_Study* study = activeStudy();
592 saveWindowsGeometry();
594 CAM_Application::onNewDoc();
596 if ( !study ) // new study will be create in THIS application
599 updateViewManagers();
603 //=======================================================================
605 /*! Purpose : SLOT. Open new document*/
606 //=======================================================================
607 void LightApp_Application::onOpenDoc()
609 SUIT_Study* study = activeStudy();
610 saveWindowsGeometry();
612 CAM_Application::onOpenDoc();
614 if ( !study ) // new study will be create in THIS application
617 updateViewManagers();
621 #include "SUIT_MessageBox.h"
622 /*! Purpose : SLOT. Open new document with \a aName.*/
623 bool LightApp_Application::onOpenDoc( const QString& aName )
625 bool isAlreadyOpen = false;
627 // Look among opened studies
628 if (activeStudy()) { // at least one study is opened
629 SUIT_Session* aSession = SUIT_Session::session();
630 QPtrList<SUIT_Application> aAppList = aSession->applications();
631 QPtrListIterator<SUIT_Application> it (aAppList);
632 SUIT_Application* aApp = 0;
633 // iterate on all applications
634 for (; (aApp = it.current()) && !isAlreadyOpen; ++it) {
635 if (aApp->activeStudy()->studyName() == aName) {
636 isAlreadyOpen = true; // Already opened, ask user what to do
638 // The document ... is already open.
639 // Do you want to reload it?
640 int aAnswer = SUIT_MessageBox::warn2(desktop(), tr("WRN_WARNING"),
641 tr("QUE_DOC_ALREADYOPEN").arg(aName),
642 tr("BUT_YES"), tr("BUT_NO"), 1, 2, 2);
643 if (aAnswer == 1) { // reload
644 if (activeStudy()->studyName() == aName && aAppList.count() > 1) {
645 // Opened in THIS (active) application.
646 STD_Application* app1 = (STD_Application*)aAppList.at(0);
647 STD_Application* app2 = (STD_Application*)aAppList.at(1);
648 if (!app1 || !app2) {
652 if (app1->activeStudy()->studyName() == aName) {
653 // app1 is this application, we need another one
656 // Close document of this application. This application will be destroyed.
657 onCloseDoc(/*ask = */false);
658 // Open the file with another application, as this one will be destroyed.
659 return app1->onOpenDoc(aName);
661 // Opened in another application.
662 STD_Application* app = (STD_Application*)aApp;
664 app->onCloseDoc(/*ask = */false);
666 } else { // do not reload
667 // OK, the study will not be reloaded, but we call
668 // CAM_Application::onOpenDoc( aName ) all the same.
669 // It will activate a desktop of the study <aName>.
675 bool res = CAM_Application::onOpenDoc( aName );
677 QAction* a = action( MRUId );
678 if ( a && a->inherits( "QtxMRUAction" ) )
680 QtxMRUAction* mru = (QtxMRUAction*)a;
682 mru->insert( aName );
684 mru->remove( aName );
689 //=======================================================================
690 // name : onHelpAbout
691 /*! Purpose : SLOT. Display "About" message box*/
692 //=======================================================================
693 void LightApp_Application::onHelpAbout()
695 LightApp_AboutDlg* dlg = new LightApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
700 /*!SLOT. Load document with \a aName.*/
701 bool LightApp_Application::onLoadDoc( const QString& aName )
703 bool res = CAM_Application::onLoadDoc( aName );
705 /*jfa tmp:QAction* a = action( MRUId );
706 if ( a && a->inherits( "QtxMRUAction" ) )
708 QtxMRUAction* mru = (QtxMRUAction*)a;
710 mru->insert( aName );
712 mru->remove( aName );
717 /*!Private SLOT. Selection.*/
718 void LightApp_Application::onSelection()
720 onSelectionChanged();
722 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
723 ((LightApp_Module*)activeModule())->selectionChanged();
727 *\param study - SUIT_Study.
729 void LightApp_Application::setActiveStudy( SUIT_Study* study )
731 CAM_Application::setActiveStudy( study );
736 //=======================================================================
737 // name : updateCommandsStatus
738 /*! Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu*/
739 //=======================================================================
740 void LightApp_Application::updateCommandsStatus()
742 CAM_Application::updateCommandsStatus();
744 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
746 QAction* a = action( id );
748 a->setEnabled( activeStudy() );
752 // Helps to execute command
753 class RunBrowser: public QThread {
756 RunBrowser(QString theApp, QString theParams, QString theHelpFile, QString theContext=NULL):
757 myApp(theApp), myParams(theParams), myHelpFile("file:" + theHelpFile + theContext), myStatus(0) {};
763 if ( !myApp.isEmpty())
765 aCommand.sprintf("%s %s %s",myApp.latin1(),myParams.latin1(),myHelpFile.latin1());
766 myStatus = system(aCommand);
769 QCustomEvent* ce2000 = new QCustomEvent (2000);
770 postEvent (qApp, ce2000);
774 if( myStatus != 0 || myApp.isEmpty())
777 aCommand.sprintf("%s %s %s", QString(DEFAULT_BROWSER).latin1(),myParams.latin1(), myHelpFile.latin1());
778 myStatus = system(aCommand);
781 QCustomEvent* ce2001 = new QCustomEvent (2001);
782 postEvent (qApp, ce2001);
795 //=======================================================================
796 // name : onHelpContentsModule
797 /*! Purpose : SLOT. Display help contents for choosen module*/
798 //=======================================================================
799 void LightApp_Application::onHelpContentsModule()
801 const QAction* obj = (QAction*) sender();
803 QString aComponentName = obj->name();
804 QString aFileName = aComponentName + "_index_v3.1.0.html";
806 QCString dir = getenv( aComponentName + "_ROOT_DIR");
807 QString homeDir = Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("doc") + Qtx::addSlash("salome") );
809 QString helpFile = QFileInfo( homeDir + aFileName ).absFilePath();
810 SUIT_ResourceMgr* resMgr = resourceMgr();
811 QString anApp = resMgr->stringValue("ExternalBrowser", "application");
812 QString aParams = resMgr->stringValue("ExternalBrowser", "parameters");
814 RunBrowser* rs = new RunBrowser(anApp, aParams, helpFile);
818 /*!Sets enable or disable some actions on selection changed.*/
819 void LightApp_Application::onSelectionChanged()
824 *\param flag - key for window
825 *\param studyId - study id
826 * Flag used how identificator of window in windows list.
828 QWidget* LightApp_Application::window( const int flag, const int studyId ) const
835 if ( !activeStudy() )
838 sId = activeStudy()->id();
841 if ( myWindows.contains( flag ) )
842 wid = myWindows[flag]->widget( sId );
847 /*!Adds window to application.
848 *\param wid - QWidget
849 *\param flag - key wor window
850 *\param studyId - study id
851 * Flag used how identificator of window in windows list.
853 void LightApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
861 if ( !activeStudy() )
864 sId = activeStudy()->id();
867 if ( !myWindows.contains( flag ) )
869 QMap<int, int> winMap;
870 currentWindows( winMap );
872 LightApp_WidgetContainer* newWC = new LightApp_WidgetContainer( flag, desktop() );
873 connect( newWC, SIGNAL( destroyed ( QObject* ) ), this, SLOT( onWCDestroyed( QObject* ) ) );
874 myWindows.insert( flag, newWC );
875 if ( winMap.contains( flag ) )
876 desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
878 myWindows[flag]->setResizeEnabled( true );
879 myWindows[flag]->setCloseMode( QDockWindow::Always );
880 myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
884 if( wid->inherits( "PythonConsole" ) )
885 f = ( ( PythonConsole* )wid )->font();
889 myWindows[flag]->insert( sId, wid );
892 setWindowShown( flag, !myWindows[flag]->isEmpty() );
895 /*!Remove window from application.
896 *\param flag - key wor window
897 *\param studyId - study id
898 * Flag used how identificator of window in windows list.
900 void LightApp_Application::removeWindow( const int flag, const int studyId )
902 if ( !myWindows.contains( flag ) )
908 if ( !activeStudy() )
911 sId = activeStudy()->id();
914 QWidget* wid = myWindows[flag]->widget( sId );
915 myWindows[flag]->remove( sId );
918 setWindowShown( flag, !myWindows[flag]->isEmpty() );
922 *\param flag - key wor window
923 *\param studyId - study id
924 * Flag used how identificator of window in windows list.
926 QWidget* LightApp_Application::getWindow( const int flag, const int studyId )
928 QWidget* wid = window( flag, studyId );
930 addWindow( wid = createWindow( flag ), flag, studyId );
935 /*!Check is window visible?(with identificator \a type)*/
936 bool LightApp_Application::isWindowVisible( const int type ) const
939 if ( myWindows.contains( type ) )
941 SUIT_Desktop* desk = ((LightApp_Application*)this)->desktop();
942 res = desk && desk->appropriate( myWindows[type] );
947 /*!Sets window show or hide.
948 *\param type - window identificator.
949 *\param on - true/false (window show/hide)
951 void LightApp_Application::setWindowShown( const int type, const bool on )
953 if ( !desktop() || !myWindows.contains( type ) )
956 QDockWindow* dw = myWindows[type];
957 desktop()->setAppropriate( dw, on );
958 on ? dw->show() : dw->hide();
961 /*!Gets "ObjectBrowser".*/
962 OB_Browser* LightApp_Application::objectBrowser()
965 QWidget* wid = getWindow( WT_ObjectBrowser );
966 if ( wid->inherits( "OB_Browser" ) )
967 ob = (OB_Browser*)wid;
971 /*!Gets "LogWindow".*/
972 LogWindow* LightApp_Application::logWindow()
975 QWidget* wid = getWindow( WT_LogWindow );
976 if ( wid->inherits( "LogWindow" ) )
977 lw = (LogWindow*)wid;
981 /*!Get "PythonConsole"*/
982 PythonConsole* LightApp_Application::pythonConsole()
984 PythonConsole* console = 0;
985 QWidget* wid = getWindow( WT_PyConsole );
986 if ( wid->inherits( "PythonConsole" ) )
987 console = (PythonConsole*)wid;
991 /*!Update obect browser*/
992 void LightApp_Application::updateObjectBrowser( const bool updateModels )
994 // update existing data models
997 LightApp_Study* study = dynamic_cast<LightApp_Study*>(activeStudy());
999 CAM_Study::ModelList dm_list;
1000 study->dataModels( dm_list );
1001 for ( CAM_Study::ModelListIterator it( dm_list ); it.current(); ++it ) {
1002 CAM_DataModel* camDM = it.current();
1003 if ( camDM && camDM->inherits( "LightApp_DataModel" ) )
1004 ((LightApp_DataModel*)camDM)->update();
1008 if ( objectBrowser() )
1010 objectBrowser()->updateGeometry();
1011 objectBrowser()->updateTree();
1015 /*!Gets preferences.*/
1016 LightApp_Preferences* LightApp_Application::preferences() const
1018 return preferences( false );
1021 /*!Gets view manager*/
1022 SUIT_ViewManager* LightApp_Application::getViewManager( const QString& vmType, const bool create )
1024 SUIT_ViewManager* aVM = viewManager( vmType );
1025 SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
1027 if ( anActiveVM && anActiveVM->getType() == vmType )
1030 if ( aVM && create )
1032 if ( !aVM->getActiveView() )
1035 aVM->getActiveView()->setFocus();
1038 aVM = createViewManager( vmType );
1043 /*!Create view manager.*/
1044 SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType )
1046 SUIT_ResourceMgr* resMgr = resourceMgr();
1048 SUIT_ViewManager* viewMgr = 0;
1049 if( vmType == GLViewer_Viewer::Type() )
1051 viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
1052 new LightApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
1054 else if( vmType == Plot2d_Viewer::Type() )
1056 viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
1057 SPlot2d_Viewer* vm = new SPlot2d_Viewer();
1058 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1059 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( viewMgr->getActiveView() );
1062 Plot2d_ViewFrame* frame = wnd->getViewFrame();
1063 frame->setBackgroundColor( resMgr->colorValue( "Plot2d", "Background", frame->backgroundColor() ) );
1066 else if( vmType == SUPERVGraph_Viewer::Type() )
1068 viewMgr = new SUPERVGraph_ViewManager( activeStudy(), desktop() );
1069 SUPERVGraph_Viewer* vm = new SUPERVGraph_Viewer();
1070 SUPERVGraph_ViewFrame* view = dynamic_cast<SUPERVGraph_ViewFrame*>( vm->getViewManager()->getActiveView() );
1072 view->setBackgroundColor( resMgr->colorValue( "SUPERVGraph", "Background", view->backgroundColor() ) );
1074 else if( vmType == OCCViewer_Viewer::Type() )
1076 viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
1077 SOCC_Viewer* vm = new SOCC_Viewer();
1078 vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
1079 vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
1082 u = resMgr->integerValue( "OCCViewer", "iso_number_u", u );
1083 v = resMgr->integerValue( "OCCViewer", "iso_number_v", v );
1084 vm->setIsos( u, v );
1085 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1086 new LightApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
1088 else if ( vmType == SVTK_Viewer::Type() )
1090 viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
1091 SVTK_Viewer* vm = dynamic_cast<SVTK_Viewer*>( viewMgr->getViewModel() );
1094 vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
1095 vm->setTrihedronSize( resMgr->integerValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ) );
1096 new LightApp_VTKSelector( vm, mySelMgr );
1103 addViewManager( viewMgr );
1104 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
1106 if ( viewWin && desktop() )
1107 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
1109 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1110 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
1115 //=======================================================================
1116 // name : onCloseView
1117 /*! Purpose : SLOT. Remove view manager from application*/
1118 //=======================================================================
1119 void LightApp_Application::onCloseView( SUIT_ViewManager* theVM )
1121 removeViewManager( theVM );
1124 /*!Protected SLOT. On study created.*/
1125 void LightApp_Application::onStudyCreated( SUIT_Study* theStudy )
1127 SUIT_DataObject* aRoot = 0;
1128 if ( theStudy && theStudy->root() )
1130 aRoot = theStudy->root();
1131 //aRoot->setName( tr( "DATA_MODELS" ) );
1133 if ( objectBrowser() != 0 )
1134 objectBrowser()->setRootObject( aRoot );
1136 activateModule( defaultModule() );
1141 /*!Protected SLOT. On study opened.*/
1142 void LightApp_Application::onStudyOpened( SUIT_Study* theStudy )
1144 SUIT_DataObject* aRoot = 0;
1145 if ( theStudy && theStudy->root() )
1147 aRoot = theStudy->root();
1150 if ( objectBrowser() != 0 ) {
1151 objectBrowser()->setRootObject( aRoot );
1154 activateModule( defaultModule() );
1161 /*!Protected SLOT. On study saved.*/
1162 void LightApp_Application::onStudySaved( SUIT_Study* )
1167 /*!Protected SLOT. On study closed.*/
1168 void LightApp_Application::onStudyClosed( SUIT_Study* )
1172 // Bug 10396: clear selection
1173 mySelMgr->clearSelected();
1175 activateModule( "" );
1177 saveWindowsGeometry();
1180 /*!Protected SLOT.On desktop activated.*/
1181 void LightApp_Application::onDesktopActivated()
1183 CAM_Application::onDesktopActivated();
1184 LightApp_Module* aModule = dynamic_cast<LightApp_Module*>(activeModule());
1186 aModule->studyActivated();
1189 /*!Gets file filter.
1190 *\retval QString "(*.bin)"
1192 QString LightApp_Application::getFileFilter() const
1197 /*! Gets file name*/
1198 QString LightApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1199 const QString& caption, QWidget* parent )
1203 QStringList fls = QStringList::split( ";;", filters, false );
1204 return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1207 /*! Gets directory*/
1208 QString LightApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1212 return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1215 /*! Get open file names*/
1216 QStringList LightApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
1217 const QString& caption, QWidget* parent )
1221 QStringList fls = QStringList::split( ";;", filters, false );
1222 return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1225 /*!Private SLOT. Update object browser.*/
1226 void LightApp_Application::onRefresh()
1228 updateObjectBrowser( true );
1231 /*!Private SLOT. On preferences.*/
1232 void LightApp_Application::onPreferences()
1234 QApplication::setOverrideCursor( Qt::waitCursor );
1236 LightApp_PreferencesDlg* prefDlg = new LightApp_PreferencesDlg( preferences( true ), desktop());
1238 QApplication::restoreOverrideCursor();
1248 /*!Protected SLOT. On preferences changed.*/
1249 void LightApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1251 LightApp_Module* sMod = 0;
1252 CAM_Module* mod = module( modName );
1253 if ( mod && mod->inherits( "LightApp_Module" ) )
1254 sMod = (LightApp_Module*)mod;
1257 sMod->preferencesChanged( section, param );
1259 preferencesChanged( section, param );
1262 /*!Private SLOT. On open document with name \a aName.*/
1263 void LightApp_Application::onMRUActivated( QString aName )
1268 /*!Remove all windows from study.*/
1269 void LightApp_Application::beforeCloseDoc( SUIT_Study* s )
1271 CAM_Application::beforeCloseDoc( s );
1273 for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1274 removeWindow( itr.key(), s->id() );
1277 /*!Update actions.*/
1278 void LightApp_Application::updateActions()
1280 updateCommandsStatus();
1283 //=======================================================================
1284 // name : createNewStudy
1285 /*! Purpose : Create new study*/
1286 //=======================================================================
1287 SUIT_Study* LightApp_Application::createNewStudy()
1289 LightApp_Study* aStudy = new LightApp_Study( this );
1291 // Set up processing of major study-related events
1292 connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
1293 connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
1294 connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );
1295 connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
1301 QWidget* LightApp_Application::createWindow( const int flag )
1304 if ( flag == WT_ObjectBrowser )
1306 OB_Browser* ob = new OB_Browser( desktop() );
1307 ob->setAutoUpdate( true );
1308 ob->setAutoOpenLevel( 1 );
1309 ob->setCaption( tr( "OBJECT_BROWSER" ) );
1310 ob->listView()->setColumnWidth( 0, OBJECT_COLUMN_WIDTH );
1311 ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
1312 ob->setFilter( new LightApp_OBFilter( selectionMgr() ) );
1314 ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1316 // Create OBSelector
1317 new LightApp_OBSelector( ob, mySelMgr );
1321 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1323 else if ( flag == WT_PyConsole )
1325 PythonConsole* pyCons = new PythonConsole( desktop() );
1326 pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1328 // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1330 else if ( flag == WT_LogWindow )
1332 LogWindow* logWin = new LogWindow( desktop() );
1333 logWin->setCaption( tr( "LOG_WINDOW" ) );
1335 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1340 /*!Default windows(Object Browser, Python Console).
1341 * Adds to map \a aMap.
1343 void LightApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1345 aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1346 aMap.insert( WT_PyConsole, Qt::DockBottom );
1347 // aMap.insert( WT_LogWindow, Qt::DockBottom );
1350 /*!Default view manager.*/
1351 void LightApp_Application::defaultViewManagers( QStringList& ) const
1356 /*!Gets preferences.
1357 * Create preferences, if \a crt = true.
1359 LightApp_Preferences* LightApp_Application::preferences( const bool crt ) const
1364 LightApp_Application* that = (LightApp_Application*)this;
1366 if ( !_prefs_ && crt )
1368 _prefs_ = new LightApp_Preferences( resourceMgr() );
1369 that->createPreferences( _prefs_ );
1372 that->myPrefs = _prefs_;
1374 QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1375 for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1377 if ( !appIt.current()->inherits( "LightApp_Application" ) )
1380 LightApp_Application* app = (LightApp_Application*)appIt.current();
1382 QStringList modNameList;
1383 app->modules( modNameList, false );
1384 for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1386 int id = _prefs_->addPreference( *it );
1387 _prefs_->setItemProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1391 app->modules( modList );
1392 for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1394 LightApp_Module* mod = 0;
1395 if ( itr.current()->inherits( "LightApp_Module" ) )
1396 mod = (LightApp_Module*)itr.current();
1398 if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1400 int modCat = _prefs_->addPreference( mod->moduleName() );
1401 _prefs_->setItemProperty( modCat, "info", QString::null );
1402 mod->createPreferences();
1407 connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1408 this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1413 /*!Add new module to application.*/
1414 void LightApp_Application::moduleAdded( CAM_Module* mod )
1416 CAM_Application::moduleAdded( mod );
1418 LightApp_Module* lightMod = 0;
1419 if ( mod && mod->inherits( "LightApp_Module" ) )
1420 lightMod = (LightApp_Module*)mod;
1422 if ( myPrefs && lightMod && !myPrefs->hasModule( lightMod->moduleName() ))
1424 int modCat = myPrefs->addPreference( mod->moduleName() );
1425 myPrefs->setItemProperty( modCat, "info", QString::null );
1426 lightMod->createPreferences();
1430 /*!Create preferences.*/
1431 void LightApp_Application::createPreferences( LightApp_Preferences* pref )
1436 int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1438 int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1439 int studyGroup = pref->addPreference( tr( "PREF_GROUP_STUDY" ), genTab );
1440 pref->setItemProperty( studyGroup, "columns", 1 );
1442 pref->addPreference( tr( "PREF_MULTI_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "multi_file" );
1443 pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "ascii_file" );
1444 int undoPref = pref->addPreference( tr( "PREF_UNDO_LEVEL" ), studyGroup, LightApp_Preferences::IntSpin, "Study", "undo_level" );
1445 pref->setItemProperty( undoPref, "min", 1 );
1446 pref->setItemProperty( undoPref, "max", 100 );
1448 int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab );
1449 pref->setItemProperty( extgroup, "columns", 1 );
1450 int apppref = pref->addPreference( tr( "PREF_APP" ), extgroup, LightApp_Preferences::File, "ExternalBrowser", "application" );
1451 pref->setItemProperty( apppref, "existing", true );
1452 pref->setItemProperty( apppref, "flags", QFileInfo::ExeUser );
1454 pref->addPreference( tr( "PREF_PARAM" ), extgroup, LightApp_Preferences::String, "ExternalBrowser", "parameters" );
1456 int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab );
1457 pref->setItemProperty( pythonConsoleGroup, "columns", 1 );
1458 pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, LightApp_Preferences::Font, "PyConsole", "font" );
1460 int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1462 int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1464 int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1466 int plot2dGroup = pref->addPreference( tr( "PREF_GROUP_PLOT2DVIEWER" ), viewTab );
1468 int supervGroup = pref->addPreference( tr( "PREF_GROUP_SUPERV" ), viewTab );
1470 pref->setItemProperty( occGroup, "columns", 1 );
1471 pref->setItemProperty( vtkGroup, "columns", 1 );
1472 pref->setItemProperty( plot2dGroup, "columns", 1 );
1474 int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1475 LightApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1476 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1477 LightApp_Preferences::Color, "OCCViewer", "background" );
1479 pref->setItemProperty( occTS, "min", 1 );
1480 pref->setItemProperty( occTS, "max", 150 );
1482 int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
1483 LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
1484 int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
1485 LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
1487 pref->setItemProperty( isoU, "min", 0 );
1488 pref->setItemProperty( isoU, "max", 100000 );
1490 pref->setItemProperty( isoV, "min", 0 );
1491 pref->setItemProperty( isoV, "max", 100000 );
1493 int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1494 LightApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1495 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1496 LightApp_Preferences::Color, "VTKViewer", "background" );
1498 pref->setItemProperty( vtkTS, "min", 1 );
1499 pref->setItemProperty( vtkTS, "max", 150 );
1501 pref->addPreference( tr( "PREF_SHOW_LEGEND" ), plot2dGroup,
1502 LightApp_Preferences::Bool, "Plot2d", "ShowLegend" );
1504 int legendPosition = pref->addPreference( tr( "PREF_LEGEND_POSITION" ), plot2dGroup,
1505 LightApp_Preferences::Selector, "Plot2d", "LegendPos" );
1506 QStringList aLegendPosList;
1507 aLegendPosList.append( tr("PREF_LEFT") );
1508 aLegendPosList.append( tr("PREF_RIGHT") );
1509 aLegendPosList.append( tr("PREF_TOP") );
1510 aLegendPosList.append( tr("PREF_BOTTOM") );
1512 QValueList<QVariant> anIndexesList;
1513 anIndexesList.append(0);
1514 anIndexesList.append(1);
1515 anIndexesList.append(2);
1516 anIndexesList.append(3);
1518 pref->setItemProperty( legendPosition, "strings", aLegendPosList );
1519 pref->setItemProperty( legendPosition, "indexes", anIndexesList );
1521 int curveType = pref->addPreference( tr( "PREF_CURVE_TYPE" ), plot2dGroup,
1522 LightApp_Preferences::Selector, "Plot2d", "CurveType" );
1523 QStringList aCurveTypesList;
1524 aCurveTypesList.append( tr("PREF_POINTS") );
1525 aCurveTypesList.append( tr("PREF_LINES") );
1526 aCurveTypesList.append( tr("PREF_SPLINE") );
1528 anIndexesList.clear();
1529 anIndexesList.append(0);
1530 anIndexesList.append(1);
1531 anIndexesList.append(2);
1533 pref->setItemProperty( curveType, "strings", aCurveTypesList );
1534 pref->setItemProperty( curveType, "indexes", anIndexesList );
1536 int markerSize = pref->addPreference( tr( "PREF_MARKER_SIZE" ), plot2dGroup,
1537 LightApp_Preferences::IntSpin, "Plot2d", "MarkerSize" );
1539 pref->setItemProperty( markerSize, "min", 0 );
1540 pref->setItemProperty( markerSize, "max", 100 );
1542 QStringList aScaleModesList;
1543 aScaleModesList.append( tr("PREF_LINEAR") );
1544 aScaleModesList.append( tr("PREF_LOGARITHMIC") );
1546 anIndexesList.clear();
1547 anIndexesList.append(0);
1548 anIndexesList.append(1);
1550 int horScale = pref->addPreference( tr( "PREF_HOR_AXIS_SCALE" ), plot2dGroup,
1551 LightApp_Preferences::Selector, "Plot2d", "HorScaleMode" );
1553 pref->setItemProperty( horScale, "strings", aScaleModesList );
1554 pref->setItemProperty( horScale, "indexes", anIndexesList );
1556 int verScale = pref->addPreference( tr( "PREF_VERT_AXIS_SCALE" ), plot2dGroup,
1557 LightApp_Preferences::Selector, "Plot2d", "VerScaleMode" );
1559 pref->setItemProperty( verScale, "strings", aScaleModesList );
1560 pref->setItemProperty( verScale, "indexes", anIndexesList );
1562 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), plot2dGroup,
1563 LightApp_Preferences::Color, "Plot2d", "Background" );
1565 int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat );
1566 int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab );
1567 pref->setItemProperty( dirGroup, "columns", 1 );
1568 pref->addPreference( tr( "" ), dirGroup,
1569 LightApp_Preferences::DirList, "FileDlg", "QuickDirList" );
1571 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), supervGroup,
1572 LightApp_Preferences::Color, "SUPERVGraph", "Background" );
1573 pref->addPreference( tr( "PREF_SUPERV_TITLE_COLOR" ), supervGroup,
1574 LightApp_Preferences::Color, "SUPERVGraph", "Title" );
1575 // pref->addPreference( tr( "PREF_SUPERV_CTRL_COLOR" ), supervGroup,
1576 // LightApp_Preferences::Color, "SUPERVGraph", "Ctrl" );
1579 /*!Changed preferences */
1580 void LightApp_Application::preferencesChanged( const QString& sec, const QString& param )
1582 SUIT_ResourceMgr* resMgr = resourceMgr();
1586 if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1588 int sz = resMgr->integerValue( sec, param, -1 );
1589 QPtrList<SUIT_ViewManager> lst;
1590 viewManagers( OCCViewer_Viewer::Type(), lst );
1591 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1593 SUIT_ViewModel* vm = it.current()->getViewModel();
1594 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1597 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1598 occVM->setTrihedronSize( sz );
1599 occVM->getAISContext()->UpdateCurrentViewer();
1603 if ( sec == QString( "VTKViewer" ) && param == QString( "trihedron_size" ) )
1605 int sz = resMgr->integerValue( sec, param, -1 );
1606 QPtrList<SUIT_ViewManager> lst;
1607 viewManagers( SVTK_Viewer::Type(), lst );
1608 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1610 SUIT_ViewModel* vm = it.current()->getViewModel();
1611 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
1614 SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
1617 vtkVM->setTrihedronSize( sz );
1623 if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
1625 QPtrList<SUIT_ViewManager> lst;
1626 viewManagers( OCCViewer_Viewer::Type(), lst );
1627 int u = resMgr->integerValue( sec, "iso_number_u" );
1628 int v = resMgr->integerValue( sec, "iso_number_v" );
1629 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
1631 OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>( it.current() );
1632 if( mgr && mgr->getOCCViewer() )
1633 mgr->getOCCViewer()->setIsos( u, v );
1637 if( sec=="ObjectBrowser" )
1639 if( param=="auto_size" )
1641 OB_Browser* ob = objectBrowser();
1645 bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
1646 ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1648 updateObjectBrowser( false );
1652 if( sec=="PyConsole" )
1655 if( pythonConsole() )
1656 pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1660 /*!Update desktop title.*/
1661 void LightApp_Application::updateDesktopTitle() {
1662 QString aTitle = applicationName();
1663 QString aVer = applicationVersion();
1664 if ( !aVer.isEmpty() )
1665 aTitle += QString( " " ) + aVer;
1667 desktop()->setCaption( aTitle );
1670 /*!Update windows after close document.*/
1671 void LightApp_Application::afterCloseDoc()
1675 CAM_Application::afterCloseDoc();
1678 /*!Update module action.*/
1679 void LightApp_Application::updateModuleActions()
1682 if ( activeModule() )
1683 modName = activeModule()->moduleName();
1685 if ( myActions.contains( modName ) )
1686 myActions[modName]->setOn( true );
1689 /*!Gets current windows.
1690 *\param winMap - output current windows map.
1692 void LightApp_Application::currentWindows( QMap<int, int>& winMap ) const
1695 if ( !activeStudy() )
1698 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
1699 ((LightApp_Module*)activeModule())->windows( winMap );
1701 defaultWindows( winMap );
1704 /*!Gets current view managers.
1705 *\param lst - output current view managers list.
1707 void LightApp_Application::currentViewManagers( QStringList& lst ) const
1710 if ( !activeStudy() )
1713 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
1714 ((LightApp_Module*)activeModule())->viewManagers( lst );
1716 defaultViewManagers( lst );
1719 /*!Update windows.*/
1720 void LightApp_Application::updateWindows()
1722 QMap<int, int> winMap;
1723 currentWindows( winMap );
1725 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1726 getWindow( it.key() );
1728 loadWindowsGeometry();
1730 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1731 setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1734 /*!Update view managers.*/
1735 void LightApp_Application::updateViewManagers()
1738 currentViewManagers( lst );
1740 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1741 getViewManager( *it, true );
1744 /*!Load windows geometry.*/
1745 void LightApp_Application::loadWindowsGeometry()
1747 QtxDockAction* dockMgr = 0;
1749 QAction* a = action( ViewWindowsId );
1750 if ( a && a->inherits( "QtxDockAction" ) )
1751 dockMgr = (QtxDockAction*)a;
1757 if ( activeModule() )
1758 modName = activeModule()->name("");
1760 QString section = QString( "windows_geometry" );
1761 if ( !modName.isEmpty() )
1762 section += QString( "." ) + modName;
1764 dockMgr->loadGeometry( resourceMgr(), section, false );
1765 dockMgr->restoreGeometry();
1768 /*!Save windows geometry.*/
1769 void LightApp_Application::saveWindowsGeometry()
1771 QtxDockAction* dockMgr = 0;
1773 QAction* a = action( ViewWindowsId );
1774 if ( a && a->inherits( "QtxDockAction" ) )
1775 dockMgr = (QtxDockAction*)a;
1781 if ( activeModule() )
1782 modName = activeModule()->name("");
1784 QString section = QString( "windows_geometry" );
1785 if ( !modName.isEmpty() )
1786 section += QString( "." ) + modName;
1788 dockMgr->storeGeometry();
1789 dockMgr->saveGeometry( resourceMgr(), section, false );
1792 /*!Activate windows.*/
1793 void LightApp_Application::activateWindows()
1795 if ( activeStudy() )
1797 for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1798 itr.data()->activate( activeStudy()->id() );
1802 /*!Adds icon names for modules.*/
1803 void LightApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
1807 SUIT_ResourceMgr* resMgr = resourceMgr();
1811 QStringList modList;
1812 modules( modList, false );
1814 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
1816 QString modName = *it;
1817 QString modIntr = moduleName( modName );
1818 QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
1820 if ( modIcon.isEmpty() )
1823 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
1824 modIcon += QString( ".png" );
1826 iconMap.insert( modName, modIcon );
1830 /*!Insert items in popup, which necessary for current application*/
1831 void LightApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
1833 CAM_Application::contextMenuPopup( type, thePopup, title );
1835 OB_Browser* ob = objectBrowser();
1836 if ( !ob || type != ob->popupClientType() )
1839 thePopup->insertSeparator();
1840 thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
1843 /*!Create empty study.*/
1844 void LightApp_Application::createEmptyStudy()
1846 CAM_Application::createEmptyStudy();
1847 if ( objectBrowser() )
1848 objectBrowser()->updateTree();
1851 /*!Activate module \a mod.*/
1852 bool LightApp_Application::activateModule( CAM_Module* mod )
1854 bool res = CAM_Application::activateModule( mod );
1855 if ( objectBrowser() )
1856 objectBrowser()->updateTree();
1860 /*!return keyborad accelerators manager object */
1861 SUIT_Accel* LightApp_Application::accel() const
1866 /*! remove dead widget container from map */
1867 void LightApp_Application::onWCDestroyed( QObject* ob )
1869 // remove destroyed widget container from windows map
1870 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1872 if ( itr.data() != ob )
1875 int key = itr.key();
1876 myWindows.remove( key );
1881 /*! redefined to remove view manager from memory */
1882 void LightApp_Application::removeViewManager( SUIT_ViewManager* vm )
1884 disconnect( vm, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1885 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
1886 STD_Application::removeViewManager( vm );
1890 /*! rename active window of desktop */
1891 void LightApp_Application::onRenameWindow()
1896 QWidget* w = desktop()->activeWindow();
1901 QString name = QInputDialog::getText( tr( "TOT_RENAME" ), tr( "PRP_RENAME" ), QLineEdit::Normal, w->caption(), &ok, w );
1902 if( ok && !name.isEmpty() )
1903 w->setCaption( name );