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 // La valeur de _Type doit etre la meme que celle dans HOMARD_Gen_i::CreateYACSSchema
47 // et doit correspondre aux defauts des boutons
49 // MESSAGE("Debut du constructeur de MonCreateYACS");
50 myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen0);
58 if (_aCaseName != QString(""))
61 {setModal(false); /* permet selection du cas dans l arbre d etude */}
64 // MESSAGE("Fin du constructeur de MonCreateYACS");
67 // ----------------------------------------------------------------------
68 MonCreateYACS::MonCreateYACS(HOMARD::HOMARD_Gen_var myHomardGen0,
70 // ----------------------------------------------------------------------
71 // Constructeur appele par MonEditYACS
73 myHomardGen(myHomardGen0),
77 // MESSAGE("Debut du constructeur de MonCreateYACS appele par MonEditYACS");
84 // ------------------------------------------------------------------------
85 MonCreateYACS::~MonCreateYACS()
86 // ------------------------------------------------------------------------
88 // no need to delete child widgets, Qt does it all for us
90 // ------------------------------------------------------------------------
91 void MonCreateYACS::InitConnect()
92 // ------------------------------------------------------------------------
94 connect( PBCaseName, SIGNAL(pressed()), this, SLOT(SetCaseName()));
95 connect( PBScriptFile, SIGNAL(pressed()), this, SLOT(SetScriptFile()));
96 connect( PBDir, SIGNAL(pressed()), this, SLOT(SetDirName()));
97 connect( PBMeshFile, SIGNAL(pressed()), this, SLOT(SetMeshFile()));
99 connect( RBConstant, SIGNAL(clicked()), this, SLOT(SetConstant()));
100 connect( RBVariable, SIGNAL(clicked()), this, SLOT(SetVariable()));
102 connect( buttonOk, SIGNAL(pressed()), this, SLOT(PushOnOK()));
103 connect( buttonApply, SIGNAL(pressed()), this, SLOT(PushOnApply()));
104 connect( buttonCancel, SIGNAL(pressed()), this, SLOT(close()));
105 connect( buttonHelp, SIGNAL(pressed()), this, SLOT(PushOnHelp()));
107 // -------------------------------
108 bool MonCreateYACS::PushOnApply()
109 // --------------------------------
111 MESSAGE("PushOnApply");
113 // Le fichier du script
114 QString aFileName=LEScriptFile->text().trimmed();
115 if (aFileName ==QString(""))
117 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
118 QObject::tr("HOM_SCRIPT_FILE") );
122 // Le repertoire de calcul
123 QString aDirName=LEDirName->text().trimmed();
124 if (aDirName == QString(""))
126 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
127 QObject::tr("HOM_CASE_DIRECTORY_4") );
130 if ( aDirName != _aDirName)
131 { QString CaseNameDir = myHomardGen->VerifieDir( aDirName.toStdString().c_str()) ;
132 if ( CaseNameDir != "" )
134 INFOS(CaseNameDir.toStdString().c_str());
136 texte = QObject::tr("HOM_CASE_DIRECTORY_2") + CaseNameDir ;
137 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
142 if (chdir(aDirName.toStdString().c_str()) != 0)
144 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
145 QObject::tr("HOM_CASE_DIRECTORY_3") );
149 // Le fichier du tout premier maillage
150 aFileName=LEMeshFile->text().trimmed();
151 if (aFileName ==QString(""))
153 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
154 QObject::tr("HOM_CASE_MESH") );
157 QString aMeshName = HOMARD_QT_COMMUN::LireNomMaillage(aFileName);
158 if (aMeshName == "" )
160 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
161 QObject::tr("HOM_MED_FILE_2") );
165 bool bOK = CreateOrUpdate() ;
167 if ( bOK ) { HOMARD_UTILS::updateObjBrowser() ; }
171 // ---------------------------------------------------
172 bool MonCreateYACS:: CreateOrUpdate()
173 //----------------------------------------------------
174 // Creation ou modification du schema
176 MESSAGE("CreateOrUpdate");
180 if ( _aCaseName == QString (""))
182 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
183 QObject::tr("HOM_CASE_NAME") );
187 QString aScriptFile=LEScriptFile->text().trimmed();
188 if ( aScriptFile != _aScriptFile )
190 _aScriptFile = aScriptFile ;
193 QString aDirName=LEDirName->text().trimmed();
194 if ( aDirName != _aDirName )
196 _aDirName = aDirName ;
199 QString aMeshFile=LEMeshFile->text().trimmed();
200 if ( aMeshFile != _aMeshFile )
202 _aMeshFile = aMeshFile ;
206 // Creation de l'objet CORBA
209 _Name=LEName->text().trimmed();
210 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()));
212 catch( SALOME::SALOME_Exception& S_ex )
214 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
215 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
221 { aYACS->SetType(_Type) ; }
223 // Ecriture du fichier
226 int codret = aYACS->Write() ;
227 if ( codret != 0 ) { bOK = false ; }
232 // ---------------------------
233 void MonCreateYACS::PushOnOK()
234 // ---------------------------
236 bool bOK = PushOnApply();
237 if ( bOK ) this->close();
239 //------------------------------
240 void MonCreateYACS::PushOnHelp()
241 //-------------------------------
243 char* LanguageShort = myHomardGen->GetLanguageShort();
244 HOMARD_UTILS::PushOnHelp(QString("yacs.html"), QString(""), QString(LanguageShort));
246 // -------------------------------------------------
247 void MonCreateYACS::SetNewName()
248 // --------------------------------------------------
251 HOMARD::listeYACSs_var MyObjects = myHomardGen->GetAllYACSsName();
252 int num = 0; QString aName="";
253 while (aName == QString("") )
255 aName.setNum(num+1) ;
256 aName.insert(0, QString("YACS_")) ;
257 for ( int i=0; i<MyObjects->length(); i++)
259 if ( aName == QString(MyObjects[i]))
267 LEName->setText(aName);
269 // ------------------------------------------------------------------------
270 void MonCreateYACS::SetCaseName()
271 // ------------------------------------------------------------------------
273 MESSAGE ("SetCaseName avec _aCaseName = " << _aCaseName.toStdString() );
274 if (_aCaseName == QString(""))
276 _aCaseName=HOMARD_QT_COMMUN::SelectionArbreEtude(QString("CasHomard"), 1);
277 if (_aCaseName == QString("")) { raise();return;};
279 LECaseName->setText(_aCaseName);
281 // ------------------------------------------------------------------------
282 void MonCreateYACS::SetDirName()
283 // ------------------------------------------------------------------------
285 QString aDirName=QFileDialog::getExistingDirectory ();
286 if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
288 // ------------------------------------------------------------------------
289 void MonCreateYACS::SetScriptFile()
290 // ------------------------------------------------------------------------
292 QString fileName0 = LEScriptFile->text().trimmed();
293 QString fileName = HOMARD_QT_COMMUN::PushNomFichier(false);
294 if (fileName.isEmpty()) fileName = fileName0 ;
295 LEScriptFile->setText(fileName);
297 // ------------------------------------------------------------------------
298 void MonCreateYACS::SetMeshFile()
299 // ------------------------------------------------------------------------
301 QString fileName0 = LEMeshFile->text().trimmed();
302 QString fileName = HOMARD_QT_COMMUN::PushNomFichier(false);
303 if (fileName.isEmpty()) fileName = fileName0 ;
304 LEMeshFile->setText(fileName);
306 // ------------------------------------------------------------------------
307 void MonCreateYACS::SetConstant()
308 // ------------------------------------------------------------------------
312 // ------------------------------------------------------------------------
313 void MonCreateYACS::SetVariable()
314 // ------------------------------------------------------------------------