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 // Pour detruire une iteration courante
459 MESSAGE ( "DeleteYACS : nomYACS = " << nomYACS << ", avec option = " << Option );
460 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
461 if (CORBA::is_nil(myYACS))
463 SALOME::ExceptionStruct es;
464 es.type = SALOME::BAD_PARAM;
465 es.text = "Invalid schema YACS";
466 throw SALOME::SALOME_Exception(es);
469 ASSERT("Programmer le menage du fichier"!=0);
470 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
471 myContextMap[GetCurrentStudyID()]._mesYACSs.erase(nomYACS);
472 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomYACS, ComponentDataType());
473 SALOMEDS::SObject_var aSO =listSO[0];
474 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
475 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
479 //=============================================================================
480 CORBA::Long HOMARD_Gen_i::DeleteZone(const char* nomZone)
482 MESSAGE ( "DeleteZone : nomZone = " << nomZone );
483 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[nomZone];
484 if (CORBA::is_nil(myZone))
486 SALOME::ExceptionStruct es;
487 es.type = SALOME::BAD_PARAM;
488 es.text = "Invalid zone";
489 throw SALOME::SALOME_Exception(es);
493 // On verifie que la zone n'est plus utilisee
494 HOMARD::listeHypo* maListe = myZone->GetHypo();
495 int numberOfHypo = maListe->length();
496 MESSAGE ( ".. Nombre d'hypotheses = " << numberOfHypo );
497 if ( numberOfHypo > 0 )
499 SALOME::ExceptionStruct es;
500 es.type = SALOME::BAD_PARAM;
501 es.text = "This zone is used in an hypothesis and cannot be deleted.";
502 throw SALOME::SALOME_Exception(es);
506 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
507 myContextMap[GetCurrentStudyID()]._mesZones.erase(nomZone);
508 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomZone, ComponentDataType());
509 SALOMEDS::SObject_var aSO =listSO[0];
510 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
511 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
515 //=============================================================================
516 //=============================================================================
518 //=============================================================================
519 //=============================================================================
520 // Invalidation des structures identifiees par leurs noms
521 //=============================================================================
522 //=============================================================================
523 void HOMARD_Gen_i::InvalideBoundary(const char* BoundaryName)
525 MESSAGE( "InvalideBoundary : BoundaryName = " << BoundaryName );
526 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
527 if (CORBA::is_nil(myBoundary))
529 SALOME::ExceptionStruct es;
530 es.type = SALOME::BAD_PARAM;
531 es.text = "Invalid boundary";
532 throw SALOME::SALOME_Exception(es);
537 SALOME::ExceptionStruct es;
538 es.type = SALOME::BAD_PARAM;
539 es.text = "No change is allowed in a boundary. Ask for evolution.";
540 throw SALOME::SALOME_Exception(es);
544 //=============================================================================
545 void HOMARD_Gen_i::InvalideHypo(const char* nomHypo)
547 MESSAGE( "InvalideHypo : nomHypo = " << nomHypo );
548 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
549 if (CORBA::is_nil(myHypo))
551 SALOME::ExceptionStruct es;
552 es.type = SALOME::BAD_PARAM;
553 es.text = "Invalid hypothesis";
554 throw SALOME::SALOME_Exception(es);
558 HOMARD::listeIters* maListe = myHypo->GetIterations();
559 int numberOfIter = maListe->length();
560 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
562 std::string nomIter = std::string((*maListe)[NumeIter]);
563 MESSAGE( ".. nomIter = " << nomIter );
564 InvalideIter(nomIter.c_str());
567 //=============================================================================
568 void HOMARD_Gen_i::InvalideIter(const char* nomIter)
570 MESSAGE("InvalideIter : nomIter = " << nomIter);
571 // Pour invalider totalement une iteration courante
572 CORBA::Long Option = 1 ;
573 return InvalideIterOption(nomIter, Option);
575 //=============================================================================
576 void HOMARD_Gen_i::InvalideIterOption(const char* nomIter, CORBA::Long Option)
578 // Option = 0 : On ne supprime pas le fichier du maillage associe
579 // Option = 1 : On supprime le fichier du maillage associe
580 MESSAGE ( "InvalideIterOption : nomIter = " << nomIter << ", avec option = " << Option );
581 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
582 if (CORBA::is_nil(myIteration))
584 SALOME::ExceptionStruct es;
585 es.type = SALOME::BAD_PARAM;
586 es.text = "Invalid iteration";
587 throw SALOME::SALOME_Exception(es);
591 HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
592 int numberOfIter = maListe->length();
593 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
595 std::string nomIterFille = std::string((*maListe)[NumeIter]);
596 MESSAGE ( ".. appel recursif de InvalideIter pour nomIter = " << nomIterFille.c_str() );
597 InvalideIter(nomIterFille.c_str());
600 // On arrive ici pour une iteration sans fille
601 MESSAGE ( "Invalidation effective de " << nomIter );
602 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
603 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aIterSO);
604 for (; aIter->More(); aIter->Next())
606 SALOMEDS::SObject_var so = aIter->Value();
607 SALOMEDS::GenericAttribute_var anAttr;
608 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
609 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
610 std::string value (aCommentAttr->Value());
611 if(value == std::string("HypoHomard")) continue;
612 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
613 aStudyBuilder->RemoveObject(so);
616 int etat = myIteration->GetState();
619 SetEtatIter(nomIter,1);
620 const char * nomCas = myIteration->GetCaseName();
621 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
622 if (CORBA::is_nil(myCase))
624 SALOME::ExceptionStruct es;
625 es.type = SALOME::BAD_PARAM;
626 es.text = "Invalid case context";
627 throw SALOME::SALOME_Exception(es);
630 std::string nomDir = myIteration->GetDirName();
631 std::string nomFichier = myIteration->GetMeshFile();
632 std::string commande= "rm -rf " + std::string(nomDir);
633 if ( Option == 1 ) { commande = commande + ";rm -rf " + std::string(nomFichier) ; }
634 MESSAGE ( "commande = " << commande );
635 if ((system(commande.c_str())) != 0)
637 SALOME::ExceptionStruct es;
638 es.type = SALOME::BAD_PARAM;
639 es.text = "The directory for the calculation cannot be cleared." ;
640 throw SALOME::SALOME_Exception(es);
643 // Suppression du maillage publie dans SMESH
644 std::string MeshName = myIteration->GetMeshName() ;
645 DeleteResultInSmesh(nomFichier, MeshName) ;
649 //=============================================================================
650 void HOMARD_Gen_i::InvalideIterInfo(const char* nomIter)
652 MESSAGE("InvalideIterInfo : nomIter = " << nomIter);
653 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
654 if (CORBA::is_nil(myIteration))
656 SALOME::ExceptionStruct es;
657 es.type = SALOME::BAD_PARAM;
658 es.text = "Invalid iteration";
659 throw SALOME::SALOME_Exception(es);
663 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
664 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aIterSO);
665 for (; aIter->More(); aIter->Next())
667 SALOMEDS::SObject_var so = aIter->Value();
668 SALOMEDS::GenericAttribute_var anAttr;
669 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
670 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
671 std::string value (aCommentAttr->Value());
672 /* MESSAGE("... value = " << value);*/
673 if( (value == std::string("logInfo")) or ( value == std::string("SummaryInfo")) )
675 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
676 aStudyBuilder->RemoveObject(so);
680 const char * nomCas = myIteration->GetCaseName();
681 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
682 if (CORBA::is_nil(myCase))
684 SALOME::ExceptionStruct es;
685 es.type = SALOME::BAD_PARAM;
686 es.text = "Invalid case context";
687 throw SALOME::SALOME_Exception(es);
690 const char* nomDir = myIteration->GetDirName();
691 std::string commande = "rm -f " + std::string(nomDir) + "/info* " ;
692 commande += std::string(nomDir) + "/Liste.*info" ;
693 /* MESSAGE ( "commande = " << commande );*/
694 if ((system(commande.c_str())) != 0)
696 SALOME::ExceptionStruct es;
697 es.type = SALOME::BAD_PARAM;
698 es.text = "The directory for the calculation cannot be cleared." ;
699 throw SALOME::SALOME_Exception(es);
703 //=============================================================================
704 void HOMARD_Gen_i::InvalideZone(const char* ZoneName)
706 MESSAGE( "InvalideZone : ZoneName = " << ZoneName );
707 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
708 if (CORBA::is_nil(myZone))
710 SALOME::ExceptionStruct es;
711 es.type = SALOME::BAD_PARAM;
712 es.text = "Invalid zone";
713 throw SALOME::SALOME_Exception(es);
716 HOMARD::listeHypo* maListe = myZone->GetHypo();
717 int numberOfHypo = maListe->length();
718 MESSAGE( ".. numberOfHypo = " << numberOfHypo );
719 for (int NumeHypo = 0; NumeHypo< numberOfHypo; NumeHypo++)
721 std::string nomHypo = std::string((*maListe)[NumeHypo]);
722 MESSAGE( ".. nomHypo = " << nomHypo );
723 InvalideHypo(nomHypo.c_str());
726 //=============================================================================
727 //=============================================================================
729 //=============================================================================
730 //=============================================================================
731 // Association de lien entre des structures identifiees par leurs noms
732 //=============================================================================
733 //=============================================================================
734 void HOMARD_Gen_i::AssociateCaseIter(const char* nomCas, const char* nomIter, const char* labelIter)
736 MESSAGE( "AssociateCaseIter : " << nomCas << ", " << nomIter << ", " << labelIter );
738 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
739 if (CORBA::is_nil(myCase))
741 SALOME::ExceptionStruct es;
742 es.type = SALOME::BAD_PARAM;
743 es.text = "Invalid case";
744 throw SALOME::SALOME_Exception(es);
748 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
749 if (CORBA::is_nil(myIteration))
751 SALOME::ExceptionStruct es;
752 es.type = SALOME::BAD_PARAM;
753 es.text = "Invalid iteration";
754 throw SALOME::SALOME_Exception(es);
758 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
759 SALOMEDS::SObject_var aCasSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
760 if (CORBA::is_nil(aCasSO))
762 SALOME::ExceptionStruct es;
763 es.type = SALOME::BAD_PARAM;
764 es.text = "Invalid case";
765 throw SALOME::SALOME_Exception(es);
769 aStudyBuilder->NewCommand();
770 SALOMEDS::SObject_var newStudyIter = aStudyBuilder->NewObject(aCasSO);
771 PublishInStudyAttr(aStudyBuilder, newStudyIter, nomIter , labelIter,
772 "iter_non_calculee.png", _orb->object_to_string(myIteration)) ;
773 aStudyBuilder->CommitCommand();
775 myCase->AddIteration(nomIter);
776 myIteration->SetCaseName(nomCas);
778 //=====================================================================================
779 void HOMARD_Gen_i::AssociateHypoZone(const char* nomHypothesis, const char* ZoneName, CORBA::Long TypeUse)
781 MESSAGE ( "AssociateHypoZone : nomHypo = " << nomHypothesis << ", ZoneName= " << ZoneName << ", TypeUse = " << TypeUse);
783 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
784 ASSERT(!CORBA::is_nil(myHypo));
785 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
786 ASSERT(!CORBA::is_nil(aHypoSO));
788 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
789 ASSERT(!CORBA::is_nil(myZone));
790 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myZone)));
791 ASSERT(!CORBA::is_nil(aZoneSO));
793 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
795 aStudyBuilder->NewCommand();
797 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aHypoSO);
798 aStudyBuilder->Addreference(aSubSO, aZoneSO);
800 aStudyBuilder->CommitCommand();
802 myZone->AddHypo(nomHypothesis);
803 myHypo->AddZone0(ZoneName, TypeUse);
805 //=============================================================================
806 void HOMARD_Gen_i::AssociateIterHypo(const char* nomIter, const char* nomHypo)
808 MESSAGE("AssociateIterHypo : nomHypo = " << nomHypo << " nomIter = " << nomIter);
810 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
811 ASSERT(!CORBA::is_nil(myHypo));
812 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
813 ASSERT(!CORBA::is_nil(aHypoSO));
815 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
816 ASSERT(!CORBA::is_nil(myIteration));
817 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
818 ASSERT(!CORBA::is_nil(aIterSO));
820 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
822 aStudyBuilder->NewCommand();
824 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
825 aStudyBuilder->Addreference(aSubSO, aHypoSO);
827 aStudyBuilder->CommitCommand();
829 myIteration->SetHypoName(nomHypo);
830 myHypo->LinkIteration(nomIter);
832 //=============================================================================
833 //=============================================================================
835 //=============================================================================
836 //=============================================================================
837 // Dissociation de lien entre des structures identifiees par leurs noms
838 //=============================================================================
839 //=============================================================================
840 void HOMARD_Gen_i::DissociateHypoZone(const char* nomHypothesis, const char* ZoneName)
842 MESSAGE ( "DissociateHypoZone : ZoneName= " << ZoneName << ", nomHypo = " << nomHypothesis);
844 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
845 ASSERT(!CORBA::is_nil(myHypo));
846 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
847 ASSERT(!CORBA::is_nil(aHypoSO));
849 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
850 ASSERT(!CORBA::is_nil(myZone));
851 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myZone)));
852 ASSERT(!CORBA::is_nil(aZoneSO));
854 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
856 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator(aHypoSO);
857 for (; it->More(); it->Next())
859 SALOMEDS::SObject_var aHypObj = it->Value();
860 SALOMEDS::SObject_var ptrObj;
861 if (aHypObj->ReferencedObject(ptrObj))
863 if (std::string(ptrObj->GetName()) == std::string(aZoneSO->GetName()))
865 aStudyBuilder->NewCommand();
866 aStudyBuilder->RemoveObject(aHypObj);
867 aStudyBuilder->CommitCommand();
873 myZone->SupprHypo(nomHypothesis);
874 myHypo->SupprZone(ZoneName);
876 //=============================================================================
877 //=============================================================================
880 //=============================================================================
881 //=============================================================================
882 // Recuperation des listes
883 //=============================================================================
884 //=============================================================================
885 HOMARD::listeBoundarys* HOMARD_Gen_i::GetAllBoundarysName()
887 MESSAGE("GetAllBoundarysName");
890 HOMARD::listeBoundarys_var ret = new HOMARD::listeBoundarys;
891 ret->length(myContextMap[GetCurrentStudyID()]._mesBoundarys.size());
892 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it;
894 for (it = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
895 it != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); it++)
897 ret[i++] = CORBA::string_dup((*it).first.c_str());
902 //=============================================================================
903 HOMARD::listeCases* HOMARD_Gen_i::GetAllCasesName()
905 MESSAGE("GetAllCasesName");
908 HOMARD::listeCases_var ret = new HOMARD::listeCases;
909 ret->length(myContextMap[GetCurrentStudyID()]._mesCas.size());
910 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
912 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
913 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
915 ret[i++] = CORBA::string_dup((*it).first.c_str());
920 //=============================================================================
921 HOMARD::listeHypotheses* HOMARD_Gen_i::GetAllHypothesesName()
923 MESSAGE("GetAllHypothesesName");
926 HOMARD::listeHypotheses_var ret = new HOMARD::listeHypotheses;
927 ret->length(myContextMap[GetCurrentStudyID()]._mesHypotheses.size());
928 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it;
930 for (it = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
931 it != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it++)
933 ret[i++] = CORBA::string_dup((*it).first.c_str());
938 //=============================================================================
939 HOMARD::listeIterations* HOMARD_Gen_i::GetAllIterationsName()
941 MESSAGE("GetAllIterationsName");
944 HOMARD::listeIterations_var ret = new HOMARD::listeIterations;
945 ret->length(myContextMap[GetCurrentStudyID()]._mesIterations.size());
946 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it;
948 for (it = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
949 it != myContextMap[GetCurrentStudyID()]._mesIterations.end(); it++)
951 ret[i++] = CORBA::string_dup((*it).first.c_str());
956 //=============================================================================
957 HOMARD::listeYACSs* HOMARD_Gen_i::GetAllYACSsName()
959 MESSAGE("GetAllYACSsName");
962 HOMARD::listeYACSs_var ret = new HOMARD::listeYACSs;
963 ret->length(myContextMap[GetCurrentStudyID()]._mesYACSs.size());
964 std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it;
966 for (it = myContextMap[GetCurrentStudyID()]._mesYACSs.begin();
967 it != myContextMap[GetCurrentStudyID()]._mesYACSs.end(); it++)
969 ret[i++] = CORBA::string_dup((*it).first.c_str());
974 //=============================================================================
975 HOMARD::listeZones* HOMARD_Gen_i::GetAllZonesName()
977 MESSAGE("GetAllZonesName");
980 HOMARD::listeZones_var ret = new HOMARD::listeZones;
981 ret->length(myContextMap[GetCurrentStudyID()]._mesZones.size());
982 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it;
984 for (it = myContextMap[GetCurrentStudyID()]._mesZones.begin();
985 it != myContextMap[GetCurrentStudyID()]._mesZones.end(); it++)
987 ret[i++] = CORBA::string_dup((*it).first.c_str());
992 //=============================================================================
993 //=============================================================================
995 //=============================================================================
996 //=============================================================================
997 // Recuperation des structures identifiees par leurs noms
998 //=============================================================================
999 //=============================================================================
1000 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::GetBoundary(const char* nomBoundary)
1002 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[nomBoundary];
1003 ASSERT(!CORBA::is_nil(myBoundary));
1004 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1006 //=============================================================================
1007 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::GetCase(const char* nomCas)
1009 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1010 ASSERT(!CORBA::is_nil(myCase));
1011 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1013 //=============================================================================
1014 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::GetHypothesis(const char* nomHypothesis)
1016 HOMARD::HOMARD_Hypothesis_var myHypothesis = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
1017 ASSERT(!CORBA::is_nil(myHypothesis));
1018 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1020 //=============================================================================
1021 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::GetIteration(const char* NomIterationation)
1023 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIterationation];
1024 ASSERT(!CORBA::is_nil(myIteration));
1025 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1027 //=============================================================================
1028 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::GetYACS(const char* nomYACS)
1030 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
1031 ASSERT(!CORBA::is_nil(myYACS));
1032 return HOMARD::HOMARD_YACS::_duplicate(myYACS);
1034 //=============================================================================
1035 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::GetZone(const char* ZoneName)
1037 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
1038 ASSERT(!CORBA::is_nil(myZone));
1039 return HOMARD::HOMARD_Zone::_duplicate(myZone);
1041 //=============================================================================
1042 //=============================================================================
1044 //=============================================================================
1045 //=============================================================================
1047 //=============================================================================
1048 //=============================================================================
1049 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)
1051 INFOS ( "MeshInfo : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1052 INFOS ( "Qual = " << Qual << ", Diam = " << Diam << ", Conn = " << Conn << ", Tail = " << Tail << ", Inte = " << Inte );
1056 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, 0, 1) ;
1057 myCase->SetDirName(DirName) ;
1059 myCase->MeshInfo(Qual, Diam, Conn, Tail, Inte) ;
1063 //=============================================================================
1064 //=============================================================================
1066 //=============================================================================
1067 //=============================================================================
1068 // Recuperation des structures par le contexte
1069 //=============================================================================
1070 //=============================================================================
1071 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::LastIteration(const char* nomCas)
1073 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1074 ASSERT(!CORBA::is_nil(myCase));
1076 HOMARD::HOMARD_Iteration_var myIteration = myCase->LastIteration();
1077 ASSERT(!CORBA::is_nil(myIteration));
1079 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1081 //=============================================================================
1082 //=============================================================================
1084 //=============================================================================
1085 //=============================================================================
1086 // Nouvelles structures
1087 //=============================================================================
1088 //=============================================================================
1089 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::newCase()
1091 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1092 HOMARD_Cas_i* aServant = new HOMARD_Cas_i(_orb, engine);
1093 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(aServant->_this());
1094 return aCase._retn();
1096 //=============================================================================
1097 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::newHypothesis()
1099 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1100 HOMARD_Hypothesis_i* aServant = new HOMARD_Hypothesis_i(_orb, engine);
1101 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(aServant->_this());
1102 return aHypo._retn();
1104 //=============================================================================
1105 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::newIteration()
1107 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1108 HOMARD_Iteration_i* aServant = new HOMARD_Iteration_i(_orb, engine);
1109 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(aServant->_this());
1110 return aIter._retn();
1112 //=============================================================================
1113 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::newBoundary()
1115 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1116 HOMARD_Boundary_i* aServant = new HOMARD_Boundary_i(_orb, engine);
1117 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(aServant->_this());
1118 return aBoundary._retn();
1120 //=============================================================================
1121 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::newZone()
1123 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1124 HOMARD_Zone_i* aServant = new HOMARD_Zone_i(_orb, engine);
1125 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(aServant->_this());
1126 return aZone._retn();
1128 //=============================================================================
1129 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::newYACS()
1131 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1132 HOMARD_YACS_i* aServant = new HOMARD_YACS_i(_orb, engine);
1133 HOMARD::HOMARD_YACS_var aYACS = HOMARD::HOMARD_YACS::_narrow(aServant->_this());
1134 return aYACS._retn();
1136 //=============================================================================
1137 //=============================================================================
1139 //=============================================================================
1140 //=============================================================================
1141 // Creation des structures identifiees par leurs noms
1142 //=============================================================================
1143 //=============================================================================
1144 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCase(const char* nomCas, const char* MeshName, const char* MeshFile)
1146 // Creation d'un cas initial
1147 // nomCas : nom du cas a creer
1148 // MeshName, MeshFile : nom et fichier du maillage correspondant
1151 INFOS ( "CreateCase : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1153 // Par defaut, on ne publie pas le maillage
1154 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 0, 0, 1) ;
1156 // Valeurs par defaut des filtrages
1157 myCase->SetPyram(0);
1159 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1161 //=============================================================================
1162 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromIteration(const char* nomCas, const char* DirNameStart)
1164 // nomCas : nom du cas a creer
1165 // DirNameStart : nom du repertoire contenant l'iteration de reprise
1168 INFOS ( "CreateCaseFromIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1169 std::string nomDirWork = getenv("PWD") ;
1172 // A. Decodage du point de reprise
1173 // A.1. Controle du repertoire de depart de l'iteration
1174 codret = chdir(DirNameStart) ;
1177 SALOME::ExceptionStruct es;
1178 es.type = SALOME::BAD_PARAM;
1179 es.text = "The directory of the iteration does not exist.";
1180 throw SALOME::SALOME_Exception(es);
1183 // A.2. Reperage des fichiers du repertoire de reprise
1184 std::string file_configuration = "" ;
1185 std::string file_maillage_homard = "" ;
1188 struct dirent *dirp;
1189 dp = opendir(DirNameStart);
1190 while ( (dirp = readdir(dp)) != NULL )
1192 std::string file_name(dirp->d_name);
1193 // MESSAGE ( file_name );
1194 bilan = file_name.find("HOMARD.Configuration.") ;
1195 if ( bilan != string::npos ) { file_configuration = file_name ; }
1196 bilan = file_name.find("maill.") ;
1197 if ( bilan != string::npos )
1199 bilan = file_name.find(".hom.med") ;
1200 if ( bilan != string::npos ) { file_maillage_homard = file_name ; }
1204 MESSAGE ( "==> file_configuration : " << file_configuration ) ;
1205 MESSAGE ( "==> file_maillage_homard : " << file_maillage_homard ) ;
1207 if ( ( file_configuration == "" ) or ( file_maillage_homard == "" ) )
1209 SALOME::ExceptionStruct es;
1210 es.type = SALOME::BAD_PARAM;
1212 if ( file_configuration == "" ) { text = "The configuration file cannot be found." ; }
1213 else { text = "The HOMARD mesh file cannot be found." ; }
1214 es.text = CORBA::string_dup(text.c_str());
1215 throw SALOME::SALOME_Exception(es);
1218 // B. Lecture du fichier de configuration
1219 // ATTENTION : on doit veiller a la coherence entre HomardDriver et CreateCaseFromIteration
1225 // le constructeur de ifstream permet d'ouvrir un fichier en lecture
1226 std::ifstream fichier( file_configuration.c_str() );
1227 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1229 std::string ligne; // variable contenant chaque ligne lue
1230 std::string mot_cle;
1231 std::string argument;
1233 // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1234 while ( std::getline( fichier, ligne ) )
1236 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1237 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1238 ligne_bis >> mot_cle ;
1239 // B.2. Des valeurs entieres : le second bloc de la ligne
1240 if ( mot_cle == "NumeIter" )
1242 ligne_bis >> NumeIter ;
1245 // B.3. Des valeurs caracteres brutes : le second bloc de la ligne est la valeur
1246 else if ( ( mot_cle == "TypeConf" ) or ( mot_cle == "TypeElem" ) )
1248 ligne_bis >> argument ;
1250 if ( mot_cle == "TypeConf" )
1252 if ( argument == "conforme" ) { TypeConf = 1 ; }
1253 else if ( argument == "non_conforme_1_noeud" ) { TypeConf = 2 ; }
1254 else if ( argument == "non_conforme_1_arete" ) { TypeConf = 3 ; }
1255 else if ( argument == "non_conforme_indicateur" ) { TypeConf = 4 ; }
1257 else if ( mot_cle == "TypeElem" )
1259 if ( argument == "ignore_pyra" ) { Pyram = 1 ; }
1260 else if ( argument == "HOMARD" ) { Pyram = 0 ; }
1263 // B.4. Des valeurs caracteres : le deuxieme bloc de la ligne peut etre encadre par des quotes :
1264 // il faut les supprimer
1265 else if ( ( mot_cle == "CCNoMNP1" ) or ( mot_cle == "CCMaiNP1" ) )
1267 ligne_bis >> argument ;
1268 if ( argument[0] == '"' ) { decalage = 1 ; }
1269 else { decalage = 0 ; }
1270 size_t size = argument.size() + 1 - 2*decalage ;
1272 if ( mot_cle == "CCNoMNP1" )
1274 MeshName = new char[ size ];
1275 strncpy( MeshName, argument.c_str()+decalage, size );
1276 MeshName[size-1] = '\0' ;
1278 else if ( mot_cle == "CCMaiNP1" )
1280 MeshFile = new char[ size ];
1281 strncpy( MeshFile, argument.c_str()+decalage, size );
1282 MeshFile[size-1] = '\0' ;
1286 MESSAGE ( "==> TypeConf : " << TypeConf ) ;
1287 MESSAGE ( "==> MeshName : " << MeshName ) ;
1288 MESSAGE ( "==> MeshFile : " << MeshFile ) ;
1289 MESSAGE ( "==> NumeIter : " << NumeIter ) ;
1290 MESSAGE ( "==> Pyram : " << Pyram ) ;
1294 SALOME::ExceptionStruct es;
1295 es.type = SALOME::BAD_PARAM;
1296 std::string text = "The configuration file cannot be read." ;
1297 es.text = CORBA::string_dup(text.c_str());
1298 throw SALOME::SALOME_Exception(es);
1301 // C. Creation effective du cas
1303 // Par defaut, on ne publie pas le maillage
1304 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, NumeIter, 1) ;
1306 // D. Parametrages lus dans le fichier de configuration
1308 myCase->SetConfType (TypeConf) ;
1309 myCase->SetPyram (Pyram) ;
1311 // E. Copie du fichier de maillage homard
1312 // E.1. Repertoire associe au cas
1313 char* nomDirCase = myCase->GetDirName() ;
1314 // E.2. Repertoire associe a l'iteration de ce cas
1316 IterName = myCase->GetIter0Name() ;
1317 HOMARD::HOMARD_Iteration_var Iter = GetIteration(IterName) ;
1318 char* nomDirIter = CreateDirNameIter(nomDirCase, 0 );
1319 Iter->SetDirNameLoc(nomDirIter);
1320 std::string nomDirIterTotal ;
1321 nomDirIterTotal = std::string(nomDirCase) + "/" + std::string(nomDirIter) ;
1322 if (mkdir(nomDirIterTotal.c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
1324 MESSAGE ( "nomDirIterTotal : " << nomDirIterTotal ) ;
1325 SALOME::ExceptionStruct es;
1326 es.type = SALOME::BAD_PARAM;
1327 std::string text = "The directory for the computation cannot be created." ;
1328 es.text = CORBA::string_dup(text.c_str());
1329 throw SALOME::SALOME_Exception(es);
1331 // E.3. Copie du maillage HOMARD au format MED
1332 codret = chdir(DirNameStart) ;
1333 std::string commande = "cp " + file_maillage_homard + " " + nomDirIterTotal ;
1334 MESSAGE ( "commande : " << commande ) ;
1335 codret = system(commande.c_str()) ;
1336 MESSAGE ( "codret : " << codret ) ;
1339 SALOME::ExceptionStruct es;
1340 es.type = SALOME::BAD_PARAM;
1341 es.text = "The starting point for the case cannot be copied into the working directory.";
1342 throw SALOME::SALOME_Exception(es);
1351 chdir(nomDirWork.c_str());
1353 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1355 //=============================================================================
1356 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseLastIteration(const char* nomCas, const char* DirNameStart)
1358 // nomCas : nom du cas a creer
1359 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1362 INFOS ( "CreateCaseFromCaseLastIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1364 std::string DirNameStartIter = CreateCase1(DirNameStart, -1) ;
1366 DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1367 HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1369 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1371 //=============================================================================
1372 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseIteration(const char* nomCas, const char* DirNameStart, CORBA::Long Number)
1374 // nomCas : nom du cas a creer
1375 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1376 // Number : numero de l'iteration de depart
1379 INFOS ( "CreateCaseFromCaseIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart << ", Number = " << Number );
1382 SALOME::ExceptionStruct es;
1383 es.type = SALOME::BAD_PARAM;
1384 es.text = "The number of iteration must be positive.";
1385 throw SALOME::SALOME_Exception(es);
1389 std::string DirNameStartIter = CreateCase1(DirNameStart, Number) ;
1391 DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1392 HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1394 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1396 //=============================================================================
1397 std::string HOMARD_Gen_i::CreateCase1(const char* DirNameStart, CORBA::Long Number)
1399 // Retourne le nom du repertoire ou se trouve l'iteration voulue.
1400 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1401 // Number : numero de l'iteration de depart ou -1 si on cherche la derniere
1404 MESSAGE ( "CreateCase1 : DirNameStart = " << DirNameStart << ", Number = " << Number );
1405 std::string nomDirWork = getenv("PWD") ;
1406 std::string DirNameStartIter ;
1408 int NumeIterMax = -1 ;
1410 // A.1. Controle du repertoire de depart du cas
1411 codret = chdir(DirNameStart) ;
1414 SALOME::ExceptionStruct es;
1415 es.type = SALOME::BAD_PARAM;
1416 es.text = "The directory of the case for the pursuit does not exist.";
1417 throw SALOME::SALOME_Exception(es);
1420 // A.2. Reperage des sous-repertoire du repertoire de reprise
1421 bool existe = false ;
1423 struct dirent *dirp;
1424 dp = opendir(DirNameStart);
1425 while ( (dirp = readdir(dp)) != NULL )
1427 std::string DirName_1(dirp->d_name);
1428 if ( ( DirName_1 != "." ) and ( DirName_1 != ".." ) )
1430 if ( chdir(DirName_1.c_str()) == 0 )
1432 // On cherche le fichier de configuration dans ce sous-repertoire
1433 codret = chdir(DirNameStart) ;
1435 struct dirent *dirp_1;
1436 dp_1 = opendir(DirName_1.c_str()) ;
1437 while ( (dirp_1 = readdir(dp_1)) != NULL )
1439 std::string file_name_1(dirp_1->d_name);
1440 int bilan = file_name_1.find("HOMARD.Configuration.") ;
1441 if ( bilan != string::npos )
1443 // Decodage du fichier pour trouver le numero d'iteration
1444 chdir(DirName_1.c_str()) ;
1445 std::ifstream fichier( file_name_1.c_str() );
1446 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1449 std::string ligne; // variable contenant chaque ligne lue
1450 std::string mot_cle;
1451 // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1452 while ( std::getline( fichier, ligne ) )
1454 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1455 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1456 ligne_bis >> mot_cle ;
1457 if ( mot_cle == "NumeIter" )
1459 ligne_bis >> NumeIter ;
1461 // MESSAGE ( "==> NumeIter : " << NumeIter ) ;
1462 if ( Number == - 1 )
1464 if ( NumeIter >= NumeIterMax )
1466 NumeIterMax = NumeIter ;
1467 DirNameStartIter = DirName_1 ;
1472 if ( NumeIter == Number )
1474 DirNameStartIter = DirName_1 ;
1484 SALOME::ExceptionStruct es;
1485 es.type = SALOME::BAD_PARAM;
1486 std::string text = "The configuration file cannot be read." ;
1487 es.text = CORBA::string_dup(text.c_str());
1488 throw SALOME::SALOME_Exception(es);
1490 chdir(DirNameStart) ;
1492 if ( existe ) { break ; }
1495 if ( existe ) { break ; }
1501 chdir(nomDirWork.c_str());
1503 if ( ( Number >= 0 and ( not existe ) ) or ( Number < 0 and ( NumeIterMax == -1 ) ) )
1505 SALOME::ExceptionStruct es;
1506 es.type = SALOME::BAD_PARAM;
1507 es.text = "The directory of the iteration does not exist.";
1508 throw SALOME::SALOME_Exception(es);
1512 return DirNameStartIter ;
1514 //=============================================================================
1515 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)
1517 // nomCas : nom du cas a creer
1518 // MeshName, MeshFile : nom et fichier du maillage correspondant
1519 // MeshOption : 0 : le maillage fourni est obligatoirement present ==> erreur si absent
1520 // 1 : le maillage fourni peut ne pas exister ==> on continue si absent
1521 // -1 : le maillage n'est pas fourni
1522 // NumeIter : numero de l'iteration correspondante : 0, pour un depart, n>0 pour une poursuite
1523 // Option : multiple de nombres premiers
1524 // 1 : aucune option
1525 // x2 : publication du maillage dans SMESH
1527 MESSAGE ( "CreateCase0 : nomCas = " << nomCas );
1528 MESSAGE ( "CreateCase0 : MeshName = " << MeshName << ", MeshFile = " << MeshFile << ", MeshOption = " << MeshOption );
1529 MESSAGE ( "CreateCase0 : NumeIter = " << NumeIter << ", Option = " << Option );
1535 // A.2. Controle du nom :
1536 if ((myContextMap[GetCurrentStudyID()]._mesCas).find(nomCas)!=(myContextMap[GetCurrentStudyID()]._mesCas).end())
1538 SALOME::ExceptionStruct es;
1539 es.type = SALOME::BAD_PARAM;
1540 es.text = "This case has already been defined.";
1541 throw SALOME::SALOME_Exception(es);
1545 // A.3. Controle du fichier du maillage
1546 int existeMeshFile ;
1547 if ( MeshOption >= 0 )
1549 existeMeshFile = MEDFileExist ( MeshFile ) ;
1550 MESSAGE ( "CreateCase0 : existeMeshFile = " << existeMeshFile );
1551 if ( ( existeMeshFile == 0 ) and ( MeshOption == 0 ) )
1553 SALOME::ExceptionStruct es;
1554 es.type = SALOME::BAD_PARAM;
1555 es.text = "The mesh file does not exist.";
1556 throw SALOME::SALOME_Exception(es);
1560 else { existeMeshFile = 0 ; }
1562 // B. Creation de l'objet cas et publication
1563 // MESSAGE ( "CreateCase0 : Creation de l'objet" );
1564 HOMARD::HOMARD_Cas_var myCase = newCase();
1565 myCase->SetName(nomCas);
1566 SALOMEDS::SObject_var aSO;
1567 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myCase, nomCas);
1568 myContextMap[GetCurrentStudyID()]._mesCas[nomCas] = myCase;
1570 // C. Caracteristiques du maillage
1571 if ( existeMeshFile != 0 )
1573 // Les valeurs extremes des coordonnees
1574 // MESSAGE ( "CreateCase0 : Les valeurs extremes des coordonnees" );
1575 std::vector<double> LesExtremes =GetBoundingBoxInMedFile(MeshFile) ;
1576 HOMARD::extrema_var aSeq = new HOMARD::extrema() ;
1577 if (LesExtremes.size()!=10) { return false; }
1579 for (int i =0 ; i< LesExtremes.size() ; i++)
1580 aSeq[i]=LesExtremes[i] ;
1581 myCase->SetBoundingBox(aSeq) ;
1583 // MESSAGE ( "CreateCase0 : Les groupes" );
1584 std::set<std::string> LesGroupes =GetListeGroupesInMedFile(MeshFile) ;
1585 HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType ;
1586 aSeqGroupe->length(LesGroupes.size());
1587 std::set<std::string>::const_iterator it ;
1589 for (it=LesGroupes.begin() ; it != LesGroupes.end() ; it++)
1590 aSeqGroupe[i++]=(*it).c_str() ;
1591 myCase->SetGroups(aSeqGroupe) ;
1594 // D. L'iteration initiale du cas
1595 MESSAGE ( "CreateCase0 : iteration initiale du cas" );
1596 // D.1. Recherche d'un nom : par defaut, on prend le nom du maillage correspondant.
1597 // Si ce nom d'iteration existe deja, on incremente avec 0, 1, 2, etc.
1599 std::string NomIteration = std::string(MeshName) ;
1600 while ( (myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration) != (myContextMap[GetCurrentStudyID()]._mesIterations.end()) )
1602 std::ostringstream nom;
1603 nom << MeshName << monNum;
1604 NomIteration = nom.str();
1607 MESSAGE ( "CreateCas0 : ==> NomIteration = " << NomIteration );
1609 // D.2. Creation de l'iteration
1610 HOMARD::HOMARD_Iteration_var anIter = newIteration();
1611 myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration] = anIter;
1612 anIter->SetName(NomIteration.c_str());
1613 AssociateCaseIter (nomCas, NomIteration.c_str(), "IterationHomard");
1615 // D.4. Maillage correspondant
1616 if ( existeMeshFile != 0 )
1618 anIter->SetMeshFile(MeshFile);
1619 if ( Option % 2 == 0 ) { PublishResultInSmesh(MeshFile, 0); }
1621 anIter->SetMeshName(MeshName);
1623 // D.5. Numero d'iteration
1624 anIter->SetNumber(NumeIter);
1627 SetEtatIter(NomIteration.c_str(), -NumeIter);
1630 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1632 //=============================================================================
1633 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::CreateHypothesis(const char* nomHypothesis)
1635 INFOS ( "CreateHypothesis : nomHypothesis = " << nomHypothesis );
1638 // A. Controle du nom :
1639 if ((myContextMap[GetCurrentStudyID()]._mesHypotheses).find(nomHypothesis) != (myContextMap[GetCurrentStudyID()]._mesHypotheses).end())
1641 SALOME::ExceptionStruct es;
1642 es.type = SALOME::BAD_PARAM;
1643 es.text = "This hypothesis has already been defined.";
1644 throw SALOME::SALOME_Exception(es);
1648 // B. Creation de l'objet
1649 HOMARD::HOMARD_Hypothesis_var myHypothesis = newHypothesis();
1650 if (CORBA::is_nil(myHypothesis))
1652 SALOME::ExceptionStruct es;
1653 es.type = SALOME::BAD_PARAM;
1654 es.text = "Unable to create the hypothesis";
1655 throw SALOME::SALOME_Exception(es);
1658 myHypothesis->SetName(nomHypothesis);
1660 // C. Enregistrement
1661 myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis] = myHypothesis;
1663 SALOMEDS::SObject_var aSO;
1664 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myHypothesis, nomHypothesis);
1666 // D. Valeurs par defaut des options avancees
1667 myHypothesis->SetNivMax(-1);
1668 myHypothesis->SetDiamMin(-1.0);
1669 myHypothesis->SetAdapInit(0);
1670 myHypothesis->SetLevelOutput(0);
1672 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1675 //=============================================================================
1676 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::CreateIteration(const char* NomIteration, const char* nomIterParent)
1677 //=============================================================================
1679 INFOS ("CreateIteration : NomIteration = " << NomIteration << ", nomIterParent = " << nomIterParent);
1682 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterParent];
1683 if (CORBA::is_nil(myIterationParent))
1685 SALOME::ExceptionStruct es;
1686 es.type = SALOME::BAD_PARAM;
1687 es.text = "The parent iteration is not defined.";
1688 throw SALOME::SALOME_Exception(es);
1692 const char* nomCas = myIterationParent->GetCaseName();
1693 MESSAGE ("CreateIteration : nomCas = " << nomCas);
1694 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1695 if (CORBA::is_nil(myCase))
1697 SALOME::ExceptionStruct es;
1698 es.type = SALOME::BAD_PARAM;
1699 es.text = "Invalid case context";
1700 throw SALOME::SALOME_Exception(es);
1703 const char* nomDirCase = myCase->GetDirName();
1705 // Controle du nom :
1706 if ((myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration)!=(myContextMap[GetCurrentStudyID()]._mesIterations).end())
1708 SALOME::ExceptionStruct es;
1709 es.type = SALOME::BAD_PARAM;
1710 es.text = "This iteration has already been defined.";
1711 throw SALOME::SALOME_Exception(es);
1715 HOMARD::HOMARD_Iteration_var myIteration = newIteration();
1716 if (CORBA::is_nil(myIteration))
1718 SALOME::ExceptionStruct es;
1719 es.type = SALOME::BAD_PARAM;
1720 es.text = "Unable to create the iteration";
1721 throw SALOME::SALOME_Exception(es);
1724 myContextMap[GetCurrentStudyID()]._mesIterations[std::string(NomIteration)] = myIteration;
1725 // Nom de l'iteration et du maillage
1726 myIteration->SetName(NomIteration);
1727 myIteration->SetMeshName(NomIteration);
1728 myIteration->SetState(1);
1730 int numero = myIterationParent->GetNumber() + 1;
1731 myIteration->SetNumber(numero);
1733 // Nombre d'iterations deja connues pour le cas, permettant
1734 // la creation d'un sous-repertoire unique
1735 int nbitercase = myCase->GetNumberofIter();
1736 char* nomDirIter = CreateDirNameIter(nomDirCase, nbitercase );
1737 myIteration->SetDirNameLoc(nomDirIter);
1739 // Le nom du fichier du maillage MED est indice par le nombre d'iterations du cas.
1740 // Si on a une chaine unique depuis le depart, ce nombre est le meme que le
1741 // numero d'iteration dans la sucession : maill.01.med, maill.02.med, etc... C'est la
1742 // situation la plus frequente.
1743 // Si on a plusieurs branches, donc des iterations du meme niveau d'adaptation, utiliser
1744 // le nombre d'iterations du cas permet d'eviter les collisions.
1746 if ( nbitercase < 100 ) { jaux = 2 ; }
1747 else if ( nbitercase < 1000 ) { jaux = 3 ; }
1748 else if ( nbitercase < 10000 ) { jaux = 4 ; }
1749 else if ( nbitercase < 100000 ) { jaux = 5 ; }
1751 std::ostringstream iaux ;
1752 iaux << std::setw(jaux) << std::setfill('0') << nbitercase ;
1753 std::stringstream MeshFile;
1754 MeshFile << nomDirCase << "/maill." << iaux.str() << ".med";
1755 myIteration->SetMeshFile(MeshFile.str().c_str());
1757 // Association avec le cas
1758 std::string label = "IterationHomard_" + std::string(nomIterParent);
1759 AssociateCaseIter(nomCas, NomIteration, label.c_str());
1760 // Lien avec l'iteration precedente
1761 myIterationParent->LinkNextIteration(NomIteration);
1762 myIteration->SetIterParentName(nomIterParent);
1764 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1766 //=============================================================================
1767 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundary(const char* BoundaryName, CORBA::Long BoundaryType)
1769 MESSAGE ("CreateBoundary : BoundaryName = " << BoundaryName << ", BoundaryType = " << BoundaryType);
1772 // Controle du nom :
1773 if ((myContextMap[GetCurrentStudyID()]._mesBoundarys).find(BoundaryName)!=(myContextMap[GetCurrentStudyID()]._mesBoundarys).end())
1775 MESSAGE ("CreateBoundary : la frontiere " << BoundaryName << " existe deja");
1776 SALOME::ExceptionStruct es;
1777 es.type = SALOME::BAD_PARAM;
1778 es.text = "This boundary has already been defined";
1779 throw SALOME::SALOME_Exception(es);
1783 HOMARD::HOMARD_Boundary_var myBoundary = newBoundary();
1784 myBoundary->SetName(BoundaryName);
1785 myBoundary->SetType(BoundaryType);
1787 myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName] = myBoundary;
1789 SALOMEDS::SObject_var aSO;
1790 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myBoundary, BoundaryName);
1792 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1794 //=============================================================================
1795 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
1797 INFOS ("CreateBoundaryDi : BoundaryName = " << BoundaryName << "MeshName = " << MeshName );
1798 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
1799 myBoundary->SetMeshFile( MeshFile ) ;
1800 myBoundary->SetMeshName( MeshName ) ;
1802 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1804 //=============================================================================
1805 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCylinder(const char* BoundaryName,
1806 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1807 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1808 CORBA::Double Rayon)
1810 INFOS ("CreateBoundaryCylinder : BoundaryName = " << BoundaryName ) ;
1812 SALOME::ExceptionStruct es;
1815 { es.text = "The radius must be positive." ;
1817 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1818 if ( daux < 0.0000001 )
1819 { es.text = "The axis must be a non 0 vector." ;
1823 es.type = SALOME::BAD_PARAM;
1824 throw SALOME::SALOME_Exception(es);
1828 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 1) ;
1829 myBoundary->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon ) ;
1831 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1833 //=============================================================================
1834 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundarySphere(const char* BoundaryName,
1835 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1836 CORBA::Double Rayon)
1838 INFOS ("CreateBoundarySphere : BoundaryName = " << BoundaryName ) ;
1840 SALOME::ExceptionStruct es;
1843 { es.text = "The radius must be positive." ;
1847 es.type = SALOME::BAD_PARAM;
1848 throw SALOME::SALOME_Exception(es);
1852 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 2) ;
1853 myBoundary->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
1855 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1857 //=============================================================================
1858 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeA(const char* BoundaryName,
1859 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe, CORBA::Double Angle,
1860 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre)
1862 INFOS ("CreateBoundaryConeA : BoundaryName = " << BoundaryName ) ;
1864 SALOME::ExceptionStruct es;
1866 if ( Angle <= 0.0 or Angle >= 90.0 )
1867 { es.text = "The angle must be included higher than 0 degree and lower than 90 degrees." ;
1869 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1870 if ( daux < 0.0000001 )
1871 { es.text = "The axis must be a non 0 vector." ;
1875 es.type = SALOME::BAD_PARAM;
1876 throw SALOME::SALOME_Exception(es);
1880 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 3) ;
1881 myBoundary->SetConeA( Xaxe, Yaxe, Zaxe, Angle, Xcentre, Ycentre, Zcentre ) ;
1883 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1885 //=============================================================================
1886 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeR(const char* BoundaryName,
1887 CORBA::Double Xcentre1, CORBA::Double Ycentre1, CORBA::Double Zcentre1, CORBA::Double Rayon1,
1888 CORBA::Double Xcentre2, CORBA::Double Ycentre2, CORBA::Double Zcentre2, CORBA::Double Rayon2)
1890 INFOS ("CreateBoundaryConeR : BoundaryName = " << BoundaryName ) ;
1892 SALOME::ExceptionStruct es;
1894 if ( Rayon1 < 0.0 or Rayon2 < 0.0 )
1895 { es.text = "The radius must be positive." ;
1897 double daux = fabs(Rayon2-Rayon1) ;
1898 if ( daux < 0.0000001 )
1899 { es.text = "The radius must be different." ;
1901 daux = fabs(Xcentre2-Xcentre1) + fabs(Ycentre2-Ycentre1) + fabs(Zcentre2-Zcentre1) ;
1902 if ( daux < 0.0000001 )
1903 { es.text = "The centers must be different." ;
1907 es.type = SALOME::BAD_PARAM;
1908 throw SALOME::SALOME_Exception(es);
1912 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 4) ;
1913 myBoundary->SetConeR( Xcentre1, Ycentre1, Zcentre1, Rayon1, Xcentre2, Ycentre2, Zcentre2, Rayon2 ) ;
1915 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1917 //=============================================================================
1918 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZone(const char* ZoneName, CORBA::Long ZoneType)
1920 MESSAGE ("CreateZone : ZoneName = " << ZoneName << ", ZoneType = " << ZoneType);
1923 // Controle du nom :
1924 if ((myContextMap[GetCurrentStudyID()]._mesZones).find(ZoneName)!=(myContextMap[GetCurrentStudyID()]._mesZones).end())
1926 SALOME::ExceptionStruct es;
1927 es.type = SALOME::BAD_PARAM;
1928 es.text = "This zone has already been defined";
1929 throw SALOME::SALOME_Exception(es);
1933 HOMARD::HOMARD_Zone_var myZone = newZone();
1934 myZone->SetName(ZoneName);
1935 myZone->SetType(ZoneType);
1937 myContextMap[GetCurrentStudyID()]._mesZones[ZoneName] = myZone;
1939 SALOMEDS::SObject_var aSO;
1940 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myZone, ZoneName);
1942 return HOMARD::HOMARD_Zone::_duplicate(myZone);
1944 //=============================================================================
1945 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox(const char* ZoneName,
1946 CORBA::Double Xmini, CORBA::Double Xmaxi,
1947 CORBA::Double Ymini, CORBA::Double Ymaxi,
1948 CORBA::Double Zmini, CORBA::Double Zmaxi)
1950 INFOS ("CreateZoneBox : ZoneName = " << ZoneName ) ;
1952 SALOME::ExceptionStruct es;
1954 if ( Xmini > Xmaxi )
1955 { es.text = "The X coordinates are not coherent." ;
1957 if ( Ymini > Ymaxi )
1958 { es.text = "The Y coordinates are not coherent." ;
1960 if ( Zmini > Zmaxi )
1961 { es.text = "The Z coordinates are not coherent." ;
1965 es.type = SALOME::BAD_PARAM;
1966 throw SALOME::SALOME_Exception(es);
1970 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 2) ;
1971 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
1973 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1975 //=============================================================================
1976 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneSphere(const char* ZoneName,
1977 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre, CORBA::Double Rayon)
1979 INFOS ("CreateZoneSphere : ZoneName = " << ZoneName ) ;
1981 SALOME::ExceptionStruct es;
1984 { es.text = "The radius must be positive." ;
1988 es.type = SALOME::BAD_PARAM;
1989 throw SALOME::SALOME_Exception(es);
1993 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 4) ;
1994 myZone->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
1996 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1998 //=============================================================================
1999 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneCylinder(const char* ZoneName,
2000 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2001 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2002 CORBA::Double Rayon, CORBA::Double Haut)
2004 INFOS ("CreateZoneCylinder : ZoneName = " << ZoneName ) ;
2006 SALOME::ExceptionStruct es;
2009 { es.text = "The radius must be positive." ;
2011 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2012 if ( daux < 0.0000001 )
2013 { es.text = "The axis must be a non 0 vector." ;
2016 { es.text = "The height must be positive." ;
2020 es.type = SALOME::BAD_PARAM;
2021 throw SALOME::SALOME_Exception(es);
2025 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 5) ;
2026 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut ) ;
2028 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2030 //=============================================================================
2031 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZonePipe(const char* ZoneName,
2032 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2033 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2034 CORBA::Double Rayon, CORBA::Double Haut, CORBA::Double Rayonint)
2036 INFOS ("CreateZonePipe : ZoneName = " << ZoneName ) ;
2038 SALOME::ExceptionStruct es;
2040 if ( Rayon <= 0.0 or Rayonint <= 0.0 )
2041 { es.text = "The radius must be positive." ;
2043 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2044 if ( daux < 0.0000001 )
2045 { es.text = "The axis must be a non 0 vector." ;
2048 { es.text = "The height must be positive." ;
2050 if ( Rayon <= Rayonint )
2051 { es.text = "The external radius must be higher than the internal radius." ;
2055 es.type = SALOME::BAD_PARAM;
2056 throw SALOME::SALOME_Exception(es);
2060 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 7) ;
2061 myZone->SetPipe( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut, Rayonint ) ;
2063 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2065 //=============================================================================
2066 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox2D(const char* ZoneName,
2067 CORBA::Double Umini, CORBA::Double Umaxi,
2068 CORBA::Double Vmini, CORBA::Double Vmaxi,
2071 INFOS ("CreateZoneBox2D : ZoneName = " << ZoneName ) ;
2072 // MESSAGE ("Umini = " << Umini << ", Umaxi =" << Umaxi ) ;
2073 // MESSAGE ("Vmini = " << Vmini << ", Vmaxi =" << Vmaxi ) ;
2074 // MESSAGE ("Orient = " << Orient ) ;
2076 SALOME::ExceptionStruct es;
2078 if ( Umini > Umaxi )
2079 { es.text = "The first coordinates are not coherent." ;
2081 if ( Vmini > Vmaxi )
2082 { es.text = "The second coordinates are not coherent." ;
2084 if ( Orient < 1 or Orient > 3 )
2085 { es.text = "The orientation must be 1, 2 or 3." ;
2089 es.type = SALOME::BAD_PARAM;
2090 throw SALOME::SALOME_Exception(es);
2094 double Xmini, Xmaxi ;
2095 double Ymini, Ymaxi ;
2096 double Zmini, Zmaxi ;
2104 else if ( Orient == 2 )
2111 else if ( Orient == 3 )
2118 else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
2120 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 10+Orient) ;
2121 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2123 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2125 //=============================================================================
2126 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDisk(const char* ZoneName,
2127 CORBA::Double Ucentre, CORBA::Double Vcentre,
2128 CORBA::Double Rayon,
2131 INFOS ("CreateZoneDisk : ZoneName = " << ZoneName ) ;
2133 SALOME::ExceptionStruct es;
2136 { es.text = "The radius must be positive." ;
2138 if ( Orient < 1 or Orient > 3 )
2139 { es.text = "The orientation must be 1, 2 or 3." ;
2143 es.type = SALOME::BAD_PARAM;
2144 throw SALOME::SALOME_Exception(es);
2152 { Xcentre = Ucentre ;
2155 else if ( Orient == 2 )
2158 Zcentre = Vcentre ; }
2159 else if ( Orient == 3 )
2160 { Xcentre = Vcentre ;
2162 Zcentre = Ucentre ; }
2163 else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
2165 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 30+Orient) ;
2166 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1. ) ;
2168 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2170 //=============================================================================
2171 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDiskWithHole(const char* ZoneName,
2172 CORBA::Double Ucentre, CORBA::Double Vcentre,
2173 CORBA::Double Rayon, CORBA::Double Rayonint,
2176 INFOS ("CreateZoneDiskWithHole : ZoneName = " << ZoneName ) ;
2178 SALOME::ExceptionStruct es;
2180 if ( Rayon <= 0.0 or Rayonint <= 0.0 )
2181 { es.text = "The radius must be positive." ;
2183 if ( Orient < 1 or Orient > 3 )
2184 { es.text = "The orientation must be 1, 2 or 3." ;
2186 if ( Rayon <= Rayonint )
2187 { es.text = "The external radius must be higher than the internal radius." ;
2191 es.type = SALOME::BAD_PARAM;
2192 throw SALOME::SALOME_Exception(es);
2200 { Xcentre = Ucentre ;
2203 else if ( Orient == 2 )
2206 Zcentre = Vcentre ; }
2207 else if ( Orient == 3 )
2208 { Xcentre = Vcentre ;
2210 Zcentre = Ucentre ; }
2211 else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
2213 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 60+Orient) ;
2214 myZone->SetPipe( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1., Rayonint ) ;
2216 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2218 //=============================================================================
2219 //=============================================================================
2224 //=============================================================================
2225 //=============================================================================
2226 // Traitement d'une iteration
2227 // etatMenage = 1 : destruction du repertoire d'execution
2228 // modeHOMARD = 1 : adaptation
2229 // != 1 : information avec les options modeHOMARD
2230 // Option1 >0 : appel depuis python
2231 // <0 : appel depuis GUI
2232 // Option2 : multiple de nombres premiers
2233 // 1 : aucune option
2234 // x2 : publication du maillage dans SMESH
2235 //=============================================================================
2236 CORBA::Long HOMARD_Gen_i::Compute(const char* NomIteration, CORBA::Long etatMenage, CORBA::Long modeHOMARD, CORBA::Long Option1, CORBA::Long Option2)
2238 INFOS ( "Compute : traitement de " << NomIteration << ", avec modeHOMARD = " << modeHOMARD << ", Option1 = " << Option1 << ", Option2 = " << Option2 );
2243 // A.1. L'objet iteration
2244 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration];
2245 ASSERT(!CORBA::is_nil(myIteration));
2247 // A.2. Numero de l'iteration
2248 // siterp1 : numero de l'iteration a traiter
2250 // siter : numero de l'iteration parent, ou 0 si deja au debut mais cela ne servira pas !
2251 // Ou si information :
2253 int NumeIter = myIteration->GetNumber();
2254 std::string siterp1 ;
2255 std::stringstream saux1 ;
2257 siterp1 = saux1.str() ;
2258 if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
2261 if ( modeHOMARD==1 )
2263 std::stringstream saux0 ;
2264 int iaux = max(0, NumeIter-1) ;
2266 siter = saux0.str() ;
2267 if (NumeIter < 11) { siter = "0" + siter ; }
2270 { siter = siterp1 ; }
2273 const char* nomCas = myIteration->GetCaseName();
2274 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
2275 ASSERT(!CORBA::is_nil(myCase));
2277 // B. Les repertoires
2278 // B.1. Le repertoire courant
2279 std::string nomDirWork = getenv("PWD") ;
2280 // B.2. Le sous-repertoire de l'iteration a traiter
2281 char* DirCompute = ComputeDirManagement(myCase, myIteration, etatMenage);
2282 MESSAGE( ". DirCompute = " << DirCompute );
2284 // C. Le fichier des messages
2285 // C.1. Le deroulement de l'execution de HOMARD
2286 std::string LogFile = DirCompute ;
2287 LogFile += "/Liste" ;
2288 if ( modeHOMARD == 1 ) { LogFile += "." + siter + ".vers." + siterp1 ; }
2290 MESSAGE (". LogFile = " << LogFile);
2291 if ( modeHOMARD == 1 ) { myIteration->SetLogFile(LogFile.c_str()); }
2292 // C.2. Le bilan de l'analyse du maillage
2293 std::string FileInfo = DirCompute ;
2295 if ( modeHOMARD == 1 ) { FileInfo += "apad" ; }
2297 { if ( NumeIter == 0 ) { FileInfo += "info_av" ; }
2298 else { FileInfo += "info_ap" ; }
2300 FileInfo += "." + siterp1 + ".bilan" ;
2301 myIteration->SetFileInfo(FileInfo.c_str());
2303 // D. On passe dans le repertoire de l'iteration a calculer
2304 MESSAGE ( ". On passe dans DirCompute = " << DirCompute );
2307 // E. Les donnees de l'execution HOMARD
2308 // E.1. L'objet du texte du fichier de configuration
2309 HomardDriver* myDriver = new HomardDriver(siter, siterp1);
2310 myDriver->TexteInit(DirCompute, LogFile, _Langue);
2312 // E.2. Le maillage associe a l'iteration
2313 const char* NomMesh = myIteration->GetMeshName();
2314 MESSAGE ( ". NomMesh = " << NomMesh );
2315 const char* MeshFile = myIteration->GetMeshFile();
2316 MESSAGE ( ". MeshFile = " << MeshFile );
2318 // E.3. Les donnees du traitement HOMARD
2320 if ( modeHOMARD == 1 )
2323 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2324 myDriver->TexteMaillage(NomMesh, MeshFile, 1);
2325 codret = ComputeAdap(myCase, myIteration, etatMenage, myDriver, Option1, Option2) ;
2329 InvalideIterInfo(NomIteration);
2330 myDriver->TexteInfo( modeHOMARD, NumeIter ) ;
2332 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2333 myDriver->TexteMaillage(NomMesh, MeshFile, 0);
2334 myDriver->CreeFichierDonn();
2337 // E.4. Ajout des informations liees a l'eventuel suivi de frontiere
2338 DriverTexteBoundary(myCase, myDriver) ;
2340 // E.5. Ecriture du texte dans le fichier
2342 { myDriver->CreeFichier(); }
2346 int codretexec = 12 ;
2349 codretexec = myDriver->ExecuteHomard(Option1);
2351 MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
2352 if ( modeHOMARD == 1 )
2354 if (codretexec == 0) { SetEtatIter(NomIteration,2); }
2355 else { SetEtatIter(NomIteration,1); }
2356 // GERALD -- QMESSAGE BOX
2360 // H. Gestion des resultats
2363 std::string Commentaire ;
2364 // H.1. Le fichier des messages, dans tous les cas
2365 Commentaire = "log" ;
2366 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2367 else { Commentaire += "Info" ; }
2368 PublishFileUnderIteration(NomIteration, LogFile.c_str(), Commentaire.c_str());
2370 // H.2. Si tout s'est bien passe :
2371 if (codretexec == 0)
2373 // H.2.1. Le fichier de bilan
2374 Commentaire = "Summary" ;
2375 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2376 else { Commentaire += "Info" ; }
2377 PublishFileUnderIteration(NomIteration, FileInfo.c_str(), Commentaire.c_str());
2378 // H.2.2. Le fichier de maillage obtenu
2379 if ( modeHOMARD == 1 )
2381 std::stringstream saux0 ;
2382 Commentaire = "Mesh" ;
2383 Commentaire += " " + siterp1 ;
2384 PublishFileUnderIteration(NomIteration, MeshFile, Commentaire.c_str());
2385 if ( Option2 % 2 == 0 ) { PublishResultInSmesh(MeshFile, 1); }
2388 // H.3 Message d'erreur en cas de probleme
2391 SALOME::ExceptionStruct es;
2392 es.type = SALOME::BAD_PARAM;
2393 std::string text = "Error during the adaptation.\n" ;
2396 ifstream fichier(LogFile.c_str(), ios::in);
2398 while(getline(fichier, ligne) and (ligne != "===== HOMARD ===== STOP ====="));
2399 while (getline(fichier, ligne)) { text += ligne+ "\n";};
2402 text += "no log file ....";
2404 es.text = CORBA::string_dup(text.c_str());
2405 throw SALOME::SALOME_Exception(es);
2409 // I. Menage et retour dans le repertoire du cas
2413 MESSAGE ( ". On retourne dans nomDirWork = " << nomDirWork );
2414 chdir(nomDirWork.c_str());
2419 //=============================================================================
2420 // Calcul d'une iteration : partie specifique a l'adaptation
2421 //=============================================================================
2422 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)
2424 MESSAGE ( "ComputeAdap" );
2429 // Etat de l'iteration
2430 int etat = myIteration->GetState();
2431 // Numero de l'iteration
2432 int NumeIter = myIteration->GetNumber();
2433 std::stringstream saux0 ;
2434 saux0 << NumeIter-1 ;
2435 std::string siter = saux0.str() ;
2436 if (NumeIter < 11) { siter = "0" + siter ; }
2438 // A.2. On ne calcule pas l iteration initiale
2441 MESSAGE ( "etat = "<<etat );
2442 SALOME::ExceptionStruct es;
2443 es.type = SALOME::BAD_PARAM;
2444 es.text = "This iteration is the first of the case and cannot be computed.";
2445 throw SALOME::SALOME_Exception(es);
2449 // A.3. On verifie qu il y a une hypothese (erreur improbable);
2450 const char* nomHypo = myIteration->GetHypoName();
2451 if (std::string(nomHypo) == std::string(""))
2453 SALOME::ExceptionStruct es;
2454 es.type = SALOME::BAD_PARAM;
2455 es.text = "This iteration does not have any associated hypothesis.";
2456 throw SALOME::SALOME_Exception(es);
2459 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
2460 ASSERT(!CORBA::is_nil(myHypo));
2462 // B. L'iteration parent
2463 const char* nomIterationParent = myIteration->GetIterParentName();
2464 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
2465 ASSERT(!CORBA::is_nil(myIterationParent));
2466 // Si l'iteration parent n'est pas calculee, on le fait (recursivite amont)
2467 if ( myIterationParent->GetState() == 1 )
2470 int codret = Compute(nomIterationParent, etatMenage, iaux, Option1, Option2);
2473 // GERALD -- QMESSAGE BOX
2474 ASSERT("Pb au calcul de l'iteration precedente" == 0);
2478 // C. Le sous-repertoire de l'iteration precedente
2479 char* DirComputePa = ComputeDirPaManagement(myCase, myIteration);
2480 MESSAGE( ". DirComputePa = " << DirComputePa );
2482 // D. Les donnees de l'adaptation HOMARD
2483 // D.1. Le type de conformite
2484 int ConfType = myCase->GetConfType();
2485 MESSAGE ( ". ConfType = " << ConfType );
2487 // D.2. Le maillage de depart
2488 const char* NomMeshParent = myIterationParent->GetMeshName();
2489 MESSAGE ( ". NomMeshParent = " << NomMeshParent );
2490 const char* MeshFileParent = myIterationParent->GetMeshFile();
2491 MESSAGE ( ". MeshFileParent = " << MeshFileParent );
2493 // D.3. Le maillage associe a l'iteration
2494 const char* MeshFile = myIteration->GetMeshFile();
2495 MESSAGE ( ". MeshFile = " << MeshFile );
2496 FILE *file = fopen(MeshFile,"r");
2500 if (etatMenage == 0)
2502 SALOME::ExceptionStruct es;
2503 es.type = SALOME::BAD_PARAM;
2504 std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
2505 es.text = CORBA::string_dup(text.c_str());
2506 throw SALOME::SALOME_Exception(es);
2511 std::string commande = "rm -f " + std::string(MeshFile);
2512 codret = system(commande.c_str());
2515 SALOME::ExceptionStruct es;
2516 es.type = SALOME::BAD_PARAM;
2517 es.text = "The mesh file cannot be deleted.";
2518 throw SALOME::SALOME_Exception(es);
2524 // D.4. Les types de raffinement et de deraffinement
2525 // Les appels corba sont lourds, il vaut mieux les grouper
2526 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
2527 ASSERT(ListTypes->length() == 3);
2528 int TypeAdap = (*ListTypes)[0];
2529 int TypeRaff = (*ListTypes)[1];
2530 int TypeDera = (*ListTypes)[2];
2532 // E. Texte du fichier de configuration
2533 // E.1. Incontournables du texte
2534 myDriver->TexteAdap();
2536 myDriver->TexteMaillageHOMARD( DirComputePa, siter, iaux ) ;
2537 myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
2538 myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
2540 // E.2. Ajout des informations liees aux zones eventuelles
2541 if ( TypeAdap == 0 )
2542 { DriverTexteZone(myHypo, myDriver) ; }
2544 // E.3. Ajout des informations liees aux champs eventuels
2545 if ( TypeAdap == 1 )
2546 { DriverTexteField(myIteration, myHypo, myDriver) ; }
2548 // E.4. Ajout des informations liees au filtrage eventuel par les groupes
2549 HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
2550 int numberOfGroups = listeGroupes->length();
2551 MESSAGE( ". Filtrage par " << numberOfGroups << " groupes");
2552 if (numberOfGroups > 0)
2554 for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
2556 std::string GroupName = std::string((*listeGroupes)[NumGroup]);
2557 MESSAGE( "... GroupName = " << GroupName );
2558 myDriver->TexteGroup(GroupName);
2562 // E.5. Ajout des informations liees a l'eventuelle interpolation des champs
2563 DriverTexteFieldInterp(myIteration, myHypo, myDriver) ;
2565 // E.6. Ajout des options avancees
2566 int Pyram = myCase->GetPyram();
2567 MESSAGE ( ". Pyram = " << Pyram );
2568 int NivMax = myHypo->GetNivMax();
2569 MESSAGE ( ". NivMax = " << NivMax );
2570 double DiamMin = myHypo->GetDiamMin() ;
2571 MESSAGE ( ". DiamMin = " << DiamMin );
2572 int AdapInit = myHypo->GetAdapInit();
2573 MESSAGE ( ". AdapInit = " << AdapInit );
2574 int LevelOutput = myHypo->GetLevelOutput();
2575 MESSAGE ( ". LevelOutput = " << LevelOutput );
2576 myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, LevelOutput);
2578 // E.7. Ajout des informations sur le deroulement de l'execution
2579 int MessInfo = myIteration->GetInfoCompute();
2580 MESSAGE ( ". MessInfo = " << MessInfo );
2581 myDriver->TexteInfoCompute(MessInfo);
2585 //=============================================================================
2586 // Creation d'un nom de sous-repertoire pour l'iteration au sein d'un repertoire parent
2587 // nomrep : nom du repertoire parent
2588 // num : le nom du sous-repertoire est sous la forme 'In', n est >= num
2589 //=============================================================================
2590 char* HOMARD_Gen_i::CreateDirNameIter(const char* nomrep, CORBA::Long num )
2592 MESSAGE ( "CreateDirNameIter : nomrep ="<< nomrep << ", num = "<<num);
2593 // On verifie que le repertoire parent existe
2594 int codret = chdir(nomrep) ;
2597 SALOME::ExceptionStruct es;
2598 es.type = SALOME::BAD_PARAM;
2599 es.text = "The directory of the case does not exist.";
2600 throw SALOME::SALOME_Exception(es);
2603 std::string nomDirActuel = getenv("PWD") ;
2604 std::string DirName ;
2605 // On boucle sur tous les noms possibles jusqu'a trouver un nom correspondant a un repertoire inconnu
2606 bool a_chercher = true ;
2607 while ( a_chercher )
2609 // On passe dans le repertoire parent
2611 // On recherche un nom sous la forme Iabc, avec abc representant le numero
2613 if ( num < 100 ) { jaux = 2 ; }
2614 else if ( num < 1000 ) { jaux = 3 ; }
2615 else if ( num < 10000 ) { jaux = 4 ; }
2616 else if ( num < 100000 ) { jaux = 5 ; }
2618 std::ostringstream iaux ;
2619 iaux << std::setw(jaux) << std::setfill('0') << num ;
2620 std::ostringstream DirNameA ;
2621 DirNameA << "I" << iaux.str();
2622 // Si on ne pas peut entrer dans le repertoire, on doit verifier
2623 // que c'est bien un probleme d'absence
2624 if ( chdir(DirNameA.str().c_str()) != 0 )
2626 bool existe = false ;
2628 struct dirent *dirp;
2629 dp = opendir(nomrep);
2630 while ( (dirp = readdir(dp)) != NULL )
2632 std::string file_name(dirp->d_name);
2633 if ( file_name == DirNameA.str() ) { existe = true ; }
2638 DirName = DirNameA.str() ;
2639 a_chercher = false ;
2646 MESSAGE ( "==> DirName = " << DirName);
2647 MESSAGE ( ". On retourne dans nomDirActuel = " << nomDirActuel );
2648 chdir(nomDirActuel.c_str());
2650 return CORBA::string_dup( DirName.c_str() );
2652 //=============================================================================
2653 // Calcul d'une iteration : gestion du repertoire de calcul
2654 // Si le sous-repertoire existe :
2655 // etatMenage = 0 : on sort en erreur si le repertoire n'est pas vide
2656 // etatMenage = 1 : on fait le menage du repertoire
2657 // etatMenage = -1 : on ne fait rien
2658 //=============================================================================
2659 char* HOMARD_Gen_i::ComputeDirManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage)
2661 MESSAGE ( "ComputeDirManagement : repertoires pour le calcul" );
2662 // B.2. Le repertoire du cas
2663 const char* nomDirCase = myCase->GetDirName();
2664 MESSAGE ( ". nomDirCase = " << nomDirCase );
2666 // B.3. Le sous-repertoire de l'iteration a calculer, puis le repertoire complet a creer
2667 // B.3.1. Le nom du sous-repertoire
2668 const char* nomDirIt = myIteration->GetDirNameLoc();
2670 // B.3.2. Le nom complet du sous-repertoire
2671 std::stringstream DirCompute ;
2672 DirCompute << nomDirCase << "/" << nomDirIt;
2673 MESSAGE (". DirCompute = " << DirCompute.str() );
2675 // B.3.3. Si le sous-repertoire n'existe pas, on le cree
2676 if (chdir(DirCompute.str().c_str()) != 0)
2678 // Creation du repertoire car il n'existe pas :
2679 if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
2681 // GERALD -- QMESSAGE BOX
2682 std::cerr << "Pb Creation du repertoire DirCompute = " << DirCompute.str() << std::endl;
2683 ASSERT("Pb a la creation du repertoire" == 0);
2688 // Le repertoire existe
2689 // On demande de faire le menage de son contenu :
2690 if (etatMenage == 1)
2692 MESSAGE (". Menage du repertoire DirCompute = " << DirCompute.str());
2693 std::string commande= "rm -rf " + DirCompute.str()+"/*" ;
2694 int codret = system(commande.c_str());
2697 // GERALD -- QMESSAGE BOX
2698 std::cerr << ". Menage du repertoire de calcul" << DirCompute.str() << std::endl;
2699 ASSERT("Pb au menage du repertoire de calcul" == 0);
2702 // On n'a pas demande de faire le menage de son contenu : on sort en erreur :
2705 if (etatMenage == 0)
2708 struct dirent *dirp;
2709 dp = opendir(DirCompute.str().c_str());
2711 while ((dirp = readdir(dp)) != NULL && result )
2713 std::string file_name(dirp->d_name);
2714 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
2717 if ( result == false)
2719 SALOME::ExceptionStruct es;
2720 es.type = SALOME::BAD_PARAM;
2721 std::string text = "Directory : " + DirCompute.str() + "is not empty";
2722 es.text = CORBA::string_dup(text.c_str());
2723 throw SALOME::SALOME_Exception(es);
2724 ASSERT("Directory is not empty" == 0);
2730 return CORBA::string_dup( DirCompute.str().c_str() );
2732 //=============================================================================
2733 // Calcul d'une iteration : gestion du repertoire de calcul de l'iteration parent
2734 //=============================================================================
2735 char* HOMARD_Gen_i::ComputeDirPaManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration)
2737 MESSAGE ( "ComputeDirPaManagement : repertoires pour le calcul" );
2738 // Le repertoire du cas
2739 const char* nomDirCase = myCase->GetDirName();
2740 MESSAGE ( ". nomDirCase = " << nomDirCase );
2742 // Le sous-repertoire de l'iteration precedente
2744 const char* nomIterationParent = myIteration->GetIterParentName();
2745 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
2746 const char* nomDirItPa = myIterationParent->GetDirNameLoc();
2747 std::stringstream DirComputePa ;
2748 DirComputePa << nomDirCase << "/" << nomDirItPa;
2749 MESSAGE( ". nomDirItPa = " << nomDirItPa);
2750 MESSAGE( ". DirComputePa = " << DirComputePa.str() );
2752 return CORBA::string_dup( DirComputePa.str().c_str() );
2754 //=============================================================================
2755 // Calcul d'une iteration : ecriture des zones dans le fichier de configuration
2756 //=============================================================================
2757 void HOMARD_Gen_i::DriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
2759 MESSAGE ( "... DriverTexteZone" );
2760 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
2761 int numberOfZonesx2 = ListZone->length();
2764 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
2766 std::string ZoneName = std::string((*ListZone)[iaux]);
2767 MESSAGE ( "... ZoneName = " << ZoneName);
2768 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
2769 ASSERT(!CORBA::is_nil(myZone));
2771 int ZoneType = myZone->GetType();
2772 std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
2773 int TypeUse = atoi( TypeUsestr.c_str() );
2774 MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
2775 NumZone = iaux/2 + 1 ;
2776 HOMARD::double_array* zone = myZone->GetCoords();
2777 if ( ZoneType == 2 or ( ZoneType>=11 and ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
2778 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.); }
2779 else if ( ZoneType == 4 ) // Cas d une sphere
2780 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.); }
2781 else if ( ZoneType == 5 or ( ZoneType>=31 and ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
2782 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.); }
2783 else if ( ZoneType == 7 or ( ZoneType>=61 and ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
2784 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]); }
2785 else { ASSERT("ZoneType est incorrect." == 0) ; }
2790 //=============================================================================
2791 // Calcul d'une iteration : ecriture des champs dans le fichier de configuration
2792 //=============================================================================
2793 void HOMARD_Gen_i::DriverTexteField(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
2795 MESSAGE ( "... DriverTexteField" );
2796 // Le fichier du champ
2797 char* FieldFile = myIteration->GetFieldFile();
2798 MESSAGE ( ". FieldFile = " << FieldFile );
2799 if (strlen(FieldFile) == 0)
2801 // GERALD -- QMESSAGE BOX
2802 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
2803 ASSERT("The file for the field is not given." == 0);
2805 // Les caracteristiques d'instants
2806 int TimeStep = myIteration->GetTimeStep();
2807 MESSAGE( ". TimeStep = " << TimeStep );
2808 int Rank = myIteration->GetRank();
2809 MESSAGE( ". Rank = " << Rank );
2810 // Les informations sur les champs
2811 HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
2813 const char* FieldName = aInfosHypo->FieldName;
2815 int TypeThR = aInfosHypo->TypeThR;
2816 double ThreshR = aInfosHypo->ThreshR;
2817 int TypeThC = aInfosHypo->TypeThC;
2818 double ThreshC = aInfosHypo->ThreshC;
2819 // Saut entre mailles ou non ?
2820 int UsField = aInfosHypo->UsField;
2821 MESSAGE( ". UsField = " << UsField );
2822 // L'usage des composantes
2823 int UsCmpI = aInfosHypo->UsCmpI;
2824 MESSAGE( ". UsCmpI = " << UsCmpI );
2826 myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
2829 HOMARD::listeComposantsHypo* mescompo = myHypo->GetListComp();
2830 int numberOfCompos = mescompo->length();
2831 MESSAGE( ". numberOfCompos = " << numberOfCompos );
2832 for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
2834 std::string nomCompo = std::string((*mescompo)[NumeComp]);
2835 MESSAGE( "... nomCompo = " << nomCompo );
2836 myDriver->TexteCompo(NumeComp, nomCompo);
2840 //=============================================================================
2841 // Calcul d'une iteration : ecriture des frontieres dans le fichier de configuration
2842 //=============================================================================
2843 void HOMARD_Gen_i::DriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, HomardDriver* myDriver)
2845 MESSAGE ( "... DriverTexteBoundary" );
2846 // On ecrit d'abord la definition des frontieres, puis les liens avec les groupes
2847 std::list<std::string> ListeBoundaryTraitees ;
2848 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
2849 int numberOfitems = ListBoundaryGroupType->length();
2850 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
2851 int BoundaryOption = 1 ;
2852 int NumBoundaryAnalytical = 0 ;
2853 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
2855 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
2856 MESSAGE ( "... BoundaryName = " << BoundaryName);
2858 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
2859 while (it != ListeBoundaryTraitees.end())
2861 MESSAGE ( "..... BoundaryNameTraitee = " << *it);
2862 if ( BoundaryName == *it ) { A_faire = 0 ; }
2867 // Caracteristiques de la frontiere
2868 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
2869 ASSERT(!CORBA::is_nil(myBoundary));
2870 int BoundaryType = myBoundary->GetType();
2871 MESSAGE ( "... BoundaryType = " << BoundaryType );
2872 // Ecriture selon le type
2873 if (BoundaryType == 0) // Cas d une frontiere discrete
2875 const char* MeshName = myBoundary->GetMeshName() ;
2876 const char* MeshFile = myBoundary->GetMeshFile() ;
2877 myDriver->TexteBoundaryDi( MeshName, MeshFile);
2878 if ( BoundaryOption % 2 != 0 ) { BoundaryOption = BoundaryOption*2 ; }
2880 else // Cas d une frontiere analytique
2882 NumBoundaryAnalytical++ ;
2883 HOMARD::double_array* coor = myBoundary->GetCoords();
2884 if (BoundaryType == 1) // Cas d un cylindre
2886 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
2887 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
2889 else if (BoundaryType == 2) // Cas d une sphere
2891 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0., 0.);
2892 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
2894 else if (BoundaryType == 3) // Cas d un cone defini par un axe et un angle
2896 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
2897 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
2899 else if (BoundaryType == 4) // Cas d un cone defini par les 2 rayons
2901 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
2902 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
2905 // Memorisation du traitement
2906 ListeBoundaryTraitees.push_back( BoundaryName );
2909 NumBoundaryAnalytical = 0 ;
2910 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
2912 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
2913 MESSAGE ( "... BoundaryName = " << BoundaryName);
2914 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
2915 ASSERT(!CORBA::is_nil(myBoundary));
2916 int BoundaryType = myBoundary->GetType();
2917 MESSAGE ( "... BoundaryType = " << BoundaryType );
2918 // Recuperation du nom du groupe
2919 std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
2920 MESSAGE ( "... GroupName = " << GroupName);
2921 if (BoundaryType == 0) // Cas d une frontiere discrete
2923 if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
2925 else // Cas d une frontiere analytique
2927 NumBoundaryAnalytical++ ;
2928 myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
2931 myDriver->TexteBoundaryOption(BoundaryOption);
2934 //=============================================================================
2935 // Calcul d'une iteration : ecriture des interpolations dans le fichier de configuration
2936 //=============================================================================
2937 void HOMARD_Gen_i::DriverTexteFieldInterp(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
2939 MESSAGE ( "... DriverTexteFieldInterp" );
2940 int TypeFieldInterp = myHypo->GetTypeFieldInterp();
2941 if (TypeFieldInterp != 0)
2943 // Le fichier des champs
2944 char* FieldFile = myIteration->GetFieldFile();
2945 MESSAGE ( ". FieldFile = " << FieldFile );
2946 if (strlen(FieldFile) == 0)
2948 // GERALD -- QMESSAGE BOX
2949 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
2950 ASSERT("The file for the field is not given." == 0);
2952 // Les caracteristiques d'instants
2953 int TimeStep = myIteration->GetTimeStep();
2954 MESSAGE( ". TimeStep = " << TimeStep );
2955 int Rank = myIteration->GetRank();
2956 MESSAGE( ". Rank = " << Rank );
2958 const char* MeshFile = myIteration->GetMeshFile();
2959 myDriver->TexteFieldInterp(TypeFieldInterp, FieldFile, MeshFile, TimeStep, Rank);
2961 if (TypeFieldInterp == 2)
2963 HOMARD::listFieldInterpHypo* meschamps = myHypo->GetListFieldInterp();
2964 int numberOfFields = meschamps->length();
2965 MESSAGE( ". numberOfFields = " << numberOfFields );
2966 for (int NumeChamp = 0; NumeChamp< numberOfFields; NumeChamp++)
2968 std::string nomChamp = std::string((*meschamps)[NumeChamp]);
2969 MESSAGE( "... nomChamp = " << nomChamp );
2970 myDriver->TexteFieldInterpName(NumeChamp, nomChamp);
2976 //===========================================================================
2977 //===========================================================================
2980 //===========================================================================
2981 //===========================================================================
2983 //===========================================================================
2984 //===========================================================================
2985 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
2986 SALOMEDS::SObject_ptr theSObject,
2987 CORBA::Object_ptr theObject,
2988 const char* theName)
2990 MESSAGE("PublishInStudy pour " << theName);
2991 SALOMEDS::SObject_var aResultSO;
2992 if (CORBA::is_nil(theStudy))
2994 SALOME::ExceptionStruct es;
2995 es.type = SALOME::BAD_PARAM;
2996 es.text = "Invalid study context";
2997 throw SALOME::SALOME_Exception(es);
3001 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
3002 // Rq : Iteration est publiee ailleurs
3003 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
3004 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(theObject);
3005 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
3006 HOMARD::HOMARD_YACS_var aYACS = HOMARD::HOMARD_YACS::_narrow(theObject);
3007 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
3009 addInStudy(theStudy);
3011 // Controle de la non publication d'un objet de meme nom
3012 if ( (!aBoundary->_is_nil()) or (!aHypo->_is_nil()) or (!aYACS->_is_nil()) or (!aZone->_is_nil()) )
3014 SALOMEDS::Study::ListOfSObject_var listSO = theStudy->FindObjectByName(theName, ComponentDataType());
3015 if (listSO->length() >= 1)
3017 MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
3018 aResultSO = listSO[0];
3019 return aResultSO._retn();
3023 // Caracteristiques de l'etude
3024 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
3025 aStudyBuilder->NewCommand();
3026 if(!aBoundary->_is_nil())
3027 aResultSO = PublishBoundaryInStudy(theStudy, aStudyBuilder, aBoundary, theName);
3028 else if(!aCase->_is_nil())
3029 aResultSO = PublishCaseInStudy(theStudy, aStudyBuilder, aCase, theName);
3030 else if(!aHypo->_is_nil())
3031 aResultSO = PublishHypotheseInStudy(theStudy, aStudyBuilder, aHypo, theName);
3032 else if(!aZone->_is_nil())
3033 aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName);
3034 else if(!aYACS->_is_nil())
3035 aResultSO = PublishYACSInStudy(theStudy, aStudyBuilder, aYACS, theName);
3037 aStudyBuilder->CommitCommand();
3039 return aResultSO._retn();
3041 //=============================================================================
3042 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy(SALOMEDS::Study_ptr theStudy,
3043 SALOMEDS::StudyBuilder_var aStudyBuilder,
3044 HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
3046 MESSAGE("PublishBoundaryStudy pour "<<theName);
3047 SALOMEDS::SObject_var aResultSO;
3049 // Caracteristique de la Boundary
3050 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[theName];
3052 // On recupere le module pere dans l etude
3053 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3054 if (theFatherHomard->_is_nil())
3056 MESSAGE("theFatherHomard->_is_nil()");
3057 return aResultSO._retn();
3060 // On ajoute la categorie des boundarys dans l etude si necessaire
3061 if ( _tag_boun == 0 )
3064 _tag_boun = _tag_gene ;
3066 MESSAGE("PublishBoundaryInStudy _tag_gene = "<<_tag_gene << ", _tag_boun = "<<_tag_boun );
3067 SALOMEDS::SObject_var aSObject;
3068 if (!theFatherHomard->FindSubObject(_tag_boun, aSObject))
3070 MESSAGE("Ajout de la categorie des boundarys");
3071 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_boun);
3072 PublishInStudyAttr(aStudyBuilder, aSObject, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
3074 else { MESSAGE("La categorie des boundarys existe deja."); }
3076 CORBA::Long BoundaryType = myBoundary->GetType();
3077 // MESSAGE("BoundaryType : "<<BoundaryType);
3080 switch (BoundaryType)
3083 { value = "BoundaryDiHomard" ;
3084 icone = "mesh_tree_mesh.png" ;
3088 { value = "BoundaryAnHomard" ;
3089 icone = "cylinderpointvector_2.png" ;
3093 { value = "BoundaryAnHomard" ;
3094 icone = "spherepoint_2.png" ;
3098 { value = "BoundaryAnHomard" ;
3099 icone = "conepointvector.png" ;
3103 { value = "BoundaryAnHomard" ;
3104 icone = "conedxyz.png" ;
3108 aResultSO = aStudyBuilder->NewObject(aSObject);
3109 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value.c_str(), icone.c_str(), _orb->object_to_string(theObject));
3110 return aResultSO._retn();
3112 //=============================================================================
3113 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::Study_ptr theStudy,
3114 SALOMEDS::StudyBuilder_var aStudyBuilder,
3115 HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
3117 MESSAGE("PublishCaseInStudy pour "<<theName);
3118 SALOMEDS::SObject_var aResultSO;
3120 if (CORBA::is_nil(theObject)) {
3121 MESSAGE("HOMARD_Gen_i::theObject->_is_nil()");
3122 return aResultSO._retn();
3124 if (theStudy->_is_nil()) {
3125 MESSAGE("HOMARD_Gen_i::theStudy->_is_nil()");
3126 return aResultSO._retn();
3129 // On recupere le module pere dans l etude
3130 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3131 if (theFatherHomard->_is_nil())
3133 MESSAGE("theFatherHomard->_is_nil()");
3134 return aResultSO._retn();
3138 MESSAGE("PublishCaseInStudy _tag_gene = "<<_tag_gene );
3139 aResultSO = aStudyBuilder->NewObject(theFatherHomard);
3140 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
3141 _orb->object_to_string(theObject) ) ;
3143 return aResultSO._retn();
3145 //=============================================================================
3146 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::Study_ptr theStudy,
3147 SALOMEDS::StudyBuilder_var aStudyBuilder,
3148 HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
3150 MESSAGE("PublishHypotheseInStudy pour "<<theName);
3151 SALOMEDS::SObject_var aResultSO;
3153 // On recupere le module pere dans l etude
3154 // On ajoute la categorie des hypotheses dans l etude si necessaire
3155 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3156 if (theFatherHomard->_is_nil())
3158 MESSAGE("theFatherHomard->_is_nil()");
3159 return aResultSO._retn();
3162 // On ajoute la categorie des hypotheses dans l etude si necessaire
3163 SALOMEDS::SObject_var aSObject;
3164 if ( _tag_hypo == 0 )
3167 _tag_hypo = _tag_gene ;
3169 MESSAGE("PublishHypotheseInStudy _tag_gene = "<<_tag_gene << ", _tag_hypo = "<<_tag_hypo );
3170 if (!theFatherHomard->FindSubObject(_tag_hypo, aSObject))
3172 MESSAGE("Ajout de la categorie des hypotheses");
3173 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_hypo);
3174 PublishInStudyAttr(aStudyBuilder, aSObject, "Hypothesis", "HypoList", "hypotheses.png", NULL);
3176 else { MESSAGE("La categorie des hypotheses existe deja."); }
3178 // Creation du resultat dans l'etude
3179 aResultSO = aStudyBuilder->NewObject(aSObject);
3180 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
3182 return aResultSO._retn();
3184 //=============================================================================
3185 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishYACSInStudy(SALOMEDS::Study_ptr theStudy,
3186 SALOMEDS::StudyBuilder_var aStudyBuilder,
3187 HOMARD::HOMARD_YACS_ptr theObject, const char* theName)
3189 MESSAGE("PublishYACSInStudy pour "<<theName);
3190 SALOMEDS::SObject_var aResultSO;
3192 // On recupere le module pere dans l etude
3193 // On ajoute la categorie des schemas YACS dans l etude si necessaire
3194 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3195 if (theFatherHomard->_is_nil())
3197 MESSAGE("theFatherHomard->_is_nil()");
3198 return aResultSO._retn();
3200 // On ajoute la categorie des schemas YACS dans l etude si necessaire
3201 if ( _tag_yacs == 0 )
3204 _tag_yacs = _tag_gene ;
3206 MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_yacs = "<<_tag_yacs );
3207 SALOMEDS::SObject_var aSObject;
3208 if (!theFatherHomard->FindSubObject(_tag_yacs, aSObject))
3210 MESSAGE("Ajout de la categorie des schemas YACS");
3211 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_yacs);
3212 PublishInStudyAttr(aStudyBuilder, aSObject, "YACS", "YACSList", "full_view.png", NULL);
3214 else { MESSAGE("La categorie des schemas YACS existe deja."); }
3216 // Creation du resultat dans l'etude
3217 aResultSO = aStudyBuilder->NewObject(aSObject);
3218 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "YACSHomard", "schema.png", _orb->object_to_string(theObject) ) ;
3220 return aResultSO._retn();
3223 //=============================================================================
3224 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::Study_ptr theStudy,
3225 SALOMEDS::StudyBuilder_var aStudyBuilder,
3226 HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
3228 MESSAGE("PublishZoneStudy pour "<<theName);
3229 SALOMEDS::SObject_var aResultSO;
3230 if (CORBA::is_nil(theObject))
3232 MESSAGE("PublishZoneInStudy : theObject->_is_nil()");
3233 return aResultSO._retn();
3235 if (theStudy->_is_nil())
3237 MESSAGE("PublishZoneInStudy : theStudy->_is_nil()");
3238 return aResultSO._retn();
3240 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3241 if (theFatherHomard->_is_nil())
3243 MESSAGE("PublishZoneInStudy : theFatherHomard->_is_nil()");
3244 return aResultSO._retn();
3247 // Caracteristique de la zone
3248 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[theName];
3249 CORBA::Long ZoneType = myZone->GetType();
3251 // On ajoute la categorie des zones dans l etude si necessaire
3252 if ( _tag_zone == 0 )
3255 _tag_zone = _tag_gene ;
3257 MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_zone = "<<_tag_zone );
3258 SALOMEDS::SObject_var aSObject;
3259 if (!theFatherHomard->FindSubObject(_tag_zone, aSObject))
3261 MESSAGE("Ajout de la categorie des zones");
3262 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_zone);
3263 PublishInStudyAttr(aStudyBuilder, aSObject, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
3265 else { MESSAGE("La categorie des zones existe deja."); }
3267 aResultSO = aStudyBuilder->NewObject(aSObject);
3276 { icone = "boxdxy_2.png" ;
3280 { icone = "boxdxyz_2.png" ;
3288 { icone = "disk_2.png" ;
3292 { icone = "spherepoint_2.png" ;
3296 { icone = "cylinderpointvector_2.png" ;
3304 { icone = "diskwithhole_2.png" ;
3308 { icone = "pipe_2.png" ;
3312 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone.c_str(), _orb->object_to_string(theObject) ) ;
3314 return aResultSO._retn();
3316 //===========================================================================
3317 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
3318 SALOMEDS::SObject_var aResultSO,
3319 const char* name, const char* comment, const char* icone, const char* ior)
3321 MESSAGE("PublishInStudyAttr pour name = "<<name<<", comment = "<<comment);
3322 // MESSAGE("icone = "<<icone);
3323 // MESSAGE("ior = "<<ior);
3324 SALOMEDS::GenericAttribute_var anAttr ;
3328 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
3329 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
3330 aNameAttrib->SetValue(name);
3333 // Ajout du commentaire
3334 if ( comment != NULL )
3336 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
3337 SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
3338 aCommentAttrib->SetValue(comment);
3342 if ( icone != NULL )
3344 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
3345 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
3346 aPixmap->SetPixMap(icone);
3352 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
3353 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3354 anIOR->SetValue(ior);
3358 //=====================================================================================
3359 void HOMARD_Gen_i::PublishBoundaryUnderCase(const char* CaseName, const char* BoundaryName)
3361 MESSAGE ( "PublishBoundaryUnderCase : CaseName = " << CaseName << ", BoundaryName= " << BoundaryName );
3363 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3364 ASSERT(!CORBA::is_nil(myCase));
3365 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3366 ASSERT(!CORBA::is_nil(aCaseSO));
3368 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3369 ASSERT(!CORBA::is_nil(myBoundary));
3370 SALOMEDS::SObject_var aBoundarySO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myBoundary)));
3371 ASSERT(!CORBA::is_nil(aBoundarySO));
3373 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3375 aStudyBuilder->NewCommand();
3377 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aCaseSO);
3378 aStudyBuilder->Addreference(aSubSO, aBoundarySO);
3380 aStudyBuilder->CommitCommand();
3383 //=====================================================================================
3384 void HOMARD_Gen_i::PublishCaseUnderYACS(const char* nomYACS, const char* CaseName)
3386 MESSAGE ( "PublishCaseUnderYACS : nomYACS = " << nomYACS << ", CaseName= " << CaseName );
3388 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3389 ASSERT(!CORBA::is_nil(myYACS));
3390 SALOMEDS::SObject_var aYACSSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3391 ASSERT(!CORBA::is_nil(aYACSSO));
3393 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3394 ASSERT(!CORBA::is_nil(myCase));
3395 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3396 ASSERT(!CORBA::is_nil(aCaseSO));
3398 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3400 aStudyBuilder->NewCommand();
3402 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3403 aStudyBuilder->Addreference(aSubSO, aCaseSO);
3405 aStudyBuilder->CommitCommand();
3408 //=============================================================================
3409 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long Option)
3410 // Option = 0 : fichier issu d'une importation
3411 // Option = 1 : fichier issu d'une execution HOMARD
3413 MESSAGE( "PublishResultInSmesh " << NomFich << ", avec Option = " << Option);
3414 if (CORBA::is_nil(myCurrentStudy))
3416 SALOME::ExceptionStruct es;
3417 es.type = SALOME::BAD_PARAM;
3418 es.text = "Invalid study context";
3419 throw SALOME::SALOME_Exception(es);
3423 // Le module SMESH est-il actif ?
3424 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3426 if (!CORBA::is_nil(aSmeshSO))
3428 // On verifie que le fichier n est pas deja publie
3429 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3430 for (; aIter->More(); aIter->Next())
3432 SALOMEDS::SObject_var aSO = aIter->Value();
3433 SALOMEDS::GenericAttribute_var aGAttr;
3434 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3436 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3437 CORBA::String_var value=anAttr->Value();
3438 if (strcmp((const char*)value,NomFich) == 0)
3440 MESSAGE ( "PublishResultInSmesh : le fichier " << NomFich << " est deja publie." );
3441 // Pour un fichier importe, on ne republie pas
3446 // Pour un fichier calcule, on commence par faire la depublication
3449 MESSAGE ( "PublishResultInSmesh : depublication" );
3450 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3451 CORBA::String_var value2=anAttr2->Value();
3452 std::string MeshName = string(value2) ;
3453 MESSAGE ( "PublishResultInSmesh : depublication de " << MeshName );
3454 DeleteResultInSmesh(NomFich, MeshName) ;
3461 // On enregistre le fichier
3462 MESSAGE( "Enregistrement du fichier");
3463 SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
3464 SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
3465 ASSERT(!CORBA::is_nil(aSmeshEngine));
3466 aSmeshEngine->SetCurrentStudy(myCurrentStudy);
3467 SMESH::DriverMED_ReadStatus theStatus;
3468 //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3470 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
3471 SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3472 for (int i = 0; i < mesMaillages->length(); i++)
3474 MESSAGE( ". Mise a jour des attributs du maillage");
3475 SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
3476 SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
3477 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3478 SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
3479 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3480 anAttr->SetValue(NomFich);
3481 SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
3482 SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
3484 if ( Option == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
3485 else { icone = "mesh_tree_mesh.png" ; }
3486 anAttr2->SetPixMap( icone );
3490 //=============================================================================
3491 void HOMARD_Gen_i::DeleteResultInSmesh(std::string NomFich, std::string MeshName)
3493 MESSAGE ("DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich );
3494 if (CORBA::is_nil(myCurrentStudy))
3496 SALOME::ExceptionStruct es;
3497 es.type = SALOME::BAD_PARAM;
3498 es.text = "Invalid study context";
3499 throw SALOME::SALOME_Exception(es);
3503 // Le module SMESH est-il actif ?
3504 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3506 if (CORBA::is_nil(aSmeshSO))
3510 // On verifie que le fichier est deja publie
3511 SALOMEDS::StudyBuilder_var myBuilder = myCurrentStudy->NewBuilder();
3512 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3513 for (; aIter->More(); aIter->Next())
3515 SALOMEDS::SObject_var aSO = aIter->Value();
3516 SALOMEDS::GenericAttribute_var aGAttr;
3517 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3519 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3520 CORBA::String_var value=anAttr->Value();
3521 if (strcmp((const char*)value,NomFich.c_str()) == 0)
3523 if (aSO->FindAttribute(aGAttr,"AttributeName"))
3525 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3526 CORBA::String_var value2=anAttr2->Value();
3527 if (strcmp((const char*)value2,MeshName.c_str()) == 0)
3529 myBuilder->RemoveObjectWithChildren( aSO ) ;
3537 //=============================================================================
3538 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
3540 // MESSAGE ("PublishFileUnderIteration pour l'iteration " << NomIter << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3541 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
3543 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
3544 if (CORBA::is_nil(myIteration))
3546 SALOME::ExceptionStruct es;
3547 es.type = SALOME::BAD_PARAM;
3548 es.text = "Invalid iterationStudy Object";
3549 throw SALOME::SALOME_Exception(es);
3553 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3555 aStudyBuilder->NewCommand();
3557 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
3558 // Pour les fichiers med, on affiche une icone de maillage
3559 // Pour les fichiers qui sont du texte, on affiche une icone de fichier texte 'texte'
3560 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
3562 std::string ior = " " ;
3563 if ( Commentaire[0] == 'I' )
3564 { icone = "med.png" ; }
3566 { icone = "texte_2.png" ; }
3567 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3569 aStudyBuilder->CommitCommand();
3572 //=============================================================================
3573 void HOMARD_Gen_i::PublishFileUnderYACS(const char* nomYACS, const char* NomFich, const char* Commentaire)
3575 // MESSAGE ("PublishFileUnderYACS pour le schema " << nomYACS << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3576 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3578 SALOMEDS::SObject_var aYACSSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3579 if (CORBA::is_nil(myYACS))
3581 SALOME::ExceptionStruct es;
3582 es.type = SALOME::BAD_PARAM;
3583 es.text = "Invalid YACSStudy Object";
3584 throw SALOME::SALOME_Exception(es);
3588 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3590 aStudyBuilder->NewCommand();
3592 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3593 std::string icone = "texte_2.png" ;
3594 std::string ior = " " ;
3595 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3597 aStudyBuilder->CommitCommand();
3600 //=============================================================================
3601 //=============================================================================
3603 //=============================================================================
3604 //=============================================================================
3605 //=============================================================================
3606 // Creation d'un schema YACS
3607 // nomCas : nom du cas a traiter
3608 // FileName : nom du fichier contenant le script de lancement du calcul
3609 // DirName : le repertoire de lancement des calculs du schéma
3610 //=============================================================================
3611 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::CreateYACSSchema (const char* nomYACS, const char* nomCas, const char* ScriptFile, const char* DirName, const char* MeshFile)
3613 INFOS ( "CreateYACSSchema : Schema YACS " << nomYACS );
3614 INFOS ( ". nomCas : " << nomCas);
3615 INFOS ( ". ScriptFile : " << ScriptFile);
3616 INFOS ( ". DirName : " << DirName);
3617 INFOS ( ". MeshFile : " << MeshFile);
3619 // A. Controle du nom :
3620 if ((myContextMap[GetCurrentStudyID()]._mesYACSs).find(nomYACS) != (myContextMap[GetCurrentStudyID()]._mesYACSs).end())
3622 SALOME::ExceptionStruct es;
3623 es.type = SALOME::BAD_PARAM;
3624 es.text = "This schema YACS has already been defined.";
3625 throw SALOME::SALOME_Exception(es);
3629 // B. Creation de l'objet
3630 HOMARD::HOMARD_YACS_var myYACS = newYACS();
3631 if (CORBA::is_nil(myYACS))
3633 SALOME::ExceptionStruct es;
3634 es.type = SALOME::BAD_PARAM;
3635 es.text = "Unable to create the schema YACS";
3636 throw SALOME::SALOME_Exception(es);
3639 myYACS->SetName( nomYACS ) ;
3641 // C. Enregistrement
3642 myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS] = myYACS;
3644 SALOMEDS::SObject_var aSO;
3645 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myYACS, nomYACS);
3647 PublishCaseUnderYACS(nomYACS, nomCas);
3649 // D. Caracterisation
3650 myYACS->SetDirName( DirName ) ;
3651 myYACS->SetMeshFile( MeshFile ) ;
3652 myYACS->SetScriptFile( ScriptFile ) ;
3653 myYACS->SetCaseName( nomCas ) ;
3654 myYACS->SetType( 1 ) ;
3656 return HOMARD::HOMARD_YACS::_duplicate(myYACS);
3658 //=============================================================================
3659 // Ecriture d'un schema YACS
3660 //=============================================================================
3661 CORBA::Long HOMARD_Gen_i::YACSWrite(const char* nomYACS)
3663 INFOS ( "YACSWrite : Ecriture de " << nomYACS );
3664 // Le repertoire du cas
3665 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3666 ASSERT(!CORBA::is_nil(myYACS));
3667 std::string casename = myYACS->GetCaseName() ;
3668 HOMARD::HOMARD_Cas_ptr caseyacs = GetCase(casename.c_str()) ;
3669 std::string dirnamecase = caseyacs->GetDirName() ;
3670 // Le nom par defaut du fichier du schema
3671 std::string YACSFile ;
3672 YACSFile = dirnamecase + "/schema.xml" ;
3674 int codret = YACSWriteOnFile(nomYACS, YACSFile.c_str()) ;
3678 //=============================================================================
3679 // Ecriture d'un schema YACS
3680 //=============================================================================
3681 CORBA::Long HOMARD_Gen_i::YACSWriteOnFile(const char* nomYACS, const char* YACSFile)
3683 INFOS ( "YACSWriteOnFile : Ecriture de " << nomYACS << " sur " << YACSFile );
3690 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3691 ASSERT(!CORBA::is_nil(myYACS));
3692 // B.2. Les caracteristiques
3693 std::string DirName = myYACS->GetDirName() ;
3694 std::string MeshFile = myYACS->GetMeshFile() ;
3695 std::string ScriptFile = myYACS->GetScriptFile() ;
3699 const char* nomCas = myYACS->GetCaseName();
3700 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
3701 ASSERT(!CORBA::is_nil(myCase));
3702 // C.2. Les instructions python associees au cas
3703 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
3704 std::string pythonCas = dumpCorbaCase.in();
3705 MESSAGE ("pythonCas :\n"<<pythonCas<<"\n");
3707 // D. Les iterations
3708 // D.1. L'iteration initiale
3709 HOMARD::HOMARD_Iteration_var Iter0 = myCase->GetIter0() ;
3710 std::string Iter0Name = myCase->GetIter0Name() ;
3711 MESSAGE (". Iter0Name = " << Iter0Name);
3712 std::string MeshName = Iter0->GetMeshName();
3713 MESSAGE (". MeshName = " << MeshName);
3714 // D.2. L'iteration numero 1
3715 HOMARD::listeIterFilles* maListe = Iter0->GetIterations();
3716 int numberOfIter = maListe->length();
3717 if ( numberOfIter > 1 )
3719 MESSAGE (". numberOfIter = " << numberOfIter);
3720 SALOME::ExceptionStruct es ;
3721 es.type = SALOME::BAD_PARAM;
3722 std::string text = "Une seule iteration est permise." ;
3723 es.text = CORBA::string_dup(text.c_str());
3724 throw SALOME::SALOME_Exception(es);
3727 std::string Iter1Name = std::string((*maListe)[0]);
3728 MESSAGE ("... Iter1Name = " << Iter1Name);
3729 HOMARD::HOMARD_Iteration_var Iter1 = GetIteration(Iter1Name.c_str()) ;
3730 MESSAGE (". Iter1 = " << Iter1);
3732 // E. L'hypothese pour passer de l'iteration initiale a la suivante
3733 // E.1. La structure
3734 std::string nomHypo = Iter1->GetHypoName();
3735 MESSAGE (". nomHypo = " << nomHypo);
3736 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
3737 ASSERT(!CORBA::is_nil(myHypo));
3738 // E.2. Les caracteristiques de l'adaptation
3739 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
3740 ASSERT(ListTypes->length() == 3);
3741 int TypeAdap = (*ListTypes)[0];
3742 // int TypeRaff = (*ListTypes)[1];
3743 // int TypeDera = (*ListTypes)[2];
3744 // E.3. Les instructions python associees a l'hypothese
3745 CORBA::String_var dumpCorbaHypo = myHypo->GetDumpPython();
3746 std::string pythonHypo = dumpCorbaHypo.in();
3747 MESSAGE ("pythonHypo :\n"<<pythonHypo<<"\n");
3749 // F. Le fichier du schema de reference
3750 // HOMARD_ROOT_DIR : repertoire ou se trouve le module HOMARD
3751 std::string YACSFile_base ;
3752 if ( getenv("HOMARD_ROOT_DIR") != NULL ) { YACSFile_base = getenv("HOMARD_ROOT_DIR") ; }
3755 SALOME::ExceptionStruct es ;
3756 es.type = SALOME::BAD_PARAM;
3757 std::string text = "HOMARD_ROOT_DIR est inconnu." ;
3758 es.text = CORBA::string_dup(text.c_str());
3759 throw SALOME::SALOME_Exception(es);
3762 YACSFile_base += "/share/salome/resources/homard/yacs_01." + _LangueShort + ".xml" ;
3764 MESSAGE("YACSFile_base ="<<YACSFile_base);
3766 // G. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
3767 YACSDriver* myDriver = new YACSDriver(YACSFile, DirName);
3768 std::ifstream fichier( YACSFile_base.c_str() );
3769 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
3771 // G.1. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
3772 std::string ligne; // variable contenant chaque ligne lue
3773 std::string mot_cle;
3774 while ( std::getline( fichier, ligne ) )
3776 // G.1.1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
3777 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
3778 ligne_bis >> mot_cle ;
3779 // G.1.2. Le maillage initial
3780 if ( mot_cle == "DataInit_MeshFile" )
3781 { myDriver->Texte_DataInit_MeshFile(MeshFile); }
3782 // G.1.3. Le script de lancement
3783 else if ( mot_cle == "Alternance_Calcul_HOMARD_Calcul" )
3784 { myDriver->Texte_Alternance_Calcul_HOMARD_Calcul(ScriptFile); }
3785 // G.1.4. Les options du cas
3786 else if ( mot_cle == "Iter_1_Case_Options" )
3787 { myDriver->Texte_Iter_1_Case_Options(pythonCas); }
3788 // G.1.5. Execution de HOMARD : le repertoire du cas
3789 else if ( mot_cle == "HOMARD_Exec_DirName" )
3790 { myDriver->Texte_HOMARD_Exec_DirName(); }
3791 // G.1.6. Execution de HOMARD : le nom du maillage
3792 else if ( mot_cle == "HOMARD_Exec_MeshName" )
3794 myDriver->Texte_HOMARD_Exec_MeshName(MeshName);
3795 std::string node = "Boucle_de_convergence.Alternance_Calcul_HOMARD.Adaptation.p0_Adaptation_HOMARD.HOMARD_Initialisation.p1_Iter_1.CreateCase" ;
3796 myDriver->TexteParametre( node, "MeshName", "string", MeshName ) ;
3798 // G.1.7. Execution de HOMARD : les options de l'hypothese
3799 else if ( mot_cle == "HOMARD_Exec_Hypo_Options" )
3800 { myDriver->Texte_python( pythonHypo, 3, "Hypo" ) ; }
3801 // G.1.8. Zones et frontieres : les creations
3802 else if ( mot_cle == "Iter_1" )
3804 std::string texte_control = myDriver->Texte_Iter_1_control() ;
3805 if ( TypeAdap == 0 ) { texte_control += YACSDriverTexteZone( myHypo, myDriver ) ; }
3806 texte_control += YACSDriverTexteBoundary( myCase, myDriver ) ;
3807 myDriver->TexteAdd(texte_control);
3809 // G.1.9. Les parametres
3810 else if ( mot_cle == "PARAMETRES" )
3811 { myDriver->TexteAddParametres(); }
3812 // G.1.n. La ligne est recopiee telle quelle
3813 else { myDriver->TexteAdd(ligne); }
3815 // G.2. Ecriture du texte dans le fichier
3817 { myDriver->CreeFichier(); }
3821 SALOME::ExceptionStruct es;
3822 es.type = SALOME::BAD_PARAM;
3823 std::string text = "The reference file for the YACS schema cannot be read." ;
3824 es.text = CORBA::string_dup(text.c_str());
3825 throw SALOME::SALOME_Exception(es);
3830 // H. Publication du fichier dans l'arbre
3832 std::string Commentaire = "xml" ;
3833 PublishFileUnderYACS(nomYACS, YACSFile, Commentaire.c_str());
3837 //=============================================================================
3838 // Ecriture d'un schema YACS : ecriture des zones associees a une hypothese
3839 //=============================================================================
3840 std::string HOMARD_Gen_i::YACSDriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, YACSDriver* myDriver)
3842 MESSAGE ( "YACSDriverTexteZone" );
3843 // A. Les zones associees a cette hypothese
3844 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
3845 int numberOfZonesx2 = ListZone->length();
3847 // B. Parcours des zones
3848 std::string texte_control ;
3849 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
3851 // 1. Reperage de la zone
3852 std::string ZoneName = std::string((*ListZone)[iaux]);
3853 MESSAGE ( "\n. ZoneName = " << ZoneName << " - " <<iaux);
3854 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
3855 ASSERT(!CORBA::is_nil(myZone));
3856 // 2. Les instructions python associees a la zone
3857 // La premiere ligne est un commentaire a eliminer
3858 // La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
3859 CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
3860 std::string pythonStructure_0 = dumpCorbaZone.in();
3861 MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
3862 std::istringstream tout (pythonStructure_0) ;
3864 std::string pythonStructure ;
3865 while ( std::getline( tout, ligne ) )
3866 { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
3867 MESSAGE ("pythonStructure :\n"<<pythonStructure);
3868 // 3. Decodage du nom du service
3869 std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
3870 MESSAGE ( "... methode = " << methode);
3871 // 4. Mise en place des instructions
3872 int ZoneType = myZone->GetType();
3873 MESSAGE ( "... ZoneType = " << ZoneType);
3874 std::string texte_control_0 ;
3875 texte_control_0 = myDriver->Texte_Iter_1_Zone(ZoneType, pythonStructure, methode, ZoneName );
3876 texte_control += texte_control_0 ;
3881 return texte_control ;
3883 //=============================================================================
3884 // Ecriture d'un schema YACS : ecriture des frontieres associees au cas
3885 //=============================================================================
3886 std::string HOMARD_Gen_i::YACSDriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, YACSDriver* myDriver)
3888 MESSAGE ( "YACSDriverTexteBoundary" );
3889 // A. Les frontieres associees au cas
3890 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
3891 int numberOfitems = ListBoundaryGroupType->length();
3893 // B. Parcours des frontieres
3894 std::string texte_control ;
3895 std::list<std::string> ListeBoundaryTraitees ;
3896 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3898 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3899 MESSAGE ( "... BoundaryName = " << BoundaryName);
3900 // Attention a n'ecrire la definition qu'une seule fois car elle peut se trouver
3901 // plusieurs fois dans la definition du cas, d'ou la liste ListeBoundaryTraitees
3903 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
3904 while (it != ListeBoundaryTraitees.end())
3906 MESSAGE ( "..... BoundaryNameTraitee = " << *it);
3907 if ( BoundaryName == *it ) { A_faire = 0 ; }
3912 // 1. Caracteristiques de la frontiere
3913 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3914 ASSERT(!CORBA::is_nil(myBoundary));
3915 // 2. Les instructions python associees a la frontiere
3916 // La premiere ligne est un commentaire a eliminer
3917 // La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
3918 CORBA::String_var dumpCorbaBoundary = myBoundary->GetDumpPython();
3919 std::string pythonStructure_0 = dumpCorbaBoundary.in();
3920 MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
3921 std::istringstream tout (pythonStructure_0) ;
3923 std::string pythonStructure ;
3924 while ( std::getline( tout, ligne ) )
3925 { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
3926 MESSAGE ("pythonStructure :\n"<<pythonStructure);
3927 // 3. Decodage du nom du service
3928 std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
3929 MESSAGE ( "... methode = " << methode);
3930 // 4. Mise en place des instructions
3931 int BoundaryType = myBoundary->GetType();
3932 MESSAGE ( "... BoundaryType = " << BoundaryType);
3933 std::string texte_control_0 ;
3934 texte_control_0 = myDriver->Texte_Iter_1_Boundary(BoundaryType, pythonStructure, methode, BoundaryName );
3935 texte_control += texte_control_0 ;
3936 // 5. Memorisation du traitement
3937 ListeBoundaryTraitees.push_back( BoundaryName );
3941 return texte_control ;
3944 //=============================================================================
3945 //=============================================================================
3946 // Next functions are inherited from SALOMEDS::Driver interface
3947 //=============================================================================
3948 //=============================================================================
3949 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
3951 CORBA::Boolean isMultiFile)
3953 MESSAGE ("Save for theURL = "<< theURL);
3954 SALOMEDS::TMPFile_var aStreamFile;
3956 // get temporary directory name
3957 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
3959 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
3960 StudyContext& context = myContextMap[ aStudy->StudyId() ];
3962 // HOMARD data file name
3963 std::string aFileName = "";
3965 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
3966 aFileName += "_HOMARD.dat";
3968 // initialize sequence of file names
3969 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
3970 aFileSeq->length(1);
3971 aFileSeq[0] = CORBA::string_dup(aFileName.c_str()) ;
3973 // get full path to the data file
3974 aFileName = tmpDir + aFileName;
3978 std::ofstream f(aFileName.c_str());
3980 // clear temporary id map
3981 context._idmap.clear();
3986 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
3987 for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
3988 HOMARD::HOMARD_Cas_var aCas = it_case->second;
3989 PortableServer::ServantBase_var aServant = GetServant(aCas);
3990 HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
3992 f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
3993 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
3997 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
3998 for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
3999 HOMARD::HOMARD_Zone_var aZone = it_zone->second;
4000 PortableServer::ServantBase_var aServant = GetServant(aZone);
4001 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4003 f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
4004 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4007 // -> save hypotheses
4008 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4009 for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
4010 HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
4011 PortableServer::ServantBase_var aServant = GetServant(aHypo);
4012 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4014 f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
4015 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4018 // -> save iterations
4019 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4020 for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
4021 HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
4022 PortableServer::ServantBase_var aServant = GetServant(aIter);
4023 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4025 f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
4026 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4029 // -> save boundaries
4030 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4031 for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
4032 HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
4033 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4034 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4035 if (aBoundaryServant) {
4036 f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
4037 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4041 MESSAGE ("close file");
4044 // put temporary files to the stream
4045 MESSAGE ("put temporary files to the stream");
4046 aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq.in(), isMultiFile);
4048 // remove temporary files
4049 MESSAGE ("remove temporary files");
4050 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4052 // return data stream
4053 MESSAGE ("return data stream");
4054 return aStreamFile._retn();
4057 //===========================================================================
4058 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
4060 CORBA::Boolean isMultiFile)
4062 // No specific ASCII persistence
4063 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
4064 return aStreamFile._retn();
4067 //===========================================================================
4068 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
4069 const SALOMEDS::TMPFile& theStream,
4071 CORBA::Boolean isMultiFile)
4073 MESSAGE ("Load pour theURL = "<< theURL);
4074 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
4076 // set current study
4077 if (myCurrentStudy->_is_nil() || aStudy->StudyId() != myCurrentStudy->StudyId())
4078 SetCurrentStudy(aStudy);
4080 // get temporary directory name
4081 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4083 // Convert the stream into sequence of files to process
4084 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
4087 // HOMARD data file name
4088 std::string aFileName = "";
4090 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
4091 aFileName = tmpDir + aFileName + "_HOMARD.dat";
4093 StudyContext& context = myContextMap[ aStudy->StudyId() ];
4097 std::ifstream f(aFileName.c_str());
4100 context._mesCas.clear();
4101 context._mesHypotheses.clear();
4102 context._mesIterations.clear();
4103 context._mesZones.clear();
4104 context._mesBoundarys.clear();
4105 context._idmap.clear();
4111 std::getline(f, line);
4112 std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
4113 std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
4114 std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
4115 std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
4116 std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
4117 std::string yacsSignature = HOMARD::GetSignature(HOMARD::YACS);
4118 if (line.substr(0, bounSignature.size()) == bounSignature) {
4119 // re-create boundary
4120 MESSAGE ("Recreation de la frontiere" );
4121 HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
4122 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4123 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4124 if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
4125 context._mesBoundarys[aBoundary->GetName()] = aBoundary;
4126 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4129 else if (line.substr(0, caseSignature.size()) == caseSignature) {
4131 MESSAGE ("Recreation du cas" );
4132 HOMARD::HOMARD_Cas_var aCase = newCase();
4133 PortableServer::ServantBase_var aServant = GetServant(aCase);
4134 HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4135 if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
4136 context._mesCas[aCase->GetName()] = aCase;
4137 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
4140 else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
4141 // re-create hypothesis
4142 MESSAGE ("Recreation de l hypothese" );
4143 HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
4144 PortableServer::ServantBase_var aServant = GetServant(aHypo);
4145 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4146 if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
4147 context._mesHypotheses[aHypo->GetName()] = aHypo;
4148 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4151 else if (line.substr(0, iterSignature.size()) == iterSignature) {
4152 // re-create iteration
4153 MESSAGE ("Recreation de l iteration" );
4154 HOMARD::HOMARD_Iteration_var aIter = newIteration();
4155 PortableServer::ServantBase_var aServant = GetServant(aIter);
4156 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4157 if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
4158 context._mesIterations[aIter->GetName()] = aIter;
4159 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4162 else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
4163 MESSAGE ("Recreation de la zone" );
4165 HOMARD::HOMARD_Zone_var aZone = newZone();
4166 PortableServer::ServantBase_var aServant = GetServant(aZone);
4167 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4168 if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
4169 context._mesZones[aZone->GetName()] = aZone;
4170 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4173 else if (line.substr(0, zoneSignature.size()) == yacsSignature) {
4174 MESSAGE ("Recreation du schema YACS" );
4176 HOMARD::HOMARD_YACS_var aYACS = newYACS();
4177 PortableServer::ServantBase_var aServant = GetServant(aYACS);
4178 HOMARD_YACS_i* aYACSServant = dynamic_cast<HOMARD_YACS_i*>(aServant.in());
4179 if (aYACSServant && aYACSServant->Restore(line.substr(yacsSignature.size()))) {
4180 context._mesYACSs[aYACS->GetName()] = aYACS;
4181 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aYACSServant);
4190 // Remove temporary files created from the stream
4192 SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4197 //===========================================================================
4198 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
4199 const SALOMEDS::TMPFile& theStream,
4201 CORBA::Boolean isMultiFile)
4203 // No specific ASCII persistence
4204 return Load(theComponent, theStream, theURL, isMultiFile);
4207 //===========================================================================
4208 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
4210 if (theComponent->GetStudy()->StudyId() == GetCurrentStudyID()) {
4211 // clearing study context should be done here:
4212 // - destroy all servants and related CORBA objects
4214 // - remove context from myContextMap
4215 myContextMap.erase(theComponent->GetStudy()->StudyId());
4216 // - nullify myCurrentStudy
4217 myCurrentStudy = SALOMEDS::Study::_nil();
4221 //===========================================================================
4222 char* HOMARD_Gen_i::ComponentDataType()
4224 return CORBA::string_dup("HOMARD");
4227 //===========================================================================
4228 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
4229 const char* IORString,
4230 CORBA::Boolean isMultiFile,
4231 CORBA::Boolean isASCII)
4233 CORBA::String_var aString("");
4234 if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
4235 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4236 CORBA::Object_var anObj = _orb->string_to_object(IORString);
4237 if (!CORBA::is_nil(anObj)) {
4238 PortableServer::ServantBase_var aServant = GetServant(anObj);
4239 PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
4241 std::map<int, PortableServer::ServantBase*>::const_iterator it;
4242 for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
4243 if (it->second == aStorable) {
4244 std::stringstream os;
4246 aString = CORBA::string_dup(os.str().c_str());
4252 return aString._retn();
4255 //===========================================================================
4256 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
4257 const char* aLocalPersistentID,
4258 CORBA::Boolean isMultiFile,
4259 CORBA::Boolean isASCII)
4261 CORBA::String_var aString("");
4262 if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
4263 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4264 int id = atoi(aLocalPersistentID);
4265 if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
4266 CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
4267 if (!CORBA::is_nil(object)) {
4268 aString = _orb->object_to_string(object);
4272 return aString._retn();
4275 //===========================================================================
4276 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
4278 if(CORBA::is_nil(myCurrentStudy))
4281 HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
4282 if(!aCas->_is_nil())
4285 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
4286 if(!aHypo->_is_nil())
4289 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
4290 if(!aZone->_is_nil())
4293 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
4294 if(!aBoundary->_is_nil())
4297 /* Iteration is not published directly
4298 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
4299 if(!aIter->_is_nil())
4305 //===========================================================================
4306 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
4308 // No Copy/Paste support
4312 //===========================================================================
4313 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
4314 CORBA::Long& theObjectID)
4316 // No Copy/Paste support
4317 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
4318 return aStreamFile._retn();
4321 //===========================================================================
4322 CORBA::Boolean HOMARD_Gen_i::CanPaste(const char *theComponentName,
4323 CORBA::Long theObjectID)
4325 // No Copy/Paste support
4329 //===========================================================================
4330 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
4331 CORBA::Long theObjectID,
4332 SALOMEDS::SObject_ptr theSObject)
4334 // No Copy/Paste support
4335 SALOMEDS::SObject_var aResultSO;
4336 return aResultSO._retn();
4339 //===========================================================================
4340 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
4342 PortableServer::Servant aServant = 0;
4343 if (!CORBA::is_nil(theObject)) {
4345 aServant = _poa->reference_to_servant(theObject);
4353 //==========================================================================
4354 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
4355 CORBA::Boolean isPublished,
4356 CORBA::Boolean isMultiFile,
4357 CORBA::Boolean& isValidScript)
4359 MESSAGE ("Entree dans DumpPython");
4361 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
4362 if(CORBA::is_nil(aStudy))
4363 return new Engines::TMPFile(0);
4365 SALOMEDS::SObject_var aSO = aStudy->FindComponent("HOMARD");
4366 if(CORBA::is_nil(aSO))
4367 return new Engines::TMPFile(0);
4369 std::string aScript = "\"\"\"\n";
4370 aScript += "Python script for HOMARD\n";
4371 aScript += "Copyright EDF-R&D 2013\n";
4372 aScript += "\"\"\"\n";
4373 aScript += "__revision__ = \"V1.2\"\n";
4374 aScript += "import HOMARD\n";
4376 aScript += "import salome\n";
4377 aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
4379 aScript += "def RebuildData(theStudy):\n";
4380 aScript += "\thomard.SetCurrentStudy(theStudy)\n";
4383 aScript += "\thomard.SetCurrentStudy(salome.myStudy)\n";
4384 MESSAGE (". Au depart \n"<<aScript);
4387 if (myContextMap[GetCurrentStudyID()]._mesBoundarys.size() > 0)
4389 MESSAGE (". Ecritures des frontieres");
4390 aScript += "#\n# Creation of the boundaries";
4391 aScript += "\n# ==========================";
4393 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4394 for (it_boundary = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
4395 it_boundary != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); ++it_boundary)
4397 HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
4398 CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
4399 std::string dumpBoundary = dumpCorbaBoundary.in();
4400 MESSAGE (dumpBoundary<<"\n");
4401 aScript += dumpBoundary;
4405 if (myContextMap[GetCurrentStudyID()]._mesZones.size() > 0)
4407 MESSAGE (". Ecritures des zones");
4408 aScript += "#\n# Creation of the zones";
4409 aScript += "\n# =====================";
4411 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4412 for ( it_zone = myContextMap[GetCurrentStudyID()]._mesZones.begin();
4413 it_zone != myContextMap[GetCurrentStudyID()]._mesZones.end(); ++it_zone)
4415 HOMARD::HOMARD_Zone_var myZone = (*it_zone).second;
4416 CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4417 std::string dumpZone = dumpCorbaZone.in();
4418 MESSAGE (dumpZone<<"\n");
4419 aScript += dumpZone;
4423 if (myContextMap[GetCurrentStudyID()]._mesHypotheses.size() > 0)
4425 MESSAGE (". Ecritures des hypotheses");
4426 aScript += "#\n# Creation of the hypotheses";
4427 aScript += "\n# ==========================";
4429 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4430 for ( it_hypo = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
4431 it_hypo != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it_hypo++)
4433 HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
4434 CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
4435 std::string dumpHypo = dumpCorbaHypo.in();
4436 MESSAGE (dumpHypo<<"\n");
4437 aScript += dumpHypo;
4441 if (myContextMap[GetCurrentStudyID()]._mesCas.size() > 0)
4443 MESSAGE (". Ecritures des cas");
4444 aScript += "#\n# Creation of the cases";
4445 aScript += "\n# =====================";
4447 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
4448 for (it_cas = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4449 it_cas != myContextMap[GetCurrentStudyID()]._mesCas.end(); it_cas++)
4451 std::string nomCas = (*it_cas).first;
4452 std::string dumpCas = std::string("\n# Creation of the case ") ;
4453 dumpCas += nomCas + std::string("\n");
4454 dumpCas += std::string("\t") + nomCas;
4455 dumpCas += std::string(" = homard.CreateCase(\"") + nomCas + std::string("\", \"");
4457 HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
4458 CORBA::String_var cIter0= myCase->GetIter0Name();
4459 std::string iter0 = cIter0.in();
4461 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[iter0];
4462 CORBA::String_var cMesh0= myIteration->GetMeshFile();
4463 std::string mesh0 = cMesh0.in();
4464 CORBA::String_var cMeshName0= myIteration->GetMeshName();
4465 std::string meshName0 = cMeshName0.in();
4466 dumpCas += meshName0 + std::string("\", \"")+ mesh0 + std::string("\")\n");
4467 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4468 std::string dumpCas2= dumpCorbaCase.in();
4470 MESSAGE (dumpCas<<dumpCas2<<"\n");
4471 aScript += dumpCas + dumpCas2;
4475 if (myContextMap[GetCurrentStudyID()]._mesIterations.size() > 0)
4477 MESSAGE (". Ecritures des iterations");
4478 aScript += "#\n# Creation of the iterations" ;
4479 aScript += "\n# ==========================";
4481 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4482 for (it_iter = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
4483 it_iter != myContextMap[GetCurrentStudyID()]._mesIterations.end(); ++it_iter)
4485 HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
4486 CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
4487 std::string dumpIter = dumpCorbaIter.in();
4488 MESSAGE (dumpIter<<"\n");
4489 aScript += dumpIter;
4493 if (myContextMap[GetCurrentStudyID()]._mesYACSs.size() > 0)
4495 MESSAGE (". Ecritures des schemas YACS");
4496 aScript += "#\n# Creation of the schemas YACS";
4497 aScript += "\n# ============================";
4499 std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it_yacs;
4500 for ( it_yacs = myContextMap[GetCurrentStudyID()]._mesYACSs.begin();
4501 it_yacs != myContextMap[GetCurrentStudyID()]._mesYACSs.end(); ++it_yacs)
4503 HOMARD::HOMARD_YACS_var myYACS = (*it_yacs).second;
4504 CORBA::String_var dumpCorbaYACS = myYACS->GetDumpPython();
4505 std::string dumpYACS = dumpCorbaYACS.in();
4506 MESSAGE (dumpYACS<<"\n");
4507 aScript += dumpYACS;
4510 MESSAGE (". Ecritures finales");
4512 aScript += "\n\tpass";
4515 if( !isMultiFile ) // remove unnecessary tabulation
4516 aScript = RemoveTabulation( aScript );
4518 // MESSAGE ("A ecrire \n"<<aScript);
4519 const size_t aLen = strlen(aScript.c_str());
4520 char* aBuffer = new char[aLen+1];
4521 strcpy(aBuffer, aScript.c_str());
4523 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
4524 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
4526 MESSAGE ("Sortie de DumpPython");
4527 return aStreamFile._retn();
4531 //=============================================================================
4532 //=============================================================================
4534 //=============================================================================
4535 //=============================================================================
4536 void HOMARD_Gen_i::IsValidStudy( )
4538 // MESSAGE( "IsValidStudy" );
4539 if (CORBA::is_nil(myCurrentStudy))
4541 SALOME::ExceptionStruct es;
4542 es.type = SALOME::BAD_PARAM;
4543 es.text = "Invalid study context";
4544 throw SALOME::SALOME_Exception(es);
4549 //=============================================================================
4550 CORBA::Boolean HOMARD_Gen_i::VerifieDir(const char* nomDir)
4552 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
4553 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4554 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
4556 if (std::string(nomDir) == std::string(it->second->GetDirName())) return false;
4560 /*//=============================================================================
4561 void SALOMEException( std::string message )
4563 SALOME::ExceptionStruct es;
4564 es.type = SALOME::BAD_PARAM;
4566 throw SALOME::SALOME_Exception(es);
4569 //=============================================================================
4570 char* HOMARD_Gen_i::getVersion()
4572 #if HOMARD_DEVELOPMENT
4573 return CORBA::string_dup(HOMARD_VERSION_STR"dev");
4575 return CORBA::string_dup(HOMARD_VERSION_STR);
4578 //===============================================================================
4579 // Recuperation de la chaine de caracteres par rapport a l'apparition d'un texte
4580 // ligne : la ligne a manipuler
4581 // texte : le texte a reperer
4582 // option : 0 : la chaine avant le texte
4583 // 1 : la chaine apres le texte
4584 // Si le texte est absent, on retourne la chaine totale
4585 //===============================================================================
4586 std::string HOMARD_Gen_i::GetStringInTexte( const std::string ligne, const std::string texte, int option )
4588 // MESSAGE("GetStringInTexte, recherche de '"<<texte<<"' dans '"<<ligne<<"'"<<", option = "<<option);
4590 std::string chaine = ligne ;
4591 int position = ligne.find_first_of( texte ) ;
4594 if ( option == 0 ) { chaine = ligne.substr( 0, position ) ; }
4595 else { chaine = ligne.substr( position+1 ) ; }
4600 // //===============================================================================
4601 // // Langue de SALOME
4602 // //===============================================================================
4603 void HOMARD_Gen_i::SetLanguageShort(const char* LanguageShort)
4605 MESSAGE ("SetLanguageShort pour LanguageShort = " << LanguageShort );
4606 _LangueShort = LanguageShort ;
4607 if ( _LangueShort == "fr" ) { _Langue = "Francais" ; }
4608 else { _Langue = "English" ; }
4611 char* HOMARD_Gen_i::GetLanguageShort()
4613 // MESSAGE ("GetLanguageShort");
4614 return CORBA::string_dup( _LangueShort.c_str() );
4617 //=============================================================================
4620 PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
4621 PortableServer::POA_ptr poa,
4622 PortableServer::ObjectId* contId,
4623 const char* instanceName,
4624 const char* interfaceName)
4626 MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
4627 HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
4628 return myHOMARD_Gen->getId();