Salome HOME
Filtrage des types de fichiers dans la sélection
[modules/homard.git] / src / HOMARDGUI / MonMeshInfo.cxx
1 // Copyright (C) 2011-2013  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "MonMeshInfo.h"
21
22 #include <QFileDialog>
23 #include <QMessageBox>
24
25 #include "SalomeApp_Tools.h"
26 #include "HOMARDGUI_Utils.h"
27 #include "HomardQtCommun.h"
28 #include "MonEditFile.h"
29 #include <utilities.h>
30
31 #ifdef WIN32
32 #include <direct.h>
33 #endif
34
35 using namespace std;
36
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
43  */
44     :
45     Ui_MeshInfo(),
46     _aCaseName(""),_aDirName(""),
47     _BlockSize(0),
48     _Connection(0),
49     _Diametre(0),
50     _Entanglement(0),
51     _Quality(0)
52 {
53       myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen0);
54       setupUi(this);
55       setModal(modal);
56       InitConnect();
57
58       SetNewCaseName() ;
59       adjustSize();
60 }
61
62 // ------------------------------------------------------------------------
63 MonMeshInfo::~MonMeshInfo()
64 // ------------------------------------------------------------------------
65 {
66     // no need to delete child widgets, Qt does it all for us
67 }
68 // ------------------------------------------------------------------------
69 void MonMeshInfo::InitConnect()
70 // ------------------------------------------------------------------------
71 {
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()));
75
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()));
81
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()));
86 }
87 // -------------------------------
88 bool MonMeshInfo::PushOnApply()
89 // --------------------------------
90 {
91   MESSAGE("PushOnApply");
92   QString aCaseName=LECaseName->text().trimmed();
93   if ( aCaseName == "" )
94   {
95     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
96                               QObject::tr("HOM_CASE_NAME") );
97     return false;
98   }
99
100   QString aDirName=LEDirName->text().trimmed();
101   if (aDirName == QString(""))
102   {
103     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
104                               QObject::tr("HOM_CASE_DIRECTORY_1") );
105     return false;
106   }
107   if ( aDirName != _aDirName)
108   { QString CaseNameDir = myHomardGen->VerifieDir( aDirName.toStdString().c_str()) ;
109     if ( CaseNameDir != "" )
110     {
111       QString texte ;
112       texte = QObject::tr("HOM_CASE_DIRECTORY_2") + CaseNameDir ;
113       QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
114                                 texte );
115       return false;
116     }
117   }
118 #ifndef WIN32
119   if (chdir(aDirName.toStdString().c_str()) != 0)
120 #else
121   if (_chdir(aDirName.toStdString().c_str()) != 0)
122 #endif
123   {
124     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
125                               QObject::tr("HOM_CASE_DIRECTORY_3") );
126     return false;
127   }
128
129   QString aFileName=LEFileName->text().trimmed();
130   if (aFileName ==QString(""))
131   {
132     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
133                               QObject::tr("HOM_CASE_MESH") );
134     return false;
135   }
136
137   QString aMeshName = HOMARD_QT_COMMUN::LireNomMaillage(aFileName);
138   if (aMeshName == "" )
139   {
140     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
141                               QObject::tr("HOM_MED_FILE_2") );
142     return false;
143   }
144   if ( ( _Quality == 0 ) && ( _Diametre == 0 ) && ( _Connection == 0 ) && ( _BlockSize == 0 ) && ( _Entanglement == 0 ) )
145   {
146     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
147                               QObject::tr("HOM_MESH_INFO") );
148     return false;
149   }
150
151   if (aCaseName != _aCaseName )
152   {
153     _aCaseName = aCaseName;
154     try
155     {
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 );
162     }
163     catch( SALOME::SALOME_Exception& S_ex )
164     {
165       QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
166                                 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
167       return false;
168     }
169   }
170
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(); }
178
179 HOMARD_UTILS::updateObjBrowser();
180   return true;
181 }
182 // ---------------------------
183 void MonMeshInfo::PushOnOK()
184 // ---------------------------
185 {
186   bool bOK = PushOnApply();
187   if ( bOK )  this->close();
188 }
189 //------------------------------
190 void MonMeshInfo::PushOnHelp()
191 //-------------------------------
192 {
193   char* LanguageShort = myHomardGen->GetLanguageShort();
194   HOMARD_UTILS::PushOnHelp(QString("gui_create_case.html"), QString(""), QString(LanguageShort));
195 }
196 // ---------------------------------
197 void MonMeshInfo::SetNewCaseName()
198 // ------------------------------
199 {
200   HOMARD::listeCases_var  MyCases = myHomardGen->GetAllCasesName();
201   int num = 0; QString aCaseName="";
202   while (aCaseName=="" )
203   {
204     aCaseName.setNum(num+1) ;
205     aCaseName.insert(0, QString("Case_")) ;
206     for ( int i=0; i<MyCases->length(); i++)
207     {
208       if ( aCaseName == QString((MyCases)[i]) )
209       {
210         num ++ ;
211         aCaseName = "" ;
212         break ;
213       }
214    }
215   }
216   LECaseName->clear() ;
217   LECaseName->insert(aCaseName);
218 }
219 // ------------------------------------------------------------------------
220 void MonMeshInfo::SetDirName()
221 // ------------------------------------------------------------------------
222 {
223   QString aDirName=QFileDialog::getExistingDirectory ();
224   if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
225 }
226 // ------------------------------------------------------------------------
227 void MonMeshInfo::SetFileName()
228 // ------------------------------------------------------------------------
229 {
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);
234 }
235 // ------------------------------------------------------------------------
236 void MonMeshInfo::CaseNameChanged()
237 // ------------------------------------------------------------------------
238 {
239   if (_aCaseName != LECaseName->text().trimmed())
240   {
241     LEFileName->setReadOnly(false);
242     PushFichier->show();
243   }
244 }
245 // ------------------------------------------------------------------------
246 void MonMeshInfo::SetBlockSize()
247 // ------------------------------------------------------------------------
248 {
249   MESSAGE("Debut de SetBlockSize ");
250   if ( CBBlockSize->isChecked() ) { _BlockSize = 1 ; }
251   else                            { _BlockSize = 0 ; }
252 }
253 // ------------------------------------------------------------------------
254 void MonMeshInfo::SetConnection()
255 // ------------------------------------------------------------------------
256 {
257   MESSAGE("Debut de SetConnection ");
258   if ( CBConnection->isChecked() ) { _Connection = 1 ; }
259   else                             { _Connection = 0 ; }
260 }
261 // ------------------------------------------------------------------------
262 void MonMeshInfo::SetDiametre()
263 // ------------------------------------------------------------------------
264 {
265   MESSAGE("Debut de SetDiametre ");
266   if ( CBDiametre->isChecked() ) { _Diametre = 1 ; }
267   else                           { _Diametre = 0 ; }
268 }
269 // ------------------------------------------------------------------------
270 void MonMeshInfo::SetEntanglement()
271 // ------------------------------------------------------------------------
272 {
273   MESSAGE("Debut de SetEntanglement ");
274   if ( CBEntanglement->isChecked() ) { _Entanglement = 1 ; }
275   else                               { _Entanglement = 0 ; }
276 }
277 // ------------------------------------------------------------------------
278 void MonMeshInfo::SetQuality()
279 // ------------------------------------------------------------------------
280 {
281   MESSAGE("Debut de SetQuality ");
282   if ( CBQuality->isChecked() ) { _Quality = 1 ; }
283   else                          { _Quality = 0 ; }
284 }