Salome HOME
integration of modifications from Gerald Nicolas
[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 // Remarques :
26 // L'ordre de description des fonctions est le meme dans tous les fichiers
27 // HOMARD_aaaa.idl, HOMARD_aaaa.hxx, HOMARD_aaaa.cxx, HOMARD_aaaa_i.hxx, HOMARD_aaaa_i.cxx :
28 // 1. Les generalites : Name, Delete, DumpPython, Dump, Restore
29 // 2. Les caracteristiques
30 // 3. Le lien avec les autres structures
31 //
32 // Quand les 2 fonctions Setxxx et Getxxx sont presentes, Setxxx est decrit en premier
33
34 #include "HOMARD_Zone.hxx"
35 #include "utilities.h"
36
37 //=============================================================================
38 /*!
39  *  default constructor:
40  */
41 //=============================================================================
42 HOMARD_Zone::HOMARD_Zone():
43   _Name( "" ),_Type( 2 ),
44   _Xmin( 0 ), _Xmax( 0 ), _Ymin( 0 ), _Ymax( 0 ), _Zmin( 0 ), _Zmax( 0 ),
45   _Xcentre( 0 ), _Ycentre( 0 ), _Zcentre( 0 ), _Rayon( 0 ),
46   _Xaxe( 0 ), _Yaxe( 0 ), _Zaxe( 0 ), _Haut( 0 ),
47   _Xincr( 0 ), _Yincr( 0 ), _Zincr( 0 )
48 {
49   MESSAGE("HOMARD_Zone") ;
50 }
51
52 //=============================================================================
53 HOMARD_Zone::~HOMARD_Zone()
54 {
55   MESSAGE("~HOMARD_Zone") ;
56 }
57 //=============================================================================
58 //=============================================================================
59 // Generalites
60 //=============================================================================
61 //=============================================================================
62 void HOMARD_Zone::SetName( const char* Name )
63 {
64   _Name = std::string( Name );
65 }
66 //=============================================================================
67 std::string HOMARD_Zone::GetName() const
68 {
69   return _Name;
70 }
71 //=============================================================================
72 std::string HOMARD_Zone::GetDumpPython() const
73 {
74 //   MESSAGE("GetDumpPython avec _Type " << _Type) ;
75 //   MESSAGE("GetDumpPython avec _Name " << _Name) ;
76   std::ostringstream aScript;
77   aScript << "\n# Creation of the ";
78   if ( _Type >= 11 and _Type <= 13 ) { aScript << "rectangle " ; }
79   else if ( _Type == 2 ) { aScript << "box " ;}
80   else if ( _Type >= 31 and _Type <= 33 ) { aScript << "disk " ;}
81   else if ( _Type == 4 ) { aScript << "sphere " ; }
82   else if ( _Type == 5 ) { aScript << "cylinder " ; }
83   else if ( _Type >= 61 and _Type <= 63 ) { aScript << "disk with hole " ;}
84   else if ( _Type == 7 ) { aScript << "pipe " ; }
85   aScript << _Name << "\n" ;
86 //
87   aScript << "\t" << _Name << " = homard.CreateZone" ;
88 //
89   switch (_Type)
90   {
91     case 11:
92     { aScript << "Box2D( \"" << _Name << "\", " << _Xmin << ", " << _Xmax << ", " << _Ymin << ", " << _Ymax << ", 1 )\n";
93       break ;
94     }
95     case 12:
96     { aScript << "Box2D( \"" << _Name << "\", " << _Ymin << ", " << _Ymax << ", " << _Zmin << ", " << _Zmax << ", 2 )\n";
97       break ;
98     }
99     case 13:
100     { aScript << "Box2D( \"" << _Name << "\", " << _Zmin << ", " << _Zmax << ", " << _Xmin << ", " << _Xmax << ", 3 )\n";
101       break ;
102     }
103     case 2:
104     { aScript << "Box( \""  << _Name << "\", " << _Xmin << ", " << _Xmax << ", " << _Ymin << ", " << _Ymax << ", " << _Zmin << ", " << _Zmax << ")\n";
105       break ;
106     }
107
108     case 4:
109     { aScript << "Sphere( \"" << _Name << "\", " << _Xcentre << ", " << _Ycentre << ", " << _Zcentre << ", " << _Rayon << ")\n";
110       break ;
111     }
112
113     case 31:
114     { aScript << "Disk( \"" << _Name << "\", " << _Xcentre << ", " << _Ycentre << ", " << _Rayon << ", 1 )\n";
115       break ;
116     }
117     case 32:
118     { aScript << "Disk( \"" << _Name << "\", " << _Ycentre << ", " << _Zcentre << ", " << _Rayon << ", 2 )\n";
119       break ;
120     }
121     case 33:
122     { aScript << "Disk( \"" << _Name << "\", " << _Zcentre << ", " << _Xcentre << ", " << _Rayon << ", 3 )\n";
123       break ;
124     }
125     case 5:
126     { aScript << "Cylinder( \"" << _Name << "\", " << _Xcentre << ", " << _Ycentre << ", " << _Zcentre << ", " << _Xaxe << ", " << _Yaxe << ", " << _Zaxe << ", " << _Rayon << ", " << _Haut << ")\n";
127       break ;
128     }
129
130     case 61:
131     { aScript << "DiskWithHole( \"" << _Name << "\", " << _Xcentre << ", " << _Ycentre << ", " << _Rayon << ", " << _Rayonint << ", 1 )\n";
132       break ;
133     }
134     case 62:
135     { aScript << "DiskWithHole( \"" << _Name << "\", " << _Ycentre << ", " << _Zcentre << ", " << _Rayon << ", " << _Rayonint << ", 2 )\n";
136       break ;
137     }
138     case 63:
139     { aScript << "DiskWithHole( \"" << _Name << "\", " << _Zcentre << ", " << _Xcentre << ", " << _Rayon << ", " << _Rayonint << ", 3 )\n";
140       break ;
141     }
142     case 7:
143     { aScript << "Pipe( \"" << _Name << "\", " << _Xcentre << ", " << _Ycentre << ", " << _Zcentre << ", " << _Xaxe << ", " << _Yaxe << ", " << _Zaxe << ", " << _Rayon << ", " << _Haut << ", " << _Rayonint << ")\n";
144       break ;
145     }
146   }
147
148   return aScript.str() ;
149 }
150 //=============================================================================
151 //=============================================================================
152 // Caracteristiques
153 //=============================================================================
154 //=============================================================================
155 void HOMARD_Zone::SetType( int Type )
156 {
157   _Type = Type;
158 }
159 //=============================================================================
160 int HOMARD_Zone::GetType() const
161 {
162   return _Type;
163 }
164 //=======================================================================================
165 void HOMARD_Zone::SetBox( double X0, double X1, double X2, double X3, double X4, double X5 )
166 {
167   _Xmin = X0; _Xmax = X1;
168   _Ymin = X2; _Ymax = X3;
169   _Zmin = X4; _Zmax = X5;
170 }
171 //=======================================================================================
172 void HOMARD_Zone::SetCylinder( double X0, double X1, double X2,
173                                double X3, double X4, double X5, double X6, double X7 )
174 {
175   _Xcentre = X0;
176   _Ycentre = X1;
177   _Zcentre = X2;
178   _Xaxe = X3;
179   _Yaxe = X4;
180   _Zaxe = X5;
181   _Rayon = X6;
182   _Haut = X7;
183 }
184 //=======================================================================================
185 void HOMARD_Zone::SetPipe( double X0, double X1, double X2,
186                            double X3, double X4, double X5, double X6, double X7, double X8 )
187 {
188   _Xcentre = X0;
189   _Ycentre = X1;
190   _Zcentre = X2;
191   _Xaxe = X3;
192   _Yaxe = X4;
193   _Zaxe = X5;
194   _Rayon = X6;
195   _Haut = X7;
196   _Rayonint = X8;
197 }
198 //======================================================================
199 void HOMARD_Zone::SetSphere( double X0, double X1, double X2, double X3 )
200 {
201   _Xcentre = X0;
202   _Ycentre = X1;
203   _Zcentre = X2;
204   _Rayon = X3;
205 }
206 //=======================================================================================
207 std::vector<double> HOMARD_Zone::GetCoords() const
208 {
209   std::vector<double> mesCoor;
210 //
211   switch (_Type)
212   {
213 //  Rectangle ou parallelepipede
214     case 11:
215     { }
216     case 12:
217     { }
218     case 13:
219     { }
220     case 2:
221     {
222       mesCoor.push_back( _Xmin ) ;
223       mesCoor.push_back( _Xmax ) ;
224       mesCoor.push_back( _Ymin ) ;
225       mesCoor.push_back( _Ymax ) ;
226       mesCoor.push_back( _Zmin ) ;
227       mesCoor.push_back( _Zmax ) ;
228       break ;
229     }
230 //  Sphere
231     case 4:
232     {
233       mesCoor.push_back( _Xcentre ) ;
234       mesCoor.push_back( _Ycentre ) ;
235       mesCoor.push_back( _Zcentre ) ;
236       mesCoor.push_back( _Rayon ) ;
237       break ;
238     }
239 //  Disque ou cylindre
240     case 31:
241     { }
242     case 32:
243     { }
244     case 33:
245     { }
246     case 5:
247     {
248       mesCoor.push_back( _Xcentre ) ;
249       mesCoor.push_back( _Ycentre ) ;
250       mesCoor.push_back( _Zcentre ) ;
251       mesCoor.push_back( _Xaxe ) ;
252       mesCoor.push_back( _Yaxe ) ;
253       mesCoor.push_back( _Zaxe ) ;
254       mesCoor.push_back( _Rayon ) ;
255       mesCoor.push_back( _Haut ) ;
256       break ;
257     }
258 //  Disque avec trou ou tuyau
259     case 61:
260     { }
261     case 62:
262     { }
263     case 63:
264     { }
265     case 7:
266     {
267       mesCoor.push_back( _Xcentre ) ;
268       mesCoor.push_back( _Ycentre ) ;
269       mesCoor.push_back( _Zcentre ) ;
270       mesCoor.push_back( _Xaxe ) ;
271       mesCoor.push_back( _Yaxe ) ;
272       mesCoor.push_back( _Zaxe ) ;
273       mesCoor.push_back( _Rayon ) ;
274       mesCoor.push_back( _Haut ) ;
275       mesCoor.push_back( _Rayonint ) ;
276       break ;
277     }
278     ASSERT ( _Type == -1 ) ;
279   }
280   return mesCoor;
281 }
282 //======================================================================
283 void HOMARD_Zone::SetLimit( double X0, double X1, double X2 )
284 {
285   _Xincr = X0; _Yincr = X1; _Zincr = X2;
286 }
287 //=======================================================================================
288 std::vector<double> HOMARD_Zone::GetLimit() const
289 {
290   std::vector<double> mesLimit;
291   mesLimit.push_back( _Xincr ) ;
292   mesLimit.push_back( _Yincr ) ;
293   mesLimit.push_back( _Zincr ) ;
294   return mesLimit;
295 }
296 //=============================================================================
297 //=============================================================================
298 // Liens avec les autres structures
299 //=============================================================================
300 //=============================================================================
301 void HOMARD_Zone::AddHypo( const char* NomHypo )
302 {
303   _ListHypo.push_back( std::string( NomHypo ) ) ;
304 }
305 //=============================================================================
306 const std::list<std::string>& HOMARD_Zone::GetHypo() const
307 {
308   return _ListHypo;
309 }
310 //=============================================================================
311 void HOMARD_Zone::SupprHypo( const char* NomHypo )
312 {
313   std::list<std::string>::iterator it = find( _ListHypo.begin(), _ListHypo.end(), NomHypo ) ;
314   if ( it != _ListHypo.end() )
315   {
316     MESSAGE ("Dans SupprHypo pour " << NomHypo) ;
317     _ListHypo.erase( it ) ;
318   }
319 }
320 //=============================================================================
321 void HOMARD_Zone::SupprHypos()
322 {
323   _ListHypo.clear() ;
324 }