Salome HOME
Fix for IPAL9140: 3.0.0 (09 Jun): "Supervision" module has to be renamed into "Superv...
[modules/gui.git] / src / SalomeApp / SalomeApp_Application.cxx
index 40f68ee2a744e00dc8c4e612a38a0b96f211365d..ffd325319d94928327607c654d29b20ef5045d08 100644 (file)
@@ -9,16 +9,21 @@
 
 #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_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>
 
@@ -26,6 +31,7 @@
 #include <GLViewer_ViewManager.h>
 
 #include <Plot2d_ViewManager.h>
+#include <SPlot2d_ViewModel.h>
 
 #include <OCCViewer_ViewManager.h>
 #include <SOCC_ViewModel.h>
@@ -45,6 +51,7 @@
 
 #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>
@@ -101,7 +110,8 @@ extern "C" SALOMEAPP_EXPORT SUIT_Application* createApplication()
 */
 
 SalomeApp_Application::SalomeApp_Application()
-: CAM_Application( false )
+: CAM_Application( false ),
+myPrefDlg( 0 )
 {
   STD_TabDesktop* desk = new STD_TabDesktop();
 
@@ -161,7 +171,40 @@ void SalomeApp_Application::start()
 
 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 )
@@ -213,7 +256,14 @@ void SalomeApp_Application::createActions()
 
   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 );
+  
   // default icon for neutral point ('SALOME' module)
   QPixmap defIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ) );
   if ( defIcon.isNull() )
@@ -272,7 +322,7 @@ void SalomeApp_Application::createActions()
   }
 
   SUIT_Tools::simplifySeparators( modTBar );
-
+  
   // New window
 
   int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 );
@@ -424,6 +474,20 @@ void SalomeApp_Application::onSelectionChanged()
 {
 }
 
+void SalomeApp_Application::onAboutRefresh()
+{
+  SalomeApp_DataModel* dm = 0;
+  if ( activeModule() )
+  {
+    CAM_DataModel* camDM = activeModule()->dataModel();
+    if ( camDM && camDM->inherits( "SalomeApp_DataModel" ) )
+      dm = (SalomeApp_DataModel*)camDM;
+  }
+
+  if ( dm )
+    dm->update();
+}
+
 void SalomeApp_Application::setActiveStudy( SUIT_Study* study )
 {
   CAM_Application::setActiveStudy( study );
@@ -462,6 +526,11 @@ void SalomeApp_Application::updateCommandsStatus()
     if ( a )
       a->setEnabled( activeStudy() );
   }
+
+  // Load script menu
+  QAction* a = action( LoadScriptId );
+  if ( a )
+    a->setEnabled( activeStudy() );
 }
 
 //=======================================================================
@@ -470,21 +539,9 @@ void SalomeApp_Application::updateCommandsStatus()
 //=======================================================================
 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
@@ -608,6 +665,40 @@ LogWindow* SalomeApp_Application::logWindow()
   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 );
@@ -633,7 +724,10 @@ SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmTyp
     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() );
@@ -678,6 +772,8 @@ void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy )
     objectBrowser()->setRootObject( aRoot );
 
   activateModule( defaultModule() );
+
+  activateWindows();
 }
 
 void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
@@ -692,10 +788,10 @@ void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
     objectBrowser()->setRootObject( aRoot );
   }
 
-  activateWindows();
-
   activateModule( defaultModule() );
 
+  activateWindows();
+
   emit studyOpened();
 }
 
@@ -713,6 +809,35 @@ void SalomeApp_Application::onStudyClosed( SUIT_Study* )
   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, false);
+  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)";
@@ -744,11 +869,16 @@ QWidget* SalomeApp_Application::createWindow( const int flag )
     ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
     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 )
@@ -767,7 +897,7 @@ QWidget* SalomeApp_Application::createWindow( const int flag )
 
     logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
   }
-  
+
   return wid;
 }
 
@@ -775,6 +905,7 @@ void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const
 {
   aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
   aMap.insert( WT_PyConsole, Qt::DockBottom );
+  aMap.insert( WT_LogWindow, Qt::DockBottom );
 }
 
 void SalomeApp_Application::defaultViewManagers( QStringList& ) const
@@ -791,24 +922,26 @@ void SalomeApp_Application::afterCloseDoc()
 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()
@@ -924,7 +1057,6 @@ void SalomeApp_Application::loadWindowsGeometry()
   if ( !modName.isEmpty() )
     section += QString( "." ) + modName;
 
-
   dockMgr->loadGeometry( resourceMgr(), section, false );
   dockMgr->restoreGeometry();
 }