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 #include "HOMARD_Gen_i.hxx"
21 #include "HOMARD_Cas_i.hxx"
22 #include "HOMARD_Hypothesis_i.hxx"
23 #include "HOMARD_Iteration_i.hxx"
24 #include "HOMARD_Boundary_i.hxx"
25 #include "HOMARD_Zone_i.hxx"
26 #include "HomardDriver.hxx"
27 #include "HOMARD_DriverTools.hxx"
28 #include "HomardMedCommun.h"
29 #include "YACSDriver.hxx"
31 #include "HOMARD_version.h"
33 #include "utilities.h"
34 #include "Utils_SINGLETON.hxx"
35 #include "Utils_CorbaException.hxx"
36 #include "SALOMEDS_Tool.hxx"
37 #include "SALOME_LifeCycleCORBA.hxx"
38 #include "SALOMEconfig.h"
39 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
40 #include CORBA_CLIENT_HEADER(SMESH_Gen)
57 //=============================================================================
59 //=============================================================================
60 std::string RemoveTabulation( std::string theScript )
62 std::string::size_type aPos = 0;
63 while( aPos < theScript.length() )
65 aPos = theScript.find( "\n\t", aPos );
66 if( aPos == std::string::npos )
68 theScript.replace( aPos, 2, "\n" );
73 //=============================================================================
75 * standard constructor
77 //=============================================================================
78 HOMARD_Gen_i::HOMARD_Gen_i( CORBA::ORB_ptr orb,
79 PortableServer::POA_ptr poa,
80 PortableServer::ObjectId * contId,
81 const char *instanceName,
82 const char *interfaceName) :
83 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
85 MESSAGE("constructor");
87 _id = _poa->activate_object(_thisObj);
89 myHomard = new ::HOMARD_Gen();
90 _NS = SINGLETON_<SALOME_NamingService>::Instance();
91 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
94 //=================================
98 //================================
99 HOMARD_Gen_i::~HOMARD_Gen_i()
102 //=============================================================================
103 //=============================================================================
104 // Utilitaires pour l'étude
105 //=============================================================================
106 //=============================================================================
107 void HOMARD_Gen_i::addInStudy(SALOMEDS::Study_ptr theStudy)
109 ASSERT(!CORBA::is_nil(theStudy));
110 MESSAGE("addInStudy: ajout eventuel du composant HOMARD dans current study ID = " << GetCurrentStudyID()) ;
111 SALOMEDS::StudyBuilder_var myBuilder = theStudy->NewBuilder();
113 // Create SComponent labelled 'homard' if it doesn't already exit
114 SALOMEDS::SComponent_var homardFather = theStudy->FindComponent(ComponentDataType());
115 if (CORBA::is_nil(homardFather))
117 myBuilder->NewCommand();
118 MESSAGE("Add Component HOMARD");
120 bool aLocked = theStudy->GetProperties()->IsLocked();
121 if (aLocked) theStudy->GetProperties()->SetLocked(false);
123 homardFather = myBuilder->NewComponent(ComponentDataType());
124 SALOMEDS::GenericAttribute_var anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributeName");
125 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
126 CORBA::Object_var objVarN = _NS->Resolve("/Kernel/ModulCatalog");
127 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
128 SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
129 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent(ComponentDataType());
130 if (!Comp->_is_nil())
132 aName->SetValue(ComponentDataType());
135 anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributePixMap");
136 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
137 aPixmap->SetPixMap("HOMARD_2.png");
138 myBuilder->DefineComponentInstance(homardFather, HOMARD_Gen::_this());
140 if (aLocked) theStudy->GetProperties()->SetLocked(true);
141 myBuilder->CommitCommand();
144 //=============================================================================
145 void HOMARD_Gen_i::SetCurrentStudy(SALOMEDS::Study_ptr theStudy)
147 MESSAGE("SetCurrentStudy: current study Id = " << GetCurrentStudyID());
148 myCurrentStudy = SALOMEDS::Study::_duplicate(theStudy);
149 this->addInStudy(myCurrentStudy);
151 //=============================================================================
152 SALOMEDS::Study_ptr HOMARD_Gen_i::GetCurrentStudy()
153 //=============================================================================
155 MESSAGE("GetCurrentStudy: study Id = " << GetCurrentStudyID());
156 return SALOMEDS::Study::_duplicate(myCurrentStudy);
158 //=============================================================================
159 CORBA::Long HOMARD_Gen_i::GetCurrentStudyID()
160 //=============================================================================
162 return myCurrentStudy->_is_nil() ? -1 : myCurrentStudy->StudyId();
164 //=============================================================================
165 //=============================================================================
167 //=============================================================================
168 //=============================================================================
169 // Utilitaires pour l'iteration
170 //=============================================================================
171 //=============================================================================
172 void HOMARD_Gen_i::SetEtatIter(const char* nomIter, const CORBA::Long Etat)
173 //=====================================================================================
175 MESSAGE( "SetEtatIter : affectation de l'etat " << Etat << " a l'iteration " << nomIter );
176 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
177 if (CORBA::is_nil(myIteration))
179 SALOME::ExceptionStruct es;
180 es.type = SALOME::BAD_PARAM;
181 es.text = "Invalid iteration";
182 throw SALOME::SALOME_Exception(es);
186 myIteration->SetState(Etat);
188 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
189 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
193 icone = "iter0.png" ;
194 else if ( Etat == 2 )
195 icone = "iter_calculee.png" ;
197 icone = "iter_non_calculee.png" ;
198 PublishInStudyAttr(aStudyBuilder, aIterSO, NULL , NULL, icone.c_str(), NULL) ;
200 aStudyBuilder->CommitCommand();
203 //=============================================================================
204 //=============================================================================
206 //=============================================================================
207 //=============================================================================
208 // Destruction des structures identifiees par leurs noms
209 //=============================================================================
210 //=============================================================================
211 CORBA::Long HOMARD_Gen_i::DeleteBoundary(const char* BoundaryName)
213 MESSAGE ( "DeleteBoundary : BoundaryName = " << BoundaryName );
214 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
215 if (CORBA::is_nil(myBoundary))
217 SALOME::ExceptionStruct es;
218 es.type = SALOME::BAD_PARAM;
219 es.text = "Invalid boundary";
220 throw SALOME::SALOME_Exception(es);
224 // On verifie que la frontiere n'est plus utilisee
225 HOMARD::listeCases* maListe = GetAllCasesName();
226 int numberOfCases = maListe->length();
227 MESSAGE ( ".. Nombre de cas = " << numberOfCases );
228 std::string CaseName ;
229 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType ;
231 HOMARD::HOMARD_Cas_var myCase ;
232 for (int NumeCas = 0; NumeCas< numberOfCases; NumeCas++)
234 CaseName = std::string((*maListe)[NumeCas]);
235 MESSAGE ( "... Examen du cas = " << CaseName.c_str() );
236 myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
237 ASSERT(!CORBA::is_nil(myCase));
238 ListBoundaryGroupType = myCase->GetBoundaryGroup();
239 numberOfitems = ListBoundaryGroupType->length();
240 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
241 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
243 if ( std::string((*ListBoundaryGroupType)[NumBoundary]) == BoundaryName )
245 SALOME::ExceptionStruct es;
246 es.type = SALOME::BAD_PARAM;
247 es.text = "This boundary is used in a case and cannot be deleted.";
248 throw SALOME::SALOME_Exception(es);
254 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
255 myContextMap[GetCurrentStudyID()]._mesBoundarys.erase(BoundaryName);
256 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(BoundaryName, ComponentDataType());
257 SALOMEDS::SObject_var aSO =listSO[0];
258 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
259 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
263 //=============================================================================
264 CORBA::Long HOMARD_Gen_i::DeleteCase(const char* nomCas, CORBA::Long Option)
266 // Pour detruire un cas
267 MESSAGE ( "DeleteCase : nomCas = " << nomCas << ", avec option = " << Option );
268 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
269 if (CORBA::is_nil(myCase))
271 SALOME::ExceptionStruct es;
272 es.type = SALOME::BAD_PARAM;
273 es.text = "Invalid case context";
274 throw SALOME::SALOME_Exception(es);
277 // On commence par detruire toutes les iterations en partant de l'initiale et y compris elle
278 CORBA::String_var nomIter = myCase->GetIter0Name();
279 CORBA::Long Option1 = 0 ;
280 if ( DeleteIterationOption(nomIter, Option1, Option) != 0 )
285 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
286 myContextMap[GetCurrentStudyID()]._mesCas.erase(nomCas);
287 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomCas, ComponentDataType());
288 SALOMEDS::SObject_var aSO =listSO[0];
289 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
290 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
294 //=============================================================================
295 CORBA::Long HOMARD_Gen_i::DeleteHypo(const char* nomHypo)
297 MESSAGE ( "DeleteHypo : nomHypo = " << nomHypo );
298 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
299 if (CORBA::is_nil(myHypo))
301 SALOME::ExceptionStruct es;
302 es.type = SALOME::BAD_PARAM;
303 es.text = "Invalid hypothesis";
304 throw SALOME::SALOME_Exception(es);
308 // On verifie que l'hypothese n'est plus utilisee
309 HOMARD::listeIters* maListeIter = myHypo->GetIterations();
310 int numberOfIter = maListeIter->length();
311 if ( numberOfIter > 0 )
313 SALOME::ExceptionStruct es;
314 es.type = SALOME::BAD_PARAM;
315 es.text = "This hypothesis is used in an iteration and cannot be deleted.";
316 throw SALOME::SALOME_Exception(es);
320 // suppression du lien avec les zones eventuelles
321 HOMARD::listeZonesHypo* maListe = myHypo->GetZones();
322 int numberOfZones = maListe->length();
323 MESSAGE ( ".. Nombre de zones = " << numberOfZones );
324 for (int NumeZone = 0; NumeZone< numberOfZones; NumeZone++)
326 std::string ZoneName = std::string((*maListe)[NumeZone]);
327 MESSAGE ( ".. suppression du lien avec la zone = " << ZoneName.c_str() );
328 DissociateHypoZone(nomHypo, ZoneName.c_str()) ;
332 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
333 myContextMap[GetCurrentStudyID()]._mesHypotheses.erase(nomHypo);
334 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomHypo, ComponentDataType());
335 SALOMEDS::SObject_var aSO =listSO[0];
336 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
337 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
341 //=============================================================================
342 CORBA::Long HOMARD_Gen_i::DeleteIteration(const char* nomIter, CORBA::Long Option)
344 // Option = 0 : On ne supprime pas le fichier du maillage associe
345 // Option = 1 : On supprime le fichier du maillage associe
346 // Pour detruire une iteration courante
347 MESSAGE ( "DeleteIteration : nomIter = " << nomIter << ", avec option = " << Option );
348 CORBA::Long Option1 = 1 ;
349 return DeleteIterationOption(nomIter, Option1, Option);
351 //=============================================================================
352 CORBA::Long HOMARD_Gen_i::DeleteIterationOption(const char* nomIter, CORBA::Long Option1, CORBA::Long Option2)
354 // Option1 = 0 : On autorise la destruction de l'iteration 0
355 // Option1 = 1 : On interdit la destruction de l'iteration 0
357 // Option2 = 0 : On ne supprime pas le fichier du maillage associe
358 // Option2 = 1 : On supprime le fichier du maillage associe
359 MESSAGE ( "DeleteIterationOption : nomIter = " << nomIter << ", avec options = " << Option1<< ", " << Option2 );
360 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
361 if (CORBA::is_nil(myIteration))
363 SALOME::ExceptionStruct es;
364 es.type = SALOME::BAD_PARAM;
365 es.text = "Invalid iteration";
366 throw SALOME::SALOME_Exception(es);
370 int numero = myIteration->GetNumber();
371 MESSAGE ( "DeleteIterationOption : numero = " << numero );
372 if ( numero == 0 and Option1 == 1 )
374 SALOME::ExceptionStruct es;
375 es.type = SALOME::BAD_PARAM;
376 es.text = "This iteration cannot be deleted.";
377 throw SALOME::SALOME_Exception(es);
381 // On detruit recursivement toutes les filles
382 HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
383 int numberOfIter = maListe->length();
384 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
386 std::string nomIterFille = std::string((*maListe)[NumeIter]);
387 MESSAGE ( ".. appel recursif de DeleteIterationOption pour nomIter = " << nomIterFille.c_str() );
388 DeleteIterationOption(nomIterFille.c_str(), Option1, Option2);
391 // On arrive ici pour une iteration sans fille
392 MESSAGE ( "Destruction effective de " << nomIter );
393 // On commence par invalider l'iteration pour faire le menage des dependances
394 // et eventuellement du maillage associe
396 if ( numero == 0 ) { option = 0 ; }
397 else { option = Option2 ; }
398 InvalideIterOption(nomIter, option) ;
400 // Retrait dans la descendance de l'iteration parent
403 std::string nomIterationParent = myIteration->GetIterParentName();
404 MESSAGE ( "Retrait dans la descendance de nomIterationParent " << nomIterationParent );
405 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
406 if (CORBA::is_nil(myIterationParent))
408 SALOME::ExceptionStruct es;
409 es.type = SALOME::BAD_PARAM;
410 es.text = "Invalid iteration";
411 throw SALOME::SALOME_Exception(es);
414 myIterationParent->UnLinkNextIteration(nomIter);
417 // suppression du lien avec l'hypothese
420 std::string nomHypo = myIteration->GetHypoName();
421 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
422 ASSERT(!CORBA::is_nil(myHypo));
423 myHypo->UnLinkIteration(nomIter);
426 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
427 myContextMap[GetCurrentStudyID()]._mesIterations.erase(nomIter);
428 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomIter, ComponentDataType());
429 SALOMEDS::SObject_var aSO =listSO[0];
430 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
431 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
432 // on peut aussi faire RemoveObject
433 // MESSAGE ( "Au final" );
434 // HOMARD::listeIterations* Liste = GetAllIterationsName() ;
435 // numberOfIter = Liste->length();
436 // for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
438 // std::string nomIterFille = std::string((*Liste)[NumeIter]);
439 // MESSAGE ( ".. nomIter = " << nomIterFille.c_str() );
444 //=============================================================================
445 CORBA::Long HOMARD_Gen_i::DeleteZone(const char* nomZone)
447 MESSAGE ( "DeleteZone : nomZone = " << nomZone );
448 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[nomZone];
449 if (CORBA::is_nil(myZone))
451 SALOME::ExceptionStruct es;
452 es.type = SALOME::BAD_PARAM;
453 es.text = "Invalid zone";
454 throw SALOME::SALOME_Exception(es);
458 // On verifie que la zone n'est plus utilisee
459 HOMARD::listeHypo* maListe = myZone->GetHypo();
460 int numberOfHypo = maListe->length();
461 MESSAGE ( ".. Nombre d'hypotheses = " << numberOfHypo );
462 if ( numberOfHypo > 0 )
464 SALOME::ExceptionStruct es;
465 es.type = SALOME::BAD_PARAM;
466 es.text = "This zone is used in an hypothesis and cannot be deleted.";
467 throw SALOME::SALOME_Exception(es);
471 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
472 myContextMap[GetCurrentStudyID()]._mesZones.erase(nomZone);
473 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomZone, ComponentDataType());
474 SALOMEDS::SObject_var aSO =listSO[0];
475 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
476 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
480 //=============================================================================
481 //=============================================================================
483 //=============================================================================
484 //=============================================================================
485 // Invalidation des structures identifiees par leurs noms
486 //=============================================================================
487 //=============================================================================
488 void HOMARD_Gen_i::InvalideBoundary(const char* BoundaryName)
490 MESSAGE( "InvalideBoundary : BoundaryName = " << BoundaryName );
491 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
492 if (CORBA::is_nil(myBoundary))
494 SALOME::ExceptionStruct es;
495 es.type = SALOME::BAD_PARAM;
496 es.text = "Invalid boundary";
497 throw SALOME::SALOME_Exception(es);
502 SALOME::ExceptionStruct es;
503 es.type = SALOME::BAD_PARAM;
504 es.text = "No change is allowed in a boundary. Ask for evolution.";
505 throw SALOME::SALOME_Exception(es);
509 //=============================================================================
510 void HOMARD_Gen_i::InvalideHypo(const char* nomHypo)
512 MESSAGE( "InvalideHypo : nomHypo = " << nomHypo );
513 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
514 if (CORBA::is_nil(myHypo))
516 SALOME::ExceptionStruct es;
517 es.type = SALOME::BAD_PARAM;
518 es.text = "Invalid hypothesis";
519 throw SALOME::SALOME_Exception(es);
523 HOMARD::listeIters* maListe = myHypo->GetIterations();
524 int numberOfIter = maListe->length();
525 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
527 std::string nomIter = std::string((*maListe)[NumeIter]);
528 MESSAGE( ".. nomIter = " << nomIter );
529 InvalideIter(nomIter.c_str());
532 //=============================================================================
533 void HOMARD_Gen_i::InvalideIter(const char* nomIter)
535 MESSAGE("InvalideIter : nomIter = " << nomIter);
536 // Pour invalider totalement une iteration courante
537 CORBA::Long Option = 1 ;
538 return InvalideIterOption(nomIter, Option);
540 //=============================================================================
541 void HOMARD_Gen_i::InvalideIterOption(const char* nomIter, CORBA::Long Option)
543 // Option = 0 : On ne supprime pas le fichier du maillage associe
544 // Option = 1 : On supprime le fichier du maillage associe
545 MESSAGE ( "InvalideIterOption : nomIter = " << nomIter << ", avec option = " << Option );
546 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
547 if (CORBA::is_nil(myIteration))
549 SALOME::ExceptionStruct es;
550 es.type = SALOME::BAD_PARAM;
551 es.text = "Invalid iteration";
552 throw SALOME::SALOME_Exception(es);
556 HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
557 int numberOfIter = maListe->length();
558 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
560 std::string nomIterFille = std::string((*maListe)[NumeIter]);
561 MESSAGE ( ".. appel recursif de InvalideIter pour nomIter = " << nomIterFille.c_str() );
562 InvalideIter(nomIterFille.c_str());
565 // On arrive ici pour une iteration sans fille
566 MESSAGE ( "Invalidation effective de " << nomIter );
567 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
568 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aIterSO);
569 for (; aIter->More(); aIter->Next())
571 SALOMEDS::SObject_var so = aIter->Value();
572 SALOMEDS::GenericAttribute_var anAttr;
573 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
574 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
575 std::string value (aCommentAttr->Value());
576 if(value == std::string("HypoHomard")) continue;
577 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
578 aStudyBuilder->RemoveObject(so);
581 int etat = myIteration->GetState();
584 SetEtatIter(nomIter,1);
585 const char * nomCas = myIteration->GetCaseName();
586 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
587 if (CORBA::is_nil(myCase))
589 SALOME::ExceptionStruct es;
590 es.type = SALOME::BAD_PARAM;
591 es.text = "Invalid case context";
592 throw SALOME::SALOME_Exception(es);
595 std::string nomDir = myIteration->GetDirName();
596 std::string nomFichier = myIteration->GetMeshFile();
597 std::string commande= "rm -rf " + std::string(nomDir);
598 if ( Option == 1 ) { commande = commande + ";rm -rf " + std::string(nomFichier) ; }
599 MESSAGE ( "commande = " << commande );
600 if ((system(commande.c_str())) != 0)
602 SALOME::ExceptionStruct es;
603 es.type = SALOME::BAD_PARAM;
604 es.text = "The directory for the calculation cannot be cleared." ;
605 throw SALOME::SALOME_Exception(es);
608 // Suppression du maillage publie dans SMESH
609 std::string MeshName = myIteration->GetMeshName() ;
610 DeleteResultInSmesh(nomFichier, MeshName) ;
614 //=============================================================================
615 void HOMARD_Gen_i::InvalideIterInfo(const char* nomIter)
617 MESSAGE("InvalideIterInfo : nomIter = " << nomIter);
618 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
619 if (CORBA::is_nil(myIteration))
621 SALOME::ExceptionStruct es;
622 es.type = SALOME::BAD_PARAM;
623 es.text = "Invalid iteration";
624 throw SALOME::SALOME_Exception(es);
628 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
629 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aIterSO);
630 for (; aIter->More(); aIter->Next())
632 SALOMEDS::SObject_var so = aIter->Value();
633 SALOMEDS::GenericAttribute_var anAttr;
634 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
635 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
636 std::string value (aCommentAttr->Value());
637 /* MESSAGE("... value = " << value);*/
638 if( (value == std::string("logInfo")) or ( value == std::string("SummaryInfo")) )
640 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
641 aStudyBuilder->RemoveObject(so);
645 const char * nomCas = myIteration->GetCaseName();
646 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
647 if (CORBA::is_nil(myCase))
649 SALOME::ExceptionStruct es;
650 es.type = SALOME::BAD_PARAM;
651 es.text = "Invalid case context";
652 throw SALOME::SALOME_Exception(es);
655 const char* nomDir = myIteration->GetDirName();
656 std::string commande = "rm -f " + std::string(nomDir) + "/info* " ;
657 commande += std::string(nomDir) + "/Liste.*info" ;
658 /* MESSAGE ( "commande = " << commande );*/
659 if ((system(commande.c_str())) != 0)
661 SALOME::ExceptionStruct es;
662 es.type = SALOME::BAD_PARAM;
663 es.text = "The directory for the calculation cannot be cleared." ;
664 throw SALOME::SALOME_Exception(es);
668 //=============================================================================
669 void HOMARD_Gen_i::InvalideZone(const char* ZoneName)
671 MESSAGE( "InvalideZone : ZoneName = " << ZoneName );
672 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
673 if (CORBA::is_nil(myZone))
675 SALOME::ExceptionStruct es;
676 es.type = SALOME::BAD_PARAM;
677 es.text = "Invalid zone";
678 throw SALOME::SALOME_Exception(es);
681 HOMARD::listeHypo* maListe = myZone->GetHypo();
682 int numberOfHypo = maListe->length();
683 MESSAGE( ".. numberOfHypo = " << numberOfHypo );
684 for (int NumeHypo = 0; NumeHypo< numberOfHypo; NumeHypo++)
686 std::string nomHypo = std::string((*maListe)[NumeHypo]);
687 MESSAGE( ".. nomHypo = " << nomHypo );
688 InvalideHypo(nomHypo.c_str());
691 //=============================================================================
692 //=============================================================================
694 //=============================================================================
695 //=============================================================================
696 // Association de lien entre des structures identifiees par leurs noms
697 //=============================================================================
698 //=============================================================================
699 void HOMARD_Gen_i::AssociateCaseIter(const char* nomCas, const char* nomIter, const char* labelIter)
701 MESSAGE( "AssociateCaseIter : " << nomCas << ", " << nomIter << ", " << labelIter );
703 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
704 if (CORBA::is_nil(myCase))
706 SALOME::ExceptionStruct es;
707 es.type = SALOME::BAD_PARAM;
708 es.text = "Invalid case";
709 throw SALOME::SALOME_Exception(es);
713 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
714 if (CORBA::is_nil(myIteration))
716 SALOME::ExceptionStruct es;
717 es.type = SALOME::BAD_PARAM;
718 es.text = "Invalid iteration";
719 throw SALOME::SALOME_Exception(es);
723 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
724 SALOMEDS::SObject_var aCasSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
725 if (CORBA::is_nil(aCasSO))
727 SALOME::ExceptionStruct es;
728 es.type = SALOME::BAD_PARAM;
729 es.text = "Invalid case";
730 throw SALOME::SALOME_Exception(es);
734 aStudyBuilder->NewCommand();
735 SALOMEDS::SObject_var newStudyIter = aStudyBuilder->NewObject(aCasSO);
736 PublishInStudyAttr(aStudyBuilder, newStudyIter, nomIter , labelIter,
737 "iter_non_calculee.png", _orb->object_to_string(myIteration)) ;
738 aStudyBuilder->CommitCommand();
740 myCase->AddIteration(nomIter);
741 myIteration->SetCaseName(nomCas);
743 //=====================================================================================
744 void HOMARD_Gen_i::AssociateHypoZone(const char* nomHypothesis, const char* ZoneName, CORBA::Long TypeUse)
746 MESSAGE ( "AssociateHypoZone : nomHypo = " << nomHypothesis << ", ZoneName= " << ZoneName << ", TypeUse = " << TypeUse);
748 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
749 ASSERT(!CORBA::is_nil(myHypo));
750 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
751 ASSERT(!CORBA::is_nil(aHypoSO));
753 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
754 ASSERT(!CORBA::is_nil(myZone));
755 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myZone)));
756 ASSERT(!CORBA::is_nil(aZoneSO));
758 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
760 aStudyBuilder->NewCommand();
762 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aHypoSO);
763 aStudyBuilder->Addreference(aSubSO, aZoneSO);
765 aStudyBuilder->CommitCommand();
767 myZone->AddHypo(nomHypothesis);
768 myHypo->AddZone0(ZoneName, TypeUse);
770 //=============================================================================
771 void HOMARD_Gen_i::AssociateIterHypo(const char* nomIter, const char* nomHypo)
773 MESSAGE("AssociateIterHypo : nomHypo = " << nomHypo << " nomIter = " << nomIter);
775 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
776 ASSERT(!CORBA::is_nil(myHypo));
777 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
778 ASSERT(!CORBA::is_nil(aHypoSO));
780 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
781 ASSERT(!CORBA::is_nil(myIteration));
782 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
783 ASSERT(!CORBA::is_nil(aIterSO));
785 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
787 aStudyBuilder->NewCommand();
789 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
790 aStudyBuilder->Addreference(aSubSO, aHypoSO);
792 aStudyBuilder->CommitCommand();
794 myIteration->SetHypoName(nomHypo);
795 myHypo->LinkIteration(nomIter);
797 //=============================================================================
798 //=============================================================================
800 //=============================================================================
801 //=============================================================================
802 // Dissociation de lien entre des structures identifiees par leurs noms
803 //=============================================================================
804 //=============================================================================
805 void HOMARD_Gen_i::DissociateHypoZone(const char* nomHypothesis, const char* ZoneName)
807 MESSAGE ( "DissociateHypoZone : ZoneName= " << ZoneName << ", nomHypo = " << nomHypothesis);
809 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
810 ASSERT(!CORBA::is_nil(myHypo));
811 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
812 ASSERT(!CORBA::is_nil(aHypoSO));
814 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
815 ASSERT(!CORBA::is_nil(myZone));
816 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myZone)));
817 ASSERT(!CORBA::is_nil(aZoneSO));
819 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
821 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator(aHypoSO);
822 for (; it->More(); it->Next())
824 SALOMEDS::SObject_var aHypObj = it->Value();
825 SALOMEDS::SObject_var ptrObj;
826 if (aHypObj->ReferencedObject(ptrObj))
828 if (std::string(ptrObj->GetName()) == std::string(aZoneSO->GetName()))
830 aStudyBuilder->NewCommand();
831 aStudyBuilder->RemoveObject(aHypObj);
832 aStudyBuilder->CommitCommand();
838 myZone->SupprHypo(nomHypothesis);
839 myHypo->SupprZone(ZoneName);
841 //=============================================================================
842 //=============================================================================
845 //=============================================================================
846 //=============================================================================
847 // Recuperation des listes
848 //=============================================================================
849 //=============================================================================
850 HOMARD::listeCases* HOMARD_Gen_i::GetAllCasesName()
852 MESSAGE("GetAllCasesName");
855 HOMARD::listeCases_var ret = new HOMARD::listeCases;
856 ret->length(myContextMap[GetCurrentStudyID()]._mesCas.size());
857 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
859 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
860 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
862 ret[i++] = CORBA::string_dup((*it).first.c_str());
867 //=============================================================================
868 HOMARD::listeHypotheses* HOMARD_Gen_i::GetAllHypothesesName()
870 MESSAGE("GetAllHypothesesName");
873 HOMARD::listeHypotheses_var ret = new HOMARD::listeHypotheses;
874 ret->length(myContextMap[GetCurrentStudyID()]._mesHypotheses.size());
875 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it;
877 for (it = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
878 it != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it++)
880 ret[i++] = CORBA::string_dup((*it).first.c_str());
885 //=============================================================================
886 HOMARD::listeZones* HOMARD_Gen_i::GetAllZonesName()
888 MESSAGE("GetAllZonesName");
891 HOMARD::listeZones_var ret = new HOMARD::listeZones;
892 ret->length(myContextMap[GetCurrentStudyID()]._mesZones.size());
893 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it;
895 for (it = myContextMap[GetCurrentStudyID()]._mesZones.begin();
896 it != myContextMap[GetCurrentStudyID()]._mesZones.end(); it++)
898 ret[i++] = CORBA::string_dup((*it).first.c_str());
903 //=============================================================================
904 HOMARD::listeIterations* HOMARD_Gen_i::GetAllIterationsName()
906 MESSAGE("GetAllIterationsName");
909 HOMARD::listeIterations_var ret = new HOMARD::listeIterations;
910 ret->length(myContextMap[GetCurrentStudyID()]._mesIterations.size());
911 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it;
913 for (it = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
914 it != myContextMap[GetCurrentStudyID()]._mesIterations.end(); it++)
916 ret[i++] = CORBA::string_dup((*it).first.c_str());
921 //=============================================================================
922 HOMARD::listeBoundarys* HOMARD_Gen_i::GetAllBoundarysName()
924 MESSAGE("GetAllBoundarysName");
927 HOMARD::listeBoundarys_var ret = new HOMARD::listeBoundarys;
928 ret->length(myContextMap[GetCurrentStudyID()]._mesBoundarys.size());
929 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it;
931 for (it = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
932 it != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); it++)
934 ret[i++] = CORBA::string_dup((*it).first.c_str());
939 //=============================================================================
940 //=============================================================================
942 //=============================================================================
943 //=============================================================================
944 // Recuperation des structures identifiees par leurs noms
945 //=============================================================================
946 //=============================================================================
947 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::GetCase(const char* nomCas)
949 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
950 ASSERT(!CORBA::is_nil(myCase));
951 return HOMARD::HOMARD_Cas::_duplicate(myCase);
953 //=============================================================================
954 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::GetZone(const char* ZoneName)
956 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
957 ASSERT(!CORBA::is_nil(myZone));
958 return HOMARD::HOMARD_Zone::_duplicate(myZone);
960 //=============================================================================
961 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::GetHypothesis(const char* nomHypothesis)
963 HOMARD::HOMARD_Hypothesis_var myHypothesis = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
964 ASSERT(!CORBA::is_nil(myHypothesis));
965 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
967 //=============================================================================
968 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::GetIteration(const char* NomIterationation)
970 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIterationation];
971 ASSERT(!CORBA::is_nil(myIteration));
972 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
974 //=============================================================================
975 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::GetBoundary(const char* nomBoundary)
977 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[nomBoundary];
978 ASSERT(!CORBA::is_nil(myBoundary));
979 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
981 //=============================================================================
982 //=============================================================================
984 //=============================================================================
985 //=============================================================================
987 //=============================================================================
988 //=============================================================================
989 void HOMARD_Gen_i::MeshInfo(const char* nomCas, const char* MeshName, const char* MeshFile, const char* DirName, CORBA::Long Qual, CORBA::Long Diam, CORBA::Long Conn, CORBA::Long Tail, CORBA::Long Inte)
991 INFOS ( "MeshInfo : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
992 INFOS ( "Qual = " << Qual << ", Diam = " << Diam << ", Conn = " << Conn << ", Tail = " << Tail << ", Inte = " << Inte );
996 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, 0, 1) ;
997 myCase->SetDirName(DirName) ;
999 myCase->MeshInfo(Qual, Diam, Conn, Tail, Inte) ;
1003 //=============================================================================
1004 //=============================================================================
1006 //=============================================================================
1007 //=============================================================================
1008 // Recuperation des structures par le contexte
1009 //=============================================================================
1010 //=============================================================================
1011 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::LastIteration(const char* nomCas)
1013 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1014 ASSERT(!CORBA::is_nil(myCase));
1016 HOMARD::HOMARD_Iteration_var myIteration = myCase->LastIteration();
1017 ASSERT(!CORBA::is_nil(myIteration));
1019 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1021 //=============================================================================
1022 //=============================================================================
1024 //=============================================================================
1025 //=============================================================================
1026 // Nouvelles structures
1027 //=============================================================================
1028 //=============================================================================
1029 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::newCase()
1031 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1032 HOMARD_Cas_i* aServant = new HOMARD_Cas_i(_orb, engine);
1033 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(aServant->_this());
1034 return aCase._retn();
1036 //=============================================================================
1037 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::newHypothesis()
1039 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1040 HOMARD_Hypothesis_i* aServant = new HOMARD_Hypothesis_i(_orb, engine);
1041 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(aServant->_this());
1042 return aHypo._retn();
1044 //=============================================================================
1045 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::newIteration()
1047 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1048 HOMARD_Iteration_i* aServant = new HOMARD_Iteration_i(_orb, engine);
1049 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(aServant->_this());
1050 return aIter._retn();
1052 //=============================================================================
1053 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::newBoundary()
1055 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1056 HOMARD_Boundary_i* aServant = new HOMARD_Boundary_i(_orb, engine);
1057 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(aServant->_this());
1058 return aBoundary._retn();
1060 //=============================================================================
1061 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::newZone()
1063 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1064 HOMARD_Zone_i* aServant = new HOMARD_Zone_i(_orb, engine);
1065 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(aServant->_this());
1066 return aZone._retn();
1068 //=============================================================================
1069 //=============================================================================
1071 //=============================================================================
1072 //=============================================================================
1073 // Creation des structures identifiees par leurs noms
1074 //=============================================================================
1075 //=============================================================================
1076 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCase(const char* nomCas, const char* MeshName, const char* MeshFile)
1078 // Creation d'un cas initial
1079 // nomCas : nom du cas a creer
1080 // MeshName, MeshFile : nom et fichier du maillage correspondant
1083 INFOS ( "CreateCase : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1085 // Par defaut, on ne publie pas le maillage
1086 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 0, 0, 1) ;
1088 // Valeurs par defaut des filtrages
1089 myCase->SetPyram(0);
1091 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1093 //=============================================================================
1094 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromIteration(const char* nomCas, const char* DirNameStart)
1096 // nomCas : nom du cas a creer
1097 // DirNameStart : nom du repertoire contenant l'iteration de reprise
1100 INFOS ( "CreateCaseFromIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1101 std::string nomDirWork = getenv("PWD") ;
1104 // A. Decodage du point de reprise
1105 // A.1. Controle du repertoire de depart de l'iteration
1106 codret = chdir(DirNameStart) ;
1109 SALOME::ExceptionStruct es;
1110 es.type = SALOME::BAD_PARAM;
1111 es.text = "The directory of the iteration does not exist.";
1112 throw SALOME::SALOME_Exception(es);
1115 // A.2. Reperage des fichiers du repertoire de reprise
1116 std::string file_configuration = "" ;
1117 std::string file_maillage_homard = "" ;
1120 struct dirent *dirp;
1121 dp = opendir(DirNameStart);
1122 while ( (dirp = readdir(dp)) != NULL )
1124 std::string file_name(dirp->d_name);
1125 // MESSAGE ( file_name );
1126 bilan = file_name.find("HOMARD.Configuration.") ;
1127 if ( bilan != string::npos ) { file_configuration = file_name ; }
1128 bilan = file_name.find("maill.") ;
1129 if ( bilan != string::npos )
1131 bilan = file_name.find(".hom.med") ;
1132 if ( bilan != string::npos ) { file_maillage_homard = file_name ; }
1136 MESSAGE ( "==> file_configuration : " << file_configuration ) ;
1137 MESSAGE ( "==> file_maillage_homard : " << file_maillage_homard ) ;
1139 if ( ( file_configuration == "" ) or ( file_maillage_homard == "" ) )
1141 SALOME::ExceptionStruct es;
1142 es.type = SALOME::BAD_PARAM;
1144 if ( file_configuration == "" ) { text = "The configuration file cannot be found." ; }
1145 else { text = "The HOMARD mesh file cannot be found." ; }
1146 es.text = CORBA::string_dup(text.c_str());
1147 throw SALOME::SALOME_Exception(es);
1150 // B. Lecture du fichier de configuration
1151 // ATTENTION : on doit veiller a la coherence entre HomardDriver et CreateCaseFromIteration
1157 // le constructeur de ifstream permet d'ouvrir un fichier en lecture
1158 std::ifstream fichier( file_configuration.c_str() );
1159 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1161 std::string ligne; // variable contenant chaque ligne lue
1162 std::string mot_cle;
1163 std::string argument;
1165 // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1166 while ( std::getline( fichier, ligne ) )
1168 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1169 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1170 ligne_bis >> mot_cle ;
1171 // B.2. Des valeurs entieres : le second bloc de la ligne
1172 if ( mot_cle == "NumeIter" )
1174 ligne_bis >> NumeIter ;
1177 // B.3. Des valeurs caracteres brutes : le second bloc de la ligne est la valeur
1178 else if ( ( mot_cle == "TypeConf" ) or ( mot_cle == "TypeElem" ) )
1180 ligne_bis >> argument ;
1182 if ( mot_cle == "TypeConf" )
1184 if ( argument == "conforme" ) { TypeConf = 1 ; }
1185 else if ( argument == "non_conforme_1_noeud" ) { TypeConf = 2 ; }
1186 else if ( argument == "non_conforme_1_arete" ) { TypeConf = 3 ; }
1187 else if ( argument == "non_conforme_indicateur" ) { TypeConf = 4 ; }
1189 else if ( mot_cle == "TypeElem" )
1191 if ( argument == "ignore_pyra" ) { Pyram = 1 ; }
1192 else if ( argument == "HOMARD" ) { Pyram = 0 ; }
1195 // B.4. Des valeurs caracteres : le deuxieme bloc de la ligne peut etre encadre par des quotes :
1196 // il faut les supprimer
1197 else if ( ( mot_cle == "CCNoMNP1" ) or ( mot_cle == "CCMaiNP1" ) )
1199 ligne_bis >> argument ;
1200 if ( argument[0] == '"' ) { decalage = 1 ; }
1201 else { decalage = 0 ; }
1202 size_t size = argument.size() + 1 - 2*decalage ;
1204 if ( mot_cle == "CCNoMNP1" )
1206 MeshName = new char[ size ];
1207 strncpy( MeshName, argument.c_str()+decalage, size );
1208 MeshName[size-1] = '\0' ;
1210 else if ( mot_cle == "CCMaiNP1" )
1212 MeshFile = new char[ size ];
1213 strncpy( MeshFile, argument.c_str()+decalage, size );
1214 MeshFile[size-1] = '\0' ;
1218 MESSAGE ( "==> TypeConf : " << TypeConf ) ;
1219 MESSAGE ( "==> MeshName : " << MeshName ) ;
1220 MESSAGE ( "==> MeshFile : " << MeshFile ) ;
1221 MESSAGE ( "==> NumeIter : " << NumeIter ) ;
1222 MESSAGE ( "==> Pyram : " << Pyram ) ;
1226 SALOME::ExceptionStruct es;
1227 es.type = SALOME::BAD_PARAM;
1228 std::string text = "The configuration file cannot be read." ;
1229 es.text = CORBA::string_dup(text.c_str());
1230 throw SALOME::SALOME_Exception(es);
1233 // C. Creation effective du cas
1235 // Par defaut, on ne publie pas le maillage
1236 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, NumeIter, 1) ;
1238 // D. Parametrages lus dans le fichier de configuration
1240 myCase->SetConfType (TypeConf) ;
1241 myCase->SetPyram (Pyram) ;
1243 // E. Copie du fichier de maillage homard
1244 // E.1. Repertoire associe au cas
1245 char* nomDirCase = myCase->GetDirName() ;
1246 // E.2. Repertoire associe a l'iteration de ce cas
1248 IterName = myCase->GetIter0Name() ;
1249 HOMARD::HOMARD_Iteration_var Iter = GetIteration(IterName) ;
1250 char* nomDirIter = CreateDirNameIter(nomDirCase, 0 );
1251 Iter->SetDirNameLoc(nomDirIter);
1252 std::string nomDirIterTotal ;
1253 nomDirIterTotal = std::string(nomDirCase) + "/" + std::string(nomDirIter) ;
1254 if (mkdir(nomDirIterTotal.c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
1256 MESSAGE ( "nomDirIterTotal : " << nomDirIterTotal ) ;
1257 SALOME::ExceptionStruct es;
1258 es.type = SALOME::BAD_PARAM;
1259 std::string text = "The directory for the computation cannot be created." ;
1260 es.text = CORBA::string_dup(text.c_str());
1261 throw SALOME::SALOME_Exception(es);
1263 // E.3. Copie du maillage HOMARD au format MED
1264 codret = chdir(DirNameStart) ;
1265 std::string commande = "cp " + file_maillage_homard + " " + nomDirIterTotal ;
1266 MESSAGE ( "commande : " << commande ) ;
1267 codret = system(commande.c_str()) ;
1268 MESSAGE ( "codret : " << codret ) ;
1271 SALOME::ExceptionStruct es;
1272 es.type = SALOME::BAD_PARAM;
1273 es.text = "The starting point for the case cannot be copied into the working directory.";
1274 throw SALOME::SALOME_Exception(es);
1283 chdir(nomDirWork.c_str());
1285 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1287 //=============================================================================
1288 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseLastIteration(const char* nomCas, const char* DirNameStart)
1290 // nomCas : nom du cas a creer
1291 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1294 INFOS ( "CreateCaseFromCaseLastIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1296 std::string DirNameStartIter = CreateCase1(DirNameStart, -1) ;
1298 DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1299 HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1301 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1303 //=============================================================================
1304 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseIteration(const char* nomCas, const char* DirNameStart, CORBA::Long Number)
1306 // nomCas : nom du cas a creer
1307 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1308 // Number : numero de l'iteration de depart
1311 INFOS ( "CreateCaseFromCaseIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart << ", Number = " << Number );
1314 SALOME::ExceptionStruct es;
1315 es.type = SALOME::BAD_PARAM;
1316 es.text = "The number of iteration must be positive.";
1317 throw SALOME::SALOME_Exception(es);
1321 std::string DirNameStartIter = CreateCase1(DirNameStart, Number) ;
1323 DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1324 HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1326 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1328 //=============================================================================
1329 std::string HOMARD_Gen_i::CreateCase1(const char* DirNameStart, CORBA::Long Number)
1331 // Retourne le nom du repertoire ou se trouve l'iteration voulue.
1332 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1333 // Number : numero de l'iteration de depart ou -1 si on cherche la derniere
1336 MESSAGE ( "CreateCase1 : DirNameStart = " << DirNameStart << ", Number = " << Number );
1337 std::string nomDirWork = getenv("PWD") ;
1338 std::string DirNameStartIter ;
1340 int NumeIterMax = -1 ;
1342 // A.1. Controle du repertoire de depart du cas
1343 codret = chdir(DirNameStart) ;
1346 SALOME::ExceptionStruct es;
1347 es.type = SALOME::BAD_PARAM;
1348 es.text = "The directory of the case for the pursuit does not exist.";
1349 throw SALOME::SALOME_Exception(es);
1352 // A.2. Reperage des sous-repertoire du repertoire de reprise
1353 bool existe = false ;
1355 struct dirent *dirp;
1356 dp = opendir(DirNameStart);
1357 while ( (dirp = readdir(dp)) != NULL )
1359 std::string DirName_1(dirp->d_name);
1360 if ( ( DirName_1 != "." ) and ( DirName_1 != ".." ) )
1362 if ( chdir(DirName_1.c_str()) == 0 )
1364 // On cherche le fichier de configuration dans ce sous-repertoire
1365 codret = chdir(DirNameStart) ;
1367 struct dirent *dirp_1;
1368 dp_1 = opendir(DirName_1.c_str()) ;
1369 while ( (dirp_1 = readdir(dp_1)) != NULL )
1371 std::string file_name_1(dirp_1->d_name);
1372 int bilan = file_name_1.find("HOMARD.Configuration.") ;
1373 if ( bilan != string::npos )
1375 // Decodage du fichier pour trouver le numero d'iteration
1376 chdir(DirName_1.c_str()) ;
1377 std::ifstream fichier( file_name_1.c_str() );
1378 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1381 std::string ligne; // variable contenant chaque ligne lue
1382 std::string mot_cle;
1383 // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1384 while ( std::getline( fichier, ligne ) )
1386 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1387 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1388 ligne_bis >> mot_cle ;
1389 if ( mot_cle == "NumeIter" )
1391 ligne_bis >> NumeIter ;
1393 // MESSAGE ( "==> NumeIter : " << NumeIter ) ;
1394 if ( Number == - 1 )
1396 if ( NumeIter >= NumeIterMax )
1398 NumeIterMax = NumeIter ;
1399 DirNameStartIter = DirName_1 ;
1404 if ( NumeIter == Number )
1406 DirNameStartIter = DirName_1 ;
1416 SALOME::ExceptionStruct es;
1417 es.type = SALOME::BAD_PARAM;
1418 std::string text = "The configuration file cannot be read." ;
1419 es.text = CORBA::string_dup(text.c_str());
1420 throw SALOME::SALOME_Exception(es);
1422 chdir(DirNameStart) ;
1424 if ( existe ) { break ; }
1427 if ( existe ) { break ; }
1433 chdir(nomDirWork.c_str());
1435 if ( ( Number >= 0 and ( not existe ) ) or ( Number < 0 and ( NumeIterMax == -1 ) ) )
1437 SALOME::ExceptionStruct es;
1438 es.type = SALOME::BAD_PARAM;
1439 es.text = "The directory of the iteration does not exist.";
1440 throw SALOME::SALOME_Exception(es);
1444 return DirNameStartIter ;
1446 //=============================================================================
1447 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCase0(const char* nomCas, const char* MeshName, const char* MeshFile, CORBA::Long MeshOption, CORBA::Long NumeIter, CORBA::Long Option)
1449 // nomCas : nom du cas a creer
1450 // MeshName, MeshFile : nom et fichier du maillage correspondant
1451 // MeshOption : 0 : le maillage fourni est obligatoirement present ==> erreur si absent
1452 // 1 : le maillage fourni peut ne pas exister ==> on continue si absent
1453 // -1 : le maillage n'est pas fourni
1454 // NumeIter : numero de l'iteration correspondante : 0, pour un depart, n>0 pour une poursuite
1455 // Option : multiple de nombres premiers
1456 // 1 : aucune option
1457 // x2 : publication du maillage dans SMESH
1459 MESSAGE ( "CreateCase0 : nomCas = " << nomCas );
1460 MESSAGE ( "CreateCase0 : MeshName = " << MeshName << ", MeshFile = " << MeshFile << ", MeshOption = " << MeshOption );
1461 MESSAGE ( "CreateCase0 : NumeIter = " << NumeIter << ", Option = " << Option );
1467 // A.2. Controle du nom :
1468 if ((myContextMap[GetCurrentStudyID()]._mesCas).find(nomCas)!=(myContextMap[GetCurrentStudyID()]._mesCas).end())
1470 SALOME::ExceptionStruct es;
1471 es.type = SALOME::BAD_PARAM;
1472 es.text = "This case has already been defined.";
1473 throw SALOME::SALOME_Exception(es);
1477 // A.3. Controle du fichier du maillage
1478 int existeMeshFile ;
1479 if ( MeshOption >= 0 )
1481 existeMeshFile = MEDFileExist ( MeshFile ) ;
1482 MESSAGE ( "CreateCase0 : existeMeshFile = " << existeMeshFile );
1483 if ( ( existeMeshFile == 0 ) and ( MeshOption == 0 ) )
1485 SALOME::ExceptionStruct es;
1486 es.type = SALOME::BAD_PARAM;
1487 es.text = "The mesh file does not exist.";
1488 throw SALOME::SALOME_Exception(es);
1492 else { existeMeshFile = 0 ; }
1494 // B. Creation de l'objet cas et publication
1495 // MESSAGE ( "CreateCase0 : Creation de l'objet" );
1496 HOMARD::HOMARD_Cas_var myCase = newCase();
1497 myCase->SetName(nomCas);
1498 SALOMEDS::SObject_var aSO;
1499 PublishInStudy(myCurrentStudy, aSO, myCase, nomCas);
1500 myContextMap[GetCurrentStudyID()]._mesCas[nomCas] = myCase;
1502 // C. Caracteristiques du maillage
1503 if ( existeMeshFile != 0 )
1505 // Les valeurs extremes des coordonnees
1506 // MESSAGE ( "CreateCase0 : Les valeurs extremes des coordonnees" );
1507 std::vector<double> LesExtremes =GetBoundingBoxInMedFile(MeshFile) ;
1508 HOMARD::extrema_var aSeq = new HOMARD::extrema() ;
1509 if (LesExtremes.size()!=10) { return false; }
1511 for (int i =0 ; i< LesExtremes.size() ; i++)
1512 aSeq[i]=LesExtremes[i] ;
1513 myCase->SetBoundingBox(aSeq) ;
1515 // MESSAGE ( "CreateCase0 : Les groupes" );
1516 std::set<std::string> LesGroupes =GetListeGroupesInMedFile(MeshFile) ;
1517 HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType ;
1518 aSeqGroupe->length(LesGroupes.size());
1519 std::set<std::string>::const_iterator it ;
1521 for (it=LesGroupes.begin() ; it != LesGroupes.end() ; it++)
1522 aSeqGroupe[i++]=(*it).c_str() ;
1523 myCase->SetGroups(aSeqGroupe) ;
1526 // D. L'iteration initiale du cas
1527 MESSAGE ( "CreateCase0 : iteration initiale du cas" );
1528 // D.1. Recherche d'un nom : par defaut, on prend le nom du maillage correspondant.
1529 // Si ce nom d'iteration existe deja, on incremente avec 0, 1, 2, etc.
1531 std::string NomIteration = std::string(MeshName) ;
1532 while ( (myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration) != (myContextMap[GetCurrentStudyID()]._mesIterations.end()) )
1534 std::ostringstream nom;
1535 nom << MeshName << monNum;
1536 NomIteration = nom.str();
1539 MESSAGE ( "CreateCas0 : ==> NomIteration = " << NomIteration );
1541 // D.2. Creation de l'iteration
1542 HOMARD::HOMARD_Iteration_var anIter = newIteration();
1543 myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration] = anIter;
1544 anIter->SetName(NomIteration.c_str());
1545 AssociateCaseIter (nomCas, NomIteration.c_str(), "IterationHomard");
1547 // D.4. Maillage correspondant
1548 if ( existeMeshFile != 0 )
1550 anIter->SetMeshFile(MeshFile);
1551 if ( Option % 2 == 0 ) { PublishResultInSmesh(MeshFile, 0); }
1553 anIter->SetMeshName(MeshName);
1555 // D.5. Numero d'iteration
1556 anIter->SetNumber(NumeIter);
1559 SetEtatIter(NomIteration.c_str(), -NumeIter);
1562 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1564 //=============================================================================
1565 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::CreateHypothesis(const char* nomHypothesis)
1567 INFOS ( "CreateHypothesis : nomHypothesis = " << nomHypothesis );
1570 // Controle du nom :
1571 if ((myContextMap[GetCurrentStudyID()]._mesHypotheses).find(nomHypothesis) != (myContextMap[GetCurrentStudyID()]._mesHypotheses).end())
1573 SALOME::ExceptionStruct es;
1574 es.type = SALOME::BAD_PARAM;
1575 es.text = "This hypothesis has already been defined.";
1576 throw SALOME::SALOME_Exception(es);
1580 HOMARD::HOMARD_Hypothesis_var myHypothesis = newHypothesis();
1581 myHypothesis->SetName(nomHypothesis);
1582 myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis] = myHypothesis;
1583 SALOMEDS::SObject_var aSO;
1584 PublishInStudy(myCurrentStudy, aSO, myHypothesis, nomHypothesis);
1586 // Valeurs par defaut des options avancees
1587 myHypothesis->SetNivMax(-1);
1588 myHypothesis->SetDiamMin(-1.0);
1589 myHypothesis->SetAdapInit(0);
1590 myHypothesis->SetLevelOutput(0);
1592 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1595 //=============================================================================
1596 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::CreateIteration(const char* NomIteration, const char* nomIterParent)
1597 //=============================================================================
1599 INFOS ("CreateIteration : NomIteration = " << NomIteration << ", nomIterParent = " << nomIterParent);
1602 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterParent];
1603 if (CORBA::is_nil(myIterationParent))
1605 SALOME::ExceptionStruct es;
1606 es.type = SALOME::BAD_PARAM;
1607 es.text = "The parent iteration is not defined.";
1608 throw SALOME::SALOME_Exception(es);
1612 const char* nomCas = myIterationParent->GetCaseName();
1613 MESSAGE ("CreateIteration : nomCas = " << nomCas);
1614 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1615 if (CORBA::is_nil(myCase))
1617 SALOME::ExceptionStruct es;
1618 es.type = SALOME::BAD_PARAM;
1619 es.text = "Invalid case context";
1620 throw SALOME::SALOME_Exception(es);
1623 const char* nomDirCase = myCase->GetDirName();
1625 // Controle du nom :
1626 if ((myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration)!=(myContextMap[GetCurrentStudyID()]._mesIterations).end())
1628 SALOME::ExceptionStruct es;
1629 es.type = SALOME::BAD_PARAM;
1630 es.text = "This iteration has already been defined.";
1631 throw SALOME::SALOME_Exception(es);
1635 HOMARD::HOMARD_Iteration_var myIteration = newIteration();
1636 if (CORBA::is_nil(myIteration))
1638 SALOME::ExceptionStruct es;
1639 es.type = SALOME::BAD_PARAM;
1640 es.text = "Unable to create the iteration";
1641 throw SALOME::SALOME_Exception(es);
1644 myContextMap[GetCurrentStudyID()]._mesIterations[std::string(NomIteration)] = myIteration;
1645 // Nom de l'iteration et du maillage
1646 myIteration->SetName(NomIteration);
1647 myIteration->SetMeshName(NomIteration);
1648 myIteration->SetState(1);
1650 int numero = myIterationParent->GetNumber() + 1;
1651 myIteration->SetNumber(numero);
1653 // Nombre d'iterations deja connues pour le cas, permettant
1654 // la creation d'un sous-repertoire unique
1655 int nbitercase = myCase->GetNumberofIter();
1656 char* nomDirIter = CreateDirNameIter(nomDirCase, nbitercase );
1657 myIteration->SetDirNameLoc(nomDirIter);
1659 // Le nom du fichier du maillage MED est indice par le nombre d'iterations du cas.
1660 // Si on a une chaine unique depuis le depart, ce nombre est le meme que le
1661 // numero d'iteration dans la sucession : maill.01.med, maill.02.med, etc... C'est la
1662 // situation la plus frequente.
1663 // Si on a plusieurs branches, donc des iterations du meme niveau d'adaptation, utiliser
1664 // le nombre d'iterations du cas permet d'eviter les collisions.
1666 if ( nbitercase < 100 ) { jaux = 2 ; }
1667 else if ( nbitercase < 1000 ) { jaux = 3 ; }
1668 else if ( nbitercase < 10000 ) { jaux = 4 ; }
1669 else if ( nbitercase < 100000 ) { jaux = 5 ; }
1671 std::ostringstream iaux ;
1672 iaux << std::setw(jaux) << std::setfill('0') << nbitercase ;
1673 std::stringstream MeshFile;
1674 MeshFile << nomDirCase << "/maill." << iaux.str() << ".med";
1675 myIteration->SetMeshFile(MeshFile.str().c_str());
1677 // Association avec le cas
1678 std::string label = "IterationHomard_" + std::string(nomIterParent);
1679 AssociateCaseIter(nomCas, NomIteration, label.c_str());
1680 // Lien avec l'iteration precedente
1681 myIterationParent->LinkNextIteration(NomIteration);
1682 myIteration->SetIterParentName(nomIterParent);
1684 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1686 //=============================================================================
1687 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundary(const char* BoundaryName, CORBA::Long BoundaryType)
1689 MESSAGE ("CreateBoundary : BoundaryName = " << BoundaryName << ", BoundaryType = " << BoundaryType);
1692 // Controle du nom :
1693 if ((myContextMap[GetCurrentStudyID()]._mesBoundarys).find(BoundaryName)!=(myContextMap[GetCurrentStudyID()]._mesBoundarys).end())
1695 MESSAGE ("CreateBoundary : la frontiere " << BoundaryName << " existe deja");
1696 SALOME::ExceptionStruct es;
1697 es.type = SALOME::BAD_PARAM;
1698 es.text = "This boundary has already been defined";
1699 throw SALOME::SALOME_Exception(es);
1703 HOMARD::HOMARD_Boundary_var myBoundary = newBoundary();
1704 myBoundary->SetName(BoundaryName);
1705 myBoundary->SetType(BoundaryType);
1707 myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName] = myBoundary;
1709 SALOMEDS::SObject_var aSO;
1710 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myBoundary, BoundaryName);
1712 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1714 //=============================================================================
1715 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
1717 INFOS ("CreateBoundaryDi : BoundaryName = " << BoundaryName << "MeshName = " << MeshName );
1718 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
1719 myBoundary->SetMeshFile( MeshFile ) ;
1720 myBoundary->SetMeshName( MeshName ) ;
1722 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1724 //=============================================================================
1725 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCylinder(const char* BoundaryName,
1726 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1727 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1728 CORBA::Double Rayon)
1730 INFOS ("CreateBoundaryCylinder : BoundaryName = " << BoundaryName ) ;
1732 SALOME::ExceptionStruct es;
1735 { es.text = "The radius must be positive." ;
1737 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1738 if ( daux < 0.0000001 )
1739 { es.text = "The axis must be a non 0 vector." ;
1743 es.type = SALOME::BAD_PARAM;
1744 throw SALOME::SALOME_Exception(es);
1748 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 1) ;
1749 myBoundary->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon ) ;
1751 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1753 //=============================================================================
1754 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundarySphere(const char* BoundaryName,
1755 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1756 CORBA::Double Rayon)
1758 INFOS ("CreateBoundarySphere : BoundaryName = " << BoundaryName ) ;
1760 SALOME::ExceptionStruct es;
1763 { es.text = "The radius must be positive." ;
1767 es.type = SALOME::BAD_PARAM;
1768 throw SALOME::SALOME_Exception(es);
1772 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 2) ;
1773 myBoundary->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
1775 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1777 //=============================================================================
1778 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeA(const char* BoundaryName,
1779 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe, CORBA::Double Angle,
1780 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre)
1782 INFOS ("CreateBoundaryConeA : BoundaryName = " << BoundaryName ) ;
1784 SALOME::ExceptionStruct es;
1786 if ( Angle <= 0.0 or Angle >= 90.0 )
1787 { es.text = "The angle must be included higher than 0 degree and lower than 90 degrees." ;
1789 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1790 if ( daux < 0.0000001 )
1791 { es.text = "The axis must be a non 0 vector." ;
1795 es.type = SALOME::BAD_PARAM;
1796 throw SALOME::SALOME_Exception(es);
1800 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 3) ;
1801 myBoundary->SetConeA( Xaxe, Yaxe, Zaxe, Angle, Xcentre, Ycentre, Zcentre ) ;
1803 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1805 //=============================================================================
1806 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeR(const char* BoundaryName,
1807 CORBA::Double Xcentre1, CORBA::Double Ycentre1, CORBA::Double Zcentre1, CORBA::Double Rayon1,
1808 CORBA::Double Xcentre2, CORBA::Double Ycentre2, CORBA::Double Zcentre2, CORBA::Double Rayon2)
1810 INFOS ("CreateBoundaryConeR : BoundaryName = " << BoundaryName ) ;
1812 SALOME::ExceptionStruct es;
1814 if ( Rayon1 < 0.0 or Rayon2 < 0.0 )
1815 { es.text = "The radius must be positive." ;
1817 double daux = fabs(Rayon2-Rayon1) ;
1818 if ( daux < 0.0000001 )
1819 { es.text = "The radius must be different." ;
1821 daux = fabs(Xcentre2-Xcentre1) + fabs(Ycentre2-Ycentre1) + fabs(Zcentre2-Zcentre1) ;
1822 if ( daux < 0.0000001 )
1823 { es.text = "The centers must be different." ;
1827 es.type = SALOME::BAD_PARAM;
1828 throw SALOME::SALOME_Exception(es);
1832 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 4) ;
1833 myBoundary->SetConeR( Xcentre1, Ycentre1, Zcentre1, Rayon1, Xcentre2, Ycentre2, Zcentre2, Rayon2 ) ;
1835 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1837 //=============================================================================
1838 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZone(const char* ZoneName, CORBA::Long ZoneType)
1840 MESSAGE ("CreateZone : ZoneName = " << ZoneName << ", ZoneType = " << ZoneType);
1843 // Controle du nom :
1844 if ((myContextMap[GetCurrentStudyID()]._mesZones).find(ZoneName)!=(myContextMap[GetCurrentStudyID()]._mesZones).end())
1846 SALOME::ExceptionStruct es;
1847 es.type = SALOME::BAD_PARAM;
1848 es.text = "This zone has already been defined";
1849 throw SALOME::SALOME_Exception(es);
1853 HOMARD::HOMARD_Zone_var myZone = newZone();
1854 myZone->SetName(ZoneName);
1855 myZone->SetType(ZoneType);
1857 myContextMap[GetCurrentStudyID()]._mesZones[ZoneName] = myZone;
1859 SALOMEDS::SObject_var aSO;
1860 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myZone, ZoneName);
1862 return HOMARD::HOMARD_Zone::_duplicate(myZone);
1864 //=============================================================================
1865 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox(const char* ZoneName,
1866 CORBA::Double Xmini, CORBA::Double Xmaxi,
1867 CORBA::Double Ymini, CORBA::Double Ymaxi,
1868 CORBA::Double Zmini, CORBA::Double Zmaxi)
1870 INFOS ("CreateZoneBox : ZoneName = " << ZoneName ) ;
1872 SALOME::ExceptionStruct es;
1874 if ( Xmini > Xmaxi )
1875 { es.text = "The X coordinates are not coherent." ;
1877 if ( Ymini > Ymaxi )
1878 { es.text = "The Y coordinates are not coherent." ;
1880 if ( Zmini > Zmaxi )
1881 { es.text = "The Z coordinates are not coherent." ;
1885 es.type = SALOME::BAD_PARAM;
1886 throw SALOME::SALOME_Exception(es);
1890 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 2) ;
1891 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
1893 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1895 //=============================================================================
1896 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneSphere(const char* ZoneName,
1897 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre, CORBA::Double Rayon)
1899 INFOS ("CreateZoneSphere : ZoneName = " << ZoneName ) ;
1901 SALOME::ExceptionStruct es;
1904 { es.text = "The radius must be positive." ;
1908 es.type = SALOME::BAD_PARAM;
1909 throw SALOME::SALOME_Exception(es);
1913 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 4) ;
1914 myZone->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
1916 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1918 //=============================================================================
1919 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneCylinder(const char* ZoneName,
1920 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1921 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1922 CORBA::Double Rayon, CORBA::Double Haut)
1924 INFOS ("CreateZoneCylinder : ZoneName = " << ZoneName ) ;
1926 SALOME::ExceptionStruct es;
1929 { es.text = "The radius must be positive." ;
1931 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1932 if ( daux < 0.0000001 )
1933 { es.text = "The axis must be a non 0 vector." ;
1936 { es.text = "The height must be positive." ;
1940 es.type = SALOME::BAD_PARAM;
1941 throw SALOME::SALOME_Exception(es);
1945 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 5) ;
1946 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut ) ;
1948 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1950 //=============================================================================
1951 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZonePipe(const char* ZoneName,
1952 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1953 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1954 CORBA::Double Rayon, CORBA::Double Haut, CORBA::Double Rayonint)
1956 INFOS ("CreateZonePipe : ZoneName = " << ZoneName ) ;
1958 SALOME::ExceptionStruct es;
1960 if ( Rayon <= 0.0 or Rayonint <= 0.0 )
1961 { es.text = "The radius must be positive." ;
1963 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1964 if ( daux < 0.0000001 )
1965 { es.text = "The axis must be a non 0 vector." ;
1968 { es.text = "The height must be positive." ;
1970 if ( Rayon <= Rayonint )
1971 { es.text = "The external radius must be higher than the internal radius." ;
1975 es.type = SALOME::BAD_PARAM;
1976 throw SALOME::SALOME_Exception(es);
1980 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 7) ;
1981 myZone->SetPipe( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut, Rayonint ) ;
1983 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1985 //=============================================================================
1986 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox2D(const char* ZoneName,
1987 CORBA::Double Umini, CORBA::Double Umaxi,
1988 CORBA::Double Vmini, CORBA::Double Vmaxi,
1991 INFOS ("CreateZoneBox2D : ZoneName = " << ZoneName ) ;
1992 // MESSAGE ("Umini = " << Umini << ", Umaxi =" << Umaxi ) ;
1993 // MESSAGE ("Vmini = " << Vmini << ", Vmaxi =" << Vmaxi ) ;
1994 // MESSAGE ("Orient = " << Orient ) ;
1996 SALOME::ExceptionStruct es;
1998 if ( Umini > Umaxi )
1999 { es.text = "The first coordinates are not coherent." ;
2001 if ( Vmini > Vmaxi )
2002 { es.text = "The second coordinates are not coherent." ;
2004 if ( Orient < 1 or Orient > 3 )
2005 { es.text = "The orientation must be 1, 2 or 3." ;
2009 es.type = SALOME::BAD_PARAM;
2010 throw SALOME::SALOME_Exception(es);
2014 double Xmini, Xmaxi ;
2015 double Ymini, Ymaxi ;
2016 double Zmini, Zmaxi ;
2024 else if ( Orient == 2 )
2031 else if ( Orient == 3 )
2038 else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
2040 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 10+Orient) ;
2041 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2043 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2045 //=============================================================================
2046 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDisk(const char* ZoneName,
2047 CORBA::Double Ucentre, CORBA::Double Vcentre,
2048 CORBA::Double Rayon,
2051 INFOS ("CreateZoneDisk : ZoneName = " << ZoneName ) ;
2053 SALOME::ExceptionStruct es;
2056 { es.text = "The radius must be positive." ;
2058 if ( Orient < 1 or Orient > 3 )
2059 { es.text = "The orientation must be 1, 2 or 3." ;
2063 es.type = SALOME::BAD_PARAM;
2064 throw SALOME::SALOME_Exception(es);
2072 { Xcentre = Ucentre ;
2075 else if ( Orient == 2 )
2078 Zcentre = Vcentre ; }
2079 else if ( Orient == 3 )
2080 { Xcentre = Vcentre ;
2082 Zcentre = Ucentre ; }
2083 else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
2085 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 30+Orient) ;
2086 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1. ) ;
2088 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2090 //=============================================================================
2091 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDiskWithHole(const char* ZoneName,
2092 CORBA::Double Ucentre, CORBA::Double Vcentre,
2093 CORBA::Double Rayon, CORBA::Double Rayonint,
2096 INFOS ("CreateZoneDiskWithHole : ZoneName = " << ZoneName ) ;
2098 SALOME::ExceptionStruct es;
2100 if ( Rayon <= 0.0 or Rayonint <= 0.0 )
2101 { es.text = "The radius must be positive." ;
2103 if ( Orient < 1 or Orient > 3 )
2104 { es.text = "The orientation must be 1, 2 or 3." ;
2106 if ( Rayon <= Rayonint )
2107 { es.text = "The external radius must be higher than the internal radius." ;
2111 es.type = SALOME::BAD_PARAM;
2112 throw SALOME::SALOME_Exception(es);
2120 { Xcentre = Ucentre ;
2123 else if ( Orient == 2 )
2126 Zcentre = Vcentre ; }
2127 else if ( Orient == 3 )
2128 { Xcentre = Vcentre ;
2130 Zcentre = Ucentre ; }
2131 else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
2133 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 60+Orient) ;
2134 myZone->SetPipe( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1., Rayonint ) ;
2136 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2138 //=============================================================================
2139 //=============================================================================
2144 //=============================================================================
2145 //=============================================================================
2146 // Traitement d'une iteration
2147 // etatMenage = 1 : destruction du repertoire d'execution
2148 // modeHOMARD = 1 : adaptation
2149 // != 1 : information avec les options modeHOMARD
2150 // Option1 >0 : appel depuis python
2151 // <0 : appel depuis GUI
2152 // Option2 : multiple de nombres premiers
2153 // 1 : aucune option
2154 // x2 : publication du maillage dans SMESH
2155 //=============================================================================
2156 CORBA::Long HOMARD_Gen_i::Compute(const char* NomIteration, CORBA::Long etatMenage, CORBA::Long modeHOMARD, CORBA::Long Option1, CORBA::Long Option2)
2158 INFOS ( "Compute : traitement de " << NomIteration << ", avec modeHOMARD = " << modeHOMARD << ", Option1 = " << Option1 << ", Option2 = " << Option2 );
2163 // A.1. L'objet iteration
2164 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration];
2165 ASSERT(!CORBA::is_nil(myIteration));
2167 // A.2. Numero de l'iteration
2168 // siterp1 : numero de l'iteration a traiter
2170 // siter : numero de l'iteration parent, ou 0 si deja au debut mais cela ne servira pas !
2171 // Ou si information :
2173 int NumeIter = myIteration->GetNumber();
2174 std::string siterp1 ;
2175 std::stringstream saux1 ;
2177 siterp1 = saux1.str() ;
2178 if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
2181 if ( modeHOMARD==1 )
2183 std::stringstream saux0 ;
2184 int iaux = max(0, NumeIter-1) ;
2186 siter = saux0.str() ;
2187 if (NumeIter < 11) { siter = "0" + siter ; }
2190 { siter = siterp1 ; }
2193 const char* nomCas = myIteration->GetCaseName();
2194 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
2195 ASSERT(!CORBA::is_nil(myCase));
2197 // B. Les repertoires
2198 // B.1. Le repertoire courant
2199 std::string nomDirWork = getenv("PWD") ;
2200 // B.2. Le sous-repertoire de l'iteration a traiter
2201 char* DirCompute = ComputeDirManagement(myCase, myIteration, etatMenage);
2202 MESSAGE( ". DirCompute = " << DirCompute );
2204 // C. Le fichier des messages
2205 // C.1. Le deroulement de l'execution de HOMARD
2206 std::string LogFile = DirCompute ;
2207 LogFile += "/Liste" ;
2208 if ( modeHOMARD == 1 ) { LogFile += "." + siter + ".vers." + siterp1 ; }
2210 MESSAGE (". LogFile = " << LogFile);
2211 if ( modeHOMARD == 1 ) { myIteration->SetLogFile(LogFile.c_str()); }
2212 // C.2. Le bilan de l'analyse du maillage
2213 std::string FileInfo = DirCompute ;
2215 if ( modeHOMARD == 1 ) { FileInfo += "apad" ; }
2217 { if ( NumeIter == 0 ) { FileInfo += "info_av" ; }
2218 else { FileInfo += "info_ap" ; }
2220 FileInfo += "." + siterp1 + ".bilan" ;
2221 myIteration->SetFileInfo(FileInfo.c_str());
2223 // D. On passe dans le repertoire de l'iteration a calculer
2224 MESSAGE ( ". On passe dans DirCompute = " << DirCompute );
2227 // E. Les donnees de l'execution HOMARD
2228 // E.1. L'objet du texte du fichier de configuration
2229 HomardDriver* myDriver = new HomardDriver(siter, siterp1);
2230 std::string Langue = "Francais" ;
2231 myDriver->TexteInit(DirCompute, LogFile, Langue);
2233 // E.2. Le maillage associe a l'iteration
2234 const char* NomMesh = myIteration->GetMeshName();
2235 MESSAGE ( ". NomMesh = " << NomMesh );
2236 const char* MeshFile = myIteration->GetMeshFile();
2237 MESSAGE ( ". MeshFile = " << MeshFile );
2239 // E.3. Les donnees du traitement HOMARD
2241 if ( modeHOMARD == 1 )
2244 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2245 myDriver->TexteMaillage(NomMesh, MeshFile, 1);
2246 codret = ComputeAdap(myCase, myIteration, etatMenage, myDriver, Option1, Option2) ;
2250 InvalideIterInfo(NomIteration);
2251 myDriver->TexteInfo( modeHOMARD, NumeIter ) ;
2253 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2254 myDriver->TexteMaillage(NomMesh, MeshFile, 0);
2255 myDriver->CreeFichierDonn();
2258 // E.4. Ajout des informations liees a l'eventuel suivi de frontiere
2259 DriverTexteBoundary(myCase, myDriver) ;
2261 // E.5. Ecriture du texte dans le fichier
2263 { myDriver->CreeFichier(); }
2267 int codretexec = 12 ;
2270 codretexec = myDriver->ExecuteHomard(Option1);
2272 MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
2273 if ( modeHOMARD == 1 )
2275 if (codretexec == 0) { SetEtatIter(NomIteration,2); }
2276 else { SetEtatIter(NomIteration,1); }
2277 // GERALD -- QMESSAGE BOX
2281 // H. Gestion des resultats
2284 std::string Commentaire ;
2285 // H.1. Le fichier des messages, dans tous les cas
2286 Commentaire = "log" ;
2287 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2288 else { Commentaire += "Info" ; }
2289 PublishFileUnderIteration(NomIteration, LogFile.c_str(), Commentaire.c_str());
2291 // H.2. Si tout s'est bien passe :
2292 if (codretexec == 0)
2294 // H.2.1. Le fichier de bilan
2295 Commentaire = "Summary" ;
2296 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2297 else { Commentaire += "Info" ; }
2298 PublishFileUnderIteration(NomIteration, FileInfo.c_str(), Commentaire.c_str());
2299 // H.2.2. Le fichier de maillage obtenu
2300 if ( modeHOMARD == 1 )
2302 std::stringstream saux0 ;
2303 Commentaire = "Iteration" ;
2304 Commentaire += " " + siter ;
2305 PublishFileUnderIteration(NomIteration, MeshFile, Commentaire.c_str());
2306 if ( Option2 % 2 == 0 ) { PublishResultInSmesh(MeshFile, 1); }
2309 // H.3 Message d'erreur en cas de probleme
2312 SALOME::ExceptionStruct es;
2313 es.type = SALOME::BAD_PARAM;
2314 std::string text = "Error during the adaptation.\n" ;
2317 ifstream fichier(LogFile.c_str(), ios::in);
2319 while(getline(fichier, ligne) and (ligne != "===== HOMARD ===== STOP ====="));
2320 while (getline(fichier, ligne)) { text += ligne+ "\n";};
2323 text += "no log file ....";
2325 es.text = CORBA::string_dup(text.c_str());
2326 throw SALOME::SALOME_Exception(es);
2330 // I. Menage et retour dans le repertoire du cas
2334 MESSAGE ( ". On retourne dans nomDirWork = " << nomDirWork );
2335 chdir(nomDirWork.c_str());
2340 //=============================================================================
2341 // Calcul d'une iteration : partie specifique a l'adaptation
2342 //=============================================================================
2343 CORBA::Long HOMARD_Gen_i::ComputeAdap(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage, HomardDriver* myDriver, CORBA::Long Option1, CORBA::Long Option2)
2345 MESSAGE ( "ComputeAdap" );
2350 // Etat de l'iteration
2351 int etat = myIteration->GetState();
2352 // Numero de l'iteration
2353 int NumeIter = myIteration->GetNumber();
2354 std::stringstream saux0 ;
2355 saux0 << NumeIter-1 ;
2356 std::string siter = saux0.str() ;
2357 if (NumeIter < 11) { siter = "0" + siter ; }
2359 // A.2. On ne calcule pas l iteration initiale
2362 MESSAGE ( "etat = "<<etat );
2363 SALOME::ExceptionStruct es;
2364 es.type = SALOME::BAD_PARAM;
2365 es.text = "This iteration is the first of the case and cannot be computed.";
2366 throw SALOME::SALOME_Exception(es);
2370 // A.3. On verifie qu il y a une hypothese (erreur improbable);
2371 const char* nomHypo = myIteration->GetHypoName();
2372 if (std::string(nomHypo) == std::string(""))
2374 SALOME::ExceptionStruct es;
2375 es.type = SALOME::BAD_PARAM;
2376 es.text = "This iteration does not have any associated hypothesis.";
2377 throw SALOME::SALOME_Exception(es);
2380 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
2381 ASSERT(!CORBA::is_nil(myHypo));
2383 // B. L'iteration parent
2384 const char* nomIterationParent = myIteration->GetIterParentName();
2385 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
2386 ASSERT(!CORBA::is_nil(myIterationParent));
2387 // Si l'iteration parent n'est pas calculee, on le fait (recursivite amont)
2388 if ( myIterationParent->GetState() == 1 )
2391 int codret = Compute(nomIterationParent, etatMenage, iaux, Option1, Option2);
2394 // GERALD -- QMESSAGE BOX
2395 ASSERT("Pb au calcul de l'iteration precedente" == 0);
2399 // C. Le sous-repertoire de l'iteration precedente
2400 char* DirComputePa = ComputeDirPaManagement(myCase, myIteration);
2401 MESSAGE( ". DirComputePa = " << DirComputePa );
2403 // D. Les donnees de l'adaptation HOMARD
2404 // D.1. Le type de conformite
2405 int ConfType = myCase->GetConfType();
2406 MESSAGE ( ". ConfType = " << ConfType );
2408 // D.2. Le maillage de depart
2409 const char* NomMeshParent = myIterationParent->GetMeshName();
2410 MESSAGE ( ". NomMeshParent = " << NomMeshParent );
2411 const char* MeshFileParent = myIterationParent->GetMeshFile();
2412 MESSAGE ( ". MeshFileParent = " << MeshFileParent );
2414 // D.3. Le maillage associe a l'iteration
2415 const char* MeshFile = myIteration->GetMeshFile();
2416 MESSAGE ( ". MeshFile = " << MeshFile );
2417 FILE *file = fopen(MeshFile,"r");
2421 if (etatMenage == 0)
2423 SALOME::ExceptionStruct es;
2424 es.type = SALOME::BAD_PARAM;
2425 std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
2426 es.text = CORBA::string_dup(text.c_str());
2427 throw SALOME::SALOME_Exception(es);
2432 std::string commande = "rm -f " + std::string(MeshFile);
2433 codret = system(commande.c_str());
2436 SALOME::ExceptionStruct es;
2437 es.type = SALOME::BAD_PARAM;
2438 es.text = "The mesh file cannot be deleted.";
2439 throw SALOME::SALOME_Exception(es);
2445 // D.4. Les types de raffinement et de deraffinement
2446 // Les appels corba sont lourds, il vaut mieux les grouper
2447 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
2448 ASSERT(ListTypes->length() == 3);
2449 int TypeAdap = (*ListTypes)[0];
2450 int TypeRaff = (*ListTypes)[1];
2451 int TypeDera = (*ListTypes)[2];
2453 // E. Texte du fichier de configuration
2454 // E.1. Incontournables du texte
2455 myDriver->TexteAdap();
2457 myDriver->TexteMaillageHOMARD( DirComputePa, siter, iaux ) ;
2458 myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
2459 myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
2461 // E.2. Ajout des informations liees aux zones eventuelles
2462 if ( TypeAdap == 0 )
2463 { DriverTexteZone(myHypo, myDriver) ; }
2465 // E.3. Ajout des informations liees aux champs eventuels
2466 if ( TypeAdap == 1 )
2467 { DriverTexteField(myIteration, myHypo, myDriver) ; }
2469 // E.4. Ajout des informations liees au filtrage eventuel par les groupes
2470 HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
2471 int numberOfGroups = listeGroupes->length();
2472 MESSAGE( ". Filtrage par " << numberOfGroups << " groupes");
2473 if (numberOfGroups > 0)
2475 for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
2477 std::string GroupName = std::string((*listeGroupes)[NumGroup]);
2478 MESSAGE( "... GroupName = " << GroupName );
2479 myDriver->TexteGroup(GroupName);
2483 // E.5. Ajout des informations liees a l'eventuelle interpolation des champs
2484 DriverTexteFieldInterp(myIteration, myHypo, myDriver) ;
2486 // E.6. Ajout des options avancees
2487 int Pyram = myCase->GetPyram();
2488 MESSAGE ( ". Pyram = " << Pyram );
2489 int NivMax = myHypo->GetNivMax();
2490 MESSAGE ( ". NivMax = " << NivMax );
2491 double DiamMin = myHypo->GetDiamMin() ;
2492 MESSAGE ( ". DiamMin = " << DiamMin );
2493 int AdapInit = myHypo->GetAdapInit();
2494 MESSAGE ( ". AdapInit = " << AdapInit );
2495 int LevelOutput = myHypo->GetLevelOutput();
2496 MESSAGE ( ". LevelOutput = " << LevelOutput );
2497 myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, LevelOutput);
2499 // E.7. Ajout des informations sur le deroulement de l'execution
2500 int MessInfo = myIteration->GetInfoCompute();
2501 MESSAGE ( ". MessInfo = " << MessInfo );
2502 myDriver->TexteInfoCompute(MessInfo);
2506 //=============================================================================
2507 // Creation d'un nom de sous-repertoire pour l'iteration au sein d'un repertoire parent
2508 // nomrep : nom du repertoire parent
2509 // num : le nom du sous-repertoire est sous la forme 'In', n est >= num
2510 //=============================================================================
2511 char* HOMARD_Gen_i::CreateDirNameIter(const char* nomrep, CORBA::Long num )
2513 MESSAGE ( "CreateDirNameIter : nomrep ="<< nomrep << ", num = "<<num);
2514 // On verifie que le repertoire parent existe
2515 int codret = chdir(nomrep) ;
2518 SALOME::ExceptionStruct es;
2519 es.type = SALOME::BAD_PARAM;
2520 es.text = "The directory of the case does not exist.";
2521 throw SALOME::SALOME_Exception(es);
2524 std::string nomDirActuel = getenv("PWD") ;
2525 std::string DirName ;
2526 // On boucle sur tous les noms possibles jusqu'a trouver un nom correspondant a un repertoire inconnu
2527 bool a_chercher = true ;
2528 while ( a_chercher )
2530 // On passe dans le repertoire parent
2532 // On recherche un nom sous la forme Iabc, avec abc representant le numero
2534 if ( num < 100 ) { jaux = 2 ; }
2535 else if ( num < 1000 ) { jaux = 3 ; }
2536 else if ( num < 10000 ) { jaux = 4 ; }
2537 else if ( num < 100000 ) { jaux = 5 ; }
2539 std::ostringstream iaux ;
2540 iaux << std::setw(jaux) << std::setfill('0') << num ;
2541 std::ostringstream DirNameA ;
2542 DirNameA << "I" << iaux.str();
2543 // Si on ne pas peut entrer dans le repertoire, on doit verifier
2544 // que c'est bien un probleme d'absence
2545 if ( chdir(DirNameA.str().c_str()) != 0 )
2547 bool existe = false ;
2549 struct dirent *dirp;
2550 dp = opendir(nomrep);
2551 while ( (dirp = readdir(dp)) != NULL )
2553 std::string file_name(dirp->d_name);
2554 if ( file_name == DirNameA.str() ) { existe = true ; }
2559 DirName = DirNameA.str() ;
2560 a_chercher = false ;
2567 MESSAGE ( "==> DirName = " << DirName);
2568 MESSAGE ( ". On retourne dans nomDirActuel = " << nomDirActuel );
2569 chdir(nomDirActuel.c_str());
2571 return CORBA::string_dup( DirName.c_str() );
2573 //=============================================================================
2574 // Calcul d'une iteration : gestion du repertoire de calcul
2575 // Si le sous-repertoire existe :
2576 // etatMenage = 0 : on sort en erreur si le repertoire n'est pas vide
2577 // etatMenage = 1 : on fait le menage du repertoire
2578 // etatMenage = -1 : on ne fait rien
2579 //=============================================================================
2580 char* HOMARD_Gen_i::ComputeDirManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage)
2582 MESSAGE ( "ComputeDirManagement : repertoires pour le calcul" );
2583 // B.2. Le repertoire du cas
2584 const char* nomDirCase = myCase->GetDirName();
2585 MESSAGE ( ". nomDirCase = " << nomDirCase );
2587 // B.3. Le sous-repertoire de l'iteration a calculer, puis le repertoire complet a creer
2588 // B.3.1. Le nom du sous-repertoire
2589 const char* nomDirIt = myIteration->GetDirNameLoc();
2591 // B.3.2. Le nom complet du sous-repertoire
2592 std::stringstream DirCompute ;
2593 DirCompute << nomDirCase << "/" << nomDirIt;
2594 MESSAGE (". DirCompute = " << DirCompute.str() );
2596 // B.3.3. Si le sous-repertoire n'existe pas, on le cree
2597 if (chdir(DirCompute.str().c_str()) != 0)
2599 // Creation du repertoire car il n'existe pas :
2600 if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
2602 // GERALD -- QMESSAGE BOX
2603 std::cerr << "Pb Creation du repertoire DirCompute = " << DirCompute.str() << std::endl;
2604 ASSERT("Pb a la creation du repertoire" == 0);
2609 // Le repertoire existe
2610 // On demande de faire le menage de son contenu :
2611 if (etatMenage == 1)
2613 MESSAGE (". Menage du repertoire DirCompute = " << DirCompute.str());
2614 std::string commande= "rm -rf " + DirCompute.str()+"/*" ;
2615 int codret = system(commande.c_str());
2618 // GERALD -- QMESSAGE BOX
2619 std::cerr << ". Menage du repertoire de calcul" << DirCompute.str() << std::endl;
2620 ASSERT("Pb au menage du repertoire de calcul" == 0);
2623 // On n'a pas demande de faire le menage de son contenu : on sort en erreur :
2626 if (etatMenage == 0)
2629 struct dirent *dirp;
2630 dp = opendir(DirCompute.str().c_str());
2632 while ((dirp = readdir(dp)) != NULL && result )
2634 std::string file_name(dirp->d_name);
2635 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
2638 if ( result == false)
2640 SALOME::ExceptionStruct es;
2641 es.type = SALOME::BAD_PARAM;
2642 std::string text = "Directory : " + DirCompute.str() + "is not empty";
2643 es.text = CORBA::string_dup(text.c_str());
2644 throw SALOME::SALOME_Exception(es);
2645 ASSERT("Directory is not empty" == 0);
2651 return CORBA::string_dup( DirCompute.str().c_str() );
2653 //=============================================================================
2654 // Calcul d'une iteration : gestion du repertoire de calcul de l'iteration parent
2655 //=============================================================================
2656 char* HOMARD_Gen_i::ComputeDirPaManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration)
2658 MESSAGE ( "ComputeDirPaManagement : repertoires pour le calcul" );
2659 // Le repertoire du cas
2660 const char* nomDirCase = myCase->GetDirName();
2661 MESSAGE ( ". nomDirCase = " << nomDirCase );
2663 // Le sous-repertoire de l'iteration precedente
2665 const char* nomIterationParent = myIteration->GetIterParentName();
2666 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
2667 const char* nomDirItPa = myIterationParent->GetDirNameLoc();
2668 std::stringstream DirComputePa ;
2669 DirComputePa << nomDirCase << "/" << nomDirItPa;
2670 MESSAGE( ". nomDirItPa = " << nomDirItPa);
2671 MESSAGE( ". DirComputePa = " << DirComputePa.str() );
2673 return CORBA::string_dup( DirComputePa.str().c_str() );
2675 //=============================================================================
2676 // Calcul d'une iteration : ecriture des zones dans le fichier de configuration
2677 //=============================================================================
2678 void HOMARD_Gen_i::DriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
2680 MESSAGE ( "... DriverTexteZone" );
2681 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
2682 int numberOfZonesx2 = ListZone->length();
2685 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
2687 std::string ZoneName = std::string((*ListZone)[iaux]);
2688 MESSAGE ( "... ZoneName = " << ZoneName);
2689 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
2690 ASSERT(!CORBA::is_nil(myZone));
2692 int ZoneType = myZone->GetType();
2693 std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
2694 int TypeUse = atoi( TypeUsestr.c_str() );
2695 MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
2696 NumZone = iaux/2 + 1 ;
2697 HOMARD::double_array* zone = myZone->GetCoords();
2698 if ( ZoneType == 2 or ( ZoneType>=11 and ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
2699 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.); }
2700 else if ( ZoneType == 4 ) // Cas d une sphere
2701 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.); }
2702 else if ( ZoneType == 5 or ( ZoneType>=31 and ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
2703 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.); }
2704 else if ( ZoneType == 7 or ( ZoneType>=61 and ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
2705 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]); }
2706 else { ASSERT("ZoneType est incorrect." == 0) ; }
2711 //=============================================================================
2712 // Calcul d'une iteration : ecriture des champs dans le fichier de configuration
2713 //=============================================================================
2714 void HOMARD_Gen_i::DriverTexteField(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
2716 MESSAGE ( "... DriverTexteField" );
2717 // Le fichier du champ
2718 char* FieldFile = myIteration->GetFieldFile();
2719 MESSAGE ( ". FieldFile = " << FieldFile );
2720 if (strlen(FieldFile) == 0)
2722 // GERALD -- QMESSAGE BOX
2723 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
2724 ASSERT("The file for the field is not given." == 0);
2726 // Les caracteristiques d'instants
2727 int TimeStep = myIteration->GetTimeStep();
2728 MESSAGE( ". TimeStep = " << TimeStep );
2729 int Rank = myIteration->GetRank();
2730 MESSAGE( ". Rank = " << Rank );
2731 // Les informations sur les champs
2732 HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
2734 const char* FieldName = aInfosHypo->FieldName;
2736 int TypeThR = aInfosHypo->TypeThR;
2737 double ThreshR = aInfosHypo->ThreshR;
2738 int TypeThC = aInfosHypo->TypeThC;
2739 double ThreshC = aInfosHypo->ThreshC;
2740 // Saut entre mailles ou non ?
2741 int UsField = aInfosHypo->UsField;
2742 MESSAGE( ". UsField = " << UsField );
2743 // L'usage des composantes
2744 int UsCmpI = aInfosHypo->UsCmpI;
2745 MESSAGE( ". UsCmpI = " << UsCmpI );
2747 myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
2750 HOMARD::listeComposantsHypo* mescompo = myHypo->GetListComp();
2751 int numberOfCompos = mescompo->length();
2752 MESSAGE( ". numberOfCompos = " << numberOfCompos );
2753 for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
2755 std::string nomCompo = std::string((*mescompo)[NumeComp]);
2756 MESSAGE( "... nomCompo = " << nomCompo );
2757 myDriver->TexteCompo(NumeComp, nomCompo);
2761 //=============================================================================
2762 // Calcul d'une iteration : ecriture des frontieres dans le fichier de configuration
2763 //=============================================================================
2764 void HOMARD_Gen_i::DriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, HomardDriver* myDriver)
2766 MESSAGE ( "... DriverTexteBoundary" );
2767 // On ecrit d'abord la definition des frontieres, puis les liens avec les groupes
2768 std::list<std::string> ListeBoundaryTraitees ;
2769 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
2770 int numberOfitems = ListBoundaryGroupType->length();
2771 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
2772 int BoundaryOption = 1 ;
2773 int NumBoundaryAnalytical = 0 ;
2774 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
2776 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
2777 MESSAGE ( "... BoundaryName = " << BoundaryName);
2779 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
2780 while (it != ListeBoundaryTraitees.end())
2782 MESSAGE ( "..... BoundaryNameTraitee = " << *it);
2783 if ( BoundaryName == *it ) { A_faire = 0 ; }
2788 // Caracteristiques de la frontiere
2789 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
2790 ASSERT(!CORBA::is_nil(myBoundary));
2791 int BoundaryType = myBoundary->GetType();
2792 MESSAGE ( "... BoundaryType = " << BoundaryType );
2793 // Ecriture selon le type
2794 if (BoundaryType == 0) // Cas d une frontiere discrete
2796 const char* MeshName = myBoundary->GetMeshName() ;
2797 const char* MeshFile = myBoundary->GetMeshFile() ;
2798 myDriver->TexteBoundaryDi( MeshName, MeshFile);
2799 if ( BoundaryOption % 2 != 0 ) { BoundaryOption = BoundaryOption*2 ; }
2801 else // Cas d une frontiere analytique
2803 NumBoundaryAnalytical++ ;
2804 HOMARD::double_array* coor = myBoundary->GetCoords();
2805 if (BoundaryType == 1) // Cas d un cylindre
2807 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
2808 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
2810 else if (BoundaryType == 2) // Cas d une sphere
2812 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0., 0.);
2813 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
2815 else if (BoundaryType == 3) // Cas d un cone defini par un axe et un angle
2817 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
2818 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
2820 else if (BoundaryType == 4) // Cas d un cone defini par les 2 rayons
2822 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
2823 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
2826 // Memorisation du traitement
2827 ListeBoundaryTraitees.push_back( BoundaryName );
2830 NumBoundaryAnalytical = 0 ;
2831 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
2833 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
2834 MESSAGE ( "... BoundaryName = " << BoundaryName);
2835 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
2836 ASSERT(!CORBA::is_nil(myBoundary));
2837 int BoundaryType = myBoundary->GetType();
2838 MESSAGE ( "... BoundaryType = " << BoundaryType );
2839 // Recuperation du nom du groupe
2840 std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
2841 MESSAGE ( "... GroupName = " << GroupName);
2842 if (BoundaryType == 0) // Cas d une frontiere discrete
2844 if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
2846 else // Cas d une frontiere analytique
2848 NumBoundaryAnalytical++ ;
2849 myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
2852 myDriver->TexteBoundaryOption(BoundaryOption);
2855 //=============================================================================
2856 // Calcul d'une iteration : ecriture des interpolations dans le fichier de configuration
2857 //=============================================================================
2858 void HOMARD_Gen_i::DriverTexteFieldInterp(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
2860 MESSAGE ( "... DriverTexteFieldInterp" );
2861 int TypeFieldInterp = myHypo->GetTypeFieldInterp();
2862 if (TypeFieldInterp != 0)
2864 // Le fichier des champs
2865 char* FieldFile = myIteration->GetFieldFile();
2866 MESSAGE ( ". FieldFile = " << FieldFile );
2867 if (strlen(FieldFile) == 0)
2869 // GERALD -- QMESSAGE BOX
2870 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
2871 ASSERT("The file for the field is not given." == 0);
2873 // Les caracteristiques d'instants
2874 int TimeStep = myIteration->GetTimeStep();
2875 MESSAGE( ". TimeStep = " << TimeStep );
2876 int Rank = myIteration->GetRank();
2877 MESSAGE( ". Rank = " << Rank );
2879 const char* MeshFile = myIteration->GetMeshFile();
2880 myDriver->TexteFieldInterp(TypeFieldInterp, FieldFile, MeshFile, TimeStep, Rank);
2882 if (TypeFieldInterp == 2)
2884 HOMARD::listFieldInterpHypo* meschamps = myHypo->GetListFieldInterp();
2885 int numberOfFields = meschamps->length();
2886 MESSAGE( ". numberOfFields = " << numberOfFields );
2887 for (int NumeChamp = 0; NumeChamp< numberOfFields; NumeChamp++)
2889 std::string nomChamp = std::string((*meschamps)[NumeChamp]);
2890 MESSAGE( "... nomChamp = " << nomChamp );
2891 myDriver->TexteFieldInterpName(NumeChamp, nomChamp);
2897 //===========================================================================
2898 //===========================================================================
2901 //===========================================================================
2902 //===========================================================================
2904 //===========================================================================
2905 //===========================================================================
2906 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
2907 SALOMEDS::SObject_ptr theSObject,
2908 CORBA::Object_ptr theObject,
2909 const char* theName)
2911 MESSAGE("PublishInStudy pour " << theName);
2912 SALOMEDS::SObject_var aResultSO;
2913 if (CORBA::is_nil(theStudy))
2915 SALOME::ExceptionStruct es;
2916 es.type = SALOME::BAD_PARAM;
2917 es.text = "Invalid study context";
2918 throw SALOME::SALOME_Exception(es);
2922 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
2923 // Rq : Iteration est publiee ailleurs
2924 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(theObject);
2925 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
2926 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
2927 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
2929 addInStudy(theStudy);
2931 // Controle de la non publication d'un objet de meme nom
2932 if ((!aHypo->_is_nil()) or (!aZone->_is_nil()) or (!aBoundary->_is_nil()))
2934 SALOMEDS::Study::ListOfSObject_var listSO = theStudy->FindObjectByName(theName, ComponentDataType());
2935 if (listSO->length() >= 1)
2937 MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
2938 std::cerr <<"This name "<<theName<<" is already used "<<listSO->length()<<" time(s)" << std::endl;
2939 aResultSO = listSO[0];
2940 return aResultSO._retn();
2944 // Caracteristiques de l'etude
2945 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
2946 aStudyBuilder->NewCommand();
2947 if(!aCase->_is_nil())
2948 aResultSO = PublishCaseInStudy(theStudy, aStudyBuilder, aCase, theName);
2949 else if(!aHypo->_is_nil())
2950 aResultSO = PublishHypotheseInStudy(theStudy, aStudyBuilder, aHypo, theName);
2951 else if(!aZone->_is_nil())
2952 aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName);
2953 else if(!aBoundary->_is_nil())
2954 aResultSO = PublishBoundaryInStudy(theStudy, aStudyBuilder, aBoundary, theName);
2956 aStudyBuilder->CommitCommand();
2957 return aResultSO._retn();
2959 //=============================================================================
2960 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::Study_ptr theStudy,
2961 SALOMEDS::StudyBuilder_var aStudyBuilder,
2962 HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
2964 MESSAGE("PublishCaseInStudy pour "<<theName);
2965 SALOMEDS::SObject_var aResultSO;
2966 SALOMEDS::GenericAttribute_var anAttr;
2968 if (CORBA::is_nil(theObject)) {
2969 MESSAGE("HOMARD_Gen_i::theObject->_is_nil()");
2970 return aResultSO._retn();
2972 if (theStudy->_is_nil()) {
2973 MESSAGE("HOMARD_Gen_i::theStudy->_is_nil()");
2974 return aResultSO._retn();
2977 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
2978 if (theFatherHomard->_is_nil())
2980 MESSAGE("theFatherHomard->_is_nil()");
2981 return aResultSO._retn();
2984 aResultSO = aStudyBuilder->NewObject(theFatherHomard);
2985 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
2986 _orb->object_to_string(theObject) ) ;
2987 return aResultSO._retn();
2990 //=============================================================================
2991 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::Study_ptr theStudy,
2992 SALOMEDS::StudyBuilder_var aStudyBuilder,
2993 HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
2995 MESSAGE("PublishZoneStudy pour "<<theName);
2996 SALOMEDS::SObject_var aResultSO;
2997 SALOMEDS::GenericAttribute_var anAttr;
2999 if (CORBA::is_nil(theObject))
3001 MESSAGE("PublishZoneInStudy : theObject->_is_nil()");
3002 return aResultSO._retn();
3004 if (theStudy->_is_nil())
3006 MESSAGE("PublishZoneInStudy : theStudy->_is_nil()");
3007 return aResultSO._retn();
3009 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3010 if (theFatherHomard->_is_nil())
3012 MESSAGE("PublishZoneInStudy : theFatherHomard->_is_nil()");
3013 return aResultSO._retn();
3016 // Caracteristique de la zone
3017 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[theName];
3018 CORBA::Long ZoneType = myZone->GetType();
3020 // On ajoute la categorie des zones dans l etude si necessaire
3021 SALOMEDS::SObject_var aSOZone;
3022 if (!theFatherHomard->FindSubObject(100, aSOZone))
3024 MESSAGE("Ajout de la categorie des zones");
3025 aSOZone = aStudyBuilder->NewObjectToTag(theFatherHomard, 100);
3026 PublishInStudyAttr(aStudyBuilder, aSOZone, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
3028 else { MESSAGE("La categorie des zones existe deja."); }
3030 aResultSO = aStudyBuilder->NewObject(aSOZone);
3039 { icone = "boxdxy_2.png" ;
3043 { icone = "boxdxyz_2.png" ;
3051 { icone = "disk_2.png" ;
3055 { icone = "spherepoint_2.png" ;
3059 { icone = "cylinderpointvector_2.png" ;
3067 { icone = "diskwithhole_2.png" ;
3071 { icone = "pipe_2.png" ;
3075 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone.c_str(), _orb->object_to_string(theObject) ) ;
3077 return aResultSO._retn();
3079 //=============================================================================
3080 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy(SALOMEDS::Study_ptr theStudy,
3081 SALOMEDS::StudyBuilder_var aStudyBuilder,
3082 HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
3084 MESSAGE("PublishBoundaryStudy pour "<<theName);
3085 SALOMEDS::SObject_var aResultSO;
3086 SALOMEDS::GenericAttribute_var anAttr;
3088 // Caracteristique de la Boundary
3089 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[theName];
3091 // On recupere le module pere dans l etude
3092 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3093 if (theFatherHomard->_is_nil())
3095 MESSAGE("theFatherHomard->_is_nil()");
3096 return aResultSO._retn();
3099 // On ajoute la categorie des boundarys dans l etude si necessaire
3100 SALOMEDS::SObject_var aSOBoundary;
3101 if (!theFatherHomard->FindSubObject(101, aSOBoundary))
3103 MESSAGE("Ajout de la categorie des boundarys");
3104 aSOBoundary = aStudyBuilder->NewObjectToTag(theFatherHomard, 101);
3105 PublishInStudyAttr(aStudyBuilder, aSOBoundary, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
3107 else { MESSAGE("La categorie des boundarys existe deja."); }
3109 aResultSO = aStudyBuilder->NewObject(aSOBoundary);
3110 CORBA::Long BoundaryType = myBoundary->GetType();
3111 // MESSAGE("BoundaryType : "<<BoundaryType);
3114 switch (BoundaryType)
3117 { value = "BoundaryDiHomard" ;
3118 icone = "mesh_tree_mesh.png" ;
3122 { value = "BoundaryAnHomard" ;
3123 icone = "cylinderpointvector_2.png" ;
3127 { value = "BoundaryAnHomard" ;
3128 icone = "spherepoint_2.png" ;
3132 { value = "BoundaryAnHomard" ;
3133 icone = "conepointvector.png" ;
3137 { value = "BoundaryAnHomard" ;
3138 icone = "conedxyz.png" ;
3142 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value.c_str(), icone.c_str(), _orb->object_to_string(theObject));
3143 return aResultSO._retn();
3146 //=============================================================================
3147 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::Study_ptr theStudy,
3148 SALOMEDS::StudyBuilder_var aStudyBuilder,
3149 HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
3151 MESSAGE("PublishHypotheseInStudy pour "<<theName);
3152 SALOMEDS::SObject_var aResultSO;
3153 SALOMEDS::GenericAttribute_var anAttr;
3155 // On recupere le module pere dans l etude
3156 // On ajoute la categorie des hypotheses dans l etude si necessaire
3157 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3158 if (theFatherHomard->_is_nil())
3160 MESSAGE("theFatherHomard->_is_nil()");
3161 return aResultSO._retn();
3163 SALOMEDS::SObject_var aSOHypothese;
3164 if (!theFatherHomard->FindSubObject(0, aSOHypothese))
3166 MESSAGE("Ajout de la categorie des hypotheses");
3167 aSOHypothese = aStudyBuilder->NewObjectToTag(theFatherHomard, 0);
3168 PublishInStudyAttr(aStudyBuilder, aSOHypothese, "Hypothesis", "HypoList","hypotheses.png", NULL);
3170 else { MESSAGE("La categorie des hypotheses existe deja."); }
3172 // Creation du resultat dans l'etude
3173 aResultSO = aStudyBuilder->NewObject(aSOHypothese);
3174 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
3176 return aResultSO._retn();
3178 //===========================================================================
3179 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
3180 SALOMEDS::SObject_var aResultSO,
3181 const char* name, const char* value, const char* icone, const char* ior)
3183 SALOMEDS::GenericAttribute_var anAttr ;
3187 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
3188 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
3189 aNameAttrib->SetValue(name);
3192 // Ajout du commentaire
3193 if ( value != NULL )
3195 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
3196 SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
3197 aCommentAttrib->SetValue(value);
3201 if ( icone != NULL )
3203 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO,"AttributePixMap");
3204 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
3205 aPixmap->SetPixMap(icone);
3211 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
3212 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3213 anIOR->SetValue(ior);
3217 //=====================================================================================
3218 void HOMARD_Gen_i::PublishBoundaryUnderCase(const char* CaseName, const char* BoundaryName)
3220 MESSAGE ( "PublishBoundaryUnderCase : CaseName = " << CaseName << ", BoundaryName= " << BoundaryName );
3222 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3223 ASSERT(!CORBA::is_nil(myCase));
3224 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3225 ASSERT(!CORBA::is_nil(aCaseSO));
3227 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3228 ASSERT(!CORBA::is_nil(myBoundary));
3229 SALOMEDS::SObject_var aBoundarySO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myBoundary)));
3230 ASSERT(!CORBA::is_nil(aBoundarySO));
3232 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3234 aStudyBuilder->NewCommand();
3236 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aCaseSO);
3237 aStudyBuilder->Addreference(aSubSO, aBoundarySO);
3239 aStudyBuilder->CommitCommand();
3242 //=============================================================================
3243 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long Option)
3244 // Option = 0 : fichier issu d'une importation
3245 // Option = 1 : fichier issu d'une execution HOMARD
3247 MESSAGE( "PublishResultInSmesh " << NomFich << ", avec Option = " << Option);
3248 if (CORBA::is_nil(myCurrentStudy))
3250 SALOME::ExceptionStruct es;
3251 es.type = SALOME::BAD_PARAM;
3252 es.text = "Invalid study context";
3253 throw SALOME::SALOME_Exception(es);
3257 // Le module SMESH est-il actif ?
3258 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3260 if (!CORBA::is_nil(aSmeshSO))
3262 // On verifie que le fichier n est pas deja publie
3263 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3264 for (; aIter->More(); aIter->Next())
3266 SALOMEDS::SObject_var aSO = aIter->Value();
3267 SALOMEDS::GenericAttribute_var aGAttr;
3268 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3270 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3271 CORBA::String_var value=anAttr->Value();
3272 if (strcmp((const char*)value,NomFich) == 0)
3274 MESSAGE ( "PublishResultInSmesh : le fichier " << NomFich << " est deja publie." );
3275 // Pour un fichier importe, on ne republie pas
3280 // Pour un fichier calcule, on commence par faire la depublication
3283 MESSAGE ( "PublishResultInSmesh : depublication" );
3284 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3285 CORBA::String_var value2=anAttr2->Value();
3286 std::string MeshName = string(value2) ;
3287 MESSAGE ( "PublishResultInSmesh : depublication de " << MeshName );
3288 DeleteResultInSmesh(NomFich, MeshName) ;
3295 // On enregistre le fichier
3296 MESSAGE( "Enregistrement du fichier");
3297 SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
3298 SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
3299 ASSERT(!CORBA::is_nil(aSmeshEngine));
3300 aSmeshEngine->SetCurrentStudy(myCurrentStudy);
3301 SMESH::DriverMED_ReadStatus theStatus;
3302 //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3304 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
3305 SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3306 for (int i = 0; i < mesMaillages->length(); i++)
3308 MESSAGE( ". Mise a jour des attributs du maillage");
3309 SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
3310 SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
3311 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3312 SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
3313 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3314 anAttr->SetValue(NomFich);
3315 SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
3316 SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
3318 if ( Option == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
3319 else { icone = "mesh_tree_mesh.png" ; }
3320 anAttr2->SetPixMap( icone );
3324 //=============================================================================
3325 void HOMARD_Gen_i::DeleteResultInSmesh(std::string NomFich, std::string MeshName)
3327 MESSAGE (" DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich );
3328 if (CORBA::is_nil(myCurrentStudy))
3330 SALOME::ExceptionStruct es;
3331 es.type = SALOME::BAD_PARAM;
3332 es.text = "Invalid study context";
3333 throw SALOME::SALOME_Exception(es);
3337 // Le module SMESH est-il actif ?
3338 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3340 if (CORBA::is_nil(aSmeshSO))
3344 // On verifie que le fichier est deja publie
3345 SALOMEDS::StudyBuilder_var myBuilder = myCurrentStudy->NewBuilder();
3346 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3347 for (; aIter->More(); aIter->Next())
3349 SALOMEDS::SObject_var aSO = aIter->Value();
3350 SALOMEDS::GenericAttribute_var aGAttr;
3351 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3353 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3354 CORBA::String_var value=anAttr->Value();
3355 if (strcmp((const char*)value,NomFich.c_str()) == 0)
3357 if (aSO->FindAttribute(aGAttr,"AttributeName"))
3359 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3360 CORBA::String_var value2=anAttr2->Value();
3361 if (strcmp((const char*)value2,MeshName.c_str()) == 0)
3363 myBuilder->RemoveObjectWithChildren( aSO ) ;
3371 //=============================================================================
3372 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
3374 // MESSAGE (" PublishFileUnderIteration pour l'iteration " << NomIter << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3375 if (CORBA::is_nil(myCurrentStudy))
3377 SALOME::ExceptionStruct es;
3378 es.type = SALOME::BAD_PARAM;
3379 es.text = "Invalid study context";
3380 throw SALOME::SALOME_Exception(es);
3384 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
3385 if (CORBA::is_nil(myIteration))
3387 SALOME::ExceptionStruct es;
3388 es.type = SALOME::BAD_PARAM;
3389 es.text = "Invalid iteration";
3390 throw SALOME::SALOME_Exception(es);
3393 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
3394 if (CORBA::is_nil(myIteration))
3396 SALOME::ExceptionStruct es;
3397 es.type = SALOME::BAD_PARAM;
3398 es.text = "Invalid iterationStudy Object";
3399 throw SALOME::SALOME_Exception(es);
3403 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3405 aStudyBuilder->NewCommand();
3407 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
3408 // Pour les fichiers med, on affiche une icone de maillage
3409 // Pour les fichiers qui sont texte, on affiche une icone de fichier texte 'texte'
3410 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
3412 std::string ior = " " ;
3413 if ( Commentaire[0] == 'I' )
3414 { icone = "med.png" ; }
3416 { icone = "texte_2.png" ; }
3417 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3419 aStudyBuilder->CommitCommand();
3422 //=============================================================================
3423 //=============================================================================
3425 //=============================================================================
3426 //=============================================================================
3427 //=============================================================================
3428 // Ecriture d'un schema YACS
3429 // nomCas : nom du cas a traiter
3430 // FileName : nom du fichier contenant le script de lancement du calcul
3431 // DirName : le repertoire de lancement des calculs du schéma
3432 //=============================================================================
3433 CORBA::Long HOMARD_Gen_i::WriteYACSSchema (const char* nomCas, const char* ScriptFile, const char* DirName, const char* MeshFile)
3435 INFOS ( "WriteYACSSchema : Schema YACS pour le cas " << nomCas);
3436 INFOS ( "ScriptFile : " << ScriptFile);
3437 INFOS ( "DirName : " << DirName);
3438 INFOS ( "MeshFile : " << MeshFile);
3444 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
3445 ASSERT(!CORBA::is_nil(myCase));
3446 // A.2. Le repertoire du cas
3447 std::string nomDirCase = myCase->GetDirName();
3448 MESSAGE ( ". nomDirCase = " << nomDirCase );
3449 // A.3. Les instructions python associees au cas
3450 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
3451 std::string pythonCas = dumpCorbaCase.in();
3452 MESSAGE ("pythonCas :\n"<<pythonCas<<"\n");
3454 // D. Les iterations
3455 // D.1. L'iteration initiale
3456 HOMARD::HOMARD_Iteration_var Iter0 = myCase->GetIter0() ;
3457 std::string Iter0Name = myCase->GetIter0Name() ;
3458 MESSAGE (". Iter0Name = " << Iter0Name);
3459 // D.2. L'iteration numero 1
3460 HOMARD::listeIterFilles* maListe = Iter0->GetIterations();
3461 int numberOfIter = maListe->length();
3462 if ( numberOfIter > 1 )
3464 MESSAGE (". numberOfIter = " << numberOfIter);
3465 SALOME::ExceptionStruct es ;
3466 es.type = SALOME::BAD_PARAM;
3467 std::string text = "Une seule iteration est permise." ;
3468 es.text = CORBA::string_dup(text.c_str());
3469 throw SALOME::SALOME_Exception(es);
3472 std::string Iter1Name = std::string((*maListe)[0]);
3473 MESSAGE ("... Iter1Name = " << Iter1Name);
3474 HOMARD::HOMARD_Iteration_var Iter1 = GetIteration(Iter1Name.c_str()) ;
3475 MESSAGE (". Iter1 = " << Iter1);
3478 // C.1. La structure
3479 std::string nomHypo = Iter1->GetHypoName();
3480 MESSAGE (". nomHypo = " << nomHypo);
3481 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
3482 ASSERT(!CORBA::is_nil(myHypo));
3483 // C.2. Les caracteristiques de l'adaptation
3484 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
3485 ASSERT(ListTypes->length() == 3);
3486 int TypeAdap = (*ListTypes)[0];
3487 // int TypeRaff = (*ListTypes)[1];
3488 // int TypeDera = (*ListTypes)[2];
3489 // C.3. Les instructions python associees a l'hypothese
3490 CORBA::String_var dumpCorbaHypo = myHypo->GetDumpPython();
3491 std::string pythonHypo = dumpCorbaHypo.in();
3492 MESSAGE ("pythonHypo :\n"<<pythonHypo<<"\n");
3494 // E. Les fichiers du schema
3495 // E.1. Le fichier du schema de reference
3496 // Le repertoire ou se trouve l'executable HOMARD
3497 std::string YACSFile_base ;
3498 if ( getenv("HOMARD_ROOT_DIR") != NULL ) { YACSFile_base = getenv("HOMARD_ROOT_DIR") ; }
3499 else { ASSERT("HOMARD_ROOT_DIR est inconnu." == 0) ; }
3500 YACSFile_base += "/share/salome/resources/homard/yacs_01.xml" ;
3501 MESSAGE("YACSFile_base ="<<YACSFile_base);
3502 // E.2. Le fichier du schema a creer
3503 std::string YACSFile = nomDirCase ;
3504 YACSFile += "/schema.xml" ;
3505 MESSAGE (". YACSFile = " << YACSFile);
3506 YACSDriver* myDriver = new YACSDriver(YACSFile, DirName);
3508 // F. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
3509 std::ifstream fichier( YACSFile_base.c_str() );
3510 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
3512 // F.1. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
3513 std::string ligne; // variable contenant chaque ligne lue
3514 std::string mot_cle;
3515 while ( std::getline( fichier, ligne ) )
3517 // F.1.1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
3518 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
3519 ligne_bis >> mot_cle ;
3520 // F.1.2. Le maillage initial
3521 if ( mot_cle == "DataInit_MeshFile" )
3523 myDriver->Texte_DataInit_MeshFile(MeshFile);
3525 // F.1.3. Le script de lancement
3526 else if ( mot_cle == "Alternance_Calcul_HOMARD_Calcul" )
3528 myDriver->Texte_Alternance_Calcul_HOMARD_Calcul(ScriptFile);
3530 // F.1.4. Les options du cas
3531 else if ( mot_cle == "HOMARD_Init_au_debut_Case_Options" )
3533 myDriver->Texte_HOMARD_Init_au_debut_Case_Options(pythonCas);
3535 // F.1.5. Execution de HOMARD : le repertoire du cas
3536 else if ( mot_cle == "HOMARD_Exec_DirName" )
3538 myDriver->Texte_HOMARD_Exec_DirName();
3540 // F.1.6. Execution de HOMARD : les options de l'hypothese
3541 else if ( mot_cle == "HOMARD_Exec_Hypo_Options" )
3543 myDriver->Texte_python( pythonHypo, 3, "Hypo" ) ;
3545 // F.1.7. Zones et frontieres : les creations
3546 else if ( mot_cle == "HOMARD_Init_au_debut" )
3548 std::string texte_control = myDriver->Texte_HOMARD_Init_au_debut_control() ;
3549 if ( TypeAdap == 0 ) { texte_control += YACSDriverTexteZone( myHypo, myDriver ) ; }
3550 texte_control += YACSDriverTexteBoundary( myCase, myDriver ) ;
3551 myDriver->TexteAdd(texte_control);
3553 // F.1.8. Zones : les parametres
3554 else if ( mot_cle == "PARAMETRES" )
3556 if ( TypeAdap == 0 )
3557 { myDriver->TexteAddParametres(); }
3559 // F.1.n. La ligne est recopiee telle quelle
3562 myDriver->TexteAdd(ligne);
3565 // F.2. Ecriture du texte dans le fichier
3567 { myDriver->CreeFichier(); }
3571 SALOME::ExceptionStruct es;
3572 es.type = SALOME::BAD_PARAM;
3573 std::string text = "The reference file for the YACS schema cannot be read." ;
3574 es.text = CORBA::string_dup(text.c_str());
3575 throw SALOME::SALOME_Exception(es);
3582 //=============================================================================
3583 // Ecriture d'un schema YACS : ecriture des zones associees a une hypothese
3584 //=============================================================================
3585 std::string HOMARD_Gen_i::YACSDriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, YACSDriver* myDriver)
3587 MESSAGE ( "YACSDriverTexteZone" );
3588 // A. Les zones associees a cette hypothese
3589 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
3590 int numberOfZonesx2 = ListZone->length();
3592 // B. Parcours des zones
3593 std::string texte_control ;
3594 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
3596 // 1. Reperage de la zone
3597 std::string ZoneName = std::string((*ListZone)[iaux]);
3598 MESSAGE ( "\n. ZoneName = " << ZoneName << " - " <<iaux);
3599 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
3600 ASSERT(!CORBA::is_nil(myZone));
3601 // 2. Les instructions python associees a la zone
3602 // La premiere ligne est un commentaire a eliminer
3603 // La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
3604 CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
3605 std::string pythonStructure_0 = dumpCorbaZone.in();
3606 MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
3607 std::istringstream tout (pythonStructure_0) ;
3609 std::string pythonStructure ;
3610 while ( std::getline( tout, ligne ) )
3611 { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
3612 MESSAGE ("pythonStructure :\n"<<pythonStructure);
3613 // 3. Decodage du nom du service
3614 std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
3615 MESSAGE ( "... methode = " << methode);
3616 // 4. Mise en place des instructions
3617 int ZoneType = myZone->GetType();
3618 MESSAGE ( "... ZoneType = " << ZoneType);
3619 std::string texte_control_0 ;
3620 texte_control_0 = myDriver->Texte_HOMARD_Init_au_debut_Zone(ZoneType, pythonStructure, methode, ZoneName );
3621 texte_control += texte_control_0 ;
3626 return texte_control ;
3628 //=============================================================================
3629 // Ecriture d'un schema YACS : ecriture des frontieres associees au cas
3630 //=============================================================================
3631 std::string HOMARD_Gen_i::YACSDriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, YACSDriver* myDriver)
3633 MESSAGE ( "YACSDriverTexteBoundary" );
3634 // A. Les frontieres associees au cas
3635 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
3636 int numberOfitems = ListBoundaryGroupType->length();
3638 // B. Parcours des frontieres
3639 std::string texte_control ;
3640 std::list<std::string> ListeBoundaryTraitees ;
3641 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3643 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3644 MESSAGE ( "... BoundaryName = " << BoundaryName);
3645 // Attention a n'ecrire la definition qu'une seule fois car elle peut se trouver
3646 // plusieurs fois dans la definition du cas, d'ou la liste ListeBoundaryTraitees
3648 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
3649 while (it != ListeBoundaryTraitees.end())
3651 MESSAGE ( "..... BoundaryNameTraitee = " << *it);
3652 if ( BoundaryName == *it ) { A_faire = 0 ; }
3657 // 1. Caracteristiques de la frontiere
3658 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3659 ASSERT(!CORBA::is_nil(myBoundary));
3660 // 2. Les instructions python associees a la frontiere
3661 // La premiere ligne est un commentaire a eliminer
3662 // La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
3663 CORBA::String_var dumpCorbaBoundary = myBoundary->GetDumpPython();
3664 std::string pythonStructure_0 = dumpCorbaBoundary.in();
3665 MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
3666 std::istringstream tout (pythonStructure_0) ;
3668 std::string pythonStructure ;
3669 while ( std::getline( tout, ligne ) )
3670 { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
3671 MESSAGE ("pythonStructure :\n"<<pythonStructure);
3672 // 3. Decodage du nom du service
3673 std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
3674 MESSAGE ( "... methode = " << methode);
3675 // 4. Mise en place des instructions
3676 int BoundaryType = myBoundary->GetType();
3677 MESSAGE ( "... BoundaryType = " << BoundaryType);
3678 std::string texte_control_0 ;
3679 texte_control_0 = myDriver->Texte_HOMARD_Init_au_debut_Boundary(BoundaryType, pythonStructure, methode, BoundaryName );
3680 texte_control += texte_control_0 ;
3681 // 5. Memorisation du traitement
3682 ListeBoundaryTraitees.push_back( BoundaryName );
3686 return texte_control ;
3689 //=============================================================================
3690 //=============================================================================
3691 // Next functions are inherited from SALOMEDS::Driver interface
3692 //=============================================================================
3693 //=============================================================================
3694 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
3696 CORBA::Boolean isMultiFile)
3698 MESSAGE (" Save for theURL = "<< theURL);
3699 SALOMEDS::TMPFile_var aStreamFile;
3701 // get temporary directory name
3702 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
3704 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
3705 StudyContext& context = myContextMap[ aStudy->StudyId() ];
3707 // HOMARD data file name
3708 std::string aFileName = "";
3710 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
3711 aFileName += "_HOMARD.dat";
3713 // initialize sequence of file names
3714 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
3715 aFileSeq->length(1);
3716 aFileSeq[0] = CORBA::string_dup(aFileName.c_str()) ;
3718 // get full path to the data file
3719 aFileName = tmpDir + aFileName;
3723 std::ofstream f(aFileName.c_str());
3725 // clear temporary id map
3726 context._idmap.clear();
3731 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
3732 for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
3733 HOMARD::HOMARD_Cas_var aCas = it_case->second;
3734 PortableServer::ServantBase_var aServant = GetServant(aCas);
3735 HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
3737 f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
3738 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
3742 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
3743 for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
3744 HOMARD::HOMARD_Zone_var aZone = it_zone->second;
3745 PortableServer::ServantBase_var aServant = GetServant(aZone);
3746 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
3748 f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
3749 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
3752 // -> save hypotheses
3753 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
3754 for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
3755 HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
3756 PortableServer::ServantBase_var aServant = GetServant(aHypo);
3757 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
3759 f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
3760 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
3763 // -> save iterations
3764 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
3765 for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
3766 HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
3767 PortableServer::ServantBase_var aServant = GetServant(aIter);
3768 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
3770 f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
3771 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
3774 // -> save boundaries
3775 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
3776 for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
3777 HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
3778 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
3779 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
3780 if (aBoundaryServant) {
3781 f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
3782 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
3786 MESSAGE ("close file");
3789 // put temporary files to the stream
3790 MESSAGE ("put temporary files to the stream");
3791 aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq.in(), isMultiFile);
3793 // remove temporary files
3794 MESSAGE ("remove temporary files");
3795 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
3797 // return data stream
3798 MESSAGE ("return data stream");
3799 return aStreamFile._retn();
3802 //===========================================================================
3803 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
3805 CORBA::Boolean isMultiFile)
3807 // No specific ASCII persistence
3808 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
3809 return aStreamFile._retn();
3812 //===========================================================================
3813 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
3814 const SALOMEDS::TMPFile& theStream,
3816 CORBA::Boolean isMultiFile)
3818 MESSAGE (" Load pour theURL = "<< theURL);
3819 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
3821 // set current study
3822 if (myCurrentStudy->_is_nil() || aStudy->StudyId() != myCurrentStudy->StudyId())
3823 SetCurrentStudy(aStudy);
3825 // get temporary directory name
3826 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
3828 // Convert the stream into sequence of files to process
3829 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
3832 // HOMARD data file name
3833 std::string aFileName = "";
3835 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
3836 aFileName = tmpDir + aFileName + "_HOMARD.dat";
3838 StudyContext& context = myContextMap[ aStudy->StudyId() ];
3842 std::ifstream f(aFileName.c_str());
3845 context._mesCas.clear();
3846 context._mesHypotheses.clear();
3847 context._mesIterations.clear();
3848 context._mesZones.clear();
3849 context._mesBoundarys.clear();
3850 context._idmap.clear();
3856 std::getline(f, line);
3857 std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
3858 std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
3859 std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
3860 std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
3861 std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
3862 if (line.substr(0, caseSignature.size()) == caseSignature) {
3864 MESSAGE (" Recreation du cas" );
3865 HOMARD::HOMARD_Cas_var aCase = newCase();
3866 PortableServer::ServantBase_var aServant = GetServant(aCase);
3867 HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
3868 if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
3869 context._mesCas[aCase->GetName()] = aCase;
3870 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
3873 else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
3874 MESSAGE (" Recreation de la zone" );
3876 HOMARD::HOMARD_Zone_var aZone = newZone();
3877 PortableServer::ServantBase_var aServant = GetServant(aZone);
3878 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
3879 if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
3880 context._mesZones[aZone->GetName()] = aZone;
3881 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
3884 else if (line.substr(0, iterSignature.size()) == iterSignature) {
3885 // re-create iteration
3886 MESSAGE (" Recreation de l iteration" );
3887 HOMARD::HOMARD_Iteration_var aIter = newIteration();
3888 PortableServer::ServantBase_var aServant = GetServant(aIter);
3889 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
3890 if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
3891 context._mesIterations[aIter->GetName()] = aIter;
3892 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
3895 else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
3896 // re-create hypothesis
3897 MESSAGE (" Recreation de l hypothese" );
3898 HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
3899 PortableServer::ServantBase_var aServant = GetServant(aHypo);
3900 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
3901 if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
3902 context._mesHypotheses[aHypo->GetName()] = aHypo;
3903 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
3906 else if (line.substr(0, bounSignature.size()) == bounSignature) {
3907 // re-create boundary
3908 MESSAGE (" Recreation de la frontiere" );
3909 HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
3910 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
3911 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
3912 if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
3913 context._mesBoundarys[aBoundary->GetName()] = aBoundary;
3914 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
3923 // Remove temporary files created from the stream
3925 SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
3930 //===========================================================================
3931 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
3932 const SALOMEDS::TMPFile& theStream,
3934 CORBA::Boolean isMultiFile)
3936 // No specific ASCII persistence
3937 return Load(theComponent, theStream, theURL, isMultiFile);
3940 //===========================================================================
3941 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
3943 if (theComponent->GetStudy()->StudyId() == GetCurrentStudyID()) {
3944 // clearing study context should be done here:
3945 // - destroy all servants and related CORBA objects
3947 // - remove context from myContextMap
3948 myContextMap.erase(theComponent->GetStudy()->StudyId());
3949 // - nullify myCurrentStudy
3950 myCurrentStudy = SALOMEDS::Study::_nil();
3954 //===========================================================================
3955 char* HOMARD_Gen_i::ComponentDataType()
3957 return CORBA::string_dup("HOMARD");
3960 //===========================================================================
3961 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
3962 const char* IORString,
3963 CORBA::Boolean isMultiFile,
3964 CORBA::Boolean isASCII)
3966 CORBA::String_var aString("");
3967 if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
3968 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
3969 CORBA::Object_var anObj = _orb->string_to_object(IORString);
3970 if (!CORBA::is_nil(anObj)) {
3971 PortableServer::ServantBase_var aServant = GetServant(anObj);
3972 PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
3974 std::map<int, PortableServer::ServantBase*>::const_iterator it;
3975 for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
3976 if (it->second == aStorable) {
3977 std::stringstream os;
3979 aString = CORBA::string_dup(os.str().c_str());
3985 return aString._retn();
3988 //===========================================================================
3989 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
3990 const char* aLocalPersistentID,
3991 CORBA::Boolean isMultiFile,
3992 CORBA::Boolean isASCII)
3994 CORBA::String_var aString("");
3995 if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
3996 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
3997 int id = atoi(aLocalPersistentID);
3998 if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
3999 CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
4000 if (!CORBA::is_nil(object)) {
4001 aString = _orb->object_to_string(object);
4005 return aString._retn();
4008 //===========================================================================
4009 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
4011 if(CORBA::is_nil(myCurrentStudy))
4014 HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
4015 if(!aCas->_is_nil())
4018 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
4019 if(!aHypo->_is_nil())
4022 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
4023 if(!aZone->_is_nil())
4026 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
4027 if(!aBoundary->_is_nil())
4030 /* Iteration is not published directly
4031 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
4032 if(!aIter->_is_nil())
4038 //===========================================================================
4039 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
4041 // No Copy/Paste support
4045 //===========================================================================
4046 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
4047 CORBA::Long& theObjectID)
4049 // No Copy/Paste support
4050 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
4051 return aStreamFile._retn();
4054 //===========================================================================
4055 CORBA::Boolean HOMARD_Gen_i::CanPaste(const char *theComponentName,
4056 CORBA::Long theObjectID)
4058 // No Copy/Paste support
4062 //===========================================================================
4063 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
4064 CORBA::Long theObjectID,
4065 SALOMEDS::SObject_ptr theSObject)
4067 // No Copy/Paste support
4068 SALOMEDS::SObject_var aResultSO;
4069 return aResultSO._retn();
4072 //===========================================================================
4073 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
4075 PortableServer::Servant aServant = 0;
4076 if (!CORBA::is_nil(theObject)) {
4078 aServant = _poa->reference_to_servant(theObject);
4086 //==========================================================================
4087 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
4088 CORBA::Boolean isPublished,
4089 CORBA::Boolean isMultiFile,
4090 CORBA::Boolean& isValidScript)
4092 MESSAGE ("Entree dans DumpPython");
4094 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
4095 if(CORBA::is_nil(aStudy))
4096 return new Engines::TMPFile(0);
4098 SALOMEDS::SObject_var aSO = aStudy->FindComponent("HOMARD");
4099 if(CORBA::is_nil(aSO))
4100 return new Engines::TMPFile(0);
4102 std::string aScript = "\"\"\"\n";
4103 aScript += "Python script for HOMARD\n";
4104 aScript += "Copyright EDF-R&D 2013\n";
4105 aScript += "\"\"\"\n";
4106 aScript += "__revision__ = \"V1.2\"\n";
4107 aScript += "import HOMARD\n";
4109 aScript += "import salome\n";
4110 aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
4112 aScript += "def RebuildData(theStudy):\n";
4113 aScript += "\thomard.SetCurrentStudy(theStudy)\n";
4116 aScript += "\thomard.SetCurrentStudy(salome.myStudy)\n";
4117 MESSAGE (". Au depart \n"<<aScript);
4120 if (myContextMap[GetCurrentStudyID()]._mesBoundarys.size() > 0)
4122 MESSAGE (". Ecritures des frontieres");
4123 aScript += "#\n# Creation of the boundaries";
4124 aScript += "\n# ==========================";
4126 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4127 for (it_boundary = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
4128 it_boundary != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); ++it_boundary)
4130 HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
4131 CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
4132 std::string dumpBoundary = dumpCorbaBoundary.in();
4133 MESSAGE (dumpBoundary<<"\n");
4134 aScript += dumpBoundary;
4138 if (myContextMap[GetCurrentStudyID()]._mesZones.size() > 0)
4140 MESSAGE (". Ecritures des zones");
4141 aScript += "#\n# Creation of the zones";
4142 aScript += "\n# =====================";
4144 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4145 for ( it_zone = myContextMap[GetCurrentStudyID()]._mesZones.begin();
4146 it_zone != myContextMap[GetCurrentStudyID()]._mesZones.end(); ++it_zone)
4148 HOMARD::HOMARD_Zone_var maZone = (*it_zone).second;
4149 CORBA::String_var dumpCorbaZone = maZone->GetDumpPython();
4150 std::string dumpZone = dumpCorbaZone.in();
4151 MESSAGE (dumpZone<<"\n");
4152 aScript += dumpZone;
4156 if (myContextMap[GetCurrentStudyID()]._mesHypotheses.size() > 0)
4158 MESSAGE (". Ecritures des hypotheses");
4159 aScript += "#\n# Creation of the hypotheses";
4160 aScript += "\n# ==========================";
4162 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4163 for ( it_hypo = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
4164 it_hypo != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it_hypo++)
4166 HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
4167 CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
4168 std::string dumpHypo = dumpCorbaHypo.in();
4169 MESSAGE (dumpHypo<<"\n");
4170 aScript += dumpHypo;
4174 if (myContextMap[GetCurrentStudyID()]._mesCas.size() > 0)
4176 MESSAGE (". Ecritures des cas");
4177 aScript += "#\n# Creation of the cases";
4178 aScript += "\n# =====================";
4180 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
4181 for (it_cas = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4182 it_cas != myContextMap[GetCurrentStudyID()]._mesCas.end(); it_cas++)
4184 std::string nomCas = (*it_cas).first;
4185 std::string dumpCas = std::string("\n# Creation of the case ") ;
4186 dumpCas += nomCas + std::string("\n");
4187 dumpCas += std::string("\t") + nomCas;
4188 dumpCas += std::string(" = homard.CreateCase(\"") + nomCas + std::string("\", \"");
4190 HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
4191 CORBA::String_var cIter0= myCase->GetIter0Name();
4192 std::string iter0 = cIter0.in();
4194 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[iter0];
4195 CORBA::String_var cMesh0= myIteration->GetMeshFile();
4196 std::string mesh0 = cMesh0.in();
4197 CORBA::String_var cMeshName0= myIteration->GetMeshName();
4198 std::string meshName0 = cMeshName0.in();
4199 dumpCas += meshName0 + std::string("\", \"")+ mesh0 + std::string("\")\n");
4200 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4201 std::string dumpCas2= dumpCorbaCase.in();
4203 MESSAGE (dumpCas<<dumpCas2<<"\n");
4204 aScript += dumpCas + dumpCas2;
4208 if (myContextMap[GetCurrentStudyID()]._mesIterations.size() > 0)
4210 MESSAGE (". Ecritures des iterations");
4211 aScript += "#\n# Creation of the iterations" ;
4212 aScript += "\n# ==========================";
4214 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4215 for (it_iter = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
4216 it_iter != myContextMap[GetCurrentStudyID()]._mesIterations.end(); ++it_iter)
4218 HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
4219 CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
4220 std::string dumpIter = dumpCorbaIter.in();
4221 MESSAGE (dumpIter<<"\n");
4222 aScript += dumpIter;
4225 MESSAGE (". Ecritures finales");
4227 aScript += "\n\tpass";
4230 if( !isMultiFile ) // remove unnecessary tabulation
4231 aScript = RemoveTabulation( aScript );
4233 // MESSAGE ("A ecrire \n"<<aScript);
4234 const size_t aLen = strlen(aScript.c_str());
4235 char* aBuffer = new char[aLen+1];
4236 strcpy(aBuffer, aScript.c_str());
4238 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
4239 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
4241 MESSAGE ("Sortie de DumpPython");
4242 return aStreamFile._retn();
4246 //=============================================================================
4247 //=============================================================================
4249 //=============================================================================
4250 //=============================================================================
4251 void HOMARD_Gen_i::IsValidStudy( )
4253 // MESSAGE( "IsValidStudy" );
4254 if (CORBA::is_nil(myCurrentStudy))
4256 SALOME::ExceptionStruct es;
4257 es.type = SALOME::BAD_PARAM;
4258 es.text = "Invalid study context";
4259 throw SALOME::SALOME_Exception(es);
4264 //=============================================================================
4265 CORBA::Boolean HOMARD_Gen_i::VerifieDir(const char* nomDir)
4267 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
4268 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4269 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
4271 if (std::string(nomDir) == std::string(it->second->GetDirName())) return false;
4275 /*//=============================================================================
4276 void SALOMEException( std::string message )
4278 SALOME::ExceptionStruct es;
4279 es.type = SALOME::BAD_PARAM;
4281 throw SALOME::SALOME_Exception(es);
4284 //=============================================================================
4285 char* HOMARD_Gen_i::getVersion()
4287 #if HOMARD_DEVELOPMENT
4288 return CORBA::string_dup(HOMARD_VERSION_STR"dev");
4290 return CORBA::string_dup(HOMARD_VERSION_STR);
4293 //===============================================================================
4294 // Recuperation de la chaine de caracteres par rapport l'apparition d'un texte
4295 // ligne : la ligne a manipuler
4296 // texte : le texte a reperer
4297 // option : 0 : la chaine avant le texte
4298 // 1 : la chaine apres le texte
4299 // Si le texte est absent, on retourne la chaine totale
4300 //===============================================================================
4301 std::string HOMARD_Gen_i::GetStringInTexte( const std::string ligne, const std::string texte, int option )
4303 // MESSAGE("GetStringInTexte, recherche de '"<<texte<<"' dans '"<<ligne<<"'"<<", option = "<<option);
4305 std::string chaine = ligne ;
4306 int position = ligne.find_first_of( texte ) ;
4309 if ( option == 0 ) { chaine = ligne.substr( 0, position ) ; }
4310 else { chaine = ligne.substr( position+1 ) ; }
4312 // Conversion de type
4317 //=============================================================================
4320 PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
4321 PortableServer::POA_ptr poa,
4322 PortableServer::ObjectId* contId,
4323 const char* instanceName,
4324 const char* interfaceName)
4326 MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
4327 HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
4328 return myHOMARD_Gen->getId();