1 // Copyright (C) 2011-2014 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 "MonPursueIteration.h"
22 #include <QFileDialog>
23 #include <QMessageBox>
25 #include "SalomeApp_Tools.h"
26 #include "HOMARDGUI_Utils.h"
27 #include "HomardQtCommun.h"
28 #include <utilities.h>
36 // -----------------------------------------------------------------------------------------
37 /* Constructs a MonPursueIteration
38 * Sets attributes to default values
40 // -----------------------------------------------------------------------------------------
41 MonPursueIteration::MonPursueIteration ( bool modal, HOMARD::HOMARD_Gen_var myHomardGen0 )
44 _aCaseName(""), _aDirName(""), _aDirNameStart("")
46 MESSAGE("Debut du constructeur de MonPursueIteration");
47 myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen0);
55 GBIterationintoCase->setVisible(0);
56 SpinBoxNumber->setVisible(0);
59 MESSAGE("Fin du constructeur de MonPursueIteration");
62 // ------------------------------------------------------------------------
63 MonPursueIteration::~MonPursueIteration()
64 // ------------------------------------------------------------------------
66 // no need to delete child widgets, Qt does it all for us
68 // ------------------------------------------------------------------------
69 void MonPursueIteration::InitConnect()
70 // ------------------------------------------------------------------------
72 connect( PushDir, SIGNAL(pressed()), this, SLOT(SetDirName()));
74 connect( RBIteration, SIGNAL(clicked()), this, SLOT(FromIteration()));
75 connect( RBCase, SIGNAL(clicked()), this, SLOT(FromCase()));
76 connect( PushDirStart, SIGNAL(pressed()), this, SLOT(SetDirNameStart()));
78 connect( RBCaseLastIteration, SIGNAL(clicked()), this, SLOT(CaseLastIteration()));
79 connect( RBCaseNIteration, SIGNAL(clicked()), this, SLOT(CaseNIteration()));
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 bool MonPursueIteration::PushOnApply()
88 // --------------------------------
90 MESSAGE("PushOnApply");
91 // 1. Enregistrement du repertoire du cas
92 QString aDirName=LEDirName->text().trimmed();
93 if (aDirName == QString(""))
95 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
96 QObject::tr("HOM_CASE_DIRECTORY_1") );
99 if ( aDirName != _aDirName)
100 { QString CaseNameDir = myHomardGen->VerifieDir( aDirName.toStdString().c_str()) ;
101 if ( CaseNameDir != "" )
104 texte = QObject::tr("HOM_CASE_DIRECTORY_2") + CaseNameDir ;
105 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
111 if (chdir(aDirName.toStdString().c_str()) != 0)
113 if (_chdir(aDirName.toStdString().c_str()) != 0)
116 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
117 QObject::tr("HOM_CASE_DIRECTORY_3") );
120 // 2. Enregistrement du repertoire de depart
121 QString aDirNameStart=LEDirNameStart->text().trimmed();
122 if (aDirNameStart == QString(""))
124 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
125 QObject::tr("HOM_START_DIRECTORY_1") );
129 if (chdir(aDirNameStart.toStdString().c_str()) != 0)
131 if (_chdir(aDirNameStart.toStdString().c_str()) != 0)
134 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
135 QObject::tr("HOM_START_DIRECTORY_3") );
139 // 3. Enregistrement du numero d'iteration
141 if ( _Type == 3 ) { Number = SpinBoxNumber->value() ; }
143 // 4. Creation du cas
144 QString _aCaseName=LECaseName->text().trimmed();
145 _aDirNameStart=aDirNameStart;
147 MESSAGE("_aCaseName = "<<_aCaseName.toStdString().c_str());
148 MESSAGE("_aDirNameStart = "<<_aDirNameStart.toStdString().c_str());
149 MESSAGE("_Type = "<<_Type);
152 case 1 : // Poursuite a partir d'une iteration
156 MESSAGE("Poursuite a partir d'une iteration");
157 aCase = myHomardGen->CreateCaseFromIteration( \
158 CORBA::string_dup(_aCaseName.toStdString().c_str()), \
159 CORBA::string_dup(_aDirNameStart.toStdString().c_str()) );
161 catch( SALOME::SALOME_Exception& S_ex )
163 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
164 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
169 case 2 : // Poursuite a partir de la derniere iteration dans un cas
173 MESSAGE("Poursuite a partir de la derniere iteration dans un cas");
174 aCase = myHomardGen->CreateCaseFromCaseLastIteration( \
175 CORBA::string_dup(_aCaseName.toStdString().c_str()), \
176 CORBA::string_dup(_aDirNameStart.toStdString().c_str()) );
178 catch( SALOME::SALOME_Exception& S_ex )
180 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
181 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
186 case 3 : // Poursuite a partir d'une iteration dans un cas
190 MESSAGE("Poursuite a partir d'une iteration dans un cas");
191 aCase = myHomardGen->CreateCaseFromCaseIteration( \
192 CORBA::string_dup(_aCaseName.toStdString().c_str()), \
193 CORBA::string_dup(_aDirNameStart.toStdString().c_str()), \
196 catch( SALOME::SALOME_Exception& S_ex )
198 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
199 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
206 aCase->SetDirName(aDirName.toStdString().c_str());
209 HOMARD_UTILS::updateObjBrowser();
213 // ---------------------------
214 void MonPursueIteration::PushOnOK()
215 // ---------------------------
217 bool bOK = PushOnApply();
218 if ( bOK ) this->close();
220 //------------------------------
221 void MonPursueIteration::PushOnHelp()
222 //-------------------------------
224 std::string LanguageShort = myHomardGen->GetLanguageShort();
225 HOMARD_UTILS::PushOnHelp(QString("gui_create_case.html"), QString(""), QString(LanguageShort.c_str()));
227 // ---------------------------------
228 void MonPursueIteration::SetNewCaseName()
229 // ------------------------------
231 HOMARD::listeCases_var MyCases = myHomardGen->GetAllCasesName();
232 int num = 0; QString aCaseName="";
233 while (aCaseName=="" )
235 aCaseName.setNum(num+1) ;
236 aCaseName.insert(0, QString("Case_")) ;
237 for ( int i=0; i<MyCases->length(); i++)
239 if ( aCaseName == QString((MyCases)[i]))
247 LECaseName->clear() ;
248 LECaseName->insert(aCaseName);
250 // ------------------------------------------------------------------------
251 void MonPursueIteration::SetDirName()
252 // ------------------------------------------------------------------------
254 QString aDirName=QFileDialog::getExistingDirectory ();
255 if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
257 // ------------------------------------------------------------------------
258 void MonPursueIteration::SetDirNameStart()
259 // ------------------------------------------------------------------------
261 QString aDirName=QFileDialog::getExistingDirectory ();
262 if (!(aDirName.isEmpty()))LEDirNameStart->setText(aDirName);
264 // ------------------------------------------------------------------------
265 void MonPursueIteration::FromIteration()
266 // ------------------------------------------------------------------------
268 GBIterationintoCase->setVisible(0);
269 SpinBoxNumber->setVisible(0);
273 // ------------------------------------------------------------------------
274 void MonPursueIteration::FromCase()
275 // ------------------------------------------------------------------------
277 GBIterationintoCase->setVisible(1);
280 // ------------------------------------------------------------------------
281 void MonPursueIteration::CaseLastIteration()
282 // ------------------------------------------------------------------------
284 SpinBoxNumber->setVisible(0);
288 // ------------------------------------------------------------------------
289 void MonPursueIteration::CaseNIteration()
290 // ------------------------------------------------------------------------
292 SpinBoxNumber->setVisible(1);