Salome HOME
updated copyright message
[modules/gui.git] / src / SALOME_SWIG / SALOMEGUI_Swig.cxx
index c6b25bdaddce4ba376b61fee700b01a343914b59..0a3de75fb8f85e6886042780850d58fd71c556fb 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -30,6 +30,7 @@
 #include <SUIT_Desktop.h>
 #include <SUIT_ViewWindow.h>
 #include <SUIT_ViewManager.h>
+#include <SUIT_ViewModel.h>
 #include <SUIT_DataObjectIterator.h>
 #include <CAM_DataModel.h>
 #include <LightApp_Application.h>
@@ -71,7 +72,7 @@
   This module provides an access to the SALOME GUI implementing set of functions
   which can be used from Python. This module is implemented using SWIG wrappings
   for some GUI functionality:
-  - getActiveStudyId(), getActiveStudyName() : get active study identifier and name
+  - getActiveStudyName() : get active study name
   - updateObjBrowser() : update contents of the Object Browser
   - SelectedCount() : get number of currently selected items
   - getSelected() : get entry of the speicified selected item
@@ -173,9 +174,8 @@ bool SALOMEGUI_Swig::hasDesktop()
 
 /*!
   \brief Update active study's Object Browser.
-  \param updateSelection this parameter is obsolete
 */
-void SALOMEGUI_Swig::updateObjBrowser( bool /*updateSelection*/ )
+void SALOMEGUI_Swig::updateObjBrowser()
 {
   class TEvent: public SALOME_Event
   {
@@ -192,30 +192,6 @@ void SALOMEGUI_Swig::updateObjBrowser( bool /*updateSelection*/ )
   ProcessVoidEvent( new TEvent() );
 }
 
-/*!
-  \fn int SALOMEGUI_Swig::getActiveStudyId()
-  \brief Get active study identifier
-  \return active study's ID or 0 if there is no active study
-*/
-
-class TGetActiveStudyIdEvent: public SALOME_Event
-{
-public:
-  typedef int TResult;
-  TResult myResult;
-  TGetActiveStudyIdEvent() : myResult( 0 ) {}
-  virtual void Execute()
-  {
-    if ( LightApp_Study* aStudy = getActiveStudy() ) {
-      myResult = aStudy->id();
-    }
-  }
-};
-int SALOMEGUI_Swig::getActiveStudyId()
-{
-  return ProcessEvent( new TGetActiveStudyIdEvent() );
-}
-
 /*!
   \fn const char* SALOMEGUI_Swig::getActiveStudyName()
   \brief Get active study name
@@ -333,7 +309,7 @@ const char* SALOMEGUI_Swig::getSelected( int index )
 {
   QStringList selected = ProcessEvent( new TGetSelectedEvent() );
   return index >= 0 && index < selected.count() ? 
-    strdup( selected[ index ].toLatin1().constData() ) : 0;
+    strdup( selected[ index ].toUtf8().constData() ) : 0;
 }
 
 /*!
@@ -354,7 +330,7 @@ void SALOMEGUI_Swig::AddIObject( const char* theEntry )
         LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr(); 
         if ( aStudy && aSelMgr ) {
           SALOME_ListIO anIOList;
-          anIOList.Append( new SALOME_InteractiveObject( myEntry.toLatin1(), "", "" ) );
+          anIOList.Append( new SALOME_InteractiveObject( myEntry.toUtf8(), "", "" ) );
           aSelMgr->setSelectedObjects( anIOList, true );
         }
       }
@@ -389,7 +365,7 @@ void SALOMEGUI_Swig::RemoveIObject( const char* theEntry )
           aSelMgr->selectedObjects( anIOList );
           SALOME_ListIteratorOfListIO anIter( anIOList );
           for( ; anIter.More(); anIter.Next() ) {
-            if ( anIter.Value()->isSame( new SALOME_InteractiveObject( myEntry.toLatin1(), "", "" ) ) ) { 
+            if ( anIter.Value()->isSame( new SALOME_InteractiveObject( myEntry.toUtf8(), "", "" ) ) ) { 
               anIOList.Remove( anIter );
               aSelMgr->setSelectedObjects( anIOList, true );
               return;
@@ -443,7 +419,7 @@ void SALOMEGUI_Swig::Display( const char* theEntry )
       LightApp_Application* anApp  = getApplication();
       LightApp_Study*       aStudy = getActiveStudy();
       if ( anApp && aStudy ) {
-       QString mname = anApp->moduleTitle( aStudy->componentDataType( myEntry ) );
+       QString mname = aStudy->componentDataType( myEntry );
        LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, true );
        if ( d ) {
          QStringList entries;
@@ -484,11 +460,11 @@ void SALOMEGUI_Swig::DisplayOnly( const char* theEntry )
        QStringList comps;
        aStudy->components( comps );
        foreach( QString comp, comps ) {
-         LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), false );
+         LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( comp, false );
          if ( d ) d->EraseAll( false, false, 0 );
        }
 
-       QString mname = anApp->moduleTitle( aStudy->componentDataType( myEntry ) );
+       QString mname = aStudy->componentDataType( myEntry );
        LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, true );
        if ( d ) {
          QStringList entries;
@@ -525,7 +501,7 @@ void SALOMEGUI_Swig::Erase( const char* theEntry )
       LightApp_Application* anApp  = getApplication();
       LightApp_Study*       aStudy = getActiveStudy();
       if ( anApp && aStudy ) {
-       QString mname = anApp->moduleTitle( aStudy->componentDataType( myEntry ) );
+       QString mname = aStudy->componentDataType( myEntry );
        LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, true );
        if ( d ) {
          QStringList entries;
@@ -563,7 +539,7 @@ void SALOMEGUI_Swig::DisplayAll()
        QStringList comps;
        aStudy->components( comps );
        foreach( QString comp, comps ) {
-         LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), true );
+         LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( comp, true );
          if ( d ) {
            QStringList entries;
            aStudy->children( aStudy->centry( comp ), entries );
@@ -594,7 +570,7 @@ void SALOMEGUI_Swig::EraseAll()
        QStringList comps;
        aStudy->components( comps );
        foreach( QString comp, comps ) {
-         LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), false );
+         LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( comp, false );
          if ( d ) d->EraseAll( false, false, 0 );
        }
       }
@@ -628,9 +604,9 @@ public:
       if (!viewMgr) return;
       SUIT_ViewWindow* window = viewMgr->getActiveView();
       if ( window ) {
-        SALOME_View* view = dynamic_cast<SALOME_View*>( window->getViewManager()->getActiveView() );
+        SALOME_View* view = dynamic_cast<SALOME_View*>( window->getViewManager()->getViewModel() );
         if ( view ) {
-          SALOME_Prs* aPrs = view->CreatePrs( myEntry.toLatin1() );
+          SALOME_Prs* aPrs = view->CreatePrs( myEntry.toUtf8() );
           myResult = !aPrs->IsNull();
         }
       }
@@ -658,7 +634,7 @@ void SALOMEGUI_Swig::UpdateView()
         if (!viewMgr) return;
         SUIT_ViewWindow* window = viewMgr->getActiveView();
         if ( window ) {
-          SALOME_View* view = dynamic_cast<SALOME_View*>( window->getViewManager()->getActiveView() );
+          SALOME_View* view = dynamic_cast<SALOME_View*>( window->getViewManager()->getViewModel() );
           if ( view )
             view->Repaint();
         }
@@ -706,6 +682,63 @@ void SALOMEGUI_Swig::FitAll()
   ProcessVoidEvent( new TEvent() );
 }
 
+void SALOMEGUI_Swig::FitSelection()
+{
+  class TEvent: public SALOME_Event
+  {
+  public:
+    TEvent() {}
+    virtual void Execute()
+    {
+      if ( LightApp_Application* anApp = getApplication() ) {
+        SUIT_ViewManager* viewMgr = anApp->activeViewManager();
+        if (!viewMgr) return;
+        SUIT_ViewWindow* window = viewMgr->getActiveView();
+        if ( window ) {
+#if !defined(DISABLE_SALOMEOBJECT) && !defined(DISABLE_VTKVIEWER)
+          if ( dynamic_cast<SVTK_ViewWindow*>( window ) )
+            (dynamic_cast<SVTK_ViewWindow*>( window ))->onFitSelection();
+#endif
+#if !defined(DISABLE_OCCVIEWER)
+          if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )
+            (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onFitSelection();
+#endif
+        }
+      }
+    }
+  };
+  ProcessVoidEvent( new TEvent() );
+}
+
+void SALOMEGUI_Swig::FitIObjects(const std::list<std::string>& entries)
+{
+  class TEvent: public SALOME_Event
+  {
+    const std::list<std::string>& myEntries;
+  public:
+    TEvent( const std::list<std::string>& objs ) : myEntries( objs ) {}
+    virtual void Execute()
+    {
+      if ( LightApp_Application* anApp = getApplication() ) {
+        SUIT_ViewManager* viewMgr = anApp->activeViewManager();
+        if (!viewMgr) return;
+        SUIT_ViewWindow* window = viewMgr->getActiveView();
+        if ( window ) {
+         SALOME_ListIO objects;
+         std::list<std::string>::const_iterator it;
+         for ( it = myEntries.begin(); it != myEntries.end(); ++it )
+           objects.Append( new SALOME_InteractiveObject( (*it).c_str(), "" ) );
+#if !defined(DISABLE_SALOMEOBJECT) && !defined(DISABLE_VTKVIEWER)
+          if ( dynamic_cast<SVTK_ViewWindow*>( window ) )
+            (dynamic_cast<SVTK_ViewWindow*>( window ))->onFitIObjects( objects );
+#endif
+        }
+      }
+    }
+  };
+  ProcessVoidEvent( new TEvent( entries ) );
+}
+
 /*!
   \brief Reset current view window to the default state.
 */
@@ -923,7 +956,7 @@ public:
        
 const char* SALOMEGUI_Swig::getViewParameters() {
   QString result = ProcessEvent( new TGetViewParameters() );
-  return result.isEmpty() ? 0 : strdup( result.toLatin1().constData() );  
+  return result.isEmpty() ? 0 : strdup( result.toUtf8().constData() );  
 }