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 int MedIdt = MEDouvrir(const_cast<char *>(aFile.toStdString().c_str()),MED_LECTURE);
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 int MedIdt = HOMARD_QT_COMMUN::OuvrirFichier(aFile);
195 int numberOfMeshes = MEDnMaa(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);
211 // =======================================================================
212 QString HOMARD_QT_COMMUN::LireNomMaillage(int MedIdt ,int MeshId)
213 // =======================================================================
215 QString NomMaillage=QString::null;
216 char maa[MED_TAILLE_NOM+1];
217 char desc[MED_TAILLE_DESC+1];
221 if ( MEDmaaInfo(MedIdt,MeshId,maa,&mdim,&type,desc) < 0 )
223 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
224 QObject::tr("HOM_MED_FILE_4") );
228 NomMaillage=QString(maa);
234 // =======================================================================
235 std::list<QString> HOMARD_QT_COMMUN::GetListeChamps(QString aFile)
236 // =======================================================================
238 // Il faut voir si plusieurs maillages
240 MESSAGE("HOMARD_QT_COMMUN::GetListeChamps");
241 std::list<QString> ListeChamp;
244 char nomcha [MED_TAILLE_NOM+1];
245 med_type_champ typcha;
248 SCRUTE(aFile.toStdString());
249 int MedIdt = HOMARD_QT_COMMUN::OuvrirFichier(aFile);
250 if ( MedIdt < 0 ) { return ListeChamp; }
252 // Le fichier Med est lisible
253 // Lecture du maillage
255 // Lecture du nombre de champs
256 med_int ncha = MEDnChamp(MedIdt, 0) ;
259 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
260 QObject::tr("HOM_MED_FILE_5") );
265 for (int i=0; i< ncha; i++)
267 /* Lecture du type du champ, des noms des composantes et du nom de l'unite*/
268 ncomp = MEDnChamp(MedIdt,i+1);
269 comp = (char*) malloc(ncomp*MED_TAILLE_PNOM+1);
270 unit = (char*) malloc(ncomp*MED_TAILLE_PNOM+1);
271 if ( MEDchampInfo(MedIdt,i+1,nomcha,&typcha,comp,unit,ncomp) < 0 )
273 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
274 QObject::tr("HOM_MED_FILE_6") );
279 ListeChamp.push_back(QString(nomcha));
287 // ======================================================================================
288 std::list<QString> HOMARD_QT_COMMUN::GetListeComposants(QString aFile, QString aChamp)
289 // ======================================================================================
291 MESSAGE ( "GetListeComposants pour le fichier " << aFile.toStdString().c_str());
292 MESSAGE ( "GetListeComposants pour le champ " << aChamp.toStdString().c_str());
294 std::list<QString> ListeComposants;
297 char nomcha [MED_TAILLE_NOM+1];
298 med_type_champ typcha;
301 int MedIdt = HOMARD_QT_COMMUN::OuvrirFichier(aFile);
302 if ( MedIdt < 0 ) { return ListeComposants; }
305 // Lecture du nombre de champs
306 med_int ncha = MEDnChamp(MedIdt, 0) ;
309 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
310 QObject::tr("HOM_MED_FILE_5") );
312 return ListeComposants;
315 for (int i=0; i< ncha; i++)
317 /* Lecture du type du champ, des noms des composantes et du nom de l'unite*/
318 ncomp = MEDnChamp(MedIdt,i+1);
319 comp = (char*) malloc(ncomp*MED_TAILLE_PNOM+1);
320 unit = (char*) malloc(ncomp*MED_TAILLE_PNOM+1);
322 if ( MEDchampInfo(MedIdt,i+1,nomcha,&typcha,comp,unit,ncomp) < 0 )
324 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
325 QObject::tr("HOM_MED_FILE_6") );
327 return ListeComposants;
329 if ( QString(nomcha) != aChamp ) {
334 for (int j = 0; j <ncomp; j++)
336 char cible[MED_TAILLE_PNOM +1];
337 strncpy(cible,comp+j*MED_TAILLE_PNOM,MED_TAILLE_PNOM );
338 cible[MED_TAILLE_PNOM ]='\0';
339 ListeComposants.push_back(QString(cible));
346 return ListeComposants;