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 "MonEditFile.h"
31 #include <utilities.h>
34 // -----------------------------------------------------------------------------------------
35 MonMeshInfo::MonMeshInfo(QWidget* parent, bool modal, HOMARD::HOMARD_Gen_var myHomardGen0)
36 // -----------------------------------------------------------------------------------------
37 /* Constructs a MonMeshInfo
38 * Inherits from CasHomard
39 * Sets attributes to default values
43 _aCaseName(""),_aDirName(""),
50 myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen0);
59 // ------------------------------------------------------------------------
60 MonMeshInfo::~MonMeshInfo()
61 // ------------------------------------------------------------------------
63 // no need to delete child widgets, Qt does it all for us
65 // ------------------------------------------------------------------------
66 void MonMeshInfo::InitConnect()
67 // ------------------------------------------------------------------------
69 connect( LECaseName, SIGNAL(textChanged(QString)), this, SLOT(CaseNameChanged()));
70 connect( PushDir, SIGNAL(pressed()), this, SLOT(SetDirName()));
71 connect( PushFichier, SIGNAL(pressed()), this, SLOT(SetFileName()));
73 connect( CBBlockSize, SIGNAL(stateChanged(int)), this, SLOT(SetBlockSize()));
74 connect( CBConnection, SIGNAL(stateChanged(int)), this, SLOT(SetConnection()));
75 connect( CBDiametre, SIGNAL(stateChanged(int)), this, SLOT(SetDiametre()));
76 connect( CBEntanglement, SIGNAL(stateChanged(int)), this, SLOT(SetEntanglement()));
77 connect( CBQuality, SIGNAL(stateChanged(int)), this, SLOT(SetQuality()));
79 connect( buttonOk, SIGNAL(pressed()), this, SLOT(PushOnOK()));
80 connect( buttonApply, SIGNAL(pressed()), this, SLOT(PushOnApply()));
81 connect( buttonCancel, SIGNAL(pressed()), this, SLOT(close()));
82 connect( buttonHelp, SIGNAL(pressed()), this, SLOT(PushOnHelp()));
84 // -------------------------------
85 bool MonMeshInfo::PushOnApply()
86 // --------------------------------
88 MESSAGE("PushOnApply");
89 QString aCaseName=LECaseName->text().trimmed();
90 if ( aCaseName == "" )
92 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
93 QObject::tr("HOM_CASE_NAME") );
97 QString aDirName=LEDirName->text().trimmed();
98 if (aDirName == QString(""))
100 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
101 QObject::tr("HOM_CASE_DIRECTORY_1") );
104 if ( aDirName != _aDirName)
105 { QString CaseNameDir = myHomardGen->VerifieDir( aDirName.toStdString().c_str()) ;
106 if ( CaseNameDir != "" )
108 INFOS(CaseNameDir.toStdString().c_str());
110 texte = QObject::tr("HOM_CASE_DIRECTORY_2") + CaseNameDir ;
111 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
116 if (chdir(aDirName.toStdString().c_str()) != 0)
118 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
119 QObject::tr("HOM_CASE_DIRECTORY_3") );
123 QString aFileName=LEFileName->text().trimmed();
124 if (aFileName ==QString(""))
126 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
127 QObject::tr("HOM_CASE_MESH") );
131 QString aMeshName = HOMARD_QT_COMMUN::LireNomMaillage(aFileName);
132 if (aMeshName == "" )
134 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
135 QObject::tr("HOM_MED_FILE_2") );
138 if ( ( _Quality == 0 ) and ( _Diametre == 0 ) and ( _Connection == 0 ) and ( _BlockSize == 0 ) and ( _Entanglement == 0 ) )
140 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
141 QObject::tr("HOM_MESH_INFO") );
145 if (aCaseName != _aCaseName )
147 _aCaseName = aCaseName;
150 myHomardGen->MeshInfo( \
151 CORBA::string_dup(_aCaseName.toStdString().c_str()), \
152 CORBA::string_dup(aMeshName.toStdString().c_str()), \
153 CORBA::string_dup(aFileName.toStdString().c_str()), \
154 CORBA::string_dup(aDirName.toStdString().c_str()), \
155 _Quality, _Diametre, _Connection, _BlockSize, _Entanglement );
157 catch( SALOME::SALOME_Exception& S_ex )
159 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
160 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
165 // Le bilan de l'analyse a afficher
166 aCase = myHomardGen->GetCase(_aCaseName.toStdString().c_str());
167 string iter0 = aCase->GetIter0Name();
168 HOMARD::HOMARD_Iteration_var aIter = myHomardGen->GetIteration(iter0.c_str());
169 aFileName = aIter->GetFileInfo() ;
170 MonEditFile *aDlg = new MonEditFile( 0, true, HOMARD::HOMARD_Gen::_duplicate(myHomardGen), aFileName, 1 ) ;
171 if ( aDlg->_codret == 0 ) { aDlg->show(); }
173 HOMARD_UTILS::updateObjBrowser();
176 // ---------------------------
177 void MonMeshInfo::PushOnOK()
178 // ---------------------------
180 bool bOK = PushOnApply();
181 if ( bOK ) this->close();
183 //------------------------------
184 void MonMeshInfo::PushOnHelp()
185 //-------------------------------
187 char* LanguageShort = myHomardGen->GetLanguageShort();
188 HOMARD_UTILS::PushOnHelp(QString("gui_create_case.html"), QString(""), QString(LanguageShort));
190 // ---------------------------------
191 void MonMeshInfo::SetNewCaseName()
192 // ------------------------------
194 HOMARD::listeCases_var MyCases = myHomardGen->GetAllCasesName();
195 int num = 0; QString aCaseName="";
196 while (aCaseName=="" )
198 aCaseName.setNum(num+1) ;
199 aCaseName.insert(0, QString("Case_")) ;
200 for ( int i=0; i<MyCases->length(); i++)
202 if ( aCaseName == QString((MyCases)[i]) )
210 LECaseName->clear() ;
211 LECaseName->insert(aCaseName);
213 // ------------------------------------------------------------------------
214 void MonMeshInfo::SetDirName()
215 // ------------------------------------------------------------------------
217 QString aDirName=QFileDialog::getExistingDirectory ();
218 if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
220 // ------------------------------------------------------------------------
221 void MonMeshInfo::SetFileName()
222 // ------------------------------------------------------------------------
224 QString fileName0 = LEFileName->text().trimmed();
225 QString fileName = HOMARD_QT_COMMUN::PushNomFichier();
226 if (fileName.isEmpty()) fileName = fileName0 ;
227 LEFileName->setText(fileName);
229 // ------------------------------------------------------------------------
230 void MonMeshInfo::CaseNameChanged()
231 // ------------------------------------------------------------------------
233 if (_aCaseName != LECaseName->text().trimmed())
235 LEFileName->setReadOnly(false);
239 // ------------------------------------------------------------------------
240 void MonMeshInfo::SetBlockSize()
241 // ------------------------------------------------------------------------
243 MESSAGE("Debut de SetBlockSize ");
244 if ( CBBlockSize->isChecked() ) { _BlockSize = 1 ; }
245 else { _BlockSize = 0 ; }
247 // ------------------------------------------------------------------------
248 void MonMeshInfo::SetConnection()
249 // ------------------------------------------------------------------------
251 MESSAGE("Debut de SetConnection ");
252 if ( CBConnection->isChecked() ) { _Connection = 1 ; }
253 else { _Connection = 0 ; }
255 // ------------------------------------------------------------------------
256 void MonMeshInfo::SetDiametre()
257 // ------------------------------------------------------------------------
259 MESSAGE("Debut de SetDiametre ");
260 if ( CBDiametre->isChecked() ) { _Diametre = 1 ; }
261 else { _Diametre = 0 ; }
263 // ------------------------------------------------------------------------
264 void MonMeshInfo::SetEntanglement()
265 // ------------------------------------------------------------------------
267 MESSAGE("Debut de SetEntanglement ");
268 if ( CBEntanglement->isChecked() ) { _Entanglement = 1 ; }
269 else { _Entanglement = 0 ; }
271 // ------------------------------------------------------------------------
272 void MonMeshInfo::SetQuality()
273 // ------------------------------------------------------------------------
275 MESSAGE("Debut de SetQuality ");
276 if ( CBQuality->isChecked() ) { _Quality = 1 ; }
277 else { _Quality = 0 ; }