Salome HOME
Merge Python 3 porting.
[modules/homard.git] / src / HOMARDGUI / HOMARDGUI.cxx
1 // Copyright (C) 2011-2016  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  File   : HOMARDGUI.cxx
21 //  Author : Gerald NICOLAS, EDF
22 //  Module : HOMARD
23
24 #include "HOMARDGUI.h"
25
26 // SALOME Includes
27 #include "Utils_ORB_INIT.hxx"
28 #include "Utils_SINGLETON.hxx"
29 #include "SALOME_LifeCycleCORBA.hxx"
30
31 #include "SUIT_ResourceMgr.h"
32 #include "SUIT_MessageBox.h"
33 #include "SUIT_Session.h"
34 #include "SUIT_ViewWindow.h"
35 #include "SUIT_ViewManager.h"
36 #include <SUIT_Desktop.h>
37
38 #include "CAM_Module.h"
39 #include "OB_Browser.h"
40
41 #include "SALOME_ListIO.hxx"
42
43 #include "SalomeApp_Application.h"
44 #include "SalomeApp_DataModel.h"
45 #include "SalomeApp_Study.h"
46 #include "LightApp_SelectionMgr.h"
47 #include "LightApp_Selection.h"
48 #include <LightApp_Preferences.h>
49 #include "SalomeApp_Module.h"
50 #include "SALOMEconfig.h"
51 #include <SALOME_LifeCycleCORBA.hxx>
52
53 #include <utilities.h>
54
55
56 // QT Includes
57 #include <QMenu>
58 #include "MonCreateCase.h"
59 #include "MonCreateIteration.h"
60 #include "MonPursueIteration.h"
61 #include "MonCreateYACS.h"
62 #include "MonEditBoundaryAn.h"
63 #include "MonEditBoundaryDi.h"
64 #include "MonEditCase.h"
65 #include "MonEditHypothesis.h"
66 #include "MonEditIteration.h"
67 #include "MonEditYACS.h"
68 #include "MonEditZone.h"
69 #include "MonMeshInfo.h"
70 #include "MonIterInfo.h"
71 #include "MonEditFile.h"
72 #include "HomardQtCommun.h"
73
74 // BOOST Includes
75 #include <boost/shared_ptr.hpp>
76
77 //Pour le _CAST
78 #include "SALOMEDS_Study.hxx"
79 #include "HOMARDGUI_Utils.h"
80
81 using namespace std;
82
83 static CORBA::ORB_var _orb;
84
85 //=======================================================================
86 // function : HOMARDGUI()
87 // purpose  : Constructor
88 //=======================================================================
89 HOMARDGUI::HOMARDGUI(const QString&) :
90            SalomeApp_Module( "HOMARD" ) // default name
91 {
92 }
93 //=======================================================================
94 // function : ~HOMARDGUI()
95 // purpose  : Destructor
96 //=======================================================================
97 HOMARDGUI::~HOMARDGUI()
98 {
99 }
100
101 //=======================================================================
102 // function : InitHOMARDGen
103 // launch HOMARD component and return a handle
104 //=======================================================================
105 HOMARD::HOMARD_Gen_var HOMARDGUI::InitHOMARDGen(SalomeApp_Application* app)
106 {
107   Engines::EngineComponent_var comp = app->lcc()->FindOrLoad_Component( "FactoryServer","HOMARD" );
108   HOMARD::HOMARD_Gen_var clr = HOMARD::HOMARD_Gen::_narrow(comp);
109   ASSERT(!CORBA::is_nil(clr));
110   return clr;
111 }
112
113 //=======================================================================
114 // Module's initialization
115 void HOMARDGUI::initialize( CAM_Application* app )
116 //=======================================================================
117 {
118   SalomeApp_Module::initialize( app );
119   InitHOMARDGen(dynamic_cast<SalomeApp_Application*>( app ));
120   anId = 0;
121   createActions();
122   createMenus();
123   recupPreferences();
124 }
125
126 //================================================
127 // function : createHOMARDAction
128 // create an item in status bar and Homard menu
129 //================================================
130 void HOMARDGUI::createHOMARDAction( const int id, const QString& po_id, const QString& icon_id, const int key, const bool toggle  )
131 {
132 //   MESSAGE("createHOMARDAction");
133   QIcon icon;
134   QWidget* parent = application()->desktop();
135   SUIT_ResourceMgr* resMgr = application()->resourceMgr();
136   QPixmap pix;
137   if ( icon_id.length() )
138      pix = resMgr->loadPixmap( "HOMARD", tr( icon_id .toLatin1().data()) );
139   else
140      pix = resMgr->loadPixmap( "HOMARD", tr( QString( "ICO_%1" ).arg( po_id ).toLatin1().data()), false );
141   if ( !pix.isNull() )
142       icon = QIcon( pix );
143
144   QString tooltip    = tr(QString( "HOM_TOP_%1" ).arg( po_id ).toLatin1().data()),
145           menu       = tr(QString( "HOM_MEN_%1" ).arg( po_id ).toLatin1().data()),
146           status_bar = tr(QString( "HOM_STB_%1" ).arg( po_id ).toLatin1().data());
147
148   createAction( id, tooltip, icon, menu, status_bar, key, parent, toggle, this, SLOT( OnGUIEvent() )  );
149 }
150
151 //================================================
152 // function : createAction
153 // constructs Homard menu
154 // calls createHOMARDAction for each item
155 //================================================
156 void HOMARDGUI::createActions(){
157 //
158   createHOMARDAction( 1101, "NEW_CASE",         "cas_calcule.png"        );
159   createHOMARDAction( 1102, "PURSUE_ITERATION", "iter_poursuite.png"     );
160   createHOMARDAction( 1103, "NEW_ITERATION",    "iter_next.png"          );
161   createHOMARDAction( 1111, "COMPUTE",          "mesh_compute.png"       );
162   createHOMARDAction( 1112, "COMPUTE_PUBLISH",  "mesh_compute.png"       );
163   createHOMARDAction( 1121, "MESH_INFO",        "advanced_mesh_info.png" );
164   createHOMARDAction( 1131, "MESH_PUBLICATION", "mesh_tree_mesh.png"     );
165 //
166   createHOMARDAction( 1201, "EDIT",             "loop.png"         );
167   createHOMARDAction( 1211, "DELETE",           "delete.png"       );
168 //
169   createHOMARDAction( 1301, "MESH_INFO",        "advanced_mesh_info.png" );
170   createHOMARDAction( 1302, "EDIT_MESS_FILE",   "texte.png"              );
171 //
172   createHOMARDAction( 1401, "YACS",             "table_view.png" );
173 //
174 }
175
176 //================================================
177 // function : createPreferences
178 //================================================
179 void HOMARDGUI::createPreferences()
180 {
181   MESSAGE("createPreferences")
182
183   int Onglet, Bloc, Pref ;
184   // 1. Generalites
185   Onglet = addPreference( tr( "PREF_TAB_GENERAL" ) );
186 //   Onglet = addPreference( tr( "PREF_TAB_SETTINGS" ) ) ;
187
188   Bloc = addPreference( tr( "PREF_PUBLICATION" ), Onglet );
189   setPreferenceProperty( Bloc, "columns", 1 );
190
191   Pref = addPreference( tr( "PREF_PUBLICATION_MAILLAGE_IN" ), Bloc, LightApp_Preferences::Bool, "HOMARD", "publish_mesh_in" );
192
193   Pref = addPreference( tr( "PREF_PUBLICATION_MAILLAGE_OUT" ), Bloc, LightApp_Preferences::Bool, "HOMARD", "publish_mesh_out" );
194
195   // 2. YACS
196   Onglet = addPreference( tr( "PREF_YACS" ) ) ;
197
198   Bloc = addPreference( tr( "PREF_YACS_MAX" ), Onglet );
199   setPreferenceProperty( Bloc, "columns", 1 );
200
201   Pref = addPreference( tr( "PREF_YACS_MAX_ITER" ), Bloc, LightApp_Preferences::IntSpin, "HOMARD", "yacs_max_iter" );
202   setPreferenceProperty( Pref, "min",  0 );
203   setPreferenceProperty( Pref, "max",  100000000 );
204   setPreferenceProperty( Pref, "step", 1 );
205
206   Pref = addPreference( tr( "PREF_YACS_MAX_NODE" ), Bloc, LightApp_Preferences::IntSpin, "HOMARD", "yacs_max_node" );
207   setPreferenceProperty( Pref, "min",  0 );
208   setPreferenceProperty( Pref, "max",  100000000 );
209   setPreferenceProperty( Pref, "step", 1000 );
210
211   Pref = addPreference( tr( "PREF_YACS_MAX_ELEM" ), Bloc, LightApp_Preferences::IntSpin, "HOMARD", "yacs_max_elem" );
212   setPreferenceProperty( Pref, "min",  0 );
213   setPreferenceProperty( Pref, "max",  100000000 );
214   setPreferenceProperty( Pref, "step", 1000 );
215
216   Bloc = addPreference( tr( "PREF_YACS_CONVERGENCE" ), Onglet );
217   setPreferenceProperty( Bloc, "columns", 1 );
218
219   Pref = addPreference( tr( "PREF_YACS_TYPE_TEST" ), Bloc, LightApp_Preferences::Selector, "HOMARD", "yacs_type_test" );
220   QStringList aListOfTypeTest;
221   aListOfTypeTest << "None";
222   aListOfTypeTest << "VTest > VRef";
223   aListOfTypeTest << "VTest < VRef";
224   setPreferenceProperty( Pref, "strings", aListOfTypeTest );
225 }
226
227
228 //================================================
229 // function : createMenus
230 //================================================
231 void HOMARDGUI::createMenus()
232 {
233   MESSAGE("createMenus")
234 //
235   int HOMARD_Id  = createMenu( tr( "HOM_MEN_HOMARD" ),  -1,  5, 10 );
236   createMenu( 1101, HOMARD_Id, -1 ); //Create_Case
237   createMenu( 1102, HOMARD_Id, -1 ); //Pursue_Iteration
238   createMenu( separator(), HOMARD_Id,-1);
239   createMenu( 1103, HOMARD_Id, -1 ); //Create_Iteration
240   createMenu( 1111, HOMARD_Id, -1 ); //Compute
241   createMenu( 1112, HOMARD_Id, -1 ); //Compute and publish
242 //
243   HOMARD_Id  = createMenu( tr( "HOM_MEN_MODIFICATION" ),  -1,  5, 10 );
244   createMenu( 1201, HOMARD_Id, -1 ); //Edit
245   createMenu( 1211, HOMARD_Id, -1 ); //Delete
246 //
247   HOMARD_Id  = createMenu( tr( "HOM_MEN_INFORMATION" ),  -1,  5, 10 );
248   createMenu( 1301, HOMARD_Id, -1 ); //Information sur un maillage
249   createMenu( 1131, HOMARD_Id, -1 ); //Mesh publication
250   createMenu( separator(), HOMARD_Id,-1);
251   createMenu( 1302, HOMARD_Id, -1 ); //EditAsciiFile pour le fichier listeStd ou bilan
252   createMenu( separator(), HOMARD_Id,-1);
253   createMenu( 1201, HOMARD_Id, -1 ); //Edit
254   createMenu( separator(), HOMARD_Id,-1);
255 //
256   HOMARD_Id  = createMenu( tr( "HOM_MEN_YACS" ),  -1,  5, 10 );
257   createMenu( 1401, HOMARD_Id, -1 ); // Création d'un schéma YACS
258   createMenu( separator(), HOMARD_Id,-1);
259 }
260
261 //================================================
262 // function : recupPreferences
263 // Pour chaque valeur, le defaut est la valeur definie dans HOMARD_Gen
264 // . Si la recuperation dans config/salome s'est bien passee a la creation de HOMARD_Gen,
265 //   ces valeurs sont les valeurs definies.
266 // . Si cela ne s'est pas bien passe, ce sont les valeurs par defaut de HOMARD_Gen
267 //================================================
268 void HOMARDGUI::recupPreferences()
269 {
270   MESSAGE("recupPreferences")
271 //
272 // A. Declarations
273 //
274   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( application() );
275   HOMARD::HOMARD_Gen_var homardGen = HOMARDGUI::InitHOMARDGen(app);
276   int defaut_i ;
277   std::string defaut_s ;
278   QString QString_v ;
279 //
280 // B. Les valeurs
281 // B.1. La langue
282 //
283   defaut_s = homardGen->GetLanguageShort();
284   SUIT_ResourceMgr* resMgr = getApp()->resourceMgr();
285   _LanguageShort = resMgr->stringValue("language", "language", QString(defaut_s.c_str()) );
286 //
287 // B.2. Les publications
288   bool publish_mesh ;
289 //
290   _PublisMeshIN = homardGen->GetPublisMeshIN();
291   if ( _PublisMeshIN == 1 ) { publish_mesh = true ;  }
292   else                      { publish_mesh = false ; }
293   publish_mesh = resMgr->booleanValue("HOMARD", "publish_mesh_in", publish_mesh );
294   if ( publish_mesh ) { _PublisMeshIN = 1 ; }
295   else                { _PublisMeshIN = 0 ; }
296 //
297   _PublisMeshOUT = homardGen->GetPublisMeshOUT();
298   if ( _PublisMeshOUT == 1 ) { publish_mesh = true ;  }
299   else                       { publish_mesh = false ; }
300   publish_mesh = resMgr->booleanValue("HOMARD", "publish_mesh_out", publish_mesh );
301   if ( publish_mesh ) { _PublisMeshOUT = 1 ; }
302   else                { _PublisMeshOUT = 0 ; }
303 //
304 // B.3. Les maximum pour YACS
305 //
306   defaut_i = homardGen->GetYACSMaxIter();
307   _YACSMaxIter = resMgr->integerValue("HOMARD", "yacs_max_iter", defaut_i );
308 //
309   defaut_i = homardGen->GetYACSMaxNode();
310   _YACSMaxNode = resMgr->integerValue("HOMARD", "yacs_max_node", defaut_i );
311 //
312   defaut_i = homardGen->GetYACSMaxElem();
313   _YACSMaxElem = resMgr->integerValue("HOMARD", "yacs_max_elem", defaut_i );
314 //
315 // B.4. La convergence pour YACS
316 //
317   defaut_i = homardGen->GetYACSConvergenceType();
318   if ( defaut_i == 1 )      { QString_v = tr("VTest > VRef") ; }
319   else if ( defaut_i == 2 ) { QString_v = tr("VTest < VRef") ; }
320   else                      { QString_v = tr("None") ; }
321   QString_v = resMgr->stringValue ( "HOMARD", "yacs_type_test", QString_v );
322   if ( ( QString_v == "VTest > VRef" ) || ( QString_v == "VTest &gt; VRef" ) )      { _YACSTypeTest = 1 ; }
323   else if ( ( QString_v == "VTest < VRef" ) || ( QString_v == "VTest &lt; VRef" ) ) { _YACSTypeTest = 2 ; }
324   else                                                                              { _YACSTypeTest = 0 ; }
325 //
326 // C. Enregistrement dans l'objet general
327 //
328   MESSAGE ("Enregistrement de LanguageShort = " << _LanguageShort.toStdString().c_str() );
329   MESSAGE ("Enregistrement de PublisMeshIN = " << _PublisMeshIN<<", PublisMeshOUT = "<< _PublisMeshOUT);
330   MESSAGE ("Enregistrement de YACSMaxIter = " << _YACSMaxIter<<", YACSMaxNode = "<< _YACSMaxNode<<", YACSMaxElem = "<< _YACSMaxElem);
331   MESSAGE ("Enregistrement de YACSTypeTest = " << _YACSTypeTest);
332 //
333   homardGen->SetLanguageShort(_LanguageShort.toStdString().c_str());
334   homardGen->SetPublisMesh(_PublisMeshIN, _PublisMeshOUT);
335   homardGen->SetYACSMaximum(_YACSMaxIter, _YACSMaxNode, _YACSMaxElem);
336 //
337   homardGen->SetYACSConvergenceType(_YACSTypeTest);
338 }
339
340 //================================================
341 void HOMARDGUI::OnGUIEvent()
342 //================================================
343 {
344   MESSAGE("OnGUIEvent()")
345   setOrb();
346   const QObject* obj = sender();
347   if ( !obj || !obj->inherits( "QAction" ) ) { return; }
348   int id = actionId((QAction*)obj);
349   if ( id != -1 ) { bool ret = OnGUIEvent( id ); }
350   MESSAGE("Fin de OnGUIEvent()");
351 }
352
353 //=======================================================================
354 // Method OnGUIEvent pour Homard
355 //=======================================================================
356 bool HOMARDGUI::OnGUIEvent (int theCommandID)
357 {
358   MESSAGE("OnGUIEvent avec theCommandID = "<<theCommandID);
359 // A. Controles
360   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( application() );
361   if ( !app ) return false;
362
363   SalomeApp_Study* stud = dynamic_cast<SalomeApp_Study*> ( app->activeStudy() );
364   if ( !stud )
365   {
366     MESSAGE ( "FAILED to cast active study to SalomeApp_Study" );
367     return false;
368   }
369
370   SUIT_Desktop* parent = application()->desktop();
371
372   HOMARD::HOMARD_Gen_var homardGen = HOMARDGUI::InitHOMARDGen(app);
373
374   if (!CORBA::is_nil(homardGen))
375     homardGen->UpdateStudy();
376
377   getApp()->updateObjectBrowser();
378
379 // B. Choix selon les commandes
380   SCRUTE(theCommandID);
381   switch (theCommandID)
382   {
383     case 1101: // Creation d un Cas
384     {
385       MESSAGE("command " << theCommandID << " activated");
386       MonCreateCase *aDlg = new MonCreateCase( true,
387                             HOMARD::HOMARD_Gen::_duplicate(homardGen) ) ;
388       aDlg->show();
389       break;
390     }
391
392     case 1102: // Poursuite d une iteration
393     {
394       MESSAGE("command " << theCommandID << " activated");
395       MonPursueIteration *aDlg = new MonPursueIteration( true,
396                                 HOMARD::HOMARD_Gen::_duplicate(homardGen) ) ;
397       aDlg->show();
398       break;
399     }
400
401     case 1103: // Creation d une Iteration
402     {
403       MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
404       MonCreateIteration *IterDlg = new MonCreateIteration( parent, true,
405                                      HOMARD::HOMARD_Gen::_duplicate(homardGen), _ObjectName ) ;
406       IterDlg->show();
407       break;
408     }
409
410     case 1111: // Compute une iteration
411     {
412       MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
413       try { homardGen->Compute(_ObjectName.toStdString().c_str(), 0, 1, -1, 1); }
414       catch( SALOME::SALOME_Exception& S_ex )
415       {
416         QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
417                                   QObject::tr(CORBA::string_dup(S_ex.details.text)) );
418         getApp()->updateObjectBrowser();
419         return false;
420       }
421       break;
422     }
423
424     case 1112: // Compute une iteration et publication
425     {
426       MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
427       try { homardGen->Compute(_ObjectName.toStdString().c_str(), 0, 1, -1, 2); }
428       catch( SALOME::SALOME_Exception& S_ex )
429       {
430         QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
431                                   QObject::tr(CORBA::string_dup(S_ex.details.text)) );
432         getApp()->updateObjectBrowser();
433         return false;
434       }
435       break;
436     }
437
438     case 1121: // Information sur le maillage de l'iteration
439     {
440       MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
441       MonIterInfo *IterDlg = new MonIterInfo( parent, true, HOMARD::HOMARD_Gen::_duplicate(homardGen), _ObjectName ) ;
442       IterDlg->show();
443       break;
444     }
445
446     case 1131: // Publication du maillage de l'iteration
447     {
448       MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
449       homardGen->PublishMeshIterInSmesh(_ObjectName.toStdString().c_str());
450       break;
451     }
452
453     case 1132: // Publication du maillage de l'iteration a partir du fichier
454     {
455       MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
456       homardGen->PublishResultInSmesh(_ObjectName.toStdString().c_str(), 1);
457       break;
458     }
459
460     case 1201: // Edition d'un objet
461     {
462       MESSAGE("command " << theCommandID << " activated");
463       QString nomObjet = HOMARD_QT_COMMUN::SelectionArbreEtude(QString(""), 1);
464       if (nomObjet == QString("")) break;
465       _PTR(SObject) obj = chercheMonObjet();
466       if (obj)
467       {
468         // Edition d'une frontiere discrete
469         if (HOMARD_UTILS::isBoundaryDi(obj))
470         {
471           MonEditBoundaryDi *aDlg = new MonEditBoundaryDi(0, true, HOMARD::HOMARD_Gen::_duplicate(homardGen), QString(""), _ObjectName ) ;
472           aDlg->show();
473         }
474         // Edition d'une frontiere analytique
475         else if (HOMARD_UTILS::isBoundaryAn(obj))
476         {
477           MonEditBoundaryAn *aDlg = new MonEditBoundaryAn(0, true, HOMARD::HOMARD_Gen::_duplicate(homardGen), QString(""), _ObjectName ) ;
478           aDlg->show();
479         }
480         // Edition d'un cas
481         else if (HOMARD_UTILS::isCase(obj))
482         {
483           MonEditCase *aDlg = new MonEditCase(true, HOMARD::HOMARD_Gen::_duplicate(homardGen), _ObjectName ) ;
484           aDlg->show();
485         }
486         // Edition d'une hypothese
487         else if (HOMARD_UTILS::isHypo(obj))
488         {
489           MonEditHypothesis *aDlg = new MonEditHypothesis(0, true, HOMARD::HOMARD_Gen::_duplicate(homardGen),  _ObjectName, QString(""), QString("")) ;
490           aDlg->show();
491         }
492         // Edition d'une iteration
493         else if (HOMARD_UTILS::isIter(obj))
494         {
495           MonEditIteration *aDlg = new MonEditIteration(parent, true, HOMARD::HOMARD_Gen::_duplicate(homardGen), QString(""), _ObjectName ) ;
496           aDlg->show();
497         }
498         // Edition d'un schema YACS
499         else if (HOMARD_UTILS::isYACS(obj))
500         {
501           MESSAGE("appel de MonEditYACS");
502           MonEditYACS *aDlg = new MonEditYACS(true, HOMARD::HOMARD_Gen::_duplicate(homardGen), _ObjectName) ;
503           aDlg->show();
504         }
505         // Edition d'une zone
506         else if (HOMARD_UTILS::isZone(obj))
507         {
508           MonEditZone *aDlg = new MonEditZone(0, true, HOMARD::HOMARD_Gen::_duplicate(homardGen), QString(""), _ObjectName ) ;
509           aDlg->show();
510         }
511       }
512       break;
513     }
514
515     case 1211: // Suppression d'un objet
516     {
517       MESSAGE("command " << theCommandID << " activated");
518       QString nomObjet = HOMARD_QT_COMMUN::SelectionArbreEtude(QString(""), 1);
519       if (nomObjet == QString("")) break;
520       _PTR(SObject) obj = chercheMonObjet();
521       if (obj)
522       {
523         // Suppression d'une frontiere
524         if ( HOMARD_UTILS::isBoundaryDi(obj) || HOMARD_UTILS::isBoundaryAn(obj) )
525         {
526           try
527           { homardGen->DeleteBoundary(_ObjectName.toStdString().c_str()); }
528           catch( SALOME::SALOME_Exception& S_ex )
529           {
530             QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
531                                       QObject::tr(CORBA::string_dup(S_ex.details.text)) );
532             getApp()->updateObjectBrowser();
533             return false;
534           }
535         }
536         // Suppression d'un cas
537         else if (HOMARD_UTILS::isCase(obj))
538         {
539           try
540           { homardGen->DeleteCase(_ObjectName.toStdString().c_str(), 1); }
541           catch( SALOME::SALOME_Exception& S_ex )
542           {
543             QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
544                                       QObject::tr(CORBA::string_dup(S_ex.details.text)) );
545             getApp()->updateObjectBrowser();
546             return false;
547           }
548         }
549         // Suppression d'une hypothese
550         else if (HOMARD_UTILS::isHypo(obj))
551         {
552           try
553           { homardGen->DeleteHypo(_ObjectName.toStdString().c_str()); }
554           catch( SALOME::SALOME_Exception& S_ex )
555           {
556             QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
557                                       QObject::tr(CORBA::string_dup(S_ex.details.text)) );
558             getApp()->updateObjectBrowser();
559             return false;
560           }
561         }
562         // Suppression d'une iteration
563         else if (HOMARD_UTILS::isIter(obj))
564         {
565           try
566           { homardGen->DeleteIteration(_ObjectName.toStdString().c_str(), 1); }
567           catch( SALOME::SALOME_Exception& S_ex )
568           {
569             QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
570                                       QObject::tr(CORBA::string_dup(S_ex.details.text)) );
571             getApp()->updateObjectBrowser();
572             return false;
573           }
574         }
575         // Suppression d'un schema YACS
576         else if (HOMARD_UTILS::isYACS(obj))
577         {
578           try
579           { homardGen->DeleteYACS(_ObjectName.toStdString().c_str(), 1); }
580           catch( SALOME::SALOME_Exception& S_ex )
581           {
582             QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
583                                       QObject::tr(CORBA::string_dup(S_ex.details.text)) );
584             getApp()->updateObjectBrowser();
585             return false;
586           }
587         }
588         // Suppression d'une zone
589         else if (HOMARD_UTILS::isZone(obj))
590         {
591           try
592           { homardGen->DeleteZone(_ObjectName.toStdString().c_str()); }
593           catch( SALOME::SALOME_Exception& S_ex )
594           {
595             QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
596                                       QObject::tr(CORBA::string_dup(S_ex.details.text)) );
597             getApp()->updateObjectBrowser();
598             return false;
599           }
600         }
601       }
602       break;
603     }
604
605     case 1301: // Information sur un maillage
606     {
607       MESSAGE("etape 1301")
608       MESSAGE("command " << theCommandID << " activated");
609       MonMeshInfo *aDlg = new MonMeshInfo( parent, true, HOMARD::HOMARD_Gen::_duplicate(homardGen) ) ;
610       aDlg->show();
611       break;
612     }
613
614     case 1302: // Affichage de fichier texte
615     {
616       MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
617       _PTR(SObject) obj = chercheMonObjet();
618       if ( (obj) && ( HOMARD_UTILS::isFileType(obj,QString("log")) || HOMARD_UTILS::isFileType(obj,QString("Summary")) || HOMARD_UTILS::isFileType(obj,QString("xml")) ) )
619       {
620           MonEditFile *aDlg = new MonEditFile( 0, true, HOMARD::HOMARD_Gen::_duplicate(homardGen), _ObjectName, 0 ) ;
621           if ( aDlg->_codret == 0 ) { aDlg->show(); }
622       }
623       break;
624     }
625
626     case 1401: // Création d'un schema YACS
627     {
628       MESSAGE("etape 1401")
629       MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
630       MonCreateYACS *aDlg = new MonCreateYACS( true, HOMARD::HOMARD_Gen::_duplicate(homardGen), _ObjectName ) ;
631       aDlg->show();
632       break;
633     }
634
635     case 1402: // Ecriture d'un schéma YACS
636     {
637       MESSAGE("etape 1402")
638       MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
639       try { homardGen->YACSWrite(_ObjectName.toStdString().c_str()); }
640       catch( SALOME::SALOME_Exception& S_ex )
641       {
642         QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
643                                   QObject::tr(CORBA::string_dup(S_ex.details.text)) );
644         getApp()->updateObjectBrowser();
645         return false;
646       }
647       break;
648     }
649
650   }
651   getApp()->updateObjectBrowser();
652   return true;
653 }
654
655 //=============================================================================
656 /*!
657  *
658  */
659 //=============================================================================
660
661 // Module's engine IOR
662 //=============================================================================
663 QString HOMARDGUI::engineIOR() const
664 //=============================================================================
665 {
666   CORBA::String_var anIOR = getApp()->orb()->object_to_string( InitHOMARDGen(getApp()) );
667   return QString( anIOR.in() );
668 }
669
670 // Module's activation
671 //=============================================================================
672 bool HOMARDGUI::activateModule( SUIT_Study* theStudy )
673 //=============================================================================
674 {
675   bool bOk = SalomeApp_Module::activateModule( theStudy );
676
677   setMenuShown( true );
678   setToolShown( true );
679
680   return bOk;
681 }
682
683 // Module's deactivation
684 //=============================================================================
685 bool HOMARDGUI::deactivateModule( SUIT_Study* theStudy )
686 //=============================================================================
687 {
688   setMenuShown( false );
689   setToolShown( false );
690
691   return SalomeApp_Module::deactivateModule( theStudy );
692 }
693
694 // Default windows
695 //=============================================================================
696 void HOMARDGUI::windows( QMap<int, int>& theMap ) const
697 //=============================================================================
698 {
699   theMap.clear();
700   theMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
701 #ifndef DISABLE_PYCONSOLE
702   theMap.insert( SalomeApp_Application::WT_PyConsole,     Qt::BottomDockWidgetArea );
703 #endif
704 }
705
706 //=============================================================================
707 void HOMARDGUI::setOrb()
708 //=============================================================================
709 {
710   try
711   {
712      ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
713      ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
714      _orb = init( 0 , 0 );
715   }
716   catch (...)
717   {
718      INFOS("internal error : orb not found");
719      _orb = 0;
720   }
721             ASSERT(! CORBA::is_nil(_orb));
722 }
723 //========================================
724 _PTR(SObject) HOMARDGUI::chercheMonObjet()
725 //========================================
726 {
727   SALOMEDSClient_SObject* aSO = NULL;
728   _PTR(SObject) obj;
729   SALOME_ListIO lst;
730   getApp()->selectionMgr()->selectedObjects( lst );
731   if (  lst.Extent() == 1 )
732   {
733     Handle(SALOME_InteractiveObject) io = lst.First();
734     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
735     _PTR(Study) study = appStudy->studyDS();
736     _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
737     _ObjectName = QString( obj->GetName().c_str() );
738     return obj;
739   }
740   else { return _PTR(SObject)(aSO); }
741 }
742 //=============================================================================
743 void HOMARDGUI::contextMenuPopup( const QString& client, QMenu* menu, QString& title )
744 //=============================================================================
745 {
746   MESSAGE("Debut de contextMenuPopup");
747   _PTR(SObject) obj = chercheMonObjet();
748   if ( obj )
749   {
750     title = QString( obj->GetName().c_str() );
751     _ObjectName = title;
752     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
753 //
754     QPixmap pix ;
755     bool DeleteObject = false ;
756     bool EditObject = false ;
757 //
758     if ( HOMARD_UTILS::isBoundaryAn(obj) )
759     {
760       EditObject = true ;
761       DeleteObject = true ;
762     }
763     else if ( HOMARD_UTILS::isBoundaryDi(obj) )
764     {
765       EditObject = true ;
766       DeleteObject = true ;
767     }
768     else if ( HOMARD_UTILS::isCase(obj) )
769     {
770       pix = resMgr->loadPixmap( "HOMARD", "table_view.png" );
771       menu->addAction(QIcon(pix), tr(QString("HOM_MEN_YACS").toLatin1().data()), this, SLOT(YACSCreate()));
772       EditObject = true ;
773       DeleteObject = true ;
774     }
775     else if ( HOMARD_UTILS::isHypo(obj) )
776     {
777       EditObject = true ;
778       DeleteObject = true ;
779     }
780     else if ( HOMARD_UTILS::isIter(obj) )
781     {
782       pix = resMgr->loadPixmap( "HOMARD", "iter_next.png" );
783       menu->addAction(QIcon(pix), tr(QString("HOM_MEN_NEW_ITERATION").toLatin1().data()), this, SLOT(NextIter()));
784       pix = resMgr->loadPixmap( "HOMARD", "mesh_compute.png" );
785       menu->addAction(QIcon(pix), tr(QString("HOM_MEN_COMPUTE").toLatin1().data()), this, SLOT(LanceCalcul0()));
786       pix = resMgr->loadPixmap( "HOMARD", "mesh_compute.png" );
787       menu->addAction(QIcon(pix), tr(QString("HOM_MEN_COMPUTE_PUBLISH").toLatin1().data()), this, SLOT(LanceCalcul1()));
788       pix = resMgr->loadPixmap( "HOMARD", "advanced_mesh_info.png" );
789       menu->addAction(QIcon(pix), tr(QString("HOM_MEN_MESH_INFO").toLatin1().data()), this, SLOT(IterInfo()));
790       pix = resMgr->loadPixmap( "HOMARD", "mesh_tree_mesh.png" );
791       menu->addAction(QIcon(pix), tr(QString("HOM_MEN_MESH_PUBLICATION").toLatin1().data()), this, SLOT(MeshPublish0()));
792       EditObject = true ;
793       DeleteObject = true ;
794     }
795     else if ( HOMARD_UTILS::isYACS(obj) )
796     {
797       pix = resMgr->loadPixmap( "HOMARD", "write.png" );
798       menu->addAction(QIcon(pix), tr(QString("HOM_MEN_WRITE").toLatin1().data()), this, SLOT(YACSWrite()));
799       EditObject = true ;
800       DeleteObject = true ;
801     }
802     else if ( HOMARD_UTILS::isZone(obj) )
803     {
804       EditObject = true ;
805       DeleteObject = true ;
806     }
807     else if ( HOMARD_UTILS::isFileType(obj,QString("log")) || HOMARD_UTILS::isFileType(obj,QString("Summary")) || HOMARD_UTILS::isFileType(obj,QString("xml")) )
808     {
809       pix = resMgr->loadPixmap( "HOMARD", "texte.png" );
810       menu->addAction(QIcon(pix), tr(QString("HOM_MEN_EDIT_MESS_FILE").toLatin1().data()), this, SLOT(EditAsciiFile()));
811     }
812     else if ( HOMARD_UTILS::isFileType(obj,QString("Mesh")) )
813     {
814       pix = resMgr->loadPixmap( "HOMARD", "mesh_tree_mesh.png" );
815       menu->addAction(QIcon(pix), tr(QString("HOM_MEN_MESH_PUBLICATION").toLatin1().data()), this, SLOT(MeshPublish1()));
816     }
817 //  Ajout d'un menu d'edition pour les objets qui le proposent
818     if ( EditObject )
819     {
820       pix = resMgr->loadPixmap( "HOMARD", "loop.png" );
821       menu->addAction(QIcon(pix), tr(QString("HOM_MEN_EDIT").toLatin1().data()), this, SLOT(Edit()));
822     }
823 //  Ajout d'un menu de destruction pour les objets qui le proposent
824     if ( DeleteObject )
825     {
826       pix = resMgr->loadPixmap( "HOMARD", "delete.png" );
827       menu->addAction(QIcon(pix), tr(QString("HOM_MEN_DELETE").toLatin1().data()), this, SLOT(Delete()));
828     }
829   }
830 }
831
832 void HOMARDGUI::NextIter()
833 {
834   this->OnGUIEvent(1103);
835 }
836
837 void HOMARDGUI::LanceCalcul0()
838 {
839   this->OnGUIEvent(1111);
840 }
841
842 void HOMARDGUI::LanceCalcul1()
843 {
844   this->OnGUIEvent(1112);
845 }
846
847 void HOMARDGUI::IterInfo()
848 {
849   this->OnGUIEvent(1121);
850 }
851
852 void HOMARDGUI::MeshPublish0()
853 {
854   this->OnGUIEvent(1131);
855 }
856
857 void HOMARDGUI::MeshPublish1()
858 {
859   this->OnGUIEvent(1132);
860 }
861
862 void HOMARDGUI::Edit()
863 {
864   this->OnGUIEvent(1201);
865 }
866
867 void HOMARDGUI::Delete()
868 {
869   this->OnGUIEvent(1211);
870 }
871
872 void HOMARDGUI::EditAsciiFile()
873 {
874   this->OnGUIEvent(1302);
875 }
876
877 void HOMARDGUI::YACSCreate()
878 {
879   this->OnGUIEvent(1401);
880 }
881 void HOMARDGUI::YACSWrite()
882 {
883   this->OnGUIEvent(1402);
884 }
885
886
887 //
888 //=============================================================================
889 // Export the module
890 //=============================================================================
891 extern "C" {
892   Standard_EXPORT CAM_Module* createModule()
893   {
894     return new HOMARDGUI("");
895   }
896 }
897