1 // Copyright (C) 2011-2014 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"
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 ; }
303 aCase->SetPyram(_Pyram);
305 HOMARD_UTILS::updateObjBrowser();
309 // ---------------------------
310 void MonCreateCase::PushOnOK()
311 // ---------------------------
313 bool bOK = PushOnApply(1);
314 if ( bOK ) this->close();
316 //------------------------------
317 void MonCreateCase::PushOnHelp()
318 //-------------------------------
320 std::string LanguageShort = myHomardGen->GetLanguageShort();
321 HOMARD_UTILS::PushOnHelp(QString("gui_create_case.html"), QString(""), QString(LanguageShort.c_str()));
323 // ---------------------------------
324 void MonCreateCase::SetNewName()
325 // ------------------------------
327 HOMARD::listeCases_var MyCases = myHomardGen->GetAllCasesName();
328 int num = 0; QString aCaseName="";
329 while (aCaseName=="" )
331 aCaseName.setNum(num+1) ;
332 aCaseName.insert(0, QString("Case_")) ;
333 for ( int i=0; i<MyCases->length(); i++)
335 if ( aCaseName == QString((MyCases)[i]))
344 LEName->insert(aCaseName);
347 // ------------------------------------------------------------------------
348 void MonCreateCase::SetDirName()
349 // ------------------------------------------------------------------------
351 QString aDirName=QFileDialog::getExistingDirectory ();
352 if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
354 // ------------------------------------------------------------------------
355 void MonCreateCase::SetFileName()
356 // ------------------------------------------------------------------------
358 QString fileName0 = LEFileName->text().trimmed();
359 QString fileName = HOMARD_QT_COMMUN::PushNomFichier( false, QString("med") ) ;
360 if (fileName.isEmpty()) fileName = fileName0 ;
361 LEFileName->setText(fileName);
363 // ------------------------------------------------------------------------
364 void MonCreateCase::SetConforme()
365 // ------------------------------------------------------------------------
367 GBTypeNoConf->setVisible(0);
373 // ------------------------------------------------------------------------
374 void MonCreateCase::SetNonConforme()
375 // ------------------------------------------------------------------------
377 GBTypeNoConf->setVisible(1);
378 RB1NpM->setChecked(true);
384 // ------------------------------------------------------------------------
385 void MonCreateCase::Set1NpM()
386 // ------------------------------------------------------------------------
390 // ------------------------------------------------------------------------
391 void MonCreateCase::Set1NpA()
392 // ------------------------------------------------------------------------
396 // ------------------------------------------------------------------------
397 void MonCreateCase::SetQuelconque()
398 // ------------------------------------------------------------------------
402 // ------------------------------------------------------------------------
403 void MonCreateCase::SetBoundaryD()
404 // ------------------------------------------------------------------------
406 MESSAGE("Debut de SetBoundaryD ");
407 if (CBBoundaryD->isChecked())
409 bool bOK = PushOnApply(0);
410 if (bOK) { GBBoundaryD->setVisible(1); }
411 else { GBBoundaryD->setVisible(0);
412 CBBoundaryD->setChecked(0);
413 CBBoundaryD->setCheckState(Qt::Unchecked); }
415 else { GBBoundaryD->setVisible(0); }
419 // ------------------------------------------------------------------------
420 void MonCreateCase::AddBoundaryDi(QString newBoundary)
421 // ------------------------------------------------------------------------
423 CBBoundaryDi->insertItem(0,newBoundary);
424 CBBoundaryDi->setCurrentIndex(0);
426 // ------------------------------------------------------------------------
427 void MonCreateCase::PushBoundaryDiNew()
428 // ------------------------------------------------------------------------
430 MonCreateBoundaryDi *BoundaryDlg = new MonCreateBoundaryDi(this, true,
431 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName, "") ;
434 // ------------------------------------------------------------------------
435 void MonCreateCase::PushBoundaryDiEdit()
436 // ------------------------------------------------------------------------
438 if (CBBoundaryDi->currentText() == QString("")) return;
439 MonEditBoundaryDi *BoundaryDlg = new MonEditBoundaryDi(this, true,
440 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName, CBBoundaryDi->currentText() ) ;
443 // ------------------------------------------------------------------------
444 void MonCreateCase::PushBoundaryDiHelp()
445 // ------------------------------------------------------------------------
447 std::string LanguageShort = myHomardGen->GetLanguageShort();
448 HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html"), QString("frontiere-discrete"), QString(LanguageShort.c_str()));
450 // ------------------------------------------------------------------------
451 void MonCreateCase::SetBoundaryA()
452 // ------------------------------------------------------------------------
454 MESSAGE("Debut de SetBoundaryA ");
455 if (CBBoundaryA->isChecked())
457 bool bOK = PushOnApply(0);
458 if (bOK) { GBBoundaryA->setVisible(1); }
459 else { GBBoundaryA->setVisible(0);
460 CBBoundaryA->setChecked(0);
461 CBBoundaryA->setCheckState(Qt::Unchecked); }
463 else { GBBoundaryA->setVisible(0); }
467 // MESSAGE("Fin de SetBoundaryA ");
469 // ------------------------------------------------------------------------
470 void MonCreateCase::AddBoundaryAn(QString newBoundary)
471 // ------------------------------------------------------------------------
473 MESSAGE("Debut de AddBoundaryAn ");
474 // Ajout d'une nouvelle colonne
475 int nbcol = TWBoundary->columnCount();
476 // MESSAGE("nbcol " << nbcol);
478 TWBoundary->setColumnCount ( nbcol ) ;
479 QTableWidgetItem *__colItem = new QTableWidgetItem();
480 __colItem->setText(QApplication::translate("CreateCase", newBoundary.toStdString().c_str(), 0, QApplication::UnicodeUTF8));
481 TWBoundary->setHorizontalHeaderItem(nbcol-1, __colItem);
482 /* TWBoundary->horizontalHeaderItem(nbcol-1)->setFlags( Qt::ItemIsSelectable|Qt::ItemIsEnabled );*/
483 // Chaque case est a cocher
484 int nbrow = TWBoundary->rowCount();
485 // MESSAGE("nbrow " << nbrow);
486 for ( int i = 0; i < nbrow; i++ )
488 TWBoundary->setItem( i, nbcol-1, new QTableWidgetItem( QString ("") ) );
489 TWBoundary->item( i, nbcol-1 )->setFlags( 0 );
490 TWBoundary->item( i, nbcol-1 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled );
491 TWBoundary->item( i, nbcol-1 )->setCheckState( Qt::Unchecked );
493 TWBoundary->resizeColumnToContents(nbcol-1);
494 // TWBoundary->resizeRowsToContents();
495 // MESSAGE("Fin de AddBoundaryAn ");
497 // ------------------------------------------------------------------------
498 void MonCreateCase::PushBoundaryAnNew()
499 // ------------------------------------------------------------------------
501 MonCreateBoundaryAn *BoundaryDlg = new MonCreateBoundaryAn(this, true,
502 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName) ;
505 // ------------------------------------------------------------------------
506 void MonCreateCase::PushBoundaryAnEdit()
507 // ------------------------------------------------------------------------
510 int nbcol = TWBoundary->columnCount();
511 for ( int i = 1; i < nbcol; i++ )
513 QTableWidgetItem *__colItem = new QTableWidgetItem();
514 __colItem = TWBoundary->horizontalHeaderItem(i);
515 nom = QString(__colItem->text()) ;
516 MESSAGE("nom "<<nom.toStdString().c_str());
517 if (nom != QString(""))
518 { MonEditBoundaryAn *BoundaryDlg = new MonEditBoundaryAn(this, true,
519 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName, nom ) ;
520 BoundaryDlg->show(); }
523 // ------------------------------------------------------------------------
524 void MonCreateCase::PushBoundaryAnHelp()
525 // ------------------------------------------------------------------------
527 std::string LanguageShort = myHomardGen->GetLanguageShort();
528 HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html"), QString("frontiere-analytique"), QString(LanguageShort.c_str()));
530 // ------------------------------------------------------------------------
531 void MonCreateCase::CaseNameChanged()
532 // ------------------------------------------------------------------------
534 if (_aCaseName != LEName->text().trimmed())
536 LEFileName->setReadOnly(false);
540 // ------------------------------------------------------------------------
541 void MonCreateCase::SetAdvanced()
542 // ------------------------------------------------------------------------
544 MESSAGE("Debut de SetAdvanced ");
545 if (CBAdvanced->isChecked()) { GBAdvancedOptions->setVisible(1); }
547 { GBAdvancedOptions->setVisible(0);
548 CBPyramid->setChecked(false);