]> SALOME platform Git repositories - modules/homard.git/blob - src/HOMARDGUI/MonCreateZone.cxx
Salome HOME
version V6_main 20110308
[modules/homard.git] / src / HOMARDGUI / MonCreateZone.cxx
1 using namespace std;
2
3 #include "MonCreateZone.h"
4 #include "MonCreateHypothesis.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 MonCreateZone::MonCreateZone(MonCreateHypothesis* parent, bool modal,
22                              HOMARD::HOMARD_Gen_var myHomardGen,
23                              QString caseName) :
24 // ------------------------------------------------------------------------------------------------------------------------------
25 /* Constructs a MonCreateZone
26    appele pour une vraie creation
27    initialise une boite et non une sphere
28 */
29     QDialog(0), Ui_CreateZone(),
30     _parent(parent),
31     _aZoneName (""),
32     _aCaseName(caseName),
33     _ZoneType(2),
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),
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", "boxdxyz.png" );
51       QIcon IS2=QIcon(pix2);
52       RBBox->setIcon(IS2);
53
54       InitConnect( );
55
56       SetNewZoneName() ;
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
60     }
61 // --------------------------------------------------------------------------------------------------------------
62 MonCreateZone::MonCreateZone(MonCreateHypothesis* parent,
63                              HOMARD::HOMARD_Gen_var myHomardGen,
64                              QString caseName):
65 // --------------------------------------------------------------------------------------------------------------
66 // Constructeur appele par MonEditZone
67 //
68     QDialog(0), Ui_CreateZone(),
69      _myHomardGen(myHomardGen),
70     _parent(parent),
71     _aZoneName (""),
72     _aCaseName(caseName),
73     _ZoneType(2),
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),
79     Chgt (false)
80     {
81   //  MESSAGE("Debut de  MonCreateZone")
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", "boxdxyz.png" );
88       QIcon IS2=QIcon(pix2);
89       RBBox->setIcon(IS2);
90       setModal(true);
91       InitConnect();
92     }
93
94 // ------------------------------------------------------------------------
95 MonCreateZone::~MonCreateZone()
96 // ------------------------------------------------------------------------
97 {
98     // no need to delete child widgets, Qt does it all for us
99 }
100 // ------------------------------------------------------------------------
101 void MonCreateZone::InitConnect()
102 // ------------------------------------------------------------------------
103 {
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() ) );
110 }
111 // ------------------------------------------------------------------------
112 void MonCreateZone::InitValZone()
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     if ( _Xincr < 0 )
136     {
137       _ZoneXmin = _Xmin;
138       _ZoneXmax = _Xmax;
139     }
140     else
141     {
142       _ZoneXmin = _Xmin - _Xincr;
143       _ZoneXmax = _Xmax + _Xincr;
144     }
145     _Xcentre=(_Xmin + _Xmax)/2.;
146 // en Y
147     if ( _Yincr < 0 )
148     {
149       _ZoneYmin = _Ymin;
150       _ZoneYmax = _Ymax;
151     }
152     else
153     {
154       _ZoneYmin = _Ymin - _Yincr;
155       _ZoneYmax = _Ymax + _Yincr;
156     }
157     _Ycentre=(_Ymin + _Ymax)/2.;
158 // en Z
159     if ( _Zincr < 0 )
160     {
161       _ZoneZmin = _Zmin;
162       _ZoneZmax = _Zmax;
163     }
164     else
165     {
166       _ZoneZmin = _Zmin - _Zincr;
167       _ZoneZmax = _Zmax + _Zincr;
168     }
169     _Zcentre=(_Zmin + _Zmax)/2.;
170 // Rayon
171     _Rayon= _DMax/4.;
172 }
173
174 // ------------------------------------------------------------------------
175 void MonCreateZone::InitMinMax()
176 // ------------------------------------------------------------------------
177 {
178 // en X
179     if ( _Xincr > 0) {
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);
185     }
186     else {
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) ;
192     }
193 // en Y
194     if ( _Yincr > 0) {
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);
200     }
201     else {
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) ;
208     }
209 // en Z
210     if ( _Zincr > 0) {
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);
216     }
217     else {
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) ;
223     }
224 // Rayon
225     SpinBox_Rayon->setSingleStep(_Rayon/10.);
226     SpinBox_Rayon->setMinimum(0.);
227 }
228 // ------------------------------------------------------------------------
229 bool MonCreateZone::PushOnApply()
230 // ------------------------------------------------------------------------
231 // Appele lorsque l'un des boutons Ok ou Apply est presse
232 //
233 {
234   std::cerr << LEZoneName->text().trimmed().toStdString() << std::endl;
235   if (LEZoneName->text().trimmed()=="")
236   {
237     QMessageBox::information( 0, "Error",
238                               "The zone must be named.",
239                               QMessageBox::Ok + QMessageBox::Default );
240     return false;
241   }
242
243   switch (_ZoneType)
244   {
245       case 2 : // il s agit d une boite
246       {
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()) )
250             Chgt = true;
251         break;
252       } 
253
254       case 4 : // il s agit d une sphere
255       {
256         if ((_ZoneXcentre != SpinBox_Xcentre->value()) or (_ZoneYcentre != SpinBox_Ycentre->value()) 
257         or  (_ZoneZcentre != SpinBox_Zcentre->value()) or (_ZoneRayon != SpinBox_Rayon->value()))
258            Chgt = true;
259            break;
260       }
261   }
262
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(); 
266
267   _ZoneXcentre=SpinBox_Xcentre->value();_ZoneYcentre=SpinBox_Ycentre->value();
268   _ZoneZcentre=SpinBox_Zcentre->value();_ZoneRayon=SpinBox_Rayon->value();
269
270   if( _ZoneType == 2 )
271   {
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 );
276       return false; }
277
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 );
282       return false; }
283
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 );
288       return false; }
289   }
290
291   bool bOK = CreateOrUpdateZone();
292   return bOK;
293
294 }
295 // ---------------------------------------------------
296 bool MonCreateZone:: CreateOrUpdateZone()
297 //----------------------------------------------------
298 //  Creation de la zone
299 //  Mise a jour des attributs de la Zone
300
301 {
302   if (_aZoneName != LEZoneName->text().trimmed())
303   {
304     try
305     {
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);
311      }
312      catch( SALOME::SALOME_Exception& S_ex ) 
313      {
314        QMessageBox::information( 0, "Error",
315                 QString(CORBA::string_dup(S_ex.details.text)),
316                 QMessageBox::Ok + QMessageBox::Default );
317        return false;
318      }
319   }
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);
325
326   HOMARD_UTILS::updateObjBrowser();
327   return true;
328 }
329 // ------------------------------------------------------------------------
330 void MonCreateZone::PushOnOK()
331 // ------------------------------------------------------------------------
332 {
333      if (PushOnApply()) this->close();
334 }
335 // ------------------------------------------------------------------------
336 void MonCreateZone::PushOnHelp()
337 // ------------------------------------------------------------------------
338 {
339   HOMARD_UTILS::PushOnHelp(QString("gui_create_zone.html") ) ;
340 }
341
342 // -----------------------------------
343 void MonCreateZone::SetNewZoneName()
344 // -----------------------------------
345 {
346 // Recherche d'un nom par defaut qui n'existe pas encore
347
348   HOMARD::listeZones_var  MyZones = _myHomardGen->GetAllZones();
349   int num = 0; QString aZoneName="";
350   while (aZoneName=="" ) 
351   {
352     aZoneName.setNum(num+1) ;
353     aZoneName.insert(0, QString("Zone_")) ;
354     for ( int i=0; i<MyZones->length(); i++) 
355     {
356       if ( aZoneName ==  QString(MyZones[i])) 
357       {
358           num=num+1;
359           aZoneName="";
360           break;
361       } 
362    } 
363   }
364   LEZoneName->clear() ;
365   LEZoneName->insert(aZoneName);
366 }
367 // ------------------------------------------------------------------------
368 void MonCreateZone::SetBox()
369 // ------------------------------------------------------------------------
370 {
371   gBBox->setVisible(1);
372   gBSphere->setVisible(0);
373   adjustSize();
374   _ZoneType=2;
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
377   if ( _Xincr > 0 ) {
378       SpinBox_Xmini->setValue(_Xcentre-10*_Xincr);
379       SpinBox_Xmaxi->setValue(_Xcentre+10*_Xincr);
380    }
381   if ( _Yincr > 0 ) {
382       SpinBox_Ymini->setValue(_Ycentre-10*_Yincr);
383       SpinBox_Ymaxi->setValue(_Ycentre+10*_Yincr);
384    }
385   if ( _Zincr > 0 ) {
386       SpinBox_Zmini->setValue(_Zcentre-10*_Zincr);
387       SpinBox_Zmaxi->setValue(_Zcentre+10*_Zincr);
388    }
389 }
390 // ------------------------------------------------------------------------
391 void MonCreateZone::SetSphere()
392 // ------------------------------------------------------------------------
393 {
394   MESSAGE("Debut de SetSphere")
395   gBBox->setVisible(0);
396   gBSphere->setVisible(1);
397   adjustSize();
398   _ZoneType=4;
399   if ( _Xincr > 0 ) {
400      SpinBox_Xcentre->setValue(_Xcentre);
401    }
402   if ( _Yincr > 0 ) {
403      SpinBox_Ycentre->setValue(_Ycentre);
404    }
405   if ( _Zincr > 0 ) {
406      SpinBox_Zcentre->setValue(_Zcentre);
407    }
408    SpinBox_Rayon->setValue(_Rayon); 
409 }
410
411