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"
33 #include "HOMARD_version.h"
35 #include "utilities.h"
36 #include "Utils_SINGLETON.hxx"
37 #include "Utils_CorbaException.hxx"
38 #include "SALOMEDS_Tool.hxx"
39 #include "SALOME_LifeCycleCORBA.hxx"
40 #include "SALOMEconfig.h"
41 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
42 #include CORBA_CLIENT_HEADER(SMESH_Gen)
59 //=============================================================================
61 //=============================================================================
62 std::string RemoveTabulation( std::string theScript )
64 std::string::size_type aPos = 0;
65 while( aPos < theScript.length() )
67 aPos = theScript.find( "\n\t", aPos );
68 if( aPos == std::string::npos )
70 theScript.replace( aPos, 2, "\n" );
75 //=============================================================================
77 * standard constructor
79 //=============================================================================
80 HOMARD_Gen_i::HOMARD_Gen_i( CORBA::ORB_ptr orb,
81 PortableServer::POA_ptr poa,
82 PortableServer::ObjectId * contId,
83 const char *instanceName,
84 const char *interfaceName) :
85 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
87 MESSAGE("constructor");
89 _id = _poa->activate_object(_thisObj);
91 myHomard = new ::HOMARD_Gen();
92 _NS = SINGLETON_<SALOME_NamingService>::Instance();
93 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
101 _Langue = "Francais" ;
102 _LangueShort = "fr" ;
104 //=================================
106 * standard destructor
108 //================================
109 HOMARD_Gen_i::~HOMARD_Gen_i()
112 //=============================================================================
113 //=============================================================================
114 // Utilitaires pour l'étude
115 //=============================================================================
116 //=============================================================================
117 void HOMARD_Gen_i::addInStudy(SALOMEDS::Study_ptr theStudy)
119 ASSERT(!CORBA::is_nil(theStudy));
120 MESSAGE("addInStudy: ajout eventuel du composant HOMARD dans current study ID = " << GetCurrentStudyID()) ;
121 SALOMEDS::StudyBuilder_var myBuilder = theStudy->NewBuilder();
123 // Create SComponent labelled 'homard' if it doesn't already exit
124 SALOMEDS::SComponent_var homardFather = theStudy->FindComponent(ComponentDataType());
125 if (CORBA::is_nil(homardFather))
127 myBuilder->NewCommand();
128 MESSAGE("Add Component HOMARD");
130 bool aLocked = theStudy->GetProperties()->IsLocked();
131 if (aLocked) theStudy->GetProperties()->SetLocked(false);
133 homardFather = myBuilder->NewComponent(ComponentDataType());
134 SALOMEDS::GenericAttribute_var anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributeName");
135 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
136 CORBA::Object_var objVarN = _NS->Resolve("/Kernel/ModulCatalog");
137 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
138 SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
139 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent(ComponentDataType());
140 if (!Comp->_is_nil())
142 aName->SetValue(ComponentDataType());
145 anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributePixMap");
146 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
147 aPixmap->SetPixMap("HOMARD_2.png");
148 myBuilder->DefineComponentInstance(homardFather, HOMARD_Gen::_this());
150 if (aLocked) theStudy->GetProperties()->SetLocked(true);
151 myBuilder->CommitCommand();
154 //=============================================================================
155 void HOMARD_Gen_i::SetCurrentStudy(SALOMEDS::Study_ptr theStudy)
157 MESSAGE("SetCurrentStudy: current study Id = " << GetCurrentStudyID());
158 myCurrentStudy = SALOMEDS::Study::_duplicate(theStudy);
159 this->addInStudy(myCurrentStudy);
161 //=============================================================================
162 SALOMEDS::Study_ptr HOMARD_Gen_i::GetCurrentStudy()
163 //=============================================================================
165 MESSAGE("GetCurrentStudy: study Id = " << GetCurrentStudyID());
166 return SALOMEDS::Study::_duplicate(myCurrentStudy);
168 //=============================================================================
169 CORBA::Long HOMARD_Gen_i::GetCurrentStudyID()
170 //=============================================================================
172 return myCurrentStudy->_is_nil() ? -1 : myCurrentStudy->StudyId();
174 //=============================================================================
175 //=============================================================================
177 //=============================================================================
178 //=============================================================================
179 // Utilitaires pour l'iteration
180 //=============================================================================
181 //=============================================================================
182 void HOMARD_Gen_i::SetEtatIter(const char* nomIter, const CORBA::Long Etat)
183 //=====================================================================================
185 MESSAGE( "SetEtatIter : affectation de l'etat " << Etat << " a l'iteration " << nomIter );
186 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
187 if (CORBA::is_nil(myIteration))
189 SALOME::ExceptionStruct es;
190 es.type = SALOME::BAD_PARAM;
191 es.text = "Invalid iteration";
192 throw SALOME::SALOME_Exception(es);
196 myIteration->SetState(Etat);
198 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
199 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
203 icone = "iter0.png" ;
204 else if ( Etat == 2 )
205 icone = "iter_calculee.png" ;
207 icone = "iter_non_calculee.png" ;
208 PublishInStudyAttr(aStudyBuilder, aIterSO, NULL , NULL, icone.c_str(), NULL) ;
210 aStudyBuilder->CommitCommand();
213 //=============================================================================
214 //=============================================================================
216 //=============================================================================
217 //=============================================================================
218 // Destruction des structures identifiees par leurs noms
219 //=============================================================================
220 //=============================================================================
221 CORBA::Long HOMARD_Gen_i::DeleteBoundary(const char* BoundaryName)
223 MESSAGE ( "DeleteBoundary : BoundaryName = " << BoundaryName );
224 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
225 if (CORBA::is_nil(myBoundary))
227 SALOME::ExceptionStruct es;
228 es.type = SALOME::BAD_PARAM;
229 es.text = "Invalid boundary";
230 throw SALOME::SALOME_Exception(es);
234 // On verifie que la frontiere n'est plus utilisee
235 HOMARD::listeCases* maListe = GetAllCasesName();
236 int numberOfCases = maListe->length();
237 MESSAGE ( ".. Nombre de cas = " << numberOfCases );
238 std::string CaseName ;
239 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType ;
241 HOMARD::HOMARD_Cas_var myCase ;
242 for (int NumeCas = 0; NumeCas< numberOfCases; NumeCas++)
244 CaseName = std::string((*maListe)[NumeCas]);
245 MESSAGE ( "... Examen du cas = " << CaseName.c_str() );
246 myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
247 ASSERT(!CORBA::is_nil(myCase));
248 ListBoundaryGroupType = myCase->GetBoundaryGroup();
249 numberOfitems = ListBoundaryGroupType->length();
250 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
251 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
253 if ( std::string((*ListBoundaryGroupType)[NumBoundary]) == BoundaryName )
255 SALOME::ExceptionStruct es;
256 es.type = SALOME::BAD_PARAM;
257 es.text = "This boundary is used in a case and cannot be deleted.";
258 throw SALOME::SALOME_Exception(es);
264 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
265 myContextMap[GetCurrentStudyID()]._mesBoundarys.erase(BoundaryName);
266 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(BoundaryName, ComponentDataType());
267 SALOMEDS::SObject_var aSO =listSO[0];
268 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
269 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
273 //=============================================================================
274 CORBA::Long HOMARD_Gen_i::DeleteCase(const char* nomCas, CORBA::Long Option)
276 // Pour detruire un cas
277 MESSAGE ( "DeleteCase : nomCas = " << nomCas << ", avec option = " << Option );
278 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
279 if (CORBA::is_nil(myCase))
281 SALOME::ExceptionStruct es;
282 es.type = SALOME::BAD_PARAM;
283 es.text = "Invalid case context";
284 throw SALOME::SALOME_Exception(es);
287 // On commence par detruire toutes les iterations en partant de l'initiale et y compris elle
288 CORBA::String_var nomIter = myCase->GetIter0Name();
289 CORBA::Long Option1 = 0 ;
290 if ( DeleteIterationOption(nomIter, Option1, Option) != 0 )
295 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
296 myContextMap[GetCurrentStudyID()]._mesCas.erase(nomCas);
297 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomCas, ComponentDataType());
298 SALOMEDS::SObject_var aSO =listSO[0];
299 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
300 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
304 //=============================================================================
305 CORBA::Long HOMARD_Gen_i::DeleteHypo(const char* nomHypo)
307 MESSAGE ( "DeleteHypo : nomHypo = " << nomHypo );
308 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
309 if (CORBA::is_nil(myHypo))
311 SALOME::ExceptionStruct es;
312 es.type = SALOME::BAD_PARAM;
313 es.text = "Invalid hypothesis";
314 throw SALOME::SALOME_Exception(es);
318 // On verifie que l'hypothese n'est plus utilisee
319 HOMARD::listeIters* maListeIter = myHypo->GetIterations();
320 int numberOfIter = maListeIter->length();
321 if ( numberOfIter > 0 )
323 SALOME::ExceptionStruct es;
324 es.type = SALOME::BAD_PARAM;
325 es.text = "This hypothesis is used in an iteration and cannot be deleted.";
326 throw SALOME::SALOME_Exception(es);
330 // suppression du lien avec les zones eventuelles
331 HOMARD::listeZonesHypo* maListe = myHypo->GetZones();
332 int numberOfZones = maListe->length();
333 MESSAGE ( ".. Nombre de zones = " << numberOfZones );
334 for (int NumeZone = 0; NumeZone< numberOfZones; NumeZone++)
336 std::string ZoneName = std::string((*maListe)[NumeZone]);
337 MESSAGE ( ".. suppression du lien avec la zone = " << ZoneName.c_str() );
338 DissociateHypoZone(nomHypo, ZoneName.c_str()) ;
342 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
343 myContextMap[GetCurrentStudyID()]._mesHypotheses.erase(nomHypo);
344 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomHypo, ComponentDataType());
345 SALOMEDS::SObject_var aSO =listSO[0];
346 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
347 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
351 //=============================================================================
352 CORBA::Long HOMARD_Gen_i::DeleteIteration(const char* nomIter, CORBA::Long Option)
354 // Option = 0 : On ne supprime pas le fichier du maillage associe
355 // Option = 1 : On supprime le fichier du maillage associe
356 // Pour detruire une iteration courante
357 MESSAGE ( "DeleteIteration : nomIter = " << nomIter << ", avec option = " << Option );
358 CORBA::Long Option1 = 1 ;
359 return DeleteIterationOption(nomIter, Option1, Option);
361 //=============================================================================
362 CORBA::Long HOMARD_Gen_i::DeleteIterationOption(const char* nomIter, CORBA::Long Option1, CORBA::Long Option2)
364 // Option1 = 0 : On autorise la destruction de l'iteration 0
365 // Option1 = 1 : On interdit la destruction de l'iteration 0
367 // Option2 = 0 : On ne supprime pas le fichier du maillage associe
368 // Option2 = 1 : On supprime le fichier du maillage associe
369 MESSAGE ( "DeleteIterationOption : nomIter = " << nomIter << ", avec options = " << Option1<< ", " << Option2 );
370 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
371 if (CORBA::is_nil(myIteration))
373 SALOME::ExceptionStruct es;
374 es.type = SALOME::BAD_PARAM;
375 es.text = "Invalid iteration";
376 throw SALOME::SALOME_Exception(es);
380 int numero = myIteration->GetNumber();
381 MESSAGE ( "DeleteIterationOption : numero = " << numero );
382 if ( numero == 0 and Option1 == 1 )
384 SALOME::ExceptionStruct es;
385 es.type = SALOME::BAD_PARAM;
386 es.text = "This iteration cannot be deleted.";
387 throw SALOME::SALOME_Exception(es);
391 // On detruit recursivement toutes les filles
392 HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
393 int numberOfIter = maListe->length();
394 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
396 std::string nomIterFille = std::string((*maListe)[NumeIter]);
397 MESSAGE ( ".. appel recursif de DeleteIterationOption pour nomIter = " << nomIterFille.c_str() );
398 DeleteIterationOption(nomIterFille.c_str(), Option1, Option2);
401 // On arrive ici pour une iteration sans fille
402 MESSAGE ( "Destruction effective de " << nomIter );
403 // On commence par invalider l'iteration pour faire le menage des dependances
404 // et eventuellement du maillage associe
406 if ( numero == 0 ) { option = 0 ; }
407 else { option = Option2 ; }
408 InvalideIterOption(nomIter, option) ;
410 // Retrait dans la descendance de l'iteration parent
413 std::string nomIterationParent = myIteration->GetIterParentName();
414 MESSAGE ( "Retrait dans la descendance de nomIterationParent " << nomIterationParent );
415 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
416 if (CORBA::is_nil(myIterationParent))
418 SALOME::ExceptionStruct es;
419 es.type = SALOME::BAD_PARAM;
420 es.text = "Invalid iteration";
421 throw SALOME::SALOME_Exception(es);
424 myIterationParent->UnLinkNextIteration(nomIter);
427 // suppression du lien avec l'hypothese
430 std::string nomHypo = myIteration->GetHypoName();
431 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
432 ASSERT(!CORBA::is_nil(myHypo));
433 myHypo->UnLinkIteration(nomIter);
436 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
437 myContextMap[GetCurrentStudyID()]._mesIterations.erase(nomIter);
438 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomIter, ComponentDataType());
439 SALOMEDS::SObject_var aSO =listSO[0];
440 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
441 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
442 // on peut aussi faire RemoveObject
443 // MESSAGE ( "Au final" );
444 // HOMARD::listeIterations* Liste = GetAllIterationsName() ;
445 // numberOfIter = Liste->length();
446 // for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
448 // std::string nomIterFille = std::string((*Liste)[NumeIter]);
449 // MESSAGE ( ".. nomIter = " << nomIterFille.c_str() );
454 //=============================================================================
455 CORBA::Long HOMARD_Gen_i::DeleteYACS(const char* nomYACS, CORBA::Long Option)
457 // Option = 0 : On ne supprime pas le fichier du schema associe
458 // Option = 1 : On supprime le fichier du schema associe
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 // Suppression eventuelle du fichier XML
472 std::string nomFichier = myYACS->GetXMLFile();
473 std::string commande = "rm -rf " + nomFichier ;
474 MESSAGE ( "commande = " << commande );
475 if ((system(commande.c_str())) != 0)
477 SALOME::ExceptionStruct es;
478 es.type = SALOME::BAD_PARAM;
479 es.text = "The xml file for the schema YACS cannot be removed." ;
480 throw SALOME::SALOME_Exception(es);
484 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
485 myContextMap[GetCurrentStudyID()]._mesYACSs.erase(nomYACS);
486 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomYACS, ComponentDataType());
487 SALOMEDS::SObject_var aSO =listSO[0];
488 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
489 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
493 //=============================================================================
494 CORBA::Long HOMARD_Gen_i::DeleteZone(const char* nomZone)
496 MESSAGE ( "DeleteZone : nomZone = " << nomZone );
497 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[nomZone];
498 if (CORBA::is_nil(myZone))
500 SALOME::ExceptionStruct es;
501 es.type = SALOME::BAD_PARAM;
502 es.text = "Invalid zone";
503 throw SALOME::SALOME_Exception(es);
507 // On verifie que la zone n'est plus utilisee
508 HOMARD::listeHypo* maListe = myZone->GetHypo();
509 int numberOfHypo = maListe->length();
510 MESSAGE ( ".. Nombre d'hypotheses = " << numberOfHypo );
511 if ( numberOfHypo > 0 )
513 SALOME::ExceptionStruct es;
514 es.type = SALOME::BAD_PARAM;
515 es.text = "This zone is used in an hypothesis and cannot be deleted.";
516 throw SALOME::SALOME_Exception(es);
520 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
521 myContextMap[GetCurrentStudyID()]._mesZones.erase(nomZone);
522 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomZone, ComponentDataType());
523 SALOMEDS::SObject_var aSO =listSO[0];
524 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
525 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
529 //=============================================================================
530 //=============================================================================
532 //=============================================================================
533 //=============================================================================
534 // Invalidation des structures identifiees par leurs noms
535 //=============================================================================
536 //=============================================================================
537 void HOMARD_Gen_i::InvalideBoundary(const char* BoundaryName)
539 MESSAGE( "InvalideBoundary : BoundaryName = " << BoundaryName );
540 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
541 if (CORBA::is_nil(myBoundary))
543 SALOME::ExceptionStruct es;
544 es.type = SALOME::BAD_PARAM;
545 es.text = "Invalid boundary";
546 throw SALOME::SALOME_Exception(es);
551 SALOME::ExceptionStruct es;
552 es.type = SALOME::BAD_PARAM;
553 es.text = "No change is allowed in a boundary. Ask for evolution.";
554 throw SALOME::SALOME_Exception(es);
558 //=============================================================================
559 void HOMARD_Gen_i::InvalideHypo(const char* nomHypo)
561 MESSAGE( "InvalideHypo : nomHypo = " << nomHypo );
562 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
563 if (CORBA::is_nil(myHypo))
565 SALOME::ExceptionStruct es;
566 es.type = SALOME::BAD_PARAM;
567 es.text = "Invalid hypothesis";
568 throw SALOME::SALOME_Exception(es);
572 HOMARD::listeIters* maListe = myHypo->GetIterations();
573 int numberOfIter = maListe->length();
574 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
576 std::string nomIter = std::string((*maListe)[NumeIter]);
577 MESSAGE( ".. nomIter = " << nomIter );
578 InvalideIter(nomIter.c_str());
581 //=============================================================================
582 void HOMARD_Gen_i::InvalideIter(const char* nomIter)
584 MESSAGE("InvalideIter : nomIter = " << nomIter);
585 // Pour invalider totalement une iteration courante
586 CORBA::Long Option = 1 ;
587 return InvalideIterOption(nomIter, Option);
589 //=============================================================================
590 void HOMARD_Gen_i::InvalideIterOption(const char* nomIter, CORBA::Long Option)
592 // Option = 0 : On ne supprime pas le fichier du maillage associe
593 // Option = 1 : On supprime le fichier du maillage associe
594 MESSAGE ( "InvalideIterOption : nomIter = " << nomIter << ", avec option = " << Option );
595 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
596 if (CORBA::is_nil(myIteration))
598 SALOME::ExceptionStruct es;
599 es.type = SALOME::BAD_PARAM;
600 es.text = "Invalid iteration";
601 throw SALOME::SALOME_Exception(es);
605 HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
606 int numberOfIter = maListe->length();
607 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
609 std::string nomIterFille = std::string((*maListe)[NumeIter]);
610 MESSAGE ( ".. appel recursif de InvalideIter pour nomIter = " << nomIterFille.c_str() );
611 InvalideIter(nomIterFille.c_str());
614 // On arrive ici pour une iteration sans fille
615 MESSAGE ( "Invalidation effective de " << nomIter );
616 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
617 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aIterSO);
618 for (; aIter->More(); aIter->Next())
620 SALOMEDS::SObject_var so = aIter->Value();
621 SALOMEDS::GenericAttribute_var anAttr;
622 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
623 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
624 std::string value (aCommentAttr->Value());
625 if(value == std::string("HypoHomard")) continue;
626 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
627 aStudyBuilder->RemoveObject(so);
630 int etat = myIteration->GetState();
633 SetEtatIter(nomIter,1);
634 const char * nomCas = myIteration->GetCaseName();
635 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
636 if (CORBA::is_nil(myCase))
638 SALOME::ExceptionStruct es;
639 es.type = SALOME::BAD_PARAM;
640 es.text = "Invalid case context";
641 throw SALOME::SALOME_Exception(es);
644 std::string nomDir = myIteration->GetDirName();
645 std::string nomFichier = myIteration->GetMeshFile();
646 std::string commande = "rm -rf " + std::string(nomDir);
647 if ( Option == 1 ) { commande = commande + ";rm -rf " + std::string(nomFichier) ; }
648 MESSAGE ( "commande = " << commande );
649 if ((system(commande.c_str())) != 0)
651 SALOME::ExceptionStruct es;
652 es.type = SALOME::BAD_PARAM;
653 es.text = "The directory for the calculation cannot be cleared." ;
654 throw SALOME::SALOME_Exception(es);
657 // Suppression du maillage publie dans SMESH
658 std::string MeshName = myIteration->GetMeshName() ;
659 DeleteResultInSmesh(nomFichier, MeshName) ;
663 //=============================================================================
664 void HOMARD_Gen_i::InvalideIterInfo(const char* nomIter)
666 MESSAGE("InvalideIterInfo : nomIter = " << nomIter);
667 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
668 if (CORBA::is_nil(myIteration))
670 SALOME::ExceptionStruct es;
671 es.type = SALOME::BAD_PARAM;
672 es.text = "Invalid iteration";
673 throw SALOME::SALOME_Exception(es);
677 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
678 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aIterSO);
679 for (; aIter->More(); aIter->Next())
681 SALOMEDS::SObject_var so = aIter->Value();
682 SALOMEDS::GenericAttribute_var anAttr;
683 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
684 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
685 std::string value (aCommentAttr->Value());
686 /* MESSAGE("... value = " << value);*/
687 if( (value == std::string("logInfo")) or ( value == std::string("SummaryInfo")) )
689 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
690 aStudyBuilder->RemoveObject(so);
694 const char * nomCas = myIteration->GetCaseName();
695 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
696 if (CORBA::is_nil(myCase))
698 SALOME::ExceptionStruct es;
699 es.type = SALOME::BAD_PARAM;
700 es.text = "Invalid case context";
701 throw SALOME::SALOME_Exception(es);
704 const char* nomDir = myIteration->GetDirName();
705 std::string commande = "rm -f " + std::string(nomDir) + "/info* " ;
706 commande += std::string(nomDir) + "/Liste.*info" ;
707 /* MESSAGE ( "commande = " << commande );*/
708 if ((system(commande.c_str())) != 0)
710 SALOME::ExceptionStruct es;
711 es.type = SALOME::BAD_PARAM;
712 es.text = "The directory for the calculation cannot be cleared." ;
713 throw SALOME::SALOME_Exception(es);
717 //=============================================================================
718 void HOMARD_Gen_i::InvalideZone(const char* ZoneName)
720 MESSAGE( "InvalideZone : ZoneName = " << ZoneName );
721 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
722 if (CORBA::is_nil(myZone))
724 SALOME::ExceptionStruct es;
725 es.type = SALOME::BAD_PARAM;
726 es.text = "Invalid zone";
727 throw SALOME::SALOME_Exception(es);
730 HOMARD::listeHypo* maListe = myZone->GetHypo();
731 int numberOfHypo = maListe->length();
732 MESSAGE( ".. numberOfHypo = " << numberOfHypo );
733 for (int NumeHypo = 0; NumeHypo< numberOfHypo; NumeHypo++)
735 std::string nomHypo = std::string((*maListe)[NumeHypo]);
736 MESSAGE( ".. nomHypo = " << nomHypo );
737 InvalideHypo(nomHypo.c_str());
740 //=============================================================================
741 //=============================================================================
743 //=============================================================================
744 //=============================================================================
745 // Association de lien entre des structures identifiees par leurs noms
746 //=============================================================================
747 //=============================================================================
748 void HOMARD_Gen_i::AssociateCaseIter(const char* nomCas, const char* nomIter, const char* labelIter)
750 MESSAGE( "AssociateCaseIter : " << nomCas << ", " << nomIter << ", " << labelIter );
752 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
753 if (CORBA::is_nil(myCase))
755 SALOME::ExceptionStruct es;
756 es.type = SALOME::BAD_PARAM;
757 es.text = "Invalid case";
758 throw SALOME::SALOME_Exception(es);
762 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
763 if (CORBA::is_nil(myIteration))
765 SALOME::ExceptionStruct es;
766 es.type = SALOME::BAD_PARAM;
767 es.text = "Invalid iteration";
768 throw SALOME::SALOME_Exception(es);
772 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
773 SALOMEDS::SObject_var aCasSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
774 if (CORBA::is_nil(aCasSO))
776 SALOME::ExceptionStruct es;
777 es.type = SALOME::BAD_PARAM;
778 es.text = "Invalid case";
779 throw SALOME::SALOME_Exception(es);
783 aStudyBuilder->NewCommand();
784 SALOMEDS::SObject_var newStudyIter = aStudyBuilder->NewObject(aCasSO);
785 PublishInStudyAttr(aStudyBuilder, newStudyIter, nomIter , labelIter,
786 "iter_non_calculee.png", _orb->object_to_string(myIteration)) ;
787 aStudyBuilder->CommitCommand();
789 myCase->AddIteration(nomIter);
790 myIteration->SetCaseName(nomCas);
792 //=====================================================================================
793 void HOMARD_Gen_i::AssociateHypoZone(const char* nomHypothesis, const char* ZoneName, CORBA::Long TypeUse)
795 MESSAGE ( "AssociateHypoZone : nomHypo = " << nomHypothesis << ", ZoneName= " << ZoneName << ", TypeUse = " << TypeUse);
797 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
798 ASSERT(!CORBA::is_nil(myHypo));
799 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
800 ASSERT(!CORBA::is_nil(aHypoSO));
802 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
803 ASSERT(!CORBA::is_nil(myZone));
804 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myZone)));
805 ASSERT(!CORBA::is_nil(aZoneSO));
807 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
809 aStudyBuilder->NewCommand();
811 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aHypoSO);
812 aStudyBuilder->Addreference(aSubSO, aZoneSO);
814 aStudyBuilder->CommitCommand();
816 myZone->AddHypo(nomHypothesis);
817 myHypo->AddZone0(ZoneName, TypeUse);
819 //=============================================================================
820 void HOMARD_Gen_i::AssociateIterHypo(const char* nomIter, const char* nomHypo)
822 MESSAGE("AssociateIterHypo : nomHypo = " << nomHypo << " nomIter = " << nomIter);
824 // Verification de l'existence de l'hypothese
825 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
826 ASSERT(!CORBA::is_nil(myHypo));
827 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
828 ASSERT(!CORBA::is_nil(aHypoSO));
830 // Verification de l'existence de l'iteration
831 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
832 ASSERT(!CORBA::is_nil(myIteration));
833 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
834 ASSERT(!CORBA::is_nil(aIterSO));
836 // Gestion de l'etude
837 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
839 aStudyBuilder->NewCommand();
841 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
842 aStudyBuilder->Addreference(aSubSO, aHypoSO);
844 aStudyBuilder->CommitCommand();
847 myIteration->SetHypoName(nomHypo);
848 myHypo->LinkIteration(nomIter);
850 // On stocke les noms des champ a interpoler pour le futur controle de la donnee des pas de temps
851 myIteration->SupprFieldInterps() ;
852 HOMARD::listeFieldInterpsHypo* ListField = myHypo->GetFieldInterps();
853 int numberOfFieldsx2 = ListField->length();
854 for (int iaux = 0; iaux< numberOfFieldsx2; iaux++)
856 std::string FieldName = std::string((*ListField)[iaux]) ;
857 myIteration->SetFieldInterp(FieldName.c_str()) ;
861 //=============================================================================
862 //=============================================================================
864 //=============================================================================
865 //=============================================================================
866 // Dissociation de lien entre des structures identifiees par leurs noms
867 //=============================================================================
868 //=============================================================================
869 void HOMARD_Gen_i::DissociateHypoZone(const char* nomHypothesis, const char* ZoneName)
871 MESSAGE ( "DissociateHypoZone : ZoneName= " << ZoneName << ", nomHypo = " << nomHypothesis);
873 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
874 ASSERT(!CORBA::is_nil(myHypo));
875 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
876 ASSERT(!CORBA::is_nil(aHypoSO));
878 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
879 ASSERT(!CORBA::is_nil(myZone));
880 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myZone)));
881 ASSERT(!CORBA::is_nil(aZoneSO));
883 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
885 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator(aHypoSO);
886 for (; it->More(); it->Next())
888 SALOMEDS::SObject_var aHypObj = it->Value();
889 SALOMEDS::SObject_var ptrObj;
890 if (aHypObj->ReferencedObject(ptrObj))
892 if (std::string(ptrObj->GetName()) == std::string(aZoneSO->GetName()))
894 aStudyBuilder->NewCommand();
895 aStudyBuilder->RemoveObject(aHypObj);
896 aStudyBuilder->CommitCommand();
902 myZone->SupprHypo(nomHypothesis);
903 myHypo->SupprZone(ZoneName);
905 //=============================================================================
906 //=============================================================================
909 //=============================================================================
910 //=============================================================================
911 // Recuperation des listes
912 //=============================================================================
913 //=============================================================================
914 HOMARD::listeBoundarys* HOMARD_Gen_i::GetAllBoundarysName()
916 MESSAGE("GetAllBoundarysName");
919 HOMARD::listeBoundarys_var ret = new HOMARD::listeBoundarys;
920 ret->length(myContextMap[GetCurrentStudyID()]._mesBoundarys.size());
921 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it;
923 for (it = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
924 it != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); it++)
926 ret[i++] = CORBA::string_dup((*it).first.c_str());
931 //=============================================================================
932 HOMARD::listeCases* HOMARD_Gen_i::GetAllCasesName()
934 MESSAGE("GetAllCasesName");
937 HOMARD::listeCases_var ret = new HOMARD::listeCases;
938 ret->length(myContextMap[GetCurrentStudyID()]._mesCas.size());
939 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
941 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
942 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
944 ret[i++] = CORBA::string_dup((*it).first.c_str());
949 //=============================================================================
950 HOMARD::listeHypotheses* HOMARD_Gen_i::GetAllHypothesesName()
952 MESSAGE("GetAllHypothesesName");
955 HOMARD::listeHypotheses_var ret = new HOMARD::listeHypotheses;
956 ret->length(myContextMap[GetCurrentStudyID()]._mesHypotheses.size());
957 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it;
959 for (it = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
960 it != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it++)
962 ret[i++] = CORBA::string_dup((*it).first.c_str());
967 //=============================================================================
968 HOMARD::listeIterations* HOMARD_Gen_i::GetAllIterationsName()
970 MESSAGE("GetAllIterationsName");
973 HOMARD::listeIterations_var ret = new HOMARD::listeIterations;
974 ret->length(myContextMap[GetCurrentStudyID()]._mesIterations.size());
975 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it;
977 for (it = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
978 it != myContextMap[GetCurrentStudyID()]._mesIterations.end(); it++)
980 ret[i++] = CORBA::string_dup((*it).first.c_str());
985 //=============================================================================
986 HOMARD::listeYACSs* HOMARD_Gen_i::GetAllYACSsName()
988 MESSAGE("GetAllYACSsName");
991 HOMARD::listeYACSs_var ret = new HOMARD::listeYACSs;
992 ret->length(myContextMap[GetCurrentStudyID()]._mesYACSs.size());
993 std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it;
995 for (it = myContextMap[GetCurrentStudyID()]._mesYACSs.begin();
996 it != myContextMap[GetCurrentStudyID()]._mesYACSs.end(); it++)
998 ret[i++] = CORBA::string_dup((*it).first.c_str());
1003 //=============================================================================
1004 HOMARD::listeZones* HOMARD_Gen_i::GetAllZonesName()
1006 MESSAGE("GetAllZonesName");
1009 HOMARD::listeZones_var ret = new HOMARD::listeZones;
1010 ret->length(myContextMap[GetCurrentStudyID()]._mesZones.size());
1011 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it;
1013 for (it = myContextMap[GetCurrentStudyID()]._mesZones.begin();
1014 it != myContextMap[GetCurrentStudyID()]._mesZones.end(); it++)
1016 ret[i++] = CORBA::string_dup((*it).first.c_str());
1021 //=============================================================================
1022 //=============================================================================
1024 //=============================================================================
1025 //=============================================================================
1026 // Recuperation des structures identifiees par leurs noms
1027 //=============================================================================
1028 //=============================================================================
1029 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::GetBoundary(const char* nomBoundary)
1031 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[nomBoundary];
1032 ASSERT(!CORBA::is_nil(myBoundary));
1033 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1035 //=============================================================================
1036 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::GetCase(const char* nomCas)
1038 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1039 ASSERT(!CORBA::is_nil(myCase));
1040 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1042 //=============================================================================
1043 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::GetHypothesis(const char* nomHypothesis)
1045 HOMARD::HOMARD_Hypothesis_var myHypothesis = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
1046 ASSERT(!CORBA::is_nil(myHypothesis));
1047 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1049 //=============================================================================
1050 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::GetIteration(const char* NomIterationation)
1052 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIterationation];
1053 ASSERT(!CORBA::is_nil(myIteration));
1054 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1056 //=============================================================================
1057 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::GetYACS(const char* nomYACS)
1059 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
1060 ASSERT(!CORBA::is_nil(myYACS));
1061 return HOMARD::HOMARD_YACS::_duplicate(myYACS);
1063 //=============================================================================
1064 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::GetZone(const char* ZoneName)
1066 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
1067 ASSERT(!CORBA::is_nil(myZone));
1068 return HOMARD::HOMARD_Zone::_duplicate(myZone);
1070 //=============================================================================
1071 //=============================================================================
1073 //=============================================================================
1074 //=============================================================================
1076 //=============================================================================
1077 //=============================================================================
1078 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)
1080 INFOS ( "MeshInfo : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1081 INFOS ( "Qual = " << Qual << ", Diam = " << Diam << ", Conn = " << Conn << ", Tail = " << Tail << ", Inte = " << Inte );
1085 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, 0, 1) ;
1086 myCase->SetDirName(DirName) ;
1088 myCase->MeshInfo(Qual, Diam, Conn, Tail, Inte) ;
1092 //=============================================================================
1093 //=============================================================================
1095 //=============================================================================
1096 //=============================================================================
1097 // Recuperation des structures par le contexte
1098 //=============================================================================
1099 //=============================================================================
1100 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::LastIteration(const char* nomCas)
1102 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1103 ASSERT(!CORBA::is_nil(myCase));
1105 HOMARD::HOMARD_Iteration_var myIteration = myCase->LastIteration();
1106 ASSERT(!CORBA::is_nil(myIteration));
1108 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1110 //=============================================================================
1111 //=============================================================================
1113 //=============================================================================
1114 //=============================================================================
1115 // Nouvelles structures
1116 //=============================================================================
1117 //=============================================================================
1118 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::newCase()
1120 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1121 HOMARD_Cas_i* aServant = new HOMARD_Cas_i(_orb, engine);
1122 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(aServant->_this());
1123 return aCase._retn();
1125 //=============================================================================
1126 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::newHypothesis()
1128 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1129 HOMARD_Hypothesis_i* aServant = new HOMARD_Hypothesis_i(_orb, engine);
1130 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(aServant->_this());
1131 return aHypo._retn();
1133 //=============================================================================
1134 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::newIteration()
1136 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1137 HOMARD_Iteration_i* aServant = new HOMARD_Iteration_i(_orb, engine);
1138 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(aServant->_this());
1139 return aIter._retn();
1141 //=============================================================================
1142 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::newBoundary()
1144 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1145 HOMARD_Boundary_i* aServant = new HOMARD_Boundary_i(_orb, engine);
1146 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(aServant->_this());
1147 return aBoundary._retn();
1149 //=============================================================================
1150 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::newZone()
1152 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1153 HOMARD_Zone_i* aServant = new HOMARD_Zone_i(_orb, engine);
1154 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(aServant->_this());
1155 return aZone._retn();
1157 //=============================================================================
1158 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::newYACS()
1160 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1161 HOMARD_YACS_i* aServant = new HOMARD_YACS_i(_orb, engine);
1162 HOMARD::HOMARD_YACS_var aYACS = HOMARD::HOMARD_YACS::_narrow(aServant->_this());
1163 return aYACS._retn();
1165 //=============================================================================
1166 //=============================================================================
1168 //=============================================================================
1169 //=============================================================================
1170 // Creation des structures identifiees par leurs noms
1171 //=============================================================================
1172 //=============================================================================
1173 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCase(const char* nomCas, const char* MeshName, const char* MeshFile)
1175 // Creation d'un cas initial
1176 // nomCas : nom du cas a creer
1177 // MeshName, MeshFile : nom et fichier du maillage correspondant
1180 INFOS ( "CreateCase : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1182 // Par defaut, on ne publie pas le maillage
1183 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 0, 0, 1) ;
1185 // Valeurs par defaut des filtrages
1186 myCase->SetPyram(0);
1188 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1190 //=============================================================================
1191 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromIteration(const char* nomCas, const char* DirNameStart)
1193 // nomCas : nom du cas a creer
1194 // DirNameStart : nom du repertoire contenant l'iteration de reprise
1197 INFOS ( "CreateCaseFromIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1198 std::string nomDirWork = getenv("PWD") ;
1201 // A. Decodage du point de reprise
1202 // A.1. Controle du repertoire de depart de l'iteration
1203 codret = chdir(DirNameStart) ;
1206 SALOME::ExceptionStruct es;
1207 es.type = SALOME::BAD_PARAM;
1208 es.text = "The directory of the iteration does not exist.";
1209 throw SALOME::SALOME_Exception(es);
1212 // A.2. Reperage des fichiers du repertoire de reprise
1213 std::string file_configuration = "" ;
1214 std::string file_maillage_homard = "" ;
1217 struct dirent *dirp;
1218 dp = opendir(DirNameStart);
1219 while ( (dirp = readdir(dp)) != NULL )
1221 std::string file_name(dirp->d_name);
1222 // MESSAGE ( file_name );
1223 bilan = file_name.find("HOMARD.Configuration.") ;
1224 if ( bilan != string::npos ) { file_configuration = file_name ; }
1225 bilan = file_name.find("maill.") ;
1226 if ( bilan != string::npos )
1228 bilan = file_name.find(".hom.med") ;
1229 if ( bilan != string::npos ) { file_maillage_homard = file_name ; }
1233 MESSAGE ( "==> file_configuration : " << file_configuration ) ;
1234 MESSAGE ( "==> file_maillage_homard : " << file_maillage_homard ) ;
1236 if ( ( file_configuration == "" ) or ( file_maillage_homard == "" ) )
1238 SALOME::ExceptionStruct es;
1239 es.type = SALOME::BAD_PARAM;
1241 if ( file_configuration == "" ) { text = "The configuration file cannot be found." ; }
1242 else { text = "The HOMARD mesh file cannot be found." ; }
1243 es.text = CORBA::string_dup(text.c_str());
1244 throw SALOME::SALOME_Exception(es);
1247 // B. Lecture du fichier de configuration
1248 // ATTENTION : on doit veiller a la coherence entre HomardDriver et CreateCaseFromIteration
1254 // le constructeur de ifstream permet d'ouvrir un fichier en lecture
1255 std::ifstream fichier( file_configuration.c_str() );
1256 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1258 std::string ligne; // variable contenant chaque ligne lue
1259 std::string mot_cle;
1260 std::string argument;
1262 // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1263 while ( std::getline( fichier, ligne ) )
1265 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1266 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1267 ligne_bis >> mot_cle ;
1268 // B.2. Des valeurs entieres : le second bloc de la ligne
1269 if ( mot_cle == "NumeIter" )
1271 ligne_bis >> NumeIter ;
1274 // B.3. Des valeurs caracteres brutes : le second bloc de la ligne est la valeur
1275 else if ( ( mot_cle == "TypeConf" ) or ( mot_cle == "TypeElem" ) )
1277 ligne_bis >> argument ;
1279 if ( mot_cle == "TypeConf" )
1281 if ( argument == "conforme" ) { TypeConf = 1 ; }
1282 else if ( argument == "non_conforme_1_noeud" ) { TypeConf = 2 ; }
1283 else if ( argument == "non_conforme_1_arete" ) { TypeConf = 3 ; }
1284 else if ( argument == "non_conforme_indicateur" ) { TypeConf = 4 ; }
1286 else if ( mot_cle == "TypeElem" )
1288 if ( argument == "ignore_pyra" ) { Pyram = 1 ; }
1289 else if ( argument == "HOMARD" ) { Pyram = 0 ; }
1292 // B.4. Des valeurs caracteres : le deuxieme bloc de la ligne peut etre encadre par des quotes :
1293 // il faut les supprimer
1294 else if ( ( mot_cle == "CCNoMNP1" ) or ( mot_cle == "CCMaiNP1" ) )
1296 ligne_bis >> argument ;
1297 if ( argument[0] == '"' ) { decalage = 1 ; }
1298 else { decalage = 0 ; }
1299 size_t size = argument.size() + 1 - 2*decalage ;
1301 if ( mot_cle == "CCNoMNP1" )
1303 MeshName = new char[ size ];
1304 strncpy( MeshName, argument.c_str()+decalage, size );
1305 MeshName[size-1] = '\0' ;
1307 else if ( mot_cle == "CCMaiNP1" )
1309 MeshFile = new char[ size ];
1310 strncpy( MeshFile, argument.c_str()+decalage, size );
1311 MeshFile[size-1] = '\0' ;
1315 MESSAGE ( "==> TypeConf : " << TypeConf ) ;
1316 MESSAGE ( "==> MeshName : " << MeshName ) ;
1317 MESSAGE ( "==> MeshFile : " << MeshFile ) ;
1318 MESSAGE ( "==> NumeIter : " << NumeIter ) ;
1319 MESSAGE ( "==> Pyram : " << Pyram ) ;
1323 SALOME::ExceptionStruct es;
1324 es.type = SALOME::BAD_PARAM;
1325 std::string text = "The configuration file cannot be read." ;
1326 es.text = CORBA::string_dup(text.c_str());
1327 throw SALOME::SALOME_Exception(es);
1330 // C. Creation effective du cas
1332 // Par defaut, on ne publie pas le maillage
1333 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, NumeIter, 1) ;
1335 // D. Parametrages lus dans le fichier de configuration
1337 myCase->SetConfType (TypeConf) ;
1338 myCase->SetPyram (Pyram) ;
1340 // E. Copie du fichier de maillage homard
1341 // E.1. Repertoire associe au cas
1342 char* nomDirCase = myCase->GetDirName() ;
1343 // E.2. Repertoire associe a l'iteration de ce cas
1345 IterName = myCase->GetIter0Name() ;
1346 HOMARD::HOMARD_Iteration_var Iter = GetIteration(IterName) ;
1347 char* nomDirIter = CreateDirNameIter(nomDirCase, 0 );
1348 Iter->SetDirNameLoc(nomDirIter);
1349 std::string nomDirIterTotal ;
1350 nomDirIterTotal = std::string(nomDirCase) + "/" + std::string(nomDirIter) ;
1351 if (mkdir(nomDirIterTotal.c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
1353 MESSAGE ( "nomDirIterTotal : " << nomDirIterTotal ) ;
1354 SALOME::ExceptionStruct es;
1355 es.type = SALOME::BAD_PARAM;
1356 std::string text = "The directory for the computation cannot be created." ;
1357 es.text = CORBA::string_dup(text.c_str());
1358 throw SALOME::SALOME_Exception(es);
1360 // E.3. Copie du maillage HOMARD au format MED
1361 codret = chdir(DirNameStart) ;
1362 std::string commande = "cp " + file_maillage_homard + " " + nomDirIterTotal ;
1363 MESSAGE ( "commande : " << commande ) ;
1364 codret = system(commande.c_str()) ;
1365 MESSAGE ( "codret : " << codret ) ;
1368 SALOME::ExceptionStruct es;
1369 es.type = SALOME::BAD_PARAM;
1370 es.text = "The starting point for the case cannot be copied into the working directory.";
1371 throw SALOME::SALOME_Exception(es);
1380 chdir(nomDirWork.c_str());
1382 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1384 //=============================================================================
1385 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseLastIteration(const char* nomCas, const char* DirNameStart)
1387 // nomCas : nom du cas a creer
1388 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1391 INFOS ( "CreateCaseFromCaseLastIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1393 std::string DirNameStartIter = CreateCase1(DirNameStart, -1) ;
1395 DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1396 HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1398 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1400 //=============================================================================
1401 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseIteration(const char* nomCas, const char* DirNameStart, CORBA::Long Number)
1403 // nomCas : nom du cas a creer
1404 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1405 // Number : numero de l'iteration de depart
1408 INFOS ( "CreateCaseFromCaseIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart << ", Number = " << Number );
1411 SALOME::ExceptionStruct es;
1412 es.type = SALOME::BAD_PARAM;
1413 es.text = "The number of iteration must be positive.";
1414 throw SALOME::SALOME_Exception(es);
1418 std::string DirNameStartIter = CreateCase1(DirNameStart, Number) ;
1420 DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1421 HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1423 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1425 //=============================================================================
1426 std::string HOMARD_Gen_i::CreateCase1(const char* DirNameStart, CORBA::Long Number)
1428 // Retourne le nom du repertoire ou se trouve l'iteration voulue.
1429 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1430 // Number : numero de l'iteration de depart ou -1 si on cherche la derniere
1433 MESSAGE ( "CreateCase1 : DirNameStart = " << DirNameStart << ", Number = " << Number );
1434 std::string nomDirWork = getenv("PWD") ;
1435 std::string DirNameStartIter ;
1437 int NumeIterMax = -1 ;
1439 // A.1. Controle du repertoire de depart du cas
1440 codret = chdir(DirNameStart) ;
1443 SALOME::ExceptionStruct es;
1444 es.type = SALOME::BAD_PARAM;
1445 es.text = "The directory of the case for the pursuit does not exist.";
1446 throw SALOME::SALOME_Exception(es);
1449 // A.2. Reperage des sous-repertoire du repertoire de reprise
1450 bool existe = false ;
1452 struct dirent *dirp;
1453 dp = opendir(DirNameStart);
1454 while ( (dirp = readdir(dp)) != NULL )
1456 std::string DirName_1(dirp->d_name);
1457 if ( ( DirName_1 != "." ) and ( DirName_1 != ".." ) )
1459 if ( chdir(DirName_1.c_str()) == 0 )
1461 // On cherche le fichier de configuration dans ce sous-repertoire
1462 codret = chdir(DirNameStart) ;
1464 struct dirent *dirp_1;
1465 dp_1 = opendir(DirName_1.c_str()) ;
1466 while ( (dirp_1 = readdir(dp_1)) != NULL )
1468 std::string file_name_1(dirp_1->d_name);
1469 int bilan = file_name_1.find("HOMARD.Configuration.") ;
1470 if ( bilan != string::npos )
1472 // Decodage du fichier pour trouver le numero d'iteration
1473 chdir(DirName_1.c_str()) ;
1474 std::ifstream fichier( file_name_1.c_str() );
1475 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1478 std::string ligne; // variable contenant chaque ligne lue
1479 std::string mot_cle;
1480 // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1481 while ( std::getline( fichier, ligne ) )
1483 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1484 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1485 ligne_bis >> mot_cle ;
1486 if ( mot_cle == "NumeIter" )
1488 ligne_bis >> NumeIter ;
1490 // MESSAGE ( "==> NumeIter : " << NumeIter ) ;
1491 if ( Number == - 1 )
1493 if ( NumeIter >= NumeIterMax )
1495 NumeIterMax = NumeIter ;
1496 DirNameStartIter = DirName_1 ;
1501 if ( NumeIter == Number )
1503 DirNameStartIter = DirName_1 ;
1513 SALOME::ExceptionStruct es;
1514 es.type = SALOME::BAD_PARAM;
1515 std::string text = "The configuration file cannot be read." ;
1516 es.text = CORBA::string_dup(text.c_str());
1517 throw SALOME::SALOME_Exception(es);
1519 chdir(DirNameStart) ;
1521 if ( existe ) { break ; }
1524 if ( existe ) { break ; }
1530 chdir(nomDirWork.c_str());
1532 if ( ( Number >= 0 and ( not existe ) ) or ( Number < 0 and ( NumeIterMax == -1 ) ) )
1534 SALOME::ExceptionStruct es;
1535 es.type = SALOME::BAD_PARAM;
1536 es.text = "The directory of the iteration does not exist.";
1537 throw SALOME::SALOME_Exception(es);
1541 return DirNameStartIter ;
1543 //=============================================================================
1544 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)
1546 // nomCas : nom du cas a creer
1547 // MeshName, MeshFile : nom et fichier du maillage correspondant
1548 // MeshOption : 0 : le maillage fourni est obligatoirement present ==> erreur si absent
1549 // 1 : le maillage fourni peut ne pas exister ==> on continue si absent
1550 // -1 : le maillage n'est pas fourni
1551 // NumeIter : numero de l'iteration correspondante : 0, pour un depart, n>0 pour une poursuite
1552 // Option : multiple de nombres premiers
1553 // 1 : aucune option
1554 // x2 : publication du maillage dans SMESH
1556 MESSAGE ( "CreateCase0 : nomCas = " << nomCas );
1557 MESSAGE ( "CreateCase0 : MeshName = " << MeshName << ", MeshFile = " << MeshFile << ", MeshOption = " << MeshOption );
1558 MESSAGE ( "CreateCase0 : NumeIter = " << NumeIter << ", Option = " << Option );
1564 // A.2. Controle du nom :
1565 if ((myContextMap[GetCurrentStudyID()]._mesCas).find(nomCas)!=(myContextMap[GetCurrentStudyID()]._mesCas).end())
1567 SALOME::ExceptionStruct es;
1568 es.type = SALOME::BAD_PARAM;
1569 es.text = "This case has already been defined.";
1570 throw SALOME::SALOME_Exception(es);
1574 // A.3. Controle du fichier du maillage
1575 int existeMeshFile ;
1576 if ( MeshOption >= 0 )
1578 existeMeshFile = MEDFileExist ( MeshFile ) ;
1579 MESSAGE ( "CreateCase0 : existeMeshFile = " << existeMeshFile );
1580 if ( ( existeMeshFile == 0 ) and ( MeshOption == 0 ) )
1582 SALOME::ExceptionStruct es;
1583 es.type = SALOME::BAD_PARAM;
1584 es.text = "The mesh file does not exist.";
1585 throw SALOME::SALOME_Exception(es);
1589 else { existeMeshFile = 0 ; }
1591 // B. Creation de l'objet cas et publication
1592 // MESSAGE ( "CreateCase0 : Creation de l'objet" );
1593 HOMARD::HOMARD_Cas_var myCase = newCase();
1594 myCase->SetName(nomCas);
1595 SALOMEDS::SObject_var aSO;
1596 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myCase, nomCas);
1597 myContextMap[GetCurrentStudyID()]._mesCas[nomCas] = myCase;
1599 // C. Caracteristiques du maillage
1600 if ( existeMeshFile != 0 )
1602 // Les valeurs extremes des coordonnees
1603 // MESSAGE ( "CreateCase0 : Les valeurs extremes des coordonnees" );
1604 std::vector<double> LesExtremes =GetBoundingBoxInMedFile(MeshFile) ;
1605 HOMARD::extrema_var aSeq = new HOMARD::extrema() ;
1606 if (LesExtremes.size()!=10) { return false; }
1608 for (int i =0 ; i< LesExtremes.size() ; i++)
1609 aSeq[i]=LesExtremes[i] ;
1610 myCase->SetBoundingBox(aSeq) ;
1612 // MESSAGE ( "CreateCase0 : Les groupes" );
1613 std::set<std::string> LesGroupes =GetListeGroupesInMedFile(MeshFile) ;
1614 HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType ;
1615 aSeqGroupe->length(LesGroupes.size());
1616 std::set<std::string>::const_iterator it ;
1618 for (it=LesGroupes.begin() ; it != LesGroupes.end() ; it++)
1619 aSeqGroupe[i++]=(*it).c_str() ;
1620 myCase->SetGroups(aSeqGroupe) ;
1623 // D. L'iteration initiale du cas
1624 MESSAGE ( "CreateCase0 : iteration initiale du cas" );
1625 // D.1. Recherche d'un nom : par defaut, on prend le nom du maillage correspondant.
1626 // Si ce nom d'iteration existe deja, on incremente avec 0, 1, 2, etc.
1628 std::string NomIteration = std::string(MeshName) ;
1629 while ( (myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration) != (myContextMap[GetCurrentStudyID()]._mesIterations.end()) )
1631 std::ostringstream nom;
1632 nom << MeshName << monNum;
1633 NomIteration = nom.str();
1636 MESSAGE ( "CreateCas0 : ==> NomIteration = " << NomIteration );
1638 // D.2. Creation de l'iteration
1639 HOMARD::HOMARD_Iteration_var anIter = newIteration();
1640 myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration] = anIter;
1641 anIter->SetName(NomIteration.c_str());
1642 AssociateCaseIter (nomCas, NomIteration.c_str(), "IterationHomard");
1644 // D.4. Maillage correspondant
1645 if ( existeMeshFile != 0 )
1647 anIter->SetMeshFile(MeshFile);
1648 if ( Option % 2 == 0 ) { PublishResultInSmesh(MeshFile, 0); }
1650 anIter->SetMeshName(MeshName);
1652 // D.5. Numero d'iteration
1653 anIter->SetNumber(NumeIter);
1656 SetEtatIter(NomIteration.c_str(), -NumeIter);
1659 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1661 //=============================================================================
1662 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::CreateHypothesis(const char* nomHypothesis)
1664 INFOS ( "CreateHypothesis : nomHypothesis = " << nomHypothesis );
1667 // A. Controle du nom :
1668 if ((myContextMap[GetCurrentStudyID()]._mesHypotheses).find(nomHypothesis) != (myContextMap[GetCurrentStudyID()]._mesHypotheses).end())
1670 SALOME::ExceptionStruct es;
1671 es.type = SALOME::BAD_PARAM;
1672 es.text = "This hypothesis has already been defined.";
1673 throw SALOME::SALOME_Exception(es);
1677 // B. Creation de l'objet
1678 HOMARD::HOMARD_Hypothesis_var myHypothesis = newHypothesis();
1679 if (CORBA::is_nil(myHypothesis))
1681 SALOME::ExceptionStruct es;
1682 es.type = SALOME::BAD_PARAM;
1683 es.text = "Unable to create the hypothesis";
1684 throw SALOME::SALOME_Exception(es);
1687 myHypothesis->SetName(nomHypothesis);
1689 // C. Enregistrement
1690 myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis] = myHypothesis;
1692 SALOMEDS::SObject_var aSO;
1693 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myHypothesis, nomHypothesis);
1695 // D. Valeurs par defaut des options avancees
1696 myHypothesis->SetNivMax(-1);
1697 myHypothesis->SetDiamMin(-1.0);
1698 myHypothesis->SetAdapInit(0);
1699 myHypothesis->SetLevelOutput(0);
1701 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1704 //=============================================================================
1705 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::CreateIteration(const char* NomIteration, const char* nomIterParent)
1706 //=============================================================================
1708 INFOS ("CreateIteration : NomIteration = " << NomIteration << ", nomIterParent = " << nomIterParent);
1711 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterParent];
1712 if (CORBA::is_nil(myIterationParent))
1714 SALOME::ExceptionStruct es;
1715 es.type = SALOME::BAD_PARAM;
1716 es.text = "The parent iteration is not defined.";
1717 throw SALOME::SALOME_Exception(es);
1721 const char* nomCas = myIterationParent->GetCaseName();
1722 MESSAGE ("CreateIteration : nomCas = " << nomCas);
1723 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1724 if (CORBA::is_nil(myCase))
1726 SALOME::ExceptionStruct es;
1727 es.type = SALOME::BAD_PARAM;
1728 es.text = "Invalid case context";
1729 throw SALOME::SALOME_Exception(es);
1732 const char* nomDirCase = myCase->GetDirName();
1734 // Controle du nom :
1735 if ((myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration)!=(myContextMap[GetCurrentStudyID()]._mesIterations).end())
1737 SALOME::ExceptionStruct es;
1738 es.type = SALOME::BAD_PARAM;
1739 es.text = "This iteration has already been defined.";
1740 throw SALOME::SALOME_Exception(es);
1744 HOMARD::HOMARD_Iteration_var myIteration = newIteration();
1745 if (CORBA::is_nil(myIteration))
1747 SALOME::ExceptionStruct es;
1748 es.type = SALOME::BAD_PARAM;
1749 es.text = "Unable to create the iteration";
1750 throw SALOME::SALOME_Exception(es);
1753 myContextMap[GetCurrentStudyID()]._mesIterations[std::string(NomIteration)] = myIteration;
1754 // Nom de l'iteration et du maillage
1755 myIteration->SetName(NomIteration);
1756 myIteration->SetMeshName(NomIteration);
1757 myIteration->SetState(1);
1759 int numero = myIterationParent->GetNumber() + 1;
1760 myIteration->SetNumber(numero);
1762 // Nombre d'iterations deja connues pour le cas, permettant
1763 // la creation d'un sous-repertoire unique
1764 int nbitercase = myCase->GetNumberofIter();
1765 char* nomDirIter = CreateDirNameIter(nomDirCase, nbitercase );
1766 myIteration->SetDirNameLoc(nomDirIter);
1768 // Le nom du fichier du maillage MED est indice par le nombre d'iterations du cas.
1769 // Si on a une chaine unique depuis le depart, ce nombre est le meme que le
1770 // numero d'iteration dans la sucession : maill.01.med, maill.02.med, etc... C'est la
1771 // situation la plus frequente.
1772 // Si on a plusieurs branches, donc des iterations du meme niveau d'adaptation, utiliser
1773 // le nombre d'iterations du cas permet d'eviter les collisions.
1775 if ( nbitercase < 100 ) { jaux = 2 ; }
1776 else if ( nbitercase < 1000 ) { jaux = 3 ; }
1777 else if ( nbitercase < 10000 ) { jaux = 4 ; }
1778 else if ( nbitercase < 100000 ) { jaux = 5 ; }
1780 std::ostringstream iaux ;
1781 iaux << std::setw(jaux) << std::setfill('0') << nbitercase ;
1782 std::stringstream MeshFile;
1783 MeshFile << nomDirCase << "/maill." << iaux.str() << ".med";
1784 myIteration->SetMeshFile(MeshFile.str().c_str());
1786 // Association avec le cas
1787 std::string label = "IterationHomard_" + std::string(nomIterParent);
1788 AssociateCaseIter(nomCas, NomIteration, label.c_str());
1789 // Lien avec l'iteration precedente
1790 myIterationParent->LinkNextIteration(NomIteration);
1791 myIteration->SetIterParentName(nomIterParent);
1793 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1795 //=============================================================================
1796 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundary(const char* BoundaryName, CORBA::Long BoundaryType)
1798 MESSAGE ("CreateBoundary : BoundaryName = " << BoundaryName << ", BoundaryType = " << BoundaryType);
1801 // Controle du nom :
1802 if ((myContextMap[GetCurrentStudyID()]._mesBoundarys).find(BoundaryName)!=(myContextMap[GetCurrentStudyID()]._mesBoundarys).end())
1804 MESSAGE ("CreateBoundary : la frontiere " << BoundaryName << " existe deja");
1805 SALOME::ExceptionStruct es;
1806 es.type = SALOME::BAD_PARAM;
1807 es.text = "This boundary has already been defined";
1808 throw SALOME::SALOME_Exception(es);
1812 HOMARD::HOMARD_Boundary_var myBoundary = newBoundary();
1813 myBoundary->SetName(BoundaryName);
1814 myBoundary->SetType(BoundaryType);
1816 myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName] = myBoundary;
1818 SALOMEDS::SObject_var aSO;
1819 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myBoundary, BoundaryName);
1821 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1823 //=============================================================================
1824 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
1826 INFOS ("CreateBoundaryDi : BoundaryName = " << BoundaryName << "MeshName = " << MeshName );
1827 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
1828 myBoundary->SetMeshFile( MeshFile ) ;
1829 myBoundary->SetMeshName( MeshName ) ;
1831 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1833 //=============================================================================
1834 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCylinder(const char* BoundaryName,
1835 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1836 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1837 CORBA::Double Rayon)
1839 INFOS ("CreateBoundaryCylinder : BoundaryName = " << BoundaryName ) ;
1841 SALOME::ExceptionStruct es;
1844 { es.text = "The radius must be positive." ;
1846 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1847 if ( daux < 0.0000001 )
1848 { es.text = "The axis must be a non 0 vector." ;
1852 es.type = SALOME::BAD_PARAM;
1853 throw SALOME::SALOME_Exception(es);
1857 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 1) ;
1858 myBoundary->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon ) ;
1860 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1862 //=============================================================================
1863 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundarySphere(const char* BoundaryName,
1864 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1865 CORBA::Double Rayon)
1867 INFOS ("CreateBoundarySphere : BoundaryName = " << BoundaryName ) ;
1869 SALOME::ExceptionStruct es;
1872 { es.text = "The radius must be positive." ;
1876 es.type = SALOME::BAD_PARAM;
1877 throw SALOME::SALOME_Exception(es);
1881 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 2) ;
1882 myBoundary->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
1884 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1886 //=============================================================================
1887 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeA(const char* BoundaryName,
1888 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe, CORBA::Double Angle,
1889 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre)
1891 INFOS ("CreateBoundaryConeA : BoundaryName = " << BoundaryName ) ;
1893 SALOME::ExceptionStruct es;
1895 if ( Angle <= 0.0 or Angle >= 90.0 )
1896 { es.text = "The angle must be included higher than 0 degree and lower than 90 degrees." ;
1898 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1899 if ( daux < 0.0000001 )
1900 { es.text = "The axis must be a non 0 vector." ;
1904 es.type = SALOME::BAD_PARAM;
1905 throw SALOME::SALOME_Exception(es);
1909 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 3) ;
1910 myBoundary->SetConeA( Xaxe, Yaxe, Zaxe, Angle, Xcentre, Ycentre, Zcentre ) ;
1912 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1914 //=============================================================================
1915 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeR(const char* BoundaryName,
1916 CORBA::Double Xcentre1, CORBA::Double Ycentre1, CORBA::Double Zcentre1, CORBA::Double Rayon1,
1917 CORBA::Double Xcentre2, CORBA::Double Ycentre2, CORBA::Double Zcentre2, CORBA::Double Rayon2)
1919 INFOS ("CreateBoundaryConeR : BoundaryName = " << BoundaryName ) ;
1921 SALOME::ExceptionStruct es;
1923 if ( Rayon1 < 0.0 or Rayon2 < 0.0 )
1924 { es.text = "The radius must be positive." ;
1926 double daux = fabs(Rayon2-Rayon1) ;
1927 if ( daux < 0.0000001 )
1928 { es.text = "The radius must be different." ;
1930 daux = fabs(Xcentre2-Xcentre1) + fabs(Ycentre2-Ycentre1) + fabs(Zcentre2-Zcentre1) ;
1931 if ( daux < 0.0000001 )
1932 { es.text = "The centers must be different." ;
1936 es.type = SALOME::BAD_PARAM;
1937 throw SALOME::SALOME_Exception(es);
1941 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 4) ;
1942 myBoundary->SetConeR( Xcentre1, Ycentre1, Zcentre1, Rayon1, Xcentre2, Ycentre2, Zcentre2, Rayon2 ) ;
1944 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1946 //=============================================================================
1947 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZone(const char* ZoneName, CORBA::Long ZoneType)
1949 MESSAGE ("CreateZone : ZoneName = " << ZoneName << ", ZoneType = " << ZoneType);
1952 // Controle du nom :
1953 if ((myContextMap[GetCurrentStudyID()]._mesZones).find(ZoneName)!=(myContextMap[GetCurrentStudyID()]._mesZones).end())
1955 SALOME::ExceptionStruct es;
1956 es.type = SALOME::BAD_PARAM;
1957 es.text = "This zone has already been defined";
1958 throw SALOME::SALOME_Exception(es);
1962 HOMARD::HOMARD_Zone_var myZone = newZone();
1963 myZone->SetName(ZoneName);
1964 myZone->SetType(ZoneType);
1966 myContextMap[GetCurrentStudyID()]._mesZones[ZoneName] = myZone;
1968 SALOMEDS::SObject_var aSO;
1969 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myZone, ZoneName);
1971 return HOMARD::HOMARD_Zone::_duplicate(myZone);
1973 //=============================================================================
1974 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox(const char* ZoneName,
1975 CORBA::Double Xmini, CORBA::Double Xmaxi,
1976 CORBA::Double Ymini, CORBA::Double Ymaxi,
1977 CORBA::Double Zmini, CORBA::Double Zmaxi)
1979 INFOS ("CreateZoneBox : ZoneName = " << ZoneName ) ;
1981 SALOME::ExceptionStruct es;
1983 if ( Xmini > Xmaxi )
1984 { es.text = "The X coordinates are not coherent." ;
1986 if ( Ymini > Ymaxi )
1987 { es.text = "The Y coordinates are not coherent." ;
1989 if ( Zmini > Zmaxi )
1990 { es.text = "The Z coordinates are not coherent." ;
1994 es.type = SALOME::BAD_PARAM;
1995 throw SALOME::SALOME_Exception(es);
1999 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 2) ;
2000 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2002 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2004 //=============================================================================
2005 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneSphere(const char* ZoneName,
2006 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre, CORBA::Double Rayon)
2008 INFOS ("CreateZoneSphere : ZoneName = " << ZoneName ) ;
2010 SALOME::ExceptionStruct es;
2013 { es.text = "The radius must be positive." ;
2017 es.type = SALOME::BAD_PARAM;
2018 throw SALOME::SALOME_Exception(es);
2022 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 4) ;
2023 myZone->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
2025 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2027 //=============================================================================
2028 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneCylinder(const char* ZoneName,
2029 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2030 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2031 CORBA::Double Rayon, CORBA::Double Haut)
2033 INFOS ("CreateZoneCylinder : ZoneName = " << ZoneName ) ;
2035 SALOME::ExceptionStruct es;
2038 { es.text = "The radius must be positive." ;
2040 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2041 if ( daux < 0.0000001 )
2042 { es.text = "The axis must be a non 0 vector." ;
2045 { es.text = "The height must be positive." ;
2049 es.type = SALOME::BAD_PARAM;
2050 throw SALOME::SALOME_Exception(es);
2054 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 5) ;
2055 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut ) ;
2057 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2059 //=============================================================================
2060 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZonePipe(const char* ZoneName,
2061 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2062 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2063 CORBA::Double Rayon, CORBA::Double Haut, CORBA::Double Rayonint)
2065 INFOS ("CreateZonePipe : ZoneName = " << ZoneName ) ;
2067 SALOME::ExceptionStruct es;
2069 if ( Rayon <= 0.0 or Rayonint <= 0.0 )
2070 { es.text = "The radius must be positive." ;
2072 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2073 if ( daux < 0.0000001 )
2074 { es.text = "The axis must be a non 0 vector." ;
2077 { es.text = "The height must be positive." ;
2079 if ( Rayon <= Rayonint )
2080 { es.text = "The external radius must be higher than the internal radius." ;
2084 es.type = SALOME::BAD_PARAM;
2085 throw SALOME::SALOME_Exception(es);
2089 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 7) ;
2090 myZone->SetPipe( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut, Rayonint ) ;
2092 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2094 //=============================================================================
2095 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox2D(const char* ZoneName,
2096 CORBA::Double Umini, CORBA::Double Umaxi,
2097 CORBA::Double Vmini, CORBA::Double Vmaxi,
2100 INFOS ("CreateZoneBox2D : ZoneName = " << ZoneName ) ;
2101 // MESSAGE ("Umini = " << Umini << ", Umaxi =" << Umaxi ) ;
2102 // MESSAGE ("Vmini = " << Vmini << ", Vmaxi =" << Vmaxi ) ;
2103 // MESSAGE ("Orient = " << Orient ) ;
2105 SALOME::ExceptionStruct es;
2107 if ( Umini > Umaxi )
2108 { es.text = "The first coordinates are not coherent." ;
2110 if ( Vmini > Vmaxi )
2111 { es.text = "The second coordinates are not coherent." ;
2113 if ( Orient < 1 or Orient > 3 )
2114 { es.text = "The orientation must be 1, 2 or 3." ;
2118 es.type = SALOME::BAD_PARAM;
2119 throw SALOME::SALOME_Exception(es);
2123 double Xmini, Xmaxi ;
2124 double Ymini, Ymaxi ;
2125 double Zmini, Zmaxi ;
2133 else if ( Orient == 2 )
2140 else if ( Orient == 3 )
2147 else { VERIFICATION( (Orient>=1) and (Orient<=3) ) ; }
2149 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 10+Orient) ;
2150 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2152 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2154 //=============================================================================
2155 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDisk(const char* ZoneName,
2156 CORBA::Double Ucentre, CORBA::Double Vcentre,
2157 CORBA::Double Rayon,
2160 INFOS ("CreateZoneDisk : ZoneName = " << ZoneName ) ;
2162 SALOME::ExceptionStruct es;
2165 { es.text = "The radius must be positive." ;
2167 if ( Orient < 1 or Orient > 3 )
2168 { es.text = "The orientation must be 1, 2 or 3." ;
2172 es.type = SALOME::BAD_PARAM;
2173 throw SALOME::SALOME_Exception(es);
2181 { Xcentre = Ucentre ;
2184 else if ( Orient == 2 )
2187 Zcentre = Vcentre ; }
2188 else if ( Orient == 3 )
2189 { Xcentre = Vcentre ;
2191 Zcentre = Ucentre ; }
2192 else { VERIFICATION( (Orient>=1) and (Orient<=3) ) ; }
2194 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 30+Orient) ;
2195 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1. ) ;
2197 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2199 //=============================================================================
2200 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDiskWithHole(const char* ZoneName,
2201 CORBA::Double Ucentre, CORBA::Double Vcentre,
2202 CORBA::Double Rayon, CORBA::Double Rayonint,
2205 INFOS ("CreateZoneDiskWithHole : ZoneName = " << ZoneName ) ;
2207 SALOME::ExceptionStruct es;
2209 if ( Rayon <= 0.0 or Rayonint <= 0.0 )
2210 { es.text = "The radius must be positive." ;
2212 if ( Orient < 1 or Orient > 3 )
2213 { es.text = "The orientation must be 1, 2 or 3." ;
2215 if ( Rayon <= Rayonint )
2216 { es.text = "The external radius must be higher than the internal radius." ;
2220 es.type = SALOME::BAD_PARAM;
2221 throw SALOME::SALOME_Exception(es);
2229 { Xcentre = Ucentre ;
2232 else if ( Orient == 2 )
2235 Zcentre = Vcentre ; }
2236 else if ( Orient == 3 )
2237 { Xcentre = Vcentre ;
2239 Zcentre = Ucentre ; }
2240 else { VERIFICATION( (Orient>=1) and (Orient<=3) ) ; }
2242 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 60+Orient) ;
2243 myZone->SetPipe( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1., Rayonint ) ;
2245 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2247 //=============================================================================
2248 //=============================================================================
2253 //=============================================================================
2254 //=============================================================================
2255 // Traitement d'une iteration
2256 // etatMenage = 1 : destruction du repertoire d'execution
2257 // modeHOMARD = 1 : adaptation
2258 // != 1 : information avec les options modeHOMARD
2259 // Option1 >0 : appel depuis python
2260 // <0 : appel depuis GUI
2261 // Option2 : multiple de nombres premiers
2262 // 1 : aucune option
2263 // x2 : publication du maillage dans SMESH
2264 //=============================================================================
2265 CORBA::Long HOMARD_Gen_i::Compute(const char* NomIteration, CORBA::Long etatMenage, CORBA::Long modeHOMARD, CORBA::Long Option1, CORBA::Long Option2)
2267 INFOS ( "Compute : traitement de " << NomIteration << ", avec modeHOMARD = " << modeHOMARD << ", Option1 = " << Option1 << ", Option2 = " << Option2 );
2272 // A.1. L'objet iteration
2273 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration];
2274 ASSERT(!CORBA::is_nil(myIteration));
2276 // A.2. Numero de l'iteration
2277 // siterp1 : numero de l'iteration a traiter
2279 // siter : numero de l'iteration parent, ou 0 si deja au debut mais cela ne servira pas !
2280 // Ou si information :
2282 int NumeIter = myIteration->GetNumber();
2283 std::string siterp1 ;
2284 std::stringstream saux1 ;
2286 siterp1 = saux1.str() ;
2287 if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
2290 if ( modeHOMARD==1 )
2292 std::stringstream saux0 ;
2293 int iaux = max(0, NumeIter-1) ;
2295 siter = saux0.str() ;
2296 if (NumeIter < 11) { siter = "0" + siter ; }
2299 { siter = siterp1 ; }
2302 const char* nomCas = myIteration->GetCaseName();
2303 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
2304 ASSERT(!CORBA::is_nil(myCase));
2306 // B. Les repertoires
2307 // B.1. Le repertoire courant
2308 std::string nomDirWork = getenv("PWD") ;
2309 // B.2. Le sous-repertoire de l'iteration a traiter
2310 char* DirCompute = ComputeDirManagement(myCase, myIteration, etatMenage);
2311 MESSAGE( ". DirCompute = " << DirCompute );
2313 // C. Le fichier des messages
2314 // C.1. Le deroulement de l'execution de HOMARD
2315 std::string LogFile = DirCompute ;
2316 LogFile += "/Liste" ;
2317 if ( modeHOMARD == 1 ) { LogFile += "." + siter + ".vers." + siterp1 ; }
2319 MESSAGE (". LogFile = " << LogFile);
2320 if ( modeHOMARD == 1 ) { myIteration->SetLogFile(LogFile.c_str()); }
2321 // C.2. Le bilan de l'analyse du maillage
2322 std::string FileInfo = DirCompute ;
2324 if ( modeHOMARD == 1 ) { FileInfo += "apad" ; }
2326 { if ( NumeIter == 0 ) { FileInfo += "info_av" ; }
2327 else { FileInfo += "info_ap" ; }
2329 FileInfo += "." + siterp1 + ".bilan" ;
2330 myIteration->SetFileInfo(FileInfo.c_str());
2332 // D. On passe dans le repertoire de l'iteration a calculer
2333 MESSAGE ( ". On passe dans DirCompute = " << DirCompute );
2336 // E. Les donnees de l'execution HOMARD
2337 // E.1. L'objet du texte du fichier de configuration
2338 HomardDriver* myDriver = new HomardDriver(siter, siterp1);
2339 myDriver->TexteInit(DirCompute, LogFile, _Langue);
2341 // E.2. Le maillage associe a l'iteration
2342 const char* NomMesh = myIteration->GetMeshName();
2343 MESSAGE ( ". NomMesh = " << NomMesh );
2344 const char* MeshFile = myIteration->GetMeshFile();
2345 MESSAGE ( ". MeshFile = " << MeshFile );
2347 // E.3. Les donnees du traitement HOMARD
2349 if ( modeHOMARD == 1 )
2352 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2353 myDriver->TexteMaillage(NomMesh, MeshFile, 1);
2354 codret = ComputeAdap(myCase, myIteration, etatMenage, myDriver, Option1, Option2) ;
2358 InvalideIterInfo(NomIteration);
2359 myDriver->TexteInfo( modeHOMARD, NumeIter ) ;
2361 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2362 myDriver->TexteMaillage(NomMesh, MeshFile, 0);
2363 myDriver->CreeFichierDonn();
2366 // E.4. Ajout des informations liees a l'eventuel suivi de frontiere
2367 DriverTexteBoundary(myCase, myDriver) ;
2369 // E.5. Ecriture du texte dans le fichier
2370 MESSAGE ( ". Ecriture du texte dans le fichier de configuration ; codret = "<<codret );
2372 { myDriver->CreeFichier(); }
2376 int codretexec = 12 ;
2379 codretexec = myDriver->ExecuteHomard(Option1);
2381 MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
2382 // En mode adaptation, on ajuste l'etat de l'iteration
2383 if ( modeHOMARD == 1 )
2385 if (codretexec == 0) { SetEtatIter(NomIteration,2); }
2386 else { SetEtatIter(NomIteration,1); }
2387 // GERALD -- QMESSAGE BOX
2391 // H. Gestion des resultats
2394 std::string Commentaire ;
2395 // H.1. Le fichier des messages, dans tous les cas
2396 Commentaire = "log" ;
2397 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2398 else { Commentaire += "Info" ; }
2399 PublishFileUnderIteration(NomIteration, LogFile.c_str(), Commentaire.c_str());
2401 // H.2. Si tout s'est bien passe :
2402 if (codretexec == 0)
2404 // H.2.1. Le fichier de bilan
2405 Commentaire = "Summary" ;
2406 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2407 else { Commentaire += "Info" ; }
2408 PublishFileUnderIteration(NomIteration, FileInfo.c_str(), Commentaire.c_str());
2409 // H.2.2. Le fichier de maillage obtenu
2410 if ( modeHOMARD == 1 )
2412 std::stringstream saux0 ;
2413 Commentaire = "Mesh" ;
2414 Commentaire += " " + siterp1 ;
2415 PublishFileUnderIteration(NomIteration, MeshFile, Commentaire.c_str());
2416 if ( Option2 % 2 == 0 ) { PublishResultInSmesh(MeshFile, 1); }
2419 // H.3 Message d'erreur
2420 if (codretexec != 0)
2423 // Message d'erreur en cas de probleme en adaptation
2424 if ( modeHOMARD == 1 )
2426 text = "Error during the adaptation.\n" ;
2427 bool stopvu = false ;
2428 std::ifstream fichier( LogFile.c_str() );
2429 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
2431 std::string ligne; // variable contenant chaque ligne lue
2432 while ( std::getline( fichier, ligne ) )
2436 { text += ligne+ "\n"; }
2439 int position = ligne.find( "===== HOMARD ===== STOP =====" ) ;
2440 if ( position > 0 ) { stopvu = true ; }
2447 text = "Voir le fichier Liste.log.\n" ;
2450 SALOME::ExceptionStruct es;
2451 es.type = SALOME::BAD_PARAM;
2452 es.text = CORBA::string_dup(text.c_str());
2453 throw SALOME::SALOME_Exception(es);
2455 // En mode information, on force le succes pour pouvoir consulter le fichier log
2456 if ( modeHOMARD != 1 ) { codretexec = 0 ; }
2460 // I. Menage et retour dans le repertoire du cas
2464 MESSAGE ( ". On retourne dans nomDirWork = " << nomDirWork );
2465 chdir(nomDirWork.c_str());
2470 //=============================================================================
2471 // Calcul d'une iteration : partie specifique a l'adaptation
2472 //=============================================================================
2473 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)
2475 MESSAGE ( "ComputeAdap" );
2480 // Etat de l'iteration
2481 int etat = myIteration->GetState();
2482 // Numero de l'iteration
2483 int NumeIter = myIteration->GetNumber();
2484 std::stringstream saux0 ;
2485 saux0 << NumeIter-1 ;
2486 std::string siter = saux0.str() ;
2487 if (NumeIter < 11) { siter = "0" + siter ; }
2489 // A.2. On ne calcule pas l iteration initiale
2492 MESSAGE ( "etat = "<<etat );
2493 SALOME::ExceptionStruct es;
2494 es.type = SALOME::BAD_PARAM;
2495 es.text = "This iteration is the first of the case and cannot be computed.";
2496 throw SALOME::SALOME_Exception(es);
2500 // A.3. On verifie qu il y a une hypothese (erreur improbable);
2501 const char* nomHypo = myIteration->GetHypoName();
2502 if (std::string(nomHypo) == std::string(""))
2504 SALOME::ExceptionStruct es;
2505 es.type = SALOME::BAD_PARAM;
2506 es.text = "This iteration does not have any associated hypothesis.";
2507 throw SALOME::SALOME_Exception(es);
2510 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
2511 ASSERT(!CORBA::is_nil(myHypo));
2513 // B. L'iteration parent
2514 const char* nomIterationParent = myIteration->GetIterParentName();
2515 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
2516 ASSERT(!CORBA::is_nil(myIterationParent));
2517 // Si l'iteration parent n'est pas calculee, on le fait (recursivite amont)
2518 if ( myIterationParent->GetState() == 1 )
2521 int codret = Compute(nomIterationParent, etatMenage, iaux, Option1, Option2);
2524 // GERALD -- QMESSAGE BOX
2525 VERIFICATION("Pb au calcul de l'iteration precedente" == 0);
2529 // C. Le sous-repertoire de l'iteration precedente
2530 char* DirComputePa = ComputeDirPaManagement(myCase, myIteration);
2531 MESSAGE( ". DirComputePa = " << DirComputePa );
2533 // D. Les donnees de l'adaptation HOMARD
2534 // D.1. Le type de conformite
2535 int ConfType = myCase->GetConfType();
2536 MESSAGE ( ". ConfType = " << ConfType );
2538 // D.2. Le maillage de depart
2539 const char* NomMeshParent = myIterationParent->GetMeshName();
2540 MESSAGE ( ". NomMeshParent = " << NomMeshParent );
2541 const char* MeshFileParent = myIterationParent->GetMeshFile();
2542 MESSAGE ( ". MeshFileParent = " << MeshFileParent );
2544 // D.3. Le maillage associe a l'iteration
2545 const char* MeshFile = myIteration->GetMeshFile();
2546 MESSAGE ( ". MeshFile = " << MeshFile );
2547 FILE *file = fopen(MeshFile,"r");
2551 if (etatMenage == 0)
2553 SALOME::ExceptionStruct es;
2554 es.type = SALOME::BAD_PARAM;
2555 std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
2556 es.text = CORBA::string_dup(text.c_str());
2557 throw SALOME::SALOME_Exception(es);
2562 std::string commande = "rm -f " + std::string(MeshFile);
2563 codret = system(commande.c_str());
2566 SALOME::ExceptionStruct es;
2567 es.type = SALOME::BAD_PARAM;
2568 es.text = "The mesh file cannot be deleted.";
2569 throw SALOME::SALOME_Exception(es);
2575 // D.4. Les types de raffinement et de deraffinement
2576 // Les appels corba sont lourds, il vaut mieux les grouper
2577 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
2578 ASSERT(ListTypes->length() == 3);
2579 int TypeAdap = (*ListTypes)[0];
2580 int TypeRaff = (*ListTypes)[1];
2581 int TypeDera = (*ListTypes)[2];
2583 // E. Texte du fichier de configuration
2584 // E.1. Incontournables du texte
2585 myDriver->TexteAdap();
2587 myDriver->TexteMaillageHOMARD( DirComputePa, siter, iaux ) ;
2588 myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
2589 myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
2591 // E.2. Ajout des informations liees aux zones eventuelles
2592 if ( TypeAdap == 0 )
2593 { DriverTexteZone(myHypo, myDriver) ; }
2595 // E.3. Ajout des informations liees aux champs eventuels
2596 if ( TypeAdap == 1 )
2597 { DriverTexteField(myIteration, myHypo, myDriver) ; }
2599 // E.4. Ajout des informations liees au filtrage eventuel par les groupes
2600 HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
2601 int numberOfGroups = listeGroupes->length();
2602 MESSAGE( ". Filtrage par " << numberOfGroups << " groupes");
2603 if (numberOfGroups > 0)
2605 for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
2607 std::string GroupName = std::string((*listeGroupes)[NumGroup]);
2608 MESSAGE( "... GroupName = " << GroupName );
2609 myDriver->TexteGroup(GroupName);
2613 // E.5. Ajout des informations liees a l'eventuelle interpolation des champs
2614 DriverTexteFieldInterp(myIteration, myHypo, myDriver) ;
2616 // E.6. Ajout des options avancees
2617 int Pyram = myCase->GetPyram();
2618 MESSAGE ( ". Pyram = " << Pyram );
2619 int NivMax = myHypo->GetNivMax();
2620 MESSAGE ( ". NivMax = " << NivMax );
2621 double DiamMin = myHypo->GetDiamMin() ;
2622 MESSAGE ( ". DiamMin = " << DiamMin );
2623 int AdapInit = myHypo->GetAdapInit();
2624 MESSAGE ( ". AdapInit = " << AdapInit );
2625 int LevelOutput = myHypo->GetLevelOutput();
2626 MESSAGE ( ". LevelOutput = " << LevelOutput );
2627 myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, LevelOutput);
2629 // E.7. Ajout des informations sur le deroulement de l'execution
2630 int MessInfo = myIteration->GetInfoCompute();
2631 MESSAGE ( ". MessInfo = " << MessInfo );
2632 myDriver->TexteInfoCompute(MessInfo);
2636 //=============================================================================
2637 // Creation d'un nom de sous-repertoire pour l'iteration au sein d'un repertoire parent
2638 // nomrep : nom du repertoire parent
2639 // num : le nom du sous-repertoire est sous la forme 'In', n est >= num
2640 //=============================================================================
2641 char* HOMARD_Gen_i::CreateDirNameIter(const char* nomrep, CORBA::Long num )
2643 MESSAGE ( "CreateDirNameIter : nomrep ="<< nomrep << ", num = "<<num);
2644 // On verifie que le repertoire parent existe
2645 int codret = chdir(nomrep) ;
2648 SALOME::ExceptionStruct es;
2649 es.type = SALOME::BAD_PARAM;
2650 es.text = "The directory of the case does not exist.";
2651 throw SALOME::SALOME_Exception(es);
2654 std::string nomDirActuel = getenv("PWD") ;
2655 std::string DirName ;
2656 // On boucle sur tous les noms possibles jusqu'a trouver un nom correspondant a un repertoire inconnu
2657 bool a_chercher = true ;
2658 while ( a_chercher )
2660 // On passe dans le repertoire parent
2662 // On recherche un nom sous la forme Iabc, avec abc representant le numero
2664 if ( num < 100 ) { jaux = 2 ; }
2665 else if ( num < 1000 ) { jaux = 3 ; }
2666 else if ( num < 10000 ) { jaux = 4 ; }
2667 else if ( num < 100000 ) { jaux = 5 ; }
2669 std::ostringstream iaux ;
2670 iaux << std::setw(jaux) << std::setfill('0') << num ;
2671 std::ostringstream DirNameA ;
2672 DirNameA << "I" << iaux.str();
2673 // Si on ne pas peut entrer dans le repertoire, on doit verifier
2674 // que c'est bien un probleme d'absence
2675 if ( chdir(DirNameA.str().c_str()) != 0 )
2677 bool existe = false ;
2679 struct dirent *dirp;
2680 dp = opendir(nomrep);
2681 while ( (dirp = readdir(dp)) != NULL )
2683 std::string file_name(dirp->d_name);
2684 if ( file_name == DirNameA.str() ) { existe = true ; }
2689 DirName = DirNameA.str() ;
2690 a_chercher = false ;
2697 MESSAGE ( "==> DirName = " << DirName);
2698 MESSAGE ( ". On retourne dans nomDirActuel = " << nomDirActuel );
2699 chdir(nomDirActuel.c_str());
2701 return CORBA::string_dup( DirName.c_str() );
2703 //=============================================================================
2704 // Calcul d'une iteration : gestion du repertoire de calcul
2705 // Si le sous-repertoire existe :
2706 // etatMenage = 0 : on sort en erreur si le repertoire n'est pas vide
2707 // etatMenage = 1 : on fait le menage du repertoire
2708 // etatMenage = -1 : on ne fait rien
2709 //=============================================================================
2710 char* HOMARD_Gen_i::ComputeDirManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage)
2712 MESSAGE ( "ComputeDirManagement : repertoires pour le calcul" );
2713 // B.2. Le repertoire du cas
2714 const char* nomDirCase = myCase->GetDirName();
2715 MESSAGE ( ". nomDirCase = " << nomDirCase );
2717 // B.3. Le sous-repertoire de l'iteration a calculer, puis le repertoire complet a creer
2718 // B.3.1. Le nom du sous-repertoire
2719 const char* nomDirIt = myIteration->GetDirNameLoc();
2721 // B.3.2. Le nom complet du sous-repertoire
2722 std::stringstream DirCompute ;
2723 DirCompute << nomDirCase << "/" << nomDirIt;
2724 MESSAGE (". DirCompute = " << DirCompute.str() );
2726 // B.3.3. Si le sous-repertoire n'existe pas, on le cree
2727 if (chdir(DirCompute.str().c_str()) != 0)
2729 // Creation du repertoire car il n'existe pas :
2730 if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
2732 // GERALD -- QMESSAGE BOX
2733 std::cerr << "Pb Creation du repertoire DirCompute = " << DirCompute.str() << std::endl;
2734 VERIFICATION("Pb a la creation du repertoire" == 0);
2739 // Le repertoire existe
2740 // On demande de faire le menage de son contenu :
2741 if (etatMenage == 1)
2743 MESSAGE (". Menage du repertoire DirCompute = " << DirCompute.str());
2744 std::string commande = "rm -rf " + DirCompute.str()+"/*" ;
2745 int codret = system(commande.c_str());
2748 // GERALD -- QMESSAGE BOX
2749 std::cerr << ". Menage du repertoire de calcul" << DirCompute.str() << std::endl;
2750 VERIFICATION("Pb au menage du repertoire de calcul" == 0);
2753 // On n'a pas demande de faire le menage de son contenu : on sort en erreur :
2756 if (etatMenage == 0)
2759 struct dirent *dirp;
2760 dp = opendir(DirCompute.str().c_str());
2762 while ((dirp = readdir(dp)) != NULL && result )
2764 std::string file_name(dirp->d_name);
2765 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
2768 if ( result == false)
2770 SALOME::ExceptionStruct es;
2771 es.type = SALOME::BAD_PARAM;
2772 std::string text = "Directory : " + DirCompute.str() + "is not empty";
2773 es.text = CORBA::string_dup(text.c_str());
2774 throw SALOME::SALOME_Exception(es);
2775 VERIFICATION("Directory is not empty" == 0);
2781 return CORBA::string_dup( DirCompute.str().c_str() );
2783 //=============================================================================
2784 // Calcul d'une iteration : gestion du repertoire de calcul de l'iteration parent
2785 //=============================================================================
2786 char* HOMARD_Gen_i::ComputeDirPaManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration)
2788 MESSAGE ( "ComputeDirPaManagement : repertoires pour le calcul" );
2789 // Le repertoire du cas
2790 const char* nomDirCase = myCase->GetDirName();
2791 MESSAGE ( ". nomDirCase = " << nomDirCase );
2793 // Le sous-repertoire de l'iteration precedente
2795 const char* nomIterationParent = myIteration->GetIterParentName();
2796 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
2797 const char* nomDirItPa = myIterationParent->GetDirNameLoc();
2798 std::stringstream DirComputePa ;
2799 DirComputePa << nomDirCase << "/" << nomDirItPa;
2800 MESSAGE( ". nomDirItPa = " << nomDirItPa);
2801 MESSAGE( ". DirComputePa = " << DirComputePa.str() );
2803 return CORBA::string_dup( DirComputePa.str().c_str() );
2805 //=============================================================================
2806 // Calcul d'une iteration : ecriture des zones dans le fichier de configuration
2807 //=============================================================================
2808 void HOMARD_Gen_i::DriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
2810 MESSAGE ( "... DriverTexteZone" );
2811 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
2812 int numberOfZonesx2 = ListZone->length();
2815 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
2817 std::string ZoneName = std::string((*ListZone)[iaux]);
2818 MESSAGE ( "... ZoneName = " << ZoneName);
2819 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
2820 ASSERT(!CORBA::is_nil(myZone));
2822 int ZoneType = myZone->GetType();
2823 std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
2824 int TypeUse = atoi( TypeUsestr.c_str() );
2825 MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
2826 NumZone = iaux/2 + 1 ;
2827 HOMARD::double_array* zone = myZone->GetCoords();
2828 if ( ZoneType == 2 or ( ZoneType>=11 and ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
2829 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.); }
2830 else if ( ZoneType == 4 ) // Cas d une sphere
2831 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.); }
2832 else if ( ZoneType == 5 or ( ZoneType>=31 and ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
2833 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.); }
2834 else if ( ZoneType == 7 or ( ZoneType>=61 and ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
2835 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]); }
2836 else { VERIFICATION("ZoneType est incorrect." == 0) ; }
2841 //=============================================================================
2842 // Calcul d'une iteration : ecriture des champs dans le fichier de configuration
2843 //=============================================================================
2844 void HOMARD_Gen_i::DriverTexteField(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
2846 MESSAGE ( "... DriverTexteField" );
2847 // Le fichier du champ
2848 char* FieldFile = myIteration->GetFieldFile();
2849 MESSAGE ( ". FieldFile = " << FieldFile );
2850 if (strlen(FieldFile) == 0)
2852 // GERALD -- QMESSAGE BOX
2853 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
2854 VERIFICATION("The file for the field is not given." == 0);
2856 // Les caracteristiques d'instants du champ de pilotage
2857 int TimeStep = myIteration->GetTimeStep();
2858 MESSAGE( ". TimeStep = " << TimeStep );
2859 int Rank = myIteration->GetRank();
2860 MESSAGE( ". Rank = " << Rank );
2861 // Les informations sur les champs
2862 HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
2864 const char* FieldName = aInfosHypo->FieldName;
2866 int TypeThR = aInfosHypo->TypeThR;
2867 double ThreshR = aInfosHypo->ThreshR;
2868 int TypeThC = aInfosHypo->TypeThC;
2869 double ThreshC = aInfosHypo->ThreshC;
2870 // Saut entre mailles ou non ?
2871 int UsField = aInfosHypo->UsField;
2872 MESSAGE( ". UsField = " << UsField );
2873 // L'usage des composantes
2874 int UsCmpI = aInfosHypo->UsCmpI;
2875 MESSAGE( ". UsCmpI = " << UsCmpI );
2877 myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
2880 HOMARD::listeComposantsHypo* mescompo = myHypo->GetComps();
2881 int numberOfCompos = mescompo->length();
2882 MESSAGE( ". numberOfCompos = " << numberOfCompos );
2883 for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
2885 std::string nomCompo = std::string((*mescompo)[NumeComp]);
2886 MESSAGE( "... nomCompo = " << nomCompo );
2887 myDriver->TexteCompo(NumeComp, nomCompo);
2891 //=============================================================================
2892 // Calcul d'une iteration : ecriture des frontieres dans le fichier de configuration
2893 // On ecrit dans l'ordre :
2894 // 1. la definition des frontieres
2895 // 2. les liens avec les groupes
2896 // 3. un entier resumant le type de comportement pour les frontieres
2897 //=============================================================================
2898 void HOMARD_Gen_i::DriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, HomardDriver* myDriver)
2900 MESSAGE ( "... DriverTexteBoundary" );
2901 // 1. Recuperation des frontieres
2902 std::list<std::string> ListeBoundaryTraitees ;
2903 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
2904 int numberOfitems = ListBoundaryGroupType->length();
2905 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
2906 int BoundaryOption = 1 ;
2907 // 2. Parcours des frontieres pour ecrire leur description
2908 int NumBoundaryAnalytical = 0 ;
2909 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
2911 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
2912 MESSAGE ( "... BoundaryName = " << BoundaryName);
2913 // 2.1. La frontiere a-t-elle deja ete ecrite ?
2914 // Cela arrive quand elle estliéé a plusieurs groupes. Il ne faut l'ecrire que la premiere fois
2916 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
2917 while (it != ListeBoundaryTraitees.end())
2919 MESSAGE ( "..... BoundaryNameTraitee = " << *it);
2920 if ( BoundaryName == *it ) { A_faire = 0 ; }
2923 // 2.2. Ecriture de la frontiere
2926 // 2.2.1. Caracteristiques de la frontiere
2927 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
2928 ASSERT(!CORBA::is_nil(myBoundary));
2929 int BoundaryType = myBoundary->GetType();
2930 MESSAGE ( "... BoundaryType = " << BoundaryType );
2931 // 2.2.2. Ecriture selon le type
2932 // 2.2.2.1. Cas d une frontiere discrete
2933 if (BoundaryType == 0)
2935 const char* MeshName = myBoundary->GetMeshName() ;
2936 const char* MeshFile = myBoundary->GetMeshFile() ;
2937 myDriver->TexteBoundaryDi( MeshName, MeshFile);
2938 if ( BoundaryOption % 2 != 0 ) { BoundaryOption = BoundaryOption*2 ; }
2940 // 2.2.2.1. Cas d une frontiere analytique
2943 NumBoundaryAnalytical++ ;
2944 HOMARD::double_array* coor = myBoundary->GetCoords();
2945 if (BoundaryType == 1) // Cas d un cylindre
2947 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
2948 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
2950 else if (BoundaryType == 2) // Cas d une sphere
2952 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0., 0.);
2953 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
2955 else if (BoundaryType == 3) // Cas d un cone defini par un axe et un angle
2957 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
2958 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
2960 else if (BoundaryType == 4) // Cas d un cone defini par les 2 rayons
2962 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
2963 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
2966 // 2.2.3. Memorisation du traitement
2967 ListeBoundaryTraitees.push_back( BoundaryName );
2970 // 3. Parcours des frontieres pour ecrire les liens avec les groupes
2971 NumBoundaryAnalytical = 0 ;
2972 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
2974 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
2975 MESSAGE ( "... BoundaryName = " << BoundaryName);
2976 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
2977 ASSERT(!CORBA::is_nil(myBoundary));
2978 int BoundaryType = myBoundary->GetType();
2979 MESSAGE ( "... BoundaryType = " << BoundaryType );
2980 // 3.1. Recuperation du nom du groupe
2981 std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
2982 MESSAGE ( "... GroupName = " << GroupName);
2983 // 3.2. Cas d une frontiere discrete
2984 if ( BoundaryType == 0 )
2986 if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
2988 // 3.3. Cas d une frontiere analytique
2991 NumBoundaryAnalytical++ ;
2992 myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
2995 // 4. Ecriture de l'option finale
2996 myDriver->TexteBoundaryOption(BoundaryOption);
3000 //=============================================================================
3001 // Calcul d'une iteration : ecriture des interpolations dans le fichier de configuration
3002 //=============================================================================
3003 void HOMARD_Gen_i::DriverTexteFieldInterp(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3005 MESSAGE ( "... DriverTexteFieldInterp" );
3006 int TypeFieldInterp = myHypo->GetTypeFieldInterp();
3007 MESSAGE ( "... TypeFieldInterp = " << TypeFieldInterp);
3008 if (TypeFieldInterp != 0)
3010 // Le fichier des champs
3011 char* FieldFile = myIteration->GetFieldFile();
3012 MESSAGE ( ". FieldFile = " << FieldFile );
3013 if (strlen(FieldFile) == 0)
3015 // GERALD -- QMESSAGE BOX
3016 VERIFICATION("The file for the field is not given." == 0);
3019 const char* MeshFile = myIteration->GetMeshFile();
3020 myDriver->TexteFieldInterp(FieldFile, MeshFile);
3023 // Interpolation de tous les champs
3024 if ( TypeFieldInterp == 1 )
3026 myDriver->TexteFieldInterpAll();
3028 // Interpolation de certains champs
3029 else if (TypeFieldInterp == 2)
3031 // Les champs et leurs instants pour l'iteration
3032 HOMARD::listeFieldInterpTSRsIter* ListFieldTSR = myIteration->GetFieldInterpsTimeStepRank();
3033 int numberOfFieldsx3 = ListFieldTSR->length();
3034 MESSAGE( ". pour iteration, numberOfFields = " << numberOfFieldsx3/3 );
3035 // Les champs pour l'hypothese
3036 HOMARD::listeFieldInterpsHypo* ListField = myHypo->GetFieldInterps();
3037 int numberOfFieldsx2 = ListField->length();
3038 MESSAGE( ". pour hypothese, numberOfFields = " << numberOfFieldsx2/2 );
3039 // On parcourt tous les champs de l'hypothese
3041 for (int iaux = 0; iaux< numberOfFieldsx2; iaux++)
3044 std::string FieldName = std::string((*ListField)[iaux]) ;
3045 // Le type d'interpolation
3046 std::string TypeInterpstr = std::string((*ListField)[iaux+1]) ;
3047 MESSAGE( "... FieldName = " << FieldName << ", TypeInterp = " << TypeInterpstr );
3048 // On cherche à savoir si des instants ont été précisés pour cette itération
3050 for (int jaux = 0; jaux< numberOfFieldsx3; jaux++)
3053 std::string FieldName2 = std::string((*ListFieldTSR)[jaux]) ;
3054 MESSAGE( "..... FieldName2 = " << FieldName2 );
3055 // Quand c'est le bon champ, on ecrit le pas de temps
3056 if ( FieldName == FieldName2 )
3060 std::string TimeStepstr = std::string((*ListFieldTSR)[jaux+1]) ;
3061 // Le numero d'ordre
3062 std::string Rankstr = std::string((*ListFieldTSR)[jaux+2]) ;
3063 MESSAGE( "..... TimeStepstr = " << TimeStepstr <<", Rankstr = "<<Rankstr );
3065 int TimeStep = atoi( TimeStepstr.c_str() );
3066 int Rank = atoi( Rankstr.c_str() );
3067 myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, TimeStep, Rank);
3071 // Si aucun instant n'a été défini
3075 myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, -1, -1);
3083 //===========================================================================
3084 //===========================================================================
3087 //===========================================================================
3088 //===========================================================================
3090 //===========================================================================
3091 //===========================================================================
3092 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
3093 SALOMEDS::SObject_ptr theSObject,
3094 CORBA::Object_ptr theObject,
3095 const char* theName)
3097 MESSAGE("PublishInStudy pour " << theName);
3098 SALOMEDS::SObject_var aResultSO;
3099 if (CORBA::is_nil(theStudy))
3101 SALOME::ExceptionStruct es;
3102 es.type = SALOME::BAD_PARAM;
3103 es.text = "Invalid study context";
3104 throw SALOME::SALOME_Exception(es);
3108 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
3109 // Rq : Iteration est publiee ailleurs
3110 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
3111 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(theObject);
3112 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
3113 HOMARD::HOMARD_YACS_var aYACS = HOMARD::HOMARD_YACS::_narrow(theObject);
3114 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
3116 addInStudy(theStudy);
3118 // Controle de la non publication d'un objet de meme nom
3119 if ( (!aBoundary->_is_nil()) or (!aHypo->_is_nil()) or (!aYACS->_is_nil()) or (!aZone->_is_nil()) )
3121 SALOMEDS::Study::ListOfSObject_var listSO = theStudy->FindObjectByName(theName, ComponentDataType());
3122 if (listSO->length() >= 1)
3124 MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
3125 aResultSO = listSO[0];
3126 return aResultSO._retn();
3130 // Caracteristiques de l'etude
3131 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
3132 aStudyBuilder->NewCommand();
3133 if(!aBoundary->_is_nil())
3134 aResultSO = PublishBoundaryInStudy(theStudy, aStudyBuilder, aBoundary, theName);
3135 else if(!aCase->_is_nil())
3136 aResultSO = PublishCaseInStudy(theStudy, aStudyBuilder, aCase, theName);
3137 else if(!aHypo->_is_nil())
3138 aResultSO = PublishHypotheseInStudy(theStudy, aStudyBuilder, aHypo, theName);
3139 else if(!aYACS->_is_nil())
3140 aResultSO = PublishYACSInStudy(theStudy, aStudyBuilder, aYACS, theName);
3141 else if(!aZone->_is_nil())
3142 aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName);
3144 aStudyBuilder->CommitCommand();
3146 return aResultSO._retn();
3148 //=============================================================================
3149 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy(SALOMEDS::Study_ptr theStudy,
3150 SALOMEDS::StudyBuilder_var aStudyBuilder,
3151 HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
3153 MESSAGE("PublishBoundaryStudy pour "<<theName);
3154 SALOMEDS::SObject_var aResultSO;
3156 // Caracteristique de la Boundary
3157 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[theName];
3159 // On recupere le module pere dans l etude
3160 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3161 if (theFatherHomard->_is_nil())
3163 MESSAGE("theFatherHomard->_is_nil()");
3164 return aResultSO._retn();
3167 // On ajoute la categorie des boundarys dans l etude si necessaire
3168 if ( _tag_boun == 0 )
3171 _tag_boun = _tag_gene ;
3173 MESSAGE("PublishBoundaryInStudy _tag_gene = "<<_tag_gene << ", _tag_boun = "<<_tag_boun );
3174 SALOMEDS::SObject_var aSObject;
3175 if (!theFatherHomard->FindSubObject(_tag_boun, aSObject))
3177 MESSAGE("Ajout de la categorie des boundarys");
3178 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_boun);
3179 PublishInStudyAttr(aStudyBuilder, aSObject, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
3181 else { MESSAGE("La categorie des boundarys existe deja."); }
3183 CORBA::Long BoundaryType = myBoundary->GetType();
3184 // MESSAGE("BoundaryType : "<<BoundaryType);
3187 switch (BoundaryType)
3190 { value = "BoundaryDiHomard" ;
3191 icone = "mesh_tree_mesh.png" ;
3195 { value = "BoundaryAnHomard" ;
3196 icone = "cylinderpointvector_2.png" ;
3200 { value = "BoundaryAnHomard" ;
3201 icone = "spherepoint_2.png" ;
3205 { value = "BoundaryAnHomard" ;
3206 icone = "conepointvector.png" ;
3210 { value = "BoundaryAnHomard" ;
3211 icone = "conedxyz.png" ;
3215 aResultSO = aStudyBuilder->NewObject(aSObject);
3216 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value.c_str(), icone.c_str(), _orb->object_to_string(theObject));
3217 return aResultSO._retn();
3219 //=============================================================================
3220 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::Study_ptr theStudy,
3221 SALOMEDS::StudyBuilder_var aStudyBuilder,
3222 HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
3224 MESSAGE("PublishCaseInStudy pour "<<theName);
3225 SALOMEDS::SObject_var aResultSO;
3227 if (CORBA::is_nil(theObject)) {
3228 MESSAGE("HOMARD_Gen_i::theObject->_is_nil()");
3229 return aResultSO._retn();
3231 if (theStudy->_is_nil()) {
3232 MESSAGE("HOMARD_Gen_i::theStudy->_is_nil()");
3233 return aResultSO._retn();
3236 // On recupere le module pere dans l etude
3237 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3238 if (theFatherHomard->_is_nil())
3240 MESSAGE("theFatherHomard->_is_nil()");
3241 return aResultSO._retn();
3245 MESSAGE("PublishCaseInStudy _tag_gene = "<<_tag_gene );
3246 aResultSO = aStudyBuilder->NewObject(theFatherHomard);
3247 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
3248 _orb->object_to_string(theObject) ) ;
3250 return aResultSO._retn();
3252 //=============================================================================
3253 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::Study_ptr theStudy,
3254 SALOMEDS::StudyBuilder_var aStudyBuilder,
3255 HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
3257 MESSAGE("PublishHypotheseInStudy pour "<<theName);
3258 SALOMEDS::SObject_var aResultSO;
3260 // On recupere le module pere dans l etude
3261 // On ajoute la categorie des hypotheses dans l etude si necessaire
3262 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3263 if (theFatherHomard->_is_nil())
3265 MESSAGE("theFatherHomard->_is_nil()");
3266 return aResultSO._retn();
3269 // On ajoute la categorie des hypotheses dans l etude si necessaire
3270 SALOMEDS::SObject_var aSObject;
3271 if ( _tag_hypo == 0 )
3274 _tag_hypo = _tag_gene ;
3276 MESSAGE("PublishHypotheseInStudy _tag_gene = "<<_tag_gene << ", _tag_hypo = "<<_tag_hypo );
3277 if (!theFatherHomard->FindSubObject(_tag_hypo, aSObject))
3279 MESSAGE("Ajout de la categorie des hypotheses");
3280 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_hypo);
3281 PublishInStudyAttr(aStudyBuilder, aSObject, "Hypothesis", "HypoList", "hypotheses.png", NULL);
3283 else { MESSAGE("La categorie des hypotheses existe deja."); }
3285 // Creation du resultat dans l'etude
3286 aResultSO = aStudyBuilder->NewObject(aSObject);
3287 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
3289 return aResultSO._retn();
3291 //=============================================================================
3292 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishYACSInStudy(SALOMEDS::Study_ptr theStudy,
3293 SALOMEDS::StudyBuilder_var aStudyBuilder,
3294 HOMARD::HOMARD_YACS_ptr theObject, const char* theName)
3296 MESSAGE("PublishYACSInStudy pour "<<theName);
3297 SALOMEDS::SObject_var aResultSO;
3299 // On recupere le module pere dans l etude
3300 // On ajoute la categorie des schemas YACS dans l etude si necessaire
3301 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3302 if (theFatherHomard->_is_nil())
3304 MESSAGE("theFatherHomard->_is_nil()");
3305 return aResultSO._retn();
3307 // On ajoute la categorie des schemas YACS dans l etude si necessaire
3308 if ( _tag_yacs == 0 )
3311 _tag_yacs = _tag_gene ;
3313 MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_yacs = "<<_tag_yacs );
3314 SALOMEDS::SObject_var aSObject;
3315 if (!theFatherHomard->FindSubObject(_tag_yacs, aSObject))
3317 MESSAGE("Ajout de la categorie des schemas YACS");
3318 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_yacs);
3319 PublishInStudyAttr(aStudyBuilder, aSObject, "YACS", "YACSList", "full_view.png", NULL);
3321 else { MESSAGE("La categorie des schemas YACS existe deja."); }
3323 // Creation du resultat dans l'etude
3324 aResultSO = aStudyBuilder->NewObject(aSObject);
3325 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "YACSHomard", "schema.png", _orb->object_to_string(theObject) ) ;
3327 return aResultSO._retn();
3330 //=============================================================================
3331 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::Study_ptr theStudy,
3332 SALOMEDS::StudyBuilder_var aStudyBuilder,
3333 HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
3335 MESSAGE("PublishZoneStudy pour "<<theName);
3336 SALOMEDS::SObject_var aResultSO;
3337 if (CORBA::is_nil(theObject))
3339 MESSAGE("PublishZoneInStudy : theObject->_is_nil()");
3340 return aResultSO._retn();
3342 if (theStudy->_is_nil())
3344 MESSAGE("PublishZoneInStudy : theStudy->_is_nil()");
3345 return aResultSO._retn();
3347 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3348 if (theFatherHomard->_is_nil())
3350 MESSAGE("PublishZoneInStudy : theFatherHomard->_is_nil()");
3351 return aResultSO._retn();
3354 // Caracteristique de la zone
3355 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[theName];
3356 CORBA::Long ZoneType = myZone->GetType();
3358 // On ajoute la categorie des zones dans l etude si necessaire
3359 if ( _tag_zone == 0 )
3362 _tag_zone = _tag_gene ;
3364 MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_zone = "<<_tag_zone );
3365 SALOMEDS::SObject_var aSObject;
3366 if (!theFatherHomard->FindSubObject(_tag_zone, aSObject))
3368 MESSAGE("Ajout de la categorie des zones");
3369 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_zone);
3370 PublishInStudyAttr(aStudyBuilder, aSObject, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
3372 else { MESSAGE("La categorie des zones existe deja."); }
3374 aResultSO = aStudyBuilder->NewObject(aSObject);
3383 { icone = "boxdxy_2.png" ;
3387 { icone = "boxdxyz_2.png" ;
3395 { icone = "disk_2.png" ;
3399 { icone = "spherepoint_2.png" ;
3403 { icone = "cylinderpointvector_2.png" ;
3411 { icone = "diskwithhole_2.png" ;
3415 { icone = "pipe_2.png" ;
3419 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone.c_str(), _orb->object_to_string(theObject) ) ;
3421 return aResultSO._retn();
3423 //===========================================================================
3424 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
3425 SALOMEDS::SObject_var aResultSO,
3426 const char* name, const char* comment, const char* icone, const char* ior)
3428 MESSAGE("PublishInStudyAttr pour name = "<<name<<", comment = "<<comment);
3429 // MESSAGE("icone = "<<icone);
3430 // MESSAGE("ior = "<<ior);
3431 SALOMEDS::GenericAttribute_var anAttr ;
3435 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
3436 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
3437 aNameAttrib->SetValue(name);
3440 // Ajout du commentaire
3441 if ( comment != NULL )
3443 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
3444 SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
3445 aCommentAttrib->SetValue(comment);
3449 if ( icone != NULL )
3451 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
3452 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
3453 aPixmap->SetPixMap(icone);
3459 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
3460 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3461 anIOR->SetValue(ior);
3465 //=====================================================================================
3466 void HOMARD_Gen_i::PublishBoundaryUnderCase(const char* CaseName, const char* BoundaryName)
3468 MESSAGE ( "PublishBoundaryUnderCase : CaseName = " << CaseName << ", BoundaryName= " << BoundaryName );
3470 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3471 ASSERT(!CORBA::is_nil(myCase));
3472 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3473 ASSERT(!CORBA::is_nil(aCaseSO));
3475 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3476 ASSERT(!CORBA::is_nil(myBoundary));
3477 SALOMEDS::SObject_var aBoundarySO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myBoundary)));
3478 ASSERT(!CORBA::is_nil(aBoundarySO));
3480 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3482 aStudyBuilder->NewCommand();
3484 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aCaseSO);
3485 aStudyBuilder->Addreference(aSubSO, aBoundarySO);
3487 aStudyBuilder->CommitCommand();
3490 //=====================================================================================
3491 void HOMARD_Gen_i::PublishCaseUnderYACS(const char* nomYACS, const char* CaseName)
3493 MESSAGE ( "PublishCaseUnderYACS : nomYACS = " << nomYACS << ", CaseName= " << CaseName );
3495 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3496 ASSERT(!CORBA::is_nil(myYACS));
3497 SALOMEDS::SObject_var aYACSSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3498 ASSERT(!CORBA::is_nil(aYACSSO));
3500 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3501 ASSERT(!CORBA::is_nil(myCase));
3502 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3503 ASSERT(!CORBA::is_nil(aCaseSO));
3505 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3507 aStudyBuilder->NewCommand();
3509 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3510 aStudyBuilder->Addreference(aSubSO, aCaseSO);
3512 aStudyBuilder->CommitCommand();
3515 //=============================================================================
3516 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long Option)
3517 // Option = 0 : fichier issu d'une importation
3518 // Option = 1 : fichier issu d'une execution HOMARD
3520 MESSAGE( "PublishResultInSmesh " << NomFich << ", avec Option = " << Option);
3521 if (CORBA::is_nil(myCurrentStudy))
3523 SALOME::ExceptionStruct es;
3524 es.type = SALOME::BAD_PARAM;
3525 es.text = "Invalid study context";
3526 throw SALOME::SALOME_Exception(es);
3530 // Le module SMESH est-il actif ?
3531 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3533 if (!CORBA::is_nil(aSmeshSO))
3535 // On verifie que le fichier n est pas deja publie
3536 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3537 for (; aIter->More(); aIter->Next())
3539 SALOMEDS::SObject_var aSO = aIter->Value();
3540 SALOMEDS::GenericAttribute_var aGAttr;
3541 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3543 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3544 CORBA::String_var value=anAttr->Value();
3545 if (strcmp((const char*)value,NomFich) == 0)
3547 MESSAGE ( "PublishResultInSmesh : le fichier " << NomFich << " est deja publie." );
3548 // Pour un fichier importe, on ne republie pas
3553 // Pour un fichier calcule, on commence par faire la depublication
3556 MESSAGE ( "PublishResultInSmesh : depublication" );
3557 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3558 CORBA::String_var value2=anAttr2->Value();
3559 std::string MeshName = string(value2) ;
3560 MESSAGE ( "PublishResultInSmesh : depublication de " << MeshName );
3561 DeleteResultInSmesh(NomFich, MeshName) ;
3568 // On enregistre le fichier
3569 MESSAGE( "Enregistrement du fichier");
3570 SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
3571 SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
3572 ASSERT(!CORBA::is_nil(aSmeshEngine));
3573 aSmeshEngine->SetCurrentStudy(myCurrentStudy);
3574 SMESH::DriverMED_ReadStatus theStatus;
3575 //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3577 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
3578 SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3579 for (int i = 0; i < mesMaillages->length(); i++)
3581 MESSAGE( ". Mise a jour des attributs du maillage");
3582 SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
3583 SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
3584 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3585 SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
3586 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3587 anAttr->SetValue(NomFich);
3588 SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
3589 SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
3591 if ( Option == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
3592 else { icone = "mesh_tree_mesh.png" ; }
3593 anAttr2->SetPixMap( icone );
3597 //=============================================================================
3598 void HOMARD_Gen_i::DeleteResultInSmesh(std::string NomFich, std::string MeshName)
3600 MESSAGE ("DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich );
3601 if (CORBA::is_nil(myCurrentStudy))
3603 SALOME::ExceptionStruct es;
3604 es.type = SALOME::BAD_PARAM;
3605 es.text = "Invalid study context";
3606 throw SALOME::SALOME_Exception(es);
3610 // Le module SMESH est-il actif ?
3611 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3613 if (CORBA::is_nil(aSmeshSO))
3617 // On verifie que le fichier est deja publie
3618 SALOMEDS::StudyBuilder_var myBuilder = myCurrentStudy->NewBuilder();
3619 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3620 for (; aIter->More(); aIter->Next())
3622 SALOMEDS::SObject_var aSO = aIter->Value();
3623 SALOMEDS::GenericAttribute_var aGAttr;
3624 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3626 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3627 CORBA::String_var value=anAttr->Value();
3628 if (strcmp((const char*)value,NomFich.c_str()) == 0)
3630 if (aSO->FindAttribute(aGAttr,"AttributeName"))
3632 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3633 CORBA::String_var value2=anAttr2->Value();
3634 if (strcmp((const char*)value2,MeshName.c_str()) == 0)
3636 myBuilder->RemoveObjectWithChildren( aSO ) ;
3644 //=============================================================================
3645 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
3647 // MESSAGE ("PublishFileUnderIteration pour l'iteration " << NomIter << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3648 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
3650 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
3651 if (CORBA::is_nil(myIteration))
3653 SALOME::ExceptionStruct es;
3654 es.type = SALOME::BAD_PARAM;
3655 es.text = "Invalid iterationStudy Object";
3656 throw SALOME::SALOME_Exception(es);
3660 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3662 aStudyBuilder->NewCommand();
3664 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
3665 // Pour les fichiers med, on affiche une icone de maillage
3666 // Pour les fichiers qui sont du texte, on affiche une icone de fichier texte 'texte'
3667 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
3669 std::string ior = " " ;
3670 if ( Commentaire[0] == 'I' )
3671 { icone = "med.png" ; }
3673 { icone = "texte_2.png" ; }
3674 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3676 aStudyBuilder->CommitCommand();
3679 //=============================================================================
3680 void HOMARD_Gen_i::PublishFileUnderYACS(const char* nomYACS, const char* NomFich, const char* Commentaire)
3682 // MESSAGE ("PublishFileUnderYACS pour le schema " << nomYACS << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3683 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3685 SALOMEDS::SObject_var aYACSSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3686 if (CORBA::is_nil(myYACS))
3688 SALOME::ExceptionStruct es;
3689 es.type = SALOME::BAD_PARAM;
3690 es.text = "Invalid YACSStudy Object";
3691 throw SALOME::SALOME_Exception(es);
3695 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3697 aStudyBuilder->NewCommand();
3699 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3700 std::string icone = "texte_2.png" ;
3701 std::string ior = " " ;
3702 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3704 aStudyBuilder->CommitCommand();
3707 //=============================================================================
3708 //=============================================================================
3710 //=============================================================================
3711 //=============================================================================
3712 //=============================================================================
3713 // Creation d'un schema YACS
3714 // nomCas : nom du cas a traiter
3715 // FileName : nom du fichier contenant le script de lancement du calcul
3716 // DirName : le repertoire de lancement des calculs du schéma
3717 //=============================================================================
3718 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::CreateYACSSchema (const char* nomYACS, const char* nomCas, const char* ScriptFile, const char* DirName, const char* MeshFile)
3720 INFOS ( "CreateYACSSchema : Schema YACS " << nomYACS );
3721 INFOS ( ". nomCas : " << nomCas);
3722 INFOS ( ". ScriptFile : " << ScriptFile);
3723 INFOS ( ". DirName : " << DirName);
3724 INFOS ( ". MeshFile : " << MeshFile);
3726 // A. Controle du nom :
3727 if ((myContextMap[GetCurrentStudyID()]._mesYACSs).find(nomYACS) != (myContextMap[GetCurrentStudyID()]._mesYACSs).end())
3729 SALOME::ExceptionStruct es;
3730 es.type = SALOME::BAD_PARAM;
3731 es.text = "This schema YACS has already been defined.";
3732 throw SALOME::SALOME_Exception(es);
3736 // B. Creation de l'objet
3737 HOMARD::HOMARD_YACS_var myYACS = newYACS();
3738 if (CORBA::is_nil(myYACS))
3740 SALOME::ExceptionStruct es;
3741 es.type = SALOME::BAD_PARAM;
3742 es.text = "Unable to create the schema YACS";
3743 throw SALOME::SALOME_Exception(es);
3746 myYACS->SetName( nomYACS ) ;
3748 // C. Enregistrement
3749 myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS] = myYACS;
3751 SALOMEDS::SObject_var aSO;
3752 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myYACS, nomYACS);
3754 PublishCaseUnderYACS(nomYACS, nomCas);
3756 // D. Caracterisation
3758 myYACS->SetDirName( DirName ) ;
3759 myYACS->SetMeshFile( MeshFile ) ;
3760 myYACS->SetScriptFile( ScriptFile ) ;
3761 myYACS->SetCaseName( nomCas ) ;
3763 // D.2.1. Type constant
3764 myYACS->SetType( 1 ) ;
3765 // D.2.2. Fichier de sauvegarde dans le repertoire du cas
3766 HOMARD::HOMARD_Cas_ptr caseyacs = GetCase(nomCas) ;
3767 std::string dirnamecase = caseyacs->GetDirName() ;
3768 std::string XMLFile ;
3769 XMLFile = dirnamecase + "/schema.xml" ;
3770 myYACS->SetXMLFile( XMLFile.c_str() ) ;
3772 return HOMARD::HOMARD_YACS::_duplicate(myYACS);
3774 //=============================================================================
3775 // Ecriture d'un schema YACS
3776 //=============================================================================
3777 CORBA::Long HOMARD_Gen_i::YACSWrite(const char* nomYACS)
3779 INFOS ( "YACSWrite : Ecriture de " << nomYACS );
3780 // Le repertoire du cas
3781 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3782 ASSERT(!CORBA::is_nil(myYACS));
3783 // Le nom du fichier du schema
3784 std::string XMLFile ;
3785 XMLFile = myYACS->GetXMLFile() ;
3787 int codret = YACSWriteOnFile(nomYACS, XMLFile.c_str()) ;
3791 //=============================================================================
3792 // Ecriture d'un schema YACS sur un fichier donne
3793 //=============================================================================
3794 CORBA::Long HOMARD_Gen_i::YACSWriteOnFile(const char* nomYACS, const char* XMLFile)
3796 INFOS ( "YACSWriteOnFile : Ecriture de " << nomYACS << " sur " << XMLFile );
3803 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3804 ASSERT(!CORBA::is_nil(myYACS));
3805 // B.2. Les caracteristiques
3806 std::string DirName = myYACS->GetDirName() ;
3807 std::string MeshFile = myYACS->GetMeshFile() ;
3808 std::string ScriptFile = myYACS->GetScriptFile() ;
3812 const char* nomCas = myYACS->GetCaseName();
3813 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
3814 ASSERT(!CORBA::is_nil(myCase));
3815 // C.2. Les instructions python associees au cas
3816 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
3817 std::string pythonCas = dumpCorbaCase.in();
3818 MESSAGE ("pythonCas :\n"<<pythonCas<<"\n");
3820 // D. Les iterations
3821 // D.1. L'iteration initiale
3822 HOMARD::HOMARD_Iteration_var Iter0 = myCase->GetIter0() ;
3823 std::string Iter0Name = myCase->GetIter0Name() ;
3824 MESSAGE (". Iter0Name = " << Iter0Name);
3825 std::string MeshName = Iter0->GetMeshName();
3826 MESSAGE (". MeshName = " << MeshName);
3827 // D.2. L'iteration numero 1
3828 HOMARD::listeIterFilles* maListe = Iter0->GetIterations();
3829 int numberOfIter = maListe->length();
3830 if ( numberOfIter > 1 )
3832 MESSAGE (". numberOfIter = " << numberOfIter);
3833 SALOME::ExceptionStruct es ;
3834 es.type = SALOME::BAD_PARAM;
3835 std::string text = "Une seule iteration est permise." ;
3836 es.text = CORBA::string_dup(text.c_str());
3837 throw SALOME::SALOME_Exception(es);
3840 std::string Iter1Name = std::string((*maListe)[0]);
3841 MESSAGE ("... Iter1Name = " << Iter1Name);
3842 HOMARD::HOMARD_Iteration_var Iter1 = GetIteration(Iter1Name.c_str()) ;
3843 // D.3. Les instructions python associees a l'iteration
3844 CORBA::String_var dumpCorbaIter = Iter1->GetDumpPython();
3845 std::string pythonIter = dumpCorbaIter.in();
3846 MESSAGE ("pythonIter :\n"<<pythonIter<<"\n");
3848 // E. L'hypothese pour passer de l'iteration initiale a la suivante
3849 // E.1. La structure
3850 std::string nomHypo = Iter1->GetHypoName();
3851 MESSAGE (". nomHypo = " << nomHypo);
3852 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
3853 ASSERT(!CORBA::is_nil(myHypo));
3854 // E.2. Les caracteristiques de l'adaptation
3855 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
3856 ASSERT(ListTypes->length() == 3);
3857 int TypeAdap = (*ListTypes)[0];
3858 // int TypeRaff = (*ListTypes)[1];
3859 // int TypeDera = (*ListTypes)[2];
3860 // E.3. Les instructions python associees a l'hypothese
3861 CORBA::String_var dumpCorbaHypo = myHypo->GetDumpPython();
3862 std::string pythonHypo = dumpCorbaHypo.in();
3863 MESSAGE ("pythonHypo :\n"<<pythonHypo<<"\n");
3865 // F. Le fichier du schema de reference
3866 // HOMARD_ROOT_DIR : repertoire ou se trouve le module HOMARD
3867 std::string XMLFile_base ;
3868 if ( getenv("HOMARD_ROOT_DIR") != NULL ) { XMLFile_base = getenv("HOMARD_ROOT_DIR") ; }
3871 SALOME::ExceptionStruct es ;
3872 es.type = SALOME::BAD_PARAM;
3873 std::string text = "HOMARD_ROOT_DIR est inconnu." ;
3874 es.text = CORBA::string_dup(text.c_str());
3875 throw SALOME::SALOME_Exception(es);
3878 XMLFile_base += "/share/salome/resources/homard/yacs_01." + _LangueShort + ".xml" ;
3880 MESSAGE("XMLFile_base ="<<XMLFile_base);
3882 // G. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
3883 YACSDriver* myDriver = new YACSDriver(XMLFile, DirName);
3884 std::ifstream fichier( XMLFile_base.c_str() );
3885 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
3887 // G.1. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
3888 std::string ligne; // variable contenant chaque ligne lue
3889 std::string mot_cle;
3890 while ( std::getline( fichier, ligne ) )
3892 // G.1.1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
3893 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
3894 ligne_bis >> mot_cle ;
3895 // G.1.2. Le maillage initial
3896 if ( mot_cle == "DataInit_MeshFile" )
3897 { myDriver->Texte_DataInit_MeshFile(MeshFile); }
3898 // G.1.3. Le script de lancement
3899 else if ( mot_cle == "Alternance_Calcul_HOMARD_Calcul" )
3900 { myDriver->Texte_Alternance_Calcul_HOMARD_Calcul(ScriptFile); }
3901 // G.1.4. Les options du cas
3902 else if ( mot_cle == "Iter_1_Case_Options" )
3903 { myDriver->Texte_Iter_1_Case_Options(pythonCas); }
3904 // G.1.5. Execution de HOMARD : le repertoire du cas
3905 else if ( mot_cle == "HOMARD_Exec_DirName" )
3906 { myDriver->Texte_HOMARD_Exec_DirName(); }
3907 // G.1.6. Execution de HOMARD : le nom du maillage
3908 else if ( mot_cle == "HOMARD_Exec_MeshName" )
3910 myDriver->Texte_HOMARD_Exec_MeshName(MeshName);
3911 std::string node = "Boucle_de_convergence.Alternance_Calcul_HOMARD.Adaptation.p0_Adaptation_HOMARD.HOMARD_Initialisation.p1_Iter_1.CreateCase" ;
3912 myDriver->TexteParametre( node, "MeshName", "string", MeshName ) ;
3914 // G.1.7. Execution de HOMARD : les options de l'hypothese
3915 else if ( mot_cle == "HOMARD_Exec_Hypo_Options" )
3916 { myDriver->Texte_python_1( pythonHypo, 3, "Hypo" ) ; }
3917 // G.1.8. Execution de HOMARD : les options de l'iteration
3918 else if ( mot_cle == "HOMARD_Exec_Iter_Options" )
3919 { myDriver->Texte_python_2( pythonIter, "TimeStep", "Iter" ) ; }
3920 // G.1.9. Zones et frontieres : les creations
3921 else if ( mot_cle == "Iter_1" )
3923 std::string texte_control = myDriver->Texte_Iter_1_control() ;
3924 if ( TypeAdap == 0 ) { texte_control += YACSDriverTexteZone( myHypo, myDriver ) ; }
3925 texte_control += YACSDriverTexteBoundary( myCase, myDriver ) ;
3926 myDriver->TexteAdd(texte_control);
3928 // G.1.10. Les parametres
3929 else if ( mot_cle == "PARAMETRES" )
3930 { myDriver->TexteAddParametres(); }
3931 // G.1.n. La ligne est recopiee telle quelle
3932 else { myDriver->TexteAdd(ligne); }
3934 // G.2. Ecriture du texte dans le fichier
3936 { myDriver->CreeFichier(); }
3940 SALOME::ExceptionStruct es;
3941 es.type = SALOME::BAD_PARAM;
3942 std::string text = "The reference file for the YACS schema cannot be read." ;
3943 es.text = CORBA::string_dup(text.c_str());
3944 throw SALOME::SALOME_Exception(es);
3949 // H. Publication du fichier dans l'arbre
3951 std::string Commentaire = "xml" ;
3952 PublishFileUnderYACS(nomYACS, XMLFile, Commentaire.c_str());
3956 //=============================================================================
3957 // Ecriture d'un schema YACS : ecriture des zones associees a une hypothese
3958 //=============================================================================
3959 std::string HOMARD_Gen_i::YACSDriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, YACSDriver* myDriver)
3961 MESSAGE ( "YACSDriverTexteZone" );
3962 // A. Les zones associees a cette hypothese
3963 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
3964 int numberOfZonesx2 = ListZone->length();
3966 // B. Parcours des zones
3967 std::string texte_control ;
3968 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
3970 // 1. Reperage de la zone
3971 std::string ZoneName = std::string((*ListZone)[iaux]);
3972 MESSAGE ( "\n. ZoneName = " << ZoneName << " - " <<iaux);
3973 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
3974 ASSERT(!CORBA::is_nil(myZone));
3975 // 2. Les instructions python associees a la zone
3976 // La premiere ligne est un commentaire a eliminer
3977 // La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
3978 CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
3979 std::string pythonStructure_0 = dumpCorbaZone.in();
3980 MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
3981 std::istringstream tout (pythonStructure_0) ;
3983 std::string pythonStructure ;
3984 while ( std::getline( tout, ligne ) )
3985 { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
3986 MESSAGE ("pythonStructure :\n"<<pythonStructure);
3987 // 3. Decodage du nom du service
3988 std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
3989 MESSAGE ( "... methode = " << methode);
3990 // 4. Mise en place des instructions
3991 int ZoneType = myZone->GetType();
3992 MESSAGE ( "... ZoneType = " << ZoneType);
3993 std::string texte_control_0 ;
3994 texte_control_0 = myDriver->Texte_Iter_1_Zone(ZoneType, pythonStructure, methode, ZoneName );
3995 texte_control += texte_control_0 ;
4000 return texte_control ;
4002 //=============================================================================
4003 // Ecriture d'un schema YACS : ecriture des frontieres associees au cas
4004 //=============================================================================
4005 std::string HOMARD_Gen_i::YACSDriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, YACSDriver* myDriver)
4007 MESSAGE ( "YACSDriverTexteBoundary" );
4008 // A. Les frontieres associees au cas
4009 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
4010 int numberOfitems = ListBoundaryGroupType->length();
4012 // B. Parcours des frontieres
4013 std::string texte_control ;
4014 std::list<std::string> ListeBoundaryTraitees ;
4015 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
4017 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
4018 MESSAGE ( "... BoundaryName = " << BoundaryName);
4019 // Attention a n'ecrire la definition qu'une seule fois car elle peut se trouver
4020 // plusieurs fois dans la definition du cas, d'ou la liste ListeBoundaryTraitees
4022 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
4023 while (it != ListeBoundaryTraitees.end())
4025 MESSAGE ( "..... BoundaryNameTraitee = " << *it);
4026 if ( BoundaryName == *it ) { A_faire = 0 ; }
4031 // 1. Caracteristiques de la frontiere
4032 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
4033 ASSERT(!CORBA::is_nil(myBoundary));
4034 // 2. Les instructions python associees a la frontiere
4035 // La premiere ligne est un commentaire a eliminer
4036 // La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4037 CORBA::String_var dumpCorbaBoundary = myBoundary->GetDumpPython();
4038 std::string pythonStructure_0 = dumpCorbaBoundary.in();
4039 MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4040 std::istringstream tout (pythonStructure_0) ;
4042 std::string pythonStructure ;
4043 while ( std::getline( tout, ligne ) )
4044 { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4045 MESSAGE ("pythonStructure :\n"<<pythonStructure);
4046 // 3. Decodage du nom du service
4047 std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4048 MESSAGE ( "... methode = " << methode);
4049 // 4. Mise en place des instructions
4050 int BoundaryType = myBoundary->GetType();
4051 MESSAGE ( "... BoundaryType = " << BoundaryType);
4052 std::string texte_control_0 ;
4053 texte_control_0 = myDriver->Texte_Iter_1_Boundary(BoundaryType, pythonStructure, methode, BoundaryName );
4054 texte_control += texte_control_0 ;
4055 // 5. Memorisation du traitement
4056 ListeBoundaryTraitees.push_back( BoundaryName );
4060 return texte_control ;
4063 //=============================================================================
4064 //=============================================================================
4065 // Next functions are inherited from SALOMEDS::Driver interface
4066 //=============================================================================
4067 //=============================================================================
4068 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
4070 CORBA::Boolean isMultiFile)
4072 MESSAGE ("Save for theURL = "<< theURL);
4073 SALOMEDS::TMPFile_var aStreamFile;
4075 // get temporary directory name
4076 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4078 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
4079 StudyContext& context = myContextMap[ aStudy->StudyId() ];
4081 // HOMARD data file name
4082 std::string aFileName = "";
4084 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
4085 aFileName += "_HOMARD.dat";
4087 // initialize sequence of file names
4088 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
4089 aFileSeq->length(1);
4090 aFileSeq[0] = CORBA::string_dup(aFileName.c_str()) ;
4092 // get full path to the data file
4093 aFileName = tmpDir + aFileName;
4097 std::ofstream f(aFileName.c_str());
4099 // clear temporary id map
4100 context._idmap.clear();
4105 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
4106 for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
4107 HOMARD::HOMARD_Cas_var aCas = it_case->second;
4108 PortableServer::ServantBase_var aServant = GetServant(aCas);
4109 HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4111 f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
4112 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
4116 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4117 for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
4118 HOMARD::HOMARD_Zone_var aZone = it_zone->second;
4119 PortableServer::ServantBase_var aServant = GetServant(aZone);
4120 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4122 f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
4123 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4126 // -> save hypotheses
4127 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4128 for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
4129 HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
4130 PortableServer::ServantBase_var aServant = GetServant(aHypo);
4131 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4133 f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
4134 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4137 // -> save iterations
4138 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4139 for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
4140 HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
4141 PortableServer::ServantBase_var aServant = GetServant(aIter);
4142 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4144 f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
4145 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4148 // -> save boundaries
4149 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4150 for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
4151 HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
4152 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4153 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4154 if (aBoundaryServant) {
4155 f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
4156 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4160 MESSAGE ("close file");
4163 // put temporary files to the stream
4164 MESSAGE ("put temporary files to the stream");
4165 aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq.in(), isMultiFile);
4167 // remove temporary files
4168 MESSAGE ("remove temporary files");
4169 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4171 // return data stream
4172 MESSAGE ("return data stream");
4173 return aStreamFile._retn();
4176 //===========================================================================
4177 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
4179 CORBA::Boolean isMultiFile)
4181 // No specific ASCII persistence
4182 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
4183 return aStreamFile._retn();
4186 //===========================================================================
4187 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
4188 const SALOMEDS::TMPFile& theStream,
4190 CORBA::Boolean isMultiFile)
4192 MESSAGE ("Load pour theURL = "<< theURL);
4193 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
4195 // set current study
4196 if (myCurrentStudy->_is_nil() || aStudy->StudyId() != myCurrentStudy->StudyId())
4197 SetCurrentStudy(aStudy);
4199 // get temporary directory name
4200 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4202 // Convert the stream into sequence of files to process
4203 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
4206 // HOMARD data file name
4207 std::string aFileName = "";
4209 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
4210 aFileName = tmpDir + aFileName + "_HOMARD.dat";
4212 StudyContext& context = myContextMap[ aStudy->StudyId() ];
4216 std::ifstream f(aFileName.c_str());
4219 context._mesCas.clear();
4220 context._mesHypotheses.clear();
4221 context._mesIterations.clear();
4222 context._mesZones.clear();
4223 context._mesBoundarys.clear();
4224 context._idmap.clear();
4230 std::getline(f, line);
4231 std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
4232 std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
4233 std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
4234 std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
4235 std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
4236 std::string yacsSignature = HOMARD::GetSignature(HOMARD::YACS);
4237 if (line.substr(0, bounSignature.size()) == bounSignature) {
4238 // re-create boundary
4239 MESSAGE ("Recreation de la frontiere" );
4240 HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
4241 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4242 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4243 if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
4244 context._mesBoundarys[aBoundary->GetName()] = aBoundary;
4245 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4248 else if (line.substr(0, caseSignature.size()) == caseSignature) {
4250 MESSAGE ("Recreation du cas" );
4251 HOMARD::HOMARD_Cas_var aCase = newCase();
4252 PortableServer::ServantBase_var aServant = GetServant(aCase);
4253 HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4254 if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
4255 context._mesCas[aCase->GetName()] = aCase;
4256 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
4259 else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
4260 // re-create hypothesis
4261 MESSAGE ("Recreation de l hypothese" );
4262 HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
4263 PortableServer::ServantBase_var aServant = GetServant(aHypo);
4264 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4265 if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
4266 context._mesHypotheses[aHypo->GetName()] = aHypo;
4267 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4270 else if (line.substr(0, iterSignature.size()) == iterSignature) {
4271 // re-create iteration
4272 MESSAGE ("Recreation de l iteration" );
4273 HOMARD::HOMARD_Iteration_var aIter = newIteration();
4274 PortableServer::ServantBase_var aServant = GetServant(aIter);
4275 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4276 if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
4277 context._mesIterations[aIter->GetName()] = aIter;
4278 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4281 else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
4282 MESSAGE ("Recreation de la zone" );
4284 HOMARD::HOMARD_Zone_var aZone = newZone();
4285 PortableServer::ServantBase_var aServant = GetServant(aZone);
4286 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4287 if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
4288 context._mesZones[aZone->GetName()] = aZone;
4289 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4292 else if (line.substr(0, zoneSignature.size()) == yacsSignature) {
4293 MESSAGE ("Recreation du schema YACS" );
4295 HOMARD::HOMARD_YACS_var aYACS = newYACS();
4296 PortableServer::ServantBase_var aServant = GetServant(aYACS);
4297 HOMARD_YACS_i* aYACSServant = dynamic_cast<HOMARD_YACS_i*>(aServant.in());
4298 if (aYACSServant && aYACSServant->Restore(line.substr(yacsSignature.size()))) {
4299 context._mesYACSs[aYACS->GetName()] = aYACS;
4300 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aYACSServant);
4309 // Remove temporary files created from the stream
4311 SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4316 //===========================================================================
4317 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
4318 const SALOMEDS::TMPFile& theStream,
4320 CORBA::Boolean isMultiFile)
4322 // No specific ASCII persistence
4323 return Load(theComponent, theStream, theURL, isMultiFile);
4326 //===========================================================================
4327 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
4329 if (theComponent->GetStudy()->StudyId() == GetCurrentStudyID()) {
4330 // clearing study context should be done here:
4331 // - destroy all servants and related CORBA objects
4333 // - remove context from myContextMap
4334 myContextMap.erase(theComponent->GetStudy()->StudyId());
4335 // - nullify myCurrentStudy
4336 myCurrentStudy = SALOMEDS::Study::_nil();
4340 //===========================================================================
4341 char* HOMARD_Gen_i::ComponentDataType()
4343 return CORBA::string_dup("HOMARD");
4346 //===========================================================================
4347 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
4348 const char* IORString,
4349 CORBA::Boolean isMultiFile,
4350 CORBA::Boolean isASCII)
4352 CORBA::String_var aString("");
4353 if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
4354 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4355 CORBA::Object_var anObj = _orb->string_to_object(IORString);
4356 if (!CORBA::is_nil(anObj)) {
4357 PortableServer::ServantBase_var aServant = GetServant(anObj);
4358 PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
4360 std::map<int, PortableServer::ServantBase*>::const_iterator it;
4361 for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
4362 if (it->second == aStorable) {
4363 std::stringstream os;
4365 aString = CORBA::string_dup(os.str().c_str());
4371 return aString._retn();
4374 //===========================================================================
4375 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
4376 const char* aLocalPersistentID,
4377 CORBA::Boolean isMultiFile,
4378 CORBA::Boolean isASCII)
4380 CORBA::String_var aString("");
4381 if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
4382 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4383 int id = atoi(aLocalPersistentID);
4384 if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
4385 CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
4386 if (!CORBA::is_nil(object)) {
4387 aString = _orb->object_to_string(object);
4391 return aString._retn();
4394 //===========================================================================
4395 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
4397 if(CORBA::is_nil(myCurrentStudy))
4400 HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
4401 if(!aCas->_is_nil())
4404 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
4405 if(!aHypo->_is_nil())
4408 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
4409 if(!aZone->_is_nil())
4412 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
4413 if(!aBoundary->_is_nil())
4416 /* Iteration is not published directly
4417 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
4418 if(!aIter->_is_nil())
4424 //===========================================================================
4425 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
4427 // No Copy/Paste support
4431 //===========================================================================
4432 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
4433 CORBA::Long& theObjectID)
4435 // No Copy/Paste support
4436 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
4437 return aStreamFile._retn();
4440 //===========================================================================
4441 CORBA::Boolean HOMARD_Gen_i::CanPaste(const char *theComponentName,
4442 CORBA::Long theObjectID)
4444 // No Copy/Paste support
4448 //===========================================================================
4449 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
4450 CORBA::Long theObjectID,
4451 SALOMEDS::SObject_ptr theSObject)
4453 // No Copy/Paste support
4454 SALOMEDS::SObject_var aResultSO;
4455 return aResultSO._retn();
4458 //===========================================================================
4459 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
4461 PortableServer::Servant aServant = 0;
4462 if (!CORBA::is_nil(theObject)) {
4464 aServant = _poa->reference_to_servant(theObject);
4472 //==========================================================================
4473 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
4474 CORBA::Boolean isPublished,
4475 CORBA::Boolean isMultiFile,
4476 CORBA::Boolean& isValidScript)
4478 MESSAGE ("Entree dans DumpPython");
4480 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
4481 if(CORBA::is_nil(aStudy))
4482 return new Engines::TMPFile(0);
4484 SALOMEDS::SObject_var aSO = aStudy->FindComponent("HOMARD");
4485 if(CORBA::is_nil(aSO))
4486 return new Engines::TMPFile(0);
4488 std::string aScript = "\"\"\"\n";
4489 aScript += "Python script for HOMARD\n";
4490 aScript += "Copyright EDF-R&D 2013\n";
4491 aScript += "\"\"\"\n";
4492 aScript += "__revision__ = \"V1.2\"\n";
4493 aScript += "import HOMARD\n";
4495 aScript += "import salome\n";
4496 aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
4498 aScript += "def RebuildData(theStudy):\n";
4499 aScript += "\thomard.SetCurrentStudy(theStudy)\n";
4502 aScript += "\thomard.SetCurrentStudy(salome.myStudy)\n";
4503 MESSAGE (". Au depart \n"<<aScript);
4506 if (myContextMap[GetCurrentStudyID()]._mesBoundarys.size() > 0)
4508 MESSAGE (". Ecritures des frontieres");
4509 aScript += "#\n# Creation of the boundaries";
4510 aScript += "\n# ==========================";
4512 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4513 for (it_boundary = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
4514 it_boundary != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); ++it_boundary)
4516 HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
4517 CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
4518 std::string dumpBoundary = dumpCorbaBoundary.in();
4519 MESSAGE (dumpBoundary<<"\n");
4520 aScript += dumpBoundary;
4524 if (myContextMap[GetCurrentStudyID()]._mesZones.size() > 0)
4526 MESSAGE (". Ecritures des zones");
4527 aScript += "#\n# Creation of the zones";
4528 aScript += "\n# =====================";
4530 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4531 for ( it_zone = myContextMap[GetCurrentStudyID()]._mesZones.begin();
4532 it_zone != myContextMap[GetCurrentStudyID()]._mesZones.end(); ++it_zone)
4534 HOMARD::HOMARD_Zone_var myZone = (*it_zone).second;
4535 CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4536 std::string dumpZone = dumpCorbaZone.in();
4537 MESSAGE (dumpZone<<"\n");
4538 aScript += dumpZone;
4542 if (myContextMap[GetCurrentStudyID()]._mesHypotheses.size() > 0)
4544 MESSAGE (". Ecritures des hypotheses");
4545 aScript += "#\n# Creation of the hypotheses";
4546 aScript += "\n# ==========================";
4548 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4549 for ( it_hypo = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
4550 it_hypo != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it_hypo++)
4552 HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
4553 CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
4554 std::string dumpHypo = dumpCorbaHypo.in();
4555 MESSAGE (dumpHypo<<"\n");
4556 aScript += dumpHypo;
4560 if (myContextMap[GetCurrentStudyID()]._mesCas.size() > 0)
4562 MESSAGE (". Ecritures des cas");
4563 aScript += "#\n# Creation of the cases";
4564 aScript += "\n# =====================";
4566 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
4567 for (it_cas = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4568 it_cas != myContextMap[GetCurrentStudyID()]._mesCas.end(); it_cas++)
4570 std::string nomCas = (*it_cas).first;
4571 std::string dumpCas = std::string("\n# Creation of the case ") ;
4572 dumpCas += nomCas + std::string("\n");
4573 dumpCas += std::string("\t") + nomCas;
4574 dumpCas += std::string(" = homard.CreateCase(\"") + nomCas + std::string("\", \"");
4576 HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
4577 CORBA::String_var cIter0= myCase->GetIter0Name();
4578 std::string iter0 = cIter0.in();
4580 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[iter0];
4581 CORBA::String_var cMesh0= myIteration->GetMeshFile();
4582 std::string mesh0 = cMesh0.in();
4583 CORBA::String_var cMeshName0= myIteration->GetMeshName();
4584 std::string meshName0 = cMeshName0.in();
4585 dumpCas += meshName0 + std::string("\", \"")+ mesh0 + std::string("\")\n");
4586 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4587 std::string dumpCas2= dumpCorbaCase.in();
4589 MESSAGE (dumpCas<<dumpCas2<<"\n");
4590 aScript += dumpCas + dumpCas2;
4594 if (myContextMap[GetCurrentStudyID()]._mesIterations.size() > 0)
4596 MESSAGE (". Ecritures des iterations");
4597 aScript += "#\n# Creation of the iterations" ;
4598 aScript += "\n# ==========================";
4600 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4601 for (it_iter = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
4602 it_iter != myContextMap[GetCurrentStudyID()]._mesIterations.end(); ++it_iter)
4604 HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
4605 CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
4606 std::string dumpIter = dumpCorbaIter.in();
4607 MESSAGE (dumpIter<<"\n");
4608 aScript += dumpIter;
4612 if (myContextMap[GetCurrentStudyID()]._mesYACSs.size() > 0)
4614 MESSAGE (". Ecritures des schemas YACS");
4615 aScript += "#\n# Creation of the schemas YACS";
4616 aScript += "\n# ============================";
4618 std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it_yacs;
4619 for ( it_yacs = myContextMap[GetCurrentStudyID()]._mesYACSs.begin();
4620 it_yacs != myContextMap[GetCurrentStudyID()]._mesYACSs.end(); ++it_yacs)
4622 HOMARD::HOMARD_YACS_var myYACS = (*it_yacs).second;
4623 CORBA::String_var dumpCorbaYACS = myYACS->GetDumpPython();
4624 std::string dumpYACS = dumpCorbaYACS.in();
4625 MESSAGE (dumpYACS<<"\n");
4626 aScript += dumpYACS;
4629 MESSAGE (". Ecritures finales");
4631 aScript += "\n\tpass";
4634 if( !isMultiFile ) // remove unnecessary tabulation
4635 aScript = RemoveTabulation( aScript );
4637 // MESSAGE ("A ecrire \n"<<aScript);
4638 const size_t aLen = strlen(aScript.c_str());
4639 char* aBuffer = new char[aLen+1];
4640 strcpy(aBuffer, aScript.c_str());
4642 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
4643 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
4645 MESSAGE ("Sortie de DumpPython");
4646 return aStreamFile._retn();
4650 //=============================================================================
4651 //=============================================================================
4653 //=============================================================================
4654 //=============================================================================
4655 void HOMARD_Gen_i::IsValidStudy( )
4657 // MESSAGE( "IsValidStudy" );
4658 if (CORBA::is_nil(myCurrentStudy))
4660 SALOME::ExceptionStruct es;
4661 es.type = SALOME::BAD_PARAM;
4662 es.text = "Invalid study context";
4663 throw SALOME::SALOME_Exception(es);
4668 //=============================================================================
4669 CORBA::Boolean HOMARD_Gen_i::VerifieDir(const char* nomDir)
4671 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
4672 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4673 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
4675 if (std::string(nomDir) == std::string(it->second->GetDirName())) return false;
4679 /*//=============================================================================
4680 void SALOMEException( std::string message )
4682 SALOME::ExceptionStruct es;
4683 es.type = SALOME::BAD_PARAM;
4685 throw SALOME::SALOME_Exception(es);
4688 //=============================================================================
4689 char* HOMARD_Gen_i::getVersion()
4691 #if HOMARD_DEVELOPMENT
4692 return CORBA::string_dup(HOMARD_VERSION_STR"dev");
4694 return CORBA::string_dup(HOMARD_VERSION_STR);
4697 //===============================================================================
4698 // Recuperation de la chaine de caracteres par rapport a l'apparition d'un texte
4699 // ligne : la ligne a manipuler
4700 // texte : le texte a reperer
4701 // option : 0 : la chaine avant le texte
4702 // 1 : la chaine apres le texte
4703 // Si le texte est absent, on retourne la chaine totale
4704 //===============================================================================
4705 std::string HOMARD_Gen_i::GetStringInTexte( const std::string ligne, const std::string texte, int option )
4707 // MESSAGE("GetStringInTexte, recherche de '"<<texte<<"' dans '"<<ligne<<"'"<<", option = "<<option);
4709 std::string chaine = ligne ;
4710 int position = ligne.find_first_of( texte ) ;
4713 if ( option == 0 ) { chaine = ligne.substr( 0, position ) ; }
4714 else { chaine = ligne.substr( position+1 ) ; }
4719 // //===============================================================================
4720 // // Langue de SALOME
4721 // //===============================================================================
4722 void HOMARD_Gen_i::SetLanguageShort(const char* LanguageShort)
4724 // MESSAGE ("SetLanguageShort pour LanguageShort = " << LanguageShort );
4725 _LangueShort = LanguageShort ;
4726 if ( _LangueShort == "fr" ) { _Langue = "Francais" ; }
4727 else { _Langue = "English" ; }
4730 char* HOMARD_Gen_i::GetLanguageShort()
4732 // MESSAGE ("GetLanguageShort");
4733 return CORBA::string_dup( _LangueShort.c_str() );
4736 //=============================================================================
4739 PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
4740 PortableServer::POA_ptr poa,
4741 PortableServer::ObjectId* contId,
4742 const char* instanceName,
4743 const char* interfaceName)
4745 MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
4746 HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
4747 return myHOMARD_Gen->getId();