1 // Copyright (C) 2011-2013 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
22 #include "MonMeshInfo.h"
24 #include <QFileDialog>
25 #include <QMessageBox>
27 #include "SalomeApp_Tools.h"
28 #include "HOMARDGUI_Utils.h"
29 #include "HomardQtCommun.h"
30 #include <utilities.h>
33 // -----------------------------------------------------------------------------------------
34 MonMeshInfo::MonMeshInfo(QWidget* parent, bool modal, HOMARD::HOMARD_Gen_var myHomardGen)
35 // -----------------------------------------------------------------------------------------
36 /* Constructs a MonMeshInfo
37 * Inherits from CasHomard
38 * Sets attributes to default values
42 _aCaseName(""),_aDirName(""),
49 _myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen);
58 // ------------------------------------------------------------------------
59 MonMeshInfo::~MonMeshInfo()
60 // ------------------------------------------------------------------------
62 // no need to delete child widgets, Qt does it all for us
64 // ------------------------------------------------------------------------
65 void MonMeshInfo::InitConnect()
66 // ------------------------------------------------------------------------
68 connect( LECaseName, SIGNAL(textChanged(QString)), this, SLOT(CaseNameChanged()));
69 connect( PushDir, SIGNAL(pressed()), this, SLOT(SetDirName()));
70 connect( PushFichier, SIGNAL(pressed()), this, SLOT(SetFileName()));
72 connect( CBBlockSize, SIGNAL(stateChanged(int)), this, SLOT(SetBlockSize()));
73 connect( CBConnection, SIGNAL(stateChanged(int)), this, SLOT(SetConnection()));
74 connect( CBDiametre, SIGNAL(stateChanged(int)), this, SLOT(SetDiametre()));
75 connect( CBEntanglement, SIGNAL(stateChanged(int)), this, SLOT(SetEntanglement()));
76 connect( CBQuality, SIGNAL(stateChanged(int)), this, SLOT(SetQuality()));
78 connect( buttonOk, SIGNAL(pressed()), this, SLOT(PushOnOK()));
79 connect( buttonApply, SIGNAL(pressed()), this, SLOT(PushOnApply()));
80 connect( buttonCancel, SIGNAL(pressed()), this, SLOT(close()));
81 connect( buttonHelp, SIGNAL(pressed()), this, SLOT(PushOnHelp()));
83 // -------------------------------
84 bool MonMeshInfo::PushOnApply()
85 // --------------------------------
87 MESSAGE("PushOnApply");
88 QString aCaseName=LECaseName->text().trimmed();
89 if ( aCaseName == "" )
91 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
92 QObject::tr("HOM_CASE_NAME") );
96 QString aDirName=LEDirName->text().trimmed();
97 if (aDirName == QString(""))
99 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
100 QObject::tr("HOM_CASE_DIRECTORY_1") );
103 if ((aDirName != _aDirName) and (_myHomardGen->VerifieDir( aDirName.toStdString().c_str()) == false))
105 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
106 QObject::tr("HOM_CASE_DIRECTORY_2") );
109 if (chdir(aDirName.toStdString().c_str()) != 0)
111 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
112 QObject::tr("HOM_CASE_DIRECTORY_3") );
116 QString aFileName=LEFileName->text().trimmed();
117 if (aFileName ==QString(""))
119 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
120 QObject::tr("HOM_CASE_MESH") );
124 QString aMeshName = HOMARD_QT_COMMUN::LireNomMaillage(aFileName);
125 if (aMeshName == "" )
127 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
128 QObject::tr("HOM_MED_FILE_2") );
131 if ( ( _Quality == 0 ) and ( _Diametre == 0 ) and ( _Connection == 0 ) and ( _BlockSize == 0 ) and ( _Entanglement == 0 ) )
133 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
134 QObject::tr("HOM_MESH_INFO") );
138 if (aCaseName != _aCaseName )
140 _aCaseName = aCaseName;
143 _myHomardGen->MeshInfo( \
144 CORBA::string_dup(_aCaseName.toStdString().c_str()), \
145 CORBA::string_dup(aMeshName.toStdString().c_str()), \
146 CORBA::string_dup(aFileName.toStdString().c_str()), \
147 CORBA::string_dup(aDirName.toStdString().c_str()), \
148 _Quality, _Diametre, _Connection, _BlockSize, _Entanglement );
150 catch( SALOME::SALOME_Exception& S_ex )
152 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
153 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
158 HOMARD_UTILS::updateObjBrowser();
161 // ---------------------------
162 void MonMeshInfo::PushOnOK()
163 // ---------------------------
165 bool bOK = PushOnApply();
166 if ( bOK ) this->close();
168 //------------------------------
169 void MonMeshInfo::PushOnHelp()
170 //-------------------------------
172 HOMARD_UTILS::PushOnHelp(QString("gui_create_case.html"));
174 // ---------------------------------
175 void MonMeshInfo::SetNewCaseName()
176 // ------------------------------
178 HOMARD::listeCases_var MyCases = _myHomardGen->GetAllCasesName();
179 int num = 0; QString aCaseName="";
180 while (aCaseName=="" )
182 aCaseName.setNum(num+1) ;
183 aCaseName.insert(0, QString("Case_")) ;
184 for ( int i=0; i<MyCases->length(); i++)
186 if ( aCaseName == QString((MyCases)[i]))
194 LECaseName->clear() ;
195 LECaseName->insert(aCaseName);
198 // ------------------------------------------------------------------------
199 void MonMeshInfo::SetDirName()
200 // ------------------------------------------------------------------------
202 QString aDirName=QFileDialog::getExistingDirectory ();
203 if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
205 // ------------------------------------------------------------------------
206 void MonMeshInfo::SetFileName()
207 // ------------------------------------------------------------------------
209 QString fileName0 = LEFileName->text().trimmed();
210 QString fileName = HOMARD_QT_COMMUN::PushNomFichier();
211 if (fileName.isEmpty()) fileName = fileName0 ;
212 LEFileName->setText(fileName);
214 // ------------------------------------------------------------------------
215 void MonMeshInfo::CaseNameChanged()
216 // ------------------------------------------------------------------------
218 if (_aCaseName != LECaseName->text().trimmed())
220 LEFileName->setReadOnly(false);
224 // ------------------------------------------------------------------------
225 void MonMeshInfo::SetBlockSize()
226 // ------------------------------------------------------------------------
228 MESSAGE("Debut de SetBlockSize ");
229 if ( CBBlockSize->isChecked() ) { _BlockSize = 1 ; }
230 else { _BlockSize = 0 ; }
232 // ------------------------------------------------------------------------
233 void MonMeshInfo::SetConnection()
234 // ------------------------------------------------------------------------
236 MESSAGE("Debut de SetConnection ");
237 if ( CBConnection->isChecked() ) { _Connection = 1 ; }
238 else { _Connection = 0 ; }
240 // ------------------------------------------------------------------------
241 void MonMeshInfo::SetDiametre()
242 // ------------------------------------------------------------------------
244 MESSAGE("Debut de SetDiametre ");
245 if ( CBDiametre->isChecked() ) { _Diametre = 1 ; }
246 else { _Diametre = 0 ; }
248 // ------------------------------------------------------------------------
249 void MonMeshInfo::SetEntanglement()
250 // ------------------------------------------------------------------------
252 MESSAGE("Debut de SetEntanglement ");
253 if ( CBEntanglement->isChecked() ) { _Entanglement = 1 ; }
254 else { _Entanglement = 0 ; }
256 // ------------------------------------------------------------------------
257 void MonMeshInfo::SetQuality()
258 // ------------------------------------------------------------------------
260 MESSAGE("Debut de SetQuality ");
261 if ( CBQuality->isChecked() ) { _Quality = 1 ; }
262 else { _Quality = 0 ; }