1 // Copyright (C) 2011-2020 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, or (at your option) any later version.
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
20 #include "MonCreateIteration.h"
21 #include "MonCreateHypothesis.h"
22 #include "MonEditHypothesis.h"
24 #include <QFileDialog>
25 #include <QMessageBox>
27 #include "SalomeApp_Tools.h"
28 #include "HOMARDGUI_Utils.h"
29 #include "HomardQtCommun.h"
30 #include <utilities.h>
34 // -----------------------------------------------------------------------------------------------------
35 MonCreateIteration::MonCreateIteration(QWidget* parent, bool modal,
36 ADAPT::ADAPT_Gen_var myAdaptGen0, QString IterParentName ):
37 // -----------------------------------------------------------------------------------------------------
38 /* Constructs a MonCreateIteration
39 * Inherits from CasHomard
40 * Sets attributes to default values
45 _IterParentName(IterParentName),
48 MESSAGE("Constructeur");
49 myAdaptGen=ADAPT::ADAPT_Gen::_duplicate(myAdaptGen0);
51 if ( modal ) { setWindowModality(Qt::WindowModal); }
52 else { setWindowModality(Qt::NonModal); }
57 if (_IterParentName != QString("")) { SetIterParentName(); }
58 else { setWindowModality(Qt::NonModal) ; /* permet selection de l'iteration dans l arbre d etude */}
63 // ------------------------------------------------------------------------
64 MonCreateIteration::~MonCreateIteration()
65 // ------------------------------------------------------------------------
67 // no need to delete child widgets, Qt does it all for us
69 // ------------------------------------------------------------------------
70 void MonCreateIteration::InitConnect()
71 // ------------------------------------------------------------------------
73 connect( PBIterParent, SIGNAL(pressed()), this, SLOT( SetIterParentName()));
74 connect( PBHypoEdit, SIGNAL(pressed()), this, SLOT( PushHypoEdit() ) );
75 connect( PBHypoNew, SIGNAL(pressed()), this, SLOT( PushHypoNew() ) );
76 connect( PushFieldFile, SIGNAL(pressed()), this, SLOT( SetFieldFile() ) );
77 connect( RBNo, SIGNAL(clicked()), this, SLOT( SetTSNo()));
78 connect( RBLast, SIGNAL(clicked()), this, SLOT( SetTSLast()));
79 connect( RBChosen, SIGNAL(clicked()), this, SLOT( SetTSChosen()));
81 connect( buttonOk, SIGNAL(pressed()), this, SLOT( PushOnOK() ) );
82 connect( buttonApply, SIGNAL(pressed()), this, SLOT( PushOnApply() ) );
83 connect( buttonCancel, SIGNAL(pressed()), this, SLOT( close() ) );
84 connect( buttonHelp, SIGNAL(pressed()), this, SLOT( PushOnHelp() ) );
86 // ------------------------------------------------------------------------
87 void MonCreateIteration::GetHypotheses()
88 // ------------------------------------------------------------------------
90 ADAPT::listeHypotheses_var mesHypotheses = myAdaptGen->GetAllHypothesesName();
91 for (int i=0; i<mesHypotheses->length(); i++)
93 CBHypothese->addItem(QString(mesHypotheses[i]));
96 // ------------------------------------------------------------------------
97 bool MonCreateIteration::PushOnApply()
98 // ------------------------------------------------------------------------
99 // Appele lorsque l'un des boutons Ok ou Apply est presse
101 MESSAGE("PushOnApply");
103 QString aName = LEName->text().trimmed();
104 if ( aName == QString (""))
106 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
107 QObject::tr("HOM_ITER_NAME") );
111 if ( _IterParentName == QString (""))
113 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
114 QObject::tr("HOM_ITER_STARTING_POINT") );
117 QString aMeshName_np1=LEMeshName_np1->text().trimmed();
118 if (aMeshName_np1 == "" )
120 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
121 QObject::tr("HOM_ITER_MESH") );
124 QString monHypoName=CBHypothese->currentText();
125 if (monHypoName == "" )
127 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
128 QObject::tr("HOM_ITER_HYPO") );
131 ADAPT::HOMARD_Hypothesis_var _myHypothesis = myAdaptGen->GetHypothesis(monHypoName.toStdString().c_str());
132 ADAPT::listeTypes_var ListTypes (_myHypothesis->GetAdapRefinUnRef());
133 int TypeAdap = ListTypes[0];
134 if ( TypeAdap == 1 && LEFieldFile->text().trimmed() == QString("") )
136 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
137 QObject::tr("HOM_ITER_FIELD_FILE") );
141 MESSAGE ("aMeshName_np1.toStdString " << aMeshName_np1.toStdString());
142 MESSAGE ("_CaseName.toStdString " << _CaseName.toStdString() );
143 MESSAGE ("_IterParentName.toStdString " << _IterParentName.toStdString() );
145 // Creation de l'objet CORBA si ce n'est pas deja fait sous le meme nom
151 std::cerr << _Name.toStdString() << std::endl;
152 aIter = myAdaptGen->CreateIteration( \
153 CORBA::string_dup(_Name.toStdString().c_str()),
154 CORBA::string_dup(_IterParentName.toStdString().c_str()));
156 catch( SALOME::SALOME_Exception& S_ex )
158 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
159 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
163 // Mise en place des attributs
164 std::string IterName = aIter->GetName() ;
166 if ( LEFieldFile->text().trimmed() != QString(""))
168 QString FieldFile=LEFieldFile->text().trimmed();
169 aIter->SetFieldFile(CORBA::string_dup(FieldFile.toStdString().c_str()));
170 int rank = SpinBox_Rank->value();
171 int step = SpinBox_TimeStep->value();
172 if ( step == -2 ) { aIter->SetTimeStepRankLast(); }
173 else { aIter->SetTimeStepRank(step,rank); }
175 myAdaptGen->AssociateIterHypo (IterName.c_str(), monHypoName.toStdString().c_str());
176 aIter->SetMeshName(CORBA::string_dup(aMeshName_np1.toStdString().c_str()));
178 HOMARD_UTILS::updateObjBrowser() ;
182 // ------------------------------------------------------------------------
183 void MonCreateIteration::PushOnOK()
184 // ------------------------------------------------------------------------
186 bool bOK = PushOnApply();
187 if ( bOK ) this->close();
189 // ------------------------------------------------------------------------
190 void MonCreateIteration::PushOnHelp()
191 // ------------------------------------------------------------------------
193 std::string LanguageShort = myAdaptGen->GetLanguageShort();
194 HOMARD_UTILS::PushOnHelp(QString("gui_create_iteration.html"), QString(""), QString(LanguageShort.c_str()));
196 // ------------------------------------------------------------------------
197 void MonCreateIteration::SetIterParentName()
198 // ------------------------------------------------------------------------
200 if (_IterParentName == QString("")) {
201 _IterParentName=HOMARD_QT_COMMUN::SelectionArbreEtude(QString("IterationHomard"), 1);
202 if (_IterParentName == QString("")) { raise();return;};
204 _CaseName=HOMARD_QT_COMMUN::SelectionCasEtude();
205 ADAPT::HOMARD_Iteration_var aIterParent = myAdaptGen->GetIteration(_IterParentName.toStdString().c_str()) ;
206 QString MeshName = aIterParent->GetMeshName();
208 LEMeshName_n->setText(MeshName);
209 LEMeshName_n->setReadOnly(1);
210 LEMeshName_np1->setText(MeshName);
212 LEIterationParentName->setText(_IterParentName);
214 // -------------------------------------------------
215 void MonCreateIteration::SetNewName()
216 // --------------------------------------------------
218 // Recherche d'un nom par defaut qui n'existe pas encore
220 ADAPT::listeIterations_var MyObjects=myAdaptGen->GetAllIterationsName();
225 aName.setNum(num+1) ;
226 aName.insert(0, QString("Iter_"));
227 for ( int i=0; i< MyObjects->length(); i++)
229 if ( aName == QString((MyObjects)[i]))
237 LEName->setText(aName);
239 // ------------------------------------------------------------------------
240 void MonCreateIteration::PushHypoEdit()
241 // ------------------------------------------------------------------------
243 if (CBHypothese->currentText() == QString("")) return;
244 if (_IterParentName == QString(""))
246 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
247 QObject::tr("HOM_ITER_STARTING_POINT") );
251 QString aFieldFile=LEFieldFile->text().trimmed();
252 MonEditHypothesis *HypoDlg = new MonEditHypothesis(this, true, ADAPT::ADAPT_Gen::_duplicate(myAdaptGen),CBHypothese->currentText(), _CaseName, aFieldFile) ;
256 // ------------------------------------------------------------------------
257 void MonCreateIteration::addHypothese(QString newHypothese)
258 // ------------------------------------------------------------------------
260 CBHypothese->insertItem(0,newHypothese);
261 CBHypothese->setCurrentIndex(0);
263 // ------------------------------------------------------------------------
264 void MonCreateIteration::PushHypoNew()
265 // ------------------------------------------------------------------------
267 if (_IterParentName == QString(""))
269 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
270 QObject::tr("HOM_ITER_STARTING_POINT") );
274 if ( _CaseName == QString(""))
276 ADAPT::HOMARD_Iteration_var aIterParent = myAdaptGen->GetIteration(_IterParentName.toStdString().c_str()) ;
277 _CaseName = aIterParent->GetCaseName();
279 QString aFieldFile=LEFieldFile->text().trimmed();
280 MonCreateHypothesis *HypoDlg = new MonCreateHypothesis(this, true, ADAPT::ADAPT_Gen::_duplicate(myAdaptGen), QString(""), _CaseName, aFieldFile) ;
283 // ------------------------------------------------------------------------
284 void MonCreateIteration::SetFieldFile()
285 // ------------------------------------------------------------------------
287 QString fileName0 = LEFieldFile->text().trimmed();
288 QString fileName = HOMARD_QT_COMMUN::PushNomFichier( false, QString("med") ) ;
289 if (fileName.isEmpty()) fileName = fileName0 ;
290 LEFieldFile->setText(fileName);
293 // ------------------------------------------------------------------------
294 void MonCreateIteration::SetTSNo()
295 // ------------------------------------------------------------------------
296 // Si on ne tient pas compte du pas de temps, on declare que le pas de temps
297 // vaut -1, valeur par defaut de med
300 SpinBox_Rank->setVisible(0);
301 SpinBox_Rank->setValue(-1);
303 TimeStep->setVisible(0);
304 SpinBox_TimeStep->setVisible(0);
305 SpinBox_TimeStep->setValue(-1);
309 // ------------------------------------------------------------------------
310 void MonCreateIteration::SetTSLast()
311 // ------------------------------------------------------------------------
312 // Si on choisit le dernier instant, on declare que le pas de temps vaut -2
315 SpinBox_Rank->setVisible(0);
316 SpinBox_Rank->setValue(-2);
318 TimeStep->setVisible(0);
319 SpinBox_TimeStep->setVisible(0);
320 SpinBox_TimeStep->setValue(-2);
324 // ------------------------------------------------------------------------
325 void MonCreateIteration::SetTSChosen()
326 // ------------------------------------------------------------------------
327 // Si choisit un instant, on prepositionne a 0
330 SpinBox_Rank->setVisible(1);
331 SpinBox_Rank->setValue(0);
333 TimeStep->setVisible(1);
334 SpinBox_TimeStep->setVisible(1);
335 SpinBox_TimeStep->setValue(0);