{
MEDCoupling::MCAuto<MEDCoupling::DataArrayByte> data;
SMESH_TRY;
- if( !this->_gen_i->IsEmbeddedMode() )
- SMESH::throwCorbaException("SMESH_Mesh_i::ExportMEDCoupling : only for embedded mode !");
+ // TODO : Fix me ! 2 next lines are required
+ //if( !this->_gen_i->IsEmbeddedMode() )
+ // SMESH::throwCorbaException("SMESH_Mesh_i::ExportMEDCoupling : only for embedded mode !");
if ( _preMeshInfo )
_preMeshInfo->FullLoadFromFile();
SMESH_CATCH( SMESH::throwCorbaException );
}
-//================================================================================
-/*!
- * \brief Export a part of mesh to a med file
- */
-//================================================================================
+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)
+ {
+ mesh->ExportMED( _file.c_str(), aMeshName.c_str(), auto_groups, _version,
+ partDS, autoDimension,have0dField,ZTolerance);
-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)
+ }
+
+ 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;
+};
+
+
+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)
{
- MESSAGE("MED version: "<< version);
SMESH_TRY;
if ( _preMeshInfo )
_preMeshInfo->FullLoadFromFile();
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);
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);
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)
+{
+ MESSAGE("MED version: "<< version);
+ MEDFileSpeCls spe(file,overwrite,version);
+ this->ExportPartToMEDCommon<MEDFileSpeCls>(spe,meshPart,auto_groups,autoDimension,fields,geomAssocFields,ZTolerance);
// dump
+ SMESH_TRY;
GEOM::ListOfGBO_var goList = new GEOM::ListOfGBO;
goList->length( fields.length() );
for ( size_t i = 0; i < fields.length(); ++i )
<< ( geomAssocFields ? geomAssocFields : "" ) << "',"
<< TVar( ZTolerance )
<< " )";
-
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)
+ {
+ _res = mesh->ExportMEDCoupling(aMeshName.c_str(),auto_groups,partDS,autoDimension,have0dField,ZTolerance);
+ }
+ 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)
+ {
+ THROW_IK_EXCEPTION("exportField Not implemented yet for full memory !");
+ }
+public:
+ MEDCoupling::MCAuto<MEDCoupling::DataArrayByte> getData() { return _res; }
+private:
+ MEDCoupling::MCAuto<MEDCoupling::DataArrayByte> _res;
+};
+
+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)
+{
+ MEDFileMemSpeCls spe;
+ this->ExportPartToMEDCommon<MEDFileMemSpeCls>(spe,meshPart,auto_groups,autoDimension,fields,geomAssocFields,ZTolerance);
+ MEDCoupling::MCAuto<MEDCoupling::DataArrayByte> res( spe.getData() );
+ MEDCoupling::DataArrayByte *ret(res.retn());
+ return reinterpret_cast<CORBA::LongLong>(ret);
+}
+
//================================================================================
/*!
* Write GEOM fields to MED file
const char* file,
CORBA::Boolean withRequiredGroups);
+
+ template<class SPECLS>
+ void ExportPartToMEDCommon(SPECLS& speCls,
+ SMESH::SMESH_IDSource_ptr meshPart,
+ CORBA::Boolean auto_groups,
+ CORBA::Boolean autoDim,
+ const GEOM::ListOfFields& fields,
+ const char* geomAssocFields,
+ CORBA::Double ZTolerance);
+
void ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart,
const char* file,
CORBA::Boolean auto_groups,
const GEOM::ListOfFields& fields,
const char* geomAssocFields,
CORBA::Double ZTolerance);
+
+ CORBA::LongLong ExportPartToMEDCoupling(SMESH::SMESH_IDSource_ptr meshPart,
+ CORBA::Boolean auto_groups,
+ CORBA::Boolean autoDim,
+ const GEOM::ListOfFields& fields,
+ const char* geomAssocFields,
+ CORBA::Double ZTolerance);
+
void ExportPartToDAT(SMESH::SMESH_IDSource_ptr meshPart,
const char* file);
void ExportPartToUNV(SMESH::SMESH_IDSource_ptr meshPart,
std::map<int, SMESH_subMesh_i*> _mapSubMesh_i; //NRI
std::map<int, ::SMESH_subMesh*> _mapSubMesh; //NRI
-private:
+public:
std::string generateMeshName( );
std::string prepareMeshNameAndGroups( const char* file, CORBA::Boolean overwrite );
-
- /*!
- * Check and correct names of mesh groups
- */
- void checkGroupNames();
-
/*
* Write GEOM fields to MED file
*/
SMESHDS_Mesh* meshDS,
const GEOM::ListOfFields& fields,
const char* geomAssocFields);
+private:
+ /*!
+ * Check and correct names of mesh groups
+ */
+ void checkGroupNames();
+
/*!
* Convert submesh ids into submesh interfaces
*/