+ QFont f;
+ if( wid->inherits( "PythonConsole" ) )
+ f = ( ( PythonConsole* )wid )->font();
+ else
+ f = wid->font();
+
+ myWindows[flag]->insert( sId, wid );
+ wid->setFont( f );
+
+ setWindowShown( flag, !myWindows[flag]->isEmpty() );
+}
+
+/*!Remove window from application.
+ *\param flag - key wor window
+ *\param studyId - study id
+ * Flag used how identificator of window in windows list.
+ */
+void SalomeApp_Application::removeWindow( const int flag, const int studyId )
+{
+ if ( !myWindows.contains( flag ) )
+ return;
+
+ int sId = studyId;
+ if ( sId < 0 )
+ {
+ if ( !activeStudy() )
+ return;
+ else
+ sId = activeStudy()->id();
+ }
+
+ QWidget* wid = myWindows[flag]->widget( sId );
+ myWindows[flag]->remove( sId );
+ delete wid;
+
+ setWindowShown( flag, !myWindows[flag]->isEmpty() );
+}
+
+/*!Gets window.
+ *\param flag - key wor window
+ *\param studyId - study id
+ * Flag used how identificator of window in windows list.
+ */
+QWidget* SalomeApp_Application::getWindow( const int flag, const int studyId )
+{
+ QWidget* wid = window( flag, studyId );
+ if ( !wid )
+ addWindow( wid = createWindow( flag ), flag, studyId );
+
+ return wid;
+}
+
+/*!Check is window visible?(with identificator \a type)*/
+bool SalomeApp_Application::isWindowVisible( const int type ) const
+{
+ bool res = false;
+ if ( myWindows.contains( type ) )
+ {
+ SUIT_Desktop* desk = ((SalomeApp_Application*)this)->desktop();
+ res = desk && desk->appropriate( myWindows[type] );
+ }
+ return res;
+}
+
+/*!Sets window show or hide.
+ *\param type - window identificator.
+ *\param on - true/false (window show/hide)
+ */
+void SalomeApp_Application::setWindowShown( const int type, const bool on )
+{
+ if ( !desktop() || !myWindows.contains( type ) )
+ return;
+
+ QDockWindow* dw = myWindows[type];
+ desktop()->setAppropriate( dw, on );
+ on ? dw->show() : dw->hide();
+}
+
+OB_Browser* SalomeApp_Application::objectBrowser()
+{
+ OB_Browser* ob = 0;
+ QWidget* wid = getWindow( WT_ObjectBrowser );
+ if ( wid->inherits( "OB_Browser" ) )
+ ob = (OB_Browser*)wid;
+ return ob;
+}
+
+/*!Gets "LogWindow".*/
+LogWindow* SalomeApp_Application::logWindow()
+{
+ LogWindow* lw = 0;
+ QWidget* wid = getWindow( WT_LogWindow );
+ if ( wid->inherits( "LogWindow" ) )
+ lw = (LogWindow*)wid;
+ return lw;
+}
+
+/*!Get "PythonConsole"*/
+PythonConsole* SalomeApp_Application::pythonConsole()
+{
+ PythonConsole* console = 0;
+ QWidget* wid = getWindow( WT_PyConsole );
+ if ( wid->inherits( "PythonConsole" ) )
+ console = (PythonConsole*)wid;
+ return console;
+}
+
+/*!Gets preferences.*/
+SalomeApp_Preferences* SalomeApp_Application::preferences() const
+{
+ return preferences( false );
+}
+
+/*!Gets view manager*/
+SUIT_ViewManager* SalomeApp_Application::getViewManager( const QString& vmType, const bool create )
+{
+ SUIT_ViewManager* aVM = viewManager( vmType );
+ SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
+
+ if ( anActiveVM && anActiveVM->getType() == vmType )
+ aVM = anActiveVM;
+
+ if ( aVM && create )
+ {
+ if ( !aVM->getActiveView() )
+ aVM->createView();
+ else
+ aVM->getActiveView()->setFocus();
+ }
+ else if ( create )
+ aVM = createViewManager( vmType );
+
+ return aVM;
+}
+
+/*!Create view manager.*/
+SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmType )
+{
+ SUIT_ResourceMgr* resMgr = resourceMgr();
+
+ SUIT_ViewManager* viewMgr = 0;
+ if ( vmType == GLViewer_Viewer::Type() )
+ {
+ viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
+ new SalomeApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
+ }
+ else if ( vmType == Plot2d_Viewer::Type() )
+ {
+ viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
+ viewMgr->setViewModel( new SPlot2d_Viewer() );// custom view model, which extends SALOME_View interface
+ }
+ else if ( vmType == OCCViewer_Viewer::Type() )
+ {
+ viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
+ SOCC_Viewer* vm = new SOCC_Viewer();
+ vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
+ vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
+ int u( 1 ), v( 1 );
+ vm->isos( u, v );
+ u = resMgr->integerValue( "OCCViewer", "iso_number_u", u );
+ v = resMgr->integerValue( "OCCViewer", "iso_number_v", v );
+ vm->setIsos( u, v );
+ viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
+ new SalomeApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
+ }
+ else if ( vmType == SVTK_Viewer::Type() )
+ {
+ viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
+ SVTK_Viewer* vm = (SVTK_Viewer*)viewMgr->getViewModel();
+ vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
+ vm->setTrihedronSize( resMgr->integerValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ) );
+ new SalomeApp_VTKSelector((SVTK_Viewer*)viewMgr->getViewModel(),mySelMgr);
+ }
+
+ if ( !viewMgr )
+ return 0;
+
+ addViewManager( viewMgr );
+ SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
+
+ if ( viewWin && desktop() )
+ viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
+
+ connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
+ this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
+
+ return viewMgr;
+}
+
+void SalomeApp_Application::onCloseView( SUIT_ViewManager* theVM )
+{
+ removeViewManager( theVM );
+}
+
+/*!Private SLOT. On study created.*/
+void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy )
+{
+ SUIT_DataObject* aRoot = 0;
+ if ( theStudy && theStudy->root() )
+ {
+ aRoot = theStudy->root();
+ //aRoot->setName( tr( "DATA_MODELS" ) );
+ }
+ if ( objectBrowser() != 0 )
+ objectBrowser()->setRootObject( aRoot );
+
+ activateModule( defaultModule() );
+
+ activateWindows();
+}
+
+/*!Private SLOT. On study opened.*/
+void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
+{
+ SUIT_DataObject* aRoot = 0;
+ if ( theStudy && theStudy->root() )
+ {
+ aRoot = theStudy->root();
+ //aRoot->dump();
+ }
+ if ( objectBrowser() != 0 ) {
+ objectBrowser()->setRootObject( aRoot );
+ }
+
+ activateModule( defaultModule() );
+
+ activateWindows();
+
+ emit studyOpened();
+}
+
+void SalomeApp_Application::onStudySaved( SUIT_Study* )
+{
+ emit studySaved();
+}
+
+/*!Private SLOT. On study closed.*/
+void SalomeApp_Application::onStudyClosed( SUIT_Study* )
+{
+ emit studyClosed();
+
+ activateModule( "" );
+
+ saveWindowsGeometry();
+}
+
+/*!Private SLOT. On dump study.*/
+void SalomeApp_Application::onDumpStudy( )
+{
+ SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
+ if ( !appStudy ) return;
+ _PTR(Study) aStudy = appStudy->studyDS();
+
+ QStringList aFilters;
+ aFilters.append( tr( "PYTHON_FILES_FILTER" ) );
+
+ SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( desktop(), false, tr("PUBLISH_IN_STUDY"), true, true);
+ fd->setCaption( tr( "TOT_DESK_FILE_DUMP_STUDY" ) );
+ fd->setFilters( aFilters );
+ fd->SetChecked(true);
+ fd->exec();
+ QString aFileName = fd->selectedFile();
+ bool toPublish = fd->IsChecked();
+ delete fd;
+
+ if(!aFileName.isEmpty()) {
+ QFileInfo aFileInfo(aFileName);
+ aStudy->DumpStudy( aFileInfo.dirPath( true ).latin1(), aFileInfo.baseName().latin1(), toPublish );
+ }
+}
+
+/*!Private SLOT. On load script.*/
+void SalomeApp_Application::onLoadScript( )
+{
+ SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
+ if ( !appStudy ) return;
+ _PTR(Study) aStudy = appStudy->studyDS();
+
+ if ( aStudy->GetProperties()->IsLocked() ) {
+ SUIT_MessageBox::warn1 ( desktop(),
+ QObject::tr("WRN_WARNING"),
+ QObject::tr("WRN_STUDY_LOCKED"),
+ QObject::tr("BUT_OK") );
+ return;
+ }
+
+ QStringList filtersList;
+ filtersList.append(tr("PYTHON_FILES_FILTER"));
+ filtersList.append(tr("ALL_FILES_FILTER"));
+
+ QString aFile = SUIT_FileDlg::getFileName( desktop(), "", filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true );
+
+ if ( !aFile.isEmpty() )
+ {
+ QString command = QString("execfile(\"%1\")").arg(aFile);
+
+ PythonConsole* pyConsole = pythonConsole();
+
+ if ( pyConsole )
+ pyConsole->exec( command );
+ }
+}
+
+/*!Private SLOT. On preferences.*/
+void SalomeApp_Application::onPreferences()
+{
+ QApplication::setOverrideCursor( Qt::waitCursor );
+
+ SalomeApp_PreferencesDlg* prefDlg = new SalomeApp_PreferencesDlg( preferences( true ), desktop());
+
+ QApplication::restoreOverrideCursor();
+
+ if ( !prefDlg )
+ return;
+
+ prefDlg->exec();
+
+ delete prefDlg;
+}
+
+/*!Private SLOT. On open document with name \a aName.*/
+void SalomeApp_Application::onMRUActivated( QString aName )
+{
+ onOpenDoc( aName );
+}
+
+/*!Private SLOT. On preferences changed.*/
+void SalomeApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
+{
+ SalomeApp_Module* sMod = 0;
+ CAM_Module* mod = module( modName );
+ if ( mod && mod->inherits( "SalomeApp_Module" ) )
+ sMod = (SalomeApp_Module*)mod;
+
+ if ( sMod )
+ sMod->preferencesChanged( section, param );
+ else
+ preferencesChanged( section, param );
+}
+
+/*!Gets file filter.
+ *\retval QString "(*.hdf)"