Salome HOME
Merge remote-tracking branch 'remotes/origin/hydro/imps_2017_salome_83' into HEAD
[modules/geom.git] / src / GEOMGUI / GEOMGUI_Selection.cxx
index 02ab2b0c65e82e3eb777df29e4c86213ac9603ec..0644ff317015fe5f28cdcde47e4db086dde88495 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
@@ -25,6 +25,8 @@
 
 #include "GEOMGUI_Selection.h"
 #include <GEOMGUI_DimensionProperty.h>
+#include <GEOMGUI_AnnotationAttrs.h>
+#include <GEOMGUI_AnnotationMgr.h>
 
 #include "GeometryGUI.h"
 #include "GEOM_Displayer.h"
@@ -151,6 +153,8 @@ QVariant GEOMGUI_Selection::parameter( const QString& p ) const
     v = hasImported();
   else if ( p == "allImported" )
     v = allImported();
+  else if (p == "annotationsCount")
+    v = annotationsCount();
   else
     v = LightApp_Selection::parameter( p );
   return v;
@@ -198,6 +202,10 @@ QVariant GEOMGUI_Selection::parameter( const int idx, const QString& p ) const
     v = hasHiddenDimensions(idx);
   else if ( p == "hasVisibleDimensions" )
     v = hasVisibleDimensions(idx);
+  else if ( p == "hasHiddenAnnotations" )
+    v = hasHiddenAnnotations(idx);
+  else if ( p == "hasVisibleAnnotations" )
+    v = hasVisibleAnnotations(idx);
   else
     v = LightApp_Selection::parameter( idx, p );
 
@@ -207,6 +215,9 @@ QVariant GEOMGUI_Selection::parameter( const int idx, const QString& p ) const
 // the method to skip temporary objects from selection (called from LightApp)
 bool GEOMGUI_Selection::processOwner( const LightApp_DataOwner* theOwner )
 {
+  if ( theOwner->entry().contains( GEOMGUI_AnnotationMgr::GetEntrySeparator() ) ) {
+    myAnnotationEntries.append( theOwner->entry() );
+  }
   return !theOwner->entry().contains("_");
 }
 
@@ -527,10 +538,8 @@ bool GEOMGUI_Selection::isNameMode( const int index ) const
 
 bool GEOMGUI_Selection::hasChildren( const _PTR(SObject)& obj )
 {
-  if ( obj ) {
-    // as soon as Use Case browser data tree was added
-    return obj->GetStudy()->GetUseCaseBuilder()->HasChildren( obj );
-  }
+  // as soon as Use Case browser data tree was added
+  return obj ? obj->GetStudy()->GetUseCaseBuilder()->HasChildren( obj ) : false;
 }
 
 bool GEOMGUI_Selection::expandable( const _PTR(SObject)& obj )
@@ -853,3 +862,63 @@ bool GEOMGUI_Selection::hasVisibleDimensions( const int theIndex ) const
   return isAnyVisible;
 }
 
+int GEOMGUI_Selection::annotationsCount() const
+{
+  return myAnnotationEntries.size();
+}
+
+bool GEOMGUI_Selection::hasAnnotations( const int theIndex, bool& theHidden, bool& theVisible ) const
+{
+  SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( study() );
+  if ( !appStudy )
+    return false;
+
+  QString anEntry = entry( theIndex );
+  _PTR(Study) aStudy = appStudy->studyDS();
+  if ( !aStudy || anEntry.isNull() )
+    return false;
+
+  _PTR(SObject) aSObj = appStudy->studyDS()->FindObjectID( anEntry.toStdString() );\r
+
+  const Handle(GEOMGUI_AnnotationAttrs)\r
+    aShapeAnnotations = GEOMGUI_AnnotationAttrs::FindAttributes( aSObj );\r
+
+  if ( aShapeAnnotations.IsNull() )\r
+    return false;\r
+
+  theHidden  = false;
+  theVisible = false;
+
+  const int aCount = aShapeAnnotations->GetNbAnnotation();
+  for ( int anI = 0; anI < aCount; ++anI )
+  {
+    if ( aShapeAnnotations->GetIsVisible( anI ) )
+      theVisible = true;
+    else
+      theHidden = true;
+  }
+
+  return aCount > 0;
+}
+
+bool GEOMGUI_Selection::hasHiddenAnnotations( const int theIndex ) const
+{
+  bool isAnyVisible, isAnyHidden = false;
+  if ( !hasAnnotations( theIndex, isAnyHidden, isAnyVisible ) )
+  {
+    return false;
+  }
+
+  return isAnyHidden;
+}
+
+bool GEOMGUI_Selection::hasVisibleAnnotations( const int theIndex ) const
+{
+  bool isAnyVisible, isAnyHidden = false;
+  if ( !hasAnnotations( theIndex, isAnyHidden, isAnyVisible ) )
+  {
+    return false;
+  }
+
+  return isAnyVisible;
+}