1 // Copyright (C) 2011-2015 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, or (at your option) any later version.
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"
27 #include <QFileDialog>
28 #include <QMessageBox>
30 #include "SalomeApp_Tools.h"
31 #include "HOMARDGUI_Utils.h"
32 #include "HomardQtCommun.h"
33 #include <utilities.h>
41 // -----------------------------------------------------------------------------------------
42 /* Constructs a MonCreateCase
43 * Inherits from CasHomard
44 * Sets attributes to default values
46 // -----------------------------------------------------------------------------------------
47 MonCreateCase::MonCreateCase( bool modal, HOMARD::HOMARD_Gen_var myHomardGen0 )
50 _aCaseName(""),_aDirName(""),
54 MESSAGE("Debut du constructeur de MonCreateCase");
55 myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen0);
61 GBBoundaryA->setVisible(0);
62 GBBoundaryD->setVisible(0);
63 GBAdvancedOptions->setVisible(0);
64 Comment->setVisible(0);
65 CBPyramid->setChecked(false);
69 // MESSAGE("Fin du constructeur de MonCreateCase");
71 // ------------------------------------------------------------------------
72 MonCreateCase::~MonCreateCase()
73 // ------------------------------------------------------------------------
75 // no need to delete child widgets, Qt does it all for us
77 // ------------------------------------------------------------------------
78 void MonCreateCase::InitConnect()
79 // ------------------------------------------------------------------------
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()));
85 connect( RBConforme, SIGNAL(clicked()), this, SLOT(SetConforme()));
86 connect( RBNonConforme, SIGNAL(clicked()), this, SLOT(SetNonConforme()));
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()) );
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()));
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()));
108 // ------------------------------------------------------------------------
109 void MonCreateCase::InitBoundarys()
110 // ------------------------------------------------------------------------
111 // Initialisation des menus avec les frontieres deja enregistrees
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++ )
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 );
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++)
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])); }
138 TWBoundary->resizeColumnsToContents();
139 TWBoundary->resizeRowsToContents();
140 TWBoundary->clearSelection();
142 // -------------------------------
143 bool MonCreateCase::PushOnApply(int option)
144 // --------------------------------
146 MESSAGE("PushOnApply");
147 QString aCaseName=LEName->text().trimmed();
148 if ( aCaseName == "" )
150 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
151 QObject::tr("HOM_CASE_NAME") );
155 QString aDirName=LEDirName->text().trimmed();
156 if (aDirName == QString(""))
158 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
159 QObject::tr("HOM_CASE_DIRECTORY_1") );
163 if ( aDirName != _aDirName)
164 { QString CaseNameDir = myHomardGen->VerifieDir( aDirName.toStdString().c_str()) ;
165 if ( ( CaseNameDir != "" ) & ( CaseNameDir != aCaseName ) )
168 texte = QObject::tr("HOM_CASE_DIRECTORY_2") + CaseNameDir ;
169 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
174 if (CHDIR(aDirName.toStdString().c_str()) != 0)
176 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
177 QObject::tr("HOM_CASE_DIRECTORY_3") );
181 QString aFileName=LEFileName->text().trimmed();
182 if (aFileName ==QString(""))
184 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
185 QObject::tr("HOM_CASE_MESH") );
189 QString aMeshName = HOMARD_QT_COMMUN::LireNomMaillage(aFileName);
190 if (aMeshName == "" )
192 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
193 QObject::tr("HOM_MED_FILE_2") );
197 // On verifie qu'un groupe n'est pas associe a deux frontieres differentes
198 if (CBBoundaryA->isChecked())
200 QStringList ListeGroup ;
202 int nbcol = TWBoundary->columnCount();
203 int nbrow = TWBoundary->rowCount();
204 for ( int col=1; col< nbcol; col++)
206 for ( int row=0; row< nbrow; row++)
208 if ( TWBoundary->item( row, col )->checkState() == Qt::Checked )
211 NomGroup = QString(TWBoundary->item(row, 0)->text()) ;
212 // MESSAGE("NomGroup "<<NomGroup.toStdString().c_str());
213 for ( int nugr = 0 ; nugr<ListeGroup.size(); nugr++)
215 // MESSAGE("....... "<<ListeGroup[nugr].toStdString().c_str());
216 if ( NomGroup == ListeGroup[nugr] )
218 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
219 QObject::tr("HOM_CASE_GROUP").arg(NomGroup) );
223 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 LEFileName->setReadOnly(true);
251 // Repertoire et type
252 aCase->SetDirName(aDirName.toStdString().c_str());
254 aCase->SetConfType(_ConfType);
256 // Menage des eventuelles frontieres deja enregistrees
257 aCase->SupprBoundaryGroup() ;
259 // Enregistrement et publication dans l'arbre d'etudes a la sortie definitive
262 if (CBBoundaryD->isChecked())
264 QString monBoundaryDiName=CBBoundaryDi->currentText();
265 if (monBoundaryDiName != "" )
267 aCase->AddBoundaryGroup(monBoundaryDiName.toStdString().c_str(), "");
270 if (CBBoundaryA->isChecked())
273 int nbcol = TWBoundary->columnCount();
274 int nbrow = TWBoundary->rowCount();
275 for ( int col=1; col< nbcol; col++)
277 for ( int row=0; row< nbrow; row++)
279 if ( TWBoundary->item( row, col )->checkState() == Qt::Checked )
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());
295 if (CBAdvanced->isChecked())
297 // Autorisation des pyramides
298 if (CBPyramid->isChecked()) { _Pyram = 1 ; }
300 aCase->SetPyram(_Pyram);
302 HOMARD_UTILS::updateObjBrowser();
306 // ---------------------------
307 void MonCreateCase::PushOnOK()
308 // ---------------------------
310 bool bOK = PushOnApply(1);
311 if ( bOK ) this->close();
313 //------------------------------
314 void MonCreateCase::PushOnHelp()
315 //-------------------------------
317 std::string LanguageShort = myHomardGen->GetLanguageShort();
318 HOMARD_UTILS::PushOnHelp(QString("gui_create_case.html"), QString(""), QString(LanguageShort.c_str()));
320 // ---------------------------------
321 void MonCreateCase::SetNewName()
322 // ------------------------------
324 HOMARD::listeCases_var MyCases = myHomardGen->GetAllCasesName();
325 int num = 0; QString aCaseName="";
326 while (aCaseName=="" )
328 aCaseName.setNum(num+1) ;
329 aCaseName.insert(0, QString("Case_")) ;
330 for ( int i=0; i<MyCases->length(); i++)
332 if ( aCaseName == QString((MyCases)[i]))
341 LEName->insert(aCaseName);
344 // ------------------------------------------------------------------------
345 void MonCreateCase::SetDirName()
346 // ------------------------------------------------------------------------
348 QString aDirName=QFileDialog::getExistingDirectory ();
349 if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
351 // ------------------------------------------------------------------------
352 void MonCreateCase::SetFileName()
353 // ------------------------------------------------------------------------
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);
360 // ------------------------------------------------------------------------
361 void MonCreateCase::SetConforme()
362 // ------------------------------------------------------------------------
366 RBNC1NpA->setVisible(0);
367 RBNCQuelconque->setVisible(0);
371 // ------------------------------------------------------------------------
372 void MonCreateCase::SetNonConforme()
373 // ------------------------------------------------------------------------
377 RBNC1NpA->setVisible(1);
378 RBNCQuelconque->setVisible(1);
382 // ------------------------------------------------------------------------
383 void MonCreateCase::SetStandard()
384 // ------------------------------------------------------------------------
386 if ( ( _ConfType == 0 ) || ( _ConfType == -1 ) ) { _ConfType = 0 ; }
387 else { _ConfType = 1 ; }
388 RBStandard->setChecked(true);
390 // ------------------------------------------------------------------------
391 void MonCreateCase::SetBox()
392 // ------------------------------------------------------------------------
394 if ( ( _ConfType == 0 ) || ( _ConfType == -1 ) ) { _ConfType = -1 ; }
395 else { _ConfType = -2 ; }
397 // ------------------------------------------------------------------------
398 void MonCreateCase::SetNC1NpA()
399 // ------------------------------------------------------------------------
403 // ------------------------------------------------------------------------
404 void MonCreateCase::SetNCQuelconque()
405 // ------------------------------------------------------------------------
409 // ------------------------------------------------------------------------
410 void MonCreateCase::SetBoundaryD()
411 // ------------------------------------------------------------------------
413 MESSAGE("Debut de SetBoundaryD ");
414 if (CBBoundaryD->isChecked())
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); }
422 else { GBBoundaryD->setVisible(0); }
426 // ------------------------------------------------------------------------
427 void MonCreateCase::AddBoundaryDi(QString newBoundary)
428 // ------------------------------------------------------------------------
430 CBBoundaryDi->insertItem(0,newBoundary);
431 CBBoundaryDi->setCurrentIndex(0);
433 // ------------------------------------------------------------------------
434 void MonCreateCase::PushBoundaryDiNew()
435 // ------------------------------------------------------------------------
437 MonCreateBoundaryDi *BoundaryDlg = new MonCreateBoundaryDi(this, true,
438 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName, "") ;
441 // ------------------------------------------------------------------------
442 void MonCreateCase::PushBoundaryDiEdit()
443 // ------------------------------------------------------------------------
445 if (CBBoundaryDi->currentText() == QString("")) return;
446 MonEditBoundaryDi *BoundaryDlg = new MonEditBoundaryDi(this, true,
447 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName, CBBoundaryDi->currentText() ) ;
450 // ------------------------------------------------------------------------
451 void MonCreateCase::PushBoundaryDiHelp()
452 // ------------------------------------------------------------------------
454 std::string LanguageShort = myHomardGen->GetLanguageShort();
455 HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html"), QString("frontiere-discrete"), QString(LanguageShort.c_str()));
457 // ------------------------------------------------------------------------
458 void MonCreateCase::SetBoundaryA()
459 // ------------------------------------------------------------------------
461 MESSAGE("Debut de SetBoundaryA ");
462 if (CBBoundaryA->isChecked())
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); }
470 else { GBBoundaryA->setVisible(0); }
474 // MESSAGE("Fin de SetBoundaryA ");
476 // ------------------------------------------------------------------------
477 void MonCreateCase::AddBoundaryAn(QString newBoundary)
478 // ------------------------------------------------------------------------
480 MESSAGE("Debut de AddBoundaryAn ");
481 // Ajout d'une nouvelle colonne
482 int nbcol = TWBoundary->columnCount();
483 // MESSAGE("nbcol " << nbcol);
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++ )
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 );
500 TWBoundary->resizeColumnToContents(nbcol-1);
501 // TWBoundary->resizeRowsToContents();
502 // MESSAGE("Fin de AddBoundaryAn ");
504 // ------------------------------------------------------------------------
505 void MonCreateCase::PushBoundaryAnNew()
506 // ------------------------------------------------------------------------
508 MonCreateBoundaryAn *BoundaryDlg = new MonCreateBoundaryAn(this, true,
509 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName) ;
512 // ------------------------------------------------------------------------
513 void MonCreateCase::PushBoundaryAnEdit()
514 // ------------------------------------------------------------------------
517 int nbcol = TWBoundary->columnCount();
518 for ( int i = 1; i < nbcol; i++ )
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(); }
530 // ------------------------------------------------------------------------
531 void MonCreateCase::PushBoundaryAnHelp()
532 // ------------------------------------------------------------------------
534 std::string LanguageShort = myHomardGen->GetLanguageShort();
535 HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html"), QString("frontiere-analytique"), QString(LanguageShort.c_str()));
537 // ------------------------------------------------------------------------
538 void MonCreateCase::CaseNameChanged()
539 // ------------------------------------------------------------------------
541 if (_aCaseName != LEName->text().trimmed())
543 LEFileName->setReadOnly(false);
547 // ------------------------------------------------------------------------
548 void MonCreateCase::SetAdvanced()
549 // ------------------------------------------------------------------------
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);}
560 { RBNC1NpA->setVisible(1);
561 RBNCQuelconque->setVisible(1);}
564 { GBAdvancedOptions->setVisible(0);
565 CBPyramid->setChecked(false);