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
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 /* Constructs a MonCreateCase
39 * Inherits from CasHomard
40 * Sets attributes to default values
42 // -----------------------------------------------------------------------------------------
43 MonCreateCase::MonCreateCase( bool modal, HOMARD::HOMARD_Gen_var myHomardGen0)
46 _aCaseName(""),_aDirName(""),
50 MESSAGE("Debut du constructeur de MonCreateCase");
51 myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen0);
57 GBBoundaryA->setVisible(0);
58 GBBoundaryD->setVisible(0);
59 GBTypeNoConf->setVisible(0);
60 GBAdvancedOptions->setVisible(0);
61 Comment->setVisible(0);
62 CBPyramid->setChecked(false);
65 MESSAGE("Fin du constructeur de MonCreateCase");
67 // ------------------------------------------------------------------------
68 MonCreateCase::~MonCreateCase()
69 // ------------------------------------------------------------------------
71 // no need to delete child widgets, Qt does it all for us
73 // ------------------------------------------------------------------------
74 void MonCreateCase::InitConnect()
75 // ------------------------------------------------------------------------
77 connect( LEName, SIGNAL(textChanged(QString)), this, SLOT(CaseNameChanged()));
78 connect( PushDir, SIGNAL(pressed()), this, SLOT(SetDirName()));
79 connect( PushFichier, SIGNAL(pressed()), this, SLOT(SetFileName()));
81 connect( RBConforme, SIGNAL(clicked()), this, SLOT(SetConforme()));
82 connect( RBNonConforme, SIGNAL(clicked()), this, SLOT(SetNonConforme()));
83 connect( RB1NpM, SIGNAL(clicked()), this, SLOT(Set1NpM()));
84 connect( RB1NpA, SIGNAL(clicked()), this, SLOT(Set1NpA()));
85 connect( RBQuelconque, SIGNAL(clicked()), this, SLOT(SetQuelconque()));
87 connect( CBBoundaryD, SIGNAL(stateChanged(int)), this, SLOT(SetBoundaryD()));
88 connect( PBBoundaryDiNew, SIGNAL(pressed()), this, SLOT(PushBoundaryDiNew()));
89 connect( PBBoundaryDiEdit, SIGNAL(pressed()), this, SLOT(PushBoundaryDiEdit()) );
90 connect( PBBoundaryDiHelp, SIGNAL(pressed()), this, SLOT(PushBoundaryDiHelp()) );
91 connect( CBBoundaryA, SIGNAL(stateChanged(int)), this, SLOT(SetBoundaryA()));
92 connect( PBBoundaryAnNew, SIGNAL(pressed()), this, SLOT(PushBoundaryAnNew()));
93 connect( PBBoundaryAnEdit, SIGNAL(pressed()), this, SLOT(PushBoundaryAnEdit()) );
94 connect( PBBoundaryAnHelp, SIGNAL(pressed()), this, SLOT(PushBoundaryAnHelp()) );
96 connect( CBAdvanced, SIGNAL(stateChanged(int)), this, SLOT(SetAdvanced()));
98 connect( buttonOk, SIGNAL(pressed()), this, SLOT(PushOnOK()));
99 connect( buttonApply, SIGNAL(pressed()), this, SLOT(PushOnApply()));
100 connect( buttonCancel, SIGNAL(pressed()), this, SLOT(close()));
101 connect( buttonHelp, SIGNAL(pressed()), this, SLOT(PushOnHelp()));
103 // ------------------------------------------------------------------------
104 void MonCreateCase::InitBoundarys()
105 // ------------------------------------------------------------------------
106 // Initialisation des menus avec les frontieres deja enregistrees
108 MESSAGE("InitBoundarys");
109 // Pour les frontieres analytiques : la colonne des groupes
110 HOMARD::ListGroupType_var _listeGroupesCas = aCase->GetGroups();
111 QTableWidgetItem *__colItem = new QTableWidgetItem();
112 __colItem->setText(QApplication::translate("CreateCase", "", 0, QApplication::UnicodeUTF8));
113 TWBoundary->setHorizontalHeaderItem(0, __colItem);
114 for ( int i = 0; i < _listeGroupesCas->length(); i++ )
116 TWBoundary->insertRow(i);
117 TWBoundary->setItem( i, 0, new QTableWidgetItem(QString((_listeGroupesCas)[i]).trimmed()));
118 TWBoundary->item( i, 0 )->setFlags(Qt::ItemIsEnabled |Qt::ItemIsSelectable );
120 // Pour les frontieres discretes : la liste a saisir
121 // Pour les frontieres analytiques : les colonnes de chaque frontiere
122 HOMARD::HOMARD_Boundary_var myBoundary ;
123 HOMARD::listeBoundarys_var mesBoundarys = myHomardGen->GetAllBoundarysName();
124 // MESSAGE("Nombre de frontieres enregistrees : "<<mesBoundarys->length());
125 for (int i=0; i<mesBoundarys->length(); i++)
127 myBoundary = myHomardGen->GetBoundary(mesBoundarys[i]);
128 int type_obj = myBoundary->GetType() ;
129 if ( type_obj==0 ) { CBBoundaryDi->addItem(QString(mesBoundarys[i])); }
130 else { AddBoundaryAn(QString(mesBoundarys[i])); }
133 TWBoundary->resizeColumnsToContents();
134 TWBoundary->resizeRowsToContents();
135 TWBoundary->clearSelection();
137 // -------------------------------
138 bool MonCreateCase::PushOnApply()
139 // --------------------------------
141 MESSAGE("PushOnApply");
142 QString aCaseName=LEName->text().trimmed();
143 if ( aCaseName == "" )
145 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
146 QObject::tr("HOM_CASE_NAME") );
150 QString aDirName=LEDirName->text().trimmed();
151 if (aDirName == QString(""))
153 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
154 QObject::tr("HOM_CASE_DIRECTORY_1") );
158 if ( aDirName != _aDirName)
159 { QString CaseNameDir = myHomardGen->VerifieDir( aDirName.toStdString().c_str()) ;
160 if ( CaseNameDir != "" )
163 texte = QObject::tr("HOM_CASE_DIRECTORY_2") + CaseNameDir ;
164 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
169 if (chdir(aDirName.toStdString().c_str()) != 0)
171 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
172 QObject::tr("HOM_CASE_DIRECTORY_3") );
176 QString aFileName=LEFileName->text().trimmed();
177 if (aFileName ==QString(""))
179 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
180 QObject::tr("HOM_CASE_MESH") );
184 QString aMeshName = HOMARD_QT_COMMUN::LireNomMaillage(aFileName);
185 if (aMeshName == "" )
187 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
188 QObject::tr("HOM_MED_FILE_2") );
192 if (CBBoundaryA->isChecked())
194 QStringList ListeGroup ;
196 int nbcol = TWBoundary->columnCount();
197 int nbrow = TWBoundary->rowCount();
198 for ( int col=1; col< nbcol; col++)
200 for ( int row=0; row< nbrow; row++)
202 if ( TWBoundary->item( row, col )->checkState() == Qt::Checked )
205 NomGroup = QString(TWBoundary->item(row, 0)->text()) ;
206 // MESSAGE("NomGroup "<<NomGroup.toStdString().c_str());
207 for ( int nugr = 0 ; nugr<ListeGroup.size(); nugr++)
209 // MESSAGE("....... "<<ListeGroup[nugr].toStdString().c_str());
210 if ( NomGroup == ListeGroup[nugr] )
212 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
213 QObject::tr("HOM_CASE_GROUP").arg(NomGroup) );
217 ListeGroup.insert(0, NomGroup );
223 if (aCaseName != _aCaseName )
225 _aCaseName = aCaseName;
228 aCase = myHomardGen->CreateCase( \
229 CORBA::string_dup(_aCaseName.toStdString().c_str()), \
230 CORBA::string_dup(aMeshName.toStdString().c_str()), \
231 CORBA::string_dup(aFileName.toStdString().c_str()) );
233 catch( SALOME::SALOME_Exception& S_ex )
235 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
236 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
239 aCase = myHomardGen->GetCase(_aCaseName.toStdString().c_str());
240 string iter0 = aCase->GetIter0Name();
241 HOMARD::HOMARD_Iteration_var aIter = myHomardGen->GetIteration(iter0.c_str());
242 QString aFileName = aIter->GetMeshFile();
243 LEFileName->setText(aFileName);
244 LEFileName->setReadOnly(true);
247 catch( SALOME::SALOME_Exception& S_ex ) {};
250 LEFileName->setReadOnly(true);
255 aCase->SetDirName(aDirName.toStdString().c_str());
257 aCase->SetConfType(_ConfType);
259 // Enregistrement de la frontiere discrete
260 if (CBBoundaryD->isChecked())
262 QString monBoundaryDiName=CBBoundaryDi->currentText();
263 if (monBoundaryDiName != "" )
265 aCase->AddBoundaryGroup(monBoundaryDiName.toStdString().c_str(), "");
269 // Enregistrement des liens (groupe,frontiere analytique)
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());
293 if (CBAdvanced->isChecked())
295 // Autorisation des pyramides
296 if (CBPyramid->isChecked()) { _Pyram = 1 ; }
299 HOMARD_UTILS::updateObjBrowser();
303 // ---------------------------
304 void MonCreateCase::PushOnOK()
305 // ---------------------------
307 bool bOK = PushOnApply();
308 if ( bOK ) this->close();
310 //------------------------------
311 void MonCreateCase::PushOnHelp()
312 //-------------------------------
314 char* LanguageShort = myHomardGen->GetLanguageShort();
315 HOMARD_UTILS::PushOnHelp(QString("gui_create_case.html"), QString(""), QString(LanguageShort));
317 // ---------------------------------
318 void MonCreateCase::SetNewName()
319 // ------------------------------
321 HOMARD::listeCases_var MyCases = myHomardGen->GetAllCasesName();
322 int num = 0; QString aCaseName="";
323 while (aCaseName=="" )
325 aCaseName.setNum(num+1) ;
326 aCaseName.insert(0, QString("Case_")) ;
327 for ( int i=0; i<MyCases->length(); i++)
329 if ( aCaseName == QString((MyCases)[i]))
338 LEName->insert(aCaseName);
341 // ------------------------------------------------------------------------
342 void MonCreateCase::SetDirName()
343 // ------------------------------------------------------------------------
345 QString aDirName=QFileDialog::getExistingDirectory ();
346 if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
348 // ------------------------------------------------------------------------
349 void MonCreateCase::SetFileName()
350 // ------------------------------------------------------------------------
352 QString fileName0 = LEFileName->text().trimmed();
353 QString fileName = HOMARD_QT_COMMUN::PushNomFichier();
354 if (fileName.isEmpty()) fileName = fileName0 ;
355 LEFileName->setText(fileName);
357 // ------------------------------------------------------------------------
358 void MonCreateCase::SetConforme()
359 // ------------------------------------------------------------------------
361 GBTypeNoConf->setVisible(0);
365 // ------------------------------------------------------------------------
366 void MonCreateCase::SetNonConforme()
367 // ------------------------------------------------------------------------
369 GBTypeNoConf->setVisible(1);
370 RB1NpM->setChecked(true);
374 // ------------------------------------------------------------------------
375 void MonCreateCase::Set1NpM()
376 // ------------------------------------------------------------------------
380 // ------------------------------------------------------------------------
381 void MonCreateCase::Set1NpA()
382 // ------------------------------------------------------------------------
386 // ------------------------------------------------------------------------
387 void MonCreateCase::SetQuelconque()
388 // ------------------------------------------------------------------------
392 // ------------------------------------------------------------------------
393 void MonCreateCase::SetBoundaryD()
394 // ------------------------------------------------------------------------
396 MESSAGE("Debut de SetBoundaryD ");
397 if (CBBoundaryD->isChecked())
399 bool bOK = PushOnApply();
400 if (bOK) { GBBoundaryD->setVisible(1); }
401 else { GBBoundaryD->setVisible(0);
402 CBBoundaryD->setChecked(0);
403 CBBoundaryD->setCheckState(Qt::Unchecked); }
405 else { GBBoundaryD->setVisible(0); }
408 // ------------------------------------------------------------------------
409 void MonCreateCase::AddBoundaryDi(QString newBoundary)
410 // ------------------------------------------------------------------------
412 CBBoundaryDi->insertItem(0,newBoundary);
413 CBBoundaryDi->setCurrentIndex(0);
415 // ------------------------------------------------------------------------
416 void MonCreateCase::PushBoundaryDiNew()
417 // ------------------------------------------------------------------------
419 MonCreateBoundaryDi *BoundaryDlg = new MonCreateBoundaryDi(this, true,
420 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName, "") ;
423 // ------------------------------------------------------------------------
424 void MonCreateCase::PushBoundaryDiEdit()
425 // ------------------------------------------------------------------------
427 if (CBBoundaryDi->currentText() == QString("")) return;
428 MonEditBoundaryDi *BoundaryDlg = new MonEditBoundaryDi(this, true,
429 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName, CBBoundaryDi->currentText() ) ;
432 // ------------------------------------------------------------------------
433 void MonCreateCase::PushBoundaryDiHelp()
434 // ------------------------------------------------------------------------
436 char* LanguageShort = myHomardGen->GetLanguageShort();
437 HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html"), QString("frontiere-discrete"), QString(LanguageShort));
439 // ------------------------------------------------------------------------
440 void MonCreateCase::SetBoundaryA()
441 // ------------------------------------------------------------------------
443 MESSAGE("Debut de SetBoundaryA ");
444 if (CBBoundaryA->isChecked())
446 bool bOK = PushOnApply();
447 if (bOK) { GBBoundaryA->setVisible(1); }
448 else { GBBoundaryA->setVisible(0);
449 CBBoundaryA->setChecked(0);
450 CBBoundaryA->setCheckState(Qt::Unchecked); }
452 else { GBBoundaryA->setVisible(0); }
455 // MESSAGE("Fin de SetBoundaryA ");
457 // ------------------------------------------------------------------------
458 void MonCreateCase::AddBoundaryAn(QString newBoundary)
459 // ------------------------------------------------------------------------
461 MESSAGE("Debut de AddBoundaryAn ");
462 // Ajout d'une nouvelle colonne
463 int nbcol = TWBoundary->columnCount();
464 // MESSAGE("nbcol " << nbcol);
466 TWBoundary->setColumnCount ( nbcol ) ;
467 QTableWidgetItem *__colItem = new QTableWidgetItem();
468 __colItem->setText(QApplication::translate("CreateCase", newBoundary.toStdString().c_str(), 0, QApplication::UnicodeUTF8));
469 TWBoundary->setHorizontalHeaderItem(nbcol-1, __colItem);
470 /* TWBoundary->horizontalHeaderItem(nbcol-1)->setFlags( Qt::ItemIsSelectable|Qt::ItemIsEnabled );*/
471 // Chaque case est a cocher
472 int nbrow = TWBoundary->rowCount();
473 // MESSAGE("nbrow " << nbrow);
474 for ( int i = 0; i < nbrow; i++ )
476 TWBoundary->setItem( i, nbcol-1, new QTableWidgetItem( QString ("") ) );
477 TWBoundary->item( i, nbcol-1 )->setFlags( 0 );
478 TWBoundary->item( i, nbcol-1 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled );
479 TWBoundary->item( i, nbcol-1 )->setCheckState( Qt::Unchecked );
481 TWBoundary->resizeColumnToContents(nbcol-1);
482 // TWBoundary->resizeRowsToContents();
483 // MESSAGE("Fin de AddBoundaryAn ");
485 // ------------------------------------------------------------------------
486 void MonCreateCase::PushBoundaryAnNew()
487 // ------------------------------------------------------------------------
489 MonCreateBoundaryAn *BoundaryDlg = new MonCreateBoundaryAn(this, true,
490 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName) ;
493 // ------------------------------------------------------------------------
494 void MonCreateCase::PushBoundaryAnEdit()
495 // ------------------------------------------------------------------------
498 int nbcol = TWBoundary->columnCount();
499 for ( int i = 1; i < nbcol; i++ )
501 QTableWidgetItem *__colItem = new QTableWidgetItem();
502 __colItem = TWBoundary->horizontalHeaderItem(i);
503 nom = QString(__colItem->text()) ;
504 MESSAGE("nom "<<nom.toStdString().c_str());
505 if (nom != QString(""))
506 { MonEditBoundaryAn *BoundaryDlg = new MonEditBoundaryAn(this, true,
507 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName, nom ) ;
508 BoundaryDlg->show(); }
511 // ------------------------------------------------------------------------
512 void MonCreateCase::PushBoundaryAnHelp()
513 // ------------------------------------------------------------------------
515 char* LanguageShort = myHomardGen->GetLanguageShort();
516 HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html"), QString("frontiere-analytique"), QString(LanguageShort));
518 // ------------------------------------------------------------------------
519 void MonCreateCase::CaseNameChanged()
520 // ------------------------------------------------------------------------
522 if (_aCaseName != LEName->text().trimmed())
524 LEFileName->setReadOnly(false);
528 // ------------------------------------------------------------------------
529 void MonCreateCase::SetAdvanced()
530 // ------------------------------------------------------------------------
532 MESSAGE("Debut de SetAdvanced ");
533 if (CBAdvanced->isChecked()) { GBAdvancedOptions->setVisible(1); }
535 { GBAdvancedOptions->setVisible(0);
536 CBPyramid->setChecked(false);