Salome HOME
Introduction de la doculmentation en anglais - phase 3
[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  * Inherits from CasHomard
36  * Sets attributes to default values
37  */
38 // -----------------------------------------------------------------------------------------
39 MonPursueIteration::MonPursueIteration (QWidget* parent, bool modal, HOMARD::HOMARD_Gen_var myHomardGen)
40     :
41     Ui_PursueIteration(),
42     _aCaseName(""), _aDirName(""), _aDirNameStart("")
43 {
44   MESSAGE("Debut du constructeur de MonPursueIteration");
45   _myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen);
46   setupUi(this);
47   setModal(modal);
48
49   InitConnect();
50
51   SetNewCaseName() ;
52   _Type = 1 ;
53   GBIterationintoCase->setVisible(0);
54   spinBoxNumber->setVisible(0);
55
56   adjustSize();
57   MESSAGE("Fin du constructeur de MonPursueIteration");
58 }
59
60 // ------------------------------------------------------------------------
61 MonPursueIteration::~MonPursueIteration()
62 // ------------------------------------------------------------------------
63 {
64     // no need to delete child widgets, Qt does it all for us
65 }
66 // ------------------------------------------------------------------------
67 void MonPursueIteration::InitConnect()
68 // ------------------------------------------------------------------------
69 {
70     connect( LECaseName,     SIGNAL(textChanged(QString)), this, SLOT(CaseNameChanged()));
71     connect( PushDir,        SIGNAL(pressed()), this, SLOT(SetDirName()));
72
73     connect( RBIteration,    SIGNAL(clicked()), this, SLOT(FromIteration()));
74     connect( RBCase,         SIGNAL(clicked()), this, SLOT(FromCase()));
75     connect( PushDirStart,   SIGNAL(pressed()), this, SLOT(SetDirNameStart()));
76
77     connect( RBCaseLastIteration, SIGNAL(clicked()), this, SLOT(CaseLastIteration()));
78     connect( RBCaseNIteration,    SIGNAL(clicked()), this, SLOT(CaseNIteration()));
79
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()));
84 }
85 // -------------------------------
86 bool MonPursueIteration::PushOnApply()
87 // --------------------------------
88 {
89   MESSAGE("PushOnApply");
90
91   QString aDirName=LEDirName->text().trimmed();
92   if (aDirName == QString(""))
93   {
94     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
95                               QObject::tr("HOM_CASE_DIRECTORY_1") );
96     return false;
97   }
98   if ((aDirName != _aDirName) and (_myHomardGen->VerifieDir( aDirName.toStdString().c_str()) == false))
99   {
100     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
101                               QObject::tr("HOM_CASE_DIRECTORY_2") );
102     return false;
103   }
104   if (chdir(aDirName.toStdString().c_str()) != 0)
105   {
106     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
107                               QObject::tr("HOM_CASE_DIRECTORY_3") );
108     return false;
109   }
110
111 // Enregistrement du numero d'iteration
112   int Number ;
113   if ( _Type == 3 ) { Number = spinBoxNumber->value() ; }
114
115 // Creation du cas
116   QString _aCaseName=LECaseName->text().trimmed();
117
118   MESSAGE("_Type = "<<_Type);
119   switch (_Type)
120   {
121     case 1 : // Poursuite a partir d'une iteration
122     {
123       try
124       {
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()) );
129       }
130       catch( SALOME::SALOME_Exception& S_ex )
131       {
132         QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
133                                   QObject::tr(CORBA::string_dup(S_ex.details.text)) );
134         return false ;
135       }
136       break;
137     }
138     case 2 : // Poursuite a partir de la derniere iteration dans un cas
139     {
140       try
141       {
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()) );
146       }
147       catch( SALOME::SALOME_Exception& S_ex )
148       {
149         QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
150                                   QObject::tr(CORBA::string_dup(S_ex.details.text)) );
151         return false ;
152       }
153       break;
154     }
155     case 3 : // Poursuite a partir d'une iteration dans un cas
156     {
157       try
158       {
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()),  \
163                   Number );
164       }
165       catch( SALOME::SALOME_Exception& S_ex )
166       {
167         QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
168                                   QObject::tr(CORBA::string_dup(S_ex.details.text)) );
169         return false ;
170       }
171       break;
172     }
173   }
174
175   HOMARD_UTILS::updateObjBrowser();
176
177   return true;
178 }
179 // ---------------------------
180 void MonPursueIteration::PushOnOK()
181 // ---------------------------
182 {
183   bool bOK = PushOnApply();
184   if ( bOK )  this->close();
185 }
186 //------------------------------
187 void MonPursueIteration::PushOnHelp()
188 //-------------------------------
189 {
190   HOMARD_UTILS::PushOnHelp(QString("gui_create_case.html"), QString(""));
191 }
192 // ---------------------------------
193 void MonPursueIteration::SetNewCaseName()
194 // ------------------------------
195 {
196   HOMARD::listeCases_var  MyCases = _myHomardGen->GetAllCasesName();
197   int num = 0; QString aCaseName="";
198   while (aCaseName=="" )
199   {
200     aCaseName.setNum(num+1) ;
201     aCaseName.insert(0, QString("Case_")) ;
202     for ( int i=0; i<MyCases->length(); i++)
203     {
204       if ( aCaseName == QString((MyCases)[i]))
205       {
206           num += 1;
207           aCaseName = "";
208           break;
209       }
210    }
211   }
212   LECaseName->clear() ;
213   LECaseName->insert(aCaseName);
214 }
215 // ------------------------------------------------------------------------
216 void MonPursueIteration::SetDirName()
217 // ------------------------------------------------------------------------
218 {
219   QString aDirName=QFileDialog::getExistingDirectory ();
220   if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
221 }
222 // ------------------------------------------------------------------------
223 void MonPursueIteration::SetDirNameStart()
224 // ------------------------------------------------------------------------
225 {
226   QString aDirName=QFileDialog::getExistingDirectory ();
227   if (!(aDirName.isEmpty()))LEDirNameStart->setText(aDirName);
228 }
229 // ------------------------------------------------------------------------
230 void MonPursueIteration::FromIteration()
231 // ------------------------------------------------------------------------
232 {
233   GBIterationintoCase->setVisible(0);
234   spinBoxNumber->setVisible(0);
235   _Type = 1 ;
236   adjustSize();
237 }
238 // ------------------------------------------------------------------------
239 void MonPursueIteration::FromCase()
240 // ------------------------------------------------------------------------
241 {
242   GBIterationintoCase->setVisible(1);
243   CaseLastIteration();
244 }
245 // ------------------------------------------------------------------------
246 void MonPursueIteration::CaseLastIteration()
247 // ------------------------------------------------------------------------
248 {
249   spinBoxNumber->setVisible(0);
250   _Type = 2 ;
251   adjustSize();
252 }
253 // ------------------------------------------------------------------------
254 void MonPursueIteration::CaseNIteration()
255 // ------------------------------------------------------------------------
256 {
257   spinBoxNumber->setVisible(1);
258   _Type = 3 ;
259   adjustSize();
260 }