1 // Copyright (C) 2011-2024 CEA, EDF
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, or (at your option) any later version.
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"
23 #include <QFileDialog>
24 #include <QMessageBox>
26 #include "SalomeApp_Tools.h"
27 #include "HOMARDGUI_Utils.h"
28 #include "HomardQtCommun.h"
29 #include <utilities.h>
37 // -----------------------------------------------------------------------------------------
38 /* Constructs a MonPursueIteration
39 * Sets attributes to default values
41 // -----------------------------------------------------------------------------------------
42 MonPursueIteration::MonPursueIteration ( bool modal, HOMARD::HOMARD_Gen_var myHomardGen0 )
45 _aCaseName(""), _aDirName(""), _aDirNameStart("")
47 MESSAGE("Debut du constructeur de MonPursueIteration");
48 myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen0);
56 GBIterationintoCase->setVisible(0);
57 SpinBoxNumber->setVisible(0);
60 MESSAGE("Fin du constructeur de MonPursueIteration");
63 // ------------------------------------------------------------------------
64 MonPursueIteration::~MonPursueIteration()
65 // ------------------------------------------------------------------------
67 // no need to delete child widgets, Qt does it all for us
69 // ------------------------------------------------------------------------
70 void MonPursueIteration::InitConnect()
71 // ------------------------------------------------------------------------
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");
92 // 1. Enregistrement du repertoire du cas
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"),
111 if (CHDIR(aDirName.toStdString().c_str()) != 0)
113 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
114 QObject::tr("HOM_CASE_DIRECTORY_3") );
117 // 2. Enregistrement du repertoire de depart
118 QString aDirNameStart=LEDirNameStart->text().trimmed();
119 if (aDirNameStart == QString(""))
121 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
122 QObject::tr("HOM_START_DIRECTORY_1") );
125 if (CHDIR(aDirNameStart.toStdString().c_str()) != 0)
127 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
128 QObject::tr("HOM_START_DIRECTORY_3") );
132 // 3. Enregistrement du numero d'iteration
134 if ( _Type == 3 ) { Number = SpinBoxNumber->value() ; }
136 // 4. Creation du cas
137 QString _aCaseName=LECaseName->text().trimmed();
138 _aDirNameStart=aDirNameStart;
140 MESSAGE("_aCaseName = "<<_aCaseName.toStdString().c_str());
141 MESSAGE("_aDirNameStart = "<<_aDirNameStart.toStdString().c_str());
142 MESSAGE("_Type = "<<_Type);
145 case 1 : // Poursuite a partir d'une iteration
149 MESSAGE("Poursuite a partir d'une iteration");
150 aCase = myHomardGen->CreateCaseFromIteration( \
151 CORBA::string_dup(_aCaseName.toStdString().c_str()), \
152 CORBA::string_dup(_aDirNameStart.toStdString().c_str()) );
154 catch( SALOME::SALOME_Exception& S_ex )
156 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
157 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
162 case 2 : // Poursuite a partir de la derniere iteration dans un cas
166 MESSAGE("Poursuite a partir de la derniere iteration dans un cas");
167 aCase = myHomardGen->CreateCaseFromCaseLastIteration( \
168 CORBA::string_dup(_aCaseName.toStdString().c_str()), \
169 CORBA::string_dup(_aDirNameStart.toStdString().c_str()) );
171 catch( SALOME::SALOME_Exception& S_ex )
173 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
174 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
179 case 3 : // Poursuite a partir d'une iteration dans un cas
183 MESSAGE("Poursuite a partir d'une iteration dans un cas");
184 aCase = myHomardGen->CreateCaseFromCaseIteration( \
185 CORBA::string_dup(_aCaseName.toStdString().c_str()), \
186 CORBA::string_dup(_aDirNameStart.toStdString().c_str()), \
189 catch( SALOME::SALOME_Exception& S_ex )
191 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
192 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
199 aCase->SetDirName(aDirName.toStdString().c_str());
202 HOMARD_UTILS::updateObjBrowser();
206 // ---------------------------
207 void MonPursueIteration::PushOnOK()
208 // ---------------------------
210 bool bOK = PushOnApply();
211 if ( bOK ) this->close();
213 //------------------------------
214 void MonPursueIteration::PushOnHelp()
215 //-------------------------------
217 std::string LanguageShort = myHomardGen->GetLanguageShort();
218 HOMARD_UTILS::PushOnHelp(QString("gui_create_case.html"), QString(""), QString(LanguageShort.c_str()));
220 // ---------------------------------
221 void MonPursueIteration::SetNewCaseName()
222 // ------------------------------
224 HOMARD::listeCases_var MyCases = myHomardGen->GetAllCasesName();
225 int num = 0; QString aCaseName="";
226 while (aCaseName=="" )
228 aCaseName.setNum(num+1) ;
229 aCaseName.insert(0, QString("Case_")) ;
230 for ( int i=0; i<MyCases->length(); i++)
232 if ( aCaseName == QString((MyCases)[i]))
240 LECaseName->clear() ;
241 LECaseName->insert(aCaseName);
243 // ------------------------------------------------------------------------
244 void MonPursueIteration::SetDirName()
245 // ------------------------------------------------------------------------
247 QString aDirName=QFileDialog::getExistingDirectory ();
248 if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
250 // ------------------------------------------------------------------------
251 void MonPursueIteration::SetDirNameStart()
252 // ------------------------------------------------------------------------
254 QString aDirName=QFileDialog::getExistingDirectory ();
255 if (!(aDirName.isEmpty()))LEDirNameStart->setText(aDirName);
257 // ------------------------------------------------------------------------
258 void MonPursueIteration::FromIteration()
259 // ------------------------------------------------------------------------
261 GBIterationintoCase->setVisible(0);
262 SpinBoxNumber->setVisible(0);
266 // ------------------------------------------------------------------------
267 void MonPursueIteration::FromCase()
268 // ------------------------------------------------------------------------
270 GBIterationintoCase->setVisible(1);
273 // ------------------------------------------------------------------------
274 void MonPursueIteration::CaseLastIteration()
275 // ------------------------------------------------------------------------
277 SpinBoxNumber->setVisible(0);
281 // ------------------------------------------------------------------------
282 void MonPursueIteration::CaseNIteration()
283 // ------------------------------------------------------------------------
285 SpinBoxNumber->setVisible(1);