1 // Copyright (C) 2011-2020 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 "MonCreateBoundaryDi.h"
21 #include "MonCreateListGroup.h"
22 #include "MonCreateCase.h"
24 #include <QFileDialog>
25 #include <QMessageBox>
27 #include "SalomeApp_Tools.h"
28 #include "HOMARDGUI_Utils.h"
29 #include "HomardQtCommun.h"
30 #include <utilities.h>
34 // -------------------------------------------------------------------------------
35 MonCreateBoundaryDi::MonCreateBoundaryDi(MonCreateCase* parent, bool modal,
36 ADAPT::ADAPT_Gen_var myHomardGen0,
37 QString caseName, QString aName)
38 // ---------------------------------------------------------------------------------
39 /* Constructs a MonCreateBoundaryDi */
41 QDialog(0), Ui_CreateBoundaryDi(),
42 _parent(parent), _aName(aName),
43 myHomardGen(ADAPT::ADAPT_Gen::_duplicate(myHomardGen0)),
46 MESSAGE("Constructeur") ;
51 if ( _aName == QString("") ) {SetNewName();};
54 // ------------------------------------------------------------------------
55 MonCreateBoundaryDi::~MonCreateBoundaryDi()
56 // ------------------------------------------------------------------------
58 // no need to delete child widgets, Qt does it all for us
60 // ------------------------------------------------------------------------
61 void MonCreateBoundaryDi::InitConnect()
62 // ------------------------------------------------------------------------
64 connect( PushFichier, SIGNAL(pressed()), this, SLOT(SetMeshFile()));
65 connect( buttonOk, SIGNAL(pressed()), this, SLOT( PushOnOK()));
66 connect( buttonApply, SIGNAL(pressed()), this, SLOT( PushOnApply()));
67 connect( buttonCancel, SIGNAL(pressed()), this, SLOT(close()));
68 connect( buttonHelp, SIGNAL(pressed()), this, SLOT( PushOnHelp()));
69 connect( CBGroupe, SIGNAL(stateChanged(int)), this, SLOT( SetFiltrage()));
72 // ------------------------------------------------------------------------
73 bool MonCreateBoundaryDi::PushOnApply()
74 // ------------------------------------------------------------------------
75 // Appele lorsque l'un des boutons Ok ou Apply est presse
80 QString aName=LEName->text().trimmed();
82 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
83 QObject::tr("HOM_BOUN_NAME") );
87 // Le maillage de la frontiere discrete
88 QString aMeshFile=LEFileName->text().trimmed();
89 if (aMeshFile ==QString(""))
91 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
92 QObject::tr("HOM_BOUN_MESH") );
96 // Le nom du maillage de la frontiere discrete
97 QString aMeshName = HOMARD_QT_COMMUN::LireNomMaillage(aMeshFile);
100 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
101 QObject::tr("HOM_MED_FILE_2") );
105 // Creation de l'objet CORBA si ce n'est pas deja fait sous le meme nom
106 if ( _aName != aName )
111 aBoundary=myHomardGen->CreateBoundaryDi(CORBA::string_dup(_aName.toStdString().c_str()), aMeshName.toStdString().c_str(), aMeshFile.toStdString().c_str());
112 _parent->AddBoundaryDi(_aName);
113 aBoundary->SetCaseCreation(_aCaseName.toStdString().c_str());
115 catch( SALOME::SALOME_Exception& S_ex )
117 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
118 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
126 HOMARD_UTILS::updateObjBrowser();
131 // ------------------------------------------------------------------------
132 void MonCreateBoundaryDi::PushOnOK()
133 // ------------------------------------------------------------------------
135 if (PushOnApply()) this->close();
136 if ( _parent ) { _parent->raise(); _parent->activateWindow(); };
138 // ------------------------------------------------------------------------
139 void MonCreateBoundaryDi::PushOnHelp()
140 // ------------------------------------------------------------------------
142 std::string LanguageShort = myHomardGen->GetLanguageShort();
143 HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html"), QString("frontiere-discrete"), QString(LanguageShort.c_str()));
145 // ------------------------------------------------------------------------
146 void MonCreateBoundaryDi::AssocieLesGroupes()
147 // ------------------------------------------------------------------------
149 ADAPT::ListGroupType_var aSeqGroupe = new ADAPT::ListGroupType;
150 aSeqGroupe->length(_listeGroupesBoundary.size());
151 QStringList::const_iterator it;
153 for (it = _listeGroupesBoundary.constBegin(); it != _listeGroupesBoundary.constEnd(); it++)
154 aSeqGroupe[i++]=(*it).toStdString().c_str();
155 aBoundary->SetGroups(aSeqGroupe);
159 // -------------------------------------------------
160 void MonCreateBoundaryDi::SetNewName()
161 // --------------------------------------------------
164 ADAPT::listeBoundarys_var MyObjects = myHomardGen->GetAllBoundarysName();
165 int num = 0; QString aName="";
166 while (aName == QString("") )
168 aName.setNum(num+1) ;
169 aName.insert(0, QString("Boun_")) ;
170 for ( int i=0; i<MyObjects->length(); i++)
172 if ( aName == QString(MyObjects[i]))
180 LEName->setText(aName);
182 // ------------------------------------------------------------------------
183 void MonCreateBoundaryDi::SetMeshFile()
184 // ------------------------------------------------------------------------
186 QString aMeshFile = HOMARD_QT_COMMUN::PushNomFichier( false, QString("med") );
187 if (!(aMeshFile.isEmpty())) LEFileName->setText(aMeshFile);
190 // ------------------------------------------------------------------------
191 void MonCreateBoundaryDi::setGroups (QStringList listGroup)
192 // ------------------------------------------------------------------------
194 _listeGroupesBoundary = listGroup;
196 // ------------------------------------------------------------------------
197 void MonCreateBoundaryDi::SetFiltrage()
198 // // ------------------------------------------------------------------------
200 if (!CBGroupe->isChecked()) return;
201 if (_aCaseName.toStdString().c_str() == QString()) {
202 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
203 QObject::tr("HOM_BOUN_CASE") );
207 MonCreateListGroup *aDlg = new MonCreateListGroup(NULL, this, true, ADAPT::ADAPT_Gen::_duplicate(myHomardGen),
208 _aCaseName, _listeGroupesBoundary) ;