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 if ( modeHOMARD == 1 )
2384 if (codretexec == 0) { SetEtatIter(NomIteration,2); }
2385 else { SetEtatIter(NomIteration,1); }
2386 // GERALD -- QMESSAGE BOX
2390 // H. Gestion des resultats
2393 std::string Commentaire ;
2394 // H.1. Le fichier des messages, dans tous les cas
2395 Commentaire = "log" ;
2396 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2397 else { Commentaire += "Info" ; }
2398 PublishFileUnderIteration(NomIteration, LogFile.c_str(), Commentaire.c_str());
2400 // H.2. Si tout s'est bien passe :
2401 if (codretexec == 0)
2403 // H.2.1. Le fichier de bilan
2404 Commentaire = "Summary" ;
2405 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2406 else { Commentaire += "Info" ; }
2407 PublishFileUnderIteration(NomIteration, FileInfo.c_str(), Commentaire.c_str());
2408 // H.2.2. Le fichier de maillage obtenu
2409 if ( modeHOMARD == 1 )
2411 std::stringstream saux0 ;
2412 Commentaire = "Mesh" ;
2413 Commentaire += " " + siterp1 ;
2414 PublishFileUnderIteration(NomIteration, MeshFile, Commentaire.c_str());
2415 if ( Option2 % 2 == 0 ) { PublishResultInSmesh(MeshFile, 1); }
2418 // H.3 Message d'erreur en cas de probleme
2421 SALOME::ExceptionStruct es;
2422 es.type = SALOME::BAD_PARAM;
2423 std::string text = "Error during the adaptation.\n" ;
2426 ifstream fichier(LogFile.c_str(), ios::in);
2428 while(getline(fichier, ligne) and (ligne != "===== HOMARD ===== STOP ====="));
2429 while (getline(fichier, ligne)) { text += ligne+ "\n";};
2432 text += "no log file ....";
2434 es.text = CORBA::string_dup(text.c_str());
2435 throw SALOME::SALOME_Exception(es);
2439 // I. Menage et retour dans le repertoire du cas
2443 MESSAGE ( ". On retourne dans nomDirWork = " << nomDirWork );
2444 chdir(nomDirWork.c_str());
2449 //=============================================================================
2450 // Calcul d'une iteration : partie specifique a l'adaptation
2451 //=============================================================================
2452 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)
2454 MESSAGE ( "ComputeAdap" );
2459 // Etat de l'iteration
2460 int etat = myIteration->GetState();
2461 // Numero de l'iteration
2462 int NumeIter = myIteration->GetNumber();
2463 std::stringstream saux0 ;
2464 saux0 << NumeIter-1 ;
2465 std::string siter = saux0.str() ;
2466 if (NumeIter < 11) { siter = "0" + siter ; }
2468 // A.2. On ne calcule pas l iteration initiale
2471 MESSAGE ( "etat = "<<etat );
2472 SALOME::ExceptionStruct es;
2473 es.type = SALOME::BAD_PARAM;
2474 es.text = "This iteration is the first of the case and cannot be computed.";
2475 throw SALOME::SALOME_Exception(es);
2479 // A.3. On verifie qu il y a une hypothese (erreur improbable);
2480 const char* nomHypo = myIteration->GetHypoName();
2481 if (std::string(nomHypo) == std::string(""))
2483 SALOME::ExceptionStruct es;
2484 es.type = SALOME::BAD_PARAM;
2485 es.text = "This iteration does not have any associated hypothesis.";
2486 throw SALOME::SALOME_Exception(es);
2489 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
2490 ASSERT(!CORBA::is_nil(myHypo));
2492 // B. L'iteration parent
2493 const char* nomIterationParent = myIteration->GetIterParentName();
2494 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
2495 ASSERT(!CORBA::is_nil(myIterationParent));
2496 // Si l'iteration parent n'est pas calculee, on le fait (recursivite amont)
2497 if ( myIterationParent->GetState() == 1 )
2500 int codret = Compute(nomIterationParent, etatMenage, iaux, Option1, Option2);
2503 // GERALD -- QMESSAGE BOX
2504 VERIFICATION("Pb au calcul de l'iteration precedente" == 0);
2508 // C. Le sous-repertoire de l'iteration precedente
2509 char* DirComputePa = ComputeDirPaManagement(myCase, myIteration);
2510 MESSAGE( ". DirComputePa = " << DirComputePa );
2512 // D. Les donnees de l'adaptation HOMARD
2513 // D.1. Le type de conformite
2514 int ConfType = myCase->GetConfType();
2515 MESSAGE ( ". ConfType = " << ConfType );
2517 // D.2. Le maillage de depart
2518 const char* NomMeshParent = myIterationParent->GetMeshName();
2519 MESSAGE ( ". NomMeshParent = " << NomMeshParent );
2520 const char* MeshFileParent = myIterationParent->GetMeshFile();
2521 MESSAGE ( ". MeshFileParent = " << MeshFileParent );
2523 // D.3. Le maillage associe a l'iteration
2524 const char* MeshFile = myIteration->GetMeshFile();
2525 MESSAGE ( ". MeshFile = " << MeshFile );
2526 FILE *file = fopen(MeshFile,"r");
2530 if (etatMenage == 0)
2532 SALOME::ExceptionStruct es;
2533 es.type = SALOME::BAD_PARAM;
2534 std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
2535 es.text = CORBA::string_dup(text.c_str());
2536 throw SALOME::SALOME_Exception(es);
2541 std::string commande = "rm -f " + std::string(MeshFile);
2542 codret = system(commande.c_str());
2545 SALOME::ExceptionStruct es;
2546 es.type = SALOME::BAD_PARAM;
2547 es.text = "The mesh file cannot be deleted.";
2548 throw SALOME::SALOME_Exception(es);
2554 // D.4. Les types de raffinement et de deraffinement
2555 // Les appels corba sont lourds, il vaut mieux les grouper
2556 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
2557 ASSERT(ListTypes->length() == 3);
2558 int TypeAdap = (*ListTypes)[0];
2559 int TypeRaff = (*ListTypes)[1];
2560 int TypeDera = (*ListTypes)[2];
2562 // E. Texte du fichier de configuration
2563 // E.1. Incontournables du texte
2564 myDriver->TexteAdap();
2566 myDriver->TexteMaillageHOMARD( DirComputePa, siter, iaux ) ;
2567 myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
2568 myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
2570 // E.2. Ajout des informations liees aux zones eventuelles
2571 if ( TypeAdap == 0 )
2572 { DriverTexteZone(myHypo, myDriver) ; }
2574 // E.3. Ajout des informations liees aux champs eventuels
2575 if ( TypeAdap == 1 )
2576 { DriverTexteField(myIteration, myHypo, myDriver) ; }
2578 // E.4. Ajout des informations liees au filtrage eventuel par les groupes
2579 HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
2580 int numberOfGroups = listeGroupes->length();
2581 MESSAGE( ". Filtrage par " << numberOfGroups << " groupes");
2582 if (numberOfGroups > 0)
2584 for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
2586 std::string GroupName = std::string((*listeGroupes)[NumGroup]);
2587 MESSAGE( "... GroupName = " << GroupName );
2588 myDriver->TexteGroup(GroupName);
2592 // E.5. Ajout des informations liees a l'eventuelle interpolation des champs
2593 DriverTexteFieldInterp(myIteration, myHypo, myDriver) ;
2595 // E.6. Ajout des options avancees
2596 int Pyram = myCase->GetPyram();
2597 MESSAGE ( ". Pyram = " << Pyram );
2598 int NivMax = myHypo->GetNivMax();
2599 MESSAGE ( ". NivMax = " << NivMax );
2600 double DiamMin = myHypo->GetDiamMin() ;
2601 MESSAGE ( ". DiamMin = " << DiamMin );
2602 int AdapInit = myHypo->GetAdapInit();
2603 MESSAGE ( ". AdapInit = " << AdapInit );
2604 int LevelOutput = myHypo->GetLevelOutput();
2605 MESSAGE ( ". LevelOutput = " << LevelOutput );
2606 myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, LevelOutput);
2608 // E.7. Ajout des informations sur le deroulement de l'execution
2609 int MessInfo = myIteration->GetInfoCompute();
2610 MESSAGE ( ". MessInfo = " << MessInfo );
2611 myDriver->TexteInfoCompute(MessInfo);
2615 //=============================================================================
2616 // Creation d'un nom de sous-repertoire pour l'iteration au sein d'un repertoire parent
2617 // nomrep : nom du repertoire parent
2618 // num : le nom du sous-repertoire est sous la forme 'In', n est >= num
2619 //=============================================================================
2620 char* HOMARD_Gen_i::CreateDirNameIter(const char* nomrep, CORBA::Long num )
2622 MESSAGE ( "CreateDirNameIter : nomrep ="<< nomrep << ", num = "<<num);
2623 // On verifie que le repertoire parent existe
2624 int codret = chdir(nomrep) ;
2627 SALOME::ExceptionStruct es;
2628 es.type = SALOME::BAD_PARAM;
2629 es.text = "The directory of the case does not exist.";
2630 throw SALOME::SALOME_Exception(es);
2633 std::string nomDirActuel = getenv("PWD") ;
2634 std::string DirName ;
2635 // On boucle sur tous les noms possibles jusqu'a trouver un nom correspondant a un repertoire inconnu
2636 bool a_chercher = true ;
2637 while ( a_chercher )
2639 // On passe dans le repertoire parent
2641 // On recherche un nom sous la forme Iabc, avec abc representant le numero
2643 if ( num < 100 ) { jaux = 2 ; }
2644 else if ( num < 1000 ) { jaux = 3 ; }
2645 else if ( num < 10000 ) { jaux = 4 ; }
2646 else if ( num < 100000 ) { jaux = 5 ; }
2648 std::ostringstream iaux ;
2649 iaux << std::setw(jaux) << std::setfill('0') << num ;
2650 std::ostringstream DirNameA ;
2651 DirNameA << "I" << iaux.str();
2652 // Si on ne pas peut entrer dans le repertoire, on doit verifier
2653 // que c'est bien un probleme d'absence
2654 if ( chdir(DirNameA.str().c_str()) != 0 )
2656 bool existe = false ;
2658 struct dirent *dirp;
2659 dp = opendir(nomrep);
2660 while ( (dirp = readdir(dp)) != NULL )
2662 std::string file_name(dirp->d_name);
2663 if ( file_name == DirNameA.str() ) { existe = true ; }
2668 DirName = DirNameA.str() ;
2669 a_chercher = false ;
2676 MESSAGE ( "==> DirName = " << DirName);
2677 MESSAGE ( ". On retourne dans nomDirActuel = " << nomDirActuel );
2678 chdir(nomDirActuel.c_str());
2680 return CORBA::string_dup( DirName.c_str() );
2682 //=============================================================================
2683 // Calcul d'une iteration : gestion du repertoire de calcul
2684 // Si le sous-repertoire existe :
2685 // etatMenage = 0 : on sort en erreur si le repertoire n'est pas vide
2686 // etatMenage = 1 : on fait le menage du repertoire
2687 // etatMenage = -1 : on ne fait rien
2688 //=============================================================================
2689 char* HOMARD_Gen_i::ComputeDirManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage)
2691 MESSAGE ( "ComputeDirManagement : repertoires pour le calcul" );
2692 // B.2. Le repertoire du cas
2693 const char* nomDirCase = myCase->GetDirName();
2694 MESSAGE ( ". nomDirCase = " << nomDirCase );
2696 // B.3. Le sous-repertoire de l'iteration a calculer, puis le repertoire complet a creer
2697 // B.3.1. Le nom du sous-repertoire
2698 const char* nomDirIt = myIteration->GetDirNameLoc();
2700 // B.3.2. Le nom complet du sous-repertoire
2701 std::stringstream DirCompute ;
2702 DirCompute << nomDirCase << "/" << nomDirIt;
2703 MESSAGE (". DirCompute = " << DirCompute.str() );
2705 // B.3.3. Si le sous-repertoire n'existe pas, on le cree
2706 if (chdir(DirCompute.str().c_str()) != 0)
2708 // Creation du repertoire car il n'existe pas :
2709 if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
2711 // GERALD -- QMESSAGE BOX
2712 std::cerr << "Pb Creation du repertoire DirCompute = " << DirCompute.str() << std::endl;
2713 VERIFICATION("Pb a la creation du repertoire" == 0);
2718 // Le repertoire existe
2719 // On demande de faire le menage de son contenu :
2720 if (etatMenage == 1)
2722 MESSAGE (". Menage du repertoire DirCompute = " << DirCompute.str());
2723 std::string commande = "rm -rf " + DirCompute.str()+"/*" ;
2724 int codret = system(commande.c_str());
2727 // GERALD -- QMESSAGE BOX
2728 std::cerr << ". Menage du repertoire de calcul" << DirCompute.str() << std::endl;
2729 VERIFICATION("Pb au menage du repertoire de calcul" == 0);
2732 // On n'a pas demande de faire le menage de son contenu : on sort en erreur :
2735 if (etatMenage == 0)
2738 struct dirent *dirp;
2739 dp = opendir(DirCompute.str().c_str());
2741 while ((dirp = readdir(dp)) != NULL && result )
2743 std::string file_name(dirp->d_name);
2744 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
2747 if ( result == false)
2749 SALOME::ExceptionStruct es;
2750 es.type = SALOME::BAD_PARAM;
2751 std::string text = "Directory : " + DirCompute.str() + "is not empty";
2752 es.text = CORBA::string_dup(text.c_str());
2753 throw SALOME::SALOME_Exception(es);
2754 VERIFICATION("Directory is not empty" == 0);
2760 return CORBA::string_dup( DirCompute.str().c_str() );
2762 //=============================================================================
2763 // Calcul d'une iteration : gestion du repertoire de calcul de l'iteration parent
2764 //=============================================================================
2765 char* HOMARD_Gen_i::ComputeDirPaManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration)
2767 MESSAGE ( "ComputeDirPaManagement : repertoires pour le calcul" );
2768 // Le repertoire du cas
2769 const char* nomDirCase = myCase->GetDirName();
2770 MESSAGE ( ". nomDirCase = " << nomDirCase );
2772 // Le sous-repertoire de l'iteration precedente
2774 const char* nomIterationParent = myIteration->GetIterParentName();
2775 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
2776 const char* nomDirItPa = myIterationParent->GetDirNameLoc();
2777 std::stringstream DirComputePa ;
2778 DirComputePa << nomDirCase << "/" << nomDirItPa;
2779 MESSAGE( ". nomDirItPa = " << nomDirItPa);
2780 MESSAGE( ". DirComputePa = " << DirComputePa.str() );
2782 return CORBA::string_dup( DirComputePa.str().c_str() );
2784 //=============================================================================
2785 // Calcul d'une iteration : ecriture des zones dans le fichier de configuration
2786 //=============================================================================
2787 void HOMARD_Gen_i::DriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
2789 MESSAGE ( "... DriverTexteZone" );
2790 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
2791 int numberOfZonesx2 = ListZone->length();
2794 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
2796 std::string ZoneName = std::string((*ListZone)[iaux]);
2797 MESSAGE ( "... ZoneName = " << ZoneName);
2798 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
2799 ASSERT(!CORBA::is_nil(myZone));
2801 int ZoneType = myZone->GetType();
2802 std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
2803 int TypeUse = atoi( TypeUsestr.c_str() );
2804 MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
2805 NumZone = iaux/2 + 1 ;
2806 HOMARD::double_array* zone = myZone->GetCoords();
2807 if ( ZoneType == 2 or ( ZoneType>=11 and ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
2808 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.); }
2809 else if ( ZoneType == 4 ) // Cas d une sphere
2810 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.); }
2811 else if ( ZoneType == 5 or ( ZoneType>=31 and ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
2812 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.); }
2813 else if ( ZoneType == 7 or ( ZoneType>=61 and ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
2814 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]); }
2815 else { VERIFICATION("ZoneType est incorrect." == 0) ; }
2820 //=============================================================================
2821 // Calcul d'une iteration : ecriture des champs dans le fichier de configuration
2822 //=============================================================================
2823 void HOMARD_Gen_i::DriverTexteField(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
2825 MESSAGE ( "... DriverTexteField" );
2826 // Le fichier du champ
2827 char* FieldFile = myIteration->GetFieldFile();
2828 MESSAGE ( ". FieldFile = " << FieldFile );
2829 if (strlen(FieldFile) == 0)
2831 // GERALD -- QMESSAGE BOX
2832 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
2833 VERIFICATION("The file for the field is not given." == 0);
2835 // Les caracteristiques d'instants du champ de pilotage
2836 int TimeStep = myIteration->GetTimeStep();
2837 MESSAGE( ". TimeStep = " << TimeStep );
2838 int Rank = myIteration->GetRank();
2839 MESSAGE( ". Rank = " << Rank );
2840 // Les informations sur les champs
2841 HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
2843 const char* FieldName = aInfosHypo->FieldName;
2845 int TypeThR = aInfosHypo->TypeThR;
2846 double ThreshR = aInfosHypo->ThreshR;
2847 int TypeThC = aInfosHypo->TypeThC;
2848 double ThreshC = aInfosHypo->ThreshC;
2849 // Saut entre mailles ou non ?
2850 int UsField = aInfosHypo->UsField;
2851 MESSAGE( ". UsField = " << UsField );
2852 // L'usage des composantes
2853 int UsCmpI = aInfosHypo->UsCmpI;
2854 MESSAGE( ". UsCmpI = " << UsCmpI );
2856 myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
2859 HOMARD::listeComposantsHypo* mescompo = myHypo->GetComps();
2860 int numberOfCompos = mescompo->length();
2861 MESSAGE( ". numberOfCompos = " << numberOfCompos );
2862 for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
2864 std::string nomCompo = std::string((*mescompo)[NumeComp]);
2865 MESSAGE( "... nomCompo = " << nomCompo );
2866 myDriver->TexteCompo(NumeComp, nomCompo);
2870 //=============================================================================
2871 // Calcul d'une iteration : ecriture des frontieres dans le fichier de configuration
2872 // On ecrit dans l'ordre :
2873 // 1. la definition des frontieres
2874 // 2. les liens avec les groupes
2875 // 3. un entier resumant le type de comportement pour les frontieres
2876 //=============================================================================
2877 void HOMARD_Gen_i::DriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, HomardDriver* myDriver)
2879 MESSAGE ( "... DriverTexteBoundary" );
2880 // 1. Recuperation des frontieres
2881 std::list<std::string> ListeBoundaryTraitees ;
2882 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
2883 int numberOfitems = ListBoundaryGroupType->length();
2884 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
2885 int BoundaryOption = 1 ;
2886 // 2. Parcours des frontieres pour ecrire leur description
2887 int NumBoundaryAnalytical = 0 ;
2888 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
2890 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
2891 MESSAGE ( "... BoundaryName = " << BoundaryName);
2892 // 2.1. La frontiere a-t-elle deja ete ecrite ?
2893 // Cela arrive quand elle estliéé a plusieurs groupes. Il ne faut l'ecrire que la premiere fois
2895 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
2896 while (it != ListeBoundaryTraitees.end())
2898 MESSAGE ( "..... BoundaryNameTraitee = " << *it);
2899 if ( BoundaryName == *it ) { A_faire = 0 ; }
2902 // 2.2. Ecriture de la frontiere
2905 // 2.2.1. Caracteristiques de la frontiere
2906 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
2907 ASSERT(!CORBA::is_nil(myBoundary));
2908 int BoundaryType = myBoundary->GetType();
2909 MESSAGE ( "... BoundaryType = " << BoundaryType );
2910 // 2.2.2. Ecriture selon le type
2911 // 2.2.2.1. Cas d une frontiere discrete
2912 if (BoundaryType == 0)
2914 const char* MeshName = myBoundary->GetMeshName() ;
2915 const char* MeshFile = myBoundary->GetMeshFile() ;
2916 myDriver->TexteBoundaryDi( MeshName, MeshFile);
2917 if ( BoundaryOption % 2 != 0 ) { BoundaryOption = BoundaryOption*2 ; }
2919 // 2.2.2.1. Cas d une frontiere analytique
2922 NumBoundaryAnalytical++ ;
2923 HOMARD::double_array* coor = myBoundary->GetCoords();
2924 if (BoundaryType == 1) // Cas d un cylindre
2926 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
2927 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
2929 else if (BoundaryType == 2) // Cas d une sphere
2931 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0., 0.);
2932 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
2934 else if (BoundaryType == 3) // Cas d un cone defini par un axe et un angle
2936 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
2937 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
2939 else if (BoundaryType == 4) // Cas d un cone defini par les 2 rayons
2941 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
2942 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
2945 // 2.2.3. Memorisation du traitement
2946 ListeBoundaryTraitees.push_back( BoundaryName );
2949 // 3. Parcours des frontieres pour ecrire les liens avec les groupes
2950 NumBoundaryAnalytical = 0 ;
2951 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
2953 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
2954 MESSAGE ( "... BoundaryName = " << BoundaryName);
2955 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
2956 ASSERT(!CORBA::is_nil(myBoundary));
2957 int BoundaryType = myBoundary->GetType();
2958 MESSAGE ( "... BoundaryType = " << BoundaryType );
2959 // 3.1. Recuperation du nom du groupe
2960 std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
2961 MESSAGE ( "... GroupName = " << GroupName);
2962 // 3.2. Cas d une frontiere discrete
2963 if ( BoundaryType == 0 )
2965 if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
2967 // 3.3. Cas d une frontiere analytique
2970 NumBoundaryAnalytical++ ;
2971 myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
2974 // 4. Ecriture de l'option finale
2975 myDriver->TexteBoundaryOption(BoundaryOption);
2979 //=============================================================================
2980 // Calcul d'une iteration : ecriture des interpolations dans le fichier de configuration
2981 //=============================================================================
2982 void HOMARD_Gen_i::DriverTexteFieldInterp(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
2984 MESSAGE ( "... DriverTexteFieldInterp" );
2985 int TypeFieldInterp = myHypo->GetTypeFieldInterp();
2986 MESSAGE ( "... TypeFieldInterp = " << TypeFieldInterp);
2987 if (TypeFieldInterp != 0)
2989 // Le fichier des champs
2990 char* FieldFile = myIteration->GetFieldFile();
2991 MESSAGE ( ". FieldFile = " << FieldFile );
2992 if (strlen(FieldFile) == 0)
2994 // GERALD -- QMESSAGE BOX
2995 VERIFICATION("The file for the field is not given." == 0);
2998 const char* MeshFile = myIteration->GetMeshFile();
2999 myDriver->TexteFieldInterp(FieldFile, MeshFile);
3002 // Interpolation de tous les champs
3003 if ( TypeFieldInterp == 1 )
3005 myDriver->TexteFieldInterpAll();
3007 // Interpolation de certains champs
3008 else if (TypeFieldInterp == 2)
3010 // Les champs et leurs instants pour l'iteration
3011 HOMARD::listeFieldInterpTSRsIter* ListFieldTSR = myIteration->GetFieldInterpsTimeStepRank();
3012 int numberOfFieldsx3 = ListFieldTSR->length();
3013 MESSAGE( ". pour iteration, numberOfFields = " << numberOfFieldsx3/3 );
3014 // Les champs pour l'hypothese
3015 HOMARD::listeFieldInterpsHypo* ListField = myHypo->GetFieldInterps();
3016 int numberOfFieldsx2 = ListField->length();
3017 MESSAGE( ". pour hypothese, numberOfFields = " << numberOfFieldsx2/2 );
3018 // On parcourt tous les champs de l'hypothese
3020 for (int iaux = 0; iaux< numberOfFieldsx2; iaux++)
3023 std::string FieldName = std::string((*ListField)[iaux]) ;
3024 // Le type d'interpolation
3025 std::string TypeInterpstr = std::string((*ListField)[iaux+1]) ;
3026 MESSAGE( "... FieldName = " << FieldName << ", TypeInterp = " << TypeInterpstr );
3027 // On cherche à savoir si des instants ont été précisés pour cette itération
3029 for (int jaux = 0; jaux< numberOfFieldsx3; jaux++)
3032 std::string FieldName2 = std::string((*ListFieldTSR)[jaux]) ;
3033 MESSAGE( "..... FieldName2 = " << FieldName2 );
3034 // Quand c'est le bon champ, on ecrit le pas de temps
3035 if ( FieldName == FieldName2 )
3039 std::string TimeStepstr = std::string((*ListFieldTSR)[jaux+1]) ;
3040 // Le numero d'ordre
3041 std::string Rankstr = std::string((*ListFieldTSR)[jaux+2]) ;
3042 MESSAGE( "..... TimeStepstr = " << TimeStepstr <<", Rankstr = "<<Rankstr );
3044 int TimeStep = atoi( TimeStepstr.c_str() );
3045 int Rank = atoi( Rankstr.c_str() );
3046 myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, TimeStep, Rank);
3050 // Si aucun instant n'a été défini
3054 myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, -1, -1);
3062 //===========================================================================
3063 //===========================================================================
3066 //===========================================================================
3067 //===========================================================================
3069 //===========================================================================
3070 //===========================================================================
3071 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
3072 SALOMEDS::SObject_ptr theSObject,
3073 CORBA::Object_ptr theObject,
3074 const char* theName)
3076 MESSAGE("PublishInStudy pour " << theName);
3077 SALOMEDS::SObject_var aResultSO;
3078 if (CORBA::is_nil(theStudy))
3080 SALOME::ExceptionStruct es;
3081 es.type = SALOME::BAD_PARAM;
3082 es.text = "Invalid study context";
3083 throw SALOME::SALOME_Exception(es);
3087 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
3088 // Rq : Iteration est publiee ailleurs
3089 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
3090 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(theObject);
3091 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
3092 HOMARD::HOMARD_YACS_var aYACS = HOMARD::HOMARD_YACS::_narrow(theObject);
3093 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
3095 addInStudy(theStudy);
3097 // Controle de la non publication d'un objet de meme nom
3098 if ( (!aBoundary->_is_nil()) or (!aHypo->_is_nil()) or (!aYACS->_is_nil()) or (!aZone->_is_nil()) )
3100 SALOMEDS::Study::ListOfSObject_var listSO = theStudy->FindObjectByName(theName, ComponentDataType());
3101 if (listSO->length() >= 1)
3103 MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
3104 aResultSO = listSO[0];
3105 return aResultSO._retn();
3109 // Caracteristiques de l'etude
3110 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
3111 aStudyBuilder->NewCommand();
3112 if(!aBoundary->_is_nil())
3113 aResultSO = PublishBoundaryInStudy(theStudy, aStudyBuilder, aBoundary, theName);
3114 else if(!aCase->_is_nil())
3115 aResultSO = PublishCaseInStudy(theStudy, aStudyBuilder, aCase, theName);
3116 else if(!aHypo->_is_nil())
3117 aResultSO = PublishHypotheseInStudy(theStudy, aStudyBuilder, aHypo, theName);
3118 else if(!aYACS->_is_nil())
3119 aResultSO = PublishYACSInStudy(theStudy, aStudyBuilder, aYACS, theName);
3120 else if(!aZone->_is_nil())
3121 aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName);
3123 aStudyBuilder->CommitCommand();
3125 return aResultSO._retn();
3127 //=============================================================================
3128 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy(SALOMEDS::Study_ptr theStudy,
3129 SALOMEDS::StudyBuilder_var aStudyBuilder,
3130 HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
3132 MESSAGE("PublishBoundaryStudy pour "<<theName);
3133 SALOMEDS::SObject_var aResultSO;
3135 // Caracteristique de la Boundary
3136 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[theName];
3138 // On recupere le module pere dans l etude
3139 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3140 if (theFatherHomard->_is_nil())
3142 MESSAGE("theFatherHomard->_is_nil()");
3143 return aResultSO._retn();
3146 // On ajoute la categorie des boundarys dans l etude si necessaire
3147 if ( _tag_boun == 0 )
3150 _tag_boun = _tag_gene ;
3152 MESSAGE("PublishBoundaryInStudy _tag_gene = "<<_tag_gene << ", _tag_boun = "<<_tag_boun );
3153 SALOMEDS::SObject_var aSObject;
3154 if (!theFatherHomard->FindSubObject(_tag_boun, aSObject))
3156 MESSAGE("Ajout de la categorie des boundarys");
3157 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_boun);
3158 PublishInStudyAttr(aStudyBuilder, aSObject, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
3160 else { MESSAGE("La categorie des boundarys existe deja."); }
3162 CORBA::Long BoundaryType = myBoundary->GetType();
3163 // MESSAGE("BoundaryType : "<<BoundaryType);
3166 switch (BoundaryType)
3169 { value = "BoundaryDiHomard" ;
3170 icone = "mesh_tree_mesh.png" ;
3174 { value = "BoundaryAnHomard" ;
3175 icone = "cylinderpointvector_2.png" ;
3179 { value = "BoundaryAnHomard" ;
3180 icone = "spherepoint_2.png" ;
3184 { value = "BoundaryAnHomard" ;
3185 icone = "conepointvector.png" ;
3189 { value = "BoundaryAnHomard" ;
3190 icone = "conedxyz.png" ;
3194 aResultSO = aStudyBuilder->NewObject(aSObject);
3195 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value.c_str(), icone.c_str(), _orb->object_to_string(theObject));
3196 return aResultSO._retn();
3198 //=============================================================================
3199 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::Study_ptr theStudy,
3200 SALOMEDS::StudyBuilder_var aStudyBuilder,
3201 HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
3203 MESSAGE("PublishCaseInStudy pour "<<theName);
3204 SALOMEDS::SObject_var aResultSO;
3206 if (CORBA::is_nil(theObject)) {
3207 MESSAGE("HOMARD_Gen_i::theObject->_is_nil()");
3208 return aResultSO._retn();
3210 if (theStudy->_is_nil()) {
3211 MESSAGE("HOMARD_Gen_i::theStudy->_is_nil()");
3212 return aResultSO._retn();
3215 // On recupere le module pere dans l etude
3216 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3217 if (theFatherHomard->_is_nil())
3219 MESSAGE("theFatherHomard->_is_nil()");
3220 return aResultSO._retn();
3224 MESSAGE("PublishCaseInStudy _tag_gene = "<<_tag_gene );
3225 aResultSO = aStudyBuilder->NewObject(theFatherHomard);
3226 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
3227 _orb->object_to_string(theObject) ) ;
3229 return aResultSO._retn();
3231 //=============================================================================
3232 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::Study_ptr theStudy,
3233 SALOMEDS::StudyBuilder_var aStudyBuilder,
3234 HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
3236 MESSAGE("PublishHypotheseInStudy pour "<<theName);
3237 SALOMEDS::SObject_var aResultSO;
3239 // On recupere le module pere dans l etude
3240 // On ajoute la categorie des hypotheses dans l etude si necessaire
3241 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3242 if (theFatherHomard->_is_nil())
3244 MESSAGE("theFatherHomard->_is_nil()");
3245 return aResultSO._retn();
3248 // On ajoute la categorie des hypotheses dans l etude si necessaire
3249 SALOMEDS::SObject_var aSObject;
3250 if ( _tag_hypo == 0 )
3253 _tag_hypo = _tag_gene ;
3255 MESSAGE("PublishHypotheseInStudy _tag_gene = "<<_tag_gene << ", _tag_hypo = "<<_tag_hypo );
3256 if (!theFatherHomard->FindSubObject(_tag_hypo, aSObject))
3258 MESSAGE("Ajout de la categorie des hypotheses");
3259 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_hypo);
3260 PublishInStudyAttr(aStudyBuilder, aSObject, "Hypothesis", "HypoList", "hypotheses.png", NULL);
3262 else { MESSAGE("La categorie des hypotheses existe deja."); }
3264 // Creation du resultat dans l'etude
3265 aResultSO = aStudyBuilder->NewObject(aSObject);
3266 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
3268 return aResultSO._retn();
3270 //=============================================================================
3271 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishYACSInStudy(SALOMEDS::Study_ptr theStudy,
3272 SALOMEDS::StudyBuilder_var aStudyBuilder,
3273 HOMARD::HOMARD_YACS_ptr theObject, const char* theName)
3275 MESSAGE("PublishYACSInStudy pour "<<theName);
3276 SALOMEDS::SObject_var aResultSO;
3278 // On recupere le module pere dans l etude
3279 // On ajoute la categorie des schemas YACS dans l etude si necessaire
3280 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3281 if (theFatherHomard->_is_nil())
3283 MESSAGE("theFatherHomard->_is_nil()");
3284 return aResultSO._retn();
3286 // On ajoute la categorie des schemas YACS dans l etude si necessaire
3287 if ( _tag_yacs == 0 )
3290 _tag_yacs = _tag_gene ;
3292 MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_yacs = "<<_tag_yacs );
3293 SALOMEDS::SObject_var aSObject;
3294 if (!theFatherHomard->FindSubObject(_tag_yacs, aSObject))
3296 MESSAGE("Ajout de la categorie des schemas YACS");
3297 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_yacs);
3298 PublishInStudyAttr(aStudyBuilder, aSObject, "YACS", "YACSList", "full_view.png", NULL);
3300 else { MESSAGE("La categorie des schemas YACS existe deja."); }
3302 // Creation du resultat dans l'etude
3303 aResultSO = aStudyBuilder->NewObject(aSObject);
3304 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "YACSHomard", "schema.png", _orb->object_to_string(theObject) ) ;
3306 return aResultSO._retn();
3309 //=============================================================================
3310 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::Study_ptr theStudy,
3311 SALOMEDS::StudyBuilder_var aStudyBuilder,
3312 HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
3314 MESSAGE("PublishZoneStudy pour "<<theName);
3315 SALOMEDS::SObject_var aResultSO;
3316 if (CORBA::is_nil(theObject))
3318 MESSAGE("PublishZoneInStudy : theObject->_is_nil()");
3319 return aResultSO._retn();
3321 if (theStudy->_is_nil())
3323 MESSAGE("PublishZoneInStudy : theStudy->_is_nil()");
3324 return aResultSO._retn();
3326 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3327 if (theFatherHomard->_is_nil())
3329 MESSAGE("PublishZoneInStudy : theFatherHomard->_is_nil()");
3330 return aResultSO._retn();
3333 // Caracteristique de la zone
3334 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[theName];
3335 CORBA::Long ZoneType = myZone->GetType();
3337 // On ajoute la categorie des zones dans l etude si necessaire
3338 if ( _tag_zone == 0 )
3341 _tag_zone = _tag_gene ;
3343 MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_zone = "<<_tag_zone );
3344 SALOMEDS::SObject_var aSObject;
3345 if (!theFatherHomard->FindSubObject(_tag_zone, aSObject))
3347 MESSAGE("Ajout de la categorie des zones");
3348 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_zone);
3349 PublishInStudyAttr(aStudyBuilder, aSObject, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
3351 else { MESSAGE("La categorie des zones existe deja."); }
3353 aResultSO = aStudyBuilder->NewObject(aSObject);
3362 { icone = "boxdxy_2.png" ;
3366 { icone = "boxdxyz_2.png" ;
3374 { icone = "disk_2.png" ;
3378 { icone = "spherepoint_2.png" ;
3382 { icone = "cylinderpointvector_2.png" ;
3390 { icone = "diskwithhole_2.png" ;
3394 { icone = "pipe_2.png" ;
3398 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone.c_str(), _orb->object_to_string(theObject) ) ;
3400 return aResultSO._retn();
3402 //===========================================================================
3403 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
3404 SALOMEDS::SObject_var aResultSO,
3405 const char* name, const char* comment, const char* icone, const char* ior)
3407 MESSAGE("PublishInStudyAttr pour name = "<<name<<", comment = "<<comment);
3408 // MESSAGE("icone = "<<icone);
3409 // MESSAGE("ior = "<<ior);
3410 SALOMEDS::GenericAttribute_var anAttr ;
3414 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
3415 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
3416 aNameAttrib->SetValue(name);
3419 // Ajout du commentaire
3420 if ( comment != NULL )
3422 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
3423 SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
3424 aCommentAttrib->SetValue(comment);
3428 if ( icone != NULL )
3430 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
3431 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
3432 aPixmap->SetPixMap(icone);
3438 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
3439 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3440 anIOR->SetValue(ior);
3444 //=====================================================================================
3445 void HOMARD_Gen_i::PublishBoundaryUnderCase(const char* CaseName, const char* BoundaryName)
3447 MESSAGE ( "PublishBoundaryUnderCase : CaseName = " << CaseName << ", BoundaryName= " << BoundaryName );
3449 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3450 ASSERT(!CORBA::is_nil(myCase));
3451 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3452 ASSERT(!CORBA::is_nil(aCaseSO));
3454 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3455 ASSERT(!CORBA::is_nil(myBoundary));
3456 SALOMEDS::SObject_var aBoundarySO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myBoundary)));
3457 ASSERT(!CORBA::is_nil(aBoundarySO));
3459 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3461 aStudyBuilder->NewCommand();
3463 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aCaseSO);
3464 aStudyBuilder->Addreference(aSubSO, aBoundarySO);
3466 aStudyBuilder->CommitCommand();
3469 //=====================================================================================
3470 void HOMARD_Gen_i::PublishCaseUnderYACS(const char* nomYACS, const char* CaseName)
3472 MESSAGE ( "PublishCaseUnderYACS : nomYACS = " << nomYACS << ", CaseName= " << CaseName );
3474 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3475 ASSERT(!CORBA::is_nil(myYACS));
3476 SALOMEDS::SObject_var aYACSSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3477 ASSERT(!CORBA::is_nil(aYACSSO));
3479 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3480 ASSERT(!CORBA::is_nil(myCase));
3481 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3482 ASSERT(!CORBA::is_nil(aCaseSO));
3484 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3486 aStudyBuilder->NewCommand();
3488 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3489 aStudyBuilder->Addreference(aSubSO, aCaseSO);
3491 aStudyBuilder->CommitCommand();
3494 //=============================================================================
3495 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long Option)
3496 // Option = 0 : fichier issu d'une importation
3497 // Option = 1 : fichier issu d'une execution HOMARD
3499 MESSAGE( "PublishResultInSmesh " << NomFich << ", avec Option = " << Option);
3500 if (CORBA::is_nil(myCurrentStudy))
3502 SALOME::ExceptionStruct es;
3503 es.type = SALOME::BAD_PARAM;
3504 es.text = "Invalid study context";
3505 throw SALOME::SALOME_Exception(es);
3509 // Le module SMESH est-il actif ?
3510 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3512 if (!CORBA::is_nil(aSmeshSO))
3514 // On verifie que le fichier n est pas deja publie
3515 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3516 for (; aIter->More(); aIter->Next())
3518 SALOMEDS::SObject_var aSO = aIter->Value();
3519 SALOMEDS::GenericAttribute_var aGAttr;
3520 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3522 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3523 CORBA::String_var value=anAttr->Value();
3524 if (strcmp((const char*)value,NomFich) == 0)
3526 MESSAGE ( "PublishResultInSmesh : le fichier " << NomFich << " est deja publie." );
3527 // Pour un fichier importe, on ne republie pas
3532 // Pour un fichier calcule, on commence par faire la depublication
3535 MESSAGE ( "PublishResultInSmesh : depublication" );
3536 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3537 CORBA::String_var value2=anAttr2->Value();
3538 std::string MeshName = string(value2) ;
3539 MESSAGE ( "PublishResultInSmesh : depublication de " << MeshName );
3540 DeleteResultInSmesh(NomFich, MeshName) ;
3547 // On enregistre le fichier
3548 MESSAGE( "Enregistrement du fichier");
3549 SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
3550 SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
3551 ASSERT(!CORBA::is_nil(aSmeshEngine));
3552 aSmeshEngine->SetCurrentStudy(myCurrentStudy);
3553 SMESH::DriverMED_ReadStatus theStatus;
3554 //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3556 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
3557 SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3558 for (int i = 0; i < mesMaillages->length(); i++)
3560 MESSAGE( ". Mise a jour des attributs du maillage");
3561 SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
3562 SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
3563 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3564 SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
3565 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3566 anAttr->SetValue(NomFich);
3567 SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
3568 SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
3570 if ( Option == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
3571 else { icone = "mesh_tree_mesh.png" ; }
3572 anAttr2->SetPixMap( icone );
3576 //=============================================================================
3577 void HOMARD_Gen_i::DeleteResultInSmesh(std::string NomFich, std::string MeshName)
3579 MESSAGE ("DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich );
3580 if (CORBA::is_nil(myCurrentStudy))
3582 SALOME::ExceptionStruct es;
3583 es.type = SALOME::BAD_PARAM;
3584 es.text = "Invalid study context";
3585 throw SALOME::SALOME_Exception(es);
3589 // Le module SMESH est-il actif ?
3590 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3592 if (CORBA::is_nil(aSmeshSO))
3596 // On verifie que le fichier est deja publie
3597 SALOMEDS::StudyBuilder_var myBuilder = myCurrentStudy->NewBuilder();
3598 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3599 for (; aIter->More(); aIter->Next())
3601 SALOMEDS::SObject_var aSO = aIter->Value();
3602 SALOMEDS::GenericAttribute_var aGAttr;
3603 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3605 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3606 CORBA::String_var value=anAttr->Value();
3607 if (strcmp((const char*)value,NomFich.c_str()) == 0)
3609 if (aSO->FindAttribute(aGAttr,"AttributeName"))
3611 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3612 CORBA::String_var value2=anAttr2->Value();
3613 if (strcmp((const char*)value2,MeshName.c_str()) == 0)
3615 myBuilder->RemoveObjectWithChildren( aSO ) ;
3623 //=============================================================================
3624 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
3626 // MESSAGE ("PublishFileUnderIteration pour l'iteration " << NomIter << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3627 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
3629 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
3630 if (CORBA::is_nil(myIteration))
3632 SALOME::ExceptionStruct es;
3633 es.type = SALOME::BAD_PARAM;
3634 es.text = "Invalid iterationStudy Object";
3635 throw SALOME::SALOME_Exception(es);
3639 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3641 aStudyBuilder->NewCommand();
3643 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
3644 // Pour les fichiers med, on affiche une icone de maillage
3645 // Pour les fichiers qui sont du texte, on affiche une icone de fichier texte 'texte'
3646 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
3648 std::string ior = " " ;
3649 if ( Commentaire[0] == 'I' )
3650 { icone = "med.png" ; }
3652 { icone = "texte_2.png" ; }
3653 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3655 aStudyBuilder->CommitCommand();
3658 //=============================================================================
3659 void HOMARD_Gen_i::PublishFileUnderYACS(const char* nomYACS, const char* NomFich, const char* Commentaire)
3661 // MESSAGE ("PublishFileUnderYACS pour le schema " << nomYACS << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3662 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3664 SALOMEDS::SObject_var aYACSSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3665 if (CORBA::is_nil(myYACS))
3667 SALOME::ExceptionStruct es;
3668 es.type = SALOME::BAD_PARAM;
3669 es.text = "Invalid YACSStudy Object";
3670 throw SALOME::SALOME_Exception(es);
3674 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3676 aStudyBuilder->NewCommand();
3678 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3679 std::string icone = "texte_2.png" ;
3680 std::string ior = " " ;
3681 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3683 aStudyBuilder->CommitCommand();
3686 //=============================================================================
3687 //=============================================================================
3689 //=============================================================================
3690 //=============================================================================
3691 //=============================================================================
3692 // Creation d'un schema YACS
3693 // nomCas : nom du cas a traiter
3694 // FileName : nom du fichier contenant le script de lancement du calcul
3695 // DirName : le repertoire de lancement des calculs du schéma
3696 //=============================================================================
3697 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::CreateYACSSchema (const char* nomYACS, const char* nomCas, const char* ScriptFile, const char* DirName, const char* MeshFile)
3699 INFOS ( "CreateYACSSchema : Schema YACS " << nomYACS );
3700 INFOS ( ". nomCas : " << nomCas);
3701 INFOS ( ". ScriptFile : " << ScriptFile);
3702 INFOS ( ". DirName : " << DirName);
3703 INFOS ( ". MeshFile : " << MeshFile);
3705 // A. Controle du nom :
3706 if ((myContextMap[GetCurrentStudyID()]._mesYACSs).find(nomYACS) != (myContextMap[GetCurrentStudyID()]._mesYACSs).end())
3708 SALOME::ExceptionStruct es;
3709 es.type = SALOME::BAD_PARAM;
3710 es.text = "This schema YACS has already been defined.";
3711 throw SALOME::SALOME_Exception(es);
3715 // B. Creation de l'objet
3716 HOMARD::HOMARD_YACS_var myYACS = newYACS();
3717 if (CORBA::is_nil(myYACS))
3719 SALOME::ExceptionStruct es;
3720 es.type = SALOME::BAD_PARAM;
3721 es.text = "Unable to create the schema YACS";
3722 throw SALOME::SALOME_Exception(es);
3725 myYACS->SetName( nomYACS ) ;
3727 // C. Enregistrement
3728 myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS] = myYACS;
3730 SALOMEDS::SObject_var aSO;
3731 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myYACS, nomYACS);
3733 PublishCaseUnderYACS(nomYACS, nomCas);
3735 // D. Caracterisation
3737 myYACS->SetDirName( DirName ) ;
3738 myYACS->SetMeshFile( MeshFile ) ;
3739 myYACS->SetScriptFile( ScriptFile ) ;
3740 myYACS->SetCaseName( nomCas ) ;
3742 // D.2.1. Type constant
3743 myYACS->SetType( 1 ) ;
3744 // D.2.2. Fichier de sauvegarde dans le repertoire du cas
3745 HOMARD::HOMARD_Cas_ptr caseyacs = GetCase(nomCas) ;
3746 std::string dirnamecase = caseyacs->GetDirName() ;
3747 std::string XMLFile ;
3748 XMLFile = dirnamecase + "/schema.xml" ;
3749 myYACS->SetXMLFile( XMLFile.c_str() ) ;
3751 return HOMARD::HOMARD_YACS::_duplicate(myYACS);
3753 //=============================================================================
3754 // Ecriture d'un schema YACS
3755 //=============================================================================
3756 CORBA::Long HOMARD_Gen_i::YACSWrite(const char* nomYACS)
3758 INFOS ( "YACSWrite : Ecriture de " << nomYACS );
3759 // Le repertoire du cas
3760 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3761 ASSERT(!CORBA::is_nil(myYACS));
3762 // Le nom du fichier du schema
3763 std::string XMLFile ;
3764 XMLFile = myYACS->GetXMLFile() ;
3766 int codret = YACSWriteOnFile(nomYACS, XMLFile.c_str()) ;
3770 //=============================================================================
3771 // Ecriture d'un schema YACS sur un fichier donne
3772 //=============================================================================
3773 CORBA::Long HOMARD_Gen_i::YACSWriteOnFile(const char* nomYACS, const char* XMLFile)
3775 INFOS ( "YACSWriteOnFile : Ecriture de " << nomYACS << " sur " << XMLFile );
3782 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3783 ASSERT(!CORBA::is_nil(myYACS));
3784 // B.2. Les caracteristiques
3785 std::string DirName = myYACS->GetDirName() ;
3786 std::string MeshFile = myYACS->GetMeshFile() ;
3787 std::string ScriptFile = myYACS->GetScriptFile() ;
3791 const char* nomCas = myYACS->GetCaseName();
3792 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
3793 ASSERT(!CORBA::is_nil(myCase));
3794 // C.2. Les instructions python associees au cas
3795 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
3796 std::string pythonCas = dumpCorbaCase.in();
3797 MESSAGE ("pythonCas :\n"<<pythonCas<<"\n");
3799 // D. Les iterations
3800 // D.1. L'iteration initiale
3801 HOMARD::HOMARD_Iteration_var Iter0 = myCase->GetIter0() ;
3802 std::string Iter0Name = myCase->GetIter0Name() ;
3803 MESSAGE (". Iter0Name = " << Iter0Name);
3804 std::string MeshName = Iter0->GetMeshName();
3805 MESSAGE (". MeshName = " << MeshName);
3806 // D.2. L'iteration numero 1
3807 HOMARD::listeIterFilles* maListe = Iter0->GetIterations();
3808 int numberOfIter = maListe->length();
3809 if ( numberOfIter > 1 )
3811 MESSAGE (". numberOfIter = " << numberOfIter);
3812 SALOME::ExceptionStruct es ;
3813 es.type = SALOME::BAD_PARAM;
3814 std::string text = "Une seule iteration est permise." ;
3815 es.text = CORBA::string_dup(text.c_str());
3816 throw SALOME::SALOME_Exception(es);
3819 std::string Iter1Name = std::string((*maListe)[0]);
3820 MESSAGE ("... Iter1Name = " << Iter1Name);
3821 HOMARD::HOMARD_Iteration_var Iter1 = GetIteration(Iter1Name.c_str()) ;
3822 // D.3. Les instructions python associees a l'iteration
3823 CORBA::String_var dumpCorbaIter = Iter1->GetDumpPython();
3824 std::string pythonIter = dumpCorbaIter.in();
3825 MESSAGE ("pythonIter :\n"<<pythonIter<<"\n");
3827 // E. L'hypothese pour passer de l'iteration initiale a la suivante
3828 // E.1. La structure
3829 std::string nomHypo = Iter1->GetHypoName();
3830 MESSAGE (". nomHypo = " << nomHypo);
3831 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
3832 ASSERT(!CORBA::is_nil(myHypo));
3833 // E.2. Les caracteristiques de l'adaptation
3834 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
3835 ASSERT(ListTypes->length() == 3);
3836 int TypeAdap = (*ListTypes)[0];
3837 // int TypeRaff = (*ListTypes)[1];
3838 // int TypeDera = (*ListTypes)[2];
3839 // E.3. Les instructions python associees a l'hypothese
3840 CORBA::String_var dumpCorbaHypo = myHypo->GetDumpPython();
3841 std::string pythonHypo = dumpCorbaHypo.in();
3842 MESSAGE ("pythonHypo :\n"<<pythonHypo<<"\n");
3844 // F. Le fichier du schema de reference
3845 // HOMARD_ROOT_DIR : repertoire ou se trouve le module HOMARD
3846 std::string XMLFile_base ;
3847 if ( getenv("HOMARD_ROOT_DIR") != NULL ) { XMLFile_base = getenv("HOMARD_ROOT_DIR") ; }
3850 SALOME::ExceptionStruct es ;
3851 es.type = SALOME::BAD_PARAM;
3852 std::string text = "HOMARD_ROOT_DIR est inconnu." ;
3853 es.text = CORBA::string_dup(text.c_str());
3854 throw SALOME::SALOME_Exception(es);
3857 XMLFile_base += "/share/salome/resources/homard/yacs_01." + _LangueShort + ".xml" ;
3859 MESSAGE("XMLFile_base ="<<XMLFile_base);
3861 // G. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
3862 YACSDriver* myDriver = new YACSDriver(XMLFile, DirName);
3863 std::ifstream fichier( XMLFile_base.c_str() );
3864 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
3866 // G.1. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
3867 std::string ligne; // variable contenant chaque ligne lue
3868 std::string mot_cle;
3869 while ( std::getline( fichier, ligne ) )
3871 // G.1.1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
3872 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
3873 ligne_bis >> mot_cle ;
3874 // G.1.2. Le maillage initial
3875 if ( mot_cle == "DataInit_MeshFile" )
3876 { myDriver->Texte_DataInit_MeshFile(MeshFile); }
3877 // G.1.3. Le script de lancement
3878 else if ( mot_cle == "Alternance_Calcul_HOMARD_Calcul" )
3879 { myDriver->Texte_Alternance_Calcul_HOMARD_Calcul(ScriptFile); }
3880 // G.1.4. Les options du cas
3881 else if ( mot_cle == "Iter_1_Case_Options" )
3882 { myDriver->Texte_Iter_1_Case_Options(pythonCas); }
3883 // G.1.5. Execution de HOMARD : le repertoire du cas
3884 else if ( mot_cle == "HOMARD_Exec_DirName" )
3885 { myDriver->Texte_HOMARD_Exec_DirName(); }
3886 // G.1.6. Execution de HOMARD : le nom du maillage
3887 else if ( mot_cle == "HOMARD_Exec_MeshName" )
3889 myDriver->Texte_HOMARD_Exec_MeshName(MeshName);
3890 std::string node = "Boucle_de_convergence.Alternance_Calcul_HOMARD.Adaptation.p0_Adaptation_HOMARD.HOMARD_Initialisation.p1_Iter_1.CreateCase" ;
3891 myDriver->TexteParametre( node, "MeshName", "string", MeshName ) ;
3893 // G.1.7. Execution de HOMARD : les options de l'hypothese
3894 else if ( mot_cle == "HOMARD_Exec_Hypo_Options" )
3895 { myDriver->Texte_python_1( pythonHypo, 3, "Hypo" ) ; }
3896 // G.1.8. Execution de HOMARD : les options de l'iteration
3897 else if ( mot_cle == "HOMARD_Exec_Iter_Options" )
3898 { myDriver->Texte_python_2( pythonIter, "TimeStep", "Iter" ) ; }
3899 // G.1.9. Zones et frontieres : les creations
3900 else if ( mot_cle == "Iter_1" )
3902 std::string texte_control = myDriver->Texte_Iter_1_control() ;
3903 if ( TypeAdap == 0 ) { texte_control += YACSDriverTexteZone( myHypo, myDriver ) ; }
3904 texte_control += YACSDriverTexteBoundary( myCase, myDriver ) ;
3905 myDriver->TexteAdd(texte_control);
3907 // G.1.10. Les parametres
3908 else if ( mot_cle == "PARAMETRES" )
3909 { myDriver->TexteAddParametres(); }
3910 // G.1.n. La ligne est recopiee telle quelle
3911 else { myDriver->TexteAdd(ligne); }
3913 // G.2. Ecriture du texte dans le fichier
3915 { myDriver->CreeFichier(); }
3919 SALOME::ExceptionStruct es;
3920 es.type = SALOME::BAD_PARAM;
3921 std::string text = "The reference file for the YACS schema cannot be read." ;
3922 es.text = CORBA::string_dup(text.c_str());
3923 throw SALOME::SALOME_Exception(es);
3928 // H. Publication du fichier dans l'arbre
3930 std::string Commentaire = "xml" ;
3931 PublishFileUnderYACS(nomYACS, XMLFile, Commentaire.c_str());
3935 //=============================================================================
3936 // Ecriture d'un schema YACS : ecriture des zones associees a une hypothese
3937 //=============================================================================
3938 std::string HOMARD_Gen_i::YACSDriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, YACSDriver* myDriver)
3940 MESSAGE ( "YACSDriverTexteZone" );
3941 // A. Les zones associees a cette hypothese
3942 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
3943 int numberOfZonesx2 = ListZone->length();
3945 // B. Parcours des zones
3946 std::string texte_control ;
3947 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
3949 // 1. Reperage de la zone
3950 std::string ZoneName = std::string((*ListZone)[iaux]);
3951 MESSAGE ( "\n. ZoneName = " << ZoneName << " - " <<iaux);
3952 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
3953 ASSERT(!CORBA::is_nil(myZone));
3954 // 2. Les instructions python associees a la zone
3955 // La premiere ligne est un commentaire a eliminer
3956 // La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
3957 CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
3958 std::string pythonStructure_0 = dumpCorbaZone.in();
3959 MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
3960 std::istringstream tout (pythonStructure_0) ;
3962 std::string pythonStructure ;
3963 while ( std::getline( tout, ligne ) )
3964 { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
3965 MESSAGE ("pythonStructure :\n"<<pythonStructure);
3966 // 3. Decodage du nom du service
3967 std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
3968 MESSAGE ( "... methode = " << methode);
3969 // 4. Mise en place des instructions
3970 int ZoneType = myZone->GetType();
3971 MESSAGE ( "... ZoneType = " << ZoneType);
3972 std::string texte_control_0 ;
3973 texte_control_0 = myDriver->Texte_Iter_1_Zone(ZoneType, pythonStructure, methode, ZoneName );
3974 texte_control += texte_control_0 ;
3979 return texte_control ;
3981 //=============================================================================
3982 // Ecriture d'un schema YACS : ecriture des frontieres associees au cas
3983 //=============================================================================
3984 std::string HOMARD_Gen_i::YACSDriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, YACSDriver* myDriver)
3986 MESSAGE ( "YACSDriverTexteBoundary" );
3987 // A. Les frontieres associees au cas
3988 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
3989 int numberOfitems = ListBoundaryGroupType->length();
3991 // B. Parcours des frontieres
3992 std::string texte_control ;
3993 std::list<std::string> ListeBoundaryTraitees ;
3994 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3996 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3997 MESSAGE ( "... BoundaryName = " << BoundaryName);
3998 // Attention a n'ecrire la definition qu'une seule fois car elle peut se trouver
3999 // plusieurs fois dans la definition du cas, d'ou la liste ListeBoundaryTraitees
4001 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
4002 while (it != ListeBoundaryTraitees.end())
4004 MESSAGE ( "..... BoundaryNameTraitee = " << *it);
4005 if ( BoundaryName == *it ) { A_faire = 0 ; }
4010 // 1. Caracteristiques de la frontiere
4011 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
4012 ASSERT(!CORBA::is_nil(myBoundary));
4013 // 2. Les instructions python associees a la frontiere
4014 // La premiere ligne est un commentaire a eliminer
4015 // La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4016 CORBA::String_var dumpCorbaBoundary = myBoundary->GetDumpPython();
4017 std::string pythonStructure_0 = dumpCorbaBoundary.in();
4018 MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4019 std::istringstream tout (pythonStructure_0) ;
4021 std::string pythonStructure ;
4022 while ( std::getline( tout, ligne ) )
4023 { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4024 MESSAGE ("pythonStructure :\n"<<pythonStructure);
4025 // 3. Decodage du nom du service
4026 std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4027 MESSAGE ( "... methode = " << methode);
4028 // 4. Mise en place des instructions
4029 int BoundaryType = myBoundary->GetType();
4030 MESSAGE ( "... BoundaryType = " << BoundaryType);
4031 std::string texte_control_0 ;
4032 texte_control_0 = myDriver->Texte_Iter_1_Boundary(BoundaryType, pythonStructure, methode, BoundaryName );
4033 texte_control += texte_control_0 ;
4034 // 5. Memorisation du traitement
4035 ListeBoundaryTraitees.push_back( BoundaryName );
4039 return texte_control ;
4042 //=============================================================================
4043 //=============================================================================
4044 // Next functions are inherited from SALOMEDS::Driver interface
4045 //=============================================================================
4046 //=============================================================================
4047 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
4049 CORBA::Boolean isMultiFile)
4051 MESSAGE ("Save for theURL = "<< theURL);
4052 SALOMEDS::TMPFile_var aStreamFile;
4054 // get temporary directory name
4055 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4057 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
4058 StudyContext& context = myContextMap[ aStudy->StudyId() ];
4060 // HOMARD data file name
4061 std::string aFileName = "";
4063 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
4064 aFileName += "_HOMARD.dat";
4066 // initialize sequence of file names
4067 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
4068 aFileSeq->length(1);
4069 aFileSeq[0] = CORBA::string_dup(aFileName.c_str()) ;
4071 // get full path to the data file
4072 aFileName = tmpDir + aFileName;
4076 std::ofstream f(aFileName.c_str());
4078 // clear temporary id map
4079 context._idmap.clear();
4084 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
4085 for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
4086 HOMARD::HOMARD_Cas_var aCas = it_case->second;
4087 PortableServer::ServantBase_var aServant = GetServant(aCas);
4088 HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4090 f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
4091 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
4095 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4096 for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
4097 HOMARD::HOMARD_Zone_var aZone = it_zone->second;
4098 PortableServer::ServantBase_var aServant = GetServant(aZone);
4099 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4101 f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
4102 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4105 // -> save hypotheses
4106 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4107 for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
4108 HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
4109 PortableServer::ServantBase_var aServant = GetServant(aHypo);
4110 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4112 f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
4113 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4116 // -> save iterations
4117 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4118 for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
4119 HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
4120 PortableServer::ServantBase_var aServant = GetServant(aIter);
4121 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4123 f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
4124 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4127 // -> save boundaries
4128 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4129 for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
4130 HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
4131 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4132 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4133 if (aBoundaryServant) {
4134 f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
4135 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4139 MESSAGE ("close file");
4142 // put temporary files to the stream
4143 MESSAGE ("put temporary files to the stream");
4144 aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq.in(), isMultiFile);
4146 // remove temporary files
4147 MESSAGE ("remove temporary files");
4148 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4150 // return data stream
4151 MESSAGE ("return data stream");
4152 return aStreamFile._retn();
4155 //===========================================================================
4156 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
4158 CORBA::Boolean isMultiFile)
4160 // No specific ASCII persistence
4161 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
4162 return aStreamFile._retn();
4165 //===========================================================================
4166 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
4167 const SALOMEDS::TMPFile& theStream,
4169 CORBA::Boolean isMultiFile)
4171 MESSAGE ("Load pour theURL = "<< theURL);
4172 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
4174 // set current study
4175 if (myCurrentStudy->_is_nil() || aStudy->StudyId() != myCurrentStudy->StudyId())
4176 SetCurrentStudy(aStudy);
4178 // get temporary directory name
4179 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4181 // Convert the stream into sequence of files to process
4182 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
4185 // HOMARD data file name
4186 std::string aFileName = "";
4188 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
4189 aFileName = tmpDir + aFileName + "_HOMARD.dat";
4191 StudyContext& context = myContextMap[ aStudy->StudyId() ];
4195 std::ifstream f(aFileName.c_str());
4198 context._mesCas.clear();
4199 context._mesHypotheses.clear();
4200 context._mesIterations.clear();
4201 context._mesZones.clear();
4202 context._mesBoundarys.clear();
4203 context._idmap.clear();
4209 std::getline(f, line);
4210 std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
4211 std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
4212 std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
4213 std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
4214 std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
4215 std::string yacsSignature = HOMARD::GetSignature(HOMARD::YACS);
4216 if (line.substr(0, bounSignature.size()) == bounSignature) {
4217 // re-create boundary
4218 MESSAGE ("Recreation de la frontiere" );
4219 HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
4220 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4221 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4222 if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
4223 context._mesBoundarys[aBoundary->GetName()] = aBoundary;
4224 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4227 else if (line.substr(0, caseSignature.size()) == caseSignature) {
4229 MESSAGE ("Recreation du cas" );
4230 HOMARD::HOMARD_Cas_var aCase = newCase();
4231 PortableServer::ServantBase_var aServant = GetServant(aCase);
4232 HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4233 if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
4234 context._mesCas[aCase->GetName()] = aCase;
4235 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
4238 else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
4239 // re-create hypothesis
4240 MESSAGE ("Recreation de l hypothese" );
4241 HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
4242 PortableServer::ServantBase_var aServant = GetServant(aHypo);
4243 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4244 if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
4245 context._mesHypotheses[aHypo->GetName()] = aHypo;
4246 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4249 else if (line.substr(0, iterSignature.size()) == iterSignature) {
4250 // re-create iteration
4251 MESSAGE ("Recreation de l iteration" );
4252 HOMARD::HOMARD_Iteration_var aIter = newIteration();
4253 PortableServer::ServantBase_var aServant = GetServant(aIter);
4254 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4255 if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
4256 context._mesIterations[aIter->GetName()] = aIter;
4257 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4260 else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
4261 MESSAGE ("Recreation de la zone" );
4263 HOMARD::HOMARD_Zone_var aZone = newZone();
4264 PortableServer::ServantBase_var aServant = GetServant(aZone);
4265 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4266 if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
4267 context._mesZones[aZone->GetName()] = aZone;
4268 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4271 else if (line.substr(0, zoneSignature.size()) == yacsSignature) {
4272 MESSAGE ("Recreation du schema YACS" );
4274 HOMARD::HOMARD_YACS_var aYACS = newYACS();
4275 PortableServer::ServantBase_var aServant = GetServant(aYACS);
4276 HOMARD_YACS_i* aYACSServant = dynamic_cast<HOMARD_YACS_i*>(aServant.in());
4277 if (aYACSServant && aYACSServant->Restore(line.substr(yacsSignature.size()))) {
4278 context._mesYACSs[aYACS->GetName()] = aYACS;
4279 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aYACSServant);
4288 // Remove temporary files created from the stream
4290 SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4295 //===========================================================================
4296 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
4297 const SALOMEDS::TMPFile& theStream,
4299 CORBA::Boolean isMultiFile)
4301 // No specific ASCII persistence
4302 return Load(theComponent, theStream, theURL, isMultiFile);
4305 //===========================================================================
4306 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
4308 if (theComponent->GetStudy()->StudyId() == GetCurrentStudyID()) {
4309 // clearing study context should be done here:
4310 // - destroy all servants and related CORBA objects
4312 // - remove context from myContextMap
4313 myContextMap.erase(theComponent->GetStudy()->StudyId());
4314 // - nullify myCurrentStudy
4315 myCurrentStudy = SALOMEDS::Study::_nil();
4319 //===========================================================================
4320 char* HOMARD_Gen_i::ComponentDataType()
4322 return CORBA::string_dup("HOMARD");
4325 //===========================================================================
4326 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
4327 const char* IORString,
4328 CORBA::Boolean isMultiFile,
4329 CORBA::Boolean isASCII)
4331 CORBA::String_var aString("");
4332 if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
4333 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4334 CORBA::Object_var anObj = _orb->string_to_object(IORString);
4335 if (!CORBA::is_nil(anObj)) {
4336 PortableServer::ServantBase_var aServant = GetServant(anObj);
4337 PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
4339 std::map<int, PortableServer::ServantBase*>::const_iterator it;
4340 for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
4341 if (it->second == aStorable) {
4342 std::stringstream os;
4344 aString = CORBA::string_dup(os.str().c_str());
4350 return aString._retn();
4353 //===========================================================================
4354 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
4355 const char* aLocalPersistentID,
4356 CORBA::Boolean isMultiFile,
4357 CORBA::Boolean isASCII)
4359 CORBA::String_var aString("");
4360 if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
4361 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4362 int id = atoi(aLocalPersistentID);
4363 if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
4364 CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
4365 if (!CORBA::is_nil(object)) {
4366 aString = _orb->object_to_string(object);
4370 return aString._retn();
4373 //===========================================================================
4374 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
4376 if(CORBA::is_nil(myCurrentStudy))
4379 HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
4380 if(!aCas->_is_nil())
4383 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
4384 if(!aHypo->_is_nil())
4387 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
4388 if(!aZone->_is_nil())
4391 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
4392 if(!aBoundary->_is_nil())
4395 /* Iteration is not published directly
4396 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
4397 if(!aIter->_is_nil())
4403 //===========================================================================
4404 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
4406 // No Copy/Paste support
4410 //===========================================================================
4411 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
4412 CORBA::Long& theObjectID)
4414 // No Copy/Paste support
4415 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
4416 return aStreamFile._retn();
4419 //===========================================================================
4420 CORBA::Boolean HOMARD_Gen_i::CanPaste(const char *theComponentName,
4421 CORBA::Long theObjectID)
4423 // No Copy/Paste support
4427 //===========================================================================
4428 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
4429 CORBA::Long theObjectID,
4430 SALOMEDS::SObject_ptr theSObject)
4432 // No Copy/Paste support
4433 SALOMEDS::SObject_var aResultSO;
4434 return aResultSO._retn();
4437 //===========================================================================
4438 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
4440 PortableServer::Servant aServant = 0;
4441 if (!CORBA::is_nil(theObject)) {
4443 aServant = _poa->reference_to_servant(theObject);
4451 //==========================================================================
4452 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
4453 CORBA::Boolean isPublished,
4454 CORBA::Boolean isMultiFile,
4455 CORBA::Boolean& isValidScript)
4457 MESSAGE ("Entree dans DumpPython");
4459 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
4460 if(CORBA::is_nil(aStudy))
4461 return new Engines::TMPFile(0);
4463 SALOMEDS::SObject_var aSO = aStudy->FindComponent("HOMARD");
4464 if(CORBA::is_nil(aSO))
4465 return new Engines::TMPFile(0);
4467 std::string aScript = "\"\"\"\n";
4468 aScript += "Python script for HOMARD\n";
4469 aScript += "Copyright EDF-R&D 2013\n";
4470 aScript += "\"\"\"\n";
4471 aScript += "__revision__ = \"V1.2\"\n";
4472 aScript += "import HOMARD\n";
4474 aScript += "import salome\n";
4475 aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
4477 aScript += "def RebuildData(theStudy):\n";
4478 aScript += "\thomard.SetCurrentStudy(theStudy)\n";
4481 aScript += "\thomard.SetCurrentStudy(salome.myStudy)\n";
4482 MESSAGE (". Au depart \n"<<aScript);
4485 if (myContextMap[GetCurrentStudyID()]._mesBoundarys.size() > 0)
4487 MESSAGE (". Ecritures des frontieres");
4488 aScript += "#\n# Creation of the boundaries";
4489 aScript += "\n# ==========================";
4491 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4492 for (it_boundary = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
4493 it_boundary != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); ++it_boundary)
4495 HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
4496 CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
4497 std::string dumpBoundary = dumpCorbaBoundary.in();
4498 MESSAGE (dumpBoundary<<"\n");
4499 aScript += dumpBoundary;
4503 if (myContextMap[GetCurrentStudyID()]._mesZones.size() > 0)
4505 MESSAGE (". Ecritures des zones");
4506 aScript += "#\n# Creation of the zones";
4507 aScript += "\n# =====================";
4509 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4510 for ( it_zone = myContextMap[GetCurrentStudyID()]._mesZones.begin();
4511 it_zone != myContextMap[GetCurrentStudyID()]._mesZones.end(); ++it_zone)
4513 HOMARD::HOMARD_Zone_var myZone = (*it_zone).second;
4514 CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4515 std::string dumpZone = dumpCorbaZone.in();
4516 MESSAGE (dumpZone<<"\n");
4517 aScript += dumpZone;
4521 if (myContextMap[GetCurrentStudyID()]._mesHypotheses.size() > 0)
4523 MESSAGE (". Ecritures des hypotheses");
4524 aScript += "#\n# Creation of the hypotheses";
4525 aScript += "\n# ==========================";
4527 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4528 for ( it_hypo = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
4529 it_hypo != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it_hypo++)
4531 HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
4532 CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
4533 std::string dumpHypo = dumpCorbaHypo.in();
4534 MESSAGE (dumpHypo<<"\n");
4535 aScript += dumpHypo;
4539 if (myContextMap[GetCurrentStudyID()]._mesCas.size() > 0)
4541 MESSAGE (". Ecritures des cas");
4542 aScript += "#\n# Creation of the cases";
4543 aScript += "\n# =====================";
4545 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
4546 for (it_cas = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4547 it_cas != myContextMap[GetCurrentStudyID()]._mesCas.end(); it_cas++)
4549 std::string nomCas = (*it_cas).first;
4550 std::string dumpCas = std::string("\n# Creation of the case ") ;
4551 dumpCas += nomCas + std::string("\n");
4552 dumpCas += std::string("\t") + nomCas;
4553 dumpCas += std::string(" = homard.CreateCase(\"") + nomCas + std::string("\", \"");
4555 HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
4556 CORBA::String_var cIter0= myCase->GetIter0Name();
4557 std::string iter0 = cIter0.in();
4559 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[iter0];
4560 CORBA::String_var cMesh0= myIteration->GetMeshFile();
4561 std::string mesh0 = cMesh0.in();
4562 CORBA::String_var cMeshName0= myIteration->GetMeshName();
4563 std::string meshName0 = cMeshName0.in();
4564 dumpCas += meshName0 + std::string("\", \"")+ mesh0 + std::string("\")\n");
4565 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4566 std::string dumpCas2= dumpCorbaCase.in();
4568 MESSAGE (dumpCas<<dumpCas2<<"\n");
4569 aScript += dumpCas + dumpCas2;
4573 if (myContextMap[GetCurrentStudyID()]._mesIterations.size() > 0)
4575 MESSAGE (". Ecritures des iterations");
4576 aScript += "#\n# Creation of the iterations" ;
4577 aScript += "\n# ==========================";
4579 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4580 for (it_iter = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
4581 it_iter != myContextMap[GetCurrentStudyID()]._mesIterations.end(); ++it_iter)
4583 HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
4584 CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
4585 std::string dumpIter = dumpCorbaIter.in();
4586 MESSAGE (dumpIter<<"\n");
4587 aScript += dumpIter;
4591 if (myContextMap[GetCurrentStudyID()]._mesYACSs.size() > 0)
4593 MESSAGE (". Ecritures des schemas YACS");
4594 aScript += "#\n# Creation of the schemas YACS";
4595 aScript += "\n# ============================";
4597 std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it_yacs;
4598 for ( it_yacs = myContextMap[GetCurrentStudyID()]._mesYACSs.begin();
4599 it_yacs != myContextMap[GetCurrentStudyID()]._mesYACSs.end(); ++it_yacs)
4601 HOMARD::HOMARD_YACS_var myYACS = (*it_yacs).second;
4602 CORBA::String_var dumpCorbaYACS = myYACS->GetDumpPython();
4603 std::string dumpYACS = dumpCorbaYACS.in();
4604 MESSAGE (dumpYACS<<"\n");
4605 aScript += dumpYACS;
4608 MESSAGE (". Ecritures finales");
4610 aScript += "\n\tpass";
4613 if( !isMultiFile ) // remove unnecessary tabulation
4614 aScript = RemoveTabulation( aScript );
4616 // MESSAGE ("A ecrire \n"<<aScript);
4617 const size_t aLen = strlen(aScript.c_str());
4618 char* aBuffer = new char[aLen+1];
4619 strcpy(aBuffer, aScript.c_str());
4621 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
4622 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
4624 MESSAGE ("Sortie de DumpPython");
4625 return aStreamFile._retn();
4629 //=============================================================================
4630 //=============================================================================
4632 //=============================================================================
4633 //=============================================================================
4634 void HOMARD_Gen_i::IsValidStudy( )
4636 // MESSAGE( "IsValidStudy" );
4637 if (CORBA::is_nil(myCurrentStudy))
4639 SALOME::ExceptionStruct es;
4640 es.type = SALOME::BAD_PARAM;
4641 es.text = "Invalid study context";
4642 throw SALOME::SALOME_Exception(es);
4647 //=============================================================================
4648 CORBA::Boolean HOMARD_Gen_i::VerifieDir(const char* nomDir)
4650 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
4651 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4652 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
4654 if (std::string(nomDir) == std::string(it->second->GetDirName())) return false;
4658 /*//=============================================================================
4659 void SALOMEException( std::string message )
4661 SALOME::ExceptionStruct es;
4662 es.type = SALOME::BAD_PARAM;
4664 throw SALOME::SALOME_Exception(es);
4667 //=============================================================================
4668 char* HOMARD_Gen_i::getVersion()
4670 #if HOMARD_DEVELOPMENT
4671 return CORBA::string_dup(HOMARD_VERSION_STR"dev");
4673 return CORBA::string_dup(HOMARD_VERSION_STR);
4676 //===============================================================================
4677 // Recuperation de la chaine de caracteres par rapport a l'apparition d'un texte
4678 // ligne : la ligne a manipuler
4679 // texte : le texte a reperer
4680 // option : 0 : la chaine avant le texte
4681 // 1 : la chaine apres le texte
4682 // Si le texte est absent, on retourne la chaine totale
4683 //===============================================================================
4684 std::string HOMARD_Gen_i::GetStringInTexte( const std::string ligne, const std::string texte, int option )
4686 // MESSAGE("GetStringInTexte, recherche de '"<<texte<<"' dans '"<<ligne<<"'"<<", option = "<<option);
4688 std::string chaine = ligne ;
4689 int position = ligne.find_first_of( texte ) ;
4692 if ( option == 0 ) { chaine = ligne.substr( 0, position ) ; }
4693 else { chaine = ligne.substr( position+1 ) ; }
4698 // //===============================================================================
4699 // // Langue de SALOME
4700 // //===============================================================================
4701 void HOMARD_Gen_i::SetLanguageShort(const char* LanguageShort)
4703 // MESSAGE ("SetLanguageShort pour LanguageShort = " << LanguageShort );
4704 _LangueShort = LanguageShort ;
4705 if ( _LangueShort == "fr" ) { _Langue = "Francais" ; }
4706 else { _Langue = "English" ; }
4709 char* HOMARD_Gen_i::GetLanguageShort()
4711 // MESSAGE ("GetLanguageShort");
4712 return CORBA::string_dup( _LangueShort.c_str() );
4715 //=============================================================================
4718 PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
4719 PortableServer::POA_ptr poa,
4720 PortableServer::ObjectId* contId,
4721 const char* instanceName,
4722 const char* interfaceName)
4724 MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
4725 HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
4726 return myHOMARD_Gen->getId();