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