#include "SalomeApp_Study.h"
#include "SalomeApp_Module.h"
+#include "SalomeApp_OBFilter.h"
+#include "SalomeApp_DataModel.h"
+#include "SalomeApp_DataObject.h"
+#include "SalomeApp_EventFilter.h"
+#include "SalomeApp_WidgetContainer.h"
+
+#include "SalomeApp_AboutDlg.h"
+#include "SalomeApp_ModuleDlg.h"
+#include "SalomeApp_PreferencesDlg.h"
+#include "SalomeApp_StudyPropertiesDlg.h"
+
#include "SalomeApp_GLSelector.h"
#include "SalomeApp_OBSelector.h"
#include "SalomeApp_OCCSelector.h"
#include "SalomeApp_VTKSelector.h"
-#include "SalomeApp_EventFilter.h"
#include "SalomeApp_SelectionMgr.h"
-#include "SalomeApp_EventFilter.h"
-#include "SalomeApp_WidgetContainer.h"
-#include "SalomeApp_ModuleDlg.h"
-#include "SalomeApp_OBFilter.h"
#include <LogWindow.h>
#include <GLViewer_ViewManager.h>
#include <Plot2d_ViewManager.h>
+#include <SPlot2d_ViewModel.h>
#include <OCCViewer_ViewManager.h>
#include <SOCC_ViewModel.h>
#include <PythonConsole_PyConsole.h>
+#include <SUIT_FileDlg.h>
#include <SUIT_MessageBox.h>
#include <SUIT_ResourceMgr.h>
#include <SUIT_ActionOperation.h>
#include <Utils_ORB_INIT.hxx>
#include <Utils_SINGLETON.hxx>
#include <SALOME_ModuleCatalog_impl.hxx>
+#include <SALOME_LifeCycleCORBA.hxx>
#include <qmap.h>
+#include <qdir.h>
#include <qlabel.h>
#include <qimage.h>
#include <qaction.h>
*/
SalomeApp_Application::SalomeApp_Application()
-: CAM_Application( false )
+: CAM_Application( false ),
+myPrefDlg( 0 )
{
STD_TabDesktop* desk = new STD_TabDesktop();
QString SalomeApp_Application::applicationName() const
{
- return "SalomeApp";
+ return tr( "APP_NAME" );
+}
+
+QString SalomeApp_Application::applicationVersion() const
+{
+ static QString _app_version;
+
+ if ( _app_version.isEmpty() )
+ {
+ QString path( ::getenv( "GUI_ROOT_DIR" ) );
+ if ( !path.isEmpty() )
+ path += QDir::separator();
+ path += QString( "bin/salome/VERSION" );
+
+ QFile vf( path );
+ if ( vf.open( IO_ReadOnly ) )
+ {
+ QString line;
+ vf.readLine( line, 1024 );
+ vf.close();
+
+ if ( !line.isEmpty() )
+ {
+ while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
+ line.remove( line.length() - 1, 1 );
+
+ int idx = line.findRev( ":" );
+ if ( idx != -1 )
+ _app_version = line.mid( idx + 1 ).stripWhiteSpace();
+ }
+ }
+ }
+
+ return _app_version;
}
CAM_Module* SalomeApp_Application::loadModule( const QString& name )
SUIT_Desktop* desk = desktop();
SUIT_ResourceMgr* resMgr = resourceMgr();
+
+ // Load script
+ createAction( LoadScriptId, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), QIconSet(),
+ tr( "MEN_DESK_FILE_LOAD_SCRIPT" ), tr( "PRP_DESK_FILE_LOAD_SCRIPT" ),
+ 0, desk, false, this, SLOT( onLoadScript() ) );
+ int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
+ createMenu( LoadScriptId, fileMenu, 10, -1 );
+
+ createAction( PropertiesId, tr( "TOT_DESK_FILE_PROPERTIES" ), QIconSet(),
+ tr( "MEN_DESK_FILE_PROPERTIES" ), tr( "PRP_DESK_FILE_PROPERTIES" ),
+ 0, desk, false, this, SLOT( onProperties() ) );
+ createMenu( PropertiesId, fileMenu, 10, -1 );
+
// default icon for neutral point ('SALOME' module)
QPixmap defIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ) );
if ( defIcon.isNull() )
}
SUIT_Tools::simplifySeparators( modTBar );
-
+
// New window
int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 );
int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
createMenu( separator(), windowMenu, -1, 1 );
+ QMap<int, int> accelMap;
+ accelMap[NewGLViewId] = ALT+Key_G;
+ accelMap[NewPlot2dId] = ALT+Key_P;
+ accelMap[NewOCCViewId] = ALT+Key_O;
+ accelMap[NewVTKViewId] = ALT+Key_K;
+
for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
{
QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), QIconSet(),
- tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
- tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
- 0, desk, false, this, SLOT( onNewWindow() ) );
+ tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
+ tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
+ accelMap.contains( id ) ? accelMap[id] : 0, desk, false, this, SLOT( onNewWindow() ) );
createMenu( a, newWinMenu, -1 );
}
{
}
+void SalomeApp_Application::onAboutRefresh()
+{
+ for ( ModuleListIterator it = modules(); it.current(); ++it )
+ {
+ CAM_DataModel* camDM = it.current()->dataModel();
+ if ( camDM && camDM->inherits( "SalomeApp_DataModel" ) )
+ ((SalomeApp_DataModel*)camDM)->update();
+ }
+}
+
void SalomeApp_Application::setActiveStudy( SUIT_Study* study )
{
CAM_Application::setActiveStudy( study );
if ( a )
a->setEnabled( activeStudy() );
}
+
+ // Load script menu
+ QAction* a = action( LoadScriptId );
+ if ( a )
+ a->setEnabled( activeStudy() );
+
+ a = action( PropertiesId );
+ if( a )
+ a->setEnabled( activeStudy() );
}
//=======================================================================
//=======================================================================
void SalomeApp_Application::onHelpAbout()
{
- QMessageBox aDlg( desktop(), "AboutDlg" );
-
- SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
- QPixmap aPixmap = aResMgr->loadPixmap( "SalomeApp", tr( "ABOUT_ICO" ) );
-
- QFontMetrics m( aDlg.font() );
- QImage anImage = aPixmap.convertToImage();
- int w = m.height() * 5;
- anImage = anImage.scale( w, w );
- aPixmap.convertFromImage( anImage );
-
- aDlg.setCaption( tr( "ABOUT" ) );
- aDlg.setText( tr( "APP_NAME_LONG" ).arg( APP_VERSION ) );
- aDlg.setIconPixmap( aPixmap );
- aDlg.exec();
+ SalomeApp_AboutDlg* dlg = new SalomeApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
+ dlg->exec();
+ delete dlg;
}
QWidget* SalomeApp_Application::window( const int flag, const int studyId ) const
return lw;
}
+PythonConsole* SalomeApp_Application::pythonConsole()
+{
+ PythonConsole* console = 0;
+ QWidget* wid = getWindow( WT_PyConsole );
+ if ( wid->inherits( "PythonConsole" ) )
+ console = (PythonConsole*)wid;
+ return console;
+}
+
+QtxResourceEdit* SalomeApp_Application::resourceEdit() const
+{
+ return 0;
+ /*
+ QtxResourceEdit* edit = 0;
+ if ( !myPrefDlg )
+ {
+ SalomeApp_Application* that = (SalomeApp_Application*)this;
+ that->myPrefDlg = new SalomeApp_PreferencesDlg( that->desktop() );
+
+ edit = myPrefDlg->resourceEdit();
+
+ QStringList modList;
+ modules( modList, false );
+ for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
+ {
+ int id = edit->addItem( *it );
+ edit->setProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
+ }
+ }
+ else
+ edit = myPrefDlg->resourceEdit();
+ */
+}
+
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;
- else if ( aVM )
+
+ if ( aVM && create )
{
if ( !aVM->getActiveView() )
aVM->createView();
+ else
+ aVM->getActiveView()->setFocus();
}
else if ( create )
aVM = createViewManager( vmType );
+
return aVM;
}
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() );
objectBrowser()->setRootObject( aRoot );
activateModule( defaultModule() );
+
+ activateWindows();
}
void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
objectBrowser()->setRootObject( aRoot );
}
- activateWindows();
-
activateModule( defaultModule() );
+ activateWindows();
+
emit studyOpened();
}
saveWindowsGeometry();
}
+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);
+ }
+}
+
QString SalomeApp_Application::getFileFilter() const
{
return "(*.hdf)";
if ( flag == WT_ObjectBrowser )
{
OB_Browser* ob = new OB_Browser( desktop() );
- ob->setFilter( new SalomeApp_OBFilter(selectionMgr()) );
-
+ ob->setAutoUpdate( true );
+ ob->setAutoOpenLevel( 1 );
ob->setCaption( tr( "OBJECT_BROWSER" ) );
ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
- ob->setAutoUpdate( true );
+ ob->setFilter( new SalomeApp_OBFilter( selectionMgr() ) );
+
+ ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
+ for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
+ ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i );
// Create OBSelector
new SalomeApp_OBSelector( ob, mySelMgr );
wid = ob;
+ connect( ob, SIGNAL( aboutRefresh() ), this, SLOT( onAboutRefresh() ) );
ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
}
else if ( flag == WT_PyConsole )
logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
}
-
+
return wid;
}
{
aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
aMap.insert( WT_PyConsole, Qt::DockBottom );
+ aMap.insert( WT_LogWindow, Qt::DockBottom );
}
void SalomeApp_Application::defaultViewManagers( QStringList& ) const
CORBA::ORB_var SalomeApp_Application::orb()
{
ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
- CORBA::ORB_var& orb = init( qApp->argc(), qApp->argv() );
-
- return orb;
+ static CORBA::ORB_var _orb = init( qApp->argc(), qApp->argv() );
+ return _orb;
}
SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr()
{
- static SALOMEDSClient_StudyManager* aStudyManager = NULL;
-
- if(!aStudyManager) {
- aStudyManager = new SALOMEDS_StudyManager();
- }
- return aStudyManager;
+ static SALOMEDSClient_StudyManager* _sm = new SALOMEDS_StudyManager();
+ return _sm;
}
SALOME_NamingService* SalomeApp_Application::namingService()
{
- return new SALOME_NamingService( orb() );
+ static SALOME_NamingService* _ns = new SALOME_NamingService( orb() );
+ return _ns;
+}
+
+SALOME_LifeCycleCORBA* SalomeApp_Application::lcc()
+{
+ static SALOME_LifeCycleCORBA* _lcc = new SALOME_LifeCycleCORBA( namingService() );
+ return _lcc;
}
QString SalomeApp_Application::defaultEngineIOR()
if ( !modName.isEmpty() )
section += QString( "." ) + modName;
-
dockMgr->loadGeometry( resourceMgr(), section, false );
dockMgr->restoreGeometry();
}
itr.data()->activate( activeStudy()->id() );
}
}
+
+void SalomeApp_Application::onProperties()
+{
+ SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
+ if( !study )
+ return;
+
+ _PTR(StudyBuilder) SB = study->studyDS()->NewBuilder();
+ SB->NewCommand();
+
+ SalomeApp_StudyPropertiesDlg aDlg( desktop() );
+ int res = aDlg.exec();
+ if( res==QDialog::Accepted && aDlg.isChanged() )
+ SB->CommitCommand();
+ else
+ SB->AbortCommand();
+
+ //study->updateCaptions();
+}
+
+QString SalomeApp_Application::getFileName( bool open )
+{
+ QStringList filtersList;
+ filtersList.append( getFileFilter() );
+ QString initial = open ? QString( "" ) : ( activeStudy() ? activeStudy()->studyName() : QString( "" ) );
+ return SUIT_FileDlg::getFileName( desktop(), initial, filtersList, QString::null, open, true );
+}