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::critical( 0, QObject::tr("HOM_ERROR"),
238 QObject::tr("HOM_ZONE_NAME") );
244 case 2 : // il s agit d une boite
246 if ((_ZoneXmin != SpinBox_Xmini->value()) or (_ZoneXmax != SpinBox_Xmaxi->value()) or
247 (_ZoneYmin != SpinBox_Ymini->value()) or (_ZoneYmax != SpinBox_Ymaxi->value()) or
248 (_ZoneZmin != SpinBox_Zmini->value()) or (_ZoneZmax != SpinBox_Zmaxi->value()) )
253 case 4 : // il s agit d une sphere
255 if ((_ZoneXcentre != SpinBox_Xcentre->value()) or (_ZoneYcentre != SpinBox_Ycentre->value())
256 or (_ZoneZcentre != SpinBox_Zcentre->value()) or (_ZoneRayon != SpinBox_Rayon->value()))
262 _ZoneXmin= SpinBox_Xmini->value(); _ZoneXmax= SpinBox_Xmaxi->value();
263 _ZoneYmin= SpinBox_Ymini->value(); _ZoneYmax= SpinBox_Ymaxi->value();
264 _ZoneZmin= SpinBox_Zmini->value(); _ZoneZmax= SpinBox_Zmaxi->value();
266 _ZoneXcentre=SpinBox_Xcentre->value();_ZoneYcentre=SpinBox_Ycentre->value();
267 _ZoneZcentre=SpinBox_Zcentre->value();_ZoneRayon=SpinBox_Rayon->value();
271 if ((_ZoneXmin>= _ZoneXmax) and (_Xincr > 0)) {
272 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
273 QObject::tr("HOM_ZONE_LIMIT").arg("X") );
276 if ((_ZoneYmin>= _ZoneYmax) and (_Yincr > 0)) {
277 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
278 QObject::tr("HOM_ZONE_LIMIT").arg("Y") );
281 if ((_ZoneZmin>= _ZoneZmax) and (_Zincr > 0)) {
282 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
283 QObject::tr("HOM_ZONE_LIMIT").arg("Z") );
287 bool bOK = CreateOrUpdateZone();
291 // ---------------------------------------------------
292 bool MonCreateZone:: CreateOrUpdateZone()
293 //----------------------------------------------------
294 // Creation de la zone
295 // Mise a jour des attributs de la Zone
298 if (_aZoneName != LEZoneName->text().trimmed())
302 _aZoneName = LEZoneName->text().trimmed();
303 aZone = _myHomardGen->CreateZone( \
304 CORBA::string_dup(_aZoneName.toStdString().c_str()), \
305 CORBA::Long(_ZoneType) );
306 _parent->addZone(_aZoneName);
308 catch( SALOME::SALOME_Exception& S_ex )
310 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
311 QString(CORBA::string_dup(S_ex.details.text)) );
315 // Mise en place des attributs
316 aZone->SetZoneType(_ZoneType);
317 aZone->SetBox(_ZoneXmin, _ZoneXmax, _ZoneYmin, _ZoneYmax, _ZoneZmin, _ZoneZmax);
318 aZone->SetSphere(_ZoneXcentre, _ZoneYcentre, _ZoneZcentre, _ZoneRayon);
319 aZone->SetLimit(_Xincr, _Yincr, _Zincr);
321 HOMARD_UTILS::updateObjBrowser();
324 // ------------------------------------------------------------------------
325 void MonCreateZone::PushOnOK()
326 // ------------------------------------------------------------------------
328 if (PushOnApply()) this->close();
330 // ------------------------------------------------------------------------
331 void MonCreateZone::PushOnHelp()
332 // ------------------------------------------------------------------------
334 HOMARD_UTILS::PushOnHelp(QString("gui_create_zone.html") ) ;
337 // -----------------------------------
338 void MonCreateZone::SetNewZoneName()
339 // -----------------------------------
341 // Recherche d'un nom par defaut qui n'existe pas encore
343 HOMARD::listeZones_var MyZones = _myHomardGen->GetAllZones();
344 int num = 0; QString aZoneName="";
345 while (aZoneName=="" )
347 aZoneName.setNum(num+1) ;
348 aZoneName.insert(0, QString("Zone_")) ;
349 for ( int i=0; i<MyZones->length(); i++)
351 if ( aZoneName == QString(MyZones[i]))
359 LEZoneName->clear() ;
360 LEZoneName->insert(aZoneName);
362 // ------------------------------------------------------------------------
363 void MonCreateZone::SetBox()
364 // ------------------------------------------------------------------------
366 gBBox->setVisible(1);
367 gBSphere->setVisible(0);
370 // Sachant que l'increment est le 1/100eme de l'ecart (min/max), cela revient
371 // a initialiser la boite sur une boite 'centrale' comprise entre 2/5 et 3/5
373 SpinBox_Xmini->setValue(_Xcentre-10*_Xincr);
374 SpinBox_Xmaxi->setValue(_Xcentre+10*_Xincr);
377 SpinBox_Ymini->setValue(_Ycentre-10*_Yincr);
378 SpinBox_Ymaxi->setValue(_Ycentre+10*_Yincr);
381 SpinBox_Zmini->setValue(_Zcentre-10*_Zincr);
382 SpinBox_Zmaxi->setValue(_Zcentre+10*_Zincr);
385 // ------------------------------------------------------------------------
386 void MonCreateZone::SetSphere()
387 // ------------------------------------------------------------------------
389 MESSAGE("Debut de SetSphere")
390 gBBox->setVisible(0);
391 gBSphere->setVisible(1);
395 SpinBox_Xcentre->setValue(_Xcentre);
398 SpinBox_Ycentre->setValue(_Ycentre);
401 SpinBox_Zcentre->setValue(_Zcentre);
403 SpinBox_Rayon->setValue(_Rayon);