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