Salome HOME
version 5_1_4 HOMARD_SRC
[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::information( 0, "Error",
64                               "The boundary must be named.",
65                               QMessageBox::Ok + QMessageBox::Default );
66     return false;
67   }
68
69 //  Le maillage de la frontiere discrete
70   QString aMeshFile=LEFileName->text().trimmed();
71   if (aMeshFile ==QString(""))
72   {
73     QMessageBox::information( 0, "Error",
74               QString("The mesh of the boundary must be selected."),
75               QMessageBox::Ok + QMessageBox::Default );
76     return false;
77   }
78
79 //  Le nom du maillage de la frontiere discrete
80   QString aMeshName = HOMARD_QT_COMMUN::LireNomMaillage(aMeshFile);
81   if (aMeshName == "" )
82   {
83     QMessageBox::information( 0, "Error",
84               QString("no mesh in mesh file"),
85               QMessageBox::Ok + QMessageBox::Default );
86     return false;
87   }
88
89 // Creation de l'objet CORBA si ce n'est pas deja fait sous le meme nom
90   if ( _aBoundaryName != aBoundaryName )
91   {
92    try 
93    {
94      _aBoundaryName=aBoundaryName;
95      _aBoundary=_myHomardGen->CreateBoundary(CORBA::string_dup(_aBoundaryName.toStdString().c_str()),0);
96      _parent->addBoundaryDi(_aBoundaryName);
97      _aBoundary->SetCaseCreation(_aCaseName.toStdString().c_str());
98    }
99    catch( SALOME::SALOME_Exception& S_ex )
100    {
101       QMessageBox::information( 0, "Error",
102                   QString(CORBA::string_dup(S_ex.details.text)),
103                   QMessageBox::Ok + QMessageBox::Default );
104       return false;
105    }
106   }
107
108 // Mise en place des attributs
109   _aBoundary->SetMeshFile(aMeshFile.toStdString().c_str());
110   _aBoundary->SetMeshName(aMeshName.toStdString().c_str());
111   AssocieLesGroupes();
112
113   HOMARD_UTILS::updateObjBrowser();
114   return true;
115 }
116
117
118 // ------------------------------------------------------------------------
119 void MonCreateBoundaryDi::PushOnOK()
120 // ------------------------------------------------------------------------
121 {
122      if (PushOnApply()) this->close();
123      if ( _parent ) { _parent->raise(); _parent->activateWindow(); };
124 }
125 // ------------------------------------------------------------------------
126 void MonCreateBoundaryDi::PushOnHelp()
127 // ------------------------------------------------------------------------
128 {
129   HOMARD_UTILS::PushOnHelp(QString("gui_create_hypothese.html"));
130 }
131 // ------------------------------------------------------------------------
132 void MonCreateBoundaryDi::AssocieLesGroupes()
133 // ------------------------------------------------------------------------
134 {
135   HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType;
136   aSeqGroupe->length(_listeGroupesBoundary.size());
137   QStringList::const_iterator it;
138   int i=0;
139   for (it = _listeGroupesBoundary.constBegin(); it != _listeGroupesBoundary.constEnd(); it++)
140      aSeqGroupe[i++]=(*it).toStdString().c_str();
141   _aBoundary->SetGroups(aSeqGroupe);
142
143 }
144
145 // -------------------------------------------------
146 void MonCreateBoundaryDi::SetNewBoundaryName()
147 // --------------------------------------------------
148 {
149
150   HOMARD::listeBoundarys_var  MyBoundarys = _myHomardGen->GetAllBoundarys();
151   int num = 0; QString aBoundaryName="";
152   while (aBoundaryName == QString("") )
153   {
154     aBoundaryName.setNum(num+1) ;
155     aBoundaryName.insert(0, QString("Boun_")) ;
156     for ( int i=0; i<MyBoundarys->length(); i++)
157     {
158       if ( aBoundaryName ==  QString(MyBoundarys[i]))
159       {
160           num=num+1;
161           aBoundaryName="";
162           break;
163       }
164    }
165   }
166   LEBoundaryName->setText(aBoundaryName);
167 }
168 // ------------------------------------------------------------------------
169 void MonCreateBoundaryDi::SetMeshFile()
170 // ------------------------------------------------------------------------
171 {
172   QString aMeshFile = HOMARD_QT_COMMUN::PushNomFichier();
173   if (!(aMeshFile.isEmpty())) LEFileName->setText(aMeshFile);
174 }
175
176 // ------------------------------------------------------------------------
177 void MonCreateBoundaryDi::setGroups (QStringList listGroup)
178 // ------------------------------------------------------------------------
179 {
180     _listeGroupesBoundary = listGroup;
181 }
182 // ------------------------------------------------------------------------
183 void MonCreateBoundaryDi::SetFiltrage()
184 // // ------------------------------------------------------------------------
185 {
186    if (!CBGroupe->isChecked()) return;
187    if (_aCaseName.toStdString().c_str() == QString()) {
188         QMessageBox::information( 0, "Error",
189                               "Case MeshFile unknowned.",
190                               QMessageBox::Ok + QMessageBox::Default );
191         return;
192    }
193
194    MonCreateListGroup *aDlg = new MonCreateListGroup(NULL,this,  TRUE, HOMARD::HOMARD_Gen::_duplicate(_myHomardGen),
195                               _aCaseName, _listeGroupesBoundary) ;
196   aDlg->show();
197 }
198