]> SALOME platform Git repositories - modules/homard.git/blob - src/HOMARDGUI/MonCreateCase.cxx
Salome HOME
82adec493cc5cbc36b529cae62d8f4314a11acf5
[modules/homard.git] / src / HOMARDGUI / MonCreateCase.cxx
1 // Copyright (C) 2011-2015  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 "MonCreateCase.h"
21 #include "MonCreateBoundaryAn.h"
22 #include "MonEditBoundaryAn.h"
23 #include "MonCreateBoundaryDi.h"
24 #include "MonEditBoundaryDi.h"
25 #include "HOMARD.hxx"
26
27 #include <QFileDialog>
28 #include <QMessageBox>
29
30 #include "SalomeApp_Tools.h"
31 #include "HOMARDGUI_Utils.h"
32 #include "HomardQtCommun.h"
33 #include <utilities.h>
34
35 #ifdef WIN32
36 #include <direct.h>
37 #endif
38
39 using namespace std;
40
41 // -----------------------------------------------------------------------------------------
42 /* Constructs a MonCreateCase
43  * Inherits from CasHomard
44  * Sets attributes to default values
45  */
46 // -----------------------------------------------------------------------------------------
47 MonCreateCase::MonCreateCase( bool modal, HOMARD::HOMARD_Gen_var myHomardGen0 )
48     :
49     Ui_CreateCase(),
50     _aCaseName(""),_aDirName(""),
51     _ConfType(0),
52     _Pyram(0)
53 {
54   MESSAGE("Debut du constructeur de MonCreateCase");
55   myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen0);
56   setupUi(this);
57   setModal(modal);
58   InitConnect();
59
60   SetNewName() ;
61   GBBoundaryA->setVisible(0);
62   GBBoundaryD->setVisible(0);
63   GBAdvancedOptions->setVisible(0);
64   Comment->setVisible(0);
65   CBPyramid->setChecked(false);
66 //
67   adjustSize();
68
69 //   MESSAGE("Fin du constructeur de MonCreateCase");
70 }
71 // ------------------------------------------------------------------------
72 MonCreateCase::~MonCreateCase()
73 // ------------------------------------------------------------------------
74 {
75     // no need to delete child widgets, Qt does it all for us
76 }
77 // ------------------------------------------------------------------------
78 void MonCreateCase::InitConnect()
79 // ------------------------------------------------------------------------
80 {
81     connect( LEName,     SIGNAL(textChanged(QString)), this, SLOT(CaseNameChanged()));
82     connect( PushDir,        SIGNAL(pressed()), this, SLOT(SetDirName()));
83     connect( PushFichier,    SIGNAL(pressed()), this, SLOT(SetFileName()));
84
85     connect( RBConforme,     SIGNAL(clicked()), this, SLOT(SetConforme()));
86     connect( RBNonConforme,  SIGNAL(clicked()), this, SLOT(SetNonConforme()));
87
88     connect( CBBoundaryD,      SIGNAL(stateChanged(int)), this, SLOT(SetBoundaryD()));
89     connect( PBBoundaryDiNew,  SIGNAL(pressed()), this, SLOT(PushBoundaryDiNew()));
90     connect( PBBoundaryDiEdit, SIGNAL(pressed()), this, SLOT(PushBoundaryDiEdit()) );
91     connect( PBBoundaryDiHelp, SIGNAL(pressed()), this, SLOT(PushBoundaryDiHelp()) );
92     connect( CBBoundaryA,      SIGNAL(stateChanged(int)), this, SLOT(SetBoundaryA()));
93     connect( PBBoundaryAnNew,  SIGNAL(pressed()), this, SLOT(PushBoundaryAnNew()));
94     connect( PBBoundaryAnEdit, SIGNAL(pressed()), this, SLOT(PushBoundaryAnEdit()) );
95     connect( PBBoundaryAnHelp, SIGNAL(pressed()), this, SLOT(PushBoundaryAnHelp()) );
96
97     connect( CBAdvanced,     SIGNAL(stateChanged(int)), this, SLOT(SetAdvanced()));
98     connect( RBStandard,     SIGNAL(clicked()), this, SLOT(SetStandard()));
99     connect( RBBox,          SIGNAL(clicked()), this, SLOT(SetBox()));
100     connect( RBNC1NpA,       SIGNAL(clicked()), this, SLOT(SetNC1NpA()));
101     connect( RBNCQuelconque, SIGNAL(clicked()), this, SLOT(SetNCQuelconque()));
102
103     connect( buttonOk,       SIGNAL(pressed()), this, SLOT(PushOnOK()));
104     connect( buttonApply,    SIGNAL(pressed()), this, SLOT(PushOnApply(0)));
105     connect( buttonCancel,   SIGNAL(pressed()), this, SLOT(close()));
106     connect( buttonHelp,     SIGNAL(pressed()), this, SLOT(PushOnHelp()));
107 }
108 // ------------------------------------------------------------------------
109 void MonCreateCase::InitBoundarys()
110 // ------------------------------------------------------------------------
111 // Initialisation des menus avec les frontieres deja enregistrees
112 {
113   MESSAGE("InitBoundarys");
114 // Pour les frontieres analytiques : la colonne des groupes
115   HOMARD::ListGroupType_var _listeGroupesCas = aCase->GetGroups();
116   QTableWidgetItem *__colItem = new QTableWidgetItem();
117   __colItem->setText(QApplication::translate("CreateCase", "", 0, QApplication::UnicodeUTF8));
118   TWBoundary->setHorizontalHeaderItem(0, __colItem);
119   for ( int i = 0; i < _listeGroupesCas->length(); i++ )
120   {
121     TWBoundary->insertRow(i);
122     TWBoundary->setItem( i, 0, new QTableWidgetItem(QString((_listeGroupesCas)[i]).trimmed()));
123     TWBoundary->item( i, 0 )->setFlags(Qt::ItemIsEnabled |Qt::ItemIsSelectable );
124   }
125 // Pour les frontieres discretes : la liste a saisir
126 // Pour les frontieres analytiques : les colonnes de chaque frontiere
127   HOMARD::HOMARD_Boundary_var myBoundary ;
128   HOMARD::listeBoundarys_var  mesBoundarys = myHomardGen->GetAllBoundarysName();
129 //   MESSAGE("Nombre de frontieres enregistrees : "<<mesBoundarys->length());
130   for (int i=0; i<mesBoundarys->length(); i++)
131   {
132     myBoundary = myHomardGen->GetBoundary(mesBoundarys[i]);
133     int type_obj = myBoundary->GetType() ;
134     if ( type_obj==0 ) { CBBoundaryDi->addItem(QString(mesBoundarys[i])); }
135     else               { AddBoundaryAn(QString(mesBoundarys[i])); }
136   }
137 // Ajustement
138   TWBoundary->resizeColumnsToContents();
139   TWBoundary->resizeRowsToContents();
140   TWBoundary->clearSelection();
141 }
142 // -------------------------------
143 bool MonCreateCase::PushOnApply(int option)
144 // --------------------------------
145 {
146   MESSAGE("PushOnApply");
147   QString aCaseName=LEName->text().trimmed();
148   if ( aCaseName == "" )
149   {
150     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
151                               QObject::tr("HOM_CASE_NAME") );
152     return false;
153   }
154
155   QString aDirName=LEDirName->text().trimmed();
156   if (aDirName == QString(""))
157   {
158     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
159                               QObject::tr("HOM_CASE_DIRECTORY_1") );
160     return false;
161   }
162
163   if ( aDirName != _aDirName)
164   { QString CaseNameDir = myHomardGen->VerifieDir( aDirName.toStdString().c_str()) ;
165     if ( ( CaseNameDir != "" ) & ( CaseNameDir != aCaseName ) )
166     {
167       QString texte ;
168       texte = QObject::tr("HOM_CASE_DIRECTORY_2") + CaseNameDir ;
169       QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
170                                 texte );
171       return false;
172     }
173   }
174   if (CHDIR(aDirName.toStdString().c_str()) != 0)
175   {
176     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
177                               QObject::tr("HOM_CASE_DIRECTORY_3") );
178     return false;
179   }
180
181   QString aFileName=LEFileName->text().trimmed();
182   if (aFileName ==QString(""))
183   {
184     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
185                               QObject::tr("HOM_CASE_MESH") );
186     return false;
187   }
188
189   QString aMeshName = HOMARD_QT_COMMUN::LireNomMaillage(aFileName);
190   if (aMeshName == "" )
191   {
192     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
193                               QObject::tr("HOM_MED_FILE_2") );
194     return false;
195   }
196
197 // On verifie qu'un groupe n'est pas associe a deux frontieres differentes
198   if (CBBoundaryA->isChecked())
199   {
200     QStringList ListeGroup ;
201     QString NomGroup ;
202     int nbcol = TWBoundary->columnCount();
203     int nbrow = TWBoundary->rowCount();
204     for ( int col=1; col< nbcol; col++)
205     {
206       for ( int row=0; row< nbrow; row++)
207       {
208         if ( TWBoundary->item( row, col )->checkState() ==  Qt::Checked )
209         {
210 //        Nom du groupe
211           NomGroup = QString(TWBoundary->item(row, 0)->text()) ;
212 //           MESSAGE("NomGroup "<<NomGroup.toStdString().c_str());
213           for ( int nugr = 0 ; nugr<ListeGroup.size(); nugr++)
214           {
215 //             MESSAGE("....... "<<ListeGroup[nugr].toStdString().c_str());
216             if ( NomGroup == ListeGroup[nugr] )
217             {
218               QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
219                                         QObject::tr("HOM_CASE_GROUP").arg(NomGroup) );
220               return false;
221             }
222           }
223           ListeGroup.insert(0, NomGroup );
224         }
225       }
226     }
227   }
228
229 // Creation du cas
230   if (aCaseName != _aCaseName )
231   {
232     _aCaseName = aCaseName;
233     try
234     {
235     aCase = myHomardGen->CreateCase( \
236             CORBA::string_dup(_aCaseName.toStdString().c_str()),  \
237             CORBA::string_dup(aMeshName.toStdString().c_str()),  \
238             CORBA::string_dup(aFileName.toStdString().c_str()) );
239     }
240     catch( SALOME::SALOME_Exception& S_ex )
241     {
242       QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
243                                 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
244       return false;
245     }
246     LEFileName->setReadOnly(true);
247     PushFichier->hide();
248     InitBoundarys();
249   }
250
251 // Repertoire et type
252   aCase->SetDirName(aDirName.toStdString().c_str());
253   _aDirName=aDirName;
254   aCase->SetConfType(_ConfType);
255
256 //   Menage des eventuelles frontieres deja enregistrees
257   aCase->SupprBoundaryGroup() ;
258
259   // Enregistrement et publication dans l'arbre d'etudes a la sortie definitive
260   if ( option > 0 )
261   {
262     if (CBBoundaryD->isChecked())
263     {
264       QString monBoundaryDiName=CBBoundaryDi->currentText();
265       if (monBoundaryDiName != "" )
266       {
267         aCase->AddBoundaryGroup(monBoundaryDiName.toStdString().c_str(), "");
268       }
269     }
270     if (CBBoundaryA->isChecked())
271     {
272       QString NomGroup ;
273       int nbcol = TWBoundary->columnCount();
274       int nbrow = TWBoundary->rowCount();
275       for ( int col=1; col< nbcol; col++)
276       {
277         for ( int row=0; row< nbrow; row++)
278         {
279           if ( TWBoundary->item( row, col )->checkState() ==  Qt::Checked )
280           {
281   //        Nom du groupe
282             NomGroup = QString(TWBoundary->item(row, 0)->text()) ;
283   //        Nom de la frontiere
284             QTableWidgetItem *__colItem = new QTableWidgetItem();
285             __colItem = TWBoundary->horizontalHeaderItem(col);
286             aCase->AddBoundaryGroup(QString(__colItem->text()).toStdString().c_str(), NomGroup.toStdString().c_str());
287           }
288         }
289       }
290     }
291   }
292
293
294 // Options avancees
295   if (CBAdvanced->isChecked())
296   {
297 // Autorisation des pyramides
298     if (CBPyramid->isChecked()) { _Pyram = 1 ; }
299   }
300   aCase->SetPyram(_Pyram);
301
302   HOMARD_UTILS::updateObjBrowser();
303
304   return true;
305 }
306 // ---------------------------
307 void MonCreateCase::PushOnOK()
308 // ---------------------------
309 {
310   bool bOK = PushOnApply(1);
311   if ( bOK ) this->close();
312 }
313 //------------------------------
314 void MonCreateCase::PushOnHelp()
315 //-------------------------------
316 {
317   std::string LanguageShort = myHomardGen->GetLanguageShort();
318   HOMARD_UTILS::PushOnHelp(QString("gui_create_case.html"), QString(""), QString(LanguageShort.c_str()));
319 }
320 // ---------------------------------
321 void MonCreateCase::SetNewName()
322 // ------------------------------
323 {
324   HOMARD::listeCases_var  MyCases = myHomardGen->GetAllCasesName();
325   int num = 0; QString aCaseName="";
326   while (aCaseName=="" )
327   {
328     aCaseName.setNum(num+1) ;
329     aCaseName.insert(0, QString("Case_")) ;
330     for ( int i=0; i<MyCases->length(); i++)
331     {
332       if ( aCaseName ==  QString((MyCases)[i]))
333       {
334         num ++ ;
335         aCaseName = "" ;
336         break ;
337       }
338    }
339   }
340   LEName->clear() ;
341   LEName->insert(aCaseName);
342 }
343
344 // ------------------------------------------------------------------------
345 void MonCreateCase::SetDirName()
346 // ------------------------------------------------------------------------
347 {
348   QString aDirName=QFileDialog::getExistingDirectory ();
349   if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
350 }
351 // ------------------------------------------------------------------------
352 void MonCreateCase::SetFileName()
353 // ------------------------------------------------------------------------
354 {
355   QString fileName0 = LEFileName->text().trimmed();
356   QString fileName = HOMARD_QT_COMMUN::PushNomFichier( false, QString("med") ) ;
357   if (fileName.isEmpty()) fileName = fileName0 ;
358   LEFileName->setText(fileName);
359 }
360 // ------------------------------------------------------------------------
361 void MonCreateCase::SetConforme()
362 // ------------------------------------------------------------------------
363 {
364 //
365   _ConfType=0;
366   RBNC1NpA->setVisible(0);
367   RBNCQuelconque->setVisible(0);
368 //
369   adjustSize();
370 }
371 // ------------------------------------------------------------------------
372 void MonCreateCase::SetNonConforme()
373 // ------------------------------------------------------------------------
374 {
375 //
376   _ConfType=1;
377   RBNC1NpA->setVisible(1);
378   RBNCQuelconque->setVisible(1);
379 //
380   adjustSize();
381 }
382 // ------------------------------------------------------------------------
383 void MonCreateCase::SetStandard()
384 // ------------------------------------------------------------------------
385 {
386   if ( ( _ConfType == 0 ) || ( _ConfType == -1 ) ) { _ConfType = 0 ; }
387   else { _ConfType = 1 ; }
388   RBStandard->setChecked(true);
389 }
390 // ------------------------------------------------------------------------
391 void MonCreateCase::SetBox()
392 // ------------------------------------------------------------------------
393 {
394   if ( ( _ConfType == 0 ) || ( _ConfType == -1 ) ) { _ConfType = -1 ; }
395   else { _ConfType = -2 ; }
396 }
397 // ------------------------------------------------------------------------
398 void MonCreateCase::SetNC1NpA()
399 // ------------------------------------------------------------------------
400 {
401   _ConfType = 2;
402 }
403 // ------------------------------------------------------------------------
404 void MonCreateCase::SetNCQuelconque()
405 // ------------------------------------------------------------------------
406 {
407   _ConfType = 3;
408 }
409 // ------------------------------------------------------------------------
410 void MonCreateCase::SetBoundaryD()
411 // ------------------------------------------------------------------------
412 {
413   MESSAGE("Debut de SetBoundaryD ");
414   if (CBBoundaryD->isChecked())
415   {
416     bool bOK = PushOnApply(0);
417     if (bOK) { GBBoundaryD->setVisible(1); }
418     else     { GBBoundaryD->setVisible(0);
419                CBBoundaryD->setChecked(0);
420                CBBoundaryD->setCheckState(Qt::Unchecked); }
421   }
422   else { GBBoundaryD->setVisible(0); }
423 //
424   adjustSize();
425 }
426 // ------------------------------------------------------------------------
427 void MonCreateCase::AddBoundaryDi(QString newBoundary)
428 // ------------------------------------------------------------------------
429 {
430   CBBoundaryDi->insertItem(0,newBoundary);
431   CBBoundaryDi->setCurrentIndex(0);
432 }
433 // ------------------------------------------------------------------------
434 void MonCreateCase::PushBoundaryDiNew()
435 // ------------------------------------------------------------------------
436 {
437    MonCreateBoundaryDi *BoundaryDlg = new MonCreateBoundaryDi(this, true,
438                 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName, "") ;
439    BoundaryDlg->show();
440 }
441 // ------------------------------------------------------------------------
442 void MonCreateCase::PushBoundaryDiEdit()
443 // ------------------------------------------------------------------------
444 {
445   if (CBBoundaryDi->currentText() == QString(""))  return;
446   MonEditBoundaryDi *BoundaryDlg = new MonEditBoundaryDi(this, true,
447        HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName, CBBoundaryDi->currentText() ) ;
448   BoundaryDlg->show();
449 }
450 // ------------------------------------------------------------------------
451 void MonCreateCase::PushBoundaryDiHelp()
452 // ------------------------------------------------------------------------
453 {
454   std::string LanguageShort = myHomardGen->GetLanguageShort();
455   HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html"), QString("frontiere-discrete"), QString(LanguageShort.c_str()));
456 }
457 // ------------------------------------------------------------------------
458 void MonCreateCase::SetBoundaryA()
459 // ------------------------------------------------------------------------
460 {
461   MESSAGE("Debut de SetBoundaryA ");
462   if (CBBoundaryA->isChecked())
463   {
464     bool bOK = PushOnApply(0);
465     if (bOK) { GBBoundaryA->setVisible(1); }
466     else     { GBBoundaryA->setVisible(0);
467                CBBoundaryA->setChecked(0);
468                CBBoundaryA->setCheckState(Qt::Unchecked); }
469   }
470   else { GBBoundaryA->setVisible(0); }
471 //
472   adjustSize();
473 //
474 //   MESSAGE("Fin de SetBoundaryA ");
475 }
476 // ------------------------------------------------------------------------
477 void MonCreateCase::AddBoundaryAn(QString newBoundary)
478 // ------------------------------------------------------------------------
479 {
480   MESSAGE("Debut de AddBoundaryAn ");
481 // Ajout d'une nouvelle colonne
482   int nbcol = TWBoundary->columnCount();
483 //   MESSAGE("nbcol " <<  nbcol);
484   nbcol += 1 ;
485   TWBoundary->setColumnCount ( nbcol ) ;
486   QTableWidgetItem *__colItem = new QTableWidgetItem();
487   __colItem->setText(QApplication::translate("CreateCase", newBoundary.toStdString().c_str(), 0, QApplication::UnicodeUTF8));
488   TWBoundary->setHorizontalHeaderItem(nbcol-1, __colItem);
489 /*  TWBoundary->horizontalHeaderItem(nbcol-1)->setFlags( Qt::ItemIsSelectable|Qt::ItemIsEnabled );*/
490 // Chaque case est a cocher
491   int nbrow = TWBoundary->rowCount();
492 //   MESSAGE("nbrow " <<  nbrow);
493   for ( int i = 0; i < nbrow; i++ )
494   {
495     TWBoundary->setItem( i, nbcol-1, new QTableWidgetItem( QString ("") ) );
496     TWBoundary->item( i, nbcol-1 )->setFlags( 0 );
497     TWBoundary->item( i, nbcol-1 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled  );
498     TWBoundary->item( i, nbcol-1 )->setCheckState( Qt::Unchecked );
499   }
500   TWBoundary->resizeColumnToContents(nbcol-1);
501 //   TWBoundary->resizeRowsToContents();
502 //   MESSAGE("Fin de AddBoundaryAn ");
503 }
504 // ------------------------------------------------------------------------
505 void MonCreateCase::PushBoundaryAnNew()
506 // ------------------------------------------------------------------------
507 {
508    MonCreateBoundaryAn *BoundaryDlg = new MonCreateBoundaryAn(this, true,
509                 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName) ;
510    BoundaryDlg->show();
511 }
512 // ------------------------------------------------------------------------
513 void MonCreateCase::PushBoundaryAnEdit()
514 // ------------------------------------------------------------------------
515 {
516   QString nom="";
517   int nbcol = TWBoundary->columnCount();
518   for ( int i = 1; i < nbcol; i++ )
519   {
520     QTableWidgetItem *__colItem = new QTableWidgetItem();
521     __colItem = TWBoundary->horizontalHeaderItem(i);
522     nom = QString(__colItem->text()) ;
523     MESSAGE("nom "<<nom.toStdString().c_str());
524     if (nom != QString(""))
525     { MonEditBoundaryAn *BoundaryDlg = new MonEditBoundaryAn(this, true,
526         HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName, nom ) ;
527       BoundaryDlg->show(); }
528   }
529 }
530 // ------------------------------------------------------------------------
531 void MonCreateCase::PushBoundaryAnHelp()
532 // ------------------------------------------------------------------------
533 {
534   std::string LanguageShort = myHomardGen->GetLanguageShort();
535   HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html"), QString("frontiere-analytique"), QString(LanguageShort.c_str()));
536 }
537 // ------------------------------------------------------------------------
538 void MonCreateCase::CaseNameChanged()
539 // ------------------------------------------------------------------------
540 {
541     if (_aCaseName != LEName->text().trimmed())
542     {
543        LEFileName->setReadOnly(false);
544        PushFichier->show();
545     }
546 }
547 // ------------------------------------------------------------------------
548 void MonCreateCase::SetAdvanced()
549 // ------------------------------------------------------------------------
550 {
551   MESSAGE("Debut de SetAdvanced ");
552   if (CBAdvanced->isChecked())
553   { GBAdvancedOptions->setVisible(1);
554     RBStandard->setVisible(1);
555     RBBox->setVisible(1);
556     if ( ( _ConfType == 0 ) || ( _ConfType == -1 ) )
557     { RBNC1NpA->setVisible(0);
558       RBNCQuelconque->setVisible(0);}
559     else
560     { RBNC1NpA->setVisible(1);
561       RBNCQuelconque->setVisible(1);}
562   }
563   else
564   { GBAdvancedOptions->setVisible(0);
565     CBPyramid->setChecked(false);
566     _Pyram = 0 ;
567     SetStandard() ;
568  }
569 //
570   adjustSize();
571 }