IPAL54303: CGNS export problems

This commit is contained in:
eap 2017-08-25 16:45:03 +03:00
parent 7c1bf48314
commit 223c5b7f5d
13 changed files with 115 additions and 21 deletions

View File

@ -715,7 +715,8 @@ module SMESH
in boolean isascii ) raises (SALOME::SALOME_Exception);
void ExportCGNS( in SMESH_IDSource meshPart,
in string file,
in boolean overwrite ) raises (SALOME::SALOME_Exception);
in boolean overwrite,
in boolean groupElemsByType) raises (SALOME::SALOME_Exception);
void ExportGMF( in SMESH_IDSource meshPart,
in string file,
in boolean withRequiredGroups) raises (SALOME::SALOME_Exception);

View File

@ -25,6 +25,7 @@
#include "DriverCGNS_Write.hxx"
#include "SMDS_IteratorOnIterators.hxx"
#include "SMDS_MeshNode.hxx"
#include "SMDS_VolumeTool.hxx"
#include "SMESHDS_GroupBase.hxx"
@ -330,7 +331,24 @@ Driver_Mesh::Status DriverCGNS_Write::Perform()
// write into a section all successive elements of one geom type
int iSec;
vector< cgsize_t > elemData;
SMDS_ElemIteratorPtr elemIt = myMesh->elementsIterator();
SMDS_ElemIteratorPtr elemIt = myMesh->elementsIterator();
vector< SMDS_ElemIteratorPtr > elemItVec;
if ( _elementsByType )
{
// create an iterator returning all elements by type
for ( int type = SMDSEntity_Node + 1; type < SMDSEntity_Last; ++type )
{
if ( type == SMDSEntity_Ball )
continue; // not supported
elemIt = myMesh->elementEntityIterator( SMDSAbs_EntityType( type ));
if ( elemIt->more() )
elemItVec.push_back( elemIt );
}
typedef SMDS_IteratorOnIterators< const SMDS_MeshElement*,
vector< SMDS_ElemIteratorPtr > > TVecIterator;
elemIt.reset( new TVecIterator( elemItVec ));
}
const SMDS_MeshElement* elem = elemIt->next();
while ( elem )
{
@ -397,6 +415,15 @@ Driver_Mesh::Status DriverCGNS_Write::Perform()
elem = elemIt->more() ? elemIt->next() : 0;
continue;
}
else // skip NOT SUPPORTED elements
{
while ( elemIt->more() )
{
elem = elemIt->next();
if ( elem->GetEntityType() != elemType )
break;
}
}
SMESH_Comment sectionName( cg_ElementTypeName( cgType ));
sectionName << " " << startID << " - " << cgID-1;
@ -405,6 +432,7 @@ Driver_Mesh::Status DriverCGNS_Write::Perform()
cgID-1, /*nbndry=*/0, &elemData[0], &iSec) != CG_OK )
return addMessage( cg_get_error(), /*fatal = */true );
}
// Write polyhedral volumes
// -------------------------
@ -531,6 +559,9 @@ Driver_Mesh::Status DriverCGNS_Write::Perform()
CGNS_ENUMT( GridLocation_t ) location = CGNS_ENUMV( Vertex );
if ( group->GetType() != SMDSAbs_Node )
{
#if CGNS_VERSION > 3130
location = CGNS_ENUMV( CellCenter );
#else
switch ( meshDim ) {
case 3:
switch ( group->GetType() ) {
@ -551,6 +582,7 @@ Driver_Mesh::Status DriverCGNS_Write::Perform()
location = CGNS_ENUMV( EdgeCenter ); break; // ???
break;
}
#endif
}
// try to extract type of boundary condition from the group name
@ -568,6 +600,8 @@ Driver_Mesh::Status DriverCGNS_Write::Perform()
const SMDS_MeshElement* elem = elemIt->next();
pnts.push_back( cgnsID( elem, elem2cgIDByEntity[ elem->GetEntityType() ]));
}
if ( pnts.size() == 0 )
continue; // can't store empty group
int iBC;
if ( cg_boco_write( _fn, iBase, iZone, name.c_str(), bcType,
CGNS_ENUMV( PointList ), pnts.size(), &pnts[0], &iBC) != CG_OK )
@ -589,7 +623,7 @@ Driver_Mesh::Status DriverCGNS_Write::Perform()
*/
//================================================================================
DriverCGNS_Write::DriverCGNS_Write(): _fn(0)
DriverCGNS_Write::DriverCGNS_Write(): _fn(0), _elementsByType( false )
{
}

View File

@ -45,9 +45,16 @@ public:
virtual Status Perform();
// to export elements either in the order of their IDs or by geometric type
void SetElementsByType( bool isByType ) { _elementsByType = isByType; }
private:
int _fn; //!< file index
// if true all elements of same geometry are exported at ones,
// else elements are exported in order of their IDs
bool _elementsByType;
};
#endif

View File

@ -1537,6 +1537,7 @@ void SMESH_Mesh::ExportUNV(const char * file,
myWriter.SetMeshId(_id);
// myWriter.SetGroups(_mapGroup);
// pass group names to SMESHDS
if ( !meshPart )
{
for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
@ -1581,17 +1582,37 @@ void SMESH_Mesh::ExportSTL(const char * file,
void SMESH_Mesh::ExportCGNS(const char * file,
const SMESHDS_Mesh* meshDS,
const char * meshName)
const char * meshName,
const bool groupElemsByType)
{
int res = Driver_Mesh::DRS_FAIL;
// pass group names to SMESHDS
for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
SMESH_Group* group = it->second;
SMESHDS_GroupBase* groupDS = group->GetGroupDS();
if ( groupDS ) {
string groupName = group->GetName();
groupDS->SetStoreName( groupName.c_str() );
}
}
#ifdef WITH_CGNS
DriverCGNS_Write myWriter;
myWriter.SetFile( file );
myWriter.SetMesh( const_cast<SMESHDS_Mesh*>( meshDS ));
myWriter.SetMeshName( SMESH_Comment("Mesh_") << meshDS->GetPersistentId());
if ( meshName && meshName[0] )
myWriter.SetMeshName( meshName );
myWriter.SetElementsByType( groupElemsByType );
res = myWriter.Perform();
if ( res != Driver_Mesh::DRS_OK )
{
SMESH_ComputeErrorPtr err = myWriter.GetError();
if ( err && !err->IsOK() && !err->myComment.empty() )
throw SALOME_Exception(("Export failed: " + err->myComment ).c_str() );
}
#endif
if ( res != Driver_Mesh::DRS_OK )
throw SALOME_Exception("Export failed");

View File

@ -267,7 +267,8 @@ class SMESH_EXPORT SMESH_Mesh
const SMESHDS_Mesh* meshPart = 0) throw(SALOME_Exception);
void ExportCGNS(const char * file,
const SMESHDS_Mesh* mesh,
const char * meshName = 0);
const char * meshName = 0,
const bool groupElemsByType = false);
void ExportGMF(const char * file,
const SMESHDS_Mesh* mesh,
bool withRequiredGroups = true );

View File

@ -684,7 +684,14 @@ namespace
}
else if ( isCGNS )// Export to CGNS
{
SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
const char* theByTypeResource = "cgns_group_elems_by_type";
toCreateGroups = SMESHGUI::resourceMgr()->booleanValue( "SMESH", theByTypeResource, false );
QStringList checkBoxes;
checkBoxes << QObject::tr("CGNS_EXPORT_ELEMS_BY_TYPE");
SalomeApp_CheckFileDlg* fd =
new SalomeApp_CheckFileDlg ( SMESHGUI::desktop(), false, checkBoxes, true, true );
fd->setWindowTitle( aTitle );
fd->setNameFilter( QObject::tr( "CGNS_FILES_FILTER" ) + " (*.cgns)" );
if ( !anInitialPath.isEmpty() )
@ -692,10 +699,13 @@ namespace
fd->selectFile(aMeshName);
SMESHGUI_FileValidator* fv = new SMESHGUI_FileValidator( fd );
fd->setValidator( fv );
fd->SetChecked( toCreateGroups, 0 );
if ( fd->exec() )
aFilename = fd->selectedFile();
toOverwrite = fv->isOverwrite();
toOverwrite = fv->isOverwrite();
toCreateGroups = fd->IsChecked(0);
SMESHGUI::resourceMgr()->setValue("SMESH", theByTypeResource, toCreateGroups );
delete fd;
}
@ -754,7 +764,7 @@ namespace
SMESHGUI_FieldSelectorWdg* fieldSelWdg = new SMESHGUI_FieldSelectorWdg();
QList< QWidget* > wdgList;
if ( fieldSelWdg->GetAllFeilds( aMeshList, aFieldList ))
if ( fieldSelWdg->GetAllFields( aMeshList, aFieldList ))
wdgList.append( fieldSelWdg );
SalomeApp_CheckFileDlg* fd =
@ -858,7 +868,7 @@ namespace
}
toCreateGroups = fd->IsChecked(0);
toFindOutDim = fd->IsChecked(1);
fieldSelWdg->GetSelectedFeilds();
fieldSelWdg->GetSelectedFields();
if ( !fieldSelWdg->parent() )
delete fieldSelWdg;
delete fd;
@ -948,7 +958,8 @@ namespace
SMESH::SMESH_Mesh_var aMeshItem = aMeshOrGroup->GetMesh();
aMeshItem->ExportCGNS( aMeshOrGroup,
aFilename.toUtf8().data(),
toOverwrite && aMeshIndex == 0 );
toOverwrite && aMeshIndex == 0,
toCreateGroups );
}
}
else if ( isGMF )

View File

@ -86,7 +86,7 @@ SMESHGUI_FieldSelectorWdg::SMESHGUI_FieldSelectorWdg( QWidget* p )
* \brief Retrieves all fields defined on geometry of given meshes
*/
bool SMESHGUI_FieldSelectorWdg::
GetAllFeilds(const QList< QPair< SMESH::SMESH_IDSource_var, QString > >& meshes,
GetAllFields(const QList< QPair< SMESH::SMESH_IDSource_var, QString > >& meshes,
QList< QPair< GEOM::ListOfFields_var, QString > >& fields)
{
myFields = & fields;
@ -166,7 +166,7 @@ GetAllFeilds(const QList< QPair< SMESH::SMESH_IDSource_var, QString > >& meshes,
/*!
* \brief Filter off not selected fields from myFields
*/
bool SMESHGUI_FieldSelectorWdg::GetSelectedFeilds()
bool SMESHGUI_FieldSelectorWdg::GetSelectedFields()
{
int nbSelected = 0;
if ( myTree->isEnabled() )

View File

@ -43,13 +43,13 @@ class SMESHGUI_EXPORT SMESHGUI_FieldSelectorWdg : public QGroupBox
public:
SMESHGUI_FieldSelectorWdg( QWidget* = 0 );
bool GetAllFeilds(const QList< QPair< SMESH::SMESH_IDSource_var, QString > >& meshes,
bool GetAllFields(const QList< QPair< SMESH::SMESH_IDSource_var, QString > >& meshes,
QList< QPair< GEOM::ListOfFields_var, QString > >& fields);
bool GetSelectedFeilds();
bool GetSelectedFields();
private slots:
void onItemCheck(QTreeWidgetItem * item, int column);
private:

View File

@ -39,6 +39,10 @@
<source>CGNS_FILES_FILTER</source>
<translation>CGNS files</translation>
</message>
<message>
<source>CGNS_EXPORT_ELEMS_BY_TYPE</source>
<translation>Group elements by type</translation>
</message>
<message>
<source>GMF_ASCII_FILES_FILTER</source>
<translation>GMF ASCII files</translation>

View File

@ -42,7 +42,11 @@
#define OCC_CATCH_SIGNALS
#endif
// Define macros to catch and convert some of possible exceptions into text or SALOME_Exception
// Define macros to catch and convert some of possible exceptions into text or SALOME_Exception.
// WARNING: SALOME::SALOME_Exception (CORBA exception) is not treated here; to care about it add
// #define SMY_OWN_CATCH catch ( SALOME::SALOME_Exception & e ) { do_something(e); }
// before #include<SMESH_TryCatch.hxx>
//-------------------------------------------------------------------------------------
#define SMESH_TRY \

View File

@ -3628,7 +3628,8 @@ void SMESH_Mesh_i::ExportPartToSTL(::SMESH::SMESH_IDSource_ptr meshPart,
void SMESH_Mesh_i::ExportCGNS(::SMESH::SMESH_IDSource_ptr meshPart,
const char* file,
CORBA::Boolean overwrite)
CORBA::Boolean overwrite,
CORBA::Boolean groupElemsByType)
throw (SALOME::SALOME_Exception)
{
#ifdef WITH_CGNS
@ -3646,8 +3647,12 @@ void SMESH_Mesh_i::ExportCGNS(::SMESH::SMESH_IDSource_ptr meshPart,
CORBA::String_var name = so->GetName();
meshName = name.in();
}
SMESH_TRY;
SMESH_MeshPartDS partDS( meshPart );
_impl->ExportCGNS(file, &partDS, meshName.c_str() );
_impl->ExportCGNS(file, &partDS, meshName.c_str(), groupElemsByType );
SMESH_CATCH( SMESH::throwCorbaException );
TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportCGNS( "
<< meshPart<< ", r'" << file << "', " << overwrite << ")";

View File

@ -251,7 +251,8 @@ public:
void ExportSTL( const char* file, bool isascii ) throw (SALOME::SALOME_Exception);
void ExportCGNS(SMESH::SMESH_IDSource_ptr meshPart,
const char* file,
CORBA::Boolean overwrite) throw (SALOME::SALOME_Exception);
CORBA::Boolean overwrite,
CORBA::Boolean groupElemsByType) throw (SALOME::SALOME_Exception);
void ExportGMF(SMESH::SMESH_IDSource_ptr meshPart,
const char* file,
CORBA::Boolean withRequiredGroups) throw (SALOME::SALOME_Exception);

View File

@ -1879,8 +1879,11 @@ class Mesh:
# @param f is the file name
# @param overwrite boolean parameter for overwriting/not overwriting the file
# @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
# @param groupElemsByType if true all elements of same entity type are exported at ones,
# else elements are exported in order of their IDs which can cause creation
# of multiple cgns sections
# @ingroup l2_impexp
def ExportCGNS(self, f, overwrite=1, meshPart=None):
def ExportCGNS(self, f, overwrite=1, meshPart=None, groupElemsByType=False):
unRegister = genObjUnRegister()
if isinstance( meshPart, list ):
meshPart = self.GetIDSource( meshPart, SMESH.ALL )
@ -1889,7 +1892,7 @@ class Mesh:
meshPart = meshPart.mesh
elif not meshPart:
meshPart = self.mesh
self.mesh.ExportCGNS(meshPart, f, overwrite)
self.mesh.ExportCGNS(meshPart, f, overwrite, groupElemsByType)
## Export the mesh in a file in GMF format.
# GMF files must have .mesh extension for the ASCII format and .meshb for
@ -2010,6 +2013,8 @@ class Mesh:
# @ingroup l2_grps_create
def MakeGroupByIds(self, groupName, elementType, elemIDs):
group = self.mesh.CreateGroup(elementType, groupName)
if isinstance( elemIDs, Mesh ):
elemIDs = elemIDs.GetMesh()
if hasattr( elemIDs, "GetIDs" ):
if hasattr( elemIDs, "SetMesh" ):
elemIDs.SetMesh( self.GetMesh() )