2 #include "HOMARDGUI_Utils.h"
4 #include "OB_Browser.h"
6 #include "SUIT_Desktop.h"
7 #include "SUIT_Application.h"
8 #include "SUIT_Session.h"
10 #include "LightApp_SelectionMgr.h"
11 #include "SalomeApp_Application.h"
12 #include "SalomeApp_Module.h"
13 #include "SalomeApp_Study.h"
15 #include "SALOME_ListIO.hxx"
16 #include "SALOME_ListIteratorOfListIO.hxx"
18 #include "SALOMEconfig.h"
19 #include "utilities.h"
21 #include <HOMARDGUI.h>
25 #include <qstringlist.h>
29 SALOME_ListIO HOMARD_UTILS::mySelected;
31 //================================================================
32 // Function : GetCStudy
33 // Returne un pointeur sur l'etude courante
34 //================================================================
35 _PTR(Study) HOMARD_UTILS::GetCStudy(const SalomeApp_Study* theStudy)
37 return theStudy->studyDS();
41 //================================================================
42 // Function : GetActiveStudy
43 // Returne un pointeur sur l'etude active
44 //================================================================
45 SUIT_Study* HOMARD_UTILS::GetActiveStudy()
47 SUIT_Application* app = SUIT_Session::session()->activeApplication();
49 return app->activeStudy();
54 //================================================================
55 // Function : GetActiveStudyDocument
56 // Returne un pointeur sur l'etude active
57 //================================================================
58 _PTR(Study) HOMARD_UTILS::GetActiveStudyDocument()
60 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(GetActiveStudy());
62 return aStudy->studyDS();
68 //================================================================
69 // Function : updateObjBrowser
70 // Purpose : met a jour l arbre d 'etude pour Homard
71 //================================================================
72 void HOMARD_UTILS::updateObjBrowser()
74 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
76 // Le nom identifiant doit etre la valeur du parametre
77 // name de la section HOMARD du fichier SalomeApp.xml
78 CAM_Module* module = app->module("Homard" );
79 SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>( module );
81 app->updateObjectBrowser();
82 appMod->updateObjBrowser( true );
85 MESSAGE( "--- HOMARD::updateObjBrowser: appMod = NULL");
89 //================================================================
90 // Function : selectedIO
91 // Return the list of selected SALOME_InteractiveObject's
92 //================================================================
93 const SALOME_ListIO& HOMARD_UTILS::selectedIO()
95 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* > ( SUIT_Session::session()->activeApplication() );
96 LightApp_SelectionMgr* aSelectionMgr = app->selectionMgr();
99 aSelectionMgr->selectedObjects( mySelected );
100 for (SALOME_ListIteratorOfListIO it (mySelected); it.More(); it.Next())
101 SCRUTE(it.Value()->getEntry());
107 //================================================================
108 // Function : IObjectCount
109 // Return the number of selected objects
110 //================================================================
111 int HOMARD_UTILS::IObjectCount()
113 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
114 LightApp_SelectionMgr* aSelectionMgr = app->selectionMgr();
117 aSelectionMgr->selectedObjects( mySelected );
118 SCRUTE(mySelected.Extent());
119 return mySelected.Extent();
124 //================================================================
125 // Function : firstIObject
126 // Purpose : Return the first selected object in the selected object list
127 //================================================================
128 Handle(SALOME_InteractiveObject) HOMARD_UTILS::firstIObject()
130 const SALOME_ListIO& aList = selectedIO();
131 return aList.Extent() > 0 ? aList.First() : Handle(SALOME_InteractiveObject)();
134 //================================================================
135 // Function : lastIObject
136 // Return the last selected object in the selected object list
137 //================================================================
138 Handle(SALOME_InteractiveObject) HOMARD_UTILS::lastIObject()
140 const SALOME_ListIO& aList = selectedIO();
141 return aList.Extent() > 0 ? aList.Last() : Handle(SALOME_InteractiveObject)();
144 //================================================================
145 // Function : isXmgrace
146 // Retourne vrai si le fichier associe est de type ASCII
147 //================================================================
148 bool HOMARD_UTILS::isXmgrace(_PTR(SObject) MonObj)
150 _PTR(GenericAttribute) anAttr;
151 if (!MonObj->FindAttribute(anAttr, "AttributeComment")) return false;
152 _PTR(AttributeComment) aFileComment (anAttr);
153 std::string Type = aFileComment->Value();
154 if (QString(Type.c_str()) == QString("HomardOuputQual")) return true;
157 //================================================================
158 // Retourne vrai si l objet est du type voulu
159 // . Dans le cas d'un cas, d'une hypothese, d'une zone, on se contente
160 // d'une comparaison simple entre le type stocke et TypeObject.
161 // . Pour l'iteration, le type stocke en attribut est sous la forme
162 // "IterationHomard" + le nom de l'iteration precedente.
163 // Il faut donc regarder si la chaine commence par TypeObject.
164 // . Idem pour le fichier de messages : "Mess " + numero d'iteration
166 // On filtre ce genre de situation avec option :
167 // -1 : comparaison totale
168 // 0 : comparaison sur le debut de la chaine
169 //================================================================
170 bool HOMARD_UTILS::isObject(_PTR(SObject) MonObj, QString TypeObject, int option)
172 // MESSAGE("isObject, TypeObject = "<<TypeObject.toStdString().c_str()<<", option = "<<option);
173 // Existence d'un attribut ?
174 _PTR(GenericAttribute) anAttr;
175 if ( !MonObj->FindAttribute(anAttr, "AttributeComment") ) return false;
177 _PTR(AttributeComment) aComment (anAttr);
178 QString Type = QString(aComment->Value().c_str());
179 // MESSAGE("Type = "<<Type.toStdString().c_str());
184 int position = Type.lastIndexOf(TypeObject);
185 if ( position == 0 ) { bOK = true ; }
189 if ( Type == TypeObject ) { bOK = true ; }
193 //================================================================
194 // Retourne vrai si l objet est une frontiere analytique
195 //================================================================
196 bool HOMARD_UTILS::isBoundaryAn(_PTR(SObject) MonObj)
198 return isObject( MonObj, QString("BoundaryAnHomard"), -1 ) ;
200 //================================================================
201 // Retourne vrai si l objet est une frontiere discrete
202 //================================================================
203 bool HOMARD_UTILS::isBoundaryDi(_PTR(SObject) MonObj)
205 return isObject( MonObj, QString("BoundaryDiHomard"), -1 ) ;
207 //================================================================
208 // Retourne vrai si l objet est une zone
209 //================================================================
210 bool HOMARD_UTILS::isZone(_PTR(SObject) MonObj)
212 return isObject( MonObj, QString("ZoneHomard"), -1 ) ;
214 //================================================================
215 // Retourne vrai si l objet est une Hypothese
216 //================================================================
217 bool HOMARD_UTILS::isHypo(_PTR(SObject) MonObj)
219 return isObject( MonObj, QString("HypoHomard"), -1 ) ;
221 //================================================================
222 // Retourne vrai si l objet est une iteration
223 //================================================================
224 bool HOMARD_UTILS::isIter(_PTR(SObject) MonObj)
226 return isObject( MonObj, QString("IterationHomard"), 0 ) ;
228 //================================================================
229 // Retourne vrai si l objet est un cas
230 //================================================================
231 bool HOMARD_UTILS::isCase(_PTR(SObject) MonObj)
233 return isObject( MonObj, QString("CasHomard"), -1 ) ;
235 //================================================================
236 // Retourne vrai si l objet est un fichier de messages
237 //================================================================
238 bool HOMARD_UTILS::isFileMess(_PTR(SObject) MonObj)
240 return isObject( MonObj, QString("Mess"), 0 ) ;
242 //================================================================
243 // Retourne vrai si l objet est un fichier de bilan
244 //================================================================
245 bool HOMARD_UTILS::isFileSummary(_PTR(SObject) MonObj)
247 return isObject( MonObj, QString("Summary"), 0 ) ;
249 //================================================================
250 // Function : ChercheFileDansSelection
251 // Retourne Le nom du fichier associe
252 //================================================================
253 QString HOMARD_UTILS::ChercheFileDansSelection()
255 MESSAGE("ChercheFileDansSelection");
256 int nbSel = HOMARD_UTILS::IObjectCount() ;
257 if (nbSel > 1 or nbSel == 0) return QString::null;
259 Handle(SALOME_InteractiveObject) aIO = HOMARD_UTILS::firstIObject();
261 if (!( aIO->hasEntry())) return QString::null;
263 _PTR(Study) myStudy = HOMARD_UTILS::GetActiveStudyDocument();
264 _PTR(SObject) aSObj ( myStudy->FindObjectID( aIO->getEntry() ) );
265 if (!aSObj) return QString::null;
267 _PTR(GenericAttribute) anAttr;
268 if (!aSObj->FindAttribute(anAttr, "AttributeExternalFileDef")) return QString::null;
269 _PTR(AttributeExternalFileDef) aFileName (anAttr);
270 std::string aFile = aFileName->Value();
272 return QString(aFile.c_str());
275 //============================================================
276 // Function ChercheDansDir
277 // Cherche tous les fichiers dans la directory qui correspondent
278 // a la fois a la base et au numero d iteration, numero d iteration +1
279 // exple info.00.bilan
280 // ou qual.tetr.00.dat
281 //================================================================================
282 QStringList HOMARD_UTILS::ChercheDansDir(QString direct, QString base, int numIter)
283 //================================================================================
288 QString strNum = QString("");
289 if (numIter != -1) strNum = HOMARD_UTILS::Transforme(numIter);
290 QString strNum1 = QString("");
291 if (numIter != -1) strNum1 = HOMARD_UTILS::Transforme(numIter+1);
293 struct dirent **namelist;
294 int n = scandir(direct.toLatin1(), &namelist, 0, alphasort);
297 QString fich =QString( namelist[n]->d_name);
298 if (fich.contains(base) > 0)
302 if ((fich.contains(strNum)>0) or (fich.contains(strNum1)>0))
314 QString HOMARD_UTILS::Transforme(int num)
316 std::ostringstream nb ;
317 nb << std::setw(2) << std::setfill('0') << num ;
318 QString retour= QString(nb.str().c_str());
323 //=============================================================================
324 void HOMARD_UTILS::AddNewRoot(int Tag, QString Racine)
325 //=============================================================================
327 _PTR(Study) myStudy = HOMARD_UTILS::GetActiveStudyDocument();
329 _PTR(StudyBuilder) myBuilder( myStudy->NewBuilder() );
331 _PTR(SComponent) aFather=myStudy->FindComponent("HOMARD");
334 _PTR(SObject) InfoRoot = myBuilder->NewObjectToTag (aFather, Tag);
335 _PTR(GenericAttribute) anAttr;
336 anAttr = myBuilder->FindOrCreateAttribute(InfoRoot, "AttributeName");
337 _PTR(AttributeName) aName (anAttr);
338 aName->SetValue(Racine.toStdString());
340 //=============================================================================
341 void HOMARD_UTILS::RangeSousTag(int Tag,QString FileName, int TagFichier, QString Comment,QString FileDir)
342 //=============================================================================
345 _PTR(Study) myStudy = HOMARD_UTILS::GetActiveStudyDocument();
347 _PTR(StudyBuilder) myBuilder( myStudy->NewBuilder() );
349 _PTR(SComponent) aFather=myStudy->FindComponent("HOMARD");
351 bool found = aFather->FindSubObject(Tag,Root);
354 _PTR(SObject) MonInfo = myBuilder->NewObjectToTag (Root, TagFichier);
356 _PTR(GenericAttribute) anAttr;
357 anAttr = myBuilder->FindOrCreateAttribute(MonInfo, "AttributeName");
358 _PTR(AttributeName) aName (anAttr);
359 aName->SetValue(FileName.toStdString());
360 QString FileComplet = FileDir +QString("/") +FileName;
361 anAttr = myBuilder->FindOrCreateAttribute(MonInfo, "AttributeExternalFileDef");
362 _PTR(AttributeExternalFileDef) aFile (anAttr);
363 aFile->SetValue((FileComplet).toStdString());
364 anAttr = myBuilder->FindOrCreateAttribute(MonInfo, "AttributeComment");
365 _PTR(AttributeComment) aComment (anAttr);
366 aComment->SetValue(Comment.toStdString());
369 //=========================================================================================================
370 void HOMARD_UTILS::PushOnHelp(QString monFichierAide)
372 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
374 HOMARDGUI* aHomardGUI = dynamic_cast<HOMARDGUI*>( app->module( "Homard" ) );
375 app->onHelpContextModule(aHomardGUI ? app->moduleName(aHomardGUI->moduleName()) : QString(""), monFichierAide);
379 //=========================================================================================================