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( RBSaturne, SIGNAL(clicked()), this, SLOT(SetSaturne()));
106 connect( RBSaturne2D, SIGNAL(clicked()), this, SLOT(SetSaturne2D()));
108 connect( buttonOk, SIGNAL(pressed()), this, SLOT(PushOnOK()));
109 connect( buttonApply, SIGNAL(pressed()), this, SLOT(PushOnApply(0)));
110 connect( buttonCancel, SIGNAL(pressed()), this, SLOT(close()));
111 connect( buttonHelp, SIGNAL(pressed()), this, SLOT(PushOnHelp()));
113 // ------------------------------------------------------------------------
114 void MonCreateCase::InitBoundarys()
115 // ------------------------------------------------------------------------
116 // Initialisation des menus avec les frontieres deja enregistrees
118 MESSAGE("InitBoundarys");
119 // Pour les frontieres analytiques : la colonne des groupes
120 HOMARD::ListGroupType_var _listeGroupesCas = aCase->GetGroups();
121 QTableWidgetItem *__colItem = new QTableWidgetItem();
122 __colItem->setText(QApplication::translate("CreateCase", "", 0));
123 TWBoundary->setHorizontalHeaderItem(0, __colItem);
124 for ( int i = 0; i < _listeGroupesCas->length(); i++ )
126 TWBoundary->insertRow(i);
127 TWBoundary->setItem( i, 0, new QTableWidgetItem(QString((_listeGroupesCas)[i]).trimmed()));
128 TWBoundary->item( i, 0 )->setFlags(Qt::ItemIsEnabled |Qt::ItemIsSelectable );
130 // Pour les frontieres discretes : la liste a saisir
131 // Pour les frontieres analytiques : les colonnes de chaque frontiere
132 HOMARD::HOMARD_Boundary_var myBoundary ;
133 HOMARD::listeBoundarys_var mesBoundarys = myHomardGen->GetAllBoundarysName();
134 // MESSAGE("Nombre de frontieres enregistrees : "<<mesBoundarys->length());
135 for (int i=0; i<mesBoundarys->length(); i++)
137 myBoundary = myHomardGen->GetBoundary(mesBoundarys[i]);
138 int type_obj = myBoundary->GetType() ;
139 if ( type_obj==0 ) { CBBoundaryDi->addItem(QString(mesBoundarys[i])); }
140 else { AddBoundaryAn(QString(mesBoundarys[i])); }
143 TWBoundary->resizeColumnsToContents();
144 TWBoundary->resizeRowsToContents();
145 TWBoundary->clearSelection();
147 // -------------------------------
148 bool MonCreateCase::PushOnApply(int option)
149 // --------------------------------
151 MESSAGE("PushOnApply");
152 QString aCaseName=LEName->text().trimmed();
153 if ( aCaseName == "" )
155 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
156 QObject::tr("HOM_CASE_NAME") );
160 QString aDirName=LEDirName->text().trimmed();
161 if (aDirName == QString(""))
163 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
164 QObject::tr("HOM_CASE_DIRECTORY_1") );
168 if ( aDirName != _aDirName)
169 { QString CaseNameDir = myHomardGen->VerifieDir( aDirName.toStdString().c_str()) ;
170 if ( ( CaseNameDir != "" ) & ( CaseNameDir != aCaseName ) )
173 texte = QObject::tr("HOM_CASE_DIRECTORY_2") + CaseNameDir ;
174 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
179 if (CHDIR(aDirName.toStdString().c_str()) != 0)
181 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
182 QObject::tr("HOM_CASE_DIRECTORY_3") );
186 QString aFileName=LEFileName->text().trimmed();
187 if (aFileName ==QString(""))
189 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
190 QObject::tr("HOM_CASE_MESH") );
194 QString aMeshName = HOMARD_QT_COMMUN::LireNomMaillage(aFileName);
195 if (aMeshName == "" )
197 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
198 QObject::tr("HOM_MED_FILE_2") );
202 // On verifie qu'un groupe n'est pas associe a deux frontieres differentes
203 if (CBBoundaryA->isChecked())
205 QStringList ListeGroup ;
207 int nbcol = TWBoundary->columnCount();
208 int nbrow = TWBoundary->rowCount();
209 for ( int col=1; col< nbcol; col++)
211 for ( int row=0; row< nbrow; row++)
213 if ( TWBoundary->item( row, col )->checkState() == Qt::Checked )
216 NomGroup = QString(TWBoundary->item(row, 0)->text()) ;
217 // MESSAGE("NomGroup "<<NomGroup.toStdString().c_str());
218 for ( int nugr = 0 ; nugr<ListeGroup.size(); nugr++)
220 // MESSAGE("....... "<<ListeGroup[nugr].toStdString().c_str());
221 if ( NomGroup == ListeGroup[nugr] )
223 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
224 QObject::tr("HOM_CASE_GROUP").arg(NomGroup) );
228 ListeGroup.insert(0, NomGroup );
235 if (aCaseName != _aCaseName )
237 _aCaseName = aCaseName;
240 aCase = myHomardGen->CreateCase( \
241 CORBA::string_dup(_aCaseName.toStdString().c_str()), \
242 CORBA::string_dup(aMeshName.toStdString().c_str()), \
243 CORBA::string_dup(aFileName.toStdString().c_str()) );
245 catch( SALOME::SALOME_Exception& S_ex )
247 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
248 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
251 LEFileName->setReadOnly(true);
256 // Repertoire et type
257 aCase->SetDirName(aDirName.toStdString().c_str());
259 aCase->SetConfType(_ConfType);
260 aCase->SetExtType(_ExtType);
262 // Menage des eventuelles frontieres deja enregistrees
263 aCase->SupprBoundaryGroup() ;
265 // Enregistrement et publication dans l'arbre d'etudes a la sortie definitive
268 if (CBBoundaryD->isChecked())
270 QString monBoundaryDiName=CBBoundaryDi->currentText();
271 if (monBoundaryDiName != "" )
273 aCase->AddBoundaryGroup(monBoundaryDiName.toStdString().c_str(), "");
276 if (CBBoundaryA->isChecked())
279 int nbcol = TWBoundary->columnCount();
280 int nbrow = TWBoundary->rowCount();
281 for ( int col=1; col< nbcol; col++)
283 for ( int row=0; row< nbrow; row++)
285 if ( TWBoundary->item( row, col )->checkState() == Qt::Checked )
288 NomGroup = QString(TWBoundary->item(row, 0)->text()) ;
289 // Nom de la frontiere
290 QTableWidgetItem *__colItem = new QTableWidgetItem();
291 __colItem = TWBoundary->horizontalHeaderItem(col);
292 aCase->AddBoundaryGroup(QString(__colItem->text()).toStdString().c_str(), NomGroup.toStdString().c_str());
301 if (CBAdvanced->isChecked())
303 // Autorisation des pyramides
304 if (CBPyramid->isChecked()) { _Pyram = 1 ; }
306 aCase->SetPyram(_Pyram);
308 HOMARD_UTILS::updateObjBrowser();
312 // ---------------------------
313 void MonCreateCase::PushOnOK()
314 // ---------------------------
316 bool bOK = PushOnApply(1);
317 if ( bOK ) this->close();
319 //------------------------------
320 void MonCreateCase::PushOnHelp()
321 //-------------------------------
323 std::string LanguageShort = myHomardGen->GetLanguageShort();
324 HOMARD_UTILS::PushOnHelp(QString("gui_create_case.html"), QString(""), QString(LanguageShort.c_str()));
326 // ---------------------------------
327 void MonCreateCase::SetNewName()
328 // ------------------------------
330 HOMARD::listeCases_var MyCases = myHomardGen->GetAllCasesName();
331 int num = 0; QString aCaseName="";
332 while (aCaseName=="" )
334 aCaseName.setNum(num+1) ;
335 aCaseName.insert(0, QString("Case_")) ;
336 for ( int i=0; i<MyCases->length(); i++)
338 if ( aCaseName == QString((MyCases)[i]))
347 LEName->insert(aCaseName);
350 // ------------------------------------------------------------------------
351 void MonCreateCase::SetDirName()
352 // ------------------------------------------------------------------------
354 QString aDirName=QFileDialog::getExistingDirectory ();
355 if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
357 // ------------------------------------------------------------------------
358 void MonCreateCase::SetFileName()
359 // ------------------------------------------------------------------------
361 QString fileName0 = LEFileName->text().trimmed();
362 QString fileName = HOMARD_QT_COMMUN::PushNomFichier( false, QString("med") ) ;
363 if (fileName.isEmpty()) fileName = fileName0 ;
364 LEFileName->setText(fileName);
366 // ------------------------------------------------------------------------
367 void MonCreateCase::SetConforme()
368 // ------------------------------------------------------------------------
372 RBNC1NpA->setVisible(0);
373 RBNCQuelconque->setVisible(0);
377 // ------------------------------------------------------------------------
378 void MonCreateCase::SetNonConforme()
379 // ------------------------------------------------------------------------
383 RBNC1NpA->setVisible(1);
384 RBNCQuelconque->setVisible(1);
388 // ------------------------------------------------------------------------
389 void MonCreateCase::SetStandard()
390 // ------------------------------------------------------------------------
392 if ( ( _ConfType == 0 ) || ( _ConfType == -1 ) ) { _ConfType = 0 ; }
393 else { _ConfType = 1 ; }
394 RBStandard->setChecked(true);
396 // ------------------------------------------------------------------------
397 void MonCreateCase::SetBox()
398 // ------------------------------------------------------------------------
400 if ( ( _ConfType == 0 ) || ( _ConfType == -1 ) ) { _ConfType = -1 ; }
401 else { _ConfType = -2 ; }
403 // ------------------------------------------------------------------------
404 void MonCreateCase::SetNC1NpA()
405 // ------------------------------------------------------------------------
409 // ------------------------------------------------------------------------
410 void MonCreateCase::SetNCQuelconque()
411 // ------------------------------------------------------------------------
415 // ------------------------------------------------------------------------
416 void MonCreateCase::SetMED()
417 // ------------------------------------------------------------------------
420 RBMED->setChecked(true);
422 // ------------------------------------------------------------------------
423 void MonCreateCase::SetSaturne()
424 // ------------------------------------------------------------------------
427 RBSaturne->setChecked(true);
429 // ------------------------------------------------------------------------
430 void MonCreateCase::SetSaturne2D()
431 // ------------------------------------------------------------------------
434 RBSaturne2D->setChecked(true);
436 // ------------------------------------------------------------------------
437 void MonCreateCase::SetBoundaryD()
438 // ------------------------------------------------------------------------
440 MESSAGE("Debut de SetBoundaryD ");
441 if (CBBoundaryD->isChecked())
443 bool bOK = PushOnApply(0);
444 if (bOK) { GBBoundaryD->setVisible(1); }
445 else { GBBoundaryD->setVisible(0);
446 CBBoundaryD->setChecked(0);
447 CBBoundaryD->setCheckState(Qt::Unchecked); }
449 else { GBBoundaryD->setVisible(0); }
453 // ------------------------------------------------------------------------
454 void MonCreateCase::AddBoundaryDi(QString newBoundary)
455 // ------------------------------------------------------------------------
457 CBBoundaryDi->insertItem(0,newBoundary);
458 CBBoundaryDi->setCurrentIndex(0);
460 // ------------------------------------------------------------------------
461 void MonCreateCase::PushBoundaryDiNew()
462 // ------------------------------------------------------------------------
464 MonCreateBoundaryDi *BoundaryDlg = new MonCreateBoundaryDi(this, true,
465 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName, "") ;
468 // ------------------------------------------------------------------------
469 void MonCreateCase::PushBoundaryDiEdit()
470 // ------------------------------------------------------------------------
472 if (CBBoundaryDi->currentText() == QString("")) return;
473 MonEditBoundaryDi *BoundaryDlg = new MonEditBoundaryDi(this, true,
474 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName, CBBoundaryDi->currentText() ) ;
477 // ------------------------------------------------------------------------
478 void MonCreateCase::PushBoundaryDiHelp()
479 // ------------------------------------------------------------------------
481 std::string LanguageShort = myHomardGen->GetLanguageShort();
482 HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html"), QString("frontiere-discrete"), QString(LanguageShort.c_str()));
484 // ------------------------------------------------------------------------
485 void MonCreateCase::SetBoundaryA()
486 // ------------------------------------------------------------------------
488 MESSAGE("Debut de SetBoundaryA ");
489 if (CBBoundaryA->isChecked())
491 bool bOK = PushOnApply(0);
492 if (bOK) { GBBoundaryA->setVisible(1); }
493 else { GBBoundaryA->setVisible(0);
494 CBBoundaryA->setChecked(0);
495 CBBoundaryA->setCheckState(Qt::Unchecked); }
497 else { GBBoundaryA->setVisible(0); }
501 // MESSAGE("Fin de SetBoundaryA ");
503 // ------------------------------------------------------------------------
504 void MonCreateCase::AddBoundaryAn(QString newBoundary)
505 // ------------------------------------------------------------------------
507 MESSAGE("Debut de AddBoundaryAn ");
508 // Ajout d'une nouvelle colonne
509 int nbcol = TWBoundary->columnCount();
510 // MESSAGE("nbcol " << nbcol);
512 TWBoundary->setColumnCount ( nbcol ) ;
513 QTableWidgetItem *__colItem = new QTableWidgetItem();
514 __colItem->setText(QApplication::translate("CreateCase", newBoundary.toStdString().c_str(), 0));
515 TWBoundary->setHorizontalHeaderItem(nbcol-1, __colItem);
516 /* TWBoundary->horizontalHeaderItem(nbcol-1)->setFlags( Qt::ItemIsSelectable|Qt::ItemIsEnabled );*/
517 // Chaque case est a cocher
518 int nbrow = TWBoundary->rowCount();
519 // MESSAGE("nbrow " << nbrow);
520 for ( int i = 0; i < nbrow; i++ )
522 TWBoundary->setItem( i, nbcol-1, new QTableWidgetItem( QString ("") ) );
523 TWBoundary->item( i, nbcol-1 )->setFlags( 0 );
524 TWBoundary->item( i, nbcol-1 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled );
525 TWBoundary->item( i, nbcol-1 )->setCheckState( Qt::Unchecked );
527 TWBoundary->resizeColumnToContents(nbcol-1);
528 // TWBoundary->resizeRowsToContents();
529 // MESSAGE("Fin de AddBoundaryAn ");
531 // ------------------------------------------------------------------------
532 void MonCreateCase::PushBoundaryAnNew()
533 // ------------------------------------------------------------------------
535 MonCreateBoundaryAn *BoundaryDlg = new MonCreateBoundaryAn(this, true,
536 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName) ;
539 // ------------------------------------------------------------------------
540 void MonCreateCase::PushBoundaryAnEdit()
541 // ------------------------------------------------------------------------
544 int nbcol = TWBoundary->columnCount();
545 for ( int i = 1; i < nbcol; i++ )
547 QTableWidgetItem *__colItem = new QTableWidgetItem();
548 __colItem = TWBoundary->horizontalHeaderItem(i);
549 nom = QString(__colItem->text()) ;
550 MESSAGE("nom "<<nom.toStdString().c_str());
551 if (nom != QString(""))
552 { MonEditBoundaryAn *BoundaryDlg = new MonEditBoundaryAn(this, true,
553 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName, nom ) ;
554 BoundaryDlg->show(); }
557 // ------------------------------------------------------------------------
558 void MonCreateCase::PushBoundaryAnHelp()
559 // ------------------------------------------------------------------------
561 std::string LanguageShort = myHomardGen->GetLanguageShort();
562 HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html"), QString("frontiere-analytique"), QString(LanguageShort.c_str()));
564 // ------------------------------------------------------------------------
565 void MonCreateCase::CaseNameChanged()
566 // ------------------------------------------------------------------------
568 if (_aCaseName != LEName->text().trimmed())
570 LEFileName->setReadOnly(false);
574 // ------------------------------------------------------------------------
575 void MonCreateCase::SetAdvanced()
576 // ------------------------------------------------------------------------
578 MESSAGE("Debut de SetAdvanced ");
579 if (CBAdvanced->isChecked())
580 { GBAdvancedOptions->setVisible(1);
581 GBConforme->setVisible(1);
582 RBStandard->setVisible(1);
583 RBBox->setVisible(1);
584 if ( ( _ConfType == 0 ) || ( _ConfType == -1 ) )
585 { RBNC1NpA->setVisible(0);
586 RBNCQuelconque->setVisible(0);}
588 { RBNC1NpA->setVisible(1);
589 RBNCQuelconque->setVisible(1);}
590 GBFormat->setVisible(1);
591 RBMED->setVisible(1);
592 RBSaturne2D->setVisible(1);
595 { GBAdvancedOptions->setVisible(0);
596 CBPyramid->setChecked(false);