Salome HOME
updated copyright message
[modules/gui.git] / src / SOCC / SOCC_ViewModel.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 224e2de..55aec6c
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// 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
@@ -25,8 +25,6 @@
 #include "SOCC_Prs.h"
 #include "SOCC_ViewWindow.h"
 
-#include "OCCViewer_Trihedron.h"
-
 #include "SUIT_Session.h"
 #include "SUIT_ResourceMgr.h"
 //#include "SUIT_Application.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>
 
-// Temporarily commented to avoid awful dependecy on SALOMEDS
-// TODO: better mechanism of storing display/erse status in a study
-// should be provided...
-//#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"
-
 #include <AIS_TypeOfIso.hxx>
 #include <Precision.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. 
-
-// Temporarily commented to avoid awful dependecy on SALOMEDS
-// TODO: better mechanism of storing display/erse status in a study
-// should be provided...
-//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
@@ -109,10 +74,6 @@ SOCC_Viewer::~SOCC_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);
   
@@ -124,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 );
+      OCCViewer_Viewer::highlight( ite.Value(), hilight, false );
       // highlight sub-shapes 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 );
-        }*/
-      }
       break;
     }
   }
@@ -153,7 +103,7 @@ bool SOCC_Viewer::highlight( const Handle(SALOME_InteractiveObject)& obj,
   \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);
@@ -294,7 +244,7 @@ void SOCC_Viewer::rename( const Handle(SALOME_InteractiveObject)& obj,
         Handle(SALOME_InteractiveObject) IO = aSh->getIO();
         if ( IO->isSame( obj ) )
         {
-          aSh->setName( name.toLatin1().data() );
+          aSh->setName( name.toUtf8().data() );
           break;
         }
       }
@@ -321,12 +271,6 @@ void SOCC_Viewer::Display( const SALOME_OCCPrs* prs )
   if ( !anOCCPrs || anOCCPrs->IsNull() )
     return;
 
-  // get SALOMEDS Study
-  // Temporarily commented to avoid awful dependecy on SALOMEDS
-  // TODO: better mechanism of storing display/erse status in a study
-  // should be provided...
-  //  _PTR(Study) study(getStudyDS());
-
   // get context
   Handle (AIS_InteractiveContext) ic = getAISContext();
 
@@ -402,8 +346,7 @@ void SOCC_Viewer::Display( const SALOME_OCCPrs* prs )
       //  Handle(SALOME_InteractiveObject)::DownCast( anAIS->GetOwner() );
       //if ( !anObj.IsNull() && anObj->hasEntry() )
       //{
-      //  if ( study  )
-      //    ToolsGUI::SetVisibility( study, anObj->getEntry(), true, this );
+      //  ToolsGUI::SetVisibility( anObj->getEntry(), true, this );
       //}
 
       // Deactivate object if necessary
@@ -420,19 +363,13 @@ void SOCC_Viewer::Display( const SALOME_OCCPrs* prs )
   \param prs - presentation
   \param forced - removes object from context
 */
-void SOCC_Viewer::Erase( const SALOME_OCCPrs* prs, const bool forced )
+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
-  // Temporarily commented to avoid awful dependecy on SALOMEDS
-  // TODO: better mechanism of storing display/erse status in a study
-  // should be provided...
-  //  _PTR(Study) study(getStudyDS());
-
   // get context
   Handle(AIS_InteractiveContext) ic = getAISContext();
 
@@ -456,8 +393,7 @@ void SOCC_Viewer::Erase( const SALOME_OCCPrs* prs, const bool forced )
       //    Handle(SALOME_InteractiveObject)::DownCast( anAIS->GetOwner() );
       //  if ( !anObj.IsNull() && anObj->hasEntry() )
       //  {
-      //  if ( study )
-      //    ToolsGUI::SetVisibility( study, anObj->getEntry(), true, this );
+      //    ToolsGUI::SetVisibility( anObj->getEntry(), true, this );
       //  }
       //}
     }
@@ -472,25 +408,21 @@ void SOCC_Viewer::Erase( const SALOME_OCCPrs* prs, const bool forced )
 */
 void SOCC_Viewer::EraseAll( SALOME_Displayer* d, const bool forced )
 {
-  // get SALOMEDS Study
-  // Temporarily commented to avoid awful dependecy on SALOMEDS
-  // TODO: better mechanism of storing display/erse status in a study
-  // should be provided...
-  //  _PTR(Study) study(getStudyDS());
-
   // 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;
   ic->DisplayedObjects( aList );
   AIS_ListIteratorOfListOfInteractive anIter( aList );
   for ( ; anIter.More(); anIter.Next() ) {
-    if ( (isTrihedronDisplayed && anIter.Value()->DynamicType() == STANDARD_TYPE( AIS_Trihedron )) ||
-         anIter.Value()->DynamicType() == STANDARD_TYPE( OCCViewer_Trihedron ))
+    if ( isTrihedronDisplayed && anIter.Value()->DynamicType() == STANDARD_TYPE( AIS_Trihedron ) )
+      continue;
+    if ( isViewCubeDisplayed && anIter.Value()->DynamicType() == STANDARD_TYPE( AIS_ViewCube ) )
       continue;
 
     // erase an object
@@ -506,8 +438,7 @@ void SOCC_Viewer::EraseAll( SALOME_Displayer* d, const bool forced )
     //  Handle(SALOME_InteractiveObject)::DownCast( anIO->GetOwner() );
 
     //  if ( !anObj.IsNull() && anObj->hasEntry() ) {
-    //  if ( study )
-    //    ToolsGUI::SetVisibility( study, anObj->getEntry(), true, this );
+    //    ToolsGUI::SetVisibility( anObj->getEntry(), true, this );
     //  }
     //}
   }
@@ -560,10 +491,7 @@ void SOCC_Viewer::LocalSelection( const SALOME_OCCPrs* thePrs, const std::list<i
   
   // Open local context if there is no one
   bool allObjects = thePrs == 0 || thePrs->IsNull();
-  if ( !ic->HasOpenedContext() ) {
-    ic->ClearCurrents( false );
-    ic->OpenLocalContext( allObjects, true, true );
-  }
+  ic->Deactivate();
 
   AIS_ListOfInteractive anObjs;
   // Get objects to be activated
@@ -572,6 +500,11 @@ void SOCC_Viewer::LocalSelection( const SALOME_OCCPrs* thePrs, const std::list<i
   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() ) {
@@ -581,14 +514,18 @@ void SOCC_Viewer::LocalSelection( const SALOME_OCCPrs* thePrs, const std::list<i
       std::list<int>::const_iterator it;
       if ( anAIS->IsKind( STANDARD_TYPE( AIS_Shape ) ) )
       {
-        ic->Load( anAIS, -1, false );
-        for( it = modes.begin(); it != modes.end(); ++it )
+        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) )
       {
-        ic->Load( anAIS, -1, false );
-        for( it = modes.begin(); it != modes.end(); ++it )
+        ic->Load( anAIS, -1 );
+        for( it = sel_modes.begin(); it != sel_modes.end(); ++it )
           ic->Activate( anAIS, *it );
       }
     }
@@ -613,7 +550,8 @@ void SOCC_Viewer::GlobalSelection( const bool update ) const
   Handle(AIS_InteractiveContext) ic = getAISContext();
   if ( !ic.IsNull() )
   {
-    ic->CloseAllContexts( false );
+    ic->Deactivate();
+    ic->Activate( 0 );
     if ( update )
       ic->CurrentViewer()->Redraw();
   }