1 // Copyright (C) 2011-2013 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "HomardQtCommun.h"
21 #include "HOMARDGUI_Utils.h"
23 #include <utilities.h>
25 #include <qmessagebox.h>
26 #include <qcombobox.h>
27 #include <qfiledialog.h>
36 #include "SalomeApp_Tools.h"
45 // ============================================================================
46 QString HOMARD_QT_COMMUN::SelectionArbreEtude(QString commentaire, int option )
47 // ============================================================================
48 // Retourne l'objet selectionne dans l'arbre d'etudes
50 // . si le commentaire est une chaine vide, on ne tient pas compte du type de l'objet
51 // et on retourne le nom de cet objet
53 // . si l'objet est du type defini par commentaite, retourne le nom de cet objet
54 // . sinon on retourne une QString("")
56 // . Si option = 0, ce n'est pas grave de ne rien trouver ; aucun message n'est emis
57 // . Si option = 1, ce n'est pas grave de ne rien trouver mais on emet un message
59 MESSAGE("SelectionArbreEtude : commentaire = " << commentaire.toStdString().c_str() << " et option = " << option);
60 int nbSel = HOMARD_UTILS::IObjectCount() ;
65 QMessageBox::warning( 0, QObject::tr("HOM_WARNING"),
66 QObject::tr("HOM_SELECT_OBJECT_1") );
72 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
73 QObject::tr("HOM_SELECT_OBJECT_2") );
77 Handle(SALOME_InteractiveObject) aIO = HOMARD_UTILS::firstIObject();
78 if ( aIO->hasEntry() )
80 _PTR(Study) aStudy = HOMARD_UTILS::GetActiveStudyDocument();
81 _PTR(SObject) aSO ( aStudy->FindObjectID( aIO->getEntry() ) );
82 _PTR(GenericAttribute) anAttr;
83 if (aSO->FindAttribute(anAttr, "AttributeComment") )
85 if ( commentaire != "" )
87 _PTR(AttributeComment) attributComment = anAttr;
88 QString aComment= QString(attributComment->Value().data());
89 MESSAGE("... aComment = " << aComment.toStdString().c_str());
90 int iaux = aComment.lastIndexOf(commentaire);
91 MESSAGE("... iaux = " << iaux);
94 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
95 QObject::tr("HOM_SELECT_OBJECT_3").arg(commentaire) );
99 if (aSO->FindAttribute(anAttr, "AttributeName") )
101 _PTR(AttributeName) attributName = anAttr;
102 QString aName= QString(attributName->Value().data());
111 // =======================================================================
112 QString HOMARD_QT_COMMUN::SelectionCasEtude()
113 // =======================================================================
115 QString aName = QString("");
116 int nbSel = HOMARD_UTILS::IObjectCount() ;
119 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
120 QObject::tr("HOM_SELECT_OBJECT_1") );
125 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
126 QObject::tr("HOM_SELECT_OBJECT_2") );
129 Handle(SALOME_InteractiveObject) aIO = HOMARD_UTILS::firstIObject();
130 if ( aIO->hasEntry() )
132 _PTR(Study) aStudy = HOMARD_UTILS::GetActiveStudyDocument();
133 _PTR(SObject) aSO ( aStudy->FindObjectID( aIO->getEntry() ) );
134 _PTR(SObject) aSObjCas = aSO->GetFather();
135 _PTR(GenericAttribute) anAttr;
136 if (aSObjCas->FindAttribute(anAttr, "AttributeName") )
138 _PTR(AttributeName) attributName = anAttr;
139 aName= QString(attributName->Value().data());
146 // =======================================================================
147 QString HOMARD_QT_COMMUN::PushNomFichier(bool avertir)
148 // =======================================================================
149 // Gestion les boutons qui permettent de
150 // 1) retourne le nom d'un fichier par une fenetre de dialogue si aucun
151 // objet est selectionne dans l arbre d etude
152 // 2) retourne le nom du fichier asocie a l objet
153 // selectionne dans l arbre d etude
155 MESSAGE("PushNomFichier");
156 QString aFile=QString::null;
157 int nbSel = HOMARD_UTILS::IObjectCount() ;
160 aFile = QFileDialog::getOpenFileName(0,QString("File Selection"),QString("") ,QString("Med files (*.med);;all (*) ") );
164 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
165 QObject::tr("HOM_SELECT_FILE_2") );
169 Handle(SALOME_InteractiveObject) aIO = HOMARD_UTILS::firstIObject();
170 if ( aIO->hasEntry() )
172 _PTR(Study) aStudy = HOMARD_UTILS::GetActiveStudyDocument();
173 _PTR(SObject) aSO ( aStudy->FindObjectID( aIO->getEntry() ) );
174 _PTR(GenericAttribute) anAttr;
175 _PTR(AttributeFileType) aFileType;
176 _PTR(AttributeExternalFileDef) aFileName;
178 if (aSO->FindAttribute(anAttr, "AttributeFileType") ) {
180 QString fileType=QString(aFileType->Value().data());
181 if ( fileType==QString("FICHIERMED")) {
182 if (aSO->FindAttribute(anAttr,"AttributeExternalFileDef")) {
184 aFile= QString(aFileName->Value().data()); }
190 if ( aFile==QString::null )
193 QMessageBox::warning( 0, QObject::tr("HOM_WARNING"),
194 QObject::tr("HOM_SELECT_STUDY") );
196 aFile = QFileDialog::getOpenFileName();
197 if (!aFile.isEmpty())
206 // =======================================================================
207 int HOMARD_QT_COMMUN::OuvrirFichier(QString aFile)
208 // =======================================================================
209 // renvoie le medId associe au fichier Med apres ouverture
211 med_int medIdt = MEDfileOpen(aFile.toStdString().c_str(),MED_ACC_RDONLY);
214 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
215 QObject::tr("HOM_MED_FILE_1") );
220 // ======================================================
221 QString HOMARD_QT_COMMUN::LireNomMaillage(QString aFile)
222 // ========================================================
224 QString nomMaillage = "" ;
227 while ( erreur == 0 )
229 // Ouverture du fichier
230 medIdt = HOMARD_QT_COMMUN::OuvrirFichier(aFile);
236 med_int numberOfMeshes = MEDnMesh(medIdt) ;
237 if (numberOfMeshes == 0 )
239 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
240 QObject::tr("HOM_MED_FILE_2") );
244 if (numberOfMeshes > 1 )
246 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
247 QObject::tr("HOM_MED_FILE_3") );
252 nomMaillage = HOMARD_QT_COMMUN::LireNomMaillage(medIdt,1);
255 // Fermeture du fichier
256 if ( medIdt > 0 ) MEDfileClose(medIdt);
260 // =======================================================================
261 QString HOMARD_QT_COMMUN::LireNomMaillage(int medIdt ,int meshId)
262 // =======================================================================
264 QString NomMaillage=QString::null;
265 char meshname[MED_NAME_SIZE+1];
266 med_int spacedim,meshdim;
267 med_mesh_type meshtype;
268 char descriptionription[MED_COMMENT_SIZE+1];
269 char dtunit[MED_SNAME_SIZE+1];
270 med_sorting_type sortingtype;
272 med_axis_type axistype;
273 int naxis = MEDmeshnAxis(medIdt,1);
274 char *axisname=new char[naxis*MED_SNAME_SIZE+1];
275 char *axisunit=new char[naxis*MED_SNAME_SIZE+1];
276 med_err aRet = MEDmeshInfo(medIdt,
290 if ( aRet < 0 ) { QMessageBox::critical( 0, QObject::tr("HOM_ERROR"), \
291 QObject::tr("HOM_MED_FILE_4") ); }
292 else { NomMaillage=QString(meshname); }
301 // =======================================================================
302 std::list<QString> HOMARD_QT_COMMUN::GetListeChamps(QString aFile)
303 // =======================================================================
305 // Il faut voir si plusieurs maillages
307 MESSAGE("GetListeChamps");
308 std::list<QString> ListeChamp ;
313 while ( erreur == 0 )
315 // Ouverture du fichier
316 SCRUTE(aFile.toStdString());
317 medIdt = HOMARD_QT_COMMUN::OuvrirFichier(aFile);
323 // Lecture du nombre de champs
324 med_int ncha = MEDnField(medIdt) ;
327 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
328 QObject::tr("HOM_MED_FILE_5") );
332 // Lecture des caracteristiques des champs
333 for (int i=0; i< ncha; i++)
335 // Lecture du nombre de composantes
336 med_int ncomp = MEDfieldnComponent(medIdt,i+1);
337 // Lecture du type du champ, des noms des composantes et du nom de l'unite
338 char nomcha [MED_NAME_SIZE+1];
339 char meshname[MED_NAME_SIZE+1];
340 char * comp = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
341 char * unit = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
342 char dtunit[MED_SNAME_SIZE+1];
344 med_field_type typcha;
346 erreur = MEDfieldInfo(medIdt,i+1,nomcha,meshname,&local,&typcha,comp,unit,dtunit,&nbofcstp) ;
351 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
352 QObject::tr("HOM_MED_FILE_6") );
355 ListeChamp.push_back(QString(nomcha));
359 // Fermeture du fichier
360 if ( medIdt > 0 ) MEDfileClose(medIdt);
365 // ======================================================================================
366 std::list<QString> HOMARD_QT_COMMUN::GetListeComposants(QString aFile, QString aChamp)
367 // ======================================================================================
369 MESSAGE ( "GetListeComposants pour le fichier " << aFile.toStdString().c_str());
370 MESSAGE ( "GetListeComposants pour le champ " << aChamp.toStdString().c_str());
372 std::list<QString> ListeComposants;
377 while ( erreur == 0 )
379 // Ouverture du fichier
380 SCRUTE(aFile.toStdString());
381 medIdt = HOMARD_QT_COMMUN::OuvrirFichier(aFile);
387 // Lecture du nombre de champs
388 med_int ncha = MEDnField(medIdt) ;
391 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
392 QObject::tr("HOM_MED_FILE_5") );
396 // Lecture des caracteristiques des champs
397 for (int i=0; i< ncha; i++)
399 // Lecture du nombre de composantes
400 med_int ncomp = MEDfieldnComponent(medIdt,i+1);
401 // Lecture du type du champ, des noms des composantes et du nom de l'unite
402 char nomcha [MED_NAME_SIZE+1];
403 char meshname[MED_NAME_SIZE+1];
404 char * comp = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
405 char * unit = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
406 char dtunit[MED_SNAME_SIZE+1];
408 med_field_type typcha;
410 erreur = MEDfieldInfo(medIdt,i+1,nomcha,meshname,&local,&typcha,comp,unit,dtunit,&nbofcstp) ;
415 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
416 QObject::tr("HOM_MED_FILE_6") );
419 // Lecture des composantes si c'est le bon champ
420 if ( QString(nomcha) == aChamp )
422 for (int j = 0; j <ncomp; j++)
424 char cible[MED_SNAME_SIZE +1];
425 strncpy(cible,comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE );
426 cible[MED_SNAME_SIZE ]='\0';
427 ListeComposants.push_back(QString(cible));
432 // Sortie si c'est bon
433 if ( QString(nomcha) == aChamp ) { break ; }
437 // Fermeture du fichier
438 if ( medIdt > 0 ) MEDfileClose(medIdt);
440 return ListeComposants;