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
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);
68 MESSAGE("Fin du constructeur de MonCreateCase");
70 // ------------------------------------------------------------------------
71 MonCreateCase::~MonCreateCase()
72 // ------------------------------------------------------------------------
74 // no need to delete child widgets, Qt does it all for us
76 // ------------------------------------------------------------------------
77 void MonCreateCase::InitConnect()
78 // ------------------------------------------------------------------------
80 connect( LEName, SIGNAL(textChanged(QString)), this, SLOT(CaseNameChanged()));
81 connect( PushDir, SIGNAL(pressed()), this, SLOT(SetDirName()));
82 connect( PushFichier, SIGNAL(pressed()), this, SLOT(SetFileName()));
84 connect( RBConforme, SIGNAL(clicked()), this, SLOT(SetConforme()));
85 connect( RBNonConforme, SIGNAL(clicked()), this, SLOT(SetNonConforme()));
86 connect( RB1NpM, SIGNAL(clicked()), this, SLOT(Set1NpM()));
87 connect( RB1NpA, SIGNAL(clicked()), this, SLOT(Set1NpA()));
88 connect( RBQuelconque, SIGNAL(clicked()), this, SLOT(SetQuelconque()));
90 connect( CBBoundaryD, SIGNAL(stateChanged(int)), this, SLOT(SetBoundaryD()));
91 connect( PBBoundaryDiNew, SIGNAL(pressed()), this, SLOT(PushBoundaryDiNew()));
92 connect( PBBoundaryDiEdit, SIGNAL(pressed()), this, SLOT(PushBoundaryDiEdit()) );
93 connect( PBBoundaryDiHelp, SIGNAL(pressed()), this, SLOT(PushBoundaryDiHelp()) );
94 connect( CBBoundaryA, SIGNAL(stateChanged(int)), this, SLOT(SetBoundaryA()));
95 connect( PBBoundaryAnNew, SIGNAL(pressed()), this, SLOT(PushBoundaryAnNew()));
96 connect( PBBoundaryAnEdit, SIGNAL(pressed()), this, SLOT(PushBoundaryAnEdit()) );
97 connect( PBBoundaryAnHelp, SIGNAL(pressed()), this, SLOT(PushBoundaryAnHelp()) );
99 connect( CBAdvanced, SIGNAL(stateChanged(int)), this, SLOT(SetAdvanced()));
101 connect( buttonOk, SIGNAL(pressed()), this, SLOT(PushOnOK()));
102 connect( buttonApply, SIGNAL(pressed()), this, SLOT(PushOnApply(0)));
103 connect( buttonCancel, SIGNAL(pressed()), this, SLOT(close()));
104 connect( buttonHelp, SIGNAL(pressed()), this, SLOT(PushOnHelp()));
106 // ------------------------------------------------------------------------
107 void MonCreateCase::InitBoundarys()
108 // ------------------------------------------------------------------------
109 // Initialisation des menus avec les frontieres deja enregistrees
111 MESSAGE("InitBoundarys");
112 // Pour les frontieres analytiques : la colonne des groupes
113 HOMARD::ListGroupType_var _listeGroupesCas = aCase->GetGroups();
114 QTableWidgetItem *__colItem = new QTableWidgetItem();
115 __colItem->setText(QApplication::translate("CreateCase", "", 0, QApplication::UnicodeUTF8));
116 TWBoundary->setHorizontalHeaderItem(0, __colItem);
117 for ( int i = 0; i < _listeGroupesCas->length(); i++ )
119 TWBoundary->insertRow(i);
120 TWBoundary->setItem( i, 0, new QTableWidgetItem(QString((_listeGroupesCas)[i]).trimmed()));
121 TWBoundary->item( i, 0 )->setFlags(Qt::ItemIsEnabled |Qt::ItemIsSelectable );
123 // Pour les frontieres discretes : la liste a saisir
124 // Pour les frontieres analytiques : les colonnes de chaque frontiere
125 HOMARD::HOMARD_Boundary_var myBoundary ;
126 HOMARD::listeBoundarys_var mesBoundarys = myHomardGen->GetAllBoundarysName();
127 // MESSAGE("Nombre de frontieres enregistrees : "<<mesBoundarys->length());
128 for (int i=0; i<mesBoundarys->length(); i++)
130 myBoundary = myHomardGen->GetBoundary(mesBoundarys[i]);
131 int type_obj = myBoundary->GetType() ;
132 if ( type_obj==0 ) { CBBoundaryDi->addItem(QString(mesBoundarys[i])); }
133 else { AddBoundaryAn(QString(mesBoundarys[i])); }
136 TWBoundary->resizeColumnsToContents();
137 TWBoundary->resizeRowsToContents();
138 TWBoundary->clearSelection();
140 // -------------------------------
141 bool MonCreateCase::PushOnApply(int option)
142 // --------------------------------
144 MESSAGE("PushOnApply");
145 QString aCaseName=LEName->text().trimmed();
146 if ( aCaseName == "" )
148 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
149 QObject::tr("HOM_CASE_NAME") );
153 QString aDirName=LEDirName->text().trimmed();
154 if (aDirName == QString(""))
156 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
157 QObject::tr("HOM_CASE_DIRECTORY_1") );
161 if ( aDirName != _aDirName)
162 { QString CaseNameDir = myHomardGen->VerifieDir( aDirName.toStdString().c_str()) ;
163 if ( ( CaseNameDir != "" ) & ( CaseNameDir != aCaseName ) )
166 texte = QObject::tr("HOM_CASE_DIRECTORY_2") + CaseNameDir ;
167 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
173 if (chdir(aDirName.toStdString().c_str()) != 0)
175 if (_chdir(aDirName.toStdString().c_str()) != 0)
178 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
179 QObject::tr("HOM_CASE_DIRECTORY_3") );
183 QString aFileName=LEFileName->text().trimmed();
184 if (aFileName ==QString(""))
186 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
187 QObject::tr("HOM_CASE_MESH") );
191 QString aMeshName = HOMARD_QT_COMMUN::LireNomMaillage(aFileName);
192 if (aMeshName == "" )
194 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
195 QObject::tr("HOM_MED_FILE_2") );
199 // On verifie qu'un groupe n'est pas associe a deux frontieres differentes
200 if (CBBoundaryA->isChecked())
202 QStringList ListeGroup ;
204 int nbcol = TWBoundary->columnCount();
205 int nbrow = TWBoundary->rowCount();
206 for ( int col=1; col< nbcol; col++)
208 for ( int row=0; row< nbrow; row++)
210 if ( TWBoundary->item( row, col )->checkState() == Qt::Checked )
213 NomGroup = QString(TWBoundary->item(row, 0)->text()) ;
214 // MESSAGE("NomGroup "<<NomGroup.toStdString().c_str());
215 for ( int nugr = 0 ; nugr<ListeGroup.size(); nugr++)
217 // MESSAGE("....... "<<ListeGroup[nugr].toStdString().c_str());
218 if ( NomGroup == ListeGroup[nugr] )
220 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
221 QObject::tr("HOM_CASE_GROUP").arg(NomGroup) );
225 ListeGroup.insert(0, NomGroup );
232 if (aCaseName != _aCaseName )
234 _aCaseName = aCaseName;
237 aCase = myHomardGen->CreateCase( \
238 CORBA::string_dup(_aCaseName.toStdString().c_str()), \
239 CORBA::string_dup(aMeshName.toStdString().c_str()), \
240 CORBA::string_dup(aFileName.toStdString().c_str()) );
242 catch( SALOME::SALOME_Exception& S_ex )
244 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
245 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
248 LEFileName->setReadOnly(true);
253 // Repertoire et type
254 aCase->SetDirName(aDirName.toStdString().c_str());
256 aCase->SetConfType(_ConfType);
258 // Menage des eventuelles frontieres deja enregistrees
259 aCase->SupprBoundaryGroup() ;
261 // Enregistrement et publication dans l'arbre d'etudes a la sortie definitive
264 if (CBBoundaryD->isChecked())
266 QString monBoundaryDiName=CBBoundaryDi->currentText();
267 if (monBoundaryDiName != "" )
269 aCase->AddBoundaryGroup(monBoundaryDiName.toStdString().c_str(), "");
272 if (CBBoundaryA->isChecked())
275 int nbcol = TWBoundary->columnCount();
276 int nbrow = TWBoundary->rowCount();
277 for ( int col=1; col< nbcol; col++)
279 for ( int row=0; row< nbrow; row++)
281 if ( TWBoundary->item( row, col )->checkState() == Qt::Checked )
284 NomGroup = QString(TWBoundary->item(row, 0)->text()) ;
285 // Nom de la frontiere
286 QTableWidgetItem *__colItem = new QTableWidgetItem();
287 __colItem = TWBoundary->horizontalHeaderItem(col);
288 aCase->AddBoundaryGroup(QString(__colItem->text()).toStdString().c_str(), NomGroup.toStdString().c_str());
297 if (CBAdvanced->isChecked())
299 // Autorisation des pyramides
300 if (CBPyramid->isChecked()) { _Pyram = 1 ; }
303 HOMARD_UTILS::updateObjBrowser();
307 // ---------------------------
308 void MonCreateCase::PushOnOK()
309 // ---------------------------
311 bool bOK = PushOnApply(1);
312 if ( bOK ) this->close();
314 //------------------------------
315 void MonCreateCase::PushOnHelp()
316 //-------------------------------
318 char* LanguageShort = myHomardGen->GetLanguageShort();
319 HOMARD_UTILS::PushOnHelp(QString("gui_create_case.html"), QString(""), QString(LanguageShort));
321 // ---------------------------------
322 void MonCreateCase::SetNewName()
323 // ------------------------------
325 HOMARD::listeCases_var MyCases = myHomardGen->GetAllCasesName();
326 int num = 0; QString aCaseName="";
327 while (aCaseName=="" )
329 aCaseName.setNum(num+1) ;
330 aCaseName.insert(0, QString("Case_")) ;
331 for ( int i=0; i<MyCases->length(); i++)
333 if ( aCaseName == QString((MyCases)[i]))
342 LEName->insert(aCaseName);
345 // ------------------------------------------------------------------------
346 void MonCreateCase::SetDirName()
347 // ------------------------------------------------------------------------
349 QString aDirName=QFileDialog::getExistingDirectory ();
350 if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
352 // ------------------------------------------------------------------------
353 void MonCreateCase::SetFileName()
354 // ------------------------------------------------------------------------
356 QString fileName0 = LEFileName->text().trimmed();
357 QString fileName = HOMARD_QT_COMMUN::PushNomFichier();
358 if (fileName.isEmpty()) fileName = fileName0 ;
359 LEFileName->setText(fileName);
361 // ------------------------------------------------------------------------
362 void MonCreateCase::SetConforme()
363 // ------------------------------------------------------------------------
365 GBTypeNoConf->setVisible(0);
369 // ------------------------------------------------------------------------
370 void MonCreateCase::SetNonConforme()
371 // ------------------------------------------------------------------------
373 GBTypeNoConf->setVisible(1);
374 RB1NpM->setChecked(true);
378 // ------------------------------------------------------------------------
379 void MonCreateCase::Set1NpM()
380 // ------------------------------------------------------------------------
384 // ------------------------------------------------------------------------
385 void MonCreateCase::Set1NpA()
386 // ------------------------------------------------------------------------
390 // ------------------------------------------------------------------------
391 void MonCreateCase::SetQuelconque()
392 // ------------------------------------------------------------------------
396 // ------------------------------------------------------------------------
397 void MonCreateCase::SetBoundaryD()
398 // ------------------------------------------------------------------------
400 MESSAGE("Debut de SetBoundaryD ");
401 if (CBBoundaryD->isChecked())
403 bool bOK = PushOnApply(0);
404 if (bOK) { GBBoundaryD->setVisible(1); }
405 else { GBBoundaryD->setVisible(0);
406 CBBoundaryD->setChecked(0);
407 CBBoundaryD->setCheckState(Qt::Unchecked); }
409 else { GBBoundaryD->setVisible(0); }
412 // ------------------------------------------------------------------------
413 void MonCreateCase::AddBoundaryDi(QString newBoundary)
414 // ------------------------------------------------------------------------
416 CBBoundaryDi->insertItem(0,newBoundary);
417 CBBoundaryDi->setCurrentIndex(0);
419 // ------------------------------------------------------------------------
420 void MonCreateCase::PushBoundaryDiNew()
421 // ------------------------------------------------------------------------
423 MonCreateBoundaryDi *BoundaryDlg = new MonCreateBoundaryDi(this, true,
424 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName, "") ;
427 // ------------------------------------------------------------------------
428 void MonCreateCase::PushBoundaryDiEdit()
429 // ------------------------------------------------------------------------
431 if (CBBoundaryDi->currentText() == QString("")) return;
432 MonEditBoundaryDi *BoundaryDlg = new MonEditBoundaryDi(this, true,
433 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName, CBBoundaryDi->currentText() ) ;
436 // ------------------------------------------------------------------------
437 void MonCreateCase::PushBoundaryDiHelp()
438 // ------------------------------------------------------------------------
440 char* LanguageShort = myHomardGen->GetLanguageShort();
441 HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html"), QString("frontiere-discrete"), QString(LanguageShort));
443 // ------------------------------------------------------------------------
444 void MonCreateCase::SetBoundaryA()
445 // ------------------------------------------------------------------------
447 MESSAGE("Debut de SetBoundaryA ");
448 if (CBBoundaryA->isChecked())
450 bool bOK = PushOnApply(0);
451 if (bOK) { GBBoundaryA->setVisible(1); }
452 else { GBBoundaryA->setVisible(0);
453 CBBoundaryA->setChecked(0);
454 CBBoundaryA->setCheckState(Qt::Unchecked); }
456 else { GBBoundaryA->setVisible(0); }
459 // MESSAGE("Fin de SetBoundaryA ");
461 // ------------------------------------------------------------------------
462 void MonCreateCase::AddBoundaryAn(QString newBoundary)
463 // ------------------------------------------------------------------------
465 MESSAGE("Debut de AddBoundaryAn ");
466 // Ajout d'une nouvelle colonne
467 int nbcol = TWBoundary->columnCount();
468 // MESSAGE("nbcol " << nbcol);
470 TWBoundary->setColumnCount ( nbcol ) ;
471 QTableWidgetItem *__colItem = new QTableWidgetItem();
472 __colItem->setText(QApplication::translate("CreateCase", newBoundary.toStdString().c_str(), 0, QApplication::UnicodeUTF8));
473 TWBoundary->setHorizontalHeaderItem(nbcol-1, __colItem);
474 /* TWBoundary->horizontalHeaderItem(nbcol-1)->setFlags( Qt::ItemIsSelectable|Qt::ItemIsEnabled );*/
475 // Chaque case est a cocher
476 int nbrow = TWBoundary->rowCount();
477 // MESSAGE("nbrow " << nbrow);
478 for ( int i = 0; i < nbrow; i++ )
480 TWBoundary->setItem( i, nbcol-1, new QTableWidgetItem( QString ("") ) );
481 TWBoundary->item( i, nbcol-1 )->setFlags( 0 );
482 TWBoundary->item( i, nbcol-1 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled );
483 TWBoundary->item( i, nbcol-1 )->setCheckState( Qt::Unchecked );
485 TWBoundary->resizeColumnToContents(nbcol-1);
486 // TWBoundary->resizeRowsToContents();
487 // MESSAGE("Fin de AddBoundaryAn ");
489 // ------------------------------------------------------------------------
490 void MonCreateCase::PushBoundaryAnNew()
491 // ------------------------------------------------------------------------
493 MonCreateBoundaryAn *BoundaryDlg = new MonCreateBoundaryAn(this, true,
494 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName) ;
497 // ------------------------------------------------------------------------
498 void MonCreateCase::PushBoundaryAnEdit()
499 // ------------------------------------------------------------------------
502 int nbcol = TWBoundary->columnCount();
503 for ( int i = 1; i < nbcol; i++ )
505 QTableWidgetItem *__colItem = new QTableWidgetItem();
506 __colItem = TWBoundary->horizontalHeaderItem(i);
507 nom = QString(__colItem->text()) ;
508 MESSAGE("nom "<<nom.toStdString().c_str());
509 if (nom != QString(""))
510 { MonEditBoundaryAn *BoundaryDlg = new MonEditBoundaryAn(this, true,
511 HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName, nom ) ;
512 BoundaryDlg->show(); }
515 // ------------------------------------------------------------------------
516 void MonCreateCase::PushBoundaryAnHelp()
517 // ------------------------------------------------------------------------
519 char* LanguageShort = myHomardGen->GetLanguageShort();
520 HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html"), QString("frontiere-analytique"), QString(LanguageShort));
522 // ------------------------------------------------------------------------
523 void MonCreateCase::CaseNameChanged()
524 // ------------------------------------------------------------------------
526 if (_aCaseName != LEName->text().trimmed())
528 LEFileName->setReadOnly(false);
532 // ------------------------------------------------------------------------
533 void MonCreateCase::SetAdvanced()
534 // ------------------------------------------------------------------------
536 MESSAGE("Debut de SetAdvanced ");
537 if (CBAdvanced->isChecked()) { GBAdvancedOptions->setVisible(1); }
539 { GBAdvancedOptions->setVisible(0);
540 CBPyramid->setChecked(false);