Salome HOME
Some corrections related to using UNICODE.
[modules/geom.git] / src / GEOMGUI / GEOMGUI_Selection.cxx
index 02ab2b0c65e82e3eb777df29e4c86213ac9603ec..017e7c2400f5f2984c04dc400568951847b48232 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("_");
 }
 
@@ -258,7 +269,7 @@ bool GEOMGUI_Selection::isVisible( const int index ) const
   GEOM::GEOM_Object_var obj = getObject( index );
   SALOME_View* view = GEOM_Displayer::GetActiveView();
   if ( !CORBA::is_nil( obj ) && view ) {
-    Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( entry( index ).toLatin1().constData(), "GEOM", "TEMP_IO" );
+    Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( entry( index ).toUtf8().constData(), "GEOM", "TEMP_IO" );
     res = view->isVisible( io );
   }
 
@@ -331,7 +342,7 @@ QString GEOMGUI_Selection::displayMode( const int index ) const
 
   SALOME_View* view = GEOM_Displayer::GetActiveView();
   if ( view /*fix for 9320==>*/&& ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
-    SALOME_Prs* prs = view->CreatePrs( entry( index ).toLatin1().constData() );
+    SALOME_Prs* prs = view->CreatePrs( entry( index ).toUtf8().constData() );
     if ( prs ) {
       if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
         SOCC_Prs* occPrs = (SOCC_Prs*) prs;
@@ -397,7 +408,7 @@ bool GEOMGUI_Selection::isVectorsMode( const int index ) const
   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() );
+    SALOME_Prs* prs = view->CreatePrs( entry( index ).toUtf8().constData() );
     if ( prs ) {
       if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
         SOCC_Prs* occPrs = (SOCC_Prs*) prs;
@@ -444,7 +455,7 @@ bool GEOMGUI_Selection::isVerticesMode( const int index ) const
   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() );
+    SALOME_Prs* prs = view->CreatePrs( entry( index ).toUtf8().constData() );
     if ( prs ) {
       if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
         SOCC_Prs* occPrs = (SOCC_Prs*) prs;
@@ -491,7 +502,7 @@ bool GEOMGUI_Selection::isNameMode( const int index ) const
   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() );
+    SALOME_Prs* prs = view->CreatePrs( entry( index ).toUtf8().constData() );
     if ( prs ) {
       if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
         SOCC_Prs* occPrs = (SOCC_Prs*) prs;
@@ -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 ? SalomeApp_Application::getStudy()->GetUseCaseBuilder()->HasChildren( obj ) : false;
 }
 
 bool GEOMGUI_Selection::expandable( const _PTR(SObject)& obj )
@@ -592,8 +601,8 @@ int GEOMGUI_Selection::nbChildren( const int index ) const
     _PTR(Study) study = appStudy->studyDS();
     if ( study && !anEntry.isEmpty() ) {
       _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
-      if ( aSO && aSO->GetStudy()->GetUseCaseBuilder()->IsUseCaseNode(aSO) ) {
-        _PTR(UseCaseIterator) it = aSO->GetStudy()->GetUseCaseBuilder()->GetUseCaseIterator( aSO ); 
+      if ( aSO && study->GetUseCaseBuilder()->IsUseCaseNode(aSO) ) {
+        _PTR(UseCaseIterator) it = study->GetUseCaseBuilder()->GetUseCaseIterator( aSO );
         for (it->Init(false); it->More(); it->Next()) nb++;
       }
     }
@@ -707,7 +716,7 @@ bool GEOMGUI_Selection::topLevel( const int index ) const
   SALOME_View* view = GEOM_Displayer::GetActiveView();
   QString viewType = activeViewType();
   if ( view && viewType == OCCViewer_Viewer::Type() ) {
-    SALOME_Prs* prs = view->CreatePrs( entry( index ).toLatin1().constData() );
+    SALOME_Prs* prs = view->CreatePrs( entry( index ).toUtf8().constData() );
     if ( prs ) {
       if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
         SOCC_Prs* occPrs = (SOCC_Prs*) prs;
@@ -743,7 +752,7 @@ bool GEOMGUI_Selection::isPhysicalMaterial( const int idx ) const
   SALOME_View* view = GEOM_Displayer::GetActiveView();
   QString viewType = activeViewType();
   if ( view ) {
-    SALOME_Prs* prs = view->CreatePrs( entry( idx ).toLatin1().constData() );
+    SALOME_Prs* prs = view->CreatePrs( entry( idx ).toUtf8().constData() );
     if ( prs ) {
       if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
         SOCC_Prs* occPrs = (SOCC_Prs*) prs;
@@ -799,21 +808,13 @@ bool GEOMGUI_Selection::isFolder( const int index ) const
 
 bool GEOMGUI_Selection::hasDimensions( 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() )
+  if ( anEntry.isNull() )
   {
     return false;
   }
 
-  GEOMGUI_DimensionProperty aDimensions( appStudy, anEntry.toStdString() );
+  GEOMGUI_DimensionProperty aDimensions( anEntry.toStdString() );
 
   theHidden  = false;
   theVisible = false;
@@ -853,3 +854,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() );
+
+  const Handle(GEOMGUI_AnnotationAttrs)
+    aShapeAnnotations = GEOMGUI_AnnotationAttrs::FindAttributes( aSObj );
+
+  if ( aShapeAnnotations.IsNull() )
+    return false;
+
+  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;
+}