]> SALOME platform Git repositories - modules/homard.git/blob - src/HOMARDGUI/MonPursueIteration.cxx
Salome HOME
Message d'erreur en cas de mauvais répertoire pour le cas en GUI
[modules/homard.git] / src / HOMARDGUI / MonPursueIteration.cxx
1 // Copyright (C) 2011-2012  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 using namespace std;
21
22 #include "MonPursueIteration.h"
23
24 #include <QFileDialog>
25 #include <QMessageBox>
26
27 #include "SalomeApp_Tools.h"
28 #include "HOMARDGUI_Utils.h"
29 #include "HomardQtCommun.h"
30 #include <utilities.h>
31
32
33 // -----------------------------------------------------------------------------------------
34 /* Constructs a MonPursueIteration
35  * Sets attributes to default values
36  */
37 // -----------------------------------------------------------------------------------------
38 MonPursueIteration::MonPursueIteration (QWidget* parent, bool modal, HOMARD::HOMARD_Gen_var myHomardGen)
39     :
40     Ui_PursueIteration(),
41     _aCaseName(""), _aDirName(""), _aDirNameStart("")
42 {
43   MESSAGE("Debut du constructeur de MonPursueIteration");
44   myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen);
45   setupUi(this);
46   setModal(modal);
47
48   InitConnect();
49
50   SetNewCaseName() ;
51   _Type = 1 ;
52   GBIterationintoCase->setVisible(0);
53   spinBoxNumber->setVisible(0);
54
55   adjustSize();
56   MESSAGE("Fin du constructeur de MonPursueIteration");
57 }
58
59 // ------------------------------------------------------------------------
60 MonPursueIteration::~MonPursueIteration()
61 // ------------------------------------------------------------------------
62 {
63     // no need to delete child widgets, Qt does it all for us
64 }
65 // ------------------------------------------------------------------------
66 void MonPursueIteration::InitConnect()
67 // ------------------------------------------------------------------------
68 {
69     connect( LECaseName,     SIGNAL(textChanged(QString)), this, SLOT(CaseNameChanged()));
70     connect( PushDir,        SIGNAL(pressed()), this, SLOT(SetDirName()));
71
72     connect( RBIteration,    SIGNAL(clicked()), this, SLOT(FromIteration()));
73     connect( RBCase,         SIGNAL(clicked()), this, SLOT(FromCase()));
74     connect( PushDirStart,   SIGNAL(pressed()), this, SLOT(SetDirNameStart()));
75
76     connect( RBCaseLastIteration, SIGNAL(clicked()), this, SLOT(CaseLastIteration()));
77     connect( RBCaseNIteration,    SIGNAL(clicked()), this, SLOT(CaseNIteration()));
78
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()));
83 }
84 // -------------------------------
85 bool MonPursueIteration::PushOnApply()
86 // --------------------------------
87 {
88   MESSAGE("PushOnApply");
89
90   QString aDirName=LEDirName->text().trimmed();
91   if (aDirName == QString(""))
92   {
93     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
94                               QObject::tr("HOM_CASE_DIRECTORY_1") );
95     return false;
96   }
97   if ( aDirName != _aDirName)
98   { QString CaseNameDir = myHomardGen->VerifieDir( aDirName.toStdString().c_str()) ;
99     if ( CaseNameDir != "" )
100     {
101       INFOS(CaseNameDir.toStdString().c_str());
102       QString texte ;
103       texte = QObject::tr("HOM_CASE_DIRECTORY_2") + CaseNameDir ;
104       QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
105                                 texte );
106       return false;
107     }
108   }
109   if (chdir(aDirName.toStdString().c_str()) != 0)
110   {
111     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
112                               QObject::tr("HOM_CASE_DIRECTORY_3") );
113     return false;
114   }
115
116 // Enregistrement du numero d'iteration
117   int Number ;
118   if ( _Type == 3 ) { Number = spinBoxNumber->value() ; }
119
120 // Creation du cas
121   QString _aCaseName=LECaseName->text().trimmed();
122
123   MESSAGE("_Type = "<<_Type);
124   switch (_Type)
125   {
126     case 1 : // Poursuite a partir d'une iteration
127     {
128       try
129       {
130         MESSAGE("Poursuite a partir d'une iteration");
131         aCase = myHomardGen->CreateCaseFromIteration( \
132                   CORBA::string_dup(_aCaseName.toStdString().c_str()),  \
133                   CORBA::string_dup(_aDirNameStart.toStdString().c_str()) );
134       }
135       catch( SALOME::SALOME_Exception& S_ex )
136       {
137         QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
138                                   QObject::tr(CORBA::string_dup(S_ex.details.text)) );
139         return false ;
140       }
141       break;
142     }
143     case 2 : // Poursuite a partir de la derniere iteration dans un cas
144     {
145       try
146       {
147         MESSAGE("Poursuite a partir de la derniere iteration dans un cas");
148         aCase = myHomardGen->CreateCaseFromCaseLastIteration( \
149                   CORBA::string_dup(_aCaseName.toStdString().c_str()),  \
150                   CORBA::string_dup(_aDirNameStart.toStdString().c_str()) );
151       }
152       catch( SALOME::SALOME_Exception& S_ex )
153       {
154         QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
155                                   QObject::tr(CORBA::string_dup(S_ex.details.text)) );
156         return false ;
157       }
158       break;
159     }
160     case 3 : // Poursuite a partir d'une iteration dans un cas
161     {
162       try
163       {
164         MESSAGE("Poursuite a partir d'une iteration dans un cas");
165         aCase = myHomardGen->CreateCaseFromCaseIteration( \
166                   CORBA::string_dup(_aCaseName.toStdString().c_str()),  \
167                   CORBA::string_dup(_aDirNameStart.toStdString().c_str()),  \
168                   Number );
169       }
170       catch( SALOME::SALOME_Exception& S_ex )
171       {
172         QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
173                                   QObject::tr(CORBA::string_dup(S_ex.details.text)) );
174         return false ;
175       }
176       break;
177     }
178   }
179
180   HOMARD_UTILS::updateObjBrowser();
181
182   return true;
183 }
184 // ---------------------------
185 void MonPursueIteration::PushOnOK()
186 // ---------------------------
187 {
188   bool bOK = PushOnApply();
189   if ( bOK )  this->close();
190 }
191 //------------------------------
192 void MonPursueIteration::PushOnHelp()
193 //-------------------------------
194 {
195   char* LanguageShort = myHomardGen->GetLanguageShort();
196   HOMARD_UTILS::PushOnHelp(QString("gui_create_case.html"), QString(""), QString(LanguageShort));
197 }
198 // ---------------------------------
199 void MonPursueIteration::SetNewCaseName()
200 // ------------------------------
201 {
202   HOMARD::listeCases_var  MyCases = myHomardGen->GetAllCasesName();
203   int num = 0; QString aCaseName="";
204   while (aCaseName=="" )
205   {
206     aCaseName.setNum(num+1) ;
207     aCaseName.insert(0, QString("Case_")) ;
208     for ( int i=0; i<MyCases->length(); i++)
209     {
210       if ( aCaseName == QString((MyCases)[i]))
211       {
212           num += 1;
213           aCaseName = "";
214           break;
215       }
216    }
217   }
218   LECaseName->clear() ;
219   LECaseName->insert(aCaseName);
220 }
221 // ------------------------------------------------------------------------
222 void MonPursueIteration::SetDirName()
223 // ------------------------------------------------------------------------
224 {
225   QString aDirName=QFileDialog::getExistingDirectory ();
226   if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
227 }
228 // ------------------------------------------------------------------------
229 void MonPursueIteration::SetDirNameStart()
230 // ------------------------------------------------------------------------
231 {
232   QString aDirName=QFileDialog::getExistingDirectory ();
233   if (!(aDirName.isEmpty()))LEDirNameStart->setText(aDirName);
234 }
235 // ------------------------------------------------------------------------
236 void MonPursueIteration::FromIteration()
237 // ------------------------------------------------------------------------
238 {
239   GBIterationintoCase->setVisible(0);
240   spinBoxNumber->setVisible(0);
241   _Type = 1 ;
242   adjustSize();
243 }
244 // ------------------------------------------------------------------------
245 void MonPursueIteration::FromCase()
246 // ------------------------------------------------------------------------
247 {
248   GBIterationintoCase->setVisible(1);
249   CaseLastIteration();
250 }
251 // ------------------------------------------------------------------------
252 void MonPursueIteration::CaseLastIteration()
253 // ------------------------------------------------------------------------
254 {
255   spinBoxNumber->setVisible(0);
256   _Type = 2 ;
257   adjustSize();
258 }
259 // ------------------------------------------------------------------------
260 void MonPursueIteration::CaseNIteration()
261 // ------------------------------------------------------------------------
262 {
263   spinBoxNumber->setVisible(1);
264   _Type = 3 ;
265   adjustSize();
266 }