Salome HOME
#19765 EDF 21730 - long time to load med file file with huge amount of groups
authoreap <eap@opencascade.com>
Mon, 20 Jul 2020 07:13:03 +0000 (10:13 +0300)
committereap <eap@opencascade.com>
Mon, 20 Jul 2020 07:13:03 +0000 (10:13 +0300)
src/SMESHGUI/SMESHGUI_GroupDlg.cxx
src/SMESHGUI/SMESHGUI_Selection.cxx
src/SMESH_I/SMESH_Mesh_i.cxx

index 21b33c443b7e5022196c3a44633009fa7374f4a0..2313c768ce438035762520a9727d1bf47be37bf1 100644 (file)
@@ -74,6 +74,7 @@
 #include <vtkActorCollection.h>
 
 // OCCT includes
 #include <vtkActorCollection.h>
 
 // OCCT includes
+#include <TColStd_MapOfAsciiString.hxx>
 #include <TColStd_MapOfInteger.hxx>
 
 // Qt includes
 #include <TColStd_MapOfInteger.hxx>
 
 // Qt includes
@@ -522,19 +523,38 @@ QString SMESHGUI_GroupDlg::GetDefaultName(const QString& theOperation)
   return aName;
 }
 
   return aName;
 }
 
+//=======================================================================
+//function : setDefaultName
+//purpose  : 
+//=======================================================================
+
 void  SMESHGUI_GroupDlg::setDefaultName() const
 {
   QString aResName;
 void  SMESHGUI_GroupDlg::setDefaultName() const
 {
   QString aResName;
-  int i=1;
-  QString aPrefix ="Group_";
-  _PTR(SObject) anObj;
-  do
+  const QString aPrefix ="Group_";
+
+  if ( myMesh->_is_nil() )
   {
   {
-    aResName = aPrefix + QString::number( i++ );
-    anObj = SMESH::getStudy()->FindObject( aResName.toUtf8().constData() );
+    aResName = aPrefix + "1";
   }
   }
-  while ( anObj );
-  myName->setText(aResName); 
+  else
+  {
+    SMESH::ListOfGroups_var allGroups = myMesh->GetGroups();
+    TColStd_MapOfAsciiString allNames( allGroups->length() );
+    for ( CORBA::ULong i = 0; i < allGroups->length(); ++i )
+    {
+      CORBA::String_var name = allGroups[i]->GetName();
+      allNames.Add( name.in() );
+    }
+    int i = 1;
+    while ( true )
+    {
+      aResName = aPrefix + QString::number( i++ );
+      if ( !allNames.Contains( aResName.toUtf8().constData() ))
+        break;
+    }
+  }
+  myName->setText(aResName);
 }
 
 //=================================================================================
 }
 
 //=================================================================================
@@ -944,7 +964,8 @@ bool SMESHGUI_GroupDlg::onApply()
 
     if (myGroup->_is_nil()) { // creation or conversion
       // check if group on geometry is not null
 
     if (myGroup->_is_nil()) { // creation or conversion
       // check if group on geometry is not null
-      if (!myGroupOnGeom->_is_nil() || !myGroupOnFilter->_is_nil()) {
+      if (!myGroupOnGeom->_is_nil() || !myGroupOnFilter->_is_nil())
+      {
         if (myMesh->_is_nil())
           return false;
         if ( myGroupOnGeom->_is_nil() )
         if (myMesh->_is_nil())
           return false;
         if ( myGroupOnGeom->_is_nil() )
@@ -958,7 +979,8 @@ bool SMESHGUI_GroupDlg::onApply()
       }
     }
 
       }
     }
 
-    if (myGroup->_is_nil()) { // creation
+    if (myGroup->_is_nil()) // creation
+    {
       if (myMesh->_is_nil())
         return false;
 
       if (myMesh->_is_nil())
         return false;
 
@@ -990,10 +1012,10 @@ bool SMESHGUI_GroupDlg::onApply()
           myGroup->Add(anIdList.inout());
         }
       }
           myGroup->Add(anIdList.inout());
         }
       }
+    }
 
 
-
-    } else { // edition
-
+    else // edition
+    {
       resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
       isCreation = false;
 
       resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
       isCreation = false;
 
@@ -1111,6 +1133,7 @@ bool SMESHGUI_GroupDlg::onApply()
     }
     anIsOk = true;
   }
     }
     anIsOk = true;
   }
+
   if (myGrpTypeId == 2) // group on filter
   {
     if ( myFilter->_is_nil() ) return false;
   if (myGrpTypeId == 2) // group on filter
   {
     if ( myFilter->_is_nil() ) return false;
@@ -1170,7 +1193,7 @@ bool SMESHGUI_GroupDlg::onApply()
           Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
           if ( isConversion ) { // need to reset TVisualObj and actor
             SMESH::RemoveVisualObjectWithActors( anIO->getEntry(), true );
           Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
           if ( isConversion ) { // need to reset TVisualObj and actor
             SMESH::RemoveVisualObjectWithActors( anIO->getEntry(), true );
-            SMESH::Update( anIO,true);
+            SMESH::Update( anIO, true );
             myActorsList.clear();
             anActor = SMESH::FindActorByEntry( anIO->getEntry() );
             if ( !anActor ) return false;
             myActorsList.clear();
             anActor = SMESH::FindActorByEntry( anIO->getEntry() );
             if ( !anActor ) return false;
index 3a32c569bf53cbceee1f916f7bba38c427dcaf06..77d5abaa23cb68de88c92fac787fb0100e664a88 100644 (file)
@@ -660,15 +660,15 @@ bool SMESHGUI_Selection::canBreakLink( int ind ) const
     if (!aEntry.isEmpty()) {
       _PTR(SObject) aSObject = SMESH::getStudy()->FindObjectID( aEntry.toStdString());
       if (aSObject) {
     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();
+        _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();
           }
         }
       }
           }
         }
       }
index 9c00cb31ee2073aa8d0f54e6090ba84c4c3d4ed8..0f827b05463cfc1c02c6ecedb80ffc15551c134c 100644 (file)
@@ -5821,15 +5821,21 @@ void SMESH_Mesh_i::CreateGroupServants()
     GEOM::GEOM_Object_var shapeVar = _gen_i->ShapeToGeomObject( shape );
     _gen_i->PublishGroup( aMesh, groupVar, shapeVar, group->GetName());
   }
     GEOM::GEOM_Object_var shapeVar = _gen_i->ShapeToGeomObject( shape );
     _gen_i->PublishGroup( aMesh, groupVar, shapeVar, group->GetName());
   }
+
   if ( !addedIDs.empty() )
   {
     // python dump
   if ( !addedIDs.empty() )
   {
     // python dump
-    set<int>::iterator id = addedIDs.begin();
-    for ( ; id != addedIDs.end(); ++id )
+    map<int, SMESH::SMESH_GroupBase_ptr>::iterator i_grp = _mapGroups.begin();
+    for ( int index = 0; i_grp != _mapGroups.end(); ++index, ++i_grp )
     {
     {
-      map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.find(*id);
-      int i = std::distance( _mapGroups.begin(), it );
-      TPythonDump() << it->second << " = " << aMesh << ".GetGroups()[ "<< i << " ]";
+      set<int>::iterator it = addedIDs.find( i_grp->first );
+      if ( it != addedIDs.end() )
+      {
+        TPythonDump() << i_grp->second << " = " << aMesh << ".GetGroups()[ "<< index << " ]";
+        addedIDs.erase( it );
+        if ( addedIDs.empty() )
+          break;
+      }
     }
   }
 }
     }
   }
 }