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 // Les valeurs de _Type, _MaxIter, _MaxNode, _MaxElem doivent etre les memes que celles dans HOMARD_Gen_i::CreateYACSSchema
49 // et doivent correspondre aux defauts des boutons
51 // MESSAGE("Debut du constructeur de MonCreateYACS");
52 myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen0);
54 if ( modal ) { setWindowModality(Qt::WindowModal); }
55 else { setWindowModality(Qt::NonModal); }
61 if (_aCaseName != QString("")) { SetCaseName(); }
62 else { setWindowModality(Qt::NonModal); /* permet selection du cas dans l arbre d etude */}
64 // Les valeurs definies dans les preferences
65 _MaxIter = myHomardGen->GetYACSMaxIter();
66 _MaxNode = myHomardGen->GetYACSMaxNode();
67 _MaxElem = myHomardGen->GetYACSMaxElem();
68 MESSAGE ("Valeur par defaut de MaxIter = " << _MaxIter<<", MaxNode = "<< _MaxNode<<", MaxElem = "<< _MaxElem);
69 SpinBoxMaxIter->setValue(_MaxIter) ;
70 SpinBoxMaxNode->setValue(_MaxNode) ;
71 SpinBoxMaxElem->setValue(_MaxElem) ;
76 // ----------------------------------------------------------------------
77 MonCreateYACS::MonCreateYACS(HOMARD::HOMARD_Gen_var myHomardGen0,
79 // ----------------------------------------------------------------------
80 // Constructeur appele par MonEditYACS
82 myHomardGen(myHomardGen0),
86 // MESSAGE("Debut du constructeur de MonCreateYACS appele par MonEditYACS");
89 setWindowModality(Qt::WindowModal);
94 // ------------------------------------------------------------------------
95 MonCreateYACS::~MonCreateYACS()
96 // ------------------------------------------------------------------------
98 // no need to delete child widgets, Qt does it all for us
100 // ------------------------------------------------------------------------
101 void MonCreateYACS::InitConnect()
102 // ------------------------------------------------------------------------
104 connect( PBCaseName, SIGNAL(pressed()), this, SLOT(SetCaseName()));
105 connect( PBScriptFile, SIGNAL(pressed()), this, SLOT(SetScriptFile()));
106 connect( PBDir, SIGNAL(pressed()), this, SLOT(SetDirName()));
107 connect( PBMeshFile, SIGNAL(pressed()), this, SLOT(SetMeshFile()));
109 connect( RBConstant, SIGNAL(clicked()), this, SLOT(SetConstant()));
110 connect( RBVariable, SIGNAL(clicked()), this, SLOT(SetVariable()));
112 connect( buttonOk, SIGNAL(pressed()), this, SLOT(PushOnOK()));
113 connect( buttonApply, SIGNAL(pressed()), this, SLOT(PushOnApply()));
114 connect( buttonCancel, SIGNAL(pressed()), this, SLOT(close()));
115 connect( buttonHelp, SIGNAL(pressed()), this, SLOT(PushOnHelp()));
117 // -------------------------------
118 bool MonCreateYACS::PushOnApply()
119 // --------------------------------
121 MESSAGE("PushOnApply");
123 // Le fichier du script
124 QString aFileName=LEScriptFile->text().trimmed();
125 if (aFileName ==QString(""))
127 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
128 QObject::tr("HOM_SCRIPT_FILE") );
132 // Le repertoire de calcul
133 QString aDirName=LEDirName->text().trimmed();
134 if (aDirName == QString(""))
136 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
137 QObject::tr("HOM_CASE_DIRECTORY_4") );
140 if ( aDirName != _aDirName)
141 { QString CaseNameDir = myHomardGen->VerifieDir( aDirName.toStdString().c_str()) ;
142 if ( CaseNameDir != "" )
145 texte = QObject::tr("HOM_CASE_DIRECTORY_2") + CaseNameDir ;
146 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
152 if (chdir(aDirName.toStdString().c_str()) != 0)
154 if (_chdir(aDirName.toStdString().c_str()) != 0)
157 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
158 QObject::tr("HOM_CASE_DIRECTORY_3") );
162 // Le fichier du tout premier maillage
163 aFileName=LEMeshFile->text().trimmed();
164 if (aFileName ==QString(""))
166 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
167 QObject::tr("HOM_CASE_MESH") );
170 QString aMeshName = HOMARD_QT_COMMUN::LireNomMaillage(aFileName);
171 if (aMeshName == "" )
173 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
174 QObject::tr("HOM_MED_FILE_2") );
178 bool bOK = CreateOrUpdate() ;
180 if ( bOK ) { HOMARD_UTILS::updateObjBrowser() ; }
184 // ---------------------------------------------------
185 bool MonCreateYACS:: CreateOrUpdate()
186 //----------------------------------------------------
187 // Creation ou modification du schema
189 MESSAGE("CreateOrUpdate");
192 // 1. Verification des donnees
194 if ( _aCaseName == QString (""))
196 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
197 QObject::tr("HOM_CASE_NAME") );
201 QString aScriptFile=LEScriptFile->text().trimmed();
202 if ( aScriptFile != _aScriptFile )
204 _aScriptFile = aScriptFile ;
207 QString aDirName=LEDirName->text().trimmed();
208 if ( aDirName != _aDirName )
210 _aDirName = aDirName ;
213 QString aMeshFile=LEMeshFile->text().trimmed();
214 if ( aMeshFile != _aMeshFile )
216 _aMeshFile = aMeshFile ;
220 // 2. Creation de l'objet CORBA
223 _Name=LEName->text().trimmed();
224 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()));
226 catch( SALOME::SALOME_Exception& S_ex )
228 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
229 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
236 // 3.1. Le type du schema
237 aYACS->SetType(_Type) ;
240 _MaxIter = SpinBoxMaxIter->value() ;
241 aYACS->SetMaxIter(_MaxIter) ;
243 _MaxNode = SpinBoxMaxNode->value() ;
244 aYACS->SetMaxNode(_MaxNode) ;
246 _MaxElem = SpinBoxMaxElem->value() ;
247 aYACS->SetMaxElem(_MaxElem) ;
251 // 4. Ecriture du fichier
254 int codret = aYACS->Write() ;
255 if ( codret != 0 ) { bOK = false ; }
260 // ---------------------------
261 void MonCreateYACS::PushOnOK()
262 // ---------------------------
264 bool bOK = PushOnApply();
265 if ( bOK ) this->close();
267 //------------------------------
268 void MonCreateYACS::PushOnHelp()
269 //-------------------------------
271 std::string LanguageShort = myHomardGen->GetLanguageShort();
272 HOMARD_UTILS::PushOnHelp(QString("yacs.html"), QString(""), QString(LanguageShort.c_str()));
274 // -------------------------------------------------
275 void MonCreateYACS::SetNewName()
276 // --------------------------------------------------
279 HOMARD::listeYACSs_var MyObjects = myHomardGen->GetAllYACSsName();
280 int num = 0; QString aName="";
281 while (aName == QString("") )
283 aName.setNum(num+1) ;
284 aName.insert(0, QString("YACS_")) ;
285 for ( int i=0; i<MyObjects->length(); i++)
287 if ( aName == QString(MyObjects[i]))
295 LEName->setText(aName);
297 // ------------------------------------------------------------------------
298 void MonCreateYACS::SetCaseName()
299 // ------------------------------------------------------------------------
301 MESSAGE ("SetCaseName avec _aCaseName = " << _aCaseName.toStdString() );
302 if (_aCaseName == QString(""))
304 _aCaseName=HOMARD_QT_COMMUN::SelectionArbreEtude(QString("CasHomard"), 1);
305 if (_aCaseName == QString("")) { raise();return;};
307 LECaseName->setText(_aCaseName);
309 // ------------------------------------------------------------------------
310 void MonCreateYACS::SetDirName()
311 // ------------------------------------------------------------------------
313 QString aDirName=QFileDialog::getExistingDirectory ();
314 if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
316 // ------------------------------------------------------------------------
317 void MonCreateYACS::SetScriptFile()
318 // ------------------------------------------------------------------------
320 QString fileName0 = LEScriptFile->text().trimmed();
321 QString fileName = HOMARD_QT_COMMUN::PushNomFichier( false, QString("py") ) ;
322 if (fileName.isEmpty()) fileName = fileName0 ;
323 LEScriptFile->setText(fileName);
325 // ------------------------------------------------------------------------
326 void MonCreateYACS::SetMeshFile()
327 // ------------------------------------------------------------------------
329 QString fileName0 = LEMeshFile->text().trimmed();
330 QString fileName = HOMARD_QT_COMMUN::PushNomFichier( false, QString("med") ) ;
331 if (fileName.isEmpty()) fileName = fileName0 ;
332 LEMeshFile->setText(fileName);
334 // ------------------------------------------------------------------------
335 void MonCreateYACS::SetConstant()
336 // ------------------------------------------------------------------------
340 // ------------------------------------------------------------------------
341 void MonCreateYACS::SetVariable()
342 // ------------------------------------------------------------------------