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