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
20 #include "MonCreateYACS.h"
22 #include <QFileDialog>
23 #include <QMessageBox>
25 #include "SalomeApp_Tools.h"
26 #include "HOMARDGUI_Utils.h"
27 #include "HomardQtCommun.h"
28 #include <utilities.h>
35 // ----------------------------------------------------------------------
36 MonCreateYACS::MonCreateYACS (bool modal, HOMARD::HOMARD_Gen_var myHomardGen0, QString CaseName ):
37 // ----------------------------------------------------------------------
38 /* Constructs a MonCreateYACS
39 * Sets attributes to default values
41 // ----------------------------------------------------------------------
48 // La valeur de _Type doit etre la meme que celle dans HOMARD_Gen_i::CreateYACSSchema
49 // et doit correspondre aux defauts des boutons
51 // MESSAGE("Debut du constructeur de MonCreateYACS");
52 myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen0);
60 if (_aCaseName != QString(""))
63 {setModal(false); /* permet selection du cas dans l arbre d etude */}
66 // MESSAGE("Fin du constructeur de MonCreateYACS");
69 // ----------------------------------------------------------------------
70 MonCreateYACS::MonCreateYACS(HOMARD::HOMARD_Gen_var myHomardGen0,
72 // ----------------------------------------------------------------------
73 // Constructeur appele par MonEditYACS
75 myHomardGen(myHomardGen0),
79 // MESSAGE("Debut du constructeur de MonCreateYACS appele par MonEditYACS");
86 // ------------------------------------------------------------------------
87 MonCreateYACS::~MonCreateYACS()
88 // ------------------------------------------------------------------------
90 // no need to delete child widgets, Qt does it all for us
92 // ------------------------------------------------------------------------
93 void MonCreateYACS::InitConnect()
94 // ------------------------------------------------------------------------
96 connect( PBCaseName, SIGNAL(pressed()), this, SLOT(SetCaseName()));
97 connect( PBScriptFile, SIGNAL(pressed()), this, SLOT(SetScriptFile()));
98 connect( PBDir, SIGNAL(pressed()), this, SLOT(SetDirName()));
99 connect( PBMeshFile, SIGNAL(pressed()), this, SLOT(SetMeshFile()));
101 connect( RBConstant, SIGNAL(clicked()), this, SLOT(SetConstant()));
102 connect( RBVariable, SIGNAL(clicked()), this, SLOT(SetVariable()));
104 connect( buttonOk, SIGNAL(pressed()), this, SLOT(PushOnOK()));
105 connect( buttonApply, SIGNAL(pressed()), this, SLOT(PushOnApply()));
106 connect( buttonCancel, SIGNAL(pressed()), this, SLOT(close()));
107 connect( buttonHelp, SIGNAL(pressed()), this, SLOT(PushOnHelp()));
109 // -------------------------------
110 bool MonCreateYACS::PushOnApply()
111 // --------------------------------
113 MESSAGE("PushOnApply");
115 // Le fichier du script
116 QString aFileName=LEScriptFile->text().trimmed();
117 if (aFileName ==QString(""))
119 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
120 QObject::tr("HOM_SCRIPT_FILE") );
124 // Le repertoire de calcul
125 QString aDirName=LEDirName->text().trimmed();
126 if (aDirName == QString(""))
128 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
129 QObject::tr("HOM_CASE_DIRECTORY_4") );
132 if ( aDirName != _aDirName)
133 { QString CaseNameDir = myHomardGen->VerifieDir( aDirName.toStdString().c_str()) ;
134 if ( CaseNameDir != "" )
137 texte = QObject::tr("HOM_CASE_DIRECTORY_2") + CaseNameDir ;
138 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
144 if (chdir(aDirName.toStdString().c_str()) != 0)
146 if (_chdir(aDirName.toStdString().c_str()) != 0)
149 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
150 QObject::tr("HOM_CASE_DIRECTORY_3") );
154 // Le fichier du tout premier maillage
155 aFileName=LEMeshFile->text().trimmed();
156 if (aFileName ==QString(""))
158 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
159 QObject::tr("HOM_CASE_MESH") );
162 QString aMeshName = HOMARD_QT_COMMUN::LireNomMaillage(aFileName);
163 if (aMeshName == "" )
165 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
166 QObject::tr("HOM_MED_FILE_2") );
170 bool bOK = CreateOrUpdate() ;
172 if ( bOK ) { HOMARD_UTILS::updateObjBrowser() ; }
176 // ---------------------------------------------------
177 bool MonCreateYACS:: CreateOrUpdate()
178 //----------------------------------------------------
179 // Creation ou modification du schema
181 MESSAGE("CreateOrUpdate");
185 if ( _aCaseName == QString (""))
187 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
188 QObject::tr("HOM_CASE_NAME") );
192 QString aScriptFile=LEScriptFile->text().trimmed();
193 if ( aScriptFile != _aScriptFile )
195 _aScriptFile = aScriptFile ;
198 QString aDirName=LEDirName->text().trimmed();
199 if ( aDirName != _aDirName )
201 _aDirName = aDirName ;
204 QString aMeshFile=LEMeshFile->text().trimmed();
205 if ( aMeshFile != _aMeshFile )
207 _aMeshFile = aMeshFile ;
211 // Creation de l'objet CORBA
214 _Name=LEName->text().trimmed();
215 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()));
217 catch( SALOME::SALOME_Exception& S_ex )
219 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
220 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
226 { aYACS->SetType(_Type) ; }
228 // Ecriture du fichier
231 int codret = aYACS->Write() ;
232 if ( codret != 0 ) { bOK = false ; }
237 // ---------------------------
238 void MonCreateYACS::PushOnOK()
239 // ---------------------------
241 bool bOK = PushOnApply();
242 if ( bOK ) this->close();
244 //------------------------------
245 void MonCreateYACS::PushOnHelp()
246 //-------------------------------
248 char* LanguageShort = myHomardGen->GetLanguageShort();
249 HOMARD_UTILS::PushOnHelp(QString("yacs.html"), QString(""), QString(LanguageShort));
251 // -------------------------------------------------
252 void MonCreateYACS::SetNewName()
253 // --------------------------------------------------
256 HOMARD::listeYACSs_var MyObjects = myHomardGen->GetAllYACSsName();
257 int num = 0; QString aName="";
258 while (aName == QString("") )
260 aName.setNum(num+1) ;
261 aName.insert(0, QString("YACS_")) ;
262 for ( int i=0; i<MyObjects->length(); i++)
264 if ( aName == QString(MyObjects[i]))
272 LEName->setText(aName);
274 // ------------------------------------------------------------------------
275 void MonCreateYACS::SetCaseName()
276 // ------------------------------------------------------------------------
278 MESSAGE ("SetCaseName avec _aCaseName = " << _aCaseName.toStdString() );
279 if (_aCaseName == QString(""))
281 _aCaseName=HOMARD_QT_COMMUN::SelectionArbreEtude(QString("CasHomard"), 1);
282 if (_aCaseName == QString("")) { raise();return;};
284 LECaseName->setText(_aCaseName);
286 // ------------------------------------------------------------------------
287 void MonCreateYACS::SetDirName()
288 // ------------------------------------------------------------------------
290 QString aDirName=QFileDialog::getExistingDirectory ();
291 if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
293 // ------------------------------------------------------------------------
294 void MonCreateYACS::SetScriptFile()
295 // ------------------------------------------------------------------------
297 QString fileName0 = LEScriptFile->text().trimmed();
298 QString fileName = HOMARD_QT_COMMUN::PushNomFichier(false);
299 if (fileName.isEmpty()) fileName = fileName0 ;
300 LEScriptFile->setText(fileName);
302 // ------------------------------------------------------------------------
303 void MonCreateYACS::SetMeshFile()
304 // ------------------------------------------------------------------------
306 QString fileName0 = LEMeshFile->text().trimmed();
307 QString fileName = HOMARD_QT_COMMUN::PushNomFichier(false);
308 if (fileName.isEmpty()) fileName = fileName0 ;
309 LEMeshFile->setText(fileName);
311 // ------------------------------------------------------------------------
312 void MonCreateYACS::SetConstant()
313 // ------------------------------------------------------------------------
317 // ------------------------------------------------------------------------
318 void MonCreateYACS::SetVariable()
319 // ------------------------------------------------------------------------