]> SALOME platform Git repositories - modules/homard.git/blob - src/HOMARDGUI/MonCreateIteration.cxx
Salome HOME
Fix problems of 'make distcheck'
[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("MonCreateIteration::PushOnApply");
85 //
86   QString aIterationName = LEIterationName->text().trimmed();
87   if ( aIterationName == QString (""))
88   {
89     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
90                               QObject::tr("HOM_ITER_NAME") );
91     return false;
92   }
93
94   if ( _IterParentName == QString (""))
95   {
96     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
97                               QObject::tr("HOM_ITER_STARTING_POINT") );
98     return false;
99   }
100   QString aMeshName_np1=LEMeshName_np1->text().trimmed();
101   if (aMeshName_np1 == "" )
102   {
103     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
104                               QObject::tr("HOM_ITER_MESH") );
105     return false;
106   }
107   QString monHypoName=CBHypothese->currentText();
108   if (monHypoName == "" )
109   {
110     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
111                               QObject::tr("HOM_ITER_HYPO") );
112     return false;
113   }
114   HOMARD::HOMARD_Hypothesis_var _myHypothesis = _myHomardGen->GetHypothesis(monHypoName.toStdString().c_str());
115   HOMARD::listeTypes_var ListTypes (_myHypothesis->GetAdapRefinUnRef());
116   int TypeAdap = ListTypes[0];
117   if ( TypeAdap == 1 and LEFieldFile->text().trimmed() == QString("") )
118   {
119     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
120                               QObject::tr("HOM_ITER_FIELD_FILE") );
121     return false;
122   }
123
124   MESSAGE ("aMeshName_np1.toStdString " << aMeshName_np1.toStdString());
125   MESSAGE ("_CaseName.toStdString " << _CaseName.toStdString() );
126   MESSAGE ("_IterParentName.toStdString " << _IterParentName.toStdString() );
127
128 // Creation de l'objet CORBA si ce n'est pas deja fait sous le meme nom
129   if (_IterationName != aIterationName)
130   {
131     try
132     {
133       _IterationName = aIterationName;
134       std::cerr << _IterationName.toStdString() << std::endl;
135       aIter = _myHomardGen->CreateIteration( \
136                CORBA::string_dup(_IterationName.toStdString().c_str()),
137                CORBA::string_dup(_IterParentName.toStdString().c_str()));
138     }
139     catch( SALOME::SALOME_Exception& S_ex )
140     {
141       QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
142                                 QString(CORBA::string_dup(S_ex.details.text)) );
143        return false;
144     }
145   }
146
147 // Mise en place des attributs
148   const char* IterName = aIter->GetName() ;
149   std::cerr << IterName << std::endl;
150
151   if ( LEFieldFile->text().trimmed() != QString(""))
152   {
153     QString FieldFile=LEFieldFile->text().trimmed();
154     int rank = SpinBox_Rank->value();
155     int step = SpinBox_TimeStep->value();
156     aIter->SetFieldFile(CORBA::string_dup(FieldFile.toStdString().c_str()));
157     aIter->SetTimeStepRank(rank,step);
158   }
159   _myHomardGen->AssociateIterHypo (IterName, monHypoName.toStdString().c_str());
160   aIter->SetMeshName(CORBA::string_dup(aMeshName_np1.toStdString().c_str()));
161
162   HOMARD_UTILS::updateObjBrowser();
163   return true;
164 }
165
166 // ------------------------------------------------------------------------
167 void MonCreateIteration::PushOnOK()
168 // ------------------------------------------------------------------------
169 {
170      bool bOK = PushOnApply();
171      if ( bOK )  this->close();
172 }
173
174 // ------------------------------------------------------------------------
175 void MonCreateIteration::PushOnHelp()
176 // ------------------------------------------------------------------------
177 {
178   HOMARD_UTILS::PushOnHelp(QString("gui_create_iteration.html"));
179 }
180
181 // ------------------------------------------------------------------------
182 void MonCreateIteration::SetIterParentName()
183 // ------------------------------------------------------------------------
184 {
185   if (_IterParentName == QString("")) {
186     _IterParentName=HOMARD_QT_COMMUN::SelectionArbreEtude(QString("IterationHomard"), 1);
187     if (_IterParentName == QString("")) { raise();return;};
188   }
189   _CaseName=HOMARD_QT_COMMUN::SelectionCasEtude();
190   HOMARD::HOMARD_Iteration_var aIterParent = _myHomardGen->GetIteration(_IterParentName.toStdString().c_str()) ;
191   QString MeshName = aIterParent->GetMeshName();
192
193   LEMeshName_n->setText(MeshName);
194   LEMeshName_n->setReadOnly(1);
195   LEMeshName_np1->setText(MeshName);
196
197   LEIterationParentName->setText(_IterParentName);
198 }
199
200 // -------------------------------------------------
201 void MonCreateIteration::SetNewIterationName()
202 // --------------------------------------------------
203 {
204 // Recherche d'un nom par defaut qui n'existe pas encore
205
206   HOMARD::listeIterations_var  myIters=_myHomardGen->GetAllIterations();
207   int num = 0;//
208   QString aIterationName="";
209   while (aIterationName=="" )
210   {
211     aIterationName.setNum(num+1) ;
212     aIterationName.insert(0, QString("Iter_"));
213     for ( int i=0; i< myIters->length(); i++)
214     {
215       if ( aIterationName ==  QString((myIters)[i]))
216       {
217           num=num+1;
218           aIterationName="";
219           break;
220       }
221    }
222   }
223   LEIterationName->setText(aIterationName);
224 }
225
226
227 // ------------------------------------------------------------------------
228 void MonCreateIteration::PushHypoEdit()
229 // ------------------------------------------------------------------------
230 {
231   if (CBHypothese->currentText() == QString(""))  return;
232   if (_IterParentName == QString(""))
233   {
234     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
235                               QObject::tr("HOM_ITER_STARTING_POINT") );
236     raise();
237     return;
238   }
239   QString aFieldFile=LEFieldFile->text().trimmed();
240   MonEditHypothesis *HypoDlg = new MonEditHypothesis(this,TRUE, HOMARD::HOMARD_Gen::_duplicate(_myHomardGen),CBHypothese->currentText(), _CaseName, aFieldFile) ;
241   HypoDlg->show();
242 }
243
244 // ------------------------------------------------------------------------
245 void MonCreateIteration::addHypothese(QString newHypothese)
246 // ------------------------------------------------------------------------
247 {
248   CBHypothese->insertItem(0,newHypothese);
249   CBHypothese->setCurrentIndex(0);
250 }
251 // ------------------------------------------------------------------------
252 void MonCreateIteration::PushHypoNew()
253 // ------------------------------------------------------------------------
254 {
255   if (_IterParentName == QString(""))
256   {
257     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
258                               QObject::tr("HOM_ITER_STARTING_POINT") );
259     raise();
260     return;
261   }
262   if ( _CaseName == QString(""))
263   {
264         _CaseName = _myHomardGen->GetCaseName(CORBA::string_dup(_IterParentName.toStdString().c_str()));
265   }
266   QString aFieldFile=LEFieldFile->text().trimmed();
267   MonCreateHypothesis *HypoDlg = new MonCreateHypothesis(this,TRUE,HOMARD::HOMARD_Gen::_duplicate(_myHomardGen),QString(""),_CaseName, aFieldFile) ;
268   HypoDlg->show();
269 }
270
271 // ------------------------------------------------------------------------
272 void MonCreateIteration::SetFieldFile()
273 // ------------------------------------------------------------------------
274
275 {
276   QString fileName0 = LEFieldFile->text().trimmed();
277   QString fileName = HOMARD_QT_COMMUN::PushNomFichier(false);
278   if (fileName.isEmpty()) fileName = fileName0 ;
279   LEFieldFile->setText(fileName);
280   raise();
281 }
282 // ------------------------------------------------------------------------
283 void MonCreateIteration::SetTSNo()
284 // ------------------------------------------------------------------------
285 // Par defaut, on declare que le pas de temps vaut -1
286 {
287   Rank->setVisible(0);
288   SpinBox_Rank->setVisible(0);
289   TimeStep->setVisible(0);
290   SpinBox_TimeStep->setVisible(0);
291   SpinBox_TimeStep->setValue(-1);
292   adjustSize();
293 }
294 // ------------------------------------------------------------------------
295 void MonCreateIteration::SetTSLast()
296 // ------------------------------------------------------------------------
297 // Par defaut, on declare que le pas de temps vaut -2
298 {
299   Rank->setVisible(0);
300   SpinBox_Rank->setVisible(0);
301   TimeStep->setVisible(0);
302   SpinBox_TimeStep->setVisible(0);
303   SpinBox_TimeStep->setValue(-2);
304   adjustSize();
305 }
306 // ------------------------------------------------------------------------
307 void MonCreateIteration::SetTSChosen()
308 // ------------------------------------------------------------------------
309 {
310   Rank->setVisible(1);
311   SpinBox_Rank->setVisible(1);
312   TimeStep->setVisible(1);
313   SpinBox_TimeStep->setVisible(1);
314   SpinBox_TimeStep->setValue(1);
315   adjustSize();
316 }
317