Salome HOME
Schémas YACS - suite
[modules/homard.git] / src / HOMARDGUI / MonCreateBoundaryDi.cxx
1 // Copyright (C) 2011-2013  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 using namespace std;
21
22 #include "MonCreateBoundaryDi.h"
23 #include "MonCreateListGroup.h"
24 #include "MonCreateCase.h"
25
26 #include <QFileDialog>
27 #include <QMessageBox>
28
29 #include "SalomeApp_Tools.h"
30 #include "HOMARDGUI_Utils.h"
31 #include "HomardQtCommun.h"
32 #include <utilities.h>
33
34 // -------------------------------------------------------------------------------
35 MonCreateBoundaryDi::MonCreateBoundaryDi(MonCreateCase* parent, bool modal,
36                                          HOMARD::HOMARD_Gen_var myHomardGen0,
37                                          QString caseName, QString aName)
38 // ---------------------------------------------------------------------------------
39 /* Constructs a MonCreateBoundaryDi */
40     :
41     QDialog(0), Ui_CreateBoundaryDi(),
42     _parent(parent), _aName(aName),
43     myHomardGen(HOMARD::HOMARD_Gen::_duplicate(myHomardGen0)),
44     _aCaseName(caseName)
45     {
46       MESSAGE("Constructeur") ;
47       setupUi(this);
48       setModal(modal);
49       InitConnect();
50
51      if ( _aName == QString("") ) {SetNewName();};
52     }
53
54 // ------------------------------------------------------------------------
55 MonCreateBoundaryDi::~MonCreateBoundaryDi()
56 // ------------------------------------------------------------------------
57 {
58     // no need to delete child widgets, Qt does it all for us
59 }
60 // ------------------------------------------------------------------------
61 void MonCreateBoundaryDi::InitConnect()
62 // ------------------------------------------------------------------------
63 {
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()));
70 }
71
72 // ------------------------------------------------------------------------
73 bool MonCreateBoundaryDi::PushOnApply()
74 // ------------------------------------------------------------------------
75 // Appele lorsque l'un des boutons Ok ou Apply est presse
76 //
77 {
78 // Verifications
79
80   QString aName=LEName->text().trimmed();
81   if (aName=="") {
82     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
83                               QObject::tr("HOM_BOUN_NAME") );
84     return false;
85   }
86
87 //  Le maillage de la frontiere discrete
88   QString aMeshFile=LEFileName->text().trimmed();
89   if (aMeshFile ==QString(""))
90   {
91     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
92                               QObject::tr("HOM_BOUN_MESH") );
93     return false;
94   }
95
96 //  Le nom du maillage de la frontiere discrete
97   QString aMeshName = HOMARD_QT_COMMUN::LireNomMaillage(aMeshFile);
98   if (aMeshName == "" )
99   {
100     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
101                               QObject::tr("HOM_MED_FILE_2") );
102     return false;
103   }
104
105 // Creation de l'objet CORBA si ce n'est pas deja fait sous le meme nom
106   if ( _aName != aName )
107   {
108    try
109    {
110      _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());
114    }
115    catch( SALOME::SALOME_Exception& S_ex )
116    {
117       QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
118                                 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
119       return false;
120    }
121   }
122
123 // Les groupes
124   AssocieLesGroupes();
125
126   HOMARD_UTILS::updateObjBrowser();
127   return true;
128 }
129
130
131 // ------------------------------------------------------------------------
132 void MonCreateBoundaryDi::PushOnOK()
133 // ------------------------------------------------------------------------
134 {
135      if (PushOnApply()) this->close();
136      if ( _parent ) { _parent->raise(); _parent->activateWindow(); };
137 }
138 // ------------------------------------------------------------------------
139 void MonCreateBoundaryDi::PushOnHelp()
140 // ------------------------------------------------------------------------
141 {
142   HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html"), QString("frontiere-discrete"));
143 }
144 // ------------------------------------------------------------------------
145 void MonCreateBoundaryDi::AssocieLesGroupes()
146 // ------------------------------------------------------------------------
147 {
148   HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType;
149   aSeqGroupe->length(_listeGroupesBoundary.size());
150   QStringList::const_iterator it;
151   int i=0;
152   for (it = _listeGroupesBoundary.constBegin(); it != _listeGroupesBoundary.constEnd(); it++)
153      aSeqGroupe[i++]=(*it).toStdString().c_str();
154   aBoundary->SetGroups(aSeqGroupe);
155
156 }
157
158 // -------------------------------------------------
159 void MonCreateBoundaryDi::SetNewName()
160 // --------------------------------------------------
161 {
162
163   HOMARD::listeBoundarys_var  MyObjects = myHomardGen->GetAllBoundarysName();
164   int num = 0; QString aName="";
165   while (aName == QString("") )
166   {
167     aName.setNum(num+1) ;
168     aName.insert(0, QString("Boun_")) ;
169     for ( int i=0; i<MyObjects->length(); i++)
170     {
171       if ( aName ==  QString(MyObjects[i]))
172       {
173           num=num+1;
174           aName="";
175           break;
176       }
177    }
178   }
179   LEName->setText(aName);
180 }
181 // ------------------------------------------------------------------------
182 void MonCreateBoundaryDi::SetMeshFile()
183 // ------------------------------------------------------------------------
184 {
185   QString aMeshFile = HOMARD_QT_COMMUN::PushNomFichier();
186   if (!(aMeshFile.isEmpty())) LEFileName->setText(aMeshFile);
187 }
188
189 // ------------------------------------------------------------------------
190 void MonCreateBoundaryDi::setGroups (QStringList listGroup)
191 // ------------------------------------------------------------------------
192 {
193     _listeGroupesBoundary = listGroup;
194 }
195 // ------------------------------------------------------------------------
196 void MonCreateBoundaryDi::SetFiltrage()
197 // // ------------------------------------------------------------------------
198 {
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") );
203     return;
204   }
205
206   MonCreateListGroup *aDlg = new MonCreateListGroup(NULL,this,  TRUE, HOMARD::HOMARD_Gen::_duplicate(myHomardGen),
207                             _aCaseName, _listeGroupesBoundary) ;
208   aDlg->show();
209 }
210