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