Salome HOME
6e8473be29e934754ef2d3357e0c9dff974798af
[modules/homard.git] / src / HOMARD / HOMARD_Zone.cxx
1 //  HOMARD HOMARD : implementaion of HOMARD idl descriptions
2 //
3 // Copyright (C) 2011-2012  CEA/DEN, EDF R&D
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 //
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 //
21 //  File   : HOMARD_Zone.cxx
22 //  Author : Paul RASCLE, EDF
23 //  Module : HOMARD
24
25 #include "HOMARD_Zone.hxx"
26 #include "utilities.h"
27
28 //=============================================================================
29 /*!
30  *  default constructor:
31  */
32 //=============================================================================
33 HOMARD_Zone::HOMARD_Zone():
34   _Name( "" ),_Type( 2 ),
35   _Xmin( 0 ), _Xmax( 0 ), _Ymin( 0 ), _Ymax( 0 ), _Zmin( 0 ), _Zmax( 0 ),
36   _Xcentre( 0 ), _Ycentre( 0 ), _Zcentre( 0 ), _Rayon( 0 ),
37   _Xaxe( 0 ), _Yaxe( 0 ), _Zaxe( 0 ), _Haut( 0 ),
38   _Xincr( 0 ), _Yincr( 0 ), _Zincr( 0 )
39 {
40   MESSAGE("HOMARD_Zone") ;
41 }
42
43 //=============================================================================
44 HOMARD_Zone::~HOMARD_Zone()
45 {
46   MESSAGE("~HOMARD_Zone") ;
47 }
48
49 //=============================================================================
50 void HOMARD_Zone::SetName( const char* Name )
51 {
52   _Name = std::string( Name ) ;
53 }
54
55 //=============================================================================
56 std::string HOMARD_Zone::GetName() const
57 {
58   return _Name;
59 }
60
61 //=============================================================================
62 std::string HOMARD_Zone::GetDumpPython() const
63 {
64 //   MESSAGE("GetDumpPython avec _Type " << _Type) ;
65 //   MESSAGE("GetDumpPython avec _Name " << _Name) ;
66   std::ostringstream aScript;
67   aScript << "\n# Creation of the ";
68   if ( _Type >= 11 and _Type <= 13 ) { aScript << "rectangle " ; }
69   else if ( _Type == 2 ) { aScript << "box " ;}
70   else if ( _Type >= 31 and _Type <= 33 ) { aScript << "disk " ;}
71   else if ( _Type == 4 ) { aScript << "sphere " ; }
72   else if ( _Type == 5 ) { aScript << "cylinder " ; }
73   else if ( _Type >= 61 and _Type <= 63 ) { aScript << "disk with hole " ;}
74   else if ( _Type == 7 ) { aScript << "pipe " ; }
75   aScript << _Name << "\n" ;
76 //
77   aScript << "\t" << _Name << " = homard.CreateZone" ;
78 //
79   switch (_Type)
80   {
81     case 11:
82     { aScript << "Box2D( \"" << _Name << "\", " << _Xmin << ", " << _Xmax << ", " << _Ymin << ", " << _Ymax << ", 1 )\n";
83       break ;
84     }
85     case 12:
86     { aScript << "Box2D( \"" << _Name << "\", " << _Ymin << ", " << _Ymax << ", " << _Zmin << ", " << _Zmax << ", 2 )\n";
87       break ;
88     }
89     case 13:
90     { aScript << "Box2D( \"" << _Name << "\", " << _Zmin << ", " << _Zmax << ", " << _Xmin << ", " << _Xmax << ", 3 )\n";
91       break ;
92     }
93     case 2:
94     { aScript << "Box( \""  << _Name << "\", " << _Xmin << ", " << _Xmax << ", " << _Ymin << ", " << _Ymax << ", " << _Zmin << ", " << _Zmax << ")\n";
95       break ;
96     }
97
98     case 4:
99     { aScript << "Sphere( \"" << _Name << "\", " << _Xcentre << ", " << _Ycentre << ", " << _Zcentre << ", " << _Rayon << ")\n";
100       break ;
101     }
102
103     case 31:
104     { aScript << "Disk( \"" << _Name << "\", " << _Xcentre << ", " << _Ycentre << ", " << _Rayon << ", 1 )\n";
105       break ;
106     }
107     case 32:
108     { aScript << "Disk( \"" << _Name << "\", " << _Ycentre << ", " << _Zcentre << ", " << _Rayon << ", 2 )\n";
109       break ;
110     }
111     case 33:
112     { aScript << "Disk( \"" << _Name << "\", " << _Zcentre << ", " << _Xcentre << ", " << _Rayon << ", 3 )\n";
113       break ;
114     }
115     case 5:
116     { aScript << "Cylinder( \"" << _Name << "\", " << _Xcentre << ", " << _Ycentre << ", " << _Zcentre << ", " << _Xaxe << ", " << _Yaxe << ", " << _Zaxe << ", " << _Rayon << ", " << _Haut << ")\n";
117       break ;
118     }
119
120     case 61:
121     { aScript << "DiskWithHole( \"" << _Name << "\", " << _Xcentre << ", " << _Ycentre << ", " << _Rayon << ", " << _Rayonint << ", 1 )\n";
122       break ;
123     }
124     case 62:
125     { aScript << "DiskWithHole( \"" << _Name << "\", " << _Ycentre << ", " << _Zcentre << ", " << _Rayon << ", " << _Rayonint << ", 2 )\n";
126       break ;
127     }
128     case 63:
129     { aScript << "DiskWithHole( \"" << _Name << "\", " << _Zcentre << ", " << _Xcentre << ", " << _Rayon << ", " << _Rayonint << ", 3 )\n";
130       break ;
131     }
132     case 7:
133     { aScript << "Pipe( \"" << _Name << "\", " << _Xcentre << ", " << _Ycentre << ", " << _Zcentre << ", " << _Xaxe << ", " << _Yaxe << ", " << _Zaxe << ", " << _Rayon << ", " << _Haut << ", " << _Rayonint << ")\n";
134       break ;
135     }
136   }
137
138   return aScript.str() ;
139 }
140
141 //=============================================================================
142 void HOMARD_Zone::SetType( int Type )
143 {
144   _Type = Type;
145 }
146
147 //=============================================================================
148 int HOMARD_Zone::GetType() const
149 {
150   return _Type;
151 }
152
153 //======================================================================
154 void HOMARD_Zone::SetLimit( double X0, double X1, double X2 )
155 {
156   _Xincr = X0; _Yincr = X1; _Zincr = X2;
157 }
158 //=======================================================================================
159 void HOMARD_Zone::SetBox( double X0, double X1, double X2, double X3, double X4, double X5 )
160 {
161   _Xmin = X0; _Xmax = X1;
162   _Ymin = X2; _Ymax = X3;
163   _Zmin = X4; _Zmax = X5;
164 }
165
166 //======================================================================
167 void HOMARD_Zone::SetSphere( double X0, double X1, double X2, double X3 )
168 {
169   _Xcentre = X0;
170   _Ycentre = X1;
171   _Zcentre = X2;
172   _Rayon = X3;
173 }
174
175 //=======================================================================================
176 void HOMARD_Zone::SetCylinder( double X0, double X1, double X2,
177                                double X3, double X4, double X5, double X6, double X7 )
178 {
179   _Xcentre = X0;
180   _Ycentre = X1;
181   _Zcentre = X2;
182   _Xaxe = X3;
183   _Yaxe = X4;
184   _Zaxe = X5;
185   _Rayon = X6;
186   _Haut = X7;
187 }
188 //=======================================================================================
189 void HOMARD_Zone::SetPipe( double X0, double X1, double X2,
190                            double X3, double X4, double X5, double X6, double X7, double X8 )
191 {
192   _Xcentre = X0;
193   _Ycentre = X1;
194   _Zcentre = X2;
195   _Xaxe = X3;
196   _Yaxe = X4;
197   _Zaxe = X5;
198   _Rayon = X6;
199   _Haut = X7;
200   _Rayonint = X8;
201 }
202
203 //=======================================================================================
204 std::vector<double> HOMARD_Zone::GetLimit() const
205 {
206   std::vector<double> mesLimit;
207   mesLimit.push_back( _Xincr ) ;
208   mesLimit.push_back( _Yincr ) ;
209   mesLimit.push_back( _Zincr ) ;
210   return mesLimit;
211 }
212
213 //=======================================================================================
214 std::vector<double> HOMARD_Zone::GetCoords() const
215 {
216   std::vector<double> mesCoor;
217 //
218   switch (_Type)
219   {
220 //  Rectangle ou parallelepipede
221     case 11:
222     { }
223     case 12:
224     { }
225     case 13:
226     { }
227     case 2:
228     {
229       mesCoor.push_back( _Xmin ) ;
230       mesCoor.push_back( _Xmax ) ;
231       mesCoor.push_back( _Ymin ) ;
232       mesCoor.push_back( _Ymax ) ;
233       mesCoor.push_back( _Zmin ) ;
234       mesCoor.push_back( _Zmax ) ;
235       break ;
236     }
237 //  Sphere
238     case 4:
239     {
240       mesCoor.push_back( _Xcentre ) ;
241       mesCoor.push_back( _Ycentre ) ;
242       mesCoor.push_back( _Zcentre ) ;
243       mesCoor.push_back( _Rayon ) ;
244       break ;
245     }
246 //  Disque ou cylindre
247     case 31:
248     { }
249     case 32:
250     { }
251     case 33:
252     { }
253     case 5:
254     {
255       mesCoor.push_back( _Xcentre ) ;
256       mesCoor.push_back( _Ycentre ) ;
257       mesCoor.push_back( _Zcentre ) ;
258       mesCoor.push_back( _Xaxe ) ;
259       mesCoor.push_back( _Yaxe ) ;
260       mesCoor.push_back( _Zaxe ) ;
261       mesCoor.push_back( _Rayon ) ;
262       mesCoor.push_back( _Haut ) ;
263       break ;
264     }
265 //  Disque avec trou ou tuyau
266     case 61:
267     { }
268     case 62:
269     { }
270     case 63:
271     { }
272     case 7:
273     {
274       mesCoor.push_back( _Xcentre ) ;
275       mesCoor.push_back( _Ycentre ) ;
276       mesCoor.push_back( _Zcentre ) ;
277       mesCoor.push_back( _Xaxe ) ;
278       mesCoor.push_back( _Yaxe ) ;
279       mesCoor.push_back( _Zaxe ) ;
280       mesCoor.push_back( _Rayon ) ;
281       mesCoor.push_back( _Haut ) ;
282       mesCoor.push_back( _Rayonint ) ;
283       break ;
284     }
285     ASSERT ( _Type == -1 ) ;
286   }
287   return mesCoor;
288 }
289
290 //=============================================================================
291 void HOMARD_Zone::AddHypo( const char* NomHypo )
292 {
293   _ListHypo.push_back( std::string( NomHypo ) ) ;
294 }
295
296 //=============================================================================
297 void HOMARD_Zone::SupprHypo( const char* NomHypo )
298 {
299   std::list<std::string>::iterator it = find( _ListHypo.begin(), _ListHypo.end(), NomHypo ) ;
300   if ( it != _ListHypo.end() )
301   {
302     MESSAGE ("Dans SupprHypo pour " << NomHypo) ;
303     _ListHypo.erase( it ) ;
304   }
305 }
306
307 //=============================================================================
308 const std::list<std::string>& HOMARD_Zone::GetHypo() const
309 {
310   return _ListHypo;
311 }
312
313 //=============================================================================
314 void HOMARD_Zone::SupprHypos()
315 {
316   _ListHypo.clear() ;
317 }