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
20 #include "MonCreateCase.h"
21 #include "MonCreateBoundaryAn.h"
22 #include "MonEditBoundaryAn.h"
23 #include "MonCreateBoundaryDi.h"
24 #include "MonEditBoundaryDi.h"
26 #include <QFileDialog>
27 #include <QMessageBox>
29 #include "SalomeApp_Tools.h"
30 #include "HOMARDGUI_Utils.h"
31 #include "HomardQtCommun.h"
32 #include <utilities.h>
40 // -----------------------------------------------------------------------------------------
41 /* Constructs a MonCreateCase
42 * Inherits from CasHomard
43 * Sets attributes to default values
45 // -----------------------------------------------------------------------------------------
46 MonCreateCase::MonCreateCase( bool modal, HOMARD::HOMARD_Gen_var myHomardGen0)
49 _aCaseName(""),_aDirName(""),
53 MESSAGE("Debut du constructeur de MonCreateCase");
54 myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen0);
60 GBBoundaryA->setVisible(0);
61 GBBoundaryD->setVisible(0);
62 GBTypeNoConf->setVisible(0);
63 GBAdvancedOptions->setVisible(0);
64 Comment->setVisible(0);
65 CBPyramid->setChecked(false);
68 MESSAGE("Fin du constructeur de MonCreateCase");
70 // ------------------------------------------------------------------------
71 MonCreateCase::~MonCreateCase()
72 // ------------------------------------------------------------------------
74 // no need to delete child widgets, Qt does it all for us
76 // ------------------------------------------------------------------------
77 void MonCreateCase::InitConnect()
78 // ------------------------------------------------------------------------
80 connect( LEName, SIGNAL(textChanged(QString)), this, SLOT(CaseNameChanged()));
81 connect( PushDir, SIGNAL(pressed()), this, SLOT(SetDirName()));
82 connect( PushFichier, SIGNAL(pressed()), this, SLOT(SetFileName()));
84 connect( RBConforme, SIGNAL(clicked()), this, SLOT(SetConforme()));
85 connect( RBNonConforme, SIGNAL(clicked()), this, SLOT(SetNonConforme()));
86 connect( RB1NpM, SIGNAL(clicked()), this, SLOT(Set1NpM()));
87 connect( RB1NpA, SIGNAL(clicked()), this, SLOT(Set1NpA()));
88 connect( RBQuelconque, SIGNAL(clicked()), this, SLOT(SetQuelconque()));
90 connect( CBBoundaryD, SIGNAL(stateChanged(int)), this, SLOT(SetBoundaryD()));
91 connect( PBBoundaryDiNew, SIGNAL(pressed()), this, SLOT(PushBoundaryDiNew()));
92 connect( PBBoundaryDiEdit, SIGNAL(pressed()), this, SLOT(PushBoundaryDiEdit()) );
93 connect( PBBoundaryDiHelp, SIGNAL(pressed()), this, SLOT(PushBoundaryDiHelp()) );
94 connect( CBBoundaryA, SIGNAL(stateChanged(int)), this, SLOT(SetBoundaryA()));
95 connect( PBBoundaryAnNew, SIGNAL(pressed()), this, SLOT(PushBoundaryAnNew()));
96 connect( PBBoundaryAnEdit, SIGNAL(pressed()), this, SLOT(PushBoundaryAnEdit()) );
97 connect( PBBoundaryAnHelp, SIGNAL(pressed()), this, SLOT(PushBoundaryAnHelp()) );
99 connect( CBAdvanced, SIGNAL(stateChanged(int)), this, SLOT(SetAdvanced()));
101 connect( buttonOk, SIGNAL(pressed()), this, SLOT(PushOnOK()));
102 connect( buttonApply, SIGNAL(pressed()), this, SLOT(PushOnApply()));
103 connect( buttonCancel, SIGNAL(pressed()), this, SLOT(close()));
104 connect( buttonHelp, SIGNAL(pressed()), this, SLOT(PushOnHelp()));
106 // ------------------------------------------------------------------------
107 void MonCreateCase::InitBoundarys()
108 // ------------------------------------------------------------------------
109 // Initialisation des menus avec les frontieres deja enregistrees
111 MESSAGE("InitBoundarys");
112 // Pour les frontieres analytiques : la colonne des groupes
113 HOMARD::ListGroupType_var _listeGroupesCas = aCase->GetGroups();
114 QTableWidgetItem *__colItem = new QTableWidgetItem();
115 __colItem->setText(QApplication::translate("CreateCase", "", 0, QApplication::UnicodeUTF8));
116 TWBoundary->setHorizontalHeaderItem(0, __colItem);
117 for ( int i = 0; i < _listeGroupesCas->length(); i++ )
119 TWBoundary->insertRow(i);
120 TWBoundary->setItem( i, 0, new QTableWidgetItem(QString((_listeGroupesCas)[i]).trimmed()));
121 TWBoundary->item( i, 0 )->setFlags(Qt::ItemIsEnabled |Qt::ItemIsSelectable );
123 // Pour les frontieres discretes : la liste a saisir
124 // Pour les frontieres analytiques : les colonnes de chaque frontiere
125 HOMARD::HOMARD_Boundary_var myBoundary ;
126 HOMARD::listeBoundarys_var mesBoundarys = myHomardGen->GetAllBoundarysName();
127 // MESSAGE("Nombre de frontieres enregistrees : "<<mesBoundarys->length());
128 for (int i=0; i<mesBoundarys->length(); i++)
130 myBoundary = myHomardGen->GetBoundary(mesBoundarys[i]);
131 int type_obj = myBoundary->GetType() ;
132 if ( type_obj==0 ) { CBBoundaryDi->addItem(QString(mesBoundarys[i])); }
133 else { AddBoundaryAn(QString(mesBoundarys[i])); }
136 TWBoundary->resizeColumnsToContents();
137 TWBoundary->resizeRowsToContents();
138 TWBoundary->clearSelection();
140 // -------------------------------
141 bool MonCreateCase::PushOnApply()
142 // --------------------------------
144 MESSAGE("PushOnApply");
145 QString aCaseName=LEName->text().trimmed();
146 if ( aCaseName == "" )
148 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
149 QObject::tr("HOM_CASE_NAME") );
153 QString aDirName=LEDirName->text().trimmed();
154 if (aDirName == QString(""))
156 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
157 QObject::tr("HOM_CASE_DIRECTORY_1") );
161 if ( aDirName != _aDirName)
162 { QString CaseNameDir = myHomardGen->VerifieDir( aDirName.toStdString().c_str()) ;
163 if ( CaseNameDir != "" )
166 texte = QObject::tr("HOM_CASE_DIRECTORY_2") + CaseNameDir ;
167 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
173 if (chdir(aDirName.toStdString().c_str()) != 0)
175 if (_chdir(aDirName.toStdString().c_str()) != 0)
178 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
179 QObject::tr("HOM_CASE_DIRECTORY_3") );
183 QString aFileName=LEFileName->text().trimmed();
184 if (aFileName ==QString(""))
186 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
187 QObject::tr("HOM_CASE_MESH") );
191 QString aMeshName = HOMARD_QT_COMMUN::LireNomMaillage(aFileName);
192 if (aMeshName == "" )
194 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
195 QObject::tr("HOM_MED_FILE_2") );
199 if (CBBoundaryA->isChecked())
201 QStringList ListeGroup ;
203 int nbcol = TWBoundary->columnCount();
204 int nbrow = TWBoundary->rowCount();
205 for ( int col=1; col< nbcol; col++)
207 for ( int row=0; row< nbrow; row++)
209 if ( TWBoundary->item( row, col )->checkState() == Qt::Checked )
212 NomGroup = QString(TWBoundary->item(row, 0)->text()) ;
213 // MESSAGE("NomGroup "<<NomGroup.toStdString().c_str());
214 for ( int nugr = 0 ; nugr<ListeGroup.size(); nugr++)
216 // MESSAGE("....... "<<ListeGroup[nugr].toStdString().c_str());
217 if ( NomGroup == ListeGroup[nugr] )
219 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
220 QObject::tr("HOM_CASE_GROUP").arg(NomGroup) );
224 ListeGroup.insert(0, NomGroup );
230 if (aCaseName != _aCaseName )
232 _aCaseName = aCaseName;
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()) );
240 catch( SALOME::SALOME_Exception& S_ex )
242 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
243 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
246 aCase = myHomardGen->GetCase(_aCaseName.toStdString().c_str());
247 string iter0 = aCase->GetIter0Name();
248 HOMARD::HOMARD_Iteration_var aIter = myHomardGen->GetIteration(iter0.c_str());
249 QString aFileName = aIter->GetMeshFile();
250 LEFileName->setText(aFileName);
251 LEFileName->setReadOnly(true);
254 catch( SALOME::SALOME_Exception& S_ex ) {};
257 LEFileName->setReadOnly(true);
262 aCase->SetDirName(aDirName.toStdString().c_str());
264 aCase->SetConfType(_ConfType);
266 // Enregistrement de la frontiere discrete
267 if (CBBoundaryD->isChecked())
269 QString monBoundaryDiName=CBBoundaryDi->currentText();
270 if (monBoundaryDiName != "" )
272 aCase->AddBoundaryGroup(monBoundaryDiName.toStdString().c_str(), "");
276 // Enregistrement des liens (groupe,frontiere analytique)
277 if (CBBoundaryA->isChecked())
280 int nbcol = TWBoundary->columnCount();
281 int nbrow = TWBoundary->rowCount();
282 for ( int col=1; col< nbcol; col++)
284 for ( int row=0; row< nbrow; row++)
286 if ( TWBoundary->item( row, col )->checkState() == Qt::Checked )
289 NomGroup = QString(TWBoundary->item(row, 0)->text()) ;
290 // Nom de la frontiere
291 QTableWidgetItem *__colItem = new QTableWidgetItem();
292 __colItem = TWBoundary->horizontalHeaderItem(col);
293 aCase->AddBoundaryGroup(QString(__colItem->text()).toStdString().c_str(), NomGroup.toStdString().c_str());
300 if (CBAdvanced->isChecked())
302 // Autorisation des pyramides
303 if (CBPyramid->isChecked()) { _Pyram = 1 ; }
306 HOMARD_UTILS::updateObjBrowser();
310 // ---------------------------
311 void MonCreateCase::PushOnOK()
312 // ---------------------------
314 bool bOK = PushOnApply();
315 if ( bOK ) this->close();
317 //------------------------------
318 void MonCreateCase::PushOnHelp()
319 //-------------------------------
321 char* LanguageShort = myHomardGen->GetLanguageShort();
322 HOMARD_UTILS::PushOnHelp(QString("gui_create_case.html"), QString(""), QString(LanguageShort));
324 // ---------------------------------
325 void MonCreateCase::SetNewName()
326 // ------------------------------
328 HOMARD::listeCases_var MyCases = myHomardGen->GetAllCasesName();
329 int num = 0; QString aCaseName="";
330 while (aCaseName=="" )
332 aCaseName.setNum(num+1) ;
333 aCaseName.insert(0, QString("Case_")) ;
334 for ( int i=0; i<MyCases->length(); i++)
336 if ( aCaseName == QString((MyCases)[i]))
345 LEName->insert(aCaseName);
348 // ------------------------------------------------------------------------
349 void MonCreateCase::SetDirName()
350 // ------------------------------------------------------------------------
352 QString aDirName=QFileDialog::getExistingDirectory ();
353 if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
355 // ------------------------------------------------------------------------
356 void MonCreateCase::SetFileName()
357 // ------------------------------------------------------------------------
359 QString fileName0 = LEFileName->text().trimmed();
360 QString fileName = HOMARD_QT_COMMUN::PushNomFichier();
361 if (fileName.isEmpty()) fileName = fileName0 ;
362 LEFileName->setText(fileName);
364 // ------------------------------------------------------------------------
365 void MonCreateCase::SetConforme()
366 // ------------------------------------------------------------------------
368 GBTypeNoConf->setVisible(0);
372 // ------------------------------------------------------------------------
373 void MonCreateCase::SetNonConforme()
374 // ------------------------------------------------------------------------
376 GBTypeNoConf->setVisible(1);
377 RB1NpM->setChecked(true);
381 // ------------------------------------------------------------------------
382 void MonCreateCase::Set1NpM()
383 // ------------------------------------------------------------------------
387 // ------------------------------------------------------------------------
388 void MonCreateCase::Set1NpA()
389 // ------------------------------------------------------------------------
393 // ------------------------------------------------------------------------
394 void MonCreateCase::SetQuelconque()
395 // ------------------------------------------------------------------------
399 // ------------------------------------------------------------------------
400 void MonCreateCase::SetBoundaryD()
401 // ------------------------------------------------------------------------
403 MESSAGE("Debut de SetBoundaryD ");
404 if (CBBoundaryD->isChecked())
406 bool bOK = PushOnApply();
407 if (bOK) { GBBoundaryD->setVisible(1); }
408 else { GBBoundaryD->setVisible(0);
409 CBBoundaryD->setChecked(0);
410 CBBoundaryD->setCheckState(Qt::Unchecked); }
412 else { GBBoundaryD->setVisible(0); }
415 // ------------------------------------------------------------------------
416 void MonCreateCase::AddBoundaryDi(QString newBoundary)
417 // ------------------------------------------------------------------------
419 CBBoundaryDi->insertItem(0,newBoundary);
420 CBBoundaryDi->setCurrentIndex(0);
422 // ------------------------------------------------------------------------
423 void MonCreateCase::PushBoundaryDiNew()
424 // ------------------------------------------------------------------------
426 MonCreateBoundaryDi *BoundaryDlg = new MonCreateBoundaryDi(this, true,
427 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName, "") ;
430 // ------------------------------------------------------------------------
431 void MonCreateCase::PushBoundaryDiEdit()
432 // ------------------------------------------------------------------------
434 if (CBBoundaryDi->currentText() == QString("")) return;
435 MonEditBoundaryDi *BoundaryDlg = new MonEditBoundaryDi(this, true,
436 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName, CBBoundaryDi->currentText() ) ;
439 // ------------------------------------------------------------------------
440 void MonCreateCase::PushBoundaryDiHelp()
441 // ------------------------------------------------------------------------
443 char* LanguageShort = myHomardGen->GetLanguageShort();
444 HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html"), QString("frontiere-discrete"), QString(LanguageShort));
446 // ------------------------------------------------------------------------
447 void MonCreateCase::SetBoundaryA()
448 // ------------------------------------------------------------------------
450 MESSAGE("Debut de SetBoundaryA ");
451 if (CBBoundaryA->isChecked())
453 bool bOK = PushOnApply();
454 if (bOK) { GBBoundaryA->setVisible(1); }
455 else { GBBoundaryA->setVisible(0);
456 CBBoundaryA->setChecked(0);
457 CBBoundaryA->setCheckState(Qt::Unchecked); }
459 else { GBBoundaryA->setVisible(0); }
462 // MESSAGE("Fin de SetBoundaryA ");
464 // ------------------------------------------------------------------------
465 void MonCreateCase::AddBoundaryAn(QString newBoundary)
466 // ------------------------------------------------------------------------
468 MESSAGE("Debut de AddBoundaryAn ");
469 // Ajout d'une nouvelle colonne
470 int nbcol = TWBoundary->columnCount();
471 // MESSAGE("nbcol " << nbcol);
473 TWBoundary->setColumnCount ( nbcol ) ;
474 QTableWidgetItem *__colItem = new QTableWidgetItem();
475 __colItem->setText(QApplication::translate("CreateCase", newBoundary.toStdString().c_str(), 0, QApplication::UnicodeUTF8));
476 TWBoundary->setHorizontalHeaderItem(nbcol-1, __colItem);
477 /* TWBoundary->horizontalHeaderItem(nbcol-1)->setFlags( Qt::ItemIsSelectable|Qt::ItemIsEnabled );*/
478 // Chaque case est a cocher
479 int nbrow = TWBoundary->rowCount();
480 // MESSAGE("nbrow " << nbrow);
481 for ( int i = 0; i < nbrow; i++ )
483 TWBoundary->setItem( i, nbcol-1, new QTableWidgetItem( QString ("") ) );
484 TWBoundary->item( i, nbcol-1 )->setFlags( 0 );
485 TWBoundary->item( i, nbcol-1 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled );
486 TWBoundary->item( i, nbcol-1 )->setCheckState( Qt::Unchecked );
488 TWBoundary->resizeColumnToContents(nbcol-1);
489 // TWBoundary->resizeRowsToContents();
490 // MESSAGE("Fin de AddBoundaryAn ");
492 // ------------------------------------------------------------------------
493 void MonCreateCase::PushBoundaryAnNew()
494 // ------------------------------------------------------------------------
496 MonCreateBoundaryAn *BoundaryDlg = new MonCreateBoundaryAn(this, true,
497 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName) ;
500 // ------------------------------------------------------------------------
501 void MonCreateCase::PushBoundaryAnEdit()
502 // ------------------------------------------------------------------------
505 int nbcol = TWBoundary->columnCount();
506 for ( int i = 1; i < nbcol; i++ )
508 QTableWidgetItem *__colItem = new QTableWidgetItem();
509 __colItem = TWBoundary->horizontalHeaderItem(i);
510 nom = QString(__colItem->text()) ;
511 MESSAGE("nom "<<nom.toStdString().c_str());
512 if (nom != QString(""))
513 { MonEditBoundaryAn *BoundaryDlg = new MonEditBoundaryAn(this, true,
514 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName, nom ) ;
515 BoundaryDlg->show(); }
518 // ------------------------------------------------------------------------
519 void MonCreateCase::PushBoundaryAnHelp()
520 // ------------------------------------------------------------------------
522 char* LanguageShort = myHomardGen->GetLanguageShort();
523 HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html"), QString("frontiere-analytique"), QString(LanguageShort));
525 // ------------------------------------------------------------------------
526 void MonCreateCase::CaseNameChanged()
527 // ------------------------------------------------------------------------
529 if (_aCaseName != LEName->text().trimmed())
531 LEFileName->setReadOnly(false);
535 // ------------------------------------------------------------------------
536 void MonCreateCase::SetAdvanced()
537 // ------------------------------------------------------------------------
539 MESSAGE("Debut de SetAdvanced ");
540 if (CBAdvanced->isChecked()) { GBAdvancedOptions->setVisible(1); }
542 { GBAdvancedOptions->setVisible(0);
543 CBPyramid->setChecked(false);