Salome HOME
57ac52d7dcca0ff8506671073e9beffa5a0f8e7a
[modules/homard.git] / src / HOMARDGUI / MonCreateBoundaryDi.cxx
1 // Copyright (C) 2011-2021  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, or (at your option) any later version.
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 #include "MonCreateBoundaryDi.h"
21 #include "MonCreateListGroup.h"
22 #include "MonCreateCase.h"
23
24 #include <QFileDialog>
25 #include <QMessageBox>
26
27 #include "SalomeApp_Tools.h"
28 #include "HOMARDGUI_Utils.h"
29 #include "HomardQtCommun.h"
30 #include <utilities.h>
31
32 using namespace std;
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   std::string LanguageShort = myHomardGen->GetLanguageShort();
143   HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html"), QString("frontiere-discrete"), QString(LanguageShort.c_str()));
144 }
145 // ------------------------------------------------------------------------
146 void MonCreateBoundaryDi::AssocieLesGroupes()
147 // ------------------------------------------------------------------------
148 {
149   HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType;
150   aSeqGroupe->length(_listeGroupesBoundary.size());
151   QStringList::const_iterator it;
152   int i=0;
153   for (it = _listeGroupesBoundary.constBegin(); it != _listeGroupesBoundary.constEnd(); it++)
154      aSeqGroupe[i++]=(*it).toStdString().c_str();
155   aBoundary->SetGroups(aSeqGroupe);
156
157 }
158
159 // -------------------------------------------------
160 void MonCreateBoundaryDi::SetNewName()
161 // --------------------------------------------------
162 {
163
164   HOMARD::listeBoundarys_var  MyObjects = myHomardGen->GetAllBoundarysName();
165   int num = 0; QString aName="";
166   while (aName == QString("") )
167   {
168     aName.setNum(num+1) ;
169     aName.insert(0, QString("Boun_")) ;
170     for ( int i=0; i<MyObjects->length(); i++)
171     {
172       if ( aName ==  QString(MyObjects[i]))
173       {
174         num ++ ;
175         aName = "" ;
176         break ;
177       }
178    }
179   }
180   LEName->setText(aName);
181 }
182 // ------------------------------------------------------------------------
183 void MonCreateBoundaryDi::SetMeshFile()
184 // ------------------------------------------------------------------------
185 {
186   QString aMeshFile = HOMARD_QT_COMMUN::PushNomFichier( false, QString("med") );
187   if (!(aMeshFile.isEmpty())) LEFileName->setText(aMeshFile);
188 }
189
190 // ------------------------------------------------------------------------
191 void MonCreateBoundaryDi::setGroups (QStringList listGroup)
192 // ------------------------------------------------------------------------
193 {
194     _listeGroupesBoundary = listGroup;
195 }
196 // ------------------------------------------------------------------------
197 void MonCreateBoundaryDi::SetFiltrage()
198 // // ------------------------------------------------------------------------
199 {
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") );
204     return;
205   }
206
207   MonCreateListGroup *aDlg = new MonCreateListGroup(NULL, this, true, HOMARD::HOMARD_Gen::_duplicate(myHomardGen),
208                             _aCaseName, _listeGroupesBoundary) ;
209   aDlg->show();
210 }
211