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("MonCreateIteration::PushOnApply");
86 QString aIterationName = LEIterationName->text().trimmed();
87 if ( aIterationName == QString (""))
89 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
90 QObject::tr("HOM_ITER_NAME") );
94 if ( _IterParentName == QString (""))
96 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
97 QObject::tr("HOM_ITER_STARTING_POINT") );
100 QString aMeshName_np1=LEMeshName_np1->text().trimmed();
101 if (aMeshName_np1 == "" )
103 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
104 QObject::tr("HOM_ITER_MESH") );
107 QString monHypoName=CBHypothese->currentText();
108 if (monHypoName == "" )
110 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
111 QObject::tr("HOM_ITER_HYPO") );
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("") )
119 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
120 QObject::tr("HOM_ITER_FIELD_FILE") );
124 MESSAGE ("aMeshName_np1.toStdString " << aMeshName_np1.toStdString());
125 MESSAGE ("_CaseName.toStdString " << _CaseName.toStdString() );
126 MESSAGE ("_IterParentName.toStdString " << _IterParentName.toStdString() );
128 // Creation de l'objet CORBA si ce n'est pas deja fait sous le meme nom
129 if (_IterationName != aIterationName)
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()));
139 catch( SALOME::SALOME_Exception& S_ex )
141 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
142 QString(CORBA::string_dup(S_ex.details.text)) );
147 // Mise en place des attributs
148 const char* IterName = aIter->GetName() ;
149 std::cerr << IterName << std::endl;
151 if ( LEFieldFile->text().trimmed() != QString(""))
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);
159 _myHomardGen->AssociateIterHypo (IterName, monHypoName.toStdString().c_str());
160 aIter->SetMeshName(CORBA::string_dup(aMeshName_np1.toStdString().c_str()));
162 HOMARD_UTILS::updateObjBrowser();
166 // ------------------------------------------------------------------------
167 void MonCreateIteration::PushOnOK()
168 // ------------------------------------------------------------------------
170 bool bOK = PushOnApply();
171 if ( bOK ) this->close();
174 // ------------------------------------------------------------------------
175 void MonCreateIteration::PushOnHelp()
176 // ------------------------------------------------------------------------
178 HOMARD_UTILS::PushOnHelp(QString("gui_create_iteration.html"));
181 // ------------------------------------------------------------------------
182 void MonCreateIteration::SetIterParentName()
183 // ------------------------------------------------------------------------
185 if (_IterParentName == QString("")) {
186 _IterParentName=HOMARD_QT_COMMUN::SelectionArbreEtude(QString("IterationHomard"), 1);
187 if (_IterParentName == QString("")) { raise();return;};
189 _CaseName=HOMARD_QT_COMMUN::SelectionCasEtude();
190 HOMARD::HOMARD_Iteration_var aIterParent = _myHomardGen->GetIteration(_IterParentName.toStdString().c_str()) ;
191 QString MeshName = aIterParent->GetMeshName();
193 LEMeshName_n->setText(MeshName);
194 LEMeshName_n->setReadOnly(1);
195 LEMeshName_np1->setText(MeshName);
197 LEIterationParentName->setText(_IterParentName);
200 // -------------------------------------------------
201 void MonCreateIteration::SetNewIterationName()
202 // --------------------------------------------------
204 // Recherche d'un nom par defaut qui n'existe pas encore
206 HOMARD::listeIterations_var myIters=_myHomardGen->GetAllIterations();
208 QString aIterationName="";
209 while (aIterationName=="" )
211 aIterationName.setNum(num+1) ;
212 aIterationName.insert(0, QString("Iter_"));
213 for ( int i=0; i< myIters->length(); i++)
215 if ( aIterationName == QString((myIters)[i]))
223 LEIterationName->setText(aIterationName);
227 // ------------------------------------------------------------------------
228 void MonCreateIteration::PushHypoEdit()
229 // ------------------------------------------------------------------------
231 if (CBHypothese->currentText() == QString("")) return;
232 if (_IterParentName == QString(""))
234 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
235 QObject::tr("HOM_ITER_STARTING_POINT") );
239 QString aFieldFile=LEFieldFile->text().trimmed();
240 MonEditHypothesis *HypoDlg = new MonEditHypothesis(this,TRUE, HOMARD::HOMARD_Gen::_duplicate(_myHomardGen),CBHypothese->currentText(), _CaseName, aFieldFile) ;
244 // ------------------------------------------------------------------------
245 void MonCreateIteration::addHypothese(QString newHypothese)
246 // ------------------------------------------------------------------------
248 CBHypothese->insertItem(0,newHypothese);
249 CBHypothese->setCurrentIndex(0);
251 // ------------------------------------------------------------------------
252 void MonCreateIteration::PushHypoNew()
253 // ------------------------------------------------------------------------
255 if (_IterParentName == QString(""))
257 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
258 QObject::tr("HOM_ITER_STARTING_POINT") );
262 if ( _CaseName == QString(""))
264 _CaseName = _myHomardGen->GetCaseName(CORBA::string_dup(_IterParentName.toStdString().c_str()));
266 QString aFieldFile=LEFieldFile->text().trimmed();
267 MonCreateHypothesis *HypoDlg = new MonCreateHypothesis(this,TRUE,HOMARD::HOMARD_Gen::_duplicate(_myHomardGen),QString(""),_CaseName, aFieldFile) ;
271 // ------------------------------------------------------------------------
272 void MonCreateIteration::SetFieldFile()
273 // ------------------------------------------------------------------------
276 QString fileName0 = LEFieldFile->text().trimmed();
277 QString fileName = HOMARD_QT_COMMUN::PushNomFichier(false);
278 if (fileName.isEmpty()) fileName = fileName0 ;
279 LEFieldFile->setText(fileName);
282 // ------------------------------------------------------------------------
283 void MonCreateIteration::SetTSNo()
284 // ------------------------------------------------------------------------
285 // Par defaut, on declare que le pas de temps vaut -1
288 SpinBox_Rank->setVisible(0);
289 TimeStep->setVisible(0);
290 SpinBox_TimeStep->setVisible(0);
291 SpinBox_TimeStep->setValue(-1);
294 // ------------------------------------------------------------------------
295 void MonCreateIteration::SetTSLast()
296 // ------------------------------------------------------------------------
297 // Par defaut, on declare que le pas de temps vaut -2
300 SpinBox_Rank->setVisible(0);
301 TimeStep->setVisible(0);
302 SpinBox_TimeStep->setVisible(0);
303 SpinBox_TimeStep->setValue(-2);
306 // ------------------------------------------------------------------------
307 void MonCreateIteration::SetTSChosen()
308 // ------------------------------------------------------------------------
311 SpinBox_Rank->setVisible(1);
312 TimeStep->setVisible(1);
313 SpinBox_TimeStep->setVisible(1);
314 SpinBox_TimeStep->setValue(1);