]> SALOME platform Git repositories - modules/smesh.git/commitdiff
Salome HOME
fix bug 10638: add and use SMESH_Mesh::GetGroups() allowing correct PythonDump of...
authoreap <eap@opencascade.com>
Thu, 4 May 2006 17:09:38 +0000 (17:09 +0000)
committereap <eap@opencascade.com>
Thu, 4 May 2006 17:09:38 +0000 (17:09 +0000)
src/SMESH_I/SMESH_Gen_i.cxx
src/SMESH_I/SMESH_Mesh_i.cxx
src/SMESH_I/SMESH_Mesh_i.hxx

index a5e803837d0b85a1c313edbd58153b67d917efe2..93d657e2098ca8a73bffbd7fa6af4bf81bc1489a 100644 (file)
@@ -699,6 +699,10 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromUNV( const char* theFileName
   SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
   ASSERT( aServant );
   aServant->ImportUNVFile( theFileName );
+
+  // Dump creation of groups
+  aServant->GetGroups();
+
   return aMesh._retn();
 }
 
@@ -717,11 +721,6 @@ SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMED( const char* theFileName,
   Unexpect aCatch(SALOME_SalomeException);
   if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshFromMED" );
 
-  // Python Dump
-  TPythonDump aPythonDump;
-  aPythonDump << "([";
-  //TCollection_AsciiString aStr ("([");
-
   // Retrieve mesh names from the file
   DriverMED_R_SMESHDS_Mesh myReader;
   myReader.SetFile( theFileName );
@@ -730,6 +729,14 @@ SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMED( const char* theFileName,
   list<string> aNames = myReader.GetMeshNames(aStatus);
   SMESH::mesh_array_var aResult = new SMESH::mesh_array();
   theStatus = (SMESH::DriverMED_ReadStatus)aStatus;
+
+  { // open a new scope to make aPythonDump die before PythonDump in SMESH_Mesh::GetGroups()
+
+  // Python Dump
+  TPythonDump aPythonDump;
+  aPythonDump << "([";
+  //TCollection_AsciiString aStr ("([");
+
   if (theStatus == SMESH::DRS_OK) {
     SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
     aStudyBuilder->NewCommand();  // There is a transaction
@@ -775,6 +782,10 @@ SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMED( const char* theFileName,
 
   // Update Python script
   aPythonDump << "], status) = " << this << ".CreateMeshesFromMED('" << theFileName << "')";
+  }
+  // Dump creation of groups
+  for ( int i = 0; i < aResult->length(); ++i )
+    aResult[ i ]->GetGroups();
 
   return aResult._retn();
 }
index 4ef420bda6e7d1008a66a92f151def1f3e5b5b03..fc489aa0c4b42ed6289ae80c9cf3cc3144a02480 100644 (file)
@@ -728,6 +728,47 @@ void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup
   _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
 }
 
+
+//================================================================================
+/*!
+ * \brief Get the list of groups existing in the mesh
+  * \retval SMESH::ListOfGroups * - list of groups
+ */
+//================================================================================
+
+SMESH::ListOfGroups * SMESH_Mesh_i::GetGroups() throw(SALOME::SALOME_Exception)
+{
+  Unexpect aCatch(SALOME_SalomeException);
+  if (MYDEBUG) MESSAGE("GetGroups");
+
+  SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
+  // Python Dump
+  TPythonDump aPythonDump;
+  aPythonDump << "[ ";
+
+  try {
+    aList->length( _mapGroups.size() );
+    int i = 0;
+    map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
+    for ( ; it != _mapGroups.end(); it++ ) {
+      if ( CORBA::is_nil( it->second )) continue;
+      aList[i++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
+      // Python Dump
+      if (i > 1) aPythonDump << ", ";
+      aPythonDump << it->second;
+    }
+    aList->length( i );
+  }
+  catch(SALOME_Exception & S_ex) {
+    THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
+  }
+
+  // Update Python script
+  aPythonDump << " ] = " << _this() << ".GetGroups()";
+
+  return aList._retn();
+}
+
 //=============================================================================
 /*! UnionGroups
  *  New group is created. All mesh elements that are
index 7b82637cef3ba491735aa42031ecd5cd127c72cf..e2fde0283968cc148ac0156102867ea901698ca9 100644 (file)
@@ -99,6 +99,9 @@ public:
   void RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
     throw (SALOME::SALOME_Exception);
   
+  SMESH::ListOfGroups* GetGroups()
+    throw (SALOME::SALOME_Exception);
+
   SMESH::SMESH_Group_ptr UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1, 
                                       SMESH::SMESH_GroupBase_ptr theGroup2, 
                                       const char* theName )