Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/homard.git] / src / HOMARDGUI / MonEditZone.cxx
1 // Copyright (C) 2011-2012  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 using namespace std;
21
22 #include "MonEditZone.h"
23
24 #include "SalomeApp_Tools.h"
25 #include "HOMARDGUI_Utils.h"
26 #include <utilities.h>
27 #include <SUIT_Desktop.h>
28 #include <SUIT_MessageBox.h>
29 #include <SUIT_ResourceMgr.h>
30 #include <SUIT_Session.h>
31 #include <SUIT_ViewManager.h>
32
33
34 // ------------------------------------------------------------------------
35 MonEditZone::MonEditZone( MonCreateHypothesis* parent, bool modal,
36                           HOMARD::HOMARD_Gen_var myHomardGen,
37                           QString caseName, QString zoneName ):
38 // ------------------------------------------------------------------------
39 /* Constructs a MonEditZone
40     herite de MonCreateZone
41 */
42     MonCreateZone(parent, myHomardGen, caseName)
43 {
44     MESSAGE("Debut de MonEditZone pour " << zoneName.toStdString().c_str());
45     setWindowTitle(QObject::tr("HOM_ZONE_EDIT_WINDOW_TITLE"));
46     _aZoneName=zoneName;
47     aZone = _myHomardGen->GetZone(_aZoneName.toStdString().c_str());
48     InitValEdit();
49 }
50 // ------------------------------------------------------------------------
51 MonEditZone::~MonEditZone()
52 // ------------------------------------------------------------------------
53 {
54     // no need to delete child widgets, Qt does it all for us
55 }
56 // ------------------------------------------------------------------------
57 void MonEditZone::InitValEdit()
58 // ------------------------------------------------------------------------
59 {
60   MESSAGE("InitValEdit ");
61   LEZoneName->setText(_aZoneName);
62   LEZoneName->setReadOnly(true);
63   _ZoneType = aZone->GetZoneType();
64   MESSAGE("InitValEdit _ZoneType ="<<_ZoneType);
65   InitValZoneLimit();
66   if (_aCaseName != QString("")) InitValZone();
67   switch (_ZoneType)
68   {
69     case 11 : // il s agit d un rectangle
70     { }
71     case 12 : // il s agit d un rectangle
72     { }
73     case 13 : // il s agit d un rectangle
74     { }
75     case 2 : // il s agit d une boite
76     {
77       InitValZoneBox();
78       SetBox();
79       break;
80     }
81     case 4 : // il s agit d une sphere
82     {
83       InitValZoneSphere();
84       SetSphere();
85       break;
86     }
87     case 31 : // il s agit d un cercle issu d'un cylindre
88     { }
89     case 32 : // il s agit d un cercle issu d'un cylindre
90     { }
91     case 33 : // il s agit d un cercle issu d'un cylindre
92     { }
93     case 5 : // il s agit d un cylindre
94     {
95       InitValZoneCylinder();
96       SetCylinder();
97       break;
98     }
99     case 61 : // il s agit d un disque avec trou issu d'un tuyau
100     { }
101     case 62 : // il s agit d un disque avec trou issu d'un tuyau
102     { }
103     case 63 : // il s agit d un disque avec trou issu d'un tuyau
104     { }
105     case 7 : // il s agit d un tuyau
106     {
107       InitValZonePipe();
108       SetPipe();
109       break;
110     }
111   };
112 }
113 // ------------------------------------------------------------------------
114 void MonEditZone::InitValZoneLimit()
115 // ------------------------------------------------------------------------
116 {
117   HOMARD::double_array_var  mesCoordLimits = aZone->GetLimit();
118   ASSERT(mesCoordLimits->length() == 3 );
119   _Xincr=mesCoordLimits[0];
120   _Yincr=mesCoordLimits[1];
121   _Zincr=mesCoordLimits[2];
122 }
123 // ------------------------------------------------------------------------
124 void MonEditZone::InitValZoneBox()
125 // ------------------------------------------------------------------------
126 {
127   HOMARD::double_array_var  mesCoordZones = aZone->GetCoords();
128   ASSERT(mesCoordZones->length() == 6 );
129   _ZoneXmin=mesCoordZones[0];
130   _ZoneXmax=mesCoordZones[1];
131   _ZoneYmin=mesCoordZones[2];
132   _ZoneYmax=mesCoordZones[3];
133   _ZoneZmin=mesCoordZones[4];
134   _ZoneZmax=mesCoordZones[5];
135 }
136 // ------------------------------------------------------------------------
137 void MonEditZone::InitValZoneSphere()
138 // ------------------------------------------------------------------------
139 {
140   HOMARD::double_array_var  mesCoordZones = aZone->GetCoords();
141   ASSERT(mesCoordZones->length() == 4 );
142   _ZoneXcentre=mesCoordZones[0];
143   _ZoneYcentre=mesCoordZones[1];
144   _ZoneZcentre=mesCoordZones[2];
145   _ZoneRayon=mesCoordZones[3];
146
147 }
148 // ------------------------------------------------------------------------
149 void MonEditZone::InitValZoneCylinder()
150 // ------------------------------------------------------------------------
151 {
152   HOMARD::double_array_var  mesCoordZones = aZone->GetCoords();
153   ASSERT(mesCoordZones->length() == 8 );
154   _ZoneXcentre=mesCoordZones[0];
155   _ZoneYcentre=mesCoordZones[1];
156   _ZoneZcentre=mesCoordZones[2];
157   _ZoneXaxis=mesCoordZones[3];
158   _ZoneYaxis=mesCoordZones[4];
159   _ZoneZaxis=mesCoordZones[5];
160   _ZoneRayon=mesCoordZones[6];
161   _ZoneHaut=mesCoordZones[7];
162 }
163 // ------------------------------------------------------------------------
164 void MonEditZone::InitValZonePipe()
165 // ------------------------------------------------------------------------
166 {
167   HOMARD::double_array_var  mesCoordZones = aZone->GetCoords();
168   ASSERT(mesCoordZones->length() == 9 );
169   _ZoneXcentre=mesCoordZones[0];
170   _ZoneYcentre=mesCoordZones[1];
171   _ZoneZcentre=mesCoordZones[2];
172   _ZoneXaxis=mesCoordZones[3];
173   _ZoneYaxis=mesCoordZones[4];
174   _ZoneZaxis=mesCoordZones[5];
175   _ZoneRayon=mesCoordZones[6];
176   _ZoneHaut=mesCoordZones[7];
177   _ZoneRayonInt=mesCoordZones[8];
178 }
179 // ------------------------------------------------------------------------
180 void MonEditZone::SetBox()
181 // ------------------------------------------------------------------------
182 {
183   MESSAGE("SetBox ");
184   gBBox->setVisible(1);
185   gBSphere->setVisible(0);
186   gBCylindre->setVisible(0) ;
187   gBPipe->setVisible(0) ;
188   RBBox->setChecked(1);
189   adjustSize();
190   RBCylinder->setDisabled(true);
191   RBPipe->setDisabled(true);
192   if ( _ZoneType == 2 ) { RBSphere->setDisabled(true); }
193   else                  { RBSphere->setVisible(0);
194                           RBPipe->setText(QApplication::translate("CreateZone", "Disk with hole", 0, QApplication::UnicodeUTF8));
195                           RBCylinder->setText(QApplication::translate("CreateZone", "Disk", 0, QApplication::UnicodeUTF8));
196                           SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr() ;
197                           QPixmap pix = resMgr->loadPixmap( "HOMARD", "boxdxy.png" ) ;
198                           QIcon IS=QIcon(pix) ;
199                           RBBox->setIcon(IS) ; }
200   adjustSize();
201
202   SpinBox_Xmini->setValue(_ZoneXmin);
203   SpinBox_Xmaxi->setValue(_ZoneXmax);
204
205   double incr ;
206   if ( _Xincr > 0 ) {incr=_Xincr;} else{incr=1.;}
207   SpinBox_Xmini->setSingleStep(incr);
208   SpinBox_Xmaxi->setSingleStep(incr);
209
210   SpinBox_Ymini->setValue(_ZoneYmin);
211   SpinBox_Ymaxi->setValue(_ZoneYmax);
212   if ( _Yincr > 0 ) {incr=_Yincr;} else{incr=1.;}
213   SpinBox_Ymini->setSingleStep(incr);
214   SpinBox_Ymaxi->setSingleStep(incr);
215
216   SpinBox_Zmini->setValue(_ZoneZmin);
217   SpinBox_Zmaxi->setValue(_ZoneZmax);
218   if ( _Zincr > 0 ) {incr=_Zincr;} else{incr=1.;}
219   SpinBox_Zmini->setSingleStep(incr);
220   SpinBox_Zmaxi->setSingleStep(incr);
221
222   if ( _ZoneType == 12 ) { SpinBox_Xmini->setDisabled(true) ;
223                            SpinBox_Xmaxi->setDisabled(true) ; }
224   else if ( _ZoneType == 13 ) { SpinBox_Ymini->setDisabled(true) ;
225                                 SpinBox_Ymaxi->setDisabled(true) ; }
226   else if ( _ZoneType == 11 ) { SpinBox_Zmini->setDisabled(true) ;
227                                 SpinBox_Zmaxi->setDisabled(true) ; }
228
229 }
230 // ------------------------------------------------------------------------
231 void MonEditZone::SetSphere()
232 // ------------------------------------------------------------------------
233 {
234   gBBox->setVisible(0);
235   gBSphere->setVisible(1);
236   gBCylindre->setVisible(0) ;
237   gBPipe->setVisible(0) ;
238   RBSphere->setChecked(1);
239   RBBox->setDisabled(true);
240   RBCylinder->setDisabled(true);
241   RBPipe->setDisabled(true);
242   adjustSize();
243
244   SpinBox_Xcentre->setValue(_ZoneXcentre);
245   if ( _Xincr > 0) { SpinBox_Xcentre->setSingleStep(_Xincr); }
246   else             { SpinBox_Xcentre->setSingleStep(1) ; }
247
248   SpinBox_Ycentre->setValue(_ZoneYcentre);
249   if ( _Yincr > 0) { SpinBox_Ycentre->setSingleStep(_Yincr); }
250   else             { SpinBox_Ycentre->setSingleStep(1) ; }
251
252   SpinBox_Zcentre->setValue(_ZoneZcentre);
253   if ( _Zincr > 0) { SpinBox_Zcentre->setSingleStep(_Zincr); }
254   else             { SpinBox_Zcentre->setSingleStep(1);}
255
256   SpinBox_Rayon->setMinimum(0.);
257   SpinBox_Rayon->setValue(_ZoneRayon);
258 }
259 // ------------------------------------------------------------------------
260 void MonEditZone::SetCylinder()
261 // ------------------------------------------------------------------------
262 {
263   MESSAGE("SetCylinder _Xincr ="<<_Xincr<< " _Yincr ="<<_Yincr<< " _Zincr ="<<_Zincr);
264   gBBox->setVisible(0);
265   gBSphere->setVisible(0);
266   gBCylindre->setVisible(1) ;
267   gBPipe->setVisible(0) ;
268   RBCylinder->setChecked(1);
269   RBBox->setDisabled(true);
270   RBPipe->setDisabled(true);
271   if ( _ZoneType == 5 ) { RBSphere->setDisabled(true); }
272   else                  { RBSphere->setVisible(0);
273                           RBPipe->setText(QApplication::translate("CreateZone", "Disk with hole", 0, QApplication::UnicodeUTF8));
274                           RBCylinder->setText(QApplication::translate("CreateZone", "Disk", 0, QApplication::UnicodeUTF8));
275                           TLXbase->setText(QApplication::translate("CreateZone", "X centre", 0, QApplication::UnicodeUTF8));
276                           TLYbase->setText(QApplication::translate("CreateZone", "Y centre", 0, QApplication::UnicodeUTF8));
277                           TLZbase->setText(QApplication::translate("CreateZone", "Z centre", 0, QApplication::UnicodeUTF8));
278                           SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr() ;
279                           QPixmap pix = resMgr->loadPixmap( "HOMARD", "disk.png" ) ;
280                           QIcon IS=QIcon(pix) ;
281                           RBCylinder->setIcon(IS) ; }
282   adjustSize();
283
284   SpinBox_Xbase->setValue(_ZoneXcentre);
285   if ( _Xincr > 0) { SpinBox_Xbase->setSingleStep(_Xincr); }
286   else             { SpinBox_Xbase->setSingleStep(1) ; }
287
288   SpinBox_Ybase->setValue(_ZoneYcentre);
289   if ( _Yincr > 0) { SpinBox_Ybase->setSingleStep(_Yincr); }
290   else             { SpinBox_Ybase->setSingleStep(1) ; }
291
292   SpinBox_Zbase->setValue(_ZoneZcentre);
293   if ( _Zincr > 0) { SpinBox_Zbase->setSingleStep(_Zincr); }
294   else             { SpinBox_Zbase->setSingleStep(1) ;}
295
296   SpinBox_Radius->setMinimum(0.);
297   SpinBox_Radius->setValue(_ZoneRayon);
298
299   if ( _ZoneType == 5 )
300   { SpinBox_Xaxis->setValue(_ZoneXaxis) ;
301     SpinBox_Yaxis->setValue(_ZoneYaxis) ;
302     SpinBox_Zaxis->setValue(_ZoneZaxis) ;
303     SpinBox_Haut->setValue(_ZoneHaut) ;
304   }
305   else
306   { SpinBox_Xaxis->setVisible(0) ;
307     SpinBox_Yaxis->setVisible(0) ;
308     SpinBox_Zaxis->setVisible(0) ;
309     SpinBox_Haut->setVisible(0) ;
310     TLXaxis->setVisible(0) ;
311     TLYaxis->setVisible(0) ;
312     TLZaxis->setVisible(0) ;
313     TLHaut->setVisible(0) ;
314     if ( _ZoneType == 32 ) { SpinBox_Xbase->setDisabled(true) ; }
315     else if ( _ZoneType == 33 ) { SpinBox_Ybase->setDisabled(true) ; }
316     else if ( _ZoneType == 31 ) { SpinBox_Zbase->setDisabled(true) ; }
317   }
318 }
319 // ------------------------------------------------------------------------
320 void MonEditZone::SetPipe()
321 // ------------------------------------------------------------------------
322 {
323   MESSAGE("SetPipe _Xincr ="<<_Xincr<< " _Yincr ="<<_Yincr<< " _Zincr ="<<_Zincr);
324   gBBox->setVisible(0);
325   gBSphere->setVisible(0);
326   gBCylindre->setVisible(0) ;
327   gBPipe->setVisible(1) ;
328   RBPipe->setChecked(1);
329   RBBox->setDisabled(true);
330   RBCylinder->setDisabled(true);
331   if ( _ZoneType == 7 ) { RBSphere->setDisabled(true); }
332   else                  { RBSphere->setVisible(0);
333                           RBPipe->setText(QApplication::translate("CreateZone", "Disk with hole", 0, QApplication::UnicodeUTF8));
334                           RBCylinder->setText(QApplication::translate("CreateZone", "Disk", 0, QApplication::UnicodeUTF8));
335                           TLXbase_p->setText(QApplication::translate("CreateZone", "X centre", 0, QApplication::UnicodeUTF8));
336                           TLYbase_p->setText(QApplication::translate("CreateZone", "Y centre", 0, QApplication::UnicodeUTF8));
337                           TLZbase_p->setText(QApplication::translate("CreateZone", "Z centre", 0, QApplication::UnicodeUTF8));
338                           SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr() ;
339                           QPixmap pix = resMgr->loadPixmap( "HOMARD", "diskwithhole.png" ) ;
340                           QIcon IS=QIcon(pix) ;
341                           RBPipe->setIcon(IS) ; }
342   adjustSize();
343
344   SpinBox_Xbase_p->setValue(_ZoneXcentre);
345   if ( _Xincr > 0) { SpinBox_Xbase_p->setSingleStep(_Xincr); }
346   else             { SpinBox_Xbase_p->setSingleStep(1) ; }
347
348   SpinBox_Ybase_p->setValue(_ZoneYcentre);
349   if ( _Yincr > 0) { SpinBox_Ybase_p->setSingleStep(_Yincr); }
350   else             { SpinBox_Ybase_p->setSingleStep(1) ; }
351
352   SpinBox_Zbase_p->setValue(_ZoneZcentre);
353   if ( _Zincr > 0) { SpinBox_Zbase_p->setSingleStep(_Zincr); }
354   else             { SpinBox_Zbase_p->setSingleStep(1) ;}
355
356   SpinBox_Radius_int->setMinimum(0.);
357   SpinBox_Radius_int->setValue(_ZoneRayonInt);
358   SpinBox_Radius_ext->setMinimum(0.);
359   SpinBox_Radius_ext->setValue(_ZoneRayon);
360
361   if ( _ZoneType == 7 )
362   { SpinBox_Xaxis_p->setValue(_ZoneXaxis) ;
363     SpinBox_Yaxis_p->setValue(_ZoneYaxis) ;
364     SpinBox_Zaxis_p->setValue(_ZoneZaxis) ;
365     SpinBox_Haut_p->setValue(_ZoneHaut) ;
366   }
367   else
368   { SpinBox_Xaxis_p->setVisible(0) ;
369     SpinBox_Yaxis_p->setVisible(0) ;
370     SpinBox_Zaxis_p->setVisible(0) ;
371     SpinBox_Haut_p->setVisible(0) ;
372     TLXaxis_p->setVisible(0) ;
373     TLYaxis_p->setVisible(0) ;
374     TLZaxis_p->setVisible(0) ;
375     TLHaut_p->setVisible(0) ;
376     if ( _ZoneType == 62 ) { SpinBox_Xbase_p->setDisabled(true) ; }
377     else if ( _ZoneType == 63 ) { SpinBox_Ybase_p->setDisabled(true) ; }
378     else if ( _ZoneType == 61 ) { SpinBox_Zbase_p->setDisabled(true) ; }
379   }
380 }
381
382
383 // ---------------------------------------------------
384 bool MonEditZone::CreateOrUpdateZone()
385 //----------------------------------------------------
386 //  Pas de Creation de la zone
387 //  Mise a jour des attributs de la Zone
388 {
389   try
390   {
391     switch (_ZoneType)
392     {
393       case 11 : // il s agit d un rectangle
394       { }
395       case 12 : // il s agit d un rectangle
396       { }
397       case 13 : // il s agit d un rectangle
398       { }
399       case 2 : // il s agit d un parallelepipede
400       { aZone->SetBox( _ZoneXmin, _ZoneXmax, _ZoneYmin, _ZoneYmax, _ZoneZmin, _ZoneZmax );
401         break;
402       }
403       case 4 : // il s agit d une sphere
404       { aZone->SetSphere( _ZoneXcentre, _ZoneYcentre, _ZoneZcentre, _ZoneRayon );
405         break;
406       }
407       case 31 : // il s agit d un disque issu d'un cylindre
408       { }
409       case 32 : // il s agit d un disque issu d'un cylindre
410       { }
411       case 33 : // il s agit d un disque issu d'un cylindre
412       { }
413       case 5 : // il s agit d un cylindre
414       { aZone->SetCylinder( _ZoneXcentre, _ZoneYcentre, _ZoneZcentre, _ZoneXaxis, _ZoneYaxis, _ZoneZaxis, _ZoneRayon, _ZoneHaut );
415         break;
416       }
417       case 61 : // il s agit d un disque issu d'un cylindre
418       { }
419       case 62 : // il s agit d un disque issu d'un cylindre
420       { }
421       case 63 : // il s agit d un disque issu d'un cylindre
422       { }
423       case 7 : // il s agit d un tuyau
424       { aZone->SetPipe( _ZoneXcentre, _ZoneYcentre, _ZoneZcentre, _ZoneXaxis, _ZoneYaxis, _ZoneZaxis, _ZoneRayon, _ZoneHaut, _ZoneRayonInt );
425         break;
426       }
427     }
428     if (Chgt) _myHomardGen->InvalideZone(_aZoneName.toStdString().c_str());
429     HOMARD_UTILS::updateObjBrowser();
430   }
431   catch( const SALOME::SALOME_Exception& S_ex ) {
432        SalomeApp_Tools::QtCatchCorbaException( S_ex );
433        return false;
434   }
435   return true;
436 }
437