Salome HOME
#19765 EDF 21730 - long time to load med file file with huge amount of groups
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Selection.cxx
index d0cd5c4dcc54cb765f55e29623e09432d8606095..77d5abaa23cb68de88c92fac787fb0100e664a88 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2019  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2020  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
@@ -125,6 +125,8 @@ QVariant SMESHGUI_Selection::parameter( const int ind, const QString& p ) const
   else if ( p=="entityMode" )           val = QVariant( entityMode( ind ) );
   else if ( p=="isNumFunctor" )         val = QVariant( isNumFunctor( ind ) );
   else if ( p=="displayMode" )          val = QVariant( displayMode( ind ) );
+  else if ( p=="hasAlgo" )              val = QVariant( hasAlgo( ind ) );
+  else if ( p=="hasErrors" )            val = QVariant( hasErrors( ind ) );
   else if ( p=="isComputable" )         val = QVariant( isComputable( ind ) );
   else if ( p=="isPreComputable" )      val = QVariant( isPreComputable( ind ) );
   else if ( p=="hasGeomReference" )     val = QVariant( hasGeomReference( ind ) );
@@ -140,6 +142,7 @@ QVariant SMESHGUI_Selection::parameter( const int ind, const QString& p ) const
   else if ( p=="nbChildren")            val = QVariant( nbChildren( ind ) );
   else if ( p=="isContainer")           val = QVariant( isContainer( ind ) );
   else if ( p=="guiState")              val = QVariant( guiState() );
+  else if ( p=="canBreakLink")          val = QVariant( canBreakLink(ind) );
 
   if ( val.isValid() )
     return val;
@@ -543,22 +546,17 @@ int SMESHGUI_Selection::dim( int ind ) const
 }
 
 //=======================================================================
-//function : isComputable
-//purpose  : return true for a ready-to-compute mesh
+//function : hasAlgo
+//purpose  : return true for a ready-to-compute [sub-]mesh
 //=======================================================================
 
-bool SMESHGUI_Selection::isComputable( int ind ) const
+bool SMESHGUI_Selection::hasAlgo( int ind ) const
 {
   if ( ind >= 0 && ind < myTypes.count() && ( myTypes[ind] == "Mesh" ||
                                               myTypes[ind].startsWith("Mesh " )))
   {
     QMap<int,int> modeMap;
-    _PTR(SObject) meshSO = SMESH::getStudy()->FindObjectID( entry( ind ).toUtf8().data() );
-
-    _PTR(SComponent) component = meshSO->GetFatherComponent();
-    if ( meshSO->Depth() - component->Depth() > 1 ) // sub-mesh, get a mesh
-      while ( meshSO->Depth() - component->Depth() > 1 )
-        meshSO = meshSO->GetFather();
+    _PTR(SObject) meshSO = SMESH::getStudy()->FindObjectID( entry( ind ).toStdString() );
 
     SMESHGUI_PrecomputeOp::getAssignedAlgos( meshSO, modeMap );
     return modeMap.size() > 0;
@@ -566,6 +564,51 @@ bool SMESHGUI_Selection::isComputable( int ind ) const
   return false;
 }
 
+
+//=======================================================================
+//function : hasAlgo
+//purpose  : return true if a mesh was computed with errors
+//=======================================================================
+
+bool SMESHGUI_Selection::hasErrors( int ind ) const
+{
+  if ( ind >= 0 && ind < myTypes.count() && ( myTypes[ind] == "Mesh"))
+  {
+    _PTR(SObject)       meshSO = SMESH::getStudy()->FindObjectID( entry( ind ).toStdString() );
+    CORBA::Object_var      obj = SMESH::SObjectToObject( meshSO );
+    SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( obj );
+    if ( !CORBA::is_nil( mesh ) )
+    {
+      SMESH::SMESH_Gen_var   gen = SMESHGUI::GetSMESHGUI()->GetSMESHGen();
+      GEOM::GEOM_Object_var geom = mesh->GetShapeToMesh();
+      SMESH::compute_error_array_var compErrors = gen->GetComputeErrors( mesh, geom );
+      return compErrors->length();
+    }
+  }
+  return false;
+}
+
+//=======================================================================
+//function : isComputable
+//purpose  : Return true if a [sub-]mesh does not have "computed" icon
+//=======================================================================
+
+bool SMESHGUI_Selection::isComputable( int ind ) const
+{
+  if ( ind >= 0 && ind < myTypes.count() && ( myTypes[ind] == "Mesh" ||
+                                              myTypes[ind].startsWith("Mesh " )))
+  {
+    _PTR(GenericAttribute) attr;
+    if ( _PTR(SObject) meshSO = SMESH::getStudy()->FindObjectID( entry( ind ).toStdString() ))
+      if ( meshSO->FindAttribute( attr, "AttributePixMap" ))
+      {
+        _PTR(AttributePixMap) pixmap = attr;
+        return ( pixmap->GetPixMap() != "ICON_SMESH_TREE_MESH" );
+      }
+  }
+  return false;
+}
+
 //=======================================================================
 //function : isPreComputable
 //purpose  : returns true for a mesh with algorithms
@@ -605,6 +648,35 @@ bool SMESHGUI_Selection::hasGeomReference( int ind ) const
   return false;
 }
 
+//=======================================================================
+//function : canBreakLink
+//purpose  : returns true if selected object is a Shaper object and it can break link
+//=======================================================================
+
+bool SMESHGUI_Selection::canBreakLink( int ind ) const
+{
+  if ( ind >= 0 && isReference(ind) ) {
+    QString aEntry = objectInfo(ind, OI_RefEntry).toString();
+    if (!aEntry.isEmpty()) {
+      _PTR(SObject) aSObject = SMESH::getStudy()->FindObjectID( aEntry.toStdString());
+      if (aSObject) {
+        _PTR(SObject) aFatherObj = aSObject->GetFather();
+        if (aFatherObj) {
+          _PTR(SComponent) aComponent = aFatherObj->GetFatherComponent();
+          if (aComponent && aComponent->ComponentDataType() == "SMESH") {
+            QString aObjEntry = entry(ind);
+            _PTR(SObject) aGeomSObject = SMESH::getStudy()->FindObjectID(aObjEntry.toStdString());
+            GEOM::GEOM_Object_var aObject = SMESH::SObjectToInterface<GEOM::GEOM_Object>(aGeomSObject);
+            if (!aObject->_is_nil())
+              return aObject->IsParametrical();
+          }
+        }
+      }
+    }
+  }
+  return false;
+}
+
 //=======================================================================
 //function : isEditableHyp
 //purpose  :