1 // File: LightApp_Application.cxx
2 // Created: 6/20/2005 18:39:45 PM
3 // Author: Natalia Donis
4 // Copyright (C) CEA 2005
6 #include "PythonConsole_PyInterp.h" // WARNING! This include must be the first!
8 #include "LightApp_Application.h"
9 #include "LightApp_WidgetContainer.h"
10 #include "LightApp_Module.h"
11 #include "LightApp_DataModel.h"
12 #include "LightApp_Study.h"
13 #include "LightApp_Preferences.h"
14 #include "LightApp_PreferencesDlg.h"
15 #include "LightApp_ModuleDlg.h"
16 #include "LightApp_AboutDlg.h"
18 #include "LightApp_OBFilter.h"
20 #include "LightApp_GLSelector.h"
21 #include "LightApp_OBSelector.h"
22 #include "LightApp_OCCSelector.h"
23 #include "LightApp_VTKSelector.h"
24 #include "LightApp_SelectionMgr.h"
26 #include <CAM_Module.h>
27 #include <CAM_DataModel.h>
28 #include <CAM_Study.h>
29 #include <STD_TabDesktop.h>
31 #include <SUIT_Session.h>
32 #include <SUIT_Study.h>
33 #include <SUIT_FileDlg.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_Tools.h>
36 #include <SUIT_Accel.h>
38 #include <QtxMRUAction.h>
39 #include <QtxDockAction.h>
40 #include <QtxToolBar.h>
42 #include <LogWindow.h>
43 #include <OB_Browser.h>
44 #include <PythonConsole_PyConsole.h>
46 #include <GLViewer_Viewer.h>
47 #include <GLViewer_ViewManager.h>
49 #include <Plot2d_ViewManager.h>
50 #include <Plot2d_ViewModel.h>
51 #include <SPlot2d_ViewModel.h>
53 #include <OCCViewer_ViewManager.h>
54 #include <SOCC_ViewModel.h>
56 #include <SVTK_ViewModel.h>
57 #include <SVTK_ViewManager.h>
58 #include <VTKViewer_ViewModel.h>
60 #include <SUPERVGraph_ViewModel.h>
61 #include <SUPERVGraph_ViewFrame.h>
62 #include <SUPERVGraph_ViewManager.h>
64 #include <QtxWorkstack.h>
70 #include <qstringlist.h>
72 #include <qapplication.h>
74 #include <qstatusbar.h>
76 #include <qinputdialog.h>
78 #define OBJECT_BROWSER_WIDTH 300
79 #define OBJECT_COLUMN_WIDTH 150
81 #define DEFAULT_BROWSER "mozilla"
83 #define FIRST_HELP_ID 1000000
85 #include "SALOME_InteractiveObject.hxx"
86 #include "SALOME_ListIO.hxx"
88 static const char* imageEmptyIcon[] = {
91 "....................",
92 "....................",
93 "....................",
94 "....................",
95 "....................",
96 "....................",
97 "....................",
98 "....................",
99 "....................",
100 "....................",
101 "....................",
102 "....................",
103 "....................",
104 "....................",
105 "....................",
106 "....................",
107 "....................",
108 "....................",
109 "....................",
110 "...................."};
112 /*!Create new instance of LightApp_Application.*/
113 extern "C" LIGHTAPP_EXPORT SUIT_Application* createApplication()
115 return new LightApp_Application();
118 LightApp_Preferences* LightApp_Application::_prefs_ = 0;
121 Class : LightApp_Application
122 Description : Application containing LightApp module
126 LightApp_Application::LightApp_Application()
127 : CAM_Application( false ),
130 STD_TabDesktop* desk = new STD_TabDesktop();
134 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
135 QPixmap aLogo = aResMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false );
137 desktop()->setIcon( aLogo );
138 desktop()->setDockableMenuBar( true );
139 desktop()->setDockableStatusBar( false );
141 // base logo (salome itself)
142 desktop()->addLogo( "_app_base", aResMgr->loadPixmap( "LightApp", tr( "APP_BASE_LOGO" ), false ) );
143 // extra logo (salome-based application)
144 desktop()->addLogo( "_app_extra", aResMgr->loadPixmap( "LightApp", tr( "APP_EXTRA_LOGO" ), false ) );
148 mySelMgr = new LightApp_SelectionMgr( this );
150 myAccel = new SUIT_Accel( desktop() );
151 myAccel->setActionKey( SUIT_Accel::PanLeft, CTRL+Key_Left, OCCViewer_Viewer::Type() );
152 myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, OCCViewer_Viewer::Type() );
153 myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, OCCViewer_Viewer::Type() );
154 myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, OCCViewer_Viewer::Type() );
155 myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, OCCViewer_Viewer::Type() );
156 myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, OCCViewer_Viewer::Type() );
157 myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, OCCViewer_Viewer::Type() );
158 myAccel->setActionKey( SUIT_Accel::RotateLeft, ALT+Key_Left, OCCViewer_Viewer::Type() );
159 myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right, OCCViewer_Viewer::Type() );
160 myAccel->setActionKey( SUIT_Accel::RotateUp, ALT+Key_Up, OCCViewer_Viewer::Type() );
161 myAccel->setActionKey( SUIT_Accel::RotateDown, ALT+Key_Down, OCCViewer_Viewer::Type() );
162 myAccel->setActionKey( SUIT_Accel::PanLeft, CTRL+Key_Left, VTKViewer_Viewer::Type() );
163 myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, VTKViewer_Viewer::Type() );
164 myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, VTKViewer_Viewer::Type() );
165 myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, VTKViewer_Viewer::Type() );
166 myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, VTKViewer_Viewer::Type() );
167 myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, VTKViewer_Viewer::Type() );
168 myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, VTKViewer_Viewer::Type() );
169 myAccel->setActionKey( SUIT_Accel::RotateLeft, ALT+Key_Left, VTKViewer_Viewer::Type() );
170 myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right, VTKViewer_Viewer::Type() );
171 myAccel->setActionKey( SUIT_Accel::RotateUp, ALT+Key_Up, VTKViewer_Viewer::Type() );
172 myAccel->setActionKey( SUIT_Accel::RotateDown, ALT+Key_Down, VTKViewer_Viewer::Type() );
174 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) );
178 *\li Save window geometry.
179 *\li Save desktop geometry.
180 *\li Save resource maneger.
181 *\li Delete selection manager.
183 LightApp_Application::~LightApp_Application()
185 saveWindowsGeometry();
190 desktop()->saveGeometry( resourceMgr(), "desktop" );
191 resourceMgr()->save();
196 /*!Start application.*/
197 void LightApp_Application::start()
200 desktop()->loadGeometry( resourceMgr(), "desktop" );
202 CAM_Application::start();
204 QAction* a = action( ViewWindowsId );
205 if ( a && a->inherits( "QtxDockAction" ) )
206 ((QtxDockAction*)a)->setAutoPlace( true );
209 updateViewManagers();
212 desktop()->statusBar()->message( "" );
215 /*!Gets application name.*/
216 QString LightApp_Application::applicationName() const
218 return tr( "APP_NAME" );
221 /*!Gets application version.*/
222 QString LightApp_Application::applicationVersion() const
224 static QString _app_version;
226 if ( _app_version.isEmpty() )
228 QString resVersion = tr( "APP_VERSION" );
229 if ( resVersion != "APP_VERSION" )
231 _app_version = resVersion;
235 QString path( ::getenv( "GUI_ROOT_DIR" ) );
236 if ( !path.isEmpty() )
237 path += QDir::separator();
238 path += QString( "bin/salome/VERSION" );
241 if ( vf.open( IO_ReadOnly ) )
244 vf.readLine( line, 1024 );
247 if ( !line.isEmpty() )
249 while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
250 line.remove( line.length() - 1, 1 );
252 int idx = line.findRev( ":" );
254 _app_version = line.mid( idx + 1 ).stripWhiteSpace();
262 /*!Load module by \a name.*/
263 CAM_Module* LightApp_Application::loadModule( const QString& name )
265 CAM_Module* mod = CAM_Application::loadModule( name );
268 connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) );
269 connect( this, SIGNAL( studySaved() ), mod, SLOT( onModelSaved() ) );
270 connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) );
275 /*!Activate module by \a modName*/
276 bool LightApp_Application::activateModule( const QString& modName )
279 CAM_Module* prevMod = activeModule();
282 actName = prevMod->moduleName();
284 if ( actName == modName )
287 putInfo( tr( "ACTIVATING_MODULE" ).arg( modName ) );
289 saveWindowsGeometry();
291 bool status = CAM_Application::activateModule( modName );
293 updateModuleActions();
301 updateViewManagers();
306 bool LightApp_Application::useStudy(const QString& theName)
309 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>(activeStudy());
312 res = aStudy->loadDocument( theName );
313 updateDesktopTitle();
314 updateCommandsStatus();
318 /*!Gets selection manager.*/
319 LightApp_SelectionMgr* LightApp_Application::selectionMgr() const
325 void LightApp_Application::createActions()
327 STD_Application::createActions();
329 SUIT_Desktop* desk = desktop();
330 SUIT_ResourceMgr* resMgr = resourceMgr();
333 createAction( PreferencesId, tr( "TOT_DESK_PREFERENCES" ), QIconSet(),
334 tr( "MEN_DESK_PREFERENCES" ), tr( "PRP_DESK_PREFERENCES" ),
335 CTRL+Key_P, desk, false, this, SLOT( onPreferences() ) );
338 int helpMenu = createMenu( tr( "MEN_DESK_HELP" ), -1, -1, 1000 );
339 int helpModuleMenu = createMenu( tr( "MEN_DESK_MODULE_HELP" ), helpMenu, -1, 0 );
340 createMenu( separator(), helpMenu, -1, 1 );
342 QStringList aModuleList;
343 modules( aModuleList, false );
345 int id = LightApp_Application::UserID + FIRST_HELP_ID;
346 // help for KERNEL and GUI
351 if (dir = getenv("GUI_ROOT_DIR")) {
352 aFileName = "GUI_index_v3.1.0.html";
353 root = Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("doc") + Qtx::addSlash("salome") );
354 if ( QFileInfo( root + aFileName ).exists() ) {
355 a = createAction( id, tr( QString("Kernel & GUI Help") ), QIconSet(),
356 tr( QString("Kernel && GUI Help") ),
357 tr( QString("Kernel & GUI Help") ),
358 0, desk, false, this, SLOT( onHelpContentsModule() ) );
359 a->setName( QString("GUI") );
360 createMenu( a, helpModuleMenu, -1 );
364 // help for other existing modules
365 QStringList::Iterator it;
366 for ( it = aModuleList.begin(); it != aModuleList.end(); ++it )
368 if ( (*it).isEmpty() )
371 QString modName = moduleName( *it );
372 aFileName = modName + "_index_v3.1.0.html";
374 if (dir = getenv( modName + "_ROOT_DIR")) {
375 root = Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("doc") + Qtx::addSlash("salome") );
376 if ( QFileInfo( root + aFileName ).exists() ) {
378 QAction* a = createAction( id, tr( moduleTitle(modName) + QString(" Help") ), QIconSet(),
379 tr( moduleTitle(modName) + QString(" Help") ),
380 tr( moduleTitle(modName) + QString(" Help") ),
381 0, desk, false, this, SLOT( onHelpContentsModule() ) );
382 a->setName( modName );
383 createMenu( a, helpModuleMenu, -1 );
390 QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), desk );
391 connect( mru, SIGNAL( activated( QString ) ), this, SLOT( onMRUActivated( QString ) ) );
392 registerAction( MRUId, mru );
394 // default icon for neutral point ('SALOME' module)
395 QPixmap defIcon = resMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false );
396 if ( defIcon.isNull() )
397 defIcon = QPixmap( imageEmptyIcon );
399 //! default icon for any module
400 QPixmap modIcon = resMgr->loadPixmap( "LightApp", tr( "APP_MODULE_ICO" ), false );
401 if ( modIcon.isNull() )
402 modIcon = QPixmap( imageEmptyIcon );
404 QToolBar* modTBar = new QtxToolBar( true, desk );
405 modTBar->setLabel( tr( "INF_TOOLBAR_MODULES" ) );
407 QActionGroup* modGroup = new QActionGroup( this );
408 modGroup->setExclusive( true );
409 modGroup->setUsesDropDown( true );
411 a = createAction( -1, tr( "APP_NAME" ), defIcon, tr( "APP_NAME" ),
412 tr( "PRP_APP_MODULE" ), 0, desk, true );
414 myActions.insert( QString(), a );
416 QMap<QString, QString> iconMap;
417 moduleIconNames( iconMap );
419 const int iconSize = 20;
421 modGroup->addTo( modTBar );
422 modTBar->addSeparator();
425 modules( modList, false );
427 for ( it = modList.begin(); it != modList.end(); ++it )
429 if ( (*it).isEmpty() )
433 if ( iconMap.contains( *it ) )
434 iconName = iconMap[*it];
436 QString modName = moduleName( *it );
438 QPixmap icon = resMgr->loadPixmap( modName, iconName, false );
442 icon.convertFromImage( icon.convertToImage().smoothScale( iconSize, iconSize, QImage::ScaleMin ) );
444 QAction* a = createAction( -1, *it, icon, *it, tr( "PRP_MODULE" ).arg( *it ), 0, desk, true );
448 myActions.insert( *it, a );
451 SUIT_Tools::simplifySeparators( modTBar );
454 int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 );
455 int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
456 createMenu( separator(), windowMenu, -1, 1 );
458 QMap<int, int> accelMap;
459 accelMap[NewGLViewId] = ALT+Key_G;
460 accelMap[NewPlot2dId] = ALT+Key_P;
461 accelMap[NewOCCViewId] = ALT+Key_O;
462 accelMap[NewVTKViewId] = ALT+Key_K;
464 for ( id = NewGLViewId; id <= NewVTKViewId; id++ )
466 QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), QIconSet(),
467 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
468 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
469 accelMap.contains( id ) ? accelMap[id] : 0, desk, false, this, SLOT( onNewWindow() ) );
470 createMenu( a, newWinMenu, -1 );
473 createAction( RenameId, tr( "TOT_RENAME" ), QIconSet(), tr( "MEN_RENAME" ), tr( "PRP_RENAME" ),
474 0, desk, false, this, SLOT( onRenameWindow() ) );
475 createMenu( RenameId, windowMenu, -1 );
477 connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) );
479 int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
480 createMenu( PreferencesId, fileMenu, 15, -1 );
481 createMenu( separator(), fileMenu, -1, 15, -1 );
484 createMenu( separator(), fileMenu, -1, 100, -1 );
485 createMenu( MRUId, fileMenu, 100, -1 );
486 createMenu( separator(), fileMenu, -1, 100, -1 );
490 /*!On module activation action.*/
491 void LightApp_Application::onModuleActivation( QAction* a )
496 QString modName = a->menuText();
497 if ( modName == tr( "APP_NAME" ) )
498 modName = QString::null;
500 // Force user to create/open a study before module activation
501 QMap<QString, QString> iconMap;
502 moduleIconNames( iconMap );
503 QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ], false );
505 icon = resourceMgr()->loadPixmap( "LightApp", tr( "APP_MODULE_BIG_ICO" ), false ); // default icon for any module
507 bool cancelled = false;
508 while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
509 LightApp_ModuleDlg aDlg( desktop(), modName, icon );
510 int res = aDlg.exec();
524 putInfo( tr("INF_CANCELLED") );
525 myActions[QString()]->setOn( true );
531 activateModule( modName );
534 /*!Default module activation.*/
535 QString LightApp_Application::defaultModule() const
537 QStringList aModuleNames;
538 modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration
539 //! If there's the one and only module --> activate it automatically
540 //! TODO: Possible improvement - default module can be taken from preferences
541 return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" );
544 /*!On new window slot.*/
545 void LightApp_Application::onNewWindow()
547 const QObject* obj = sender();
548 if ( !obj || !obj->inherits( "QAction" ) )
552 int id = actionId( (QAction*)obj );
556 type = GLViewer_Viewer::Type();
559 type = Plot2d_Viewer::Type();
562 type = OCCViewer_Viewer::Type();
565 type = VTKViewer_Viewer::Type();
569 if ( !type.isEmpty() )
570 createViewManager( type );
573 //=======================================================================
575 /*! Purpose : SLOT. Create new document*/
576 //=======================================================================
577 void LightApp_Application::onNewDoc()
579 SUIT_Study* study = activeStudy();
581 saveWindowsGeometry();
583 CAM_Application::onNewDoc();
585 if ( !study ) // new study will be create in THIS application
588 updateViewManagers();
592 //=======================================================================
594 /*! Purpose : SLOT. Open new document*/
595 //=======================================================================
596 void LightApp_Application::onOpenDoc()
598 SUIT_Study* study = activeStudy();
599 saveWindowsGeometry();
601 CAM_Application::onOpenDoc();
603 if ( !study ) // new study will be create in THIS application
606 updateViewManagers();
610 #include "SUIT_MessageBox.h"
611 /*! Purpose : SLOT. Open new document with \a aName.*/
612 bool LightApp_Application::onOpenDoc( const QString& aName )
614 bool isAlreadyOpen = false;
616 // Look among opened studies
617 if (activeStudy()) { // at least one study is opened
618 SUIT_Session* aSession = SUIT_Session::session();
619 QPtrList<SUIT_Application> aAppList = aSession->applications();
620 QPtrListIterator<SUIT_Application> it (aAppList);
621 SUIT_Application* aApp = 0;
622 // iterate on all applications
623 for (; (aApp = it.current()) && !isAlreadyOpen; ++it) {
624 if (aApp->activeStudy()->studyName() == aName) {
625 isAlreadyOpen = true; // Already opened, ask user what to do
627 // The document ... is already open.
628 // Do you want to reload it?
629 int aAnswer = SUIT_MessageBox::warn2(desktop(), tr("WRN_WARNING"),
630 tr("QUE_DOC_ALREADYOPEN").arg(aName),
631 tr("BUT_YES"), tr("BUT_NO"), 1, 2, 2);
632 if (aAnswer == 1) { // reload
633 if (activeStudy()->studyName() == aName && aAppList.count() > 1) {
634 // Opened in THIS (active) application.
635 STD_Application* app1 = (STD_Application*)aAppList.at(0);
636 STD_Application* app2 = (STD_Application*)aAppList.at(1);
637 if (!app1 || !app2) {
641 if (app1->activeStudy()->studyName() == aName) {
642 // app1 is this application, we need another one
645 // Close document of this application. This application will be destroyed.
646 onCloseDoc(/*ask = */false);
647 // Open the file with another application, as this one will be destroyed.
648 return app1->onOpenDoc(aName);
650 // Opened in another application.
651 STD_Application* app = (STD_Application*)aApp;
653 app->onCloseDoc(/*ask = */false);
655 } else { // do not reload
656 // OK, the study will not be reloaded, but we call
657 // CAM_Application::onOpenDoc( aName ) all the same.
658 // It will activate a desktop of the study <aName>.
664 bool res = CAM_Application::onOpenDoc( aName );
666 QAction* a = action( MRUId );
667 if ( a && a->inherits( "QtxMRUAction" ) )
669 QtxMRUAction* mru = (QtxMRUAction*)a;
671 mru->insert( aName );
673 mru->remove( aName );
678 //=======================================================================
679 // name : onHelpAbout
680 /*! Purpose : SLOT. Display "About" message box*/
681 //=======================================================================
682 void LightApp_Application::onHelpAbout()
684 LightApp_AboutDlg* dlg = new LightApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
689 /*!SLOT. Load document with \a aName.*/
690 bool LightApp_Application::onLoadDoc( const QString& aName )
692 bool res = CAM_Application::onLoadDoc( aName );
694 /*jfa tmp:QAction* a = action( MRUId );
695 if ( a && a->inherits( "QtxMRUAction" ) )
697 QtxMRUAction* mru = (QtxMRUAction*)a;
699 mru->insert( aName );
701 mru->remove( aName );
706 /*!Private SLOT. Selection.*/
707 void LightApp_Application::onSelection()
709 onSelectionChanged();
711 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
712 ((LightApp_Module*)activeModule())->selectionChanged();
716 *\param study - SUIT_Study.
718 void LightApp_Application::setActiveStudy( SUIT_Study* study )
720 CAM_Application::setActiveStudy( study );
725 //=======================================================================
726 // name : updateCommandsStatus
727 /*! Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu*/
728 //=======================================================================
729 void LightApp_Application::updateCommandsStatus()
731 CAM_Application::updateCommandsStatus();
733 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
735 QAction* a = action( id );
737 a->setEnabled( activeStudy() );
741 // Helps to execute command
742 class RunBrowser: public QThread {
745 RunBrowser(QString theApp, QString theParams, QString theHelpFile, QString theContext=NULL):
746 myApp(theApp), myParams(theParams), myHelpFile("file:" + theHelpFile + theContext), myStatus(0) {};
752 if ( !myApp.isEmpty())
754 aCommand.sprintf("%s %s %s",myApp.latin1(),myParams.latin1(),myHelpFile.latin1());
755 myStatus = system(aCommand);
758 QCustomEvent* ce2000 = new QCustomEvent (2000);
759 postEvent (qApp, ce2000);
763 if( myStatus != 0 || myApp.isEmpty())
766 aCommand.sprintf("%s %s %s", QString(DEFAULT_BROWSER).latin1(),myParams.latin1(), myHelpFile.latin1());
767 myStatus = system(aCommand);
770 QCustomEvent* ce2001 = new QCustomEvent (2001);
771 postEvent (qApp, ce2001);
784 //=======================================================================
785 // name : onHelpContentsModule
786 /*! Purpose : SLOT. Display help contents for choosen module*/
787 //=======================================================================
788 void LightApp_Application::onHelpContentsModule()
790 const QAction* obj = (QAction*) sender();
792 QString aComponentName = obj->name();
793 QString aFileName = aComponentName + "_index_v3.1.0.html";
795 QCString dir = getenv( aComponentName + "_ROOT_DIR");
796 QString homeDir = Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("doc") + Qtx::addSlash("salome") );
798 QString helpFile = QFileInfo( homeDir + aFileName ).absFilePath();
799 SUIT_ResourceMgr* resMgr = resourceMgr();
800 QString anApp = resMgr->stringValue("ExternalBrowser", "application");
801 QString aParams = resMgr->stringValue("ExternalBrowser", "parameters");
803 RunBrowser* rs = new RunBrowser(anApp, aParams, helpFile);
807 /*!Sets enable or disable some actions on selection changed.*/
808 void LightApp_Application::onSelectionChanged()
813 *\param flag - key for window
814 *\param studyId - study id
815 * Flag used how identificator of window in windows list.
817 QWidget* LightApp_Application::window( const int flag, const int studyId ) const
824 if ( !activeStudy() )
827 sId = activeStudy()->id();
830 if ( myWindows.contains( flag ) )
831 wid = myWindows[flag]->widget( sId );
836 /*!Adds window to application.
837 *\param wid - QWidget
838 *\param flag - key wor window
839 *\param studyId - study id
840 * Flag used how identificator of window in windows list.
842 void LightApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
850 if ( !activeStudy() )
853 sId = activeStudy()->id();
856 if ( !myWindows.contains( flag ) )
858 QMap<int, int> winMap;
859 currentWindows( winMap );
861 LightApp_WidgetContainer* newWC = new LightApp_WidgetContainer( flag, desktop() );
862 connect( newWC, SIGNAL( destroyed ( QObject* ) ), this, SLOT( onWCDestroyed( QObject* ) ) );
863 myWindows.insert( flag, newWC );
864 if ( winMap.contains( flag ) )
865 desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
867 myWindows[flag]->setResizeEnabled( true );
868 myWindows[flag]->setCloseMode( QDockWindow::Always );
869 myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
873 if( wid->inherits( "PythonConsole" ) )
874 f = ( ( PythonConsole* )wid )->font();
878 myWindows[flag]->insert( sId, wid );
881 setWindowShown( flag, !myWindows[flag]->isEmpty() );
884 /*!Remove window from application.
885 *\param flag - key wor window
886 *\param studyId - study id
887 * Flag used how identificator of window in windows list.
889 void LightApp_Application::removeWindow( const int flag, const int studyId )
891 if ( !myWindows.contains( flag ) )
897 if ( !activeStudy() )
900 sId = activeStudy()->id();
903 QWidget* wid = myWindows[flag]->widget( sId );
904 myWindows[flag]->remove( sId );
907 setWindowShown( flag, !myWindows[flag]->isEmpty() );
911 *\param flag - key wor window
912 *\param studyId - study id
913 * Flag used how identificator of window in windows list.
915 QWidget* LightApp_Application::getWindow( const int flag, const int studyId )
917 QWidget* wid = window( flag, studyId );
919 addWindow( wid = createWindow( flag ), flag, studyId );
924 /*!Check is window visible?(with identificator \a type)*/
925 bool LightApp_Application::isWindowVisible( const int type ) const
928 if ( myWindows.contains( type ) )
930 SUIT_Desktop* desk = ((LightApp_Application*)this)->desktop();
931 res = desk && desk->appropriate( myWindows[type] );
936 /*!Sets window show or hide.
937 *\param type - window identificator.
938 *\param on - true/false (window show/hide)
940 void LightApp_Application::setWindowShown( const int type, const bool on )
942 if ( !desktop() || !myWindows.contains( type ) )
945 QDockWindow* dw = myWindows[type];
946 desktop()->setAppropriate( dw, on );
947 on ? dw->show() : dw->hide();
950 /*!Gets "ObjectBrowser".*/
951 OB_Browser* LightApp_Application::objectBrowser()
954 QWidget* wid = getWindow( WT_ObjectBrowser );
955 if ( wid->inherits( "OB_Browser" ) )
956 ob = (OB_Browser*)wid;
960 /*!Gets "LogWindow".*/
961 LogWindow* LightApp_Application::logWindow()
964 QWidget* wid = getWindow( WT_LogWindow );
965 if ( wid->inherits( "LogWindow" ) )
966 lw = (LogWindow*)wid;
970 /*!Get "PythonConsole"*/
971 PythonConsole* LightApp_Application::pythonConsole()
973 PythonConsole* console = 0;
974 QWidget* wid = getWindow( WT_PyConsole );
975 if ( wid->inherits( "PythonConsole" ) )
976 console = (PythonConsole*)wid;
980 /*!Update obect browser*/
981 void LightApp_Application::updateObjectBrowser( const bool updateModels )
983 // update existing data models
986 LightApp_Study* study = dynamic_cast<LightApp_Study*>(activeStudy());
988 CAM_Study::ModelList dm_list;
989 study->dataModels( dm_list );
990 for ( CAM_Study::ModelListIterator it( dm_list ); it.current(); ++it ) {
991 CAM_DataModel* camDM = it.current();
992 if ( camDM && camDM->inherits( "LightApp_DataModel" ) )
993 ((LightApp_DataModel*)camDM)->update();
997 if ( objectBrowser() )
999 objectBrowser()->updateGeometry();
1000 objectBrowser()->updateTree();
1004 /*!Gets preferences.*/
1005 LightApp_Preferences* LightApp_Application::preferences() const
1007 return preferences( false );
1010 /*!Gets view manager*/
1011 SUIT_ViewManager* LightApp_Application::getViewManager( const QString& vmType, const bool create )
1013 SUIT_ViewManager* aVM = viewManager( vmType );
1014 SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
1016 if ( anActiveVM && anActiveVM->getType() == vmType )
1019 if ( aVM && create )
1021 if ( !aVM->getActiveView() )
1024 aVM->getActiveView()->setFocus();
1027 aVM = createViewManager( vmType );
1032 /*!Create view manager.*/
1033 SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType )
1035 SUIT_ResourceMgr* resMgr = resourceMgr();
1037 SUIT_ViewManager* viewMgr = 0;
1038 if( vmType == GLViewer_Viewer::Type() )
1040 viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
1041 new LightApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
1043 else if( vmType == Plot2d_Viewer::Type() )
1045 viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
1046 SPlot2d_Viewer* vm = new SPlot2d_Viewer();
1047 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1048 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( viewMgr->getActiveView() );
1051 Plot2d_ViewFrame* frame = wnd->getViewFrame();
1052 frame->setBackgroundColor( resMgr->colorValue( "Plot2d", "Background", frame->backgroundColor() ) );
1055 else if( vmType == SUPERVGraph_Viewer::Type() )
1057 viewMgr = new SUPERVGraph_ViewManager( activeStudy(), desktop() );
1058 SUPERVGraph_Viewer* vm = new SUPERVGraph_Viewer();
1059 SUPERVGraph_ViewFrame* view = dynamic_cast<SUPERVGraph_ViewFrame*>( vm->getViewManager()->getActiveView() );
1061 view->setBackgroundColor( resMgr->colorValue( "SUPERVGraph", "Background", view->backgroundColor() ) );
1063 else if( vmType == OCCViewer_Viewer::Type() )
1065 viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
1066 SOCC_Viewer* vm = new SOCC_Viewer();
1067 vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
1068 vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
1071 u = resMgr->integerValue( "OCCViewer", "iso_number_u", u );
1072 v = resMgr->integerValue( "OCCViewer", "iso_number_v", v );
1073 vm->setIsos( u, v );
1074 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1075 new LightApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
1077 else if ( vmType == SVTK_Viewer::Type() )
1079 viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
1080 SVTK_Viewer* vm = dynamic_cast<SVTK_Viewer*>( viewMgr->getViewModel() );
1083 vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
1084 vm->setTrihedronSize( resMgr->integerValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ) );
1085 new LightApp_VTKSelector( vm, mySelMgr );
1092 addViewManager( viewMgr );
1093 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
1095 if ( viewWin && desktop() )
1096 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
1098 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1099 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
1104 //=======================================================================
1105 // name : onCloseView
1106 /*! Purpose : SLOT. Remove view manager from application*/
1107 //=======================================================================
1108 void LightApp_Application::onCloseView( SUIT_ViewManager* theVM )
1110 removeViewManager( theVM );
1113 /*!Protected SLOT. On study created.*/
1114 void LightApp_Application::onStudyCreated( SUIT_Study* theStudy )
1116 SUIT_DataObject* aRoot = 0;
1117 if ( theStudy && theStudy->root() )
1119 aRoot = theStudy->root();
1120 //aRoot->setName( tr( "DATA_MODELS" ) );
1122 if ( objectBrowser() != 0 )
1123 objectBrowser()->setRootObject( aRoot );
1125 activateModule( defaultModule() );
1130 /*!Protected SLOT. On study opened.*/
1131 void LightApp_Application::onStudyOpened( SUIT_Study* theStudy )
1133 SUIT_DataObject* aRoot = 0;
1134 if ( theStudy && theStudy->root() )
1136 aRoot = theStudy->root();
1139 if ( objectBrowser() != 0 ) {
1140 objectBrowser()->setRootObject( aRoot );
1143 activateModule( defaultModule() );
1150 /*!Protected SLOT. On study saved.*/
1151 void LightApp_Application::onStudySaved( SUIT_Study* )
1156 /*!Protected SLOT. On study closed.*/
1157 void LightApp_Application::onStudyClosed( SUIT_Study* )
1161 // Bug 10396: clear selection
1162 mySelMgr->clearSelected();
1164 activateModule( "" );
1166 saveWindowsGeometry();
1169 /*!Protected SLOT.On desktop activated.*/
1170 void LightApp_Application::onDesktopActivated()
1172 CAM_Application::onDesktopActivated();
1173 LightApp_Module* aModule = dynamic_cast<LightApp_Module*>(activeModule());
1175 aModule->studyActivated();
1178 /*!Gets file filter.
1179 *\retval QString "(*.bin)"
1181 QString LightApp_Application::getFileFilter() const
1186 /*! Gets file name*/
1187 QString LightApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1188 const QString& caption, QWidget* parent )
1192 QStringList fls = QStringList::split( ";;", filters, false );
1193 return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1196 /*! Gets directory*/
1197 QString LightApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1201 return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1204 /*! Get open file names*/
1205 QStringList LightApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
1206 const QString& caption, QWidget* parent )
1210 QStringList fls = QStringList::split( ";;", filters, false );
1211 return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1214 /*!Private SLOT. Update object browser.*/
1215 void LightApp_Application::onRefresh()
1217 updateObjectBrowser( true );
1220 /*!Private SLOT. On preferences.*/
1221 void LightApp_Application::onPreferences()
1223 QApplication::setOverrideCursor( Qt::waitCursor );
1225 LightApp_PreferencesDlg* prefDlg = new LightApp_PreferencesDlg( preferences( true ), desktop());
1227 QApplication::restoreOverrideCursor();
1237 /*!Protected SLOT. On preferences changed.*/
1238 void LightApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1240 LightApp_Module* sMod = 0;
1241 CAM_Module* mod = module( modName );
1242 if ( mod && mod->inherits( "LightApp_Module" ) )
1243 sMod = (LightApp_Module*)mod;
1246 sMod->preferencesChanged( section, param );
1248 preferencesChanged( section, param );
1251 /*!Private SLOT. On open document with name \a aName.*/
1252 void LightApp_Application::onMRUActivated( QString aName )
1257 /*!Remove all windows from study.*/
1258 void LightApp_Application::beforeCloseDoc( SUIT_Study* s )
1260 CAM_Application::beforeCloseDoc( s );
1262 for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1263 removeWindow( itr.key(), s->id() );
1266 /*!Update actions.*/
1267 void LightApp_Application::updateActions()
1269 updateCommandsStatus();
1272 //=======================================================================
1273 // name : createNewStudy
1274 /*! Purpose : Create new study*/
1275 //=======================================================================
1276 SUIT_Study* LightApp_Application::createNewStudy()
1278 LightApp_Study* aStudy = new LightApp_Study( this );
1280 // Set up processing of major study-related events
1281 connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
1282 connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
1283 connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );
1284 connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
1290 QWidget* LightApp_Application::createWindow( const int flag )
1293 if ( flag == WT_ObjectBrowser )
1295 OB_Browser* ob = new OB_Browser( desktop() );
1296 ob->setAutoUpdate( true );
1297 ob->setAutoOpenLevel( 1 );
1298 ob->setCaption( tr( "OBJECT_BROWSER" ) );
1299 ob->listView()->setColumnWidth( 0, OBJECT_COLUMN_WIDTH );
1300 ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
1301 ob->setFilter( new LightApp_OBFilter( selectionMgr() ) );
1303 ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1305 // Create OBSelector
1306 new LightApp_OBSelector( ob, mySelMgr );
1310 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1312 else if ( flag == WT_PyConsole )
1314 PythonConsole* pyCons = new PythonConsole( desktop() );
1315 pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1317 // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1319 else if ( flag == WT_LogWindow )
1321 LogWindow* logWin = new LogWindow( desktop() );
1322 logWin->setCaption( tr( "LOG_WINDOW" ) );
1324 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1329 /*!Default windows(Object Browser, Python Console).
1330 * Adds to map \a aMap.
1332 void LightApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1334 aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1335 aMap.insert( WT_PyConsole, Qt::DockBottom );
1336 // aMap.insert( WT_LogWindow, Qt::DockBottom );
1339 /*!Default view manager.*/
1340 void LightApp_Application::defaultViewManagers( QStringList& ) const
1345 /*!Gets preferences.
1346 * Create preferences, if \a crt = true.
1348 LightApp_Preferences* LightApp_Application::preferences( const bool crt ) const
1353 LightApp_Application* that = (LightApp_Application*)this;
1355 if ( !_prefs_ && crt )
1357 _prefs_ = new LightApp_Preferences( resourceMgr() );
1358 that->createPreferences( _prefs_ );
1361 that->myPrefs = _prefs_;
1363 QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1364 for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1366 if ( !appIt.current()->inherits( "LightApp_Application" ) )
1369 LightApp_Application* app = (LightApp_Application*)appIt.current();
1371 QStringList modNameList;
1372 app->modules( modNameList, false );
1373 for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1375 int id = _prefs_->addPreference( *it );
1376 _prefs_->setItemProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1380 app->modules( modList );
1381 for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1383 LightApp_Module* mod = 0;
1384 if ( itr.current()->inherits( "LightApp_Module" ) )
1385 mod = (LightApp_Module*)itr.current();
1387 if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1389 int modCat = _prefs_->addPreference( mod->moduleName() );
1390 _prefs_->setItemProperty( modCat, "info", QString::null );
1391 mod->createPreferences();
1396 connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1397 this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1402 /*!Add new module to application.*/
1403 void LightApp_Application::moduleAdded( CAM_Module* mod )
1405 CAM_Application::moduleAdded( mod );
1407 LightApp_Module* lightMod = 0;
1408 if ( mod && mod->inherits( "LightApp_Module" ) )
1409 lightMod = (LightApp_Module*)mod;
1411 if ( myPrefs && lightMod && !myPrefs->hasModule( lightMod->moduleName() ))
1413 int modCat = myPrefs->addPreference( mod->moduleName() );
1414 myPrefs->setItemProperty( modCat, "info", QString::null );
1415 lightMod->createPreferences();
1419 /*!Create preferences.*/
1420 void LightApp_Application::createPreferences( LightApp_Preferences* pref )
1425 int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1427 int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1428 int studyGroup = pref->addPreference( tr( "PREF_GROUP_STUDY" ), genTab );
1429 pref->setItemProperty( studyGroup, "columns", 1 );
1431 pref->addPreference( tr( "PREF_MULTI_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "multi_file" );
1432 pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "ascii_file" );
1433 int undoPref = pref->addPreference( tr( "PREF_UNDO_LEVEL" ), studyGroup, LightApp_Preferences::IntSpin, "Study", "undo_level" );
1434 pref->setItemProperty( undoPref, "min", 1 );
1435 pref->setItemProperty( undoPref, "max", 100 );
1437 int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab );
1438 pref->setItemProperty( extgroup, "columns", 1 );
1439 int apppref = pref->addPreference( tr( "PREF_APP" ), extgroup, LightApp_Preferences::File, "ExternalBrowser", "application" );
1440 pref->setItemProperty( apppref, "existing", true );
1441 pref->setItemProperty( apppref, "flags", QFileInfo::ExeUser );
1443 pref->addPreference( tr( "PREF_PARAM" ), extgroup, LightApp_Preferences::String, "ExternalBrowser", "parameters" );
1445 int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab );
1446 pref->setItemProperty( pythonConsoleGroup, "columns", 1 );
1447 pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, LightApp_Preferences::Font, "PyConsole", "font" );
1449 int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1451 int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1453 int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1455 int plot2dGroup = pref->addPreference( tr( "PREF_GROUP_PLOT2DVIEWER" ), viewTab );
1457 int supervGroup = pref->addPreference( tr( "PREF_GROUP_SUPERV" ), viewTab );
1459 pref->setItemProperty( occGroup, "columns", 1 );
1460 pref->setItemProperty( vtkGroup, "columns", 1 );
1461 pref->setItemProperty( plot2dGroup, "columns", 1 );
1463 int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1464 LightApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1465 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1466 LightApp_Preferences::Color, "OCCViewer", "background" );
1468 pref->setItemProperty( occTS, "min", 1 );
1469 pref->setItemProperty( occTS, "max", 150 );
1471 int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
1472 LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
1473 int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
1474 LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
1476 pref->setItemProperty( isoU, "min", 0 );
1477 pref->setItemProperty( isoU, "max", 100000 );
1479 pref->setItemProperty( isoV, "min", 0 );
1480 pref->setItemProperty( isoV, "max", 100000 );
1482 int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1483 LightApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1484 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1485 LightApp_Preferences::Color, "VTKViewer", "background" );
1487 pref->setItemProperty( vtkTS, "min", 1 );
1488 pref->setItemProperty( vtkTS, "max", 150 );
1490 pref->addPreference( tr( "PREF_SHOW_LEGEND" ), plot2dGroup,
1491 LightApp_Preferences::Bool, "Plot2d", "ShowLegend" );
1493 int legendPosition = pref->addPreference( tr( "PREF_LEGEND_POSITION" ), plot2dGroup,
1494 LightApp_Preferences::Selector, "Plot2d", "LegendPos" );
1495 QStringList aLegendPosList;
1496 aLegendPosList.append( tr("PREF_LEFT") );
1497 aLegendPosList.append( tr("PREF_RIGHT") );
1498 aLegendPosList.append( tr("PREF_TOP") );
1499 aLegendPosList.append( tr("PREF_BOTTOM") );
1501 QValueList<QVariant> anIndexesList;
1502 anIndexesList.append(0);
1503 anIndexesList.append(1);
1504 anIndexesList.append(2);
1505 anIndexesList.append(3);
1507 pref->setItemProperty( legendPosition, "strings", aLegendPosList );
1508 pref->setItemProperty( legendPosition, "indexes", anIndexesList );
1510 int curveType = pref->addPreference( tr( "PREF_CURVE_TYPE" ), plot2dGroup,
1511 LightApp_Preferences::Selector, "Plot2d", "CurveType" );
1512 QStringList aCurveTypesList;
1513 aCurveTypesList.append( tr("PREF_POINTS") );
1514 aCurveTypesList.append( tr("PREF_LINES") );
1515 aCurveTypesList.append( tr("PREF_SPLINE") );
1517 anIndexesList.clear();
1518 anIndexesList.append(0);
1519 anIndexesList.append(1);
1520 anIndexesList.append(2);
1522 pref->setItemProperty( curveType, "strings", aCurveTypesList );
1523 pref->setItemProperty( curveType, "indexes", anIndexesList );
1525 int markerSize = pref->addPreference( tr( "PREF_MARKER_SIZE" ), plot2dGroup,
1526 LightApp_Preferences::IntSpin, "Plot2d", "MarkerSize" );
1528 pref->setItemProperty( markerSize, "min", 0 );
1529 pref->setItemProperty( markerSize, "max", 100 );
1531 QStringList aScaleModesList;
1532 aScaleModesList.append( tr("PREF_LINEAR") );
1533 aScaleModesList.append( tr("PREF_LOGARITHMIC") );
1535 anIndexesList.clear();
1536 anIndexesList.append(0);
1537 anIndexesList.append(1);
1539 int horScale = pref->addPreference( tr( "PREF_HOR_AXIS_SCALE" ), plot2dGroup,
1540 LightApp_Preferences::Selector, "Plot2d", "HorScaleMode" );
1542 pref->setItemProperty( horScale, "strings", aScaleModesList );
1543 pref->setItemProperty( horScale, "indexes", anIndexesList );
1545 int verScale = pref->addPreference( tr( "PREF_VERT_AXIS_SCALE" ), plot2dGroup,
1546 LightApp_Preferences::Selector, "Plot2d", "VerScaleMode" );
1548 pref->setItemProperty( verScale, "strings", aScaleModesList );
1549 pref->setItemProperty( verScale, "indexes", anIndexesList );
1551 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), plot2dGroup,
1552 LightApp_Preferences::Color, "Plot2d", "Background" );
1554 int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat );
1555 int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab );
1556 pref->setItemProperty( dirGroup, "columns", 1 );
1557 pref->addPreference( tr( "" ), dirGroup,
1558 LightApp_Preferences::DirList, "FileDlg", "QuickDirList" );
1560 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), supervGroup,
1561 LightApp_Preferences::Color, "SUPERVGraph", "Background" );
1562 pref->addPreference( tr( "PREF_SUPERV_TITLE_COLOR" ), supervGroup,
1563 LightApp_Preferences::Color, "SUPERVGraph", "Title" );
1564 // pref->addPreference( tr( "PREF_SUPERV_CTRL_COLOR" ), supervGroup,
1565 // LightApp_Preferences::Color, "SUPERVGraph", "Ctrl" );
1568 /*!Changed preferences */
1569 void LightApp_Application::preferencesChanged( const QString& sec, const QString& param )
1571 SUIT_ResourceMgr* resMgr = resourceMgr();
1575 if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1577 int sz = resMgr->integerValue( sec, param, -1 );
1578 QPtrList<SUIT_ViewManager> lst;
1579 viewManagers( OCCViewer_Viewer::Type(), lst );
1580 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1582 SUIT_ViewModel* vm = it.current()->getViewModel();
1583 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1586 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1587 occVM->setTrihedronSize( sz );
1588 occVM->getAISContext()->UpdateCurrentViewer();
1592 if ( sec == QString( "VTKViewer" ) && param == QString( "trihedron_size" ) )
1594 int sz = resMgr->integerValue( sec, param, -1 );
1595 QPtrList<SUIT_ViewManager> lst;
1596 viewManagers( SVTK_Viewer::Type(), lst );
1597 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1599 SUIT_ViewModel* vm = it.current()->getViewModel();
1600 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
1603 SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
1606 vtkVM->setTrihedronSize( sz );
1612 if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
1614 QPtrList<SUIT_ViewManager> lst;
1615 viewManagers( OCCViewer_Viewer::Type(), lst );
1616 int u = resMgr->integerValue( sec, "iso_number_u" );
1617 int v = resMgr->integerValue( sec, "iso_number_v" );
1618 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
1620 OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>( it.current() );
1621 if( mgr && mgr->getOCCViewer() )
1622 mgr->getOCCViewer()->setIsos( u, v );
1626 if( sec=="ObjectBrowser" )
1628 if( param=="auto_size" )
1630 OB_Browser* ob = objectBrowser();
1634 bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
1635 ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1637 updateObjectBrowser( false );
1641 if( sec=="PyConsole" )
1644 if( pythonConsole() )
1645 pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1649 /*!Update desktop title.*/
1650 void LightApp_Application::updateDesktopTitle() {
1651 QString aTitle = applicationName();
1652 QString aVer = applicationVersion();
1653 if ( !aVer.isEmpty() )
1654 aTitle += QString( " " ) + aVer;
1656 desktop()->setCaption( aTitle );
1659 /*!Update windows after close document.*/
1660 void LightApp_Application::afterCloseDoc()
1664 CAM_Application::afterCloseDoc();
1667 /*!Update module action.*/
1668 void LightApp_Application::updateModuleActions()
1671 if ( activeModule() )
1672 modName = activeModule()->moduleName();
1674 if ( myActions.contains( modName ) )
1675 myActions[modName]->setOn( true );
1678 /*!Gets current windows.
1679 *\param winMap - output current windows map.
1681 void LightApp_Application::currentWindows( QMap<int, int>& winMap ) const
1684 if ( !activeStudy() )
1687 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
1688 ((LightApp_Module*)activeModule())->windows( winMap );
1690 defaultWindows( winMap );
1693 /*!Gets current view managers.
1694 *\param lst - output current view managers list.
1696 void LightApp_Application::currentViewManagers( QStringList& lst ) const
1699 if ( !activeStudy() )
1702 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
1703 ((LightApp_Module*)activeModule())->viewManagers( lst );
1705 defaultViewManagers( lst );
1708 /*!Update windows.*/
1709 void LightApp_Application::updateWindows()
1711 QMap<int, int> winMap;
1712 currentWindows( winMap );
1714 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1715 getWindow( it.key() );
1717 loadWindowsGeometry();
1719 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1720 setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1723 /*!Update view managers.*/
1724 void LightApp_Application::updateViewManagers()
1727 currentViewManagers( lst );
1729 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1730 getViewManager( *it, true );
1733 /*!Load windows geometry.*/
1734 void LightApp_Application::loadWindowsGeometry()
1736 QtxDockAction* dockMgr = 0;
1738 QAction* a = action( ViewWindowsId );
1739 if ( a && a->inherits( "QtxDockAction" ) )
1740 dockMgr = (QtxDockAction*)a;
1746 if ( activeModule() )
1747 modName = activeModule()->name("");
1749 QString section = QString( "windows_geometry" );
1750 if ( !modName.isEmpty() )
1751 section += QString( "." ) + modName;
1753 dockMgr->loadGeometry( resourceMgr(), section, false );
1754 dockMgr->restoreGeometry();
1757 /*!Save windows geometry.*/
1758 void LightApp_Application::saveWindowsGeometry()
1760 QtxDockAction* dockMgr = 0;
1762 QAction* a = action( ViewWindowsId );
1763 if ( a && a->inherits( "QtxDockAction" ) )
1764 dockMgr = (QtxDockAction*)a;
1770 if ( activeModule() )
1771 modName = activeModule()->name("");
1773 QString section = QString( "windows_geometry" );
1774 if ( !modName.isEmpty() )
1775 section += QString( "." ) + modName;
1777 dockMgr->storeGeometry();
1778 dockMgr->saveGeometry( resourceMgr(), section, false );
1781 /*!Activate windows.*/
1782 void LightApp_Application::activateWindows()
1784 if ( activeStudy() )
1786 for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1787 itr.data()->activate( activeStudy()->id() );
1791 /*!Adds icon names for modules.*/
1792 void LightApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
1796 SUIT_ResourceMgr* resMgr = resourceMgr();
1800 QStringList modList;
1801 modules( modList, false );
1803 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
1805 QString modName = *it;
1806 QString modIntr = moduleName( modName );
1807 QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
1809 if ( modIcon.isEmpty() )
1812 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
1813 modIcon += QString( ".png" );
1815 iconMap.insert( modName, modIcon );
1819 /*!Insert items in popup, which necessary for current application*/
1820 void LightApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
1822 CAM_Application::contextMenuPopup( type, thePopup, title );
1824 OB_Browser* ob = objectBrowser();
1825 if ( !ob || type != ob->popupClientType() )
1828 thePopup->insertSeparator();
1829 thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
1832 /*!Create empty study.*/
1833 void LightApp_Application::createEmptyStudy()
1835 CAM_Application::createEmptyStudy();
1836 if ( objectBrowser() )
1837 objectBrowser()->updateTree();
1840 /*!Activate module \a mod.*/
1841 bool LightApp_Application::activateModule( CAM_Module* mod )
1843 bool res = CAM_Application::activateModule( mod );
1844 if ( objectBrowser() )
1845 objectBrowser()->updateTree();
1849 /*!return keyborad accelerators manager object */
1850 SUIT_Accel* LightApp_Application::accel() const
1855 /*! remove dead widget container from map */
1856 void LightApp_Application::onWCDestroyed( QObject* ob )
1858 // remove destroyed widget container from windows map
1859 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1861 if ( itr.data() != ob )
1864 int key = itr.key();
1865 myWindows.remove( key );
1870 /*! redefined to remove view manager from memory */
1871 void LightApp_Application::removeViewManager( SUIT_ViewManager* vm )
1873 disconnect( vm, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1874 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
1875 STD_Application::removeViewManager( vm );
1879 /*! rename active window of desktop */
1880 void LightApp_Application::onRenameWindow()
1885 QWidget* w = desktop()->activeWindow();
1890 QString name = QInputDialog::getText( tr( "TOT_RENAME" ), tr( "PRP_RENAME" ), QLineEdit::Normal, w->caption(), &ok, w );
1891 if( ok && !name.isEmpty() )
1892 w->setCaption( name );