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