1 // Copyright (C) 2011-2012 CEA/DEN, EDF R&D
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.
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
22 #include "MonCreateYACS.h"
24 #include <QFileDialog>
25 #include <QMessageBox>
27 #include "SalomeApp_Tools.h"
28 #include "HOMARDGUI_Utils.h"
29 #include "HomardQtCommun.h"
30 #include <utilities.h>
33 // -----------------------------------------------------------------------------------------
34 /* Constructs a MonCreateYACS
35 * Sets attributes to default values
37 // -----------------------------------------------------------------------------------------
38 MonCreateYACS::MonCreateYACS (QWidget* parent, bool modal, HOMARD::HOMARD_Gen_var myHomardGen, QString CaseName )
46 MESSAGE("Debut du constructeur de MonCreateYACS");
47 _myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen);
53 if (_aCaseName != QString(""))
56 {setModal(false); /* permet selection du cas dans l arbre d etude */}
59 MESSAGE("Fin du constructeur de MonCreateYACS");
62 // ------------------------------------------------------------------------
63 MonCreateYACS::~MonCreateYACS()
64 // ------------------------------------------------------------------------
66 // no need to delete child widgets, Qt does it all for us
68 // ------------------------------------------------------------------------
69 void MonCreateYACS::InitConnect()
70 // ------------------------------------------------------------------------
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()));
77 connect( RBStatic, SIGNAL(clicked()), this, SLOT(FromIteration()));
78 connect( RBTransient, SIGNAL(clicked()), this, SLOT(FromCase()));
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()));
85 // -------------------------------
86 bool MonCreateYACS::PushOnApply()
87 // --------------------------------
89 MESSAGE("PushOnApply");
91 if ( _aCaseName == QString (""))
93 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
94 QObject::tr("HOM_CASE_NAME") );
97 // Le fichier du script
98 QString aFileName=LEFileNameScript->text().trimmed();
99 if (aFileName ==QString(""))
101 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
102 QObject::tr("HOM_SCRIPT_FILE") );
106 // Le repertoire de calcul
107 QString aDirName=LEDirName->text().trimmed();
108 if (aDirName == QString(""))
110 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
111 QObject::tr("HOM_CASE_DIRECTORY_4") );
114 if ((aDirName != _aDirName) and (_myHomardGen->VerifieDir( aDirName.toStdString().c_str()) == false))
116 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
117 QObject::tr("HOM_CASE_DIRECTORY_2") );
120 if (chdir(aDirName.toStdString().c_str()) != 0)
122 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
123 QObject::tr("HOM_CASE_DIRECTORY_3") );
127 // Le fichier du tout premier maillage
128 aFileName=LEFileNameMesh->text().trimmed();
129 if (aFileName ==QString(""))
131 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
132 QObject::tr("HOM_CASE_MESH") );
135 QString aMeshName = HOMARD_QT_COMMUN::LireNomMaillage(aFileName);
136 if (aMeshName == "" )
138 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
139 QObject::tr("HOM_MED_FILE_2") );
143 HOMARD_UTILS::updateObjBrowser();
144 MESSAGE ("_aCaseName.toStdString " << _aCaseName.toStdString() );
148 // ---------------------------
149 void MonCreateYACS::PushOnOK()
150 // ---------------------------
152 bool bOK = PushOnApply();
153 if ( bOK ) this->close();
155 //------------------------------
156 void MonCreateYACS::PushOnHelp()
157 //-------------------------------
159 HOMARD_UTILS::PushOnHelp(QString("gui_create_case.html"), QString(""));
161 // ------------------------------------------------------------------------
162 void MonCreateYACS::SetCaseName()
163 // ------------------------------------------------------------------------
165 MESSAGE ("SetCaseName avec _aCaseName = " << _aCaseName.toStdString() );
166 if (_aCaseName == QString(""))
168 _aCaseName=HOMARD_QT_COMMUN::SelectionArbreEtude(QString("CasHomard"), 1);
169 if (_aCaseName == QString("")) { raise();return;};
171 /* MESSAGE ("appel de GetCase avec _aCaseName = " << _aCaseName.toStdString() );*/
172 aCase = _myHomardGen->GetCase(_aCaseName.toStdString().c_str());
173 LECaseName->setText(_aCaseName);
175 // ------------------------------------------------------------------------
176 void MonCreateYACS::SetDirName()
177 // ------------------------------------------------------------------------
179 QString aDirName=QFileDialog::getExistingDirectory ();
180 if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
182 // ------------------------------------------------------------------------
183 void MonCreateYACS::SetFileNameScript()
184 // ------------------------------------------------------------------------
186 QString fileName0 = LEFileNameScript->text().trimmed();
187 QString fileName = HOMARD_QT_COMMUN::PushNomFichier(false);
188 if (fileName.isEmpty()) fileName = fileName0 ;
189 LEFileNameScript->setText(fileName);
191 // ------------------------------------------------------------------------
192 void MonCreateYACS::SetFileNameMesh()
193 // ------------------------------------------------------------------------
195 QString fileName0 = LEFileNameMesh->text().trimmed();
196 QString fileName = HOMARD_QT_COMMUN::PushNomFichier(false);
197 if (fileName.isEmpty()) fileName = fileName0 ;
198 LEFileNameMesh->setText(fileName);