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