1 // Copyright (C) 2011-2012 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "MonEditZone.h"
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>
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
42 MonCreateZone(parent, myHomardGen, caseName)
44 MESSAGE("Debut de MonEditZone pour " << zoneName.toStdString().c_str());
45 setWindowTitle(QObject::tr("HOM_ZONE_EDIT_WINDOW_TITLE"));
47 aZone = _myHomardGen->GetZone(_aZoneName.toStdString().c_str());
50 // ------------------------------------------------------------------------
51 MonEditZone::~MonEditZone()
52 // ------------------------------------------------------------------------
54 // no need to delete child widgets, Qt does it all for us
56 // ------------------------------------------------------------------------
57 void MonEditZone::InitValEdit()
58 // ------------------------------------------------------------------------
60 MESSAGE("InitValEdit ");
61 LEZoneName->setText(_aZoneName);
62 LEZoneName->setReadOnly(true);
63 _ZoneType = aZone->GetZoneType();
64 MESSAGE("InitValEdit _ZoneType ="<<_ZoneType);
66 if (_aCaseName != QString("")) InitValZone();
69 case 11 : // il s agit d un rectangle
71 case 12 : // il s agit d un rectangle
73 case 13 : // il s agit d un rectangle
75 case 2 : // il s agit d une boite
81 case 4 : // il s agit d une sphere
87 case 31 : // il s agit d un cercle issu d'un cylindre
89 case 32 : // il s agit d un cercle issu d'un cylindre
91 case 33 : // il s agit d un cercle issu d'un cylindre
93 case 5 : // il s agit d un cylindre
95 InitValZoneCylinder();
99 case 61 : // il s agit d un disque avec trou issu d'un tuyau
101 case 62 : // il s agit d un disque avec trou issu d'un tuyau
103 case 63 : // il s agit d un disque avec trou issu d'un tuyau
105 case 7 : // il s agit d un tuyau
113 // ------------------------------------------------------------------------
114 void MonEditZone::InitValZoneLimit()
115 // ------------------------------------------------------------------------
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];
123 // ------------------------------------------------------------------------
124 void MonEditZone::InitValZoneBox()
125 // ------------------------------------------------------------------------
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];
136 // ------------------------------------------------------------------------
137 void MonEditZone::InitValZoneSphere()
138 // ------------------------------------------------------------------------
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];
148 // ------------------------------------------------------------------------
149 void MonEditZone::InitValZoneCylinder()
150 // ------------------------------------------------------------------------
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];
163 // ------------------------------------------------------------------------
164 void MonEditZone::InitValZonePipe()
165 // ------------------------------------------------------------------------
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];
179 // ------------------------------------------------------------------------
180 void MonEditZone::SetBox()
181 // ------------------------------------------------------------------------
184 gBBox->setVisible(1);
185 gBSphere->setVisible(0);
186 gBCylindre->setVisible(0) ;
187 gBPipe->setVisible(0) ;
188 RBBox->setChecked(1);
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) ; }
202 SpinBox_Xmini->setValue(_ZoneXmin);
203 SpinBox_Xmaxi->setValue(_ZoneXmax);
206 if ( _Xincr > 0 ) {incr=_Xincr;} else{incr=1.;}
207 SpinBox_Xmini->setSingleStep(incr);
208 SpinBox_Xmaxi->setSingleStep(incr);
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);
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);
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) ; }
230 // ------------------------------------------------------------------------
231 void MonEditZone::SetSphere()
232 // ------------------------------------------------------------------------
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);
244 SpinBox_Xcentre->setValue(_ZoneXcentre);
245 if ( _Xincr > 0) { SpinBox_Xcentre->setSingleStep(_Xincr); }
246 else { SpinBox_Xcentre->setSingleStep(1) ; }
248 SpinBox_Ycentre->setValue(_ZoneYcentre);
249 if ( _Yincr > 0) { SpinBox_Ycentre->setSingleStep(_Yincr); }
250 else { SpinBox_Ycentre->setSingleStep(1) ; }
252 SpinBox_Zcentre->setValue(_ZoneZcentre);
253 if ( _Zincr > 0) { SpinBox_Zcentre->setSingleStep(_Zincr); }
254 else { SpinBox_Zcentre->setSingleStep(1);}
256 SpinBox_Rayon->setMinimum(0.);
257 SpinBox_Rayon->setValue(_ZoneRayon);
259 // ------------------------------------------------------------------------
260 void MonEditZone::SetCylinder()
261 // ------------------------------------------------------------------------
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) ; }
284 SpinBox_Xbase->setValue(_ZoneXcentre);
285 if ( _Xincr > 0) { SpinBox_Xbase->setSingleStep(_Xincr); }
286 else { SpinBox_Xbase->setSingleStep(1) ; }
288 SpinBox_Ybase->setValue(_ZoneYcentre);
289 if ( _Yincr > 0) { SpinBox_Ybase->setSingleStep(_Yincr); }
290 else { SpinBox_Ybase->setSingleStep(1) ; }
292 SpinBox_Zbase->setValue(_ZoneZcentre);
293 if ( _Zincr > 0) { SpinBox_Zbase->setSingleStep(_Zincr); }
294 else { SpinBox_Zbase->setSingleStep(1) ;}
296 SpinBox_Radius->setMinimum(0.);
297 SpinBox_Radius->setValue(_ZoneRayon);
299 if ( _ZoneType == 5 )
300 { SpinBox_Xaxis->setValue(_ZoneXaxis) ;
301 SpinBox_Yaxis->setValue(_ZoneYaxis) ;
302 SpinBox_Zaxis->setValue(_ZoneZaxis) ;
303 SpinBox_Haut->setValue(_ZoneHaut) ;
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) ; }
319 // ------------------------------------------------------------------------
320 void MonEditZone::SetPipe()
321 // ------------------------------------------------------------------------
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) ; }
344 SpinBox_Xbase_p->setValue(_ZoneXcentre);
345 if ( _Xincr > 0) { SpinBox_Xbase_p->setSingleStep(_Xincr); }
346 else { SpinBox_Xbase_p->setSingleStep(1) ; }
348 SpinBox_Ybase_p->setValue(_ZoneYcentre);
349 if ( _Yincr > 0) { SpinBox_Ybase_p->setSingleStep(_Yincr); }
350 else { SpinBox_Ybase_p->setSingleStep(1) ; }
352 SpinBox_Zbase_p->setValue(_ZoneZcentre);
353 if ( _Zincr > 0) { SpinBox_Zbase_p->setSingleStep(_Zincr); }
354 else { SpinBox_Zbase_p->setSingleStep(1) ;}
356 SpinBox_Radius_int->setMinimum(0.);
357 SpinBox_Radius_int->setValue(_ZoneRayonInt);
358 SpinBox_Radius_ext->setMinimum(0.);
359 SpinBox_Radius_ext->setValue(_ZoneRayon);
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) ;
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) ; }
383 // ---------------------------------------------------
384 bool MonEditZone::CreateOrUpdateZone()
385 //----------------------------------------------------
386 // Pas de Creation de la zone
387 // Mise a jour des attributs de la Zone
393 case 11 : // il s agit d un rectangle
395 case 12 : // il s agit d un rectangle
397 case 13 : // il s agit d un rectangle
399 case 2 : // il s agit d un parallelepipede
400 { aZone->SetBox( _ZoneXmin, _ZoneXmax, _ZoneYmin, _ZoneYmax, _ZoneZmin, _ZoneZmax );
403 case 4 : // il s agit d une sphere
404 { aZone->SetSphere( _ZoneXcentre, _ZoneYcentre, _ZoneZcentre, _ZoneRayon );
407 case 31 : // il s agit d un disque issu d'un cylindre
409 case 32 : // il s agit d un disque issu d'un cylindre
411 case 33 : // il s agit d un disque issu d'un cylindre
413 case 5 : // il s agit d un cylindre
414 { aZone->SetCylinder( _ZoneXcentre, _ZoneYcentre, _ZoneZcentre, _ZoneXaxis, _ZoneYaxis, _ZoneZaxis, _ZoneRayon, _ZoneHaut );
417 case 61 : // il s agit d un disque issu d'un cylindre
419 case 62 : // il s agit d un disque issu d'un cylindre
421 case 63 : // il s agit d un disque issu d'un cylindre
423 case 7 : // il s agit d un tuyau
424 { aZone->SetPipe( _ZoneXcentre, _ZoneYcentre, _ZoneZcentre, _ZoneXaxis, _ZoneYaxis, _ZoneZaxis, _ZoneRayon, _ZoneHaut, _ZoneRayonInt );
428 if (Chgt) _myHomardGen->InvalideZone(_aZoneName.toStdString().c_str());
429 HOMARD_UTILS::updateObjBrowser();
431 catch( const SALOME::SALOME_Exception& S_ex ) {
432 SalomeApp_Tools::QtCatchCorbaException( S_ex );