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 // ----------------------------------------------------------------------
51 // Les valeurs de _Type, _MaxIter, _MaxNode, _MaxElem doivent etre les memes que celles dans HOMARD_Gen_i::CreateYACSSchema
52 // et doivent correspondre aux defauts des boutons
54 // MESSAGE("Debut du constructeur de MonCreateYACS");
55 myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen0);
57 if ( modal ) { setWindowModality(Qt::WindowModal); }
58 else { setWindowModality(Qt::NonModal); }
64 if (_aCaseName != QString("")) { SetCaseName(); }
65 else { setWindowModality(Qt::NonModal); /* permet selection du cas dans l arbre d etude */}
70 // ----------------------------------------------------------------------
71 MonCreateYACS::MonCreateYACS(HOMARD::HOMARD_Gen_var myHomardGen0,
73 // ----------------------------------------------------------------------
74 // Constructeur appele par MonEditYACS
76 myHomardGen(myHomardGen0),
80 // MESSAGE("Debut du constructeur de MonCreateYACS appele par MonEditYACS");
83 setWindowModality(Qt::WindowModal);
88 // ------------------------------------------------------------------------
89 MonCreateYACS::~MonCreateYACS()
90 // ------------------------------------------------------------------------
92 // no need to delete child widgets, Qt does it all for us
94 // ------------------------------------------------------------------------
95 void MonCreateYACS::InitConnect()
96 // ------------------------------------------------------------------------
98 connect( PBCaseName, SIGNAL(pressed()), this, SLOT(SetCaseName()));
99 connect( PBScriptFile, SIGNAL(pressed()), this, SLOT(SetScriptFile()));
100 connect( PBDir, SIGNAL(pressed()), this, SLOT(SetDirName()));
101 connect( PBMeshFile, SIGNAL(pressed()), this, SLOT(SetMeshFile()));
103 connect( RBConstant, SIGNAL(clicked()), this, SLOT(SetConstant()));
104 connect( RBVariable, SIGNAL(clicked()), this, SLOT(SetVariable()));
106 connect( buttonOk, SIGNAL(pressed()), this, SLOT(PushOnOK()));
107 connect( buttonApply, SIGNAL(pressed()), this, SLOT(PushOnApply()));
108 connect( buttonCancel, SIGNAL(pressed()), this, SLOT(close()));
109 connect( buttonHelp, SIGNAL(pressed()), this, SLOT(PushOnHelp()));
111 // -------------------------------
112 bool MonCreateYACS::PushOnApply()
113 // --------------------------------
115 MESSAGE("PushOnApply");
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)
135 { QString CaseNameDir = myHomardGen->VerifieDir( aDirName.toStdString().c_str()) ;
136 if ( CaseNameDir != "" )
139 texte = QObject::tr("HOM_CASE_DIRECTORY_2") + CaseNameDir ;
140 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
146 if (chdir(aDirName.toStdString().c_str()) != 0)
148 if (_chdir(aDirName.toStdString().c_str()) != 0)
151 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
152 QObject::tr("HOM_CASE_DIRECTORY_3") );
156 // Le fichier du tout premier maillage
157 aFileName=LEMeshFile->text().trimmed();
158 if (aFileName ==QString(""))
160 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
161 QObject::tr("HOM_CASE_MESH") );
164 QString aMeshName = HOMARD_QT_COMMUN::LireNomMaillage(aFileName);
165 if (aMeshName == "" )
167 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
168 QObject::tr("HOM_MED_FILE_2") );
172 bool bOK = CreateOrUpdate() ;
174 if ( bOK ) { HOMARD_UTILS::updateObjBrowser() ; }
178 // ---------------------------------------------------
179 bool MonCreateYACS:: CreateOrUpdate()
180 //----------------------------------------------------
181 // Creation ou modification du schema
183 MESSAGE("CreateOrUpdate");
186 // 1. Verification des donnees
188 if ( _aCaseName == QString (""))
190 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
191 QObject::tr("HOM_CASE_NAME") );
195 QString aScriptFile=LEScriptFile->text().trimmed();
196 if ( aScriptFile != _aScriptFile )
198 _aScriptFile = aScriptFile ;
201 QString aDirName=LEDirName->text().trimmed();
202 if ( aDirName != _aDirName )
204 _aDirName = aDirName ;
207 QString aMeshFile=LEMeshFile->text().trimmed();
208 if ( aMeshFile != _aMeshFile )
210 _aMeshFile = aMeshFile ;
214 // 2. Creation de l'objet CORBA
217 _Name=LEName->text().trimmed();
218 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()));
220 catch( SALOME::SALOME_Exception& S_ex )
222 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
223 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
230 // 3.1. Le type du schema
231 aYACS->SetType(_Type) ;
234 _MaxIter = SpinBoxMaxIter->value() ;
235 // aYACS->SetMaxIter(_MaxIter) ;
237 _MaxNode = SpinBoxMaxNode->value() ;
238 // aYACS->SetMaxNode(_MaxNode) ;
240 _MaxElem = SpinBoxMaxElem->value() ;
241 // aYACS->SetMaxElem(_MaxElem) ;
245 // 4. Ecriture du fichier
248 int codret = aYACS->Write() ;
249 if ( codret != 0 ) { bOK = false ; }
254 // ---------------------------
255 void MonCreateYACS::PushOnOK()
256 // ---------------------------
258 bool bOK = PushOnApply();
259 if ( bOK ) this->close();
261 //------------------------------
262 void MonCreateYACS::PushOnHelp()
263 //-------------------------------
265 std::string LanguageShort = myHomardGen->GetLanguageShort();
266 HOMARD_UTILS::PushOnHelp(QString("yacs.html"), QString(""), QString(LanguageShort.c_str()));
268 // -------------------------------------------------
269 void MonCreateYACS::SetNewName()
270 // --------------------------------------------------
273 HOMARD::listeYACSs_var MyObjects = myHomardGen->GetAllYACSsName();
274 int num = 0; QString aName="";
275 while (aName == QString("") )
277 aName.setNum(num+1) ;
278 aName.insert(0, QString("YACS_")) ;
279 for ( int i=0; i<MyObjects->length(); i++)
281 if ( aName == QString(MyObjects[i]))
289 LEName->setText(aName);
291 // ------------------------------------------------------------------------
292 void MonCreateYACS::SetCaseName()
293 // ------------------------------------------------------------------------
295 MESSAGE ("SetCaseName avec _aCaseName = " << _aCaseName.toStdString() );
296 if (_aCaseName == QString(""))
298 _aCaseName=HOMARD_QT_COMMUN::SelectionArbreEtude(QString("CasHomard"), 1);
299 if (_aCaseName == QString("")) { raise();return;};
301 LECaseName->setText(_aCaseName);
303 // ------------------------------------------------------------------------
304 void MonCreateYACS::SetDirName()
305 // ------------------------------------------------------------------------
307 QString aDirName=QFileDialog::getExistingDirectory ();
308 if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
310 // ------------------------------------------------------------------------
311 void MonCreateYACS::SetScriptFile()
312 // ------------------------------------------------------------------------
314 QString fileName0 = LEScriptFile->text().trimmed();
315 QString fileName = HOMARD_QT_COMMUN::PushNomFichier( false, QString("py") ) ;
316 if (fileName.isEmpty()) fileName = fileName0 ;
317 LEScriptFile->setText(fileName);
319 // ------------------------------------------------------------------------
320 void MonCreateYACS::SetMeshFile()
321 // ------------------------------------------------------------------------
323 QString fileName0 = LEMeshFile->text().trimmed();
324 QString fileName = HOMARD_QT_COMMUN::PushNomFichier( false, QString("med") ) ;
325 if (fileName.isEmpty()) fileName = fileName0 ;
326 LEMeshFile->setText(fileName);
328 // ------------------------------------------------------------------------
329 void MonCreateYACS::SetConstant()
330 // ------------------------------------------------------------------------
334 // ------------------------------------------------------------------------
335 void MonCreateYACS::SetVariable()
336 // ------------------------------------------------------------------------