]> SALOME platform Git repositories - modules/homard.git/blob - src/HOMARDGUI/MonCreateBoundaryDi.cxx
Salome HOME
Fix problems of 'make distcheck'
[modules/homard.git] / src / HOMARDGUI / MonCreateBoundaryDi.cxx
1 using namespace std;
2
3 #include "MonCreateBoundaryDi.h"
4 #include "MonCreateListGroup.h"
5 #include "MonCreateCase.h"
6
7 #include <QFileDialog>
8 #include <QMessageBox>
9
10 #include "SalomeApp_Tools.h"
11 #include "HOMARDGUI_Utils.h"
12 #include "HomardQtCommun.h"
13 #include <utilities.h>
14
15 // -------------------------------------------------------------------------------
16 MonCreateBoundaryDi::MonCreateBoundaryDi(MonCreateCase* parent, bool modal,
17                                          HOMARD::HOMARD_Gen_var myHomardGen,
18                                          QString caseName, QString aBoundaryName)
19 // ---------------------------------------------------------------------------------
20 /* Constructs a MonCreateBoundaryDi */
21     :
22     QDialog(0), Ui_CreateBoundaryDi(),
23     _parent(parent), _aBoundaryName(aBoundaryName),
24     _myHomardGen(HOMARD::HOMARD_Gen::_duplicate(myHomardGen)),
25     _aCaseName(caseName)
26     {
27       MESSAGE("Constructeur") ;
28       setupUi(this);
29       setModal(modal);
30       InitConnect();
31
32      if ( _aBoundaryName == QString("") ) {SetNewBoundaryName();};
33     }
34
35 // ------------------------------------------------------------------------
36 MonCreateBoundaryDi::~MonCreateBoundaryDi()
37 // ------------------------------------------------------------------------
38 {
39     // no need to delete child widgets, Qt does it all for us
40 }
41 // ------------------------------------------------------------------------
42 void MonCreateBoundaryDi::InitConnect()
43 // ------------------------------------------------------------------------
44 {
45     connect( PushFichier,  SIGNAL(pressed()), this, SLOT(SetMeshFile()));
46     connect( buttonOk,     SIGNAL(pressed()), this, SLOT( PushOnOK()));
47     connect( buttonApply,  SIGNAL(pressed()), this, SLOT( PushOnApply()));
48     connect( buttonCancel, SIGNAL(pressed()), this, SLOT(close()));
49     connect( buttonHelp,   SIGNAL(pressed()), this, SLOT( PushOnHelp()));
50     connect( CBGroupe,     SIGNAL(stateChanged(int)), this, SLOT( SetFiltrage()));
51 }
52
53 // ------------------------------------------------------------------------
54 bool MonCreateBoundaryDi::PushOnApply()
55 // ------------------------------------------------------------------------
56 // Appele lorsque l'un des boutons Ok ou Apply est presse
57 //
58 {
59 // Verifications
60
61   QString aBoundaryName=LEBoundaryName->text().trimmed();
62   if (aBoundaryName=="") {
63     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
64                               QObject::tr("HOM_BOUN_NAME") );
65     return false;
66   }
67
68 //  Le maillage de la frontiere discrete
69   QString aMeshFile=LEFileName->text().trimmed();
70   if (aMeshFile ==QString(""))
71   {
72     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
73                               QObject::tr("HOM_BOUN_MESH") );
74     return false;
75   }
76
77 //  Le nom du maillage de la frontiere discrete
78   QString aMeshName = HOMARD_QT_COMMUN::LireNomMaillage(aMeshFile);
79   if (aMeshName == "" )
80   {
81     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
82                               QObject::tr("HOM_MED_FILE_2") );
83     return false;
84   }
85
86 // Creation de l'objet CORBA si ce n'est pas deja fait sous le meme nom
87   if ( _aBoundaryName != aBoundaryName )
88   {
89    try
90    {
91      _aBoundaryName=aBoundaryName;
92      _aBoundary=_myHomardGen->CreateBoundary(CORBA::string_dup(_aBoundaryName.toStdString().c_str()),0);
93      _parent->addBoundaryDi(_aBoundaryName);
94      _aBoundary->SetCaseCreation(_aCaseName.toStdString().c_str());
95    }
96    catch( SALOME::SALOME_Exception& S_ex )
97    {
98       QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
99                                 QString(CORBA::string_dup(S_ex.details.text)) );
100       return false;
101    }
102   }
103
104 // Mise en place des attributs
105   _aBoundary->SetMeshFile(aMeshFile.toStdString().c_str());
106   _aBoundary->SetMeshName(aMeshName.toStdString().c_str());
107   AssocieLesGroupes();
108
109   HOMARD_UTILS::updateObjBrowser();
110   return true;
111 }
112
113
114 // ------------------------------------------------------------------------
115 void MonCreateBoundaryDi::PushOnOK()
116 // ------------------------------------------------------------------------
117 {
118      if (PushOnApply()) this->close();
119      if ( _parent ) { _parent->raise(); _parent->activateWindow(); };
120 }
121 // ------------------------------------------------------------------------
122 void MonCreateBoundaryDi::PushOnHelp()
123 // ------------------------------------------------------------------------
124 {
125   HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html#frontiere-discrete"));
126 }
127 // ------------------------------------------------------------------------
128 void MonCreateBoundaryDi::AssocieLesGroupes()
129 // ------------------------------------------------------------------------
130 {
131   HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType;
132   aSeqGroupe->length(_listeGroupesBoundary.size());
133   QStringList::const_iterator it;
134   int i=0;
135   for (it = _listeGroupesBoundary.constBegin(); it != _listeGroupesBoundary.constEnd(); it++)
136      aSeqGroupe[i++]=(*it).toStdString().c_str();
137   _aBoundary->SetGroups(aSeqGroupe);
138
139 }
140
141 // -------------------------------------------------
142 void MonCreateBoundaryDi::SetNewBoundaryName()
143 // --------------------------------------------------
144 {
145
146   HOMARD::listeBoundarys_var  MyBoundarys = _myHomardGen->GetAllBoundarys();
147   int num = 0; QString aBoundaryName="";
148   while (aBoundaryName == QString("") )
149   {
150     aBoundaryName.setNum(num+1) ;
151     aBoundaryName.insert(0, QString("Boun_")) ;
152     for ( int i=0; i<MyBoundarys->length(); i++)
153     {
154       if ( aBoundaryName ==  QString(MyBoundarys[i]))
155       {
156           num=num+1;
157           aBoundaryName="";
158           break;
159       }
160    }
161   }
162   LEBoundaryName->setText(aBoundaryName);
163 }
164 // ------------------------------------------------------------------------
165 void MonCreateBoundaryDi::SetMeshFile()
166 // ------------------------------------------------------------------------
167 {
168   QString aMeshFile = HOMARD_QT_COMMUN::PushNomFichier();
169   if (!(aMeshFile.isEmpty())) LEFileName->setText(aMeshFile);
170 }
171
172 // ------------------------------------------------------------------------
173 void MonCreateBoundaryDi::setGroups (QStringList listGroup)
174 // ------------------------------------------------------------------------
175 {
176     _listeGroupesBoundary = listGroup;
177 }
178 // ------------------------------------------------------------------------
179 void MonCreateBoundaryDi::SetFiltrage()
180 // // ------------------------------------------------------------------------
181 {
182   if (!CBGroupe->isChecked()) return;
183   if (_aCaseName.toStdString().c_str() == QString()) {
184     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
185                               QObject::tr("HOM_BOUN_CASE") );
186     return;
187   }
188
189   MonCreateListGroup *aDlg = new MonCreateListGroup(NULL,this,  TRUE, HOMARD::HOMARD_Gen::_duplicate(_myHomardGen),
190                             _aCaseName, _listeGroupesBoundary) ;
191   aDlg->show();
192 }
193