Salome HOME
Merge from V6_main 01/04/2013
[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 <utilities.h>
31
32
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
39  */
40     :
41     Ui_MeshInfo(),
42     _aCaseName(""),_aDirName(""),
43     _BlockSize(0),
44     _Connection(0),
45     _Diametre(0),
46     _Entanglement(0),
47     _Quality(0)
48 {
49       _myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen);
50       setupUi(this);
51       setModal(modal);
52       InitConnect();
53
54       SetNewCaseName() ;
55       adjustSize();
56 }
57
58 // ------------------------------------------------------------------------
59 MonMeshInfo::~MonMeshInfo()
60 // ------------------------------------------------------------------------
61 {
62     // no need to delete child widgets, Qt does it all for us
63 }
64 // ------------------------------------------------------------------------
65 void MonMeshInfo::InitConnect()
66 // ------------------------------------------------------------------------
67 {
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()));
71
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()));
77
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()));
82 }
83 // -------------------------------
84 bool MonMeshInfo::PushOnApply()
85 // --------------------------------
86 {
87   MESSAGE("PushOnApply");
88   QString aCaseName=LECaseName->text().trimmed();
89   if ( aCaseName == "" )
90   {
91     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
92                               QObject::tr("HOM_CASE_NAME") );
93     return false;
94   }
95
96   QString aDirName=LEDirName->text().trimmed();
97   if (aDirName == QString(""))
98   {
99     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
100                               QObject::tr("HOM_CASE_DIRECTORY_1") );
101     return false;
102   }
103   if ((aDirName != _aDirName) and (_myHomardGen->VerifieDir( aDirName.toStdString().c_str()) == false))
104   {
105     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
106                               QObject::tr("HOM_CASE_DIRECTORY_2") );
107     return false;
108   }
109   if (chdir(aDirName.toStdString().c_str()) != 0)
110   {
111     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
112                               QObject::tr("HOM_CASE_DIRECTORY_3") );
113     return false;
114   }
115
116   QString aFileName=LEFileName->text().trimmed();
117   if (aFileName ==QString(""))
118   {
119     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
120                               QObject::tr("HOM_CASE_MESH") );
121     return false;
122   }
123
124   QString aMeshName = HOMARD_QT_COMMUN::LireNomMaillage(aFileName);
125   if (aMeshName == "" )
126   {
127     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
128                               QObject::tr("HOM_MED_FILE_2") );
129     return false;
130   }
131   if ( ( _Quality == 0 ) and ( _Diametre == 0 ) and ( _Connection == 0 ) and ( _BlockSize == 0 ) and ( _Entanglement == 0 ) )
132   {
133     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
134                               QObject::tr("HOM_MESH_INFO") );
135     return false;
136   }
137
138   if (aCaseName != _aCaseName )
139   {
140     _aCaseName = aCaseName;
141     try
142     {
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 );
149     }
150     catch( SALOME::SALOME_Exception& S_ex )
151     {
152       QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
153                                 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
154       return false;
155     }
156   }
157
158   HOMARD_UTILS::updateObjBrowser();
159   return true;
160 }
161 // ---------------------------
162 void MonMeshInfo::PushOnOK()
163 // ---------------------------
164 {
165      bool bOK = PushOnApply();
166      if ( bOK )  this->close();
167 }
168 //------------------------------
169 void MonMeshInfo::PushOnHelp()
170 //-------------------------------
171 {
172   HOMARD_UTILS::PushOnHelp(QString("gui_create_case.html"));
173 }
174 // ---------------------------------
175 void MonMeshInfo::SetNewCaseName()
176 // ------------------------------
177 {
178   HOMARD::listeCases_var  MyCases = _myHomardGen->GetAllCasesName();
179   int num = 0; QString aCaseName="";
180   while (aCaseName=="" )
181   {
182     aCaseName.setNum(num+1) ;
183     aCaseName.insert(0, QString("Case_")) ;
184     for ( int i=0; i<MyCases->length(); i++)
185     {
186       if ( aCaseName ==  QString((MyCases)[i]))
187       {
188           num=num+1;
189           aCaseName="";
190           break;
191       }
192    }
193   }
194   LECaseName->clear() ;
195   LECaseName->insert(aCaseName);
196 }
197
198 // ------------------------------------------------------------------------
199 void MonMeshInfo::SetDirName()
200 // ------------------------------------------------------------------------
201 {
202   QString aDirName=QFileDialog::getExistingDirectory ();
203   if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
204 }
205 // ------------------------------------------------------------------------
206 void MonMeshInfo::SetFileName()
207 // ------------------------------------------------------------------------
208 {
209   QString fileName0 = LEFileName->text().trimmed();
210   QString fileName = HOMARD_QT_COMMUN::PushNomFichier();
211   if (fileName.isEmpty()) fileName = fileName0 ;
212   LEFileName->setText(fileName);
213 }
214 // ------------------------------------------------------------------------
215 void MonMeshInfo::CaseNameChanged()
216 // ------------------------------------------------------------------------
217 {
218     if (_aCaseName != LECaseName->text().trimmed())
219     {
220        LEFileName->setReadOnly(false);
221        PushFichier->show();
222     }
223 }
224 // ------------------------------------------------------------------------
225 void MonMeshInfo::SetBlockSize()
226 // ------------------------------------------------------------------------
227 {
228   MESSAGE("Debut de SetBlockSize ");
229   if ( CBBlockSize->isChecked() ) { _BlockSize = 1 ; }
230   else                            { _BlockSize = 0 ; }
231 }
232 // ------------------------------------------------------------------------
233 void MonMeshInfo::SetConnection()
234 // ------------------------------------------------------------------------
235 {
236   MESSAGE("Debut de SetConnection ");
237   if ( CBConnection->isChecked() ) { _Connection = 1 ; }
238   else                             { _Connection = 0 ; }
239 }
240 // ------------------------------------------------------------------------
241 void MonMeshInfo::SetDiametre()
242 // ------------------------------------------------------------------------
243 {
244   MESSAGE("Debut de SetDiametre ");
245   if ( CBDiametre->isChecked() ) { _Diametre = 1 ; }
246   else                           { _Diametre = 0 ; }
247 }
248 // ------------------------------------------------------------------------
249 void MonMeshInfo::SetEntanglement()
250 // ------------------------------------------------------------------------
251 {
252   MESSAGE("Debut de SetEntanglement ");
253   if ( CBEntanglement->isChecked() ) { _Entanglement = 1 ; }
254   else                               { _Entanglement = 0 ; }
255 }
256 // ------------------------------------------------------------------------
257 void MonMeshInfo::SetQuality()
258 // ------------------------------------------------------------------------
259 {
260   MESSAGE("Debut de SetQuality ");
261   if ( CBQuality->isChecked() ) { _Quality = 1 ; }
262   else                          { _Quality = 0 ; }
263 }