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 * Sets attributes to default values
37 // -----------------------------------------------------------------------------------------
38 MonPursueIteration::MonPursueIteration (QWidget* parent, bool modal, HOMARD::HOMARD_Gen_var myHomardGen)
41 _aCaseName(""), _aDirName(""), _aDirNameStart("")
43 MESSAGE("Debut du constructeur de MonPursueIteration");
44 myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen);
52 GBIterationintoCase->setVisible(0);
53 spinBoxNumber->setVisible(0);
56 MESSAGE("Fin du constructeur de MonPursueIteration");
59 // ------------------------------------------------------------------------
60 MonPursueIteration::~MonPursueIteration()
61 // ------------------------------------------------------------------------
63 // no need to delete child widgets, Qt does it all for us
65 // ------------------------------------------------------------------------
66 void MonPursueIteration::InitConnect()
67 // ------------------------------------------------------------------------
69 connect( LECaseName, SIGNAL(textChanged(QString)), this, SLOT(CaseNameChanged()));
70 connect( PushDir, SIGNAL(pressed()), this, SLOT(SetDirName()));
72 connect( RBIteration, SIGNAL(clicked()), this, SLOT(FromIteration()));
73 connect( RBCase, SIGNAL(clicked()), this, SLOT(FromCase()));
74 connect( PushDirStart, SIGNAL(pressed()), this, SLOT(SetDirNameStart()));
76 connect( RBCaseLastIteration, SIGNAL(clicked()), this, SLOT(CaseLastIteration()));
77 connect( RBCaseNIteration, SIGNAL(clicked()), this, SLOT(CaseNIteration()));
79 connect( buttonOk, SIGNAL(pressed()), this, SLOT(PushOnOK()));
80 connect( buttonApply, SIGNAL(pressed()), this, SLOT(PushOnApply()));
81 connect( buttonCancel, SIGNAL(pressed()), this, SLOT(close()));
82 connect( buttonHelp, SIGNAL(pressed()), this, SLOT(PushOnHelp()));
84 // -------------------------------
85 bool MonPursueIteration::PushOnApply()
86 // --------------------------------
88 MESSAGE("PushOnApply");
90 QString aDirName=LEDirName->text().trimmed();
91 if (aDirName == QString(""))
93 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
94 QObject::tr("HOM_CASE_DIRECTORY_1") );
97 if ( aDirName != _aDirName)
98 { QString CaseNameDir = myHomardGen->VerifieDir( aDirName.toStdString().c_str()) ;
99 if ( CaseNameDir != "" )
102 texte = QObject::tr("HOM_CASE_DIRECTORY_2") + CaseNameDir ;
103 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
108 if (chdir(aDirName.toStdString().c_str()) != 0)
110 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
111 QObject::tr("HOM_CASE_DIRECTORY_3") );
115 // Enregistrement du numero d'iteration
117 if ( _Type == 3 ) { Number = spinBoxNumber->value() ; }
120 QString _aCaseName=LECaseName->text().trimmed();
122 MESSAGE("_Type = "<<_Type);
125 case 1 : // Poursuite a partir d'une iteration
129 MESSAGE("Poursuite a partir d'une iteration");
130 aCase = myHomardGen->CreateCaseFromIteration( \
131 CORBA::string_dup(_aCaseName.toStdString().c_str()), \
132 CORBA::string_dup(_aDirNameStart.toStdString().c_str()) );
134 catch( SALOME::SALOME_Exception& S_ex )
136 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
137 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
142 case 2 : // Poursuite a partir de la derniere iteration dans un cas
146 MESSAGE("Poursuite a partir de la derniere iteration dans un cas");
147 aCase = myHomardGen->CreateCaseFromCaseLastIteration( \
148 CORBA::string_dup(_aCaseName.toStdString().c_str()), \
149 CORBA::string_dup(_aDirNameStart.toStdString().c_str()) );
151 catch( SALOME::SALOME_Exception& S_ex )
153 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
154 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
159 case 3 : // Poursuite a partir d'une iteration dans un cas
163 MESSAGE("Poursuite a partir d'une iteration dans un cas");
164 aCase = myHomardGen->CreateCaseFromCaseIteration( \
165 CORBA::string_dup(_aCaseName.toStdString().c_str()), \
166 CORBA::string_dup(_aDirNameStart.toStdString().c_str()), \
169 catch( SALOME::SALOME_Exception& S_ex )
171 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
172 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
179 HOMARD_UTILS::updateObjBrowser();
183 // ---------------------------
184 void MonPursueIteration::PushOnOK()
185 // ---------------------------
187 bool bOK = PushOnApply();
188 if ( bOK ) this->close();
190 //------------------------------
191 void MonPursueIteration::PushOnHelp()
192 //-------------------------------
194 char* LanguageShort = myHomardGen->GetLanguageShort();
195 HOMARD_UTILS::PushOnHelp(QString("gui_create_case.html"), QString(""), QString(LanguageShort));
197 // ---------------------------------
198 void MonPursueIteration::SetNewCaseName()
199 // ------------------------------
201 HOMARD::listeCases_var MyCases = myHomardGen->GetAllCasesName();
202 int num = 0; QString aCaseName="";
203 while (aCaseName=="" )
205 aCaseName.setNum(num+1) ;
206 aCaseName.insert(0, QString("Case_")) ;
207 for ( int i=0; i<MyCases->length(); i++)
209 if ( aCaseName == QString((MyCases)[i]))
217 LECaseName->clear() ;
218 LECaseName->insert(aCaseName);
220 // ------------------------------------------------------------------------
221 void MonPursueIteration::SetDirName()
222 // ------------------------------------------------------------------------
224 QString aDirName=QFileDialog::getExistingDirectory ();
225 if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
227 // ------------------------------------------------------------------------
228 void MonPursueIteration::SetDirNameStart()
229 // ------------------------------------------------------------------------
231 QString aDirName=QFileDialog::getExistingDirectory ();
232 if (!(aDirName.isEmpty()))LEDirNameStart->setText(aDirName);
234 // ------------------------------------------------------------------------
235 void MonPursueIteration::FromIteration()
236 // ------------------------------------------------------------------------
238 GBIterationintoCase->setVisible(0);
239 spinBoxNumber->setVisible(0);
243 // ------------------------------------------------------------------------
244 void MonPursueIteration::FromCase()
245 // ------------------------------------------------------------------------
247 GBIterationintoCase->setVisible(1);
250 // ------------------------------------------------------------------------
251 void MonPursueIteration::CaseLastIteration()
252 // ------------------------------------------------------------------------
254 spinBoxNumber->setVisible(0);
258 // ------------------------------------------------------------------------
259 void MonPursueIteration::CaseNIteration()
260 // ------------------------------------------------------------------------
262 spinBoxNumber->setVisible(1);