1 // Copyright (C) 2011-2020 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, or (at your option) any later version.
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"
23 #include <QFileDialog>
24 #include <QMessageBox>
26 #include "SalomeApp_Tools.h"
27 #include "HOMARDGUI_Utils.h"
28 #include "HomardQtCommun.h"
29 #include <utilities.h>
36 // ----------------------------------------------------------------------
37 MonCreateYACS::MonCreateYACS (bool modal, ADAPT::ADAPT_Gen_var myHomardGen0, QString CaseName ):
38 // ----------------------------------------------------------------------
39 /* Constructs a MonCreateYACS
40 * Sets attributes to default values
42 // ----------------------------------------------------------------------
49 // Les valeurs de _Type, _MaxIter, _MaxNode, _MaxElem doivent etre les memes que celles dans ADAPT_Gen_i::CreateYACSSchema
50 // et doivent correspondre aux defauts des boutons
52 // MESSAGE("Debut du constructeur de MonCreateYACS");
53 myHomardGen=ADAPT::ADAPT_Gen::_duplicate(myHomardGen0);
55 if ( modal ) { setWindowModality(Qt::WindowModal); }
56 else { setWindowModality(Qt::NonModal); }
62 if (_aCaseName != QString("")) { SetCaseName(); }
63 else { setWindowModality(Qt::NonModal); /* permet selection du cas dans l arbre d etude */}
65 // Les valeurs definies dans les preferences
66 _MaxIter = myHomardGen->GetYACSMaxIter();
67 _MaxNode = myHomardGen->GetYACSMaxNode();
68 _MaxElem = myHomardGen->GetYACSMaxElem();
69 MESSAGE ("Valeur par defaut de MaxIter = " << _MaxIter<<", MaxNode = "<< _MaxNode<<", MaxElem = "<< _MaxElem);
70 SpinBoxMaxIter->setValue(_MaxIter) ;
71 SpinBoxMaxNode->setValue(_MaxNode) ;
72 SpinBoxMaxElem->setValue(_MaxElem) ;
77 // ----------------------------------------------------------------------
78 MonCreateYACS::MonCreateYACS(ADAPT::ADAPT_Gen_var myHomardGen0,
80 // ----------------------------------------------------------------------
81 // Constructeur appele par MonEditYACS
83 myHomardGen(myHomardGen0),
87 // MESSAGE("Debut du constructeur de MonCreateYACS appele par MonEditYACS");
90 setWindowModality(Qt::WindowModal);
95 // ------------------------------------------------------------------------
96 MonCreateYACS::~MonCreateYACS()
97 // ------------------------------------------------------------------------
99 // no need to delete child widgets, Qt does it all for us
101 // ------------------------------------------------------------------------
102 void MonCreateYACS::InitConnect()
103 // ------------------------------------------------------------------------
105 connect( PBCaseName, SIGNAL(pressed()), this, SLOT(SetCaseName()));
106 connect( PBScriptFile, SIGNAL(pressed()), this, SLOT(SetScriptFile()));
107 connect( PBDir, SIGNAL(pressed()), this, SLOT(SetDirName()));
108 connect( PBMeshFile, SIGNAL(pressed()), this, SLOT(SetMeshFile()));
110 connect( RBConstant, SIGNAL(clicked()), this, SLOT(SetConstant()));
111 connect( RBVariable, SIGNAL(clicked()), this, SLOT(SetVariable()));
113 connect( buttonOk, SIGNAL(pressed()), this, SLOT(PushOnOK()));
114 connect( buttonApply, SIGNAL(pressed()), this, SLOT(PushOnApply()));
115 connect( buttonCancel, SIGNAL(pressed()), this, SLOT(close()));
116 connect( buttonHelp, SIGNAL(pressed()), this, SLOT(PushOnHelp()));
118 // -------------------------------
119 bool MonCreateYACS::PushOnApply()
120 // --------------------------------
122 MESSAGE("PushOnApply");
124 // Le fichier du script
125 QString aFileName=LEScriptFile->text().trimmed();
126 if (aFileName ==QString(""))
128 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
129 QObject::tr("HOM_SCRIPT_FILE") );
133 // Le repertoire de calcul
134 QString aDirName=LEDirName->text().trimmed();
135 if (aDirName == QString(""))
137 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
138 QObject::tr("HOM_CASE_DIRECTORY_4") );
141 if ( aDirName != _aDirName)
142 { QString CaseNameDir = myHomardGen->VerifieDir( aDirName.toStdString().c_str()) ;
143 if ( CaseNameDir != "" )
146 texte = QObject::tr("HOM_CASE_DIRECTORY_2") + CaseNameDir ;
147 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
152 if (CHDIR(aDirName.toStdString().c_str()) != 0)
154 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
155 QObject::tr("HOM_CASE_DIRECTORY_3") );
159 // Le fichier du tout premier maillage
160 aFileName=LEMeshFile->text().trimmed();
161 if (aFileName ==QString(""))
163 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
164 QObject::tr("HOM_CASE_MESH") );
167 QString aMeshName = HOMARD_QT_COMMUN::LireNomMaillage(aFileName);
168 if (aMeshName == "" )
170 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
171 QObject::tr("HOM_MED_FILE_2") );
175 bool bOK = CreateOrUpdate() ;
177 if ( bOK ) { HOMARD_UTILS::updateObjBrowser() ; }
181 // ---------------------------------------------------
182 bool MonCreateYACS:: CreateOrUpdate()
183 //----------------------------------------------------
184 // Creation ou modification du schema
186 MESSAGE("CreateOrUpdate");
189 // 1. Verification des donnees
191 if ( _aCaseName == QString (""))
193 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
194 QObject::tr("HOM_CASE_NAME") );
198 QString aScriptFile=LEScriptFile->text().trimmed();
199 if ( aScriptFile != _aScriptFile )
201 _aScriptFile = aScriptFile ;
204 QString aDirName=LEDirName->text().trimmed();
205 if ( aDirName != _aDirName )
207 _aDirName = aDirName ;
210 QString aMeshFile=LEMeshFile->text().trimmed();
211 if ( aMeshFile != _aMeshFile )
213 _aMeshFile = aMeshFile ;
217 // 2. Creation de l'objet CORBA
220 _Name=LEName->text().trimmed();
221 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()));
223 catch( SALOME::SALOME_Exception& S_ex )
225 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
226 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
233 // 3.1. Le type du schema
234 aYACS->SetType(_Type) ;
237 _MaxIter = SpinBoxMaxIter->value() ;
238 aYACS->SetMaxIter(_MaxIter) ;
240 _MaxNode = SpinBoxMaxNode->value() ;
241 aYACS->SetMaxNode(_MaxNode) ;
243 _MaxElem = SpinBoxMaxElem->value() ;
244 aYACS->SetMaxElem(_MaxElem) ;
248 // 4. Ecriture du fichier
251 int codret = aYACS->Write() ;
252 if ( codret != 0 ) { bOK = false ; }
257 // ---------------------------
258 void MonCreateYACS::PushOnOK()
259 // ---------------------------
261 bool bOK = PushOnApply();
262 if ( bOK ) this->close();
264 //------------------------------
265 void MonCreateYACS::PushOnHelp()
266 //-------------------------------
268 std::string LanguageShort = myHomardGen->GetLanguageShort();
269 HOMARD_UTILS::PushOnHelp(QString("yacs.html"), QString(""), QString(LanguageShort.c_str()));
271 // -------------------------------------------------
272 void MonCreateYACS::SetNewName()
273 // --------------------------------------------------
276 ADAPT::listeYACSs_var MyObjects = myHomardGen->GetAllYACSsName();
277 int num = 0; QString aName="";
278 while (aName == QString("") )
280 aName.setNum(num+1) ;
281 aName.insert(0, QString("YACS_")) ;
282 for ( int i=0; i<MyObjects->length(); i++)
284 if ( aName == QString(MyObjects[i]))
292 LEName->setText(aName);
294 // ------------------------------------------------------------------------
295 void MonCreateYACS::SetCaseName()
296 // ------------------------------------------------------------------------
298 MESSAGE ("SetCaseName avec _aCaseName = " << _aCaseName.toStdString() );
299 if (_aCaseName == QString(""))
301 _aCaseName=HOMARD_QT_COMMUN::SelectionArbreEtude(QString("CasHomard"), 1);
302 if (_aCaseName == QString("")) { raise();return;};
304 LECaseName->setText(_aCaseName);
306 // ------------------------------------------------------------------------
307 void MonCreateYACS::SetDirName()
308 // ------------------------------------------------------------------------
310 QString aDirName=QFileDialog::getExistingDirectory ();
311 if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
313 // ------------------------------------------------------------------------
314 void MonCreateYACS::SetScriptFile()
315 // ------------------------------------------------------------------------
317 QString fileName0 = LEScriptFile->text().trimmed();
318 QString fileName = HOMARD_QT_COMMUN::PushNomFichier( false, QString("py") ) ;
319 if (fileName.isEmpty()) fileName = fileName0 ;
320 LEScriptFile->setText(fileName);
322 // ------------------------------------------------------------------------
323 void MonCreateYACS::SetMeshFile()
324 // ------------------------------------------------------------------------
326 QString fileName0 = LEMeshFile->text().trimmed();
327 QString fileName = HOMARD_QT_COMMUN::PushNomFichier( false, QString("med") ) ;
328 if (fileName.isEmpty()) fileName = fileName0 ;
329 LEMeshFile->setText(fileName);
331 // ------------------------------------------------------------------------
332 void MonCreateYACS::SetConstant()
333 // ------------------------------------------------------------------------
337 // ------------------------------------------------------------------------
338 void MonCreateYACS::SetVariable()
339 // ------------------------------------------------------------------------