1 // Copyright (C) 2011-2023 CEA, EDF
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, or (at your option) any later version.
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"
36 #include "SALOMEconfig.h"
37 #include "utilities.h"
39 #include <HOMARDGUI.h>
43 #include <qstringlist.h>
49 SALOME_ListIO HOMARD_UTILS::mySelected;
51 //================================================================
52 // Function : GetActiveStudy
53 // Returne un pointeur sur l'etude active
54 //================================================================
55 SUIT_Study* HOMARD_UTILS::GetActiveStudy()
57 SUIT_Application* app = SUIT_Session::session()->activeApplication();
59 return app->activeStudy();
64 //================================================================
65 // Function : getStudy
66 // Returne un pointeur sur l'etude active
67 //================================================================
68 _PTR(Study) HOMARD_UTILS::getStudy()
70 static _PTR(Study) _study;
72 _study = SalomeApp_Application::getStudy();
76 //================================================================
77 // Function : updateObjBrowser
78 // Purpose : met a jour l arbre d 'etude pour Homard
79 //================================================================
80 void HOMARD_UTILS::updateObjBrowser()
82 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
84 // Le nom identifiant doit etre la valeur du parametre
85 // name de la section HOMARD du fichier SalomeApp.xml
86 CAM_Module* module = app->module("Homard" );
87 SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>( module );
89 app->updateObjectBrowser();
90 appMod->updateObjBrowser( true );
93 MESSAGE( "--- HOMARD::updateObjBrowser: appMod = NULL");
97 //================================================================
98 // Function : selectedIO
99 // Return the list of selected SALOME_InteractiveObject's
100 //================================================================
101 const SALOME_ListIO& HOMARD_UTILS::selectedIO()
103 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* > ( SUIT_Session::session()->activeApplication() );
104 LightApp_SelectionMgr* aSelectionMgr = app->selectionMgr();
107 aSelectionMgr->selectedObjects( mySelected );
108 for (SALOME_ListIteratorOfListIO it (mySelected); it.More(); it.Next())
109 SCRUTE(it.Value()->getEntry());
114 //================================================================
115 // Function : IObjectCount
116 // Return the number of selected objects
117 //================================================================
118 int HOMARD_UTILS::IObjectCount()
120 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
121 LightApp_SelectionMgr* aSelectionMgr = app->selectionMgr();
124 aSelectionMgr->selectedObjects( mySelected );
125 SCRUTE(mySelected.Extent());
126 return mySelected.Extent();
131 //================================================================
132 // Function : firstIObject
133 // Purpose : Return the first selected object in the selected object list
134 //================================================================
135 Handle(SALOME_InteractiveObject) HOMARD_UTILS::firstIObject()
137 const SALOME_ListIO& aList = selectedIO();
138 return aList.Extent() > 0 ? aList.First() : Handle(SALOME_InteractiveObject)();
141 //================================================================
142 // Function : lastIObject
143 // Return the last selected object in the selected object list
144 //================================================================
145 Handle(SALOME_InteractiveObject) HOMARD_UTILS::lastIObject()
147 const SALOME_ListIO& aList = selectedIO();
148 return aList.Extent() > 0 ? aList.Last() : Handle(SALOME_InteractiveObject)();
151 //================================================================
152 // Retourne vrai si l'objet est du type voulu
153 // . Dans le cas d'un cas, d'une hypothese, d'une zone, on se contente
154 // d'une comparaison simple entre le type stocke et TypeObject.
155 // . Pour l'iteration, le type stocke en attribut est sous la forme
156 // "IterationHomard" + le nom de l'iteration precedente.
157 // Il faut donc regarder si la chaine commence par TypeObject.
158 // . Idem pour le fichier de messages : "Mess " + numero d'iteration
160 // On filtre ce genre de situation avec option :
161 // -1 : comparaison totale
162 // 0 : comparaison sur le debut de la chaine
163 //================================================================
164 bool HOMARD_UTILS::isObject(_PTR(SObject) MonObj, QString TypeObject, int option)
166 // MESSAGE("isObject, TypeObject = "<<TypeObject.toStdString().c_str()<<", option = "<<option);
167 // Existence d'un attribut ?
168 _PTR(GenericAttribute) anAttr;
169 if ( !MonObj->FindAttribute(anAttr, "AttributeComment") ) return false;
171 _PTR(AttributeComment) aComment (anAttr);
172 QString Type = QString(aComment->Value().c_str());
173 // MESSAGE("Type = "<<Type.toStdString().c_str());
178 int position = Type.lastIndexOf(TypeObject);
179 // MESSAGE("position = "<<position);
180 if ( position == 0 ) { bOK = true ; }
184 if ( Type == TypeObject ) { bOK = true ; }
188 //================================================================
189 // Retourne vrai si l'objet est une frontiere CAO
190 //================================================================
191 bool HOMARD_UTILS::isBoundaryCAO(_PTR(SObject) MonObj)
193 return isObject( MonObj, QString("BoundaryCAOHomard"), -1 ) ;
195 //================================================================
196 // Retourne vrai si l'objet est une frontiere analytique
197 //================================================================
198 bool HOMARD_UTILS::isBoundaryAn(_PTR(SObject) MonObj)
200 return isObject( MonObj, QString("BoundaryAnHomard"), -1 ) ;
202 //================================================================
203 // Retourne vrai si l'objet est une frontiere discrete
204 //================================================================
205 bool HOMARD_UTILS::isBoundaryDi(_PTR(SObject) MonObj)
207 return isObject( MonObj, QString("BoundaryDiHomard"), -1 ) ;
209 //================================================================
210 // Retourne vrai si l'objet est un cas
211 //================================================================
212 bool HOMARD_UTILS::isCase(_PTR(SObject) MonObj)
214 return isObject( MonObj, QString("CasHomard"), -1 ) ;
216 //================================================================
217 // Retourne vrai si l'objet est une Hypothese
218 //================================================================
219 bool HOMARD_UTILS::isHypo(_PTR(SObject) MonObj)
221 return isObject( MonObj, QString("HypoHomard"), -1 ) ;
223 //================================================================
224 // Retourne vrai si l'objet est une iteration
225 //================================================================
226 bool HOMARD_UTILS::isIter(_PTR(SObject) MonObj)
228 return isObject( MonObj, QString("IterationHomard"), 0 ) ;
230 //================================================================
231 // Retourne vrai si l'objet est un schema YACS
232 //================================================================
233 bool HOMARD_UTILS::isYACS(_PTR(SObject) MonObj)
235 return isObject( MonObj, QString("YACSHomard"), -1 ) ;
237 //================================================================
238 // Retourne vrai si l'objet est une zone
239 //================================================================
240 bool HOMARD_UTILS::isZone(_PTR(SObject) MonObj)
242 return isObject( MonObj, QString("ZoneHomard"), -1 ) ;
244 //================================================================
245 // Retourne vrai si l'objet est un fichier de type TypeFile
246 //================================================================
247 bool HOMARD_UTILS::isFileType(_PTR(SObject) MonObj, QString TypeFile)
249 return isObject( MonObj, TypeFile, 0 ) ;
252 //=========================================================================================================
253 void HOMARD_UTILS::PushOnHelp(QString monFichierAide, QString contexte, QString LanguageShort)
255 MESSAGE("Debut de PushOnHelp avec monFichierAide = "<< monFichierAide.toStdString().c_str());
256 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
259 HOMARDGUI* aHomardGUI = dynamic_cast<HOMARDGUI*>( app->module( "Homard" ) );
260 // Repertoire de reference de la documentation
261 QString rep = aHomardGUI ? app->moduleName(aHomardGUI->moduleName()) : QString("") ;
262 // WARNING/ATTENTION : si on savait recuperer la langue depuis les preferences, on ne ferait pas le passage par argument
263 // SUIT_ResourceMgr* resMgr = getApp()->resourceMgr();
264 // SUIT_ResourceMgr* resMgr = myModule->getApp()->resourceMgr();
265 // QString langue = resMgr->stringValue("language", "language", "en");
266 // QString langue = "fr" ;
267 MESSAGE(". LanguageShort " << LanguageShort.toStdString().c_str()) ;
268 // Complement du fichier
269 QString fichier = QString(LanguageShort+"/"+monFichierAide) ;
270 MESSAGE(". Appel de onHelpContextModule avec :");
271 MESSAGE(" rep = "<< rep.toStdString().c_str());
272 MESSAGE(" fichier = "<< fichier.toStdString().c_str());
273 MESSAGE(" contexte = "<< contexte.toStdString().c_str());
275 app->onHelpContextModule(rep, fichier, contexte);
278 //=========================================================================================================