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