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>
34 #include "SalomeApp_Tools.h"
43 // ============================================================================
44 QString HOMARD_QT_COMMUN::SelectionArbreEtude(QString commentaire, int option )
45 // ============================================================================
46 // Retourne l'objet selectionne dans l'arbre d'etudes
48 // . si le commentaire est une chaine vide, on ne tient pas compte du type de l'objet
49 // et on retourne le nom de cet objet
51 // . si l'objet est du type defini par commentaitr, retourne le nom de cet objet
52 // . sinon on retourne une QString("")
54 // . Si option = 0, ce n'est pas grave de ne rien trouver ; aucun message n'est emis
55 // . Si option = 1, ce n'est pas grave de ne rien trouver mais on emet un message
57 MESSAGE("SelectionArbreEtude : commentaire = " << commentaire.toStdString().c_str() << " et option = " << option);
58 int nbSel = HOMARD_UTILS::IObjectCount() ;
63 QMessageBox::warning( 0, QObject::tr("HOM_WARNING"),
64 QObject::tr("HOM_SELECT_OBJECT_1") );
70 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
71 QObject::tr("HOM_SELECT_OBJECT_2") );
75 Handle(SALOME_InteractiveObject) aIO = HOMARD_UTILS::firstIObject();
76 if ( aIO->hasEntry() )
78 _PTR(Study) aStudy = HOMARD_UTILS::GetActiveStudyDocument();
79 _PTR(SObject) aSO ( aStudy->FindObjectID( aIO->getEntry() ) );
80 _PTR(GenericAttribute) anAttr;
81 if (aSO->FindAttribute(anAttr, "AttributeComment") )
83 if ( commentaire != "" )
85 _PTR(AttributeComment) attributComment = anAttr;
86 QString aComment= QString(attributComment->Value().data());
87 MESSAGE("... aComment = " << aComment.toStdString().c_str());
88 int iaux = aComment.lastIndexOf(commentaire);
89 MESSAGE("... iaux = " << iaux);
92 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
93 QObject::tr("HOM_SELECT_OBJECT_3").arg(commentaire) );
97 if (aSO->FindAttribute(anAttr, "AttributeName") )
99 _PTR(AttributeName) attributName = anAttr;
100 QString aName= QString(attributName->Value().data());
109 // =======================================================================
110 QString HOMARD_QT_COMMUN::SelectionCasEtude()
111 // =======================================================================
113 QString aName = QString("");
114 int nbSel = HOMARD_UTILS::IObjectCount() ;
117 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
118 QObject::tr("HOM_SELECT_OBJECT_1") );
123 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
124 QObject::tr("HOM_SELECT_OBJECT_2") );
127 Handle(SALOME_InteractiveObject) aIO = HOMARD_UTILS::firstIObject();
128 if ( aIO->hasEntry() )
130 _PTR(Study) aStudy = HOMARD_UTILS::GetActiveStudyDocument();
131 _PTR(SObject) aSO ( aStudy->FindObjectID( aIO->getEntry() ) );
132 _PTR(SObject) aSObjCas = aSO->GetFather();
133 _PTR(GenericAttribute) anAttr;
134 if (aSObjCas->FindAttribute(anAttr, "AttributeName") )
136 _PTR(AttributeName) attributName = anAttr;
137 aName= QString(attributName->Value().data());
144 // =======================================================================
145 QString HOMARD_QT_COMMUN::PushNomFichier(bool avertir)
146 // =======================================================================
147 // Gestion les boutons qui permettent de
148 // 1) retourne le nom d'un fichier par une fenetre de dialogue si aucun
149 // objet est selectionne dans l arbre d etude
150 // 2) retourne le nom du fichier asocie a l objet
151 // selectionne dans l arbre d etude
153 MESSAGE("PushNomFichier");
154 QString aFile=QString::null;
155 int nbSel = HOMARD_UTILS::IObjectCount() ;
158 aFile = QFileDialog::getOpenFileName(0,QString("File Selection"),QString("") ,QString("Med files (*.med);;all (*) ") );
162 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
163 QObject::tr("HOM_SELECT_FILE_2") );
167 Handle(SALOME_InteractiveObject) aIO = HOMARD_UTILS::firstIObject();
168 if ( aIO->hasEntry() )
170 _PTR(Study) aStudy = HOMARD_UTILS::GetActiveStudyDocument();
171 _PTR(SObject) aSO ( aStudy->FindObjectID( aIO->getEntry() ) );
172 _PTR(GenericAttribute) anAttr;
173 _PTR(AttributeFileType) aFileType;
174 _PTR(AttributeExternalFileDef) aFileName;
176 if (aSO->FindAttribute(anAttr, "AttributeFileType") ) {
178 QString fileType=QString(aFileType->Value().data());
179 if ( fileType==QString("FICHIERMED")) {
180 if (aSO->FindAttribute(anAttr,"AttributeExternalFileDef")) {
182 aFile= QString(aFileName->Value().data()); }
188 if ( aFile==QString::null )
191 QMessageBox::warning( 0, QObject::tr("HOM_WARNING"),
192 QObject::tr("HOM_SELECT_STUDY") );
194 aFile = QFileDialog::getOpenFileName();
195 if (!aFile.isEmpty())
204 // =======================================================================
205 int HOMARD_QT_COMMUN::OuvrirFichier(QString aFile)
206 // =======================================================================
207 // renvoie le medId associe au fichier Med apres ouverture
209 med_int medIdt = MEDfileOpen(aFile.toStdString().c_str(),MED_ACC_RDONLY);
212 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
213 QObject::tr("HOM_MED_FILE_1") );
218 // ======================================================
219 QString HOMARD_QT_COMMUN::LireNomMaillage(QString aFile)
220 // ========================================================
222 QString nomMaillage = "" ;
225 while ( erreur == 0 )
227 // Ouverture du fichier
228 medIdt = HOMARD_QT_COMMUN::OuvrirFichier(aFile);
234 med_int numberOfMeshes = MEDnMesh(medIdt) ;
235 if (numberOfMeshes == 0 )
237 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
238 QObject::tr("HOM_MED_FILE_2") );
242 if (numberOfMeshes > 1 )
244 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
245 QObject::tr("HOM_MED_FILE_3") );
250 nomMaillage = HOMARD_QT_COMMUN::LireNomMaillage(medIdt,1);
253 // Fermeture du fichier
254 if ( medIdt > 0 ) MEDfileClose(medIdt);
258 // =======================================================================
259 QString HOMARD_QT_COMMUN::LireNomMaillage(int medIdt ,int meshId)
260 // =======================================================================
262 QString NomMaillage=QString::null;
263 char meshname[MED_NAME_SIZE+1];
264 med_int spacedim,meshdim;
265 med_mesh_type meshtype;
266 char descriptionription[MED_COMMENT_SIZE+1];
267 char dtunit[MED_SNAME_SIZE+1];
268 med_sorting_type sortingtype;
270 med_axis_type axistype;
271 int naxis = MEDmeshnAxis(medIdt,1);
272 char *axisname=new char[naxis*MED_SNAME_SIZE+1];
273 char *axisunit=new char[naxis*MED_SNAME_SIZE+1];
274 med_err aRet = MEDmeshInfo(medIdt,
288 if ( aRet < 0 ) { QMessageBox::critical( 0, QObject::tr("HOM_ERROR"), \
289 QObject::tr("HOM_MED_FILE_4") ); }
290 else { NomMaillage=QString(meshname); }
299 // =======================================================================
300 std::list<QString> HOMARD_QT_COMMUN::GetListeChamps(QString aFile)
301 // =======================================================================
303 // Il faut voir si plusieurs maillages
305 MESSAGE("GetListeChamps");
306 std::list<QString> ListeChamp ;
311 while ( erreur == 0 )
313 // Ouverture du fichier
314 SCRUTE(aFile.toStdString());
315 medIdt = HOMARD_QT_COMMUN::OuvrirFichier(aFile);
321 // Lecture du nombre de champs
322 med_int ncha = MEDnField(medIdt) ;
325 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
326 QObject::tr("HOM_MED_FILE_5") );
330 // Lecture des caracteristiques des champs
331 for (int i=0; i< ncha; i++)
333 // Lecture du nombre de composantes
334 med_int ncomp = MEDfieldnComponent(medIdt,i+1);
335 // Lecture du type du champ, des noms des composantes et du nom de l'unite
336 char nomcha [MED_NAME_SIZE+1];
337 char meshname[MED_NAME_SIZE+1];
338 char * comp = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
339 char * unit = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
340 char dtunit[MED_SNAME_SIZE+1];
342 med_field_type typcha;
344 erreur = MEDfieldInfo(medIdt,i+1,nomcha,meshname,&local,&typcha,comp,unit,dtunit,&nbofcstp) ;
349 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
350 QObject::tr("HOM_MED_FILE_6") );
353 ListeChamp.push_back(QString(nomcha));
357 // Fermeture du fichier
358 if ( medIdt > 0 ) MEDfileClose(medIdt);
363 // ======================================================================================
364 std::list<QString> HOMARD_QT_COMMUN::GetListeComposants(QString aFile, QString aChamp)
365 // ======================================================================================
367 MESSAGE ( "GetListeComposants pour le fichier " << aFile.toStdString().c_str());
368 MESSAGE ( "GetListeComposants pour le champ " << aChamp.toStdString().c_str());
370 std::list<QString> ListeComposants;
375 while ( erreur == 0 )
377 // Ouverture du fichier
378 SCRUTE(aFile.toStdString());
379 medIdt = HOMARD_QT_COMMUN::OuvrirFichier(aFile);
385 // Lecture du nombre de champs
386 med_int ncha = MEDnField(medIdt) ;
389 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
390 QObject::tr("HOM_MED_FILE_5") );
394 // Lecture des caracteristiques des champs
395 for (int i=0; i< ncha; i++)
397 // Lecture du nombre de composantes
398 med_int ncomp = MEDfieldnComponent(medIdt,i+1);
399 // Lecture du type du champ, des noms des composantes et du nom de l'unite
400 char nomcha [MED_NAME_SIZE+1];
401 char meshname[MED_NAME_SIZE+1];
402 char * comp = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
403 char * unit = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
404 char dtunit[MED_SNAME_SIZE+1];
406 med_field_type typcha;
408 erreur = MEDfieldInfo(medIdt,i+1,nomcha,meshname,&local,&typcha,comp,unit,dtunit,&nbofcstp) ;
413 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
414 QObject::tr("HOM_MED_FILE_6") );
417 // Lecture des composantes si c'est le bon champ
418 if ( QString(nomcha) == aChamp )
420 for (int j = 0; j <ncomp; j++)
422 char cible[MED_SNAME_SIZE +1];
423 strncpy(cible,comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE );
424 cible[MED_SNAME_SIZE ]='\0';
425 ListeComposants.push_back(QString(cible));
430 // Sortie si c'est bon
431 if ( QString(nomcha) == aChamp ) { break ; }
435 // Fermeture du fichier
436 if ( medIdt > 0 ) MEDfileClose(medIdt);
438 return ListeComposants;