3 #include "MonCreateBoundaryAn.h"
4 #include "MonCreateCase.h"
9 #include "SalomeApp_Tools.h"
10 #include "HOMARDGUI_Utils.h"
11 #include "HomardQtCommun.h"
12 #include <utilities.h>
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>
20 // ------------------------------------------------------------------------------------------------------------------------
21 MonCreateBoundaryAn::MonCreateBoundaryAn(MonCreateCase* parent, bool modal,
22 HOMARD::HOMARD_Gen_var myHomardGen,
24 // ------------------------------------------------------------------------------------------------------------------------------
25 /* Constructs a MonCreateBoundaryAn
26 appele pour une vraie creation
27 initialise un cylindre et non une sphere
29 QDialog(0), Ui_CreateBoundaryAn(),
31 _aBoundaryAnName (""),
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),
40 MESSAGE("Constructeur") ;
41 _myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen);
46 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
47 QPixmap pix = resMgr->loadPixmap( "HOMARD", "spherepoint.png" );
49 RBSphere->setIcon(IS);
50 QPixmap pix2 = resMgr->loadPixmap( "HOMARD", "cylinderpointvector.png" );
51 QIcon IS2=QIcon(pix2);
52 RBCylindre->setIcon(IS2);
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
61 // --------------------------------------------------------------------------------------------------------------
62 MonCreateBoundaryAn::MonCreateBoundaryAn(MonCreateCase* parent,
63 HOMARD::HOMARD_Gen_var myHomardGen,
65 // --------------------------------------------------------------------------------------------------------------
66 // Constructeur appele par MonEditBoundaryAn
68 QDialog(0), Ui_CreateBoundaryAn(),
69 _myHomardGen(myHomardGen),
71 _aBoundaryAnName (""),
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),
81 // MESSAGE("Debut de MonCreateBoundaryAn")
83 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
84 QPixmap pix = resMgr->loadPixmap( "HOMARD", "spherepoint.png" );
86 RBSphere->setIcon(IS);
87 QPixmap pix2 = resMgr->loadPixmap( "HOMARD", "cylinderpointvector.png" );
88 QIcon IS2=QIcon(pix2);
89 RBCylindre->setIcon(IS2);
94 // ------------------------------------------------------------------------
95 MonCreateBoundaryAn::~MonCreateBoundaryAn()
96 // ------------------------------------------------------------------------
98 // no need to delete child widgets, Qt does it all for us
100 // ------------------------------------------------------------------------
101 void MonCreateBoundaryAn::InitConnect()
102 // ------------------------------------------------------------------------
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() ) );
111 // ------------------------------------------------------------------------
112 void MonCreateBoundaryAn::InitValBoundaryAn()
113 // ------------------------------------------------------------------------
116 // 1. Les coordonnees extremes du maillage
118 if (_aCaseName == QString("")) { return; }
120 HOMARD::HOMARD_Cas_var aCas = _myHomardGen->GetCas(_aCaseName.toStdString().c_str());
121 HOMARD::extrema_var MesExtremes = aCas->GetBoundingBox();
122 int num = MesExtremes->length() ;
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);
133 // 2. Caracteristiques des zones
135 _Xcentre=(_Xmin + _Xmax)/2.;
137 _Ycentre=(_Ymin + _Ymax)/2.;
139 _Zcentre=(_Zmin + _Zmax)/2.;
144 // ------------------------------------------------------------------------
145 void MonCreateBoundaryAn::InitMinMax()
146 // ------------------------------------------------------------------------
149 SpinBox_Xaxis->setSingleStep(0.1);
150 SpinBox_Xcentre->setSingleStep(_Xincr);
152 SpinBox_Yaxis->setSingleStep(0.1);
153 SpinBox_Ycentre->setSingleStep(_Yincr);
155 SpinBox_Zaxis->setSingleStep(0.1);
156 SpinBox_Zcentre->setSingleStep(_Zincr);
158 SpinBox_Radius->setSingleStep(_Rayon/10.);
159 SpinBox_Radius->setMinimum(0.);
160 SpinBox_Rayon->setSingleStep(_Rayon/10.);
161 SpinBox_Rayon->setMinimum(0.);
163 // ------------------------------------------------------------------------
164 bool MonCreateBoundaryAn::PushOnApply()
165 // ------------------------------------------------------------------------
166 // Appele lorsque l'un des boutons Ok ou Apply est presse
169 std::cerr << LEBoundaryName->text().trimmed().toStdString() << std::endl;
170 if (LEBoundaryName->text().trimmed()=="")
172 QMessageBox::information( 0, "Error",
173 "The boundary must be named.",
174 QMessageBox::Ok + QMessageBox::Default );
178 switch (_BoundaryType)
180 case 1 : // il s agit d un cylindre
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()) )
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();
202 case 4 : // il s agit d une sphere
204 if ((_BoundaryAnXcentre != SpinBox_Xcentre->value()) or
205 (_BoundaryAnYcentre != SpinBox_Ycentre->value()) or
206 (_BoundaryAnZcentre != SpinBox_Zcentre->value()) or
207 (_BoundaryAnRayon != SpinBox_Rayon->value()) )
210 _BoundaryAnXcentre=SpinBox_Xcentre->value();
211 _BoundaryAnYcentre=SpinBox_Ycentre->value();
212 _BoundaryAnZcentre=SpinBox_Zcentre->value();
213 _BoundaryAnRayon=SpinBox_Rayon->value();
219 bool bOK = CreateOrUpdateBoundaryAn();
223 // ---------------------------------------------------
224 bool MonCreateBoundaryAn:: CreateOrUpdateBoundaryAn()
225 //----------------------------------------------------
226 // Creation de l'objet boundary
227 // Mise a jour des attributs de la BoundaryAn
230 if (_aBoundaryAnName != LEBoundaryName->text().trimmed())
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);
240 catch( SALOME::SALOME_Exception& S_ex )
242 QMessageBox::information( 0, "Error",
243 QString(CORBA::string_dup(S_ex.details.text)),
244 QMessageBox::Ok + QMessageBox::Default );
248 // Mise en place des attributs
249 aBoundaryAn->SetBoundaryType(_BoundaryType);
250 switch (_BoundaryType)
252 case 1 : // il s agit d un cylindre
254 aBoundaryAn->SetCylinder(_BoundaryAnXcentre, _BoundaryAnYcentre, _BoundaryAnZcentre, _BoundaryAnXaxis, _BoundaryAnYaxis, _BoundaryAnZaxis, _BoundaryAnRayon );
258 case 2 : // il s agit d une sphere
260 aBoundaryAn->SetSphere(_BoundaryAnXcentre, _BoundaryAnYcentre, _BoundaryAnZcentre, _BoundaryAnRayon);
264 aBoundaryAn->SetLimit(_Xincr, _Yincr, _Zincr);
266 HOMARD_UTILS::updateObjBrowser();
269 // ------------------------------------------------------------------------
270 void MonCreateBoundaryAn::PushOnOK()
271 // ------------------------------------------------------------------------
273 if (PushOnApply()) this->close();
275 // ------------------------------------------------------------------------
276 void MonCreateBoundaryAn::PushOnHelp()
277 // ------------------------------------------------------------------------
279 HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html#un-cylindre") ) ;
282 // -----------------------------------
283 void MonCreateBoundaryAn::SetNewBoundaryAnName()
284 // -----------------------------------
286 // Recherche d'un nom par defaut qui n'existe pas encore
288 HOMARD::listeBoundarys_var MyBoundaryAns = _myHomardGen->GetAllBoundarys();
289 int num = 0; QString aBoundaryAnName="";
290 while (aBoundaryAnName=="" )
292 aBoundaryAnName.setNum(num+1) ;
293 aBoundaryAnName.insert(0, QString("Boun_")) ;
294 for ( int i=0; i<MyBoundaryAns->length(); i++)
296 if ( aBoundaryAnName == QString(MyBoundaryAns[i]))
304 LEBoundaryName->clear() ;
305 LEBoundaryName->insert(aBoundaryAnName);
307 // ------------------------------------------------------------------------
308 void MonCreateBoundaryAn::SetCylinder()
309 // ------------------------------------------------------------------------
311 MESSAGE("Debut de SetCylinder")
312 gBCylindre->setVisible(1);
313 gBSphere->setVisible(0);
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")
325 // ------------------------------------------------------------------------
326 void MonCreateBoundaryAn::SetSphere()
327 // ------------------------------------------------------------------------
329 MESSAGE("Debut de SetSphere")
330 gBCylindre->setVisible(0);
331 gBSphere->setVisible(1);
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")