]> SALOME platform Git repositories - modules/homard.git/blob - src/HOMARDGUI/MonCreateBoundaryAn.cxx
Salome HOME
version V6_main 20110308
[modules/homard.git] / src / HOMARDGUI / MonCreateBoundaryAn.cxx
1 using namespace std;
2
3 #include "MonCreateBoundaryAn.h"
4 #include "MonCreateCase.h"
5
6 #include <QFileDialog>
7 #include <QMessageBox>
8
9 #include "SalomeApp_Tools.h"
10 #include "HOMARDGUI_Utils.h"
11 #include "HomardQtCommun.h"
12 #include <utilities.h>
13
14 #include <SUIT_Desktop.h>
15 #include <SUIT_MessageBox.h>
16 #include <SUIT_ResourceMgr.h>
17 #include <SUIT_Session.h>
18 #include <SUIT_ViewManager.h>
19
20 // ------------------------------------------------------------------------------------------------------------------------
21 MonCreateBoundaryAn::MonCreateBoundaryAn(MonCreateCase* parent, bool modal,
22                              HOMARD::HOMARD_Gen_var myHomardGen,
23                              QString caseName) :
24 // ------------------------------------------------------------------------------------------------------------------------------
25 /* Constructs a MonCreateBoundaryAn
26    appele pour une vraie creation
27    initialise un cylindre et non une sphere
28 */
29     QDialog(0), Ui_CreateBoundaryAn(),
30     _parent(parent),
31     _aBoundaryAnName (""),
32     _aCaseName(caseName),
33     _BoundaryType(1),
34     _BoundaryAnXcentre(0), _BoundaryAnYcentre(0), _BoundaryAnZcentre(0), _BoundaryAnRayon(0),
35     _BoundaryAnXaxis(0), _BoundaryAnYaxis(0), _BoundaryAnZaxis(0),
36     _Xcentre(0), _Ycentre(0), _Zcentre(0), _Rayon(0),
37     _Xmin(0), _Xmax(0), _Xincr(0), _Ymin(0), _Ymax(0), _Yincr(0), _Zmin(0), _Zmax(0), _Zincr(0), _DMax(0),
38     Chgt (false)
39     {
40       MESSAGE("Constructeur") ;
41       _myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen);
42       setupUi(this);
43       setModal(modal);
44
45     //  Gestion des icones
46       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
47       QPixmap pix = resMgr->loadPixmap( "HOMARD", "spherepoint.png" );
48       QIcon IS=QIcon(pix);
49       RBSphere->setIcon(IS);
50       QPixmap pix2 = resMgr->loadPixmap( "HOMARD", "cylinderpointvector.png" );
51       QIcon IS2=QIcon(pix2);
52       RBCylindre->setIcon(IS2);
53
54       InitConnect( );
55
56       SetNewBoundaryAnName() ;
57       InitValBoundaryAn();           // Cherche les valeurs de la boite englobante le maillage
58       InitMinMax();            // Initialise les bornes des boutons
59       SetCylinder();                // Propose un cylindre en premier choix
60     }
61 // --------------------------------------------------------------------------------------------------------------
62 MonCreateBoundaryAn::MonCreateBoundaryAn(MonCreateCase* parent,
63                              HOMARD::HOMARD_Gen_var myHomardGen,
64                              QString caseName):
65 // --------------------------------------------------------------------------------------------------------------
66 // Constructeur appele par MonEditBoundaryAn
67 //
68     QDialog(0), Ui_CreateBoundaryAn(),
69      _myHomardGen(myHomardGen),
70     _parent(parent),
71     _aBoundaryAnName (""),
72     _aCaseName(caseName),
73     _BoundaryType(1),
74     _BoundaryAnXcentre(0), _BoundaryAnYcentre(0), _BoundaryAnZcentre(0), _BoundaryAnRayon(0),
75     _BoundaryAnXaxis(0), _BoundaryAnYaxis(0), _BoundaryAnZaxis(0),
76     // Pour affichage lors de l edition d une BoundaryAn sans nom de Cas
77     _Xcentre(0), _Ycentre(0), _Zcentre(0), _Rayon(0),
78     _Xmin(1), _Xmax(1), _Xincr(1), _Ymin(1), _Ymax(1), _Yincr(1), _Zmin(1), _Zmax(1), _Zincr(1), _DMax(1),
79     Chgt (false)
80     {
81   //  MESSAGE("Debut de  MonCreateBoundaryAn")
82       setupUi(this);
83       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
84       QPixmap pix = resMgr->loadPixmap( "HOMARD", "spherepoint.png" );
85       QIcon IS=QIcon(pix);
86       RBSphere->setIcon(IS);
87       QPixmap pix2 = resMgr->loadPixmap( "HOMARD", "cylinderpointvector.png" );
88       QIcon IS2=QIcon(pix2);
89       RBCylindre->setIcon(IS2);
90       setModal(true);
91       InitConnect();
92     }
93
94 // ------------------------------------------------------------------------
95 MonCreateBoundaryAn::~MonCreateBoundaryAn()
96 // ------------------------------------------------------------------------
97 {
98     // no need to delete child widgets, Qt does it all for us
99 }
100 // ------------------------------------------------------------------------
101 void MonCreateBoundaryAn::InitConnect()
102 // ------------------------------------------------------------------------
103 {
104     connect( RBCylindre,   SIGNAL(clicked()) , this, SLOT(SetCylinder()) ) ;
105     connect( RBSphere,     SIGNAL(clicked()) , this, SLOT(SetSphere()) ) ;
106     connect( buttonOk,     SIGNAL( pressed() ), this, SLOT( PushOnOK() ) );
107     connect( buttonApply,  SIGNAL( pressed() ), this, SLOT( PushOnApply() ) );
108     connect( buttonCancel, SIGNAL( pressed() ), this, SLOT( close() ) );
109     connect( buttonHelp,   SIGNAL( pressed() ), this, SLOT( PushOnHelp() ) );
110 }
111 // ------------------------------------------------------------------------
112 void MonCreateBoundaryAn::InitValBoundaryAn()
113 // ------------------------------------------------------------------------
114 {
115 //
116 //  1. Les coordonnees extremes du maillage
117 //
118     if (_aCaseName == QString("")) { return; }
119
120     HOMARD::HOMARD_Cas_var aCas = _myHomardGen->GetCas(_aCaseName.toStdString().c_str());
121     HOMARD::extrema_var  MesExtremes = aCas->GetBoundingBox();
122     int num = MesExtremes->length() ;
123     ASSERT(num == 10);
124     _Xmin=MesExtremes[0]; _Xmax=MesExtremes[1]; _Xincr=MesExtremes[2];
125     _Ymin=MesExtremes[3]; _Ymax=MesExtremes[4]; _Yincr=MesExtremes[5];
126     _Zmin=MesExtremes[6]; _Zmax=MesExtremes[7]; _Zincr=MesExtremes[8];
127     _DMax=MesExtremes[9];
128      MESSAGE ("_Xmin : " << _Xmin << " _Xmax : " << _Xmax << " _Xincr : " << _Xincr ) ;
129      MESSAGE ("_Ymin : " << _Ymin << " _Ymax : " << _Ymax << " _Yincr : " << _Yincr ) ;
130      MESSAGE ("_Zmin : " << _Zmin << " _Zmax : " << _Zmax << " _Zincr : " << _Zincr) ;
131      MESSAGE ("_DMax : " << _DMax);
132
133 //  2. Caracteristiques des zones
134 // en X
135     _Xcentre=(_Xmin + _Xmax)/2.;
136 // en Y
137     _Ycentre=(_Ymin + _Ymax)/2.;
138 // en Z
139     _Zcentre=(_Zmin + _Zmax)/2.;
140 // Rayon
141     _Rayon= _DMax/4.;
142 }
143
144 // ------------------------------------------------------------------------
145 void MonCreateBoundaryAn::InitMinMax()
146 // ------------------------------------------------------------------------
147 {
148 // en X
149   SpinBox_Xaxis->setSingleStep(0.1);
150   SpinBox_Xcentre->setSingleStep(_Xincr);
151 //en Y
152       SpinBox_Yaxis->setSingleStep(0.1);
153       SpinBox_Ycentre->setSingleStep(_Yincr);
154 //en Z
155       SpinBox_Zaxis->setSingleStep(0.1);
156       SpinBox_Zcentre->setSingleStep(_Zincr);
157 // Rayon
158     SpinBox_Radius->setSingleStep(_Rayon/10.);
159     SpinBox_Radius->setMinimum(0.);
160     SpinBox_Rayon->setSingleStep(_Rayon/10.);
161     SpinBox_Rayon->setMinimum(0.);
162 }
163 // ------------------------------------------------------------------------
164 bool MonCreateBoundaryAn::PushOnApply()
165 // ------------------------------------------------------------------------
166 // Appele lorsque l'un des boutons Ok ou Apply est presse
167 //
168 {
169   std::cerr << LEBoundaryName->text().trimmed().toStdString() << std::endl;
170   if (LEBoundaryName->text().trimmed()=="")
171   {
172     QMessageBox::information( 0, "Error",
173                               "The boundary must be named.",
174                               QMessageBox::Ok + QMessageBox::Default );
175     return false;
176   }
177
178   switch (_BoundaryType)
179   {
180       case 1 : // il s agit d un cylindre
181       {
182         if ((_BoundaryAnXcentre != SpinBox_Xcent->value())  or
183             (_BoundaryAnYcentre != SpinBox_Ycent->value())  or
184             (_BoundaryAnZcentre != SpinBox_Zcent->value())  or
185             (_BoundaryAnRayon   != SpinBox_Radius->value()) or
186             (_BoundaryAnXaxis   != SpinBox_Xaxis->value()) or
187             (_BoundaryAnYaxis   != SpinBox_Yaxis->value()) or
188             (_BoundaryAnZaxis   != SpinBox_Zaxis->value()) )
189         {
190             Chgt = true;
191             _BoundaryAnXaxis= SpinBox_Xaxis->value();
192             _BoundaryAnYaxis= SpinBox_Yaxis->value();
193             _BoundaryAnZaxis= SpinBox_Zaxis->value();
194             _BoundaryAnXcentre=SpinBox_Xcent->value();
195             _BoundaryAnYcentre=SpinBox_Ycent->value();
196             _BoundaryAnZcentre=SpinBox_Zcent->value();
197             _BoundaryAnRayon=SpinBox_Radius->value();
198         }
199         break;
200       }
201
202       case 4 : // il s agit d une sphere
203       {
204         if ((_BoundaryAnXcentre != SpinBox_Xcentre->value()) or
205             (_BoundaryAnYcentre != SpinBox_Ycentre->value()) or
206             (_BoundaryAnZcentre != SpinBox_Zcentre->value()) or
207             (_BoundaryAnRayon   != SpinBox_Rayon->value())  )
208         {
209            Chgt = true;
210           _BoundaryAnXcentre=SpinBox_Xcentre->value();
211           _BoundaryAnYcentre=SpinBox_Ycentre->value();
212           _BoundaryAnZcentre=SpinBox_Zcentre->value();
213           _BoundaryAnRayon=SpinBox_Rayon->value();
214         }
215         break;
216       }
217   }
218
219   bool bOK = CreateOrUpdateBoundaryAn();
220   return bOK;
221
222 }
223 // ---------------------------------------------------
224 bool MonCreateBoundaryAn:: CreateOrUpdateBoundaryAn()
225 //----------------------------------------------------
226 //  Creation de l'objet boundary
227 //  Mise a jour des attributs de la BoundaryAn
228
229 {
230   if (_aBoundaryAnName != LEBoundaryName->text().trimmed())
231   {
232     try
233     {
234       _aBoundaryAnName = LEBoundaryName->text().trimmed();
235       aBoundaryAn = _myHomardGen->CreateBoundary( \
236               CORBA::string_dup(_aBoundaryAnName.toStdString().c_str()), \
237               CORBA::Long(_BoundaryType) );
238       _parent->addBoundaryAn(_aBoundaryAnName);
239      }
240      catch( SALOME::SALOME_Exception& S_ex )
241      {
242        QMessageBox::information( 0, "Error",
243                 QString(CORBA::string_dup(S_ex.details.text)),
244                 QMessageBox::Ok + QMessageBox::Default );
245        return false;
246      }
247   }
248 // Mise en place des attributs
249   aBoundaryAn->SetBoundaryType(_BoundaryType);
250   switch (_BoundaryType)
251   {
252       case 1 : // il s agit d un cylindre
253       {
254         aBoundaryAn->SetCylinder(_BoundaryAnXcentre, _BoundaryAnYcentre, _BoundaryAnZcentre, _BoundaryAnXaxis, _BoundaryAnYaxis, _BoundaryAnZaxis, _BoundaryAnRayon );
255         break;
256       }
257
258       case 2 : // il s agit d une sphere
259       {
260         aBoundaryAn->SetSphere(_BoundaryAnXcentre, _BoundaryAnYcentre, _BoundaryAnZcentre, _BoundaryAnRayon);
261         break;
262       }
263   }
264   aBoundaryAn->SetLimit(_Xincr, _Yincr, _Zincr);
265
266   HOMARD_UTILS::updateObjBrowser();
267   return true;
268 }
269 // ------------------------------------------------------------------------
270 void MonCreateBoundaryAn::PushOnOK()
271 // ------------------------------------------------------------------------
272 {
273      if (PushOnApply()) this->close();
274 }
275 // ------------------------------------------------------------------------
276 void MonCreateBoundaryAn::PushOnHelp()
277 // ------------------------------------------------------------------------
278 {
279   HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html#un-cylindre") ) ;
280 }
281
282 // -----------------------------------
283 void MonCreateBoundaryAn::SetNewBoundaryAnName()
284 // -----------------------------------
285 {
286 // Recherche d'un nom par defaut qui n'existe pas encore
287
288   HOMARD::listeBoundarys_var  MyBoundaryAns = _myHomardGen->GetAllBoundarys();
289   int num = 0; QString aBoundaryAnName="";
290   while (aBoundaryAnName=="" )
291   {
292     aBoundaryAnName.setNum(num+1) ;
293     aBoundaryAnName.insert(0, QString("Boun_")) ;
294     for ( int i=0; i<MyBoundaryAns->length(); i++)
295     {
296       if ( aBoundaryAnName ==  QString(MyBoundaryAns[i]))
297       {
298           num=num+1;
299           aBoundaryAnName="";
300           break;
301       }
302    }
303   }
304   LEBoundaryName->clear() ;
305   LEBoundaryName->insert(aBoundaryAnName);
306 }
307 // ------------------------------------------------------------------------
308 void MonCreateBoundaryAn::SetCylinder()
309 // ------------------------------------------------------------------------
310 {
311   MESSAGE("Debut de SetCylinder")
312   gBCylindre->setVisible(1);
313   gBSphere->setVisible(0);
314   adjustSize();
315   _BoundaryType=1;
316   SpinBox_Xcent->setValue(_Xcentre);
317   SpinBox_Xaxis->setValue(1.);
318   SpinBox_Ycent->setValue(_Ycentre);
319   SpinBox_Yaxis->setValue(1.);
320   SpinBox_Zcent->setValue(_Zcentre);
321   SpinBox_Zaxis->setValue(1.);
322   SpinBox_Radius->setValue(_Rayon);
323   MESSAGE("Fin de SetCylinder")
324 }
325 // ------------------------------------------------------------------------
326 void MonCreateBoundaryAn::SetSphere()
327 // ------------------------------------------------------------------------
328 {
329   MESSAGE("Debut de SetSphere")
330   gBCylindre->setVisible(0);
331   gBSphere->setVisible(1);
332   adjustSize();
333   _BoundaryType=2;
334   SpinBox_Xcentre->setValue(_Xcentre);
335   SpinBox_Ycentre->setValue(_Ycentre);
336   SpinBox_Zcentre->setValue(_Zcentre);
337   SpinBox_Rayon->setValue(_Rayon);
338   MESSAGE("Fin de SetSphere")
339 }
340
341