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