1 // Copyright (C) 2011-2014 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 "MonMeshInfo.h"
22 #include <QFileDialog>
23 #include <QMessageBox>
25 #include "SalomeApp_Tools.h"
26 #include "HOMARDGUI_Utils.h"
27 #include "HomardQtCommun.h"
28 #include "MonEditFile.h"
29 #include <utilities.h>
37 // -----------------------------------------------------------------------------------------
38 MonMeshInfo::MonMeshInfo(QWidget* parent, bool modal, HOMARD::HOMARD_Gen_var myHomardGen0)
39 // -----------------------------------------------------------------------------------------
40 /* Constructs a MonMeshInfo
41 * Inherits from CasHomard
42 * Sets attributes to default values
46 _aCaseName(""),_aDirName(""),
53 myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen0);
62 // ------------------------------------------------------------------------
63 MonMeshInfo::~MonMeshInfo()
64 // ------------------------------------------------------------------------
66 // no need to delete child widgets, Qt does it all for us
68 // ------------------------------------------------------------------------
69 void MonMeshInfo::InitConnect()
70 // ------------------------------------------------------------------------
72 connect( LECaseName, SIGNAL(textChanged(QString)), this, SLOT(CaseNameChanged()));
73 connect( PushDir, SIGNAL(pressed()), this, SLOT(SetDirName()));
74 connect( PushFichier, SIGNAL(pressed()), this, SLOT(SetFileName()));
76 connect( CBBlockSize, SIGNAL(stateChanged(int)), this, SLOT(SetBlockSize()));
77 connect( CBConnection, SIGNAL(stateChanged(int)), this, SLOT(SetConnection()));
78 connect( CBDiametre, SIGNAL(stateChanged(int)), this, SLOT(SetDiametre()));
79 connect( CBEntanglement, SIGNAL(stateChanged(int)), this, SLOT(SetEntanglement()));
80 connect( CBQuality, SIGNAL(stateChanged(int)), this, SLOT(SetQuality()));
82 connect( buttonOk, SIGNAL(pressed()), this, SLOT(PushOnOK()));
83 connect( buttonApply, SIGNAL(pressed()), this, SLOT(PushOnApply()));
84 connect( buttonCancel, SIGNAL(pressed()), this, SLOT(close()));
85 connect( buttonHelp, SIGNAL(pressed()), this, SLOT(PushOnHelp()));
87 // -------------------------------
88 bool MonMeshInfo::PushOnApply()
89 // --------------------------------
91 MESSAGE("PushOnApply");
92 QString aCaseName=LECaseName->text().trimmed();
93 if ( aCaseName == "" )
95 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
96 QObject::tr("HOM_CASE_NAME") );
100 QString aDirName=LEDirName->text().trimmed();
101 if (aDirName == QString(""))
103 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
104 QObject::tr("HOM_CASE_DIRECTORY_1") );
107 if ( aDirName != _aDirName)
108 { QString CaseNameDir = myHomardGen->VerifieDir( aDirName.toStdString().c_str()) ;
109 if ( CaseNameDir != "" )
112 texte = QObject::tr("HOM_CASE_DIRECTORY_2") + CaseNameDir ;
113 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
119 if (chdir(aDirName.toStdString().c_str()) != 0)
121 if (_chdir(aDirName.toStdString().c_str()) != 0)
124 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
125 QObject::tr("HOM_CASE_DIRECTORY_3") );
129 QString aFileName=LEFileName->text().trimmed();
130 if (aFileName ==QString(""))
132 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
133 QObject::tr("HOM_CASE_MESH") );
137 QString aMeshName = HOMARD_QT_COMMUN::LireNomMaillage(aFileName);
138 if (aMeshName == "" )
140 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
141 QObject::tr("HOM_MED_FILE_2") );
144 if ( ( _Quality == 0 ) && ( _Diametre == 0 ) && ( _Connection == 0 ) && ( _BlockSize == 0 ) && ( _Entanglement == 0 ) )
146 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
147 QObject::tr("HOM_MESH_INFO") );
151 if (aCaseName != _aCaseName )
153 _aCaseName = aCaseName;
156 myHomardGen->MeshInfo( \
157 CORBA::string_dup(_aCaseName.toStdString().c_str()), \
158 CORBA::string_dup(aMeshName.toStdString().c_str()), \
159 CORBA::string_dup(aFileName.toStdString().c_str()), \
160 CORBA::string_dup(aDirName.toStdString().c_str()), \
161 _Quality, _Diametre, _Connection, _BlockSize, _Entanglement );
163 catch( SALOME::SALOME_Exception& S_ex )
165 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
166 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
171 // Le bilan de l'analyse a afficher
172 aCase = myHomardGen->GetCase(_aCaseName.toStdString().c_str());
173 string iter0 = aCase->GetIter0Name();
174 HOMARD::HOMARD_Iteration_var aIter = myHomardGen->GetIteration(iter0.c_str());
175 aFileName = aIter->GetFileInfo() ;
176 MonEditFile *aDlg = new MonEditFile( 0, true, HOMARD::HOMARD_Gen::_duplicate(myHomardGen), aFileName, 1 ) ;
177 if ( aDlg->_codret == 0 ) { aDlg->show(); }
179 HOMARD_UTILS::updateObjBrowser();
182 // ---------------------------
183 void MonMeshInfo::PushOnOK()
184 // ---------------------------
186 bool bOK = PushOnApply();
187 if ( bOK ) this->close();
189 //------------------------------
190 void MonMeshInfo::PushOnHelp()
191 //-------------------------------
193 std::string LanguageShort = myHomardGen->GetLanguageShort();
194 HOMARD_UTILS::PushOnHelp(QString("gui_create_case.html"), QString(""), QString(LanguageShort.c_str()));
196 // ---------------------------------
197 void MonMeshInfo::SetNewCaseName()
198 // ------------------------------
200 HOMARD::listeCases_var MyCases = myHomardGen->GetAllCasesName();
201 int num = 0; QString aCaseName="";
202 while (aCaseName=="" )
204 aCaseName.setNum(num+1) ;
205 aCaseName.insert(0, QString("Case_")) ;
206 for ( int i=0; i<MyCases->length(); i++)
208 if ( aCaseName == QString((MyCases)[i]) )
216 LECaseName->clear() ;
217 LECaseName->insert(aCaseName);
219 // ------------------------------------------------------------------------
220 void MonMeshInfo::SetDirName()
221 // ------------------------------------------------------------------------
223 QString aDirName=QFileDialog::getExistingDirectory ();
224 if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
226 // ------------------------------------------------------------------------
227 void MonMeshInfo::SetFileName()
228 // ------------------------------------------------------------------------
230 QString fileName0 = LEFileName->text().trimmed();
231 QString fileName = HOMARD_QT_COMMUN::PushNomFichier( false, QString("med") ) ;
232 if (fileName.isEmpty()) fileName = fileName0 ;
233 LEFileName->setText(fileName);
235 // ------------------------------------------------------------------------
236 void MonMeshInfo::CaseNameChanged()
237 // ------------------------------------------------------------------------
239 if (_aCaseName != LECaseName->text().trimmed())
241 LEFileName->setReadOnly(false);
245 // ------------------------------------------------------------------------
246 void MonMeshInfo::SetBlockSize()
247 // ------------------------------------------------------------------------
249 MESSAGE("Debut de SetBlockSize ");
250 if ( CBBlockSize->isChecked() ) { _BlockSize = 1 ; }
251 else { _BlockSize = 0 ; }
253 // ------------------------------------------------------------------------
254 void MonMeshInfo::SetConnection()
255 // ------------------------------------------------------------------------
257 MESSAGE("Debut de SetConnection ");
258 if ( CBConnection->isChecked() ) { _Connection = 1 ; }
259 else { _Connection = 0 ; }
261 // ------------------------------------------------------------------------
262 void MonMeshInfo::SetDiametre()
263 // ------------------------------------------------------------------------
265 MESSAGE("Debut de SetDiametre ");
266 if ( CBDiametre->isChecked() ) { _Diametre = 1 ; }
267 else { _Diametre = 0 ; }
269 // ------------------------------------------------------------------------
270 void MonMeshInfo::SetEntanglement()
271 // ------------------------------------------------------------------------
273 MESSAGE("Debut de SetEntanglement ");
274 if ( CBEntanglement->isChecked() ) { _Entanglement = 1 ; }
275 else { _Entanglement = 0 ; }
277 // ------------------------------------------------------------------------
278 void MonMeshInfo::SetQuality()
279 // ------------------------------------------------------------------------
281 MESSAGE("Debut de SetQuality ");
282 if ( CBQuality->isChecked() ) { _Quality = 1 ; }
283 else { _Quality = 0 ; }