Salome HOME
Unicode support: correct handling of unicode on GUI level
[modules/gui.git] / src / SALOME_SWIG / SALOMEGUI_Swig.cxx
index d1ee880c200091ac3a2f669aca882d4c39d36cee..1209276473cbefb0f2bfdfa543be7c429b2613dd 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -62,6 +62,7 @@
 #endif
 #endif
 
+#include <utilities.h>
 
 /*!
   \class SALOMEGUI_Swig
@@ -70,7 +71,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
@@ -172,9 +173,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
   {
@@ -191,30 +191,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
@@ -332,7 +308,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;
 }
 
 /*!
@@ -353,7 +329,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 );
         }
       }
@@ -388,7 +364,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;
@@ -483,7 +459,7 @@ 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 ), true );
+         LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), false );
          if ( d ) d->EraseAll( false, false, 0 );
        }
 
@@ -593,7 +569,7 @@ void SALOMEGUI_Swig::EraseAll()
        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( anApp->moduleTitle( comp ), false );
          if ( d ) d->EraseAll( false, false, 0 );
        }
       }
@@ -623,11 +599,13 @@ public:
   virtual void Execute()
   {
     if ( LightApp_Application* anApp = getApplication() ) {
-      SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
+      SUIT_ViewManager* viewMgr = anApp->activeViewManager();
+      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();
         }
       }
@@ -651,9 +629,11 @@ void SALOMEGUI_Swig::UpdateView()
     virtual void Execute()
     {
       if ( LightApp_Application* anApp = getApplication() ) {
-        SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
+        SUIT_ViewManager* viewMgr = anApp->activeViewManager();
+        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();
         }
@@ -668,6 +648,7 @@ void SALOMEGUI_Swig::UpdateView()
 */
 void SALOMEGUI_Swig::FitAll()
 {
+  MESSAGE("FitAll");
   class TEvent: public SALOME_Event
   {
   public:
@@ -675,7 +656,9 @@ void SALOMEGUI_Swig::FitAll()
     virtual void Execute()
     {
       if ( LightApp_Application* anApp = getApplication() ) {
-        SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
+        SUIT_ViewManager* viewMgr = anApp->activeViewManager();
+        if (!viewMgr) return;
+        SUIT_ViewWindow* window = viewMgr->getActiveView();
         if ( window ) {
 #ifndef DISABLE_SALOMEOBJECT
 #ifndef DISABLE_VTKVIEWER
@@ -710,7 +693,9 @@ void SALOMEGUI_Swig::ResetView()
     virtual void Execute()
     {
       if ( LightApp_Application* anApp = getApplication() ) {
-        SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
+        SUIT_ViewManager* viewMgr = anApp->activeViewManager();
+        if (!viewMgr) return;
+        SUIT_ViewWindow* window = viewMgr->getActiveView();
         if ( window ) {
 #ifndef DISABLE_SALOMEOBJECT
 #ifndef DISABLE_VTKVIEWER
@@ -764,7 +749,9 @@ static void setView( int view )
     virtual void Execute()
     {
       if ( LightApp_Application* anApp = getApplication() ) {
-        SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
+           SUIT_ViewManager* viewMgr = anApp->activeViewManager();
+           if (!viewMgr) return;
+           SUIT_ViewWindow* window = viewMgr->getActiveView();
         if ( window ) {
 #ifndef DISABLE_SALOMEOBJECT
 #ifndef DISABLE_VTKVIEWER
@@ -880,7 +867,9 @@ public:
   TGetViewParameters() : myResult( "" ) {}
   virtual void Execute() {  
     if ( LightApp_Application* anApp = getApplication() ) {
-      if ( SUIT_ViewWindow* window = anApp->desktop()->activeWindow() ) {
+         SUIT_ViewManager* viewMgr = anApp->activeViewManager();
+         if (!viewMgr) return;
+         if ( SUIT_ViewWindow* window = viewMgr->getActiveView() ) {
 #ifndef DISABLE_VTKVIEWER
        if ( SVTK_ViewWindow* svtk = dynamic_cast<SVTK_ViewWindow*>( window ) ) {         
          if ( vtkRenderer* ren = svtk->getRenderer()) {                    
@@ -909,7 +898,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() );  
 }
 
 
@@ -944,7 +933,9 @@ static void setViewParameter( int parameter, QList<double>& values ) {
 
     virtual void Execute() {
       if ( LightApp_Application* anApp = getApplication() ) {
-       if ( SUIT_ViewWindow* window = anApp->desktop()->activeWindow() ) {
+         SUIT_ViewManager* viewMgr = anApp->activeViewManager();
+         if (!viewMgr) return;
+         if ( SUIT_ViewWindow* window = viewMgr->getActiveView() ) {
 #ifndef DISABLE_VTKVIEWER
          if ( SVTK_ViewWindow* svtk = dynamic_cast<SVTK_ViewWindow*>( window ) ) {       
            if ( vtkRenderer* ren = svtk->getRenderer()) {