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);
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()));
87 connect( RB1NpM, SIGNAL(clicked()), this, SLOT(Set1NpM()));
88 connect( RB1NpA, SIGNAL(clicked()), this, SLOT(Set1NpA()));
89 connect( RBQuelconque, SIGNAL(clicked()), this, SLOT(SetQuelconque()));
91 connect( CBBoundaryD, SIGNAL(stateChanged(int)), this, SLOT(SetBoundaryD()));
92 connect( PBBoundaryDiNew, SIGNAL(pressed()), this, SLOT(PushBoundaryDiNew()));
93 connect( PBBoundaryDiEdit, SIGNAL(pressed()), this, SLOT(PushBoundaryDiEdit()) );
94 connect( PBBoundaryDiHelp, SIGNAL(pressed()), this, SLOT(PushBoundaryDiHelp()) );
95 connect( CBBoundaryA, SIGNAL(stateChanged(int)), this, SLOT(SetBoundaryA()));
96 connect( PBBoundaryAnNew, SIGNAL(pressed()), this, SLOT(PushBoundaryAnNew()));
97 connect( PBBoundaryAnEdit, SIGNAL(pressed()), this, SLOT(PushBoundaryAnEdit()) );
98 connect( PBBoundaryAnHelp, SIGNAL(pressed()), this, SLOT(PushBoundaryAnHelp()) );
100 connect( CBAdvanced, SIGNAL(stateChanged(int)), this, SLOT(SetAdvanced()));
102 connect( buttonOk, SIGNAL(pressed()), this, SLOT(PushOnOK()));
103 connect( buttonApply, SIGNAL(pressed()), this, SLOT(PushOnApply(0)));
104 connect( buttonCancel, SIGNAL(pressed()), this, SLOT(close()));
105 connect( buttonHelp, SIGNAL(pressed()), this, SLOT(PushOnHelp()));
107 // ------------------------------------------------------------------------
108 void MonCreateCase::InitBoundarys()
109 // ------------------------------------------------------------------------
110 // Initialisation des menus avec les frontieres deja enregistrees
112 MESSAGE("InitBoundarys");
113 // Pour les frontieres analytiques : la colonne des groupes
114 HOMARD::ListGroupType_var _listeGroupesCas = aCase->GetGroups();
115 QTableWidgetItem *__colItem = new QTableWidgetItem();
116 __colItem->setText(QApplication::translate("CreateCase", "", 0, QApplication::UnicodeUTF8));
117 TWBoundary->setHorizontalHeaderItem(0, __colItem);
118 for ( int i = 0; i < _listeGroupesCas->length(); i++ )
120 TWBoundary->insertRow(i);
121 TWBoundary->setItem( i, 0, new QTableWidgetItem(QString((_listeGroupesCas)[i]).trimmed()));
122 TWBoundary->item( i, 0 )->setFlags(Qt::ItemIsEnabled |Qt::ItemIsSelectable );
124 // Pour les frontieres discretes : la liste a saisir
125 // Pour les frontieres analytiques : les colonnes de chaque frontiere
126 HOMARD::HOMARD_Boundary_var myBoundary ;
127 HOMARD::listeBoundarys_var mesBoundarys = myHomardGen->GetAllBoundarysName();
128 // MESSAGE("Nombre de frontieres enregistrees : "<<mesBoundarys->length());
129 for (int i=0; i<mesBoundarys->length(); i++)
131 myBoundary = myHomardGen->GetBoundary(mesBoundarys[i]);
132 int type_obj = myBoundary->GetType() ;
133 if ( type_obj==0 ) { CBBoundaryDi->addItem(QString(mesBoundarys[i])); }
134 else { AddBoundaryAn(QString(mesBoundarys[i])); }
137 TWBoundary->resizeColumnsToContents();
138 TWBoundary->resizeRowsToContents();
139 TWBoundary->clearSelection();
141 // -------------------------------
142 bool MonCreateCase::PushOnApply(int option)
143 // --------------------------------
145 MESSAGE("PushOnApply");
146 QString aCaseName=LEName->text().trimmed();
147 if ( aCaseName == "" )
149 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
150 QObject::tr("HOM_CASE_NAME") );
154 QString aDirName=LEDirName->text().trimmed();
155 if (aDirName == QString(""))
157 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
158 QObject::tr("HOM_CASE_DIRECTORY_1") );
162 if ( aDirName != _aDirName)
163 { QString CaseNameDir = myHomardGen->VerifieDir( aDirName.toStdString().c_str()) ;
164 if ( ( CaseNameDir != "" ) & ( CaseNameDir != aCaseName ) )
167 texte = QObject::tr("HOM_CASE_DIRECTORY_2") + CaseNameDir ;
168 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
174 if (chdir(aDirName.toStdString().c_str()) != 0)
176 if (_chdir(aDirName.toStdString().c_str()) != 0)
179 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
180 QObject::tr("HOM_CASE_DIRECTORY_3") );
184 QString aFileName=LEFileName->text().trimmed();
185 if (aFileName ==QString(""))
187 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
188 QObject::tr("HOM_CASE_MESH") );
192 QString aMeshName = HOMARD_QT_COMMUN::LireNomMaillage(aFileName);
193 if (aMeshName == "" )
195 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
196 QObject::tr("HOM_MED_FILE_2") );
200 // On verifie qu'un groupe n'est pas associe a deux frontieres differentes
201 if (CBBoundaryA->isChecked())
203 QStringList ListeGroup ;
205 int nbcol = TWBoundary->columnCount();
206 int nbrow = TWBoundary->rowCount();
207 for ( int col=1; col< nbcol; col++)
209 for ( int row=0; row< nbrow; row++)
211 if ( TWBoundary->item( row, col )->checkState() == Qt::Checked )
214 NomGroup = QString(TWBoundary->item(row, 0)->text()) ;
215 // MESSAGE("NomGroup "<<NomGroup.toStdString().c_str());
216 for ( int nugr = 0 ; nugr<ListeGroup.size(); nugr++)
218 // MESSAGE("....... "<<ListeGroup[nugr].toStdString().c_str());
219 if ( NomGroup == ListeGroup[nugr] )
221 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
222 QObject::tr("HOM_CASE_GROUP").arg(NomGroup) );
226 ListeGroup.insert(0, NomGroup );
233 if (aCaseName != _aCaseName )
235 _aCaseName = aCaseName;
238 aCase = myHomardGen->CreateCase( \
239 CORBA::string_dup(_aCaseName.toStdString().c_str()), \
240 CORBA::string_dup(aMeshName.toStdString().c_str()), \
241 CORBA::string_dup(aFileName.toStdString().c_str()) );
243 catch( SALOME::SALOME_Exception& S_ex )
245 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
246 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
249 LEFileName->setReadOnly(true);
254 // Repertoire et type
255 aCase->SetDirName(aDirName.toStdString().c_str());
257 aCase->SetConfType(_ConfType);
259 // Menage des eventuelles frontieres deja enregistrees
260 aCase->SupprBoundaryGroup() ;
262 // Enregistrement et publication dans l'arbre d'etudes a la sortie definitive
265 if (CBBoundaryD->isChecked())
267 QString monBoundaryDiName=CBBoundaryDi->currentText();
268 if (monBoundaryDiName != "" )
270 aCase->AddBoundaryGroup(monBoundaryDiName.toStdString().c_str(), "");
273 if (CBBoundaryA->isChecked())
276 int nbcol = TWBoundary->columnCount();
277 int nbrow = TWBoundary->rowCount();
278 for ( int col=1; col< nbcol; col++)
280 for ( int row=0; row< nbrow; row++)
282 if ( TWBoundary->item( row, col )->checkState() == Qt::Checked )
285 NomGroup = QString(TWBoundary->item(row, 0)->text()) ;
286 // Nom de la frontiere
287 QTableWidgetItem *__colItem = new QTableWidgetItem();
288 __colItem = TWBoundary->horizontalHeaderItem(col);
289 aCase->AddBoundaryGroup(QString(__colItem->text()).toStdString().c_str(), NomGroup.toStdString().c_str());
298 if (CBAdvanced->isChecked())
300 // Autorisation des pyramides
301 if (CBPyramid->isChecked()) { _Pyram = 1 ; }
304 HOMARD_UTILS::updateObjBrowser();
308 // ---------------------------
309 void MonCreateCase::PushOnOK()
310 // ---------------------------
312 bool bOK = PushOnApply(1);
313 if ( bOK ) this->close();
315 //------------------------------
316 void MonCreateCase::PushOnHelp()
317 //-------------------------------
319 std::string LanguageShort = myHomardGen->GetLanguageShort();
320 HOMARD_UTILS::PushOnHelp(QString("gui_create_case.html"), QString(""), QString(LanguageShort.c_str()));
322 // ---------------------------------
323 void MonCreateCase::SetNewName()
324 // ------------------------------
326 HOMARD::listeCases_var MyCases = myHomardGen->GetAllCasesName();
327 int num = 0; QString aCaseName="";
328 while (aCaseName=="" )
330 aCaseName.setNum(num+1) ;
331 aCaseName.insert(0, QString("Case_")) ;
332 for ( int i=0; i<MyCases->length(); i++)
334 if ( aCaseName == QString((MyCases)[i]))
343 LEName->insert(aCaseName);
346 // ------------------------------------------------------------------------
347 void MonCreateCase::SetDirName()
348 // ------------------------------------------------------------------------
350 QString aDirName=QFileDialog::getExistingDirectory ();
351 if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
353 // ------------------------------------------------------------------------
354 void MonCreateCase::SetFileName()
355 // ------------------------------------------------------------------------
357 QString fileName0 = LEFileName->text().trimmed();
358 QString fileName = HOMARD_QT_COMMUN::PushNomFichier( false, QString("med") ) ;
359 if (fileName.isEmpty()) fileName = fileName0 ;
360 LEFileName->setText(fileName);
362 // ------------------------------------------------------------------------
363 void MonCreateCase::SetConforme()
364 // ------------------------------------------------------------------------
366 GBTypeNoConf->setVisible(0);
372 // ------------------------------------------------------------------------
373 void MonCreateCase::SetNonConforme()
374 // ------------------------------------------------------------------------
376 GBTypeNoConf->setVisible(1);
377 RB1NpM->setChecked(true);
383 // ------------------------------------------------------------------------
384 void MonCreateCase::Set1NpM()
385 // ------------------------------------------------------------------------
389 // ------------------------------------------------------------------------
390 void MonCreateCase::Set1NpA()
391 // ------------------------------------------------------------------------
395 // ------------------------------------------------------------------------
396 void MonCreateCase::SetQuelconque()
397 // ------------------------------------------------------------------------
401 // ------------------------------------------------------------------------
402 void MonCreateCase::SetBoundaryD()
403 // ------------------------------------------------------------------------
405 MESSAGE("Debut de SetBoundaryD ");
406 if (CBBoundaryD->isChecked())
408 bool bOK = PushOnApply(0);
409 if (bOK) { GBBoundaryD->setVisible(1); }
410 else { GBBoundaryD->setVisible(0);
411 CBBoundaryD->setChecked(0);
412 CBBoundaryD->setCheckState(Qt::Unchecked); }
414 else { GBBoundaryD->setVisible(0); }
418 // ------------------------------------------------------------------------
419 void MonCreateCase::AddBoundaryDi(QString newBoundary)
420 // ------------------------------------------------------------------------
422 CBBoundaryDi->insertItem(0,newBoundary);
423 CBBoundaryDi->setCurrentIndex(0);
425 // ------------------------------------------------------------------------
426 void MonCreateCase::PushBoundaryDiNew()
427 // ------------------------------------------------------------------------
429 MonCreateBoundaryDi *BoundaryDlg = new MonCreateBoundaryDi(this, true,
430 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName, "") ;
433 // ------------------------------------------------------------------------
434 void MonCreateCase::PushBoundaryDiEdit()
435 // ------------------------------------------------------------------------
437 if (CBBoundaryDi->currentText() == QString("")) return;
438 MonEditBoundaryDi *BoundaryDlg = new MonEditBoundaryDi(this, true,
439 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName, CBBoundaryDi->currentText() ) ;
442 // ------------------------------------------------------------------------
443 void MonCreateCase::PushBoundaryDiHelp()
444 // ------------------------------------------------------------------------
446 std::string LanguageShort = myHomardGen->GetLanguageShort();
447 HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html"), QString("frontiere-discrete"), QString(LanguageShort.c_str()));
449 // ------------------------------------------------------------------------
450 void MonCreateCase::SetBoundaryA()
451 // ------------------------------------------------------------------------
453 MESSAGE("Debut de SetBoundaryA ");
454 if (CBBoundaryA->isChecked())
456 bool bOK = PushOnApply(0);
457 if (bOK) { GBBoundaryA->setVisible(1); }
458 else { GBBoundaryA->setVisible(0);
459 CBBoundaryA->setChecked(0);
460 CBBoundaryA->setCheckState(Qt::Unchecked); }
462 else { GBBoundaryA->setVisible(0); }
466 // MESSAGE("Fin de SetBoundaryA ");
468 // ------------------------------------------------------------------------
469 void MonCreateCase::AddBoundaryAn(QString newBoundary)
470 // ------------------------------------------------------------------------
472 MESSAGE("Debut de AddBoundaryAn ");
473 // Ajout d'une nouvelle colonne
474 int nbcol = TWBoundary->columnCount();
475 // MESSAGE("nbcol " << nbcol);
477 TWBoundary->setColumnCount ( nbcol ) ;
478 QTableWidgetItem *__colItem = new QTableWidgetItem();
479 __colItem->setText(QApplication::translate("CreateCase", newBoundary.toStdString().c_str(), 0, QApplication::UnicodeUTF8));
480 TWBoundary->setHorizontalHeaderItem(nbcol-1, __colItem);
481 /* TWBoundary->horizontalHeaderItem(nbcol-1)->setFlags( Qt::ItemIsSelectable|Qt::ItemIsEnabled );*/
482 // Chaque case est a cocher
483 int nbrow = TWBoundary->rowCount();
484 // MESSAGE("nbrow " << nbrow);
485 for ( int i = 0; i < nbrow; i++ )
487 TWBoundary->setItem( i, nbcol-1, new QTableWidgetItem( QString ("") ) );
488 TWBoundary->item( i, nbcol-1 )->setFlags( 0 );
489 TWBoundary->item( i, nbcol-1 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled );
490 TWBoundary->item( i, nbcol-1 )->setCheckState( Qt::Unchecked );
492 TWBoundary->resizeColumnToContents(nbcol-1);
493 // TWBoundary->resizeRowsToContents();
494 // MESSAGE("Fin de AddBoundaryAn ");
496 // ------------------------------------------------------------------------
497 void MonCreateCase::PushBoundaryAnNew()
498 // ------------------------------------------------------------------------
500 MonCreateBoundaryAn *BoundaryDlg = new MonCreateBoundaryAn(this, true,
501 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName) ;
504 // ------------------------------------------------------------------------
505 void MonCreateCase::PushBoundaryAnEdit()
506 // ------------------------------------------------------------------------
509 int nbcol = TWBoundary->columnCount();
510 for ( int i = 1; i < nbcol; i++ )
512 QTableWidgetItem *__colItem = new QTableWidgetItem();
513 __colItem = TWBoundary->horizontalHeaderItem(i);
514 nom = QString(__colItem->text()) ;
515 MESSAGE("nom "<<nom.toStdString().c_str());
516 if (nom != QString(""))
517 { MonEditBoundaryAn *BoundaryDlg = new MonEditBoundaryAn(this, true,
518 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName, nom ) ;
519 BoundaryDlg->show(); }
522 // ------------------------------------------------------------------------
523 void MonCreateCase::PushBoundaryAnHelp()
524 // ------------------------------------------------------------------------
526 std::string LanguageShort = myHomardGen->GetLanguageShort();
527 HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html"), QString("frontiere-analytique"), QString(LanguageShort.c_str()));
529 // ------------------------------------------------------------------------
530 void MonCreateCase::CaseNameChanged()
531 // ------------------------------------------------------------------------
533 if (_aCaseName != LEName->text().trimmed())
535 LEFileName->setReadOnly(false);
539 // ------------------------------------------------------------------------
540 void MonCreateCase::SetAdvanced()
541 // ------------------------------------------------------------------------
543 MESSAGE("Debut de SetAdvanced ");
544 if (CBAdvanced->isChecked()) { GBAdvancedOptions->setVisible(1); }
546 { GBAdvancedOptions->setVisible(0);
547 CBPyramid->setChecked(false);