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