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