Salome HOME
Merge remote branch 'origin/V7_dev'
[modules/geom.git] / src / GEOMGUI / GEOMGUI_Selection.cxx
index 4f8a71c7d9310758ff7e75957edab09bdb095a6a..51fd1788927a8f834e3b52c82f085532a9bff0b2 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  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
@@ -65,7 +65,6 @@
 #include <AIS_InteractiveObject.hxx>
 #include <AIS_ListOfInteractive.hxx>
 #include <AIS_GraphicTool.hxx>
-#include <AIS_Drawer.hxx>
 #include <Aspect_TypeOfFacingModel.hxx>
 #include <Prs3d_ShadingAspect.hxx>
 #include<Graphic3d_MaterialAspect.hxx>
     else \
       str = QString(); }
 
-#define VTK_DISPLAY_MODE_TO_STRING( str, dm ) { \
-    if ( dm == 0 ) \
-      str = QString( "Wireframe" ); \
-    else if ( dm == 1 )    \
-      str = QString( "Shading" ); \
-    else if ( dm == 3 )    \
-      str = QString( "ShadingWithEdges" ); \
-    else \
-      str = QString(); }
-
 #define USE_VISUAL_PROP_MAP
 
+#ifdef USE_VISUAL_PROP_MAP
+  #define VTK_DISPLAY_MODE_TO_STRING( str, dm ) { \
+      if ( dm == 0 ) \
+        str = QString( "Wireframe" ); \
+      else if ( dm == 1 )    \
+        str = QString( "Shading" ); \
+      else if ( dm == 2 )    \
+        str = QString( "ShadingWithEdges" ); \
+      else \
+        str = QString(); }
+#else
+  #define VTK_DISPLAY_MODE_TO_STRING( str, dm ) { \
+      if ( dm == 0 ) \
+        str = QString( "Wireframe" ); \
+      else if ( dm == 1 )    \
+        str = QString( "Shading" ); \
+      else if ( dm == 3 )    \
+        str = QString( "ShadingWithEdges" ); \
+      else \
+        str = QString(); }
+#endif
+
 GEOMGUI_Selection::GEOMGUI_Selection()
 : LightApp_Selection()
 {
@@ -159,6 +170,10 @@ QVariant GEOMGUI_Selection::parameter( const int idx, const QString& p ) const
     v = isAutoColor( idx );
   else if ( p == "isVectorsMode" )
     v = isVectorsMode( idx );
+  else if ( p == "isVerticesMode" )
+    v = isVerticesMode( idx );
+  else if ( p == "isNameMode" )
+    v = isNameMode( idx );
   else if ( p == "topLevel" )
     v = topLevel( idx );
   else if ( p == "autoBringToFront" )
@@ -366,7 +381,7 @@ QString GEOMGUI_Selection::displayMode( const int index ) const
 
 bool GEOMGUI_Selection::autoBringToFront( const int /*index*/ ) const
 {
-  return SUIT_Session::session()->resourceMgr()->booleanValue( "Geometry", "auto_bring_to_front" );
+  return SUIT_Session::session()->resourceMgr()->booleanValue( "Geometry", "auto_bring_to_front", "false" );
 }
 
 bool GEOMGUI_Selection::isVectorsMode( const int index ) const
@@ -416,6 +431,100 @@ bool GEOMGUI_Selection::isVectorsMode( const int index ) const
   return res;
 }
 
+bool GEOMGUI_Selection::isVerticesMode( const int index ) const
+{
+#ifdef USE_VISUAL_PROP_MAP
+  QVariant v = visibleProperty( entry( index ), GEOM::propertyName( GEOM::Vertices ) );
+  if ( v.canConvert( QVariant::Bool ) )
+    return v.toBool();
+#endif
+
+  bool res = false;
+  
+  SALOME_View* view = GEOM_Displayer::GetActiveView();
+  QString viewType = activeViewType();
+  if ( view && ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
+    SALOME_Prs* prs = view->CreatePrs( entry( index ).toLatin1().constData() );
+    if ( prs ) {
+      if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
+        SOCC_Prs* occPrs = (SOCC_Prs*) prs;
+        AIS_ListOfInteractive lst;
+        occPrs->GetObjects( lst );
+        if ( lst.Extent() ) {
+          Handle(AIS_InteractiveObject) io = lst.First();
+          if ( !io.IsNull() ) {
+            Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(io);
+            if ( !aSh.IsNull() )
+              res = aSh->isShowVertices();
+          }
+        }
+      }
+      else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
+        SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
+        vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
+        if ( lst ) {
+          lst->InitTraversal();
+          vtkActor* actor = lst->GetNextActor();
+          if ( actor ) {
+            GEOM_Actor* aGeomActor = GEOM_Actor::SafeDownCast(actor);
+            if ( aGeomActor )
+              res = aGeomActor->GetVerticesMode();
+            }
+        }
+      }
+    }
+  }
+
+  return res;
+}
+
+bool GEOMGUI_Selection::isNameMode( const int index ) const
+{
+#ifdef USE_VISUAL_PROP_MAP
+  QVariant v = visibleProperty( entry( index ), GEOM::propertyName( GEOM::ShowName ) );
+  if ( v.canConvert( QVariant::Bool ) )
+    return v.toBool();
+#endif
+
+  bool res = false;
+
+  SALOME_View* view = GEOM_Displayer::GetActiveView();
+  QString viewType = activeViewType();
+  if ( view && ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
+    SALOME_Prs* prs = view->CreatePrs( entry( index ).toLatin1().constData() );
+    if ( prs ) {
+      if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
+        SOCC_Prs* occPrs = (SOCC_Prs*) prs;
+        AIS_ListOfInteractive lst;
+        occPrs->GetObjects( lst );
+        if ( lst.Extent() ) {
+          Handle(AIS_InteractiveObject) io = lst.First();
+          if ( !io.IsNull() ) {
+            Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(io);
+            if ( !aSh.IsNull() )
+              res = aSh->isShowName();
+          }
+        }
+      }
+      else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
+        SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
+        vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
+        if ( lst ) {
+          lst->InitTraversal();
+          vtkActor* actor = lst->GetNextActor();
+          if ( actor ) {
+            GEOM_Actor* aGeomActor = GEOM_Actor::SafeDownCast(actor);
+            if ( aGeomActor )
+              res = aGeomActor->GetNameMode();
+            }
+        }
+      }
+    }
+  }
+
+  return res;
+}
+
 bool GEOMGUI_Selection::hasChildren( const _PTR(SObject)& obj )
 {
   if ( obj ) {
@@ -660,7 +769,8 @@ bool GEOMGUI_Selection::isPhysicalMaterial( const int idx ) const
             GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( actor );
             if ( aGeomGActor ) {
               GEOM_VTKPropertyMaterial* mat  = GEOM_VTKPropertyMaterial::SafeDownCast(aGeomGActor->GetProperty());
-              res = mat->GetPhysical();
+              if ( mat )
+                res = mat->GetPhysical();
             } // if ( salome actor )
           } // if ( actor )
         } // if ( lst == vtkPrs->GetObjects() )