Salome HOME
Debug of CMake build procedure
[modules/gui.git] / src / SALOME_SWIG / SALOMEGUI_Swig.cxx
index ea767e60b9d538fc91925bd1e5a296babcb55980..98d11c99de40a22756d70cbc1e91cc296dcdcdf5 100644 (file)
-//  SALOME SALOMEGUI : implementation of desktop and GUI kernel
+// Copyright (C) 2007-2014  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
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
-// 
-//  This library is free software; you can redistribute it and/or 
-//  modify it under the terms of the GNU Lesser General Public 
-//  License as published by the Free Software Foundation; either 
-//  version 2.1 of the License. 
-// 
-//  This library is distributed in the hope that it will be useful, 
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-//  Lesser General Public License for more details. 
-// 
-//  You should have received a copy of the GNU Lesser General Public 
-//  License along with this library; if not, write to the Free Software 
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
-// 
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
-//  File   : SALOMEGUI_Swig.cxx
-//  Author : Vadim SANDLER
-//  Module : SALOME
-//  $Header$
 
+//  SALOME SALOMEGUI : implementation of desktop and GUI kernel
+// File   : SALOMEGUI_Swig.cxx
+// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
+//
 #include "SALOMEGUI_Swig.hxx"
 
-#include "SUIT_Session.h"
-#include "SUIT_Desktop.h"
-#include "SUIT_DataObjectIterator.h"
-#include "OB_Browser.h"
-#include "SalomeApp_Application.h"
-#include "SalomeApp_Study.h"
-#include "SalomeApp_Module.h"
-#include "SalomeApp_DataObject.h"
-#include "LightApp_SelectionMgr.h"
-#include "SALOME_Prs.h"
-#include "SOCC_ViewModel.h"
-#include "SVTK_ViewModel.h"
+#include <SUIT_Session.h>
+#include <SUIT_Desktop.h>
+#include <SUIT_ViewWindow.h>
+#include <SUIT_ViewManager.h>
+#include <SUIT_DataObjectIterator.h>
+#include <CAM_DataModel.h>
+#include <LightApp_Application.h>
+#include <LightApp_Displayer.h>
+#include <LightApp_Study.h>
+#include <LightApp_Module.h>
+#include <LightApp_DataObject.h>
+#include <LightApp_SelectionMgr.h>
+#include <LightApp_DataOwner.h>
+#include <SALOME_Prs.h>
+#include <SALOME_Event.h>
+
+#ifndef DISABLE_SALOMEOBJECT
+  #include <SALOME_ListIO.hxx>
+  #include <SALOME_InteractiveObject.hxx>
+  #include <SALOME_ListIteratorOfListIO.hxx>
+#ifndef DISABLE_OCCVIEWER
+    #include <SOCC_ViewModel.h>
+    #include <SOCC_ViewWindow.h>
+#endif
+#ifndef DISABLE_VTKVIEWER
+    #include <SVTK_ViewModel.h>
+    #include <SVTK_ViewWindow.h>
+#endif
+#ifndef DISABLE_PLOT2DVIEWER
+    #include <SPlot2d_ViewWindow.h>
+#endif
+#endif
 
-#include "SALOME_Event.hxx"
-#include "SALOME_ListIO.hxx"
-#include "SALOME_InteractiveObject.hxx"
-#include "SALOME_ListIteratorOfListIO.hxx"
 
-//#include "utilities.h"
+/*!
+  \class SALOMEGUI_Swig
+  \brief Python interface module for SALOME GUI.
+
+  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
+  - updateObjBrowser() : update contents of the Object Browser
+  - SelectedCount() : get number of currently selected items
+  - getSelected() : get entry of the speicified selected item
+  - ClearIObjects() : clear selection
+  - Display(), DisplayOnly(), Erase() : display/erase objects
+  - etc.
 
-#include <SALOMEconfig.h>
-#include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
+  Instance of this class is created every time "import salome" line is typed 
+  - in IAPP embedded Python interpretor  (SALOME_Session_Server executable)
+  - in inline Python nodes in Supervisor (in SALOME_Container executable)
+  - in stand-alone Python console outside any executable
+
+  SALOME GUI (desktop and other objects) is only available in SALOME_Session_Server.
+  It means that it can not be accessed from the external Python console.
+
+  The usage in Python:
+  \code
+  import libSALOME_Swig
+  sg = libSALOME_Swig.SALOMEGUI_Swig()
+  if sg.hasDesktop():
+      selcount = sg.SelectedCount()
+      if selcount > 0:
+          sg.Erase( sg.getSelected( 0 ) )
+      pass
+  \endcode
+*/
 
-using namespace std;
+/*
+  --- INTERNAL COMMENTS SECTION ---
 
-/*!
-  asv : 3.12.04 : added checking for NULL GUI objects in almost all methods.
+  ASV : 03.12.04 : added checking for NULL GUI objects in almost all methods.
   In the scope of fixing bug PAL6869.
 
-  (PR : modify comments)
-  Instance of this class is created every time "import salome" line is typed 
-  - in IAPP embedded Python interpretor  (SALOME_Session_Server executable),
-  - in inline Python nodes in Supervisor (in SALOME_Container executable),
-  - in stand-alone Python console outside any executable.
-  SALOME GUI(desktop and other objects) is only available in SALOME_Session_Server
-
   VSR : 19.04.05 : Reimplemented for new SALOME GUI (SUIT-based)
   All methods are implemeted using Event mechanism.
   Display/Erase methods use SALOME_Prs/SALOME_View mechanism. It is currently
@@ -71,78 +108,80 @@ using namespace std;
 */
 
 /*!
-  getApplication()
-  Returns active application object [ static ]
+  \brief Get active application object
+  \internal
+  \return active application or 0 if there is no any
 */
-static SalomeApp_Application* getApplication() {
+static LightApp_Application* getApplication()
+{
   if ( SUIT_Session::session() )
-    return dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
-  return NULL;
+    return dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
+  return 0;
 }
 
 /*!
-  getActiveStudy()
-  Gets active study or 0 if there is no study opened [ static ]
+  \brief Get active study object
+  \internal
+  \return active study or 0 if there is no study opened
 */
-static SalomeApp_Study* getActiveStudy()
+static LightApp_Study* getActiveStudy()
 {
   if ( getApplication() )
-    return dynamic_cast<SalomeApp_Study*>( getApplication()->activeStudy() );
+    return dynamic_cast<LightApp_Study*>( getApplication()->activeStudy() );
   return 0;
 }
 
 /*!
-  SALOMEGUI_Swig::SALOMEGUI_Swig
-  Constructor
+  \brief Constructor.
 */
 SALOMEGUI_Swig::SALOMEGUI_Swig()
 {
 }
 
 /*!
-  SALOMEGUI_Swig::~SALOMEGUI_Swig
-  Destructor
+  \brief Destructor
 */
 SALOMEGUI_Swig::~SALOMEGUI_Swig()
 {
 }
 
 /*!
-  SALOMEGUI_Swig::hasDesktop
-  Returns TRUE if GUI is available.
+  \fn bool SALOMEGUI_Swig::hasDesktop()
+  \brief Check GUI availability.
+  \return \c true if GUI is available
 */
-class THasDesktopEvent: public SALOME_Event {
+
+class THasDesktopEvent: public SALOME_Event
+{
 public:
   typedef bool TResult;
   TResult myResult;
   THasDesktopEvent() : myResult( false ) {}
-  virtual void Execute() {
+  virtual void Execute()
+  {
     myResult = (bool)( getApplication() && getApplication()->desktop() );
   }
 };
-
-/*!
-  \return true if GUI is available.
-*/
 bool SALOMEGUI_Swig::hasDesktop()
 {
   return ProcessEvent( new THasDesktopEvent() );
 }
 
 /*!
-  SALOMEGUI_Swig::updateObjBrowser
-  Updates active study's Object Browser.
-  VSR: updateSelection parameter is currently not used. Will be implemented or removed lately.
+  \brief Update active study's Object Browser.
+  \param updateSelection this parameter is obsolete
 */
 void SALOMEGUI_Swig::updateObjBrowser( bool /*updateSelection*/ )
 {
-  class TEvent: public SALOME_Event {
+  class TEvent: public SALOME_Event
+  {
   public:
     TEvent() {}
-    virtual void Execute() {
-      if ( SalomeApp_Application* anApp = getApplication() ) {
-       anApp->updateObjectBrowser();
-       anApp->updateActions(); //SRN: added in order to update the toolbar
+    virtual void Execute()
+    {
+      if ( LightApp_Application* anApp = getApplication() ) {
+        anApp->updateObjectBrowser();
+        anApp->updateActions(); //SRN: added in order to update the toolbar
       }
     }
   };
@@ -150,200 +189,170 @@ void SALOMEGUI_Swig::updateObjBrowser( bool /*updateSelection*/ )
 }
 
 /*!
-  SALOMEGUI_Swig::getActiveStudyId
-  Returns active study's ID or 0 if there is no active study.
+  \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 {
+
+class TGetActiveStudyIdEvent: public SALOME_Event
+{
 public:
   typedef int TResult;
   TResult myResult;
   TGetActiveStudyIdEvent() : myResult( 0 ) {}
-  virtual void Execute() {
-    if ( SalomeApp_Study* aStudy = getActiveStudy() ) {
-      myResult = aStudy->studyDS()->StudyId();
+  virtual void Execute()
+  {
+    if ( LightApp_Study* aStudy = getActiveStudy() ) {
+      myResult = aStudy->id();
     }
   }
 };
-
-/*!
-  \return active study's ID or 0 if there is no active study.
-*/
 int SALOMEGUI_Swig::getActiveStudyId()
 {
   return ProcessEvent( new TGetActiveStudyIdEvent() );
 }
 
 /*!
-  SALOMEGUI_Swig::getActiveStudyName
-  Returns active study's name or NULL if there is no active study.
+  \fn const char* SALOMEGUI_Swig::getActiveStudyName()
+  \brief Get active study name
+  \return active study's name or null string if there is no active study
 */
-class TGetActiveStudyNameEvent: public SALOME_Event {
+
+class TGetActiveStudyNameEvent: public SALOME_Event
+{
 public:
-  typedef string TResult;
+  typedef std::string TResult;
   TResult myResult;
   TGetActiveStudyNameEvent() {}
-  virtual void Execute() {
-    if ( SalomeApp_Study* aStudy = getActiveStudy() ) {
-      myResult = aStudy->studyDS()->Name();
+  virtual void Execute()
+  {
+    if ( LightApp_Study* aStudy = getActiveStudy() ) {
+      myResult = aStudy->id();
     }
   }
 };
-
-/*!
-  \return active study's name or NULL if there is no active study.
-*/
 const char* SALOMEGUI_Swig::getActiveStudyName()
 {
-  string result = ProcessEvent( new TGetActiveStudyNameEvent() );
-  return result.empty() ? NULL : result.c_str();
+  std::string result = ProcessEvent( new TGetActiveStudyNameEvent() );
+  return result.empty() ? 0 : result.c_str();
 }
 
 /*!
-  SALOMEGUI_Swig::getComponentName
-  Returns the name of the component by its user name.
+  \fn const char* SALOMEGUI_Swig::getComponentName( const char* componentUserName )
+  \brief Get name of the component by its title (user name)
+  \param componentUserName component title (user name)
+  \return component name or null string if component title is invalid
 */
-class TGetModulCatalogEvent: public SALOME_Event {
-public:
-  typedef CORBA::Object_var TResult;
-  TResult myResult;
-  TGetModulCatalogEvent() : myResult(CORBA::Object::_nil()) {}
-  virtual void Execute() {
-    if (SalomeApp_Application* anApp = getApplication())
-      myResult = anApp->namingService()->Resolve("/Kernel/ModulCatalog");
-  }
-};
 
 /*!
-  \return the name of the component by its user name.
+  \fn const char* SALOMEGUI_Swig::getComponentUserName( const char* componentName )
+  \brief Get title (user name) of the component by its name
+  \param componentName component name
+  \return component title or null string if component name is invalid
 */
-const char* SALOMEGUI_Swig::getComponentName( const char* componentUserName )
+
+class TGetComponentNameEvent: public SALOME_Event
 {
-  CORBA::Object_var anObject = ProcessEvent(new TGetModulCatalogEvent());
-  if (!CORBA::is_nil(anObject)) {
-    SALOME_ModuleCatalog::ModuleCatalog_var aCatalogue =
-      SALOME_ModuleCatalog::ModuleCatalog::_narrow( anObject );
-    SALOME_ModuleCatalog::ListOfIAPP_Affich_var aModules = aCatalogue->GetComponentIconeList();
-    for ( unsigned int ind = 0; ind < aModules->length(); ind++ ) {
-      CORBA::String_var aModuleName     = aModules[ ind ].modulename;
-      CORBA::String_var aModuleUserName = aModules[ ind ].moduleusername;
-      if ( strcmp(componentUserName, aModuleUserName.in()) == 0 )
-        return aModuleName._retn();
+public:
+  typedef QString TResult;
+  TResult myResult;
+  QString myName;
+  bool    myIsUserName;
+  TGetComponentNameEvent( const QString& name, bool isUserName )
+    : myName( name ), myIsUserName( isUserName ) {}
+  virtual void Execute()
+  {
+    if ( LightApp_Application* app = getApplication() ) {
+      myResult = myIsUserName ? app->moduleTitle( myName ) : app->moduleName( myName );
     }
   }
-  return 0;
+};
+const char* SALOMEGUI_Swig::getComponentName( const char* componentUserName )
+{
+  QString result = ProcessEvent( new TGetComponentNameEvent( componentUserName, false ) );
+  return result.isEmpty() ? 0 : strdup( result.toLatin1().constData() );
 }
-
-/*!
-  SALOMEGUI_Swig::getComponentUserName
-  Returns the user name of the component by its name.
-*/
 const char* SALOMEGUI_Swig::getComponentUserName( const char* componentName )
 {
-  CORBA::Object_var anObject = ProcessEvent(new TGetModulCatalogEvent());
-  if (!CORBA::is_nil(anObject)) {
-    SALOME_ModuleCatalog::ModuleCatalog_var aCatalogue =
-      SALOME_ModuleCatalog::ModuleCatalog::_narrow( anObject );
-    SALOME_ModuleCatalog::ListOfIAPP_Affich_var aModules = aCatalogue->GetComponentIconeList();
-    for ( unsigned int ind = 0; ind < aModules->length(); ind++ ) {
-      CORBA::String_var aModuleName     = aModules[ ind ].modulename;
-      CORBA::String_var aModuleUserName = aModules[ ind ].moduleusername;
-      if ( strcmp(componentName, aModuleName.in()) == 0 )
-        return aModuleUserName._retn();
-    }
-  }
-  return 0;
+  QString result = ProcessEvent( new TGetComponentNameEvent( componentName, true ) );
+  return result.isEmpty() ? 0 : strdup( result.toLatin1().constData() );
 }
 
 /*!
-  SALOMEGUI_Swig::SelectedCount
-  Returns the number of selected objects.
+  \fn int SALOMEGUI_Swig::SelectedCount()
+  \brief Get number of selected items
+  \return number of selected items in the active study
 */
-class TSelectedCountEvent: public SALOME_Event {
-public:
-  typedef int TResult;
-  TResult myResult;
-  TSelectedCountEvent() : myResult( 0 ) {}
-  virtual void Execute() {
-    if ( SalomeApp_Application* anApp = getApplication() ) {
-      SalomeApp_Study*       aStudy  = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() ); // for sure!
-      LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr(); 
-      if ( aStudy && aSelMgr ) {
-       SALOME_ListIO anIOList;
-       aSelMgr->selectedObjects( anIOList );
-       myResult = anIOList.Extent();
-      }
-    }
-  }
-};
 
 /*!
-  \return the number of selected objects.
+  \fn const char* SALOMEGUI_Swig::getSelected( int index )
+  \brief Get entry of the specified selected item
+  \param index selected object index
+  \return selected object entry (null string if index is invalid)
 */
-int SALOMEGUI_Swig::SelectedCount()
-{
-  return ProcessEvent( new TSelectedCountEvent() );
-}
 
-/*!
-  SALOMEGUI_Swig::getSelected
-  Returns the selected object entry by the given index.
-*/
-class TGetSelectedEvent: public SALOME_Event {
+class TGetSelectedEvent: public SALOME_Event
+{
 public:
-  typedef QString TResult;
+  typedef QStringList TResult;
   TResult myResult;
-  int     myIndex;
-  TGetSelectedEvent( int theIndex ) : myIndex( theIndex ) {}
-  virtual void Execute() {
-    if ( SalomeApp_Application* anApp = getApplication() ) {
-      SalomeApp_Study*       aStudy  = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() ); // for sure!
+  TGetSelectedEvent() {}
+  virtual void Execute()
+  {
+    if ( LightApp_Application* anApp = getApplication() ) {
+      LightApp_Study* aStudy  = dynamic_cast<LightApp_Study*>( anApp->activeStudy() ); // for sure!
       LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr(); 
       if ( aStudy && aSelMgr ) {
-       SALOME_ListIO anIOList;
-       aSelMgr->selectedObjects( anIOList );
-       if ( myIndex < anIOList.Extent() ) {
-         int index = 0;
-         SALOME_ListIteratorOfListIO anIter( anIOList );
-         for( ; anIter.More(); anIter.Next(), index++ ) {
-           Handle(SALOME_InteractiveObject) anIO = anIter.Value();
-           if ( myIndex == index ) {
-             myResult = anIO->getEntry();
-             return;
-           }
-         }
-       }
+        SUIT_DataOwnerPtrList aList;
+        aSelMgr->selected( aList );
+
+        for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); 
+              itr != aList.end(); ++itr ) {
+          const LightApp_DataOwner* owner = 
+            dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
+          if( !owner )
+            continue;
+          QString entry = owner->entry();
+          if( !myResult.contains( entry ) )
+            myResult.append( entry );
+        }
       }
     }
   }
 };
-
-/*!
-  \return the selected object entry by the given index.
-*/
+int SALOMEGUI_Swig::SelectedCount()
+{
+  QStringList selected = ProcessEvent( new TGetSelectedEvent() );
+  return selected.count();
+}
 const char* SALOMEGUI_Swig::getSelected( int index )
 {
-  QString result = ProcessEvent( new TGetSelectedEvent( index ) );
-  return result.isEmpty() ? NULL : strdup(result.latin1());
+  QStringList selected = ProcessEvent( new TGetSelectedEvent() );
+  return index >= 0 && index < selected.count() ? 
+    strdup( selected[ index ].toLatin1().constData() ) : 0;
 }
 
 /*!
-  Adds an object with the given entry to the selection.
+  \brief Add an object to the current selection.
+  \param theEntry object entry
 */
 void SALOMEGUI_Swig::AddIObject( const char* theEntry )
 {
-  class TEvent: public SALOME_Event {
+  class TEvent: public SALOME_Event
+  {
   public:
     QString myEntry;
     TEvent( const char* theEntry ) : myEntry( theEntry ) {}
-    virtual void Execute() {
-      if ( SalomeApp_Application* anApp = getApplication() ) {
-       SalomeApp_Study*       aStudy  = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() ); // for sure!
-       LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr(); 
-       if ( aStudy && aSelMgr ) {
-         SALOME_ListIO anIOList;
-         anIOList.Append( new SALOME_InteractiveObject( myEntry, "", "" ) );
-         aSelMgr->setSelectedObjects( anIOList, true );
-       }
+    virtual void Execute()
+    {
+      if ( LightApp_Application* anApp = getApplication() ) {
+        LightApp_Study*       aStudy  = dynamic_cast<LightApp_Study*>( anApp->activeStudy() ); // for sure!
+        LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr(); 
+        if ( aStudy && aSelMgr ) {
+          SALOME_ListIO anIOList;
+          anIOList.Append( new SALOME_InteractiveObject( myEntry.toLatin1(), "", "" ) );
+          aSelMgr->setSelectedObjects( anIOList, true );
+        }
       }
     }
   };
@@ -351,35 +360,38 @@ void SALOMEGUI_Swig::AddIObject( const char* theEntry )
 }
 
 /*!
-  Removes the object with the given entry from the selection.
+  \brief Remove the object from the selection.
+  \param theEntry object entry
 */
 void SALOMEGUI_Swig::RemoveIObject( const char* theEntry )
 {
-  class TEvent: public SALOME_Event {
+  class TEvent: public SALOME_Event
+  {
   public:
     QString myEntry;
     TEvent( const char* theEntry ) : myEntry( theEntry ) {}
-    virtual void Execute() {
-      if ( SalomeApp_Application* anApp = getApplication() ) {
-       SalomeApp_Study*       aStudy  = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() ); // for sure!
-       LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr(); 
-       if ( aStudy && aSelMgr ) {
-         SALOME_ListIO anIOList;
-         // VSR: temporary solution, until LightApp_SelectionMgr::unsetSelectedObjects() method appears
-         // Lately this should be replaced by the following:
-         // anIOList.Append( new SALOME_InteractiveObject( myEntry, "", "" ) );
-         // aSelMgr->unsetSelectedObjects( anIOList );
-         ///////////////////////////////////////////////
-         aSelMgr->selectedObjects( anIOList );
-         SALOME_ListIteratorOfListIO anIter( anIOList );
-         for( ; anIter.More(); anIter.Next() ) {
-           if ( anIter.Value()->isSame( new SALOME_InteractiveObject( myEntry, "", "" ) ) ) { 
-             anIOList.Remove( anIter );
-             aSelMgr->setSelectedObjects( anIOList, true );
-             return;
-           }
-         }
-       }
+    virtual void Execute()
+    {
+      if ( LightApp_Application* anApp = getApplication() ) {
+        LightApp_Study* aStudy  = dynamic_cast<LightApp_Study*>( anApp->activeStudy() ); // for sure!
+        LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr(); 
+        if ( aStudy && aSelMgr ) {
+          SALOME_ListIO anIOList;
+          // VSR: temporary solution, until LightApp_SelectionMgr::unsetSelectedObjects() method appears
+          // Lately this should be replaced by the following:
+          // anIOList.Append( new SALOME_InteractiveObject( myEntry, "", "" ) );
+          // aSelMgr->unsetSelectedObjects( anIOList );
+          ///////////////////////////////////////////////
+          aSelMgr->selectedObjects( anIOList );
+          SALOME_ListIteratorOfListIO anIter( anIOList );
+          for( ; anIter.More(); anIter.Next() ) {
+            if ( anIter.Value()->isSame( new SALOME_InteractiveObject( myEntry.toLatin1(), "", "" ) ) ) { 
+              anIOList.Remove( anIter );
+              aSelMgr->setSelectedObjects( anIOList, true );
+              return;
+            }
+          }
+        }
       }
     }
   };
@@ -387,19 +399,21 @@ void SALOMEGUI_Swig::RemoveIObject( const char* theEntry )
 }
 
 /*!
-  Clears selection.
+  \brief Clear selection (unselect all objects).
 */
 void SALOMEGUI_Swig::ClearIObjects()
 {
-  class TEvent: public SALOME_Event {
+  class TEvent: public SALOME_Event
+  {
   public:
     TEvent() {}
-    virtual void Execute() {
-      if ( SalomeApp_Application* anApp = getApplication() ) {
-       SalomeApp_Study*       aStudy  = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() ); // for sure!
-       LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr(); 
-       if ( aStudy && aSelMgr )
-         aSelMgr->clearSelected();
+    virtual void Execute()
+    {
+      if ( LightApp_Application* anApp = getApplication() ) {
+        LightApp_Study* aStudy  = dynamic_cast<LightApp_Study*>( anApp->activeStudy() ); // for sure!
+        LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr(); 
+        if ( aStudy && aSelMgr )
+          aSelMgr->clearSelected();
       }
     }
   };
@@ -407,23 +421,34 @@ void SALOMEGUI_Swig::ClearIObjects()
 }
 
 /*!
-  Displays an object in the current view window
-  (the presentable object should be previously created and displayed in this viewer).
-  VSR: For the current moment implemented for OCC and VTK viewers only.
-*/             
+  \brief Display an object in the current view window.
+
+  The presentable object should be previously created and
+  displayed in this viewer.
+
+  \param theEntry object entry
+*/              
 void SALOMEGUI_Swig::Display( const char* theEntry )
 {
-  class TEvent: public SALOME_Event {
+  class TEvent: public SALOME_Event
+  {
     QString myEntry;
   public:
     TEvent( const char* theEntry ) : myEntry( theEntry ) {}
     virtual void Execute() {
-      if ( SalomeApp_Application* anApp = getApplication() ) {
-       SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
-       if ( window ) {
-         SALOME_View* view = dynamic_cast<SALOME_View*>( window->getViewManager()->getViewModel() );
-         if ( view )
-           view->Display( view->CreatePrs( myEntry ) );
+      LightApp_Application* anApp  = getApplication();
+      LightApp_Study*       aStudy = getActiveStudy();
+      if ( anApp && aStudy ) {
+       QString mname = anApp->moduleTitle( aStudy->componentDataType( myEntry ) );
+       LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, true );
+       if ( d ) {
+         QStringList entries;
+         if( aStudy->isComponent( myEntry ) )
+           aStudy->children( myEntry, entries );
+         else
+           entries.append( myEntry );
+         foreach( QString entry, entries )
+           d->Display( aStudy->referencedToEntry( entry ), false, 0 );
        }
       }
     }
@@ -432,25 +457,43 @@ void SALOMEGUI_Swig::Display( const char* theEntry )
 }
 
 /*!
-  Displays an object in the current view window and erases all other
-  (the presentable object should be previously created and displayed in this viewer).
-  VSR: For the current moment implemented for OCC and VTK viewers only.
+  \brief Displays an object in the current view window and 
+  erases all other ones.
+
+  The presentable object should be previously created and 
+  displayed in this viewer.
+
+  \param theEntry object entry
 */
 void SALOMEGUI_Swig::DisplayOnly( const char* theEntry )
 {
-  class TEvent: public SALOME_Event {
+  class TEvent: public SALOME_Event
+  {
     QString myEntry;
   public:
     TEvent( const char* theEntry ) : myEntry( theEntry ) {}
-    virtual void Execute() {
-      if ( SalomeApp_Application* anApp = getApplication() ) {
-       SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
-       if ( window ) {
-         SALOME_View* view = dynamic_cast<SALOME_View*>( window->getViewManager()->getViewModel() );
-         if ( view ) {
-           view->EraseAll( false );
-           view->Display( view->CreatePrs( myEntry ) );
-         }
+    virtual void Execute()
+    {
+      LightApp_Application* anApp  = getApplication();
+      LightApp_Study*       aStudy = getActiveStudy();
+      if ( anApp && aStudy ) {
+       QStringList comps;
+       aStudy->components( comps );
+       foreach( QString comp, comps ) {
+         LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), true );
+         if ( d ) d->EraseAll( false, false, 0 );
+       }
+
+       QString mname = anApp->moduleTitle( aStudy->componentDataType( myEntry ) );
+       LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, true );
+       if ( d ) {
+         QStringList entries;
+         if( aStudy->isComponent( myEntry ) )
+           aStudy->children( myEntry, entries );
+         else
+           entries.append( myEntry );
+         foreach( QString entry, entries )
+           d->Display( aStudy->referencedToEntry( entry ), false, 0 );
        }
       }
     }
@@ -459,23 +502,35 @@ void SALOMEGUI_Swig::DisplayOnly( const char* theEntry )
 }
 
 /*!
-  Erases an object in the current view window
-  (the presentable object should be previously created and displayed in this viewer).
-  VSR: For the current moment implemented for OCC and VTK viewers only.
-*/             
+  \brief Erase an object in the current view window.
+
+  The presentable object should be previously created and 
+  displayed in this viewer.
+
+  \param theEntry object entry
+*/              
 void SALOMEGUI_Swig::Erase( const char* theEntry )
 {
-  class TEvent: public SALOME_Event {
+  class TEvent: public SALOME_Event
+  {
     QString myEntry;
   public:
     TEvent( const char* theEntry ) : myEntry( theEntry ) {}
-    virtual void Execute() {
-      if ( SalomeApp_Application* anApp = getApplication() ) {
-       SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
-       if ( window ) {
-         SALOME_View* view = dynamic_cast<SALOME_View*>( window->getViewManager()->getViewModel() );
-         if ( view )
-           view->Erase( view->CreatePrs( myEntry ) );
+    virtual void Execute()
+    {
+      LightApp_Application* anApp  = getApplication();
+      LightApp_Study*       aStudy = getActiveStudy();
+      if ( anApp && aStudy ) {
+       QString mname = anApp->moduleTitle( aStudy->componentDataType( myEntry ) );
+       LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, true );
+       if ( d ) {
+         QStringList entries;
+         if( aStudy->isComponent( myEntry ) )
+           aStudy->children( myEntry, entries );
+         else
+           entries.append( myEntry );
+         foreach( QString entry, entries )
+           d->Erase( aStudy->referencedToEntry( entry ), false, false, 0 );
        }
       }
     }
@@ -484,28 +539,32 @@ void SALOMEGUI_Swig::Erase( const char* theEntry )
 }
 
 /*!
-  Displays all active module's child objects in the current view window
-  (the presentable objects should be previously created and displayed in this viewer).
-  VSR: For the current moment implemented for OCC and VTK viewers only.
+  \brief Display all active module's presentable 
+  child objects in the current view window.
+  
+  The presentable objects should be previously created and
+  displayed in this viewer.
 */
 void SALOMEGUI_Swig::DisplayAll()
 {
-  class TEvent: public SALOME_Event {
+  class TEvent: public SALOME_Event
+  {
   public:
     TEvent() {}
-    virtual void Execute() {
-      if ( SalomeApp_Application* anApp = getApplication() ) {
-       SalomeApp_Study*  study        = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() ); // for sure!
-       SUIT_ViewWindow*  window       = anApp->desktop()->activeWindow();
-       SalomeApp_Module* activeModule = dynamic_cast<SalomeApp_Module*>( anApp->activeModule() );
-       if ( study && window && activeModule ) {
-         SALOME_View* view = dynamic_cast<SALOME_View*>( window->getViewManager()->getViewModel() );
-         if ( view ) {
-           for ( SUIT_DataObjectIterator it( activeModule->dataModel()->root(), SUIT_DataObjectIterator::DepthLeft ); it.current(); ++it ) {
-             SalomeApp_DataObject* obj = dynamic_cast<SalomeApp_DataObject*>( it.current() );
-             if ( obj && !obj->entry().isEmpty() )
-               view->Display( view->CreatePrs( obj->entry() ) );
-           }
+    virtual void Execute()
+    {
+      LightApp_Application* anApp  = getApplication();
+      LightApp_Study*       aStudy = getActiveStudy();
+      if ( anApp && aStudy ) {
+       QStringList comps;
+       aStudy->components( comps );
+       foreach( QString comp, comps ) {
+         LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), true );
+         if ( d ) {
+           QStringList entries;
+           aStudy->children( aStudy->centry( comp ), entries );
+           foreach( QString entry, entries )
+             d->Display( aStudy->referencedToEntry( entry ), false, 0 );
          }
        }
       }
@@ -515,21 +574,24 @@ void SALOMEGUI_Swig::DisplayAll()
 }
 
 /*!
-  Erases all objects from the current view window
-  VSR: For the current moment implemented for OCC and VTK viewers only.
+  \brief Erase all objects from the current view window.
 */
 void SALOMEGUI_Swig::EraseAll()
 {
-  class TEvent: public SALOME_Event {
+  class TEvent: public SALOME_Event
+  {
   public:
     TEvent() {}
-    virtual void Execute() {
-      if ( SalomeApp_Application* anApp = getApplication() ) {
-       SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
-       if ( window ) {
-         SALOME_View* view = dynamic_cast<SALOME_View*>( window->getViewManager()->getViewModel() );
-         if ( view )
-           view->EraseAll( false );
+    virtual void Execute()
+    {
+      LightApp_Application* anApp  = getApplication();
+      LightApp_Study*       aStudy = getActiveStudy();
+      if ( anApp && aStudy ) {
+       QStringList comps;
+       aStudy->components( comps );
+       foreach( QString comp, comps ) {
+         LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), true );
+         if ( d ) d->EraseAll( false, false, 0 );
        }
       }
     }
@@ -538,34 +600,262 @@ void SALOMEGUI_Swig::EraseAll()
 }
 
 /*!
-  Returns TRUE if the object with given entry is in the current viewer.
+  \fn bool SALOMEGUI_Swig::IsInCurrentView( const char* theEntry )
+  \brief Check it the object is displayed in the current view window.
+
   VSR: For the current moment implemented for OCC and VTK viewers only.
+
+  \param theEntry object entry
+  \return \c true if the object with given entry is displayed 
+          in the current viewer
 */
-class TIsInViewerEvent: public SALOME_Event {
+
+class TIsInViewerEvent: public SALOME_Event
+{
   QString myEntry;
 public:
   typedef bool TResult;
   TResult myResult;
   TIsInViewerEvent( const char* theEntry ) : myEntry( theEntry ), myResult( false ) {}
-  virtual void Execute() {
-    if ( SalomeApp_Application* anApp = getApplication() ) {
+  virtual void Execute()
+  {
+    if ( LightApp_Application* anApp = getApplication() ) {
       SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
       if ( window ) {
-       SALOME_View* view = dynamic_cast<SALOME_View*>( window->getViewManager()->getViewModel() );
-       if ( view ) {
-         SALOME_Prs* aPrs = view->CreatePrs( myEntry );
-         myResult = aPrs->IsNull();
-       }
+        SALOME_View* view = dynamic_cast<SALOME_View*>( window->getViewManager()->getActiveView() );
+        if ( view ) {
+          SALOME_Prs* aPrs = view->CreatePrs( myEntry.toLatin1() );
+          myResult = !aPrs->IsNull();
+        }
       }
     }
   }
 };
+bool SALOMEGUI_Swig::IsInCurrentView( const char* theEntry )
+{
+  return ProcessEvent( new TIsInViewerEvent( theEntry ) );
+}
 
 /*!
-  \return TRUE if the object with given entry is in the current viewer.
-  VSR: For the current moment implemented for OCC and VTK viewers only.
+  \brief Update (repaint) current view window.
 */
-bool SALOMEGUI_Swig::IsInCurrentView( const char* theEntry )
+void SALOMEGUI_Swig::UpdateView()
 {
-  return ProcessEvent( new TIsInViewerEvent( theEntry ) );
+  class TEvent: public SALOME_Event
+  {
+  public:
+    TEvent() {}
+    virtual void Execute()
+    {
+      if ( LightApp_Application* anApp = getApplication() ) {
+        SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
+        if ( window ) {
+          SALOME_View* view = dynamic_cast<SALOME_View*>( window->getViewManager()->getActiveView() );
+          if ( view )
+            view->Repaint();
+        }
+      }
+    }
+  };
+  ProcessVoidEvent( new TEvent() );
+}
+
+/*!
+  \brief Fit current view window to display all its contents.
+*/
+void SALOMEGUI_Swig::FitAll()
+{
+  class TEvent: public SALOME_Event
+  {
+  public:
+    TEvent() {}
+    virtual void Execute()
+    {
+      if ( LightApp_Application* anApp = getApplication() ) {
+        SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
+        if ( window ) {
+#ifndef DISABLE_SALOMEOBJECT
+#ifndef DISABLE_VTKVIEWER
+          if ( dynamic_cast<SVTK_ViewWindow*>( window ) )
+            ( dynamic_cast<SVTK_ViewWindow*>( window ) )->onFitAll();
+#endif
+#ifndef DISABLE_PLOT2DVIEWER
+          if ( dynamic_cast<SPlot2d_ViewWindow*>( window ) )
+            ( dynamic_cast<SPlot2d_ViewWindow*>( window ) )->onFitAll();
+#endif
+#endif
+#ifndef DISABLE_OCCVIEWER
+          if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )
+            ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )->onFitAll();
+#endif
+        }
+      }
+    }
+  };
+  ProcessVoidEvent( new TEvent() );
+}
+
+/*!
+  \brief Reset current view window to the default state.
+*/
+void SALOMEGUI_Swig::ResetView()
+{
+  class TEvent: public SALOME_Event
+  {
+  public:
+    TEvent() {}
+    virtual void Execute()
+    {
+      if ( LightApp_Application* anApp = getApplication() ) {
+        SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
+        if ( window ) {
+#ifndef DISABLE_SALOMEOBJECT
+#ifndef DISABLE_VTKVIEWER
+          if ( dynamic_cast<SVTK_ViewWindow*>( window ) )
+            (dynamic_cast<SVTK_ViewWindow*>( window ))->onResetView();
+#endif
+#ifndef DISABLE_PLOT2DVIEWER
+          if ( dynamic_cast<SPlot2d_ViewWindow*>( window ) )
+            (dynamic_cast<SPlot2d_ViewWindow*>( window ))->onFitAll();
+          // VSR: there is no 'ResetView' functionality for Plot2d viewer,
+          // so we use 'FitAll' instead.
+#endif
+#endif
+#ifndef DISABLE_OCCVIEWER
+          if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )
+            (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onResetView();
+#endif
+        }
+      }
+    }
+  };
+  ProcessVoidEvent( new TEvent() );
+}
+
+/*!
+  \brief View operation type.
+  \internal
+*/
+enum {
+  __ViewTop,          //!< view top side
+  __ViewBottom,       //!< view bottom side
+  __ViewLeft,         //!< view left side
+  __ViewRight,        //!< view right side
+  __ViewFront,        //!< view front side
+  __ViewBack          //!< view back side
+};
+
+/*!
+  \brief Change the view of the current view window.
+  \internal
+  \param view view operation type
+*/
+static void setView( int view )
+{
+  class TEvent: public SALOME_Event
+  {
+  private:
+    int myView;
+  public:
+    TEvent( int view ) : myView( view ) {}
+    virtual void Execute()
+    {
+      if ( LightApp_Application* anApp = getApplication() ) {
+        SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
+        if ( window ) {
+#ifndef DISABLE_SALOMEOBJECT
+#ifndef DISABLE_VTKVIEWER
+          if ( dynamic_cast<SVTK_ViewWindow*>( window ) ) {
+            switch( myView ) {
+            case __ViewTop:
+              (dynamic_cast<SVTK_ViewWindow*>( window ))->onTopView(); break;
+            case __ViewBottom:
+              (dynamic_cast<SVTK_ViewWindow*>( window ))->onBottomView(); break;
+            case __ViewLeft:
+              (dynamic_cast<SVTK_ViewWindow*>( window ))->onLeftView(); break;
+            case __ViewRight:
+              (dynamic_cast<SVTK_ViewWindow*>( window ))->onRightView(); break;
+            case __ViewFront:
+              (dynamic_cast<SVTK_ViewWindow*>( window ))->onFrontView(); break;
+            case __ViewBack:
+              (dynamic_cast<SVTK_ViewWindow*>( window ))->onBackView(); break;
+            default:
+              break;
+            }
+          }
+#endif
+#endif
+#ifndef DISABLE_OCCVIEWER
+          if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) ) {
+            switch( myView ) {
+            case __ViewTop:
+              (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onTopView(); break;
+            case __ViewBottom:
+              (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onBottomView(); break;
+            case __ViewLeft:
+              (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onLeftView(); break;
+            case __ViewRight:
+              (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onRightView(); break;
+            case __ViewFront:
+              (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onFrontView(); break;
+            case __ViewBack:
+              (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onBackView(); break;
+            default:
+              break;
+            }
+          }
+#endif
+        }
+      }
+    }
+  };
+  ProcessVoidEvent( new TEvent( view ) );
+}
+
+/*!
+  \brief Switch current view window to show the top view.
+*/
+void SALOMEGUI_Swig::ViewTop()
+{
+  setView( __ViewTop );
+}
+
+/*!
+  \brief Switch current view window to show the bottom view
+*/
+void SALOMEGUI_Swig::ViewBottom()
+{
+  setView( __ViewBottom );
+}
+
+/*!
+  \brief Switch current view window to show the left view
+*/
+void SALOMEGUI_Swig::ViewLeft()
+{
+  setView( __ViewLeft );
+}
+
+/*!
+  \brief Switch current view window to show the right view
+*/
+void SALOMEGUI_Swig::ViewRight()
+{
+  setView( __ViewRight );
+}
+
+/*!
+  \brief Switch current view window to show the front view
+*/
+void SALOMEGUI_Swig::ViewFront()
+{
+  setView( __ViewFront );
+}
+
+/*!
+  \brief Switch current view window to show the back view
+*/
+void SALOMEGUI_Swig::ViewBack()
+{
+  setView( __ViewBack );
 }