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);
#include "DriverCGNS_Write.hxx"
+#include "SMDS_IteratorOnIterators.hxx"
#include "SMDS_MeshNode.hxx"
#include "SMDS_VolumeTool.hxx"
#include "SMESHDS_GroupBase.hxx"
// 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 )
{
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;
cgID-1, /*nbndry=*/0, &elemData[0], &iSec) != CG_OK )
return addMessage( cg_get_error(), /*fatal = */true );
}
+
// Write polyhedral volumes
// -------------------------
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() ) {
location = CGNS_ENUMV( EdgeCenter ); break; // ???
break;
}
+#endif
}
// try to extract type of boundary condition from the group name
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 )
*/
//================================================================================
-DriverCGNS_Write::DriverCGNS_Write(): _fn(0)
+DriverCGNS_Write::DriverCGNS_Write(): _fn(0), _elementsByType( false )
{
}
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
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++ ) {
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");
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 );
}
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() )
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;
}
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 =
}
toCreateGroups = fd->IsChecked(0);
toFindOutDim = fd->IsChecked(1);
- fieldSelWdg->GetSelectedFeilds();
+ fieldSelWdg->GetSelectedFields();
if ( !fieldSelWdg->parent() )
delete fieldSelWdg;
delete fd;
SMESH::SMESH_Mesh_var aMeshItem = aMeshOrGroup->GetMesh();
aMeshItem->ExportCGNS( aMeshOrGroup,
aFilename.toUtf8().data(),
- toOverwrite && aMeshIndex == 0 );
+ toOverwrite && aMeshIndex == 0,
+ toCreateGroups );
}
}
else if ( isGMF )
* \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;
/*!
* \brief Filter off not selected fields from myFields
*/
-bool SMESHGUI_FieldSelectorWdg::GetSelectedFeilds()
+bool SMESHGUI_FieldSelectorWdg::GetSelectedFields()
{
int nbSelected = 0;
if ( myTree->isEnabled() )
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:
<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>
#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 \
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
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 << ")";
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);
# @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 )
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
# @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() )