Salome HOME
a37c196d3f998a2a1ff8c7d4664d1c3c8ee3cb6b
[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 // 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   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 void 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 ;
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 // }
108
109 /*!
110   * \brief Launches the GUI for the adaptation
111   * \param theCommandID - the integer that references the operation
112   * \return bool OK/notOK
113 */
114 bool SMESHGUI_AdaptDlg::OnGUIEvent (int theCommandID)
115 {
116 //   std::cout  << "SMESHGUI_AdaptDlg:OnGUIEvent avec theCommandID : " << theCommandID << std::endl;
117 // A. Controles
118   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
119   if ( !app ) return false;
120
121   SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*> ( app->activeStudy() );
122   if ( !aStudy )
123   {
124     INFOS ( "FAILED to cast active study to SalomeApp_Study" );
125     return false;
126   }
127
128   SUIT_Desktop* parent = SUIT_Session::session()->activeApplication()->desktop();
129
130   SALOME_LifeCycleCORBA* ls = new SALOME_LifeCycleCORBA(app->namingService());
131   Engines::EngineComponent_var comp = ls->FindOrLoad_Component("FactoryServer", "SMESH");
132 //   ADAPT::ADAPT_Gen_var adaptGen = ADAPT::ADAPT_Gen::_narrow(comp);
133 //   if (!CORBA::is_nil(adaptGen))
134 //     adaptGen->UpdateStudy();
135
136   mySMESHGUI->getApp()->updateObjectBrowser();
137 //
138 // B. Choix selon les commandes
139   bool ok = true ;
140   SCRUTE(theCommandID);
141   switch (theCommandID)
142   {
143     case 8020: // Adaptation avec MG-Adpat
144     {
145 //       INFOS("Interface avec MG-Adapt" );
146
147       SMESH::MG_ADAPT_ptr model = SMESHGUI::GetSMESHGen()->CreateMG_ADAPT();
148       bool isCreation = false;
149       if (mySMESHGUI->isStudyLocked()) break;
150       mySMESHGUI->EmitSignalDeactivateDialog();
151       SMESHGUI_MG_ADAPTDRIVER *mgAdapt = new SMESHGUI_MG_ADAPTDRIVER(mySMESHGUI, model, isCreation);
152       mgAdapt->show();
153       break;
154     }
155
156   }
157   mySMESHGUI->getApp()->updateObjectBrowser();
158   return ok;
159 }
160
161
162