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::information( 0, "Bad selection",
39 QString("Select an object."),
40 QMessageBox::Ok + QMessageBox::Default );
46 QMessageBox::information( 0, "Bad selection",
47 QString("Select one object only."),
48 QMessageBox::Ok + QMessageBox::Default );
52 Handle(SALOME_InteractiveObject) aIO = HOMARD_UTILS::firstIObject();
53 if ( aIO->hasEntry() )
55 _PTR(Study) aStudy = HOMARD_UTILS::GetActiveStudyDocument();
56 _PTR(SObject) aSO ( aStudy->FindObjectID( aIO->getEntry() ) );
57 _PTR(GenericAttribute) anAttr;
58 if (aSO->FindAttribute(anAttr, "AttributeComment") )
60 _PTR(AttributeComment) attributComment = anAttr;
61 QString aComment= QString(attributComment->Value().data());
62 int iteration = aComment.lastIndexOf(commentaire);
65 QString message=QString("Select an object : ");
66 message += commentaire;
67 QMessageBox::information( 0, "Bad selection", message,
68 QMessageBox::Ok + QMessageBox::Default );
71 if (aSO->FindAttribute(anAttr, "AttributeName") )
73 _PTR(AttributeName) attributName = anAttr;
74 QString aName= QString(attributName->Value().data());
82 // =======================================================================
83 QString HOMARD_QT_COMMUN::SelectionCasEtude()
84 // =======================================================================
86 QString aName = QString("");
87 int nbSel = HOMARD_UTILS::IObjectCount() ;
88 if ((nbSel > 1) or ( nbSel == 0 ))
90 QMessageBox::information( 0, "Bad selection",
91 QString("Select one object only"),
92 QMessageBox::Ok + QMessageBox::Default );
95 Handle(SALOME_InteractiveObject) aIO = HOMARD_UTILS::firstIObject();
96 if ( aIO->hasEntry() )
98 _PTR(Study) aStudy = HOMARD_UTILS::GetActiveStudyDocument();
99 _PTR(SObject) aSO ( aStudy->FindObjectID( aIO->getEntry() ) );
100 _PTR(SObject) aSObjCas = aSO->GetFather();
101 _PTR(GenericAttribute) anAttr;
102 if (aSObjCas->FindAttribute(anAttr, "AttributeName") )
104 _PTR(AttributeName) attributName = anAttr;
105 aName= QString(attributName->Value().data());
112 // =======================================================================
113 QString HOMARD_QT_COMMUN::PushNomFichier(bool avertir)
114 // =======================================================================
115 // Gestion les boutons qui permettent de
116 // 1) retourne le nom d'un fichier par une fenetre de dialogue si aucun
117 // objet est selectionne dans l arbre d etude
118 // 2) retourne le nom du fichier asocie a l objet
119 // selectionne dans l arbre d etude
121 MESSAGE("HOMARD_QT_COMMUN::PushNomFichier");
122 QString aFile=QString::null;
123 int nbSel = HOMARD_UTILS::IObjectCount() ;
126 aFile = QFileDialog::getOpenFileName(0,QString("File Selection"),QString("") ,QString("Med files (*.med);;all (*) ") );
130 QMessageBox::information( 0, "Bad selection",
131 QString("Select one file only"),
132 QMessageBox::Ok + QMessageBox::Default );
136 Handle(SALOME_InteractiveObject) aIO = HOMARD_UTILS::firstIObject();
137 if ( aIO->hasEntry() )
139 _PTR(Study) aStudy = HOMARD_UTILS::GetActiveStudyDocument();
140 _PTR(SObject) aSO ( aStudy->FindObjectID( aIO->getEntry() ) );
141 _PTR(GenericAttribute) anAttr;
142 _PTR(AttributeFileType) aFileType;
143 _PTR(AttributeExternalFileDef) aFileName;
145 if (aSO->FindAttribute(anAttr, "AttributeFileType") ) {
147 QString fileType=QString(aFileType->Value().data());
148 if ( fileType==QString("FICHIERMED")) {
149 if (aSO->FindAttribute(anAttr,"AttributeExternalFileDef")) {
151 aFile= QString(aFileName->Value().data()); } } } } }
153 if ( aFile==QString::null )
156 QMessageBox::information( 0, "Bad selection",
157 QString(" Select a study object with associated MED file \n or a MED file"),
158 QMessageBox::Ok + QMessageBox::Default );
160 aFile = QFileDialog::getOpenFileName();
161 if (!aFile.isEmpty())
172 // =======================================================================
173 int HOMARD_QT_COMMUN::OuvrirFichier(QString aFile)
174 // =======================================================================
175 // renvoie le medId associe au fichier Med apres ouverture
177 int MedIdt = MEDouvrir(const_cast<char *>(aFile.toStdString().c_str()),MED_LECTURE);
180 QMessageBox::information( 0, "Bad selection",
181 QString("MED File is unreadable"),
182 QMessageBox::Ok + QMessageBox::Default );
187 // ======================================================
188 QString HOMARD_QT_COMMUN::LireNomMaillage(QString aFile)
189 // ========================================================
192 int MedIdt = HOMARD_QT_COMMUN::OuvrirFichier(aFile);
193 int numberOfMeshes = MEDnMaa(MedIdt) ;
194 if (numberOfMeshes != 1 )
196 QMessageBox::information( 0, "Bad selection",
197 QString("MED File contains more than one mesh"),
198 QMessageBox::Ok + QMessageBox::Default );
201 QString nomMaillage= HOMARD_QT_COMMUN::LireNomMaillage(MedIdt,1);
205 // =======================================================================
206 QString HOMARD_QT_COMMUN::LireNomMaillage(int MedIdt ,int MeshId)
207 // =======================================================================
209 QString NomMaillage=QString::null;
210 char maa[MED_TAILLE_NOM+1];
211 char desc[MED_TAILLE_DESC+1];
215 if ( MEDmaaInfo(MedIdt,MeshId,maa,&mdim,&type,desc) < 0 )
217 QMessageBox::information( 0, "Bad selection",
218 QString("Error : Mesh is unreadable"),
219 QMessageBox::Ok + QMessageBox::Default );
223 NomMaillage=QString(maa);
229 // =======================================================================
230 std::list<QString> HOMARD_QT_COMMUN::GetListeChamps(QString aFile)
231 // =======================================================================
233 // Il faut voir si plusieurs maillages
235 MESSAGE("HOMARD_QT_COMMUN::GetListeChamps");
236 std::list<QString> ListeChamp;
239 char nomcha [MED_TAILLE_NOM+1];
240 med_type_champ typcha;
243 SCRUTE(aFile.toStdString());
244 int MedIdt = HOMARD_QT_COMMUN::OuvrirFichier(aFile);
245 if ( MedIdt < 0 ) { return ListeChamp; }
247 // Le fichier Med est lisible
248 // Lecture du maillage
250 // Lecture du nombre de champs
251 med_int ncha = MEDnChamp(MedIdt, 0) ;
254 QMessageBox::information( 0, "Bad selection",
255 QString(" Error : Fields are unreadable"),
256 QMessageBox::Ok + QMessageBox::Default );
261 for (int i=0; i< ncha; i++)
263 if ((ncomp = MEDnChamp(MedIdt,i+1)) < 0)
265 QMessageBox::information( 0, "Bad selection",
266 QString("Error : field's componants are unreadable"),
267 QMessageBox::Ok + QMessageBox::Default );
272 /* Lecture du type du champ, des noms des composantes et du nom de l'unite*/
273 comp = (char*) malloc(ncomp*MED_TAILLE_PNOM+1);
274 unit = (char*) malloc(ncomp*MED_TAILLE_PNOM+1);
275 if ( MEDchampInfo(MedIdt,i+1,nomcha,&typcha,comp,unit,ncomp) < 0 )
277 QMessageBox::information( 0, "Bad selection",
278 QString(" Error : Fields are unreadable"),
279 QMessageBox::Ok + QMessageBox::Default );
284 ListeChamp.push_back(QString(nomcha));
292 // ======================================================================================
293 std::list<QString> HOMARD_QT_COMMUN::GetListeComposants(QString aFile, QString aChamp)
294 // ======================================================================================
296 MESSAGE ( "GetListeComposants pour le fichier " << aFile.toStdString().c_str());
297 MESSAGE ( "GetListeComposants pour le champ " << aChamp.toStdString().c_str());
299 std::list<QString> ListeComposants;
302 char nomcha [MED_TAILLE_NOM+1];
303 med_type_champ typcha;
306 int MedIdt = HOMARD_QT_COMMUN::OuvrirFichier(aFile);
307 if ( MedIdt < 0 ) { return ListeComposants; }
310 // Lecture du nombre de champs
311 med_int ncha = MEDnChamp(MedIdt, 0) ;
314 QMessageBox::information( 0, "Bad selection",
315 QString(" Error : Fields are unreadable"),
316 QMessageBox::Ok + QMessageBox::Default );
318 return ListeComposants;
321 for (int i=0; i< ncha; i++)
323 if ((ncomp = MEDnChamp(MedIdt,i+1)) < 0)
325 QMessageBox::information( 0, "Bad selection",
326 QString("Error : field's componants are unreadable"),
327 QMessageBox::Ok + QMessageBox::Default );
329 return ListeComposants;
332 /* Lecture du type du champ, des noms des composantes et du nom de l'unite*/
333 comp = (char*) malloc(ncomp*MED_TAILLE_PNOM+1);
334 unit = (char*) malloc(ncomp*MED_TAILLE_PNOM+1);
336 if ( MEDchampInfo(MedIdt,i+1,nomcha,&typcha,comp,unit,ncomp) < 0 )
338 QMessageBox::information( 0, "Bad selection",
339 QString(" Error : Fields are unreadable"),
340 QMessageBox::Ok + QMessageBox::Default );
342 return ListeComposants;
344 if ( QString(nomcha) != aChamp ) {
349 for (int j = 0; j <ncomp; j++)
351 char cible[MED_TAILLE_PNOM +1];
352 strncpy(cible,comp+j*MED_TAILLE_PNOM,MED_TAILLE_PNOM );
353 cible[MED_TAILLE_PNOM ]='\0';
354 ListeComposants.push_back(QString(cible));
361 return ListeComposants;
364 // =======================================================================
365 void HOMARD_QT_COMMUN::Recopie(QString aDir, QString aFichier)
366 // =======================================================================
368 if (chdir(aDir.toLatin1()) != 0)
370 if (mkdir(aDir.toLatin1(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
372 QMessageBox::information( 0, "ERROR",
373 QString("Unable to create directory."),
374 QMessageBox::Ok + QMessageBox::Default );
376 //ASSERT("Pb a la creation de la directory" == 0);
378 if (chdir(aDir.toLatin1()) != 0)
380 QMessageBox::information( 0, "ERROR",
381 QString("Unable to access directory."),
382 QMessageBox::Ok + QMessageBox::Default );
384 //ASSERT("Pb pour acceder la directory" == 0);
387 QString copie = QString("cp ")+aFichier+QString(" ")+aDir;
388 system(copie.toLatin1());
391 // =======================================================================
392 void HOMARD_QT_COMMUN::Creetmp()
393 // =======================================================================
395 QString aDir=QString("/tmp/Homard/");
396 if (chdir(aDir.toLatin1()) != 0)
398 if (mkdir(aDir.toLatin1(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
400 QMessageBox::information( 0, "ERROR",
401 QString("Unable to create directory /tmp/Homard."),
402 QMessageBox::Ok + QMessageBox::Default );
405 if (chdir(aDir.toLatin1()) != 0)
407 QMessageBox::information( 0, "ERROR",
408 QString("Unable to access directory /tmp/Homard."),
409 QMessageBox::Ok + QMessageBox::Default );