1 // Copyright (C) 2011-2020 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, 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"
42 #include <qstringlist.h>
48 SALOME_ListIO HOMARD_UTILS::mySelected;
50 //================================================================
51 // Function : GetActiveStudy
52 // Returne un pointeur sur l'etude active
53 //================================================================
54 SUIT_Study* HOMARD_UTILS::GetActiveStudy()
56 SUIT_Application* app = SUIT_Session::session()->activeApplication();
58 return app->activeStudy();
63 //================================================================
64 // Function : getStudy
65 // Returne un pointeur sur l'etude active
66 //================================================================
67 _PTR(Study) HOMARD_UTILS::getStudy()
69 static _PTR(Study) _study;
71 _study = SalomeApp_Application::getStudy();
75 //================================================================
76 // Function : updateObjBrowser
77 // Purpose : met a jour l arbre d 'etude pour Homard
78 //================================================================
79 void HOMARD_UTILS::updateObjBrowser()
81 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
83 // Le nom identifiant doit etre la valeur du parametre
84 // name de la section HOMARD du fichier SalomeApp.xml
85 CAM_Module* module = app->module("Homard" );
86 SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>( module );
88 app->updateObjectBrowser();
89 appMod->updateObjBrowser( true );
92 MESSAGE( "--- ADAPT::updateObjBrowser: appMod = NULL");
96 //================================================================
97 // Function : selectedIO
98 // Return the list of selected SALOME_InteractiveObject's
99 //================================================================
100 const SALOME_ListIO& HOMARD_UTILS::selectedIO()
102 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* > ( SUIT_Session::session()->activeApplication() );
103 LightApp_SelectionMgr* aSelectionMgr = app->selectionMgr();
106 aSelectionMgr->selectedObjects( mySelected );
107 for (SALOME_ListIteratorOfListIO it (mySelected); it.More(); it.Next())
108 SCRUTE(it.Value()->getEntry());
113 //================================================================
114 // Function : IObjectCount
115 // Return the number of selected objects
116 //================================================================
117 int HOMARD_UTILS::IObjectCount()
119 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
120 LightApp_SelectionMgr* aSelectionMgr = app->selectionMgr();
123 aSelectionMgr->selectedObjects( mySelected );
124 SCRUTE(mySelected.Extent());
125 return mySelected.Extent();
130 //================================================================
131 // Function : firstIObject
132 // Purpose : Return the first selected object in the selected object list
133 //================================================================
134 Handle(SALOME_InteractiveObject) HOMARD_UTILS::firstIObject()
136 const SALOME_ListIO& aList = selectedIO();
137 return aList.Extent() > 0 ? aList.First() : Handle(SALOME_InteractiveObject)();
140 //================================================================
141 // Function : lastIObject
142 // Return the last selected object in the selected object list
143 //================================================================
144 Handle(SALOME_InteractiveObject) HOMARD_UTILS::lastIObject()
146 const SALOME_ListIO& aList = selectedIO();
147 return aList.Extent() > 0 ? aList.Last() : Handle(SALOME_InteractiveObject)();
150 //================================================================
151 // Retourne vrai si l'objet est du type voulu
152 // . Dans le cas d'un cas, d'une hypothese, d'une zone, on se contente
153 // d'une comparaison simple entre le type stocke et TypeObject.
154 // . Pour l'iteration, le type stocke en attribut est sous la forme
155 // "IterationHomard" + le nom de l'iteration precedente.
156 // Il faut donc regarder si la chaine commence par TypeObject.
157 // . Idem pour le fichier de messages : "Mess " + numero d'iteration
159 // On filtre ce genre de situation avec option :
160 // -1 : comparaison totale
161 // 0 : comparaison sur le debut de la chaine
162 //================================================================
163 bool HOMARD_UTILS::isObject(_PTR(SObject) MonObj, QString TypeObject, int option)
165 // MESSAGE("isObject, TypeObject = "<<TypeObject.toStdString().c_str()<<", option = "<<option);
166 // Existence d'un attribut ?
167 _PTR(GenericAttribute) anAttr;
168 if ( !MonObj->FindAttribute(anAttr, "AttributeComment") ) return false;
170 _PTR(AttributeComment) aComment (anAttr);
171 QString Type = QString(aComment->Value().c_str());
172 // MESSAGE("Type = "<<Type.toStdString().c_str());
177 int position = Type.lastIndexOf(TypeObject);
178 // MESSAGE("position = "<<position);
179 if ( position == 0 ) { bOK = true ; }
183 if ( Type == TypeObject ) { bOK = true ; }
187 //================================================================
188 // Retourne vrai si l'objet est une frontiere CAO
189 //================================================================
190 bool HOMARD_UTILS::isBoundaryCAO(_PTR(SObject) MonObj)
192 return isObject( MonObj, QString("BoundaryCAOHomard"), -1 ) ;
194 //================================================================
195 // Retourne vrai si l'objet est une frontiere analytique
196 //================================================================
197 bool HOMARD_UTILS::isBoundaryAn(_PTR(SObject) MonObj)
199 return isObject( MonObj, QString("BoundaryAnHomard"), -1 ) ;
201 //================================================================
202 // Retourne vrai si l'objet est une frontiere discrete
203 //================================================================
204 bool HOMARD_UTILS::isBoundaryDi(_PTR(SObject) MonObj)
206 return isObject( MonObj, QString("BoundaryDiHomard"), -1 ) ;
208 //================================================================
209 // Retourne vrai si l'objet est un cas
210 //================================================================
211 bool HOMARD_UTILS::isCase(_PTR(SObject) MonObj)
213 return isObject( MonObj, QString("CasHomard"), -1 ) ;
215 //================================================================
216 // Retourne vrai si l'objet est une Hypothese
217 //================================================================
218 bool HOMARD_UTILS::isHypo(_PTR(SObject) MonObj)
220 return isObject( MonObj, QString("HypoHomard"), -1 ) ;
222 //================================================================
223 // Retourne vrai si l'objet est une iteration
224 //================================================================
225 bool HOMARD_UTILS::isIter(_PTR(SObject) MonObj)
227 return isObject( MonObj, QString("IterationHomard"), 0 ) ;
229 //================================================================
230 // Retourne vrai si l'objet est un schema YACS
231 //================================================================
232 bool HOMARD_UTILS::isYACS(_PTR(SObject) MonObj)
234 return isObject( MonObj, QString("YACSHomard"), -1 ) ;
236 //================================================================
237 // Retourne vrai si l'objet est une zone
238 //================================================================
239 bool HOMARD_UTILS::isZone(_PTR(SObject) MonObj)
241 return isObject( MonObj, QString("ZoneHomard"), -1 ) ;
243 //================================================================
244 // Retourne vrai si l'objet est un fichier de type TypeFile
245 //================================================================
246 bool HOMARD_UTILS::isFileType(_PTR(SObject) MonObj, QString TypeFile)
248 return isObject( MonObj, TypeFile, 0 ) ;
251 //=========================================================================================================
252 void HOMARD_UTILS::PushOnHelp(QString monFichierAide, QString contexte, QString LanguageShort)
254 MESSAGE("Debut de PushOnHelp avec monFichierAide = "<< monFichierAide.toStdString().c_str());
255 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
258 // ADAPTGUI* aHomardGUI = dynamic_cast<ADAPTGUI*>( app->module( "Homard" ) );
259 // // Repertoire de reference de la documentation
260 // QString rep = aHomardGUI ? app->moduleName(aHomardGUI->moduleName()) : QString("") ;
261 // // WARNING/ATTENTION : si on savait recuperer la langue depuis les preferences, on ne ferait pas le passage par argument
262 // // SUIT_ResourceMgr* resMgr = getApp()->resourceMgr();
263 // // SUIT_ResourceMgr* resMgr = myModule->getApp()->resourceMgr();
264 // // QString langue = resMgr->stringValue("language", "language", "en");
265 // // QString langue = "fr" ;
266 // MESSAGE(". LanguageShort " << LanguageShort.toStdString().c_str()) ;
267 // // Complement du fichier
268 // QString fichier = QString(LanguageShort+"/"+monFichierAide) ;
269 // MESSAGE(". Appel de onHelpContextModule avec :");
270 // MESSAGE(" rep = "<< rep.toStdString().c_str());
271 // MESSAGE(" fichier = "<< fichier.toStdString().c_str());
272 // MESSAGE(" contexte = "<< contexte.toStdString().c_str());
274 // app->onHelpContextModule(rep, fichier, contexte);
277 //=========================================================================================================