Salome HOME
Merge branch 'master' into gni/adaptation
[modules/smesh.git] / src / ADAPTGUI / MonEditBoundaryAn.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 "MonEditBoundaryAn.h"
21
22 #include "SalomeApp_Tools.h"
23 #include "HOMARDGUI_Utils.h"
24 #include <utilities.h>
25
26 using namespace std;
27
28 // ------------------------------------------------------------------------
29 MonEditBoundaryAn::MonEditBoundaryAn( MonCreateCase* parent, bool modal,
30                           ADAPT::ADAPT_Gen_var myAdaptGen,
31                           QString caseName, QString Name ):
32 // ------------------------------------------------------------------------
33 /* Constructs a MonEditBoundaryAn
34     herite de MonCreateBoundaryAn
35 */
36     MonCreateBoundaryAn(parent, myAdaptGen, caseName)
37 {
38     MESSAGE("Debut de MonEditBoundaryAn pour " << Name.toStdString().c_str());
39     setWindowTitle(QObject::tr("HOM_BOUN_A_EDIT_WINDOW_TITLE"));
40     _Name=Name;
41     aBoundaryAn = myAdaptGen->GetBoundary(_Name.toStdString().c_str());
42     InitValEdit();
43 }
44 // ------------------------------------------------------------------------
45 MonEditBoundaryAn::~MonEditBoundaryAn()
46 // ------------------------------------------------------------------------
47 {
48     // no need to delete child widgets, Qt does it all for us
49 }
50 // ------------------------------------------------------------------------
51 void MonEditBoundaryAn::InitValEdit()
52 // ------------------------------------------------------------------------
53 {
54   LEName->setText(_Name);
55   LEName->setReadOnly(true);
56   _Type = aBoundaryAn->GetType();
57   MESSAGE("_Type : "<<_Type);
58   InitValBoundaryAnLimit();
59   if (_aCaseName != QString("")) InitValBoundaryAn();
60   switch (_Type)
61   {
62     case 1 : // il s agit d un cylindre
63     {
64       InitValBoundaryAnCylindre();
65       SetCylinder();
66       break;
67     }
68     case 2: // il s agit d une sphere
69     {
70       InitValBoundaryAnSphere();
71       SetSphere();
72       break;
73     }
74     case 3: // il s agit d un cone defini par un axe et un angle
75     {
76       InitValBoundaryAnConeA();
77       SetConeA();
78       break;
79     }
80     case 4: // il s agit d un cone defini par les 2 rayons
81     {
82       InitValBoundaryAnConeR();
83       SetConeR();
84       break;
85     }
86     case 5: // il s agit d un tore
87     {
88       InitValBoundaryAnTore();
89       SetTore();
90       break;
91     }
92   };
93 }
94 // ------------------------------------------------------------------------
95 void MonEditBoundaryAn::InitValBoundaryAnLimit()
96 // ------------------------------------------------------------------------
97 {
98   ADAPT::double_array_var  mesCoordLimits = aBoundaryAn->GetLimit();
99   ASSERT(mesCoordLimits->length() == 3 );
100   _Xincr=mesCoordLimits[0];
101   _Yincr=mesCoordLimits[1];
102   _Zincr=mesCoordLimits[2];
103 }
104 // ------------------------------------------------------------------------
105 void MonEditBoundaryAn::InitValBoundaryAnCylindre()
106 // ------------------------------------------------------------------------
107 {
108   ADAPT::double_array_var  mesCoordBoundary = aBoundaryAn->GetCoords();
109   ASSERT(mesCoordBoundary->length() == 7 );
110   _BoundaryAnXcentre=mesCoordBoundary[0];
111   _BoundaryAnYcentre=mesCoordBoundary[1];
112   _BoundaryAnZcentre=mesCoordBoundary[2];
113   _BoundaryAnXaxis=mesCoordBoundary[3];
114   _BoundaryAnYaxis=mesCoordBoundary[4];
115   _BoundaryAnZaxis=mesCoordBoundary[5];
116   _BoundaryAnRayon=mesCoordBoundary[6];
117 }
118 // ------------------------------------------------------------------------
119 void MonEditBoundaryAn::InitValBoundaryAnSphere()
120 // ------------------------------------------------------------------------
121 {
122   ADAPT::double_array_var  mesCoordBoundary = aBoundaryAn->GetCoords();
123   ASSERT(mesCoordBoundary->length() == 4 );
124   _BoundaryAnXcentre=mesCoordBoundary[0];
125   _BoundaryAnYcentre=mesCoordBoundary[1];
126   _BoundaryAnZcentre=mesCoordBoundary[2];
127   _BoundaryAnRayon=mesCoordBoundary[3];
128 }
129 // ------------------------------------------------------------------------
130 void MonEditBoundaryAn::InitValBoundaryAnConeA()
131 // ------------------------------------------------------------------------
132 {
133   ADAPT::double_array_var  mesCoordBoundary = aBoundaryAn->GetCoords();
134   ASSERT(mesCoordBoundary->length() == 7 );
135   _BoundaryAnXaxisCone=mesCoordBoundary[0];
136   _BoundaryAnYaxisCone=mesCoordBoundary[1];
137   _BoundaryAnZaxisCone=mesCoordBoundary[2];
138   _BoundaryAngle=mesCoordBoundary[3];
139   _BoundaryAnXorigCone=mesCoordBoundary[4];
140   _BoundaryAnYorigCone=mesCoordBoundary[5];
141   _BoundaryAnZorigCone=mesCoordBoundary[6];
142   convertRayonAngle(-1) ;
143 }
144 // ------------------------------------------------------------------------
145 void MonEditBoundaryAn::InitValBoundaryAnConeR()
146 // ------------------------------------------------------------------------
147 {
148   ADAPT::double_array_var  mesCoordBoundary = aBoundaryAn->GetCoords();
149   ASSERT(mesCoordBoundary->length() == 8 );
150   _BoundaryAnXcone1=mesCoordBoundary[0];
151   _BoundaryAnYcone1=mesCoordBoundary[1];
152   _BoundaryAnZcone1=mesCoordBoundary[2];
153   _BoundaryAnRayon1=mesCoordBoundary[3];
154   _BoundaryAnXcone2=mesCoordBoundary[4];
155   _BoundaryAnYcone2=mesCoordBoundary[5];
156   _BoundaryAnZcone2=mesCoordBoundary[6];
157   _BoundaryAnRayon2=mesCoordBoundary[7];
158   convertRayonAngle(1) ;
159 }
160 // ------------------------------------------------------------------------
161 void MonEditBoundaryAn::InitValBoundaryAnTore()
162 // ------------------------------------------------------------------------
163 {
164   ADAPT::double_array_var  mesCoordBoundary = aBoundaryAn->GetCoords();
165   ASSERT(mesCoordBoundary->length() == 8 );
166   _BoundaryAnXcentre=mesCoordBoundary[0];
167   _BoundaryAnYcentre=mesCoordBoundary[1];
168   _BoundaryAnZcentre=mesCoordBoundary[2];
169   _BoundaryAnXaxis=mesCoordBoundary[3];
170   _BoundaryAnYaxis=mesCoordBoundary[4];
171   _BoundaryAnZaxis=mesCoordBoundary[5];
172   _BoundaryAnRayon1=mesCoordBoundary[6];
173   _BoundaryAnRayon2=mesCoordBoundary[7];
174 }
175 // ------------------------------------------------------------------------
176 void MonEditBoundaryAn::SetCylinder()
177 // ------------------------------------------------------------------------
178 {
179   gBCylindre->setVisible(1);
180   gBSphere->setVisible(0);
181   gBCone->setVisible(0);
182   gBTore->setVisible(0);
183   RBCylindre->setChecked(1);
184   _Type=1;
185   RBSphere->setDisabled(true);
186   RBCone->setDisabled(true);
187   RBTore->setDisabled(true);
188
189   SpinBox_Xcent->setValue(_BoundaryAnXcentre);
190   SpinBox_Ycent->setValue(_BoundaryAnYcentre);
191   SpinBox_Zcent->setValue(_BoundaryAnZcentre);
192
193   SpinBox_Xaxis->setValue(_BoundaryAnXaxis);
194   SpinBox_Yaxis->setValue(_BoundaryAnYaxis);
195   SpinBox_Zaxis->setValue(_BoundaryAnZaxis);
196
197
198   SpinBox_Xaxis->setSingleStep(0.1);
199   SpinBox_Xcentre->setSingleStep(_Xincr);
200   SpinBox_Yaxis->setSingleStep(0.1);
201   SpinBox_Ycentre->setSingleStep(_Yincr);
202   SpinBox_Zaxis->setSingleStep(0.1);
203   SpinBox_Zcentre->setSingleStep(_Zincr);
204 // Rayon
205   SpinBox_Radius->setValue(_BoundaryAnRayon);
206   SpinBox_Radius->setSingleStep(_BoundaryAnRayon/10.);
207 //
208   adjustSize();
209 }
210 // ------------------------------------------------------------------------
211 void MonEditBoundaryAn::SetSphere()
212 // ------------------------------------------------------------------------
213 {
214   gBCylindre->setVisible(0);
215   gBSphere->setVisible(1);
216   RBSphere->setChecked(1);
217   gBCone->setVisible(0);
218   gBTore->setVisible(0);
219   RBCylindre->setDisabled(true);
220   RBCone->setDisabled(true);
221   RBTore->setDisabled(true);
222   _Type=2 ;
223
224   SpinBox_Xcentre->setValue(_BoundaryAnXcentre);
225   if ( _Xincr > 0) { SpinBox_Xcentre->setSingleStep(_Xincr); }
226   else             { SpinBox_Xcentre->setSingleStep(1) ; }
227
228   SpinBox_Ycentre->setValue(_BoundaryAnYcentre);
229   if ( _Yincr > 0) { SpinBox_Ycentre->setSingleStep(_Yincr); }
230   else             { SpinBox_Ycentre->setSingleStep(1) ; }
231
232   SpinBox_Zcentre->setValue(_BoundaryAnZcentre);
233   if ( _Zincr > 0) { SpinBox_Zcentre->setSingleStep(_Zincr); }
234   else             { SpinBox_Zcentre->setSingleStep(1);}
235
236   SpinBox_Rayon->setValue(_BoundaryAnRayon);
237 //
238   adjustSize();
239 }
240 // ------------------------------------------------------------------------
241 void MonEditBoundaryAn::SetConeA()
242 // ------------------------------------------------------------------------
243 {
244   gBCylindre->setVisible(0);
245   gBSphere->setVisible(0);
246   gBCone->setVisible(1);
247   RBCone->setChecked(1);
248   gBTore->setVisible(0);
249   RB_Def_angle->setChecked(1);
250   RBCylindre->setDisabled(true);
251   RBSphere->setDisabled(true);
252   RBTore->setDisabled(true);
253   _Type=3;
254 //
255   TLCone_X1->setText(QApplication::translate("CreateBoundaryAn", "X axis", 0));
256   SpinBox_Cone_X1->setValue(_BoundaryAnXaxisCone);
257   TLCone_Y1->setText(QApplication::translate("CreateBoundaryAn", "Y axis", 0));
258   SpinBox_Cone_Y1->setValue(_BoundaryAnYaxisCone);
259   TLCone_Z1->setText(QApplication::translate("CreateBoundaryAn", "Z axis", 0));
260   SpinBox_Cone_Z1->setValue(_BoundaryAnZaxisCone);
261 //
262   TLCone_X2->setText(QApplication::translate("CreateBoundaryAn", "X centre", 0));
263   SpinBox_Cone_X2->setValue(_BoundaryAnXorigCone);
264   TLCone_Y2->setText(QApplication::translate("CreateBoundaryAn", "Y centre", 0));
265   SpinBox_Cone_Y2->setValue(_BoundaryAnYorigCone);
266   TLCone_Z2->setText(QApplication::translate("CreateBoundaryAn", "Z centre", 0));
267   SpinBox_Cone_Z2->setValue(_BoundaryAnZorigCone);
268 //
269   TLCone_V1->setText(QApplication::translate("CreateBoundaryAn", "Angle", 0));
270   SpinBox_Cone_V1->setValue(_BoundaryAngle);
271   SpinBox_Cone_V1->setSingleStep(1.);
272   SpinBox_Cone_V1->setMaximum(90.);
273 //
274   TLCone_V2->setVisible(0);
275   SpinBox_Cone_V2->setVisible(0);
276 //
277   adjustSize();
278 }
279 // ------------------------------------------------------------------------
280 void MonEditBoundaryAn::SetConeR()
281 // ------------------------------------------------------------------------
282 {
283   gBCylindre->setVisible(0);
284   gBSphere->setVisible(0);
285   gBCone->setVisible(1);
286   gBTore->setVisible(0);
287   RBCone->setChecked(1);
288   RB_Def_radius->setChecked(1);
289   RBCylindre->setDisabled(true);
290   RBSphere->setDisabled(true);
291   RBTore->setDisabled(true);
292   _Type=4;
293 //
294   TLCone_X1->setText(QApplication::translate("CreateBoundaryAn", "X centre 1", 0));
295   SpinBox_Cone_X1->setValue(_BoundaryAnXcone1);
296   TLCone_Y1->setText(QApplication::translate("CreateBoundaryAn", "Y centre 1", 0));
297   SpinBox_Cone_Y1->setValue(_BoundaryAnYcone1);
298   TLCone_Z1->setText(QApplication::translate("CreateBoundaryAn", "Z centre 1", 0));
299   SpinBox_Cone_Z1->setValue(_BoundaryAnZcone1);
300 //
301   TLCone_V1->setText(QApplication::translate("CreateBoundaryAn", "Radius 1", 0));
302   SpinBox_Cone_V1->setSingleStep(_Rayon/10.);
303   SpinBox_Cone_V1->setMaximum(100000.*_DMax);
304   SpinBox_Cone_V1->setValue(_BoundaryAnRayon1);
305 //
306   TLCone_X2->setText(QApplication::translate("CreateBoundaryAn", "X centre 2", 0));
307   SpinBox_Cone_X2->setValue(_BoundaryAnXcone2);
308   TLCone_Y2->setText(QApplication::translate("CreateBoundaryAn", "Y centre 2", 0));
309   SpinBox_Cone_Y2->setValue(_BoundaryAnYcone2);
310   TLCone_Z2->setText(QApplication::translate("CreateBoundaryAn", "Z centre 2", 0));
311   SpinBox_Cone_Z2->setValue(_BoundaryAnZcone2);
312 //
313   TLCone_V2->setVisible(1);
314   SpinBox_Cone_V2->setVisible(1);
315   TLCone_V2->setText(QApplication::translate("CreateBoundaryAn", "Radius 2", 0));
316   SpinBox_Cone_V2->setValue(_BoundaryAnRayon2);
317 //
318   adjustSize();
319 }
320 // ------------------------------------------------------------------------
321 void MonEditBoundaryAn::SetTore()
322 // ------------------------------------------------------------------------
323 {
324   gBCylindre->setVisible(0);
325   gBSphere->setVisible(0);
326   gBCone->setVisible(0);
327   gBTore->setVisible(1);
328   RBTore->setChecked(1);
329   _Type=5;
330   RBCylindre->setDisabled(true);
331   RBSphere->setDisabled(true);
332   RBCone->setDisabled(true);
333
334   SpinBoxToreXcent->setValue(_BoundaryAnXcentre);
335   SpinBoxToreYcent->setValue(_BoundaryAnYcentre);
336   SpinBoxToreZcent->setValue(_BoundaryAnZcentre);
337
338   SpinBoxToreXaxe->setValue(_BoundaryAnXaxis);
339   SpinBoxToreYaxe->setValue(_BoundaryAnYaxis);
340   SpinBoxToreZaxe->setValue(_BoundaryAnZaxis);
341
342
343   SpinBoxToreXaxe->setSingleStep(0.1);
344   SpinBoxToreXcent->setSingleStep(_Xincr);
345   SpinBoxToreYaxe->setSingleStep(0.1);
346   SpinBoxToreYcent->setSingleStep(_Yincr);
347   SpinBoxToreZaxe->setSingleStep(0.1);
348   SpinBoxToreZcent->setSingleStep(_Zincr);
349 // Rayon de revolution
350   SpinBoxToreRRev->setValue(_BoundaryAnRayon1);
351   SpinBoxToreRRev->setSingleStep(_BoundaryAnRayon1/10.);
352 // Rayon primaire
353   SpinBoxToreRPri->setValue(_BoundaryAnRayon2);
354   SpinBoxToreRPri->setSingleStep(_BoundaryAnRayon2/10.);
355 //
356   adjustSize();
357 }
358 // ---------------------------------------------------
359 bool MonEditBoundaryAn::CreateOrUpdateBoundaryAn()
360 //----------------------------------------------------
361 //  Mise a jour des attributs de la BoundaryAn
362 {
363   switch (_Type)
364   {
365     case 1 : // il s agit d un cylindre
366     {
367       aBoundaryAn->SetCylinder(_BoundaryAnXcentre, _BoundaryAnYcentre, _BoundaryAnZcentre, _BoundaryAnXaxis, _BoundaryAnYaxis, _BoundaryAnZaxis, _BoundaryAnRayon );
368       break;
369     }
370     case 2 : // il s agit d une sphere
371     {
372       aBoundaryAn->SetSphere(_BoundaryAnXcentre, _BoundaryAnYcentre, _BoundaryAnZcentre, _BoundaryAnRayon);
373       break;
374     }
375     case 3 : // il s agit d un cone defini par un axe et un angle
376     {
377       aBoundaryAn = myAdaptGen->CreateBoundaryConeA(CORBA::string_dup(_Name.toStdString().c_str()), \
378       _BoundaryAnXaxisCone, _BoundaryAnYaxisCone, _BoundaryAnZaxisCone, _BoundaryAngle, \
379       _BoundaryAnXorigCone, _BoundaryAnYorigCone, _BoundaryAnYorigCone);
380       break;
381     }
382     case 4 : // il s agit d un cone defini par les 2 rayons
383     {
384       aBoundaryAn = myAdaptGen->CreateBoundaryConeR(CORBA::string_dup(_Name.toStdString().c_str()), \
385         _BoundaryAnXcone1, _BoundaryAnYcone1, _BoundaryAnZcone1, _BoundaryAnRayon1, \
386         _BoundaryAnXcone2, _BoundaryAnYcone2, _BoundaryAnZcone2, _BoundaryAnRayon2);
387       break;
388     }
389     case 5 : // il s agit d un tore
390     {
391       aBoundaryAn->SetTorus(_BoundaryAnXcentre, _BoundaryAnYcentre, _BoundaryAnZcentre, _BoundaryAnXaxis, _BoundaryAnYaxis, _BoundaryAnZaxis, _BoundaryAnRayon1, _BoundaryAnRayon2 );
392       break;
393     }
394   }
395   if (Chgt) myAdaptGen->InvalideBoundary(_Name.toStdString().c_str());
396   HOMARD_UTILS::updateObjBrowser();
397   return true;
398 }
399