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 "MonPursueIteration.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>
33 // -----------------------------------------------------------------------------------------
34 /* Constructs a MonPursueIteration
35 * Inherits from CasHomard
36 * Sets attributes to default values
38 // -----------------------------------------------------------------------------------------
39 MonPursueIteration::MonPursueIteration (QWidget* parent, bool modal, HOMARD::HOMARD_Gen_var myHomardGen)
42 _aCaseName(""), _aDirName(""), _aDirNameStart("")
44 MESSAGE("Debut du constructeur de MonPursueIteration");
45 _myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen);
53 GBIterationintoCase->setVisible(0);
54 spinBoxNumber->setVisible(0);
57 MESSAGE("Fin du constructeur de MonPursueIteration");
60 // ------------------------------------------------------------------------
61 MonPursueIteration::~MonPursueIteration()
62 // ------------------------------------------------------------------------
64 // no need to delete child widgets, Qt does it all for us
66 // ------------------------------------------------------------------------
67 void MonPursueIteration::InitConnect()
68 // ------------------------------------------------------------------------
70 connect( LECaseName, SIGNAL(textChanged(QString)), this, SLOT(CaseNameChanged()));
71 connect( PushDir, SIGNAL(pressed()), this, SLOT(SetDirName()));
73 connect( RBIteration, SIGNAL(clicked()), this, SLOT(FromIteration()));
74 connect( RBCase, SIGNAL(clicked()), this, SLOT(FromCase()));
75 connect( PushDirStart, SIGNAL(pressed()), this, SLOT(SetDirNameStart()));
77 connect( RBCaseLastIteration, SIGNAL(clicked()), this, SLOT(CaseLastIteration()));
78 connect( RBCaseNIteration, SIGNAL(clicked()), this, SLOT(CaseNIteration()));
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 bool MonPursueIteration::PushOnApply()
87 // --------------------------------
89 MESSAGE("PushOnApply");
91 QString aDirName=LEDirName->text().trimmed();
92 if (aDirName == QString(""))
94 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
95 QObject::tr("HOM_CASE_DIRECTORY_1") );
98 if ((aDirName != _aDirName) and (_myHomardGen->VerifieDir( aDirName.toStdString().c_str()) == false))
100 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
101 QObject::tr("HOM_CASE_DIRECTORY_2") );
104 if (chdir(aDirName.toStdString().c_str()) != 0)
106 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
107 QObject::tr("HOM_CASE_DIRECTORY_3") );
111 // Enregistrement du numero d'iteration
113 if ( _Type == 3 ) { Number = spinBoxNumber->value() ; }
116 QString _aCaseName=LECaseName->text().trimmed();
118 MESSAGE("_Type = "<<_Type);
121 case 1 : // Poursuite a partir d'une iteration
125 MESSAGE("Poursuite a partir d'une iteration");
126 aCase = _myHomardGen->CreateCaseFromIteration( \
127 CORBA::string_dup(_aCaseName.toStdString().c_str()), \
128 CORBA::string_dup(_aDirNameStart.toStdString().c_str()) );
130 catch( SALOME::SALOME_Exception& S_ex )
132 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
133 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
138 case 2 : // Poursuite a partir de la derniere iteration dans un cas
142 MESSAGE("Poursuite a partir de la derniere iteration dans un cas");
143 aCase = _myHomardGen->CreateCaseFromCaseLastIteration( \
144 CORBA::string_dup(_aCaseName.toStdString().c_str()), \
145 CORBA::string_dup(_aDirNameStart.toStdString().c_str()) );
147 catch( SALOME::SALOME_Exception& S_ex )
149 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
150 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
155 case 3 : // Poursuite a partir d'une iteration dans un cas
159 MESSAGE("Poursuite a partir d'une iteration dans un cas");
160 aCase = _myHomardGen->CreateCaseFromCaseIteration( \
161 CORBA::string_dup(_aCaseName.toStdString().c_str()), \
162 CORBA::string_dup(_aDirNameStart.toStdString().c_str()), \
165 catch( SALOME::SALOME_Exception& S_ex )
167 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
168 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
175 HOMARD_UTILS::updateObjBrowser();
179 // ---------------------------
180 void MonPursueIteration::PushOnOK()
181 // ---------------------------
183 bool bOK = PushOnApply();
184 if ( bOK ) this->close();
186 //------------------------------
187 void MonPursueIteration::PushOnHelp()
188 //-------------------------------
190 HOMARD_UTILS::PushOnHelp(QString("gui_create_case.html"), QString(""));
192 // ---------------------------------
193 void MonPursueIteration::SetNewCaseName()
194 // ------------------------------
196 HOMARD::listeCases_var MyCases = _myHomardGen->GetAllCasesName();
197 int num = 0; QString aCaseName="";
198 while (aCaseName=="" )
200 aCaseName.setNum(num+1) ;
201 aCaseName.insert(0, QString("Case_")) ;
202 for ( int i=0; i<MyCases->length(); i++)
204 if ( aCaseName == QString((MyCases)[i]))
212 LECaseName->clear() ;
213 LECaseName->insert(aCaseName);
215 // ------------------------------------------------------------------------
216 void MonPursueIteration::SetDirName()
217 // ------------------------------------------------------------------------
219 QString aDirName=QFileDialog::getExistingDirectory ();
220 if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
222 // ------------------------------------------------------------------------
223 void MonPursueIteration::SetDirNameStart()
224 // ------------------------------------------------------------------------
226 QString aDirName=QFileDialog::getExistingDirectory ();
227 if (!(aDirName.isEmpty()))LEDirNameStart->setText(aDirName);
229 // ------------------------------------------------------------------------
230 void MonPursueIteration::FromIteration()
231 // ------------------------------------------------------------------------
233 GBIterationintoCase->setVisible(0);
234 spinBoxNumber->setVisible(0);
238 // ------------------------------------------------------------------------
239 void MonPursueIteration::FromCase()
240 // ------------------------------------------------------------------------
242 GBIterationintoCase->setVisible(1);
245 // ------------------------------------------------------------------------
246 void MonPursueIteration::CaseLastIteration()
247 // ------------------------------------------------------------------------
249 spinBoxNumber->setVisible(0);
253 // ------------------------------------------------------------------------
254 void MonPursueIteration::CaseNIteration()
255 // ------------------------------------------------------------------------
257 spinBoxNumber->setVisible(1);