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 myHomardGen0, QString CaseName )
46 MESSAGE("Debut du constructeur de MonCreateYACS");
47 myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen0);
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(QWidget* parent,
66 HOMARD::HOMARD_Gen_var myHomardGen0,
68 // ----------------------------------------------------------------------
69 // Constructeur appele par MonEditYACS
71 myHomardGen(myHomardGen0),
75 // MESSAGE("Debut de MonCreateYACS")
82 // ------------------------------------------------------------------------
83 MonCreateYACS::~MonCreateYACS()
84 // ------------------------------------------------------------------------
86 // no need to delete child widgets, Qt does it all for us
88 // ------------------------------------------------------------------------
89 void MonCreateYACS::InitConnect()
90 // ------------------------------------------------------------------------
92 connect( PBCaseName, SIGNAL(pressed()), this, SLOT(SetCaseName()));
93 connect( PushDir, SIGNAL(pressed()), this, SLOT(SetDirName()));
94 connect( PushFile, SIGNAL(pressed()), this, SLOT(SetScriptFile()));
95 connect( PushFile_2, SIGNAL(pressed()), this, SLOT(SetMeshFile()));
97 connect( RBStatic, SIGNAL(clicked()), this, SLOT(SetType(1)));
98 connect( RBTransient, SIGNAL(clicked()), this, SLOT(SetType(2)));
100 connect( buttonOk, SIGNAL(pressed()), this, SLOT(PushOnOK()));
101 connect( buttonApply, SIGNAL(pressed()), this, SLOT(PushOnApply()));
102 connect( buttonCancel, SIGNAL(pressed()), this, SLOT(close()));
103 connect( buttonHelp, SIGNAL(pressed()), this, SLOT(PushOnHelp()));
105 // -------------------------------
106 bool MonCreateYACS::PushOnApply()
107 // --------------------------------
109 MESSAGE("PushOnApply");
111 if ( _aCaseName == QString (""))
113 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
114 QObject::tr("HOM_CASE_NAME") );
117 // Le fichier du script
118 QString aFileName=LEScriptFile->text().trimmed();
119 if (aFileName ==QString(""))
121 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
122 QObject::tr("HOM_SCRIPT_FILE") );
126 // Le repertoire de calcul
127 QString aDirName=LEDirName->text().trimmed();
128 if (aDirName == QString(""))
130 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
131 QObject::tr("HOM_CASE_DIRECTORY_4") );
134 if ((aDirName != _aDirName) and (myHomardGen->VerifieDir( aDirName.toStdString().c_str()) == false))
136 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
137 QObject::tr("HOM_CASE_DIRECTORY_2") );
140 if (chdir(aDirName.toStdString().c_str()) != 0)
142 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
143 QObject::tr("HOM_CASE_DIRECTORY_3") );
147 // Le fichier du tout premier maillage
148 aFileName=LEMeshFile->text().trimmed();
149 if (aFileName ==QString(""))
151 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
152 QObject::tr("HOM_CASE_MESH") );
155 QString aMeshName = HOMARD_QT_COMMUN::LireNomMaillage(aFileName);
156 if (aMeshName == "" )
158 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
159 QObject::tr("HOM_MED_FILE_2") );
163 HOMARD_UTILS::updateObjBrowser();
164 MESSAGE ("_aCaseName.toStdString " << _aCaseName.toStdString() );
166 // Creation de l'objet CORBA
169 _Name=LEName->text().trimmed();
170 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());
171 // _parent->AddYACS(_Name);
173 catch( SALOME::SALOME_Exception& S_ex )
175 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
176 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
182 // ---------------------------
183 void MonCreateYACS::PushOnOK()
184 // ---------------------------
186 bool bOK = PushOnApply();
187 if ( bOK ) this->close();
189 //------------------------------
190 void MonCreateYACS::PushOnHelp()
191 //-------------------------------
193 HOMARD_UTILS::PushOnHelp(QString("gui_create_case.html"), QString(""));
195 // -------------------------------------------------
196 void MonCreateYACS::SetNewName()
197 // --------------------------------------------------
200 HOMARD::listeYACSs_var MyObjects = myHomardGen->GetAllYACSsName();
201 int num = 0; QString aName="";
202 while (aName == QString("") )
204 aName.setNum(num+1) ;
205 aName.insert(0, QString("YACS_")) ;
206 for ( int i=0; i<MyObjects->length(); i++)
208 if ( aName == QString(MyObjects[i]))
216 LEName->setText(aName);
218 // ------------------------------------------------------------------------
219 void MonCreateYACS::SetCaseName()
220 // ------------------------------------------------------------------------
222 MESSAGE ("SetCaseName avec _aCaseName = " << _aCaseName.toStdString() );
223 if (_aCaseName == QString(""))
225 _aCaseName=HOMARD_QT_COMMUN::SelectionArbreEtude(QString("CasHomard"), 1);
226 if (_aCaseName == QString("")) { raise();return;};
228 /* MESSAGE ("appel de GetCase avec _aCaseName = " << _aCaseName.toStdString() );*/
229 aCase = myHomardGen->GetCase(_aCaseName.toStdString().c_str());
230 LECaseName->setText(_aCaseName);
232 // ------------------------------------------------------------------------
233 void MonCreateYACS::SetDirName()
234 // ------------------------------------------------------------------------
236 QString aDirName=QFileDialog::getExistingDirectory ();
237 if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
239 // ------------------------------------------------------------------------
240 void MonCreateYACS::SetScriptFile()
241 // ------------------------------------------------------------------------
243 QString fileName0 = LEScriptFile->text().trimmed();
244 QString fileName = HOMARD_QT_COMMUN::PushNomFichier(false);
245 if (fileName.isEmpty()) fileName = fileName0 ;
246 LEScriptFile->setText(fileName);
248 // ------------------------------------------------------------------------
249 void MonCreateYACS::SetMeshFile()
250 // ------------------------------------------------------------------------
252 QString fileName0 = LEMeshFile->text().trimmed();
253 QString fileName = HOMARD_QT_COMMUN::PushNomFichier(false);
254 if (fileName.isEmpty()) fileName = fileName0 ;
255 LEMeshFile->setText(fileName);
257 // ------------------------------------------------------------------------
258 void MonCreateYACS::SetType(int Type)
259 // ------------------------------------------------------------------------