Salome HOME
getViewManager() correction
[modules/gui.git] / src / SalomeApp / SalomeApp_Application.cxx
index e95d3b11fb0af6a6675e51ac1cde9146035e4cc1..401317f2dce29a6c5469eb03146201ac37559ed7 100644 (file)
 #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"
@@ -28,6 +32,7 @@
 #include <GLViewer_ViewManager.h>
 
 #include <Plot2d_ViewManager.h>
+#include <SPlot2d_ViewModel.h>
 
 #include <OCCViewer_ViewManager.h>
 #include <SOCC_ViewModel.h>
@@ -47,6 +52,7 @@
 
 #include <PythonConsole_PyConsole.h>
 
+#include <SUIT_FileDlg.h>
 #include <SUIT_MessageBox.h>
 #include <SUIT_ResourceMgr.h>
 #include <SUIT_ActionOperation.h>
@@ -105,7 +111,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();
 
@@ -250,7 +257,20 @@ 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 );
+
+  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() )
@@ -309,7 +329,7 @@ void SalomeApp_Application::createActions()
   }
 
   SUIT_Tools::simplifySeparators( modTBar );
-
+  
   // New window
 
   int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 );
@@ -461,6 +481,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 );
@@ -499,6 +533,15 @@ void SalomeApp_Application::updateCommandsStatus()
     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() );
 }
 
 //=======================================================================
@@ -633,19 +676,58 @@ 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 );
   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;
 }
 
@@ -658,7 +740,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() );
@@ -703,6 +788,8 @@ void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy )
     objectBrowser()->setRootObject( aRoot );
 
   activateModule( defaultModule() );
+
+  activateWindows();
 }
 
 void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
@@ -717,10 +804,10 @@ void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
     objectBrowser()->setRootObject( aRoot );
   }
 
-  activateWindows();
-
   activateModule( defaultModule() );
 
+  activateWindows();
+
   emit studyOpened();
 }
 
@@ -738,6 +825,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)";
@@ -769,11 +885,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 )
@@ -792,7 +913,7 @@ QWidget* SalomeApp_Application::createWindow( const int flag )
 
     logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
   }
-  
+
   return wid;
 }
 
@@ -987,3 +1108,22 @@ void SalomeApp_Application::activateWindows()
       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();
+}