Salome HOME
Création automatique de schémas YACS à partir d'un cas
[modules/homard.git] / src / HOMARD / HOMARD_Hypothesis.cxx
1 //  HOMARD HOMARD : implementation of HOMARD idl descriptions
2 //
3 // Copyright (C) 2011-2013  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_Hypothesis.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_Hypothesis.hxx"
35 #include "utilities.h"
36
37 //=============================================================================
38 /*!
39  *  default constructor:
40  */
41 //=============================================================================
42 HOMARD_Hypothesis::HOMARD_Hypothesis():
43   _Name(""), _NomCasCreation(""),
44   _TypeAdap(-1), _TypeRaff(0), _TypeDera(0),
45   _Field(""),
46   _TypeThR(0), _ThreshR(0),
47   _TypeThC(0), _ThreshC(0),
48   _UsField(0), _UsCmpI(0),  _TypeFieldInterp(0)
49 {
50   MESSAGE("HOMARD_Hypothesis");
51 }
52
53 //=============================================================================
54 /*!
55  */
56 //=============================================================================
57 HOMARD_Hypothesis::~HOMARD_Hypothesis()
58 {
59   MESSAGE("~HOMARD_Hypothesis");
60 }
61 //=============================================================================
62 //=============================================================================
63 // Generalites
64 //=============================================================================
65 //=============================================================================
66 void HOMARD_Hypothesis::SetName( const char* Name )
67 {
68   _Name = std::string( Name );
69 }
70 //=============================================================================
71 std::string HOMARD_Hypothesis::GetName() const
72 {
73   return _Name;
74 }
75 //=============================================================================
76 std::string HOMARD_Hypothesis::GetDumpPython() const
77 {
78   std::ostringstream aScript;
79   aScript << "\n# Creation of the hypothesis " << _Name << "\n" ;
80   aScript << "\t" << _Name << " = homard.CreateHypothesis(\"" << _Name << "\")\n";
81   aScript << "\t" << _Name << ".SetAdapRefinUnRef(" << _TypeAdap << ", " << _TypeRaff << ", " << _TypeDera << ")\n";
82
83 // Raffinement selon des zones geometriques
84   std::list<std::string>::const_iterator it = _ListZone.begin();
85   int TypeUse ;
86   while(it != _ListZone.end())
87   {
88       aScript << "\t" << _Name << ".AddZone(\"" << *it;
89       it++;
90       if ( *it == "1" ) { TypeUse =  1 ; }
91       else              { TypeUse = -1 ; }
92       aScript << "\", " << TypeUse << ")\n";
93       it++;
94   }
95
96 // Raffinement selon un champ
97   if ( _TypeAdap == 1 )
98   {
99     aScript << "\t" << _Name << ".SetField(\"" << _Field << "\")\n";
100     aScript << "\t" << _Name << ".SetUseField(" << _UsField << ")\n";
101     aScript << "\t" << _Name << ".SetUseComp(" << _UsCmpI << ")\n";
102     std::list<std::string>::const_iterator it_comp = _ListComposant.begin();
103     while(it_comp != _ListComposant.end())
104     {
105       aScript << "\t" << _Name << ".AddComp(\"" << *it_comp << "\")\n";
106       it_comp++;
107     }
108     if ( _TypeRaff == 1 )
109     {
110       aScript << "\t" << _Name << ".SetRefinThr(" << _TypeThR << ", " << _ThreshR << ")\n";
111     }
112     if ( _TypeDera == 1 )
113     {
114       aScript << "\t" << _Name << ".SetUnRefThr(" << _TypeThC << ", " << _ThreshC << ")\n";
115     }
116   }
117
118 // Filtrage du raffinement par des groupes
119    for ( it=_ListGroupSelected.begin(); it!=_ListGroupSelected.end();it++)
120        aScript << "\t" << _Name << ".AddGroup(\""  << (*it) <<  "\")\n" ;
121
122 // Interpolation champ
123   aScript << "\t" << _Name << ".SetTypeFieldInterp(" << _TypeFieldInterp << ")\n";
124   if ( _TypeFieldInterp == 2 )
125   {
126     std::list<std::string>::const_iterator it_champ = _ListFieldInterp.begin();
127     while(it_champ != _ListFieldInterp.end())
128     {
129       aScript << "\t" << _Name << ".AddFieldInterp(\"" << *it_champ << "\")\n";
130       it_champ++;
131     }
132   }
133   if ( _NivMax > 0 )
134   {
135     aScript << "\t" <<_Name << ".SetNivMax(" << _NivMax << ")\n";
136   }
137   if ( _DiamMin > 0 )
138   {
139     aScript << "\t" <<_Name << ".SetDiamMin(" << _DiamMin << ")\n";
140   }
141   if ( _AdapInit != 0 )
142   {
143     aScript << "\t" <<_Name << ".SetAdapInit(" << _AdapInit << ")\n";
144   }
145   if ( _LevelOutput != 0 )
146   {
147     aScript << "\t" <<_Name << ".SetLevelOutput(" << _LevelOutput << ")\n";
148   }
149
150   return aScript.str();
151 }
152 //=============================================================================
153 //=============================================================================
154 // Caracteristiques
155 //=============================================================================
156 //=============================================================================
157 void HOMARD_Hypothesis::SetAdapType( int TypeAdap )
158 {
159   ASSERT (!((TypeAdap < -1) or (TypeAdap > 1)));
160   _TypeAdap = TypeAdap;
161 }
162 //=============================================================================
163 int HOMARD_Hypothesis::GetAdapType() const
164 {
165   return _TypeAdap;
166 }
167 //=============================================================================
168 void HOMARD_Hypothesis::SetRefinTypeDera( int TypeRaff, int TypeDera )
169 {
170   ASSERT(!(( TypeRaff < 0) or (TypeRaff > 1)));
171   _TypeRaff = TypeRaff;
172   ASSERT(! ((TypeDera < 0) or (TypeDera > 1)));
173   _TypeDera = TypeDera;
174 }
175 //=============================================================================
176 int HOMARD_Hypothesis::GetRefinType() const
177 {
178   return _TypeRaff;
179 }
180 //=============================================================================
181 int HOMARD_Hypothesis::GetUnRefType() const
182 {
183   return _TypeDera;
184 }
185 //=============================================================================
186 void HOMARD_Hypothesis::SetField( const char* FieldName )
187 {
188   _Field = std::string( FieldName );
189   MESSAGE( "SetField : FieldName = " << FieldName );
190 }
191 //=============================================================================
192 std::string HOMARD_Hypothesis::GetFieldName() const
193 {
194   return _Field;
195 }
196 //=============================================================================
197 void HOMARD_Hypothesis::SetUseField( int UsField )
198 {
199   ASSERT(!((UsField < 0) or (UsField > 1 )));
200   _UsField = UsField;
201 }
202 //=============================================================================
203 int HOMARD_Hypothesis::GetUseField() const
204 {
205   return _UsField;
206 }
207 //=============================================================================
208 void HOMARD_Hypothesis::SetUseComp( int UsCmpI )
209 {
210   ASSERT(!((UsCmpI < 0) or (UsCmpI > 2)));
211   _UsCmpI = UsCmpI;
212 }
213 //=============================================================================
214 int HOMARD_Hypothesis::GetUseComp() const
215 {
216   return _UsCmpI;
217 }
218 //=============================================================================
219 void HOMARD_Hypothesis::AddComp( const char* NomComposant )
220 {
221   _ListComposant.push_back( std::string( NomComposant ) );
222 }
223 //=============================================================================
224 void HOMARD_Hypothesis::SupprComp()
225 {
226   MESSAGE ("SupprComp") ;
227   _ListComposant.clear();
228 }
229 //=============================================================================
230 const std::list<std::string>& HOMARD_Hypothesis::GetListComp() const
231 {
232   return _ListComposant;
233 }
234 //=============================================================================
235 void HOMARD_Hypothesis::SetRefinThr( int TypeThR, double ThreshR )
236 {
237   MESSAGE( "SetRefinThr : TypeThR = " << TypeThR << ", ThreshR = " << ThreshR );
238   ASSERT(!(( TypeThR < 0) or (TypeThR > 4 )));
239   _TypeThR = TypeThR;
240   _ThreshR = ThreshR;
241 }
242 //=============================================================================
243 int HOMARD_Hypothesis::GetRefinThrType() const
244 {
245   return _TypeThR;
246 }
247 //=============================================================================
248 double HOMARD_Hypothesis::GetThreshR() const
249 {
250   return _ThreshR;
251 }
252 //=============================================================================
253 void HOMARD_Hypothesis::SetUnRefThr( int TypeThC, double ThreshC )
254 {
255   ASSERT(!((TypeThC < 0) or (TypeThC > 4)));
256   _TypeThC = TypeThC;
257   _ThreshC = ThreshC;
258 }
259 //=============================================================================
260 int HOMARD_Hypothesis::GetUnRefThrType() const
261 {
262   return _TypeThC;
263 }
264 //=============================================================================
265 double HOMARD_Hypothesis::GetThreshC() const
266 {
267   return _ThreshC;
268 }
269 //=============================================================================
270 void HOMARD_Hypothesis::SetNivMax( int NivMax )
271 //=============================================================================
272 {
273   _NivMax = NivMax;
274 }
275 //=============================================================================
276 const int HOMARD_Hypothesis::GetNivMax() const
277 //=============================================================================
278 {
279   return _NivMax;
280 }
281 //=============================================================================
282 void HOMARD_Hypothesis::SetDiamMin( double DiamMin )
283 //=============================================================================
284 {
285   _DiamMin = DiamMin;
286 }
287 //=============================================================================
288 const double HOMARD_Hypothesis::GetDiamMin() const
289 //=============================================================================
290 {
291   return _DiamMin;
292 }
293 //=============================================================================
294 void HOMARD_Hypothesis::SetAdapInit( int AdapInit )
295 //=============================================================================
296 {
297   _AdapInit = AdapInit;
298 }
299 //=============================================================================
300 const int HOMARD_Hypothesis::GetAdapInit() const
301 //=============================================================================
302 {
303   return _AdapInit;
304 }
305 //=============================================================================
306 void HOMARD_Hypothesis::SetLevelOutput( int LevelOutput )
307 //=============================================================================
308 {
309   _LevelOutput = LevelOutput;
310 }
311 //=============================================================================
312 const int HOMARD_Hypothesis::GetLevelOutput() const
313 //=============================================================================
314 {
315   return _LevelOutput;
316 }
317 //=============================================================================
318 void HOMARD_Hypothesis::AddGroup( const char* Group)
319 {
320   _ListGroupSelected.push_back(Group);
321 }
322 //=============================================================================
323 void HOMARD_Hypothesis::SetGroups( const std::list<std::string>& ListGroup )
324 {
325   _ListGroupSelected.clear();
326   std::list<std::string>::const_iterator it = ListGroup.begin();
327   while(it != ListGroup.end())
328     _ListGroupSelected.push_back((*it++));
329 }
330 //=============================================================================
331 const std::list<std::string>& HOMARD_Hypothesis::GetGroups() const
332 {
333   return _ListGroupSelected;
334 }
335 //=============================================================================
336 void HOMARD_Hypothesis::SetTypeFieldInterp( int TypeFieldInterp )
337 {
338   ASSERT (!((TypeFieldInterp < -1) or (TypeFieldInterp > 2)));
339   _TypeFieldInterp = TypeFieldInterp;
340 }
341 //=============================================================================
342 int HOMARD_Hypothesis::GetTypeFieldInterp() const
343 {
344   return _TypeFieldInterp;
345 }
346 //=============================================================================
347 void HOMARD_Hypothesis::AddFieldInterp( const char* FieldInterp )
348 {
349   _ListFieldInterp.push_back( std::string( FieldInterp ) );
350 }
351 //=============================================================================
352 void HOMARD_Hypothesis::SupprFieldInterp()
353 {
354   MESSAGE ("SupprFieldInterp") ;
355   _ListFieldInterp.clear();
356 }
357 //=============================================================================
358 const std::list<std::string>& HOMARD_Hypothesis::GetListFieldInterp() const
359 {
360   return _ListFieldInterp;
361 }
362 //=============================================================================
363 //=============================================================================
364 // Liens avec les autres structures
365 //=============================================================================
366 //=============================================================================
367 void HOMARD_Hypothesis::SetCaseCreation( const char* NomCasCreation )
368 {
369   _NomCasCreation = std::string( NomCasCreation );
370 }
371 //=============================================================================
372 std::string HOMARD_Hypothesis::GetCaseCreation() const
373 {
374   return _NomCasCreation;
375 }
376 //=============================================================================
377 void HOMARD_Hypothesis::LinkIteration( const char* NomIteration )
378 {
379   _ListIter.push_back( std::string( NomIteration ) );
380 }
381 //=============================================================================
382 void HOMARD_Hypothesis::UnLinkIteration( const char* NomIteration )
383 {
384   std::list<std::string>::iterator it = find( _ListIter.begin(), _ListIter.end(), NomIteration ) ;
385   if ( it != _ListIter.end() )
386   {
387     MESSAGE ("Dans UnLinkIteration pour " << NomIteration) ;
388     it = _ListIter.erase( it ) ;
389   }
390 }
391 //=============================================================================
392 void HOMARD_Hypothesis::UnLinkIterations()
393 {
394   _ListIter.clear();
395 }
396 //=============================================================================
397 const std::list<std::string>& HOMARD_Hypothesis::GetIterations() const
398 {
399   return _ListIter;
400 }
401 //=============================================================================
402 void HOMARD_Hypothesis::AddZone( const char* NomZone, int TypeUse )
403 {
404   MESSAGE ("Dans AddZone pour " << NomZone) ;
405 // On commence par la supprimer au cas ou elle aurait deja ete inseree
406 // Cela peut se produire dans un schema YACS quand on repasse plusieurs fois par la
407 // definition de l'hypothese
408   SupprZone( NomZone ) ;
409 // Insertion veritable
410 // . Nom de la zone
411   _ListZone.push_back( std::string( NomZone ) );
412 // . Usage de la zone
413   std::stringstream saux1 ;
414   saux1 << TypeUse ;
415   _ListZone.push_back( saux1.str() );
416 }
417 //=============================================================================
418 void HOMARD_Hypothesis::SupprZone( const char* NomZone )
419 {
420   MESSAGE ("Dans SupprZone pour " << NomZone) ;
421   std::list<std::string>::iterator it = find( _ListZone.begin(), _ListZone.end(), NomZone );
422 // Attention a supprimer le nom de zone et le type d'usage
423   if ( it != _ListZone.end() )
424   {
425     it = _ListZone.erase( it );
426     it = _ListZone.erase( it );
427   }
428 }
429 //=============================================================================
430 void HOMARD_Hypothesis::SupprZones()
431 {
432   _ListZone.clear();
433 }
434 //=============================================================================
435 const std::list<std::string>& HOMARD_Hypothesis::GetZones() const
436 {
437   return _ListZone;
438 }