1 // Copyright (C) 2011-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "HOMARD_Gen_i.hxx"
21 #include "HOMARD_Cas_i.hxx"
22 #include "HOMARD_Hypothesis_i.hxx"
23 #include "HOMARD_Iteration_i.hxx"
24 #include "HOMARD_Boundary_i.hxx"
25 #include "HOMARD_Zone_i.hxx"
26 #include "HomardDriver.hxx"
27 #include "HOMARD_DriverTools.hxx"
28 #include "HomardMedCommun.h"
29 #include "YACSDriver.hxx"
31 #include "HOMARD_version.h"
33 #include "utilities.h"
34 #include "Utils_SINGLETON.hxx"
35 #include "Utils_CorbaException.hxx"
36 #include "SALOMEDS_Tool.hxx"
37 #include "SALOME_LifeCycleCORBA.hxx"
38 #include "SALOMEconfig.h"
39 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
40 #include CORBA_CLIENT_HEADER(SMESH_Gen)
57 //=============================================================================
59 //=============================================================================
60 std::string RemoveTabulation( std::string theScript )
62 std::string::size_type aPos = 0;
63 while( aPos < theScript.length() )
65 aPos = theScript.find( "\n\t", aPos );
66 if( aPos == std::string::npos )
68 theScript.replace( aPos, 2, "\n" );
73 //=============================================================================
75 * standard constructor
77 //=============================================================================
78 HOMARD_Gen_i::HOMARD_Gen_i( CORBA::ORB_ptr orb,
79 PortableServer::POA_ptr poa,
80 PortableServer::ObjectId * contId,
81 const char *instanceName,
82 const char *interfaceName) :
83 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
85 MESSAGE("constructor");
87 _id = _poa->activate_object(_thisObj);
89 myHomard = new ::HOMARD_Gen();
90 _NS = SINGLETON_<SALOME_NamingService>::Instance();
91 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
94 //=================================
98 //================================
99 HOMARD_Gen_i::~HOMARD_Gen_i()
102 //=============================================================================
103 //=============================================================================
104 // Utilitaires pour l'étude
105 //=============================================================================
106 //=============================================================================
107 void HOMARD_Gen_i::addInStudy(SALOMEDS::Study_ptr theStudy)
109 ASSERT(!CORBA::is_nil(theStudy));
110 MESSAGE("addInStudy: ajout eventuel du composant HOMARD dans current study ID = " << GetCurrentStudyID()) ;
111 SALOMEDS::StudyBuilder_var myBuilder = theStudy->NewBuilder();
113 // Create SComponent labelled 'homard' if it doesn't already exit
114 SALOMEDS::SComponent_var homardFather = theStudy->FindComponent(ComponentDataType());
115 if (CORBA::is_nil(homardFather))
117 myBuilder->NewCommand();
118 MESSAGE("Add Component HOMARD");
120 bool aLocked = theStudy->GetProperties()->IsLocked();
121 if (aLocked) theStudy->GetProperties()->SetLocked(false);
123 homardFather = myBuilder->NewComponent(ComponentDataType());
124 SALOMEDS::GenericAttribute_var anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributeName");
125 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
126 CORBA::Object_var objVarN = _NS->Resolve("/Kernel/ModulCatalog");
127 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
128 SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
129 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent(ComponentDataType());
130 if (!Comp->_is_nil())
132 aName->SetValue(ComponentDataType());
135 anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributePixMap");
136 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
137 aPixmap->SetPixMap("HOMARD_2.png");
138 myBuilder->DefineComponentInstance(homardFather, HOMARD_Gen::_this());
140 if (aLocked) theStudy->GetProperties()->SetLocked(true);
141 myBuilder->CommitCommand();
144 //=============================================================================
145 void HOMARD_Gen_i::SetCurrentStudy(SALOMEDS::Study_ptr theStudy)
147 MESSAGE("SetCurrentStudy: current study Id = " << GetCurrentStudyID());
148 myCurrentStudy = SALOMEDS::Study::_duplicate(theStudy);
149 this->addInStudy(myCurrentStudy);
151 //=============================================================================
152 SALOMEDS::Study_ptr HOMARD_Gen_i::GetCurrentStudy()
153 //=============================================================================
155 MESSAGE("GetCurrentStudy: study Id = " << GetCurrentStudyID());
156 return SALOMEDS::Study::_duplicate(myCurrentStudy);
158 //=============================================================================
159 CORBA::Long HOMARD_Gen_i::GetCurrentStudyID()
160 //=============================================================================
162 return myCurrentStudy->_is_nil() ? -1 : myCurrentStudy->StudyId();
164 //=============================================================================
165 //=============================================================================
167 //=============================================================================
168 //=============================================================================
169 // Utilitaires pour l'iteration
170 //=============================================================================
171 //=============================================================================
172 void HOMARD_Gen_i::SetEtatIter(const char* nomIter, const CORBA::Long Etat)
173 //=====================================================================================
175 MESSAGE( "SetEtatIter : affectation de l'etat " << Etat << " a l'iteration " << nomIter );
176 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
177 if (CORBA::is_nil(myIteration))
179 SALOME::ExceptionStruct es;
180 es.type = SALOME::BAD_PARAM;
181 es.text = "Invalid iteration";
182 throw SALOME::SALOME_Exception(es);
186 myIteration->SetState(Etat);
188 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
189 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
193 icone = "iter0.png" ;
194 else if ( Etat == 2 )
195 icone = "iter_calculee.png" ;
197 icone = "iter_non_calculee.png" ;
198 PublishInStudyAttr(aStudyBuilder, aIterSO, NULL , NULL, icone.c_str(), NULL) ;
200 aStudyBuilder->CommitCommand();
203 //=============================================================================
204 //=============================================================================
206 //=============================================================================
207 //=============================================================================
208 // Destruction des structures identifiees par leurs noms
209 //=============================================================================
210 //=============================================================================
211 CORBA::Long HOMARD_Gen_i::DeleteBoundary(const char* BoundaryName)
213 MESSAGE ( "DeleteBoundary : BoundaryName = " << BoundaryName );
214 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
215 if (CORBA::is_nil(myBoundary))
217 SALOME::ExceptionStruct es;
218 es.type = SALOME::BAD_PARAM;
219 es.text = "Invalid boundary";
220 throw SALOME::SALOME_Exception(es);
224 // On verifie que la frontiere n'est plus utilisee
225 HOMARD::listeCases* maListe = GetAllCasesName();
226 int numberOfCases = maListe->length();
227 MESSAGE ( ".. Nombre de cas = " << numberOfCases );
228 std::string CaseName ;
229 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType ;
231 HOMARD::HOMARD_Cas_var myCase ;
232 for (int NumeCas = 0; NumeCas< numberOfCases; NumeCas++)
234 CaseName = std::string((*maListe)[NumeCas]);
235 MESSAGE ( "... Examen du cas = " << CaseName.c_str() );
236 myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
237 ASSERT(!CORBA::is_nil(myCase));
238 ListBoundaryGroupType = myCase->GetBoundaryGroup();
239 numberOfitems = ListBoundaryGroupType->length();
240 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
241 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
243 if ( std::string((*ListBoundaryGroupType)[NumBoundary]) == BoundaryName )
245 SALOME::ExceptionStruct es;
246 es.type = SALOME::BAD_PARAM;
247 es.text = "This boundary is used in a case and cannot be deleted.";
248 throw SALOME::SALOME_Exception(es);
254 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
255 myContextMap[GetCurrentStudyID()]._mesBoundarys.erase(BoundaryName);
256 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(BoundaryName, ComponentDataType());
257 SALOMEDS::SObject_var aSO =listSO[0];
258 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
259 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
263 //=============================================================================
264 CORBA::Long HOMARD_Gen_i::DeleteCase(const char* nomCas, CORBA::Long Option)
266 // Pour detruire un cas
267 MESSAGE ( "DeleteCase : nomCas = " << nomCas << ", avec option = " << Option );
268 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
269 if (CORBA::is_nil(myCase))
271 SALOME::ExceptionStruct es;
272 es.type = SALOME::BAD_PARAM;
273 es.text = "Invalid case context";
274 throw SALOME::SALOME_Exception(es);
277 // On commence par detruire toutes les iterations en partant de l'initiale et y compris elle
278 CORBA::String_var nomIter = myCase->GetIter0Name();
279 CORBA::Long Option1 = 0 ;
280 if ( DeleteIterationOption(nomIter, Option1, Option) != 0 )
285 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
286 myContextMap[GetCurrentStudyID()]._mesCas.erase(nomCas);
287 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomCas, ComponentDataType());
288 SALOMEDS::SObject_var aSO =listSO[0];
289 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
290 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
294 //=============================================================================
295 CORBA::Long HOMARD_Gen_i::DeleteHypo(const char* nomHypo)
297 MESSAGE ( "DeleteHypo : nomHypo = " << nomHypo );
298 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
299 if (CORBA::is_nil(myHypo))
301 SALOME::ExceptionStruct es;
302 es.type = SALOME::BAD_PARAM;
303 es.text = "Invalid hypothesis";
304 throw SALOME::SALOME_Exception(es);
308 // On verifie que l'hypothese n'est plus utilisee
309 HOMARD::listeIters* maListeIter = myHypo->GetIterations();
310 int numberOfIter = maListeIter->length();
311 if ( numberOfIter > 0 )
313 SALOME::ExceptionStruct es;
314 es.type = SALOME::BAD_PARAM;
315 es.text = "This hypothesis is used in an iteration and cannot be deleted.";
316 throw SALOME::SALOME_Exception(es);
320 // suppression du lien avec les zones eventuelles
321 HOMARD::listeZonesHypo* maListe = myHypo->GetZones();
322 int numberOfZones = maListe->length();
323 MESSAGE ( ".. Nombre de zones = " << numberOfZones );
324 for (int NumeZone = 0; NumeZone< numberOfZones; NumeZone++)
326 std::string ZoneName = std::string((*maListe)[NumeZone]);
327 MESSAGE ( ".. suppression du lien avec la zone = " << ZoneName.c_str() );
328 DissociateHypoZone(nomHypo, ZoneName.c_str()) ;
332 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
333 myContextMap[GetCurrentStudyID()]._mesHypotheses.erase(nomHypo);
334 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomHypo, ComponentDataType());
335 SALOMEDS::SObject_var aSO =listSO[0];
336 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
337 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
341 //=============================================================================
342 CORBA::Long HOMARD_Gen_i::DeleteIteration(const char* nomIter, CORBA::Long Option)
344 // Option = 0 : On ne supprime pas le fichier du maillage associe
345 // Option = 1 : On supprime le fichier du maillage associe
346 // Pour detruire une iteration courante
347 MESSAGE ( "DeleteIteration : nomIter = " << nomIter << ", avec option = " << Option );
348 CORBA::Long Option1 = 1 ;
349 return DeleteIterationOption(nomIter, Option1, Option);
351 //=============================================================================
352 CORBA::Long HOMARD_Gen_i::DeleteIterationOption(const char* nomIter, CORBA::Long Option1, CORBA::Long Option2)
354 // Option1 = 0 : On autorise la destruction de l'iteration 0
355 // Option1 = 1 : On interdit la destruction de l'iteration 0
357 // Option2 = 0 : On ne supprime pas le fichier du maillage associe
358 // Option2 = 1 : On supprime le fichier du maillage associe
359 MESSAGE ( "DeleteIterationOption : nomIter = " << nomIter << ", avec options = " << Option1<< ", " << Option2 );
360 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
361 if (CORBA::is_nil(myIteration))
363 SALOME::ExceptionStruct es;
364 es.type = SALOME::BAD_PARAM;
365 es.text = "Invalid iteration";
366 throw SALOME::SALOME_Exception(es);
370 int numero = myIteration->GetNumber();
371 MESSAGE ( "DeleteIterationOption : numero = " << numero );
372 if ( numero == 0 and Option1 == 1 )
374 SALOME::ExceptionStruct es;
375 es.type = SALOME::BAD_PARAM;
376 es.text = "This iteration cannot be deleted.";
377 throw SALOME::SALOME_Exception(es);
381 // On detruit recursivement toutes les filles
382 HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
383 int numberOfIter = maListe->length();
384 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
386 std::string nomIterFille = std::string((*maListe)[NumeIter]);
387 MESSAGE ( ".. appel recursif de DeleteIterationOption pour nomIter = " << nomIterFille.c_str() );
388 DeleteIterationOption(nomIterFille.c_str(), Option1, Option2);
391 // On arrive ici pour une iteration sans fille
392 MESSAGE ( "Destruction effective de " << nomIter );
393 // On commence par invalider l'iteration pour faire le menage des dependances
394 // et eventuellement du maillage associe
396 if ( numero == 0 ) { option = 0 ; }
397 else { option = Option2 ; }
398 InvalideIterOption(nomIter, option) ;
400 // Retrait dans la descendance de l'iteration parent
403 std::string nomIterationParent = myIteration->GetIterParentName();
404 MESSAGE ( "Retrait dans la descendance de nomIterationParent " << nomIterationParent );
405 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
406 if (CORBA::is_nil(myIterationParent))
408 SALOME::ExceptionStruct es;
409 es.type = SALOME::BAD_PARAM;
410 es.text = "Invalid iteration";
411 throw SALOME::SALOME_Exception(es);
414 myIterationParent->UnLinkNextIteration(nomIter);
417 // suppression du lien avec l'hypothese
420 std::string nomHypo = myIteration->GetHypoName();
421 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
422 ASSERT(!CORBA::is_nil(myHypo));
423 myHypo->UnLinkIteration(nomIter);
426 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
427 myContextMap[GetCurrentStudyID()]._mesIterations.erase(nomIter);
428 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomIter, ComponentDataType());
429 SALOMEDS::SObject_var aSO =listSO[0];
430 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
431 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
432 // on peut aussi faire RemoveObject
433 // MESSAGE ( "Au final" );
434 // HOMARD::listeIterations* Liste = GetAllIterationsName() ;
435 // numberOfIter = Liste->length();
436 // for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
438 // std::string nomIterFille = std::string((*Liste)[NumeIter]);
439 // MESSAGE ( ".. nomIter = " << nomIterFille.c_str() );
444 //=============================================================================
445 CORBA::Long HOMARD_Gen_i::DeleteZone(const char* nomZone)
447 MESSAGE ( "DeleteZone : nomZone = " << nomZone );
448 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[nomZone];
449 if (CORBA::is_nil(myZone))
451 SALOME::ExceptionStruct es;
452 es.type = SALOME::BAD_PARAM;
453 es.text = "Invalid zone";
454 throw SALOME::SALOME_Exception(es);
458 // On verifie que la zone n'est plus utilisee
459 HOMARD::listeHypo* maListe = myZone->GetHypo();
460 int numberOfHypo = maListe->length();
461 MESSAGE ( ".. Nombre d'hypotheses = " << numberOfHypo );
462 if ( numberOfHypo > 0 )
464 SALOME::ExceptionStruct es;
465 es.type = SALOME::BAD_PARAM;
466 es.text = "This zone is used in an hypothesis and cannot be deleted.";
467 throw SALOME::SALOME_Exception(es);
471 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
472 myContextMap[GetCurrentStudyID()]._mesZones.erase(nomZone);
473 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomZone, ComponentDataType());
474 SALOMEDS::SObject_var aSO =listSO[0];
475 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
476 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
480 //=============================================================================
481 //=============================================================================
483 //=============================================================================
484 //=============================================================================
485 // Invalidation des structures identifiees par leurs noms
486 //=============================================================================
487 //=============================================================================
488 void HOMARD_Gen_i::InvalideBoundary(const char* BoundaryName)
490 MESSAGE( "InvalideBoundary : BoundaryName = " << BoundaryName );
491 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
492 if (CORBA::is_nil(myBoundary))
494 SALOME::ExceptionStruct es;
495 es.type = SALOME::BAD_PARAM;
496 es.text = "Invalid boundary";
497 throw SALOME::SALOME_Exception(es);
502 SALOME::ExceptionStruct es;
503 es.type = SALOME::BAD_PARAM;
504 es.text = "No change is allowed in a boundary. Ask for evolution.";
505 throw SALOME::SALOME_Exception(es);
509 //=============================================================================
510 void HOMARD_Gen_i::InvalideHypo(const char* nomHypo)
512 MESSAGE( "InvalideHypo : nomHypo = " << nomHypo );
513 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
514 if (CORBA::is_nil(myHypo))
516 SALOME::ExceptionStruct es;
517 es.type = SALOME::BAD_PARAM;
518 es.text = "Invalid hypothesis";
519 throw SALOME::SALOME_Exception(es);
523 HOMARD::listeIters* maListe = myHypo->GetIterations();
524 int numberOfIter = maListe->length();
525 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
527 std::string nomIter = std::string((*maListe)[NumeIter]);
528 MESSAGE( ".. nomIter = " << nomIter );
529 InvalideIter(nomIter.c_str());
532 //=============================================================================
533 void HOMARD_Gen_i::InvalideIter(const char* nomIter)
535 MESSAGE("InvalideIter : nomIter = " << nomIter);
536 // Pour invalider totalement une iteration courante
537 CORBA::Long Option = 1 ;
538 return InvalideIterOption(nomIter, Option);
540 //=============================================================================
541 void HOMARD_Gen_i::InvalideIterOption(const char* nomIter, CORBA::Long Option)
543 // Option = 0 : On ne supprime pas le fichier du maillage associe
544 // Option = 1 : On supprime le fichier du maillage associe
545 MESSAGE ( "InvalideIterOption : nomIter = " << nomIter << ", avec option = " << Option );
546 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
547 if (CORBA::is_nil(myIteration))
549 SALOME::ExceptionStruct es;
550 es.type = SALOME::BAD_PARAM;
551 es.text = "Invalid iteration";
552 throw SALOME::SALOME_Exception(es);
556 HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
557 int numberOfIter = maListe->length();
558 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
560 std::string nomIterFille = std::string((*maListe)[NumeIter]);
561 MESSAGE ( ".. appel recursif de InvalideIter pour nomIter = " << nomIterFille.c_str() );
562 InvalideIter(nomIterFille.c_str());
565 // On arrive ici pour une iteration sans fille
566 MESSAGE ( "Invalidation effective de " << nomIter );
567 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
568 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aIterSO);
569 for (; aIter->More(); aIter->Next())
571 SALOMEDS::SObject_var so = aIter->Value();
572 SALOMEDS::GenericAttribute_var anAttr;
573 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
574 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
575 std::string value (aCommentAttr->Value());
576 if(value == std::string("HypoHomard")) continue;
577 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
578 aStudyBuilder->RemoveObject(so);
581 int etat = myIteration->GetState();
584 SetEtatIter(nomIter,1);
585 const char * nomCas = myIteration->GetCaseName();
586 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
587 if (CORBA::is_nil(myCase))
589 SALOME::ExceptionStruct es;
590 es.type = SALOME::BAD_PARAM;
591 es.text = "Invalid case context";
592 throw SALOME::SALOME_Exception(es);
595 std::string nomDir = myIteration->GetDirName();
596 std::string nomFichier = myIteration->GetMeshFile();
597 std::string commande= "rm -rf " + std::string(nomDir);
598 if ( Option == 1 ) { commande = commande + ";rm -rf " + std::string(nomFichier) ; }
599 MESSAGE ( "commande = " << commande );
600 if ((system(commande.c_str())) != 0)
602 SALOME::ExceptionStruct es;
603 es.type = SALOME::BAD_PARAM;
604 es.text = "The directory for the calculation cannot be cleared." ;
605 throw SALOME::SALOME_Exception(es);
608 // Suppression du maillage publie dans SMESH
609 std::string MeshName = myIteration->GetMeshName() ;
610 DeleteResultInSmesh(nomFichier, MeshName) ;
614 //=============================================================================
615 void HOMARD_Gen_i::InvalideIterInfo(const char* nomIter)
617 MESSAGE("InvalideIterInfo : nomIter = " << nomIter);
618 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
619 if (CORBA::is_nil(myIteration))
621 SALOME::ExceptionStruct es;
622 es.type = SALOME::BAD_PARAM;
623 es.text = "Invalid iteration";
624 throw SALOME::SALOME_Exception(es);
628 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
629 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aIterSO);
630 for (; aIter->More(); aIter->Next())
632 SALOMEDS::SObject_var so = aIter->Value();
633 SALOMEDS::GenericAttribute_var anAttr;
634 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
635 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
636 std::string value (aCommentAttr->Value());
637 /* MESSAGE("... value = " << value);*/
638 if( (value == std::string("logInfo")) or ( value == std::string("SummaryInfo")) )
640 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
641 aStudyBuilder->RemoveObject(so);
645 const char * nomCas = myIteration->GetCaseName();
646 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
647 if (CORBA::is_nil(myCase))
649 SALOME::ExceptionStruct es;
650 es.type = SALOME::BAD_PARAM;
651 es.text = "Invalid case context";
652 throw SALOME::SALOME_Exception(es);
655 const char* nomDir = myIteration->GetDirName();
656 std::string commande = "rm -f " + std::string(nomDir) + "/info* " ;
657 commande += std::string(nomDir) + "/Liste.*info" ;
658 /* MESSAGE ( "commande = " << commande );*/
659 if ((system(commande.c_str())) != 0)
661 SALOME::ExceptionStruct es;
662 es.type = SALOME::BAD_PARAM;
663 es.text = "The directory for the calculation cannot be cleared." ;
664 throw SALOME::SALOME_Exception(es);
668 //=============================================================================
669 void HOMARD_Gen_i::InvalideZone(const char* ZoneName)
671 MESSAGE( "InvalideZone : ZoneName = " << ZoneName );
672 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
673 if (CORBA::is_nil(myZone))
675 SALOME::ExceptionStruct es;
676 es.type = SALOME::BAD_PARAM;
677 es.text = "Invalid zone";
678 throw SALOME::SALOME_Exception(es);
681 HOMARD::listeHypo* maListe = myZone->GetHypo();
682 int numberOfHypo = maListe->length();
683 MESSAGE( ".. numberOfHypo = " << numberOfHypo );
684 for (int NumeHypo = 0; NumeHypo< numberOfHypo; NumeHypo++)
686 std::string nomHypo = std::string((*maListe)[NumeHypo]);
687 MESSAGE( ".. nomHypo = " << nomHypo );
688 InvalideHypo(nomHypo.c_str());
691 //=============================================================================
692 //=============================================================================
694 //=============================================================================
695 //=============================================================================
696 // Association de lien entre des structures identifiees par leurs noms
697 //=============================================================================
698 //=============================================================================
699 void HOMARD_Gen_i::AssociateCaseIter(const char* nomCas, const char* nomIter, const char* labelIter)
701 MESSAGE( "AssociateCaseIter : " << nomCas << ", " << nomIter << ", " << labelIter );
703 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
704 if (CORBA::is_nil(myCase))
706 SALOME::ExceptionStruct es;
707 es.type = SALOME::BAD_PARAM;
708 es.text = "Invalid case";
709 throw SALOME::SALOME_Exception(es);
713 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
714 if (CORBA::is_nil(myIteration))
716 SALOME::ExceptionStruct es;
717 es.type = SALOME::BAD_PARAM;
718 es.text = "Invalid iteration";
719 throw SALOME::SALOME_Exception(es);
723 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
724 SALOMEDS::SObject_var aCasSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
725 if (CORBA::is_nil(aCasSO))
727 SALOME::ExceptionStruct es;
728 es.type = SALOME::BAD_PARAM;
729 es.text = "Invalid case";
730 throw SALOME::SALOME_Exception(es);
734 aStudyBuilder->NewCommand();
735 SALOMEDS::SObject_var newStudyIter = aStudyBuilder->NewObject(aCasSO);
736 PublishInStudyAttr(aStudyBuilder, newStudyIter, nomIter , labelIter,
737 "iter_non_calculee.png", _orb->object_to_string(myIteration)) ;
738 aStudyBuilder->CommitCommand();
740 myCase->AddIteration(nomIter);
741 myIteration->SetCaseName(nomCas);
743 //=====================================================================================
744 void HOMARD_Gen_i::AssociateHypoZone(const char* nomHypothesis, const char* ZoneName, CORBA::Long TypeUse)
746 MESSAGE ( "AssociateHypoZone : nomHypo = " << nomHypothesis << ", ZoneName= " << ZoneName << ", TypeUse = " << TypeUse);
748 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
749 ASSERT(!CORBA::is_nil(myHypo));
750 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
751 ASSERT(!CORBA::is_nil(aHypoSO));
753 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
754 ASSERT(!CORBA::is_nil(myZone));
755 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myZone)));
756 ASSERT(!CORBA::is_nil(aZoneSO));
758 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
760 aStudyBuilder->NewCommand();
762 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aHypoSO);
763 aStudyBuilder->Addreference(aSubSO, aZoneSO);
765 aStudyBuilder->CommitCommand();
767 myZone->AddHypo(nomHypothesis);
768 myHypo->AddZone0(ZoneName, TypeUse);
770 //=============================================================================
771 void HOMARD_Gen_i::AssociateIterHypo(const char* nomIter, const char* nomHypo)
773 MESSAGE("AssociateIterHypo : nomHypo = " << nomHypo << " nomIter = " << nomIter);
775 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
776 ASSERT(!CORBA::is_nil(myHypo));
777 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
778 ASSERT(!CORBA::is_nil(aHypoSO));
780 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
781 ASSERT(!CORBA::is_nil(myIteration));
782 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
783 ASSERT(!CORBA::is_nil(aIterSO));
785 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
787 aStudyBuilder->NewCommand();
789 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
790 aStudyBuilder->Addreference(aSubSO, aHypoSO);
792 aStudyBuilder->CommitCommand();
794 myIteration->SetHypoName(nomHypo);
795 myHypo->LinkIteration(nomIter);
797 //=============================================================================
798 //=============================================================================
800 //=============================================================================
801 //=============================================================================
802 // Dissociation de lien entre des structures identifiees par leurs noms
803 //=============================================================================
804 //=============================================================================
805 void HOMARD_Gen_i::DissociateHypoZone(const char* nomHypothesis, const char* ZoneName)
807 MESSAGE ( "DissociateHypoZone : ZoneName= " << ZoneName << ", nomHypo = " << nomHypothesis);
809 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
810 ASSERT(!CORBA::is_nil(myHypo));
811 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
812 ASSERT(!CORBA::is_nil(aHypoSO));
814 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
815 ASSERT(!CORBA::is_nil(myZone));
816 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myZone)));
817 ASSERT(!CORBA::is_nil(aZoneSO));
819 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
821 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator(aHypoSO);
822 for (; it->More(); it->Next())
824 SALOMEDS::SObject_var aHypObj = it->Value();
825 SALOMEDS::SObject_var ptrObj;
826 if (aHypObj->ReferencedObject(ptrObj))
828 if (std::string(ptrObj->GetName()) == std::string(aZoneSO->GetName()))
830 aStudyBuilder->NewCommand();
831 aStudyBuilder->RemoveObject(aHypObj);
832 aStudyBuilder->CommitCommand();
838 myZone->SupprHypo(nomHypothesis);
839 myHypo->SupprZone(ZoneName);
841 //=============================================================================
842 //=============================================================================
845 //=============================================================================
846 //=============================================================================
847 // Recuperation des listes
848 //=============================================================================
849 //=============================================================================
850 HOMARD::listeCases* HOMARD_Gen_i::GetAllCasesName()
852 MESSAGE("GetAllCasesName");
855 HOMARD::listeCases_var ret = new HOMARD::listeCases;
856 ret->length(myContextMap[GetCurrentStudyID()]._mesCas.size());
857 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
859 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
860 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
862 ret[i++] = CORBA::string_dup((*it).first.c_str());
867 //=============================================================================
868 HOMARD::listeHypotheses* HOMARD_Gen_i::GetAllHypothesesName()
870 MESSAGE("GetAllHypothesesName");
873 HOMARD::listeHypotheses_var ret = new HOMARD::listeHypotheses;
874 ret->length(myContextMap[GetCurrentStudyID()]._mesHypotheses.size());
875 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it;
877 for (it = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
878 it != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it++)
880 ret[i++] = CORBA::string_dup((*it).first.c_str());
885 //=============================================================================
886 HOMARD::listeZones* HOMARD_Gen_i::GetAllZonesName()
888 MESSAGE("GetAllZonesName");
891 HOMARD::listeZones_var ret = new HOMARD::listeZones;
892 ret->length(myContextMap[GetCurrentStudyID()]._mesZones.size());
893 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it;
895 for (it = myContextMap[GetCurrentStudyID()]._mesZones.begin();
896 it != myContextMap[GetCurrentStudyID()]._mesZones.end(); it++)
898 ret[i++] = CORBA::string_dup((*it).first.c_str());
903 //=============================================================================
904 HOMARD::listeIterations* HOMARD_Gen_i::GetAllIterationsName()
906 MESSAGE("GetAllIterationsName");
909 HOMARD::listeIterations_var ret = new HOMARD::listeIterations;
910 ret->length(myContextMap[GetCurrentStudyID()]._mesIterations.size());
911 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it;
913 for (it = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
914 it != myContextMap[GetCurrentStudyID()]._mesIterations.end(); it++)
916 ret[i++] = CORBA::string_dup((*it).first.c_str());
921 //=============================================================================
922 HOMARD::listeBoundarys* HOMARD_Gen_i::GetAllBoundarysName()
924 MESSAGE("GetAllBoundarysName");
927 HOMARD::listeBoundarys_var ret = new HOMARD::listeBoundarys;
928 ret->length(myContextMap[GetCurrentStudyID()]._mesBoundarys.size());
929 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it;
931 for (it = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
932 it != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); it++)
934 ret[i++] = CORBA::string_dup((*it).first.c_str());
939 //=============================================================================
940 //=============================================================================
942 //=============================================================================
943 //=============================================================================
944 // Recuperation des structures identifiees par leurs noms
945 //=============================================================================
946 //=============================================================================
947 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::GetCase(const char* nomCas)
949 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
950 ASSERT(!CORBA::is_nil(myCase));
951 return HOMARD::HOMARD_Cas::_duplicate(myCase);
953 //=============================================================================
954 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::GetZone(const char* ZoneName)
956 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
957 ASSERT(!CORBA::is_nil(myZone));
958 return HOMARD::HOMARD_Zone::_duplicate(myZone);
960 //=============================================================================
961 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::GetHypothesis(const char* nomHypothesis)
963 HOMARD::HOMARD_Hypothesis_var myHypothesis = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
964 ASSERT(!CORBA::is_nil(myHypothesis));
965 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
967 //=============================================================================
968 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::GetIteration(const char* NomIterationation)
970 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIterationation];
971 ASSERT(!CORBA::is_nil(myIteration));
972 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
974 //=============================================================================
975 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::GetBoundary(const char* nomBoundary)
977 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[nomBoundary];
978 ASSERT(!CORBA::is_nil(myBoundary));
979 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
981 //=============================================================================
982 //=============================================================================
984 //=============================================================================
985 //=============================================================================
987 //=============================================================================
988 //=============================================================================
989 void HOMARD_Gen_i::MeshInfo(const char* nomCas, const char* MeshName, const char* MeshFile, const char* DirName, CORBA::Long Qual, CORBA::Long Diam, CORBA::Long Conn, CORBA::Long Tail, CORBA::Long Inte)
991 MESSAGE ( "MeshInfo : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
992 MESSAGE ( "Qual = " << Qual << ", Diam = " << Diam << ", Conn = " << Conn << ", Tail = " << Tail << ", Inte = " << Inte );
996 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, 0, 1) ;
997 myCase->SetDirName(DirName) ;
999 myCase->MeshInfo(Qual, Diam, Conn, Tail, Inte) ;
1003 //=============================================================================
1004 //=============================================================================
1006 //=============================================================================
1007 //=============================================================================
1008 // Recuperation des structures par le contexte
1009 //=============================================================================
1010 //=============================================================================
1011 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::LastIteration(const char* nomCas)
1013 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1014 ASSERT(!CORBA::is_nil(myCase));
1016 HOMARD::HOMARD_Iteration_var myIteration = myCase->LastIteration();
1017 ASSERT(!CORBA::is_nil(myIteration));
1019 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1021 //=============================================================================
1022 //=============================================================================
1024 //=============================================================================
1025 //=============================================================================
1026 // Nouvelles structures
1027 //=============================================================================
1028 //=============================================================================
1029 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::newCase()
1031 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1032 HOMARD_Cas_i* aServant = new HOMARD_Cas_i(_orb, engine);
1033 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(aServant->_this());
1034 return aCase._retn();
1036 //=============================================================================
1037 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::newHypothesis()
1039 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1040 HOMARD_Hypothesis_i* aServant = new HOMARD_Hypothesis_i(_orb, engine);
1041 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(aServant->_this());
1042 return aHypo._retn();
1044 //=============================================================================
1045 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::newIteration()
1047 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1048 HOMARD_Iteration_i* aServant = new HOMARD_Iteration_i(_orb, engine);
1049 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(aServant->_this());
1050 return aIter._retn();
1052 //=============================================================================
1053 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::newBoundary()
1055 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1056 HOMARD_Boundary_i* aServant = new HOMARD_Boundary_i(_orb, engine);
1057 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(aServant->_this());
1058 return aBoundary._retn();
1060 //=============================================================================
1061 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::newZone()
1063 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1064 HOMARD_Zone_i* aServant = new HOMARD_Zone_i(_orb, engine);
1065 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(aServant->_this());
1066 return aZone._retn();
1068 //=============================================================================
1069 //=============================================================================
1071 //=============================================================================
1072 //=============================================================================
1073 // Creation des structures identifiees par leurs noms
1074 //=============================================================================
1075 //=============================================================================
1076 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCase(const char* nomCas, const char* MeshName, const char* MeshFile)
1078 // Creation d'un cas initial
1079 // nomCas : nom du cas a creer
1080 // MeshName, MeshFile : nom et fichier du maillage correspondant
1083 MESSAGE ( "CreateCase : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1085 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 0, 0, 2) ;
1087 // Valeurs par defaut des filtrages
1088 myCase->SetPyram(0);
1090 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1092 //=============================================================================
1093 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromIteration(const char* nomCas, const char* DirNameStart)
1095 // nomCas : nom du cas a creer
1096 // DirNameStart : nom du repertoire contenant l'iteration de reprise
1099 MESSAGE ( "CreateCaseFromIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1100 std::string nomDirWork = getenv("PWD") ;
1103 // A. Decodage du point de reprise
1104 // A.1. Controle du repertoire de depart de l'iteration
1105 codret = chdir(DirNameStart) ;
1108 SALOME::ExceptionStruct es;
1109 es.type = SALOME::BAD_PARAM;
1110 es.text = "The directory of the iteration does not exist.";
1111 throw SALOME::SALOME_Exception(es);
1114 // A.2. Reperage des fichiers du repertoire de reprise
1115 std::string file_configuration = "" ;
1116 std::string file_maillage_homard = "" ;
1119 struct dirent *dirp;
1120 dp = opendir(DirNameStart);
1121 while ( (dirp = readdir(dp)) != NULL )
1123 std::string file_name(dirp->d_name);
1124 // MESSAGE ( file_name );
1125 bilan = file_name.find("HOMARD.Configuration.") ;
1126 if ( bilan != string::npos ) { file_configuration = file_name ; }
1127 bilan = file_name.find("maill.") ;
1128 if ( bilan != string::npos )
1130 bilan = file_name.find(".hom.med") ;
1131 if ( bilan != string::npos ) { file_maillage_homard = file_name ; }
1135 MESSAGE ( "==> file_configuration : " << file_configuration ) ;
1136 MESSAGE ( "==> file_maillage_homard : " << file_maillage_homard ) ;
1138 if ( ( file_configuration == "" ) or ( file_maillage_homard == "" ) )
1140 SALOME::ExceptionStruct es;
1141 es.type = SALOME::BAD_PARAM;
1143 if ( file_configuration == "" ) { text = "The configuration file cannot be found." ; }
1144 else { text = "The HOMARD mesh file cannot be found." ; }
1145 es.text = CORBA::string_dup(text.c_str());
1146 throw SALOME::SALOME_Exception(es);
1149 // B. Lecture du fichier de configuration
1150 // ATTENTION : on doit veiller a la coherence entre HomardDriver et CreateCaseFromIteration
1156 // le constructeur de ifstream permet d'ouvrir un fichier en lecture
1157 std::ifstream fichier( file_configuration.c_str() );
1158 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1160 std::string ligne; // variable contenant chaque ligne lue
1161 std::string mot_cle;
1162 std::string argument;
1164 // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1165 while ( std::getline( fichier, ligne ) )
1167 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1168 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1169 ligne_bis >> mot_cle ;
1170 // B.2. Des valeurs entieres : le second bloc de la ligne
1171 if ( mot_cle == "NumeIter" )
1173 ligne_bis >> NumeIter ;
1176 // B.3. Des valeurs caracteres brutes : le second bloc de la ligne est la valeur
1177 else if ( ( mot_cle == "TypeConf" ) or ( mot_cle == "TypeElem" ) )
1179 ligne_bis >> argument ;
1181 if ( mot_cle == "TypeConf" )
1183 if ( argument == "conforme" ) { TypeConf = 1 ; }
1184 else if ( argument == "non_conforme_1_noeud" ) { TypeConf = 2 ; }
1185 else if ( argument == "non_conforme_1_arete" ) { TypeConf = 3 ; }
1186 else if ( argument == "non_conforme_indicateur" ) { TypeConf = 4 ; }
1188 else if ( mot_cle == "TypeElem" )
1190 if ( argument == "ignore_pyra" ) { Pyram = 1 ; }
1191 else if ( argument == "HOMARD" ) { Pyram = 0 ; }
1194 // B.4. Des valeurs caracteres : le deuxieme bloc de la ligne peut etre encadre par des quotes :
1195 // il faut les supprimer
1196 else if ( ( mot_cle == "CCNoMNP1" ) or ( mot_cle == "CCMaiNP1" ) )
1198 ligne_bis >> argument ;
1199 if ( argument[0] == '"' ) { decalage = 1 ; }
1200 else { decalage = 0 ; }
1201 size_t size = argument.size() + 1 - 2*decalage ;
1203 if ( mot_cle == "CCNoMNP1" )
1205 MeshName = new char[ size ];
1206 strncpy( MeshName, argument.c_str()+decalage, size );
1207 MeshName[size-1] = '\0' ;
1209 else if ( mot_cle == "CCMaiNP1" )
1211 MeshFile = new char[ size ];
1212 strncpy( MeshFile, argument.c_str()+decalage, size );
1213 MeshFile[size-1] = '\0' ;
1217 MESSAGE ( "==> TypeConf : " << TypeConf ) ;
1218 MESSAGE ( "==> MeshName : " << MeshName ) ;
1219 MESSAGE ( "==> MeshFile : " << MeshFile ) ;
1220 MESSAGE ( "==> NumeIter : " << NumeIter ) ;
1221 MESSAGE ( "==> Pyram : " << Pyram ) ;
1225 SALOME::ExceptionStruct es;
1226 es.type = SALOME::BAD_PARAM;
1227 std::string text = "The configuration file cannot be read." ;
1228 es.text = CORBA::string_dup(text.c_str());
1229 throw SALOME::SALOME_Exception(es);
1232 // C. Creation effective du cas
1234 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, NumeIter, 2) ;
1236 // D. Parametrages lus dans le fichier de configuration
1238 myCase->SetConfType (TypeConf) ;
1239 myCase->SetPyram (Pyram) ;
1241 // E. Copie du fichier de maillage homard
1242 // E.1. Repertoire associe au cas
1243 char* nomDirCase = myCase->GetDirName() ;
1244 // E.2. Repertoire associe a l'iteration de ce cas
1246 IterName = myCase->GetIter0Name() ;
1247 HOMARD::HOMARD_Iteration_var Iter = GetIteration(IterName) ;
1248 char* nomDirIter = CreateDirNameIter(nomDirCase, 0 );
1249 Iter->SetDirNameLoc(nomDirIter);
1250 std::string nomDirIterTotal ;
1251 nomDirIterTotal = std::string(nomDirCase) + "/" + std::string(nomDirIter) ;
1252 if (mkdir(nomDirIterTotal.c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
1254 MESSAGE ( "nomDirIterTotal : " << nomDirIterTotal ) ;
1255 SALOME::ExceptionStruct es;
1256 es.type = SALOME::BAD_PARAM;
1257 std::string text = "The directory for the computation cannot be created." ;
1258 es.text = CORBA::string_dup(text.c_str());
1259 throw SALOME::SALOME_Exception(es);
1261 // E.3. Copie du maillage HOMARD au format MED
1262 codret = chdir(DirNameStart) ;
1263 std::string commande = "cp " + file_maillage_homard + " " + nomDirIterTotal ;
1264 MESSAGE ( "commande : " << commande ) ;
1265 codret = system(commande.c_str()) ;
1266 MESSAGE ( "codret : " << codret ) ;
1269 SALOME::ExceptionStruct es;
1270 es.type = SALOME::BAD_PARAM;
1271 es.text = "The starting point for the case cannot be copied into the working directory.";
1272 throw SALOME::SALOME_Exception(es);
1281 chdir(nomDirWork.c_str());
1283 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1285 //=============================================================================
1286 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseLastIteration(const char* nomCas, const char* DirNameStart)
1288 // nomCas : nom du cas a creer
1289 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1292 MESSAGE ( "CreateCaseFromCaseLastIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1294 std::string DirNameStartIter = CreateCase1(DirNameStart, -1) ;
1296 DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1297 HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1299 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1301 //=============================================================================
1302 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseIteration(const char* nomCas, const char* DirNameStart, CORBA::Long Number)
1304 // nomCas : nom du cas a creer
1305 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1306 // Number : numero de l'iteration de depart
1309 MESSAGE ( "CreateCaseFromCaseIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart << ", Number = " << Number );
1312 SALOME::ExceptionStruct es;
1313 es.type = SALOME::BAD_PARAM;
1314 es.text = "The number of iteration must be positive.";
1315 throw SALOME::SALOME_Exception(es);
1319 std::string DirNameStartIter = CreateCase1(DirNameStart, Number) ;
1321 DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1322 HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1324 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1326 //=============================================================================
1327 std::string HOMARD_Gen_i::CreateCase1(const char* DirNameStart, CORBA::Long Number)
1329 // Retourne le nom du repertoire ou se trouve l'iteration voulue.
1330 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1331 // Number : numero de l'iteration de depart ou -1 si on cherche la derniere
1334 MESSAGE ( "CreateCase1 : DirNameStart = " << DirNameStart << ", Number = " << Number );
1335 std::string nomDirWork = getenv("PWD") ;
1336 std::string DirNameStartIter ;
1338 int NumeIterMax = -1 ;
1340 // A.1. Controle du repertoire de depart du cas
1341 codret = chdir(DirNameStart) ;
1344 SALOME::ExceptionStruct es;
1345 es.type = SALOME::BAD_PARAM;
1346 es.text = "The directory of the case for the pursuit does not exist.";
1347 throw SALOME::SALOME_Exception(es);
1350 // A.2. Reperage des sous-repertoire du repertoire de reprise
1351 bool existe = false ;
1353 struct dirent *dirp;
1354 dp = opendir(DirNameStart);
1355 while ( (dirp = readdir(dp)) != NULL )
1357 std::string DirName_1(dirp->d_name);
1358 if ( ( DirName_1 != "." ) and ( DirName_1 != ".." ) )
1360 if ( chdir(DirName_1.c_str()) == 0 )
1362 // On cherche le fichier de configuration dans ce sous-repertoire
1363 codret = chdir(DirNameStart) ;
1365 struct dirent *dirp_1;
1366 dp_1 = opendir(DirName_1.c_str()) ;
1367 while ( (dirp_1 = readdir(dp_1)) != NULL )
1369 std::string file_name_1(dirp_1->d_name);
1370 int bilan = file_name_1.find("HOMARD.Configuration.") ;
1371 if ( bilan != string::npos )
1373 // Decodage du fichier pour trouver le numero d'iteration
1374 chdir(DirName_1.c_str()) ;
1375 std::ifstream fichier( file_name_1.c_str() );
1376 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1379 std::string ligne; // variable contenant chaque ligne lue
1380 std::string mot_cle;
1381 // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1382 while ( std::getline( fichier, ligne ) )
1384 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1385 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1386 ligne_bis >> mot_cle ;
1387 if ( mot_cle == "NumeIter" )
1389 ligne_bis >> NumeIter ;
1391 // MESSAGE ( "==> NumeIter : " << NumeIter ) ;
1392 if ( Number == - 1 )
1394 if ( NumeIter >= NumeIterMax )
1396 NumeIterMax = NumeIter ;
1397 DirNameStartIter = DirName_1 ;
1402 if ( NumeIter == Number )
1404 DirNameStartIter = DirName_1 ;
1414 SALOME::ExceptionStruct es;
1415 es.type = SALOME::BAD_PARAM;
1416 std::string text = "The configuration file cannot be read." ;
1417 es.text = CORBA::string_dup(text.c_str());
1418 throw SALOME::SALOME_Exception(es);
1420 chdir(DirNameStart) ;
1422 if ( existe ) { break ; }
1425 if ( existe ) { break ; }
1431 chdir(nomDirWork.c_str());
1433 if ( ( Number >= 0 and ( not existe ) ) or ( Number < 0 and ( NumeIterMax == -1 ) ) )
1435 SALOME::ExceptionStruct es;
1436 es.type = SALOME::BAD_PARAM;
1437 es.text = "The directory of the iteration does not exist.";
1438 throw SALOME::SALOME_Exception(es);
1442 return DirNameStartIter ;
1444 //=============================================================================
1445 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)
1447 // nomCas : nom du cas a creer
1448 // MeshName, MeshFile : nom et fichier du maillage correspondant
1449 // MeshOption : 0 : le maillage fourni est obligatoirement present ==> erreur si absent
1450 // 1 : le maillage fourni peut ne pas exister ==> on continue si absent
1451 // -1 : le maillage n'est pas fourni
1452 // NumeIter : numero de l'iteration correspondante : 0, pour un depart, n>0 pour une poursuite
1453 // Option : multiple de nombres premiers
1454 // 1 : aucune option
1455 // x2 : publication du maillage dans SMESH
1457 MESSAGE ( "CreateCase0 : nomCas = " << nomCas );
1458 MESSAGE ( "CreateCase0 : MeshName = " << MeshName << ", MeshFile = " << MeshFile << ", MeshOption = " << MeshOption );
1459 MESSAGE ( "CreateCase0 : NumeIter = " << NumeIter << ", Option = " << Option );
1465 // A.2. Controle du nom :
1466 if ((myContextMap[GetCurrentStudyID()]._mesCas).find(nomCas)!=(myContextMap[GetCurrentStudyID()]._mesCas).end())
1468 SALOME::ExceptionStruct es;
1469 es.type = SALOME::BAD_PARAM;
1470 es.text = "This case has already been defined.";
1471 throw SALOME::SALOME_Exception(es);
1475 // A.3. Controle du fichier du maillage
1476 int existeMeshFile ;
1477 if ( MeshOption >= 0 )
1479 existeMeshFile = MEDFileExist ( MeshFile ) ;
1480 MESSAGE ( "CreateCase0 : existeMeshFile = " << existeMeshFile );
1481 if ( ( existeMeshFile == 0 ) and ( MeshOption == 0 ) )
1483 SALOME::ExceptionStruct es;
1484 es.type = SALOME::BAD_PARAM;
1485 es.text = "The mesh file does not exist.";
1486 throw SALOME::SALOME_Exception(es);
1490 else { existeMeshFile = 0 ; }
1492 // B. Creation de l'objet cas et publication
1493 // MESSAGE ( "CreateCase0 : Creation de l'objet" );
1494 HOMARD::HOMARD_Cas_var myCase = newCase();
1495 myCase->SetName(nomCas);
1496 SALOMEDS::SObject_var aSO;
1497 PublishInStudy(myCurrentStudy, aSO, myCase, nomCas);
1498 myContextMap[GetCurrentStudyID()]._mesCas[nomCas] = myCase;
1500 // C. Caracteristiques du maillage
1501 if ( existeMeshFile != 0 )
1503 // Les valeurs extremes des coordonnees
1504 // MESSAGE ( "CreateCase0 : Les valeurs extremes des coordonnees" );
1505 std::vector<double> LesExtremes =GetBoundingBoxInMedFile(MeshFile) ;
1506 HOMARD::extrema_var aSeq = new HOMARD::extrema() ;
1507 if (LesExtremes.size()!=10) { return false; }
1509 for (int i =0 ; i< LesExtremes.size() ; i++)
1510 aSeq[i]=LesExtremes[i] ;
1511 myCase->SetBoundingBox(aSeq) ;
1513 // MESSAGE ( "CreateCase0 : Les groupes" );
1514 std::set<std::string> LesGroupes =GetListeGroupesInMedFile(MeshFile) ;
1515 HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType ;
1516 aSeqGroupe->length(LesGroupes.size());
1517 std::set<std::string>::const_iterator it ;
1519 for (it=LesGroupes.begin() ; it != LesGroupes.end() ; it++)
1520 aSeqGroupe[i++]=(*it).c_str() ;
1521 myCase->SetGroups(aSeqGroupe) ;
1524 // D. L'iteration initiale du cas
1525 MESSAGE ( "CreateCase0 : iteration initiale du cas" );
1526 // D.1. Recherche d'un nom : par defaut, on prend le nom du maillage correspondant.
1527 // Si ce nom d'iteration existe deja, on incremente avec 0, 1, 2, etc.
1529 std::string NomIteration = std::string(MeshName) ;
1530 while ( (myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration) != (myContextMap[GetCurrentStudyID()]._mesIterations.end()) )
1532 std::ostringstream nom;
1533 nom << MeshName << monNum;
1534 NomIteration = nom.str();
1537 MESSAGE ( "CreateCas0 : ==> NomIteration = " << NomIteration );
1539 // D.2. Creation de l'iteration
1540 HOMARD::HOMARD_Iteration_var anIter = newIteration();
1541 myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration] = anIter;
1542 anIter->SetName(NomIteration.c_str());
1543 AssociateCaseIter (nomCas, NomIteration.c_str(), "IterationHomard");
1545 // D.4. Maillage correspondant
1546 if ( existeMeshFile != 0 )
1548 anIter->SetMeshFile(MeshFile);
1549 if ( Option % 2 == 0 ) { PublishResultInSmesh(MeshFile, 0); }
1551 anIter->SetMeshName(MeshName);
1553 // D.5. Numero d'iteration
1554 anIter->SetNumber(NumeIter);
1557 SetEtatIter(NomIteration.c_str(), -NumeIter);
1560 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1562 //=============================================================================
1563 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::CreateHypothesis(const char* nomHypothesis)
1565 MESSAGE ( "CreateHypothesis : nomHypothesis = " << nomHypothesis );
1568 // Controle du nom :
1569 if ((myContextMap[GetCurrentStudyID()]._mesHypotheses).find(nomHypothesis) != (myContextMap[GetCurrentStudyID()]._mesHypotheses).end())
1571 SALOME::ExceptionStruct es;
1572 es.type = SALOME::BAD_PARAM;
1573 es.text = "This hypothesis has already been defined.";
1574 throw SALOME::SALOME_Exception(es);
1578 HOMARD::HOMARD_Hypothesis_var myHypothesis = newHypothesis();
1579 myHypothesis->SetName(nomHypothesis);
1580 myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis] = myHypothesis;
1581 SALOMEDS::SObject_var aSO;
1582 PublishInStudy(myCurrentStudy, aSO, myHypothesis, nomHypothesis);
1584 // Valeurs par defaut des options avancees
1585 myHypothesis->SetNivMax(-1);
1586 myHypothesis->SetDiamMin(-1.0);
1587 myHypothesis->SetAdapInit(0);
1588 myHypothesis->SetLevelOutput(0);
1590 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1593 //=============================================================================
1594 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::CreateIteration(const char* NomIteration, const char* nomIterParent)
1595 //=============================================================================
1597 MESSAGE ("CreateIteration : NomIteration = " << NomIteration << ", nomIterParent = " << nomIterParent);
1600 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterParent];
1601 if (CORBA::is_nil(myIterationParent))
1603 SALOME::ExceptionStruct es;
1604 es.type = SALOME::BAD_PARAM;
1605 es.text = "The parent iteration is not defined.";
1606 throw SALOME::SALOME_Exception(es);
1610 const char* nomCas = myIterationParent->GetCaseName();
1611 MESSAGE ("CreateIteration : nomCas = " << nomCas);
1612 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1613 if (CORBA::is_nil(myCase))
1615 SALOME::ExceptionStruct es;
1616 es.type = SALOME::BAD_PARAM;
1617 es.text = "Invalid case context";
1618 throw SALOME::SALOME_Exception(es);
1621 const char* nomDirCase = myCase->GetDirName();
1623 // Controle du nom :
1624 if ((myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration)!=(myContextMap[GetCurrentStudyID()]._mesIterations).end())
1626 SALOME::ExceptionStruct es;
1627 es.type = SALOME::BAD_PARAM;
1628 es.text = "This iteration has already been defined.";
1629 throw SALOME::SALOME_Exception(es);
1633 HOMARD::HOMARD_Iteration_var myIteration = newIteration();
1634 if (CORBA::is_nil(myIteration))
1636 SALOME::ExceptionStruct es;
1637 es.type = SALOME::BAD_PARAM;
1638 es.text = "Unable to create the iteration";
1639 throw SALOME::SALOME_Exception(es);
1642 myContextMap[GetCurrentStudyID()]._mesIterations[std::string(NomIteration)] = myIteration;
1643 // Nom de l'iteration et du maillage
1644 myIteration->SetName(NomIteration);
1645 myIteration->SetMeshName(NomIteration);
1646 myIteration->SetState(1);
1648 int numero = myIterationParent->GetNumber() + 1;
1649 myIteration->SetNumber(numero);
1651 // Nombre d'iterations deja connues pour le cas, permettant
1652 // la creation d'un sous-repertoire unique
1653 int nbitercase = myCase->GetNumberofIter();
1654 char* nomDirIter = CreateDirNameIter(nomDirCase, nbitercase );
1655 myIteration->SetDirNameLoc(nomDirIter);
1657 // Le nom du fichier du maillage MED est indice par le nombre d'iterations du cas.
1658 // Si on a une chaine unique depuis le depart, ce nombre est le meme que le
1659 // numero d'iteration dans la sucession : maill.01.med, maill.02.med, etc... C'est la
1660 // situation la plus frequente.
1661 // Si on a plusieurs branches, donc des iterations du meme niveau d'adaptation, utiliser
1662 // le nombre d'iterations du cas permet d'eviter les collisions.
1664 if ( nbitercase < 100 ) { jaux = 2 ; }
1665 else if ( nbitercase < 1000 ) { jaux = 3 ; }
1666 else if ( nbitercase < 10000 ) { jaux = 4 ; }
1667 else if ( nbitercase < 100000 ) { jaux = 5 ; }
1669 std::ostringstream iaux ;
1670 iaux << std::setw(jaux) << std::setfill('0') << nbitercase ;
1671 std::stringstream MeshFile;
1672 MeshFile << nomDirCase << "/maill." << iaux.str() << ".med";
1673 myIteration->SetMeshFile(MeshFile.str().c_str());
1675 // Association avec le cas
1676 std::string label = "IterationHomard_" + std::string(nomIterParent);
1677 AssociateCaseIter(nomCas, NomIteration, label.c_str());
1678 // Lien avec l'iteration precedente
1679 myIterationParent->LinkNextIteration(NomIteration);
1680 myIteration->SetIterParentName(nomIterParent);
1682 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1684 //=============================================================================
1685 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundary(const char* BoundaryName, CORBA::Long BoundaryType)
1687 MESSAGE ("CreateBoundary : BoundaryName = " << BoundaryName << ", BoundaryType = " << BoundaryType);
1690 // Controle du nom :
1691 if ((myContextMap[GetCurrentStudyID()]._mesBoundarys).find(BoundaryName)!=(myContextMap[GetCurrentStudyID()]._mesBoundarys).end())
1693 MESSAGE ("CreateBoundary : la frontiere " << BoundaryName << " existe deja");
1694 SALOME::ExceptionStruct es;
1695 es.type = SALOME::BAD_PARAM;
1696 es.text = "This boundary has already been defined";
1697 throw SALOME::SALOME_Exception(es);
1701 HOMARD::HOMARD_Boundary_var myBoundary = newBoundary();
1702 myBoundary->SetName(BoundaryName);
1703 myBoundary->SetType(BoundaryType);
1705 myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName] = myBoundary;
1707 SALOMEDS::SObject_var aSO;
1708 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myBoundary, BoundaryName);
1710 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1712 //=============================================================================
1713 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
1715 MESSAGE ("CreateBoundaryDi : BoundaryName = " << BoundaryName << "MeshName = " << MeshName );
1716 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
1717 myBoundary->SetMeshFile( MeshFile ) ;
1718 myBoundary->SetMeshName( MeshName ) ;
1720 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1722 //=============================================================================
1723 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCylinder(const char* BoundaryName,
1724 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1725 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1726 CORBA::Double Rayon)
1728 MESSAGE ("CreateBoundaryCylinder : BoundaryName = " << BoundaryName ) ;
1730 SALOME::ExceptionStruct es;
1733 { es.text = "The radius must be positive." ;
1735 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1736 if ( daux < 0.0000001 )
1737 { es.text = "The axis must be a non 0 vector." ;
1741 es.type = SALOME::BAD_PARAM;
1742 throw SALOME::SALOME_Exception(es);
1746 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 1) ;
1747 myBoundary->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon ) ;
1749 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1751 //=============================================================================
1752 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundarySphere(const char* BoundaryName,
1753 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1754 CORBA::Double Rayon)
1756 MESSAGE ("CreateBoundarySphere : BoundaryName = " << BoundaryName ) ;
1758 SALOME::ExceptionStruct es;
1761 { es.text = "The radius must be positive." ;
1765 es.type = SALOME::BAD_PARAM;
1766 throw SALOME::SALOME_Exception(es);
1770 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 2) ;
1771 myBoundary->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
1773 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1775 //=============================================================================
1776 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeA(const char* BoundaryName,
1777 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe, CORBA::Double Angle,
1778 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre)
1780 MESSAGE ("CreateBoundaryConeA : BoundaryName = " << BoundaryName ) ;
1782 SALOME::ExceptionStruct es;
1784 if ( Angle <= 0.0 or Angle >= 90.0 )
1785 { es.text = "The angle must be included higher than 0 degree and lower than 90 degrees." ;
1787 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1788 if ( daux < 0.0000001 )
1789 { es.text = "The axis must be a non 0 vector." ;
1793 es.type = SALOME::BAD_PARAM;
1794 throw SALOME::SALOME_Exception(es);
1798 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 3) ;
1799 myBoundary->SetConeA( Xaxe, Yaxe, Zaxe, Angle, Xcentre, Ycentre, Zcentre ) ;
1801 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1803 //=============================================================================
1804 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeR(const char* BoundaryName,
1805 CORBA::Double Xcentre1, CORBA::Double Ycentre1, CORBA::Double Zcentre1, CORBA::Double Rayon1,
1806 CORBA::Double Xcentre2, CORBA::Double Ycentre2, CORBA::Double Zcentre2, CORBA::Double Rayon2)
1808 MESSAGE ("CreateBoundaryConeR : BoundaryName = " << BoundaryName ) ;
1810 SALOME::ExceptionStruct es;
1812 if ( Rayon1 < 0.0 or Rayon2 < 0.0 )
1813 { es.text = "The radius must be positive." ;
1815 double daux = fabs(Rayon2-Rayon1) ;
1816 if ( daux < 0.0000001 )
1817 { es.text = "The radius must be different." ;
1819 daux = fabs(Xcentre2-Xcentre1) + fabs(Ycentre2-Ycentre1) + fabs(Zcentre2-Zcentre1) ;
1820 if ( daux < 0.0000001 )
1821 { es.text = "The centers must be different." ;
1825 es.type = SALOME::BAD_PARAM;
1826 throw SALOME::SALOME_Exception(es);
1830 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 4) ;
1831 myBoundary->SetConeR( Xcentre1, Ycentre1, Zcentre1, Rayon1, Xcentre2, Ycentre2, Zcentre2, Rayon2 ) ;
1833 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1835 //=============================================================================
1836 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZone(const char* ZoneName, CORBA::Long ZoneType)
1838 MESSAGE ("CreateZone : ZoneName = " << ZoneName << ", ZoneType = " << ZoneType);
1841 // Controle du nom :
1842 if ((myContextMap[GetCurrentStudyID()]._mesZones).find(ZoneName)!=(myContextMap[GetCurrentStudyID()]._mesZones).end())
1844 SALOME::ExceptionStruct es;
1845 es.type = SALOME::BAD_PARAM;
1846 es.text = "This zone has already been defined";
1847 throw SALOME::SALOME_Exception(es);
1851 HOMARD::HOMARD_Zone_var myZone = newZone();
1852 myZone->SetName(ZoneName);
1853 myZone->SetType(ZoneType);
1855 myContextMap[GetCurrentStudyID()]._mesZones[ZoneName] = myZone;
1857 SALOMEDS::SObject_var aSO;
1858 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myZone, ZoneName);
1860 return HOMARD::HOMARD_Zone::_duplicate(myZone);
1862 //=============================================================================
1863 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox(const char* ZoneName,
1864 CORBA::Double Xmini, CORBA::Double Xmaxi,
1865 CORBA::Double Ymini, CORBA::Double Ymaxi,
1866 CORBA::Double Zmini, CORBA::Double Zmaxi)
1868 MESSAGE ("CreateZoneBox : ZoneName = " << ZoneName ) ;
1870 SALOME::ExceptionStruct es;
1872 if ( Xmini > Xmaxi )
1873 { es.text = "The X coordinates are not coherent." ;
1875 if ( Ymini > Ymaxi )
1876 { es.text = "The Y coordinates are not coherent." ;
1878 if ( Zmini > Zmaxi )
1879 { es.text = "The Z coordinates are not coherent." ;
1883 es.type = SALOME::BAD_PARAM;
1884 throw SALOME::SALOME_Exception(es);
1888 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 2) ;
1889 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
1891 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1893 //=============================================================================
1894 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneSphere(const char* ZoneName,
1895 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre, CORBA::Double Rayon)
1897 MESSAGE ("CreateZoneSphere : ZoneName = " << ZoneName ) ;
1899 SALOME::ExceptionStruct es;
1902 { es.text = "The radius must be positive." ;
1906 es.type = SALOME::BAD_PARAM;
1907 throw SALOME::SALOME_Exception(es);
1911 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 4) ;
1912 myZone->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
1914 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1916 //=============================================================================
1917 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneCylinder(const char* ZoneName,
1918 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1919 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1920 CORBA::Double Rayon, CORBA::Double Haut)
1922 MESSAGE ("CreateZoneCylinder : ZoneName = " << ZoneName ) ;
1924 SALOME::ExceptionStruct es;
1927 { es.text = "The radius must be positive." ;
1929 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1930 if ( daux < 0.0000001 )
1931 { es.text = "The axis must be a non 0 vector." ;
1934 { es.text = "The height must be positive." ;
1938 es.type = SALOME::BAD_PARAM;
1939 throw SALOME::SALOME_Exception(es);
1943 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 5) ;
1944 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut ) ;
1946 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1948 //=============================================================================
1949 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZonePipe(const char* ZoneName,
1950 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1951 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1952 CORBA::Double Rayon, CORBA::Double Haut, CORBA::Double Rayonint)
1954 MESSAGE ("CreateZonePipe : ZoneName = " << ZoneName ) ;
1956 SALOME::ExceptionStruct es;
1958 if ( Rayon <= 0.0 or Rayonint <= 0.0 )
1959 { es.text = "The radius must be positive." ;
1961 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1962 if ( daux < 0.0000001 )
1963 { es.text = "The axis must be a non 0 vector." ;
1966 { es.text = "The height must be positive." ;
1968 if ( Rayon <= Rayonint )
1969 { es.text = "The external radius must be higher than the internal radius." ;
1973 es.type = SALOME::BAD_PARAM;
1974 throw SALOME::SALOME_Exception(es);
1978 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 7) ;
1979 myZone->SetPipe( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut, Rayonint ) ;
1981 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1983 //=============================================================================
1984 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox2D(const char* ZoneName,
1985 CORBA::Double Umini, CORBA::Double Umaxi,
1986 CORBA::Double Vmini, CORBA::Double Vmaxi,
1989 MESSAGE ("CreateZoneBox2D : ZoneName = " << ZoneName ) ;
1990 // MESSAGE ("Umini = " << Umini << ", Umaxi =" << Umaxi ) ;
1991 // MESSAGE ("Vmini = " << Vmini << ", Vmaxi =" << Vmaxi ) ;
1992 // MESSAGE ("Orient = " << Orient ) ;
1994 SALOME::ExceptionStruct es;
1996 if ( Umini > Umaxi )
1997 { es.text = "The first coordinates are not coherent." ;
1999 if ( Vmini > Vmaxi )
2000 { es.text = "The second coordinates are not coherent." ;
2002 if ( Orient < 1 or Orient > 3 )
2003 { es.text = "The orientation must be 1, 2 or 3." ;
2007 es.type = SALOME::BAD_PARAM;
2008 throw SALOME::SALOME_Exception(es);
2012 double Xmini, Xmaxi ;
2013 double Ymini, Ymaxi ;
2014 double Zmini, Zmaxi ;
2022 else if ( Orient == 2 )
2029 else if ( Orient == 3 )
2036 else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
2038 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 10+Orient) ;
2039 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2041 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2043 //=============================================================================
2044 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDisk(const char* ZoneName,
2045 CORBA::Double Ucentre, CORBA::Double Vcentre,
2046 CORBA::Double Rayon,
2049 MESSAGE ("CreateZoneDisk : ZoneName = " << ZoneName ) ;
2051 SALOME::ExceptionStruct es;
2054 { es.text = "The radius must be positive." ;
2056 if ( Orient < 1 or Orient > 3 )
2057 { es.text = "The orientation must be 1, 2 or 3." ;
2061 es.type = SALOME::BAD_PARAM;
2062 throw SALOME::SALOME_Exception(es);
2070 { Xcentre = Ucentre ;
2073 else if ( Orient == 2 )
2076 Zcentre = Vcentre ; }
2077 else if ( Orient == 3 )
2078 { Xcentre = Vcentre ;
2080 Zcentre = Ucentre ; }
2081 else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
2083 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 30+Orient) ;
2084 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1. ) ;
2086 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2088 //=============================================================================
2089 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDiskWithHole(const char* ZoneName,
2090 CORBA::Double Ucentre, CORBA::Double Vcentre,
2091 CORBA::Double Rayon, CORBA::Double Rayonint,
2094 MESSAGE ("CreateZoneDiskWithHole : ZoneName = " << ZoneName ) ;
2096 SALOME::ExceptionStruct es;
2098 if ( Rayon <= 0.0 or Rayonint <= 0.0 )
2099 { es.text = "The radius must be positive." ;
2101 if ( Orient < 1 or Orient > 3 )
2102 { es.text = "The orientation must be 1, 2 or 3." ;
2104 if ( Rayon <= Rayonint )
2105 { es.text = "The external radius must be higher than the internal radius." ;
2109 es.type = SALOME::BAD_PARAM;
2110 throw SALOME::SALOME_Exception(es);
2118 { Xcentre = Ucentre ;
2121 else if ( Orient == 2 )
2124 Zcentre = Vcentre ; }
2125 else if ( Orient == 3 )
2126 { Xcentre = Vcentre ;
2128 Zcentre = Ucentre ; }
2129 else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
2131 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 60+Orient) ;
2132 myZone->SetPipe( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1., Rayonint ) ;
2134 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2136 //=============================================================================
2137 //=============================================================================
2142 //=============================================================================
2143 //=============================================================================
2144 // Traitement d'une iteration
2145 // etatMenage = 1 : destruction du repertoire d'execution
2146 // modeHOMARD = 1 : adaptation
2147 // != 1 : information avec les options modeHOMARD
2148 // Option1 >0 : appel depuis python
2149 // <0 : appel depuis GUI
2150 // Option2 : multiple de nombres premiers
2151 // 1 : aucune option
2152 // x2 : publication du maillage dans SMESH
2153 //=============================================================================
2154 CORBA::Long HOMARD_Gen_i::Compute(const char* NomIteration, CORBA::Long etatMenage, CORBA::Long modeHOMARD, CORBA::Long Option1, CORBA::Long Option2)
2156 MESSAGE ( "Compute : traitement de " << NomIteration << ", avec modeHOMARD = " << modeHOMARD << ", avec Option1 = " << Option1 << ", avec Option2 = " << Option2 );
2161 // A.1. L'objet iteration
2162 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration];
2163 ASSERT(!CORBA::is_nil(myIteration));
2165 // A.2. Numero de l'iteration
2166 // siterp1 : numero de l'iteration a traiter
2168 // siter : numero de l'iteration parent, ou 0 si deja au debut mais cela ne servira pas !
2169 // Ou si information :
2171 int NumeIter = myIteration->GetNumber();
2172 std::string siterp1 ;
2173 std::stringstream saux1 ;
2175 siterp1 = saux1.str() ;
2176 if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
2179 if ( modeHOMARD==1 )
2181 std::stringstream saux0 ;
2182 int iaux = max(0, NumeIter-1) ;
2184 siter = saux0.str() ;
2185 if (NumeIter < 11) { siter = "0" + siter ; }
2188 { siter = siterp1 ; }
2191 const char* nomCas = myIteration->GetCaseName();
2192 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
2193 ASSERT(!CORBA::is_nil(myCase));
2195 // B. Les repertoires
2196 // B.1. Le repertoire courant
2197 std::string nomDirWork = getenv("PWD") ;
2198 // B.2. Le sous-repertoire de l'iteration a traiter
2199 char* DirCompute = ComputeDirManagement(myCase, myIteration, etatMenage);
2200 MESSAGE( ". DirCompute = " << DirCompute );
2202 // C. Le fichier des messages
2203 // C.1. Le deroulement de l'execution de HOMARD
2204 std::string LogFile = DirCompute ;
2205 LogFile += "/Liste" ;
2206 if ( modeHOMARD == 1 ) { LogFile += "." + siter + ".vers." + siterp1 ; }
2208 MESSAGE (". LogFile = " << LogFile);
2209 if ( modeHOMARD == 1 ) { myIteration->SetLogFile(LogFile.c_str()); }
2210 // C.2. Le bilan de l'analyse du maillage
2211 std::string FileInfo = DirCompute ;
2213 if ( modeHOMARD == 1 ) { FileInfo += "apad" ; }
2215 { if ( NumeIter == 0 ) { FileInfo += "info_av" ; }
2216 else { FileInfo += "info_ap" ; }
2218 FileInfo += "." + siterp1 + ".bilan" ;
2219 myIteration->SetFileInfo(FileInfo.c_str());
2221 // D. On passe dans le repertoire de l'iteration a calculer
2222 MESSAGE ( ". On passe dans DirCompute = " << DirCompute );
2225 // E. Les donnees de l'execution HOMARD
2226 // E.1. L'objet du texte du fichier de configuration
2227 HomardDriver* myDriver = new HomardDriver(siter, siterp1);
2228 std::string Langue = "Francais" ;
2229 myDriver->TexteInit(DirCompute, LogFile, Langue);
2231 // E.2. Le maillage associe a l'iteration
2232 const char* NomMesh = myIteration->GetMeshName();
2233 MESSAGE ( ". NomMesh = " << NomMesh );
2234 const char* MeshFile = myIteration->GetMeshFile();
2235 MESSAGE ( ". MeshFile = " << MeshFile );
2237 // E.3. Les donnees du traitement HOMARD
2239 if ( modeHOMARD == 1 )
2242 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2243 myDriver->TexteMaillage(NomMesh, MeshFile, 1);
2244 codret = ComputeAdap(myCase, myIteration, etatMenage, myDriver, Option1, Option2) ;
2248 InvalideIterInfo(NomIteration);
2249 myDriver->TexteInfo( modeHOMARD, NumeIter ) ;
2251 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2252 myDriver->TexteMaillage(NomMesh, MeshFile, 0);
2253 myDriver->CreeFichierDonn();
2256 // E.4. Ajout des informations liees a l'eventuel suivi de frontiere
2257 DriverTexteBoundary(myCase, myDriver) ;
2259 // E.5. Ecriture du texte dans le fichier
2261 { myDriver->CreeFichier(); }
2265 int codretexec = 12 ;
2268 codretexec = myDriver->ExecuteHomard(Option1);
2270 MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
2271 if ( modeHOMARD == 1 )
2273 if (codretexec == 0) { SetEtatIter(NomIteration,2); }
2274 else { SetEtatIter(NomIteration,1); }
2275 // GERALD -- QMESSAGE BOX
2279 // H. Gestion des resultats
2282 std::string Commentaire ;
2283 // H.1. Le fichier des messages, dans tous les cas
2284 Commentaire = "log" ;
2285 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2286 else { Commentaire += "Info" ; }
2287 PublishFileUnderIteration(NomIteration, LogFile.c_str(), Commentaire.c_str());
2289 // H.2. Si tout s'est bien passe :
2290 if (codretexec == 0)
2292 // H.2.1. Le fichier de bilan
2293 Commentaire = "Summary" ;
2294 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2295 else { Commentaire += "Info" ; }
2296 PublishFileUnderIteration(NomIteration, FileInfo.c_str(), Commentaire.c_str());
2297 // H.2.2. Le fichier de maillage obtenu
2298 if ( modeHOMARD == 1 )
2300 std::stringstream saux0 ;
2301 Commentaire = "Iteration" ;
2302 Commentaire += " " + siter ;
2303 PublishFileUnderIteration(NomIteration, MeshFile, Commentaire.c_str());
2304 if ( Option2 % 2 == 0 ) { PublishResultInSmesh(MeshFile, 1); }
2307 // H.3 Message d'erreur en cas de probleme
2310 SALOME::ExceptionStruct es;
2311 es.type = SALOME::BAD_PARAM;
2312 std::string text = "Error during the adaptation.\n" ;
2315 ifstream fichier(LogFile.c_str(), ios::in);
2317 while(getline(fichier, ligne) and (ligne != "===== HOMARD ===== STOP ====="));
2318 while (getline(fichier, ligne)) { text += ligne+ "\n";};
2321 text += "no log file ....";
2323 es.text = CORBA::string_dup(text.c_str());
2324 throw SALOME::SALOME_Exception(es);
2328 // I. Menage et retour dans le repertoire du cas
2332 MESSAGE ( ". On retourne dans nomDirWork = " << nomDirWork );
2333 chdir(nomDirWork.c_str());
2338 //=============================================================================
2339 // Calcul d'une iteration : partie specifique a l'adaptation
2340 //=============================================================================
2341 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)
2343 MESSAGE ( "ComputeAdap" );
2348 // Etat de l'iteration
2349 int etat = myIteration->GetState();
2350 // Numero de l'iteration
2351 int NumeIter = myIteration->GetNumber();
2352 std::stringstream saux0 ;
2353 saux0 << NumeIter-1 ;
2354 std::string siter = saux0.str() ;
2355 if (NumeIter < 11) { siter = "0" + siter ; }
2357 // A.2. On ne calcule pas l iteration initiale
2360 MESSAGE ( "etat = "<<etat );
2361 SALOME::ExceptionStruct es;
2362 es.type = SALOME::BAD_PARAM;
2363 es.text = "This iteration is the first of the case and cannot be computed.";
2364 throw SALOME::SALOME_Exception(es);
2368 // A.3. On verifie qu il y a une hypothese (erreur improbable);
2369 const char* nomHypo = myIteration->GetHypoName();
2370 if (std::string(nomHypo) == std::string(""))
2372 SALOME::ExceptionStruct es;
2373 es.type = SALOME::BAD_PARAM;
2374 es.text = "This iteration does not have any associated hypothesis.";
2375 throw SALOME::SALOME_Exception(es);
2378 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
2379 ASSERT(!CORBA::is_nil(myHypo));
2381 // B. L'iteration parent
2382 const char* nomIterationParent = myIteration->GetIterParentName();
2383 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
2384 ASSERT(!CORBA::is_nil(myIterationParent));
2385 // Si l'iteration parent n'est pas calculee, on le fait (recursivite amont)
2386 if ( myIterationParent->GetState() == 1 )
2389 int codret = Compute(nomIterationParent, etatMenage, iaux, Option1, Option2);
2392 // GERALD -- QMESSAGE BOX
2393 ASSERT("Pb au calcul de l'iteration precedente" == 0);
2397 // C. Le sous-repertoire de l'iteration precedente
2398 char* DirComputePa = ComputeDirPaManagement(myCase, myIteration);
2399 MESSAGE( ". DirComputePa = " << DirComputePa );
2401 // D. Les donnees de l'adaptation HOMARD
2402 // D.1. Le type de conformite
2403 int ConfType = myCase->GetConfType();
2404 MESSAGE ( ". ConfType = " << ConfType );
2406 // D.2. Le maillage de depart
2407 const char* NomMeshParent = myIterationParent->GetMeshName();
2408 MESSAGE ( ". NomMeshParent = " << NomMeshParent );
2409 const char* MeshFileParent = myIterationParent->GetMeshFile();
2410 MESSAGE ( ". MeshFileParent = " << MeshFileParent );
2412 // D.3. Le maillage associe a l'iteration
2413 const char* MeshFile = myIteration->GetMeshFile();
2414 MESSAGE ( ". MeshFile = " << MeshFile );
2415 FILE *file = fopen(MeshFile,"r");
2419 if (etatMenage == 0)
2421 SALOME::ExceptionStruct es;
2422 es.type = SALOME::BAD_PARAM;
2423 std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
2424 es.text = CORBA::string_dup(text.c_str());
2425 throw SALOME::SALOME_Exception(es);
2430 std::string commande = "rm -f " + std::string(MeshFile);
2431 codret = system(commande.c_str());
2434 SALOME::ExceptionStruct es;
2435 es.type = SALOME::BAD_PARAM;
2436 es.text = "The mesh file cannot be deleted.";
2437 throw SALOME::SALOME_Exception(es);
2443 // D.4. Les types de raffinement et de deraffinement
2444 // Les appels corba sont lourds, il vaut mieux les grouper
2445 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
2446 ASSERT(ListTypes->length() == 3);
2447 int TypeAdap = (*ListTypes)[0];
2448 int TypeRaff = (*ListTypes)[1];
2449 int TypeDera = (*ListTypes)[2];
2451 // E. Texte du fichier de configuration
2452 // E.1. Incontournables du texte
2453 myDriver->TexteAdap();
2455 myDriver->TexteMaillageHOMARD( DirComputePa, siter, iaux ) ;
2456 myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
2457 myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
2459 // E.2. Ajout des informations liees aux zones eventuelles
2460 if ( TypeAdap == 0 )
2461 { DriverTexteZone(myHypo, myDriver) ; }
2463 // E.3. Ajout des informations liees aux champs eventuels
2464 if ( TypeAdap == 1 )
2465 { DriverTexteField(myIteration, myHypo, myDriver) ; }
2467 // E.4. Ajout des informations liees au filtrage eventuel par les groupes
2468 HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
2469 int numberOfGroups = listeGroupes->length();
2470 MESSAGE( ". Filtrage par " << numberOfGroups << " groupes");
2471 if (numberOfGroups > 0)
2473 for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
2475 std::string GroupName = std::string((*listeGroupes)[NumGroup]);
2476 MESSAGE( "... GroupName = " << GroupName );
2477 myDriver->TexteGroup(GroupName);
2481 // E.5. Ajout des informations liees a l'eventuelle interpolation des champs
2482 DriverTexteFieldInterp(myIteration, myHypo, myDriver) ;
2484 // E.6. Ajout des options avancees
2485 int Pyram = myCase->GetPyram();
2486 MESSAGE ( ". Pyram = " << Pyram );
2487 int NivMax = myHypo->GetNivMax();
2488 MESSAGE ( ". NivMax = " << NivMax );
2489 double DiamMin = myHypo->GetDiamMin() ;
2490 MESSAGE ( ". DiamMin = " << DiamMin );
2491 int AdapInit = myHypo->GetAdapInit();
2492 MESSAGE ( ". AdapInit = " << AdapInit );
2493 int LevelOutput = myHypo->GetLevelOutput();
2494 MESSAGE ( ". LevelOutput = " << LevelOutput );
2495 myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, LevelOutput);
2497 // E.7. Ajout des informations sur le deroulement de l'execution
2498 int MessInfo = myIteration->GetInfoCompute();
2499 MESSAGE ( ". MessInfo = " << MessInfo );
2500 myDriver->TexteInfoCompute(MessInfo);
2504 //=============================================================================
2505 // Creation d'un nom de sous-repertoire pour l'iteration au sein d'un repertoire parent
2506 // nomrep : nom du repertoire parent
2507 // num : le nom du sous-repertoire est sous la forme 'In', n est >= num
2508 //=============================================================================
2509 char* HOMARD_Gen_i::CreateDirNameIter(const char* nomrep, CORBA::Long num )
2511 MESSAGE ( "CreateDirNameIter : nomrep ="<< nomrep << ", num = "<<num);
2512 // On verifie que le repertoire parent existe
2513 int codret = chdir(nomrep) ;
2516 SALOME::ExceptionStruct es;
2517 es.type = SALOME::BAD_PARAM;
2518 es.text = "The directory of the case does not exist.";
2519 throw SALOME::SALOME_Exception(es);
2522 std::string nomDirActuel = getenv("PWD") ;
2523 std::string DirName ;
2524 // On boucle sur tous les noms possibles jusqu'a trouver un nom correspondant a un repertoire inconnu
2525 bool a_chercher = true ;
2526 while ( a_chercher )
2528 // On passe dans le repertoire parent
2530 // On recherche un nom sous la forme Iabc, avec abc representant le numero
2532 if ( num < 100 ) { jaux = 2 ; }
2533 else if ( num < 1000 ) { jaux = 3 ; }
2534 else if ( num < 10000 ) { jaux = 4 ; }
2535 else if ( num < 100000 ) { jaux = 5 ; }
2537 std::ostringstream iaux ;
2538 iaux << std::setw(jaux) << std::setfill('0') << num ;
2539 std::ostringstream DirNameA ;
2540 DirNameA << "I" << iaux.str();
2541 // Si on ne pas peut entrer dans le repertoire, on doit verifier
2542 // que c'est bien un probleme d'absence
2543 if ( chdir(DirNameA.str().c_str()) != 0 )
2545 bool existe = false ;
2547 struct dirent *dirp;
2548 dp = opendir(nomrep);
2549 while ( (dirp = readdir(dp)) != NULL )
2551 std::string file_name(dirp->d_name);
2552 if ( file_name == DirNameA.str() ) { existe = true ; }
2557 DirName = DirNameA.str() ;
2558 a_chercher = false ;
2565 MESSAGE ( "==> DirName = " << DirName);
2566 MESSAGE ( ". On retourne dans nomDirActuel = " << nomDirActuel );
2567 chdir(nomDirActuel.c_str());
2569 return CORBA::string_dup( DirName.c_str() );
2571 //=============================================================================
2572 // Calcul d'une iteration : gestion du repertoire de calcul
2573 // Si le sous-repertoire existe :
2574 // etatMenage = 0 : on sort en erreur si le repertoire n'est pas vide
2575 // etatMenage = 1 : on fait le menage du repertoire
2576 // etatMenage = -1 : on ne fait rien
2577 //=============================================================================
2578 char* HOMARD_Gen_i::ComputeDirManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage)
2580 MESSAGE ( "ComputeDirManagement : repertoires pour le calcul" );
2581 // B.2. Le repertoire du cas
2582 const char* nomDirCase = myCase->GetDirName();
2583 MESSAGE ( ". nomDirCase = " << nomDirCase );
2585 // B.3. Le sous-repertoire de l'iteration a calculer, puis le repertoire complet a creer
2586 // B.3.1. Le nom du sous-repertoire
2587 const char* nomDirIt = myIteration->GetDirNameLoc();
2589 // B.3.2. Le nom complet du sous-repertoire
2590 std::stringstream DirCompute ;
2591 DirCompute << nomDirCase << "/" << nomDirIt;
2592 MESSAGE (". DirCompute = " << DirCompute.str() );
2594 // B.3.3. Si le sous-repertoire n'existe pas, on le cree
2595 if (chdir(DirCompute.str().c_str()) != 0)
2597 // Creation du repertoire car il n'existe pas :
2598 if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
2600 // GERALD -- QMESSAGE BOX
2601 std::cerr << "Pb Creation du repertoire DirCompute = " << DirCompute.str() << std::endl;
2602 ASSERT("Pb a la creation du repertoire" == 0);
2607 // Le repertoire existe
2608 // On demande de faire le menage de son contenu :
2609 if (etatMenage == 1)
2611 MESSAGE (". Menage du repertoire DirCompute = " << DirCompute.str());
2612 std::string commande= "rm -rf " + DirCompute.str()+"/*" ;
2613 int codret = system(commande.c_str());
2616 // GERALD -- QMESSAGE BOX
2617 std::cerr << ". Menage du repertoire de calcul" << DirCompute.str() << std::endl;
2618 ASSERT("Pb au menage du repertoire de calcul" == 0);
2621 // On n'a pas demande de faire le menage de son contenu : on sort en erreur :
2624 if (etatMenage == 0)
2627 struct dirent *dirp;
2628 dp = opendir(DirCompute.str().c_str());
2630 while ((dirp = readdir(dp)) != NULL && result )
2632 std::string file_name(dirp->d_name);
2633 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
2636 if ( result == false)
2638 SALOME::ExceptionStruct es;
2639 es.type = SALOME::BAD_PARAM;
2640 std::string text = "Directory : " + DirCompute.str() + "is not empty";
2641 es.text = CORBA::string_dup(text.c_str());
2642 throw SALOME::SALOME_Exception(es);
2643 ASSERT("Directory is not empty" == 0);
2649 return CORBA::string_dup( DirCompute.str().c_str() );
2651 //=============================================================================
2652 // Calcul d'une iteration : gestion du repertoire de calcul de l'iteration parent
2653 //=============================================================================
2654 char* HOMARD_Gen_i::ComputeDirPaManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration)
2656 MESSAGE ( "ComputeDirPaManagement : repertoires pour le calcul" );
2657 // Le repertoire du cas
2658 const char* nomDirCase = myCase->GetDirName();
2659 MESSAGE ( ". nomDirCase = " << nomDirCase );
2661 // Le sous-repertoire de l'iteration precedente
2663 const char* nomIterationParent = myIteration->GetIterParentName();
2664 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
2665 const char* nomDirItPa = myIterationParent->GetDirNameLoc();
2666 std::stringstream DirComputePa ;
2667 DirComputePa << nomDirCase << "/" << nomDirItPa;
2668 MESSAGE( ". nomDirItPa = " << nomDirItPa);
2669 MESSAGE( ". DirComputePa = " << DirComputePa.str() );
2671 return CORBA::string_dup( DirComputePa.str().c_str() );
2673 //=============================================================================
2674 // Calcul d'une iteration : ecriture des zones dans le fichier de configuration
2675 //=============================================================================
2676 void HOMARD_Gen_i::DriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
2678 MESSAGE ( "... DriverTexteZone" );
2679 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
2680 int numberOfZonesx2 = ListZone->length();
2683 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
2685 std::string ZoneName = std::string((*ListZone)[iaux]);
2686 MESSAGE ( "... ZoneName = " << ZoneName);
2687 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
2688 ASSERT(!CORBA::is_nil(myZone));
2690 int ZoneType = myZone->GetType();
2691 std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
2692 int TypeUse = atoi( TypeUsestr.c_str() );
2693 MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
2694 NumZone = iaux/2 + 1 ;
2695 HOMARD::double_array* zone = myZone->GetCoords();
2696 if ( ZoneType == 2 or ( ZoneType>=11 and ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
2697 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.); }
2698 else if ( ZoneType == 4 ) // Cas d une sphere
2699 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.); }
2700 else if ( ZoneType == 5 or ( ZoneType>=31 and ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
2701 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.); }
2702 else if ( ZoneType == 7 or ( ZoneType>=61 and ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
2703 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]); }
2704 else { ASSERT("ZoneType est incorrect." == 0) ; }
2709 //=============================================================================
2710 // Calcul d'une iteration : ecriture des champs dans le fichier de configuration
2711 //=============================================================================
2712 void HOMARD_Gen_i::DriverTexteField(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
2714 MESSAGE ( "... DriverTexteField" );
2715 // Le fichier du champ
2716 char* FieldFile = myIteration->GetFieldFile();
2717 MESSAGE ( ". FieldFile = " << FieldFile );
2718 if (strlen(FieldFile) == 0)
2720 // GERALD -- QMESSAGE BOX
2721 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
2722 ASSERT("The file for the field is not given." == 0);
2724 // Les caracteristiques d'instants
2725 int TimeStep = myIteration->GetTimeStep();
2726 MESSAGE( ". TimeStep = " << TimeStep );
2727 int Rank = myIteration->GetRank();
2728 MESSAGE( ". Rank = " << Rank );
2729 // Les informations sur les champs
2730 HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
2732 const char* FieldName = aInfosHypo->FieldName;
2734 int TypeThR = aInfosHypo->TypeThR;
2735 double ThreshR = aInfosHypo->ThreshR;
2736 int TypeThC = aInfosHypo->TypeThC;
2737 double ThreshC = aInfosHypo->ThreshC;
2738 // Saut entre mailles ou non ?
2739 int UsField = aInfosHypo->UsField;
2740 MESSAGE( ". UsField = " << UsField );
2741 // L'usage des composantes
2742 int UsCmpI = aInfosHypo->UsCmpI;
2743 MESSAGE( ". UsCmpI = " << UsCmpI );
2745 myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
2748 HOMARD::listeComposantsHypo* mescompo = myHypo->GetListComp();
2749 int numberOfCompos = mescompo->length();
2750 MESSAGE( ". numberOfCompos = " << numberOfCompos );
2751 for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
2753 std::string nomCompo = std::string((*mescompo)[NumeComp]);
2754 MESSAGE( "... nomCompo = " << nomCompo );
2755 myDriver->TexteCompo(NumeComp, nomCompo);
2759 //=============================================================================
2760 // Calcul d'une iteration : ecriture des frontieres dans le fichier de configuration
2761 //=============================================================================
2762 void HOMARD_Gen_i::DriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, HomardDriver* myDriver)
2764 MESSAGE ( "... DriverTexteBoundary" );
2765 // On ecrit d'abord la definition des frontieres, puis les liens avec les groupes
2766 std::list<std::string> ListeBoundaryTraitees ;
2767 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
2768 int numberOfitems = ListBoundaryGroupType->length();
2769 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
2770 int BoundaryOption = 1 ;
2771 int NumBoundaryAnalytical = 0 ;
2772 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
2774 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
2775 MESSAGE ( "... BoundaryName = " << BoundaryName);
2777 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
2778 while (it != ListeBoundaryTraitees.end())
2780 MESSAGE ( "... BoundaryNameTraitee = " << *it);
2781 if ( BoundaryName == *it ) { A_faire = 0 ; }
2786 // Caracteristiques de la frontiere
2787 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
2788 ASSERT(!CORBA::is_nil(myBoundary));
2789 int BoundaryType = myBoundary->GetType();
2790 MESSAGE ( "... BoundaryType = " << BoundaryType );
2791 // Ecriture selon le type
2792 if (BoundaryType == 0) // Cas d une frontiere discrete
2794 const char* MeshName = myBoundary->GetMeshName() ;
2795 const char* MeshFile = myBoundary->GetMeshFile() ;
2796 myDriver->TexteBoundaryDi( MeshName, MeshFile);
2797 BoundaryOption = BoundaryOption*2 ;
2799 else // Cas d une frontiere analytique
2801 NumBoundaryAnalytical++ ;
2802 HOMARD::double_array* coor = myBoundary->GetCoords();
2803 if (BoundaryType == 1) // Cas d un cylindre
2805 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
2806 BoundaryOption = BoundaryOption*3 ;
2808 else if (BoundaryType == 2) // Cas d une sphere
2810 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0., 0.);
2811 BoundaryOption = BoundaryOption*3 ;
2813 else if (BoundaryType == 3) // Cas d un cone defini par un axe et un angle
2815 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
2816 BoundaryOption = BoundaryOption*3 ;
2818 else if (BoundaryType == 4) // Cas d un cone defini par les 2 rayons
2820 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
2821 BoundaryOption = BoundaryOption*3 ;
2824 // Memorisation du traitement
2825 ListeBoundaryTraitees.push_back( BoundaryName );
2828 NumBoundaryAnalytical = 0 ;
2829 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
2831 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
2832 MESSAGE ( "... BoundaryName = " << BoundaryName);
2833 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
2834 ASSERT(!CORBA::is_nil(myBoundary));
2835 int BoundaryType = myBoundary->GetType();
2836 MESSAGE ( "... BoundaryType = " << BoundaryType );
2837 // Recuperation du nom du groupe
2838 std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
2839 MESSAGE ( "... GroupName = " << GroupName);
2840 if (BoundaryType == 0) // Cas d une frontiere discrete
2842 if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
2844 else // Cas d une frontiere analytique
2846 NumBoundaryAnalytical++ ;
2847 myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
2850 myDriver->TexteBoundaryOption(BoundaryOption);
2853 //=============================================================================
2854 // Calcul d'une iteration : ecriture des interpolations dans le fichier de configuration
2855 //=============================================================================
2856 void HOMARD_Gen_i::DriverTexteFieldInterp(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
2858 MESSAGE ( "... DriverTexteFieldInterp" );
2859 int TypeFieldInterp = myHypo->GetTypeFieldInterp();
2860 if (TypeFieldInterp != 0)
2862 // Le fichier des champs
2863 char* FieldFile = myIteration->GetFieldFile();
2864 MESSAGE ( ". FieldFile = " << FieldFile );
2865 if (strlen(FieldFile) == 0)
2867 // GERALD -- QMESSAGE BOX
2868 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
2869 ASSERT("The file for the field is not given." == 0);
2871 // Les caracteristiques d'instants
2872 int TimeStep = myIteration->GetTimeStep();
2873 MESSAGE( ". TimeStep = " << TimeStep );
2874 int Rank = myIteration->GetRank();
2875 MESSAGE( ". Rank = " << Rank );
2877 const char* MeshFile = myIteration->GetMeshFile();
2878 myDriver->TexteFieldInterp(TypeFieldInterp, FieldFile, MeshFile, TimeStep, Rank);
2880 if (TypeFieldInterp == 2)
2882 HOMARD::listFieldInterpHypo* meschamps = myHypo->GetListFieldInterp();
2883 int numberOfFields = meschamps->length();
2884 MESSAGE( ". numberOfFields = " << numberOfFields );
2885 for (int NumeChamp = 0; NumeChamp< numberOfFields; NumeChamp++)
2887 std::string nomChamp = std::string((*meschamps)[NumeChamp]);
2888 MESSAGE( "... nomChamp = " << nomChamp );
2889 myDriver->TexteFieldInterpName(NumeChamp, nomChamp);
2895 //===========================================================================
2896 //===========================================================================
2899 //===========================================================================
2900 //===========================================================================
2902 //===========================================================================
2903 //===========================================================================
2904 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
2905 SALOMEDS::SObject_ptr theSObject,
2906 CORBA::Object_ptr theObject,
2907 const char* theName)
2909 MESSAGE("PublishInStudy pour " << theName);
2910 SALOMEDS::SObject_var aResultSO;
2911 if (CORBA::is_nil(theStudy))
2913 SALOME::ExceptionStruct es;
2914 es.type = SALOME::BAD_PARAM;
2915 es.text = "Invalid study context";
2916 throw SALOME::SALOME_Exception(es);
2920 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
2921 // Rq : Iteration est publiee ailleurs
2922 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(theObject);
2923 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
2924 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
2925 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
2927 addInStudy(theStudy);
2929 // Controle de la non publication d'un objet de meme nom
2930 if ((!aHypo->_is_nil()) or (!aZone->_is_nil()) or (!aBoundary->_is_nil()))
2932 SALOMEDS::Study::ListOfSObject_var listSO = theStudy->FindObjectByName(theName, ComponentDataType());
2933 if (listSO->length() >= 1)
2935 MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
2936 std::cerr <<"This name "<<theName<<" is already used "<<listSO->length()<<" time(s)" << std::endl;
2937 aResultSO = listSO[0];
2938 return aResultSO._retn();
2942 // Caracteristiques de l'etude
2943 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
2944 aStudyBuilder->NewCommand();
2945 if(!aCase->_is_nil())
2946 aResultSO = PublishCaseInStudy(theStudy, aStudyBuilder, aCase, theName);
2947 else if(!aHypo->_is_nil())
2948 aResultSO = PublishHypotheseInStudy(theStudy, aStudyBuilder, aHypo, theName);
2949 else if(!aZone->_is_nil())
2950 aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName);
2951 else if(!aBoundary->_is_nil())
2952 aResultSO = PublishBoundaryInStudy(theStudy, aStudyBuilder, aBoundary, theName);
2954 aStudyBuilder->CommitCommand();
2955 return aResultSO._retn();
2957 //=============================================================================
2958 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::Study_ptr theStudy,
2959 SALOMEDS::StudyBuilder_var aStudyBuilder,
2960 HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
2962 MESSAGE("PublishCaseInStudy pour "<<theName);
2963 SALOMEDS::SObject_var aResultSO;
2964 SALOMEDS::GenericAttribute_var anAttr;
2966 if (CORBA::is_nil(theObject)) {
2967 MESSAGE("HOMARD_Gen_i::theObject->_is_nil()");
2968 return aResultSO._retn();
2970 if (theStudy->_is_nil()) {
2971 MESSAGE("HOMARD_Gen_i::theStudy->_is_nil()");
2972 return aResultSO._retn();
2975 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
2976 if (theFatherHomard->_is_nil())
2978 MESSAGE("theFatherHomard->_is_nil()");
2979 return aResultSO._retn();
2982 aResultSO = aStudyBuilder->NewObject(theFatherHomard);
2983 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
2984 _orb->object_to_string(theObject) ) ;
2985 return aResultSO._retn();
2988 //=============================================================================
2989 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::Study_ptr theStudy,
2990 SALOMEDS::StudyBuilder_var aStudyBuilder,
2991 HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
2993 MESSAGE("PublishZoneStudy pour "<<theName);
2994 SALOMEDS::SObject_var aResultSO;
2995 SALOMEDS::GenericAttribute_var anAttr;
2997 if (CORBA::is_nil(theObject))
2999 MESSAGE("PublishZoneInStudy : theObject->_is_nil()");
3000 return aResultSO._retn();
3002 if (theStudy->_is_nil())
3004 MESSAGE("PublishZoneInStudy : theStudy->_is_nil()");
3005 return aResultSO._retn();
3007 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3008 if (theFatherHomard->_is_nil())
3010 MESSAGE("PublishZoneInStudy : theFatherHomard->_is_nil()");
3011 return aResultSO._retn();
3014 // Caracteristique de la zone
3015 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[theName];
3016 CORBA::Long ZoneType = myZone->GetType();
3018 // On ajoute la categorie des zones dans l etude si necessaire
3019 SALOMEDS::SObject_var aSOZone;
3020 if (!theFatherHomard->FindSubObject(100, aSOZone))
3022 MESSAGE("Ajout de la categorie des zones");
3023 aSOZone = aStudyBuilder->NewObjectToTag(theFatherHomard, 100);
3024 PublishInStudyAttr(aStudyBuilder, aSOZone, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
3026 else { MESSAGE("La categorie des zones existe deja."); }
3028 aResultSO = aStudyBuilder->NewObject(aSOZone);
3037 { icone = "boxdxy_2.png" ;
3041 { icone = "boxdxyz_2.png" ;
3049 { icone = "disk_2.png" ;
3053 { icone = "spherepoint_2.png" ;
3057 { icone = "cylinderpointvector_2.png" ;
3065 { icone = "diskwithhole_2.png" ;
3069 { icone = "pipe_2.png" ;
3073 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone.c_str(), _orb->object_to_string(theObject) ) ;
3075 return aResultSO._retn();
3077 //=============================================================================
3078 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy(SALOMEDS::Study_ptr theStudy,
3079 SALOMEDS::StudyBuilder_var aStudyBuilder,
3080 HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
3082 MESSAGE("PublishBoundaryStudy pour "<<theName);
3083 SALOMEDS::SObject_var aResultSO;
3084 SALOMEDS::GenericAttribute_var anAttr;
3086 // Caracteristique de la Boundary
3087 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[theName];
3089 // On recupere le module pere dans l etude
3090 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3091 if (theFatherHomard->_is_nil())
3093 MESSAGE("theFatherHomard->_is_nil()");
3094 return aResultSO._retn();
3097 // On ajoute la categorie des boundarys dans l etude si necessaire
3098 SALOMEDS::SObject_var aSOBoundary;
3099 if (!theFatherHomard->FindSubObject(101, aSOBoundary))
3101 MESSAGE("Ajout de la categorie des boundarys");
3102 aSOBoundary = aStudyBuilder->NewObjectToTag(theFatherHomard, 101);
3103 PublishInStudyAttr(aStudyBuilder, aSOBoundary, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
3105 else { MESSAGE("La categorie des boundarys existe deja."); }
3107 aResultSO = aStudyBuilder->NewObject(aSOBoundary);
3108 CORBA::Long BoundaryType = myBoundary->GetType();
3109 // MESSAGE("BoundaryType : "<<BoundaryType);
3112 switch (BoundaryType)
3115 { value = "BoundaryDiHomard" ;
3116 icone = "mesh_tree_mesh.png" ;
3120 { value = "BoundaryAnHomard" ;
3121 icone = "cylinderpointvector_2.png" ;
3125 { value = "BoundaryAnHomard" ;
3126 icone = "spherepoint_2.png" ;
3130 { value = "BoundaryAnHomard" ;
3131 icone = "conepointvector.png" ;
3135 { value = "BoundaryAnHomard" ;
3136 icone = "conedxyz.png" ;
3140 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value.c_str(), icone.c_str(), _orb->object_to_string(theObject));
3141 return aResultSO._retn();
3144 //=============================================================================
3145 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::Study_ptr theStudy,
3146 SALOMEDS::StudyBuilder_var aStudyBuilder,
3147 HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
3149 MESSAGE("PublishHypotheseInStudy pour "<<theName);
3150 SALOMEDS::SObject_var aResultSO;
3151 SALOMEDS::GenericAttribute_var anAttr;
3153 // On recupere le module pere dans l etude
3154 // On ajoute la categorie des hypotheses dans l etude si necessaire
3155 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3156 if (theFatherHomard->_is_nil())
3158 MESSAGE("theFatherHomard->_is_nil()");
3159 return aResultSO._retn();
3161 SALOMEDS::SObject_var aSOHypothese;
3162 if (!theFatherHomard->FindSubObject(0, aSOHypothese))
3164 MESSAGE("Ajout de la categorie des hypotheses");
3165 aSOHypothese = aStudyBuilder->NewObjectToTag(theFatherHomard, 0);
3166 PublishInStudyAttr(aStudyBuilder, aSOHypothese, "Hypothesis", "HypoList","hypotheses.png", NULL);
3168 else { MESSAGE("La categorie des hypotheses existe deja."); }
3170 // Creation du resultat dans l'etude
3171 aResultSO = aStudyBuilder->NewObject(aSOHypothese);
3172 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
3174 return aResultSO._retn();
3176 //===========================================================================
3177 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
3178 SALOMEDS::SObject_var aResultSO,
3179 const char* name, const char* value, const char* icone, const char* ior)
3181 SALOMEDS::GenericAttribute_var anAttr ;
3185 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
3186 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
3187 aNameAttrib->SetValue(name);
3190 // Ajout du commentaire
3191 if ( value != NULL )
3193 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
3194 SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
3195 aCommentAttrib->SetValue(value);
3199 if ( icone != NULL )
3201 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO,"AttributePixMap");
3202 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
3203 aPixmap->SetPixMap(icone);
3209 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
3210 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3211 anIOR->SetValue(ior);
3215 //=====================================================================================
3216 void HOMARD_Gen_i::PublishBoundaryUnderCase(const char* CaseName, const char* BoundaryName)
3218 MESSAGE ( "PublishBoundaryUnderCase : CaseName = " << CaseName << ", BoundaryName= " << BoundaryName );
3220 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3221 ASSERT(!CORBA::is_nil(myCase));
3222 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3223 ASSERT(!CORBA::is_nil(aCaseSO));
3225 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3226 ASSERT(!CORBA::is_nil(myBoundary));
3227 SALOMEDS::SObject_var aBoundarySO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myBoundary)));
3228 ASSERT(!CORBA::is_nil(aBoundarySO));
3230 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3232 aStudyBuilder->NewCommand();
3234 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aCaseSO);
3235 aStudyBuilder->Addreference(aSubSO, aBoundarySO);
3237 aStudyBuilder->CommitCommand();
3240 //=============================================================================
3241 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long Option)
3242 // Option = 0 : fichier issu d'une importation
3243 // Option = 1 : fichier issu d'une execution HOMARD
3245 MESSAGE( "PublishResultInSmesh " << NomFich << ", avec Option = " << Option);
3246 if (CORBA::is_nil(myCurrentStudy))
3248 SALOME::ExceptionStruct es;
3249 es.type = SALOME::BAD_PARAM;
3250 es.text = "Invalid study context";
3251 throw SALOME::SALOME_Exception(es);
3255 // Le module SMESH est-il actif ?
3256 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3258 if (!CORBA::is_nil(aSmeshSO))
3260 // On verifie que le fichier n est pas deja publie
3261 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3262 for (; aIter->More(); aIter->Next())
3264 SALOMEDS::SObject_var aSO = aIter->Value();
3265 SALOMEDS::GenericAttribute_var aGAttr;
3266 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3268 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3269 CORBA::String_var value=anAttr->Value();
3270 if (strcmp((const char*)value,NomFich) == 0)
3272 MESSAGE ( "PublishResultInSmesh : le fichier " << NomFich << " est deja publie." );
3273 // Pour un fichier importe, on ne republie pas
3278 // Pour un fichier calcule, on commence par faire la depublication
3281 MESSAGE ( "PublishResultInSmesh : depublication" );
3282 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3283 CORBA::String_var value2=anAttr2->Value();
3284 std::string MeshName = string(value2) ;
3285 MESSAGE ( "PublishResultInSmesh : depublication de " << MeshName );
3286 DeleteResultInSmesh(NomFich, MeshName) ;
3293 // On enregistre le fichier
3294 MESSAGE( "Enregistrement du fichier");
3295 SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
3296 SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
3297 ASSERT(!CORBA::is_nil(aSmeshEngine));
3298 aSmeshEngine->SetCurrentStudy(myCurrentStudy);
3299 SMESH::DriverMED_ReadStatus theStatus;
3300 //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3302 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
3303 SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3304 for (int i = 0; i < mesMaillages->length(); i++)
3306 MESSAGE( ". Mise a jour des attributs du maillage");
3307 SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
3308 SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
3309 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3310 SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
3311 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3312 anAttr->SetValue(NomFich);
3313 SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
3314 SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
3316 if ( Option == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
3317 else { icone = "mesh_tree_mesh.png" ; }
3318 anAttr2->SetPixMap( icone );
3322 //=============================================================================
3323 void HOMARD_Gen_i::DeleteResultInSmesh(std::string NomFich, std::string MeshName)
3325 MESSAGE (" DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich );
3326 if (CORBA::is_nil(myCurrentStudy))
3328 SALOME::ExceptionStruct es;
3329 es.type = SALOME::BAD_PARAM;
3330 es.text = "Invalid study context";
3331 throw SALOME::SALOME_Exception(es);
3335 // Le module SMESH est-il actif ?
3336 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3338 if (CORBA::is_nil(aSmeshSO))
3342 // On verifie que le fichier est deja publie
3343 SALOMEDS::StudyBuilder_var myBuilder = myCurrentStudy->NewBuilder();
3344 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3345 for (; aIter->More(); aIter->Next())
3347 SALOMEDS::SObject_var aSO = aIter->Value();
3348 SALOMEDS::GenericAttribute_var aGAttr;
3349 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3351 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3352 CORBA::String_var value=anAttr->Value();
3353 if (strcmp((const char*)value,NomFich.c_str()) == 0)
3355 if (aSO->FindAttribute(aGAttr,"AttributeName"))
3357 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3358 CORBA::String_var value2=anAttr2->Value();
3359 if (strcmp((const char*)value2,MeshName.c_str()) == 0)
3361 myBuilder->RemoveObjectWithChildren( aSO ) ;
3369 //=============================================================================
3370 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
3372 // MESSAGE (" PublishFileUnderIteration pour l'iteration " << NomIter << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3373 if (CORBA::is_nil(myCurrentStudy))
3375 SALOME::ExceptionStruct es;
3376 es.type = SALOME::BAD_PARAM;
3377 es.text = "Invalid study context";
3378 throw SALOME::SALOME_Exception(es);
3382 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
3383 if (CORBA::is_nil(myIteration))
3385 SALOME::ExceptionStruct es;
3386 es.type = SALOME::BAD_PARAM;
3387 es.text = "Invalid iteration";
3388 throw SALOME::SALOME_Exception(es);
3391 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
3392 if (CORBA::is_nil(myIteration))
3394 SALOME::ExceptionStruct es;
3395 es.type = SALOME::BAD_PARAM;
3396 es.text = "Invalid iterationStudy Object";
3397 throw SALOME::SALOME_Exception(es);
3401 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3403 aStudyBuilder->NewCommand();
3405 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
3406 // Pour les fichiers med, on affiche une icone de maillage
3407 // Pour les fichiers qui sont texte, on affiche une icone de fichier texte 'texte'
3408 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
3410 std::string ior = " " ;
3411 if ( Commentaire[0] == 'I' )
3412 { icone = "med.png" ; }
3414 { icone = "texte_2.png" ; }
3415 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3417 aStudyBuilder->CommitCommand();
3420 //=============================================================================
3421 //=============================================================================
3423 //=============================================================================
3424 //=============================================================================
3425 //=============================================================================
3426 // Ecriture d'un schema YACS
3427 // nomCas : nom du cas a traiter
3428 // FileName : nom du fichier contenant le script de lancement du calcul
3429 // DirName : le repertoire de lancement des calculs du schéma
3430 //=============================================================================
3431 CORBA::Long HOMARD_Gen_i::WriteYACSSchema (const char* nomCas, const char* ScriptFile, const char* DirName, const char* MeshFile)
3433 MESSAGE ( "WriteYACSSchema : Schema YACS pour le cas " << nomCas);
3434 MESSAGE ( "ScriptFile : " << ScriptFile);
3435 MESSAGE ( "DirName : " << DirName);
3436 MESSAGE ( "MeshFile : " << MeshFile);
3442 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
3443 ASSERT(!CORBA::is_nil(myCase));
3444 // A.2. Le repertoire du cas
3445 std::string nomDirCase = myCase->GetDirName();
3446 MESSAGE ( ". nomDirCase = " << nomDirCase );
3447 // A.3. Les instructions python associees au cas
3448 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
3449 std::string pythonCas = dumpCorbaCase.in();
3450 MESSAGE ("pythonCas :\n"<<pythonCas<<"\n");
3452 // D. Les iterations
3453 // D.1. L'iteration initiale
3454 HOMARD::HOMARD_Iteration_var Iter0 = myCase->GetIter0() ;
3455 std::string Iter0Name = myCase->GetIter0Name() ;
3456 MESSAGE (". Iter0Name = " << Iter0Name);
3457 // D.2. L'iteration numero 1
3458 HOMARD::listeIterFilles* maListe = Iter0->GetIterations();
3459 int numberOfIter = maListe->length();
3460 if ( numberOfIter > 1 )
3462 MESSAGE (". numberOfIter = " << numberOfIter);
3463 SALOME::ExceptionStruct es ;
3464 es.type = SALOME::BAD_PARAM;
3465 std::string text = "Une seule iteration est permise." ;
3466 es.text = CORBA::string_dup(text.c_str());
3467 throw SALOME::SALOME_Exception(es);
3470 std::string Iter1Name = std::string((*maListe)[0]);
3471 MESSAGE ("... Iter1Name = " << Iter1Name);
3472 HOMARD::HOMARD_Iteration_var Iter1 = GetIteration(Iter1Name.c_str()) ;
3473 MESSAGE (". Iter1 = " << Iter1);
3476 // C.1. La structure
3477 std::string nomHypo = Iter1->GetHypoName();
3478 MESSAGE (". nomHypo = " << nomHypo);
3479 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
3480 ASSERT(!CORBA::is_nil(myHypo));
3481 // C.2. Les caracteristiques de l'adaptation
3482 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
3483 ASSERT(ListTypes->length() == 3);
3484 int TypeAdap = (*ListTypes)[0];
3485 // int TypeRaff = (*ListTypes)[1];
3486 // int TypeDera = (*ListTypes)[2];
3487 // C.3. Les instructions python associees a l'hypothese
3488 CORBA::String_var dumpCorbaHypo = myHypo->GetDumpPython();
3489 std::string pythonHypo = dumpCorbaHypo.in();
3490 MESSAGE ("pythonHypo :\n"<<pythonHypo<<"\n");
3492 // E. Les fichiers du schema
3493 // E.1. Le fichier du schema de reference
3494 // Le repertoire ou se trouve l'executable HOMARD
3495 std::string YACSFile_base ;
3496 if ( getenv("HOMARD_ROOT_DIR") != NULL ) { YACSFile_base = getenv("HOMARD_ROOT_DIR") ; }
3497 else { ASSERT("HOMARD_ROOT_DIR est inconnu." == 0) ; }
3498 YACSFile_base += "/share/salome/resources/homard/yacs_01.xml" ;
3499 MESSAGE("YACSFile_base ="<<YACSFile_base);
3500 // E.2. Le fichier du schema a creer
3501 std::string YACSFile = nomDirCase ;
3502 YACSFile += "/schema.xml" ;
3503 MESSAGE (". YACSFile = " << YACSFile);
3504 YACSDriver* myDriver = new YACSDriver(YACSFile, DirName);
3506 // F. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
3507 std::ifstream fichier( YACSFile_base.c_str() );
3508 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
3510 // F.1. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
3511 std::string ligne; // variable contenant chaque ligne lue
3512 std::string mot_cle;
3513 while ( std::getline( fichier, ligne ) )
3515 // F.1.1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
3516 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
3517 ligne_bis >> mot_cle ;
3518 // F.1.2. Le maillage initial
3519 if ( mot_cle == "DataInit_MeshFile" )
3521 myDriver->Texte_DataInit_MeshFile(MeshFile);
3523 // F.1.3. Le script de lancement
3524 else if ( mot_cle == "Alternance_Calcul_HOMARD_Calcul" )
3526 myDriver->Texte_Alternance_Calcul_HOMARD_Calcul(ScriptFile);
3528 // F.1.4. Les options du cas
3529 else if ( mot_cle == "HOMARD_Init_au_debut_Case_Options" )
3531 myDriver->Texte_HOMARD_Init_au_debut_Case_Options(pythonCas);
3533 // F.1.5. Execution de HOMARD : le repertoire du cas
3534 else if ( mot_cle == "HOMARD_Exec_DirName" )
3536 myDriver->Texte_HOMARD_Exec_DirName();
3538 // F.1.6. Execution de HOMARD : les options de l'hypothese
3539 else if ( mot_cle == "HOMARD_Exec_Hypo_Options" )
3541 myDriver->Texte_python( pythonHypo, 3, "Hypo" ) ;
3543 // F.1.7. Zones : les creations
3544 else if ( mot_cle == "HOMARD_Init_au_debut_Zone" )
3547 if ( TypeAdap == 0 )
3548 { YACSDriverTexteZone( myHypo, myDriver ) ; }
3551 saux = myDriver->Texte_HOMARD_Init_au_debut_control();
3552 myDriver->TexteAdd(saux);
3555 // F.1.8. Zones : les parametres
3556 else if ( mot_cle == "PARAMETRES" )
3558 if ( TypeAdap == 0 )
3559 { myDriver->TexteAddParametres(); }
3561 // F.1.n. La ligne est recopiee telle quelle
3564 myDriver->TexteAdd(ligne);
3567 // F.2. Ecriture du texte dans le fichier
3569 { myDriver->CreeFichier(); }
3573 SALOME::ExceptionStruct es;
3574 es.type = SALOME::BAD_PARAM;
3575 std::string text = "The reference file for the YACS schema cannot be read." ;
3576 es.text = CORBA::string_dup(text.c_str());
3577 throw SALOME::SALOME_Exception(es);
3584 //=============================================================================
3585 // Ecriture d'un schema YACS : ecriture des zones associees a une hypothese
3586 //=============================================================================
3587 void HOMARD_Gen_i::YACSDriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, YACSDriver* myDriver)
3589 MESSAGE ( "YACSDriverTexteZone" );
3590 // A. Les zones associees a cette hypothese
3591 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
3592 int numberOfZonesx2 = ListZone->length();
3594 // B. Initialisation du texte de controle
3595 std::string texte_control = myDriver->Texte_HOMARD_Init_au_debut_control() ;
3597 // C. Parcours des zones
3598 std::string noeud = "CreateHypothesis" ;
3599 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
3601 // 1. Reperage de la zone
3602 std::string ZoneName = std::string((*ListZone)[iaux]);
3603 MESSAGE ( "\n. ZoneName = " << ZoneName << " - " <<iaux);
3604 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
3605 ASSERT(!CORBA::is_nil(myZone));
3606 // 2. Les instructions python associees a la zone
3607 // La premiere ligne est un commentaire a eliminer
3608 // La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
3609 CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
3610 std::string pythonZone_0 = dumpCorbaZone.in();
3611 MESSAGE ("pythonZone_0 :"<<pythonZone_0);
3612 std::istringstream tout (pythonZone_0) ;
3614 std::string pythonZone ;
3615 while ( std::getline( tout, ligne ) )
3616 { pythonZone = GetStringInTexte ( ligne, ".", 1 ) ; }
3617 MESSAGE ("pythonZone :\n"<<pythonZone);
3618 // 3. Decodage du nom du service
3619 std::string methode = GetStringInTexte ( pythonZone, "(", 0 ) ;
3620 MESSAGE ( "... methode = " << methode);
3621 // 4. Mise en place des instructions
3622 int ZoneType = myZone->GetType();
3623 MESSAGE ( "... ZoneType = " << ZoneType);
3624 std::string texte_control_zone ;
3625 texte_control_zone = myDriver->Texte_HOMARD_Init_au_debut_Zone(ZoneType, pythonZone, methode, ZoneName, noeud );
3626 texte_control += texte_control_zone ;
3628 noeud = methode + "_" + ZoneName ;
3632 // D. Ajout du texte de controle
3633 MESSAGE ( "... texte_control =\n" << texte_control);
3634 myDriver->TexteAdd(texte_control) ;
3639 //=============================================================================
3640 //=============================================================================
3641 // Next functions are inherited from SALOMEDS::Driver interface
3642 //=============================================================================
3643 //=============================================================================
3644 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
3646 CORBA::Boolean isMultiFile)
3648 MESSAGE (" Save for theURL = "<< theURL);
3649 SALOMEDS::TMPFile_var aStreamFile;
3651 // get temporary directory name
3652 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
3654 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
3655 StudyContext& context = myContextMap[ aStudy->StudyId() ];
3657 // HOMARD data file name
3658 std::string aFileName = "";
3660 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
3661 aFileName += "_HOMARD.dat";
3663 // initialize sequence of file names
3664 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
3665 aFileSeq->length(1);
3666 aFileSeq[0] = CORBA::string_dup(aFileName.c_str()) ;
3668 // get full path to the data file
3669 aFileName = tmpDir + aFileName;
3673 std::ofstream f(aFileName.c_str());
3675 // clear temporary id map
3676 context._idmap.clear();
3681 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
3682 for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
3683 HOMARD::HOMARD_Cas_var aCas = it_case->second;
3684 PortableServer::ServantBase_var aServant = GetServant(aCas);
3685 HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
3687 f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
3688 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
3692 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
3693 for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
3694 HOMARD::HOMARD_Zone_var aZone = it_zone->second;
3695 PortableServer::ServantBase_var aServant = GetServant(aZone);
3696 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
3698 f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
3699 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
3702 // -> save hypotheses
3703 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
3704 for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
3705 HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
3706 PortableServer::ServantBase_var aServant = GetServant(aHypo);
3707 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
3709 f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
3710 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
3713 // -> save iterations
3714 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
3715 for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
3716 HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
3717 PortableServer::ServantBase_var aServant = GetServant(aIter);
3718 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
3720 f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
3721 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
3724 // -> save boundaries
3725 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
3726 for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
3727 HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
3728 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
3729 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
3730 if (aBoundaryServant) {
3731 f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
3732 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
3736 MESSAGE ("close file");
3739 // put temporary files to the stream
3740 MESSAGE ("put temporary files to the stream");
3741 aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq.in(), isMultiFile);
3743 // remove temporary files
3744 MESSAGE ("remove temporary files");
3745 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
3747 // return data stream
3748 MESSAGE ("return data stream");
3749 return aStreamFile._retn();
3752 //===========================================================================
3753 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
3755 CORBA::Boolean isMultiFile)
3757 // No specific ASCII persistence
3758 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
3759 return aStreamFile._retn();
3762 //===========================================================================
3763 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
3764 const SALOMEDS::TMPFile& theStream,
3766 CORBA::Boolean isMultiFile)
3768 MESSAGE (" Load pour theURL = "<< theURL);
3769 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
3771 // set current study
3772 if (myCurrentStudy->_is_nil() || aStudy->StudyId() != myCurrentStudy->StudyId())
3773 SetCurrentStudy(aStudy);
3775 // get temporary directory name
3776 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
3778 // Convert the stream into sequence of files to process
3779 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
3782 // HOMARD data file name
3783 std::string aFileName = "";
3785 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
3786 aFileName = tmpDir + aFileName + "_HOMARD.dat";
3788 StudyContext& context = myContextMap[ aStudy->StudyId() ];
3792 std::ifstream f(aFileName.c_str());
3795 context._mesCas.clear();
3796 context._mesHypotheses.clear();
3797 context._mesIterations.clear();
3798 context._mesZones.clear();
3799 context._mesBoundarys.clear();
3800 context._idmap.clear();
3806 std::getline(f, line);
3807 std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
3808 std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
3809 std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
3810 std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
3811 std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
3812 if (line.substr(0, caseSignature.size()) == caseSignature) {
3814 MESSAGE (" Recreation du cas" );
3815 HOMARD::HOMARD_Cas_var aCase = newCase();
3816 PortableServer::ServantBase_var aServant = GetServant(aCase);
3817 HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
3818 if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
3819 context._mesCas[aCase->GetName()] = aCase;
3820 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
3823 else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
3824 MESSAGE (" Recreation de la zone" );
3826 HOMARD::HOMARD_Zone_var aZone = newZone();
3827 PortableServer::ServantBase_var aServant = GetServant(aZone);
3828 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
3829 if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
3830 context._mesZones[aZone->GetName()] = aZone;
3831 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
3834 else if (line.substr(0, iterSignature.size()) == iterSignature) {
3835 // re-create iteration
3836 MESSAGE (" Recreation de l iteration" );
3837 HOMARD::HOMARD_Iteration_var aIter = newIteration();
3838 PortableServer::ServantBase_var aServant = GetServant(aIter);
3839 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
3840 if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
3841 context._mesIterations[aIter->GetName()] = aIter;
3842 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
3845 else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
3846 // re-create hypothesis
3847 MESSAGE (" Recreation de l hypothese" );
3848 HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
3849 PortableServer::ServantBase_var aServant = GetServant(aHypo);
3850 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
3851 if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
3852 context._mesHypotheses[aHypo->GetName()] = aHypo;
3853 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
3856 else if (line.substr(0, bounSignature.size()) == bounSignature) {
3857 // re-create boundary
3858 MESSAGE (" Recreation de la frontiere" );
3859 HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
3860 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
3861 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
3862 if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
3863 context._mesBoundarys[aBoundary->GetName()] = aBoundary;
3864 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
3873 // Remove temporary files created from the stream
3875 SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
3880 //===========================================================================
3881 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
3882 const SALOMEDS::TMPFile& theStream,
3884 CORBA::Boolean isMultiFile)
3886 // No specific ASCII persistence
3887 return Load(theComponent, theStream, theURL, isMultiFile);
3890 //===========================================================================
3891 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
3893 if (theComponent->GetStudy()->StudyId() == GetCurrentStudyID()) {
3894 // clearing study context should be done here:
3895 // - destroy all servants and related CORBA objects
3897 // - remove context from myContextMap
3898 myContextMap.erase(theComponent->GetStudy()->StudyId());
3899 // - nullify myCurrentStudy
3900 myCurrentStudy = SALOMEDS::Study::_nil();
3904 //===========================================================================
3905 char* HOMARD_Gen_i::ComponentDataType()
3907 return CORBA::string_dup("HOMARD");
3910 //===========================================================================
3911 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
3912 const char* IORString,
3913 CORBA::Boolean isMultiFile,
3914 CORBA::Boolean isASCII)
3916 CORBA::String_var aString("");
3917 if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
3918 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
3919 CORBA::Object_var anObj = _orb->string_to_object(IORString);
3920 if (!CORBA::is_nil(anObj)) {
3921 PortableServer::ServantBase_var aServant = GetServant(anObj);
3922 PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
3924 std::map<int, PortableServer::ServantBase*>::const_iterator it;
3925 for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
3926 if (it->second == aStorable) {
3927 std::stringstream os;
3929 aString = CORBA::string_dup(os.str().c_str());
3935 return aString._retn();
3938 //===========================================================================
3939 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
3940 const char* aLocalPersistentID,
3941 CORBA::Boolean isMultiFile,
3942 CORBA::Boolean isASCII)
3944 CORBA::String_var aString("");
3945 if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
3946 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
3947 int id = atoi(aLocalPersistentID);
3948 if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
3949 CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
3950 if (!CORBA::is_nil(object)) {
3951 aString = _orb->object_to_string(object);
3955 return aString._retn();
3958 //===========================================================================
3959 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
3961 if(CORBA::is_nil(myCurrentStudy))
3964 HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
3965 if(!aCas->_is_nil())
3968 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
3969 if(!aHypo->_is_nil())
3972 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
3973 if(!aZone->_is_nil())
3976 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
3977 if(!aBoundary->_is_nil())
3980 /* Iteration is not published directly
3981 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
3982 if(!aIter->_is_nil())
3988 //===========================================================================
3989 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
3991 // No Copy/Paste support
3995 //===========================================================================
3996 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
3997 CORBA::Long& theObjectID)
3999 // No Copy/Paste support
4000 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
4001 return aStreamFile._retn();
4004 //===========================================================================
4005 CORBA::Boolean HOMARD_Gen_i::CanPaste(const char *theComponentName,
4006 CORBA::Long theObjectID)
4008 // No Copy/Paste support
4012 //===========================================================================
4013 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
4014 CORBA::Long theObjectID,
4015 SALOMEDS::SObject_ptr theSObject)
4017 // No Copy/Paste support
4018 SALOMEDS::SObject_var aResultSO;
4019 return aResultSO._retn();
4022 //===========================================================================
4023 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
4025 PortableServer::Servant aServant = 0;
4026 if (!CORBA::is_nil(theObject)) {
4028 aServant = _poa->reference_to_servant(theObject);
4036 //==========================================================================
4037 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
4038 CORBA::Boolean isPublished,
4039 CORBA::Boolean isMultiFile,
4040 CORBA::Boolean& isValidScript)
4042 MESSAGE ("Entree dans DumpPython");
4044 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
4045 if(CORBA::is_nil(aStudy))
4046 return new Engines::TMPFile(0);
4048 SALOMEDS::SObject_var aSO = aStudy->FindComponent("HOMARD");
4049 if(CORBA::is_nil(aSO))
4050 return new Engines::TMPFile(0);
4052 std::string aScript = "\"\"\"\n";
4053 aScript += "Python script for HOMARD\n";
4054 aScript += "Copyright EDF-R&D 2013\n";
4055 aScript += "\"\"\"\n";
4056 aScript += "__revision__ = \"V1.2\"\n";
4057 aScript += "import HOMARD\n";
4059 aScript += "import salome\n";
4060 aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
4062 aScript += "def RebuildData(theStudy):\n";
4063 aScript += "\thomard.SetCurrentStudy(theStudy)\n";
4066 aScript += "\thomard.SetCurrentStudy(salome.myStudy)\n";
4067 MESSAGE (". Au depart \n"<<aScript);
4070 if (myContextMap[GetCurrentStudyID()]._mesBoundarys.size() > 0)
4072 MESSAGE (". Ecritures des frontieres");
4073 aScript += "#\n# Creation of the boundaries";
4074 aScript += "\n# ==========================";
4076 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4077 for (it_boundary = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
4078 it_boundary != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); ++it_boundary)
4080 HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
4081 CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
4082 std::string dumpBoundary = dumpCorbaBoundary.in();
4083 MESSAGE (dumpBoundary<<"\n");
4084 aScript += dumpBoundary;
4088 if (myContextMap[GetCurrentStudyID()]._mesZones.size() > 0)
4090 MESSAGE (". Ecritures des zones");
4091 aScript += "#\n# Creation of the zones";
4092 aScript += "\n# =====================";
4094 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4095 for ( it_zone = myContextMap[GetCurrentStudyID()]._mesZones.begin();
4096 it_zone != myContextMap[GetCurrentStudyID()]._mesZones.end(); ++it_zone)
4098 HOMARD::HOMARD_Zone_var maZone = (*it_zone).second;
4099 CORBA::String_var dumpCorbaZone = maZone->GetDumpPython();
4100 std::string dumpZone = dumpCorbaZone.in();
4101 MESSAGE (dumpZone<<"\n");
4102 aScript += dumpZone;
4106 if (myContextMap[GetCurrentStudyID()]._mesHypotheses.size() > 0)
4108 MESSAGE (". Ecritures des hypotheses");
4109 aScript += "#\n# Creation of the hypotheses";
4110 aScript += "\n# ==========================";
4112 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4113 for ( it_hypo = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
4114 it_hypo != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it_hypo++)
4116 HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
4117 CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
4118 std::string dumpHypo = dumpCorbaHypo.in();
4119 MESSAGE (dumpHypo<<"\n");
4120 aScript += dumpHypo;
4124 if (myContextMap[GetCurrentStudyID()]._mesCas.size() > 0)
4126 MESSAGE (". Ecritures des cas");
4127 aScript += "#\n# Creation of the cases";
4128 aScript += "\n# =====================";
4130 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
4131 for (it_cas = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4132 it_cas != myContextMap[GetCurrentStudyID()]._mesCas.end(); it_cas++)
4134 std::string nomCas = (*it_cas).first;
4135 std::string dumpCas = std::string("\n# Creation of the case ") ;
4136 dumpCas += nomCas + std::string("\n");
4137 dumpCas += std::string("\t") + nomCas;
4138 dumpCas += std::string(" = homard.CreateCase('") + nomCas + std::string("', '");
4140 HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
4141 CORBA::String_var cIter0= myCase->GetIter0Name();
4142 std::string iter0 = cIter0.in();
4144 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[iter0];
4145 CORBA::String_var cMesh0= myIteration->GetMeshFile();
4146 std::string mesh0 = cMesh0.in();
4147 CORBA::String_var cMeshName0= myIteration->GetMeshName();
4148 std::string meshName0 = cMeshName0.in();
4149 dumpCas += meshName0 + std::string("', '")+ mesh0 + std::string("')\n");
4150 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4151 std::string dumpCas2= dumpCorbaCase.in();
4153 MESSAGE (dumpCas<<dumpCas2<<"\n");
4154 aScript += dumpCas + dumpCas2;
4158 if (myContextMap[GetCurrentStudyID()]._mesIterations.size() > 0)
4160 MESSAGE (". Ecritures des iterations");
4161 aScript += "#\n# Creation of the iterations" ;
4162 aScript += "\n# ==========================";
4164 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4165 for (it_iter = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
4166 it_iter != myContextMap[GetCurrentStudyID()]._mesIterations.end(); ++it_iter)
4168 HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
4169 CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
4170 std::string dumpIter = dumpCorbaIter.in();
4171 MESSAGE (dumpIter<<"\n");
4172 aScript += dumpIter;
4175 MESSAGE (". Ecritures finales");
4177 aScript += "\n\tpass";
4180 if( !isMultiFile ) // remove unnecessary tabulation
4181 aScript = RemoveTabulation( aScript );
4183 // MESSAGE ("A ecrire \n"<<aScript);
4184 const size_t aLen = strlen(aScript.c_str());
4185 char* aBuffer = new char[aLen+1];
4186 strcpy(aBuffer, aScript.c_str());
4188 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
4189 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
4191 MESSAGE ("Sortie de DumpPython");
4192 return aStreamFile._retn();
4196 //=============================================================================
4197 //=============================================================================
4199 //=============================================================================
4200 //=============================================================================
4201 void HOMARD_Gen_i::IsValidStudy( )
4203 // MESSAGE( "IsValidStudy" );
4204 if (CORBA::is_nil(myCurrentStudy))
4206 SALOME::ExceptionStruct es;
4207 es.type = SALOME::BAD_PARAM;
4208 es.text = "Invalid study context";
4209 throw SALOME::SALOME_Exception(es);
4214 //=============================================================================
4215 CORBA::Boolean HOMARD_Gen_i::VerifieDir(const char* nomDir)
4217 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
4218 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4219 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
4221 if (std::string(nomDir) == std::string(it->second->GetDirName())) return false;
4225 /*//=============================================================================
4226 void SALOMEException( std::string message )
4228 SALOME::ExceptionStruct es;
4229 es.type = SALOME::BAD_PARAM;
4231 throw SALOME::SALOME_Exception(es);
4234 //=============================================================================
4235 char* HOMARD_Gen_i::getVersion()
4237 #if HOMARD_DEVELOPMENT
4238 return CORBA::string_dup(HOMARD_VERSION_STR"dev");
4240 return CORBA::string_dup(HOMARD_VERSION_STR);
4243 //===============================================================================
4244 // Recuperation de la chaine de caracteres par rapport l'apparition d'un texte
4245 // ligne : la ligne a manipuler
4246 // texte : le texte a reperer
4247 // option : 0 : la chaine avant le texte
4248 // 1 : la chaine apres le texte
4249 // Si le texte est absent, on retourne la chaine totale
4250 //===============================================================================
4251 std::string HOMARD_Gen_i::GetStringInTexte( const std::string ligne, const std::string texte, int option )
4253 // MESSAGE("GetStringInTexte, recherche de '"<<texte<<"' dans '"<<ligne<<"'"<<", option = "<<option);
4255 std::string chaine = ligne ;
4256 int position = ligne.find_first_of( texte ) ;
4259 if ( option == 0 ) { chaine = ligne.substr( 0, position ) ; }
4260 else { chaine = ligne.substr( position+1 ) ; }
4262 // Conversion de type
4267 //=============================================================================
4270 PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
4271 PortableServer::POA_ptr poa,
4272 PortableServer::ObjectId* contId,
4273 const char* instanceName,
4274 const char* interfaceName)
4276 MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
4277 HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
4278 return myHOMARD_Gen->getId();