1 #include "HomardQtCommun.h"
2 #include "HOMARDGUI_Utils.h"
6 #include <qmessagebox.h>
8 #include <qfiledialog.h>
15 #include "SalomeApp_Tools.h"
24 // ============================================================================
25 QString HOMARD_QT_COMMUN::SelectionArbreEtude(QString commentaire, int grave )
26 // ============================================================================
27 // Regarde si l'objet selectionne correspond a un objet de tyoe
28 // commentaire. si c'est le cas, retourne le nom de cet objet,
29 // sinon retourne une QString("")
30 // Si grave = 0, ce n'est pas grave de ne rien trouver et pas de message
31 // Si grave = 1, ce n'est pas grave de ne rien trouver mais on emet un message
33 int nbSel = HOMARD_UTILS::IObjectCount() ;
38 QMessageBox::warning( 0, QObject::tr("HOM_WARNING"),
39 QObject::tr("HOM_SELECT_OBJECT_1") );
45 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
46 QObject::tr("HOM_SELECT_OBJECT_2") );
50 Handle(SALOME_InteractiveObject) aIO = HOMARD_UTILS::firstIObject();
51 if ( aIO->hasEntry() )
53 _PTR(Study) aStudy = HOMARD_UTILS::GetActiveStudyDocument();
54 _PTR(SObject) aSO ( aStudy->FindObjectID( aIO->getEntry() ) );
55 _PTR(GenericAttribute) anAttr;
56 if (aSO->FindAttribute(anAttr, "AttributeComment") )
58 _PTR(AttributeComment) attributComment = anAttr;
59 QString aComment= QString(attributComment->Value().data());
60 int iteration = aComment.lastIndexOf(commentaire);
63 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
64 QObject::tr("HOM_SELECT_OBJECT_3").arg(commentaire) );
67 if (aSO->FindAttribute(anAttr, "AttributeName") )
69 _PTR(AttributeName) attributName = anAttr;
70 QString aName= QString(attributName->Value().data());
79 // =======================================================================
80 QString HOMARD_QT_COMMUN::SelectionCasEtude()
81 // =======================================================================
83 QString aName = QString("");
84 int nbSel = HOMARD_UTILS::IObjectCount() ;
87 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
88 QObject::tr("HOM_SELECT_OBJECT_1") );
93 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
94 QObject::tr("HOM_SELECT_OBJECT_2") );
97 Handle(SALOME_InteractiveObject) aIO = HOMARD_UTILS::firstIObject();
98 if ( aIO->hasEntry() )
100 _PTR(Study) aStudy = HOMARD_UTILS::GetActiveStudyDocument();
101 _PTR(SObject) aSO ( aStudy->FindObjectID( aIO->getEntry() ) );
102 _PTR(SObject) aSObjCas = aSO->GetFather();
103 _PTR(GenericAttribute) anAttr;
104 if (aSObjCas->FindAttribute(anAttr, "AttributeName") )
106 _PTR(AttributeName) attributName = anAttr;
107 aName= QString(attributName->Value().data());
114 // =======================================================================
115 QString HOMARD_QT_COMMUN::PushNomFichier(bool avertir)
116 // =======================================================================
117 // Gestion les boutons qui permettent de
118 // 1) retourne le nom d'un fichier par une fenetre de dialogue si aucun
119 // objet est selectionne dans l arbre d etude
120 // 2) retourne le nom du fichier asocie a l objet
121 // selectionne dans l arbre d etude
123 MESSAGE("HOMARD_QT_COMMUN::PushNomFichier");
124 QString aFile=QString::null;
125 int nbSel = HOMARD_UTILS::IObjectCount() ;
128 aFile = QFileDialog::getOpenFileName(0,QString("File Selection"),QString("") ,QString("Med files (*.med);;all (*) ") );
132 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
133 QObject::tr("HOM_SELECT_FILE_2") );
137 Handle(SALOME_InteractiveObject) aIO = HOMARD_UTILS::firstIObject();
138 if ( aIO->hasEntry() )
140 _PTR(Study) aStudy = HOMARD_UTILS::GetActiveStudyDocument();
141 _PTR(SObject) aSO ( aStudy->FindObjectID( aIO->getEntry() ) );
142 _PTR(GenericAttribute) anAttr;
143 _PTR(AttributeFileType) aFileType;
144 _PTR(AttributeExternalFileDef) aFileName;
146 if (aSO->FindAttribute(anAttr, "AttributeFileType") ) {
148 QString fileType=QString(aFileType->Value().data());
149 if ( fileType==QString("FICHIERMED")) {
150 if (aSO->FindAttribute(anAttr,"AttributeExternalFileDef")) {
152 aFile= QString(aFileName->Value().data()); }
158 if ( aFile==QString::null )
161 QMessageBox::warning( 0, QObject::tr("HOM_WARNING"),
162 QObject::tr("HOM_SELECT_STUDY") );
164 aFile = QFileDialog::getOpenFileName();
165 if (!aFile.isEmpty())
176 // =======================================================================
177 int HOMARD_QT_COMMUN::OuvrirFichier(QString aFile)
178 // =======================================================================
179 // renvoie le medId associe au fichier Med apres ouverture
181 med_int medIdt = MEDfileOpen(aFile.toStdString().c_str(),MED_ACC_RDONLY);
184 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
185 QObject::tr("HOM_MED_FILE_1") );
190 // ======================================================
191 QString HOMARD_QT_COMMUN::LireNomMaillage(QString aFile)
192 // ========================================================
194 med_int medIdt = HOMARD_QT_COMMUN::OuvrirFichier(aFile);
195 med_int numberOfMeshes = MEDnMesh(medIdt) ;
196 if (numberOfMeshes == 0 )
198 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
199 QObject::tr("HOM_MED_FILE_2") );
201 if (numberOfMeshes > 1 )
203 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
204 QObject::tr("HOM_MED_FILE_3") );
207 QString nomMaillage= HOMARD_QT_COMMUN::LireNomMaillage(medIdt,1);
208 MEDfileClose(medIdt);
211 // =======================================================================
212 QString HOMARD_QT_COMMUN::LireNomMaillage(int medIdt ,int meshId)
213 // =======================================================================
215 QString NomMaillage=QString::null;
216 char meshname[MED_NAME_SIZE+1];
217 med_int spacedim,meshdim;
218 med_mesh_type meshtype;
219 char descriptionription[MED_COMMENT_SIZE+1];
220 char dtunit[MED_SNAME_SIZE+1];
221 med_sorting_type sortingtype;
223 med_axis_type axistype;
224 int naxis = MEDmeshnAxis(medIdt,1);
225 char *axisname=new char[naxis*MED_SNAME_SIZE+1];
226 char *axisunit=new char[naxis*MED_SNAME_SIZE+1];
227 med_err aRet = MEDmeshInfo(medIdt,
243 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
244 QObject::tr("HOM_MED_FILE_4") );
248 NomMaillage=QString(meshname);
254 // =======================================================================
255 std::list<QString> HOMARD_QT_COMMUN::GetListeChamps(QString aFile)
256 // =======================================================================
258 // Il faut voir si plusieurs maillages
260 MESSAGE("HOMARD_QT_COMMUN::GetListeChamps");
261 std::list<QString> ListeChamp;
264 char nomcha [MED_NAME_SIZE+1];
265 char meshname[MED_NAME_SIZE+1];
266 med_field_type typcha;
271 SCRUTE(aFile.toStdString());
272 med_int medIdt = HOMARD_QT_COMMUN::OuvrirFichier(aFile);
273 if ( medIdt < 0 ) { return ListeChamp; }
275 // Le fichier Med est lisible
276 // Lecture du maillage
278 // Lecture du nombre de champs
279 med_int ncha = MEDnField(medIdt) ;
282 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
283 QObject::tr("HOM_MED_FILE_5") );
284 MEDfileClose(medIdt);
288 for (int i=0; i< ncha; i++)
290 /* Lecture du type du champ, des noms des composantes et du nom de l'unite*/
291 ncomp = MEDfieldnComponent(medIdt,i+1);
292 comp = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
293 unit = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
294 char dtunit[MED_SNAME_SIZE+1];
295 if ( MEDfieldInfo(medIdt,i+1,nomcha,meshname,&local,&typcha,comp,unit,dtunit,&nbofcstp) < 0 )
297 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
298 QObject::tr("HOM_MED_FILE_6") );
299 MEDfileClose(medIdt);
303 ListeChamp.push_back(QString(nomcha));
307 MEDfileClose(medIdt);
311 // ======================================================================================
312 std::list<QString> HOMARD_QT_COMMUN::GetListeComposants(QString aFile, QString aChamp)
313 // ======================================================================================
315 MESSAGE ( "GetListeComposants pour le fichier " << aFile.toStdString().c_str());
316 MESSAGE ( "GetListeComposants pour le champ " << aChamp.toStdString().c_str());
318 std::list<QString> ListeComposants;
321 char nomcha [MED_NAME_SIZE+1];
322 char meshname[MED_NAME_SIZE+1];
323 med_field_type typcha;
328 int medIdt = HOMARD_QT_COMMUN::OuvrirFichier(aFile);
329 if ( medIdt < 0 ) { return ListeComposants; }
332 // Lecture du nombre de champs
333 med_int ncha = MEDnField(medIdt) ;
336 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
337 QObject::tr("HOM_MED_FILE_5") );
338 MEDfileClose(medIdt);
339 return ListeComposants;
342 for (int i=0; i< ncha; i++)
344 /* Lecture du type du champ, des noms des composantes et du nom de l'unite*/
345 ncomp = MEDfieldnComponent(medIdt,i+1);
346 comp = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
347 unit = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
348 char dtunit[MED_SNAME_SIZE+1];
350 if ( MEDfieldInfo(medIdt,i+1,nomcha,meshname,&local,&typcha,comp,unit,dtunit,&nbofcstp) < 0 )
352 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
353 QObject::tr("HOM_MED_FILE_6") );
354 MEDfileClose(medIdt);
355 return ListeComposants;
358 if ( QString(nomcha) != aChamp ) {
364 for (int j = 0; j <ncomp; j++)
366 char cible[MED_SNAME_SIZE +1];
367 strncpy(cible,comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE );
368 cible[MED_SNAME_SIZE ]='\0';
369 ListeComposants.push_back(QString(cible));
375 MEDfileClose(medIdt);
376 return ListeComposants;