Salome HOME
studyActivated() virtual method has been added
[modules/gui.git] / src / SalomeApp / SalomeApp_Application.cxx
index 6aae237c8e6eaef20f328df97e061b7207419cf0..8638fdc51777b071f773dc2f3da17605e15c1f36 100644 (file)
@@ -20,6 +20,7 @@
 #include "SalomeApp_Preferences.h"
 #include "SalomeApp_PreferencesDlg.h"
 #include "SalomeApp_StudyPropertiesDlg.h"
+#include "SalomeApp_CheckFileDlg.h"
 
 #include "SalomeApp_GLSelector.h"
 #include "SalomeApp_OBSelector.h"
@@ -127,7 +128,7 @@ myPrefs( 0 )
   setDesktop( desk );
 
   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
-  QPixmap aLogo = aResMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ) );
+  QPixmap aLogo = aResMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ), false );
 
   desktop()->setIcon( aLogo );
   desktop()->setDockableMenuBar( true );
@@ -265,10 +266,15 @@ void SalomeApp_Application::createActions()
 
   SUIT_Desktop* desk = desktop();
   SUIT_ResourceMgr* resMgr = resourceMgr();
-
+  
+  // Dump study
+  createAction( DumpStudyId, tr( "TOT_DESK_FILE_DUMP_STUDY" ), QIconSet(),
+               tr( "MEN_DESK_FILE_DUMP_STUDY" ), tr( "PRP_DESK_FILE_DUMP_STUDY" ),
+               0, desk, false, this, SLOT( onDumpStudy() ) );
+    
   // Load script
-  createAction( LoadScriptId, tr( "TOT_DESK_LOADSCRIPT" ), QIconSet(),
-               tr( "MEN_DESK_LOADSCRIPT" ), tr( "PRP_DESK_LOADSCRIPT" ),
+  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() ) );
 
   // Properties
@@ -287,12 +293,12 @@ void SalomeApp_Application::createActions()
   registerAction( MRUId, mru );
 
   // default icon for neutral point ('SALOME' module)
-  QPixmap defIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ) );
+  QPixmap defIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ), false );
   if ( defIcon.isNull() )
     defIcon = QPixmap( imageEmptyIcon );
 
   // default icon for any module
-  QPixmap modIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_MODULE_ICO" ) );
+  QPixmap modIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_MODULE_ICO" ), false );
   if ( modIcon.isNull() )
     modIcon = QPixmap( imageEmptyIcon );
 
@@ -330,7 +336,7 @@ void SalomeApp_Application::createActions()
 
     QString modName = moduleName( *it );
 
-    QPixmap icon = resMgr->loadPixmap( modName, iconName );
+    QPixmap icon = resMgr->loadPixmap( modName, iconName, false );
     if ( icon.isNull() )
       icon = modIcon;
 
@@ -367,12 +373,11 @@ void SalomeApp_Application::createActions()
   }
   connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) );
 
-
-
   int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
 
+  createMenu( DumpStudyId, fileMenu, 10, -1 );
   createMenu( separator(), fileMenu, -1, 15, -1 );
-  createMenu( LoadScriptId, fileMenu, 15, -1 );
+  createMenu( LoadScriptId, fileMenu, 10, -1 );
   createMenu( separator(), fileMenu, -1, 15, -1 );
   createMenu( PropertiesId, fileMenu, 10, -1 );
   createMenu( separator(), fileMenu, -1, 15, -1 );
@@ -398,7 +403,9 @@ void SalomeApp_Application::onModuleActivation( QAction* a )
   // Force user to create/open a study before module activation
   QMap<QString, QString> iconMap;
   moduleIconNames( iconMap );
-  QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ] );
+  QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ], false );
+  if ( icon.isNull() )
+    icon = resourceMgr()->loadPixmap( "SalomeApp", tr( "APP_MODULE_BIG_ICO" ), false ); // default icon for any module
 
   bool cancelled = false;
   while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
@@ -517,6 +524,22 @@ bool SalomeApp_Application::onOpenDoc( const QString& aName )
   return res;
 }
 
+bool SalomeApp_Application::onLoadDoc( const QString& aName )
+{
+  bool res = CAM_Application::onLoadDoc( aName );
+
+  /*jfa tmp:QAction* a = action( MRUId );
+  if ( a && a->inherits( "QtxMRUAction" ) )
+  {
+    QtxMRUAction* mru = (QtxMRUAction*)a;
+    if ( res )
+      mru->insert( aName );
+    else
+      mru->remove( aName );
+  }*/
+  return res;
+}
+
 void SalomeApp_Application::onSelection()
 {
   onSelectionChanged();
@@ -525,21 +548,58 @@ void SalomeApp_Application::onSelection()
     ((SalomeApp_Module*)activeModule())->selectionChanged();
 }
 
-void SalomeApp_Application::onSelectionChanged()
+void SalomeApp_Application::onCopy() 
 {
- /*
-   SalomeApp_Module* module = dynamic_cast<SalomeApp_Module*>(activeModule());
-   if(module == NULL) return;
-   
-   QString ior = module->engineIOR();
-   if(ior.length() < 5) return; //Not a real CORBA IOR
-   CORBA::Object_var obj = orb()->string_to_object(ior.latin1());
-   if(CORBA::is_nil(obj)) return;
-   
-   SALOMEDS::Driver_var engine = SALOMEDS::Driver::_narrow(obj);
-   if(CORBA::is_nil(engine)) return;
-*/
+  SALOME_ListIO list;
+  SalomeApp_SelectionMgr* mgr = selectionMgr();
+  mgr->selectedObjects(list);
+  
+  SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
+  if(study == NULL) return;
+  
+  _PTR(Study) stdDS = study->studyDS();
+  if(!stdDS) return;
+
+  SALOME_ListIteratorOfListIO it( list ); 
+  if(it.More())
+    {
+      _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
+      try {
+       studyMgr()->Copy(so);
+       onSelectionChanged();
+      }
+      catch(...) {
+      }
+    }
+}
 
+void SalomeApp_Application::onPaste() 
+{
+  SALOME_ListIO list;
+  SalomeApp_SelectionMgr* mgr = selectionMgr();
+  mgr->selectedObjects(list);
+  
+  SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
+  if(study == NULL) return;
+  
+  _PTR(Study) stdDS = study->studyDS();
+  if(!stdDS) return;
+  
+  SALOME_ListIteratorOfListIO it( list ); 
+  if(it.More())
+    {
+      _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
+      try {
+       studyMgr()->Paste(so);
+       updateObjectBrowser( true );
+      }
+      catch(...) {
+      }
+    }
+}
+
+void SalomeApp_Application::onSelectionChanged()
+{
    SALOME_ListIO list;
    SalomeApp_SelectionMgr* mgr = selectionMgr();
    mgr->selectedObjects(list);
@@ -551,37 +611,62 @@ void SalomeApp_Application::onSelectionChanged()
    if(!stdDS) return;
    
    QAction* qaction;  
-   
-   for ( SALOME_ListIteratorOfListIO it( list ); it.More(); it.Next() )
+
+   SALOME_ListIteratorOfListIO it( list ); 
+   if(it.More() && list.Extent() == 1)
    {
       _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
-      qaction = action(EditCutId);
-      if( studyMgr()->CanCopy(so) ) {
-        qaction->setEnabled(true);
-       qaction = action(EditCopyId); 
-       qaction->setEnabled(true);  
-      }
-      else {
-        qaction->setEnabled(false);
-       qaction = action(EditCopyId);
-       qaction->setEnabled(false);         
-      }
+
+      qaction = action(EditCopyId); 
+      if(studyMgr()->CanCopy(so) ) qaction->setEnabled(true);  
+      else qaction->setEnabled(false);         
+     
       qaction = action(EditPasteId);
       if( studyMgr()->CanPaste(so) ) qaction->setEnabled(true);
       else qaction->setEnabled(false);
    } 
+   else {
+     qaction = action(EditCopyId); 
+     qaction->setEnabled(false); 
+     qaction = action(EditPasteId);
+     qaction->setEnabled(false);
+   }
 }              
  
-
 void SalomeApp_Application::onRefresh()
 {
-  for ( ModuleListIterator it = modules(); it.current(); ++it )
-  {    
-    CAM_DataModel* camDM = it.current()->dataModel();
-    if ( camDM && camDM->inherits( "SalomeApp_DataModel" ) )
-      ((SalomeApp_DataModel*)camDM)->update();
-  }
-  objectBrowser()->updateTree();
+  updateObjectBrowser( true );
+}
+
+void SalomeApp_Application::onOpenWith()
+{
+  QApplication::setOverrideCursor( Qt::waitCursor );
+  SALOME_ListIO aList;
+  SalomeApp_SelectionMgr* mgr = selectionMgr();
+  mgr->selectedObjects(aList);
+  if (aList.Extent() != 1)
+    {
+      QApplication::restoreOverrideCursor();
+      return;
+    }
+  Handle(SALOME_InteractiveObject) aIObj = aList.First();
+  QString aModuleName(aIObj->getComponentDataType());
+  QString aModuleTitle = moduleTitle(aModuleName);
+  activateModule(aModuleTitle);
+  QApplication::restoreOverrideCursor();
+}
+
+bool SalomeApp_Application::useStudy(const QString& theName)
+{
+  createEmptyStudy();
+  SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(activeStudy());
+  bool res = false;
+  if (aStudy)
+    res = aStudy->loadDocument( theName );
+  updateDesktopTitle();
+  updateCommandsStatus();
+  return res;
 }
 
 void SalomeApp_Application::setActiveStudy( SUIT_Study* study )
@@ -623,8 +708,13 @@ void SalomeApp_Application::updateCommandsStatus()
       a->setEnabled( activeStudy() );
   }
 
+  // Dump study menu
+  QAction* a = action( DumpStudyId );
+  if ( a )
+    a->setEnabled( activeStudy() );
+
   // Load script menu
-  QAction* a = action( LoadScriptId );
+  a = action( LoadScriptId );
   if ( a )
     a->setEnabled( activeStudy() );
   
@@ -632,8 +722,6 @@ void SalomeApp_Application::updateCommandsStatus()
   if( a )
     a->setEnabled( activeStudy() );
     
-  a = action(EditCutId);
-  a->setEnabled(false);        
   a = action(EditCopyId);
   a->setEnabled(false);              
   a = action(EditPasteId);
@@ -828,6 +916,11 @@ SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmTyp
     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 );
   }
@@ -836,6 +929,7 @@ SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmTyp
     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);
   }
 
@@ -908,6 +1002,30 @@ void SalomeApp_Application::onStudyClosed( SUIT_Study* )
   saveWindowsGeometry();
 }
 
+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 );
+  }
+}
+
 void SalomeApp_Application::onLoadScript( )
 {
   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
@@ -926,7 +1044,7 @@ void SalomeApp_Application::onLoadScript( )
   filtersList.append(tr("PYTHON_FILES_FILTER"));
   filtersList.append(tr("ALL_FILES_FILTER"));
 
-  QString aFile = SUIT_FileDlg::getFileName( desktop(), "", filtersList, tr( "TOT_DESK_LOADSCRIPT" ), true, true );
+  QString aFile = SUIT_FileDlg::getFileName( desktop(), "", filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true );
 
   if ( !aFile.isEmpty() )
   {
@@ -1140,15 +1258,32 @@ void SalomeApp_Application::createPreferences( SalomeApp_Preferences* pref )
   pref->setProperty( occGroup, "columns", 1 );
   pref->setProperty( vtkGroup, "columns", 1 );
 
-  pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
-                      SalomeApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
+  int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
+                                  SalomeApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
                       SalomeApp_Preferences::Color, "OCCViewer", "background" );
 
-  pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
-                      SalomeApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
+  pref->setProperty( occTS, "min", 1 );
+  pref->setProperty( occTS, "max", 150 );
+
+  int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
+                                 SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
+  int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
+                                 SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
+
+  pref->setProperty( isoU, "min", 0 );
+  pref->setProperty( isoU, "max", 100000 );
+
+  pref->setProperty( isoV, "min", 0 );
+  pref->setProperty( isoV, "max", 100000 );
+
+  int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
+                                  SalomeApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
                       SalomeApp_Preferences::Color, "VTKViewer", "background" );
+
+  pref->setProperty( vtkTS, "min", 1 );
+  pref->setProperty( vtkTS, "max", 150 );
 }
 
 void SalomeApp_Application::preferencesChanged( const QString& sec, const QString& param )
@@ -1173,6 +1308,34 @@ void SalomeApp_Application::preferencesChanged( const QString& sec, const QStrin
       occVM->getAISContext()->UpdateCurrentViewer();
     }
   }
+
+  if ( sec == QString( "VTKViewer" ) && param == QString( "trihedron_size" ) )
+  {
+    int sz = resMgr->integerValue( sec, param, -1 );
+    QPtrList<SUIT_ViewManager> lst;
+    viewManagers( SVTK_Viewer::Type(), lst );
+    for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
+    {
+      SUIT_ViewModel* vm = it.current()->getViewModel();
+      if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
+       continue;
+
+      SVTK_Viewer* vtkVM = (SVTK_Viewer*)vm;
+      vtkVM->setTrihedronSize( sz );
+      vtkVM->Repaint();
+    }
+  }
+  
+  if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
+  {
+    QPtrList<SUIT_ViewManager> lst;
+    viewManagers( OCCViewer_Viewer::Type(), lst );
+    int u = resMgr->integerValue( sec, "iso_number_u" );
+    int v = resMgr->integerValue( sec, "iso_number_v" );
+    for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
+      ((OCCViewer_Viewer*)it.current())->setIsos( u, v );
+  }
+  
 }
 
 void SalomeApp_Application::afterCloseDoc()
@@ -1391,10 +1554,60 @@ QString SalomeApp_Application::getDirectory( const QString& initial, const QStri
   return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
 }
 
+QStringList SalomeApp_Application::getOpenFileNames( const QString& initial, const QString& filters, 
+                                                    const QString& caption, QWidget* parent )
+{
+  if ( !parent )
+    parent = desktop();
+  QStringList fls = QStringList::split( ";;", filters, false );
+  return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
+}
+
 void SalomeApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
 {
   CAM_Application::contextMenuPopup( type, thePopup, title );
   thePopup->insertSeparator();
   thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
+  
+  // "Activate module" item should appear only if it's necessary
+  OB_Browser* ob = objectBrowser();
+  if ( !ob || type != ob->popupClientType() )
+    return;
+  SALOME_ListIO aList;
+  SalomeApp_SelectionMgr* mgr = selectionMgr();
+  mgr->selectedObjects(aList);
+  if (aList.Extent() != 1)
+    return;
+  Handle(SALOME_InteractiveObject) aIObj = aList.First();
+  QString aModuleName(aIObj->getComponentDataType());
+  QString aModuleTitle = moduleTitle(aModuleName);
+  CAM_Module* currentModule = activeModule();
+  if (currentModule && currentModule->moduleName() == aModuleTitle)
+    return;
+  thePopup->insertItem( tr( "MEN_OPENWITH" ), this, SLOT( onOpenWith() ) );
+}
+
+void SalomeApp_Application::updateObjectBrowser( const bool updateModels )
+{
+  if ( updateModels ) 
+  {
+    for ( ModuleListIterator it = modules(); it.current(); ++it )
+    {    
+      CAM_DataModel* camDM = it.current()->dataModel();
+      if ( camDM && camDM->inherits( "SalomeApp_DataModel" ) )
+        ((SalomeApp_DataModel*)camDM)->update();
+    }
+  }
+  if ( objectBrowser() )
+    objectBrowser()->updateTree();
 }
 
+
+//************************************************************
+void SalomeApp_Application::onDesktopActivated()
+{
+  CAM_Application::onDesktopActivated();
+  SalomeApp_Module* aModule = dynamic_cast<SalomeApp_Module*>(activeModule());
+  if(aModule)
+    aModule->studyActivated();
+}