1 // Copyright (C) 2011-2012 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
22 #include "MonCreateBoundaryDi.h"
23 #include "MonCreateListGroup.h"
24 #include "MonCreateCase.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>
34 // -------------------------------------------------------------------------------
35 MonCreateBoundaryDi::MonCreateBoundaryDi(MonCreateCase* parent, bool modal,
36 HOMARD::HOMARD_Gen_var myHomardGen,
37 QString caseName, QString aBoundaryName)
38 // ---------------------------------------------------------------------------------
39 /* Constructs a MonCreateBoundaryDi */
41 QDialog(0), Ui_CreateBoundaryDi(),
42 _parent(parent), _aBoundaryName(aBoundaryName),
43 _myHomardGen(HOMARD::HOMARD_Gen::_duplicate(myHomardGen)),
46 MESSAGE("Constructeur") ;
51 if ( _aBoundaryName == QString("") ) {SetNewBoundaryName();};
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 aBoundaryName=LEBoundaryName->text().trimmed();
81 if (aBoundaryName=="") {
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 ( _aBoundaryName != aBoundaryName )
110 _aBoundaryName=aBoundaryName;
111 _aBoundary=_myHomardGen->CreateBoundaryDi(CORBA::string_dup(_aBoundaryName.toStdString().c_str()), aMeshName.toStdString().c_str(), aMeshFile.toStdString().c_str());
112 _parent->AddBoundaryDi(_aBoundaryName);
113 _aBoundary->SetCaseCreation(_aCaseName.toStdString().c_str());
115 catch( SALOME::SALOME_Exception& S_ex )
117 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
118 QString(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 HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html#frontiere-discrete"));
144 // ------------------------------------------------------------------------
145 void MonCreateBoundaryDi::AssocieLesGroupes()
146 // ------------------------------------------------------------------------
148 HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType;
149 aSeqGroupe->length(_listeGroupesBoundary.size());
150 QStringList::const_iterator it;
152 for (it = _listeGroupesBoundary.constBegin(); it != _listeGroupesBoundary.constEnd(); it++)
153 aSeqGroupe[i++]=(*it).toStdString().c_str();
154 _aBoundary->SetGroups(aSeqGroupe);
158 // -------------------------------------------------
159 void MonCreateBoundaryDi::SetNewBoundaryName()
160 // --------------------------------------------------
163 HOMARD::listeBoundarys_var MyBoundarys = _myHomardGen->GetAllBoundarysName();
164 int num = 0; QString aBoundaryName="";
165 while (aBoundaryName == QString("") )
167 aBoundaryName.setNum(num+1) ;
168 aBoundaryName.insert(0, QString("Boun_")) ;
169 for ( int i=0; i<MyBoundarys->length(); i++)
171 if ( aBoundaryName == QString(MyBoundarys[i]))
179 LEBoundaryName->setText(aBoundaryName);
181 // ------------------------------------------------------------------------
182 void MonCreateBoundaryDi::SetMeshFile()
183 // ------------------------------------------------------------------------
185 QString aMeshFile = HOMARD_QT_COMMUN::PushNomFichier();
186 if (!(aMeshFile.isEmpty())) LEFileName->setText(aMeshFile);
189 // ------------------------------------------------------------------------
190 void MonCreateBoundaryDi::setGroups (QStringList listGroup)
191 // ------------------------------------------------------------------------
193 _listeGroupesBoundary = listGroup;
195 // ------------------------------------------------------------------------
196 void MonCreateBoundaryDi::SetFiltrage()
197 // // ------------------------------------------------------------------------
199 if (!CBGroupe->isChecked()) return;
200 if (_aCaseName.toStdString().c_str() == QString()) {
201 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
202 QObject::tr("HOM_BOUN_CASE") );
206 MonCreateListGroup *aDlg = new MonCreateListGroup(NULL,this, TRUE, HOMARD::HOMARD_Gen::_duplicate(_myHomardGen),
207 _aCaseName, _listeGroupesBoundary) ;