Salome HOME
4703c6c84c056d9be4da8cc06660e8c1d842f40b
[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   };
76 }
77 // ------------------------------------------------------------------------
78 void MonEditBoundaryAn::InitValBoundaryAnLimit()
79 // ------------------------------------------------------------------------
80 {
81   HOMARD::double_array_var  mesCoordLimits = aBoundaryAn->GetLimit();
82   ASSERT(mesCoordLimits->length() == 3 );
83   _Xincr=mesCoordLimits[0];
84   _Yincr=mesCoordLimits[1];
85   _Zincr=mesCoordLimits[2];
86 }
87 // ------------------------------------------------------------------------
88 void MonEditBoundaryAn::InitValBoundaryAnCylindre()
89 // ------------------------------------------------------------------------
90 {
91   HOMARD::double_array_var  mesCoordBoundary = aBoundaryAn->GetCoords();
92   ASSERT(mesCoordBoundary->length() == 7 );
93   _BoundaryAnXcentre=mesCoordBoundary[0];
94   _BoundaryAnYcentre=mesCoordBoundary[1];
95   _BoundaryAnZcentre=mesCoordBoundary[2];
96   _BoundaryAnXaxis=mesCoordBoundary[3];
97   _BoundaryAnYaxis=mesCoordBoundary[4];
98   _BoundaryAnZaxis=mesCoordBoundary[5];
99   _BoundaryAnRayon=mesCoordBoundary[6];
100 }
101 // ------------------------------------------------------------------------
102 void MonEditBoundaryAn::InitValBoundaryAnSphere()
103 // ------------------------------------------------------------------------
104 {
105   HOMARD::double_array_var  mesCoordBoundary = aBoundaryAn->GetCoords();
106   ASSERT(mesCoordBoundary->length() == 4 );
107   _BoundaryAnXcentre=mesCoordBoundary[0];
108   _BoundaryAnYcentre=mesCoordBoundary[1];
109   _BoundaryAnZcentre=mesCoordBoundary[2];
110   _BoundaryAnRayon=mesCoordBoundary[3];
111 }
112 // ------------------------------------------------------------------------
113 void MonEditBoundaryAn::SetCylinder()
114 // ------------------------------------------------------------------------
115 {
116   gBCylindre->setVisible(1);
117   gBSphere->setVisible(0);
118   RBCylindre->setChecked(1);
119   adjustSize();
120   _Type=1;
121   RBSphere->setDisabled(true);
122   adjustSize();
123
124   SpinBox_Xcent->setValue(_BoundaryAnXcentre);
125   SpinBox_Ycent->setValue(_BoundaryAnYcentre);
126   SpinBox_Zcent->setValue(_BoundaryAnZcentre);
127
128   SpinBox_Xaxis->setValue(_BoundaryAnXaxis);
129   SpinBox_Yaxis->setValue(_BoundaryAnYaxis);
130   SpinBox_Zaxis->setValue(_BoundaryAnZaxis);
131
132
133   SpinBox_Xaxis->setSingleStep(0.1);
134   SpinBox_Xcentre->setSingleStep(_Xincr);
135   SpinBox_Yaxis->setSingleStep(0.1);
136   SpinBox_Ycentre->setSingleStep(_Yincr);
137   SpinBox_Zaxis->setSingleStep(0.1);
138   SpinBox_Zcentre->setSingleStep(_Zincr);
139 // Rayon
140   SpinBox_Radius->setValue(_BoundaryAnRayon);
141   SpinBox_Radius->setSingleStep(_BoundaryAnRayon/10.);
142
143 }
144 // ------------------------------------------------------------------------
145 void MonEditBoundaryAn::SetSphere()
146 // ------------------------------------------------------------------------
147 {
148   gBCylindre->setVisible(0);
149   gBSphere->setVisible(1);
150   RBSphere->setChecked(1);
151   RBCylindre->setDisabled(true);
152   adjustSize();
153   _Type=2 ;
154
155   SpinBox_Xcentre->setValue(_BoundaryAnXcentre);
156   if ( _Xincr > 0) { SpinBox_Xcentre->setSingleStep(_Xincr); }
157   else             { SpinBox_Xcentre->setSingleStep(1) ; }
158
159   SpinBox_Ycentre->setValue(_BoundaryAnYcentre);
160   if ( _Yincr > 0) { SpinBox_Ycentre->setSingleStep(_Yincr); }
161   else             { SpinBox_Ycentre->setSingleStep(1) ; }
162
163   SpinBox_Zcentre->setValue(_BoundaryAnZcentre);
164   if ( _Zincr > 0) { SpinBox_Zcentre->setSingleStep(_Zincr); }
165   else             { SpinBox_Zcentre->setSingleStep(1);}
166
167   SpinBox_Rayon->setMinimum(0.);
168   SpinBox_Rayon->setValue(_BoundaryAnRayon);
169 }
170 // ---------------------------------------------------
171 bool MonEditBoundaryAn::CreateOrUpdateBoundaryAn()
172 //----------------------------------------------------
173 //  Mise a jour des attributs de la BoundaryAn
174 {
175   switch (_Type)
176   {
177     case 1 : // il s agit d un cylindre
178     {
179       aBoundaryAn->SetCylinder(_BoundaryAnXcentre, _BoundaryAnYcentre, _BoundaryAnZcentre, _BoundaryAnXaxis, _BoundaryAnYaxis, _BoundaryAnZaxis, _BoundaryAnRayon );
180       break;
181     }
182     case 2 : // il s agit d une sphere
183     {
184       aBoundaryAn->SetSphere(_BoundaryAnXcentre, _BoundaryAnYcentre, _BoundaryAnZcentre, _BoundaryAnRayon);
185       break;
186     }
187   }
188   if (Chgt) _myHomardGen->InvalideBoundary(_aName.toStdString().c_str());
189   HOMARD_UTILS::updateObjBrowser();
190   return true;
191 }
192