1 // Copyright (C) 2011-2013 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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
26 // Quand les 2 fonctions Setxxx et Getxxx sont presentes, Setxxx est decrit en premier
29 #include "HOMARD_Cas_i.hxx"
30 #include "HOMARD_Gen_i.hxx"
31 #include "HOMARD_Cas.hxx"
32 #include "HOMARD_DriverTools.hxx"
34 #include "utilities.h"
37 //=============================================================================
39 * standard constructor
41 //=============================================================================
42 HOMARD_Cas_i::HOMARD_Cas_i()
44 MESSAGE( "Default constructor, not for use" );
48 //=============================================================================
50 * standard constructor
52 //=============================================================================
53 HOMARD_Cas_i::HOMARD_Cas_i( CORBA::ORB_ptr orb,
54 HOMARD::HOMARD_Gen_var engine )
56 MESSAGE( "HOMARD_Cas_i" );
59 myHomardCas = new ::HOMARD_Cas();
60 ASSERT( myHomardCas );
63 //=============================================================================
67 //=============================================================================
68 HOMARD_Cas_i::~HOMARD_Cas_i()
71 //=============================================================================
72 //=============================================================================
74 //=============================================================================
75 //=============================================================================
76 void HOMARD_Cas_i::SetName( const char* Name )
78 ASSERT( myHomardCas );
79 myHomardCas->SetName( Name );
81 //=============================================================================
82 char* HOMARD_Cas_i::GetName()
84 ASSERT( myHomardCas );
85 return CORBA::string_dup( myHomardCas->GetName().c_str() );
87 //=============================================================================
88 CORBA::Long HOMARD_Cas_i::Delete()
90 ASSERT( myHomardCas );
91 char* CaseName = GetName() ;
92 MESSAGE ( "Delete : destruction du cas " << CaseName );
93 return _gen_i->DeleteCase(CaseName) ;
95 //=============================================================================
96 char* HOMARD_Cas_i::GetDumpPython()
98 ASSERT( myHomardCas );
99 return CORBA::string_dup( myHomardCas->GetDumpPython().c_str() );
101 //=============================================================================
102 std::string HOMARD_Cas_i::Dump() const
104 return HOMARD::Dump( *myHomardCas );
106 //=============================================================================
107 bool HOMARD_Cas_i::Restore( const std::string& stream )
109 return HOMARD::Restore( *myHomardCas, stream );
111 //=============================================================================
112 //=============================================================================
114 //=============================================================================
115 //=============================================================================
116 void HOMARD_Cas_i::SetDirName( const char* NomDir )
118 ASSERT( myHomardCas );
120 // A. Changement/creation du repertoire
121 char* oldrep = GetDirName() ;
122 codret = myHomardCas->SetDirName( NomDir );
125 SALOME::ExceptionStruct es;
126 es.type = SALOME::BAD_PARAM;
128 if ( codret == 1 ) { text = "The directory for the case cannot be modified because some iterations are already defined." ; }
129 else { text = "The directory for the case cannot be reached." ; }
130 es.text = CORBA::string_dup(text.c_str());
131 throw SALOME::SALOME_Exception(es);
133 // B. En cas de reprise, deplacement du point de depart
134 if ( GetState() != 0 )
136 MESSAGE ( "etat : " << GetState() ) ;
137 char* Iter0Name = GetIter0Name() ;
138 HOMARD::HOMARD_Iteration_ptr Iter = _gen_i->GetIteration(Iter0Name) ;
139 char* DirNameIter = Iter->GetDirName() ;
140 std::string commande = "mv " + std::string(oldrep) + "/" + std::string(DirNameIter) + " " + std::string(NomDir) ;
141 codret = system(commande.c_str()) ;
144 SALOME::ExceptionStruct es;
145 es.type = SALOME::BAD_PARAM;
146 std::string text = "The starting point for the case cannot be moved into the new directory." ;
147 es.text = CORBA::string_dup(text.c_str());
148 throw SALOME::SALOME_Exception(es);
153 //=============================================================================
154 char* HOMARD_Cas_i::GetDirName()
156 ASSERT( myHomardCas );
157 return CORBA::string_dup( myHomardCas->GetDirName().c_str() );
159 //=============================================================================
160 CORBA::Long HOMARD_Cas_i::GetState()
162 ASSERT( myHomardCas );
163 // Nom de l'iteration initiale
164 char* Iter0Name = GetIter0Name() ;
165 HOMARD::HOMARD_Iteration_ptr Iter = _gen_i->GetIteration(Iter0Name) ;
166 int state = Iter->GetNumber() ;
169 //=============================================================================
170 CORBA::Long HOMARD_Cas_i::GetNumberofIter()
172 ASSERT( myHomardCas );
173 return myHomardCas->GetNumberofIter();
175 //=============================================================================
176 void HOMARD_Cas_i::SetConfType( CORBA::Long ConfType )
178 ASSERT( myHomardCas );
179 myHomardCas->SetConfType( ConfType );
181 //=============================================================================
182 CORBA::Long HOMARD_Cas_i::GetConfType()
184 ASSERT( myHomardCas );
185 return myHomardCas->GetConfType();
187 //=============================================================================
188 void HOMARD_Cas_i::SetBoundingBox( const HOMARD::extrema& LesExtrema )
190 ASSERT( myHomardCas );
191 std::vector<double> VExtrema;
192 ASSERT( LesExtrema.length() == 10 );
193 VExtrema.resize( LesExtrema.length() );
194 for ( int i = 0; i < LesExtrema.length(); i++ )
196 VExtrema[i] = LesExtrema[i];
198 myHomardCas->SetBoundingBox( VExtrema );
200 //=============================================================================
201 HOMARD::extrema* HOMARD_Cas_i::GetBoundingBox()
203 ASSERT(myHomardCas );
204 HOMARD::extrema_var aResult = new HOMARD::extrema();
205 std::vector<double> LesExtremes = myHomardCas->GetBoundingBox();
206 ASSERT( LesExtremes.size() == 10 );
207 aResult->length( 10 );
208 for ( int i = 0; i < LesExtremes.size(); i++ )
210 aResult[i] = LesExtremes[i];
212 return aResult._retn();
214 //=============================================================================
215 void HOMARD_Cas_i::AddGroup( const char* Group)
217 ASSERT( myHomardCas );
218 myHomardCas->AddGroup( Group );
220 //=============================================================================
221 void HOMARD_Cas_i::SetGroups( const HOMARD::ListGroupType& ListGroup )
223 ASSERT( myHomardCas );
224 std::list<std::string> ListString ;
225 for ( int i = 0; i < ListGroup.length(); i++ )
227 ListString.push_back(std::string(ListGroup[i]));
229 myHomardCas->SetGroups( ListString );
231 //=============================================================================
232 HOMARD::ListGroupType* HOMARD_Cas_i::GetGroups()
234 ASSERT(myHomardCas );
235 const std::list<std::string>& ListString = myHomardCas->GetGroups();
236 HOMARD::ListGroupType_var aResult = new HOMARD::ListGroupType();
237 aResult->length( ListString.size() );
238 std::list<std::string>::const_iterator it;
240 for ( it = ListString.begin(); it != ListString.end(); it++ )
242 aResult[i++] = CORBA::string_dup( (*it).c_str() );
244 return aResult._retn();
246 //=============================================================================
247 void HOMARD_Cas_i::AddBoundaryGroup( const char* BoundaryName, const char* Group)
249 MESSAGE ("AddBoundaryGroup : BoundaryName = "<< BoundaryName << ", Group = " << Group );
250 ASSERT( myHomardCas );
251 // La frontiere est-elle deja enregistree pour ce cas ?
252 const std::list<std::string>& ListBoundaryGroup = myHomardCas->GetBoundaryGroup();
253 std::list<std::string>::const_iterator it;
255 for ( it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++ )
257 if ( *it == BoundaryName )
261 // Enregistrement de la frontiere dans la reference du cas
262 myHomardCas->AddBoundaryGroup( BoundaryName, Group );
263 // Pour une nouvelle frontiere, publication dans l'arbre d'etudes sous le cas
266 char* CaseName = GetName() ;
267 MESSAGE ( "AddBoundaryGroup : insertion de la frontiere dans l'arbre de " << CaseName );
268 _gen_i->PublishBoundaryUnderCase(CaseName, BoundaryName) ;
271 //=============================================================================
272 HOMARD::ListBoundaryGroupType* HOMARD_Cas_i::GetBoundaryGroup()
274 MESSAGE ("GetBoundaryGroup");
275 ASSERT(myHomardCas );
276 const std::list<std::string>& ListBoundaryGroup = myHomardCas->GetBoundaryGroup();
277 HOMARD::ListBoundaryGroupType_var aResult = new HOMARD::ListBoundaryGroupType();
278 aResult->length( ListBoundaryGroup.size() );
279 std::list<std::string>::const_iterator it;
281 for ( it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++ )
283 aResult[i++] = CORBA::string_dup( (*it).c_str() );
285 return aResult._retn();
287 //=============================================================================
288 void HOMARD_Cas_i::SetPyram( CORBA::Long Pyram )
290 MESSAGE ("SetPyram, Pyram = " << Pyram );
291 ASSERT( myHomardCas );
292 myHomardCas->SetPyram( Pyram );
294 //=============================================================================
295 CORBA::Long HOMARD_Cas_i::GetPyram()
297 MESSAGE ("GetPyram");
298 ASSERT( myHomardCas );
299 return myHomardCas->GetPyram();
301 //=============================================================================
302 void HOMARD_Cas_i::MeshInfo(CORBA::Long Qual, CORBA::Long Diam, CORBA::Long Conn, CORBA::Long Tail, CORBA::Long Inte)
304 MESSAGE ( "MeshInfo : information sur le maillage initial du cas" );
305 ASSERT( myHomardCas );
307 // Nom de l'iteration
308 char* IterName = GetIter0Name() ;
309 CORBA::Long etatMenage = -1 ;
310 CORBA::Long modeHOMARD = 7 ;
311 CORBA::Long Option1 = 1 ;
312 CORBA::Long Option2 = 1 ;
313 if ( Qual != 0 ) { modeHOMARD = modeHOMARD*5 ; }
314 if ( Diam != 0 ) { modeHOMARD = modeHOMARD*19 ; }
315 if ( Conn != 0 ) { modeHOMARD = modeHOMARD*11 ; }
316 if ( Tail != 0 ) { modeHOMARD = modeHOMARD*13 ; }
317 if ( Inte != 0 ) { modeHOMARD = modeHOMARD*3 ; }
318 CORBA::Long codret = _gen_i->Compute(IterName, etatMenage, modeHOMARD, Option1, Option2) ;
319 MESSAGE ( "MeshInfo : codret = " << codret );
322 //=============================================================================
323 //=============================================================================
324 // Liens avec les autres structures
325 //=============================================================================
326 //=============================================================================
327 char* HOMARD_Cas_i::GetIter0Name()
329 ASSERT( myHomardCas );
330 return CORBA::string_dup( myHomardCas->GetIter0Name().c_str() );
332 //=============================================================================
333 HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::GetIter0()
335 // Nom de l'iteration initiale
336 char* Iter0Name = GetIter0Name() ;
337 MESSAGE ( "GetIter0 : Iter0Name = " << Iter0Name );
338 return _gen_i->GetIteration(Iter0Name) ;
340 //=============================================================================
341 HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::NextIteration( const char* IterName )
343 // Nom de l'iteration parent
344 char* NomIterParent = GetIter0Name() ;
345 MESSAGE ( "NextIteration : IterName = " << IterName );
346 MESSAGE ( "NextIteration : NomIterParent = " << NomIterParent );
347 return _gen_i->CreateIteration(IterName, NomIterParent) ;
349 //=============================================================================
350 HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::LastIteration( )
352 HOMARD::HOMARD_Iteration_ptr Iter ;
353 HOMARD::listeIterFilles_var ListeIterFilles ;
355 // Iteration initiale du cas
356 IterName = GetIter0Name() ;
357 // On va explorer la descendance de cette iteration initiale
358 // jusqu'a trouver celle qui n'a pas de filles
359 int nbiterfilles = 1 ;
360 while ( nbiterfilles == 1 )
362 // L'iteration associee
363 // MESSAGE ( ".. IterName = " << IterName );
364 Iter = _gen_i->GetIteration(IterName) ;
365 // Les filles de cette iteration
366 ListeIterFilles = Iter->GetIterations() ;
367 nbiterfilles = ListeIterFilles->length() ;
368 // MESSAGE ( ".. nbiterfilles = " << nbiterfilles );
369 // S'il y a au moins 2 filles, arret : on ne sait pas faire
370 ASSERT( nbiterfilles <= 1 ) ;
371 // S'il y a une fille unique, on recupere le nom de la fille et on recommence
372 if ( nbiterfilles == 1 )
373 { IterName = ListeIterFilles[0] ; }
378 //=============================================================================
379 void HOMARD_Cas_i::AddIteration( const char* NomIteration )
381 ASSERT( myHomardCas );
382 myHomardCas->AddIteration( NomIteration );