]> SALOME platform Git repositories - modules/homard.git/blob - src/HOMARDGUI/MonCreateYACS.cxx
Salome HOME
6612fba40e8ae121ae653c92e59920896522a7fd
[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 /* Constructs a MonCreateYACS
35  * Sets attributes to default values
36  */
37 // -----------------------------------------------------------------------------------------
38 MonCreateYACS::MonCreateYACS (QWidget* parent, bool modal, HOMARD::HOMARD_Gen_var myHomardGen, QString CaseName )
39     :
40     Ui_CreateYACS(),
41     _aCaseName(CaseName),
42     _aFileNameScript(""),
43     _aDirName(""),
44     _aFileNameMesh("")
45 {
46   MESSAGE("Debut du constructeur de MonCreateYACS");
47   _myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen);
48   setupUi(this);
49   setModal(modal);
50
51   InitConnect();
52
53   if (_aCaseName != QString(""))
54     { SetCaseName(); }
55   else
56     {setModal(false); /* permet selection du cas dans l arbre d etude */}
57
58   adjustSize();
59   MESSAGE("Fin du constructeur de MonCreateYACS");
60 }
61
62 // ------------------------------------------------------------------------
63 MonCreateYACS::~MonCreateYACS()
64 // ------------------------------------------------------------------------
65 {
66     // no need to delete child widgets, Qt does it all for us
67 }
68 // ------------------------------------------------------------------------
69 void MonCreateYACS::InitConnect()
70 // ------------------------------------------------------------------------
71 {
72     connect( PBCaseName,     SIGNAL(pressed()), this, SLOT(SetCaseName()));
73     connect( PushDir,        SIGNAL(pressed()), this, SLOT(SetDirName()));
74     connect( PushFile,       SIGNAL(pressed()), this, SLOT(SetFileNameScript()));
75     connect( PushFile_2,     SIGNAL(pressed()), this, SLOT(SetFileNameMesh()));
76
77     connect( RBStatic,       SIGNAL(clicked()), this, SLOT(FromIteration()));
78     connect( RBTransient,    SIGNAL(clicked()), this, SLOT(FromCase()));
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 MonCreateYACS::PushOnApply()
87 // --------------------------------
88 {
89   MESSAGE("PushOnApply");
90
91   if ( _aCaseName == QString (""))
92   {
93     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
94                               QObject::tr("HOM_CASE_NAME") );
95     return false;
96   }
97 // Le fichier du script
98   QString aFileName=LEFileNameScript->text().trimmed();
99   if (aFileName ==QString(""))
100   {
101     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
102                               QObject::tr("HOM_SCRIPT_FILE") );
103     return false;
104   }
105
106 // Le repertoire de calcul
107   QString aDirName=LEDirName->text().trimmed();
108   if (aDirName == QString(""))
109   {
110     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
111                               QObject::tr("HOM_CASE_DIRECTORY_4") );
112     return false;
113   }
114   if ((aDirName != _aDirName) and (_myHomardGen->VerifieDir( aDirName.toStdString().c_str()) == false))
115   {
116     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
117                               QObject::tr("HOM_CASE_DIRECTORY_2") );
118     return false;
119   }
120   if (chdir(aDirName.toStdString().c_str()) != 0)
121   {
122     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
123                               QObject::tr("HOM_CASE_DIRECTORY_3") );
124     return false;
125   }
126
127 // Le fichier du tout premier maillage
128   aFileName=LEFileNameMesh->text().trimmed();
129   if (aFileName ==QString(""))
130   {
131     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
132                               QObject::tr("HOM_CASE_MESH") );
133     return false;
134   }
135   QString aMeshName = HOMARD_QT_COMMUN::LireNomMaillage(aFileName);
136   if (aMeshName == "" )
137   {
138     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
139                               QObject::tr("HOM_MED_FILE_2") );
140     return false;
141   }
142
143   HOMARD_UTILS::updateObjBrowser();
144   MESSAGE ("_aCaseName.toStdString " << _aCaseName.toStdString() );
145
146   return true;
147 }
148 // ---------------------------
149 void MonCreateYACS::PushOnOK()
150 // ---------------------------
151 {
152   bool bOK = PushOnApply();
153   if ( bOK )  this->close();
154 }
155 //------------------------------
156 void MonCreateYACS::PushOnHelp()
157 //-------------------------------
158 {
159   HOMARD_UTILS::PushOnHelp(QString("gui_create_case.html"), QString(""));
160 }
161 // ------------------------------------------------------------------------
162 void MonCreateYACS::SetCaseName()
163 // ------------------------------------------------------------------------
164 {
165   MESSAGE ("SetCaseName avec _aCaseName = " << _aCaseName.toStdString() );
166   if (_aCaseName == QString(""))
167   {
168     _aCaseName=HOMARD_QT_COMMUN::SelectionArbreEtude(QString("CasHomard"), 1);
169     if (_aCaseName == QString("")) { raise();return;};
170   }
171 /*  MESSAGE ("appel de GetCase avec _aCaseName = " << _aCaseName.toStdString() );*/
172   aCase = _myHomardGen->GetCase(_aCaseName.toStdString().c_str());
173   LECaseName->setText(_aCaseName);
174 }
175 // ------------------------------------------------------------------------
176 void MonCreateYACS::SetDirName()
177 // ------------------------------------------------------------------------
178 {
179   QString aDirName=QFileDialog::getExistingDirectory ();
180   if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
181 }
182 // ------------------------------------------------------------------------
183 void MonCreateYACS::SetFileNameScript()
184 // ------------------------------------------------------------------------
185 {
186   QString fileName0 = LEFileNameScript->text().trimmed();
187   QString fileName = HOMARD_QT_COMMUN::PushNomFichier(false);
188   if (fileName.isEmpty()) fileName = fileName0 ;
189   LEFileNameScript->setText(fileName);
190 }
191 // ------------------------------------------------------------------------
192 void MonCreateYACS::SetFileNameMesh()
193 // ------------------------------------------------------------------------
194 {
195   QString fileName0 = LEFileNameMesh->text().trimmed();
196   QString fileName = HOMARD_QT_COMMUN::PushNomFichier(false);
197   if (fileName.isEmpty()) fileName = fileName0 ;
198   LEFileNameMesh->setText(fileName);
199 }