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
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 (QWidget* parent, bool modal, HOMARD::HOMARD_Gen_var myHomardGen)
44 _aCaseName(""), _aDirName(""), _aDirNameStart("")
46 MESSAGE("Debut du constructeur de MonPursueIteration");
47 myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen);
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( LECaseName, SIGNAL(textChanged(QString)), this, SLOT(CaseNameChanged()));
73 connect( PushDir, SIGNAL(pressed()), this, SLOT(SetDirName()));
75 connect( RBIteration, SIGNAL(clicked()), this, SLOT(FromIteration()));
76 connect( RBCase, SIGNAL(clicked()), this, SLOT(FromCase()));
77 connect( PushDirStart, SIGNAL(pressed()), this, SLOT(SetDirNameStart()));
79 connect( RBCaseLastIteration, SIGNAL(clicked()), this, SLOT(CaseLastIteration()));
80 connect( RBCaseNIteration, SIGNAL(clicked()), this, SLOT(CaseNIteration()));
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 bool MonPursueIteration::PushOnApply()
89 // --------------------------------
91 MESSAGE("PushOnApply");
93 QString aDirName=LEDirName->text().trimmed();
94 if (aDirName == QString(""))
96 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
97 QObject::tr("HOM_CASE_DIRECTORY_1") );
100 if ( aDirName != _aDirName)
101 { QString CaseNameDir = myHomardGen->VerifieDir( aDirName.toStdString().c_str()) ;
102 if ( CaseNameDir != "" )
105 texte = QObject::tr("HOM_CASE_DIRECTORY_2") + CaseNameDir ;
106 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
112 if (chdir(aDirName.toStdString().c_str()) != 0)
114 if (_chdir(aDirName.toStdString().c_str()) != 0)
117 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
118 QObject::tr("HOM_CASE_DIRECTORY_3") );
122 // Enregistrement du numero d'iteration
124 if ( _Type == 3 ) { Number = spinBoxNumber->value() ; }
127 QString _aCaseName=LECaseName->text().trimmed();
129 MESSAGE("_Type = "<<_Type);
132 case 1 : // Poursuite a partir d'une iteration
136 MESSAGE("Poursuite a partir d'une iteration");
137 aCase = myHomardGen->CreateCaseFromIteration( \
138 CORBA::string_dup(_aCaseName.toStdString().c_str()), \
139 CORBA::string_dup(_aDirNameStart.toStdString().c_str()) );
141 catch( SALOME::SALOME_Exception& S_ex )
143 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
144 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
149 case 2 : // Poursuite a partir de la derniere iteration dans un cas
153 MESSAGE("Poursuite a partir de la derniere iteration dans un cas");
154 aCase = myHomardGen->CreateCaseFromCaseLastIteration( \
155 CORBA::string_dup(_aCaseName.toStdString().c_str()), \
156 CORBA::string_dup(_aDirNameStart.toStdString().c_str()) );
158 catch( SALOME::SALOME_Exception& S_ex )
160 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
161 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
166 case 3 : // Poursuite a partir d'une iteration dans un cas
170 MESSAGE("Poursuite a partir d'une iteration dans un cas");
171 aCase = myHomardGen->CreateCaseFromCaseIteration( \
172 CORBA::string_dup(_aCaseName.toStdString().c_str()), \
173 CORBA::string_dup(_aDirNameStart.toStdString().c_str()), \
176 catch( SALOME::SALOME_Exception& S_ex )
178 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
179 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
186 HOMARD_UTILS::updateObjBrowser();
190 // ---------------------------
191 void MonPursueIteration::PushOnOK()
192 // ---------------------------
194 bool bOK = PushOnApply();
195 if ( bOK ) this->close();
197 //------------------------------
198 void MonPursueIteration::PushOnHelp()
199 //-------------------------------
201 char* LanguageShort = myHomardGen->GetLanguageShort();
202 HOMARD_UTILS::PushOnHelp(QString("gui_create_case.html"), QString(""), QString(LanguageShort));
204 // ---------------------------------
205 void MonPursueIteration::SetNewCaseName()
206 // ------------------------------
208 HOMARD::listeCases_var MyCases = myHomardGen->GetAllCasesName();
209 int num = 0; QString aCaseName="";
210 while (aCaseName=="" )
212 aCaseName.setNum(num+1) ;
213 aCaseName.insert(0, QString("Case_")) ;
214 for ( int i=0; i<MyCases->length(); i++)
216 if ( aCaseName == QString((MyCases)[i]))
224 LECaseName->clear() ;
225 LECaseName->insert(aCaseName);
227 // ------------------------------------------------------------------------
228 void MonPursueIteration::SetDirName()
229 // ------------------------------------------------------------------------
231 QString aDirName=QFileDialog::getExistingDirectory ();
232 if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
234 // ------------------------------------------------------------------------
235 void MonPursueIteration::SetDirNameStart()
236 // ------------------------------------------------------------------------
238 QString aDirName=QFileDialog::getExistingDirectory ();
239 if (!(aDirName.isEmpty()))LEDirNameStart->setText(aDirName);
241 // ------------------------------------------------------------------------
242 void MonPursueIteration::FromIteration()
243 // ------------------------------------------------------------------------
245 GBIterationintoCase->setVisible(0);
246 spinBoxNumber->setVisible(0);
250 // ------------------------------------------------------------------------
251 void MonPursueIteration::FromCase()
252 // ------------------------------------------------------------------------
254 GBIterationintoCase->setVisible(1);
257 // ------------------------------------------------------------------------
258 void MonPursueIteration::CaseLastIteration()
259 // ------------------------------------------------------------------------
261 spinBoxNumber->setVisible(0);
265 // ------------------------------------------------------------------------
266 void MonPursueIteration::CaseNIteration()
267 // ------------------------------------------------------------------------
269 spinBoxNumber->setVisible(1);