1 // Copyright (C) 2011 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->GetAllHypotheses();
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 int rank = SpinBox_Rank->value();
174 int step = SpinBox_TimeStep->value();
175 aIter->SetFieldFile(CORBA::string_dup(FieldFile.toStdString().c_str()));
176 aIter->SetTimeStepRank(step,rank);
178 _myHomardGen->AssociateIterHypo (IterName, monHypoName.toStdString().c_str());
179 aIter->SetMeshName(CORBA::string_dup(aMeshName_np1.toStdString().c_str()));
181 HOMARD_UTILS::updateObjBrowser();
185 // ------------------------------------------------------------------------
186 void MonCreateIteration::PushOnOK()
187 // ------------------------------------------------------------------------
189 bool bOK = PushOnApply();
190 if ( bOK ) this->close();
193 // ------------------------------------------------------------------------
194 void MonCreateIteration::PushOnHelp()
195 // ------------------------------------------------------------------------
197 HOMARD_UTILS::PushOnHelp(QString("gui_create_iteration.html"));
200 // ------------------------------------------------------------------------
201 void MonCreateIteration::SetIterParentName()
202 // ------------------------------------------------------------------------
204 if (_IterParentName == QString("")) {
205 _IterParentName=HOMARD_QT_COMMUN::SelectionArbreEtude(QString("IterationHomard"), 1);
206 if (_IterParentName == QString("")) { raise();return;};
208 _CaseName=HOMARD_QT_COMMUN::SelectionCasEtude();
209 HOMARD::HOMARD_Iteration_var aIterParent = _myHomardGen->GetIteration(_IterParentName.toStdString().c_str()) ;
210 QString MeshName = aIterParent->GetMeshName();
212 LEMeshName_n->setText(MeshName);
213 LEMeshName_n->setReadOnly(1);
214 LEMeshName_np1->setText(MeshName);
216 LEIterationParentName->setText(_IterParentName);
219 // -------------------------------------------------
220 void MonCreateIteration::SetNewIterationName()
221 // --------------------------------------------------
223 // Recherche d'un nom par defaut qui n'existe pas encore
225 HOMARD::listeIterations_var myIters=_myHomardGen->GetAllIterations();
227 QString aIterationName="";
228 while (aIterationName=="" )
230 aIterationName.setNum(num+1) ;
231 aIterationName.insert(0, QString("Iter_"));
232 for ( int i=0; i< myIters->length(); i++)
234 if ( aIterationName == QString((myIters)[i]))
242 LEIterationName->setText(aIterationName);
246 // ------------------------------------------------------------------------
247 void MonCreateIteration::PushHypoEdit()
248 // ------------------------------------------------------------------------
250 if (CBHypothese->currentText() == QString("")) return;
251 if (_IterParentName == QString(""))
253 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
254 QObject::tr("HOM_ITER_STARTING_POINT") );
258 QString aFieldFile=LEFieldFile->text().trimmed();
259 MonEditHypothesis *HypoDlg = new MonEditHypothesis(this,TRUE, HOMARD::HOMARD_Gen::_duplicate(_myHomardGen),CBHypothese->currentText(), _CaseName, aFieldFile) ;
263 // ------------------------------------------------------------------------
264 void MonCreateIteration::addHypothese(QString newHypothese)
265 // ------------------------------------------------------------------------
267 CBHypothese->insertItem(0,newHypothese);
268 CBHypothese->setCurrentIndex(0);
270 // ------------------------------------------------------------------------
271 void MonCreateIteration::PushHypoNew()
272 // ------------------------------------------------------------------------
274 if (_IterParentName == QString(""))
276 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
277 QObject::tr("HOM_ITER_STARTING_POINT") );
281 if ( _CaseName == QString(""))
283 _CaseName = _myHomardGen->GetCaseName(CORBA::string_dup(_IterParentName.toStdString().c_str()));
285 QString aFieldFile=LEFieldFile->text().trimmed();
286 MonCreateHypothesis *HypoDlg = new MonCreateHypothesis(this,TRUE,HOMARD::HOMARD_Gen::_duplicate(_myHomardGen),QString(""),_CaseName, aFieldFile) ;
290 // ------------------------------------------------------------------------
291 void MonCreateIteration::SetFieldFile()
292 // ------------------------------------------------------------------------
295 QString fileName0 = LEFieldFile->text().trimmed();
296 QString fileName = HOMARD_QT_COMMUN::PushNomFichier(false);
297 if (fileName.isEmpty()) fileName = fileName0 ;
298 LEFieldFile->setText(fileName);
301 // ------------------------------------------------------------------------
302 void MonCreateIteration::SetTSNo()
303 // ------------------------------------------------------------------------
304 // Par defaut, on declare que le pas de temps vaut -1
307 SpinBox_Rank->setVisible(0);
308 TimeStep->setVisible(0);
309 SpinBox_TimeStep->setVisible(0);
310 SpinBox_TimeStep->setValue(-1);
313 // ------------------------------------------------------------------------
314 void MonCreateIteration::SetTSLast()
315 // ------------------------------------------------------------------------
316 // Par defaut, on declare que le pas de temps vaut -2
319 SpinBox_Rank->setVisible(0);
320 TimeStep->setVisible(0);
321 SpinBox_TimeStep->setVisible(0);
322 SpinBox_TimeStep->setValue(-2);
325 // ------------------------------------------------------------------------
326 void MonCreateIteration::SetTSChosen()
327 // ------------------------------------------------------------------------
330 SpinBox_Rank->setVisible(1);
331 TimeStep->setVisible(1);
332 SpinBox_TimeStep->setVisible(1);
333 SpinBox_TimeStep->setValue(1);