]> SALOME platform Git repositories - modules/homard.git/blob - src/HOMARDGUI/MonMeshInfo.cxx
Salome HOME
Reorganisation des cas-tests et des tutoriaux
[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 using namespace std;
21
22 #include "MonMeshInfo.h"
23
24 #include <QFileDialog>
25 #include <QMessageBox>
26
27 #include "SalomeApp_Tools.h"
28 #include "HOMARDGUI_Utils.h"
29 #include "HomardQtCommun.h"
30 #include "MonEditFile.h"
31 #include <utilities.h>
32
33
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
40  */
41     :
42     Ui_MeshInfo(),
43     _aCaseName(""),_aDirName(""),
44     _BlockSize(0),
45     _Connection(0),
46     _Diametre(0),
47     _Entanglement(0),
48     _Quality(0)
49 {
50       myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen0);
51       setupUi(this);
52       setModal(modal);
53       InitConnect();
54
55       SetNewCaseName() ;
56       adjustSize();
57 }
58
59 // ------------------------------------------------------------------------
60 MonMeshInfo::~MonMeshInfo()
61 // ------------------------------------------------------------------------
62 {
63     // no need to delete child widgets, Qt does it all for us
64 }
65 // ------------------------------------------------------------------------
66 void MonMeshInfo::InitConnect()
67 // ------------------------------------------------------------------------
68 {
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()));
72
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()));
78
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()));
83 }
84 // -------------------------------
85 bool MonMeshInfo::PushOnApply()
86 // --------------------------------
87 {
88   MESSAGE("PushOnApply");
89   QString aCaseName=LECaseName->text().trimmed();
90   if ( aCaseName == "" )
91   {
92     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
93                               QObject::tr("HOM_CASE_NAME") );
94     return false;
95   }
96
97   QString aDirName=LEDirName->text().trimmed();
98   if (aDirName == QString(""))
99   {
100     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
101                               QObject::tr("HOM_CASE_DIRECTORY_1") );
102     return false;
103   }
104   if ( aDirName != _aDirName)
105   { QString CaseNameDir = myHomardGen->VerifieDir( aDirName.toStdString().c_str()) ;
106     if ( CaseNameDir != "" )
107     {
108       QString texte ;
109       texte = QObject::tr("HOM_CASE_DIRECTORY_2") + CaseNameDir ;
110       QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
111                                 texte );
112       return false;
113     }
114   }
115   if (chdir(aDirName.toStdString().c_str()) != 0)
116   {
117     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
118                               QObject::tr("HOM_CASE_DIRECTORY_3") );
119     return false;
120   }
121
122   QString aFileName=LEFileName->text().trimmed();
123   if (aFileName ==QString(""))
124   {
125     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
126                               QObject::tr("HOM_CASE_MESH") );
127     return false;
128   }
129
130   QString aMeshName = HOMARD_QT_COMMUN::LireNomMaillage(aFileName);
131   if (aMeshName == "" )
132   {
133     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
134                               QObject::tr("HOM_MED_FILE_2") );
135     return false;
136   }
137   if ( ( _Quality == 0 ) and ( _Diametre == 0 ) and ( _Connection == 0 ) and ( _BlockSize == 0 ) and ( _Entanglement == 0 ) )
138   {
139     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
140                               QObject::tr("HOM_MESH_INFO") );
141     return false;
142   }
143
144   if (aCaseName != _aCaseName )
145   {
146     _aCaseName = aCaseName;
147     try
148     {
149       myHomardGen->MeshInfo( \
150             CORBA::string_dup(_aCaseName.toStdString().c_str()),  \
151             CORBA::string_dup(aMeshName.toStdString().c_str()),  \
152             CORBA::string_dup(aFileName.toStdString().c_str()),  \
153             CORBA::string_dup(aDirName.toStdString().c_str()),  \
154             _Quality, _Diametre, _Connection, _BlockSize, _Entanglement );
155     }
156     catch( SALOME::SALOME_Exception& S_ex )
157     {
158       QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
159                                 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
160       return false;
161     }
162   }
163
164   // Le bilan de l'analyse a afficher
165   aCase = myHomardGen->GetCase(_aCaseName.toStdString().c_str());
166   string iter0 = aCase->GetIter0Name();
167   HOMARD::HOMARD_Iteration_var aIter =  myHomardGen->GetIteration(iter0.c_str());
168   aFileName = aIter->GetFileInfo() ;
169   MonEditFile *aDlg = new MonEditFile( 0, true, HOMARD::HOMARD_Gen::_duplicate(myHomardGen), aFileName, 1 ) ;
170   if ( aDlg->_codret == 0 ) { aDlg->show(); }
171
172 HOMARD_UTILS::updateObjBrowser();
173   return true;
174 }
175 // ---------------------------
176 void MonMeshInfo::PushOnOK()
177 // ---------------------------
178 {
179   bool bOK = PushOnApply();
180   if ( bOK )  this->close();
181 }
182 //------------------------------
183 void MonMeshInfo::PushOnHelp()
184 //-------------------------------
185 {
186   char* LanguageShort = myHomardGen->GetLanguageShort();
187   HOMARD_UTILS::PushOnHelp(QString("gui_create_case.html"), QString(""), QString(LanguageShort));
188 }
189 // ---------------------------------
190 void MonMeshInfo::SetNewCaseName()
191 // ------------------------------
192 {
193   HOMARD::listeCases_var  MyCases = myHomardGen->GetAllCasesName();
194   int num = 0; QString aCaseName="";
195   while (aCaseName=="" )
196   {
197     aCaseName.setNum(num+1) ;
198     aCaseName.insert(0, QString("Case_")) ;
199     for ( int i=0; i<MyCases->length(); i++)
200     {
201       if ( aCaseName == QString((MyCases)[i]) )
202       {
203         num += 1 ;
204         aCaseName="";
205         break;
206       }
207    }
208   }
209   LECaseName->clear() ;
210   LECaseName->insert(aCaseName);
211 }
212 // ------------------------------------------------------------------------
213 void MonMeshInfo::SetDirName()
214 // ------------------------------------------------------------------------
215 {
216   QString aDirName=QFileDialog::getExistingDirectory ();
217   if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
218 }
219 // ------------------------------------------------------------------------
220 void MonMeshInfo::SetFileName()
221 // ------------------------------------------------------------------------
222 {
223   QString fileName0 = LEFileName->text().trimmed();
224   QString fileName = HOMARD_QT_COMMUN::PushNomFichier();
225   if (fileName.isEmpty()) fileName = fileName0 ;
226   LEFileName->setText(fileName);
227 }
228 // ------------------------------------------------------------------------
229 void MonMeshInfo::CaseNameChanged()
230 // ------------------------------------------------------------------------
231 {
232   if (_aCaseName != LECaseName->text().trimmed())
233   {
234     LEFileName->setReadOnly(false);
235     PushFichier->show();
236   }
237 }
238 // ------------------------------------------------------------------------
239 void MonMeshInfo::SetBlockSize()
240 // ------------------------------------------------------------------------
241 {
242   MESSAGE("Debut de SetBlockSize ");
243   if ( CBBlockSize->isChecked() ) { _BlockSize = 1 ; }
244   else                            { _BlockSize = 0 ; }
245 }
246 // ------------------------------------------------------------------------
247 void MonMeshInfo::SetConnection()
248 // ------------------------------------------------------------------------
249 {
250   MESSAGE("Debut de SetConnection ");
251   if ( CBConnection->isChecked() ) { _Connection = 1 ; }
252   else                             { _Connection = 0 ; }
253 }
254 // ------------------------------------------------------------------------
255 void MonMeshInfo::SetDiametre()
256 // ------------------------------------------------------------------------
257 {
258   MESSAGE("Debut de SetDiametre ");
259   if ( CBDiametre->isChecked() ) { _Diametre = 1 ; }
260   else                           { _Diametre = 0 ; }
261 }
262 // ------------------------------------------------------------------------
263 void MonMeshInfo::SetEntanglement()
264 // ------------------------------------------------------------------------
265 {
266   MESSAGE("Debut de SetEntanglement ");
267   if ( CBEntanglement->isChecked() ) { _Entanglement = 1 ; }
268   else                               { _Entanglement = 0 ; }
269 }
270 // ------------------------------------------------------------------------
271 void MonMeshInfo::SetQuality()
272 // ------------------------------------------------------------------------
273 {
274   MESSAGE("Debut de SetQuality ");
275   if ( CBQuality->isChecked() ) { _Quality = 1 ; }
276   else                          { _Quality = 0 ; }
277 }