1 // Copyright (C) 2011-2013 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "MonCreateCase.h"
23 #include "MonCreateBoundaryAn.h"
24 #include "MonEditBoundaryAn.h"
25 #include "MonCreateBoundaryDi.h"
26 #include "MonEditBoundaryDi.h"
28 #include <QFileDialog>
29 #include <QMessageBox>
31 #include "SalomeApp_Tools.h"
32 #include "HOMARDGUI_Utils.h"
33 #include "HomardQtCommun.h"
34 #include <utilities.h>
37 // -----------------------------------------------------------------------------------------
38 MonCreateCase::MonCreateCase(QWidget* parent, bool modal, HOMARD::HOMARD_Gen_var myHomardGen)
39 // -----------------------------------------------------------------------------------------
40 /* Constructs a MonCreateCase
41 * Inherits from CasHomard
42 * Sets attributes to default values
46 _aCaseName(""),_aDirName(""),
50 _myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen);
56 GBBoundaryA->setVisible(0);
57 GBBoundaryD->setVisible(0);
58 GBTypeNoConf->setVisible(0);
60 GBAdvancedOptions->setVisible(0);
61 CBPyramid->setChecked(false);
64 // ------------------------------------------------------------------------
65 MonCreateCase::~MonCreateCase()
66 // ------------------------------------------------------------------------
68 // no need to delete child widgets, Qt does it all for us
70 // ------------------------------------------------------------------------
71 void MonCreateCase::InitConnect()
72 // ------------------------------------------------------------------------
74 connect( PushDir, SIGNAL(pressed()), this, SLOT(SetDirName()));
75 connect( PushFichier, SIGNAL(pressed()), this, SLOT(SetFileName()));
77 connect( RBConforme, SIGNAL(clicked()), this, SLOT(SetConforme()));
78 connect( RBNonConforme, SIGNAL(clicked()), this, SLOT(SetNonConforme()));
79 connect( RB1NpM, SIGNAL(clicked()), this, SLOT(Set1NpM()));
80 connect( RB1NpA, SIGNAL(clicked()), this, SLOT(Set1NpA()));
81 connect( RBQuelconque, SIGNAL(clicked()), this, SLOT(SetQuelconque()));
83 connect( CBBoundaryD, SIGNAL(stateChanged(int)), this, SLOT(SetBoundaryD()));
84 connect( PBBoundaryDiNew, SIGNAL(pressed()), this, SLOT(PushBoundaryDiNew()));
85 connect( PBBoundaryDiEdit, SIGNAL(pressed()), this, SLOT(PushBoundaryDiEdit()) );
86 connect( PBBoundaryDiHelp, SIGNAL(pressed()), this, SLOT(PushBoundaryDiHelp()) );
87 connect( CBBoundaryA, SIGNAL(stateChanged(int)), this, SLOT(SetBoundaryA()));
88 connect( PBBoundaryAnNew, SIGNAL(pressed()), this, SLOT(PushBoundaryAnNew()));
89 connect( PBBoundaryAnEdit, SIGNAL(pressed()), this, SLOT(PushBoundaryAnEdit()) );
90 connect( PBBoundaryAnHelp, SIGNAL(pressed()), this, SLOT(PushBoundaryAnHelp()) );
92 connect( CBAdvanced, SIGNAL(stateChanged(int)), this, SLOT(SetAdvanced()));
94 connect( buttonOk, SIGNAL(pressed()), this, SLOT(PushOnOK()));
95 connect( buttonApply, SIGNAL(pressed()), this, SLOT(PushOnApply()));
96 connect( buttonCancel, SIGNAL(pressed()), this, SLOT(close()));
97 connect( buttonHelp, SIGNAL(pressed()), this, SLOT(PushOnHelp()));
98 connect( LECaseName, SIGNAL(textChanged(QString)), this, SLOT(CaseNameChanged()));
100 // ------------------------------------------------------------------------
101 void MonCreateCase::InitBoundarys()
102 // ------------------------------------------------------------------------
103 // Initialisation des menus avec les frontieres deja enregistrees
105 MESSAGE("InitBoundarys");
106 // Pour les frontieres analytiques : la colonne des groupes
107 HOMARD::ListGroupType_var _listeGroupesCas = aCase->GetGroups();
108 QTableWidgetItem *__colItem = new QTableWidgetItem();
109 __colItem->setText(QApplication::translate("CreateCase", "", 0, QApplication::UnicodeUTF8));
110 TWBoundary->setHorizontalHeaderItem(0, __colItem);
111 for ( int i = 0; i < _listeGroupesCas->length(); i++ )
113 TWBoundary->insertRow(i);
114 TWBoundary->setItem( i, 0, new QTableWidgetItem(QString((_listeGroupesCas)[i]).trimmed()));
115 TWBoundary->item( i, 0 )->setFlags(Qt::ItemIsEnabled |Qt::ItemIsSelectable );
117 // Pour les frontieres discretes : la liste a saisir
118 // Pour les frontieres analytiques : les colonnes de chaque frontiere
119 HOMARD::HOMARD_Boundary_var myBoundary ;
120 HOMARD::listeBoundarys_var mesBoundarys = _myHomardGen->GetAllBoundarysName();
121 // MESSAGE("Nombre de frontieres enregistrees : "<<mesBoundarys->length());
122 for (int i=0; i<mesBoundarys->length(); i++)
124 myBoundary = _myHomardGen->GetBoundary(mesBoundarys[i]);
125 int type_obj = myBoundary->GetType() ;
126 if ( type_obj==0 ) { CBBoundaryDi->addItem(QString(mesBoundarys[i])); }
127 else { AddBoundaryAn(QString(mesBoundarys[i])); }
130 TWBoundary->resizeColumnsToContents();
131 TWBoundary->resizeRowsToContents();
132 TWBoundary->clearSelection();
134 // -------------------------------
135 bool MonCreateCase::PushOnApply()
136 // --------------------------------
138 MESSAGE("PushOnApply");
139 QString aCaseName=LECaseName->text().trimmed();
140 if ( aCaseName == "" )
142 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
143 QObject::tr("HOM_CASE_NAME") );
147 QString aDirName=LEDirName->text().trimmed();
148 if (aDirName == QString(""))
150 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
151 QObject::tr("HOM_CASE_DIRECTORY_1") );
154 if ((aDirName != _aDirName) and (_myHomardGen->VerifieDir( aDirName.toStdString().c_str()) == false))
156 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
157 QObject::tr("HOM_CASE_DIRECTORY_2") );
160 if (chdir(aDirName.toStdString().c_str()) != 0)
162 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
163 QObject::tr("HOM_CASE_DIRECTORY_3") );
167 QString aFileName=LEFileName->text().trimmed();
168 if (aFileName ==QString(""))
170 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
171 QObject::tr("HOM_CASE_MESH") );
175 QString aMeshName = HOMARD_QT_COMMUN::LireNomMaillage(aFileName);
176 if (aMeshName == "" )
178 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
179 QObject::tr("HOM_MED_FILE_2") );
183 if (CBBoundaryA->isChecked())
185 QStringList ListeGroup ;
187 int nbcol = TWBoundary->columnCount();
188 int nbrow = TWBoundary->rowCount();
189 for ( int col=1; col< nbcol; col++)
191 for ( int row=0; row< nbrow; row++)
193 if ( TWBoundary->item( row, col )->checkState() == Qt::Checked )
196 NomGroup = QString(TWBoundary->item(row, 0)->text()) ;
197 // MESSAGE("NomGroup "<<NomGroup.toStdString().c_str());
198 for ( int nugr = 0 ; nugr<ListeGroup.size(); nugr++)
200 // MESSAGE("....... "<<ListeGroup[nugr].toStdString().c_str());
201 if ( NomGroup == ListeGroup[nugr] )
203 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
204 QObject::tr("HOM_CASE_GROUP").arg(NomGroup) );
208 ListeGroup.insert(0, NomGroup );
214 if (aCaseName != _aCaseName )
216 _aCaseName = aCaseName;
219 aCase = _myHomardGen->CreateCase( \
220 CORBA::string_dup(_aCaseName.toStdString().c_str()), \
221 CORBA::string_dup(aMeshName.toStdString().c_str()), \
222 CORBA::string_dup(aFileName.toStdString().c_str()) );
224 catch( SALOME::SALOME_Exception& S_ex )
226 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
227 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
230 aCase = _myHomardGen->GetCase(_aCaseName.toStdString().c_str());
231 string iter0 = aCase->GetIter0Name();
232 HOMARD::HOMARD_Iteration_var aIter = _myHomardGen->GetIteration(iter0.c_str());
233 QString aFileName = aIter->GetMeshFile();
234 LEFileName->setText(aFileName);
235 LEFileName->setReadOnly(true);
238 catch( SALOME::SALOME_Exception& S_ex ) {};
241 LEFileName->setReadOnly(true);
246 aCase->SetDirName(aDirName.toStdString().c_str());
248 aCase->SetConfType(_ConfType);
250 // Enregistrement de la frontiere discrete
251 if (CBBoundaryD->isChecked())
253 QString monBoundaryDiName=CBBoundaryDi->currentText();
254 if (monBoundaryDiName != "" )
256 aCase->AddBoundaryGroup(monBoundaryDiName.toStdString().c_str(), "");
260 // Enregistrement des liens (groupe,frontiere analytique)
261 if (CBBoundaryA->isChecked())
264 int nbcol = TWBoundary->columnCount();
265 int nbrow = TWBoundary->rowCount();
266 for ( int col=1; col< nbcol; col++)
268 for ( int row=0; row< nbrow; row++)
270 if ( TWBoundary->item( row, col )->checkState() == Qt::Checked )
273 NomGroup = QString(TWBoundary->item(row, 0)->text()) ;
274 // Nom de la frontiere
275 QTableWidgetItem *__colItem = new QTableWidgetItem();
276 __colItem = TWBoundary->horizontalHeaderItem(col);
277 aCase->AddBoundaryGroup(QString(__colItem->text()).toStdString().c_str(), NomGroup.toStdString().c_str());
284 if (CBAdvanced->isChecked())
286 // Autorisation des pyramides
287 if (CBPyramid->isChecked()) { _Pyram = 1 ; }
290 HOMARD_UTILS::updateObjBrowser();
294 // ---------------------------
295 void MonCreateCase::PushOnOK()
296 // ---------------------------
298 bool bOK = PushOnApply();
299 if ( bOK ) this->close();
301 //------------------------------
302 void MonCreateCase::PushOnHelp()
303 //-------------------------------
305 HOMARD_UTILS::PushOnHelp(QString("gui_create_case.html"));
307 // ---------------------------------
308 void MonCreateCase::SetNewCaseName()
309 // ------------------------------
311 HOMARD::listeCases_var MyCases = _myHomardGen->GetAllCasesName();
312 int num = 0; QString aCaseName="";
313 while (aCaseName=="" )
315 aCaseName.setNum(num+1) ;
316 aCaseName.insert(0, QString("Case_")) ;
317 for ( int i=0; i<MyCases->length(); i++)
319 if ( aCaseName == QString((MyCases)[i]))
327 LECaseName->clear() ;
328 LECaseName->insert(aCaseName);
331 // ------------------------------------------------------------------------
332 void MonCreateCase::SetDirName()
333 // ------------------------------------------------------------------------
335 QString aDirName=QFileDialog::getExistingDirectory ();
336 if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
338 // ------------------------------------------------------------------------
339 void MonCreateCase::SetFileName()
340 // ------------------------------------------------------------------------
342 QString fileName0 = LEFileName->text().trimmed();
343 QString fileName = HOMARD_QT_COMMUN::PushNomFichier();
344 if (fileName.isEmpty()) fileName = fileName0 ;
345 LEFileName->setText(fileName);
347 // ------------------------------------------------------------------------
348 void MonCreateCase::SetConforme()
349 // ------------------------------------------------------------------------
351 GBTypeNoConf->setVisible(0);
355 // ------------------------------------------------------------------------
356 void MonCreateCase::SetNonConforme()
357 // ------------------------------------------------------------------------
359 GBTypeNoConf->setVisible(1);
360 RB1NpM->setChecked(true);
364 // ------------------------------------------------------------------------
365 void MonCreateCase::Set1NpM()
366 // ------------------------------------------------------------------------
370 // ------------------------------------------------------------------------
371 void MonCreateCase::Set1NpA()
372 // ------------------------------------------------------------------------
376 // ------------------------------------------------------------------------
377 void MonCreateCase::SetQuelconque()
378 // ------------------------------------------------------------------------
382 // ------------------------------------------------------------------------
383 void MonCreateCase::SetBoundaryD()
384 // ------------------------------------------------------------------------
386 MESSAGE("Debut de SetBoundaryD ");
387 if (CBBoundaryD->isChecked())
389 bool bOK = PushOnApply();
390 if (bOK) { GBBoundaryD->setVisible(1); }
391 else { GBBoundaryD->setVisible(0);
392 CBBoundaryD->setChecked(0);
393 CBBoundaryD->setCheckState(Qt::Unchecked); }
395 else { GBBoundaryD->setVisible(0); }
398 // ------------------------------------------------------------------------
399 void MonCreateCase::AddBoundaryDi(QString newBoundary)
400 // ------------------------------------------------------------------------
402 CBBoundaryDi->insertItem(0,newBoundary);
403 CBBoundaryDi->setCurrentIndex(0);
405 // ------------------------------------------------------------------------
406 void MonCreateCase::PushBoundaryDiNew()
407 // ------------------------------------------------------------------------
409 MonCreateBoundaryDi *BoundaryDlg = new MonCreateBoundaryDi(this, true,
410 HOMARD::HOMARD_Gen::_duplicate(_myHomardGen), _aCaseName, "") ;
413 // ------------------------------------------------------------------------
414 void MonCreateCase::PushBoundaryDiEdit()
415 // ------------------------------------------------------------------------
417 if (CBBoundaryDi->currentText() == QString("")) return;
418 MonEditBoundaryDi *BoundaryDlg = new MonEditBoundaryDi(this, true,
419 HOMARD::HOMARD_Gen::_duplicate(_myHomardGen), _aCaseName, CBBoundaryDi->currentText() ) ;
422 // ------------------------------------------------------------------------
423 void MonCreateCase::PushBoundaryDiHelp()
424 // ------------------------------------------------------------------------
426 HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html#frontiere-discrete") ) ;
428 // ------------------------------------------------------------------------
429 void MonCreateCase::SetBoundaryA()
430 // ------------------------------------------------------------------------
432 MESSAGE("Debut de SetBoundaryA ");
433 if (CBBoundaryA->isChecked())
435 bool bOK = PushOnApply();
436 if (bOK) { GBBoundaryA->setVisible(1); }
437 else { GBBoundaryA->setVisible(0);
438 CBBoundaryA->setChecked(0);
439 CBBoundaryA->setCheckState(Qt::Unchecked); }
441 else { GBBoundaryA->setVisible(0); }
444 // MESSAGE("Fin de SetBoundaryA ");
446 // ------------------------------------------------------------------------
447 void MonCreateCase::AddBoundaryAn(QString newBoundary)
448 // ------------------------------------------------------------------------
450 MESSAGE("Debut de AddBoundaryAn ");
451 // Ajout d'une nouvelle colonne
452 int nbcol = TWBoundary->columnCount();
453 // MESSAGE("nbcol " << nbcol);
455 TWBoundary->setColumnCount ( nbcol ) ;
456 QTableWidgetItem *__colItem = new QTableWidgetItem();
457 __colItem->setText(QApplication::translate("CreateCase", newBoundary.toStdString().c_str(), 0, QApplication::UnicodeUTF8));
458 TWBoundary->setHorizontalHeaderItem(nbcol-1, __colItem);
459 /* TWBoundary->horizontalHeaderItem(nbcol-1)->setFlags( Qt::ItemIsSelectable|Qt::ItemIsEnabled );*/
460 // Chaque case est a cocher
461 int nbrow = TWBoundary->rowCount();
462 // MESSAGE("nbrow " << nbrow);
463 for ( int i = 0; i < nbrow; i++ )
465 TWBoundary->setItem( i, nbcol-1, new QTableWidgetItem( QString ("") ) );
466 TWBoundary->item( i, nbcol-1 )->setFlags( 0 );
467 TWBoundary->item( i, nbcol-1 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled );
468 TWBoundary->item( i, nbcol-1 )->setCheckState( Qt::Unchecked );
470 TWBoundary->resizeColumnToContents(nbcol-1);
471 // TWBoundary->resizeRowsToContents();
472 // MESSAGE("Fin de AddBoundaryAn ");
474 // ------------------------------------------------------------------------
475 void MonCreateCase::PushBoundaryAnNew()
476 // ------------------------------------------------------------------------
478 MonCreateBoundaryAn *BoundaryDlg = new MonCreateBoundaryAn(this, true,
479 HOMARD::HOMARD_Gen::_duplicate(_myHomardGen), _aCaseName) ;
482 // ------------------------------------------------------------------------
483 void MonCreateCase::PushBoundaryAnEdit()
484 // ------------------------------------------------------------------------
487 int nbcol = TWBoundary->columnCount();
488 for ( int i = 1; i < nbcol; i++ )
490 QTableWidgetItem *__colItem = new QTableWidgetItem();
491 __colItem = TWBoundary->horizontalHeaderItem(i);
492 nom = QString(__colItem->text()) ;
493 MESSAGE("nom "<<nom.toStdString().c_str());
494 if (nom != QString(""))
495 { MonEditBoundaryAn *BoundaryDlg = new MonEditBoundaryAn(this, true,
496 HOMARD::HOMARD_Gen::_duplicate(_myHomardGen), _aCaseName, nom ) ;
497 BoundaryDlg->show(); }
500 // ------------------------------------------------------------------------
501 void MonCreateCase::PushBoundaryAnHelp()
502 // ------------------------------------------------------------------------
504 HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html#frontiere-analytique") ) ;
506 // ------------------------------------------------------------------------
507 void MonCreateCase::CaseNameChanged()
508 // ------------------------------------------------------------------------
510 if (_aCaseName != LECaseName->text().trimmed())
512 LEFileName->setReadOnly(false);
516 // ------------------------------------------------------------------------
517 void MonCreateCase::SetAdvanced()
518 // ------------------------------------------------------------------------
520 MESSAGE("Debut de SetAdvanced ");
521 if (CBAdvanced->isChecked()) { GBAdvancedOptions->setVisible(1); }
523 { GBAdvancedOptions->setVisible(0);
524 CBPyramid->setChecked(false);