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 "MonMeshInfo.h"
23 #include <QFileDialog>
24 #include <QMessageBox>
26 #include "SalomeApp_Tools.h"
27 #include "HOMARDGUI_Utils.h"
28 #include "HomardQtCommun.h"
29 #include "MonEditFile.h"
30 #include <utilities.h>
38 // -----------------------------------------------------------------------------------------
39 MonMeshInfo::MonMeshInfo(QWidget* parent, bool modal, ADAPT::ADAPT_Gen_var myAdaptGen0)
40 // -----------------------------------------------------------------------------------------
41 /* Constructs a MonMeshInfo
42 * Inherits from CasHomard
43 * Sets attributes to default values
47 _aCaseName(""),_aDirName(""),
54 myAdaptGen=ADAPT::ADAPT_Gen::_duplicate(myAdaptGen0);
63 // ------------------------------------------------------------------------
64 MonMeshInfo::~MonMeshInfo()
65 // ------------------------------------------------------------------------
67 // no need to delete child widgets, Qt does it all for us
69 // ------------------------------------------------------------------------
70 void MonMeshInfo::InitConnect()
71 // ------------------------------------------------------------------------
73 connect( LECaseName, SIGNAL(textChanged(QString)), this, SLOT(CaseNameChanged()));
74 connect( PushDir, SIGNAL(pressed()), this, SLOT(SetDirName()));
75 connect( PushFichier, SIGNAL(pressed()), this, SLOT(SetFileName()));
77 connect( CBBlockSize, SIGNAL(stateChanged(int)), this, SLOT(SetBlockSize()));
78 connect( CBConnection, SIGNAL(stateChanged(int)), this, SLOT(SetConnection()));
79 connect( CBDiametre, SIGNAL(stateChanged(int)), this, SLOT(SetDiametre()));
80 connect( CBEntanglement, SIGNAL(stateChanged(int)), this, SLOT(SetEntanglement()));
81 connect( CBQuality, SIGNAL(stateChanged(int)), this, SLOT(SetQuality()));
83 connect( buttonOk, SIGNAL(pressed()), this, SLOT(PushOnOK()));
84 connect( buttonApply, SIGNAL(pressed()), this, SLOT(PushOnApply()));
85 connect( buttonCancel, SIGNAL(pressed()), this, SLOT(close()));
86 connect( buttonHelp, SIGNAL(pressed()), this, SLOT(PushOnHelp()));
88 // -------------------------------
89 bool MonMeshInfo::PushOnApply()
90 // --------------------------------
92 MESSAGE("PushOnApply");
93 QString aCaseName=LECaseName->text().trimmed();
94 if ( aCaseName == "" )
96 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
97 QObject::tr("HOM_CASE_NAME") );
101 QString aDirName=LEDirName->text().trimmed();
102 if (aDirName == QString(""))
104 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
105 QObject::tr("HOM_CASE_DIRECTORY_1") );
108 if ( aDirName != _aDirName)
109 { QString CaseNameDir = myAdaptGen->VerifieDir( aDirName.toStdString().c_str()) ;
110 if ( CaseNameDir != "" )
113 texte = QObject::tr("HOM_CASE_DIRECTORY_2") + CaseNameDir ;
114 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
119 if (CHDIR(aDirName.toStdString().c_str()) != 0)
121 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
122 QObject::tr("HOM_CASE_DIRECTORY_3") );
126 QString aFileName=LEFileName->text().trimmed();
127 if (aFileName ==QString(""))
129 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
130 QObject::tr("HOM_CASE_MESH") );
134 QString aMeshName = HOMARD_QT_COMMUN::LireNomMaillage(aFileName);
135 if (aMeshName == "" )
137 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
138 QObject::tr("HOM_MED_FILE_2") );
141 if ( ( _Quality == 0 ) && ( _Diametre == 0 ) && ( _Connection == 0 ) && ( _BlockSize == 0 ) && ( _Entanglement == 0 ) )
143 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
144 QObject::tr("HOM_MESH_INFO") );
148 if (aCaseName != _aCaseName )
150 _aCaseName = aCaseName;
153 myAdaptGen->MeshInfo( \
154 CORBA::string_dup(_aCaseName.toStdString().c_str()), \
155 CORBA::string_dup(aMeshName.toStdString().c_str()), \
156 CORBA::string_dup(aFileName.toStdString().c_str()), \
157 CORBA::string_dup(aDirName.toStdString().c_str()), \
158 _Quality, _Diametre, _Connection, _BlockSize, _Entanglement );
160 catch( SALOME::SALOME_Exception& S_ex )
162 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
163 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
168 // Le bilan de l'analyse a afficher
169 aCase = myAdaptGen->GetCase(_aCaseName.toStdString().c_str());
170 string iter0 = aCase->GetIter0Name();
171 ADAPT::HOMARD_Iteration_var aIter = myAdaptGen->GetIteration(iter0.c_str());
172 aFileName = aIter->GetFileInfo() ;
173 MonEditFile *aDlg = new MonEditFile( 0, true, ADAPT::ADAPT_Gen::_duplicate(myAdaptGen), aFileName, 1 ) ;
174 if ( aDlg->_codret == 0 ) { aDlg->show(); }
176 HOMARD_UTILS::updateObjBrowser();
179 // ---------------------------
180 void MonMeshInfo::PushOnOK()
181 // ---------------------------
183 bool bOK = PushOnApply();
184 if ( bOK ) this->close();
186 //------------------------------
187 void MonMeshInfo::PushOnHelp()
188 //-------------------------------
190 std::string LanguageShort = myAdaptGen->GetLanguageShort();
191 HOMARD_UTILS::PushOnHelp(QString("gui_create_case.html"), QString(""), QString(LanguageShort.c_str()));
193 // ---------------------------------
194 void MonMeshInfo::SetNewCaseName()
195 // ------------------------------
197 ADAPT::listeCases_var MyCases = myAdaptGen->GetAllCasesName();
198 int num = 0; QString aCaseName="";
199 while (aCaseName=="" )
201 aCaseName.setNum(num+1) ;
202 aCaseName.insert(0, QString("Case_")) ;
203 for ( int i=0; i<MyCases->length(); i++)
205 if ( aCaseName == QString((MyCases)[i]) )
213 LECaseName->clear() ;
214 LECaseName->insert(aCaseName);
216 // ------------------------------------------------------------------------
217 void MonMeshInfo::SetDirName()
218 // ------------------------------------------------------------------------
220 QString aDirName=QFileDialog::getExistingDirectory ();
221 if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
223 // ------------------------------------------------------------------------
224 void MonMeshInfo::SetFileName()
225 // ------------------------------------------------------------------------
227 QString fileName0 = LEFileName->text().trimmed();
228 QString fileName = HOMARD_QT_COMMUN::PushNomFichier( false, QString("med") ) ;
229 if (fileName.isEmpty()) fileName = fileName0 ;
230 LEFileName->setText(fileName);
232 // ------------------------------------------------------------------------
233 void MonMeshInfo::CaseNameChanged()
234 // ------------------------------------------------------------------------
236 if (_aCaseName != LECaseName->text().trimmed())
238 LEFileName->setReadOnly(false);
242 // ------------------------------------------------------------------------
243 void MonMeshInfo::SetBlockSize()
244 // ------------------------------------------------------------------------
246 MESSAGE("Debut de SetBlockSize ");
247 if ( CBBlockSize->isChecked() ) { _BlockSize = 1 ; }
248 else { _BlockSize = 0 ; }
250 // ------------------------------------------------------------------------
251 void MonMeshInfo::SetConnection()
252 // ------------------------------------------------------------------------
254 MESSAGE("Debut de SetConnection ");
255 if ( CBConnection->isChecked() ) { _Connection = 1 ; }
256 else { _Connection = 0 ; }
258 // ------------------------------------------------------------------------
259 void MonMeshInfo::SetDiametre()
260 // ------------------------------------------------------------------------
262 MESSAGE("Debut de SetDiametre ");
263 if ( CBDiametre->isChecked() ) { _Diametre = 1 ; }
264 else { _Diametre = 0 ; }
266 // ------------------------------------------------------------------------
267 void MonMeshInfo::SetEntanglement()
268 // ------------------------------------------------------------------------
270 MESSAGE("Debut de SetEntanglement ");
271 if ( CBEntanglement->isChecked() ) { _Entanglement = 1 ; }
272 else { _Entanglement = 0 ; }
274 // ------------------------------------------------------------------------
275 void MonMeshInfo::SetQuality()
276 // ------------------------------------------------------------------------
278 MESSAGE("Debut de SetQuality ");
279 if ( CBQuality->isChecked() ) { _Quality = 1 ; }
280 else { _Quality = 0 ; }