1 // Copyright (C) 2011-2012 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())
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 med_int medIdt = HOMARD_QT_COMMUN::OuvrirFichier(aFile);
225 med_int numberOfMeshes = MEDnMesh(medIdt) ;
226 if (numberOfMeshes == 0 )
228 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
229 QObject::tr("HOM_MED_FILE_2") );
231 if (numberOfMeshes > 1 )
233 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
234 QObject::tr("HOM_MED_FILE_3") );
237 QString nomMaillage= HOMARD_QT_COMMUN::LireNomMaillage(medIdt,1);
238 MEDfileClose(medIdt);
241 // =======================================================================
242 QString HOMARD_QT_COMMUN::LireNomMaillage(int medIdt ,int meshId)
243 // =======================================================================
245 QString NomMaillage=QString::null;
246 char meshname[MED_NAME_SIZE+1];
247 med_int spacedim,meshdim;
248 med_mesh_type meshtype;
249 char descriptionription[MED_COMMENT_SIZE+1];
250 char dtunit[MED_SNAME_SIZE+1];
251 med_sorting_type sortingtype;
253 med_axis_type axistype;
254 int naxis = MEDmeshnAxis(medIdt,1);
255 char *axisname=new char[naxis*MED_SNAME_SIZE+1];
256 char *axisunit=new char[naxis*MED_SNAME_SIZE+1];
257 med_err aRet = MEDmeshInfo(medIdt,
273 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
274 QObject::tr("HOM_MED_FILE_4") );
278 NomMaillage=QString(meshname);
284 // =======================================================================
285 std::list<QString> HOMARD_QT_COMMUN::GetListeChamps(QString aFile)
286 // =======================================================================
288 // Il faut voir si plusieurs maillages
290 MESSAGE("GetListeChamps");
291 std::list<QString> ListeChamp;
294 char nomcha [MED_NAME_SIZE+1];
295 char meshname[MED_NAME_SIZE+1];
296 med_field_type typcha;
301 SCRUTE(aFile.toStdString());
302 med_int medIdt = HOMARD_QT_COMMUN::OuvrirFichier(aFile);
303 if ( medIdt < 0 ) { return ListeChamp; }
305 // Le fichier Med est lisible
306 // Lecture du maillage
308 // Lecture du nombre de champs
309 med_int ncha = MEDnField(medIdt) ;
312 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
313 QObject::tr("HOM_MED_FILE_5") );
314 MEDfileClose(medIdt);
318 for (int i=0; i< ncha; i++)
320 /* Lecture du type du champ, des noms des composantes et du nom de l'unite*/
321 ncomp = MEDfieldnComponent(medIdt,i+1);
322 comp = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
323 unit = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
324 char dtunit[MED_SNAME_SIZE+1];
325 if ( MEDfieldInfo(medIdt,i+1,nomcha,meshname,&local,&typcha,comp,unit,dtunit,&nbofcstp) < 0 )
327 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
328 QObject::tr("HOM_MED_FILE_6") );
329 MEDfileClose(medIdt);
333 ListeChamp.push_back(QString(nomcha));
337 MEDfileClose(medIdt);
341 // ======================================================================================
342 std::list<QString> HOMARD_QT_COMMUN::GetListeComposants(QString aFile, QString aChamp)
343 // ======================================================================================
345 MESSAGE ( "GetListeComposants pour le fichier " << aFile.toStdString().c_str());
346 MESSAGE ( "GetListeComposants pour le champ " << aChamp.toStdString().c_str());
348 std::list<QString> ListeComposants;
351 char nomcha [MED_NAME_SIZE+1];
352 char meshname[MED_NAME_SIZE+1];
353 med_field_type typcha;
358 int medIdt = HOMARD_QT_COMMUN::OuvrirFichier(aFile);
359 if ( medIdt < 0 ) { return ListeComposants; }
362 // Lecture du nombre de champs
363 med_int ncha = MEDnField(medIdt) ;
366 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
367 QObject::tr("HOM_MED_FILE_5") );
368 MEDfileClose(medIdt);
369 return ListeComposants;
372 for (int i=0; i< ncha; i++)
374 /* Lecture du type du champ, des noms des composantes et du nom de l'unite*/
375 ncomp = MEDfieldnComponent(medIdt,i+1);
376 comp = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
377 unit = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
378 char dtunit[MED_SNAME_SIZE+1];
380 if ( MEDfieldInfo(medIdt,i+1,nomcha,meshname,&local,&typcha,comp,unit,dtunit,&nbofcstp) < 0 )
382 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
383 QObject::tr("HOM_MED_FILE_6") );
384 MEDfileClose(medIdt);
385 return ListeComposants;
388 if ( QString(nomcha) != aChamp ) {
394 for (int j = 0; j <ncomp; j++)
396 char cible[MED_SNAME_SIZE +1];
397 strncpy(cible,comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE );
398 cible[MED_SNAME_SIZE ]='\0';
399 ListeComposants.push_back(QString(cible));
405 MEDfileClose(medIdt);
406 return ListeComposants;