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 MonCreateYACS::MonCreateYACS (bool modal, HOMARD::HOMARD_Gen_var myHomardGen0, QString CaseName ):
35 // ----------------------------------------------------------------------
36 /* Constructs a MonCreateYACS
37 * Sets attributes to default values
39 // ----------------------------------------------------------------------
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(HOMARD::HOMARD_Gen_var myHomardGen0,
67 // ----------------------------------------------------------------------
68 // Constructeur appele par MonEditYACS
70 myHomardGen(myHomardGen0),
74 // MESSAGE("Debut du constructeur de MonCreateYACS appele par MonEditYACS");
81 // ------------------------------------------------------------------------
82 MonCreateYACS::~MonCreateYACS()
83 // ------------------------------------------------------------------------
85 // no need to delete child widgets, Qt does it all for us
87 // ------------------------------------------------------------------------
88 void MonCreateYACS::InitConnect()
89 // ------------------------------------------------------------------------
91 connect( PBCaseName, SIGNAL(pressed()), this, SLOT(SetCaseName()));
92 connect( PBScriptFile, SIGNAL(pressed()), this, SLOT(SetScriptFile()));
93 connect( PBDir, SIGNAL(pressed()), this, SLOT(SetDirName()));
94 connect( PBMeshFile, SIGNAL(pressed()), this, SLOT(SetMeshFile()));
96 connect( RBStatic, SIGNAL(clicked()), this, SLOT(SetType(1)));
97 connect( RBTransient, SIGNAL(clicked()), this, SLOT(SetType(2)));
99 connect( buttonOk, SIGNAL(pressed()), this, SLOT(PushOnOK()));
100 connect( buttonApply, SIGNAL(pressed()), this, SLOT(PushOnApply()));
101 connect( buttonCancel, SIGNAL(pressed()), this, SLOT(close()));
102 connect( buttonHelp, SIGNAL(pressed()), this, SLOT(PushOnHelp()));
104 // -------------------------------
105 bool MonCreateYACS::PushOnApply()
106 // --------------------------------
108 MESSAGE("PushOnApply");
110 // Le fichier du script
111 QString aFileName=LEScriptFile->text().trimmed();
112 if (aFileName ==QString(""))
114 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
115 QObject::tr("HOM_SCRIPT_FILE") );
119 // Le repertoire de calcul
120 QString aDirName=LEDirName->text().trimmed();
121 if (aDirName == QString(""))
123 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
124 QObject::tr("HOM_CASE_DIRECTORY_4") );
127 if ((aDirName != _aDirName) and (myHomardGen->VerifieDir( aDirName.toStdString().c_str()) == false))
129 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
130 QObject::tr("HOM_CASE_DIRECTORY_2") );
133 if (chdir(aDirName.toStdString().c_str()) != 0)
135 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
136 QObject::tr("HOM_CASE_DIRECTORY_3") );
140 // Le fichier du tout premier maillage
141 aFileName=LEMeshFile->text().trimmed();
142 if (aFileName ==QString(""))
144 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
145 QObject::tr("HOM_CASE_MESH") );
148 QString aMeshName = HOMARD_QT_COMMUN::LireNomMaillage(aFileName);
149 if (aMeshName == "" )
151 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
152 QObject::tr("HOM_MED_FILE_2") );
156 bool bOK = CreateOrUpdate() ;
158 if ( bOK ) { HOMARD_UTILS::updateObjBrowser() ; }
162 // ---------------------------------------------------
163 bool MonCreateYACS:: CreateOrUpdate()
164 //----------------------------------------------------
165 // Creation ou modification du schema
167 MESSAGE("CreateOrUpdate");
171 if ( _aCaseName == QString (""))
173 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
174 QObject::tr("HOM_CASE_NAME") );
178 QString aScriptFile=LEScriptFile->text().trimmed();
179 if ( aScriptFile != _aScriptFile )
181 _aScriptFile = aScriptFile ;
184 QString aDirName=LEDirName->text().trimmed();
185 if ( aDirName != _aDirName )
187 _aDirName = aDirName ;
190 QString aMeshFile=LEMeshFile->text().trimmed();
191 if ( aMeshFile != _aMeshFile )
193 _aMeshFile = aMeshFile ;
197 // Creation de l'objet CORBA
200 _Name=LEName->text().trimmed();
201 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()));
203 catch( SALOME::SALOME_Exception& S_ex )
205 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
206 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
212 { aYACS->SetType(_Type) ; }
214 // Ecriture du fichier
220 // ---------------------------
221 void MonCreateYACS::PushOnOK()
222 // ---------------------------
224 bool bOK = PushOnApply();
225 if ( bOK ) this->close();
227 //------------------------------
228 void MonCreateYACS::PushOnHelp()
229 //-------------------------------
231 HOMARD_UTILS::PushOnHelp(QString("gui_create_case.html"), QString(""));
233 // -------------------------------------------------
234 void MonCreateYACS::SetNewName()
235 // --------------------------------------------------
238 HOMARD::listeYACSs_var MyObjects = myHomardGen->GetAllYACSsName();
239 int num = 0; QString aName="";
240 while (aName == QString("") )
242 aName.setNum(num+1) ;
243 aName.insert(0, QString("YACS_")) ;
244 for ( int i=0; i<MyObjects->length(); i++)
246 if ( aName == QString(MyObjects[i]))
254 LEName->setText(aName);
256 // ------------------------------------------------------------------------
257 void MonCreateYACS::SetCaseName()
258 // ------------------------------------------------------------------------
260 MESSAGE ("SetCaseName avec _aCaseName = " << _aCaseName.toStdString() );
261 if (_aCaseName == QString(""))
263 _aCaseName=HOMARD_QT_COMMUN::SelectionArbreEtude(QString("CasHomard"), 1);
264 if (_aCaseName == QString("")) { raise();return;};
266 LECaseName->setText(_aCaseName);
268 // ------------------------------------------------------------------------
269 void MonCreateYACS::SetDirName()
270 // ------------------------------------------------------------------------
272 QString aDirName=QFileDialog::getExistingDirectory ();
273 if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
275 // ------------------------------------------------------------------------
276 void MonCreateYACS::SetScriptFile()
277 // ------------------------------------------------------------------------
279 QString fileName0 = LEScriptFile->text().trimmed();
280 QString fileName = HOMARD_QT_COMMUN::PushNomFichier(false);
281 if (fileName.isEmpty()) fileName = fileName0 ;
282 LEScriptFile->setText(fileName);
284 // ------------------------------------------------------------------------
285 void MonCreateYACS::SetMeshFile()
286 // ------------------------------------------------------------------------
288 QString fileName0 = LEMeshFile->text().trimmed();
289 QString fileName = HOMARD_QT_COMMUN::PushNomFichier(false);
290 if (fileName.isEmpty()) fileName = fileName0 ;
291 LEMeshFile->setText(fileName);
293 // ------------------------------------------------------------------------
294 void MonCreateYACS::SetType(int Type)
295 // ------------------------------------------------------------------------