3 #include "MonCreateIteration.h"
4 #include "MonCreateHypothesis.h"
5 #include "MonEditHypothesis.h"
10 #include "SalomeApp_Tools.h"
11 #include "HOMARDGUI_Utils.h"
12 #include "HomardQtCommun.h"
13 #include <utilities.h>
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
27 _IterParentName(IterParentName),
30 MESSAGE("Constructeur");
31 _myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen);
36 SetNewIterationName();
38 if (_IterParentName != QString(""))
39 { SetIterParentName(); }
41 {setModal(false); /* permet selection de l iteration dans l arbre d etude */}
45 // ------------------------------------------------------------------------
46 MonCreateIteration::~MonCreateIteration()
47 // ------------------------------------------------------------------------
49 // no need to delete child widgets, Qt does it all for us
51 // ------------------------------------------------------------------------
52 void MonCreateIteration::InitConnect()
53 // ------------------------------------------------------------------------
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()));
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() ) );
68 // ------------------------------------------------------------------------
69 void MonCreateIteration::GetHypotheses()
70 // ------------------------------------------------------------------------
72 HOMARD::listeHypotheses_var mesHypotheses = _myHomardGen->GetAllHypotheses();
73 for (int i=0; i<mesHypotheses->length(); i++)
75 CBHypothese->addItem(QString(mesHypotheses[i]));
79 // ------------------------------------------------------------------------
80 bool MonCreateIteration::PushOnApply()
81 // ------------------------------------------------------------------------
82 // Appele lorsque l'un des boutons Ok ou Apply est presse
84 MESSAGE("PushOnApply");
86 QString aIterationName = LEIterationName->text().trimmed();
87 if ( aIterationName == QString (""))
89 QMessageBox::information( 0, "Error",
90 QString(" Nommer l iteration "),
91 QMessageBox::Ok + QMessageBox::Default );
95 if ( _IterParentName == QString (""))
97 QMessageBox::information( 0, "Error",
98 QString(" Donner le point de depart "),
99 QMessageBox::Ok + QMessageBox::Default );
102 QString aMeshName_np1=LEMeshName_np1->text().trimmed();
103 if (aMeshName_np1 == "" )
105 QMessageBox::information( 0, "Error",
106 QString(" Donner le nom du maillage final."),
107 QMessageBox::Ok + QMessageBox::Default );
110 QString monHypoName=CBHypothese->currentText();
111 if (monHypoName == "" )
113 QMessageBox::information( 0, "Error",
114 QString(" Choisir une hypothese "),
115 QMessageBox::Ok + QMessageBox::Default );
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("") )
123 QMessageBox::information( 0, "Error",
124 QString("Avec cette hypothese, il faut fournir le fichier du champ."),
125 QMessageBox::Ok + QMessageBox::Default );
129 MESSAGE ("aMeshName_np1.toStdString " << aMeshName_np1.toStdString());
130 MESSAGE ("_CaseName.toStdString " << _CaseName.toStdString() );
131 MESSAGE ("_IterParentName.toStdString " << _IterParentName.toStdString() );
133 // Creation de l'objet CORBA si ce n'est pas deja fait sous le meme nom
134 if (_IterationName != aIterationName)
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()));
144 catch( SALOME::SALOME_Exception& S_ex )
146 QMessageBox::information( 0, "Error",
147 QString(CORBA::string_dup(S_ex.details.text)),
148 QMessageBox::Ok + QMessageBox::Default );
153 // Mise en place des attributs
154 const char* IterName = aIter->GetName() ;
155 std::cerr << IterName << std::endl;
157 if ( LEFieldFile->text().trimmed() != QString(""))
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);
165 _myHomardGen->AssociateIterHypo (IterName, monHypoName.toStdString().c_str());
166 aIter->SetMeshName(CORBA::string_dup(aMeshName_np1.toStdString().c_str()));
168 HOMARD_UTILS::updateObjBrowser();
172 // ------------------------------------------------------------------------
173 void MonCreateIteration::PushOnOK()
174 // ------------------------------------------------------------------------
176 bool bOK = PushOnApply();
177 if ( bOK ) this->close();
180 // ------------------------------------------------------------------------
181 void MonCreateIteration::PushOnHelp()
182 // ------------------------------------------------------------------------
184 HOMARD_UTILS::PushOnHelp(QString("gui_create_iteration.html"));
187 // ------------------------------------------------------------------------
188 void MonCreateIteration::SetIterParentName()
189 // ------------------------------------------------------------------------
191 if (_IterParentName == QString("")) {
192 _IterParentName=HOMARD_QT_COMMUN::SelectionArbreEtude(QString("IterationHomard"), 1);
193 if (_IterParentName == QString("")) { raise();return;};
195 _CaseName=HOMARD_QT_COMMUN::SelectionCasEtude();
196 HOMARD::HOMARD_Iteration_var aIterParent = _myHomardGen->GetIteration(_IterParentName.toStdString().c_str()) ;
197 QString MeshName = aIterParent->GetMeshName();
199 LEMeshName_n->setText(MeshName);
200 LEMeshName_n->setReadOnly(1);
201 LEMeshName_np1->setText(MeshName);
203 LEIterationParentName->setText(_IterParentName);
206 // -------------------------------------------------
207 void MonCreateIteration::SetNewIterationName()
208 // --------------------------------------------------
210 // Recherche d'un nom par defaut qui n'existe pas encore
212 HOMARD::listeIterations_var myIters=_myHomardGen->GetAllIterations();
214 QString aIterationName="";
215 while (aIterationName=="" )
217 aIterationName.setNum(num+1) ;
218 aIterationName.insert(0, QString("Iter_"));
219 for ( int i=0; i< myIters->length(); i++)
221 if ( aIterationName == QString((myIters)[i]))
229 LEIterationName->setText(aIterationName);
233 // ------------------------------------------------------------------------
234 void MonCreateIteration::PushHypoEdit()
235 // ------------------------------------------------------------------------
237 if (CBHypothese->currentText() == QString("")) return;
238 if (_IterParentName == QString(""))
240 QMessageBox::information( 0, "Error",
241 QString("The previous iteration must be given."),
242 QMessageBox::Ok + QMessageBox::Default );
246 QString aFieldFile=LEFieldFile->text().trimmed();
247 MonEditHypothesis *HypoDlg = new MonEditHypothesis(this,TRUE, HOMARD::HOMARD_Gen::_duplicate(_myHomardGen),CBHypothese->currentText(), _CaseName, aFieldFile) ;
251 // ------------------------------------------------------------------------
252 void MonCreateIteration::addHypothese(QString newHypothese)
253 // ------------------------------------------------------------------------
255 CBHypothese->insertItem(0,newHypothese);
256 CBHypothese->setCurrentIndex(0);
258 // ------------------------------------------------------------------------
259 void MonCreateIteration::PushHypoNew()
260 // ------------------------------------------------------------------------
262 if (_IterParentName == QString(""))
264 QMessageBox::information( 0, "Error",
265 QString("The previous iteration must be given."),
266 QMessageBox::Ok + QMessageBox::Default );
270 if ( _CaseName == QString(""))
272 _CaseName = _myHomardGen->GetCaseName(CORBA::string_dup(_IterParentName.toStdString().c_str()));
274 QString aFieldFile=LEFieldFile->text().trimmed();
275 MonCreateHypothesis *HypoDlg = new MonCreateHypothesis(this,TRUE,HOMARD::HOMARD_Gen::_duplicate(_myHomardGen),QString(""),_CaseName, aFieldFile) ;
279 // ------------------------------------------------------------------------
280 void MonCreateIteration::SetFieldFile()
281 // ------------------------------------------------------------------------
284 QString fileName0 = LEFieldFile->text().trimmed();
285 QString fileName = HOMARD_QT_COMMUN::PushNomFichier(false);
286 if (fileName.isEmpty()) fileName = fileName0 ;
287 LEFieldFile->setText(fileName);
290 // ------------------------------------------------------------------------
291 void MonCreateIteration::SetTSNo()
292 // ------------------------------------------------------------------------
293 // Par defaut, on declare que le pas de temps vaut -1
296 SpinBox_Rank->setVisible(0);
297 TimeStep->setVisible(0);
298 SpinBox_TimeStep->setVisible(0);
299 SpinBox_TimeStep->setValue(-1);
302 // ------------------------------------------------------------------------
303 void MonCreateIteration::SetTSLast()
304 // ------------------------------------------------------------------------
305 // Par defaut, on declare que le pas de temps vaut -2
308 SpinBox_Rank->setVisible(0);
309 TimeStep->setVisible(0);
310 SpinBox_TimeStep->setVisible(0);
311 SpinBox_TimeStep->setValue(-2);
314 // ------------------------------------------------------------------------
315 void MonCreateIteration::SetTSChosen()
316 // ------------------------------------------------------------------------
319 SpinBox_Rank->setVisible(1);
320 TimeStep->setVisible(1);
321 SpinBox_TimeStep->setVisible(1);
322 SpinBox_TimeStep->setValue(1);