Salome HOME
ménage
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_AdaptDlg.cxx
1 // Copyright (C) 2011-2020  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 //  SMESH SMESHGUI : GUI for the adaptation in the SMESH component
21 //  File   : SMESHGUI_AdaptDlg.cxx
22 //  Author : Gerald NICOLAS, EDF
23
24 //  SMESH includes
25 #include "SMESHGUI.h"
26 #include "SMESHGUI_AdaptDlg.h"
27
28 // SALOME GUI includes
29 #include <SUIT_Desktop.h>
30 #include <SUIT_ResourceMgr.h>
31 #include <SUIT_Session.h>
32 #include <SalomeApp_Application.h>
33 #include <SalomeApp_Study.h>
34
35 // HOMARD includes
36 #include "MonCreateCase.h"
37
38 // SALOME KERNEL includes
39 #include "utilities.h"
40 #include <SALOME_LifeCycleCORBA.hxx>
41
42 //=================================================================================
43 // function : SMESHGUI_AdaptDlg()
44 // purpose  :
45 //=================================================================================
46 SMESHGUI_AdaptDlg::SMESHGUI_AdaptDlg( SMESHGUI* theModule,
47                                       int theCommandID,
48                                       SMESH::SMESH_Mesh_ptr theMesh )
49   : mySMESHGUI( theModule )
50 {
51   bool ok = action( theCommandID ) ;
52 }
53
54 //=================================================================================
55 // function : ~SMESHGUI_AdaptDlg()
56 // purpose  : Destroys the object and frees any allocated resources
57 //=================================================================================
58 SMESHGUI_AdaptDlg::~SMESHGUI_AdaptDlg()
59 {
60 }
61
62 /*!
63   * \brief Pilote les actions d'adaption de maillage
64   * \param
65   * \return bool OK/notOK
66 */
67 bool SMESHGUI_AdaptDlg::action (int theCommandID)
68 //=======================================================================
69 {
70   std::cout  << "SMESHGUI_AdaptDlg::action avec theCommandID : " << theCommandID << std::endl;
71
72 // Preferences
73   recupPreferences();
74
75 // Menus and actions
76   bool ok =  OnGUIEvent (theCommandID) ;
77   if ( ! ok ) INFOS("Erreur");
78
79   return ok ;
80 }
81
82 /*!
83   * \brief Gets the preferences for the adaptation
84   * \param
85   * \return
86   *
87   * Pour chaque valeur, le defaut est la valeur definie dans ADAPT_Gen
88   * . Si la recuperation dans config/salome s'est bien passee a la creation de ADAPT_Gen
89   *   ces valeurs sont les valeurs definies.
90   * . Si cela ne s'est pas bien passe, ce sont les valeurs par defaut de ADAPT_Gen
91 */
92 void SMESHGUI_AdaptDlg::recupPreferences()
93 {
94   INFOS("Début de recupPreferences")
95 //
96 // A. Declarations
97 //
98   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
99   SALOME_LifeCycleCORBA* ls = new SALOME_LifeCycleCORBA(app->namingService());
100   Engines::EngineComponent_var comp = ls->FindOrLoad_Component("FactoryServer", "SMESH");
101   ADAPT::ADAPT_Gen_var adaptGen = ADAPT::ADAPT_Gen::_narrow(comp);
102   if (!CORBA::is_nil(adaptGen))
103     adaptGen->UpdateStudy();
104
105   SUIT_ResourceMgr* resMgr = mySMESHGUI->getApp()->resourceMgr();
106
107 // B. Les valeurs
108 // B.1. La langue
109
110   _LanguageShort = resMgr->stringValue("language", "language", "en" );
111   INFOS ("Enregistrement de LanguageShort = " << _LanguageShort.toStdString().c_str() );
112 //   adaptGen->SetLanguageShort(_LanguageShort.toStdString().c_str());
113
114 // B.2. Les publications
115   bool publish_mesh ;
116
117   publish_mesh = resMgr->booleanValue("HOMARD", "publish_mesh_in", false );
118   if ( publish_mesh ) { _PublisMeshIN = 1 ; }
119   else                { _PublisMeshIN = 0 ; }
120
121   publish_mesh = resMgr->booleanValue("HOMARD", "publish_mesh_out", false );
122   if ( publish_mesh ) { _PublisMeshOUT = 1 ; }
123   else                { _PublisMeshOUT = 0 ; }
124
125   INFOS ("Enregistrement de PublisMeshIN = " << _PublisMeshIN<<", PublisMeshOUT = "<< _PublisMeshOUT);
126 //   adaptGen->SetPublisMesh(_PublisMeshIN, _PublisMeshOUT);
127
128 // B.3. Les maximum pour YACS
129
130   _YACSMaxIter = resMgr->integerValue("HOMARD", "yacs_max_iter", 0 );
131   _YACSMaxNode = resMgr->integerValue("HOMARD", "yacs_max_node", 0 );
132   _YACSMaxElem = resMgr->integerValue("HOMARD", "yacs_max_elem", 0 );
133
134   INFOS ("Enregistrement de YACSMaxIter = " << _YACSMaxIter<<", YACSMaxNode = "<< _YACSMaxNode<<", YACSMaxElem = "<< _YACSMaxElem);
135 //   adaptGen->SetYACSMaximum(_YACSMaxIter, _YACSMaxNode, _YACSMaxElem);
136
137 // B.4. La convergence pour YACS
138
139   QString QString_v = resMgr->stringValue ( "HOMARD", "yacs_type_test", "None" );
140   if ( ( QString_v == "VTest > VRef" ) || ( QString_v == "VTest &gt; VRef" ) )      { _YACSTypeTest = 1 ; }
141   else if ( ( QString_v == "VTest < VRef" ) || ( QString_v == "VTest &lt; VRef" ) ) { _YACSTypeTest = 2 ; }
142   else                                                                              { _YACSTypeTest = 0 ; }
143
144   INFOS ("Enregistrement de YACSTypeTest = " << _YACSTypeTest);
145 //   adaptGen->SetYACSConvergenceType(_YACSTypeTest);
146
147   INFOS("Fin de recupPreferences")
148 }
149
150 /*!
151   * \brief Launches the GUI for the adaptation
152   * \param theCommandID - the integer that references the operation
153   * \return bool OK/notOK
154 */
155 bool SMESHGUI_AdaptDlg::OnGUIEvent (int theCommandID)
156 {
157   std::cout  << "OnGUIEvent avec theCommandID : " << theCommandID << std::endl;
158 // A. Controles
159   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
160   if ( !app ) return false;
161
162   SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*> ( app->activeStudy() );
163   if ( !aStudy )
164   {
165     INFOS ( "FAILED to cast active study to SalomeApp_Study" );
166     return false;
167   }
168
169   SUIT_Desktop* parent = SUIT_Session::session()->activeApplication()->desktop();
170
171   SALOME_LifeCycleCORBA* ls = new SALOME_LifeCycleCORBA(app->namingService());
172   Engines::EngineComponent_var comp = ls->FindOrLoad_Component("FactoryServer", "SMESH");
173   ADAPT::ADAPT_Gen_var adaptGen = ADAPT::ADAPT_Gen::_narrow(comp);
174   if (!CORBA::is_nil(adaptGen))
175     adaptGen->UpdateStudy();
176
177   mySMESHGUI->getApp()->updateObjectBrowser();
178 //
179 // B. Choix selon les commandes
180   bool ok = true ;
181   SCRUTE(theCommandID);
182   switch (theCommandID)
183   {
184     case 8000: // Raffinement uniforme
185     {
186       INFOS("Raffinement uniforme");
187 //       A faire
188       break;
189     }
190     case 8011: // Création d'un Cas
191     {
192       INFOS("Création d'un Cas");
193       MonCreateCase *aDlg = new MonCreateCase( true,
194                             ADAPT::ADAPT_Gen::_duplicate(adaptGen) ) ;
195       aDlg->show();
196       break;
197     }
198     case 8012: // Création d'un cas en poursuite d'une itération
199     {
200       INFOS("Création d'un cas en poursuite d'une itération");
201 //       MonPursueIteration *aDlg = new MonPursueIteration( true,
202 //                                 ADAPT::ADAPT_Gen::_duplicate(adaptGen) ) ;
203 //       aDlg->show();
204 //       break;
205     }
206     case 8013: // Création d'une itération
207     {
208       INFOS("Création d'une itération" );
209 //       MonCreateIteration *IterDlg = new MonCreateIteration( parent, true,
210 //                                      ADAPT::ADAPT_Gen::_duplicate(adaptGen), _ObjectName ) ;
211 //       IterDlg->show();
212       break;
213     }
214     case 8014: // Calcule une itération
215     {
216       INFOS("Calcule une itération" );
217 //       try { adaptGen->Compute(_ObjectName.toStdString().c_str(), 0, 1, -1, 1); }
218 //       catch( SALOME::SALOME_Exception& S_ex )
219 //       {
220 //         QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
221 //                                   QObject::tr(CORBA::string_dup(S_ex.details.text)) );
222 //         mySMESHGUI->getApp()->updateObjectBrowser();
223 //         ok = false;
224 //       }
225       break;
226     }
227     case 8015: // Calcule une itération et publication
228     {
229       INFOS("Calcule une itération et publication");
230 //       try { adaptGen->Compute(_ObjectName.toStdString().c_str(), 0, 1, -1, 2); }
231 //       catch( SALOME::SALOME_Exception& S_ex )
232 //       {
233 //         QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
234 //                                   QObject::tr(CORBA::string_dup(S_ex.details.text)) );
235 //         mySMESHGUI->getApp()->updateObjectBrowser();
236 //         ok = false;
237 //       }
238       break;
239     }
240     case 8020: // Adaptation avec MG-Adpat
241     {
242       INFOS("Interface avec MG-Adapt" );
243 //       A faire
244       break;
245     }
246
247   }
248   mySMESHGUI->getApp()->updateObjectBrowser();
249   return ok;
250 }
251
252
253