1 // Copyright (C) 2011-2012 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "MonCreateIteration.h"
23 #include "MonCreateHypothesis.h"
24 #include "MonEditHypothesis.h"
26 #include <QFileDialog>
27 #include <QMessageBox>
29 #include "SalomeApp_Tools.h"
30 #include "HOMARDGUI_Utils.h"
31 #include "HomardQtCommun.h"
32 #include <utilities.h>
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
46 _IterParentName(IterParentName),
49 MESSAGE("Constructeur");
50 _myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen);
55 SetNewIterationName();
57 if (_IterParentName != QString(""))
58 { SetIterParentName(); }
60 {setModal(false); /* permet selection de l iteration dans l arbre d etude */}
64 // ------------------------------------------------------------------------
65 MonCreateIteration::~MonCreateIteration()
66 // ------------------------------------------------------------------------
68 // no need to delete child widgets, Qt does it all for us
70 // ------------------------------------------------------------------------
71 void MonCreateIteration::InitConnect()
72 // ------------------------------------------------------------------------
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()));
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() ) );
87 // ------------------------------------------------------------------------
88 void MonCreateIteration::GetHypotheses()
89 // ------------------------------------------------------------------------
91 HOMARD::listeHypotheses_var mesHypotheses = _myHomardGen->GetAllHypothesesName();
92 for (int i=0; i<mesHypotheses->length(); i++)
94 CBHypothese->addItem(QString(mesHypotheses[i]));
98 // ------------------------------------------------------------------------
99 bool MonCreateIteration::PushOnApply()
100 // ------------------------------------------------------------------------
101 // Appele lorsque l'un des boutons Ok ou Apply est presse
103 MESSAGE("MonCreateIteration::PushOnApply");
105 QString aIterationName = LEIterationName->text().trimmed();
106 if ( aIterationName == QString (""))
108 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
109 QObject::tr("HOM_ITER_NAME") );
113 if ( _IterParentName == QString (""))
115 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
116 QObject::tr("HOM_ITER_STARTING_POINT") );
119 QString aMeshName_np1=LEMeshName_np1->text().trimmed();
120 if (aMeshName_np1 == "" )
122 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
123 QObject::tr("HOM_ITER_MESH") );
126 QString monHypoName=CBHypothese->currentText();
127 if (monHypoName == "" )
129 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
130 QObject::tr("HOM_ITER_HYPO") );
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("") )
138 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
139 QObject::tr("HOM_ITER_FIELD_FILE") );
143 MESSAGE ("aMeshName_np1.toStdString " << aMeshName_np1.toStdString());
144 MESSAGE ("_CaseName.toStdString " << _CaseName.toStdString() );
145 MESSAGE ("_IterParentName.toStdString " << _IterParentName.toStdString() );
147 // Creation de l'objet CORBA si ce n'est pas deja fait sous le meme nom
148 if (_IterationName != aIterationName)
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()));
158 catch( SALOME::SALOME_Exception& S_ex )
160 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
161 QString(CORBA::string_dup(S_ex.details.text)) );
166 // Mise en place des attributs
167 const char* IterName = aIter->GetName() ;
168 std::cerr << IterName << std::endl;
170 if ( LEFieldFile->text().trimmed() != QString(""))
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); }
179 _myHomardGen->AssociateIterHypo (IterName, monHypoName.toStdString().c_str());
180 aIter->SetMeshName(CORBA::string_dup(aMeshName_np1.toStdString().c_str()));
182 HOMARD_UTILS::updateObjBrowser();
186 // ------------------------------------------------------------------------
187 void MonCreateIteration::PushOnOK()
188 // ------------------------------------------------------------------------
190 bool bOK = PushOnApply();
191 if ( bOK ) this->close();
194 // ------------------------------------------------------------------------
195 void MonCreateIteration::PushOnHelp()
196 // ------------------------------------------------------------------------
198 HOMARD_UTILS::PushOnHelp(QString("gui_create_iteration.html"));
201 // ------------------------------------------------------------------------
202 void MonCreateIteration::SetIterParentName()
203 // ------------------------------------------------------------------------
205 if (_IterParentName == QString("")) {
206 _IterParentName=HOMARD_QT_COMMUN::SelectionArbreEtude(QString("IterationHomard"), 1);
207 if (_IterParentName == QString("")) { raise();return;};
209 _CaseName=HOMARD_QT_COMMUN::SelectionCasEtude();
210 HOMARD::HOMARD_Iteration_var aIterParent = _myHomardGen->GetIteration(_IterParentName.toStdString().c_str()) ;
211 QString MeshName = aIterParent->GetMeshName();
213 LEMeshName_n->setText(MeshName);
214 LEMeshName_n->setReadOnly(1);
215 LEMeshName_np1->setText(MeshName);
217 LEIterationParentName->setText(_IterParentName);
220 // -------------------------------------------------
221 void MonCreateIteration::SetNewIterationName()
222 // --------------------------------------------------
224 // Recherche d'un nom par defaut qui n'existe pas encore
226 HOMARD::listeIterations_var myIters=_myHomardGen->GetAllIterationsName();
228 QString aIterationName="";
229 while (aIterationName=="" )
231 aIterationName.setNum(num+1) ;
232 aIterationName.insert(0, QString("Iter_"));
233 for ( int i=0; i< myIters->length(); i++)
235 if ( aIterationName == QString((myIters)[i]))
243 LEIterationName->setText(aIterationName);
247 // ------------------------------------------------------------------------
248 void MonCreateIteration::PushHypoEdit()
249 // ------------------------------------------------------------------------
251 if (CBHypothese->currentText() == QString("")) return;
252 if (_IterParentName == QString(""))
254 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
255 QObject::tr("HOM_ITER_STARTING_POINT") );
259 QString aFieldFile=LEFieldFile->text().trimmed();
260 MonEditHypothesis *HypoDlg = new MonEditHypothesis(this,TRUE, HOMARD::HOMARD_Gen::_duplicate(_myHomardGen),CBHypothese->currentText(), _CaseName, aFieldFile) ;
264 // ------------------------------------------------------------------------
265 void MonCreateIteration::addHypothese(QString newHypothese)
266 // ------------------------------------------------------------------------
268 CBHypothese->insertItem(0,newHypothese);
269 CBHypothese->setCurrentIndex(0);
271 // ------------------------------------------------------------------------
272 void MonCreateIteration::PushHypoNew()
273 // ------------------------------------------------------------------------
275 if (_IterParentName == QString(""))
277 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
278 QObject::tr("HOM_ITER_STARTING_POINT") );
282 if ( _CaseName == QString(""))
284 HOMARD::HOMARD_Iteration_var aIterParent = _myHomardGen->GetIteration(_IterParentName.toStdString().c_str()) ;
285 _CaseName = aIterParent->GetCaseName();
287 QString aFieldFile=LEFieldFile->text().trimmed();
288 MonCreateHypothesis *HypoDlg = new MonCreateHypothesis(this,TRUE,HOMARD::HOMARD_Gen::_duplicate(_myHomardGen),QString(""),_CaseName, aFieldFile) ;
292 // ------------------------------------------------------------------------
293 void MonCreateIteration::SetFieldFile()
294 // ------------------------------------------------------------------------
297 QString fileName0 = LEFieldFile->text().trimmed();
298 QString fileName = HOMARD_QT_COMMUN::PushNomFichier(false);
299 if (fileName.isEmpty()) fileName = fileName0 ;
300 LEFieldFile->setText(fileName);
303 // ------------------------------------------------------------------------
304 void MonCreateIteration::SetTSNo()
305 // ------------------------------------------------------------------------
306 // Si on ne tient pas compte du pas de temps, on declare que le pas de temps
307 // vaut -1, valeur par defaut de med
310 SpinBox_Rank->setVisible(0);
311 SpinBox_Rank->setValue(-1);
313 TimeStep->setVisible(0);
314 SpinBox_TimeStep->setVisible(0);
315 SpinBox_TimeStep->setValue(-1);
319 // ------------------------------------------------------------------------
320 void MonCreateIteration::SetTSLast()
321 // ------------------------------------------------------------------------
322 // Si on choisit le dernier instant, on declare que le pas de temps vaut -2
325 SpinBox_Rank->setVisible(0);
326 SpinBox_Rank->setValue(-2);
328 TimeStep->setVisible(0);
329 SpinBox_TimeStep->setVisible(0);
330 SpinBox_TimeStep->setValue(-2);
334 // ------------------------------------------------------------------------
335 void MonCreateIteration::SetTSChosen()
336 // ------------------------------------------------------------------------
337 // Si choisit un instant, on prepositionne a 0
340 SpinBox_Rank->setVisible(1);
341 SpinBox_Rank->setValue(0);
343 TimeStep->setVisible(1);
344 SpinBox_TimeStep->setVisible(1);
345 SpinBox_TimeStep->setValue(0);