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);
55 if (_aCaseName != QString(""))
58 {setModal(false); /* permet selection du cas dans l arbre d etude */}
61 MESSAGE("Fin du constructeur de MonCreateYACS");
64 // ------------------------------------------------------------------------
65 MonCreateYACS::~MonCreateYACS()
66 // ------------------------------------------------------------------------
68 // no need to delete child widgets, Qt does it all for us
70 // ------------------------------------------------------------------------
71 void MonCreateYACS::InitConnect()
72 // ------------------------------------------------------------------------
74 connect( PBCaseName, SIGNAL(pressed()), this, SLOT(SetCaseName()));
75 connect( PushDir, SIGNAL(pressed()), this, SLOT(SetDirName()));
76 connect( PushFile, SIGNAL(pressed()), this, SLOT(SetScriptFile()));
77 connect( PushFile_2, SIGNAL(pressed()), this, SLOT(SetMeshFile()));
79 connect( RBStatic, SIGNAL(clicked()), this, SLOT(SetType(1)));
80 connect( RBTransient, SIGNAL(clicked()), this, SLOT(SetType(2)));
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 MonCreateYACS::PushOnApply()
89 // --------------------------------
91 MESSAGE("PushOnApply");
93 if ( _aCaseName == QString (""))
95 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
96 QObject::tr("HOM_CASE_NAME") );
99 // Le fichier du script
100 QString aFileName=LEScriptFile->text().trimmed();
101 if (aFileName ==QString(""))
103 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
104 QObject::tr("HOM_SCRIPT_FILE") );
108 // Le repertoire de calcul
109 QString aDirName=LEDirName->text().trimmed();
110 if (aDirName == QString(""))
112 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
113 QObject::tr("HOM_CASE_DIRECTORY_4") );
116 if ((aDirName != _aDirName) and (myHomardGen->VerifieDir( aDirName.toStdString().c_str()) == false))
118 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
119 QObject::tr("HOM_CASE_DIRECTORY_2") );
122 if (chdir(aDirName.toStdString().c_str()) != 0)
124 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
125 QObject::tr("HOM_CASE_DIRECTORY_3") );
129 // Le fichier du tout premier maillage
130 aFileName=LEMeshFile->text().trimmed();
131 if (aFileName ==QString(""))
133 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
134 QObject::tr("HOM_CASE_MESH") );
137 QString aMeshName = HOMARD_QT_COMMUN::LireNomMaillage(aFileName);
138 if (aMeshName == "" )
140 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
141 QObject::tr("HOM_MED_FILE_2") );
145 HOMARD_UTILS::updateObjBrowser();
146 MESSAGE ("_aCaseName.toStdString " << _aCaseName.toStdString() );
148 // Creation de l'objet CORBA
151 _Name=LEName->text().trimmed();
152 aYACS=myHomardGen->CreateYACSSchema(CORBA::string_dup(_Name.toStdString().c_str()), _aCaseName.toStdString().c_str(), _aScriptFile.toStdString().c_str(), _aDirName.toStdString().c_str(), _aMeshFile.toStdString().c_str());
153 // _parent->AddYACS(_Name);
155 catch( SALOME::SALOME_Exception& S_ex )
157 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
158 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
164 // ---------------------------
165 void MonCreateYACS::PushOnOK()
166 // ---------------------------
168 bool bOK = PushOnApply();
169 if ( bOK ) this->close();
171 //------------------------------
172 void MonCreateYACS::PushOnHelp()
173 //-------------------------------
175 HOMARD_UTILS::PushOnHelp(QString("gui_create_case.html"), QString(""));
177 // -------------------------------------------------
178 void MonCreateYACS::SetNewName()
179 // --------------------------------------------------
182 HOMARD::listeYACSs_var MyObjects = myHomardGen->GetAllYACSsName();
183 int num = 0; QString aName="";
184 while (aName == QString("") )
186 aName.setNum(num+1) ;
187 aName.insert(0, QString("YACS_")) ;
188 for ( int i=0; i<MyObjects->length(); i++)
190 if ( aName == QString(MyObjects[i]))
198 LEName->setText(aName);
200 // ------------------------------------------------------------------------
201 void MonCreateYACS::SetCaseName()
202 // ------------------------------------------------------------------------
204 MESSAGE ("SetCaseName avec _aCaseName = " << _aCaseName.toStdString() );
205 if (_aCaseName == QString(""))
207 _aCaseName=HOMARD_QT_COMMUN::SelectionArbreEtude(QString("CasHomard"), 1);
208 if (_aCaseName == QString("")) { raise();return;};
210 /* MESSAGE ("appel de GetCase avec _aCaseName = " << _aCaseName.toStdString() );*/
211 aCase = myHomardGen->GetCase(_aCaseName.toStdString().c_str());
212 LECaseName->setText(_aCaseName);
214 // ------------------------------------------------------------------------
215 void MonCreateYACS::SetDirName()
216 // ------------------------------------------------------------------------
218 QString aDirName=QFileDialog::getExistingDirectory ();
219 if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
221 // ------------------------------------------------------------------------
222 void MonCreateYACS::SetScriptFile()
223 // ------------------------------------------------------------------------
225 QString fileName0 = LEScriptFile->text().trimmed();
226 QString fileName = HOMARD_QT_COMMUN::PushNomFichier(false);
227 if (fileName.isEmpty()) fileName = fileName0 ;
228 LEScriptFile->setText(fileName);
230 // ------------------------------------------------------------------------
231 void MonCreateYACS::SetMeshFile()
232 // ------------------------------------------------------------------------
234 QString fileName0 = LEMeshFile->text().trimmed();
235 QString fileName = HOMARD_QT_COMMUN::PushNomFichier(false);
236 if (fileName.isEmpty()) fileName = fileName0 ;
237 LEMeshFile->setText(fileName);
239 // ------------------------------------------------------------------------
240 void MonCreateYACS::SetType(int Type)
241 // ------------------------------------------------------------------------