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 "HOMARD_YACS_i.hxx"
27 #include "HomardDriver.hxx"
28 #include "HOMARD_DriverTools.hxx"
29 #include "HomardMedCommun.h"
30 #include "YACSDriver.hxx"
32 #include "HOMARD_version.h"
34 #include "utilities.h"
35 #include "Utils_SINGLETON.hxx"
36 #include "Utils_CorbaException.hxx"
37 #include "SALOMEDS_Tool.hxx"
38 #include "SALOME_LifeCycleCORBA.hxx"
39 #include "SALOMEconfig.h"
40 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
41 #include CORBA_CLIENT_HEADER(SMESH_Gen)
58 //=============================================================================
60 //=============================================================================
61 std::string RemoveTabulation( std::string theScript )
63 std::string::size_type aPos = 0;
64 while( aPos < theScript.length() )
66 aPos = theScript.find( "\n\t", aPos );
67 if( aPos == std::string::npos )
69 theScript.replace( aPos, 2, "\n" );
74 //=============================================================================
76 * standard constructor
78 //=============================================================================
79 HOMARD_Gen_i::HOMARD_Gen_i( CORBA::ORB_ptr orb,
80 PortableServer::POA_ptr poa,
81 PortableServer::ObjectId * contId,
82 const char *instanceName,
83 const char *interfaceName) :
84 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
86 MESSAGE("constructor");
88 _id = _poa->activate_object(_thisObj);
90 myHomard = new ::HOMARD_Gen();
91 _NS = SINGLETON_<SALOME_NamingService>::Instance();
92 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
100 _Langue = "Francais" ;
101 _LangueShort = "fr" ;
103 //=================================
105 * standard destructor
107 //================================
108 HOMARD_Gen_i::~HOMARD_Gen_i()
111 //=============================================================================
112 //=============================================================================
113 // Utilitaires pour l'étude
114 //=============================================================================
115 //=============================================================================
116 void HOMARD_Gen_i::addInStudy(SALOMEDS::Study_ptr theStudy)
118 ASSERT(!CORBA::is_nil(theStudy));
119 MESSAGE("addInStudy: ajout eventuel du composant HOMARD dans current study ID = " << GetCurrentStudyID()) ;
120 SALOMEDS::StudyBuilder_var myBuilder = theStudy->NewBuilder();
122 // Create SComponent labelled 'homard' if it doesn't already exit
123 SALOMEDS::SComponent_var homardFather = theStudy->FindComponent(ComponentDataType());
124 if (CORBA::is_nil(homardFather))
126 myBuilder->NewCommand();
127 MESSAGE("Add Component HOMARD");
129 bool aLocked = theStudy->GetProperties()->IsLocked();
130 if (aLocked) theStudy->GetProperties()->SetLocked(false);
132 homardFather = myBuilder->NewComponent(ComponentDataType());
133 SALOMEDS::GenericAttribute_var anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributeName");
134 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
135 CORBA::Object_var objVarN = _NS->Resolve("/Kernel/ModulCatalog");
136 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
137 SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
138 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent(ComponentDataType());
139 if (!Comp->_is_nil())
141 aName->SetValue(ComponentDataType());
144 anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributePixMap");
145 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
146 aPixmap->SetPixMap("HOMARD_2.png");
147 myBuilder->DefineComponentInstance(homardFather, HOMARD_Gen::_this());
149 if (aLocked) theStudy->GetProperties()->SetLocked(true);
150 myBuilder->CommitCommand();
153 //=============================================================================
154 void HOMARD_Gen_i::SetCurrentStudy(SALOMEDS::Study_ptr theStudy)
156 MESSAGE("SetCurrentStudy: current study Id = " << GetCurrentStudyID());
157 myCurrentStudy = SALOMEDS::Study::_duplicate(theStudy);
158 this->addInStudy(myCurrentStudy);
160 //=============================================================================
161 SALOMEDS::Study_ptr HOMARD_Gen_i::GetCurrentStudy()
162 //=============================================================================
164 MESSAGE("GetCurrentStudy: study Id = " << GetCurrentStudyID());
165 return SALOMEDS::Study::_duplicate(myCurrentStudy);
167 //=============================================================================
168 CORBA::Long HOMARD_Gen_i::GetCurrentStudyID()
169 //=============================================================================
171 return myCurrentStudy->_is_nil() ? -1 : myCurrentStudy->StudyId();
173 //=============================================================================
174 //=============================================================================
176 //=============================================================================
177 //=============================================================================
178 // Utilitaires pour l'iteration
179 //=============================================================================
180 //=============================================================================
181 void HOMARD_Gen_i::SetEtatIter(const char* nomIter, const CORBA::Long Etat)
182 //=====================================================================================
184 MESSAGE( "SetEtatIter : affectation de l'etat " << Etat << " a l'iteration " << nomIter );
185 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
186 if (CORBA::is_nil(myIteration))
188 SALOME::ExceptionStruct es;
189 es.type = SALOME::BAD_PARAM;
190 es.text = "Invalid iteration";
191 throw SALOME::SALOME_Exception(es);
195 myIteration->SetState(Etat);
197 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
198 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
202 icone = "iter0.png" ;
203 else if ( Etat == 2 )
204 icone = "iter_calculee.png" ;
206 icone = "iter_non_calculee.png" ;
207 PublishInStudyAttr(aStudyBuilder, aIterSO, NULL , NULL, icone.c_str(), NULL) ;
209 aStudyBuilder->CommitCommand();
212 //=============================================================================
213 //=============================================================================
215 //=============================================================================
216 //=============================================================================
217 // Destruction des structures identifiees par leurs noms
218 //=============================================================================
219 //=============================================================================
220 CORBA::Long HOMARD_Gen_i::DeleteBoundary(const char* BoundaryName)
222 MESSAGE ( "DeleteBoundary : BoundaryName = " << BoundaryName );
223 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
224 if (CORBA::is_nil(myBoundary))
226 SALOME::ExceptionStruct es;
227 es.type = SALOME::BAD_PARAM;
228 es.text = "Invalid boundary";
229 throw SALOME::SALOME_Exception(es);
233 // On verifie que la frontiere n'est plus utilisee
234 HOMARD::listeCases* maListe = GetAllCasesName();
235 int numberOfCases = maListe->length();
236 MESSAGE ( ".. Nombre de cas = " << numberOfCases );
237 std::string CaseName ;
238 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType ;
240 HOMARD::HOMARD_Cas_var myCase ;
241 for (int NumeCas = 0; NumeCas< numberOfCases; NumeCas++)
243 CaseName = std::string((*maListe)[NumeCas]);
244 MESSAGE ( "... Examen du cas = " << CaseName.c_str() );
245 myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
246 ASSERT(!CORBA::is_nil(myCase));
247 ListBoundaryGroupType = myCase->GetBoundaryGroup();
248 numberOfitems = ListBoundaryGroupType->length();
249 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
250 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
252 if ( std::string((*ListBoundaryGroupType)[NumBoundary]) == BoundaryName )
254 SALOME::ExceptionStruct es;
255 es.type = SALOME::BAD_PARAM;
256 es.text = "This boundary is used in a case and cannot be deleted.";
257 throw SALOME::SALOME_Exception(es);
263 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
264 myContextMap[GetCurrentStudyID()]._mesBoundarys.erase(BoundaryName);
265 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(BoundaryName, ComponentDataType());
266 SALOMEDS::SObject_var aSO =listSO[0];
267 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
268 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
272 //=============================================================================
273 CORBA::Long HOMARD_Gen_i::DeleteCase(const char* nomCas, CORBA::Long Option)
275 // Pour detruire un cas
276 MESSAGE ( "DeleteCase : nomCas = " << nomCas << ", avec option = " << Option );
277 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
278 if (CORBA::is_nil(myCase))
280 SALOME::ExceptionStruct es;
281 es.type = SALOME::BAD_PARAM;
282 es.text = "Invalid case context";
283 throw SALOME::SALOME_Exception(es);
286 // On commence par detruire toutes les iterations en partant de l'initiale et y compris elle
287 CORBA::String_var nomIter = myCase->GetIter0Name();
288 CORBA::Long Option1 = 0 ;
289 if ( DeleteIterationOption(nomIter, Option1, Option) != 0 )
294 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
295 myContextMap[GetCurrentStudyID()]._mesCas.erase(nomCas);
296 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomCas, ComponentDataType());
297 SALOMEDS::SObject_var aSO =listSO[0];
298 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
299 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
303 //=============================================================================
304 CORBA::Long HOMARD_Gen_i::DeleteHypo(const char* nomHypo)
306 MESSAGE ( "DeleteHypo : nomHypo = " << nomHypo );
307 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
308 if (CORBA::is_nil(myHypo))
310 SALOME::ExceptionStruct es;
311 es.type = SALOME::BAD_PARAM;
312 es.text = "Invalid hypothesis";
313 throw SALOME::SALOME_Exception(es);
317 // On verifie que l'hypothese n'est plus utilisee
318 HOMARD::listeIters* maListeIter = myHypo->GetIterations();
319 int numberOfIter = maListeIter->length();
320 if ( numberOfIter > 0 )
322 SALOME::ExceptionStruct es;
323 es.type = SALOME::BAD_PARAM;
324 es.text = "This hypothesis is used in an iteration and cannot be deleted.";
325 throw SALOME::SALOME_Exception(es);
329 // suppression du lien avec les zones eventuelles
330 HOMARD::listeZonesHypo* maListe = myHypo->GetZones();
331 int numberOfZones = maListe->length();
332 MESSAGE ( ".. Nombre de zones = " << numberOfZones );
333 for (int NumeZone = 0; NumeZone< numberOfZones; NumeZone++)
335 std::string ZoneName = std::string((*maListe)[NumeZone]);
336 MESSAGE ( ".. suppression du lien avec la zone = " << ZoneName.c_str() );
337 DissociateHypoZone(nomHypo, ZoneName.c_str()) ;
341 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
342 myContextMap[GetCurrentStudyID()]._mesHypotheses.erase(nomHypo);
343 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomHypo, ComponentDataType());
344 SALOMEDS::SObject_var aSO =listSO[0];
345 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
346 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
350 //=============================================================================
351 CORBA::Long HOMARD_Gen_i::DeleteIteration(const char* nomIter, CORBA::Long Option)
353 // Option = 0 : On ne supprime pas le fichier du maillage associe
354 // Option = 1 : On supprime le fichier du maillage associe
355 // Pour detruire une iteration courante
356 MESSAGE ( "DeleteIteration : nomIter = " << nomIter << ", avec option = " << Option );
357 CORBA::Long Option1 = 1 ;
358 return DeleteIterationOption(nomIter, Option1, Option);
360 //=============================================================================
361 CORBA::Long HOMARD_Gen_i::DeleteIterationOption(const char* nomIter, CORBA::Long Option1, CORBA::Long Option2)
363 // Option1 = 0 : On autorise la destruction de l'iteration 0
364 // Option1 = 1 : On interdit la destruction de l'iteration 0
366 // Option2 = 0 : On ne supprime pas le fichier du maillage associe
367 // Option2 = 1 : On supprime le fichier du maillage associe
368 MESSAGE ( "DeleteIterationOption : nomIter = " << nomIter << ", avec options = " << Option1<< ", " << Option2 );
369 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
370 if (CORBA::is_nil(myIteration))
372 SALOME::ExceptionStruct es;
373 es.type = SALOME::BAD_PARAM;
374 es.text = "Invalid iteration";
375 throw SALOME::SALOME_Exception(es);
379 int numero = myIteration->GetNumber();
380 MESSAGE ( "DeleteIterationOption : numero = " << numero );
381 if ( numero == 0 and Option1 == 1 )
383 SALOME::ExceptionStruct es;
384 es.type = SALOME::BAD_PARAM;
385 es.text = "This iteration cannot be deleted.";
386 throw SALOME::SALOME_Exception(es);
390 // On detruit recursivement toutes les filles
391 HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
392 int numberOfIter = maListe->length();
393 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
395 std::string nomIterFille = std::string((*maListe)[NumeIter]);
396 MESSAGE ( ".. appel recursif de DeleteIterationOption pour nomIter = " << nomIterFille.c_str() );
397 DeleteIterationOption(nomIterFille.c_str(), Option1, Option2);
400 // On arrive ici pour une iteration sans fille
401 MESSAGE ( "Destruction effective de " << nomIter );
402 // On commence par invalider l'iteration pour faire le menage des dependances
403 // et eventuellement du maillage associe
405 if ( numero == 0 ) { option = 0 ; }
406 else { option = Option2 ; }
407 InvalideIterOption(nomIter, option) ;
409 // Retrait dans la descendance de l'iteration parent
412 std::string nomIterationParent = myIteration->GetIterParentName();
413 MESSAGE ( "Retrait dans la descendance de nomIterationParent " << nomIterationParent );
414 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
415 if (CORBA::is_nil(myIterationParent))
417 SALOME::ExceptionStruct es;
418 es.type = SALOME::BAD_PARAM;
419 es.text = "Invalid iteration";
420 throw SALOME::SALOME_Exception(es);
423 myIterationParent->UnLinkNextIteration(nomIter);
426 // suppression du lien avec l'hypothese
429 std::string nomHypo = myIteration->GetHypoName();
430 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
431 ASSERT(!CORBA::is_nil(myHypo));
432 myHypo->UnLinkIteration(nomIter);
435 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
436 myContextMap[GetCurrentStudyID()]._mesIterations.erase(nomIter);
437 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomIter, ComponentDataType());
438 SALOMEDS::SObject_var aSO =listSO[0];
439 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
440 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
441 // on peut aussi faire RemoveObject
442 // MESSAGE ( "Au final" );
443 // HOMARD::listeIterations* Liste = GetAllIterationsName() ;
444 // numberOfIter = Liste->length();
445 // for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
447 // std::string nomIterFille = std::string((*Liste)[NumeIter]);
448 // MESSAGE ( ".. nomIter = " << nomIterFille.c_str() );
453 //=============================================================================
454 CORBA::Long HOMARD_Gen_i::DeleteYACS(const char* nomYACS, CORBA::Long Option)
456 // Option = 0 : On ne supprime pas le fichier du schema associe
457 // Option = 1 : On supprime le fichier du schema associe
458 MESSAGE ( "DeleteYACS : nomYACS = " << nomYACS << ", avec option = " << Option );
459 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
460 if (CORBA::is_nil(myYACS))
462 SALOME::ExceptionStruct es;
463 es.type = SALOME::BAD_PARAM;
464 es.text = "Invalid schema YACS";
465 throw SALOME::SALOME_Exception(es);
468 // Suppression eventuelle du fichier XML
471 std::string nomFichier = myYACS->GetXMLFile();
472 std::string commande = "rm -rf " + nomFichier ;
473 MESSAGE ( "commande = " << commande );
474 if ((system(commande.c_str())) != 0)
476 SALOME::ExceptionStruct es;
477 es.type = SALOME::BAD_PARAM;
478 es.text = "The xml file for the schema YACS cannot be removed." ;
479 throw SALOME::SALOME_Exception(es);
483 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
484 myContextMap[GetCurrentStudyID()]._mesYACSs.erase(nomYACS);
485 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomYACS, ComponentDataType());
486 SALOMEDS::SObject_var aSO =listSO[0];
487 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
488 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
492 //=============================================================================
493 CORBA::Long HOMARD_Gen_i::DeleteZone(const char* nomZone)
495 MESSAGE ( "DeleteZone : nomZone = " << nomZone );
496 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[nomZone];
497 if (CORBA::is_nil(myZone))
499 SALOME::ExceptionStruct es;
500 es.type = SALOME::BAD_PARAM;
501 es.text = "Invalid zone";
502 throw SALOME::SALOME_Exception(es);
506 // On verifie que la zone n'est plus utilisee
507 HOMARD::listeHypo* maListe = myZone->GetHypo();
508 int numberOfHypo = maListe->length();
509 MESSAGE ( ".. Nombre d'hypotheses = " << numberOfHypo );
510 if ( numberOfHypo > 0 )
512 SALOME::ExceptionStruct es;
513 es.type = SALOME::BAD_PARAM;
514 es.text = "This zone is used in an hypothesis and cannot be deleted.";
515 throw SALOME::SALOME_Exception(es);
519 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
520 myContextMap[GetCurrentStudyID()]._mesZones.erase(nomZone);
521 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomZone, ComponentDataType());
522 SALOMEDS::SObject_var aSO =listSO[0];
523 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
524 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
528 //=============================================================================
529 //=============================================================================
531 //=============================================================================
532 //=============================================================================
533 // Invalidation des structures identifiees par leurs noms
534 //=============================================================================
535 //=============================================================================
536 void HOMARD_Gen_i::InvalideBoundary(const char* BoundaryName)
538 MESSAGE( "InvalideBoundary : BoundaryName = " << BoundaryName );
539 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
540 if (CORBA::is_nil(myBoundary))
542 SALOME::ExceptionStruct es;
543 es.type = SALOME::BAD_PARAM;
544 es.text = "Invalid boundary";
545 throw SALOME::SALOME_Exception(es);
550 SALOME::ExceptionStruct es;
551 es.type = SALOME::BAD_PARAM;
552 es.text = "No change is allowed in a boundary. Ask for evolution.";
553 throw SALOME::SALOME_Exception(es);
557 //=============================================================================
558 void HOMARD_Gen_i::InvalideHypo(const char* nomHypo)
560 MESSAGE( "InvalideHypo : nomHypo = " << nomHypo );
561 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
562 if (CORBA::is_nil(myHypo))
564 SALOME::ExceptionStruct es;
565 es.type = SALOME::BAD_PARAM;
566 es.text = "Invalid hypothesis";
567 throw SALOME::SALOME_Exception(es);
571 HOMARD::listeIters* maListe = myHypo->GetIterations();
572 int numberOfIter = maListe->length();
573 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
575 std::string nomIter = std::string((*maListe)[NumeIter]);
576 MESSAGE( ".. nomIter = " << nomIter );
577 InvalideIter(nomIter.c_str());
580 //=============================================================================
581 void HOMARD_Gen_i::InvalideIter(const char* nomIter)
583 MESSAGE("InvalideIter : nomIter = " << nomIter);
584 // Pour invalider totalement une iteration courante
585 CORBA::Long Option = 1 ;
586 return InvalideIterOption(nomIter, Option);
588 //=============================================================================
589 void HOMARD_Gen_i::InvalideIterOption(const char* nomIter, CORBA::Long Option)
591 // Option = 0 : On ne supprime pas le fichier du maillage associe
592 // Option = 1 : On supprime le fichier du maillage associe
593 MESSAGE ( "InvalideIterOption : nomIter = " << nomIter << ", avec option = " << Option );
594 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
595 if (CORBA::is_nil(myIteration))
597 SALOME::ExceptionStruct es;
598 es.type = SALOME::BAD_PARAM;
599 es.text = "Invalid iteration";
600 throw SALOME::SALOME_Exception(es);
604 HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
605 int numberOfIter = maListe->length();
606 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
608 std::string nomIterFille = std::string((*maListe)[NumeIter]);
609 MESSAGE ( ".. appel recursif de InvalideIter pour nomIter = " << nomIterFille.c_str() );
610 InvalideIter(nomIterFille.c_str());
613 // On arrive ici pour une iteration sans fille
614 MESSAGE ( "Invalidation effective de " << nomIter );
615 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
616 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aIterSO);
617 for (; aIter->More(); aIter->Next())
619 SALOMEDS::SObject_var so = aIter->Value();
620 SALOMEDS::GenericAttribute_var anAttr;
621 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
622 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
623 std::string value (aCommentAttr->Value());
624 if(value == std::string("HypoHomard")) continue;
625 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
626 aStudyBuilder->RemoveObject(so);
629 int etat = myIteration->GetState();
632 SetEtatIter(nomIter,1);
633 const char * nomCas = myIteration->GetCaseName();
634 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
635 if (CORBA::is_nil(myCase))
637 SALOME::ExceptionStruct es;
638 es.type = SALOME::BAD_PARAM;
639 es.text = "Invalid case context";
640 throw SALOME::SALOME_Exception(es);
643 std::string nomDir = myIteration->GetDirName();
644 std::string nomFichier = myIteration->GetMeshFile();
645 std::string commande = "rm -rf " + std::string(nomDir);
646 if ( Option == 1 ) { commande = commande + ";rm -rf " + std::string(nomFichier) ; }
647 MESSAGE ( "commande = " << commande );
648 if ((system(commande.c_str())) != 0)
650 SALOME::ExceptionStruct es;
651 es.type = SALOME::BAD_PARAM;
652 es.text = "The directory for the calculation cannot be cleared." ;
653 throw SALOME::SALOME_Exception(es);
656 // Suppression du maillage publie dans SMESH
657 std::string MeshName = myIteration->GetMeshName() ;
658 DeleteResultInSmesh(nomFichier, MeshName) ;
662 //=============================================================================
663 void HOMARD_Gen_i::InvalideIterInfo(const char* nomIter)
665 MESSAGE("InvalideIterInfo : nomIter = " << nomIter);
666 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
667 if (CORBA::is_nil(myIteration))
669 SALOME::ExceptionStruct es;
670 es.type = SALOME::BAD_PARAM;
671 es.text = "Invalid iteration";
672 throw SALOME::SALOME_Exception(es);
676 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
677 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aIterSO);
678 for (; aIter->More(); aIter->Next())
680 SALOMEDS::SObject_var so = aIter->Value();
681 SALOMEDS::GenericAttribute_var anAttr;
682 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
683 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
684 std::string value (aCommentAttr->Value());
685 /* MESSAGE("... value = " << value);*/
686 if( (value == std::string("logInfo")) or ( value == std::string("SummaryInfo")) )
688 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
689 aStudyBuilder->RemoveObject(so);
693 const char * nomCas = myIteration->GetCaseName();
694 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
695 if (CORBA::is_nil(myCase))
697 SALOME::ExceptionStruct es;
698 es.type = SALOME::BAD_PARAM;
699 es.text = "Invalid case context";
700 throw SALOME::SALOME_Exception(es);
703 const char* nomDir = myIteration->GetDirName();
704 std::string commande = "rm -f " + std::string(nomDir) + "/info* " ;
705 commande += std::string(nomDir) + "/Liste.*info" ;
706 /* MESSAGE ( "commande = " << commande );*/
707 if ((system(commande.c_str())) != 0)
709 SALOME::ExceptionStruct es;
710 es.type = SALOME::BAD_PARAM;
711 es.text = "The directory for the calculation cannot be cleared." ;
712 throw SALOME::SALOME_Exception(es);
716 //=============================================================================
717 void HOMARD_Gen_i::InvalideZone(const char* ZoneName)
719 MESSAGE( "InvalideZone : ZoneName = " << ZoneName );
720 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
721 if (CORBA::is_nil(myZone))
723 SALOME::ExceptionStruct es;
724 es.type = SALOME::BAD_PARAM;
725 es.text = "Invalid zone";
726 throw SALOME::SALOME_Exception(es);
729 HOMARD::listeHypo* maListe = myZone->GetHypo();
730 int numberOfHypo = maListe->length();
731 MESSAGE( ".. numberOfHypo = " << numberOfHypo );
732 for (int NumeHypo = 0; NumeHypo< numberOfHypo; NumeHypo++)
734 std::string nomHypo = std::string((*maListe)[NumeHypo]);
735 MESSAGE( ".. nomHypo = " << nomHypo );
736 InvalideHypo(nomHypo.c_str());
739 //=============================================================================
740 //=============================================================================
742 //=============================================================================
743 //=============================================================================
744 // Association de lien entre des structures identifiees par leurs noms
745 //=============================================================================
746 //=============================================================================
747 void HOMARD_Gen_i::AssociateCaseIter(const char* nomCas, const char* nomIter, const char* labelIter)
749 MESSAGE( "AssociateCaseIter : " << nomCas << ", " << nomIter << ", " << labelIter );
751 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
752 if (CORBA::is_nil(myCase))
754 SALOME::ExceptionStruct es;
755 es.type = SALOME::BAD_PARAM;
756 es.text = "Invalid case";
757 throw SALOME::SALOME_Exception(es);
761 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
762 if (CORBA::is_nil(myIteration))
764 SALOME::ExceptionStruct es;
765 es.type = SALOME::BAD_PARAM;
766 es.text = "Invalid iteration";
767 throw SALOME::SALOME_Exception(es);
771 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
772 SALOMEDS::SObject_var aCasSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
773 if (CORBA::is_nil(aCasSO))
775 SALOME::ExceptionStruct es;
776 es.type = SALOME::BAD_PARAM;
777 es.text = "Invalid case";
778 throw SALOME::SALOME_Exception(es);
782 aStudyBuilder->NewCommand();
783 SALOMEDS::SObject_var newStudyIter = aStudyBuilder->NewObject(aCasSO);
784 PublishInStudyAttr(aStudyBuilder, newStudyIter, nomIter , labelIter,
785 "iter_non_calculee.png", _orb->object_to_string(myIteration)) ;
786 aStudyBuilder->CommitCommand();
788 myCase->AddIteration(nomIter);
789 myIteration->SetCaseName(nomCas);
791 //=====================================================================================
792 void HOMARD_Gen_i::AssociateHypoZone(const char* nomHypothesis, const char* ZoneName, CORBA::Long TypeUse)
794 MESSAGE ( "AssociateHypoZone : nomHypo = " << nomHypothesis << ", ZoneName= " << ZoneName << ", TypeUse = " << TypeUse);
796 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
797 ASSERT(!CORBA::is_nil(myHypo));
798 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
799 ASSERT(!CORBA::is_nil(aHypoSO));
801 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
802 ASSERT(!CORBA::is_nil(myZone));
803 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myZone)));
804 ASSERT(!CORBA::is_nil(aZoneSO));
806 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
808 aStudyBuilder->NewCommand();
810 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aHypoSO);
811 aStudyBuilder->Addreference(aSubSO, aZoneSO);
813 aStudyBuilder->CommitCommand();
815 myZone->AddHypo(nomHypothesis);
816 myHypo->AddZone0(ZoneName, TypeUse);
818 //=============================================================================
819 void HOMARD_Gen_i::AssociateIterHypo(const char* nomIter, const char* nomHypo)
821 MESSAGE("AssociateIterHypo : nomHypo = " << nomHypo << " nomIter = " << nomIter);
823 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
824 ASSERT(!CORBA::is_nil(myHypo));
825 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
826 ASSERT(!CORBA::is_nil(aHypoSO));
828 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
829 ASSERT(!CORBA::is_nil(myIteration));
830 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
831 ASSERT(!CORBA::is_nil(aIterSO));
833 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
835 aStudyBuilder->NewCommand();
837 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
838 aStudyBuilder->Addreference(aSubSO, aHypoSO);
840 aStudyBuilder->CommitCommand();
842 myIteration->SetHypoName(nomHypo);
843 myHypo->LinkIteration(nomIter);
845 //=============================================================================
846 //=============================================================================
848 //=============================================================================
849 //=============================================================================
850 // Dissociation de lien entre des structures identifiees par leurs noms
851 //=============================================================================
852 //=============================================================================
853 void HOMARD_Gen_i::DissociateHypoZone(const char* nomHypothesis, const char* ZoneName)
855 MESSAGE ( "DissociateHypoZone : ZoneName= " << ZoneName << ", nomHypo = " << nomHypothesis);
857 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
858 ASSERT(!CORBA::is_nil(myHypo));
859 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
860 ASSERT(!CORBA::is_nil(aHypoSO));
862 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
863 ASSERT(!CORBA::is_nil(myZone));
864 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myZone)));
865 ASSERT(!CORBA::is_nil(aZoneSO));
867 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
869 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator(aHypoSO);
870 for (; it->More(); it->Next())
872 SALOMEDS::SObject_var aHypObj = it->Value();
873 SALOMEDS::SObject_var ptrObj;
874 if (aHypObj->ReferencedObject(ptrObj))
876 if (std::string(ptrObj->GetName()) == std::string(aZoneSO->GetName()))
878 aStudyBuilder->NewCommand();
879 aStudyBuilder->RemoveObject(aHypObj);
880 aStudyBuilder->CommitCommand();
886 myZone->SupprHypo(nomHypothesis);
887 myHypo->SupprZone(ZoneName);
889 //=============================================================================
890 //=============================================================================
893 //=============================================================================
894 //=============================================================================
895 // Recuperation des listes
896 //=============================================================================
897 //=============================================================================
898 HOMARD::listeBoundarys* HOMARD_Gen_i::GetAllBoundarysName()
900 MESSAGE("GetAllBoundarysName");
903 HOMARD::listeBoundarys_var ret = new HOMARD::listeBoundarys;
904 ret->length(myContextMap[GetCurrentStudyID()]._mesBoundarys.size());
905 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it;
907 for (it = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
908 it != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); it++)
910 ret[i++] = CORBA::string_dup((*it).first.c_str());
915 //=============================================================================
916 HOMARD::listeCases* HOMARD_Gen_i::GetAllCasesName()
918 MESSAGE("GetAllCasesName");
921 HOMARD::listeCases_var ret = new HOMARD::listeCases;
922 ret->length(myContextMap[GetCurrentStudyID()]._mesCas.size());
923 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
925 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
926 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
928 ret[i++] = CORBA::string_dup((*it).first.c_str());
933 //=============================================================================
934 HOMARD::listeHypotheses* HOMARD_Gen_i::GetAllHypothesesName()
936 MESSAGE("GetAllHypothesesName");
939 HOMARD::listeHypotheses_var ret = new HOMARD::listeHypotheses;
940 ret->length(myContextMap[GetCurrentStudyID()]._mesHypotheses.size());
941 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it;
943 for (it = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
944 it != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it++)
946 ret[i++] = CORBA::string_dup((*it).first.c_str());
951 //=============================================================================
952 HOMARD::listeIterations* HOMARD_Gen_i::GetAllIterationsName()
954 MESSAGE("GetAllIterationsName");
957 HOMARD::listeIterations_var ret = new HOMARD::listeIterations;
958 ret->length(myContextMap[GetCurrentStudyID()]._mesIterations.size());
959 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it;
961 for (it = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
962 it != myContextMap[GetCurrentStudyID()]._mesIterations.end(); it++)
964 ret[i++] = CORBA::string_dup((*it).first.c_str());
969 //=============================================================================
970 HOMARD::listeYACSs* HOMARD_Gen_i::GetAllYACSsName()
972 MESSAGE("GetAllYACSsName");
975 HOMARD::listeYACSs_var ret = new HOMARD::listeYACSs;
976 ret->length(myContextMap[GetCurrentStudyID()]._mesYACSs.size());
977 std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it;
979 for (it = myContextMap[GetCurrentStudyID()]._mesYACSs.begin();
980 it != myContextMap[GetCurrentStudyID()]._mesYACSs.end(); it++)
982 ret[i++] = CORBA::string_dup((*it).first.c_str());
987 //=============================================================================
988 HOMARD::listeZones* HOMARD_Gen_i::GetAllZonesName()
990 MESSAGE("GetAllZonesName");
993 HOMARD::listeZones_var ret = new HOMARD::listeZones;
994 ret->length(myContextMap[GetCurrentStudyID()]._mesZones.size());
995 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it;
997 for (it = myContextMap[GetCurrentStudyID()]._mesZones.begin();
998 it != myContextMap[GetCurrentStudyID()]._mesZones.end(); it++)
1000 ret[i++] = CORBA::string_dup((*it).first.c_str());
1005 //=============================================================================
1006 //=============================================================================
1008 //=============================================================================
1009 //=============================================================================
1010 // Recuperation des structures identifiees par leurs noms
1011 //=============================================================================
1012 //=============================================================================
1013 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::GetBoundary(const char* nomBoundary)
1015 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[nomBoundary];
1016 ASSERT(!CORBA::is_nil(myBoundary));
1017 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1019 //=============================================================================
1020 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::GetCase(const char* nomCas)
1022 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1023 ASSERT(!CORBA::is_nil(myCase));
1024 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1026 //=============================================================================
1027 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::GetHypothesis(const char* nomHypothesis)
1029 HOMARD::HOMARD_Hypothesis_var myHypothesis = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
1030 ASSERT(!CORBA::is_nil(myHypothesis));
1031 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1033 //=============================================================================
1034 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::GetIteration(const char* NomIterationation)
1036 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIterationation];
1037 ASSERT(!CORBA::is_nil(myIteration));
1038 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1040 //=============================================================================
1041 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::GetYACS(const char* nomYACS)
1043 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
1044 ASSERT(!CORBA::is_nil(myYACS));
1045 return HOMARD::HOMARD_YACS::_duplicate(myYACS);
1047 //=============================================================================
1048 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::GetZone(const char* ZoneName)
1050 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
1051 ASSERT(!CORBA::is_nil(myZone));
1052 return HOMARD::HOMARD_Zone::_duplicate(myZone);
1054 //=============================================================================
1055 //=============================================================================
1057 //=============================================================================
1058 //=============================================================================
1060 //=============================================================================
1061 //=============================================================================
1062 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)
1064 INFOS ( "MeshInfo : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1065 INFOS ( "Qual = " << Qual << ", Diam = " << Diam << ", Conn = " << Conn << ", Tail = " << Tail << ", Inte = " << Inte );
1069 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, 0, 1) ;
1070 myCase->SetDirName(DirName) ;
1072 myCase->MeshInfo(Qual, Diam, Conn, Tail, Inte) ;
1076 //=============================================================================
1077 //=============================================================================
1079 //=============================================================================
1080 //=============================================================================
1081 // Recuperation des structures par le contexte
1082 //=============================================================================
1083 //=============================================================================
1084 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::LastIteration(const char* nomCas)
1086 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1087 ASSERT(!CORBA::is_nil(myCase));
1089 HOMARD::HOMARD_Iteration_var myIteration = myCase->LastIteration();
1090 ASSERT(!CORBA::is_nil(myIteration));
1092 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1094 //=============================================================================
1095 //=============================================================================
1097 //=============================================================================
1098 //=============================================================================
1099 // Nouvelles structures
1100 //=============================================================================
1101 //=============================================================================
1102 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::newCase()
1104 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1105 HOMARD_Cas_i* aServant = new HOMARD_Cas_i(_orb, engine);
1106 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(aServant->_this());
1107 return aCase._retn();
1109 //=============================================================================
1110 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::newHypothesis()
1112 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1113 HOMARD_Hypothesis_i* aServant = new HOMARD_Hypothesis_i(_orb, engine);
1114 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(aServant->_this());
1115 return aHypo._retn();
1117 //=============================================================================
1118 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::newIteration()
1120 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1121 HOMARD_Iteration_i* aServant = new HOMARD_Iteration_i(_orb, engine);
1122 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(aServant->_this());
1123 return aIter._retn();
1125 //=============================================================================
1126 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::newBoundary()
1128 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1129 HOMARD_Boundary_i* aServant = new HOMARD_Boundary_i(_orb, engine);
1130 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(aServant->_this());
1131 return aBoundary._retn();
1133 //=============================================================================
1134 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::newZone()
1136 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1137 HOMARD_Zone_i* aServant = new HOMARD_Zone_i(_orb, engine);
1138 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(aServant->_this());
1139 return aZone._retn();
1141 //=============================================================================
1142 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::newYACS()
1144 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1145 HOMARD_YACS_i* aServant = new HOMARD_YACS_i(_orb, engine);
1146 HOMARD::HOMARD_YACS_var aYACS = HOMARD::HOMARD_YACS::_narrow(aServant->_this());
1147 return aYACS._retn();
1149 //=============================================================================
1150 //=============================================================================
1152 //=============================================================================
1153 //=============================================================================
1154 // Creation des structures identifiees par leurs noms
1155 //=============================================================================
1156 //=============================================================================
1157 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCase(const char* nomCas, const char* MeshName, const char* MeshFile)
1159 // Creation d'un cas initial
1160 // nomCas : nom du cas a creer
1161 // MeshName, MeshFile : nom et fichier du maillage correspondant
1164 INFOS ( "CreateCase : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1166 // Par defaut, on ne publie pas le maillage
1167 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 0, 0, 1) ;
1169 // Valeurs par defaut des filtrages
1170 myCase->SetPyram(0);
1172 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1174 //=============================================================================
1175 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromIteration(const char* nomCas, const char* DirNameStart)
1177 // nomCas : nom du cas a creer
1178 // DirNameStart : nom du repertoire contenant l'iteration de reprise
1181 INFOS ( "CreateCaseFromIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1182 std::string nomDirWork = getenv("PWD") ;
1185 // A. Decodage du point de reprise
1186 // A.1. Controle du repertoire de depart de l'iteration
1187 codret = chdir(DirNameStart) ;
1190 SALOME::ExceptionStruct es;
1191 es.type = SALOME::BAD_PARAM;
1192 es.text = "The directory of the iteration does not exist.";
1193 throw SALOME::SALOME_Exception(es);
1196 // A.2. Reperage des fichiers du repertoire de reprise
1197 std::string file_configuration = "" ;
1198 std::string file_maillage_homard = "" ;
1201 struct dirent *dirp;
1202 dp = opendir(DirNameStart);
1203 while ( (dirp = readdir(dp)) != NULL )
1205 std::string file_name(dirp->d_name);
1206 // MESSAGE ( file_name );
1207 bilan = file_name.find("HOMARD.Configuration.") ;
1208 if ( bilan != string::npos ) { file_configuration = file_name ; }
1209 bilan = file_name.find("maill.") ;
1210 if ( bilan != string::npos )
1212 bilan = file_name.find(".hom.med") ;
1213 if ( bilan != string::npos ) { file_maillage_homard = file_name ; }
1217 MESSAGE ( "==> file_configuration : " << file_configuration ) ;
1218 MESSAGE ( "==> file_maillage_homard : " << file_maillage_homard ) ;
1220 if ( ( file_configuration == "" ) or ( file_maillage_homard == "" ) )
1222 SALOME::ExceptionStruct es;
1223 es.type = SALOME::BAD_PARAM;
1225 if ( file_configuration == "" ) { text = "The configuration file cannot be found." ; }
1226 else { text = "The HOMARD mesh file cannot be found." ; }
1227 es.text = CORBA::string_dup(text.c_str());
1228 throw SALOME::SALOME_Exception(es);
1231 // B. Lecture du fichier de configuration
1232 // ATTENTION : on doit veiller a la coherence entre HomardDriver et CreateCaseFromIteration
1238 // le constructeur de ifstream permet d'ouvrir un fichier en lecture
1239 std::ifstream fichier( file_configuration.c_str() );
1240 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1242 std::string ligne; // variable contenant chaque ligne lue
1243 std::string mot_cle;
1244 std::string argument;
1246 // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1247 while ( std::getline( fichier, ligne ) )
1249 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1250 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1251 ligne_bis >> mot_cle ;
1252 // B.2. Des valeurs entieres : le second bloc de la ligne
1253 if ( mot_cle == "NumeIter" )
1255 ligne_bis >> NumeIter ;
1258 // B.3. Des valeurs caracteres brutes : le second bloc de la ligne est la valeur
1259 else if ( ( mot_cle == "TypeConf" ) or ( mot_cle == "TypeElem" ) )
1261 ligne_bis >> argument ;
1263 if ( mot_cle == "TypeConf" )
1265 if ( argument == "conforme" ) { TypeConf = 1 ; }
1266 else if ( argument == "non_conforme_1_noeud" ) { TypeConf = 2 ; }
1267 else if ( argument == "non_conforme_1_arete" ) { TypeConf = 3 ; }
1268 else if ( argument == "non_conforme_indicateur" ) { TypeConf = 4 ; }
1270 else if ( mot_cle == "TypeElem" )
1272 if ( argument == "ignore_pyra" ) { Pyram = 1 ; }
1273 else if ( argument == "HOMARD" ) { Pyram = 0 ; }
1276 // B.4. Des valeurs caracteres : le deuxieme bloc de la ligne peut etre encadre par des quotes :
1277 // il faut les supprimer
1278 else if ( ( mot_cle == "CCNoMNP1" ) or ( mot_cle == "CCMaiNP1" ) )
1280 ligne_bis >> argument ;
1281 if ( argument[0] == '"' ) { decalage = 1 ; }
1282 else { decalage = 0 ; }
1283 size_t size = argument.size() + 1 - 2*decalage ;
1285 if ( mot_cle == "CCNoMNP1" )
1287 MeshName = new char[ size ];
1288 strncpy( MeshName, argument.c_str()+decalage, size );
1289 MeshName[size-1] = '\0' ;
1291 else if ( mot_cle == "CCMaiNP1" )
1293 MeshFile = new char[ size ];
1294 strncpy( MeshFile, argument.c_str()+decalage, size );
1295 MeshFile[size-1] = '\0' ;
1299 MESSAGE ( "==> TypeConf : " << TypeConf ) ;
1300 MESSAGE ( "==> MeshName : " << MeshName ) ;
1301 MESSAGE ( "==> MeshFile : " << MeshFile ) ;
1302 MESSAGE ( "==> NumeIter : " << NumeIter ) ;
1303 MESSAGE ( "==> Pyram : " << Pyram ) ;
1307 SALOME::ExceptionStruct es;
1308 es.type = SALOME::BAD_PARAM;
1309 std::string text = "The configuration file cannot be read." ;
1310 es.text = CORBA::string_dup(text.c_str());
1311 throw SALOME::SALOME_Exception(es);
1314 // C. Creation effective du cas
1316 // Par defaut, on ne publie pas le maillage
1317 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, NumeIter, 1) ;
1319 // D. Parametrages lus dans le fichier de configuration
1321 myCase->SetConfType (TypeConf) ;
1322 myCase->SetPyram (Pyram) ;
1324 // E. Copie du fichier de maillage homard
1325 // E.1. Repertoire associe au cas
1326 char* nomDirCase = myCase->GetDirName() ;
1327 // E.2. Repertoire associe a l'iteration de ce cas
1329 IterName = myCase->GetIter0Name() ;
1330 HOMARD::HOMARD_Iteration_var Iter = GetIteration(IterName) ;
1331 char* nomDirIter = CreateDirNameIter(nomDirCase, 0 );
1332 Iter->SetDirNameLoc(nomDirIter);
1333 std::string nomDirIterTotal ;
1334 nomDirIterTotal = std::string(nomDirCase) + "/" + std::string(nomDirIter) ;
1335 if (mkdir(nomDirIterTotal.c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
1337 MESSAGE ( "nomDirIterTotal : " << nomDirIterTotal ) ;
1338 SALOME::ExceptionStruct es;
1339 es.type = SALOME::BAD_PARAM;
1340 std::string text = "The directory for the computation cannot be created." ;
1341 es.text = CORBA::string_dup(text.c_str());
1342 throw SALOME::SALOME_Exception(es);
1344 // E.3. Copie du maillage HOMARD au format MED
1345 codret = chdir(DirNameStart) ;
1346 std::string commande = "cp " + file_maillage_homard + " " + nomDirIterTotal ;
1347 MESSAGE ( "commande : " << commande ) ;
1348 codret = system(commande.c_str()) ;
1349 MESSAGE ( "codret : " << codret ) ;
1352 SALOME::ExceptionStruct es;
1353 es.type = SALOME::BAD_PARAM;
1354 es.text = "The starting point for the case cannot be copied into the working directory.";
1355 throw SALOME::SALOME_Exception(es);
1364 chdir(nomDirWork.c_str());
1366 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1368 //=============================================================================
1369 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseLastIteration(const char* nomCas, const char* DirNameStart)
1371 // nomCas : nom du cas a creer
1372 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1375 INFOS ( "CreateCaseFromCaseLastIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1377 std::string DirNameStartIter = CreateCase1(DirNameStart, -1) ;
1379 DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1380 HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1382 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1384 //=============================================================================
1385 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseIteration(const char* nomCas, const char* DirNameStart, CORBA::Long Number)
1387 // nomCas : nom du cas a creer
1388 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1389 // Number : numero de l'iteration de depart
1392 INFOS ( "CreateCaseFromCaseIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart << ", Number = " << Number );
1395 SALOME::ExceptionStruct es;
1396 es.type = SALOME::BAD_PARAM;
1397 es.text = "The number of iteration must be positive.";
1398 throw SALOME::SALOME_Exception(es);
1402 std::string DirNameStartIter = CreateCase1(DirNameStart, Number) ;
1404 DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1405 HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1407 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1409 //=============================================================================
1410 std::string HOMARD_Gen_i::CreateCase1(const char* DirNameStart, CORBA::Long Number)
1412 // Retourne le nom du repertoire ou se trouve l'iteration voulue.
1413 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1414 // Number : numero de l'iteration de depart ou -1 si on cherche la derniere
1417 MESSAGE ( "CreateCase1 : DirNameStart = " << DirNameStart << ", Number = " << Number );
1418 std::string nomDirWork = getenv("PWD") ;
1419 std::string DirNameStartIter ;
1421 int NumeIterMax = -1 ;
1423 // A.1. Controle du repertoire de depart du cas
1424 codret = chdir(DirNameStart) ;
1427 SALOME::ExceptionStruct es;
1428 es.type = SALOME::BAD_PARAM;
1429 es.text = "The directory of the case for the pursuit does not exist.";
1430 throw SALOME::SALOME_Exception(es);
1433 // A.2. Reperage des sous-repertoire du repertoire de reprise
1434 bool existe = false ;
1436 struct dirent *dirp;
1437 dp = opendir(DirNameStart);
1438 while ( (dirp = readdir(dp)) != NULL )
1440 std::string DirName_1(dirp->d_name);
1441 if ( ( DirName_1 != "." ) and ( DirName_1 != ".." ) )
1443 if ( chdir(DirName_1.c_str()) == 0 )
1445 // On cherche le fichier de configuration dans ce sous-repertoire
1446 codret = chdir(DirNameStart) ;
1448 struct dirent *dirp_1;
1449 dp_1 = opendir(DirName_1.c_str()) ;
1450 while ( (dirp_1 = readdir(dp_1)) != NULL )
1452 std::string file_name_1(dirp_1->d_name);
1453 int bilan = file_name_1.find("HOMARD.Configuration.") ;
1454 if ( bilan != string::npos )
1456 // Decodage du fichier pour trouver le numero d'iteration
1457 chdir(DirName_1.c_str()) ;
1458 std::ifstream fichier( file_name_1.c_str() );
1459 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1462 std::string ligne; // variable contenant chaque ligne lue
1463 std::string mot_cle;
1464 // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1465 while ( std::getline( fichier, ligne ) )
1467 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1468 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1469 ligne_bis >> mot_cle ;
1470 if ( mot_cle == "NumeIter" )
1472 ligne_bis >> NumeIter ;
1474 // MESSAGE ( "==> NumeIter : " << NumeIter ) ;
1475 if ( Number == - 1 )
1477 if ( NumeIter >= NumeIterMax )
1479 NumeIterMax = NumeIter ;
1480 DirNameStartIter = DirName_1 ;
1485 if ( NumeIter == Number )
1487 DirNameStartIter = DirName_1 ;
1497 SALOME::ExceptionStruct es;
1498 es.type = SALOME::BAD_PARAM;
1499 std::string text = "The configuration file cannot be read." ;
1500 es.text = CORBA::string_dup(text.c_str());
1501 throw SALOME::SALOME_Exception(es);
1503 chdir(DirNameStart) ;
1505 if ( existe ) { break ; }
1508 if ( existe ) { break ; }
1514 chdir(nomDirWork.c_str());
1516 if ( ( Number >= 0 and ( not existe ) ) or ( Number < 0 and ( NumeIterMax == -1 ) ) )
1518 SALOME::ExceptionStruct es;
1519 es.type = SALOME::BAD_PARAM;
1520 es.text = "The directory of the iteration does not exist.";
1521 throw SALOME::SALOME_Exception(es);
1525 return DirNameStartIter ;
1527 //=============================================================================
1528 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)
1530 // nomCas : nom du cas a creer
1531 // MeshName, MeshFile : nom et fichier du maillage correspondant
1532 // MeshOption : 0 : le maillage fourni est obligatoirement present ==> erreur si absent
1533 // 1 : le maillage fourni peut ne pas exister ==> on continue si absent
1534 // -1 : le maillage n'est pas fourni
1535 // NumeIter : numero de l'iteration correspondante : 0, pour un depart, n>0 pour une poursuite
1536 // Option : multiple de nombres premiers
1537 // 1 : aucune option
1538 // x2 : publication du maillage dans SMESH
1540 MESSAGE ( "CreateCase0 : nomCas = " << nomCas );
1541 MESSAGE ( "CreateCase0 : MeshName = " << MeshName << ", MeshFile = " << MeshFile << ", MeshOption = " << MeshOption );
1542 MESSAGE ( "CreateCase0 : NumeIter = " << NumeIter << ", Option = " << Option );
1548 // A.2. Controle du nom :
1549 if ((myContextMap[GetCurrentStudyID()]._mesCas).find(nomCas)!=(myContextMap[GetCurrentStudyID()]._mesCas).end())
1551 SALOME::ExceptionStruct es;
1552 es.type = SALOME::BAD_PARAM;
1553 es.text = "This case has already been defined.";
1554 throw SALOME::SALOME_Exception(es);
1558 // A.3. Controle du fichier du maillage
1559 int existeMeshFile ;
1560 if ( MeshOption >= 0 )
1562 existeMeshFile = MEDFileExist ( MeshFile ) ;
1563 MESSAGE ( "CreateCase0 : existeMeshFile = " << existeMeshFile );
1564 if ( ( existeMeshFile == 0 ) and ( MeshOption == 0 ) )
1566 SALOME::ExceptionStruct es;
1567 es.type = SALOME::BAD_PARAM;
1568 es.text = "The mesh file does not exist.";
1569 throw SALOME::SALOME_Exception(es);
1573 else { existeMeshFile = 0 ; }
1575 // B. Creation de l'objet cas et publication
1576 // MESSAGE ( "CreateCase0 : Creation de l'objet" );
1577 HOMARD::HOMARD_Cas_var myCase = newCase();
1578 myCase->SetName(nomCas);
1579 SALOMEDS::SObject_var aSO;
1580 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myCase, nomCas);
1581 myContextMap[GetCurrentStudyID()]._mesCas[nomCas] = myCase;
1583 // C. Caracteristiques du maillage
1584 if ( existeMeshFile != 0 )
1586 // Les valeurs extremes des coordonnees
1587 // MESSAGE ( "CreateCase0 : Les valeurs extremes des coordonnees" );
1588 std::vector<double> LesExtremes =GetBoundingBoxInMedFile(MeshFile) ;
1589 HOMARD::extrema_var aSeq = new HOMARD::extrema() ;
1590 if (LesExtremes.size()!=10) { return false; }
1592 for (int i =0 ; i< LesExtremes.size() ; i++)
1593 aSeq[i]=LesExtremes[i] ;
1594 myCase->SetBoundingBox(aSeq) ;
1596 // MESSAGE ( "CreateCase0 : Les groupes" );
1597 std::set<std::string> LesGroupes =GetListeGroupesInMedFile(MeshFile) ;
1598 HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType ;
1599 aSeqGroupe->length(LesGroupes.size());
1600 std::set<std::string>::const_iterator it ;
1602 for (it=LesGroupes.begin() ; it != LesGroupes.end() ; it++)
1603 aSeqGroupe[i++]=(*it).c_str() ;
1604 myCase->SetGroups(aSeqGroupe) ;
1607 // D. L'iteration initiale du cas
1608 MESSAGE ( "CreateCase0 : iteration initiale du cas" );
1609 // D.1. Recherche d'un nom : par defaut, on prend le nom du maillage correspondant.
1610 // Si ce nom d'iteration existe deja, on incremente avec 0, 1, 2, etc.
1612 std::string NomIteration = std::string(MeshName) ;
1613 while ( (myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration) != (myContextMap[GetCurrentStudyID()]._mesIterations.end()) )
1615 std::ostringstream nom;
1616 nom << MeshName << monNum;
1617 NomIteration = nom.str();
1620 MESSAGE ( "CreateCas0 : ==> NomIteration = " << NomIteration );
1622 // D.2. Creation de l'iteration
1623 HOMARD::HOMARD_Iteration_var anIter = newIteration();
1624 myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration] = anIter;
1625 anIter->SetName(NomIteration.c_str());
1626 AssociateCaseIter (nomCas, NomIteration.c_str(), "IterationHomard");
1628 // D.4. Maillage correspondant
1629 if ( existeMeshFile != 0 )
1631 anIter->SetMeshFile(MeshFile);
1632 if ( Option % 2 == 0 ) { PublishResultInSmesh(MeshFile, 0); }
1634 anIter->SetMeshName(MeshName);
1636 // D.5. Numero d'iteration
1637 anIter->SetNumber(NumeIter);
1640 SetEtatIter(NomIteration.c_str(), -NumeIter);
1643 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1645 //=============================================================================
1646 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::CreateHypothesis(const char* nomHypothesis)
1648 INFOS ( "CreateHypothesis : nomHypothesis = " << nomHypothesis );
1651 // A. Controle du nom :
1652 if ((myContextMap[GetCurrentStudyID()]._mesHypotheses).find(nomHypothesis) != (myContextMap[GetCurrentStudyID()]._mesHypotheses).end())
1654 SALOME::ExceptionStruct es;
1655 es.type = SALOME::BAD_PARAM;
1656 es.text = "This hypothesis has already been defined.";
1657 throw SALOME::SALOME_Exception(es);
1661 // B. Creation de l'objet
1662 HOMARD::HOMARD_Hypothesis_var myHypothesis = newHypothesis();
1663 if (CORBA::is_nil(myHypothesis))
1665 SALOME::ExceptionStruct es;
1666 es.type = SALOME::BAD_PARAM;
1667 es.text = "Unable to create the hypothesis";
1668 throw SALOME::SALOME_Exception(es);
1671 myHypothesis->SetName(nomHypothesis);
1673 // C. Enregistrement
1674 myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis] = myHypothesis;
1676 SALOMEDS::SObject_var aSO;
1677 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myHypothesis, nomHypothesis);
1679 // D. Valeurs par defaut des options avancees
1680 myHypothesis->SetNivMax(-1);
1681 myHypothesis->SetDiamMin(-1.0);
1682 myHypothesis->SetAdapInit(0);
1683 myHypothesis->SetLevelOutput(0);
1685 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1688 //=============================================================================
1689 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::CreateIteration(const char* NomIteration, const char* nomIterParent)
1690 //=============================================================================
1692 INFOS ("CreateIteration : NomIteration = " << NomIteration << ", nomIterParent = " << nomIterParent);
1695 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterParent];
1696 if (CORBA::is_nil(myIterationParent))
1698 SALOME::ExceptionStruct es;
1699 es.type = SALOME::BAD_PARAM;
1700 es.text = "The parent iteration is not defined.";
1701 throw SALOME::SALOME_Exception(es);
1705 const char* nomCas = myIterationParent->GetCaseName();
1706 MESSAGE ("CreateIteration : nomCas = " << nomCas);
1707 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1708 if (CORBA::is_nil(myCase))
1710 SALOME::ExceptionStruct es;
1711 es.type = SALOME::BAD_PARAM;
1712 es.text = "Invalid case context";
1713 throw SALOME::SALOME_Exception(es);
1716 const char* nomDirCase = myCase->GetDirName();
1718 // Controle du nom :
1719 if ((myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration)!=(myContextMap[GetCurrentStudyID()]._mesIterations).end())
1721 SALOME::ExceptionStruct es;
1722 es.type = SALOME::BAD_PARAM;
1723 es.text = "This iteration has already been defined.";
1724 throw SALOME::SALOME_Exception(es);
1728 HOMARD::HOMARD_Iteration_var myIteration = newIteration();
1729 if (CORBA::is_nil(myIteration))
1731 SALOME::ExceptionStruct es;
1732 es.type = SALOME::BAD_PARAM;
1733 es.text = "Unable to create the iteration";
1734 throw SALOME::SALOME_Exception(es);
1737 myContextMap[GetCurrentStudyID()]._mesIterations[std::string(NomIteration)] = myIteration;
1738 // Nom de l'iteration et du maillage
1739 myIteration->SetName(NomIteration);
1740 myIteration->SetMeshName(NomIteration);
1741 myIteration->SetState(1);
1743 int numero = myIterationParent->GetNumber() + 1;
1744 myIteration->SetNumber(numero);
1746 // Nombre d'iterations deja connues pour le cas, permettant
1747 // la creation d'un sous-repertoire unique
1748 int nbitercase = myCase->GetNumberofIter();
1749 char* nomDirIter = CreateDirNameIter(nomDirCase, nbitercase );
1750 myIteration->SetDirNameLoc(nomDirIter);
1752 // Le nom du fichier du maillage MED est indice par le nombre d'iterations du cas.
1753 // Si on a une chaine unique depuis le depart, ce nombre est le meme que le
1754 // numero d'iteration dans la sucession : maill.01.med, maill.02.med, etc... C'est la
1755 // situation la plus frequente.
1756 // Si on a plusieurs branches, donc des iterations du meme niveau d'adaptation, utiliser
1757 // le nombre d'iterations du cas permet d'eviter les collisions.
1759 if ( nbitercase < 100 ) { jaux = 2 ; }
1760 else if ( nbitercase < 1000 ) { jaux = 3 ; }
1761 else if ( nbitercase < 10000 ) { jaux = 4 ; }
1762 else if ( nbitercase < 100000 ) { jaux = 5 ; }
1764 std::ostringstream iaux ;
1765 iaux << std::setw(jaux) << std::setfill('0') << nbitercase ;
1766 std::stringstream MeshFile;
1767 MeshFile << nomDirCase << "/maill." << iaux.str() << ".med";
1768 myIteration->SetMeshFile(MeshFile.str().c_str());
1770 // Association avec le cas
1771 std::string label = "IterationHomard_" + std::string(nomIterParent);
1772 AssociateCaseIter(nomCas, NomIteration, label.c_str());
1773 // Lien avec l'iteration precedente
1774 myIterationParent->LinkNextIteration(NomIteration);
1775 myIteration->SetIterParentName(nomIterParent);
1777 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1779 //=============================================================================
1780 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundary(const char* BoundaryName, CORBA::Long BoundaryType)
1782 MESSAGE ("CreateBoundary : BoundaryName = " << BoundaryName << ", BoundaryType = " << BoundaryType);
1785 // Controle du nom :
1786 if ((myContextMap[GetCurrentStudyID()]._mesBoundarys).find(BoundaryName)!=(myContextMap[GetCurrentStudyID()]._mesBoundarys).end())
1788 MESSAGE ("CreateBoundary : la frontiere " << BoundaryName << " existe deja");
1789 SALOME::ExceptionStruct es;
1790 es.type = SALOME::BAD_PARAM;
1791 es.text = "This boundary has already been defined";
1792 throw SALOME::SALOME_Exception(es);
1796 HOMARD::HOMARD_Boundary_var myBoundary = newBoundary();
1797 myBoundary->SetName(BoundaryName);
1798 myBoundary->SetType(BoundaryType);
1800 myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName] = myBoundary;
1802 SALOMEDS::SObject_var aSO;
1803 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myBoundary, BoundaryName);
1805 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1807 //=============================================================================
1808 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
1810 INFOS ("CreateBoundaryDi : BoundaryName = " << BoundaryName << "MeshName = " << MeshName );
1811 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
1812 myBoundary->SetMeshFile( MeshFile ) ;
1813 myBoundary->SetMeshName( MeshName ) ;
1815 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1817 //=============================================================================
1818 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCylinder(const char* BoundaryName,
1819 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1820 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1821 CORBA::Double Rayon)
1823 INFOS ("CreateBoundaryCylinder : BoundaryName = " << BoundaryName ) ;
1825 SALOME::ExceptionStruct es;
1828 { es.text = "The radius must be positive." ;
1830 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1831 if ( daux < 0.0000001 )
1832 { es.text = "The axis must be a non 0 vector." ;
1836 es.type = SALOME::BAD_PARAM;
1837 throw SALOME::SALOME_Exception(es);
1841 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 1) ;
1842 myBoundary->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon ) ;
1844 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1846 //=============================================================================
1847 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundarySphere(const char* BoundaryName,
1848 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1849 CORBA::Double Rayon)
1851 INFOS ("CreateBoundarySphere : BoundaryName = " << BoundaryName ) ;
1853 SALOME::ExceptionStruct es;
1856 { es.text = "The radius must be positive." ;
1860 es.type = SALOME::BAD_PARAM;
1861 throw SALOME::SALOME_Exception(es);
1865 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 2) ;
1866 myBoundary->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
1868 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1870 //=============================================================================
1871 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeA(const char* BoundaryName,
1872 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe, CORBA::Double Angle,
1873 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre)
1875 INFOS ("CreateBoundaryConeA : BoundaryName = " << BoundaryName ) ;
1877 SALOME::ExceptionStruct es;
1879 if ( Angle <= 0.0 or Angle >= 90.0 )
1880 { es.text = "The angle must be included higher than 0 degree and lower than 90 degrees." ;
1882 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1883 if ( daux < 0.0000001 )
1884 { es.text = "The axis must be a non 0 vector." ;
1888 es.type = SALOME::BAD_PARAM;
1889 throw SALOME::SALOME_Exception(es);
1893 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 3) ;
1894 myBoundary->SetConeA( Xaxe, Yaxe, Zaxe, Angle, Xcentre, Ycentre, Zcentre ) ;
1896 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1898 //=============================================================================
1899 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeR(const char* BoundaryName,
1900 CORBA::Double Xcentre1, CORBA::Double Ycentre1, CORBA::Double Zcentre1, CORBA::Double Rayon1,
1901 CORBA::Double Xcentre2, CORBA::Double Ycentre2, CORBA::Double Zcentre2, CORBA::Double Rayon2)
1903 INFOS ("CreateBoundaryConeR : BoundaryName = " << BoundaryName ) ;
1905 SALOME::ExceptionStruct es;
1907 if ( Rayon1 < 0.0 or Rayon2 < 0.0 )
1908 { es.text = "The radius must be positive." ;
1910 double daux = fabs(Rayon2-Rayon1) ;
1911 if ( daux < 0.0000001 )
1912 { es.text = "The radius must be different." ;
1914 daux = fabs(Xcentre2-Xcentre1) + fabs(Ycentre2-Ycentre1) + fabs(Zcentre2-Zcentre1) ;
1915 if ( daux < 0.0000001 )
1916 { es.text = "The centers must be different." ;
1920 es.type = SALOME::BAD_PARAM;
1921 throw SALOME::SALOME_Exception(es);
1925 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 4) ;
1926 myBoundary->SetConeR( Xcentre1, Ycentre1, Zcentre1, Rayon1, Xcentre2, Ycentre2, Zcentre2, Rayon2 ) ;
1928 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1930 //=============================================================================
1931 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZone(const char* ZoneName, CORBA::Long ZoneType)
1933 MESSAGE ("CreateZone : ZoneName = " << ZoneName << ", ZoneType = " << ZoneType);
1936 // Controle du nom :
1937 if ((myContextMap[GetCurrentStudyID()]._mesZones).find(ZoneName)!=(myContextMap[GetCurrentStudyID()]._mesZones).end())
1939 SALOME::ExceptionStruct es;
1940 es.type = SALOME::BAD_PARAM;
1941 es.text = "This zone has already been defined";
1942 throw SALOME::SALOME_Exception(es);
1946 HOMARD::HOMARD_Zone_var myZone = newZone();
1947 myZone->SetName(ZoneName);
1948 myZone->SetType(ZoneType);
1950 myContextMap[GetCurrentStudyID()]._mesZones[ZoneName] = myZone;
1952 SALOMEDS::SObject_var aSO;
1953 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myZone, ZoneName);
1955 return HOMARD::HOMARD_Zone::_duplicate(myZone);
1957 //=============================================================================
1958 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox(const char* ZoneName,
1959 CORBA::Double Xmini, CORBA::Double Xmaxi,
1960 CORBA::Double Ymini, CORBA::Double Ymaxi,
1961 CORBA::Double Zmini, CORBA::Double Zmaxi)
1963 INFOS ("CreateZoneBox : ZoneName = " << ZoneName ) ;
1965 SALOME::ExceptionStruct es;
1967 if ( Xmini > Xmaxi )
1968 { es.text = "The X coordinates are not coherent." ;
1970 if ( Ymini > Ymaxi )
1971 { es.text = "The Y coordinates are not coherent." ;
1973 if ( Zmini > Zmaxi )
1974 { es.text = "The Z coordinates are not coherent." ;
1978 es.type = SALOME::BAD_PARAM;
1979 throw SALOME::SALOME_Exception(es);
1983 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 2) ;
1984 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
1986 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1988 //=============================================================================
1989 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneSphere(const char* ZoneName,
1990 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre, CORBA::Double Rayon)
1992 INFOS ("CreateZoneSphere : ZoneName = " << ZoneName ) ;
1994 SALOME::ExceptionStruct es;
1997 { es.text = "The radius must be positive." ;
2001 es.type = SALOME::BAD_PARAM;
2002 throw SALOME::SALOME_Exception(es);
2006 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 4) ;
2007 myZone->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
2009 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2011 //=============================================================================
2012 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneCylinder(const char* ZoneName,
2013 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2014 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2015 CORBA::Double Rayon, CORBA::Double Haut)
2017 INFOS ("CreateZoneCylinder : ZoneName = " << ZoneName ) ;
2019 SALOME::ExceptionStruct es;
2022 { es.text = "The radius must be positive." ;
2024 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2025 if ( daux < 0.0000001 )
2026 { es.text = "The axis must be a non 0 vector." ;
2029 { es.text = "The height must be positive." ;
2033 es.type = SALOME::BAD_PARAM;
2034 throw SALOME::SALOME_Exception(es);
2038 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 5) ;
2039 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut ) ;
2041 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2043 //=============================================================================
2044 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZonePipe(const char* ZoneName,
2045 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2046 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2047 CORBA::Double Rayon, CORBA::Double Haut, CORBA::Double Rayonint)
2049 INFOS ("CreateZonePipe : ZoneName = " << ZoneName ) ;
2051 SALOME::ExceptionStruct es;
2053 if ( Rayon <= 0.0 or Rayonint <= 0.0 )
2054 { es.text = "The radius must be positive." ;
2056 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2057 if ( daux < 0.0000001 )
2058 { es.text = "The axis must be a non 0 vector." ;
2061 { es.text = "The height must be positive." ;
2063 if ( Rayon <= Rayonint )
2064 { es.text = "The external radius must be higher than the internal radius." ;
2068 es.type = SALOME::BAD_PARAM;
2069 throw SALOME::SALOME_Exception(es);
2073 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 7) ;
2074 myZone->SetPipe( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut, Rayonint ) ;
2076 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2078 //=============================================================================
2079 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox2D(const char* ZoneName,
2080 CORBA::Double Umini, CORBA::Double Umaxi,
2081 CORBA::Double Vmini, CORBA::Double Vmaxi,
2084 INFOS ("CreateZoneBox2D : ZoneName = " << ZoneName ) ;
2085 // MESSAGE ("Umini = " << Umini << ", Umaxi =" << Umaxi ) ;
2086 // MESSAGE ("Vmini = " << Vmini << ", Vmaxi =" << Vmaxi ) ;
2087 // MESSAGE ("Orient = " << Orient ) ;
2089 SALOME::ExceptionStruct es;
2091 if ( Umini > Umaxi )
2092 { es.text = "The first coordinates are not coherent." ;
2094 if ( Vmini > Vmaxi )
2095 { es.text = "The second coordinates are not coherent." ;
2097 if ( Orient < 1 or Orient > 3 )
2098 { es.text = "The orientation must be 1, 2 or 3." ;
2102 es.type = SALOME::BAD_PARAM;
2103 throw SALOME::SALOME_Exception(es);
2107 double Xmini, Xmaxi ;
2108 double Ymini, Ymaxi ;
2109 double Zmini, Zmaxi ;
2117 else if ( Orient == 2 )
2124 else if ( Orient == 3 )
2131 else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
2133 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 10+Orient) ;
2134 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2136 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2138 //=============================================================================
2139 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDisk(const char* ZoneName,
2140 CORBA::Double Ucentre, CORBA::Double Vcentre,
2141 CORBA::Double Rayon,
2144 INFOS ("CreateZoneDisk : ZoneName = " << ZoneName ) ;
2146 SALOME::ExceptionStruct es;
2149 { es.text = "The radius must be positive." ;
2151 if ( Orient < 1 or Orient > 3 )
2152 { es.text = "The orientation must be 1, 2 or 3." ;
2156 es.type = SALOME::BAD_PARAM;
2157 throw SALOME::SALOME_Exception(es);
2165 { Xcentre = Ucentre ;
2168 else if ( Orient == 2 )
2171 Zcentre = Vcentre ; }
2172 else if ( Orient == 3 )
2173 { Xcentre = Vcentre ;
2175 Zcentre = Ucentre ; }
2176 else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
2178 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 30+Orient) ;
2179 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1. ) ;
2181 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2183 //=============================================================================
2184 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDiskWithHole(const char* ZoneName,
2185 CORBA::Double Ucentre, CORBA::Double Vcentre,
2186 CORBA::Double Rayon, CORBA::Double Rayonint,
2189 INFOS ("CreateZoneDiskWithHole : ZoneName = " << ZoneName ) ;
2191 SALOME::ExceptionStruct es;
2193 if ( Rayon <= 0.0 or Rayonint <= 0.0 )
2194 { es.text = "The radius must be positive." ;
2196 if ( Orient < 1 or Orient > 3 )
2197 { es.text = "The orientation must be 1, 2 or 3." ;
2199 if ( Rayon <= Rayonint )
2200 { es.text = "The external radius must be higher than the internal radius." ;
2204 es.type = SALOME::BAD_PARAM;
2205 throw SALOME::SALOME_Exception(es);
2213 { Xcentre = Ucentre ;
2216 else if ( Orient == 2 )
2219 Zcentre = Vcentre ; }
2220 else if ( Orient == 3 )
2221 { Xcentre = Vcentre ;
2223 Zcentre = Ucentre ; }
2224 else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
2226 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 60+Orient) ;
2227 myZone->SetPipe( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1., Rayonint ) ;
2229 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2231 //=============================================================================
2232 //=============================================================================
2237 //=============================================================================
2238 //=============================================================================
2239 // Traitement d'une iteration
2240 // etatMenage = 1 : destruction du repertoire d'execution
2241 // modeHOMARD = 1 : adaptation
2242 // != 1 : information avec les options modeHOMARD
2243 // Option1 >0 : appel depuis python
2244 // <0 : appel depuis GUI
2245 // Option2 : multiple de nombres premiers
2246 // 1 : aucune option
2247 // x2 : publication du maillage dans SMESH
2248 //=============================================================================
2249 CORBA::Long HOMARD_Gen_i::Compute(const char* NomIteration, CORBA::Long etatMenage, CORBA::Long modeHOMARD, CORBA::Long Option1, CORBA::Long Option2)
2251 INFOS ( "Compute : traitement de " << NomIteration << ", avec modeHOMARD = " << modeHOMARD << ", Option1 = " << Option1 << ", Option2 = " << Option2 );
2256 // A.1. L'objet iteration
2257 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration];
2258 ASSERT(!CORBA::is_nil(myIteration));
2260 // A.2. Numero de l'iteration
2261 // siterp1 : numero de l'iteration a traiter
2263 // siter : numero de l'iteration parent, ou 0 si deja au debut mais cela ne servira pas !
2264 // Ou si information :
2266 int NumeIter = myIteration->GetNumber();
2267 std::string siterp1 ;
2268 std::stringstream saux1 ;
2270 siterp1 = saux1.str() ;
2271 if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
2274 if ( modeHOMARD==1 )
2276 std::stringstream saux0 ;
2277 int iaux = max(0, NumeIter-1) ;
2279 siter = saux0.str() ;
2280 if (NumeIter < 11) { siter = "0" + siter ; }
2283 { siter = siterp1 ; }
2286 const char* nomCas = myIteration->GetCaseName();
2287 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
2288 ASSERT(!CORBA::is_nil(myCase));
2290 // B. Les repertoires
2291 // B.1. Le repertoire courant
2292 std::string nomDirWork = getenv("PWD") ;
2293 // B.2. Le sous-repertoire de l'iteration a traiter
2294 char* DirCompute = ComputeDirManagement(myCase, myIteration, etatMenage);
2295 MESSAGE( ". DirCompute = " << DirCompute );
2297 // C. Le fichier des messages
2298 // C.1. Le deroulement de l'execution de HOMARD
2299 std::string LogFile = DirCompute ;
2300 LogFile += "/Liste" ;
2301 if ( modeHOMARD == 1 ) { LogFile += "." + siter + ".vers." + siterp1 ; }
2303 MESSAGE (". LogFile = " << LogFile);
2304 if ( modeHOMARD == 1 ) { myIteration->SetLogFile(LogFile.c_str()); }
2305 // C.2. Le bilan de l'analyse du maillage
2306 std::string FileInfo = DirCompute ;
2308 if ( modeHOMARD == 1 ) { FileInfo += "apad" ; }
2310 { if ( NumeIter == 0 ) { FileInfo += "info_av" ; }
2311 else { FileInfo += "info_ap" ; }
2313 FileInfo += "." + siterp1 + ".bilan" ;
2314 myIteration->SetFileInfo(FileInfo.c_str());
2316 // D. On passe dans le repertoire de l'iteration a calculer
2317 MESSAGE ( ". On passe dans DirCompute = " << DirCompute );
2320 // E. Les donnees de l'execution HOMARD
2321 // E.1. L'objet du texte du fichier de configuration
2322 HomardDriver* myDriver = new HomardDriver(siter, siterp1);
2323 myDriver->TexteInit(DirCompute, LogFile, _Langue);
2325 // E.2. Le maillage associe a l'iteration
2326 const char* NomMesh = myIteration->GetMeshName();
2327 MESSAGE ( ". NomMesh = " << NomMesh );
2328 const char* MeshFile = myIteration->GetMeshFile();
2329 MESSAGE ( ". MeshFile = " << MeshFile );
2331 // E.3. Les donnees du traitement HOMARD
2333 if ( modeHOMARD == 1 )
2336 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2337 myDriver->TexteMaillage(NomMesh, MeshFile, 1);
2338 codret = ComputeAdap(myCase, myIteration, etatMenage, myDriver, Option1, Option2) ;
2342 InvalideIterInfo(NomIteration);
2343 myDriver->TexteInfo( modeHOMARD, NumeIter ) ;
2345 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2346 myDriver->TexteMaillage(NomMesh, MeshFile, 0);
2347 myDriver->CreeFichierDonn();
2350 // E.4. Ajout des informations liees a l'eventuel suivi de frontiere
2351 DriverTexteBoundary(myCase, myDriver) ;
2353 // E.5. Ecriture du texte dans le fichier
2355 { myDriver->CreeFichier(); }
2359 int codretexec = 12 ;
2362 codretexec = myDriver->ExecuteHomard(Option1);
2364 MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
2365 if ( modeHOMARD == 1 )
2367 if (codretexec == 0) { SetEtatIter(NomIteration,2); }
2368 else { SetEtatIter(NomIteration,1); }
2369 // GERALD -- QMESSAGE BOX
2373 // H. Gestion des resultats
2376 std::string Commentaire ;
2377 // H.1. Le fichier des messages, dans tous les cas
2378 Commentaire = "log" ;
2379 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2380 else { Commentaire += "Info" ; }
2381 PublishFileUnderIteration(NomIteration, LogFile.c_str(), Commentaire.c_str());
2383 // H.2. Si tout s'est bien passe :
2384 if (codretexec == 0)
2386 // H.2.1. Le fichier de bilan
2387 Commentaire = "Summary" ;
2388 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2389 else { Commentaire += "Info" ; }
2390 PublishFileUnderIteration(NomIteration, FileInfo.c_str(), Commentaire.c_str());
2391 // H.2.2. Le fichier de maillage obtenu
2392 if ( modeHOMARD == 1 )
2394 std::stringstream saux0 ;
2395 Commentaire = "Mesh" ;
2396 Commentaire += " " + siterp1 ;
2397 PublishFileUnderIteration(NomIteration, MeshFile, Commentaire.c_str());
2398 if ( Option2 % 2 == 0 ) { PublishResultInSmesh(MeshFile, 1); }
2401 // H.3 Message d'erreur en cas de probleme
2404 SALOME::ExceptionStruct es;
2405 es.type = SALOME::BAD_PARAM;
2406 std::string text = "Error during the adaptation.\n" ;
2409 ifstream fichier(LogFile.c_str(), ios::in);
2411 while(getline(fichier, ligne) and (ligne != "===== HOMARD ===== STOP ====="));
2412 while (getline(fichier, ligne)) { text += ligne+ "\n";};
2415 text += "no log file ....";
2417 es.text = CORBA::string_dup(text.c_str());
2418 throw SALOME::SALOME_Exception(es);
2422 // I. Menage et retour dans le repertoire du cas
2426 MESSAGE ( ". On retourne dans nomDirWork = " << nomDirWork );
2427 chdir(nomDirWork.c_str());
2432 //=============================================================================
2433 // Calcul d'une iteration : partie specifique a l'adaptation
2434 //=============================================================================
2435 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)
2437 MESSAGE ( "ComputeAdap" );
2442 // Etat de l'iteration
2443 int etat = myIteration->GetState();
2444 // Numero de l'iteration
2445 int NumeIter = myIteration->GetNumber();
2446 std::stringstream saux0 ;
2447 saux0 << NumeIter-1 ;
2448 std::string siter = saux0.str() ;
2449 if (NumeIter < 11) { siter = "0" + siter ; }
2451 // A.2. On ne calcule pas l iteration initiale
2454 MESSAGE ( "etat = "<<etat );
2455 SALOME::ExceptionStruct es;
2456 es.type = SALOME::BAD_PARAM;
2457 es.text = "This iteration is the first of the case and cannot be computed.";
2458 throw SALOME::SALOME_Exception(es);
2462 // A.3. On verifie qu il y a une hypothese (erreur improbable);
2463 const char* nomHypo = myIteration->GetHypoName();
2464 if (std::string(nomHypo) == std::string(""))
2466 SALOME::ExceptionStruct es;
2467 es.type = SALOME::BAD_PARAM;
2468 es.text = "This iteration does not have any associated hypothesis.";
2469 throw SALOME::SALOME_Exception(es);
2472 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
2473 ASSERT(!CORBA::is_nil(myHypo));
2475 // B. L'iteration parent
2476 const char* nomIterationParent = myIteration->GetIterParentName();
2477 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
2478 ASSERT(!CORBA::is_nil(myIterationParent));
2479 // Si l'iteration parent n'est pas calculee, on le fait (recursivite amont)
2480 if ( myIterationParent->GetState() == 1 )
2483 int codret = Compute(nomIterationParent, etatMenage, iaux, Option1, Option2);
2486 // GERALD -- QMESSAGE BOX
2487 ASSERT("Pb au calcul de l'iteration precedente" == 0);
2491 // C. Le sous-repertoire de l'iteration precedente
2492 char* DirComputePa = ComputeDirPaManagement(myCase, myIteration);
2493 MESSAGE( ". DirComputePa = " << DirComputePa );
2495 // D. Les donnees de l'adaptation HOMARD
2496 // D.1. Le type de conformite
2497 int ConfType = myCase->GetConfType();
2498 MESSAGE ( ". ConfType = " << ConfType );
2500 // D.2. Le maillage de depart
2501 const char* NomMeshParent = myIterationParent->GetMeshName();
2502 MESSAGE ( ". NomMeshParent = " << NomMeshParent );
2503 const char* MeshFileParent = myIterationParent->GetMeshFile();
2504 MESSAGE ( ". MeshFileParent = " << MeshFileParent );
2506 // D.3. Le maillage associe a l'iteration
2507 const char* MeshFile = myIteration->GetMeshFile();
2508 MESSAGE ( ". MeshFile = " << MeshFile );
2509 FILE *file = fopen(MeshFile,"r");
2513 if (etatMenage == 0)
2515 SALOME::ExceptionStruct es;
2516 es.type = SALOME::BAD_PARAM;
2517 std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
2518 es.text = CORBA::string_dup(text.c_str());
2519 throw SALOME::SALOME_Exception(es);
2524 std::string commande = "rm -f " + std::string(MeshFile);
2525 codret = system(commande.c_str());
2528 SALOME::ExceptionStruct es;
2529 es.type = SALOME::BAD_PARAM;
2530 es.text = "The mesh file cannot be deleted.";
2531 throw SALOME::SALOME_Exception(es);
2537 // D.4. Les types de raffinement et de deraffinement
2538 // Les appels corba sont lourds, il vaut mieux les grouper
2539 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
2540 ASSERT(ListTypes->length() == 3);
2541 int TypeAdap = (*ListTypes)[0];
2542 int TypeRaff = (*ListTypes)[1];
2543 int TypeDera = (*ListTypes)[2];
2545 // E. Texte du fichier de configuration
2546 // E.1. Incontournables du texte
2547 myDriver->TexteAdap();
2549 myDriver->TexteMaillageHOMARD( DirComputePa, siter, iaux ) ;
2550 myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
2551 myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
2553 // E.2. Ajout des informations liees aux zones eventuelles
2554 if ( TypeAdap == 0 )
2555 { DriverTexteZone(myHypo, myDriver) ; }
2557 // E.3. Ajout des informations liees aux champs eventuels
2558 if ( TypeAdap == 1 )
2559 { DriverTexteField(myIteration, myHypo, myDriver) ; }
2561 // E.4. Ajout des informations liees au filtrage eventuel par les groupes
2562 HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
2563 int numberOfGroups = listeGroupes->length();
2564 MESSAGE( ". Filtrage par " << numberOfGroups << " groupes");
2565 if (numberOfGroups > 0)
2567 for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
2569 std::string GroupName = std::string((*listeGroupes)[NumGroup]);
2570 MESSAGE( "... GroupName = " << GroupName );
2571 myDriver->TexteGroup(GroupName);
2575 // E.5. Ajout des informations liees a l'eventuelle interpolation des champs
2576 DriverTexteFieldInterp(myIteration, myHypo, myDriver) ;
2578 // E.6. Ajout des options avancees
2579 int Pyram = myCase->GetPyram();
2580 MESSAGE ( ". Pyram = " << Pyram );
2581 int NivMax = myHypo->GetNivMax();
2582 MESSAGE ( ". NivMax = " << NivMax );
2583 double DiamMin = myHypo->GetDiamMin() ;
2584 MESSAGE ( ". DiamMin = " << DiamMin );
2585 int AdapInit = myHypo->GetAdapInit();
2586 MESSAGE ( ". AdapInit = " << AdapInit );
2587 int LevelOutput = myHypo->GetLevelOutput();
2588 MESSAGE ( ". LevelOutput = " << LevelOutput );
2589 myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, LevelOutput);
2591 // E.7. Ajout des informations sur le deroulement de l'execution
2592 int MessInfo = myIteration->GetInfoCompute();
2593 MESSAGE ( ". MessInfo = " << MessInfo );
2594 myDriver->TexteInfoCompute(MessInfo);
2598 //=============================================================================
2599 // Creation d'un nom de sous-repertoire pour l'iteration au sein d'un repertoire parent
2600 // nomrep : nom du repertoire parent
2601 // num : le nom du sous-repertoire est sous la forme 'In', n est >= num
2602 //=============================================================================
2603 char* HOMARD_Gen_i::CreateDirNameIter(const char* nomrep, CORBA::Long num )
2605 MESSAGE ( "CreateDirNameIter : nomrep ="<< nomrep << ", num = "<<num);
2606 // On verifie que le repertoire parent existe
2607 int codret = chdir(nomrep) ;
2610 SALOME::ExceptionStruct es;
2611 es.type = SALOME::BAD_PARAM;
2612 es.text = "The directory of the case does not exist.";
2613 throw SALOME::SALOME_Exception(es);
2616 std::string nomDirActuel = getenv("PWD") ;
2617 std::string DirName ;
2618 // On boucle sur tous les noms possibles jusqu'a trouver un nom correspondant a un repertoire inconnu
2619 bool a_chercher = true ;
2620 while ( a_chercher )
2622 // On passe dans le repertoire parent
2624 // On recherche un nom sous la forme Iabc, avec abc representant le numero
2626 if ( num < 100 ) { jaux = 2 ; }
2627 else if ( num < 1000 ) { jaux = 3 ; }
2628 else if ( num < 10000 ) { jaux = 4 ; }
2629 else if ( num < 100000 ) { jaux = 5 ; }
2631 std::ostringstream iaux ;
2632 iaux << std::setw(jaux) << std::setfill('0') << num ;
2633 std::ostringstream DirNameA ;
2634 DirNameA << "I" << iaux.str();
2635 // Si on ne pas peut entrer dans le repertoire, on doit verifier
2636 // que c'est bien un probleme d'absence
2637 if ( chdir(DirNameA.str().c_str()) != 0 )
2639 bool existe = false ;
2641 struct dirent *dirp;
2642 dp = opendir(nomrep);
2643 while ( (dirp = readdir(dp)) != NULL )
2645 std::string file_name(dirp->d_name);
2646 if ( file_name == DirNameA.str() ) { existe = true ; }
2651 DirName = DirNameA.str() ;
2652 a_chercher = false ;
2659 MESSAGE ( "==> DirName = " << DirName);
2660 MESSAGE ( ". On retourne dans nomDirActuel = " << nomDirActuel );
2661 chdir(nomDirActuel.c_str());
2663 return CORBA::string_dup( DirName.c_str() );
2665 //=============================================================================
2666 // Calcul d'une iteration : gestion du repertoire de calcul
2667 // Si le sous-repertoire existe :
2668 // etatMenage = 0 : on sort en erreur si le repertoire n'est pas vide
2669 // etatMenage = 1 : on fait le menage du repertoire
2670 // etatMenage = -1 : on ne fait rien
2671 //=============================================================================
2672 char* HOMARD_Gen_i::ComputeDirManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage)
2674 MESSAGE ( "ComputeDirManagement : repertoires pour le calcul" );
2675 // B.2. Le repertoire du cas
2676 const char* nomDirCase = myCase->GetDirName();
2677 MESSAGE ( ". nomDirCase = " << nomDirCase );
2679 // B.3. Le sous-repertoire de l'iteration a calculer, puis le repertoire complet a creer
2680 // B.3.1. Le nom du sous-repertoire
2681 const char* nomDirIt = myIteration->GetDirNameLoc();
2683 // B.3.2. Le nom complet du sous-repertoire
2684 std::stringstream DirCompute ;
2685 DirCompute << nomDirCase << "/" << nomDirIt;
2686 MESSAGE (". DirCompute = " << DirCompute.str() );
2688 // B.3.3. Si le sous-repertoire n'existe pas, on le cree
2689 if (chdir(DirCompute.str().c_str()) != 0)
2691 // Creation du repertoire car il n'existe pas :
2692 if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
2694 // GERALD -- QMESSAGE BOX
2695 std::cerr << "Pb Creation du repertoire DirCompute = " << DirCompute.str() << std::endl;
2696 ASSERT("Pb a la creation du repertoire" == 0);
2701 // Le repertoire existe
2702 // On demande de faire le menage de son contenu :
2703 if (etatMenage == 1)
2705 MESSAGE (". Menage du repertoire DirCompute = " << DirCompute.str());
2706 std::string commande = "rm -rf " + DirCompute.str()+"/*" ;
2707 int codret = system(commande.c_str());
2710 // GERALD -- QMESSAGE BOX
2711 std::cerr << ". Menage du repertoire de calcul" << DirCompute.str() << std::endl;
2712 ASSERT("Pb au menage du repertoire de calcul" == 0);
2715 // On n'a pas demande de faire le menage de son contenu : on sort en erreur :
2718 if (etatMenage == 0)
2721 struct dirent *dirp;
2722 dp = opendir(DirCompute.str().c_str());
2724 while ((dirp = readdir(dp)) != NULL && result )
2726 std::string file_name(dirp->d_name);
2727 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
2730 if ( result == false)
2732 SALOME::ExceptionStruct es;
2733 es.type = SALOME::BAD_PARAM;
2734 std::string text = "Directory : " + DirCompute.str() + "is not empty";
2735 es.text = CORBA::string_dup(text.c_str());
2736 throw SALOME::SALOME_Exception(es);
2737 ASSERT("Directory is not empty" == 0);
2743 return CORBA::string_dup( DirCompute.str().c_str() );
2745 //=============================================================================
2746 // Calcul d'une iteration : gestion du repertoire de calcul de l'iteration parent
2747 //=============================================================================
2748 char* HOMARD_Gen_i::ComputeDirPaManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration)
2750 MESSAGE ( "ComputeDirPaManagement : repertoires pour le calcul" );
2751 // Le repertoire du cas
2752 const char* nomDirCase = myCase->GetDirName();
2753 MESSAGE ( ". nomDirCase = " << nomDirCase );
2755 // Le sous-repertoire de l'iteration precedente
2757 const char* nomIterationParent = myIteration->GetIterParentName();
2758 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
2759 const char* nomDirItPa = myIterationParent->GetDirNameLoc();
2760 std::stringstream DirComputePa ;
2761 DirComputePa << nomDirCase << "/" << nomDirItPa;
2762 MESSAGE( ". nomDirItPa = " << nomDirItPa);
2763 MESSAGE( ". DirComputePa = " << DirComputePa.str() );
2765 return CORBA::string_dup( DirComputePa.str().c_str() );
2767 //=============================================================================
2768 // Calcul d'une iteration : ecriture des zones dans le fichier de configuration
2769 //=============================================================================
2770 void HOMARD_Gen_i::DriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
2772 MESSAGE ( "... DriverTexteZone" );
2773 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
2774 int numberOfZonesx2 = ListZone->length();
2777 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
2779 std::string ZoneName = std::string((*ListZone)[iaux]);
2780 MESSAGE ( "... ZoneName = " << ZoneName);
2781 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
2782 ASSERT(!CORBA::is_nil(myZone));
2784 int ZoneType = myZone->GetType();
2785 std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
2786 int TypeUse = atoi( TypeUsestr.c_str() );
2787 MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
2788 NumZone = iaux/2 + 1 ;
2789 HOMARD::double_array* zone = myZone->GetCoords();
2790 if ( ZoneType == 2 or ( ZoneType>=11 and ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
2791 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.); }
2792 else if ( ZoneType == 4 ) // Cas d une sphere
2793 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.); }
2794 else if ( ZoneType == 5 or ( ZoneType>=31 and ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
2795 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.); }
2796 else if ( ZoneType == 7 or ( ZoneType>=61 and ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
2797 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]); }
2798 else { ASSERT("ZoneType est incorrect." == 0) ; }
2803 //=============================================================================
2804 // Calcul d'une iteration : ecriture des champs dans le fichier de configuration
2805 //=============================================================================
2806 void HOMARD_Gen_i::DriverTexteField(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
2808 MESSAGE ( "... DriverTexteField" );
2809 // Le fichier du champ
2810 char* FieldFile = myIteration->GetFieldFile();
2811 MESSAGE ( ". FieldFile = " << FieldFile );
2812 if (strlen(FieldFile) == 0)
2814 // GERALD -- QMESSAGE BOX
2815 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
2816 ASSERT("The file for the field is not given." == 0);
2818 // Les caracteristiques d'instants
2819 int TimeStep = myIteration->GetTimeStep();
2820 MESSAGE( ". TimeStep = " << TimeStep );
2821 int Rank = myIteration->GetRank();
2822 MESSAGE( ". Rank = " << Rank );
2823 // Les informations sur les champs
2824 HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
2826 const char* FieldName = aInfosHypo->FieldName;
2828 int TypeThR = aInfosHypo->TypeThR;
2829 double ThreshR = aInfosHypo->ThreshR;
2830 int TypeThC = aInfosHypo->TypeThC;
2831 double ThreshC = aInfosHypo->ThreshC;
2832 // Saut entre mailles ou non ?
2833 int UsField = aInfosHypo->UsField;
2834 MESSAGE( ". UsField = " << UsField );
2835 // L'usage des composantes
2836 int UsCmpI = aInfosHypo->UsCmpI;
2837 MESSAGE( ". UsCmpI = " << UsCmpI );
2839 myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
2842 HOMARD::listeComposantsHypo* mescompo = myHypo->GetListComp();
2843 int numberOfCompos = mescompo->length();
2844 MESSAGE( ". numberOfCompos = " << numberOfCompos );
2845 for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
2847 std::string nomCompo = std::string((*mescompo)[NumeComp]);
2848 MESSAGE( "... nomCompo = " << nomCompo );
2849 myDriver->TexteCompo(NumeComp, nomCompo);
2853 //=============================================================================
2854 // Calcul d'une iteration : ecriture des frontieres dans le fichier de configuration
2855 //=============================================================================
2856 void HOMARD_Gen_i::DriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, HomardDriver* myDriver)
2858 MESSAGE ( "... DriverTexteBoundary" );
2859 // On ecrit d'abord la definition des frontieres, puis les liens avec les groupes
2860 std::list<std::string> ListeBoundaryTraitees ;
2861 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
2862 int numberOfitems = ListBoundaryGroupType->length();
2863 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
2864 int BoundaryOption = 1 ;
2865 int NumBoundaryAnalytical = 0 ;
2866 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
2868 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
2869 MESSAGE ( "... BoundaryName = " << BoundaryName);
2871 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
2872 while (it != ListeBoundaryTraitees.end())
2874 MESSAGE ( "..... BoundaryNameTraitee = " << *it);
2875 if ( BoundaryName == *it ) { A_faire = 0 ; }
2880 // Caracteristiques de la frontiere
2881 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
2882 ASSERT(!CORBA::is_nil(myBoundary));
2883 int BoundaryType = myBoundary->GetType();
2884 MESSAGE ( "... BoundaryType = " << BoundaryType );
2885 // Ecriture selon le type
2886 if (BoundaryType == 0) // Cas d une frontiere discrete
2888 const char* MeshName = myBoundary->GetMeshName() ;
2889 const char* MeshFile = myBoundary->GetMeshFile() ;
2890 myDriver->TexteBoundaryDi( MeshName, MeshFile);
2891 if ( BoundaryOption % 2 != 0 ) { BoundaryOption = BoundaryOption*2 ; }
2893 else // Cas d une frontiere analytique
2895 NumBoundaryAnalytical++ ;
2896 HOMARD::double_array* coor = myBoundary->GetCoords();
2897 if (BoundaryType == 1) // Cas d un cylindre
2899 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
2900 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
2902 else if (BoundaryType == 2) // Cas d une sphere
2904 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0., 0.);
2905 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
2907 else if (BoundaryType == 3) // Cas d un cone defini par un axe et un angle
2909 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
2910 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
2912 else if (BoundaryType == 4) // Cas d un cone defini par les 2 rayons
2914 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
2915 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
2918 // Memorisation du traitement
2919 ListeBoundaryTraitees.push_back( BoundaryName );
2922 NumBoundaryAnalytical = 0 ;
2923 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
2925 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
2926 MESSAGE ( "... BoundaryName = " << BoundaryName);
2927 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
2928 ASSERT(!CORBA::is_nil(myBoundary));
2929 int BoundaryType = myBoundary->GetType();
2930 MESSAGE ( "... BoundaryType = " << BoundaryType );
2931 // Recuperation du nom du groupe
2932 std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
2933 MESSAGE ( "... GroupName = " << GroupName);
2934 if (BoundaryType == 0) // Cas d une frontiere discrete
2936 if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
2938 else // Cas d une frontiere analytique
2940 NumBoundaryAnalytical++ ;
2941 myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
2944 myDriver->TexteBoundaryOption(BoundaryOption);
2947 //=============================================================================
2948 // Calcul d'une iteration : ecriture des interpolations dans le fichier de configuration
2949 //=============================================================================
2950 void HOMARD_Gen_i::DriverTexteFieldInterp(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
2952 MESSAGE ( "... DriverTexteFieldInterp" );
2953 int TypeFieldInterp = myHypo->GetTypeFieldInterp();
2954 if (TypeFieldInterp != 0)
2956 // Le fichier des champs
2957 char* FieldFile = myIteration->GetFieldFile();
2958 MESSAGE ( ". FieldFile = " << FieldFile );
2959 if (strlen(FieldFile) == 0)
2961 // GERALD -- QMESSAGE BOX
2962 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
2963 ASSERT("The file for the field is not given." == 0);
2965 // Les caracteristiques d'instants
2966 int TimeStep = myIteration->GetTimeStep();
2967 MESSAGE( ". TimeStep = " << TimeStep );
2968 int Rank = myIteration->GetRank();
2969 MESSAGE( ". Rank = " << Rank );
2971 const char* MeshFile = myIteration->GetMeshFile();
2972 myDriver->TexteFieldInterp(TypeFieldInterp, FieldFile, MeshFile, TimeStep, Rank);
2974 if (TypeFieldInterp == 2)
2976 HOMARD::listFieldInterpHypo* meschamps = myHypo->GetListFieldInterp();
2977 int numberOfFields = meschamps->length();
2978 MESSAGE( ". numberOfFields = " << numberOfFields );
2979 for (int NumeChamp = 0; NumeChamp< numberOfFields; NumeChamp++)
2981 std::string nomChamp = std::string((*meschamps)[NumeChamp]);
2982 MESSAGE( "... nomChamp = " << nomChamp );
2983 myDriver->TexteFieldInterpName(NumeChamp, nomChamp);
2989 //===========================================================================
2990 //===========================================================================
2993 //===========================================================================
2994 //===========================================================================
2996 //===========================================================================
2997 //===========================================================================
2998 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
2999 SALOMEDS::SObject_ptr theSObject,
3000 CORBA::Object_ptr theObject,
3001 const char* theName)
3003 MESSAGE("PublishInStudy pour " << theName);
3004 SALOMEDS::SObject_var aResultSO;
3005 if (CORBA::is_nil(theStudy))
3007 SALOME::ExceptionStruct es;
3008 es.type = SALOME::BAD_PARAM;
3009 es.text = "Invalid study context";
3010 throw SALOME::SALOME_Exception(es);
3014 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
3015 // Rq : Iteration est publiee ailleurs
3016 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
3017 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(theObject);
3018 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
3019 HOMARD::HOMARD_YACS_var aYACS = HOMARD::HOMARD_YACS::_narrow(theObject);
3020 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
3022 addInStudy(theStudy);
3024 // Controle de la non publication d'un objet de meme nom
3025 if ( (!aBoundary->_is_nil()) or (!aHypo->_is_nil()) or (!aYACS->_is_nil()) or (!aZone->_is_nil()) )
3027 SALOMEDS::Study::ListOfSObject_var listSO = theStudy->FindObjectByName(theName, ComponentDataType());
3028 if (listSO->length() >= 1)
3030 MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
3031 aResultSO = listSO[0];
3032 return aResultSO._retn();
3036 // Caracteristiques de l'etude
3037 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
3038 aStudyBuilder->NewCommand();
3039 if(!aBoundary->_is_nil())
3040 aResultSO = PublishBoundaryInStudy(theStudy, aStudyBuilder, aBoundary, theName);
3041 else if(!aCase->_is_nil())
3042 aResultSO = PublishCaseInStudy(theStudy, aStudyBuilder, aCase, theName);
3043 else if(!aHypo->_is_nil())
3044 aResultSO = PublishHypotheseInStudy(theStudy, aStudyBuilder, aHypo, theName);
3045 else if(!aYACS->_is_nil())
3046 aResultSO = PublishYACSInStudy(theStudy, aStudyBuilder, aYACS, theName);
3047 else if(!aZone->_is_nil())
3048 aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName);
3050 aStudyBuilder->CommitCommand();
3052 return aResultSO._retn();
3054 //=============================================================================
3055 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy(SALOMEDS::Study_ptr theStudy,
3056 SALOMEDS::StudyBuilder_var aStudyBuilder,
3057 HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
3059 MESSAGE("PublishBoundaryStudy pour "<<theName);
3060 SALOMEDS::SObject_var aResultSO;
3062 // Caracteristique de la Boundary
3063 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[theName];
3065 // On recupere le module pere dans l etude
3066 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3067 if (theFatherHomard->_is_nil())
3069 MESSAGE("theFatherHomard->_is_nil()");
3070 return aResultSO._retn();
3073 // On ajoute la categorie des boundarys dans l etude si necessaire
3074 if ( _tag_boun == 0 )
3077 _tag_boun = _tag_gene ;
3079 MESSAGE("PublishBoundaryInStudy _tag_gene = "<<_tag_gene << ", _tag_boun = "<<_tag_boun );
3080 SALOMEDS::SObject_var aSObject;
3081 if (!theFatherHomard->FindSubObject(_tag_boun, aSObject))
3083 MESSAGE("Ajout de la categorie des boundarys");
3084 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_boun);
3085 PublishInStudyAttr(aStudyBuilder, aSObject, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
3087 else { MESSAGE("La categorie des boundarys existe deja."); }
3089 CORBA::Long BoundaryType = myBoundary->GetType();
3090 // MESSAGE("BoundaryType : "<<BoundaryType);
3093 switch (BoundaryType)
3096 { value = "BoundaryDiHomard" ;
3097 icone = "mesh_tree_mesh.png" ;
3101 { value = "BoundaryAnHomard" ;
3102 icone = "cylinderpointvector_2.png" ;
3106 { value = "BoundaryAnHomard" ;
3107 icone = "spherepoint_2.png" ;
3111 { value = "BoundaryAnHomard" ;
3112 icone = "conepointvector.png" ;
3116 { value = "BoundaryAnHomard" ;
3117 icone = "conedxyz.png" ;
3121 aResultSO = aStudyBuilder->NewObject(aSObject);
3122 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value.c_str(), icone.c_str(), _orb->object_to_string(theObject));
3123 return aResultSO._retn();
3125 //=============================================================================
3126 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::Study_ptr theStudy,
3127 SALOMEDS::StudyBuilder_var aStudyBuilder,
3128 HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
3130 MESSAGE("PublishCaseInStudy pour "<<theName);
3131 SALOMEDS::SObject_var aResultSO;
3133 if (CORBA::is_nil(theObject)) {
3134 MESSAGE("HOMARD_Gen_i::theObject->_is_nil()");
3135 return aResultSO._retn();
3137 if (theStudy->_is_nil()) {
3138 MESSAGE("HOMARD_Gen_i::theStudy->_is_nil()");
3139 return aResultSO._retn();
3142 // On recupere le module pere dans l etude
3143 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3144 if (theFatherHomard->_is_nil())
3146 MESSAGE("theFatherHomard->_is_nil()");
3147 return aResultSO._retn();
3151 MESSAGE("PublishCaseInStudy _tag_gene = "<<_tag_gene );
3152 aResultSO = aStudyBuilder->NewObject(theFatherHomard);
3153 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
3154 _orb->object_to_string(theObject) ) ;
3156 return aResultSO._retn();
3158 //=============================================================================
3159 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::Study_ptr theStudy,
3160 SALOMEDS::StudyBuilder_var aStudyBuilder,
3161 HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
3163 MESSAGE("PublishHypotheseInStudy pour "<<theName);
3164 SALOMEDS::SObject_var aResultSO;
3166 // On recupere le module pere dans l etude
3167 // On ajoute la categorie des hypotheses dans l etude si necessaire
3168 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3169 if (theFatherHomard->_is_nil())
3171 MESSAGE("theFatherHomard->_is_nil()");
3172 return aResultSO._retn();
3175 // On ajoute la categorie des hypotheses dans l etude si necessaire
3176 SALOMEDS::SObject_var aSObject;
3177 if ( _tag_hypo == 0 )
3180 _tag_hypo = _tag_gene ;
3182 MESSAGE("PublishHypotheseInStudy _tag_gene = "<<_tag_gene << ", _tag_hypo = "<<_tag_hypo );
3183 if (!theFatherHomard->FindSubObject(_tag_hypo, aSObject))
3185 MESSAGE("Ajout de la categorie des hypotheses");
3186 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_hypo);
3187 PublishInStudyAttr(aStudyBuilder, aSObject, "Hypothesis", "HypoList", "hypotheses.png", NULL);
3189 else { MESSAGE("La categorie des hypotheses existe deja."); }
3191 // Creation du resultat dans l'etude
3192 aResultSO = aStudyBuilder->NewObject(aSObject);
3193 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
3195 return aResultSO._retn();
3197 //=============================================================================
3198 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishYACSInStudy(SALOMEDS::Study_ptr theStudy,
3199 SALOMEDS::StudyBuilder_var aStudyBuilder,
3200 HOMARD::HOMARD_YACS_ptr theObject, const char* theName)
3202 MESSAGE("PublishYACSInStudy pour "<<theName);
3203 SALOMEDS::SObject_var aResultSO;
3205 // On recupere le module pere dans l etude
3206 // On ajoute la categorie des schemas YACS dans l etude si necessaire
3207 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3208 if (theFatherHomard->_is_nil())
3210 MESSAGE("theFatherHomard->_is_nil()");
3211 return aResultSO._retn();
3213 // On ajoute la categorie des schemas YACS dans l etude si necessaire
3214 if ( _tag_yacs == 0 )
3217 _tag_yacs = _tag_gene ;
3219 MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_yacs = "<<_tag_yacs );
3220 SALOMEDS::SObject_var aSObject;
3221 if (!theFatherHomard->FindSubObject(_tag_yacs, aSObject))
3223 MESSAGE("Ajout de la categorie des schemas YACS");
3224 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_yacs);
3225 PublishInStudyAttr(aStudyBuilder, aSObject, "YACS", "YACSList", "full_view.png", NULL);
3227 else { MESSAGE("La categorie des schemas YACS existe deja."); }
3229 // Creation du resultat dans l'etude
3230 aResultSO = aStudyBuilder->NewObject(aSObject);
3231 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "YACSHomard", "schema.png", _orb->object_to_string(theObject) ) ;
3233 return aResultSO._retn();
3236 //=============================================================================
3237 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::Study_ptr theStudy,
3238 SALOMEDS::StudyBuilder_var aStudyBuilder,
3239 HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
3241 MESSAGE("PublishZoneStudy pour "<<theName);
3242 SALOMEDS::SObject_var aResultSO;
3243 if (CORBA::is_nil(theObject))
3245 MESSAGE("PublishZoneInStudy : theObject->_is_nil()");
3246 return aResultSO._retn();
3248 if (theStudy->_is_nil())
3250 MESSAGE("PublishZoneInStudy : theStudy->_is_nil()");
3251 return aResultSO._retn();
3253 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3254 if (theFatherHomard->_is_nil())
3256 MESSAGE("PublishZoneInStudy : theFatherHomard->_is_nil()");
3257 return aResultSO._retn();
3260 // Caracteristique de la zone
3261 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[theName];
3262 CORBA::Long ZoneType = myZone->GetType();
3264 // On ajoute la categorie des zones dans l etude si necessaire
3265 if ( _tag_zone == 0 )
3268 _tag_zone = _tag_gene ;
3270 MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_zone = "<<_tag_zone );
3271 SALOMEDS::SObject_var aSObject;
3272 if (!theFatherHomard->FindSubObject(_tag_zone, aSObject))
3274 MESSAGE("Ajout de la categorie des zones");
3275 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_zone);
3276 PublishInStudyAttr(aStudyBuilder, aSObject, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
3278 else { MESSAGE("La categorie des zones existe deja."); }
3280 aResultSO = aStudyBuilder->NewObject(aSObject);
3289 { icone = "boxdxy_2.png" ;
3293 { icone = "boxdxyz_2.png" ;
3301 { icone = "disk_2.png" ;
3305 { icone = "spherepoint_2.png" ;
3309 { icone = "cylinderpointvector_2.png" ;
3317 { icone = "diskwithhole_2.png" ;
3321 { icone = "pipe_2.png" ;
3325 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone.c_str(), _orb->object_to_string(theObject) ) ;
3327 return aResultSO._retn();
3329 //===========================================================================
3330 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
3331 SALOMEDS::SObject_var aResultSO,
3332 const char* name, const char* comment, const char* icone, const char* ior)
3334 MESSAGE("PublishInStudyAttr pour name = "<<name<<", comment = "<<comment);
3335 // MESSAGE("icone = "<<icone);
3336 // MESSAGE("ior = "<<ior);
3337 SALOMEDS::GenericAttribute_var anAttr ;
3341 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
3342 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
3343 aNameAttrib->SetValue(name);
3346 // Ajout du commentaire
3347 if ( comment != NULL )
3349 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
3350 SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
3351 aCommentAttrib->SetValue(comment);
3355 if ( icone != NULL )
3357 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
3358 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
3359 aPixmap->SetPixMap(icone);
3365 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
3366 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3367 anIOR->SetValue(ior);
3371 //=====================================================================================
3372 void HOMARD_Gen_i::PublishBoundaryUnderCase(const char* CaseName, const char* BoundaryName)
3374 MESSAGE ( "PublishBoundaryUnderCase : CaseName = " << CaseName << ", BoundaryName= " << BoundaryName );
3376 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3377 ASSERT(!CORBA::is_nil(myCase));
3378 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3379 ASSERT(!CORBA::is_nil(aCaseSO));
3381 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3382 ASSERT(!CORBA::is_nil(myBoundary));
3383 SALOMEDS::SObject_var aBoundarySO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myBoundary)));
3384 ASSERT(!CORBA::is_nil(aBoundarySO));
3386 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3388 aStudyBuilder->NewCommand();
3390 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aCaseSO);
3391 aStudyBuilder->Addreference(aSubSO, aBoundarySO);
3393 aStudyBuilder->CommitCommand();
3396 //=====================================================================================
3397 void HOMARD_Gen_i::PublishCaseUnderYACS(const char* nomYACS, const char* CaseName)
3399 MESSAGE ( "PublishCaseUnderYACS : nomYACS = " << nomYACS << ", CaseName= " << CaseName );
3401 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3402 ASSERT(!CORBA::is_nil(myYACS));
3403 SALOMEDS::SObject_var aYACSSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3404 ASSERT(!CORBA::is_nil(aYACSSO));
3406 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3407 ASSERT(!CORBA::is_nil(myCase));
3408 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3409 ASSERT(!CORBA::is_nil(aCaseSO));
3411 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3413 aStudyBuilder->NewCommand();
3415 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3416 aStudyBuilder->Addreference(aSubSO, aCaseSO);
3418 aStudyBuilder->CommitCommand();
3421 //=============================================================================
3422 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long Option)
3423 // Option = 0 : fichier issu d'une importation
3424 // Option = 1 : fichier issu d'une execution HOMARD
3426 MESSAGE( "PublishResultInSmesh " << NomFich << ", avec Option = " << Option);
3427 if (CORBA::is_nil(myCurrentStudy))
3429 SALOME::ExceptionStruct es;
3430 es.type = SALOME::BAD_PARAM;
3431 es.text = "Invalid study context";
3432 throw SALOME::SALOME_Exception(es);
3436 // Le module SMESH est-il actif ?
3437 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3439 if (!CORBA::is_nil(aSmeshSO))
3441 // On verifie que le fichier n est pas deja publie
3442 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3443 for (; aIter->More(); aIter->Next())
3445 SALOMEDS::SObject_var aSO = aIter->Value();
3446 SALOMEDS::GenericAttribute_var aGAttr;
3447 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3449 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3450 CORBA::String_var value=anAttr->Value();
3451 if (strcmp((const char*)value,NomFich) == 0)
3453 MESSAGE ( "PublishResultInSmesh : le fichier " << NomFich << " est deja publie." );
3454 // Pour un fichier importe, on ne republie pas
3459 // Pour un fichier calcule, on commence par faire la depublication
3462 MESSAGE ( "PublishResultInSmesh : depublication" );
3463 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3464 CORBA::String_var value2=anAttr2->Value();
3465 std::string MeshName = string(value2) ;
3466 MESSAGE ( "PublishResultInSmesh : depublication de " << MeshName );
3467 DeleteResultInSmesh(NomFich, MeshName) ;
3474 // On enregistre le fichier
3475 MESSAGE( "Enregistrement du fichier");
3476 SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
3477 SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
3478 ASSERT(!CORBA::is_nil(aSmeshEngine));
3479 aSmeshEngine->SetCurrentStudy(myCurrentStudy);
3480 SMESH::DriverMED_ReadStatus theStatus;
3481 //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3483 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
3484 SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3485 for (int i = 0; i < mesMaillages->length(); i++)
3487 MESSAGE( ". Mise a jour des attributs du maillage");
3488 SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
3489 SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
3490 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3491 SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
3492 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3493 anAttr->SetValue(NomFich);
3494 SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
3495 SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
3497 if ( Option == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
3498 else { icone = "mesh_tree_mesh.png" ; }
3499 anAttr2->SetPixMap( icone );
3503 //=============================================================================
3504 void HOMARD_Gen_i::DeleteResultInSmesh(std::string NomFich, std::string MeshName)
3506 MESSAGE ("DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich );
3507 if (CORBA::is_nil(myCurrentStudy))
3509 SALOME::ExceptionStruct es;
3510 es.type = SALOME::BAD_PARAM;
3511 es.text = "Invalid study context";
3512 throw SALOME::SALOME_Exception(es);
3516 // Le module SMESH est-il actif ?
3517 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3519 if (CORBA::is_nil(aSmeshSO))
3523 // On verifie que le fichier est deja publie
3524 SALOMEDS::StudyBuilder_var myBuilder = myCurrentStudy->NewBuilder();
3525 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3526 for (; aIter->More(); aIter->Next())
3528 SALOMEDS::SObject_var aSO = aIter->Value();
3529 SALOMEDS::GenericAttribute_var aGAttr;
3530 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3532 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3533 CORBA::String_var value=anAttr->Value();
3534 if (strcmp((const char*)value,NomFich.c_str()) == 0)
3536 if (aSO->FindAttribute(aGAttr,"AttributeName"))
3538 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3539 CORBA::String_var value2=anAttr2->Value();
3540 if (strcmp((const char*)value2,MeshName.c_str()) == 0)
3542 myBuilder->RemoveObjectWithChildren( aSO ) ;
3550 //=============================================================================
3551 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
3553 // MESSAGE ("PublishFileUnderIteration pour l'iteration " << NomIter << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3554 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
3556 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
3557 if (CORBA::is_nil(myIteration))
3559 SALOME::ExceptionStruct es;
3560 es.type = SALOME::BAD_PARAM;
3561 es.text = "Invalid iterationStudy Object";
3562 throw SALOME::SALOME_Exception(es);
3566 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3568 aStudyBuilder->NewCommand();
3570 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
3571 // Pour les fichiers med, on affiche une icone de maillage
3572 // Pour les fichiers qui sont du texte, on affiche une icone de fichier texte 'texte'
3573 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
3575 std::string ior = " " ;
3576 if ( Commentaire[0] == 'I' )
3577 { icone = "med.png" ; }
3579 { icone = "texte_2.png" ; }
3580 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3582 aStudyBuilder->CommitCommand();
3585 //=============================================================================
3586 void HOMARD_Gen_i::PublishFileUnderYACS(const char* nomYACS, const char* NomFich, const char* Commentaire)
3588 // MESSAGE ("PublishFileUnderYACS pour le schema " << nomYACS << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3589 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3591 SALOMEDS::SObject_var aYACSSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3592 if (CORBA::is_nil(myYACS))
3594 SALOME::ExceptionStruct es;
3595 es.type = SALOME::BAD_PARAM;
3596 es.text = "Invalid YACSStudy Object";
3597 throw SALOME::SALOME_Exception(es);
3601 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3603 aStudyBuilder->NewCommand();
3605 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3606 std::string icone = "texte_2.png" ;
3607 std::string ior = " " ;
3608 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3610 aStudyBuilder->CommitCommand();
3613 //=============================================================================
3614 //=============================================================================
3616 //=============================================================================
3617 //=============================================================================
3618 //=============================================================================
3619 // Creation d'un schema YACS
3620 // nomCas : nom du cas a traiter
3621 // FileName : nom du fichier contenant le script de lancement du calcul
3622 // DirName : le repertoire de lancement des calculs du schéma
3623 //=============================================================================
3624 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::CreateYACSSchema (const char* nomYACS, const char* nomCas, const char* ScriptFile, const char* DirName, const char* MeshFile)
3626 INFOS ( "CreateYACSSchema : Schema YACS " << nomYACS );
3627 INFOS ( ". nomCas : " << nomCas);
3628 INFOS ( ". ScriptFile : " << ScriptFile);
3629 INFOS ( ". DirName : " << DirName);
3630 INFOS ( ". MeshFile : " << MeshFile);
3632 // A. Controle du nom :
3633 if ((myContextMap[GetCurrentStudyID()]._mesYACSs).find(nomYACS) != (myContextMap[GetCurrentStudyID()]._mesYACSs).end())
3635 SALOME::ExceptionStruct es;
3636 es.type = SALOME::BAD_PARAM;
3637 es.text = "This schema YACS has already been defined.";
3638 throw SALOME::SALOME_Exception(es);
3642 // B. Creation de l'objet
3643 HOMARD::HOMARD_YACS_var myYACS = newYACS();
3644 if (CORBA::is_nil(myYACS))
3646 SALOME::ExceptionStruct es;
3647 es.type = SALOME::BAD_PARAM;
3648 es.text = "Unable to create the schema YACS";
3649 throw SALOME::SALOME_Exception(es);
3652 myYACS->SetName( nomYACS ) ;
3654 // C. Enregistrement
3655 myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS] = myYACS;
3657 SALOMEDS::SObject_var aSO;
3658 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myYACS, nomYACS);
3660 PublishCaseUnderYACS(nomYACS, nomCas);
3662 // D. Caracterisation
3664 myYACS->SetDirName( DirName ) ;
3665 myYACS->SetMeshFile( MeshFile ) ;
3666 myYACS->SetScriptFile( ScriptFile ) ;
3667 myYACS->SetCaseName( nomCas ) ;
3669 // D.2.1. Type constant
3670 myYACS->SetType( 1 ) ;
3671 // D.2.2. Fichier de sauvegarde dans le repertoire du cas
3672 HOMARD::HOMARD_Cas_ptr caseyacs = GetCase(nomCas) ;
3673 std::string dirnamecase = caseyacs->GetDirName() ;
3674 std::string XMLFile ;
3675 XMLFile = dirnamecase + "/schema.xml" ;
3676 myYACS->SetXMLFile( XMLFile.c_str() ) ;
3678 return HOMARD::HOMARD_YACS::_duplicate(myYACS);
3680 //=============================================================================
3681 // Ecriture d'un schema YACS
3682 //=============================================================================
3683 CORBA::Long HOMARD_Gen_i::YACSWrite(const char* nomYACS)
3685 INFOS ( "YACSWrite : Ecriture de " << nomYACS );
3686 // Le repertoire du cas
3687 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3688 ASSERT(!CORBA::is_nil(myYACS));
3689 // Le nom du fichier du schema
3690 std::string XMLFile ;
3691 XMLFile = myYACS->GetXMLFile() ;
3693 int codret = YACSWriteOnFile(nomYACS, XMLFile.c_str()) ;
3697 //=============================================================================
3698 // Ecriture d'un schema YACS sur un fichier donne
3699 //=============================================================================
3700 CORBA::Long HOMARD_Gen_i::YACSWriteOnFile(const char* nomYACS, const char* XMLFile)
3702 INFOS ( "YACSWriteOnFile : Ecriture de " << nomYACS << " sur " << XMLFile );
3709 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3710 ASSERT(!CORBA::is_nil(myYACS));
3711 // B.2. Les caracteristiques
3712 std::string DirName = myYACS->GetDirName() ;
3713 std::string MeshFile = myYACS->GetMeshFile() ;
3714 std::string ScriptFile = myYACS->GetScriptFile() ;
3718 const char* nomCas = myYACS->GetCaseName();
3719 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
3720 ASSERT(!CORBA::is_nil(myCase));
3721 // C.2. Les instructions python associees au cas
3722 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
3723 std::string pythonCas = dumpCorbaCase.in();
3724 MESSAGE ("pythonCas :\n"<<pythonCas<<"\n");
3726 // D. Les iterations
3727 // D.1. L'iteration initiale
3728 HOMARD::HOMARD_Iteration_var Iter0 = myCase->GetIter0() ;
3729 std::string Iter0Name = myCase->GetIter0Name() ;
3730 MESSAGE (". Iter0Name = " << Iter0Name);
3731 std::string MeshName = Iter0->GetMeshName();
3732 MESSAGE (". MeshName = " << MeshName);
3733 // D.2. L'iteration numero 1
3734 HOMARD::listeIterFilles* maListe = Iter0->GetIterations();
3735 int numberOfIter = maListe->length();
3736 if ( numberOfIter > 1 )
3738 MESSAGE (". numberOfIter = " << numberOfIter);
3739 SALOME::ExceptionStruct es ;
3740 es.type = SALOME::BAD_PARAM;
3741 std::string text = "Une seule iteration est permise." ;
3742 es.text = CORBA::string_dup(text.c_str());
3743 throw SALOME::SALOME_Exception(es);
3746 std::string Iter1Name = std::string((*maListe)[0]);
3747 MESSAGE ("... Iter1Name = " << Iter1Name);
3748 HOMARD::HOMARD_Iteration_var Iter1 = GetIteration(Iter1Name.c_str()) ;
3750 // E. L'hypothese pour passer de l'iteration initiale a la suivante
3751 // E.1. La structure
3752 std::string nomHypo = Iter1->GetHypoName();
3753 MESSAGE (". nomHypo = " << nomHypo);
3754 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
3755 ASSERT(!CORBA::is_nil(myHypo));
3756 // E.2. Les caracteristiques de l'adaptation
3757 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
3758 ASSERT(ListTypes->length() == 3);
3759 int TypeAdap = (*ListTypes)[0];
3760 // int TypeRaff = (*ListTypes)[1];
3761 // int TypeDera = (*ListTypes)[2];
3762 // E.3. Les instructions python associees a l'hypothese
3763 CORBA::String_var dumpCorbaHypo = myHypo->GetDumpPython();
3764 std::string pythonHypo = dumpCorbaHypo.in();
3765 MESSAGE ("pythonHypo :\n"<<pythonHypo<<"\n");
3767 // F. Le fichier du schema de reference
3768 // HOMARD_ROOT_DIR : repertoire ou se trouve le module HOMARD
3769 std::string XMLFile_base ;
3770 if ( getenv("HOMARD_ROOT_DIR") != NULL ) { XMLFile_base = getenv("HOMARD_ROOT_DIR") ; }
3773 SALOME::ExceptionStruct es ;
3774 es.type = SALOME::BAD_PARAM;
3775 std::string text = "HOMARD_ROOT_DIR est inconnu." ;
3776 es.text = CORBA::string_dup(text.c_str());
3777 throw SALOME::SALOME_Exception(es);
3780 XMLFile_base += "/share/salome/resources/homard/yacs_01." + _LangueShort + ".xml" ;
3782 MESSAGE("XMLFile_base ="<<XMLFile_base);
3784 // G. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
3785 YACSDriver* myDriver = new YACSDriver(XMLFile, DirName);
3786 std::ifstream fichier( XMLFile_base.c_str() );
3787 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
3789 // G.1. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
3790 std::string ligne; // variable contenant chaque ligne lue
3791 std::string mot_cle;
3792 while ( std::getline( fichier, ligne ) )
3794 // G.1.1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
3795 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
3796 ligne_bis >> mot_cle ;
3797 // G.1.2. Le maillage initial
3798 if ( mot_cle == "DataInit_MeshFile" )
3799 { myDriver->Texte_DataInit_MeshFile(MeshFile); }
3800 // G.1.3. Le script de lancement
3801 else if ( mot_cle == "Alternance_Calcul_HOMARD_Calcul" )
3802 { myDriver->Texte_Alternance_Calcul_HOMARD_Calcul(ScriptFile); }
3803 // G.1.4. Les options du cas
3804 else if ( mot_cle == "Iter_1_Case_Options" )
3805 { myDriver->Texte_Iter_1_Case_Options(pythonCas); }
3806 // G.1.5. Execution de HOMARD : le repertoire du cas
3807 else if ( mot_cle == "HOMARD_Exec_DirName" )
3808 { myDriver->Texte_HOMARD_Exec_DirName(); }
3809 // G.1.6. Execution de HOMARD : le nom du maillage
3810 else if ( mot_cle == "HOMARD_Exec_MeshName" )
3812 myDriver->Texte_HOMARD_Exec_MeshName(MeshName);
3813 std::string node = "Boucle_de_convergence.Alternance_Calcul_HOMARD.Adaptation.p0_Adaptation_HOMARD.HOMARD_Initialisation.p1_Iter_1.CreateCase" ;
3814 myDriver->TexteParametre( node, "MeshName", "string", MeshName ) ;
3816 // G.1.7. Execution de HOMARD : les options de l'hypothese
3817 else if ( mot_cle == "HOMARD_Exec_Hypo_Options" )
3818 { myDriver->Texte_python( pythonHypo, 3, "Hypo" ) ; }
3819 // G.1.8. Zones et frontieres : les creations
3820 else if ( mot_cle == "Iter_1" )
3822 std::string texte_control = myDriver->Texte_Iter_1_control() ;
3823 if ( TypeAdap == 0 ) { texte_control += YACSDriverTexteZone( myHypo, myDriver ) ; }
3824 texte_control += YACSDriverTexteBoundary( myCase, myDriver ) ;
3825 myDriver->TexteAdd(texte_control);
3827 // G.1.9. Les parametres
3828 else if ( mot_cle == "PARAMETRES" )
3829 { myDriver->TexteAddParametres(); }
3830 // G.1.n. La ligne est recopiee telle quelle
3831 else { myDriver->TexteAdd(ligne); }
3833 // G.2. Ecriture du texte dans le fichier
3835 { myDriver->CreeFichier(); }
3839 SALOME::ExceptionStruct es;
3840 es.type = SALOME::BAD_PARAM;
3841 std::string text = "The reference file for the YACS schema cannot be read." ;
3842 es.text = CORBA::string_dup(text.c_str());
3843 throw SALOME::SALOME_Exception(es);
3848 // H. Publication du fichier dans l'arbre
3850 std::string Commentaire = "xml" ;
3851 PublishFileUnderYACS(nomYACS, XMLFile, Commentaire.c_str());
3855 //=============================================================================
3856 // Ecriture d'un schema YACS : ecriture des zones associees a une hypothese
3857 //=============================================================================
3858 std::string HOMARD_Gen_i::YACSDriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, YACSDriver* myDriver)
3860 MESSAGE ( "YACSDriverTexteZone" );
3861 // A. Les zones associees a cette hypothese
3862 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
3863 int numberOfZonesx2 = ListZone->length();
3865 // B. Parcours des zones
3866 std::string texte_control ;
3867 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
3869 // 1. Reperage de la zone
3870 std::string ZoneName = std::string((*ListZone)[iaux]);
3871 MESSAGE ( "\n. ZoneName = " << ZoneName << " - " <<iaux);
3872 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
3873 ASSERT(!CORBA::is_nil(myZone));
3874 // 2. Les instructions python associees a la zone
3875 // La premiere ligne est un commentaire a eliminer
3876 // La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
3877 CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
3878 std::string pythonStructure_0 = dumpCorbaZone.in();
3879 MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
3880 std::istringstream tout (pythonStructure_0) ;
3882 std::string pythonStructure ;
3883 while ( std::getline( tout, ligne ) )
3884 { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
3885 MESSAGE ("pythonStructure :\n"<<pythonStructure);
3886 // 3. Decodage du nom du service
3887 std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
3888 MESSAGE ( "... methode = " << methode);
3889 // 4. Mise en place des instructions
3890 int ZoneType = myZone->GetType();
3891 MESSAGE ( "... ZoneType = " << ZoneType);
3892 std::string texte_control_0 ;
3893 texte_control_0 = myDriver->Texte_Iter_1_Zone(ZoneType, pythonStructure, methode, ZoneName );
3894 texte_control += texte_control_0 ;
3899 return texte_control ;
3901 //=============================================================================
3902 // Ecriture d'un schema YACS : ecriture des frontieres associees au cas
3903 //=============================================================================
3904 std::string HOMARD_Gen_i::YACSDriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, YACSDriver* myDriver)
3906 MESSAGE ( "YACSDriverTexteBoundary" );
3907 // A. Les frontieres associees au cas
3908 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
3909 int numberOfitems = ListBoundaryGroupType->length();
3911 // B. Parcours des frontieres
3912 std::string texte_control ;
3913 std::list<std::string> ListeBoundaryTraitees ;
3914 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3916 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3917 MESSAGE ( "... BoundaryName = " << BoundaryName);
3918 // Attention a n'ecrire la definition qu'une seule fois car elle peut se trouver
3919 // plusieurs fois dans la definition du cas, d'ou la liste ListeBoundaryTraitees
3921 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
3922 while (it != ListeBoundaryTraitees.end())
3924 MESSAGE ( "..... BoundaryNameTraitee = " << *it);
3925 if ( BoundaryName == *it ) { A_faire = 0 ; }
3930 // 1. Caracteristiques de la frontiere
3931 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3932 ASSERT(!CORBA::is_nil(myBoundary));
3933 // 2. Les instructions python associees a la frontiere
3934 // La premiere ligne est un commentaire a eliminer
3935 // La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
3936 CORBA::String_var dumpCorbaBoundary = myBoundary->GetDumpPython();
3937 std::string pythonStructure_0 = dumpCorbaBoundary.in();
3938 MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
3939 std::istringstream tout (pythonStructure_0) ;
3941 std::string pythonStructure ;
3942 while ( std::getline( tout, ligne ) )
3943 { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
3944 MESSAGE ("pythonStructure :\n"<<pythonStructure);
3945 // 3. Decodage du nom du service
3946 std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
3947 MESSAGE ( "... methode = " << methode);
3948 // 4. Mise en place des instructions
3949 int BoundaryType = myBoundary->GetType();
3950 MESSAGE ( "... BoundaryType = " << BoundaryType);
3951 std::string texte_control_0 ;
3952 texte_control_0 = myDriver->Texte_Iter_1_Boundary(BoundaryType, pythonStructure, methode, BoundaryName );
3953 texte_control += texte_control_0 ;
3954 // 5. Memorisation du traitement
3955 ListeBoundaryTraitees.push_back( BoundaryName );
3959 return texte_control ;
3962 //=============================================================================
3963 //=============================================================================
3964 // Next functions are inherited from SALOMEDS::Driver interface
3965 //=============================================================================
3966 //=============================================================================
3967 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
3969 CORBA::Boolean isMultiFile)
3971 MESSAGE ("Save for theURL = "<< theURL);
3972 SALOMEDS::TMPFile_var aStreamFile;
3974 // get temporary directory name
3975 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
3977 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
3978 StudyContext& context = myContextMap[ aStudy->StudyId() ];
3980 // HOMARD data file name
3981 std::string aFileName = "";
3983 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
3984 aFileName += "_HOMARD.dat";
3986 // initialize sequence of file names
3987 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
3988 aFileSeq->length(1);
3989 aFileSeq[0] = CORBA::string_dup(aFileName.c_str()) ;
3991 // get full path to the data file
3992 aFileName = tmpDir + aFileName;
3996 std::ofstream f(aFileName.c_str());
3998 // clear temporary id map
3999 context._idmap.clear();
4004 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
4005 for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
4006 HOMARD::HOMARD_Cas_var aCas = it_case->second;
4007 PortableServer::ServantBase_var aServant = GetServant(aCas);
4008 HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4010 f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
4011 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
4015 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4016 for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
4017 HOMARD::HOMARD_Zone_var aZone = it_zone->second;
4018 PortableServer::ServantBase_var aServant = GetServant(aZone);
4019 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4021 f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
4022 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4025 // -> save hypotheses
4026 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4027 for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
4028 HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
4029 PortableServer::ServantBase_var aServant = GetServant(aHypo);
4030 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4032 f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
4033 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4036 // -> save iterations
4037 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4038 for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
4039 HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
4040 PortableServer::ServantBase_var aServant = GetServant(aIter);
4041 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4043 f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
4044 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4047 // -> save boundaries
4048 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4049 for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
4050 HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
4051 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4052 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4053 if (aBoundaryServant) {
4054 f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
4055 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4059 MESSAGE ("close file");
4062 // put temporary files to the stream
4063 MESSAGE ("put temporary files to the stream");
4064 aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq.in(), isMultiFile);
4066 // remove temporary files
4067 MESSAGE ("remove temporary files");
4068 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4070 // return data stream
4071 MESSAGE ("return data stream");
4072 return aStreamFile._retn();
4075 //===========================================================================
4076 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
4078 CORBA::Boolean isMultiFile)
4080 // No specific ASCII persistence
4081 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
4082 return aStreamFile._retn();
4085 //===========================================================================
4086 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
4087 const SALOMEDS::TMPFile& theStream,
4089 CORBA::Boolean isMultiFile)
4091 MESSAGE ("Load pour theURL = "<< theURL);
4092 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
4094 // set current study
4095 if (myCurrentStudy->_is_nil() || aStudy->StudyId() != myCurrentStudy->StudyId())
4096 SetCurrentStudy(aStudy);
4098 // get temporary directory name
4099 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4101 // Convert the stream into sequence of files to process
4102 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
4105 // HOMARD data file name
4106 std::string aFileName = "";
4108 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
4109 aFileName = tmpDir + aFileName + "_HOMARD.dat";
4111 StudyContext& context = myContextMap[ aStudy->StudyId() ];
4115 std::ifstream f(aFileName.c_str());
4118 context._mesCas.clear();
4119 context._mesHypotheses.clear();
4120 context._mesIterations.clear();
4121 context._mesZones.clear();
4122 context._mesBoundarys.clear();
4123 context._idmap.clear();
4129 std::getline(f, line);
4130 std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
4131 std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
4132 std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
4133 std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
4134 std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
4135 std::string yacsSignature = HOMARD::GetSignature(HOMARD::YACS);
4136 if (line.substr(0, bounSignature.size()) == bounSignature) {
4137 // re-create boundary
4138 MESSAGE ("Recreation de la frontiere" );
4139 HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
4140 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4141 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4142 if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
4143 context._mesBoundarys[aBoundary->GetName()] = aBoundary;
4144 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4147 else if (line.substr(0, caseSignature.size()) == caseSignature) {
4149 MESSAGE ("Recreation du cas" );
4150 HOMARD::HOMARD_Cas_var aCase = newCase();
4151 PortableServer::ServantBase_var aServant = GetServant(aCase);
4152 HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4153 if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
4154 context._mesCas[aCase->GetName()] = aCase;
4155 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
4158 else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
4159 // re-create hypothesis
4160 MESSAGE ("Recreation de l hypothese" );
4161 HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
4162 PortableServer::ServantBase_var aServant = GetServant(aHypo);
4163 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4164 if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
4165 context._mesHypotheses[aHypo->GetName()] = aHypo;
4166 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4169 else if (line.substr(0, iterSignature.size()) == iterSignature) {
4170 // re-create iteration
4171 MESSAGE ("Recreation de l iteration" );
4172 HOMARD::HOMARD_Iteration_var aIter = newIteration();
4173 PortableServer::ServantBase_var aServant = GetServant(aIter);
4174 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4175 if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
4176 context._mesIterations[aIter->GetName()] = aIter;
4177 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4180 else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
4181 MESSAGE ("Recreation de la zone" );
4183 HOMARD::HOMARD_Zone_var aZone = newZone();
4184 PortableServer::ServantBase_var aServant = GetServant(aZone);
4185 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4186 if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
4187 context._mesZones[aZone->GetName()] = aZone;
4188 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4191 else if (line.substr(0, zoneSignature.size()) == yacsSignature) {
4192 MESSAGE ("Recreation du schema YACS" );
4194 HOMARD::HOMARD_YACS_var aYACS = newYACS();
4195 PortableServer::ServantBase_var aServant = GetServant(aYACS);
4196 HOMARD_YACS_i* aYACSServant = dynamic_cast<HOMARD_YACS_i*>(aServant.in());
4197 if (aYACSServant && aYACSServant->Restore(line.substr(yacsSignature.size()))) {
4198 context._mesYACSs[aYACS->GetName()] = aYACS;
4199 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aYACSServant);
4208 // Remove temporary files created from the stream
4210 SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4215 //===========================================================================
4216 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
4217 const SALOMEDS::TMPFile& theStream,
4219 CORBA::Boolean isMultiFile)
4221 // No specific ASCII persistence
4222 return Load(theComponent, theStream, theURL, isMultiFile);
4225 //===========================================================================
4226 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
4228 if (theComponent->GetStudy()->StudyId() == GetCurrentStudyID()) {
4229 // clearing study context should be done here:
4230 // - destroy all servants and related CORBA objects
4232 // - remove context from myContextMap
4233 myContextMap.erase(theComponent->GetStudy()->StudyId());
4234 // - nullify myCurrentStudy
4235 myCurrentStudy = SALOMEDS::Study::_nil();
4239 //===========================================================================
4240 char* HOMARD_Gen_i::ComponentDataType()
4242 return CORBA::string_dup("HOMARD");
4245 //===========================================================================
4246 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
4247 const char* IORString,
4248 CORBA::Boolean isMultiFile,
4249 CORBA::Boolean isASCII)
4251 CORBA::String_var aString("");
4252 if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
4253 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4254 CORBA::Object_var anObj = _orb->string_to_object(IORString);
4255 if (!CORBA::is_nil(anObj)) {
4256 PortableServer::ServantBase_var aServant = GetServant(anObj);
4257 PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
4259 std::map<int, PortableServer::ServantBase*>::const_iterator it;
4260 for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
4261 if (it->second == aStorable) {
4262 std::stringstream os;
4264 aString = CORBA::string_dup(os.str().c_str());
4270 return aString._retn();
4273 //===========================================================================
4274 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
4275 const char* aLocalPersistentID,
4276 CORBA::Boolean isMultiFile,
4277 CORBA::Boolean isASCII)
4279 CORBA::String_var aString("");
4280 if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
4281 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4282 int id = atoi(aLocalPersistentID);
4283 if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
4284 CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
4285 if (!CORBA::is_nil(object)) {
4286 aString = _orb->object_to_string(object);
4290 return aString._retn();
4293 //===========================================================================
4294 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
4296 if(CORBA::is_nil(myCurrentStudy))
4299 HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
4300 if(!aCas->_is_nil())
4303 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
4304 if(!aHypo->_is_nil())
4307 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
4308 if(!aZone->_is_nil())
4311 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
4312 if(!aBoundary->_is_nil())
4315 /* Iteration is not published directly
4316 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
4317 if(!aIter->_is_nil())
4323 //===========================================================================
4324 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
4326 // No Copy/Paste support
4330 //===========================================================================
4331 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
4332 CORBA::Long& theObjectID)
4334 // No Copy/Paste support
4335 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
4336 return aStreamFile._retn();
4339 //===========================================================================
4340 CORBA::Boolean HOMARD_Gen_i::CanPaste(const char *theComponentName,
4341 CORBA::Long theObjectID)
4343 // No Copy/Paste support
4347 //===========================================================================
4348 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
4349 CORBA::Long theObjectID,
4350 SALOMEDS::SObject_ptr theSObject)
4352 // No Copy/Paste support
4353 SALOMEDS::SObject_var aResultSO;
4354 return aResultSO._retn();
4357 //===========================================================================
4358 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
4360 PortableServer::Servant aServant = 0;
4361 if (!CORBA::is_nil(theObject)) {
4363 aServant = _poa->reference_to_servant(theObject);
4371 //==========================================================================
4372 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
4373 CORBA::Boolean isPublished,
4374 CORBA::Boolean isMultiFile,
4375 CORBA::Boolean& isValidScript)
4377 MESSAGE ("Entree dans DumpPython");
4379 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
4380 if(CORBA::is_nil(aStudy))
4381 return new Engines::TMPFile(0);
4383 SALOMEDS::SObject_var aSO = aStudy->FindComponent("HOMARD");
4384 if(CORBA::is_nil(aSO))
4385 return new Engines::TMPFile(0);
4387 std::string aScript = "\"\"\"\n";
4388 aScript += "Python script for HOMARD\n";
4389 aScript += "Copyright EDF-R&D 2013\n";
4390 aScript += "\"\"\"\n";
4391 aScript += "__revision__ = \"V1.2\"\n";
4392 aScript += "import HOMARD\n";
4394 aScript += "import salome\n";
4395 aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
4397 aScript += "def RebuildData(theStudy):\n";
4398 aScript += "\thomard.SetCurrentStudy(theStudy)\n";
4401 aScript += "\thomard.SetCurrentStudy(salome.myStudy)\n";
4402 MESSAGE (". Au depart \n"<<aScript);
4405 if (myContextMap[GetCurrentStudyID()]._mesBoundarys.size() > 0)
4407 MESSAGE (". Ecritures des frontieres");
4408 aScript += "#\n# Creation of the boundaries";
4409 aScript += "\n# ==========================";
4411 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4412 for (it_boundary = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
4413 it_boundary != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); ++it_boundary)
4415 HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
4416 CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
4417 std::string dumpBoundary = dumpCorbaBoundary.in();
4418 MESSAGE (dumpBoundary<<"\n");
4419 aScript += dumpBoundary;
4423 if (myContextMap[GetCurrentStudyID()]._mesZones.size() > 0)
4425 MESSAGE (". Ecritures des zones");
4426 aScript += "#\n# Creation of the zones";
4427 aScript += "\n# =====================";
4429 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4430 for ( it_zone = myContextMap[GetCurrentStudyID()]._mesZones.begin();
4431 it_zone != myContextMap[GetCurrentStudyID()]._mesZones.end(); ++it_zone)
4433 HOMARD::HOMARD_Zone_var myZone = (*it_zone).second;
4434 CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4435 std::string dumpZone = dumpCorbaZone.in();
4436 MESSAGE (dumpZone<<"\n");
4437 aScript += dumpZone;
4441 if (myContextMap[GetCurrentStudyID()]._mesHypotheses.size() > 0)
4443 MESSAGE (". Ecritures des hypotheses");
4444 aScript += "#\n# Creation of the hypotheses";
4445 aScript += "\n# ==========================";
4447 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4448 for ( it_hypo = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
4449 it_hypo != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it_hypo++)
4451 HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
4452 CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
4453 std::string dumpHypo = dumpCorbaHypo.in();
4454 MESSAGE (dumpHypo<<"\n");
4455 aScript += dumpHypo;
4459 if (myContextMap[GetCurrentStudyID()]._mesCas.size() > 0)
4461 MESSAGE (". Ecritures des cas");
4462 aScript += "#\n# Creation of the cases";
4463 aScript += "\n# =====================";
4465 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
4466 for (it_cas = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4467 it_cas != myContextMap[GetCurrentStudyID()]._mesCas.end(); it_cas++)
4469 std::string nomCas = (*it_cas).first;
4470 std::string dumpCas = std::string("\n# Creation of the case ") ;
4471 dumpCas += nomCas + std::string("\n");
4472 dumpCas += std::string("\t") + nomCas;
4473 dumpCas += std::string(" = homard.CreateCase(\"") + nomCas + std::string("\", \"");
4475 HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
4476 CORBA::String_var cIter0= myCase->GetIter0Name();
4477 std::string iter0 = cIter0.in();
4479 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[iter0];
4480 CORBA::String_var cMesh0= myIteration->GetMeshFile();
4481 std::string mesh0 = cMesh0.in();
4482 CORBA::String_var cMeshName0= myIteration->GetMeshName();
4483 std::string meshName0 = cMeshName0.in();
4484 dumpCas += meshName0 + std::string("\", \"")+ mesh0 + std::string("\")\n");
4485 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4486 std::string dumpCas2= dumpCorbaCase.in();
4488 MESSAGE (dumpCas<<dumpCas2<<"\n");
4489 aScript += dumpCas + dumpCas2;
4493 if (myContextMap[GetCurrentStudyID()]._mesIterations.size() > 0)
4495 MESSAGE (". Ecritures des iterations");
4496 aScript += "#\n# Creation of the iterations" ;
4497 aScript += "\n# ==========================";
4499 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4500 for (it_iter = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
4501 it_iter != myContextMap[GetCurrentStudyID()]._mesIterations.end(); ++it_iter)
4503 HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
4504 CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
4505 std::string dumpIter = dumpCorbaIter.in();
4506 MESSAGE (dumpIter<<"\n");
4507 aScript += dumpIter;
4511 if (myContextMap[GetCurrentStudyID()]._mesYACSs.size() > 0)
4513 MESSAGE (". Ecritures des schemas YACS");
4514 aScript += "#\n# Creation of the schemas YACS";
4515 aScript += "\n# ============================";
4517 std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it_yacs;
4518 for ( it_yacs = myContextMap[GetCurrentStudyID()]._mesYACSs.begin();
4519 it_yacs != myContextMap[GetCurrentStudyID()]._mesYACSs.end(); ++it_yacs)
4521 HOMARD::HOMARD_YACS_var myYACS = (*it_yacs).second;
4522 CORBA::String_var dumpCorbaYACS = myYACS->GetDumpPython();
4523 std::string dumpYACS = dumpCorbaYACS.in();
4524 MESSAGE (dumpYACS<<"\n");
4525 aScript += dumpYACS;
4528 MESSAGE (". Ecritures finales");
4530 aScript += "\n\tpass";
4533 if( !isMultiFile ) // remove unnecessary tabulation
4534 aScript = RemoveTabulation( aScript );
4536 // MESSAGE ("A ecrire \n"<<aScript);
4537 const size_t aLen = strlen(aScript.c_str());
4538 char* aBuffer = new char[aLen+1];
4539 strcpy(aBuffer, aScript.c_str());
4541 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
4542 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
4544 MESSAGE ("Sortie de DumpPython");
4545 return aStreamFile._retn();
4549 //=============================================================================
4550 //=============================================================================
4552 //=============================================================================
4553 //=============================================================================
4554 void HOMARD_Gen_i::IsValidStudy( )
4556 // MESSAGE( "IsValidStudy" );
4557 if (CORBA::is_nil(myCurrentStudy))
4559 SALOME::ExceptionStruct es;
4560 es.type = SALOME::BAD_PARAM;
4561 es.text = "Invalid study context";
4562 throw SALOME::SALOME_Exception(es);
4567 //=============================================================================
4568 CORBA::Boolean HOMARD_Gen_i::VerifieDir(const char* nomDir)
4570 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
4571 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4572 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
4574 if (std::string(nomDir) == std::string(it->second->GetDirName())) return false;
4578 /*//=============================================================================
4579 void SALOMEException( std::string message )
4581 SALOME::ExceptionStruct es;
4582 es.type = SALOME::BAD_PARAM;
4584 throw SALOME::SALOME_Exception(es);
4587 //=============================================================================
4588 char* HOMARD_Gen_i::getVersion()
4590 #if HOMARD_DEVELOPMENT
4591 return CORBA::string_dup(HOMARD_VERSION_STR"dev");
4593 return CORBA::string_dup(HOMARD_VERSION_STR);
4596 //===============================================================================
4597 // Recuperation de la chaine de caracteres par rapport a l'apparition d'un texte
4598 // ligne : la ligne a manipuler
4599 // texte : le texte a reperer
4600 // option : 0 : la chaine avant le texte
4601 // 1 : la chaine apres le texte
4602 // Si le texte est absent, on retourne la chaine totale
4603 //===============================================================================
4604 std::string HOMARD_Gen_i::GetStringInTexte( const std::string ligne, const std::string texte, int option )
4606 // MESSAGE("GetStringInTexte, recherche de '"<<texte<<"' dans '"<<ligne<<"'"<<", option = "<<option);
4608 std::string chaine = ligne ;
4609 int position = ligne.find_first_of( texte ) ;
4612 if ( option == 0 ) { chaine = ligne.substr( 0, position ) ; }
4613 else { chaine = ligne.substr( position+1 ) ; }
4618 // //===============================================================================
4619 // // Langue de SALOME
4620 // //===============================================================================
4621 void HOMARD_Gen_i::SetLanguageShort(const char* LanguageShort)
4623 MESSAGE ("SetLanguageShort pour LanguageShort = " << LanguageShort );
4624 _LangueShort = LanguageShort ;
4625 if ( _LangueShort == "fr" ) { _Langue = "Francais" ; }
4626 else { _Langue = "English" ; }
4629 char* HOMARD_Gen_i::GetLanguageShort()
4631 // MESSAGE ("GetLanguageShort");
4632 return CORBA::string_dup( _LangueShort.c_str() );
4635 //=============================================================================
4638 PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
4639 PortableServer::POA_ptr poa,
4640 PortableServer::ObjectId* contId,
4641 const char* instanceName,
4642 const char* interfaceName)
4644 MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
4645 HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
4646 return myHOMARD_Gen->getId();