]> SALOME platform Git repositories - modules/homard.git/blob - src/HOMARDGUI/MonCreateZone.cxx
Salome HOME
version 5_1_4 HOMARD_SRC
[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->setMinimum(0.);
226 }
227 // ------------------------------------------------------------------------
228 bool MonCreateZone::PushOnApply()
229 // ------------------------------------------------------------------------
230 // Appele lorsque l'un des boutons Ok ou Apply est presse
231 //
232 {
233   std::cerr << LEZoneName->text().trimmed().toStdString() << std::endl;
234   if (LEZoneName->text().trimmed()=="")
235   {
236     QMessageBox::information( 0, "Error",
237                               "The zone must be named.",
238                               QMessageBox::Ok + QMessageBox::Default );
239     return false;
240   }
241
242   switch (_ZoneType)
243   {
244       case 2 : // il s agit d une boite
245       {
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()) )
249             Chgt = true;
250         break;
251       } 
252
253       case 4 : // il s agit d une sphere
254       {
255         if ((_ZoneXcentre != SpinBox_Xcentre->value()) or (_ZoneYcentre != SpinBox_Ycentre->value()) 
256         or  (_ZoneZcentre != SpinBox_Zcentre->value()) or (_ZoneRayon != SpinBox_Rayon->value()))
257            Chgt = true;
258            break;
259       }
260   }
261
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(); 
265
266   _ZoneXcentre=SpinBox_Xcentre->value();_ZoneYcentre=SpinBox_Ycentre->value();
267   _ZoneZcentre=SpinBox_Zcentre->value();_ZoneRayon=SpinBox_Rayon->value();
268
269   if( _ZoneType == 2 )
270   {
271     if ((_ZoneXmin>= _ZoneXmax) and (_Xincr > 0)) {
272       QMessageBox::information( 0, "Error",
273                QString("X maxi must be greater than X mini."),
274                QMessageBox::Ok + QMessageBox::Default );
275       return false; }
276
277     if  ((_ZoneYmin>= _ZoneYmax) and (_Yincr > 0)) {
278       QMessageBox::information( 0, "Error",
279                   QString("Y maxi must be greater than Y mini."),
280                   QMessageBox::Ok + QMessageBox::Default );
281       return false; }
282
283     if ((_ZoneZmin>= _ZoneZmax) and (_Zincr > 0)) {
284       QMessageBox::information( 0, "Error",
285                     QString("Z maxi must be greater than Z mini."),
286                     QMessageBox::Ok + QMessageBox::Default );
287       return false; }
288   }
289
290   bool bOK = CreateOrUpdateZone();
291   return bOK;
292
293 }
294 // ---------------------------------------------------
295 bool MonCreateZone:: CreateOrUpdateZone()
296 //----------------------------------------------------
297 //  Creation de la zone
298 //  Mise a jour des attributs de la Zone
299
300 {
301   if (_aZoneName != LEZoneName->text().trimmed())
302   {
303     try
304     {
305       _aZoneName = LEZoneName->text().trimmed();
306       aZone = _myHomardGen->CreateZone( \
307               CORBA::string_dup(_aZoneName.toStdString().c_str()), \
308               CORBA::Long(_ZoneType) );
309       _parent->addZone(_aZoneName);
310      }
311      catch( SALOME::SALOME_Exception& S_ex ) 
312      {
313        QMessageBox::information( 0, "Error",
314                 QString(CORBA::string_dup(S_ex.details.text)),
315                 QMessageBox::Ok + QMessageBox::Default );
316        return false;
317      }
318   }
319 // Mise en place des attributs
320   aZone->SetZoneType(_ZoneType);
321   aZone->SetBox(_ZoneXmin, _ZoneXmax, _ZoneYmin, _ZoneYmax, _ZoneZmin, _ZoneZmax);
322   aZone->SetSphere(_ZoneXcentre, _ZoneYcentre, _ZoneZcentre, _ZoneRayon);
323   aZone->SetLimit(_Xincr, _Yincr, _Zincr);
324
325   HOMARD_UTILS::updateObjBrowser();
326   return true;
327 }
328 // ------------------------------------------------------------------------
329 void MonCreateZone::PushOnOK()
330 // ------------------------------------------------------------------------
331 {
332      if (PushOnApply()) this->close();
333 }
334 // ------------------------------------------------------------------------
335 void MonCreateZone::PushOnHelp()
336 // ------------------------------------------------------------------------
337 {
338   HOMARD_UTILS::PushOnHelp(QString("gui_create_zone.html") ) ;
339 }
340
341 // -----------------------------------
342 void MonCreateZone::SetNewZoneName()
343 // -----------------------------------
344 {
345 // Recherche d'un nom par defaut qui n'existe pas encore
346
347   HOMARD::listeZones_var  MyZones = _myHomardGen->GetAllZones();
348   int num = 0; QString aZoneName="";
349   while (aZoneName=="" ) 
350   {
351     aZoneName.setNum(num+1) ;
352     aZoneName.insert(0, QString("Zone_")) ;
353     for ( int i=0; i<MyZones->length(); i++) 
354     {
355       if ( aZoneName ==  QString(MyZones[i])) 
356       {
357           num=num+1;
358           aZoneName="";
359           break;
360       } 
361    } 
362   }
363   LEZoneName->clear() ;
364   LEZoneName->insert(aZoneName);
365 }
366 // ------------------------------------------------------------------------
367 void MonCreateZone::SetBox()
368 // ------------------------------------------------------------------------
369 {
370   gBBox->setVisible(1);
371   gBSphere->setVisible(0);
372   adjustSize();
373   _ZoneType=2;
374 // Sachant que l'increment est le 1/100eme de l'ecart (min/max), cela revient
375 // a initialiser la boite sur une boite 'centrale' comprise entre 2/5 et 3/5
376   if ( _Xincr > 0 ) {
377       SpinBox_Xmini->setValue(_Xcentre-10*_Xincr);
378       SpinBox_Xmaxi->setValue(_Xcentre+10*_Xincr);
379    }
380   if ( _Yincr > 0 ) {
381       SpinBox_Ymini->setValue(_Ycentre-10*_Yincr);
382       SpinBox_Ymaxi->setValue(_Ycentre+10*_Yincr);
383    }
384   if ( _Zincr > 0 ) {
385       SpinBox_Zmini->setValue(_Zcentre-10*_Zincr);
386       SpinBox_Zmaxi->setValue(_Zcentre+10*_Zincr);
387    }
388 }
389 // ------------------------------------------------------------------------
390 void MonCreateZone::SetSphere()
391 // ------------------------------------------------------------------------
392 {
393   MESSAGE("Debut de SetSphere")
394   gBBox->setVisible(0);
395   gBSphere->setVisible(1);
396   adjustSize();
397   _ZoneType=4;
398   if ( _Xincr > 0 ) {
399      SpinBox_Xcentre->setValue(_Xcentre);
400    }
401   if ( _Yincr > 0 ) {
402      SpinBox_Ycentre->setValue(_Ycentre);
403    }
404   if ( _Zincr > 0 ) {
405      SpinBox_Zcentre->setValue(_Zcentre);
406    }
407    SpinBox_Rayon->setValue(_Rayon); 
408 }
409
410