1 // Copyright (C) 2011-2013 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>
34 // -----------------------------------------------------------------------------------------------------
35 MonCreateIteration::MonCreateIteration(QWidget* parent, bool modal,
36 HOMARD::HOMARD_Gen_var myHomardGen, QString IterParentName ):
37 // -----------------------------------------------------------------------------------------------------
38 /* Constructs a MonCreateIteration
39 * Inherits from CasHomard
40 * Sets attributes to default values
45 _IterParentName(IterParentName),
48 MESSAGE("Constructeur");
49 _myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen);
54 SetNewIterationName();
56 if (_IterParentName != QString(""))
57 { SetIterParentName(); }
59 {setModal(false); /* permet selection de l iteration dans l arbre d etude */}
62 // ------------------------------------------------------------------------
63 MonCreateIteration::~MonCreateIteration()
64 // ------------------------------------------------------------------------
66 // no need to delete child widgets, Qt does it all for us
68 // ------------------------------------------------------------------------
69 void MonCreateIteration::InitConnect()
70 // ------------------------------------------------------------------------
72 connect( PBIterParent, SIGNAL(pressed()), this, SLOT( SetIterParentName()));
73 connect( PBHypoEdit, SIGNAL(pressed()), this, SLOT( PushHypoEdit() ) );
74 connect( PBHypoNew, SIGNAL(pressed()), this, SLOT( PushHypoNew() ) );
75 connect( PushFieldFile, SIGNAL(pressed()), this, SLOT( SetFieldFile() ) );
76 connect( RBNo, SIGNAL(clicked()), this, SLOT( SetTSNo()));
77 connect( RBLast, SIGNAL(clicked()), this, SLOT( SetTSLast()));
78 connect( RBChosen, SIGNAL(clicked()), this, SLOT( SetTSChosen()));
80 connect( buttonOk, SIGNAL(pressed()), this, SLOT( PushOnOK() ) );
81 connect( buttonApply, SIGNAL(pressed()), this, SLOT( PushOnApply() ) );
82 connect( buttonCancel, SIGNAL(pressed()), this, SLOT( close() ) );
83 connect( buttonHelp, SIGNAL(pressed()), this, SLOT( PushOnHelp() ) );
85 // ------------------------------------------------------------------------
86 void MonCreateIteration::GetHypotheses()
87 // ------------------------------------------------------------------------
89 HOMARD::listeHypotheses_var mesHypotheses = _myHomardGen->GetAllHypothesesName();
90 for (int i=0; i<mesHypotheses->length(); i++)
92 CBHypothese->addItem(QString(mesHypotheses[i]));
95 // ------------------------------------------------------------------------
96 bool MonCreateIteration::PushOnApply()
97 // ------------------------------------------------------------------------
98 // Appele lorsque l'un des boutons Ok ou Apply est presse
100 MESSAGE("MonCreateIteration::PushOnApply");
102 QString aIterationName = LEIterationName->text().trimmed();
103 if ( aIterationName == QString (""))
105 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
106 QObject::tr("HOM_ITER_NAME") );
110 if ( _IterParentName == QString (""))
112 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
113 QObject::tr("HOM_ITER_STARTING_POINT") );
116 QString aMeshName_np1=LEMeshName_np1->text().trimmed();
117 if (aMeshName_np1 == "" )
119 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
120 QObject::tr("HOM_ITER_MESH") );
123 QString monHypoName=CBHypothese->currentText();
124 if (monHypoName == "" )
126 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
127 QObject::tr("HOM_ITER_HYPO") );
130 HOMARD::HOMARD_Hypothesis_var _myHypothesis = _myHomardGen->GetHypothesis(monHypoName.toStdString().c_str());
131 HOMARD::listeTypes_var ListTypes (_myHypothesis->GetAdapRefinUnRef());
132 int TypeAdap = ListTypes[0];
133 if ( TypeAdap == 1 and LEFieldFile->text().trimmed() == QString("") )
135 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
136 QObject::tr("HOM_ITER_FIELD_FILE") );
140 MESSAGE ("aMeshName_np1.toStdString " << aMeshName_np1.toStdString());
141 MESSAGE ("_CaseName.toStdString " << _CaseName.toStdString() );
142 MESSAGE ("_IterParentName.toStdString " << _IterParentName.toStdString() );
144 // Creation de l'objet CORBA si ce n'est pas deja fait sous le meme nom
145 if (_IterationName != aIterationName)
149 _IterationName = aIterationName;
150 std::cerr << _IterationName.toStdString() << std::endl;
151 aIter = _myHomardGen->CreateIteration( \
152 CORBA::string_dup(_IterationName.toStdString().c_str()),
153 CORBA::string_dup(_IterParentName.toStdString().c_str()));
155 catch( SALOME::SALOME_Exception& S_ex )
157 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
158 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
162 // Mise en place des attributs
163 std::string IterName = aIter->GetName() ;
165 if ( LEFieldFile->text().trimmed() != QString(""))
167 QString FieldFile=LEFieldFile->text().trimmed();
168 aIter->SetFieldFile(CORBA::string_dup(FieldFile.toStdString().c_str()));
169 int rank = SpinBox_Rank->value();
170 int step = SpinBox_TimeStep->value();
171 if ( step == -2 ) { aIter->SetTimeStepRankLast(); }
172 else { aIter->SetTimeStepRank(step,rank); }
174 _myHomardGen->AssociateIterHypo (IterName.c_str(), monHypoName.toStdString().c_str());
175 aIter->SetMeshName(CORBA::string_dup(aMeshName_np1.toStdString().c_str()));
177 HOMARD_UTILS::updateObjBrowser() ;
181 // ------------------------------------------------------------------------
182 void MonCreateIteration::PushOnOK()
183 // ------------------------------------------------------------------------
185 bool bOK = PushOnApply();
186 if ( bOK ) this->close();
188 // ------------------------------------------------------------------------
189 void MonCreateIteration::PushOnHelp()
190 // ------------------------------------------------------------------------
192 HOMARD_UTILS::PushOnHelp(QString("gui_create_iteration.html"));
194 // ------------------------------------------------------------------------
195 void MonCreateIteration::SetIterParentName()
196 // ------------------------------------------------------------------------
198 if (_IterParentName == QString("")) {
199 _IterParentName=HOMARD_QT_COMMUN::SelectionArbreEtude(QString("IterationHomard"), 1);
200 if (_IterParentName == QString("")) { raise();return;};
202 _CaseName=HOMARD_QT_COMMUN::SelectionCasEtude();
203 HOMARD::HOMARD_Iteration_var aIterParent = _myHomardGen->GetIteration(_IterParentName.toStdString().c_str()) ;
204 QString MeshName = aIterParent->GetMeshName();
206 LEMeshName_n->setText(MeshName);
207 LEMeshName_n->setReadOnly(1);
208 LEMeshName_np1->setText(MeshName);
210 LEIterationParentName->setText(_IterParentName);
212 // -------------------------------------------------
213 void MonCreateIteration::SetNewIterationName()
214 // --------------------------------------------------
216 // Recherche d'un nom par defaut qui n'existe pas encore
218 HOMARD::listeIterations_var myIters=_myHomardGen->GetAllIterationsName();
220 QString aIterationName="";
221 while (aIterationName=="" )
223 aIterationName.setNum(num+1) ;
224 aIterationName.insert(0, QString("Iter_"));
225 for ( int i=0; i< myIters->length(); i++)
227 if ( aIterationName == QString((myIters)[i]))
235 LEIterationName->setText(aIterationName);
237 // ------------------------------------------------------------------------
238 void MonCreateIteration::PushHypoEdit()
239 // ------------------------------------------------------------------------
241 if (CBHypothese->currentText() == QString("")) return;
242 if (_IterParentName == QString(""))
244 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
245 QObject::tr("HOM_ITER_STARTING_POINT") );
249 QString aFieldFile=LEFieldFile->text().trimmed();
250 MonEditHypothesis *HypoDlg = new MonEditHypothesis(this,TRUE, HOMARD::HOMARD_Gen::_duplicate(_myHomardGen),CBHypothese->currentText(), _CaseName, aFieldFile) ;
254 // ------------------------------------------------------------------------
255 void MonCreateIteration::addHypothese(QString newHypothese)
256 // ------------------------------------------------------------------------
258 CBHypothese->insertItem(0,newHypothese);
259 CBHypothese->setCurrentIndex(0);
261 // ------------------------------------------------------------------------
262 void MonCreateIteration::PushHypoNew()
263 // ------------------------------------------------------------------------
265 if (_IterParentName == QString(""))
267 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
268 QObject::tr("HOM_ITER_STARTING_POINT") );
272 if ( _CaseName == QString(""))
274 HOMARD::HOMARD_Iteration_var aIterParent = _myHomardGen->GetIteration(_IterParentName.toStdString().c_str()) ;
275 _CaseName = aIterParent->GetCaseName();
277 QString aFieldFile=LEFieldFile->text().trimmed();
278 MonCreateHypothesis *HypoDlg = new MonCreateHypothesis(this,TRUE,HOMARD::HOMARD_Gen::_duplicate(_myHomardGen),QString(""),_CaseName, aFieldFile) ;
281 // ------------------------------------------------------------------------
282 void MonCreateIteration::SetFieldFile()
283 // ------------------------------------------------------------------------
285 QString fileName0 = LEFieldFile->text().trimmed();
286 QString fileName = HOMARD_QT_COMMUN::PushNomFichier(false);
287 if (fileName.isEmpty()) fileName = fileName0 ;
288 LEFieldFile->setText(fileName);
291 // ------------------------------------------------------------------------
292 void MonCreateIteration::SetTSNo()
293 // ------------------------------------------------------------------------
294 // Si on ne tient pas compte du pas de temps, on declare que le pas de temps
295 // vaut -1, valeur par defaut de med
298 SpinBox_Rank->setVisible(0);
299 SpinBox_Rank->setValue(-1);
301 TimeStep->setVisible(0);
302 SpinBox_TimeStep->setVisible(0);
303 SpinBox_TimeStep->setValue(-1);
307 // ------------------------------------------------------------------------
308 void MonCreateIteration::SetTSLast()
309 // ------------------------------------------------------------------------
310 // Si on choisit le dernier instant, on declare que le pas de temps vaut -2
313 SpinBox_Rank->setVisible(0);
314 SpinBox_Rank->setValue(-2);
316 TimeStep->setVisible(0);
317 SpinBox_TimeStep->setVisible(0);
318 SpinBox_TimeStep->setValue(-2);
322 // ------------------------------------------------------------------------
323 void MonCreateIteration::SetTSChosen()
324 // ------------------------------------------------------------------------
325 // Si choisit un instant, on prepositionne a 0
328 SpinBox_Rank->setVisible(1);
329 SpinBox_Rank->setValue(0);
331 TimeStep->setVisible(1);
332 SpinBox_TimeStep->setVisible(1);
333 SpinBox_TimeStep->setValue(0);