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