Salome HOME
8e75e0f6ebcef69ad9c6e5f5f40b96fb23aebcad
[modules/smesh.git] / src / ADAPTGUI / MonEditIteration.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 #include "MonEditIteration.h"
21
22 #include "SalomeApp_Tools.h"
23 #include "HOMARDGUI_Utils.h"
24 #include "HomardQtCommun.h"
25 #include <utilities.h>
26
27 using namespace std;
28
29 // -------------------------------------------------------------------------------------------------------------------------------------
30 MonEditIteration::MonEditIteration ( QWidget* parent, bool modal,
31                                      ADAPT::ADAPT_Gen_var myAdaptGen,
32                                      QString IterParentName, QString IterName ):
33 // -------------------------------------------------------------------------------------------------------------------------------------
34 /* Constructs a MonEditIteration
35     herite de MonCreateIteration
36 */
37    MonCreateIteration(parent, modal, myAdaptGen, IterParentName),
38    _rank(-1), _step(-1), _IterationName(""), _FieldFile(""),_aTypeAdap()
39 {
40     MESSAGE("Debut de  MonEditIteration" << IterName.toStdString().c_str());
41     setWindowTitle(QObject::tr("HOM_ITER_EDIT_WINDOW_TITLE"));
42     _IterationName = IterName;
43     aIter = myAdaptGen->GetIteration(_IterationName.toStdString().c_str());
44
45 //  Attention au cas ou c'est une iteration initiale : il faut inhiber l'essentiel
46     int etat = aIter->GetState() ;
47     if ( etat <= 0 ) { InitValEdit0(etat); }
48     else             { InitValEdit(); }
49 }
50 // ------------------------------
51 MonEditIteration::~MonEditIteration()
52 // ------------------------------
53 {
54 }
55
56 // ------------------------------
57 void MonEditIteration::InitValEdit0(int etat)
58 // ------------------------------
59 //    Cas d'une iteration initiale d'un cas (initial ou poursuite)
60 {
61 //
62       LEName->setText(_IterationName);
63       LEName->setReadOnly(true);
64
65 //    Invisibilite de l'iteration parent
66       Iter_Parent->setVisible(0);
67       PBIterParent->setVisible(0);
68       LEIterationParentName->setVisible(0);
69
70 //    Affichage bloque du nom du maillage de l'iteration courante
71       QString MeshName = aIter->GetMeshName();
72       Mesh_n->setText(QObject::tr("HOM_ITER_STARTING_POINT_0"));
73       LEMeshName_n->setText(MeshName);
74       LEMeshName_n->setReadOnly(1);
75
76 //    Message general
77       if ( etat == 0 ) { Mesh_np1->setText(QObject::tr("HOM_ITER_STARTING_POINT_1")) ; }
78       else             { Mesh_np1->setText(QObject::tr("HOM_ITER_STARTING_POINT_2")) ; }
79       LEMeshName_np1->setVisible(0);
80 //
81 //    Invisibilite des hypotheses et des champs
82       Hypothese->setVisible(0);
83       GBField->setVisible(0);
84 //
85 }
86 // ------------------------------
87 void MonEditIteration::InitValEdit()
88 // ------------------------------
89 //    Cas d'une iteration courante
90 {
91 //    Affichage bloque du nom de l'iteration
92   LEName->setText(_IterationName);
93   LEName->setReadOnly(true);
94
95   //    Affichage bloque du nom de l'iteration parent
96   _IterParentName = aIter->GetIterParentName();
97   LEIterationParentName->setText(_IterParentName);
98   LEIterationParentName->setReadOnly(true);
99   PBIterParent->setEnabled(false);
100   PBIterParent->setVisible(0);
101
102   //    Affichage bloque du nom du maillage de l'iteration parent
103   aIterParent = myAdaptGen->GetIteration(_IterParentName.toStdString().c_str());
104   QString MeshNameParent = aIterParent->GetMeshName();
105   LEMeshName_n->setText(MeshNameParent);
106   LEMeshName_n->setReadOnly(1);
107
108   //    Affichage bloque du nom du maillage de l'iteration courante
109   QString MeshName = aIter->GetMeshName();
110   LEMeshName_np1->setText(MeshName);
111   LEMeshName_np1->setReadOnly(1);
112
113   //    Affichage de la bonne hypothese
114   QString HypoName = aIter->GetHypoName();
115   CBHypothese->insertItem(0,HypoName);
116   CBHypothese->setCurrentIndex(0);
117   CBHypothese->setEnabled(false);
118   PBHypoNew->setVisible(0);
119
120   //    Pour une adaptation selon un champ
121   ADAPT::HOMARD_Hypothesis_var myHypo = myAdaptGen->GetHypothesis(HypoName.toStdString().c_str()) ;
122   _aTypeAdap = myHypo->GetAdapType() ;
123   if ( _aTypeAdap == 1 )
124   {
125     _FieldFile = aIter->GetFieldFile();
126     LEFieldFile->setText(_FieldFile);
127     _step = aIter->GetTimeStep() ;
128     SpinBox_TimeStep->setValue(_step);
129     _rank = aIter->GetRank() ;
130     SpinBox_Rank->setValue(_rank);
131
132   // Cas ou on prend le dernier pas de temps ou sans pas de temps
133     if ( _step <= -1 )
134     {
135       Rank->setVisible(0);
136       SpinBox_Rank->setVisible(0);
137       TimeStep->setVisible(0);
138       SpinBox_TimeStep->setVisible(0);
139
140       if ( _step == -2 ) { RBLast->setChecked(true); }
141       else               { RBNo->setChecked(true); }
142     }
143
144   // Cas avec pas de temps
145     else
146     {
147       Rank->setVisible(1);
148       SpinBox_Rank->setVisible(1);
149       TimeStep->setVisible(1);
150       SpinBox_TimeStep->setVisible(1);
151       RBChosen->setChecked(true);
152     }
153   }
154   else
155   {
156     GBField->setVisible(0);
157   }
158 //
159   adjustSize();
160 //
161 }
162
163 // -------------------------------------
164 bool MonEditIteration::PushOnApply()
165 // -------------------------------------
166 {
167   if ( _aTypeAdap ==  1)
168   {
169 // Pour du raffinement selon un champ, les instants ont-ils change ?
170     if ( (_FieldFile != LEFieldFile->text().trimmed()) ||
171        (  _rank != SpinBox_Rank->value())  ||
172        (  _step != SpinBox_TimeStep->value()))
173     {
174       _FieldFile = LEFieldFile->text().trimmed();
175       aIter->SetFieldFile(CORBA::string_dup(_FieldFile.toStdString().c_str()));
176       _rank = SpinBox_Rank->value();
177       _step = SpinBox_TimeStep->value();
178       if ( _step == -2 ) { aIter->SetTimeStepRankLast(); }
179       else               { aIter->SetTimeStepRank(_step, _rank); }
180       myAdaptGen->InvalideIter(_IterationName.toStdString().c_str());
181       HOMARD_UTILS::updateObjBrowser();
182     }
183   }
184   return true;
185
186 };