]> SALOME platform Git repositories - modules/homard.git/blob - src/HOMARDGUI/MonCreateYACS.cxx
Salome HOME
Reorganisation des cas-tests et des tutoriaux
[modules/homard.git] / src / HOMARDGUI / MonCreateYACS.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 "MonCreateYACS.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 MonCreateYACS::MonCreateYACS (bool modal, HOMARD::HOMARD_Gen_var myHomardGen0, QString CaseName ):
35 // ----------------------------------------------------------------------
36 /* Constructs a MonCreateYACS
37  * Sets attributes to default values
38  */
39 // ----------------------------------------------------------------------
40   Ui_CreateYACS(),
41   _aCaseName(CaseName),
42   _aScriptFile(""),
43   _aDirName(""),
44   _aMeshFile(""),
45   _Type(1)
46   // La valeur de _Type doit etre la meme que celle dans HOMARD_Gen_i::CreateYACSSchema
47   // et doit correspondre aux defauts des boutons
48   {
49 //     MESSAGE("Debut du constructeur de MonCreateYACS");
50     myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen0);
51     setupUi(this);
52     setModal(modal);
53
54     InitConnect();
55
56     SetNewName() ;
57
58     if (_aCaseName != QString(""))
59       { SetCaseName(); }
60     else
61       {setModal(false); /* permet selection du cas dans l arbre d etude */}
62
63     adjustSize();
64 //     MESSAGE("Fin du constructeur de MonCreateYACS");
65   }
66
67 // ----------------------------------------------------------------------
68 MonCreateYACS::MonCreateYACS(HOMARD::HOMARD_Gen_var myHomardGen0,
69                              QString caseName):
70 // ----------------------------------------------------------------------
71 // Constructeur appele par MonEditYACS
72 //
73     myHomardGen(myHomardGen0),
74     _Name (""),
75     Chgt (false)
76     {
77 //       MESSAGE("Debut du constructeur de MonCreateYACS appele par MonEditYACS");
78       setupUi(this) ;
79
80       setModal(true) ;
81       InitConnect() ;
82     }
83
84 // ------------------------------------------------------------------------
85 MonCreateYACS::~MonCreateYACS()
86 // ------------------------------------------------------------------------
87 {
88     // no need to delete child widgets, Qt does it all for us
89 }
90 // ------------------------------------------------------------------------
91 void MonCreateYACS::InitConnect()
92 // ------------------------------------------------------------------------
93 {
94     connect( PBCaseName,     SIGNAL(pressed()), this, SLOT(SetCaseName()));
95     connect( PBScriptFile,   SIGNAL(pressed()), this, SLOT(SetScriptFile()));
96     connect( PBDir,          SIGNAL(pressed()), this, SLOT(SetDirName()));
97     connect( PBMeshFile,     SIGNAL(pressed()), this, SLOT(SetMeshFile()));
98
99     connect( RBConstant,     SIGNAL(clicked()), this, SLOT(SetConstant()));
100     connect( RBVariable,     SIGNAL(clicked()), this, SLOT(SetVariable()));
101
102     connect( buttonOk,       SIGNAL(pressed()), this, SLOT(PushOnOK()));
103     connect( buttonApply,    SIGNAL(pressed()), this, SLOT(PushOnApply()));
104     connect( buttonCancel,   SIGNAL(pressed()), this, SLOT(close()));
105     connect( buttonHelp,     SIGNAL(pressed()), this, SLOT(PushOnHelp()));
106 }
107 // -------------------------------
108 bool MonCreateYACS::PushOnApply()
109 // --------------------------------
110 {
111   MESSAGE("PushOnApply");
112
113 // Le fichier du script
114   QString aFileName=LEScriptFile->text().trimmed();
115   if (aFileName ==QString(""))
116   {
117     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
118                               QObject::tr("HOM_SCRIPT_FILE") );
119     return false;
120   }
121
122 // Le repertoire de calcul
123   QString aDirName=LEDirName->text().trimmed();
124   if (aDirName == QString(""))
125   {
126     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
127                               QObject::tr("HOM_CASE_DIRECTORY_4") );
128     return false;
129   }
130   if ( aDirName != _aDirName)
131   { QString CaseNameDir = myHomardGen->VerifieDir( aDirName.toStdString().c_str()) ;
132     if ( CaseNameDir != "" )
133     {
134       QString texte ;
135       texte = QObject::tr("HOM_CASE_DIRECTORY_2") + CaseNameDir ;
136       QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
137                                 texte );
138       return false;
139     }
140   }
141   if (chdir(aDirName.toStdString().c_str()) != 0)
142   {
143     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
144                               QObject::tr("HOM_CASE_DIRECTORY_3") );
145     return false;
146   }
147
148 // Le fichier du tout premier maillage
149   aFileName=LEMeshFile->text().trimmed();
150   if (aFileName ==QString(""))
151   {
152     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
153                               QObject::tr("HOM_CASE_MESH") );
154     return false;
155   }
156   QString aMeshName = HOMARD_QT_COMMUN::LireNomMaillage(aFileName);
157   if (aMeshName == "" )
158   {
159     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
160                               QObject::tr("HOM_MED_FILE_2") );
161     return false;
162   }
163
164   bool bOK = CreateOrUpdate() ;
165
166   if ( bOK ) { HOMARD_UTILS::updateObjBrowser() ; }
167
168   return bOK;
169 }
170 // ---------------------------------------------------
171 bool MonCreateYACS:: CreateOrUpdate()
172 //----------------------------------------------------
173 //  Creation ou modification du schema
174 {
175   MESSAGE("CreateOrUpdate");
176   bool bOK = true ;
177
178   // Le cas
179   if ( _aCaseName == QString (""))
180   {
181     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
182                               QObject::tr("HOM_CASE_NAME") );
183     return false;
184   }
185   // Les donnees
186   QString aScriptFile=LEScriptFile->text().trimmed();
187   if ( aScriptFile != _aScriptFile )
188   {
189     _aScriptFile = aScriptFile ;
190     Chgt = true ;
191   }
192   QString aDirName=LEDirName->text().trimmed();
193   if ( aDirName != _aDirName )
194   {
195     _aDirName = aDirName ;
196     Chgt = true ;
197   }
198   QString aMeshFile=LEMeshFile->text().trimmed();
199   if ( aMeshFile != _aMeshFile )
200   {
201     _aMeshFile = aMeshFile ;
202     Chgt = true ;
203   }
204
205   // Creation de l'objet CORBA
206   try
207   {
208     _Name=LEName->text().trimmed();
209     aYACS=myHomardGen->CreateYACSSchema(CORBA::string_dup(_Name.toStdString().c_str()), CORBA::string_dup(_aCaseName.toStdString().c_str()), CORBA::string_dup(_aScriptFile.toStdString().c_str()), CORBA::string_dup(_aDirName.toStdString().c_str()), CORBA::string_dup(_aMeshFile.toStdString().c_str()));
210   }
211   catch( SALOME::SALOME_Exception& S_ex )
212   {
213     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
214                               QObject::tr(CORBA::string_dup(S_ex.details.text)) );
215     bOK = false;
216   }
217
218   // Options
219   if ( bOK )
220   { aYACS->SetType(_Type) ; }
221
222   // Ecriture du fichier
223   if ( bOK )
224   {
225     int codret = aYACS->Write() ;
226     if ( codret != 0 ) { bOK = false ; }
227   }
228
229   return bOK;
230 }
231 // ---------------------------
232 void MonCreateYACS::PushOnOK()
233 // ---------------------------
234 {
235   bool bOK = PushOnApply();
236   if ( bOK ) this->close();
237 }
238 //------------------------------
239 void MonCreateYACS::PushOnHelp()
240 //-------------------------------
241 {
242   char* LanguageShort = myHomardGen->GetLanguageShort();
243   HOMARD_UTILS::PushOnHelp(QString("yacs.html"), QString(""), QString(LanguageShort));
244 }
245 // -------------------------------------------------
246 void MonCreateYACS::SetNewName()
247 // --------------------------------------------------
248 {
249
250   HOMARD::listeYACSs_var MyObjects = myHomardGen->GetAllYACSsName();
251   int num = 0; QString aName="";
252   while (aName == QString("") )
253   {
254     aName.setNum(num+1) ;
255     aName.insert(0, QString("YACS_")) ;
256     for ( int i=0; i<MyObjects->length(); i++)
257     {
258       if ( aName ==  QString(MyObjects[i]))
259       {
260           num=num+1;
261           aName="";
262           break;
263       }
264    }
265   }
266   LEName->setText(aName);
267 }
268 // ------------------------------------------------------------------------
269 void MonCreateYACS::SetCaseName()
270 // ------------------------------------------------------------------------
271 {
272   MESSAGE ("SetCaseName avec _aCaseName = " << _aCaseName.toStdString() );
273   if (_aCaseName == QString(""))
274   {
275     _aCaseName=HOMARD_QT_COMMUN::SelectionArbreEtude(QString("CasHomard"), 1);
276     if (_aCaseName == QString("")) { raise();return;};
277   }
278   LECaseName->setText(_aCaseName);
279 }
280 // ------------------------------------------------------------------------
281 void MonCreateYACS::SetDirName()
282 // ------------------------------------------------------------------------
283 {
284   QString aDirName=QFileDialog::getExistingDirectory ();
285   if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
286 }
287 // ------------------------------------------------------------------------
288 void MonCreateYACS::SetScriptFile()
289 // ------------------------------------------------------------------------
290 {
291   QString fileName0 = LEScriptFile->text().trimmed();
292   QString fileName = HOMARD_QT_COMMUN::PushNomFichier(false);
293   if (fileName.isEmpty()) fileName = fileName0 ;
294   LEScriptFile->setText(fileName);
295 }
296 // ------------------------------------------------------------------------
297 void MonCreateYACS::SetMeshFile()
298 // ------------------------------------------------------------------------
299 {
300   QString fileName0 = LEMeshFile->text().trimmed();
301   QString fileName = HOMARD_QT_COMMUN::PushNomFichier(false);
302   if (fileName.isEmpty()) fileName = fileName0 ;
303   LEMeshFile->setText(fileName);
304 }
305 // ------------------------------------------------------------------------
306 void MonCreateYACS::SetConstant()
307 // ------------------------------------------------------------------------
308 {
309   _Type = 1 ;
310 }
311 // ------------------------------------------------------------------------
312 void MonCreateYACS::SetVariable()
313 // ------------------------------------------------------------------------
314 {
315   _Type = 2 ;
316 }