1 // Copyright (C) 2011-2012 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 QString(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();
293 // ---------------------------
294 void MonCreateCase::PushOnOK()
295 // ---------------------------
297 bool bOK = PushOnApply();
298 if ( bOK ) this->close();
300 //------------------------------
301 void MonCreateCase::PushOnHelp()
302 //-------------------------------
304 HOMARD_UTILS::PushOnHelp(QString("gui_create_case.html"));
306 // ---------------------------------
307 void MonCreateCase::SetNewCaseName()
308 // ------------------------------
310 HOMARD::listeCases_var MyCases = _myHomardGen->GetAllCasesName();
311 int num = 0; QString aCaseName="";
312 while (aCaseName=="" )
314 aCaseName.setNum(num+1) ;
315 aCaseName.insert(0, QString("Case_")) ;
316 for ( int i=0; i<MyCases->length(); i++)
318 if ( aCaseName == QString((MyCases)[i]))
326 LECaseName->clear() ;
327 LECaseName->insert(aCaseName);
330 // ------------------------------------------------------------------------
331 void MonCreateCase::SetDirName()
332 // ------------------------------------------------------------------------
334 QString aDirName=QFileDialog::getExistingDirectory ();
335 if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
337 // ------------------------------------------------------------------------
338 void MonCreateCase::SetFileName()
339 // ------------------------------------------------------------------------
341 QString fileName0 = LEFileName->text().trimmed();
342 QString fileName = HOMARD_QT_COMMUN::PushNomFichier();
343 if (fileName.isEmpty()) fileName = fileName0 ;
344 LEFileName->setText(fileName);
346 // ------------------------------------------------------------------------
347 void MonCreateCase::SetConforme()
348 // ------------------------------------------------------------------------
350 GBTypeNoConf->setVisible(0);
354 // ------------------------------------------------------------------------
355 void MonCreateCase::SetNonConforme()
356 // ------------------------------------------------------------------------
358 GBTypeNoConf->setVisible(1);
359 RB1NpM->setChecked(true);
363 // ------------------------------------------------------------------------
364 void MonCreateCase::Set1NpM()
365 // ------------------------------------------------------------------------
369 // ------------------------------------------------------------------------
370 void MonCreateCase::Set1NpA()
371 // ------------------------------------------------------------------------
375 // ------------------------------------------------------------------------
376 void MonCreateCase::SetQuelconque()
377 // ------------------------------------------------------------------------
381 // ------------------------------------------------------------------------
382 void MonCreateCase::SetBoundaryD()
383 // ------------------------------------------------------------------------
385 MESSAGE("Debut de SetBoundaryD ");
386 if (CBBoundaryD->isChecked())
388 bool bOK = PushOnApply();
389 if (bOK) { GBBoundaryD->setVisible(1); }
390 else { GBBoundaryD->setVisible(0);
391 CBBoundaryD->setChecked(0);
392 CBBoundaryD->setCheckState(Qt::Unchecked); }
394 else { GBBoundaryD->setVisible(0); }
397 // ------------------------------------------------------------------------
398 void MonCreateCase::AddBoundaryDi(QString newBoundary)
399 // ------------------------------------------------------------------------
401 CBBoundaryDi->insertItem(0,newBoundary);
402 CBBoundaryDi->setCurrentIndex(0);
404 // ------------------------------------------------------------------------
405 void MonCreateCase::PushBoundaryDiNew()
406 // ------------------------------------------------------------------------
408 MonCreateBoundaryDi *BoundaryDlg = new MonCreateBoundaryDi(this, true,
409 HOMARD::HOMARD_Gen::_duplicate(_myHomardGen), _aCaseName, "") ;
412 // ------------------------------------------------------------------------
413 void MonCreateCase::PushBoundaryDiEdit()
414 // ------------------------------------------------------------------------
416 if (CBBoundaryDi->currentText() == QString("")) return;
417 MonEditBoundaryDi *BoundaryDlg = new MonEditBoundaryDi(this, true,
418 HOMARD::HOMARD_Gen::_duplicate(_myHomardGen), _aCaseName, CBBoundaryDi->currentText() ) ;
421 // ------------------------------------------------------------------------
422 void MonCreateCase::PushBoundaryDiHelp()
423 // ------------------------------------------------------------------------
425 HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html#frontiere-discrete") ) ;
427 // ------------------------------------------------------------------------
428 void MonCreateCase::SetBoundaryA()
429 // ------------------------------------------------------------------------
431 MESSAGE("Debut de SetBoundaryA ");
432 if (CBBoundaryA->isChecked())
434 bool bOK = PushOnApply();
435 if (bOK) { GBBoundaryA->setVisible(1); }
436 else { GBBoundaryA->setVisible(0);
437 CBBoundaryA->setChecked(0);
438 CBBoundaryA->setCheckState(Qt::Unchecked); }
440 else { GBBoundaryA->setVisible(0); }
443 // MESSAGE("Fin de SetBoundaryA ");
445 // ------------------------------------------------------------------------
446 void MonCreateCase::AddBoundaryAn(QString newBoundary)
447 // ------------------------------------------------------------------------
449 MESSAGE("Debut de AddBoundaryAn ");
450 // Ajout d'une nouvelle colonne
451 int nbcol = TWBoundary->columnCount();
452 // MESSAGE("nbcol " << nbcol);
454 TWBoundary->setColumnCount ( nbcol ) ;
455 QTableWidgetItem *__colItem = new QTableWidgetItem();
456 __colItem->setText(QApplication::translate("CreateCase", newBoundary.toStdString().c_str(), 0, QApplication::UnicodeUTF8));
457 TWBoundary->setHorizontalHeaderItem(nbcol-1, __colItem);
458 /* TWBoundary->horizontalHeaderItem(nbcol-1)->setFlags( Qt::ItemIsSelectable|Qt::ItemIsEnabled );*/
459 // Chaque case est a cocher
460 int nbrow = TWBoundary->rowCount();
461 // MESSAGE("nbrow " << nbrow);
462 for ( int i = 0; i < nbrow; i++ )
464 TWBoundary->setItem( i, nbcol-1, new QTableWidgetItem( QString ("") ) );
465 TWBoundary->item( i, nbcol-1 )->setFlags( 0 );
466 TWBoundary->item( i, nbcol-1 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled );
467 TWBoundary->item( i, nbcol-1 )->setCheckState( Qt::Unchecked );
469 TWBoundary->resizeColumnToContents(nbcol-1);
470 // TWBoundary->resizeRowsToContents();
471 // MESSAGE("Fin de AddBoundaryAn ");
473 // ------------------------------------------------------------------------
474 void MonCreateCase::PushBoundaryAnNew()
475 // ------------------------------------------------------------------------
477 MonCreateBoundaryAn *BoundaryDlg = new MonCreateBoundaryAn(this, true,
478 HOMARD::HOMARD_Gen::_duplicate(_myHomardGen), _aCaseName) ;
481 // ------------------------------------------------------------------------
482 void MonCreateCase::PushBoundaryAnEdit()
483 // ------------------------------------------------------------------------
486 int nbcol = TWBoundary->columnCount();
487 for ( int i = 1; i < nbcol; i++ )
489 QTableWidgetItem *__colItem = new QTableWidgetItem();
490 __colItem = TWBoundary->horizontalHeaderItem(i);
491 nom = QString(__colItem->text()) ;
492 MESSAGE("nom "<<nom.toStdString().c_str());
493 if (nom != QString(""))
494 { MonEditBoundaryAn *BoundaryDlg = new MonEditBoundaryAn(this, true,
495 HOMARD::HOMARD_Gen::_duplicate(_myHomardGen), _aCaseName, nom ) ;
496 BoundaryDlg->show(); }
499 // ------------------------------------------------------------------------
500 void MonCreateCase::PushBoundaryAnHelp()
501 // ------------------------------------------------------------------------
503 HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html#frontiere-analytique") ) ;
505 // ------------------------------------------------------------------------
506 void MonCreateCase::CaseNameChanged()
507 // ------------------------------------------------------------------------
509 if (_aCaseName != LECaseName->text().trimmed())
511 LEFileName->setReadOnly(false);
515 // ------------------------------------------------------------------------
516 void MonCreateCase::SetAdvanced()
517 // ------------------------------------------------------------------------
519 MESSAGE("Debut de SetAdvanced ");
520 if (CBAdvanced->isChecked()) { GBAdvancedOptions->setVisible(1); }
522 { GBAdvancedOptions->setVisible(0);
523 CBPyramid->setChecked(false);