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
21 #include "HOMARDGUI_Utils.h"
23 #include "OB_Browser.h"
25 #include "SUIT_Desktop.h"
26 #include "SUIT_Application.h"
27 #include "SUIT_Session.h"
29 #include "LightApp_SelectionMgr.h"
30 #include "SalomeApp_Application.h"
31 #include "SalomeApp_Module.h"
32 #include "SalomeApp_Study.h"
34 #include "SALOME_ListIO.hxx"
35 #include "SALOME_ListIteratorOfListIO.hxx"
37 #include "SALOMEconfig.h"
38 #include "utilities.h"
40 #include <HOMARDGUI.h>
44 #include <qstringlist.h>
48 SALOME_ListIO HOMARD_UTILS::mySelected;
50 //================================================================
51 // Function : GetCStudy
52 // Returne un pointeur sur l'etude courante
53 //================================================================
54 _PTR(Study) HOMARD_UTILS::GetCStudy(const SalomeApp_Study* theStudy)
56 return theStudy->studyDS();
59 //================================================================
60 // Function : GetActiveStudy
61 // Returne un pointeur sur l'etude active
62 //================================================================
63 SUIT_Study* HOMARD_UTILS::GetActiveStudy()
65 SUIT_Application* app = SUIT_Session::session()->activeApplication();
67 return app->activeStudy();
72 //================================================================
73 // Function : GetActiveStudyDocument
74 // Returne un pointeur sur l'etude active
75 //================================================================
76 _PTR(Study) HOMARD_UTILS::GetActiveStudyDocument()
78 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(GetActiveStudy());
80 return aStudy->studyDS();
86 //================================================================
87 // Function : updateObjBrowser
88 // Purpose : met a jour l arbre d 'etude pour Homard
89 //================================================================
90 void HOMARD_UTILS::updateObjBrowser()
92 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
94 // Le nom identifiant doit etre la valeur du parametre
95 // name de la section HOMARD du fichier SalomeApp.xml
96 CAM_Module* module = app->module("Homard" );
97 SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>( module );
99 app->updateObjectBrowser();
100 appMod->updateObjBrowser( true );
103 MESSAGE( "--- HOMARD::updateObjBrowser: appMod = NULL");
107 //================================================================
108 // Function : selectedIO
109 // Return the list of selected SALOME_InteractiveObject's
110 //================================================================
111 const SALOME_ListIO& HOMARD_UTILS::selectedIO()
113 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* > ( SUIT_Session::session()->activeApplication() );
114 LightApp_SelectionMgr* aSelectionMgr = app->selectionMgr();
117 aSelectionMgr->selectedObjects( mySelected );
118 for (SALOME_ListIteratorOfListIO it (mySelected); it.More(); it.Next())
119 SCRUTE(it.Value()->getEntry());
124 //================================================================
125 // Function : IObjectCount
126 // Return the number of selected objects
127 //================================================================
128 int HOMARD_UTILS::IObjectCount()
130 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
131 LightApp_SelectionMgr* aSelectionMgr = app->selectionMgr();
134 aSelectionMgr->selectedObjects( mySelected );
135 SCRUTE(mySelected.Extent());
136 return mySelected.Extent();
141 //================================================================
142 // Function : firstIObject
143 // Purpose : Return the first selected object in the selected object list
144 //================================================================
145 Handle(SALOME_InteractiveObject) HOMARD_UTILS::firstIObject()
147 const SALOME_ListIO& aList = selectedIO();
148 return aList.Extent() > 0 ? aList.First() : Handle(SALOME_InteractiveObject)();
151 //================================================================
152 // Function : lastIObject
153 // Return the last selected object in the selected object list
154 //================================================================
155 Handle(SALOME_InteractiveObject) HOMARD_UTILS::lastIObject()
157 const SALOME_ListIO& aList = selectedIO();
158 return aList.Extent() > 0 ? aList.Last() : Handle(SALOME_InteractiveObject)();
161 //================================================================
162 // Retourne vrai si l objet est du type voulu
163 // . Dans le cas d'un cas, d'une hypothese, d'une zone, on se contente
164 // d'une comparaison simple entre le type stocke et TypeObject.
165 // . Pour l'iteration, le type stocke en attribut est sous la forme
166 // "IterationHomard" + le nom de l'iteration precedente.
167 // Il faut donc regarder si la chaine commence par TypeObject.
168 // . Idem pour le fichier de messages : "Mess " + numero d'iteration
170 // On filtre ce genre de situation avec option :
171 // -1 : comparaison totale
172 // 0 : comparaison sur le debut de la chaine
173 //================================================================
174 bool HOMARD_UTILS::isObject(_PTR(SObject) MonObj, QString TypeObject, int option)
176 // MESSAGE("isObject, TypeObject = "<<TypeObject.toStdString().c_str()<<", option = "<<option);
177 // Existence d'un attribut ?
178 _PTR(GenericAttribute) anAttr;
179 if ( !MonObj->FindAttribute(anAttr, "AttributeComment") ) return false;
181 _PTR(AttributeComment) aComment (anAttr);
182 QString Type = QString(aComment->Value().c_str());
183 // MESSAGE("Type = "<<Type.toStdString().c_str());
188 int position = Type.lastIndexOf(TypeObject);
189 if ( position == 0 ) { bOK = true ; }
193 if ( Type == TypeObject ) { bOK = true ; }
197 //================================================================
198 // Retourne vrai si l objet est une frontiere analytique
199 //================================================================
200 bool HOMARD_UTILS::isBoundaryAn(_PTR(SObject) MonObj)
202 return isObject( MonObj, QString("BoundaryAnHomard"), -1 ) ;
204 //================================================================
205 // Retourne vrai si l objet est une frontiere discrete
206 //================================================================
207 bool HOMARD_UTILS::isBoundaryDi(_PTR(SObject) MonObj)
209 return isObject( MonObj, QString("BoundaryDiHomard"), -1 ) ;
211 //================================================================
212 // Retourne vrai si l objet est un cas
213 //================================================================
214 bool HOMARD_UTILS::isCase(_PTR(SObject) MonObj)
216 return isObject( MonObj, QString("CasHomard"), -1 ) ;
218 //================================================================
219 // Retourne vrai si l objet est une Hypothese
220 //================================================================
221 bool HOMARD_UTILS::isHypo(_PTR(SObject) MonObj)
223 return isObject( MonObj, QString("HypoHomard"), -1 ) ;
225 //================================================================
226 // Retourne vrai si l objet est une iteration
227 //================================================================
228 bool HOMARD_UTILS::isIter(_PTR(SObject) MonObj)
230 return isObject( MonObj, QString("IterationHomard"), 0 ) ;
232 //================================================================
233 // Retourne vrai si l objet est un schema YACS
234 //================================================================
235 bool HOMARD_UTILS::isYACS(_PTR(SObject) MonObj)
237 return isObject( MonObj, QString("YACSHomard"), -1 ) ;
239 //================================================================
240 // Retourne vrai si l objet est une zone
241 //================================================================
242 bool HOMARD_UTILS::isZone(_PTR(SObject) MonObj)
244 return isObject( MonObj, QString("ZoneHomard"), -1 ) ;
246 //================================================================
247 // Retourne vrai si l objet est un fichier de type TypeFile
248 //================================================================
249 bool HOMARD_UTILS::isFileType(_PTR(SObject) MonObj, QString TypeFile)
251 return isObject( MonObj, TypeFile, 0 ) ;
254 //=========================================================================================================
255 void HOMARD_UTILS::PushOnHelp(QString monFichierAide, QString contexte, QString LanguageShort)
257 MESSAGE("Debut de PushOnHelp avec monFichierAide = "<< monFichierAide.toStdString().c_str());
258 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
261 HOMARDGUI* aHomardGUI = dynamic_cast<HOMARDGUI*>( app->module( "Homard" ) );
262 // Repertoire de reference de la documentation
263 QString rep = aHomardGUI ? app->moduleName(aHomardGUI->moduleName()) : QString("") ;
264 // WARNING/ATTENTION : si on savait recuperer la langue depuis les preferences, on ne fera pas le passage par argument
265 // SUIT_ResourceMgr* resMgr = getApp()->resourceMgr();
266 // SUIT_ResourceMgr* resMgr = myModule->getApp()->resourceMgr();
267 // QString langue = resMgr->stringValue("language", "language", "en");
268 // QString langue = "fr" ;
269 MESSAGE(". LanguageShort " << LanguageShort.toStdString().c_str()) ;
270 // Complement du fichier
271 QString fichier = QString(LanguageShort+"/"+monFichierAide) ;
272 MESSAGE(". Appel de onHelpContextModule avec :");
273 MESSAGE(" rep = "<< rep.toStdString().c_str());
274 MESSAGE(" fichier = "<< fichier.toStdString().c_str());
275 MESSAGE(" contexte = "<< contexte.toStdString().c_str());
277 app->onHelpContextModule(rep, fichier, contexte);
280 //=========================================================================================================