3 #include "MonCreateZone.h"
4 #include "MonCreateHypothesis.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 MonCreateZone::MonCreateZone(MonCreateHypothesis* parent, bool modal,
22 HOMARD::HOMARD_Gen_var myHomardGen,
24 // ------------------------------------------------------------------------------------------------------------------------------
25 /* Constructs a MonCreateZone
26 appele pour une vraie creation
27 initialise une boite et non une sphere
29 QDialog(0), Ui_CreateZone(),
34 _Xcentre(0), _Ycentre(0), _Zcentre(0), _Rayon(0),
35 _ZoneXcentre(0), _ZoneYcentre(0), _ZoneZcentre(0), _ZoneRayon(0),
36 _ZoneXmin(0), _ZoneXmax(0), _ZoneYmin(0), _ZoneYmax(0), _ZoneZmin(0), _ZoneZmax(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", "boxdxyz.png" );
51 QIcon IS2=QIcon(pix2);
57 InitValZone(); // Cherche les valeurs de la boite englobante le maillage
58 InitMinMax(); // Initialise les bornes des boutons
59 SetBox(); // Propose une boite en premier choix
61 // --------------------------------------------------------------------------------------------------------------
62 MonCreateZone::MonCreateZone(MonCreateHypothesis* parent,
63 HOMARD::HOMARD_Gen_var myHomardGen,
65 // --------------------------------------------------------------------------------------------------------------
66 // Constructeur appele par MonEditZone
68 QDialog(0), Ui_CreateZone(),
69 _myHomardGen(myHomardGen),
74 _Xcentre(0), _Ycentre(0), _Zcentre(0), _Rayon(0),
75 _ZoneXcentre(0), _ZoneYcentre(0), _ZoneZcentre(0), _ZoneRayon(0),
76 _ZoneXmin(0), _ZoneXmax(0), _ZoneYmin(0), _ZoneYmax(0), _ZoneZmin(0), _ZoneZmax(0),
77 // Pour affichage lors de l edition d une Zone sans nom de Cas
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 MonCreateZone")
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", "boxdxyz.png" );
88 QIcon IS2=QIcon(pix2);
94 // ------------------------------------------------------------------------
95 MonCreateZone::~MonCreateZone()
96 // ------------------------------------------------------------------------
98 // no need to delete child widgets, Qt does it all for us
100 // ------------------------------------------------------------------------
101 void MonCreateZone::InitConnect()
102 // ------------------------------------------------------------------------
104 connect( RBBox, SIGNAL(clicked()) , this, SLOT(SetBox()) ) ;
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 MonCreateZone::InitValZone()
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
142 _ZoneXmin = _Xmin - _Xincr;
143 _ZoneXmax = _Xmax + _Xincr;
145 _Xcentre=(_Xmin + _Xmax)/2.;
154 _ZoneYmin = _Ymin - _Yincr;
155 _ZoneYmax = _Ymax + _Yincr;
157 _Ycentre=(_Ymin + _Ymax)/2.;
166 _ZoneZmin = _Zmin - _Zincr;
167 _ZoneZmax = _Zmax + _Zincr;
169 _Zcentre=(_Zmin + _Zmax)/2.;
174 // ------------------------------------------------------------------------
175 void MonCreateZone::InitMinMax()
176 // ------------------------------------------------------------------------
180 SpinBox_Xmini->setRange(_ZoneXmin,_ZoneXmax);
181 SpinBox_Xmaxi->setRange(_ZoneXmin,_ZoneXmax);
182 SpinBox_Xmini->setSingleStep(_Xincr);
183 SpinBox_Xmaxi->setSingleStep(_Xincr);
184 SpinBox_Xcentre->setSingleStep(_Xincr);
187 SpinBox_Xmini->setValue(_ZoneXmin) ;
188 SpinBox_Xmaxi->setValue(_ZoneXmax) ;
189 SpinBox_Xmini->setEnabled(false) ;
190 SpinBox_Xmaxi->setEnabled(false) ;
191 SpinBox_Xcentre->setEnabled(false) ;
195 SpinBox_Ymini->setRange(_ZoneYmin,_ZoneYmax);
196 SpinBox_Ymaxi->setRange(_ZoneYmin,_ZoneYmax);
197 SpinBox_Ymini->setSingleStep(_Yincr);
198 SpinBox_Ymaxi->setSingleStep(_Yincr);
199 SpinBox_Ycentre->setSingleStep(_Yincr);
202 SpinBox_Ymini->setValue(_ZoneYmin) ;
203 SpinBox_Ymaxi->setValue(_ZoneYmax) ;
204 SpinBox_Ycentre->setValue(_Ycentre);
205 SpinBox_Ymini->setEnabled(false) ;
206 SpinBox_Ymaxi->setEnabled(false) ;
207 SpinBox_Ycentre->setEnabled(false) ;
211 SpinBox_Zmini->setRange(_ZoneZmin,_ZoneZmax);
212 SpinBox_Zmaxi->setRange(_ZoneZmin,_ZoneZmax);
213 SpinBox_Zmini->setSingleStep(_Zincr);
214 SpinBox_Zmaxi->setSingleStep(_Zincr);
215 SpinBox_Zcentre->setSingleStep(_Zincr);
218 SpinBox_Zmini->setValue(_ZoneZmin) ;
219 SpinBox_Zmaxi->setValue(_ZoneZmax) ;
220 SpinBox_Zmini->setEnabled(false) ;
221 SpinBox_Zmaxi->setEnabled(false) ;
222 SpinBox_Zcentre->setEnabled(false) ;
225 SpinBox_Rayon->setSingleStep(_Rayon/10.);
226 SpinBox_Rayon->setMinimum(0.);
228 // ------------------------------------------------------------------------
229 bool MonCreateZone::PushOnApply()
230 // ------------------------------------------------------------------------
231 // Appele lorsque l'un des boutons Ok ou Apply est presse
234 std::cerr << LEZoneName->text().trimmed().toStdString() << std::endl;
235 if (LEZoneName->text().trimmed()=="")
237 QMessageBox::information( 0, "Error",
238 "The zone must be named.",
239 QMessageBox::Ok + QMessageBox::Default );
245 case 2 : // il s agit d une boite
247 if ((_ZoneXmin != SpinBox_Xmini->value()) or (_ZoneXmax != SpinBox_Xmaxi->value()) or
248 (_ZoneYmin != SpinBox_Ymini->value()) or (_ZoneYmax != SpinBox_Ymaxi->value()) or
249 (_ZoneZmin != SpinBox_Zmini->value()) or (_ZoneZmax != SpinBox_Zmaxi->value()) )
254 case 4 : // il s agit d une sphere
256 if ((_ZoneXcentre != SpinBox_Xcentre->value()) or (_ZoneYcentre != SpinBox_Ycentre->value())
257 or (_ZoneZcentre != SpinBox_Zcentre->value()) or (_ZoneRayon != SpinBox_Rayon->value()))
263 _ZoneXmin= SpinBox_Xmini->value(); _ZoneXmax= SpinBox_Xmaxi->value();
264 _ZoneYmin= SpinBox_Ymini->value(); _ZoneYmax= SpinBox_Ymaxi->value();
265 _ZoneZmin= SpinBox_Zmini->value(); _ZoneZmax= SpinBox_Zmaxi->value();
267 _ZoneXcentre=SpinBox_Xcentre->value();_ZoneYcentre=SpinBox_Ycentre->value();
268 _ZoneZcentre=SpinBox_Zcentre->value();_ZoneRayon=SpinBox_Rayon->value();
272 if ((_ZoneXmin>= _ZoneXmax) and (_Xincr > 0)) {
273 QMessageBox::information( 0, "Error",
274 QString("X maxi must be greater than X mini."),
275 QMessageBox::Ok + QMessageBox::Default );
278 if ((_ZoneYmin>= _ZoneYmax) and (_Yincr > 0)) {
279 QMessageBox::information( 0, "Error",
280 QString("Y maxi must be greater than Y mini."),
281 QMessageBox::Ok + QMessageBox::Default );
284 if ((_ZoneZmin>= _ZoneZmax) and (_Zincr > 0)) {
285 QMessageBox::information( 0, "Error",
286 QString("Z maxi must be greater than Z mini."),
287 QMessageBox::Ok + QMessageBox::Default );
291 bool bOK = CreateOrUpdateZone();
295 // ---------------------------------------------------
296 bool MonCreateZone:: CreateOrUpdateZone()
297 //----------------------------------------------------
298 // Creation de la zone
299 // Mise a jour des attributs de la Zone
302 if (_aZoneName != LEZoneName->text().trimmed())
306 _aZoneName = LEZoneName->text().trimmed();
307 aZone = _myHomardGen->CreateZone( \
308 CORBA::string_dup(_aZoneName.toStdString().c_str()), \
309 CORBA::Long(_ZoneType) );
310 _parent->addZone(_aZoneName);
312 catch( SALOME::SALOME_Exception& S_ex )
314 QMessageBox::information( 0, "Error",
315 QString(CORBA::string_dup(S_ex.details.text)),
316 QMessageBox::Ok + QMessageBox::Default );
320 // Mise en place des attributs
321 aZone->SetZoneType(_ZoneType);
322 aZone->SetBox(_ZoneXmin, _ZoneXmax, _ZoneYmin, _ZoneYmax, _ZoneZmin, _ZoneZmax);
323 aZone->SetSphere(_ZoneXcentre, _ZoneYcentre, _ZoneZcentre, _ZoneRayon);
324 aZone->SetLimit(_Xincr, _Yincr, _Zincr);
326 HOMARD_UTILS::updateObjBrowser();
329 // ------------------------------------------------------------------------
330 void MonCreateZone::PushOnOK()
331 // ------------------------------------------------------------------------
333 if (PushOnApply()) this->close();
335 // ------------------------------------------------------------------------
336 void MonCreateZone::PushOnHelp()
337 // ------------------------------------------------------------------------
339 HOMARD_UTILS::PushOnHelp(QString("gui_create_zone.html") ) ;
342 // -----------------------------------
343 void MonCreateZone::SetNewZoneName()
344 // -----------------------------------
346 // Recherche d'un nom par defaut qui n'existe pas encore
348 HOMARD::listeZones_var MyZones = _myHomardGen->GetAllZones();
349 int num = 0; QString aZoneName="";
350 while (aZoneName=="" )
352 aZoneName.setNum(num+1) ;
353 aZoneName.insert(0, QString("Zone_")) ;
354 for ( int i=0; i<MyZones->length(); i++)
356 if ( aZoneName == QString(MyZones[i]))
364 LEZoneName->clear() ;
365 LEZoneName->insert(aZoneName);
367 // ------------------------------------------------------------------------
368 void MonCreateZone::SetBox()
369 // ------------------------------------------------------------------------
371 gBBox->setVisible(1);
372 gBSphere->setVisible(0);
375 // Sachant que l'increment est le 1/100eme de l'ecart (min/max), cela revient
376 // a initialiser la boite sur une boite 'centrale' comprise entre 2/5 et 3/5
378 SpinBox_Xmini->setValue(_Xcentre-10*_Xincr);
379 SpinBox_Xmaxi->setValue(_Xcentre+10*_Xincr);
382 SpinBox_Ymini->setValue(_Ycentre-10*_Yincr);
383 SpinBox_Ymaxi->setValue(_Ycentre+10*_Yincr);
386 SpinBox_Zmini->setValue(_Zcentre-10*_Zincr);
387 SpinBox_Zmaxi->setValue(_Zcentre+10*_Zincr);
390 // ------------------------------------------------------------------------
391 void MonCreateZone::SetSphere()
392 // ------------------------------------------------------------------------
394 MESSAGE("Debut de SetSphere")
395 gBBox->setVisible(0);
396 gBSphere->setVisible(1);
400 SpinBox_Xcentre->setValue(_Xcentre);
403 SpinBox_Ycentre->setValue(_Ycentre);
406 SpinBox_Zcentre->setValue(_Zcentre);
408 SpinBox_Rayon->setValue(_Rayon);