]> SALOME platform Git repositories - modules/homard.git/blob - src/HOMARDGUI/MonCreateIteration.cxx
Salome HOME
Set dev tag back to 1
[modules/homard.git] / src / HOMARDGUI / MonCreateIteration.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 "MonCreateIteration.h"
23 #include "MonCreateHypothesis.h"
24 #include "MonEditHypothesis.h"
25
26 #include <QFileDialog>
27 #include <QMessageBox>
28
29 #include "SalomeApp_Tools.h"
30 #include "HOMARDGUI_Utils.h"
31 #include "HomardQtCommun.h"
32 #include <utilities.h>
33
34
35 // -----------------------------------------------------------------------------------------------------
36 MonCreateIteration::MonCreateIteration(QWidget* parent, bool modal,
37                                        HOMARD::HOMARD_Gen_var myHomardGen, QString IterParentName ):
38 // -----------------------------------------------------------------------------------------------------
39 /* Constructs a MonCreateIteration
40  * Inherits from CasHomard
41  * Sets attributes to default values
42  */
43     QDialog(0),
44     Ui_CreateIteration(),
45     _IterationName(""),
46     _IterParentName(IterParentName),
47     _CaseName("")
48     {
49       MESSAGE("Constructeur");
50       _myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen);
51       setupUi(this);
52       setModal(modal);
53       InitConnect();
54
55       SetNewIterationName();
56       GetHypotheses();
57       if (_IterParentName != QString(""))
58          { SetIterParentName(); }
59       else
60          {setModal(false); /* permet selection de l iteration dans l arbre d etude */}
61       SetTSNo();
62     }
63
64 // ------------------------------------------------------------------------
65 MonCreateIteration::~MonCreateIteration()
66 // ------------------------------------------------------------------------
67 {
68     // no need to delete child widgets, Qt does it all for us
69 }
70 // ------------------------------------------------------------------------
71 void MonCreateIteration::InitConnect()
72 // ------------------------------------------------------------------------
73 {
74     connect( PBIterParent,  SIGNAL(pressed()), this, SLOT( SetIterParentName()));
75     connect( PBHypoEdit,    SIGNAL(pressed()), this, SLOT( PushHypoEdit() ) );
76     connect( PBHypoNew,     SIGNAL(pressed()), this, SLOT( PushHypoNew() ) );
77     connect( PushFieldFile, SIGNAL(pressed()), this, SLOT( SetFieldFile() ) );
78     connect( RBNo,          SIGNAL(clicked()), this, SLOT( SetTSNo()));
79     connect( RBLast,        SIGNAL(clicked()), this, SLOT( SetTSLast()));
80     connect( RBChosen,      SIGNAL(clicked()), this, SLOT( SetTSChosen()));
81
82     connect( buttonOk,     SIGNAL(pressed()), this, SLOT( PushOnOK() ) );
83     connect( buttonApply,  SIGNAL(pressed()), this, SLOT( PushOnApply() ) );
84     connect( buttonCancel, SIGNAL(pressed()), this, SLOT( close() ) );
85     connect( buttonHelp,   SIGNAL(pressed()), this, SLOT( PushOnHelp() ) );
86 }
87 // ------------------------------------------------------------------------
88 void MonCreateIteration::GetHypotheses()
89 // ------------------------------------------------------------------------
90 {
91      HOMARD::listeHypotheses_var  mesHypotheses = _myHomardGen->GetAllHypothesesName();
92      for (int i=0; i<mesHypotheses->length(); i++)
93      {
94          CBHypothese->addItem(QString(mesHypotheses[i]));
95      }
96 }
97
98 // ------------------------------------------------------------------------
99 bool MonCreateIteration::PushOnApply()
100 // ------------------------------------------------------------------------
101 // Appele lorsque l'un des boutons Ok ou Apply est presse
102 {
103   MESSAGE("MonCreateIteration::PushOnApply");
104 //
105   QString aIterationName = LEIterationName->text().trimmed();
106   if ( aIterationName == QString (""))
107   {
108     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
109                               QObject::tr("HOM_ITER_NAME") );
110     return false;
111   }
112
113   if ( _IterParentName == QString (""))
114   {
115     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
116                               QObject::tr("HOM_ITER_STARTING_POINT") );
117     return false;
118   }
119   QString aMeshName_np1=LEMeshName_np1->text().trimmed();
120   if (aMeshName_np1 == "" )
121   {
122     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
123                               QObject::tr("HOM_ITER_MESH") );
124     return false;
125   }
126   QString monHypoName=CBHypothese->currentText();
127   if (monHypoName == "" )
128   {
129     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
130                               QObject::tr("HOM_ITER_HYPO") );
131     return false;
132   }
133   HOMARD::HOMARD_Hypothesis_var _myHypothesis = _myHomardGen->GetHypothesis(monHypoName.toStdString().c_str());
134   HOMARD::listeTypes_var ListTypes (_myHypothesis->GetAdapRefinUnRef());
135   int TypeAdap = ListTypes[0];
136   if ( TypeAdap == 1 and LEFieldFile->text().trimmed() == QString("") )
137   {
138     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
139                               QObject::tr("HOM_ITER_FIELD_FILE") );
140     return false;
141   }
142
143   MESSAGE ("aMeshName_np1.toStdString " << aMeshName_np1.toStdString());
144   MESSAGE ("_CaseName.toStdString " << _CaseName.toStdString() );
145   MESSAGE ("_IterParentName.toStdString " << _IterParentName.toStdString() );
146
147 // Creation de l'objet CORBA si ce n'est pas deja fait sous le meme nom
148   if (_IterationName != aIterationName)
149   {
150     try
151     {
152       _IterationName = aIterationName;
153       std::cerr << _IterationName.toStdString() << std::endl;
154       aIter = _myHomardGen->CreateIteration( \
155                CORBA::string_dup(_IterationName.toStdString().c_str()),
156                CORBA::string_dup(_IterParentName.toStdString().c_str()));
157     }
158     catch( SALOME::SALOME_Exception& S_ex )
159     {
160       QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
161                                 QString(CORBA::string_dup(S_ex.details.text)) );
162        return false;
163     }
164   }
165
166 // Mise en place des attributs
167   const char* IterName = aIter->GetName() ;
168   std::cerr << IterName << std::endl;
169
170   if ( LEFieldFile->text().trimmed() != QString(""))
171   {
172     QString FieldFile=LEFieldFile->text().trimmed();
173     aIter->SetFieldFile(CORBA::string_dup(FieldFile.toStdString().c_str()));
174     int rank = SpinBox_Rank->value();
175     int step = SpinBox_TimeStep->value();
176     if ( step == -2 ) { aIter->SetTimeStepRankLast(); }
177     else              { aIter->SetTimeStepRank(step,rank); }
178   }
179   _myHomardGen->AssociateIterHypo (IterName, monHypoName.toStdString().c_str());
180   aIter->SetMeshName(CORBA::string_dup(aMeshName_np1.toStdString().c_str()));
181
182   HOMARD_UTILS::updateObjBrowser();
183   return true;
184 }
185
186 // ------------------------------------------------------------------------
187 void MonCreateIteration::PushOnOK()
188 // ------------------------------------------------------------------------
189 {
190      bool bOK = PushOnApply();
191      if ( bOK )  this->close();
192 }
193
194 // ------------------------------------------------------------------------
195 void MonCreateIteration::PushOnHelp()
196 // ------------------------------------------------------------------------
197 {
198   HOMARD_UTILS::PushOnHelp(QString("gui_create_iteration.html"));
199 }
200
201 // ------------------------------------------------------------------------
202 void MonCreateIteration::SetIterParentName()
203 // ------------------------------------------------------------------------
204 {
205   if (_IterParentName == QString("")) {
206     _IterParentName=HOMARD_QT_COMMUN::SelectionArbreEtude(QString("IterationHomard"), 1);
207     if (_IterParentName == QString("")) { raise();return;};
208   }
209   _CaseName=HOMARD_QT_COMMUN::SelectionCasEtude();
210   HOMARD::HOMARD_Iteration_var aIterParent = _myHomardGen->GetIteration(_IterParentName.toStdString().c_str()) ;
211   QString MeshName = aIterParent->GetMeshName();
212
213   LEMeshName_n->setText(MeshName);
214   LEMeshName_n->setReadOnly(1);
215   LEMeshName_np1->setText(MeshName);
216
217   LEIterationParentName->setText(_IterParentName);
218 }
219
220 // -------------------------------------------------
221 void MonCreateIteration::SetNewIterationName()
222 // --------------------------------------------------
223 {
224 // Recherche d'un nom par defaut qui n'existe pas encore
225
226   HOMARD::listeIterations_var  myIters=_myHomardGen->GetAllIterationsName();
227   int num = 0;//
228   QString aIterationName="";
229   while (aIterationName=="" )
230   {
231     aIterationName.setNum(num+1) ;
232     aIterationName.insert(0, QString("Iter_"));
233     for ( int i=0; i< myIters->length(); i++)
234     {
235       if ( aIterationName ==  QString((myIters)[i]))
236       {
237           num=num+1;
238           aIterationName="";
239           break;
240       }
241    }
242   }
243   LEIterationName->setText(aIterationName);
244 }
245
246
247 // ------------------------------------------------------------------------
248 void MonCreateIteration::PushHypoEdit()
249 // ------------------------------------------------------------------------
250 {
251   if (CBHypothese->currentText() == QString(""))  return;
252   if (_IterParentName == QString(""))
253   {
254     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
255                               QObject::tr("HOM_ITER_STARTING_POINT") );
256     raise();
257     return;
258   }
259   QString aFieldFile=LEFieldFile->text().trimmed();
260   MonEditHypothesis *HypoDlg = new MonEditHypothesis(this,TRUE, HOMARD::HOMARD_Gen::_duplicate(_myHomardGen),CBHypothese->currentText(), _CaseName, aFieldFile) ;
261   HypoDlg->show();
262 }
263
264 // ------------------------------------------------------------------------
265 void MonCreateIteration::addHypothese(QString newHypothese)
266 // ------------------------------------------------------------------------
267 {
268   CBHypothese->insertItem(0,newHypothese);
269   CBHypothese->setCurrentIndex(0);
270 }
271 // ------------------------------------------------------------------------
272 void MonCreateIteration::PushHypoNew()
273 // ------------------------------------------------------------------------
274 {
275   if (_IterParentName == QString(""))
276   {
277     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
278                               QObject::tr("HOM_ITER_STARTING_POINT") );
279     raise();
280     return;
281   }
282   if ( _CaseName == QString(""))
283   {
284          HOMARD::HOMARD_Iteration_var aIterParent = _myHomardGen->GetIteration(_IterParentName.toStdString().c_str()) ;
285         _CaseName = aIterParent->GetCaseName();
286   }
287   QString aFieldFile=LEFieldFile->text().trimmed();
288   MonCreateHypothesis *HypoDlg = new MonCreateHypothesis(this,TRUE,HOMARD::HOMARD_Gen::_duplicate(_myHomardGen),QString(""),_CaseName, aFieldFile) ;
289   HypoDlg->show();
290 }
291
292 // ------------------------------------------------------------------------
293 void MonCreateIteration::SetFieldFile()
294 // ------------------------------------------------------------------------
295
296 {
297   QString fileName0 = LEFieldFile->text().trimmed();
298   QString fileName = HOMARD_QT_COMMUN::PushNomFichier(false);
299   if (fileName.isEmpty()) fileName = fileName0 ;
300   LEFieldFile->setText(fileName);
301   raise();
302 }
303 // ------------------------------------------------------------------------
304 void MonCreateIteration::SetTSNo()
305 // ------------------------------------------------------------------------
306 // Si on ne tient pas compte du pas de temps, on declare que le pas de temps
307 // vaut -1, valeur par defaut de med
308 {
309   Rank->setVisible(0);
310   SpinBox_Rank->setVisible(0);
311   SpinBox_Rank->setValue(-1);
312
313   TimeStep->setVisible(0);
314   SpinBox_TimeStep->setVisible(0);
315   SpinBox_TimeStep->setValue(-1);
316
317   adjustSize();
318 }
319 // ------------------------------------------------------------------------
320 void MonCreateIteration::SetTSLast()
321 // ------------------------------------------------------------------------
322 // Si on choisit le dernier instant, on declare que le pas de temps vaut -2
323 {
324   Rank->setVisible(0);
325   SpinBox_Rank->setVisible(0);
326   SpinBox_Rank->setValue(-2);
327
328   TimeStep->setVisible(0);
329   SpinBox_TimeStep->setVisible(0);
330   SpinBox_TimeStep->setValue(-2);
331
332   adjustSize();
333 }
334 // ------------------------------------------------------------------------
335 void MonCreateIteration::SetTSChosen()
336 // ------------------------------------------------------------------------
337 // Si choisit un instant, on prepositionne a 0
338 {
339   Rank->setVisible(1);
340   SpinBox_Rank->setVisible(1);
341   SpinBox_Rank->setValue(0);
342
343   TimeStep->setVisible(1);
344   SpinBox_TimeStep->setVisible(1);
345   SpinBox_TimeStep->setValue(0);
346
347   adjustSize();
348 }
349