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"
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 GBTypeNoConf->setVisible(0);
64 GBAdvancedOptions->setVisible(0);
65 Comment->setVisible(0);
66 CBPyramid->setChecked(false);
70 // MESSAGE("Fin du constructeur de MonCreateCase");
72 // ------------------------------------------------------------------------
73 MonCreateCase::~MonCreateCase()
74 // ------------------------------------------------------------------------
76 // no need to delete child widgets, Qt does it all for us
78 // ------------------------------------------------------------------------
79 void MonCreateCase::InitConnect()
80 // ------------------------------------------------------------------------
82 connect( LEName, SIGNAL(textChanged(QString)), this, SLOT(CaseNameChanged()));
83 connect( PushDir, SIGNAL(pressed()), this, SLOT(SetDirName()));
84 connect( PushFichier, SIGNAL(pressed()), this, SLOT(SetFileName()));
86 connect( RBConforme, SIGNAL(clicked()), this, SLOT(SetConforme()));
87 connect( RBNonConforme, SIGNAL(clicked()), this, SLOT(SetNonConforme()));
88 connect( RB1NpM, SIGNAL(clicked()), this, SLOT(Set1NpM()));
89 connect( RB1NpA, SIGNAL(clicked()), this, SLOT(Set1NpA()));
90 connect( RBQuelconque, SIGNAL(clicked()), this, SLOT(SetQuelconque()));
92 connect( CBBoundaryD, SIGNAL(stateChanged(int)), this, SLOT(SetBoundaryD()));
93 connect( PBBoundaryDiNew, SIGNAL(pressed()), this, SLOT(PushBoundaryDiNew()));
94 connect( PBBoundaryDiEdit, SIGNAL(pressed()), this, SLOT(PushBoundaryDiEdit()) );
95 connect( PBBoundaryDiHelp, SIGNAL(pressed()), this, SLOT(PushBoundaryDiHelp()) );
96 connect( CBBoundaryA, SIGNAL(stateChanged(int)), this, SLOT(SetBoundaryA()));
97 connect( PBBoundaryAnNew, SIGNAL(pressed()), this, SLOT(PushBoundaryAnNew()));
98 connect( PBBoundaryAnEdit, SIGNAL(pressed()), this, SLOT(PushBoundaryAnEdit()) );
99 connect( PBBoundaryAnHelp, SIGNAL(pressed()), this, SLOT(PushBoundaryAnHelp()) );
101 connect( CBAdvanced, SIGNAL(stateChanged(int)), this, SLOT(SetAdvanced()));
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 // ------------------------------------------------------------------------
364 GBTypeNoConf->setVisible(0);
370 // ------------------------------------------------------------------------
371 void MonCreateCase::SetNonConforme()
372 // ------------------------------------------------------------------------
374 GBTypeNoConf->setVisible(1);
375 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(0);
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); }
416 // ------------------------------------------------------------------------
417 void MonCreateCase::AddBoundaryDi(QString newBoundary)
418 // ------------------------------------------------------------------------
420 CBBoundaryDi->insertItem(0,newBoundary);
421 CBBoundaryDi->setCurrentIndex(0);
423 // ------------------------------------------------------------------------
424 void MonCreateCase::PushBoundaryDiNew()
425 // ------------------------------------------------------------------------
427 MonCreateBoundaryDi *BoundaryDlg = new MonCreateBoundaryDi(this, true,
428 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName, "") ;
431 // ------------------------------------------------------------------------
432 void MonCreateCase::PushBoundaryDiEdit()
433 // ------------------------------------------------------------------------
435 if (CBBoundaryDi->currentText() == QString("")) return;
436 MonEditBoundaryDi *BoundaryDlg = new MonEditBoundaryDi(this, true,
437 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName, CBBoundaryDi->currentText() ) ;
440 // ------------------------------------------------------------------------
441 void MonCreateCase::PushBoundaryDiHelp()
442 // ------------------------------------------------------------------------
444 std::string LanguageShort = myHomardGen->GetLanguageShort();
445 HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html"), QString("frontiere-discrete"), QString(LanguageShort.c_str()));
447 // ------------------------------------------------------------------------
448 void MonCreateCase::SetBoundaryA()
449 // ------------------------------------------------------------------------
451 MESSAGE("Debut de SetBoundaryA ");
452 if (CBBoundaryA->isChecked())
454 bool bOK = PushOnApply(0);
455 if (bOK) { GBBoundaryA->setVisible(1); }
456 else { GBBoundaryA->setVisible(0);
457 CBBoundaryA->setChecked(0);
458 CBBoundaryA->setCheckState(Qt::Unchecked); }
460 else { GBBoundaryA->setVisible(0); }
464 // MESSAGE("Fin de SetBoundaryA ");
466 // ------------------------------------------------------------------------
467 void MonCreateCase::AddBoundaryAn(QString newBoundary)
468 // ------------------------------------------------------------------------
470 MESSAGE("Debut de AddBoundaryAn ");
471 // Ajout d'une nouvelle colonne
472 int nbcol = TWBoundary->columnCount();
473 // MESSAGE("nbcol " << nbcol);
475 TWBoundary->setColumnCount ( nbcol ) ;
476 QTableWidgetItem *__colItem = new QTableWidgetItem();
477 __colItem->setText(QApplication::translate("CreateCase", newBoundary.toStdString().c_str(), 0, QApplication::UnicodeUTF8));
478 TWBoundary->setHorizontalHeaderItem(nbcol-1, __colItem);
479 /* TWBoundary->horizontalHeaderItem(nbcol-1)->setFlags( Qt::ItemIsSelectable|Qt::ItemIsEnabled );*/
480 // Chaque case est a cocher
481 int nbrow = TWBoundary->rowCount();
482 // MESSAGE("nbrow " << nbrow);
483 for ( int i = 0; i < nbrow; i++ )
485 TWBoundary->setItem( i, nbcol-1, new QTableWidgetItem( QString ("") ) );
486 TWBoundary->item( i, nbcol-1 )->setFlags( 0 );
487 TWBoundary->item( i, nbcol-1 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled );
488 TWBoundary->item( i, nbcol-1 )->setCheckState( Qt::Unchecked );
490 TWBoundary->resizeColumnToContents(nbcol-1);
491 // TWBoundary->resizeRowsToContents();
492 // MESSAGE("Fin de AddBoundaryAn ");
494 // ------------------------------------------------------------------------
495 void MonCreateCase::PushBoundaryAnNew()
496 // ------------------------------------------------------------------------
498 MonCreateBoundaryAn *BoundaryDlg = new MonCreateBoundaryAn(this, true,
499 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName) ;
502 // ------------------------------------------------------------------------
503 void MonCreateCase::PushBoundaryAnEdit()
504 // ------------------------------------------------------------------------
507 int nbcol = TWBoundary->columnCount();
508 for ( int i = 1; i < nbcol; i++ )
510 QTableWidgetItem *__colItem = new QTableWidgetItem();
511 __colItem = TWBoundary->horizontalHeaderItem(i);
512 nom = QString(__colItem->text()) ;
513 MESSAGE("nom "<<nom.toStdString().c_str());
514 if (nom != QString(""))
515 { MonEditBoundaryAn *BoundaryDlg = new MonEditBoundaryAn(this, true,
516 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName, nom ) ;
517 BoundaryDlg->show(); }
520 // ------------------------------------------------------------------------
521 void MonCreateCase::PushBoundaryAnHelp()
522 // ------------------------------------------------------------------------
524 std::string LanguageShort = myHomardGen->GetLanguageShort();
525 HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html"), QString("frontiere-analytique"), QString(LanguageShort.c_str()));
527 // ------------------------------------------------------------------------
528 void MonCreateCase::CaseNameChanged()
529 // ------------------------------------------------------------------------
531 if (_aCaseName != LEName->text().trimmed())
533 LEFileName->setReadOnly(false);
537 // ------------------------------------------------------------------------
538 void MonCreateCase::SetAdvanced()
539 // ------------------------------------------------------------------------
541 MESSAGE("Debut de SetAdvanced ");
542 if (CBAdvanced->isChecked()) { GBAdvancedOptions->setVisible(1); }
544 { GBAdvancedOptions->setVisible(0);
545 CBPyramid->setChecked(false);