les champs par medcoupling

This commit is contained in:
GERALD NICOLAS 2021-02-10 16:31:01 +01:00
parent 58ca79c858
commit b54385ddd4
5 changed files with 30 additions and 52 deletions

View File

@ -1152,22 +1152,31 @@ void MgAdapt::copyMgAdaptHypothesisData( const MgAdaptHypothesisData* from)
data->myVerboseLevel = from->myVerboseLevel;
}
std::vector<std::string> MgAdapt::getListFieldsNames(std::string fileIn)
{
MEDCoupling::MCAuto<MEDCoupling::MEDFileData> mfd = MEDCoupling::MEDFileData::New(fileIn);
std::vector<std::string> listFieldsNames(mfd->getFields()->getFieldsNames());
return listFieldsNames ;
}
bool MgAdapt::checkFieldName(std::string fileIn)
{
bool ret = false ;
MEDCoupling::MCAuto<MEDCoupling::MEDFileData> mfd = MEDCoupling::MEDFileData::New(fileIn);
std::vector<std::string> fieldNames(mfd->getFields()->getFieldsNames());
std::size_t jaux(fieldNames.size());
std::vector<std::string> listFieldsNames = getListFieldsNames(fileIn);
std::size_t jaux(listFieldsNames.size());
for(std::size_t j=0;j<jaux;j++)
{
if ( fieldName == fieldNames[j] )
{ ret = true ; }
if ( fieldName == listFieldsNames[j] )
{
ret = true ;
break ;
}
}
if ( ! ret )
{
std::cout << "Available field names:" << std::endl;
for(std::size_t j=0;j<jaux;j++)
{ std::cout << fieldNames[j] << std::endl;}
{ std::cout << listFieldsNames[j] << std::endl;}
SALOME::ExceptionStruct es;
es.type = SALOME::BAD_PARAM;
std::string text = "Field " + fieldName + " is not found." ;
@ -1190,7 +1199,10 @@ bool MgAdapt::checkTimeStepRank(std::string fileIn)
for(std::size_t j=0;j<jaux;j++)
{
if ( ( timeStep == timesteprank[j].first ) & ( rank == timesteprank[j].second ) )
{ ret = true ; }
{
ret = true ;
break ;
}
}
if ( ! ret )
{

View File

@ -328,6 +328,7 @@ private :
void execCmd( const char* cmd, int& err);
void cleanUp();
void appendMsgToLogFile(std::string& msg);
std::vector<std::string> getListFieldsNames(std::string fileIn) ;
bool checkFieldName(std::string fileIn) ;
bool checkTimeStepRank(std::string fileIn) ;

View File

@ -42,7 +42,6 @@ INCLUDE_DIRECTORIES(
${PROJECT_SOURCE_DIR}/src/Controls
${PROJECT_SOURCE_DIR}/src/SMESHClient
${PROJECT_SOURCE_DIR}/src/MEDWrapper
${PROJECT_SOURCE_DIR}/src/ADAPT
${PROJECT_BINARY_DIR}
${PROJECT_BINARY_DIR}/idl
${MEDCOUPLING_INCLUDE_DIRS}

View File

@ -23,6 +23,8 @@
#include "MG_ADAPTGUI.hxx"
#include "MEDFileData.hxx"
#include "SUIT_Desktop.h"
#include "SUIT_Application.h"
#include "SUIT_Session.h"
@ -1363,21 +1365,13 @@ std::map<QString, int> GetListeChamps(QString aFile, bool errorMessage)
std::map<QString, int> ListeChamp ;
med_err erreur = 0 ;
med_idt medIdt ;
while ( erreur == 0 )
{
// Ouverture du fichier
SCRUTE(aFile.toStdString());
medIdt = OuvrirFichier(aFile);
if ( medIdt < 0 )
{
erreur = 1 ;
break ;
}
// Lecture du nombre de champs
med_int ncha = MEDnField(medIdt) ;
if (ncha < 1 )
MEDCoupling::MCAuto<MEDCoupling::MEDFileData> mfd = MEDCoupling::MEDFileData::New(aFile.toStdString());
std::vector<std::string> listFieldsNames(mfd->getFields()->getFieldsNames());
std::size_t jaux(listFieldsNames.size());
if (jaux < 1 )
{
if(errorMessage)
{
@ -1387,40 +1381,14 @@ std::map<QString, int> GetListeChamps(QString aFile, bool errorMessage)
erreur = 2 ;
break ;
}
// Lecture des caracteristiques des champs
for (int i=0; i< ncha; i++)
med_int nbofcstp = 1;
for(std::size_t j=0;j<jaux;j++)
{
// Lecture du nombre de composantes
med_int ncomp = MEDfieldnComponent(medIdt,i+1);
// Lecture du type du champ, des noms des composantes et du nom de l'unite
char nomcha [MED_NAME_SIZE+1];
char meshname[MED_NAME_SIZE+1];
char * comp = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
char * unit = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
char dtunit[MED_SNAME_SIZE+1];
med_bool local;
med_field_type typcha;
med_int nbofcstp;
erreur = MEDfieldInfo(medIdt,i+1,nomcha,meshname,&local,&typcha,comp,unit,dtunit,&nbofcstp) ;
free(comp);
free(unit);
if ( erreur < 0 )
{
if(errorMessage)
{
QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
QObject::tr("MG_ADAPT_MED_FILE_6") );
}
break ;
}
ListeChamp.insert(std::pair<QString, int> (QString(nomcha), nbofcstp));
// std::cout << listFieldsNames[j] << std::endl;
ListeChamp.insert(std::pair<QString, int> (QString(listFieldsNames[j].c_str()), nbofcstp));
}
break ;
}
// Fermeture du fichier
if ( medIdt > 0 ) MEDfileClose(medIdt);
return ListeChamp;
}

View File

@ -43,9 +43,7 @@
#include <med.h>
#include <QObject>
// model
//~#include "MG_ADAPT.h"
#include "MG_ADAPTGUI.hxx"
//~#include "MG_ADAPT.hxx"
#include CORBA_SERVER_HEADER(MG_ADAPT)