]> SALOME platform Git repositories - modules/homard.git/blob - src/HOMARDGUI/MonCreateBoundaryAn.cxx
Salome HOME
Fix problems of 'make distcheck'
[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::critical( 0, QObject::tr("HOM_ERROR"),
173                               QObject::tr("HOM_BOUN_NAME") );
174     return false;
175   }
176
177   switch (_BoundaryType)
178   {
179       case 1 : // il s agit d un cylindre
180       {
181         if ((_BoundaryAnXcentre != SpinBox_Xcent->value())  or
182             (_BoundaryAnYcentre != SpinBox_Ycent->value())  or
183             (_BoundaryAnZcentre != SpinBox_Zcent->value())  or
184             (_BoundaryAnRayon   != SpinBox_Radius->value()) or
185             (_BoundaryAnXaxis   != SpinBox_Xaxis->value()) or
186             (_BoundaryAnYaxis   != SpinBox_Yaxis->value()) or
187             (_BoundaryAnZaxis   != SpinBox_Zaxis->value()) )
188         {
189             Chgt = true;
190             _BoundaryAnXaxis= SpinBox_Xaxis->value();
191             _BoundaryAnYaxis= SpinBox_Yaxis->value();
192             _BoundaryAnZaxis= SpinBox_Zaxis->value();
193             _BoundaryAnXcentre=SpinBox_Xcent->value();
194             _BoundaryAnYcentre=SpinBox_Ycent->value();
195             _BoundaryAnZcentre=SpinBox_Zcent->value();
196             _BoundaryAnRayon=SpinBox_Radius->value();
197         }
198         break;
199       }
200
201       case 4 : // il s agit d une sphere
202       {
203         if ((_BoundaryAnXcentre != SpinBox_Xcentre->value()) or
204             (_BoundaryAnYcentre != SpinBox_Ycentre->value()) or
205             (_BoundaryAnZcentre != SpinBox_Zcentre->value()) or
206             (_BoundaryAnRayon   != SpinBox_Rayon->value())  )
207         {
208            Chgt = true;
209           _BoundaryAnXcentre=SpinBox_Xcentre->value();
210           _BoundaryAnYcentre=SpinBox_Ycentre->value();
211           _BoundaryAnZcentre=SpinBox_Zcentre->value();
212           _BoundaryAnRayon=SpinBox_Rayon->value();
213         }
214         break;
215       }
216   }
217
218   bool bOK = CreateOrUpdateBoundaryAn();
219   return bOK;
220
221 }
222 // ---------------------------------------------------
223 bool MonCreateBoundaryAn:: CreateOrUpdateBoundaryAn()
224 //----------------------------------------------------
225 //  Creation de l'objet boundary
226 //  Mise a jour des attributs de la BoundaryAn
227
228 {
229   if (_aBoundaryAnName != LEBoundaryName->text().trimmed())
230   {
231     try
232     {
233       _aBoundaryAnName = LEBoundaryName->text().trimmed();
234       aBoundaryAn = _myHomardGen->CreateBoundary( \
235               CORBA::string_dup(_aBoundaryAnName.toStdString().c_str()), \
236               CORBA::Long(_BoundaryType) );
237       _parent->addBoundaryAn(_aBoundaryAnName);
238     }
239     catch( SALOME::SALOME_Exception& S_ex )
240     {
241       QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
242                                 QString(CORBA::string_dup(S_ex.details.text)) );
243       return false;
244     }
245   }
246 // Mise en place des attributs
247   aBoundaryAn->SetBoundaryType(_BoundaryType);
248   switch (_BoundaryType)
249   {
250       case 1 : // il s agit d un cylindre
251       {
252         aBoundaryAn->SetCylinder(_BoundaryAnXcentre, _BoundaryAnYcentre, _BoundaryAnZcentre, _BoundaryAnXaxis, _BoundaryAnYaxis, _BoundaryAnZaxis, _BoundaryAnRayon );
253         break;
254       }
255
256       case 2 : // il s agit d une sphere
257       {
258         aBoundaryAn->SetSphere(_BoundaryAnXcentre, _BoundaryAnYcentre, _BoundaryAnZcentre, _BoundaryAnRayon);
259         break;
260       }
261   }
262   aBoundaryAn->SetLimit(_Xincr, _Yincr, _Zincr);
263
264   HOMARD_UTILS::updateObjBrowser();
265   return true;
266 }
267 // ------------------------------------------------------------------------
268 void MonCreateBoundaryAn::PushOnOK()
269 // ------------------------------------------------------------------------
270 {
271      if (PushOnApply()) this->close();
272 }
273 // ------------------------------------------------------------------------
274 void MonCreateBoundaryAn::PushOnHelp()
275 // ------------------------------------------------------------------------
276 {
277   HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html#un-cylindre") ) ;
278 }
279
280 // -----------------------------------
281 void MonCreateBoundaryAn::SetNewBoundaryAnName()
282 // -----------------------------------
283 {
284 // Recherche d'un nom par defaut qui n'existe pas encore
285
286   HOMARD::listeBoundarys_var  MyBoundaryAns = _myHomardGen->GetAllBoundarys();
287   int num = 0; QString aBoundaryAnName="";
288   while (aBoundaryAnName=="" )
289   {
290     aBoundaryAnName.setNum(num+1) ;
291     aBoundaryAnName.insert(0, QString("Boun_")) ;
292     for ( int i=0; i<MyBoundaryAns->length(); i++)
293     {
294       if ( aBoundaryAnName ==  QString(MyBoundaryAns[i]))
295       {
296           num=num+1;
297           aBoundaryAnName="";
298           break;
299       }
300    }
301   }
302   LEBoundaryName->clear() ;
303   LEBoundaryName->insert(aBoundaryAnName);
304 }
305 // ------------------------------------------------------------------------
306 void MonCreateBoundaryAn::SetCylinder()
307 // ------------------------------------------------------------------------
308 {
309   MESSAGE("Debut de SetCylinder")
310   gBCylindre->setVisible(1);
311   gBSphere->setVisible(0);
312   adjustSize();
313   _BoundaryType=1;
314   SpinBox_Xcent->setValue(_Xcentre);
315   SpinBox_Xaxis->setValue(1.);
316   SpinBox_Ycent->setValue(_Ycentre);
317   SpinBox_Yaxis->setValue(1.);
318   SpinBox_Zcent->setValue(_Zcentre);
319   SpinBox_Zaxis->setValue(1.);
320   SpinBox_Radius->setValue(_Rayon);
321   MESSAGE("Fin de SetCylinder")
322 }
323 // ------------------------------------------------------------------------
324 void MonCreateBoundaryAn::SetSphere()
325 // ------------------------------------------------------------------------
326 {
327   MESSAGE("Debut de SetSphere")
328   gBCylindre->setVisible(0);
329   gBSphere->setVisible(1);
330   adjustSize();
331   _BoundaryType=2;
332   SpinBox_Xcentre->setValue(_Xcentre);
333   SpinBox_Ycentre->setValue(_Ycentre);
334   SpinBox_Zcentre->setValue(_Zcentre);
335   SpinBox_Rayon->setValue(_Rayon);
336   MESSAGE("Fin de SetSphere")
337 }
338
339