Salome HOME
22406: EDF SMESH Regression : Items are missing in group contextual menu
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Selection.cxx
index 758993e4df723f4fd5af7ddb4252f9c5c110402f..6e82d5b46c4708698a48b543c105080f67b49cc3 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2013  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
@@ -127,6 +127,9 @@ QVariant SMESHGUI_Selection::parameter( const int ind, const QString& p ) const
   else if ( p=="groupType" )     val = QVariant( groupType( ind ) );
   else if ( p=="quadratic2DMode") val =  QVariant(quadratic2DMode(ind));
   else if ( p=="isDistributionVisible") val = QVariant(isDistributionVisible(ind));
+  else if ( p=="hasChildren") val = QVariant(hasChildren(ind));
+  else if ( p=="nbChildren") val = QVariant(nbChildren(ind));
+  else if ( p=="isContainer") val = QVariant(isContainer(ind));
 
   if( val.isValid() )
     return val;
@@ -379,7 +382,7 @@ bool SMESHGUI_Selection::isAutoColor( int ind ) const
 
 //=======================================================================
 //function : numberOfNodes
-//purpose  : 
+//purpose  : this method is actually used to check if an object is empty or not
 //=======================================================================
 
 int SMESHGUI_Selection::numberOfNodes( int ind ) const
@@ -398,7 +401,7 @@ int SMESHGUI_Selection::numberOfNodes( int ind ) const
         return aSubMeshObj->GetNumberOfNodes(true);
       SMESH::SMESH_GroupBase_var aGroupObj = SMESH::SMESH_GroupBase::_narrow( obj );
       if ( !aGroupObj->_is_nil() )
-        return aGroupObj->Size();
+        return aGroupObj->IsEmpty() ? 0 : 1; // aGroupObj->Size();
     }
   }
   return 0;
@@ -529,6 +532,50 @@ QVariant SMESHGUI_Selection::isVisible( int ind ) const
   return QVariant( false );
 }
 
+//=======================================================================
+//function : hasChildren
+//purpose  : 
+//=======================================================================
+
+bool SMESHGUI_Selection::hasChildren( int ind ) const
+{
+  if ( ind >= 0 )
+  {
+    _PTR(SObject) sobj = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).toLatin1().data() );
+    return SMESH::GetActiveStudyDocument()->GetUseCaseBuilder()->HasChildren( sobj );
+  }
+  return false;
+}
+
+//=======================================================================
+//function : hasChildren
+//purpose  : 
+//=======================================================================
+
+int SMESHGUI_Selection::nbChildren( int ind ) const
+{
+  int nb = 0;
+  if ( ind >= 0 )
+  {
+    _PTR(SObject) sobj = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).toLatin1().data() );
+    if ( sobj->GetStudy()->GetUseCaseBuilder()->IsUseCaseNode( sobj ) ) {
+      _PTR(UseCaseIterator) it = sobj->GetStudy()->GetUseCaseBuilder()->GetUseCaseIterator( sobj ); 
+      for (it->Init(false); it->More(); it->Next()) nb++;
+    }
+  }
+  return nb;
+}
+
+//=======================================================================
+//function : isContainer
+//purpose  : 
+//=======================================================================
+
+bool SMESHGUI_Selection::isContainer( int ind ) const
+{
+  return ind >= 0 && ind < myTypes.count() && myTypes[ind] == "Unknown";
+}
+
 //=======================================================================
 //function : type
 //purpose  : 
@@ -653,7 +700,7 @@ bool SMESHGUI_Selection::isImported( const int ind ) const
     SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( SMESH::SObjectToObject( SO ) );
     if( !aMesh->_is_nil() )
     {
-      SALOME_MED::MedFileInfo_var inf = aMesh->GetMEDFileInfo();
+      SMESH::MedFileInfo_var inf = aMesh->GetMEDFileInfo();
       res = strlen( (char*)inf->fileName ) > 0;
     }
   }