From: eap Date: Thu, 4 May 2006 17:09:38 +0000 (+0000) Subject: fix bug 10638: add and use SMESH_Mesh::GetGroups() allowing correct PythonDump of... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=22967ffd3fa3dadbe4811aba01ed79c3940b3193;p=modules%2Fsmesh.git fix bug 10638: add and use SMESH_Mesh::GetGroups() allowing correct PythonDump of groups of imported mesh --- diff --git a/src/SMESH_I/SMESH_Gen_i.cxx b/src/SMESH_I/SMESH_Gen_i.cxx index a5e803837..93d657e20 100644 --- a/src/SMESH_I/SMESH_Gen_i.cxx +++ b/src/SMESH_I/SMESH_Gen_i.cxx @@ -699,6 +699,10 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromUNV( const char* theFileName SMESH_Mesh_i* aServant = dynamic_cast( 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 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(); } diff --git a/src/SMESH_I/SMESH_Mesh_i.cxx b/src/SMESH_I/SMESH_Mesh_i.cxx index 4ef420bda..fc489aa0c 100644 --- a/src/SMESH_I/SMESH_Mesh_i.cxx +++ b/src/SMESH_I/SMESH_Mesh_i.cxx @@ -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::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 diff --git a/src/SMESH_I/SMESH_Mesh_i.hxx b/src/SMESH_I/SMESH_Mesh_i.hxx index 7b82637ce..e2fde0283 100644 --- a/src/SMESH_I/SMESH_Mesh_i.hxx +++ b/src/SMESH_I/SMESH_Mesh_i.hxx @@ -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 )