Salome HOME
Suivi de frontières 2D sur des cônes (suite)
[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                                 QObject::tr(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
184   return true;
185 }
186
187 // ------------------------------------------------------------------------
188 void MonCreateIteration::PushOnOK()
189 // ------------------------------------------------------------------------
190 {
191      bool bOK = PushOnApply();
192      if ( bOK )  this->close();
193 }
194
195 // ------------------------------------------------------------------------
196 void MonCreateIteration::PushOnHelp()
197 // ------------------------------------------------------------------------
198 {
199   HOMARD_UTILS::PushOnHelp(QString("gui_create_iteration.html"));
200 }
201
202 // ------------------------------------------------------------------------
203 void MonCreateIteration::SetIterParentName()
204 // ------------------------------------------------------------------------
205 {
206   if (_IterParentName == QString("")) {
207     _IterParentName=HOMARD_QT_COMMUN::SelectionArbreEtude(QString("IterationHomard"), 1);
208     if (_IterParentName == QString("")) { raise();return;};
209   }
210   _CaseName=HOMARD_QT_COMMUN::SelectionCasEtude();
211   HOMARD::HOMARD_Iteration_var aIterParent = _myHomardGen->GetIteration(_IterParentName.toStdString().c_str()) ;
212   QString MeshName = aIterParent->GetMeshName();
213
214   LEMeshName_n->setText(MeshName);
215   LEMeshName_n->setReadOnly(1);
216   LEMeshName_np1->setText(MeshName);
217
218   LEIterationParentName->setText(_IterParentName);
219 }
220
221 // -------------------------------------------------
222 void MonCreateIteration::SetNewIterationName()
223 // --------------------------------------------------
224 {
225 // Recherche d'un nom par defaut qui n'existe pas encore
226
227   HOMARD::listeIterations_var  myIters=_myHomardGen->GetAllIterationsName();
228   int num = 0;//
229   QString aIterationName="";
230   while (aIterationName=="" )
231   {
232     aIterationName.setNum(num+1) ;
233     aIterationName.insert(0, QString("Iter_"));
234     for ( int i=0; i< myIters->length(); i++)
235     {
236       if ( aIterationName ==  QString((myIters)[i]))
237       {
238           num=num+1;
239           aIterationName="";
240           break;
241       }
242    }
243   }
244   LEIterationName->setText(aIterationName);
245 }
246
247
248 // ------------------------------------------------------------------------
249 void MonCreateIteration::PushHypoEdit()
250 // ------------------------------------------------------------------------
251 {
252   if (CBHypothese->currentText() == QString(""))  return;
253   if (_IterParentName == QString(""))
254   {
255     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
256                               QObject::tr("HOM_ITER_STARTING_POINT") );
257     raise();
258     return;
259   }
260   QString aFieldFile=LEFieldFile->text().trimmed();
261   MonEditHypothesis *HypoDlg = new MonEditHypothesis(this,TRUE, HOMARD::HOMARD_Gen::_duplicate(_myHomardGen),CBHypothese->currentText(), _CaseName, aFieldFile) ;
262   HypoDlg->show();
263 }
264
265 // ------------------------------------------------------------------------
266 void MonCreateIteration::addHypothese(QString newHypothese)
267 // ------------------------------------------------------------------------
268 {
269   CBHypothese->insertItem(0,newHypothese);
270   CBHypothese->setCurrentIndex(0);
271 }
272 // ------------------------------------------------------------------------
273 void MonCreateIteration::PushHypoNew()
274 // ------------------------------------------------------------------------
275 {
276   if (_IterParentName == QString(""))
277   {
278     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
279                               QObject::tr("HOM_ITER_STARTING_POINT") );
280     raise();
281     return;
282   }
283   if ( _CaseName == QString(""))
284   {
285          HOMARD::HOMARD_Iteration_var aIterParent = _myHomardGen->GetIteration(_IterParentName.toStdString().c_str()) ;
286         _CaseName = aIterParent->GetCaseName();
287   }
288   QString aFieldFile=LEFieldFile->text().trimmed();
289   MonCreateHypothesis *HypoDlg = new MonCreateHypothesis(this,TRUE,HOMARD::HOMARD_Gen::_duplicate(_myHomardGen),QString(""),_CaseName, aFieldFile) ;
290   HypoDlg->show();
291 }
292
293 // ------------------------------------------------------------------------
294 void MonCreateIteration::SetFieldFile()
295 // ------------------------------------------------------------------------
296
297 {
298   QString fileName0 = LEFieldFile->text().trimmed();
299   QString fileName = HOMARD_QT_COMMUN::PushNomFichier(false);
300   if (fileName.isEmpty()) fileName = fileName0 ;
301   LEFieldFile->setText(fileName);
302   raise();
303 }
304 // ------------------------------------------------------------------------
305 void MonCreateIteration::SetTSNo()
306 // ------------------------------------------------------------------------
307 // Si on ne tient pas compte du pas de temps, on declare que le pas de temps
308 // vaut -1, valeur par defaut de med
309 {
310   Rank->setVisible(0);
311   SpinBox_Rank->setVisible(0);
312   SpinBox_Rank->setValue(-1);
313
314   TimeStep->setVisible(0);
315   SpinBox_TimeStep->setVisible(0);
316   SpinBox_TimeStep->setValue(-1);
317
318   adjustSize();
319 }
320 // ------------------------------------------------------------------------
321 void MonCreateIteration::SetTSLast()
322 // ------------------------------------------------------------------------
323 // Si on choisit le dernier instant, on declare que le pas de temps vaut -2
324 {
325   Rank->setVisible(0);
326   SpinBox_Rank->setVisible(0);
327   SpinBox_Rank->setValue(-2);
328
329   TimeStep->setVisible(0);
330   SpinBox_TimeStep->setVisible(0);
331   SpinBox_TimeStep->setValue(-2);
332
333   adjustSize();
334 }
335 // ------------------------------------------------------------------------
336 void MonCreateIteration::SetTSChosen()
337 // ------------------------------------------------------------------------
338 // Si choisit un instant, on prepositionne a 0
339 {
340   Rank->setVisible(1);
341   SpinBox_Rank->setVisible(1);
342   SpinBox_Rank->setValue(0);
343
344   TimeStep->setVisible(1);
345   SpinBox_TimeStep->setVisible(1);
346   SpinBox_TimeStep->setValue(0);
347
348   adjustSize();
349 }
350