Salome HOME
integration of modifications from Gerald Nicolas
[modules/homard.git] / src / HOMARD_I / HOMARD_Cas_i.cxx
1 // Copyright (C) 2011-2012  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Remarques :
20 // L'ordre de description des fonctions est le meme dans tous les fichiers
21 // HOMARD_aaaa.idl, HOMARD_aaaa.hxx, HOMARD_aaaa.cxx, HOMARD_aaaa_i.hxx, HOMARD_aaaa_i.cxx :
22 // 1. Les generalites : Name, Delete, DumpPython, Dump, Restore
23 // 2. Les caracteristiques
24 // 3. Le lien avec les autres structures
25 //
26 // Quand les 2 fonctions Setxxx et Getxxx sont presentes, Setxxx est decrit en premier
27 //
28
29 #include "HOMARD_Cas_i.hxx"
30 #include "HOMARD_Gen_i.hxx"
31 #include "HOMARD_Cas.hxx"
32 #include "HOMARD_DriverTools.hxx"
33
34 #include "utilities.h"
35 #include <vector>
36
37 //=============================================================================
38 /*!
39  *  standard constructor
40  */
41 //=============================================================================
42 HOMARD_Cas_i::HOMARD_Cas_i()
43 {
44   MESSAGE( "Default constructor, not for use" );
45   ASSERT( 0 );
46 }
47
48 //=============================================================================
49 /*!
50  *  standard constructor
51  */
52 //=============================================================================
53 HOMARD_Cas_i::HOMARD_Cas_i( CORBA::ORB_ptr orb,
54                             HOMARD::HOMARD_Gen_var engine )
55 {
56   MESSAGE( "HOMARD_Cas_i" );
57   _gen_i = engine;
58   _orb = orb;
59   myHomardCas = new ::HOMARD_Cas();
60   ASSERT( myHomardCas );
61 }
62
63 //=============================================================================
64 /*!
65  *  standard destructor
66  */
67 //=============================================================================
68 HOMARD_Cas_i::~HOMARD_Cas_i()
69 {
70 }
71 //=============================================================================
72 //=============================================================================
73 // Generalites
74 //=============================================================================
75 //=============================================================================
76 void HOMARD_Cas_i::SetName( const char* Name )
77 {
78   ASSERT( myHomardCas );
79   myHomardCas->SetName( Name );
80 }
81 //=============================================================================
82 char* HOMARD_Cas_i::GetName()
83 {
84   ASSERT( myHomardCas );
85   return CORBA::string_dup( myHomardCas->GetName().c_str() );
86 }
87 //=============================================================================
88 CORBA::Long  HOMARD_Cas_i::Delete()
89 {
90   ASSERT( myHomardCas );
91   char* CaseName = GetName() ;
92   MESSAGE ( "Delete : destruction du cas " << CaseName );
93   return _gen_i->DeleteCase(CaseName) ;
94 }
95 //=============================================================================
96 char* HOMARD_Cas_i::GetDumpPython()
97 {
98   ASSERT( myHomardCas );
99   return CORBA::string_dup( myHomardCas->GetDumpPython().c_str() );
100 }
101 //=============================================================================
102 std::string HOMARD_Cas_i::Dump() const
103 {
104   return HOMARD::Dump( *myHomardCas );
105 }
106 //=============================================================================
107 bool HOMARD_Cas_i::Restore( const std::string& stream )
108 {
109   return HOMARD::Restore( *myHomardCas, stream );
110 }
111 //=============================================================================
112 //=============================================================================
113 // Caracteristiques
114 //=============================================================================
115 //=============================================================================
116 void HOMARD_Cas_i::SetDirName( const char* NomDir )
117 {
118   ASSERT( myHomardCas );
119   myHomardCas->SetDirName( NomDir );
120 }
121 //=============================================================================
122 char* HOMARD_Cas_i::GetDirName()
123 {
124   ASSERT( myHomardCas );
125   return CORBA::string_dup( myHomardCas->GetDirName().c_str() );
126 }
127 //=============================================================================
128 CORBA::Long HOMARD_Cas_i::GetNumber()
129 {
130   ASSERT( myHomardCas );
131   return myHomardCas->GetNumber();
132 }
133 //=============================================================================
134 void HOMARD_Cas_i::SetConfType( CORBA::Long ConfType )
135 {
136   ASSERT( myHomardCas );
137   myHomardCas->SetConfType( ConfType );
138 }
139 //=============================================================================
140 CORBA::Long HOMARD_Cas_i::GetConfType()
141 {
142   ASSERT( myHomardCas );
143   return myHomardCas->GetConfType();
144 }
145 //=============================================================================
146 void HOMARD_Cas_i::SetBoundingBox( const HOMARD::extrema& LesExtrema )
147 {
148   ASSERT( myHomardCas );
149   std::vector<double> VExtrema;
150   ASSERT( LesExtrema.length() == 10 );
151   VExtrema.resize( LesExtrema.length() );
152   for ( int i = 0; i < LesExtrema.length(); i++ )
153   {
154     VExtrema[i] = LesExtrema[i];
155   }
156
157   myHomardCas->SetBoundingBox( VExtrema );
158 }
159 //=============================================================================
160 HOMARD::extrema* HOMARD_Cas_i::GetBoundingBox()
161 {
162   ASSERT(myHomardCas );
163   HOMARD::extrema_var aResult = new HOMARD::extrema();
164   std::vector<double> LesExtremes = myHomardCas->GetBoundingBox();
165   ASSERT( LesExtremes.size() == 10 );
166   aResult->length( 10 );
167   for ( int i = 0; i < LesExtremes.size(); i++ )
168   {
169     aResult[i] = LesExtremes[i];
170   }
171   return aResult._retn();
172 }
173 //=============================================================================
174 void HOMARD_Cas_i::AddGroup( const char* Group)
175 {
176   ASSERT( myHomardCas );
177   myHomardCas->AddGroup( Group );
178 }
179 //=============================================================================
180 void HOMARD_Cas_i::SetGroups( const HOMARD::ListGroupType& ListGroup )
181 {
182   ASSERT( myHomardCas );
183   std::list<std::string> ListString ;
184   for ( int i = 0; i < ListGroup.length(); i++ )
185   {
186     ListString.push_back(std::string(ListGroup[i]));
187   }
188
189   myHomardCas->SetGroups( ListString );
190 }
191 //=============================================================================
192 HOMARD::ListGroupType* HOMARD_Cas_i::GetGroups()
193 {
194   ASSERT(myHomardCas );
195   const std::list<std::string>& ListString = myHomardCas->GetGroups();
196   HOMARD::ListGroupType_var aResult = new HOMARD::ListGroupType();
197   aResult->length( ListString.size() );
198   std::list<std::string>::const_iterator it;
199   int i = 0;
200   for ( it = ListString.begin(); it != ListString.end(); it++ )
201   {
202     aResult[i++] = CORBA::string_dup( (*it).c_str() );
203   }
204   return aResult._retn();
205 }
206 //=============================================================================
207 void HOMARD_Cas_i::AddBoundaryGroup( const char* BoundaryName, const char* Group)
208 {
209   MESSAGE ("AddBoundaryGroup : BoundaryName = "<< BoundaryName << ", Group = " << Group );
210   ASSERT( myHomardCas );
211   // La frontiere est-elle deja enregistree pour ce cas ?
212   const std::list<std::string>& ListBoundaryGroup = myHomardCas->GetBoundaryGroup();
213   std::list<std::string>::const_iterator it;
214   int existe = 0;
215   for ( it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++ )
216   {
217     if ( *it == BoundaryName )
218     { existe = 1 ; }
219     it++ ;
220   }
221   // Enregistrement de la frontiere dans la reference du cas
222   myHomardCas->AddBoundaryGroup( BoundaryName, Group );
223   // Pour une nouvelle frontiere, publication dans l'arbre d'etudes sous le cas
224   if ( existe == 0 )
225   {
226     char* CaseName = GetName() ;
227     MESSAGE ( "AddBoundaryGroup : insertion de la frontiere dans l'arbre de " << CaseName );
228     _gen_i->PublishBoundaryUnderCase(CaseName, BoundaryName) ;
229   }
230 }
231 //=============================================================================
232 HOMARD::ListBoundaryGroupType* HOMARD_Cas_i::GetBoundaryGroup()
233 {
234   MESSAGE ("GetBoundaryGroup");
235   ASSERT(myHomardCas );
236   const std::list<std::string>& ListBoundaryGroup = myHomardCas->GetBoundaryGroup();
237   HOMARD::ListBoundaryGroupType_var aResult = new HOMARD::ListBoundaryGroupType();
238   aResult->length( ListBoundaryGroup.size() );
239   std::list<std::string>::const_iterator it;
240   int i = 0;
241   for ( it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++ )
242   {
243     aResult[i++] = CORBA::string_dup( (*it).c_str() );
244   }
245   return aResult._retn();
246 }
247 //=============================================================================
248 void HOMARD_Cas_i::SetPyram( CORBA::Long Pyram )
249 {
250   MESSAGE ("SetPyram, Pyram = " << Pyram );
251   ASSERT( myHomardCas );
252   myHomardCas->SetPyram( Pyram );
253 }
254 //=============================================================================
255 CORBA::Long HOMARD_Cas_i::GetPyram()
256 {
257   MESSAGE ("GetPyram");
258   ASSERT( myHomardCas );
259   return myHomardCas->GetPyram();
260 }
261 //=============================================================================
262 //=============================================================================
263 // Liens avec les autres structures
264 //=============================================================================
265 //=============================================================================
266 char* HOMARD_Cas_i::GetIter0Name()
267 {
268   ASSERT( myHomardCas );
269   return CORBA::string_dup( myHomardCas->GetIter0Name().c_str() );
270 }
271 //=============================================================================
272 HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::GetIter0()
273 {
274 // Nom de l'iteration parent
275   char* Iter0Name = GetIter0Name() ;
276   MESSAGE ( "GetIter0 : Iter0Name      = " << Iter0Name );
277   return _gen_i->GetIteration(Iter0Name) ;
278 }
279 //=============================================================================
280 HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::NextIteration( const char* IterName )
281 {
282 // Nom de l'iteration parent
283   char* NomIterParent = GetIter0Name() ;
284   MESSAGE ( "NextIteration : IterName      = " << IterName );
285   MESSAGE ( "NextIteration : NomIterParent = " << NomIterParent );
286   return _gen_i->CreateIteration(IterName, NomIterParent) ;
287 }
288 //=============================================================================
289 HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::LastIteration( )
290 {
291   HOMARD::HOMARD_Iteration_ptr Iter ;
292   HOMARD::listeIterFilles_var ListeIterFilles ;
293   char* IterName ;
294 // Iteration initiale du cas
295   IterName = GetIter0Name() ;
296 // On va explorer la descendance de cette iteration initiale
297 // jusqu'a trouver celle qui n'a pas de filles
298   int nbiterfilles = 1 ;
299   while ( nbiterfilles == 1 )
300   {
301 // L'iteration associee
302 //     MESSAGE ( ".. IterName = " << IterName );
303     Iter = _gen_i->GetIteration(IterName) ;
304 // Les filles de cette iteration
305     ListeIterFilles = Iter->GetIterations() ;
306     nbiterfilles = ListeIterFilles->length() ;
307 //     MESSAGE ( ".. nbiterfilles = " << nbiterfilles );
308 // S'il y a au moins 2 filles, arret : on ne sait pas faire
309     ASSERT( nbiterfilles <= 1 ) ;
310 // S'il y a une fille unique, on recupere le nom de la fille et on recommence
311     if ( nbiterfilles == 1 )
312     { IterName = ListeIterFilles[0] ; }
313   }
314 //
315   return Iter ;
316 }
317 //=============================================================================
318 void HOMARD_Cas_i::AddIteration( const char* NomIteration )
319 {
320   ASSERT( myHomardCas );
321   myHomardCas->AddIteration( NomIteration );
322 }