Salome HOME
updated copyright message
[modules/gui.git] / src / SOCC / SOCC_ViewModel.cxx
old mode 100755 (executable)
new mode 100644 (file)
index c21735b..55aec6c
@@ -1,65 +1,79 @@
+// Copyright (C) 2007-2023  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.
+//
+// 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
+//
+
 #include "SOCC_ViewModel.h"
 
 #include "SOCC_Prs.h"
+#include "SOCC_ViewWindow.h"
 
 #include "SUIT_Session.h"
-#include "SUIT_Application.h"
+#include "SUIT_ResourceMgr.h"
+//#include "SUIT_Application.h"
 
-#include "ToolsGUI.h"
+//#include "ToolsGUI.h"
 
-#include <SALOMEconfig.h>
-#include CORBA_CLIENT_HEADER(SALOMEDS)
+// Temporarily commented to avoid awful dependecy on SALOMEDS
+// TODO: better mechanism of storing display/erse status in a study
+// should be provided...
+//#include <SALOMEconfig.h>
+//#include CORBA_CLIENT_HEADER(SALOMEDS)
 
 #include <AIS_ListIteratorOfListOfInteractive.hxx>
-#include <Visual3d_View.hxx>
 
 #include <SALOME_AISShape.hxx>
 #include <SALOME_AISObject.hxx>
+#include <SALOME_InteractiveObject.hxx>
+#include <SALOME_ListIO.hxx>
 
-#include <Utils_ORB_INIT.hxx>
-#include <Utils_SINGLETON.hxx>
-#include <SALOME_ModuleCatalog_impl.hxx>
-#include <SALOME_NamingService.hxx>
-
-#include "SALOMEDSClient.hxx"
-#include "SALOMEDS_StudyManager.hxx"
-
-// in order NOT TO link with SalomeApp, here the code returns SALOMEDS_Study.
-// SalomeApp_Study::studyDS() does it as well, but -- here it is retrieved from 
-// SALOMEDS::StudyManager - no linkage with SalomeApp. 
+#include <AIS_TypeOfIso.hxx>
+#include <Precision.hxx>
 
-static _PTR(Study) getStudyDS() 
-{
-  SALOMEDSClient_Study* aStudy = NULL;
-  _PTR(StudyManager) aMgr( new SALOMEDS_StudyManager() );
-
-  // get id of SUIT_Study, if it's a SalomeApp_Study, it will return
-  //    id of its underlying SALOMEDS::Study
-  SUIT_Application* app = SUIT_Session::session()->activeApplication();
-  if ( !app )  return _PTR(Study)(aStudy); 
-  SUIT_Study* stud = app->activeStudy();
-  if ( !stud ) return _PTR(Study)(aStudy);  
-  const int id = stud->id(); // virtual method, must return SALOMEDS_Study id
-  // get SALOMEDS_Study with this id from StudyMgr
-  return aMgr->GetStudyByID( id );
-}
+#include <algorithm>
 
+/*!
+  Constructor
+  \param DisplayTrihedron - is trihedron displayed
+*/
 SOCC_Viewer::SOCC_Viewer( bool DisplayTrihedron )
 : OCCViewer_Viewer( DisplayTrihedron )
 {
 }
 
+/*!
+  Destructor
+*/
 SOCC_Viewer::~SOCC_Viewer()
 {
 }
 
+/*!
+  Hilights/unhilights object in viewer
+  \param obj - object to be updated
+  \param hilight - if it is true, object will be hilighted, otherwise it will be unhilighted
+  \param update - update current viewer
+*/
 bool SOCC_Viewer::highlight( const Handle(SALOME_InteractiveObject)& obj,
                              bool hilight, bool upd )
 {
-  bool isInLocal = getAISContext()->HasOpenedContext();
-  //SUIT_Study* ActiveStudy = SUIT_Application::getDesktop()->getActiveStudy();
-  //SALOME_Selection* Sel = SALOME_Selection::Selection( ActiveStudy->getSelection() );
-
   AIS_ListOfInteractive List;
   getAISContext()->DisplayedObjects(List);
   
@@ -71,19 +85,8 @@ bool SOCC_Viewer::highlight( const Handle(SALOME_InteractiveObject)& obj,
 
     if ( !anObj.IsNull() && anObj->hasEntry() && anObj->isSame( obj ) )
     {
-      if ( !isInLocal )
-          OCCViewer_Viewer::highlight( ite.Value(), hilight, false );
-      // highlight subshapes only when local selection is active
-      else
-      {
-        /*if ( ite.Value()->IsKind( STANDARD_TYPE( SALOME_AISShape ) ) )
-        {
-          Handle(SALOME_AISShape) aSh = Handle(SALOME_AISShape)::DownCast( ite.Value() );
-          TColStd_IndexedMapOfInteger MapIndex;
-          Sel->GetIndex( IObject, MapIndex );
-          aSh->highlightSubShapes( MapIndex, highlight );
-        }*/
-      }
+      OCCViewer_Viewer::highlight( ite.Value(), hilight, false );
+      // highlight sub-shapes only when local selection is active
       break;
     }
   }
@@ -94,18 +97,16 @@ bool SOCC_Viewer::highlight( const Handle(SALOME_InteractiveObject)& obj,
   return false;
 }
 
+/*!
+  \return true if object is in viewer or in collector
+  \param obj - object to be checked
+  \param onlyInViewer - search object only in viewer (so object must be displayed)
+*/
 bool SOCC_Viewer::isInViewer( const Handle(SALOME_InteractiveObject)& obj,
-                              bool onlyInViewer )
+                              bool /*onlyInViewer*/ )
 {
   AIS_ListOfInteractive List;
   getAISContext()->DisplayedObjects(List);
-
-  if( !onlyInViewer ) {
-    AIS_ListOfInteractive List1;
-    getAISContext()->ObjectsInCollector(List1);
-    List.Append(List1);
-  }
-
   AIS_ListIteratorOfListOfInteractive ite(List);
   for ( ; ite.More(); ite.Next() )
   {
@@ -118,84 +119,113 @@ bool SOCC_Viewer::isInViewer( const Handle(SALOME_InteractiveObject)& obj,
   return false;
 }
 
+/*!
+  \return true if object is displayed in viewer
+  \param obj - object to be checked
+*/
 bool SOCC_Viewer::isVisible( const Handle(SALOME_InteractiveObject)& obj )
 {
-  AIS_ListOfInteractive List;
-  getAISContext()->DisplayedObjects( List );
 
-  AIS_ListIteratorOfListOfInteractive ite( List );
-  for ( ; ite.More(); ite.Next() )
-  {
-    Handle(SALOME_InteractiveObject) anObj =
-      Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );
-
-    if ( !anObj.IsNull() && anObj->hasEntry() && anObj->isSame( obj ) )
-      return getAISContext()->IsDisplayed( ite.Value() );
+  std::map< std::string , std::vector<Handle(AIS_InteractiveObject)> >::iterator it=entry2aisobjects.find(obj->getEntry());
+  if(it != entry2aisobjects.end())
+    {
+      // get context
+      Handle (AIS_InteractiveContext) ic = getAISContext();
+      std::vector<Handle(AIS_InteractiveObject)>& List = it->second;
+      for( unsigned int ind = 0; ind < List.size(); ind++ )
+        {
+          Handle(AIS_InteractiveObject) anAIS=List[ind];
+          if(ic->IsDisplayed(anAIS))
+            return true;
+        }
   }
   
   return false;
 }
 
+/*!
+  Sets color of object
+  \param obj - object to be updated
+  \param color - new color
+  \param update - update current viewer
+*/
 void SOCC_Viewer::setColor( const Handle(SALOME_InteractiveObject)& obj,
                             const QColor& color, bool update )
 {
-  AIS_ListOfInteractive List;
-  getAISContext()->DisplayedObjects(List);
-  
-  AIS_ListIteratorOfListOfInteractive ite(List);
-  for ( ; ite.More(); ite.Next() )
-  {
-    Handle(SALOME_InteractiveObject) anObj =
-        Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );
+  if(obj.IsNull() || !obj->hasEntry() )
+    return;
 
-    if ( !anObj.IsNull() && anObj->hasEntry() && anObj->isSame( obj ) )
+  if(entry2aisobjects.count(obj->getEntry())>0)
     {
-      OCCViewer_Viewer::setColor( ite.Value(), color, update );
-      return;
+      // get context
+      Handle (AIS_InteractiveContext) ic = getAISContext();
+      std::vector<Handle(AIS_InteractiveObject)>& List = entry2aisobjects[obj->getEntry()];
+      for( unsigned int ind = 0; ind < List.size(); ind++ )
+        {
+          Handle(AIS_InteractiveObject) anAIS=List[ind];
+          if( !anAIS.IsNull() && ic->IsDisplayed(anAIS))
+            OCCViewer_Viewer::setColor( anAIS, color, update );
+        }
     }
-  }
 }
 
+/*!
+  Changes display mode of object
+  \param obj - object to be processed
+  \param mode - new display mode
+  \param update - update current viewer
+*/
 void SOCC_Viewer::switchRepresentation( const Handle(SALOME_InteractiveObject)& obj,
                                         int mode, bool update )
 {
-  AIS_ListOfInteractive List;
-  getAISContext()->DisplayedObjects(List);
-  
-  AIS_ListIteratorOfListOfInteractive ite(List);
-  for ( ; ite.More(); ite.Next() )
-  {
-    Handle(SALOME_InteractiveObject) anObj =
-        Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );
+  if(obj.IsNull() || !obj->hasEntry() )
+    return;
 
-    if ( !anObj.IsNull() && anObj->hasEntry() && anObj->isSame( obj ) )
+  if(entry2aisobjects.count(obj->getEntry())>0)
     {
-      OCCViewer_Viewer::switchRepresentation( ite.Value(), mode, update );
-      return;
+      // get context
+      Handle (AIS_InteractiveContext) ic = getAISContext();
+      std::vector<Handle(AIS_InteractiveObject)>& List = entry2aisobjects[obj->getEntry()];
+      for( unsigned int ind = 0; ind < List.size(); ind++ )
+        {
+          Handle(AIS_InteractiveObject) anAIS=List[ind];
+          if( !anAIS.IsNull() && ic->IsDisplayed(anAIS))
+            OCCViewer_Viewer::switchRepresentation( anAIS, mode, update );
+        }
     }
-  }
 }
 
+/*!
+  Changes transparency of object
+  \param obj - object to be processed
+  \param trans - new transparency
+  \param update - update current viewer
+*/
 void SOCC_Viewer::setTransparency( const Handle(SALOME_InteractiveObject)& obj,
                                    float trans, bool update )
 {
-  AIS_ListOfInteractive List;
-  getAISContext()->DisplayedObjects( List );
-  
-  AIS_ListIteratorOfListOfInteractive ite( List );
-  for ( ; ite.More(); ite.Next() )
-  {
-    Handle(SALOME_InteractiveObject) anObj =
-        Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );
+  if(obj.IsNull() || !obj->hasEntry() )
+    return;
 
-    if ( !anObj.IsNull() && anObj->hasEntry() && anObj->isSame( obj ) )
+  if(entry2aisobjects.count(obj->getEntry())>0)
     {
-      OCCViewer_Viewer::setTransparency( ite.Value(), trans, update );
-      return;
+      // get context
+      Handle (AIS_InteractiveContext) ic = getAISContext();
+      std::vector<Handle(AIS_InteractiveObject)>& List = entry2aisobjects[obj->getEntry()];
+      for( unsigned int ind = 0; ind < List.size(); ind++ )
+        {
+          Handle(AIS_InteractiveObject) anAIS=List[ind];
+          if( !anAIS.IsNull() && ic->IsDisplayed(anAIS))
+            OCCViewer_Viewer::setTransparency( anAIS, trans, update );
+        }
     }
-  }
 }
 
+/*!
+  Changes name of object
+  \param obj - object to be renamed
+  \param name - new name
+*/
 void SOCC_Viewer::rename( const Handle(SALOME_InteractiveObject)& obj,
                           const QString& name )
 {
@@ -214,7 +244,7 @@ void SOCC_Viewer::rename( const Handle(SALOME_InteractiveObject)& obj,
         Handle(SALOME_InteractiveObject) IO = aSh->getIO();
         if ( IO->isSame( obj ) )
         {
-          aSh->setName( (char*)name.latin1() );
+          aSh->setName( name.toUtf8().data() );
           break;
         }
       }
@@ -229,10 +259,11 @@ void SOCC_Viewer::rename( const Handle(SALOME_InteractiveObject)& obj,
   }
 }
 
-//=======================================================================
-// name    : Display
-// Purpose : Display presentation
-//=======================================================================
+
+/*!
+  Display presentation
+  \param prs - presentation
+*/
 void SOCC_Viewer::Display( const SALOME_OCCPrs* prs )
 {
   // try do downcast object
@@ -240,19 +271,9 @@ void SOCC_Viewer::Display( const SALOME_OCCPrs* prs )
   if ( !anOCCPrs || anOCCPrs->IsNull() )
     return;
 
-  // get SALOMEDS Study
-  _PTR(Study) study(getStudyDS());
-
   // get context
   Handle (AIS_InteractiveContext) ic = getAISContext();
 
-  // get all displayed objects
-  AIS_ListOfInteractive List;
-  ic->DisplayedObjects( List );
-  // get objects in the collector
-  AIS_ListOfInteractive ListCollector;
-  ic->ObjectsInCollector( ListCollector );
-
   // get objects to be displayed
   AIS_ListOfInteractive anAISObjects;
   anOCCPrs->GetObjects( anAISObjects );
@@ -264,97 +285,91 @@ void SOCC_Viewer::Display( const SALOME_OCCPrs* prs )
     if ( !anAIS.IsNull() )
     {
       // try to find presentation in the viewer
-      bool bDisplayed = false;
-      AIS_ListIteratorOfListOfInteractive ite( List );
-      for ( ; ite.More(); ite.Next() )
-      {
-        // compare presentations by handles
-        // if the object is already displayed - nothing to do more
-        if ( ite.Value() == anAIS )
-        {
-          // Deactivate object if necessary
-          if ( !anOCCPrs->ToActivate() )
-            ic->Deactivate( anAIS );
-          bDisplayed = true;
-          break;
-        }
-      }
 
-      if ( bDisplayed )
-        continue;
-
-      // then try to find presentation in the collector
-      bDisplayed = false;
-      ite.Initialize( ListCollector );
-      for ( ; ite.More(); ite.Next() )
-      {
-        // compare presentations by handles
-        // if the object is in collector - display it
-        if ( ite.Value() == anAIS )
+      // if the object is already displayed - nothing to do more
+      if(ic->IsDisplayed(anAIS))
         {
-          ic->DisplayFromCollector( anAIS, false );
-
           // Deactivate object if necessary
           if ( !anOCCPrs->ToActivate() )
             ic->Deactivate( anAIS );
-          bDisplayed = true;
-
-          // Set visibility flag
-          Handle(SALOME_InteractiveObject) anObj =
-            Handle(SALOME_InteractiveObject)::DownCast( anAIS->GetOwner() );
-          if ( !anObj.IsNull() && anObj->hasEntry() )
-          {
-           if ( study )
-             ToolsGUI::SetVisibility( study, anObj->getEntry(), true, this );
-          }
-
-          break;
+          continue;
         }
-      }
-      if ( bDisplayed )
-        continue;
 
       // if object is not displayed and not found in the collector - display it
       if ( anAIS->IsKind( STANDARD_TYPE(AIS_Trihedron) ) )
       {
         Handle(AIS_Trihedron) aTrh = Handle(AIS_Trihedron)::DownCast( anAIS );
         double aNewSize = 100, aSize = 100;
-        getTrihedronSize( aNewSize, aSize );
+        computeTrihedronSize( aNewSize, aSize );
         aTrh->SetSize( aTrh == getTrihedron() ? aNewSize : 0.5 * aNewSize );
       }
 
       ic->Display( anAIS, false );
-
-      // Set visibility flag
-      Handle(SALOME_InteractiveObject) anObj =
-        Handle(SALOME_InteractiveObject)::DownCast( anAIS->GetOwner() );
-      if ( !anObj.IsNull() && anObj->hasEntry() )
+      Handle(SALOME_AISShape) aSh = Handle(SALOME_AISShape)::DownCast (anAIS);
+      if (!aSh.IsNull())
       {
-       if ( study  )
-         ToolsGUI::SetVisibility( study, anObj->getEntry(), true, this );
+        aSh->SetClippable (prs->IsClippable());
+        applyExistingClipPlanesToObject (anAIS);
+        bool top = (aSh->isTopLevel() && aSh->switchTopLevel());
+             ic->SetZLayer( aSh, top ? getTopLayerId() : 0 );
+                   if(!aSh->toActivate())
+        {
+                           ic->Deactivate( aSh );
+                   }
       }
 
+      //Register anAIS (if it has an entry) in entry2aisobjects map
+      Handle(SALOME_InteractiveObject) anObj = Handle(SALOME_InteractiveObject)::DownCast( anAIS->GetOwner() );
+      if ( !anObj.IsNull() && anObj->hasEntry())
+        {
+          std::vector<Handle(AIS_InteractiveObject)>& List = entry2aisobjects[anObj->getEntry()];
+          int found=0;
+          for ( unsigned int ind = 0; ind < List.size(); ind++ )
+          {
+            if(List[ind] == anAIS)
+              {
+                found=1;
+                break;
+              }
+          }
+          if(!found)
+            {
+              List.push_back(anAIS);
+            }
+        }
+
+      // Set visibility flag
+      // Temporarily commented to avoid awful dependecy on SALOMEDS
+      // TODO: better mechanism of storing display/erse status in a study
+      // should be provided...
+      //Handle(SALOME_InteractiveObject) anObj =
+      //  Handle(SALOME_InteractiveObject)::DownCast( anAIS->GetOwner() );
+      //if ( !anObj.IsNull() && anObj->hasEntry() )
+      //{
+      //  ToolsGUI::SetVisibility( anObj->getEntry(), true, this );
+      //}
+
       // Deactivate object if necessary
       if ( !anOCCPrs->ToActivate() )
         ic->Deactivate( anAIS );
     }
   }
+  updateTrihedron();
 }
 
-//=======================================================================
-// name    : Erase
-// Purpose : Erase presentation
-//=======================================================================
-void SOCC_Viewer::Erase( const SALOME_OCCPrs* prs, const bool forced )
+
+/*!
+  Erase presentation
+  \param prs - presentation
+  \param forced - removes object from context
+*/
+void SOCC_Viewer::Erase( const SALOME_OCCPrs* prs, const bool /*forced*/ )
 {
   // try do downcast object
   const SOCC_Prs* anOCCPrs = dynamic_cast<const SOCC_Prs*>( prs );
   if ( !anOCCPrs || anOCCPrs->IsNull() )
     return;
 
-  // get SALOMEDS Study
-  _PTR(Study) study(getStudyDS());
-
   // get context
   Handle(AIS_InteractiveContext) ic = getAISContext();
 
@@ -367,37 +382,38 @@ void SOCC_Viewer::Erase( const SALOME_OCCPrs* prs, const bool forced )
     Handle(AIS_InteractiveObject) anAIS = aIter.Value();
     if ( !anAIS.IsNull() ) {
       // erase the object from context : move it to collector
-      ic->Erase( anAIS, false, forced ? false : true );
-
+      ic->Erase( anAIS, false );
       // Set visibility flag if necessary
-      if ( !forced )
-      {
-        Handle(SALOME_InteractiveObject) anObj =
-          Handle(SALOME_InteractiveObject)::DownCast( anAIS->GetOwner() );
-        if ( !anObj.IsNull() && anObj->hasEntry() )
-        {
-         if ( study )
-           ToolsGUI::SetVisibility( study, anObj->getEntry(), true, this );
-        }
-      }
+      // Temporarily commented to avoid awful dependecy on SALOMEDS
+      // TODO: better mechanism of storing display/erse status in a study
+      // should be provided...
+      //if ( !forced )
+      //{
+      //  Handle(SALOME_InteractiveObject) anObj =
+      //    Handle(SALOME_InteractiveObject)::DownCast( anAIS->GetOwner() );
+      //  if ( !anObj.IsNull() && anObj->hasEntry() )
+      //  {
+      //    ToolsGUI::SetVisibility( anObj->getEntry(), true, this );
+      //  }
+      //}
     }
   }
+  updateTrihedron();
 }
 
-//=======================================================================
-// name    : EraseAll
-// Purpose : Erase all presentations
-//=======================================================================
-void SOCC_Viewer::EraseAll( const bool forced )
-{
-  // get SALOMEDS Study
-  _PTR(Study) study(getStudyDS());
 
+/*!
+  Erase all presentations
+  \param forced - removes all objects from context
+*/
+void SOCC_Viewer::EraseAll( SALOME_Displayer* d, const bool forced )
+{
   // get context
   Handle(AIS_InteractiveContext) ic = getAISContext();
 
   // check if trihedron is displayed
-  Standard_Boolean isTrihedronDisplayed = ic->IsDisplayed( getTrihedron() );
+  Standard_Boolean isTrihedronDisplayed = isTrihedronVisible();
+  Standard_Boolean isViewCubeDisplayed  = isViewCubeVisible();
 
   // get objects to be erased (all currently displayed objects)
   AIS_ListOfInteractive aList;
@@ -406,191 +422,187 @@ void SOCC_Viewer::EraseAll( const bool forced )
   for ( ; anIter.More(); anIter.Next() ) {
     if ( isTrihedronDisplayed && anIter.Value()->DynamicType() == STANDARD_TYPE( AIS_Trihedron ) )
       continue;
+    if ( isViewCubeDisplayed && anIter.Value()->DynamicType() == STANDARD_TYPE( AIS_ViewCube ) )
+      continue;
 
     // erase an object
     Handle(AIS_InteractiveObject) anIO = anIter.Value();
-    ic->Erase( anIO, false, forced ? false : true );
+    ic->Erase( anIO, false );
     
     // Set visibility flag if necessary
-    if ( !forced ) {
-      Handle(SALOME_InteractiveObject) anObj =
-       Handle(SALOME_InteractiveObject)::DownCast( anIO->GetOwner() );
-
-      if ( !anObj.IsNull() && anObj->hasEntry() ) {
-       if ( study )
-         ToolsGUI::SetVisibility( study, anObj->getEntry(), true, this );
-      }
-    }
+    // Temporarily commented to avoid awful dependecy on SALOMEDS
+    // TODO: better mechanism of storing display/erse status in a study
+    // should be provided...
+    //if ( !forced ) {
+    //  Handle(SALOME_InteractiveObject) anObj =
+    //  Handle(SALOME_InteractiveObject)::DownCast( anIO->GetOwner() );
+
+    //  if ( !anObj.IsNull() && anObj->hasEntry() ) {
+    //    ToolsGUI::SetVisibility( anObj->getEntry(), true, this );
+    //  }
+    //}
   }
 
-  // display trihedron if necessary
-  if ( isTrihedronDisplayed )
-    getAISContext()->Display( getTrihedron() );
-  else
-    Repaint();
+  SALOME_View::EraseAll( d, forced );
+
+  Repaint();
+  updateTrihedron();
 }
 
-//=======================================================================
-// name    : CreatePrs
-// Purpose : Create presentation corresponding to the entry
-//=======================================================================
+/*!
+  Create presentation corresponding to the entry
+  \param entry - entry
+*/
 SALOME_Prs* SOCC_Viewer::CreatePrs( const char* entry )
 {
-  SOCC_Prs* prs = new SOCC_Prs();
+  SOCC_Prs* prs = new SOCC_Prs(entry);
   if ( entry )
   {
-    // get context
-    Handle(AIS_InteractiveContext) ic = getAISContext();
-
-    // get displayed objects
-    AIS_ListOfInteractive List;
-    ic->DisplayedObjects( List );
-    // get objects in the collector
-    AIS_ListOfInteractive ListCollector;
-    ic->ObjectsInCollector( ListCollector );
-    List.Append( ListCollector );
-
-    AIS_ListIteratorOfListOfInteractive ite( List );
-    for ( ; ite.More(); ite.Next() )
-    {
-      Handle(SALOME_InteractiveObject) anObj =
-        Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );
-
-      if ( !anObj.IsNull() && anObj->hasEntry() && strcmp( anObj->getEntry(), entry ) == 0 )
-        prs->AddObject( ite.Value() );
-    }
+    if(entry2aisobjects.count(entry)>0)
+      {
+        //ais object exists
+        std::vector<Handle(AIS_InteractiveObject)> List = entry2aisobjects[entry];
+        // get context
+        Handle(AIS_InteractiveContext) ic = getAISContext();
+        //add all ais
+        for ( unsigned int ind = 0; ind < List.size(); ind++ )
+          {
+            Handle(AIS_InteractiveObject) anAIS=List[ind];
+            if(ic->IsDisplayed(anAIS))
+              {
+                prs->AddObject( anAIS );
+              }
+          }
+      }
   }
   return prs;
 }
 
-//=======================================================================
-// name    : LocalSelection
-// Purpose : Activates selection of sub shapes
-//=======================================================================
-void SOCC_Viewer::LocalSelection( const SALOME_OCCPrs* thePrs, const int theMode )
+/*!
+  Activates selection of sub-shapes
+*/
+void SOCC_Viewer::LocalSelection( const SALOME_OCCPrs* thePrs, const std::list<int> modes )
 {
-  Handle(AIS_InteractiveContext) anIC = getAISContext();
+  Handle(AIS_InteractiveContext) ic = getAISContext();
   
   const SOCC_Prs* anOCCPrs = dynamic_cast<const SOCC_Prs*>( thePrs );
-  if ( anIC.IsNull() )
+  if ( ic.IsNull() )
     return;
   
   // Open local context if there is no one
   bool allObjects = thePrs == 0 || thePrs->IsNull();
-  if ( !anIC->HasOpenedContext() ) {
-    anIC->ClearCurrents( false );
-    anIC->OpenLocalContext( allObjects, true, true );
-  }
+  ic->Deactivate();
 
   AIS_ListOfInteractive anObjs;
   // Get objects to be activated
   if ( allObjects ) 
-    anIC->DisplayedObjects( anObjs );
+    ic->DisplayedObjects( anObjs );
   else
     anOCCPrs->GetObjects( anObjs );
 
+  std::list<int> sel_modes;
+  for ( int i = TopAbs_COMPOUND; i < TopAbs_SHAPE; i++ )
+    if ( std::find(modes.begin(), modes.end(), (int)TopAbs_SHAPE) != modes.end() || std::find(modes.begin(), modes.end(), i) != modes.end())
+      sel_modes.push_back(i);
+
   // Activate selection of objects from prs
   AIS_ListIteratorOfListOfInteractive aIter( anObjs );
   for ( ; aIter.More(); aIter.Next() ) {
     Handle(AIS_InteractiveObject) anAIS = aIter.Value();
     if ( !anAIS.IsNull() )
     {
+      std::list<int>::const_iterator it;
       if ( anAIS->IsKind( STANDARD_TYPE( AIS_Shape ) ) )
       {
-        anIC->Load( anAIS, -1, false );
-        anIC->Activate( anAIS, AIS_Shape::SelectionMode( (TopAbs_ShapeEnum)theMode ) );
+        ic->Load( anAIS, -1 );
+        for( it = sel_modes.begin(); it != sel_modes.end(); ++it )
+          ic->Activate( anAIS, AIS_Shape::SelectionMode( (TopAbs_ShapeEnum)*it ) );
+      }
+      else if ( anAIS->DynamicType() == STANDARD_TYPE(AIS_ViewCube) )
+      {
+        ic->Activate( anAIS, 0 );
       }
       else if ( anAIS->DynamicType() != STANDARD_TYPE(AIS_Trihedron) )
       {
-        anIC->Load( anAIS, -1, false );
-        anIC->Activate( anAIS, theMode );
+        ic->Load( anAIS, -1 );
+        for( it = sel_modes.begin(); it != sel_modes.end(); ++it )
+          ic->Activate( anAIS, *it );
       }
     }
   }
 }
 
-//=======================================================================
-// name    : GlobalSelection
-// Purpose : Deactivates selection of sub shapes
-//=======================================================================
-void SOCC_Viewer::GlobalSelection( const bool update ) const
+/*!
+  Activates selection of sub-shapes
+*/
+void SOCC_Viewer::LocalSelection( const SALOME_OCCPrs* thePrs, const int theMode )
 {
-  Handle(AIS_InteractiveContext) anIC = getAISContext();
-  if ( !anIC.IsNull() )
-    anIC->CloseAllContexts( false );
-  if ( update )
-    anIC->CurrentViewer()->Redraw();
+  std::list<int> modes;
+  modes.push_back( theMode );
+  LocalSelection( thePrs, modes );
 }
 
-//=======================================================================
-// name    : BeforeDisplay
-// Purpose : Axiluary method called before displaying of objects
-//=======================================================================
-void  SOCC_Viewer::BeforeDisplay( SALOME_Displayer* d )
+/*!
+  Deactivates selection of sub-shapes
+*/
+void SOCC_Viewer::GlobalSelection( const bool update ) const
 {
-  d->BeforeDisplay( this, SALOME_OCCViewType() );
+  Handle(AIS_InteractiveContext) ic = getAISContext();
+  if ( !ic.IsNull() )
+  {
+    ic->Deactivate();
+    ic->Activate( 0 );
+    if ( update )
+      ic->CurrentViewer()->Redraw();
+  }
 }
 
-//=======================================================================
-// name    : AfterDisplay
-// Purpose : Axiluary method called after displaying of objects
-//=======================================================================
-void SOCC_Viewer::AfterDisplay( SALOME_Displayer* d )
-{
-  d->AfterDisplay( this, SALOME_OCCViewType() );
-}
 
-//=======================================================================
-// name    : getTrihedronSize
-// Purpose : Get new and current trihedron size corresponding to the
-//           current model size
-//=======================================================================
-bool SOCC_Viewer::getTrihedronSize( double& theNewSize, double& theSize )
+/*!
+  \Collect objects visible in viewer
+  \param theList - visible objects collection
+*/
+void SOCC_Viewer::GetVisible( SALOME_ListIO& theList )
 {
-  theNewSize = 100;
-  theSize = 100;
-
-  //SRN: BUG IPAL8996, a usage of method ActiveView without an initialization
-  Handle(V3d_Viewer) viewer = getViewer3d();
-  viewer->InitActiveViews();
-  if(!viewer->MoreActiveViews()) return false;
-
-  Handle(V3d_View) view3d = viewer->ActiveView();
-  //SRN: END of fix
-
-  if ( view3d.IsNull() )
-    return false;
-
-  double Xmin = 0, Ymin = 0, Zmin = 0, Xmax = 0, Ymax = 0, Zmax = 0;
-  double aMaxSide;
-
-  view3d->View()->MinMaxValues( Xmin, Ymin, Zmin, Xmax, Ymax, Zmax );
-
-  if ( Xmin == RealFirst() || Ymin == RealFirst() || Zmin == RealFirst() ||
-       Xmax == RealLast()  || Ymax == RealLast()  || Zmax == RealLast() )
-    return false;
-
-  aMaxSide = Xmax - Xmin;
-  if ( aMaxSide < Ymax -Ymin ) aMaxSide = Ymax -Ymin;
-  if ( aMaxSide < Zmax -Zmin ) aMaxSide = Zmax -Zmin;
-
-  float aSizeInPercents = SUIT_Session::session()->resourceMgr()->doubleValue("Viewer:TrihedronSize", 105.);
-
-  static float EPS = 5.0E-3;
-  theSize = getTrihedron()->Size();
-  theNewSize = aMaxSide*aSizeInPercents / 100.0;
+  AIS_ListOfInteractive List;
+  getAISContext()->DisplayedObjects(List);
+  
+  AIS_ListIteratorOfListOfInteractive ite(List);
+  for ( ; ite.More(); ite.Next() )
+  {
+    Handle(SALOME_InteractiveObject) anObj =
+        Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );
 
-  return fabs( theNewSize - theSize ) > theSize * EPS ||
-         fabs( theNewSize - theSize) > theNewSize * EPS;
+    if ( !anObj.IsNull() && anObj->hasEntry() )
+      theList.Append( anObj );
+  }
 }
 
-//=======================================================================
-// name    : Repaint
-// Purpose : 
-//=======================================================================
+/*!
+  Updates current viewer
+*/
 void SOCC_Viewer::Repaint()
 {
 //  onAdjustTrihedron();
   getViewer3d()->Update();
 }
 
+
+/*!
+  create SOCC_ViewWindow
+*/
+/*SUIT_ViewWindow* SOCC_Viewer::createView( SUIT_Desktop* theDesktop )
+{
+  SOCC_ViewWindow* view = new SOCC_ViewWindow(theDesktop, this);
+  //initView( view );
+  initView( view->getView(OCCViewer_ViewFrame::MAIN_VIEW) );
+  return view;
+  }*/
+
+/* 
+ * Returns a new OCCViewer_ViewWindow instance which will be placed as a sub window in ViewFrame
+ */
+OCCViewer_ViewWindow* SOCC_Viewer::createSubWindow()
+{
+  return new SOCC_ViewWindow( 0,  this);
+}