}
}
+/*!
+ Return a MeshName
+ */
+std::string SMESH_Mesh_i::generateMeshName()
+{
+ string aMeshName = "Mesh";
+ SALOMEDS::Study_var aStudy = SMESH_Gen_i::GetSMESHGen()->getStudyServant();
+ if ( !aStudy->_is_nil() )
+ {
+ SALOMEDS::SObject_wrap aMeshSO = _gen_i->ObjectToSObject( _this() );
+ if ( !aMeshSO->_is_nil() )
+ {
+ CORBA::String_var name = aMeshSO->GetName();
+ aMeshName = name;
+ }
+ }
+ return aMeshName;
+}
+
//================================================================================
/*!
* \brief Prepare a file for export and pass names of mesh groups from study to mesh DS
{
// Perform Export
PrepareForWriting(file, overwrite);
- string aMeshName = "Mesh";
+ string aMeshName(this->generateMeshName());
SALOMEDS::Study_var aStudy = SMESH_Gen_i::GetSMESHGen()->getStudyServant();
if ( !aStudy->_is_nil() ) {
SALOMEDS::SObject_wrap aMeshSO = _gen_i->ObjectToSObject( _this() );
if ( !aMeshSO->_is_nil() ) {
- CORBA::String_var name = aMeshSO->GetName();
- aMeshName = name;
// asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
if ( !aStudy->GetProperties()->IsLocked() )
{
SMESH_CATCH( SMESH::throwCorbaException );
}
+CORBA::LongLong SMESH_Mesh_i::ExportMEDCoupling(CORBA::Boolean auto_groups, CORBA::Boolean autoDimension)
+{
+ MEDCoupling::MCAuto<MEDCoupling::DataArrayByte> data;
+ SMESH_TRY;
+ // TODO : Fix me ! 2 next lines are required
+ if( !this->_gen_i->isSSLMode() )
+ SMESH::throwCorbaException("SMESH_Mesh_i::ExportMEDCoupling : only for embedded mode !");
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ string aMeshName = this->generateMeshName();
+ data = _impl->ExportMEDCoupling( aMeshName.c_str(), auto_groups, 0, autoDimension );
+ SMESH_CATCH( SMESH::throwCorbaException );
+ MEDCoupling::DataArrayByte *ret(data.retn());
+ return reinterpret_cast<CORBA::LongLong>(ret);
+}
+
//================================================================================
/*!
* \brief Export a mesh to a SAUV file
*/
//================================================================================
-void SMESH_Mesh_i::ExportDAT (const char *file)
+void SMESH_Mesh_i::ExportDAT (const char *file, CORBA::Boolean renumber )
{
SMESH_TRY;
if ( _preMeshInfo )
// check names of groups
checkGroupNames();
// Update Python script
- TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportDAT( r'" << file << "' )";
+ TPythonDump() << SMESH::SMESH_Mesh_var(_this())
+ << ".ExportDAT( r'" << file<< ", " << renumber << "' )";
// Perform Export
- PrepareForWriting(file);
- _impl->ExportDAT(file);
+ PrepareForWriting( file );
+ _impl->ExportDAT( file, /*part=*/nullptr, renumber );
SMESH_CATCH( SMESH::throwCorbaException );
}
*/
//================================================================================
-void SMESH_Mesh_i::ExportUNV (const char *file)
+void SMESH_Mesh_i::ExportUNV (const char *file, CORBA::Boolean renumber)
{
SMESH_TRY;
if ( _preMeshInfo )
// check names of groups
checkGroupNames();
// Update Python script
- TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportUNV( r'" << file << "' )";
+ TPythonDump() << SMESH::SMESH_Mesh_var(_this())
+ << ".ExportUNV( r'" << file << "' " << renumber << "' )";
// Perform Export
- PrepareForWriting(file);
- _impl->ExportUNV(file);
+ PrepareForWriting( file );
+ _impl->ExportUNV( file, /*part=*/nullptr, renumber );
SMESH_CATCH( SMESH::throwCorbaException );
}
SMESH_CATCH( SMESH::throwCorbaException );
}
+//================================================================================
+
+class MEDFileSpeCls
+{
+public:
+ MEDFileSpeCls(const char * file,
+ CORBA::Boolean overwrite,
+ CORBA::Long version)
+ :_file(file), _overwrite(overwrite), _version(version)
+ {}
+ std::string prepareMeshNameAndGroups(SMESH_Mesh_i& self)
+ {
+ return self.prepareMeshNameAndGroups(_file.c_str(),_overwrite);
+ }
+
+ void exportTo(SMESH_Mesh *mesh, const std::string& aMeshName, CORBA::Boolean auto_groups,
+ SMESH_MeshPartDS* partDS, CORBA::Boolean autoDimension, bool have0dField,
+ CORBA::Double ZTolerance, CORBA::Boolean saveNumbers )
+ {
+ mesh->ExportMED( _file.c_str(), aMeshName.c_str(), auto_groups, _version,
+ partDS, autoDimension, have0dField, ZTolerance, saveNumbers );
+ }
+
+ void exportField(SMESH_Mesh_i& self, const std::string& aMeshName, bool have0dField,
+ SMESHDS_Mesh *meshDS, const GEOM::ListOfFields& fields,
+ const char*geomAssocFields)
+ {
+ DriverMED_W_Field fieldWriter;
+ fieldWriter.SetFile( _file.c_str() );
+ fieldWriter.SetMeshName( aMeshName );
+ fieldWriter.AddODOnVertices( have0dField );
+ self.exportMEDFields( fieldWriter, meshDS, fields, geomAssocFields );
+ }
+
+ void prepareForWriting(SMESH_Mesh_i& self) { self.PrepareForWriting(_file.c_str(), _overwrite); }
+
+private:
+ std::string _file;
+ CORBA::Boolean _overwrite;
+ CORBA::Long _version;
+};
+
//================================================================================
/*!
* \brief Export a part of mesh to a med file
*/
//================================================================================
-void SMESH_Mesh_i::ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart,
- const char* file,
- CORBA::Boolean auto_groups,
- CORBA::Long version,
- CORBA::Boolean overwrite,
- CORBA::Boolean autoDimension,
- const GEOM::ListOfFields& fields,
- const char* geomAssocFields,
- CORBA::Double ZTolerance)
+template<class SPECLS>
+void SMESH_Mesh_i::ExportPartToMEDCommon(SPECLS& speCls,
+ SMESH::SMESH_IDSource_ptr meshPart,
+ CORBA::Boolean auto_groups,
+ CORBA::Boolean autoDimension,
+ const GEOM::ListOfFields& fields,
+ const char* geomAssocFields,
+ CORBA::Double ZTolerance,
+ CORBA::Boolean saveNumbers)
{
- MESSAGE("MED version: "<< version);
SMESH_TRY;
if ( _preMeshInfo )
_preMeshInfo->FullLoadFromFile();
if ( fieldShape->_is_nil() )
THROW_SALOME_CORBA_EXCEPTION( "Null shape under a field", SALOME::INTERNAL_ERROR );
if ( !fieldShape->IsSame( shapeToMesh ) )
- THROW_SALOME_CORBA_EXCEPTION
- ( "Field defined not on shape", SALOME::BAD_PARAM);
+ THROW_SALOME_CORBA_EXCEPTION( "Field defined not on shape", SALOME::BAD_PARAM);
if ( fields[i]->GetDimension() == 0 )
have0dField = true;
}
if ( CORBA::is_nil( meshPart ) ||
SMESH::DownCast< SMESH_Mesh_i* >( meshPart ))
{
- aMeshName = prepareMeshNameAndGroups(file, overwrite);
- _impl->ExportMED( file, aMeshName.c_str(), auto_groups, version,
- 0, autoDimension, /*addODOnVertices=*/have0dField,
- ZTolerance);
+ aMeshName = speCls.prepareMeshNameAndGroups(*this);
+ speCls.exportTo(_impl, aMeshName, auto_groups, nullptr, autoDimension,
+ have0dField, ZTolerance, saveNumbers );
meshDS = _impl->GetMeshDS();
}
else
if ( _preMeshInfo )
_preMeshInfo->FullLoadFromFile();
- PrepareForWriting(file, overwrite);
+ speCls.prepareForWriting(*this);
SALOMEDS::SObject_wrap SO = _gen_i->ObjectToSObject( meshPart );
if ( !SO->_is_nil() ) {
}
SMESH_MeshPartDS* partDS = new SMESH_MeshPartDS( meshPart );
- _impl->ExportMED( file, aMeshName.c_str(), auto_groups, version,
- partDS, autoDimension, /*addODOnVertices=*/have0dField, ZTolerance);
+ speCls.exportTo(_impl, aMeshName, auto_groups, partDS, autoDimension,
+ have0dField, ZTolerance, saveNumbers);
meshDS = tmpDSDeleter._obj = partDS;
}
if ( _impl->HasShapeToMesh() )
{
- DriverMED_W_Field fieldWriter;
- fieldWriter.SetFile( file );
- fieldWriter.SetMeshName( aMeshName );
- fieldWriter.AddODOnVertices( have0dField );
-
- exportMEDFields( fieldWriter, meshDS, fields, geomAssocFields );
+ speCls.exportField( *this, aMeshName, have0dField, meshDS, fields, geomAssocFields);
}
+ SMESH_CATCH( SMESH::throwCorbaException );
+}
+//================================================================================
+/*!
+ * \brief Export a part of mesh to a med file
+ */
+//================================================================================
+
+void SMESH_Mesh_i::ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart,
+ const char* file,
+ CORBA::Boolean auto_groups,
+ CORBA::Long version,
+ CORBA::Boolean overwrite,
+ CORBA::Boolean autoDimension,
+ const GEOM::ListOfFields& fields,
+ const char* geomAssocFields,
+ CORBA::Double ZTolerance,
+ CORBA::Boolean saveNumbers)
+{
+ MESSAGE("MED version: "<< version);
+
+ MEDFileSpeCls spe( file, overwrite, version );
+ this->ExportPartToMEDCommon( spe, meshPart, auto_groups, autoDimension, fields,
+ geomAssocFields, ZTolerance, saveNumbers );
// dump
+ SMESH_TRY;
GEOM::ListOfGBO_var goList = new GEOM::ListOfGBO;
goList->length( fields.length() );
for ( size_t i = 0; i < fields.length(); ++i )
<< autoDimension << ", "
<< goList << ", '"
<< ( geomAssocFields ? geomAssocFields : "" ) << "',"
- << TVar( ZTolerance )
+ << TVar( ZTolerance ) << ", "
+ << saveNumbers
<< " )";
+ SMESH_CATCH( SMESH::throwCorbaException );
+}
+
+//================================================================================
+
+class MEDFileMemSpeCls
+{
+public:
+ std::string prepareMeshNameAndGroups(SMESH_Mesh_i& self) { return self.generateMeshName(); }
+
+ void exportTo(SMESH_Mesh *mesh, const std::string& aMeshName, CORBA::Boolean auto_groups,
+ SMESH_MeshPartDS* partDS, CORBA::Boolean autoDimension, bool have0dField,
+ CORBA::Double ZTolerance, CORBA::Boolean saveNumbers )
+ {
+ _res = mesh->ExportMEDCoupling(aMeshName.c_str(), auto_groups, partDS,
+ autoDimension, have0dField, ZTolerance, saveNumbers );
+ }
+ void prepareForWriting(SMESH_Mesh_i& /*self*/) { /* nothing here */ }
+
+ void exportField(SMESH_Mesh_i& self, const std::string& aMeshName, bool have0dField,
+ SMESHDS_Mesh *meshDS, const GEOM::ListOfFields& fields,
+ const char*geomAssocFields)
+ {
+ DriverMED_W_Field_Mem fieldWriter(_res);
+ fieldWriter.SetMeshName( aMeshName );
+ fieldWriter.AddODOnVertices( have0dField );
+ self.exportMEDFields( fieldWriter, meshDS, fields, geomAssocFields );
+ _res = fieldWriter.getData();
+ }
+public:
+ MEDCoupling::MCAuto<MEDCoupling::DataArrayByte> getData() { return _res; }
+
+private:
+ MEDCoupling::MCAuto<MEDCoupling::DataArrayByte> _res;
+};
+
+//================================================================================
+/*!
+ * \brief Export a part of mesh to a MEDCoupling DS
+ */
+//================================================================================
+
+CORBA::LongLong SMESH_Mesh_i::ExportPartToMEDCoupling(SMESH::SMESH_IDSource_ptr meshPart,
+ CORBA::Boolean auto_groups,
+ CORBA::Boolean autoDimension,
+ const GEOM::ListOfFields& fields,
+ const char* geomAssocFields,
+ CORBA::Double ZTolerance,
+ CORBA::Boolean saveNumbers)
+{
+ MEDCoupling::MCAuto<MEDCoupling::DataArrayByte> data;
+
+ SMESH_TRY;
+ if( !this->_gen_i->isSSLMode() )
+ SMESH::throwCorbaException("SMESH_Mesh_i::ExportPartToMEDCoupling : only for embedded mode !");
+
+ MEDFileMemSpeCls spe;
+ this->ExportPartToMEDCommon( spe, meshPart, auto_groups, autoDimension, fields, geomAssocFields,
+ ZTolerance, saveNumbers );
+ data = spe.getData();
SMESH_CATCH( SMESH::throwCorbaException );
+
+ MEDCoupling::DataArrayByte *ret(data.retn());
+ return reinterpret_cast<CORBA::LongLong>(ret);
}
//================================================================================
*/
//================================================================================
-void SMESH_Mesh_i::ExportPartToDAT(::SMESH::SMESH_IDSource_ptr meshPart,
- const char* file)
+void SMESH_Mesh_i::ExportPartToDAT(SMESH::SMESH_IDSource_ptr meshPart,
+ const char* file,
+ CORBA::Boolean renumber )
{
SMESH_TRY;
- if ( _preMeshInfo )
- _preMeshInfo->FullLoadFromFile();
-
- PrepareForWriting(file);
SMESH_MeshPartDS partDS( meshPart );
- _impl->ExportDAT(file,&partDS);
+ _impl->ExportDAT( file, &partDS, renumber );
TPythonDump() << SMESH::SMESH_Mesh_var(_this())
- << ".ExportPartToDAT( " << meshPart << ", r'" << file << "' )";
+ << ".ExportPartToDAT( " << meshPart << ", r'" << file << ", " << renumber << "' )";
SMESH_CATCH( SMESH::throwCorbaException );
}
*/
//================================================================================
-void SMESH_Mesh_i::ExportPartToUNV(::SMESH::SMESH_IDSource_ptr meshPart,
- const char* file)
+void SMESH_Mesh_i::ExportPartToUNV(SMESH::SMESH_IDSource_ptr meshPart,
+ const char* file,
+ CORBA::Boolean renumber)
{
SMESH_TRY;
if ( _preMeshInfo )
PrepareForWriting(file);
SMESH_MeshPartDS partDS( meshPart );
- _impl->ExportUNV(file, &partDS);
+ _impl->ExportUNV(file, &partDS, renumber );
TPythonDump() << SMESH::SMESH_Mesh_var(_this())
- << ".ExportPartToUNV( " << meshPart<< ", r'" << file << "' )";
+ << ".ExportPartToUNV( " << meshPart<< ", r'" << file << ", " << renumber << "' )";
SMESH_CATCH( SMESH::throwCorbaException );
}
if ( const SMDS_MeshElement* elem = aMeshDS->FindElement(id) )
{
aResult->length( elem->NbNodes() );
- for ( SMESH::smIdType i = 0; i < aResult->length(); ++i )
+ for ( CORBA::ULong i = 0; i < aResult->length(); ++i )
if ( const SMDS_MeshNode* n = elem->GetNode( i ))
aResult[ i ] = n->GetID();
}
{
aResult->length( vtool.NbFaceNodes( faceIndex ));
const SMDS_MeshNode** nn = vtool.GetFaceNodes( faceIndex );
- for ( SMESH::smIdType i = 0; i < aResult->length(); ++i )
+ for ( CORBA::ULong i = 0; i < aResult->length(); ++i )
aResult[ i ] = nn[ i ]->GetID();
}
}
if ( SMESHDS_Mesh* mesh = _impl->GetMeshDS() )
{
vector< const SMDS_MeshNode * > nn( nodes.length() );
- for ( SMESH::smIdType i = 0; i < nodes.length(); ++i )
+ for ( CORBA::ULong i = 0; i < nodes.length(); ++i )
nn[i] = mesh->FindNode( nodes[i] );
std::vector<const SMDS_MeshElement *> elems;