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