Salome HOME
Passage en utf8
[modules/homard.git] / src / HOMARDGUI / HOMARDGUI.cxx
1 // Copyright (C) 2011-2014  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   HOMARD::HOMARD_Gen_var homardGen = HOMARDGUI::InitHOMARDGen(app);
372
373   if (!CORBA::is_nil(homardGen))
374   {
375     // Set current study
376     SalomeApp_Study* aSAStudy =dynamic_cast<SalomeApp_Study*>(app->activeStudy());
377     _PTR(Study) aStudy = aSAStudy->studyDS();
378     SALOMEDS::Study_ptr aStudyDS;
379     if (aStudy)
380       aStudyDS = _CAST(Study,aStudy)->GetStudy();
381       homardGen->SetCurrentStudy(aStudyDS);
382    }
383   getApp()->updateObjectBrowser();
384
385 // B. Choix selon les commandes
386   SCRUTE(theCommandID);
387   switch (theCommandID)
388   {
389     case 1101: // Creation d un Cas
390     {
391       MESSAGE("command " << theCommandID << " activated");
392       MonCreateCase *aDlg = new MonCreateCase( true,
393                             HOMARD::HOMARD_Gen::_duplicate(homardGen) ) ;
394       aDlg->show();
395       break;
396     }
397
398     case 1102: // Poursuite d une iteration
399     {
400       MESSAGE("command " << theCommandID << " activated");
401       MonPursueIteration *aDlg = new MonPursueIteration( true,
402                                 HOMARD::HOMARD_Gen::_duplicate(homardGen) ) ;
403       aDlg->show();
404       break;
405     }
406
407     case 1103: // Creation d une Iteration
408     {
409       MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
410       MonCreateIteration *IterDlg = new MonCreateIteration( parent, true,
411                                      HOMARD::HOMARD_Gen::_duplicate(homardGen), _ObjectName ) ;
412       IterDlg->show();
413       break;
414     }
415
416     case 1111: // Compute une iteration
417     {
418       MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
419       try { homardGen->Compute(_ObjectName.toStdString().c_str(), 0, 1, -1, 1); }
420       catch( SALOME::SALOME_Exception& S_ex )
421       {
422         QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
423                                   QObject::tr(CORBA::string_dup(S_ex.details.text)) );
424         getApp()->updateObjectBrowser();
425         return false;
426       }
427       break;
428     }
429
430     case 1112: // Compute une iteration et publication
431     {
432       MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
433       try { homardGen->Compute(_ObjectName.toStdString().c_str(), 0, 1, -1, 2); }
434       catch( SALOME::SALOME_Exception& S_ex )
435       {
436         QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
437                                   QObject::tr(CORBA::string_dup(S_ex.details.text)) );
438         getApp()->updateObjectBrowser();
439         return false;
440       }
441       break;
442     }
443
444     case 1121: // Information sur le maillage de l'iteration
445     {
446       MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
447       MonIterInfo *IterDlg = new MonIterInfo( parent, true, HOMARD::HOMARD_Gen::_duplicate(homardGen), _ObjectName ) ;
448       IterDlg->show();
449       break;
450     }
451
452     case 1131: // Publication du maillage de l'iteration
453     {
454       MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
455       homardGen->PublishMeshIterInSmesh(_ObjectName.toStdString().c_str());
456       break;
457     }
458
459     case 1132: // Publication du maillage de l'iteration a partir du fichier
460     {
461       MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
462       homardGen->PublishResultInSmesh(_ObjectName.toStdString().c_str(), 1);
463       break;
464     }
465
466     case 1201: // Edition d'un objet
467     {
468       MESSAGE("command " << theCommandID << " activated");
469       QString nomObjet = HOMARD_QT_COMMUN::SelectionArbreEtude(QString(""), 1);
470       if (nomObjet == QString("")) break;
471       _PTR(SObject) obj = chercheMonObjet();
472       if (obj)
473       {
474         // Edition d'une frontiere discrete
475         if (HOMARD_UTILS::isBoundaryDi(obj))
476         {
477           MonEditBoundaryDi *aDlg = new MonEditBoundaryDi(0, true, HOMARD::HOMARD_Gen::_duplicate(homardGen), QString(""), _ObjectName ) ;
478           aDlg->show();
479         }
480         // Edition d'une frontiere analytique
481         else if (HOMARD_UTILS::isBoundaryAn(obj))
482         {
483           MonEditBoundaryAn *aDlg = new MonEditBoundaryAn(0, true, HOMARD::HOMARD_Gen::_duplicate(homardGen), QString(""), _ObjectName ) ;
484           aDlg->show();
485         }
486         // Edition d'un cas
487         else if (HOMARD_UTILS::isCase(obj))
488         {
489           MonEditCase *aDlg = new MonEditCase(true, HOMARD::HOMARD_Gen::_duplicate(homardGen), _ObjectName ) ;
490           aDlg->show();
491         }
492         // Edition d'une hypothese
493         else if (HOMARD_UTILS::isHypo(obj))
494         {
495           MonEditHypothesis *aDlg = new MonEditHypothesis(0, true, HOMARD::HOMARD_Gen::_duplicate(homardGen),  _ObjectName, QString(""), QString("")) ;
496           aDlg->show();
497         }
498         // Edition d'une iteration
499         else if (HOMARD_UTILS::isIter(obj))
500         {
501           MonEditIteration *aDlg = new MonEditIteration(parent, true, HOMARD::HOMARD_Gen::_duplicate(homardGen), QString(""), _ObjectName ) ;
502           aDlg->show();
503         }
504         // Edition d'un schema YACS
505         else if (HOMARD_UTILS::isYACS(obj))
506         {
507           MESSAGE("appel de MonEditYACS");
508           MonEditYACS *aDlg = new MonEditYACS(true, HOMARD::HOMARD_Gen::_duplicate(homardGen), _ObjectName) ;
509           aDlg->show();
510         }
511         // Edition d'une zone
512         else if (HOMARD_UTILS::isZone(obj))
513         {
514           MonEditZone *aDlg = new MonEditZone(0, true, HOMARD::HOMARD_Gen::_duplicate(homardGen), QString(""), _ObjectName ) ;
515           aDlg->show();
516         }
517       }
518       break;
519     }
520
521     case 1211: // Suppression d'un objet
522     {
523       MESSAGE("command " << theCommandID << " activated");
524       QString nomObjet = HOMARD_QT_COMMUN::SelectionArbreEtude(QString(""), 1);
525       if (nomObjet == QString("")) break;
526       _PTR(SObject) obj = chercheMonObjet();
527       if (obj)
528       {
529         // Suppression d'une frontiere
530         if ( HOMARD_UTILS::isBoundaryDi(obj) || HOMARD_UTILS::isBoundaryAn(obj) )
531         {
532           try
533           { homardGen->DeleteBoundary(_ObjectName.toStdString().c_str()); }
534           catch( SALOME::SALOME_Exception& S_ex )
535           {
536             QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
537                                       QObject::tr(CORBA::string_dup(S_ex.details.text)) );
538             getApp()->updateObjectBrowser();
539             return false;
540           }
541         }
542         // Suppression d'un cas
543         else if (HOMARD_UTILS::isCase(obj))
544         {
545           try
546           { homardGen->DeleteCase(_ObjectName.toStdString().c_str(), 1); }
547           catch( SALOME::SALOME_Exception& S_ex )
548           {
549             QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
550                                       QObject::tr(CORBA::string_dup(S_ex.details.text)) );
551             getApp()->updateObjectBrowser();
552             return false;
553           }
554         }
555         // Suppression d'une hypothese
556         else if (HOMARD_UTILS::isHypo(obj))
557         {
558           try
559           { homardGen->DeleteHypo(_ObjectName.toStdString().c_str()); }
560           catch( SALOME::SALOME_Exception& S_ex )
561           {
562             QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
563                                       QObject::tr(CORBA::string_dup(S_ex.details.text)) );
564             getApp()->updateObjectBrowser();
565             return false;
566           }
567         }
568         // Suppression d'une iteration
569         else if (HOMARD_UTILS::isIter(obj))
570         {
571           try
572           { homardGen->DeleteIteration(_ObjectName.toStdString().c_str(), 1); }
573           catch( SALOME::SALOME_Exception& S_ex )
574           {
575             QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
576                                       QObject::tr(CORBA::string_dup(S_ex.details.text)) );
577             getApp()->updateObjectBrowser();
578             return false;
579           }
580         }
581         // Suppression d'un schema YACS
582         else if (HOMARD_UTILS::isYACS(obj))
583         {
584           try
585           { homardGen->DeleteYACS(_ObjectName.toStdString().c_str(), 1); }
586           catch( SALOME::SALOME_Exception& S_ex )
587           {
588             QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
589                                       QObject::tr(CORBA::string_dup(S_ex.details.text)) );
590             getApp()->updateObjectBrowser();
591             return false;
592           }
593         }
594         // Suppression d'une zone
595         else if (HOMARD_UTILS::isZone(obj))
596         {
597           try
598           { homardGen->DeleteZone(_ObjectName.toStdString().c_str()); }
599           catch( SALOME::SALOME_Exception& S_ex )
600           {
601             QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
602                                       QObject::tr(CORBA::string_dup(S_ex.details.text)) );
603             getApp()->updateObjectBrowser();
604             return false;
605           }
606         }
607       }
608       break;
609     }
610
611     case 1301: // Information sur un maillage
612     {
613       MESSAGE("etape 1301")
614       MESSAGE("command " << theCommandID << " activated");
615       MonMeshInfo *aDlg = new MonMeshInfo( parent, true, HOMARD::HOMARD_Gen::_duplicate(homardGen) ) ;
616       aDlg->show();
617       break;
618     }
619
620     case 1302: // Affichage de fichier texte
621     {
622       MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
623       _PTR(SObject) obj = chercheMonObjet();
624       if ( (obj) && ( HOMARD_UTILS::isFileType(obj,QString("log")) || HOMARD_UTILS::isFileType(obj,QString("Summary")) || HOMARD_UTILS::isFileType(obj,QString("xml")) ) )
625       {
626           MonEditFile *aDlg = new MonEditFile( 0, true, HOMARD::HOMARD_Gen::_duplicate(homardGen), _ObjectName, 0 ) ;
627           if ( aDlg->_codret == 0 ) { aDlg->show(); }
628       }
629       break;
630     }
631
632     case 1401: // Création d'un schema YACS
633     {
634       MESSAGE("etape 1401")
635       MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
636       MonCreateYACS *aDlg = new MonCreateYACS( true, HOMARD::HOMARD_Gen::_duplicate(homardGen), _ObjectName ) ;
637       aDlg->show();
638       break;
639     }
640
641     case 1402: // Ecriture d'un schéma YACS
642     {
643       MESSAGE("etape 1402")
644       MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
645       try { homardGen->YACSWrite(_ObjectName.toStdString().c_str()); }
646       catch( SALOME::SALOME_Exception& S_ex )
647       {
648         QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
649                                   QObject::tr(CORBA::string_dup(S_ex.details.text)) );
650         getApp()->updateObjectBrowser();
651         return false;
652       }
653       break;
654     }
655
656   }
657   getApp()->updateObjectBrowser();
658   return true;
659 }
660
661 //=============================================================================
662 /*!
663  *
664  */
665 //=============================================================================
666
667 // Module's engine IOR
668 //=============================================================================
669 QString HOMARDGUI::engineIOR() const
670 //=============================================================================
671 {
672   CORBA::String_var anIOR = getApp()->orb()->object_to_string( InitHOMARDGen(getApp()) );
673   return QString( anIOR.in() );
674 }
675
676 // Module's activation
677 //=============================================================================
678 bool HOMARDGUI::activateModule( SUIT_Study* theStudy )
679 //=============================================================================
680 {
681   bool bOk = SalomeApp_Module::activateModule( theStudy );
682
683   setMenuShown( true );
684   setToolShown( true );
685
686   return bOk;
687 }
688
689 // Module's deactivation
690 //=============================================================================
691 bool HOMARDGUI::deactivateModule( SUIT_Study* theStudy )
692 //=============================================================================
693 {
694   setMenuShown( false );
695   setToolShown( false );
696
697   return SalomeApp_Module::deactivateModule( theStudy );
698 }
699
700 // Default windows
701 //=============================================================================
702 void HOMARDGUI::windows( QMap<int, int>& theMap ) const
703 //=============================================================================
704 {
705   theMap.clear();
706   theMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
707   theMap.insert( SalomeApp_Application::WT_PyConsole,     Qt::BottomDockWidgetArea );
708 }
709
710 //=============================================================================
711 void HOMARDGUI::setOrb()
712 //=============================================================================
713 {
714   try
715   {
716      ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
717      ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
718      _orb = init( 0 , 0 );
719   }
720   catch (...)
721   {
722      INFOS("internal error : orb not found");
723      _orb = 0;
724   }
725             ASSERT(! CORBA::is_nil(_orb));
726 }
727 //========================================
728 _PTR(SObject) HOMARDGUI::chercheMonObjet()
729 //========================================
730 {
731   SALOMEDSClient_SObject* aSO = NULL;
732   _PTR(SObject) obj;
733   SALOME_ListIO lst;
734   getApp()->selectionMgr()->selectedObjects( lst );
735   if (  lst.Extent() == 1 )
736   {
737     Handle(SALOME_InteractiveObject) io = lst.First();
738     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
739     _PTR(Study) study = appStudy->studyDS();
740     _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
741     _ObjectName = QString( obj->GetName().c_str() );
742     return obj;
743   }
744   else { return _PTR(SObject)(aSO); }
745 }
746 //=============================================================================
747 void HOMARDGUI::contextMenuPopup( const QString& client, QMenu* menu, QString& title )
748 //=============================================================================
749 {
750   MESSAGE("Debut de contextMenuPopup");
751   _PTR(SObject) obj = chercheMonObjet();
752   if ( obj )
753   {
754     title = QString( obj->GetName().c_str() );
755     _ObjectName = title;
756     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
757 //
758     QPixmap pix ;
759     bool DeleteObject = false ;
760     bool EditObject = false ;
761 //
762     if ( HOMARD_UTILS::isBoundaryAn(obj) )
763     {
764       EditObject = true ;
765       DeleteObject = true ;
766     }
767     else if ( HOMARD_UTILS::isBoundaryDi(obj) )
768     {
769       EditObject = true ;
770       DeleteObject = true ;
771     }
772     else if ( HOMARD_UTILS::isCase(obj) )
773     {
774       pix = resMgr->loadPixmap( "HOMARD", "table_view.png" );
775       menu->addAction(QIcon(pix), tr(QString("HOM_MEN_YACS").toLatin1().data()), this, SLOT(YACSCreate()));
776       EditObject = true ;
777       DeleteObject = true ;
778     }
779     else if ( HOMARD_UTILS::isHypo(obj) )
780     {
781       EditObject = true ;
782       DeleteObject = true ;
783     }
784     else if ( HOMARD_UTILS::isIter(obj) )
785     {
786       pix = resMgr->loadPixmap( "HOMARD", "iter_next.png" );
787       menu->addAction(QIcon(pix), tr(QString("HOM_MEN_NEW_ITERATION").toLatin1().data()), this, SLOT(NextIter()));
788       pix = resMgr->loadPixmap( "HOMARD", "mesh_compute.png" );
789       menu->addAction(QIcon(pix), tr(QString("HOM_MEN_COMPUTE").toLatin1().data()), this, SLOT(LanceCalcul0()));
790       pix = resMgr->loadPixmap( "HOMARD", "mesh_compute.png" );
791       menu->addAction(QIcon(pix), tr(QString("HOM_MEN_COMPUTE_PUBLISH").toLatin1().data()), this, SLOT(LanceCalcul1()));
792       pix = resMgr->loadPixmap( "HOMARD", "advanced_mesh_info.png" );
793       menu->addAction(QIcon(pix), tr(QString("HOM_MEN_MESH_INFO").toLatin1().data()), this, SLOT(IterInfo()));
794       pix = resMgr->loadPixmap( "HOMARD", "mesh_tree_mesh.png" );
795       menu->addAction(QIcon(pix), tr(QString("HOM_MEN_MESH_PUBLICATION").toLatin1().data()), this, SLOT(MeshPublish0()));
796       EditObject = true ;
797       DeleteObject = true ;
798     }
799     else if ( HOMARD_UTILS::isYACS(obj) )
800     {
801       pix = resMgr->loadPixmap( "HOMARD", "write.png" );
802       menu->addAction(QIcon(pix), tr(QString("HOM_MEN_WRITE").toLatin1().data()), this, SLOT(YACSWrite()));
803       EditObject = true ;
804       DeleteObject = true ;
805     }
806     else if ( HOMARD_UTILS::isZone(obj) )
807     {
808       EditObject = true ;
809       DeleteObject = true ;
810     }
811     else if ( HOMARD_UTILS::isFileType(obj,QString("log")) || HOMARD_UTILS::isFileType(obj,QString("Summary")) || HOMARD_UTILS::isFileType(obj,QString("xml")) )
812     {
813       pix = resMgr->loadPixmap( "HOMARD", "texte.png" );
814       menu->addAction(QIcon(pix), tr(QString("HOM_MEN_EDIT_MESS_FILE").toLatin1().data()), this, SLOT(EditAsciiFile()));
815     }
816     else if ( HOMARD_UTILS::isFileType(obj,QString("Mesh")) )
817     {
818       pix = resMgr->loadPixmap( "HOMARD", "mesh_tree_mesh.png" );
819       menu->addAction(QIcon(pix), tr(QString("HOM_MEN_MESH_PUBLICATION").toLatin1().data()), this, SLOT(MeshPublish1()));
820     }
821 //  Ajout d'un menu d'edition pour les objets qui le proposent
822     if ( EditObject )
823     {
824       pix = resMgr->loadPixmap( "HOMARD", "loop.png" );
825       menu->addAction(QIcon(pix), tr(QString("HOM_MEN_EDIT").toLatin1().data()), this, SLOT(Edit()));
826     }
827 //  Ajout d'un menu de destruction pour les objets qui le proposent
828     if ( DeleteObject )
829     {
830       pix = resMgr->loadPixmap( "HOMARD", "delete.png" );
831       menu->addAction(QIcon(pix), tr(QString("HOM_MEN_DELETE").toLatin1().data()), this, SLOT(Delete()));
832     }
833   }
834 }
835
836 void HOMARDGUI::NextIter()
837 {
838   this->OnGUIEvent(1103);
839 }
840
841 void HOMARDGUI::LanceCalcul0()
842 {
843   this->OnGUIEvent(1111);
844 }
845
846 void HOMARDGUI::LanceCalcul1()
847 {
848   this->OnGUIEvent(1112);
849 }
850
851 void HOMARDGUI::IterInfo()
852 {
853   this->OnGUIEvent(1121);
854 }
855
856 void HOMARDGUI::MeshPublish0()
857 {
858   this->OnGUIEvent(1131);
859 }
860
861 void HOMARDGUI::MeshPublish1()
862 {
863   this->OnGUIEvent(1132);
864 }
865
866 void HOMARDGUI::Edit()
867 {
868   this->OnGUIEvent(1201);
869 }
870
871 void HOMARDGUI::Delete()
872 {
873   this->OnGUIEvent(1211);
874 }
875
876 void HOMARDGUI::EditAsciiFile()
877 {
878   this->OnGUIEvent(1302);
879 }
880
881 void HOMARDGUI::YACSCreate()
882 {
883   this->OnGUIEvent(1401);
884 }
885 void HOMARDGUI::YACSWrite()
886 {
887   this->OnGUIEvent(1402);
888 }
889
890
891 //
892 //=============================================================================
893 // Export the module
894 //=============================================================================
895 extern "C" {
896   Standard_EXPORT CAM_Module* createModule()
897   {
898     return new HOMARDGUI("");
899   }
900 }
901