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"
38 //=============================================================================
40 * standard constructor
42 //=============================================================================
43 HOMARD_Cas_i::HOMARD_Cas_i()
45 MESSAGE( "Default constructor, not for use" );
49 //=============================================================================
51 * standard constructor
53 //=============================================================================
54 HOMARD_Cas_i::HOMARD_Cas_i( CORBA::ORB_ptr orb,
55 HOMARD::HOMARD_Gen_var engine )
57 MESSAGE( "HOMARD_Cas_i" );
60 myHomardCas = new ::HOMARD_Cas();
61 ASSERT( myHomardCas );
64 //=============================================================================
68 //=============================================================================
69 HOMARD_Cas_i::~HOMARD_Cas_i()
72 //=============================================================================
73 //=============================================================================
75 //=============================================================================
76 //=============================================================================
77 void HOMARD_Cas_i::SetName( const char* Name )
79 ASSERT( myHomardCas );
80 myHomardCas->SetName( Name );
82 //=============================================================================
83 char* HOMARD_Cas_i::GetName()
85 ASSERT( myHomardCas );
86 return CORBA::string_dup( myHomardCas->GetName().c_str() );
88 //=============================================================================
89 CORBA::Long HOMARD_Cas_i::Delete( CORBA::Long Option )
91 ASSERT( myHomardCas );
92 char* CaseName = GetName() ;
93 MESSAGE ( "Delete : destruction du cas " << CaseName << ", Option = " << Option );
94 return _gen_i->DeleteCase(CaseName, Option) ;
96 //=============================================================================
97 char* HOMARD_Cas_i::GetDumpPython()
99 ASSERT( myHomardCas );
100 return CORBA::string_dup( myHomardCas->GetDumpPython().c_str() );
102 //=============================================================================
103 std::string HOMARD_Cas_i::Dump() const
105 return HOMARD::Dump( *myHomardCas );
107 //=============================================================================
108 bool HOMARD_Cas_i::Restore( const std::string& stream )
110 return HOMARD::Restore( *myHomardCas, stream );
112 //=============================================================================
113 //=============================================================================
115 //=============================================================================
116 //=============================================================================
117 void HOMARD_Cas_i::SetDirName( const char* NomDir )
119 ASSERT( myHomardCas );
121 // A. recuperation du nom ; on ne fait rien si c'est le meme
122 char* oldrep = GetDirName() ;
123 MESSAGE ( "SetDirName : passage de oldrep = "<< oldrep << " a NomDir = "<<NomDir);
124 if ( oldrep == NomDir ) { return ; }
125 // B. Changement/creation du repertoire
126 codret = myHomardCas->SetDirName( NomDir );
129 SALOME::ExceptionStruct es;
130 es.type = SALOME::BAD_PARAM;
132 if ( codret == 1 ) { text = "The directory for the case cannot be modified because some iterations are already defined." ; }
133 else { text = "The directory for the case cannot be reached." ; }
134 es.text = CORBA::string_dup(text.c_str());
135 throw SALOME::SALOME_Exception(es);
137 // C. En cas de reprise, deplacement du point de depart
138 if ( GetState() != 0 )
140 MESSAGE ( "etat : " << GetState() ) ;
141 // C.1. Nom local du repertoire de l'iteration de depart dans le repertoire actuel du cas
142 HOMARD::HOMARD_Iteration_ptr Iter = GetIter0() ;
143 char* DirNameIter = Iter->GetDirNameLoc() ;
144 MESSAGE ( "SetDirName : nom actuel pour le repertoire de l iteration, DirNameIter = "<< DirNameIter);
145 // C.2. Recherche d'un nom local pour l'iteration de depart dans le futur repertoire du cas
146 char* nomDirIter = _gen_i->CreateDirNameIter(NomDir, 0 );
147 MESSAGE ( "SetDirName : nom futur pour le repertoire de l iteration, nomDirIter = "<< nomDirIter);
148 // C.3. Creation du futur repertoire local pour l'iteration de depart
149 std::string nomDirIterTotal ;
150 nomDirIterTotal = std::string(NomDir) + "/" + std::string(nomDirIter) ;
151 if (mkdir(nomDirIterTotal.c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
153 MESSAGE ( "nomDirIterTotal : " << nomDirIterTotal ) ;
154 SALOME::ExceptionStruct es;
155 es.type = SALOME::BAD_PARAM;
156 std::string text = "The directory for the starting iteration cannot be created." ;
157 es.text = CORBA::string_dup(text.c_str());
158 throw SALOME::SALOME_Exception(es);
160 // C.4. Deplacement du contenu du repertoire
161 std::string oldnomDirIterTotal ;
162 oldnomDirIterTotal = std::string(oldrep) + "/" + std::string(DirNameIter) ;
163 std::string commande = "mv " + std::string(oldnomDirIterTotal) + "/*" + " " + std::string(nomDirIterTotal) ;
164 codret = system(commande.c_str()) ;
167 SALOME::ExceptionStruct es;
168 es.type = SALOME::BAD_PARAM;
169 std::string text = "The starting point for the case cannot be moved into the new directory." ;
170 es.text = CORBA::string_dup(text.c_str());
171 throw SALOME::SALOME_Exception(es);
173 commande = "rm -rf " + std::string(oldnomDirIterTotal) ;
174 codret = system(commande.c_str()) ;
177 SALOME::ExceptionStruct es;
178 es.type = SALOME::BAD_PARAM;
179 std::string text = "The starting point for the case cannot be deleted." ;
180 es.text = CORBA::string_dup(text.c_str());
181 throw SALOME::SALOME_Exception(es);
183 // C.5. Memorisation du nom du repertoire de l'iteration
184 Iter->SetDirNameLoc(nomDirIter) ;
188 //=============================================================================
189 char* HOMARD_Cas_i::GetDirName()
191 ASSERT( myHomardCas );
192 return CORBA::string_dup( myHomardCas->GetDirName().c_str() );
194 //=============================================================================
195 CORBA::Long HOMARD_Cas_i::GetState()
197 ASSERT( myHomardCas );
198 // Nom de l'iteration initiale
199 char* Iter0Name = GetIter0Name() ;
200 HOMARD::HOMARD_Iteration_ptr Iter = _gen_i->GetIteration(Iter0Name) ;
201 int state = Iter->GetNumber() ;
204 //=============================================================================
205 CORBA::Long HOMARD_Cas_i::GetNumberofIter()
207 ASSERT( myHomardCas );
208 return myHomardCas->GetNumberofIter();
210 //=============================================================================
211 void HOMARD_Cas_i::SetConfType( CORBA::Long ConfType )
213 ASSERT( myHomardCas );
214 myHomardCas->SetConfType( ConfType );
216 //=============================================================================
217 CORBA::Long HOMARD_Cas_i::GetConfType()
219 ASSERT( myHomardCas );
220 return myHomardCas->GetConfType();
222 //=============================================================================
223 void HOMARD_Cas_i::SetBoundingBox( const HOMARD::extrema& LesExtrema )
225 ASSERT( myHomardCas );
226 std::vector<double> VExtrema;
227 ASSERT( LesExtrema.length() == 10 );
228 VExtrema.resize( LesExtrema.length() );
229 for ( int i = 0; i < LesExtrema.length(); i++ )
231 VExtrema[i] = LesExtrema[i];
233 myHomardCas->SetBoundingBox( VExtrema );
235 //=============================================================================
236 HOMARD::extrema* HOMARD_Cas_i::GetBoundingBox()
238 ASSERT(myHomardCas );
239 HOMARD::extrema_var aResult = new HOMARD::extrema();
240 std::vector<double> LesExtremes = myHomardCas->GetBoundingBox();
241 ASSERT( LesExtremes.size() == 10 );
242 aResult->length( 10 );
243 for ( int i = 0; i < LesExtremes.size(); i++ )
245 aResult[i] = LesExtremes[i];
247 return aResult._retn();
249 //=============================================================================
250 void HOMARD_Cas_i::AddGroup( const char* Group)
252 ASSERT( myHomardCas );
253 myHomardCas->AddGroup( Group );
255 //=============================================================================
256 void HOMARD_Cas_i::SetGroups( const HOMARD::ListGroupType& ListGroup )
258 ASSERT( myHomardCas );
259 std::list<std::string> ListString ;
260 for ( int i = 0; i < ListGroup.length(); i++ )
262 ListString.push_back(std::string(ListGroup[i]));
264 myHomardCas->SetGroups( ListString );
266 //=============================================================================
267 HOMARD::ListGroupType* HOMARD_Cas_i::GetGroups()
269 ASSERT(myHomardCas );
270 const std::list<std::string>& ListString = myHomardCas->GetGroups();
271 HOMARD::ListGroupType_var aResult = new HOMARD::ListGroupType();
272 aResult->length( ListString.size() );
273 std::list<std::string>::const_iterator it;
275 for ( it = ListString.begin(); it != ListString.end(); it++ )
277 aResult[i++] = CORBA::string_dup( (*it).c_str() );
279 return aResult._retn();
281 //=============================================================================
282 void HOMARD_Cas_i::AddBoundaryGroup( const char* BoundaryName, const char* Group)
284 MESSAGE ("AddBoundaryGroup : BoundaryName = "<< BoundaryName << ", Group = " << Group );
285 ASSERT( myHomardCas );
286 // La frontiere est-elle deja enregistree pour ce cas ?
287 const std::list<std::string>& ListBoundaryGroup = myHomardCas->GetBoundaryGroup();
288 std::list<std::string>::const_iterator it;
290 for ( it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++ )
292 if ( *it == BoundaryName )
296 // Enregistrement de la frontiere dans la reference du cas
297 myHomardCas->AddBoundaryGroup( BoundaryName, Group );
298 // Pour une nouvelle frontiere, publication dans l'arbre d'etudes sous le cas
301 char* CaseName = GetName() ;
302 MESSAGE ( "AddBoundaryGroup : insertion de la frontiere dans l'arbre de " << CaseName );
303 _gen_i->PublishBoundaryUnderCase(CaseName, BoundaryName) ;
306 //=============================================================================
307 HOMARD::ListBoundaryGroupType* HOMARD_Cas_i::GetBoundaryGroup()
309 MESSAGE ("GetBoundaryGroup");
310 ASSERT(myHomardCas );
311 const std::list<std::string>& ListBoundaryGroup = myHomardCas->GetBoundaryGroup();
312 HOMARD::ListBoundaryGroupType_var aResult = new HOMARD::ListBoundaryGroupType();
313 aResult->length( ListBoundaryGroup.size() );
314 std::list<std::string>::const_iterator it;
316 for ( it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++ )
318 aResult[i++] = CORBA::string_dup( (*it).c_str() );
320 return aResult._retn();
322 //=============================================================================
323 void HOMARD_Cas_i::SetPyram( CORBA::Long Pyram )
325 MESSAGE ("SetPyram, Pyram = " << Pyram );
326 ASSERT( myHomardCas );
327 myHomardCas->SetPyram( Pyram );
329 //=============================================================================
330 CORBA::Long HOMARD_Cas_i::GetPyram()
332 MESSAGE ("GetPyram");
333 ASSERT( myHomardCas );
334 return myHomardCas->GetPyram();
336 //=============================================================================
337 void HOMARD_Cas_i::MeshInfo(CORBA::Long Qual, CORBA::Long Diam, CORBA::Long Conn, CORBA::Long Tail, CORBA::Long Inte)
339 MESSAGE ( "MeshInfo : information sur le maillage initial du cas" );
340 ASSERT( myHomardCas );
342 // Nom de l'iteration
343 char* IterName = GetIter0Name() ;
344 CORBA::Long etatMenage = -1 ;
345 CORBA::Long modeHOMARD = 7 ;
346 CORBA::Long Option1 = 1 ;
347 CORBA::Long Option2 = 1 ;
348 if ( Qual != 0 ) { modeHOMARD = modeHOMARD*5 ; }
349 if ( Diam != 0 ) { modeHOMARD = modeHOMARD*19 ; }
350 if ( Conn != 0 ) { modeHOMARD = modeHOMARD*11 ; }
351 if ( Tail != 0 ) { modeHOMARD = modeHOMARD*13 ; }
352 if ( Inte != 0 ) { modeHOMARD = modeHOMARD*3 ; }
353 CORBA::Long codret = _gen_i->Compute(IterName, etatMenage, modeHOMARD, Option1, Option2) ;
354 MESSAGE ( "MeshInfo : codret = " << codret );
357 //=============================================================================
358 //=============================================================================
359 // Liens avec les autres structures
360 //=============================================================================
361 //=============================================================================
362 char* HOMARD_Cas_i::GetIter0Name()
364 ASSERT( myHomardCas );
365 return CORBA::string_dup( myHomardCas->GetIter0Name().c_str() );
367 //=============================================================================
368 HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::GetIter0()
370 // Nom de l'iteration initiale
371 char* Iter0Name = GetIter0Name() ;
372 MESSAGE ( "GetIter0 : Iter0Name = " << Iter0Name );
373 return _gen_i->GetIteration(Iter0Name) ;
375 //=============================================================================
376 HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::NextIteration( const char* IterName )
378 // Nom de l'iteration parent
379 char* NomIterParent = GetIter0Name() ;
380 MESSAGE ( "NextIteration : IterName = " << IterName );
381 MESSAGE ( "NextIteration : NomIterParent = " << NomIterParent );
382 return _gen_i->CreateIteration(IterName, NomIterParent) ;
384 //=============================================================================
385 HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::LastIteration( )
387 HOMARD::HOMARD_Iteration_ptr Iter ;
388 HOMARD::listeIterFilles_var ListeIterFilles ;
390 // Iteration initiale du cas
391 IterName = GetIter0Name() ;
392 // On va explorer la descendance de cette iteration initiale
393 // jusqu'a trouver celle qui n'a pas de filles
394 int nbiterfilles = 1 ;
395 while ( nbiterfilles == 1 )
397 // L'iteration associee
398 // MESSAGE ( ".. IterName = " << IterName );
399 Iter = _gen_i->GetIteration(IterName) ;
400 // Les filles de cette iteration
401 ListeIterFilles = Iter->GetIterations() ;
402 nbiterfilles = ListeIterFilles->length() ;
403 // MESSAGE ( ".. nbiterfilles = " << nbiterfilles );
404 // S'il y a au moins 2 filles, arret : on ne sait pas faire
405 ASSERT( nbiterfilles <= 1 ) ;
406 // S'il y a une fille unique, on recupere le nom de la fille et on recommence
407 if ( nbiterfilles == 1 )
408 { IterName = ListeIterFilles[0] ; }
413 //=============================================================================
414 void HOMARD_Cas_i::AddIteration( const char* NomIteration )
416 ASSERT( myHomardCas );
417 myHomardCas->AddIteration( NomIteration );