Salome HOME
Merge branch 'master' into gni/adaptation
[modules/smesh.git] / src / ADAPTGUI / MonCreateBoundaryCAO.cxx
1 // Copyright (C) 2011-2020  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 "MonCreateBoundaryCAO.h"
21 #include "MonCreateListGroupCAO.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 MonCreateBoundaryCAO::MonCreateBoundaryCAO(MonCreateCase* parent, bool modal,
36                                          ADAPT::ADAPT_Gen_var myHomardGen0,
37                                          QString caseName, QString aName)
38 // ---------------------------------------------------------------------------------
39 /* Constructs a MonCreateBoundaryCAO */
40     :
41     QDialog(0), Ui_CreateBoundaryCAO(),
42     _parent(parent), _aName(aName),
43     myHomardGen(ADAPT::ADAPT_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 MonCreateBoundaryCAO::~MonCreateBoundaryCAO()
56 // ------------------------------------------------------------------------
57 {
58     // no need to delete child widgets, Qt does it all for us
59 }
60 // ------------------------------------------------------------------------
61 void MonCreateBoundaryCAO::InitConnect()
62 // ------------------------------------------------------------------------
63 {
64     connect( PushFichier,  SIGNAL(pressed()), this, SLOT(SetCAOFile()));
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 MonCreateBoundaryCAO::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 //  La CAO
88   QString aCAOFile=LEFileName->text().trimmed();
89   if (aCAOFile ==QString(""))
90   {
91     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
92                               QObject::tr("HOM_BOUN_CAO") );
93     return false;
94   }
95
96 // Creation de l'objet CORBA si ce n'est pas deja fait sous le meme nom
97   if ( _aName != aName )
98   {
99    try
100    {
101      _aName=aName;
102      aBoundary=myHomardGen->CreateBoundaryCAO(CORBA::string_dup(_aName.toStdString().c_str()), aCAOFile.toStdString().c_str());
103      _parent->AddBoundaryCAO(_aName);
104      aBoundary->SetCaseCreation(_aCaseName.toStdString().c_str());
105    }
106    catch( SALOME::SALOME_Exception& S_ex )
107    {
108       QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
109                                 QObject::tr(CORBA::string_dup(S_ex.details.text)) );
110       return false;
111    }
112   }
113
114 // Les groupes
115   AssocieLesGroupes();
116
117   HOMARD_UTILS::updateObjBrowser();
118   return true;
119 }
120
121
122 // ------------------------------------------------------------------------
123 void MonCreateBoundaryCAO::PushOnOK()
124 // ------------------------------------------------------------------------
125 {
126      if (PushOnApply()) this->close();
127      if ( _parent ) { _parent->raise(); _parent->activateWindow(); };
128 }
129 // ------------------------------------------------------------------------
130 void MonCreateBoundaryCAO::PushOnHelp()
131 // ------------------------------------------------------------------------
132 {
133   std::string LanguageShort = myHomardGen->GetLanguageShort();
134   HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html"), QString("CAO"), QString(LanguageShort.c_str()));
135 }
136 // ------------------------------------------------------------------------
137 void MonCreateBoundaryCAO::AssocieLesGroupes()
138 // ------------------------------------------------------------------------
139 {
140   ADAPT::ListGroupType_var aSeqGroupe = new ADAPT::ListGroupType;
141   aSeqGroupe->length(_listeGroupesBoundary.size());
142   QStringList::const_iterator it;
143   int i=0;
144   for (it = _listeGroupesBoundary.constBegin(); it != _listeGroupesBoundary.constEnd(); it++)
145      aSeqGroupe[i++]=(*it).toStdString().c_str();
146   aBoundary->SetGroups(aSeqGroupe);
147
148 }
149
150 // -------------------------------------------------
151 void MonCreateBoundaryCAO::SetNewName()
152 // --------------------------------------------------
153 {
154
155   ADAPT::listeBoundarys_var  MyObjects = myHomardGen->GetAllBoundarysName();
156   int num = 0; QString aName="";
157   while (aName == QString("") )
158   {
159     aName.setNum(num+1) ;
160     aName.insert(0, QString("Boun_")) ;
161     for ( int i=0; i<MyObjects->length(); i++)
162     {
163       if ( aName ==  QString(MyObjects[i]))
164       {
165         num ++ ;
166         aName = "" ;
167         break ;
168       }
169    }
170   }
171   LEName->setText(aName);
172 }
173 // ------------------------------------------------------------------------
174 void MonCreateBoundaryCAO::SetCAOFile()
175 // ------------------------------------------------------------------------
176 {
177   QString aCAOFile = HOMARD_QT_COMMUN::PushNomFichier( false, QString("xao") );
178   if (!(aCAOFile.isEmpty())) LEFileName->setText(aCAOFile);
179 }
180
181 // ------------------------------------------------------------------------
182 void MonCreateBoundaryCAO::setGroups (QStringList listGroup)
183 // ------------------------------------------------------------------------
184 {
185     _listeGroupesBoundary = listGroup;
186 }
187 // ------------------------------------------------------------------------
188 void MonCreateBoundaryCAO::SetFiltrage()
189 // // ------------------------------------------------------------------------
190 {
191   if (!CBGroupe->isChecked()) return;
192   if (_aCaseName.toStdString().c_str() == QString()) {
193     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
194                               QObject::tr("HOM_BOUN_CASE") );
195     return;
196   }
197
198   MonCreateListGroupCAO *aDlg = new MonCreateListGroupCAO(NULL, this, true, ADAPT::ADAPT_Gen::_duplicate(myHomardGen),
199                             _aCaseName, _listeGroupesBoundary) ;
200   aDlg->show();
201 }
202