Salome HOME
bos #26453: SMESH: uniform refinement
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_HomardUtils.cxx
1 // Copyright (C) 2011-2021  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20
21 #include "SMESHGUI_HomardUtils.h"
22
23 #include <utilities.h>
24
25 #include "OB_Browser.h"
26
27 #include "SUIT_Desktop.h"
28 #include "SUIT_Application.h"
29 #include "SUIT_Session.h"
30
31 #include "LightApp_SelectionMgr.h"
32 #include "SalomeApp_Application.h"
33 #include "SalomeApp_Module.h"
34 #include "SalomeApp_Study.h"
35
36 #include "SALOME_ListIO.hxx"
37
38 #include "SALOMEconfig.h"
39 #include <string>
40
41 #include <qmessagebox.h>
42 #include <qcombobox.h>
43 #include <qfiledialog.h>
44 #include <qstring.h>
45 #include <stdlib.h>
46 #include <qstringlist.h>
47
48 #include <sys/stat.h>
49 #ifndef WIN32
50 #include <dirent.h>
51 #include <unistd.h>
52 #endif
53
54 #include "SalomeApp_Tools.h"
55
56 #include <med.h>
57
58 SALOME_ListIO SMESH_HOMARD_UTILS::mySelected;
59
60 //================================================================
61 // Function : GetActiveStudy
62 // Returne un pointeur sur l'etude active
63 //================================================================
64 SUIT_Study* SMESH_HOMARD_UTILS::GetActiveStudy()
65 {
66     SUIT_Application* app = SUIT_Session::session()->activeApplication();
67     if (app)
68       return app->activeStudy();
69     else
70       return NULL;
71 }
72
73 //================================================================
74 // Function : getStudy
75 // Returne un pointeur sur l'etude active
76 //================================================================
77 _PTR(Study) SMESH_HOMARD_UTILS::getStudy()
78 {
79   static _PTR(Study) _study;
80   if(!_study)
81     _study = SalomeApp_Application::getStudy();
82   return _study;
83 }
84
85 //================================================================
86 // Function : updateObjBrowser
87 // Purpose  : met a jour l arbre d 'etude pour Homard
88 //================================================================
89 void SMESH_HOMARD_UTILS::updateObjBrowser()
90 {
91     SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
92     if (app) {
93       //  Le nom identifiant doit etre la valeur du parametre
94       // name de la section HOMARD du fichier SalomeApp.xml
95       CAM_Module* module = app->module("Homard" );
96       SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>( module );
97       if ( appMod ) {
98         app->updateObjectBrowser();
99         appMod->updateObjBrowser( true );
100       }
101       else
102         MESSAGE( "---   SMESHHOMARD::updateObjBrowser: appMod = NULL");
103     }
104 }
105
106 //================================================================
107 // Function : selectedIO
108 // Return the list of selected SALOME_InteractiveObject's
109 //================================================================
110 const SALOME_ListIO& SMESH_HOMARD_UTILS::selectedIO()
111 {
112       SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* > ( SUIT_Session::session()->activeApplication() );
113       LightApp_SelectionMgr* aSelectionMgr = app->selectionMgr();
114       if( aSelectionMgr )
115       {
116               aSelectionMgr->selectedObjects( mySelected );
117         for (SALOME_ListIteratorOfListIO it (mySelected); it.More(); it.Next())
118         SCRUTE(it.Value()->getEntry());
119       };
120       return mySelected;
121 }
122
123 //================================================================
124 // Function : IObjectCount
125 // Return the number of selected objects
126 //================================================================
127 int SMESH_HOMARD_UTILS::IObjectCount()
128 {
129       SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
130       LightApp_SelectionMgr* aSelectionMgr = app->selectionMgr();
131       if( aSelectionMgr )
132       {
133               aSelectionMgr->selectedObjects( mySelected );
134               SCRUTE(mySelected.Extent());
135         return mySelected.Extent();
136       }
137       return 0;
138 }
139
140 //================================================================
141 // Function : firstIObject
142 // Purpose  :  Return the first selected object in the selected object list
143 //================================================================
144 Handle(SALOME_InteractiveObject) SMESH_HOMARD_UTILS::firstIObject()
145 {
146       const SALOME_ListIO& aList = selectedIO();
147       return aList.Extent() > 0 ? aList.First() : Handle(SALOME_InteractiveObject)();
148 }
149
150 //================================================================
151 // Function : lastIObject
152 // Return the last selected object in the selected object list
153 //================================================================
154 Handle(SALOME_InteractiveObject) SMESH_HOMARD_UTILS::lastIObject()
155 {
156       const SALOME_ListIO& aList = selectedIO();
157       return aList.Extent() > 0 ? aList.Last() : Handle(SALOME_InteractiveObject)();
158 }
159
160 //================================================================
161 // Retourne vrai si l'objet est du type voulu
162 // . Dans le cas d'un cas, d'une hypothese, d'une zone, on se contente
163 // d'une comparaison simple entre le type stocke et TypeObject.
164 // . Pour l'iteration, le type stocke en attribut est sous la forme
165 // "IterationHomard" + le nom de l'iteration precedente.
166 // Il faut donc regarder si la chaine commence par TypeObject.
167 // . Idem pour le fichier de messages : "Mess " + numero d'iteration
168 //
169 // On filtre ce genre de situation avec option :
170 //  -1 : comparaison totale
171 //   0 : comparaison sur le debut de la chaine
172 //================================================================
173 bool SMESH_HOMARD_UTILS::isObject(_PTR(SObject) MonObj, QString TypeObject, int option)
174 {
175 //   MESSAGE("isObject, TypeObject = "<<TypeObject.toStdString().c_str()<<", option = "<<option);
176 // Existence d'un attribut ?
177   _PTR(GenericAttribute) anAttr;
178   if ( !MonObj->FindAttribute(anAttr, "AttributeComment") ) return false;
179 // Quel type ?
180   _PTR(AttributeComment) aComment (anAttr);
181   QString Type = QString(aComment->Value().c_str());
182 //   MESSAGE("Type = "<<Type.toStdString().c_str());
183 // Est-ce le bon ?
184   bool bOK = false ;
185   if ( option == 0 )
186   {
187     int position = Type.lastIndexOf(TypeObject);
188 //     MESSAGE("position = "<<position);
189     if ( position == 0 ) { bOK = true ; }
190   }
191   else
192   {
193     if ( Type == TypeObject ) { bOK = true ; }
194   }
195   return bOK ;
196 }
197 //================================================================
198 // Retourne vrai si l'objet est une frontiere CAO
199 //================================================================
200 bool SMESH_HOMARD_UTILS::isBoundaryCAO(_PTR(SObject) MonObj)
201 {
202    return isObject( MonObj, QString("BoundaryCAOHomard"), -1 ) ;
203 }
204 //================================================================
205 // Retourne vrai si l'objet est une frontiere analytique
206 //================================================================
207 bool SMESH_HOMARD_UTILS::isBoundaryAn(_PTR(SObject) MonObj)
208 {
209    return isObject( MonObj, QString("BoundaryAnHomard"), -1 ) ;
210 }
211 //================================================================
212 // Retourne vrai si l'objet est une frontiere discrete
213 //================================================================
214 bool SMESH_HOMARD_UTILS::isBoundaryDi(_PTR(SObject) MonObj)
215 {
216    return isObject( MonObj, QString("BoundaryDiHomard"), -1 ) ;
217 }
218 //================================================================
219 // Retourne vrai si l'objet est un cas
220 //================================================================
221 bool SMESH_HOMARD_UTILS::isCase(_PTR(SObject) MonObj)
222 {
223    return isObject( MonObj, QString("CasHomard"), -1 ) ;
224 }
225 //================================================================
226 // Retourne vrai si l'objet est une Hypothese
227 //================================================================
228 bool SMESH_HOMARD_UTILS::isHypo(_PTR(SObject) MonObj)
229 {
230    return isObject( MonObj, QString("HypoHomard"), -1 ) ;
231 }
232 //================================================================
233 // Retourne vrai si l'objet est une iteration
234 //================================================================
235 bool SMESH_HOMARD_UTILS::isIter(_PTR(SObject) MonObj)
236 {
237    return isObject( MonObj, QString("IterationHomard"), 0 ) ;
238 }
239 //================================================================
240 // Retourne vrai si l'objet est un fichier de type TypeFile
241 //================================================================
242 bool SMESH_HOMARD_UTILS::isFileType(_PTR(SObject) MonObj, QString TypeFile)
243 {
244    return isObject( MonObj, TypeFile, 0 ) ;
245 }
246
247 // ============================================================================
248 QString SMESH_HOMARD_QT_COMMUN::SelectionArbreEtude(QString commentaire, int option )
249 // ============================================================================
250 // Retourne l'objet selectionne dans l'arbre d'etudes
251 // commentaire :
252 // . si le commentaire est une chaine vide, on ne tient pas compte du type de l'objet
253 //   et on retourne le nom de cet objet
254 // . sinon :
255 //   . si l'objet est du type defini par commentaire, retourne le nom de cet objet
256 //   . sinon on retourne une QString("")
257 // option :
258 // . Si option = 0, ce n'est pas grave de ne rien trouver ; aucun message n'est emis
259 // . Si option = 1, ce n'est pas grave de ne rien trouver mais on emet un message
260 {
261 //   MESSAGE("SelectionArbreEtude : commentaire = " << commentaire.toStdString().c_str() << " et option = " << option);
262   int nbSel = SMESH_HOMARD_UTILS::IObjectCount() ;
263   if ( nbSel == 0 )
264   {
265     if ( option == 1 )
266     {
267       QMessageBox::warning( 0, QObject::tr("HOM_WARNING"),
268                                QObject::tr("HOM_SELECT_OBJECT_1") );
269     }
270     return QString("");
271   }
272   if ( nbSel > 1 )
273   {
274     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
275                               QObject::tr("HOM_SELECT_OBJECT_2") );
276     return QString("");
277   }
278 //
279   Handle(SALOME_InteractiveObject) aIO = SMESH_HOMARD_UTILS::firstIObject();
280   if ( aIO->hasEntry() )
281   {
282 //     MESSAGE("aIO->getEntry() = " << aIO->getEntry());
283     _PTR(Study) aStudy = SMESH_HOMARD_UTILS::getStudy();
284     _PTR(SObject) aSO ( aStudy->FindObjectID( aIO->getEntry() ) );
285     _PTR(GenericAttribute) anAttr;
286     if (aSO->FindAttribute(anAttr, "AttributeComment") )
287     {
288       if ( commentaire != "" )
289       {
290         _PTR(AttributeComment) attributComment = anAttr;
291         QString aComment= QString(attributComment->Value().data());
292 //         MESSAGE("... aComment = " << aComment.toStdString().c_str());
293         int iaux = aComment.lastIndexOf(commentaire);
294 //         MESSAGE("... iaux = " << iaux);
295         if ( iaux !=0  )
296         {
297           QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
298                                     QObject::tr("HOM_SELECT_OBJECT_3").arg(commentaire) );
299           return QString("");
300         }
301       }
302       if (aSO->FindAttribute(anAttr, "AttributeName") )
303       {
304         _PTR(AttributeName) attributName = anAttr;
305         QString aName= QString(attributName->Value().data());
306         return aName;
307       }
308     }
309   }
310 //
311   return QString("");
312 }
313
314 // =======================================================================
315 QString SMESH_HOMARD_QT_COMMUN::SelectionCasEtude()
316 // =======================================================================
317 {
318   QString aName    = QString("");
319   int nbSel = SMESH_HOMARD_UTILS::IObjectCount() ;
320   if ( nbSel == 0 )
321   {
322     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
323                               QObject::tr("HOM_SELECT_OBJECT_1") );
324     return QString("");
325   }
326   if ( nbSel > 1 )
327   {
328     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
329                               QObject::tr("HOM_SELECT_OBJECT_2") );
330     return QString("");
331   }
332   Handle(SALOME_InteractiveObject) aIO = SMESH_HOMARD_UTILS::firstIObject();
333   if ( aIO->hasEntry() )
334   {
335         _PTR(Study) aStudy = SMESH_HOMARD_UTILS::getStudy();
336         _PTR(SObject) aSO ( aStudy->FindObjectID( aIO->getEntry() ) );
337         _PTR(SObject) aSObjCas = aSO->GetFather();
338         _PTR(GenericAttribute) anAttr;
339         if (aSObjCas->FindAttribute(anAttr, "AttributeName") )
340         {
341             _PTR(AttributeName) attributName = anAttr;
342             aName= QString(attributName->Value().data());
343         }
344         return aName;
345     }
346     return QString("");
347 }
348
349 // =======================================================================
350 QString SMESH_HOMARD_QT_COMMUN::PushNomFichier(bool avertir, QString TypeFichier)
351 // =======================================================================
352 // Gestion les boutons qui permettent  de
353 // 1) retourne le nom d'un fichier par une fenetre de dialogue si aucun
354 //    objet est selectionne dans l arbre d etude
355 // 2) retourne le nom du fichier asocie a l objet
356 //    selectionne dans l arbre d etude
357 {
358 //   MESSAGE("PushNomFichier avec avertir "<<avertir<<" et TypeFichier = "<<TypeFichier.toStdString().c_str());
359   QString aFile = QString::null;
360 //
361   // A. Filtre
362   QString filtre  ;
363 //
364   if ( TypeFichier == "med" )     { filtre = QString("Med") ; }
365   else if ( TypeFichier == "py" ) { filtre = QString("Python") ; }
366   else                            { filtre = TypeFichier ; }
367   //
368   if ( TypeFichier != "" ) { filtre += QString(" files (*.") + TypeFichier + QString(");;") ; }
369   //
370   filtre += QString("all (*) ") ;
371   //
372   // B. Selection
373   //int nbSel = SMESH_HOMARD_UTILS::IObjectCount() ;
374   int nbSel = 0;
375   //   MESSAGE("nbSel ="<<nbSel);
376   // B.1. Rien n'est selectionne
377   if ( nbSel == 0 )
378   {
379     //aFile = QFileDialog::getOpenFileName(0, QObject::tr("HOM_SELECT_FILE_0"), QString(""), QString("Med files (*.med);;all (*) ") );
380     aFile = QFileDialog::getOpenFileName(0, QObject::tr("HOM_SELECT_FILE_0"), QString(""), filtre );
381   }
382   // B.2. Un objet est selectionne
383   else if (nbSel == 1)
384   {
385     Handle(SALOME_InteractiveObject) aIO = SMESH_HOMARD_UTILS::firstIObject();
386     if ( aIO->hasEntry() )
387     {
388       _PTR(Study) aStudy = SMESH_HOMARD_UTILS::getStudy();
389       _PTR(SObject) aSO ( aStudy->FindObjectID( aIO->getEntry() ) );
390       _PTR(GenericAttribute) anAttr;
391       _PTR(AttributeFileType) aFileType;
392       _PTR(AttributeExternalFileDef) aFileName;
393       if (aSO) {
394         if (aSO->FindAttribute(anAttr, "AttributeFileType") ) {
395           aFileType=anAttr;
396           QString fileType=QString(aFileType->Value().data());
397           if ( fileType==QString("FICHIERMED")) {
398             if (aSO->FindAttribute(anAttr,"AttributeExternalFileDef")) {
399             aFileName=anAttr;
400             aFile= QString(aFileName->Value().data()); }
401           }
402         }
403       }
404     }
405
406     if ( aFile==QString::null )
407     {
408       if ( avertir ) {
409         QMessageBox::warning( 0, QObject::tr("HOM_WARNING"),
410                                  QObject::tr("HOM_SELECT_STUDY") );
411       }
412       aFile = QFileDialog::getOpenFileName(0, QObject::tr("HOM_SELECT_FILE_0"), QString(""), filtre );
413     }
414   }
415   // B.3. Bizarre
416   else
417   {
418     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
419                               QObject::tr("HOM_SELECT_FILE_2") );
420   }
421
422   return aFile;
423 }
424 // =======================================================================
425 med_idt SMESH_HOMARD_QT_COMMUN::OuvrirFichier(QString aFile)
426 // =======================================================================
427 // renvoie le medId associe au fichier Med apres ouverture
428 {
429   med_idt medIdt = MEDfileOpen(aFile.toStdString().c_str(),MED_ACC_RDONLY);
430   if (medIdt <0)
431   {
432     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
433                               QObject::tr("HOM_MED_FILE_1") );
434   }
435   return medIdt;
436 }
437
438 // ======================================================
439 QString SMESH_HOMARD_QT_COMMUN::LireNomMaillage(QString aFile)
440 // ========================================================
441 {
442   QString nomMaillage = "" ;
443   int erreur = 0 ;
444   med_idt medIdt ;
445   while ( erreur == 0 )
446   {
447     //  Ouverture du fichier
448     medIdt = SMESH_HOMARD_QT_COMMUN::OuvrirFichier(aFile);
449     if ( medIdt < 0 )
450     {
451       erreur = 1 ;
452       break ;
453     }
454     med_int numberOfMeshes = MEDnMesh(medIdt) ;
455     if (numberOfMeshes == 0 )
456     {
457       QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
458                                 QObject::tr("HOM_MED_FILE_2") );
459       erreur = 2 ;
460       break ;
461     }
462     if (numberOfMeshes > 1 )
463     {
464       QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
465                                 QObject::tr("HOM_MED_FILE_3") );
466       erreur = 3 ;
467       break ;
468     }
469
470     nomMaillage = SMESH_HOMARD_QT_COMMUN::LireNomMaillage2(medIdt,1);
471     break ;
472   }
473   // Fermeture du fichier
474   if ( medIdt > 0 ) MEDfileClose(medIdt);
475
476   return nomMaillage;
477 }
478 // =======================================================================
479 QString SMESH_HOMARD_QT_COMMUN::LireNomMaillage2(med_idt medIdt ,int meshId)
480 // =======================================================================
481 {
482   QString NomMaillage=QString::null;
483   char meshname[MED_NAME_SIZE+1];
484   med_int spacedim,meshdim;
485   med_mesh_type meshtype;
486   char descriptionription[MED_COMMENT_SIZE+1];
487   char dtunit[MED_SNAME_SIZE+1];
488   med_sorting_type sortingtype;
489   med_int nstep;
490   med_axis_type axistype;
491   int naxis = MEDmeshnAxis(medIdt,1);
492   char *axisname=new char[naxis*MED_SNAME_SIZE+1];
493   char *axisunit=new char[naxis*MED_SNAME_SIZE+1];
494   med_err aRet = MEDmeshInfo(medIdt,
495                           meshId,
496                           meshname,
497                           &spacedim,
498                           &meshdim,
499                           &meshtype,
500                           descriptionription,
501                           dtunit,
502                           &sortingtype,
503                           &nstep,
504                           &axistype,
505                           axisname,
506                           axisunit);
507
508   if ( aRet < 0 ) { QMessageBox::critical( 0, QObject::tr("HOM_ERROR"), \
509                                               QObject::tr("HOM_MED_FILE_4") );  }
510   else            { NomMaillage=QString(meshname); }
511
512   delete[] axisname ;
513   delete[] axisunit ;
514
515   return NomMaillage;
516 }
517
518
519 // =======================================================================
520 std::list<QString> SMESH_HOMARD_QT_COMMUN::GetListeChamps(QString aFile)
521 // =======================================================================
522 {
523 // Il faut voir si plusieurs maillages
524
525   MESSAGE("GetListeChamps");
526   std::list<QString> ListeChamp ;
527
528   med_err erreur = 0 ;
529   med_idt medIdt ;
530
531   while ( erreur == 0 )
532   {
533     // Ouverture du fichier
534     SCRUTE(aFile.toStdString());
535     medIdt = SMESH_HOMARD_QT_COMMUN::OuvrirFichier(aFile);
536     if ( medIdt < 0 )
537     {
538       erreur = 1 ;
539       break ;
540     }
541   // Lecture du nombre de champs
542     med_int ncha = MEDnField(medIdt) ;
543     if (ncha < 1 )
544     {
545       QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
546                                 QObject::tr("HOM_MED_FILE_5") );
547       erreur = 2 ;
548       break ;
549     }
550   // Lecture des caracteristiques des champs
551     for (int i=0; i< ncha; i++)
552     {
553 //       Lecture du nombre de composantes
554       med_int ncomp = MEDfieldnComponent(medIdt,i+1);
555 //       Lecture du type du champ, des noms des composantes et du nom de l'unite
556       char nomcha  [MED_NAME_SIZE+1];
557       char meshname[MED_NAME_SIZE+1];
558       char * comp = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
559       char * unit = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
560       char dtunit[MED_SNAME_SIZE+1];
561       med_bool local;
562       med_field_type typcha;
563       med_int nbofcstp;
564       erreur = MEDfieldInfo(medIdt,i+1,nomcha,meshname,&local,&typcha,comp,unit,dtunit,&nbofcstp) ;
565       free(comp);
566       free(unit);
567       if ( erreur < 0 )
568       {
569         QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
570                                   QObject::tr("HOM_MED_FILE_6") );
571         break ;
572       }
573       ListeChamp.push_back(QString(nomcha));
574     }
575     break ;
576   }
577   // Fermeture du fichier
578   if ( medIdt > 0 ) MEDfileClose(medIdt);
579
580   return ListeChamp;
581 }
582
583 // ======================================================================================
584 std::list<QString> SMESH_HOMARD_QT_COMMUN::GetListeComposants(QString aFile, QString aChamp)
585 // ======================================================================================
586 {
587   MESSAGE ( "GetListeComposants pour le fichier " << aFile.toStdString().c_str());
588   MESSAGE ( "GetListeComposants pour le champ " << aChamp.toStdString().c_str());
589
590   std::list<QString> ListeComposants;
591
592   med_err erreur = 0 ;
593   med_idt medIdt ;
594
595   while ( erreur == 0 )
596   {
597     // Ouverture du fichier
598     SCRUTE(aFile.toStdString());
599     medIdt = SMESH_HOMARD_QT_COMMUN::OuvrirFichier(aFile);
600     if ( medIdt < 0 )
601     {
602       erreur = 1 ;
603       break ;
604     }
605   // Lecture du nombre de champs
606     med_int ncha = MEDnField(medIdt) ;
607     if (ncha < 1 )
608     {
609       QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
610                                 QObject::tr("HOM_MED_FILE_5") );
611       erreur = 2 ;
612       break ;
613     }
614   // Lecture des caracteristiques des champs
615     for (int i=0; i< ncha; i++)
616     {
617 //       Lecture du nombre de composantes
618       med_int ncomp = MEDfieldnComponent(medIdt,i+1);
619 //       Lecture du type du champ, des noms des composantes et du nom de l'unite
620       char nomcha  [MED_NAME_SIZE+1];
621       char meshname[MED_NAME_SIZE+1];
622       char * comp = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
623       char * unit = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
624       char dtunit[MED_SNAME_SIZE+1];
625       med_bool local;
626       med_field_type typcha;
627       med_int nbofcstp;
628       erreur = MEDfieldInfo(medIdt,i+1,nomcha,meshname,&local,&typcha,comp,unit,dtunit,&nbofcstp) ;
629       free(unit);
630       if ( erreur < 0 )
631       {
632         free(comp);
633         QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
634                                   QObject::tr("HOM_MED_FILE_6") );
635         break ;
636       }
637       // Lecture des composantes si c'est le bon champ
638       if ( QString(nomcha) == aChamp )
639       {
640         for (int j = 0; j <ncomp; j++)
641         {
642           char cible[MED_SNAME_SIZE +1];
643           strncpy(cible,comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE );
644           cible[MED_SNAME_SIZE ]='\0';
645           ListeComposants.push_back(QString(cible));
646         }
647       }
648       // Menage
649       free(comp);
650       // Sortie si c'est bon
651       if ( QString(nomcha) == aChamp ) { break ; }
652     }
653     break ;
654   }
655   // Fermeture du fichier
656   if ( medIdt > 0 ) MEDfileClose(medIdt);
657
658   return ListeComposants;
659 }