1 // Copyright (C) 2011-2016 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(""),
55 MESSAGE("Debut du constructeur de MonCreateCase");
56 myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen0);
62 GBBoundaryA->setVisible(0);
63 GBBoundaryD->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()));
89 connect( CBBoundaryD, SIGNAL(stateChanged(int)), this, SLOT(SetBoundaryD()));
90 connect( PBBoundaryDiNew, SIGNAL(pressed()), this, SLOT(PushBoundaryDiNew()));
91 connect( PBBoundaryDiEdit, SIGNAL(pressed()), this, SLOT(PushBoundaryDiEdit()) );
92 connect( PBBoundaryDiHelp, SIGNAL(pressed()), this, SLOT(PushBoundaryDiHelp()) );
93 connect( CBBoundaryA, SIGNAL(stateChanged(int)), this, SLOT(SetBoundaryA()));
94 connect( PBBoundaryAnNew, SIGNAL(pressed()), this, SLOT(PushBoundaryAnNew()));
95 connect( PBBoundaryAnEdit, SIGNAL(pressed()), this, SLOT(PushBoundaryAnEdit()) );
96 connect( PBBoundaryAnHelp, SIGNAL(pressed()), this, SLOT(PushBoundaryAnHelp()) );
98 connect( CBAdvanced, SIGNAL(stateChanged(int)), this, SLOT(SetAdvanced()));
99 connect( RBStandard, SIGNAL(clicked()), this, SLOT(SetStandard()));
100 connect( RBBox, SIGNAL(clicked()), this, SLOT(SetBox()));
101 connect( RBNC1NpA, SIGNAL(clicked()), this, SLOT(SetNC1NpA()));
102 connect( RBNCQuelconque, SIGNAL(clicked()), this, SLOT(SetNCQuelconque()));
104 connect( RBMED, SIGNAL(clicked()), this, SLOT(SetMED()));
105 connect( RBSaturne2D, SIGNAL(clicked()), this, SLOT(SetSaturne2D()));
107 connect( buttonOk, SIGNAL(pressed()), this, SLOT(PushOnOK()));
108 connect( buttonApply, SIGNAL(pressed()), this, SLOT(PushOnApply(0)));
109 connect( buttonCancel, SIGNAL(pressed()), this, SLOT(close()));
110 connect( buttonHelp, SIGNAL(pressed()), this, SLOT(PushOnHelp()));
112 // ------------------------------------------------------------------------
113 void MonCreateCase::InitBoundarys()
114 // ------------------------------------------------------------------------
115 // Initialisation des menus avec les frontieres deja enregistrees
117 MESSAGE("InitBoundarys");
118 // Pour les frontieres analytiques : la colonne des groupes
119 HOMARD::ListGroupType_var _listeGroupesCas = aCase->GetGroups();
120 QTableWidgetItem *__colItem = new QTableWidgetItem();
121 __colItem->setText(QApplication::translate("CreateCase", "", 0));
122 TWBoundary->setHorizontalHeaderItem(0, __colItem);
123 for ( int i = 0; i < _listeGroupesCas->length(); i++ )
125 TWBoundary->insertRow(i);
126 TWBoundary->setItem( i, 0, new QTableWidgetItem(QString((_listeGroupesCas)[i]).trimmed()));
127 TWBoundary->item( i, 0 )->setFlags(Qt::ItemIsEnabled |Qt::ItemIsSelectable );
129 // Pour les frontieres discretes : la liste a saisir
130 // Pour les frontieres analytiques : les colonnes de chaque frontiere
131 HOMARD::HOMARD_Boundary_var myBoundary ;
132 HOMARD::listeBoundarys_var mesBoundarys = myHomardGen->GetAllBoundarysName();
133 // MESSAGE("Nombre de frontieres enregistrees : "<<mesBoundarys->length());
134 for (int i=0; i<mesBoundarys->length(); i++)
136 myBoundary = myHomardGen->GetBoundary(mesBoundarys[i]);
137 int type_obj = myBoundary->GetType() ;
138 if ( type_obj==0 ) { CBBoundaryDi->addItem(QString(mesBoundarys[i])); }
139 else { AddBoundaryAn(QString(mesBoundarys[i])); }
142 TWBoundary->resizeColumnsToContents();
143 TWBoundary->resizeRowsToContents();
144 TWBoundary->clearSelection();
146 // -------------------------------
147 bool MonCreateCase::PushOnApply(int option)
148 // --------------------------------
150 MESSAGE("PushOnApply");
151 QString aCaseName=LEName->text().trimmed();
152 if ( aCaseName == "" )
154 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
155 QObject::tr("HOM_CASE_NAME") );
159 QString aDirName=LEDirName->text().trimmed();
160 if (aDirName == QString(""))
162 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
163 QObject::tr("HOM_CASE_DIRECTORY_1") );
167 if ( aDirName != _aDirName)
168 { QString CaseNameDir = myHomardGen->VerifieDir( aDirName.toStdString().c_str()) ;
169 if ( ( CaseNameDir != "" ) & ( CaseNameDir != aCaseName ) )
172 texte = QObject::tr("HOM_CASE_DIRECTORY_2") + CaseNameDir ;
173 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
178 if (CHDIR(aDirName.toStdString().c_str()) != 0)
180 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
181 QObject::tr("HOM_CASE_DIRECTORY_3") );
185 QString aFileName=LEFileName->text().trimmed();
186 if (aFileName ==QString(""))
188 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
189 QObject::tr("HOM_CASE_MESH") );
193 QString aMeshName = HOMARD_QT_COMMUN::LireNomMaillage(aFileName);
194 if (aMeshName == "" )
196 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
197 QObject::tr("HOM_MED_FILE_2") );
201 // On verifie qu'un groupe n'est pas associe a deux frontieres differentes
202 if (CBBoundaryA->isChecked())
204 QStringList ListeGroup ;
206 int nbcol = TWBoundary->columnCount();
207 int nbrow = TWBoundary->rowCount();
208 for ( int col=1; col< nbcol; col++)
210 for ( int row=0; row< nbrow; row++)
212 if ( TWBoundary->item( row, col )->checkState() == Qt::Checked )
215 NomGroup = QString(TWBoundary->item(row, 0)->text()) ;
216 // MESSAGE("NomGroup "<<NomGroup.toStdString().c_str());
217 for ( int nugr = 0 ; nugr<ListeGroup.size(); nugr++)
219 // MESSAGE("....... "<<ListeGroup[nugr].toStdString().c_str());
220 if ( NomGroup == ListeGroup[nugr] )
222 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
223 QObject::tr("HOM_CASE_GROUP").arg(NomGroup) );
227 ListeGroup.insert(0, NomGroup );
234 if (aCaseName != _aCaseName )
236 _aCaseName = aCaseName;
239 aCase = myHomardGen->CreateCase( \
240 CORBA::string_dup(_aCaseName.toStdString().c_str()), \
241 CORBA::string_dup(aMeshName.toStdString().c_str()), \
242 CORBA::string_dup(aFileName.toStdString().c_str()) );
244 catch( SALOME::SALOME_Exception& S_ex )
246 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
247 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
250 LEFileName->setReadOnly(true);
255 // Repertoire et type
256 aCase->SetDirName(aDirName.toStdString().c_str());
258 aCase->SetConfType(_ConfType);
259 aCase->SetExtType(_ExtType);
261 // Menage des eventuelles frontieres deja enregistrees
262 aCase->SupprBoundaryGroup() ;
264 // Enregistrement et publication dans l'arbre d'etudes a la sortie definitive
267 if (CBBoundaryD->isChecked())
269 QString monBoundaryDiName=CBBoundaryDi->currentText();
270 if (monBoundaryDiName != "" )
272 aCase->AddBoundaryGroup(monBoundaryDiName.toStdString().c_str(), "");
275 if (CBBoundaryA->isChecked())
278 int nbcol = TWBoundary->columnCount();
279 int nbrow = TWBoundary->rowCount();
280 for ( int col=1; col< nbcol; col++)
282 for ( int row=0; row< nbrow; row++)
284 if ( TWBoundary->item( row, col )->checkState() == Qt::Checked )
287 NomGroup = QString(TWBoundary->item(row, 0)->text()) ;
288 // Nom de la frontiere
289 QTableWidgetItem *__colItem = new QTableWidgetItem();
290 __colItem = TWBoundary->horizontalHeaderItem(col);
291 aCase->AddBoundaryGroup(QString(__colItem->text()).toStdString().c_str(), NomGroup.toStdString().c_str());
300 if (CBAdvanced->isChecked())
302 // Autorisation des pyramides
303 if (CBPyramid->isChecked()) { _Pyram = 1 ; }
305 aCase->SetPyram(_Pyram);
307 HOMARD_UTILS::updateObjBrowser();
311 // ---------------------------
312 void MonCreateCase::PushOnOK()
313 // ---------------------------
315 bool bOK = PushOnApply(1);
316 if ( bOK ) this->close();
318 //------------------------------
319 void MonCreateCase::PushOnHelp()
320 //-------------------------------
322 std::string LanguageShort = myHomardGen->GetLanguageShort();
323 HOMARD_UTILS::PushOnHelp(QString("gui_create_case.html"), QString(""), QString(LanguageShort.c_str()));
325 // ---------------------------------
326 void MonCreateCase::SetNewName()
327 // ------------------------------
329 HOMARD::listeCases_var MyCases = myHomardGen->GetAllCasesName();
330 int num = 0; QString aCaseName="";
331 while (aCaseName=="" )
333 aCaseName.setNum(num+1) ;
334 aCaseName.insert(0, QString("Case_")) ;
335 for ( int i=0; i<MyCases->length(); i++)
337 if ( aCaseName == QString((MyCases)[i]))
346 LEName->insert(aCaseName);
349 // ------------------------------------------------------------------------
350 void MonCreateCase::SetDirName()
351 // ------------------------------------------------------------------------
353 QString aDirName=QFileDialog::getExistingDirectory ();
354 if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
356 // ------------------------------------------------------------------------
357 void MonCreateCase::SetFileName()
358 // ------------------------------------------------------------------------
360 QString fileName0 = LEFileName->text().trimmed();
361 QString fileName = HOMARD_QT_COMMUN::PushNomFichier( false, QString("med") ) ;
362 if (fileName.isEmpty()) fileName = fileName0 ;
363 LEFileName->setText(fileName);
365 // ------------------------------------------------------------------------
366 void MonCreateCase::SetConforme()
367 // ------------------------------------------------------------------------
371 RBNC1NpA->setVisible(0);
372 RBNCQuelconque->setVisible(0);
376 // ------------------------------------------------------------------------
377 void MonCreateCase::SetNonConforme()
378 // ------------------------------------------------------------------------
382 RBNC1NpA->setVisible(1);
383 RBNCQuelconque->setVisible(1);
387 // ------------------------------------------------------------------------
388 void MonCreateCase::SetStandard()
389 // ------------------------------------------------------------------------
391 if ( ( _ConfType == 0 ) || ( _ConfType == -1 ) ) { _ConfType = 0 ; }
392 else { _ConfType = 1 ; }
393 RBStandard->setChecked(true);
395 // ------------------------------------------------------------------------
396 void MonCreateCase::SetBox()
397 // ------------------------------------------------------------------------
399 if ( ( _ConfType == 0 ) || ( _ConfType == -1 ) ) { _ConfType = -1 ; }
400 else { _ConfType = -2 ; }
402 // ------------------------------------------------------------------------
403 void MonCreateCase::SetNC1NpA()
404 // ------------------------------------------------------------------------
408 // ------------------------------------------------------------------------
409 void MonCreateCase::SetNCQuelconque()
410 // ------------------------------------------------------------------------
414 // ------------------------------------------------------------------------
415 void MonCreateCase::SetMED()
416 // ------------------------------------------------------------------------
419 RBMED->setChecked(true);
421 // ------------------------------------------------------------------------
422 void MonCreateCase::SetSaturne2D()
423 // ------------------------------------------------------------------------
426 RBSaturne2D->setChecked(true);
428 // ------------------------------------------------------------------------
429 void MonCreateCase::SetBoundaryD()
430 // ------------------------------------------------------------------------
432 MESSAGE("Debut de SetBoundaryD ");
433 if (CBBoundaryD->isChecked())
435 bool bOK = PushOnApply(0);
436 if (bOK) { GBBoundaryD->setVisible(1); }
437 else { GBBoundaryD->setVisible(0);
438 CBBoundaryD->setChecked(0);
439 CBBoundaryD->setCheckState(Qt::Unchecked); }
441 else { GBBoundaryD->setVisible(0); }
445 // ------------------------------------------------------------------------
446 void MonCreateCase::AddBoundaryDi(QString newBoundary)
447 // ------------------------------------------------------------------------
449 CBBoundaryDi->insertItem(0,newBoundary);
450 CBBoundaryDi->setCurrentIndex(0);
452 // ------------------------------------------------------------------------
453 void MonCreateCase::PushBoundaryDiNew()
454 // ------------------------------------------------------------------------
456 MonCreateBoundaryDi *BoundaryDlg = new MonCreateBoundaryDi(this, true,
457 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName, "") ;
460 // ------------------------------------------------------------------------
461 void MonCreateCase::PushBoundaryDiEdit()
462 // ------------------------------------------------------------------------
464 if (CBBoundaryDi->currentText() == QString("")) return;
465 MonEditBoundaryDi *BoundaryDlg = new MonEditBoundaryDi(this, true,
466 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName, CBBoundaryDi->currentText() ) ;
469 // ------------------------------------------------------------------------
470 void MonCreateCase::PushBoundaryDiHelp()
471 // ------------------------------------------------------------------------
473 std::string LanguageShort = myHomardGen->GetLanguageShort();
474 HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html"), QString("frontiere-discrete"), QString(LanguageShort.c_str()));
476 // ------------------------------------------------------------------------
477 void MonCreateCase::SetBoundaryA()
478 // ------------------------------------------------------------------------
480 MESSAGE("Debut de SetBoundaryA ");
481 if (CBBoundaryA->isChecked())
483 bool bOK = PushOnApply(0);
484 if (bOK) { GBBoundaryA->setVisible(1); }
485 else { GBBoundaryA->setVisible(0);
486 CBBoundaryA->setChecked(0);
487 CBBoundaryA->setCheckState(Qt::Unchecked); }
489 else { GBBoundaryA->setVisible(0); }
493 // MESSAGE("Fin de SetBoundaryA ");
495 // ------------------------------------------------------------------------
496 void MonCreateCase::AddBoundaryAn(QString newBoundary)
497 // ------------------------------------------------------------------------
499 MESSAGE("Debut de AddBoundaryAn ");
500 // Ajout d'une nouvelle colonne
501 int nbcol = TWBoundary->columnCount();
502 // MESSAGE("nbcol " << nbcol);
504 TWBoundary->setColumnCount ( nbcol ) ;
505 QTableWidgetItem *__colItem = new QTableWidgetItem();
506 __colItem->setText(QApplication::translate("CreateCase", newBoundary.toStdString().c_str(), 0));
507 TWBoundary->setHorizontalHeaderItem(nbcol-1, __colItem);
508 /* TWBoundary->horizontalHeaderItem(nbcol-1)->setFlags( Qt::ItemIsSelectable|Qt::ItemIsEnabled );*/
509 // Chaque case est a cocher
510 int nbrow = TWBoundary->rowCount();
511 // MESSAGE("nbrow " << nbrow);
512 for ( int i = 0; i < nbrow; i++ )
514 TWBoundary->setItem( i, nbcol-1, new QTableWidgetItem( QString ("") ) );
515 TWBoundary->item( i, nbcol-1 )->setFlags( 0 );
516 TWBoundary->item( i, nbcol-1 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled );
517 TWBoundary->item( i, nbcol-1 )->setCheckState( Qt::Unchecked );
519 TWBoundary->resizeColumnToContents(nbcol-1);
520 // TWBoundary->resizeRowsToContents();
521 // MESSAGE("Fin de AddBoundaryAn ");
523 // ------------------------------------------------------------------------
524 void MonCreateCase::PushBoundaryAnNew()
525 // ------------------------------------------------------------------------
527 MonCreateBoundaryAn *BoundaryDlg = new MonCreateBoundaryAn(this, true,
528 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName) ;
531 // ------------------------------------------------------------------------
532 void MonCreateCase::PushBoundaryAnEdit()
533 // ------------------------------------------------------------------------
536 int nbcol = TWBoundary->columnCount();
537 for ( int i = 1; i < nbcol; i++ )
539 QTableWidgetItem *__colItem = new QTableWidgetItem();
540 __colItem = TWBoundary->horizontalHeaderItem(i);
541 nom = QString(__colItem->text()) ;
542 MESSAGE("nom "<<nom.toStdString().c_str());
543 if (nom != QString(""))
544 { MonEditBoundaryAn *BoundaryDlg = new MonEditBoundaryAn(this, true,
545 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName, nom ) ;
546 BoundaryDlg->show(); }
549 // ------------------------------------------------------------------------
550 void MonCreateCase::PushBoundaryAnHelp()
551 // ------------------------------------------------------------------------
553 std::string LanguageShort = myHomardGen->GetLanguageShort();
554 HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html"), QString("frontiere-analytique"), QString(LanguageShort.c_str()));
556 // ------------------------------------------------------------------------
557 void MonCreateCase::CaseNameChanged()
558 // ------------------------------------------------------------------------
560 if (_aCaseName != LEName->text().trimmed())
562 LEFileName->setReadOnly(false);
566 // ------------------------------------------------------------------------
567 void MonCreateCase::SetAdvanced()
568 // ------------------------------------------------------------------------
570 MESSAGE("Debut de SetAdvanced ");
571 if (CBAdvanced->isChecked())
572 { GBAdvancedOptions->setVisible(1);
573 GBConforme->setVisible(1);
574 RBStandard->setVisible(1);
575 RBBox->setVisible(1);
576 if ( ( _ConfType == 0 ) || ( _ConfType == -1 ) )
577 { RBNC1NpA->setVisible(0);
578 RBNCQuelconque->setVisible(0);}
580 { RBNC1NpA->setVisible(1);
581 RBNCQuelconque->setVisible(1);}
582 GBFormat->setVisible(1);
583 RBMED->setVisible(1);
584 RBSaturne2D->setVisible(1);
587 { GBAdvancedOptions->setVisible(0);
588 CBPyramid->setChecked(false);