1 // Copyright (C) 2011-2020 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, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "HOMARD_Gen_i.hxx"
21 #include "HOMARD_Cas_i.hxx"
22 #include "HOMARD_Hypothesis_i.hxx"
23 #include "HOMARD_Iteration_i.hxx"
24 #include "HOMARD_Boundary_i.hxx"
25 #include "HOMARD_Zone_i.hxx"
26 #include "HOMARD_YACS_i.hxx"
27 #include "HomardDriver.hxx"
28 #include "HOMARD_DriverTools.hxx"
29 #include "HomardMedCommun.h"
30 #include "YACSDriver.hxx"
33 #include "FrontTrack.hxx"
35 #include "HOMARD_version.h"
37 #include "utilities.h"
38 #include "Basics_Utils.hxx"
39 #include "Basics_DirUtils.hxx"
40 #include "Utils_SINGLETON.hxx"
41 #include "Utils_CorbaException.hxx"
42 #include "SALOMEDS_Tool.hxx"
43 #include "SALOME_LifeCycleCORBA.hxx"
44 #include "SALOMEconfig.h"
45 #include <SMESH_Gen_i.hxx>
46 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
47 #include CORBA_CLIENT_HEADER(SMESH_Gen)
70 //=============================================================================
72 //=============================================================================
73 std::string RemoveTabulation( std::string theScript )
75 std::string::size_type aPos = 0;
76 while( aPos < theScript.length() )
78 aPos = theScript.find( "\n\t", aPos );
79 if( aPos == std::string::npos )
81 theScript.replace( aPos, 2, "\n" );
86 //=============================================================================
88 * standard constructor
90 //=============================================================================
91 HOMARD_Gen_i::HOMARD_Gen_i( CORBA::ORB_ptr orb,
92 PortableServer::POA_ptr poa,
93 PortableServer::ObjectId * contId,
94 const char *instanceName,
95 const char *interfaceName) :
96 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
98 INFOS("constructor de HOMARD_Gen_i");
99 MESSAGE("constructor");
101 _id = _poa->activate_object(_thisObj);
103 myHomard = new ::HOMARD_Gen();
104 _NS = SINGLETON_<SALOME_NamingService>::Instance();
105 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
108 myStudy = SALOMEDS::Study::_duplicate( SMESH_Gen_i::getStudyServant() );
118 //=================================
120 * standard destructor
122 //================================
123 HOMARD_Gen_i::~HOMARD_Gen_i()
126 //=============================================================================
127 //=============================================================================
128 // Utilitaires pour l'étude
129 //=============================================================================
130 //=============================================================================
131 void HOMARD_Gen_i::UpdateStudy()
133 ASSERT(!CORBA::is_nil(myStudy));
134 SALOMEDS::StudyBuilder_var myBuilder = myStudy->NewBuilder();
136 // Create SComponent labelled 'homard' if it doesn't already exit
137 SALOMEDS::SComponent_var homardFather = myStudy->FindComponent(ComponentDataType());
138 if (CORBA::is_nil(homardFather))
140 myBuilder->NewCommand();
141 MESSAGE("Add Component HOMARD");
143 bool aLocked = myStudy->GetProperties()->IsLocked();
144 if (aLocked) myStudy->GetProperties()->SetLocked(false);
146 homardFather = myBuilder->NewComponent(ComponentDataType());
147 SALOMEDS::GenericAttribute_var anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributeName");
148 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
149 CORBA::Object_var objVarN = _NS->Resolve("/Kernel/ModulCatalog");
150 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
151 SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
152 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent(ComponentDataType());
153 if (!Comp->_is_nil())
155 aName->SetValue(ComponentDataType());
158 anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributePixMap");
159 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
160 aPixmap->SetPixMap("HOMARD_2.png");
161 myBuilder->DefineComponentInstance(homardFather, HOMARD_Gen::_this());
163 if (aLocked) myStudy->GetProperties()->SetLocked(true);
164 myBuilder->CommitCommand();
168 //=============================================================================
169 //=============================================================================
170 // Utilitaires pour l'iteration
171 //=============================================================================
172 //=============================================================================
173 void HOMARD_Gen_i::SetEtatIter(const char* nomIter, const CORBA::Long Etat)
174 //=====================================================================================
176 MESSAGE( "SetEtatIter : affectation de l'etat " << Etat << " a l'iteration " << nomIter );
177 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
178 if (CORBA::is_nil(myIteration))
180 SALOME::ExceptionStruct es;
181 es.type = SALOME::BAD_PARAM;
182 es.text = "Invalid iteration";
183 throw SALOME::SALOME_Exception(es);
187 myIteration->SetState(Etat);
189 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
190 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
194 icone = "iter0.png" ;
195 else if ( Etat == 2 )
196 icone = "iter_calculee.png" ;
198 icone = "iter_non_calculee.png" ;
199 PublishInStudyAttr(aStudyBuilder, aIterSO, NULL , NULL, icone.c_str(), NULL) ;
201 aStudyBuilder->CommitCommand();
204 //=============================================================================
205 //=============================================================================
207 //=============================================================================
208 //=============================================================================
209 // Destruction des structures identifiees par leurs noms
210 //=============================================================================
211 //=============================================================================
212 CORBA::Long HOMARD_Gen_i::DeleteBoundary(const char* BoundaryName)
214 MESSAGE ( "DeleteBoundary : BoundaryName = " << BoundaryName );
215 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
216 if (CORBA::is_nil(myBoundary))
218 SALOME::ExceptionStruct es;
219 es.type = SALOME::BAD_PARAM;
220 es.text = "Invalid boundary";
221 throw SALOME::SALOME_Exception(es);
225 // On verifie que la frontiere n'est plus utilisee
226 HOMARD::listeCases* maListe = GetAllCasesName();
227 int numberOfCases = maListe->length();
228 MESSAGE ( ".. Nombre de cas = " << numberOfCases );
229 std::string CaseName ;
230 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType ;
232 HOMARD::HOMARD_Cas_var myCase ;
233 for (int NumeCas = 0; NumeCas< numberOfCases; NumeCas++)
235 CaseName = std::string((*maListe)[NumeCas]);
236 MESSAGE ( "... Examen du cas = " << CaseName.c_str() );
237 myCase = myStudyContext._mesCas[CaseName];
238 ASSERT(!CORBA::is_nil(myCase));
239 ListBoundaryGroupType = myCase->GetBoundaryGroup();
240 numberOfitems = ListBoundaryGroupType->length();
241 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
242 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
244 if ( std::string((*ListBoundaryGroupType)[NumBoundary]) == BoundaryName )
246 SALOME::ExceptionStruct es;
247 es.type = SALOME::BAD_PARAM;
248 es.text = "This boundary is used in a case and cannot be deleted.";
249 throw SALOME::SALOME_Exception(es);
255 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
256 myStudyContext._mesBoundarys.erase(BoundaryName);
257 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(BoundaryName, ComponentDataType());
258 SALOMEDS::SObject_var aSO =listSO[0];
259 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
260 myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
264 //=============================================================================
265 CORBA::Long HOMARD_Gen_i::DeleteCase(const char* nomCas, CORBA::Long Option)
267 // Pour detruire un cas
268 MESSAGE ( "DeleteCase : nomCas = " << nomCas << ", avec option = " << Option );
269 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
270 if (CORBA::is_nil(myCase))
272 SALOME::ExceptionStruct es;
273 es.type = SALOME::BAD_PARAM;
274 es.text = "Invalid case context";
275 throw SALOME::SALOME_Exception(es);
278 // On commence par detruire toutes les iterations en partant de l'initiale et y compris elle
279 CORBA::String_var nomIter = myCase->GetIter0Name();
280 CORBA::Long Option1 = 0 ;
281 if ( DeleteIterationOption(nomIter, Option1, Option) != 0 )
286 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
287 myStudyContext._mesCas.erase(nomCas);
288 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(nomCas, ComponentDataType());
289 SALOMEDS::SObject_var aSO =listSO[0];
290 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
291 myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
295 //=============================================================================
296 CORBA::Long HOMARD_Gen_i::DeleteHypo(const char* nomHypo)
298 MESSAGE ( "DeleteHypo : nomHypo = " << nomHypo );
299 HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
300 if (CORBA::is_nil(myHypo))
302 SALOME::ExceptionStruct es;
303 es.type = SALOME::BAD_PARAM;
304 es.text = "Invalid hypothesis";
305 throw SALOME::SALOME_Exception(es);
309 // On verifie que l'hypothese n'est plus utilisee
310 HOMARD::listeIters* maListeIter = myHypo->GetIterations();
311 int numberOfIter = maListeIter->length();
312 if ( numberOfIter > 0 )
314 SALOME::ExceptionStruct es;
315 es.type = SALOME::BAD_PARAM;
316 es.text = "This hypothesis is used in an iteration and cannot be deleted.";
317 throw SALOME::SALOME_Exception(es);
321 // suppression du lien avec les zones eventuelles
322 HOMARD::listeZonesHypo* maListe = myHypo->GetZones();
323 int numberOfZones = maListe->length();
324 MESSAGE ( ".. Nombre de zones = " << numberOfZones );
325 for (int NumeZone = 0; NumeZone< numberOfZones; NumeZone++)
327 std::string ZoneName = std::string((*maListe)[NumeZone]);
328 MESSAGE ( ".. suppression du lien avec la zone = " << ZoneName.c_str() );
329 DissociateHypoZone(nomHypo, ZoneName.c_str()) ;
333 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
334 myStudyContext._mesHypotheses.erase(nomHypo);
335 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(nomHypo, ComponentDataType());
336 SALOMEDS::SObject_var aSO =listSO[0];
337 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
338 myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
342 //=============================================================================
343 CORBA::Long HOMARD_Gen_i::DeleteIteration(const char* nomIter, CORBA::Long Option)
345 // Option = 0 : On ne supprime pas le fichier du maillage associe
346 // Option = 1 : On supprime le fichier du maillage associe
347 // Pour detruire une iteration courante
348 MESSAGE ( "DeleteIteration : nomIter = " << nomIter << ", avec option = " << Option );
349 CORBA::Long Option1 = 1 ;
350 return DeleteIterationOption(nomIter, Option1, Option);
352 //=============================================================================
353 CORBA::Long HOMARD_Gen_i::DeleteIterationOption(const char* nomIter, CORBA::Long Option1, CORBA::Long Option2)
355 // Option1 = 0 : On autorise la destruction de l'iteration 0
356 // Option1 = 1 : On interdit la destruction de l'iteration 0
358 // Option2 = 0 : On ne supprime pas le fichier du maillage associe
359 // Option2 = 1 : On supprime le fichier du maillage associe
360 MESSAGE ( "DeleteIterationOption : nomIter = " << nomIter << ", avec options = " << Option1<< ", " << Option2 );
361 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
362 if (CORBA::is_nil(myIteration))
364 SALOME::ExceptionStruct es;
365 es.type = SALOME::BAD_PARAM;
366 es.text = "Invalid iteration";
367 throw SALOME::SALOME_Exception(es);
371 int numero = myIteration->GetNumber();
372 MESSAGE ( "DeleteIterationOption : numero = " << numero );
373 if ( numero == 0 && Option1 == 1 )
375 SALOME::ExceptionStruct es;
376 es.type = SALOME::BAD_PARAM;
377 es.text = "This iteration cannot be deleted.";
378 throw SALOME::SALOME_Exception(es);
382 // On detruit recursivement toutes les filles
383 HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
384 int numberOfIter = maListe->length();
385 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
387 std::string nomIterFille = std::string((*maListe)[NumeIter]);
388 MESSAGE ( ".. appel recursif de DeleteIterationOption pour nomIter = " << nomIterFille.c_str() );
389 DeleteIterationOption(nomIterFille.c_str(), Option1, Option2);
392 // On arrive ici pour une iteration sans fille
393 MESSAGE ( "Destruction effective de " << nomIter );
394 // On commence par invalider l'iteration pour faire le menage des dependances
395 // et eventuellement du maillage associe
397 if ( numero == 0 ) { option = 0 ; }
398 else { option = Option2 ; }
399 InvalideIterOption(nomIter, option) ;
401 // Retrait dans la descendance de l'iteration parent
404 std::string nomIterationParent = myIteration->GetIterParentName();
405 MESSAGE ( "Retrait dans la descendance de nomIterationParent " << nomIterationParent );
406 HOMARD::HOMARD_Iteration_var myIterationParent = myStudyContext._mesIterations[nomIterationParent];
407 if (CORBA::is_nil(myIterationParent))
409 SALOME::ExceptionStruct es;
410 es.type = SALOME::BAD_PARAM;
411 es.text = "Invalid iteration";
412 throw SALOME::SALOME_Exception(es);
415 myIterationParent->UnLinkNextIteration(nomIter);
418 // suppression du lien avec l'hypothese
421 std::string nomHypo = myIteration->GetHypoName();
422 HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
423 ASSERT(!CORBA::is_nil(myHypo));
424 myHypo->UnLinkIteration(nomIter);
427 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
428 myStudyContext._mesIterations.erase(nomIter);
429 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(nomIter, ComponentDataType());
430 SALOMEDS::SObject_var aSO =listSO[0];
431 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
432 myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
433 // on peut aussi faire RemoveObject
434 // MESSAGE ( "Au final" );
435 // HOMARD::listeIterations* Liste = GetAllIterationsName() ;
436 // numberOfIter = Liste->length();
437 // for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
439 // std::string nomIterFille = std::string((*Liste)[NumeIter]);
440 // MESSAGE ( ".. nomIter = " << nomIterFille.c_str() );
445 //=============================================================================
446 CORBA::Long HOMARD_Gen_i::DeleteYACS(const char* nomYACS, CORBA::Long Option)
448 // Option = 0 : On ne supprime pas le fichier du schema associe
449 // Option = 1 : On supprime le fichier du schema associe
450 MESSAGE ( "DeleteYACS : nomYACS = " << nomYACS << ", avec option = " << Option );
451 HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
452 if (CORBA::is_nil(myYACS))
454 SALOME::ExceptionStruct es;
455 es.type = SALOME::BAD_PARAM;
456 es.text = "Invalid schema YACS";
457 throw SALOME::SALOME_Exception(es);
460 // Suppression eventuelle du fichier XML
463 std::string nomFichier = myYACS->GetXMLFile();
464 std::string commande = "rm -rf " + nomFichier ;
465 MESSAGE ( "commande = " << commande );
466 if ((system(commande.c_str())) != 0)
468 SALOME::ExceptionStruct es;
469 es.type = SALOME::BAD_PARAM;
470 es.text = "The xml file for the schema YACS cannot be removed." ;
471 throw SALOME::SALOME_Exception(es);
475 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
476 myStudyContext._mesYACSs.erase(nomYACS);
477 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(nomYACS, ComponentDataType());
478 SALOMEDS::SObject_var aSO =listSO[0];
479 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
480 myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
484 //=============================================================================
485 CORBA::Long HOMARD_Gen_i::DeleteZone(const char* nomZone)
487 MESSAGE ( "DeleteZone : nomZone = " << nomZone );
488 HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[nomZone];
489 if (CORBA::is_nil(myZone))
491 SALOME::ExceptionStruct es;
492 es.type = SALOME::BAD_PARAM;
493 es.text = "Invalid zone";
494 throw SALOME::SALOME_Exception(es);
498 // On verifie que la zone n'est plus utilisee
499 HOMARD::listeHypo* maListe = myZone->GetHypo();
500 int numberOfHypo = maListe->length();
501 MESSAGE ( ".. Nombre d'hypotheses = " << numberOfHypo );
502 if ( numberOfHypo > 0 )
504 SALOME::ExceptionStruct es;
505 es.type = SALOME::BAD_PARAM;
506 es.text = "This zone is used in a hypothesis and cannot be deleted.";
507 throw SALOME::SALOME_Exception(es);
511 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
512 myStudyContext._mesZones.erase(nomZone);
513 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(nomZone, ComponentDataType());
514 SALOMEDS::SObject_var aSO =listSO[0];
515 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
516 myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
520 //=============================================================================
521 //=============================================================================
523 //=============================================================================
524 //=============================================================================
525 // Invalidation des structures identifiees par leurs noms
526 //=============================================================================
527 //=============================================================================
528 void HOMARD_Gen_i::InvalideBoundary(const char* BoundaryName)
530 MESSAGE( "InvalideBoundary : BoundaryName = " << BoundaryName );
531 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
532 if (CORBA::is_nil(myBoundary))
534 SALOME::ExceptionStruct es;
535 es.type = SALOME::BAD_PARAM;
536 es.text = "Invalid boundary";
537 throw SALOME::SALOME_Exception(es);
542 SALOME::ExceptionStruct es;
543 es.type = SALOME::BAD_PARAM;
544 es.text = "No change is allowed in a boundary. Ask for evolution.";
545 throw SALOME::SALOME_Exception(es);
549 //=============================================================================
550 void HOMARD_Gen_i::InvalideHypo(const char* nomHypo)
552 MESSAGE( "InvalideHypo : nomHypo = " << nomHypo );
553 HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
554 if (CORBA::is_nil(myHypo))
556 SALOME::ExceptionStruct es;
557 es.type = SALOME::BAD_PARAM;
558 es.text = "Invalid hypothesis";
559 throw SALOME::SALOME_Exception(es);
563 HOMARD::listeIters* maListe = myHypo->GetIterations();
564 int numberOfIter = maListe->length();
565 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
567 std::string nomIter = std::string((*maListe)[NumeIter]);
568 MESSAGE( ".. nomIter = " << nomIter );
569 InvalideIter(nomIter.c_str());
572 //=============================================================================
573 void HOMARD_Gen_i::InvalideIter(const char* nomIter)
575 MESSAGE("InvalideIter : nomIter = " << nomIter);
576 // Pour invalider totalement une iteration courante
577 CORBA::Long Option = 1 ;
578 return InvalideIterOption(nomIter, Option);
580 //=============================================================================
581 void HOMARD_Gen_i::InvalideIterOption(const char* nomIter, CORBA::Long Option)
583 // Option = 0 : On ne supprime pas le fichier du maillage associe
584 // Option = 1 : On supprime le fichier du maillage associe
585 MESSAGE ( "InvalideIterOption : nomIter = " << nomIter << ", avec option = " << Option );
586 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
587 if (CORBA::is_nil(myIteration))
589 SALOME::ExceptionStruct es;
590 es.type = SALOME::BAD_PARAM;
591 es.text = "Invalid iteration";
592 throw SALOME::SALOME_Exception(es);
596 HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
597 int numberOfIter = maListe->length();
598 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
600 std::string nomIterFille = std::string((*maListe)[NumeIter]);
601 MESSAGE ( ".. appel recursif de InvalideIter pour nomIter = " << nomIterFille.c_str() );
602 InvalideIter(nomIterFille.c_str());
605 // On arrive ici pour une iteration sans fille
606 MESSAGE ( "Invalidation effective de " << nomIter );
607 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
608 SALOMEDS::ChildIterator_var aIter = myStudy->NewChildIterator(aIterSO);
609 for (; aIter->More(); aIter->Next())
611 SALOMEDS::SObject_var so = aIter->Value();
612 SALOMEDS::GenericAttribute_var anAttr;
613 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
614 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
615 std::string value (aCommentAttr->Value());
616 if(value == std::string("IterationHomard")) continue;
617 if(value == std::string("HypoHomard")) continue;
618 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
619 aStudyBuilder->RemoveObject(so);
622 int etat = myIteration->GetState();
625 SetEtatIter(nomIter,1);
626 const char * nomCas = myIteration->GetCaseName();
627 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
628 if (CORBA::is_nil(myCase))
630 SALOME::ExceptionStruct es;
631 es.type = SALOME::BAD_PARAM;
632 es.text = "Invalid case context";
633 throw SALOME::SALOME_Exception(es);
636 std::string nomDir = myIteration->GetDirName();
637 std::string nomFichier = myIteration->GetMeshFile();
638 std::string commande = "rm -rf " + std::string(nomDir);
639 if ( Option == 1 ) { commande = commande + ";rm -rf " + std::string(nomFichier) ; }
640 MESSAGE ( "commande = " << commande );
641 if ((system(commande.c_str())) != 0)
643 SALOME::ExceptionStruct es;
644 es.type = SALOME::BAD_PARAM;
645 es.text = "The directory for the calculation cannot be cleared." ;
646 throw SALOME::SALOME_Exception(es);
649 // Suppression du maillage publie dans SMESH
650 std::string MeshName = myIteration->GetMeshName() ;
651 DeleteResultInSmesh(nomFichier, MeshName) ;
655 //=============================================================================
656 void HOMARD_Gen_i::InvalideIterInfo(const char* nomIter)
658 MESSAGE("InvalideIterInfo : nomIter = " << nomIter);
659 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
660 if (CORBA::is_nil(myIteration))
662 SALOME::ExceptionStruct es;
663 es.type = SALOME::BAD_PARAM;
664 es.text = "Invalid iteration";
665 throw SALOME::SALOME_Exception(es);
669 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
670 SALOMEDS::ChildIterator_var aIter = myStudy->NewChildIterator(aIterSO);
671 for (; aIter->More(); aIter->Next())
673 SALOMEDS::SObject_var so = aIter->Value();
674 SALOMEDS::GenericAttribute_var anAttr;
675 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
676 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
677 std::string value (aCommentAttr->Value());
678 /* MESSAGE("... value = " << value);*/
679 if( (value == std::string("logInfo")) || ( value == std::string("SummaryInfo")) )
681 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
682 aStudyBuilder->RemoveObject(so);
686 const char * nomCas = myIteration->GetCaseName();
687 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
688 if (CORBA::is_nil(myCase))
690 SALOME::ExceptionStruct es;
691 es.type = SALOME::BAD_PARAM;
692 es.text = "Invalid case context";
693 throw SALOME::SALOME_Exception(es);
696 const char* nomDir = myIteration->GetDirName();
697 std::string commande = "rm -f " + std::string(nomDir) + "/info* " ;
698 commande += std::string(nomDir) + "/Liste.*info" ;
699 /* MESSAGE ( "commande = " << commande );*/
700 if ((system(commande.c_str())) != 0)
702 SALOME::ExceptionStruct es;
703 es.type = SALOME::BAD_PARAM;
704 es.text = "The directory for the calculation cannot be cleared." ;
705 throw SALOME::SALOME_Exception(es);
709 //=============================================================================
710 void HOMARD_Gen_i::InvalideYACS(const char* YACSName)
712 MESSAGE( "InvalideYACS : YACSName = " << YACSName );
713 HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[YACSName];
714 if (CORBA::is_nil(myYACS))
716 SALOME::ExceptionStruct es;
717 es.type = SALOME::BAD_PARAM;
718 es.text = "Invalid schema YACS";
719 throw SALOME::SALOME_Exception(es);
723 SALOMEDS::SObject_var aYACSSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
724 SALOMEDS::ChildIterator_var aYACS = myStudy->NewChildIterator(aYACSSO);
725 for (; aYACS->More(); aYACS->Next())
727 SALOMEDS::SObject_var so = aYACS->Value();
728 SALOMEDS::GenericAttribute_var anAttr;
729 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
730 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
731 std::string value (aCommentAttr->Value());
732 if( value == std::string("xml") )
734 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
735 aStudyBuilder->RemoveObject(so);
738 std::string nomFichier = myYACS->GetXMLFile();
739 std::string commande = "rm -rf " + std::string(nomFichier) ;
740 MESSAGE ( "commande = " << commande );
741 if ((system(commande.c_str())) != 0)
743 SALOME::ExceptionStruct es;
744 es.type = SALOME::BAD_PARAM;
745 es.text = "The XML file for the schema YACS cannot be removed." ;
746 throw SALOME::SALOME_Exception(es);
750 //=============================================================================
751 void HOMARD_Gen_i::InvalideZone(const char* ZoneName)
753 MESSAGE( "InvalideZone : ZoneName = " << ZoneName );
754 HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
755 if (CORBA::is_nil(myZone))
757 SALOME::ExceptionStruct es;
758 es.type = SALOME::BAD_PARAM;
759 es.text = "Invalid zone";
760 throw SALOME::SALOME_Exception(es);
763 HOMARD::listeHypo* maListe = myZone->GetHypo();
764 int numberOfHypo = maListe->length();
765 MESSAGE( ".. numberOfHypo = " << numberOfHypo );
766 for (int NumeHypo = 0; NumeHypo< numberOfHypo; NumeHypo++)
768 std::string nomHypo = std::string((*maListe)[NumeHypo]);
769 MESSAGE( ".. nomHypo = " << nomHypo );
770 InvalideHypo(nomHypo.c_str());
773 //=============================================================================
774 //=============================================================================
776 //=============================================================================
777 //=============================================================================
778 // Association de lien entre des structures identifiees par leurs noms
779 //=============================================================================
780 //=============================================================================
781 void HOMARD_Gen_i::AssociateCaseIter(const char* nomCas, const char* nomIter, const char* labelIter)
783 MESSAGE( "AssociateCaseIter : " << nomCas << ", " << nomIter << ", " << labelIter );
785 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
786 if (CORBA::is_nil(myCase))
788 SALOME::ExceptionStruct es;
789 es.type = SALOME::BAD_PARAM;
790 es.text = "Invalid case";
791 throw SALOME::SALOME_Exception(es);
795 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
796 if (CORBA::is_nil(myIteration))
798 SALOME::ExceptionStruct es;
799 es.type = SALOME::BAD_PARAM;
800 es.text = "Invalid iteration";
801 throw SALOME::SALOME_Exception(es);
805 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
806 SALOMEDS::SObject_var aCasSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myCase)));
807 if (CORBA::is_nil(aCasSO))
809 SALOME::ExceptionStruct es;
810 es.type = SALOME::BAD_PARAM;
811 es.text = "Invalid case";
812 throw SALOME::SALOME_Exception(es);
816 aStudyBuilder->NewCommand();
817 SALOMEDS::SObject_var newStudyIter = aStudyBuilder->NewObject(aCasSO);
818 PublishInStudyAttr(aStudyBuilder, newStudyIter, nomIter , labelIter,
819 "iter_non_calculee.png", _orb->object_to_string(myIteration)) ;
820 aStudyBuilder->CommitCommand();
822 myCase->AddIteration(nomIter);
823 myIteration->SetCaseName(nomCas);
825 //=====================================================================================
826 void HOMARD_Gen_i::AssociateHypoZone(const char* nomHypothesis, const char* ZoneName, CORBA::Long TypeUse)
828 MESSAGE ( "AssociateHypoZone : nomHypo = " << nomHypothesis << ", ZoneName= " << ZoneName << ", TypeUse = " << TypeUse);
830 HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypothesis];
831 ASSERT(!CORBA::is_nil(myHypo));
832 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
833 ASSERT(!CORBA::is_nil(aHypoSO));
835 HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
836 ASSERT(!CORBA::is_nil(myZone));
837 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myZone)));
838 ASSERT(!CORBA::is_nil(aZoneSO));
840 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
842 aStudyBuilder->NewCommand();
844 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aHypoSO);
845 aStudyBuilder->Addreference(aSubSO, aZoneSO);
847 aStudyBuilder->CommitCommand();
849 myZone->AddHypo(nomHypothesis);
850 myHypo->AddZone0(ZoneName, TypeUse);
852 //=============================================================================
853 void HOMARD_Gen_i::AssociateIterHypo(const char* nomIter, const char* nomHypo)
855 MESSAGE("AssociateIterHypo : nomHypo = " << nomHypo << " nomIter = " << nomIter);
857 // Verification de l'existence de l'hypothese
858 HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
859 ASSERT(!CORBA::is_nil(myHypo));
860 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
861 ASSERT(!CORBA::is_nil(aHypoSO));
863 // Verification de l'existence de l'iteration
864 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
865 ASSERT(!CORBA::is_nil(myIteration));
866 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
867 ASSERT(!CORBA::is_nil(aIterSO));
869 // Gestion de l'arbre d'etudes
870 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
871 aStudyBuilder->NewCommand();
872 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
873 aStudyBuilder->Addreference(aSubSO, aHypoSO);
874 aStudyBuilder->CommitCommand();
877 myIteration->SetHypoName(nomHypo);
878 myHypo->LinkIteration(nomIter);
880 // On stocke les noms des champ a interpoler pour le futur controle de la donnée des pas de temps
881 myIteration->SupprFieldInterps() ;
882 HOMARD::listeFieldInterpsHypo* ListField = myHypo->GetFieldInterps();
883 int numberOfFieldsx2 = ListField->length();
884 for (int iaux = 0; iaux< numberOfFieldsx2; iaux++)
886 std::string FieldName = std::string((*ListField)[iaux]) ;
887 myIteration->SetFieldInterp(FieldName.c_str()) ;
891 //=============================================================================
892 //=============================================================================
894 //=============================================================================
895 //=============================================================================
896 // Dissociation de lien entre des structures identifiees par leurs noms
897 //=============================================================================
898 //=============================================================================
899 void HOMARD_Gen_i::DissociateHypoZone(const char* nomHypothesis, const char* ZoneName)
901 MESSAGE ( "DissociateHypoZone : ZoneName= " << ZoneName << ", nomHypo = " << nomHypothesis);
903 HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypothesis];
904 ASSERT(!CORBA::is_nil(myHypo));
905 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
906 ASSERT(!CORBA::is_nil(aHypoSO));
908 HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
909 ASSERT(!CORBA::is_nil(myZone));
910 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myZone)));
911 ASSERT(!CORBA::is_nil(aZoneSO));
913 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
915 SALOMEDS::ChildIterator_var it = myStudy->NewChildIterator(aHypoSO);
916 for (; it->More(); it->Next())
918 SALOMEDS::SObject_var aHypObj = it->Value();
919 SALOMEDS::SObject_var ptrObj;
920 if (aHypObj->ReferencedObject(ptrObj))
922 if (std::string(ptrObj->GetName()) == std::string(aZoneSO->GetName()))
924 aStudyBuilder->NewCommand();
925 aStudyBuilder->RemoveObject(aHypObj);
926 aStudyBuilder->CommitCommand();
932 myZone->SupprHypo(nomHypothesis);
933 myHypo->SupprZone(ZoneName);
935 //=============================================================================
936 //=============================================================================
939 //=============================================================================
940 //=============================================================================
941 // Recuperation des listes
942 //=============================================================================
943 //=============================================================================
944 HOMARD::listeBoundarys* HOMARD_Gen_i::GetAllBoundarysName()
946 MESSAGE("GetAllBoundarysName");
949 HOMARD::listeBoundarys_var ret = new HOMARD::listeBoundarys;
950 ret->length(myStudyContext._mesBoundarys.size());
951 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it;
953 for (it = myStudyContext._mesBoundarys.begin();
954 it != myStudyContext._mesBoundarys.end(); it++)
956 ret[i++] = CORBA::string_dup((*it).first.c_str());
961 //=============================================================================
962 HOMARD::listeCases* HOMARD_Gen_i::GetAllCasesName()
964 MESSAGE("GetAllCasesName");
967 HOMARD::listeCases_var ret = new HOMARD::listeCases;
968 ret->length(myStudyContext._mesCas.size());
969 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
971 for (it = myStudyContext._mesCas.begin();
972 it != myStudyContext._mesCas.end(); it++)
974 ret[i++] = CORBA::string_dup((*it).first.c_str());
979 //=============================================================================
980 HOMARD::listeHypotheses* HOMARD_Gen_i::GetAllHypothesesName()
982 MESSAGE("GetAllHypothesesName");
985 HOMARD::listeHypotheses_var ret = new HOMARD::listeHypotheses;
986 ret->length(myStudyContext._mesHypotheses.size());
987 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it;
989 for (it = myStudyContext._mesHypotheses.begin();
990 it != myStudyContext._mesHypotheses.end(); it++)
992 ret[i++] = CORBA::string_dup((*it).first.c_str());
997 //=============================================================================
998 HOMARD::listeIterations* HOMARD_Gen_i::GetAllIterationsName()
1000 MESSAGE("GetAllIterationsName");
1003 HOMARD::listeIterations_var ret = new HOMARD::listeIterations;
1004 ret->length(myStudyContext._mesIterations.size());
1005 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it;
1007 for (it = myStudyContext._mesIterations.begin();
1008 it != myStudyContext._mesIterations.end(); it++)
1010 ret[i++] = CORBA::string_dup((*it).first.c_str());
1015 //=============================================================================
1016 HOMARD::listeYACSs* HOMARD_Gen_i::GetAllYACSsName()
1018 MESSAGE("GetAllYACSsName");
1021 HOMARD::listeYACSs_var ret = new HOMARD::listeYACSs;
1022 ret->length(myStudyContext._mesYACSs.size());
1023 std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it;
1025 for (it = myStudyContext._mesYACSs.begin();
1026 it != myStudyContext._mesYACSs.end(); it++)
1028 ret[i++] = CORBA::string_dup((*it).first.c_str());
1033 //=============================================================================
1034 HOMARD::listeZones* HOMARD_Gen_i::GetAllZonesName()
1036 MESSAGE("GetAllZonesName");
1039 HOMARD::listeZones_var ret = new HOMARD::listeZones;
1040 ret->length(myStudyContext._mesZones.size());
1041 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it;
1043 for (it = myStudyContext._mesZones.begin();
1044 it != myStudyContext._mesZones.end(); it++)
1046 ret[i++] = CORBA::string_dup((*it).first.c_str());
1051 //=============================================================================
1052 //=============================================================================
1054 //=============================================================================
1055 //=============================================================================
1056 // Recuperation des structures identifiees par leurs noms
1057 //=============================================================================
1058 //=============================================================================
1059 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::GetBoundary(const char* nomBoundary)
1061 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[nomBoundary];
1062 ASSERT(!CORBA::is_nil(myBoundary));
1063 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1065 //=============================================================================
1066 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::GetCase(const char* nomCas)
1068 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
1069 ASSERT(!CORBA::is_nil(myCase));
1070 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1072 //=============================================================================
1073 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::GetHypothesis(const char* nomHypothesis)
1075 HOMARD::HOMARD_Hypothesis_var myHypothesis = myStudyContext._mesHypotheses[nomHypothesis];
1076 ASSERT(!CORBA::is_nil(myHypothesis));
1077 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1079 //=============================================================================
1080 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::GetIteration(const char* NomIterationation)
1082 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[NomIterationation];
1083 ASSERT(!CORBA::is_nil(myIteration));
1084 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1086 //=============================================================================
1087 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::GetYACS(const char* nomYACS)
1089 HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
1090 ASSERT(!CORBA::is_nil(myYACS));
1091 return HOMARD::HOMARD_YACS::_duplicate(myYACS);
1093 //=============================================================================
1094 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::GetZone(const char* ZoneName)
1096 HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
1097 ASSERT(!CORBA::is_nil(myZone));
1098 return HOMARD::HOMARD_Zone::_duplicate(myZone);
1100 //=============================================================================
1101 //=============================================================================
1103 //=============================================================================
1104 //=============================================================================
1106 //=============================================================================
1107 //=============================================================================
1108 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)
1110 INFOS ( "MeshInfo : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1111 INFOS ( "Qual = " << Qual << ", Diam = " << Diam << ", Conn = " << Conn << ", Tail = " << Tail << ", Inte = " << Inte );
1116 if ( _PublisMeshIN != 0 ) option = 2 ;
1117 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, 0, option) ;
1118 myCase->SetDirName(DirName) ;
1120 myCase->MeshInfo(Qual, Diam, Conn, Tail, Inte) ;
1124 //=============================================================================
1125 //=============================================================================
1127 //=============================================================================
1128 //=============================================================================
1129 // Recuperation des structures par le contexte
1130 //=============================================================================
1131 //=============================================================================
1132 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::LastIteration(const char* nomCas)
1134 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
1135 ASSERT(!CORBA::is_nil(myCase));
1137 HOMARD::HOMARD_Iteration_var myIteration = myCase->LastIteration();
1138 ASSERT(!CORBA::is_nil(myIteration));
1140 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1142 //=============================================================================
1143 //=============================================================================
1145 //=============================================================================
1146 //=============================================================================
1147 // Nouvelles structures
1148 //=============================================================================
1149 //=============================================================================
1150 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::newCase()
1152 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1153 HOMARD_Cas_i* aServant = new HOMARD_Cas_i(_orb, engine);
1154 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(aServant->_this());
1155 return aCase._retn();
1157 //=============================================================================
1158 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::newHypothesis()
1160 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1161 HOMARD_Hypothesis_i* aServant = new HOMARD_Hypothesis_i(_orb, engine);
1162 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(aServant->_this());
1163 return aHypo._retn();
1165 //=============================================================================
1166 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::newIteration()
1168 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1169 HOMARD_Iteration_i* aServant = new HOMARD_Iteration_i(_orb, engine);
1170 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(aServant->_this());
1171 return aIter._retn();
1173 //=============================================================================
1174 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::newBoundary()
1176 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1177 HOMARD_Boundary_i* aServant = new HOMARD_Boundary_i(_orb, engine);
1178 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(aServant->_this());
1179 return aBoundary._retn();
1181 //=============================================================================
1182 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::newZone()
1184 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1185 HOMARD_Zone_i* aServant = new HOMARD_Zone_i(_orb, engine);
1186 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(aServant->_this());
1187 return aZone._retn();
1189 //=============================================================================
1190 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::newYACS()
1192 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1193 HOMARD_YACS_i* aServant = new HOMARD_YACS_i(_orb, engine);
1194 HOMARD::HOMARD_YACS_var aYACS = HOMARD::HOMARD_YACS::_narrow(aServant->_this());
1195 return aYACS._retn();
1197 //=============================================================================
1198 //=============================================================================
1200 //=============================================================================
1201 //=============================================================================
1202 // Creation des structures identifiees par leurs noms
1203 //=============================================================================
1204 //=============================================================================
1205 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCase(const char* nomCas, const char* MeshName, const char* MeshFile)
1207 // Creation d'un cas initial
1208 // nomCas : nom du cas a creer
1209 // MeshName, MeshFile : nom et fichier du maillage correspondant
1212 INFOS ( "CreateCase : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1215 if ( _PublisMeshIN != 0 ) option = 2 ;
1216 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 0, 0, option) ;
1218 // Valeurs par defaut des filtrages
1219 myCase->SetPyram(0);
1221 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1223 //=============================================================================
1224 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromIteration(const char* nomCas, const char* DirNameStart)
1226 // nomCas : nom du cas a creer
1227 // DirNameStart : nom du répertoire contenant l'iteration de reprise
1230 INFOS ( "CreateCaseFromIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1231 std::string nomDirWork = getenv("PWD") ;
1234 // A. Decodage du point de reprise
1235 // A.1. Controle du répertoire de depart de l'iteration
1236 codret = CHDIR(DirNameStart) ;
1239 SALOME::ExceptionStruct es;
1240 es.type = SALOME::BAD_PARAM;
1241 es.text = "The directory of the iteration does not exist.";
1242 throw SALOME::SALOME_Exception(es);
1245 // A.2. Reperage des fichiers du répertoire de reprise
1246 std::string file_configuration = "" ;
1247 std::string file_maillage_homard = "" ;
1251 struct dirent *dirp;
1252 dp = opendir(DirNameStart);
1253 while ( (dirp = readdir(dp)) != NULL )
1255 std::string file_name(dirp->d_name);
1256 // MESSAGE ( file_name );
1257 bilan = file_name.find("HOMARD.Configuration.") ;
1258 if ( bilan != string::npos ) { file_configuration = file_name ; }
1259 bilan = file_name.find("maill.") ;
1260 if ( bilan != string::npos )
1262 bilan = file_name.find(".hom.med") ;
1263 if ( bilan != string::npos ) { file_maillage_homard = file_name ; }
1268 HANDLE hFind = INVALID_HANDLE_VALUE;
1269 WIN32_FIND_DATA ffd;
1270 hFind = FindFirstFile(DirNameStart, &ffd);
1271 if (INVALID_HANDLE_VALUE != hFind) {
1272 while (FindNextFile(hFind, &ffd) != 0) {
1273 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
1274 std::string file_name(ffd.cFileName);
1275 bilan = file_name.find("HOMARD.Configuration.") ;
1276 if ( bilan != string::npos ) { file_configuration = file_name ; }
1277 bilan = file_name.find("maill.") ;
1278 if ( bilan != string::npos )
1280 bilan = file_name.find(".hom.med") ;
1281 if ( bilan != string::npos ) { file_maillage_homard = file_name ; }
1287 MESSAGE ( "==> file_configuration : " << file_configuration ) ;
1288 MESSAGE ( "==> file_maillage_homard : " << file_maillage_homard ) ;
1290 if ( ( file_configuration == "" ) || ( file_maillage_homard == "" ) )
1292 SALOME::ExceptionStruct es;
1293 es.type = SALOME::BAD_PARAM;
1295 if ( file_configuration == "" ) { text = "The configuration file cannot be found." ; }
1296 else { text = "The HOMARD mesh file cannot be found." ; }
1297 es.text = CORBA::string_dup(text.c_str());
1298 throw SALOME::SALOME_Exception(es);
1301 // B. Lecture du fichier de configuration
1302 // ATTENTION : on doit veiller a la coherence entre HomardDriver et CreateCaseFromIteration
1309 // le constructeur de ifstream permet d'ouvrir un fichier en lecture
1310 std::ifstream fichier( file_configuration.c_str() );
1311 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1313 std::string ligne; // variable contenant chaque ligne lue
1314 std::string mot_cle;
1315 std::string argument;
1317 // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1318 while ( std::getline( fichier, ligne ) )
1320 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1321 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1322 ligne_bis >> mot_cle ;
1323 // B.2. Des valeurs entieres : le second bloc de la ligne
1324 if ( mot_cle == "NumeIter" )
1326 ligne_bis >> NumeIter ;
1329 // B.3. Des valeurs caracteres brutes : le second bloc de la ligne est la valeur
1330 else if ( ( mot_cle == "TypeConf" ) || ( mot_cle == "TypeElem" ) )
1332 ligne_bis >> argument ;
1334 if ( mot_cle == "TypeConf" )
1336 if ( argument == "conforme" ) { TypeConf = 1 ; }
1337 else if ( argument == "non_conforme_1_noeud" ) { TypeConf = 2 ; }
1338 else if ( argument == "non_conforme_1_arete" ) { TypeConf = 3 ; }
1339 else if ( argument == "non_conforme_indicateur" ) { TypeConf = 4 ; }
1341 else if ( mot_cle == "TypeElem" )
1343 if ( argument == "ignore_pyra" ) { Pyram = 1 ; }
1344 else if ( argument == "HOMARD" ) { Pyram = 0 ; }
1347 // B.4. Des valeurs caracteres : le deuxieme bloc de la ligne peut etre encadre par des quotes :
1348 // il faut les supprimer
1349 else if ( ( mot_cle == "CCNoMNP1" ) || ( mot_cle == "CCMaiNP1" ) )
1351 ligne_bis >> argument ;
1352 if ( argument[0] == '"' ) { decalage = 1 ; }
1353 else { decalage = 0 ; }
1354 size_t size = argument.size() + 1 - 2*decalage ;
1356 if ( mot_cle == "CCNoMNP1" )
1358 MeshName = new char[ size ];
1359 strncpy( MeshName, argument.c_str()+decalage, size );
1360 MeshName[size-1] = '\0' ;
1362 else if ( mot_cle == "CCMaiNP1" )
1364 MeshFile = new char[ size ];
1365 strncpy( MeshFile, argument.c_str()+decalage, size );
1366 MeshFile[size-1] = '\0' ;
1370 MESSAGE ( "==> TypeConf : " << TypeConf ) ;
1371 MESSAGE ( "==> MeshName : " << MeshName ) ;
1372 MESSAGE ( "==> MeshFile : " << MeshFile ) ;
1373 MESSAGE ( "==> NumeIter : " << NumeIter ) ;
1374 MESSAGE ( "==> Pyram : " << Pyram ) ;
1378 SALOME::ExceptionStruct es;
1379 es.type = SALOME::BAD_PARAM;
1380 std::string text = "The configuration file cannot be read." ;
1381 es.text = CORBA::string_dup(text.c_str());
1382 throw SALOME::SALOME_Exception(es);
1385 // C. Creation effective du cas
1388 if ( _PublisMeshIN != 0 ) option = 2 ;
1389 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, NumeIter, option) ;
1391 // D. Parametrages lus dans le fichier de configuration
1393 myCase->SetConfType (TypeConf) ;
1394 myCase->SetExtType (TypeExt) ;
1395 myCase->SetPyram (Pyram) ;
1397 // E. Copie du fichier de maillage homard
1398 // E.1. Répertoire associe au cas
1399 char* nomDirCase = myCase->GetDirName() ;
1400 // E.2. Répertoire associe a l'iteration de ce cas
1402 IterName = myCase->GetIter0Name() ;
1403 HOMARD::HOMARD_Iteration_var Iter = GetIteration(IterName) ;
1404 char* nomDirIter = CreateDirNameIter(nomDirCase, 0 );
1405 Iter->SetDirNameLoc(nomDirIter);
1406 std::string nomDirIterTotal ;
1407 nomDirIterTotal = std::string(nomDirCase) + "/" + std::string(nomDirIter) ;
1409 if (mkdir(nomDirIterTotal.c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
1411 if (_mkdir(nomDirIterTotal.c_str()) != 0)
1414 MESSAGE ( "nomDirIterTotal : " << nomDirIterTotal ) ;
1415 SALOME::ExceptionStruct es;
1416 es.type = SALOME::BAD_PARAM;
1417 std::string text = "The directory for the computation cannot be created." ;
1418 es.text = CORBA::string_dup(text.c_str());
1419 throw SALOME::SALOME_Exception(es);
1421 // E.3. Copie du maillage HOMARD au format MED
1422 codret = CHDIR(DirNameStart) ;
1423 std::string commande = "cp " + file_maillage_homard + " " + nomDirIterTotal ;
1424 MESSAGE ( "commande : " << commande ) ;
1425 codret = system(commande.c_str()) ;
1426 MESSAGE ( "codret : " << codret ) ;
1429 SALOME::ExceptionStruct es;
1430 es.type = SALOME::BAD_PARAM;
1431 es.text = "The starting point for the case cannot be copied into the working directory.";
1432 throw SALOME::SALOME_Exception(es);
1441 CHDIR(nomDirWork.c_str());
1442 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1444 //=============================================================================
1445 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseLastIteration(const char* nomCas, const char* DirNameStart)
1447 // nomCas : nom du cas a creer
1448 // DirNameStart : nom du répertoire du cas contenant l'iteration de reprise
1451 INFOS ( "CreateCaseFromCaseLastIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1453 std::string DirNameStartIter = CreateCase1(DirNameStart, -1) ;
1455 DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1456 HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1458 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1460 //=============================================================================
1461 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseIteration(const char* nomCas, const char* DirNameStart, CORBA::Long Number)
1463 // nomCas : nom du cas a creer
1464 // DirNameStart : nom du répertoire du cas contenant l'iteration de reprise
1465 // Number : numero de l'iteration de depart
1468 INFOS ( "CreateCaseFromCaseIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart << ", Number = " << Number );
1471 SALOME::ExceptionStruct es;
1472 es.type = SALOME::BAD_PARAM;
1473 es.text = "The number of iteration must be positive.";
1474 throw SALOME::SALOME_Exception(es);
1478 std::string DirNameStartIter = CreateCase1(DirNameStart, Number) ;
1480 DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1481 HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1483 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1485 //=============================================================================
1486 std::string HOMARD_Gen_i::CreateCase1(const char* DirNameStart, CORBA::Long Number)
1488 // Retourne le nom du répertoire ou se trouve l'iteration voulue.
1489 // DirNameStart : nom du répertoire du cas contenant l'iteration de reprise
1490 // Number : numero de l'iteration de depart ou -1 si on cherche la derniere
1493 MESSAGE ( "CreateCase1 : DirNameStart = " << DirNameStart << ", Number = " << Number );
1494 std::string nomDirWork = getenv("PWD") ;
1495 std::string DirNameStartIter ;
1497 int NumeIterMax = -1 ;
1499 // A.1. Controle du répertoire de depart du cas
1500 codret = CHDIR(DirNameStart) ;
1503 SALOME::ExceptionStruct es;
1504 es.type = SALOME::BAD_PARAM;
1505 es.text = "The directory of the case for the pursuit does not exist.";
1506 throw SALOME::SALOME_Exception(es);
1509 // A.2. Reperage des sous-répertoire du répertoire de reprise
1510 bool existe = false ;
1513 struct dirent *dirp;
1514 dp = opendir(DirNameStart);
1515 while ( (dirp = readdir(dp)) != NULL ) {
1516 std::string DirName_1(dirp->d_name);
1518 HANDLE hFind = INVALID_HANDLE_VALUE;
1519 WIN32_FIND_DATA ffd;
1520 hFind = FindFirstFile(DirNameStart, &ffd);
1521 if (INVALID_HANDLE_VALUE != hFind) {
1522 while (FindNextFile(hFind, &ffd) != 0) {
1523 std::string DirName_1 = "";
1524 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1525 DirName_1 = std::string(ffd.cFileName);
1528 if ( ( DirName_1 != "." ) && ( DirName_1 != ".." ) )
1530 if ( CHDIR(DirName_1.c_str()) == 0 )
1532 // On cherche le fichier de configuration dans ce sous-répertoire
1533 codret = CHDIR(DirNameStart);
1536 struct dirent *dirp_1;
1537 dp_1 = opendir(DirName_1.c_str()) ;
1538 while ( (dirp_1 = readdir(dp_1)) != NULL )
1540 std::string file_name_1(dirp_1->d_name);
1542 HANDLE hFind1 = INVALID_HANDLE_VALUE;
1543 WIN32_FIND_DATA ffd1;
1544 hFind1 = FindFirstFile(DirName_1.c_str(), &ffd1);
1545 while (FindNextFile(hFind1, &ffd1) != 0)
1547 if (ffd1.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
1548 std::string file_name_1(ffd1.cFileName);
1550 int bilan = file_name_1.find("HOMARD.Configuration.") ;
1551 if ( bilan != string::npos )
1553 // Decodage du fichier pour trouver le numero d'iteration
1554 CHDIR(DirName_1.c_str()) ;
1556 std::ifstream fichier( file_name_1.c_str() );
1557 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1560 std::string ligne; // variable contenant chaque ligne lue
1561 std::string mot_cle;
1562 // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1563 while ( std::getline( fichier, ligne ) )
1565 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1566 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1567 ligne_bis >> mot_cle ;
1568 if ( mot_cle == "NumeIter" )
1570 ligne_bis >> NumeIter ;
1572 // MESSAGE ( "==> NumeIter : " << NumeIter ) ;
1573 if ( Number == - 1 )
1575 if ( NumeIter >= NumeIterMax )
1577 NumeIterMax = NumeIter ;
1578 DirNameStartIter = DirName_1 ;
1583 if ( NumeIter == Number )
1585 DirNameStartIter = DirName_1 ;
1595 SALOME::ExceptionStruct es;
1596 es.type = SALOME::BAD_PARAM;
1597 std::string text = "The configuration file cannot be read." ;
1598 es.text = CORBA::string_dup(text.c_str());
1599 throw SALOME::SALOME_Exception(es);
1601 CHDIR(DirNameStart) ;
1603 if ( existe ) { break ; }
1610 if ( existe ) { break ; }
1619 CHDIR(nomDirWork.c_str());
1621 if ( ( Number >= 0 && ( !existe ) ) || ( Number < 0 && ( NumeIterMax == -1 ) ) )
1623 SALOME::ExceptionStruct es;
1624 es.type = SALOME::BAD_PARAM;
1625 es.text = "The directory of the iteration does not exist.";
1626 throw SALOME::SALOME_Exception(es);
1630 return DirNameStartIter ;
1632 //=============================================================================
1633 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)
1635 // nomCas : nom du cas a creer
1636 // MeshName, MeshFile : nom et fichier du maillage correspondant
1637 // MeshOption : 0 : le maillage fourni est obligatoirement present ==> erreur si absent
1638 // 1 : le maillage fourni peut ne pas exister ==> on continue si absent
1639 // -1 : le maillage n'est pas fourni
1640 // NumeIter : numero de l'iteration correspondante : 0, pour un depart, n>0 pour une poursuite
1641 // Option : multiple de nombres premiers
1642 // 1 : aucune option
1643 // x2 : publication du maillage dans SMESH
1645 MESSAGE ( "CreateCase0 : nomCas = " << nomCas );
1646 MESSAGE ( "CreateCase0 : MeshName = " << MeshName << ", MeshFile = " << MeshFile << ", MeshOption = " << MeshOption );
1647 MESSAGE ( "CreateCase0 : NumeIter = " << NumeIter << ", Option = " << Option );
1653 // A.2. Controle du nom :
1654 if ((myStudyContext._mesCas).find(nomCas)!=(myStudyContext._mesCas).end())
1656 SALOME::ExceptionStruct es;
1657 es.type = SALOME::BAD_PARAM;
1658 es.text = "This case has already been defined.";
1659 throw SALOME::SALOME_Exception(es);
1663 // A.3. Controle du fichier du maillage
1664 int existeMeshFile ;
1665 if ( MeshOption >= 0 )
1667 existeMeshFile = MEDFileExist ( MeshFile ) ;
1668 MESSAGE ( "CreateCase0 : existeMeshFile = " << existeMeshFile );
1669 if ( ( existeMeshFile == 0 ) && ( MeshOption == 0 ) )
1671 SALOME::ExceptionStruct es;
1672 es.type = SALOME::BAD_PARAM;
1673 es.text = "The mesh file does not exist.";
1674 throw SALOME::SALOME_Exception(es);
1678 else { existeMeshFile = 0 ; }
1680 // B. Creation de l'objet cas et publication
1681 // MESSAGE ( "CreateCase0 : Creation de l'objet" );
1682 HOMARD::HOMARD_Cas_var myCase = newCase();
1683 myCase->SetName(nomCas);
1684 SALOMEDS::SObject_var aSO;
1685 SALOMEDS::SObject_var aResultSO=PublishInStudy(aSO, myCase, nomCas);
1686 myStudyContext._mesCas[nomCas] = myCase;
1688 // C. Caracteristiques du maillage
1689 if ( existeMeshFile != 0 )
1691 // Les valeurs extremes des coordonnées
1692 // MESSAGE ( "CreateCase0 : Les valeurs extremes des coordonnées" );
1693 std::vector<double> LesExtremes =GetBoundingBoxInMedFile(MeshFile) ;
1694 HOMARD::extrema_var aSeq = new HOMARD::extrema() ;
1695 if (LesExtremes.size()!=10) { return 0; }
1697 for (int i =0 ; i< LesExtremes.size() ; i++)
1698 aSeq[i]=LesExtremes[i] ;
1699 myCase->SetBoundingBox(aSeq) ;
1701 // MESSAGE ( "CreateCase0 : Les groupes" );
1702 std::set<std::string> LesGroupes =GetListeGroupesInMedFile(MeshFile) ;
1703 HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType ;
1704 aSeqGroupe->length(LesGroupes.size());
1705 std::set<std::string>::const_iterator it ;
1707 for (it=LesGroupes.begin() ; it != LesGroupes.end() ; it++)
1708 aSeqGroupe[i++]=(*it).c_str() ;
1709 myCase->SetGroups(aSeqGroupe) ;
1712 // D. L'iteration initiale du cas
1713 MESSAGE ( "CreateCase0 : iteration initiale du cas" );
1714 // D.1. Recherche d'un nom : par defaut, on prend le nom du maillage correspondant.
1715 // Si ce nom d'iteration existe deja, on incremente avec 0, 1, 2, etc.
1717 std::string NomIteration = std::string(MeshName) ;
1718 while ( (myStudyContext._mesIterations).find(NomIteration) != (myStudyContext._mesIterations.end()) )
1720 std::ostringstream nom;
1721 nom << MeshName << monNum;
1722 NomIteration = nom.str();
1725 MESSAGE ( "CreateCas0 : ==> NomIteration = " << NomIteration );
1727 // D.2. Creation de l'iteration
1728 HOMARD::HOMARD_Iteration_var anIter = newIteration();
1729 myStudyContext._mesIterations[NomIteration] = anIter;
1730 anIter->SetName(NomIteration.c_str());
1731 AssociateCaseIter (nomCas, NomIteration.c_str(), "IterationHomard");
1733 // D.4. Maillage correspondant
1734 if ( existeMeshFile != 0 )
1736 anIter->SetMeshFile(MeshFile);
1737 if ( Option % 2 == 0 ) { PublishResultInSmesh(MeshFile, 0); }
1739 anIter->SetMeshName(MeshName);
1741 // D.5. Numero d'iteration
1742 anIter->SetNumber(NumeIter);
1745 SetEtatIter(NomIteration.c_str(), -NumeIter);
1748 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1750 //=============================================================================
1751 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::CreateHypothesis(const char* nomHypothesis)
1753 INFOS ( "CreateHypothesis : nomHypothesis = " << nomHypothesis );
1756 // A. Controle du nom :
1757 if ((myStudyContext._mesHypotheses).find(nomHypothesis) != (myStudyContext._mesHypotheses).end())
1759 SALOME::ExceptionStruct es;
1760 es.type = SALOME::BAD_PARAM;
1761 es.text = "This hypothesis has already been defined.";
1762 throw SALOME::SALOME_Exception(es);
1766 // B. Creation de l'objet
1767 HOMARD::HOMARD_Hypothesis_var myHypothesis = newHypothesis();
1768 if (CORBA::is_nil(myHypothesis))
1770 SALOME::ExceptionStruct es;
1771 es.type = SALOME::BAD_PARAM;
1772 es.text = "Unable to create the hypothesis";
1773 throw SALOME::SALOME_Exception(es);
1776 myHypothesis->SetName(nomHypothesis);
1778 // C. Enregistrement
1779 myStudyContext._mesHypotheses[nomHypothesis] = myHypothesis;
1781 SALOMEDS::SObject_var aSO;
1782 SALOMEDS::SObject_var aResultSO=PublishInStudy(aSO, myHypothesis, nomHypothesis);
1784 // D. Valeurs par defaut des options avancees
1785 myHypothesis->SetNivMax(-1);
1786 myHypothesis->SetDiamMin(-1.0);
1787 myHypothesis->SetAdapInit(0);
1788 myHypothesis->SetExtraOutput(1);
1790 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1793 //=============================================================================
1794 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::CreateIteration(const char* NomIteration, const char* nomIterParent)
1795 //=============================================================================
1797 INFOS ("CreateIteration : NomIteration = " << NomIteration << ", nomIterParent = " << nomIterParent);
1800 HOMARD::HOMARD_Iteration_var myIterationParent = myStudyContext._mesIterations[nomIterParent];
1801 if (CORBA::is_nil(myIterationParent))
1803 SALOME::ExceptionStruct es;
1804 es.type = SALOME::BAD_PARAM;
1805 es.text = "The parent iteration is not defined.";
1806 throw SALOME::SALOME_Exception(es);
1810 const char* nomCas = myIterationParent->GetCaseName();
1811 MESSAGE ("CreateIteration : nomCas = " << nomCas);
1812 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
1813 if (CORBA::is_nil(myCase))
1815 SALOME::ExceptionStruct es;
1816 es.type = SALOME::BAD_PARAM;
1817 es.text = "Invalid case context";
1818 throw SALOME::SALOME_Exception(es);
1821 const char* nomDirCase = myCase->GetDirName();
1823 // Controle du nom :
1824 if ((myStudyContext._mesIterations).find(NomIteration)!=(myStudyContext._mesIterations).end())
1826 SALOME::ExceptionStruct es;
1827 es.type = SALOME::BAD_PARAM;
1828 es.text = "This iteration has already been defined.";
1829 throw SALOME::SALOME_Exception(es);
1833 HOMARD::HOMARD_Iteration_var myIteration = newIteration();
1834 if (CORBA::is_nil(myIteration))
1836 SALOME::ExceptionStruct es;
1837 es.type = SALOME::BAD_PARAM;
1838 es.text = "Unable to create the iteration";
1839 throw SALOME::SALOME_Exception(es);
1842 myStudyContext._mesIterations[std::string(NomIteration)] = myIteration;
1843 // Nom de l'iteration et du maillage
1844 myIteration->SetName(NomIteration);
1845 myIteration->SetMeshName(NomIteration);
1846 myIteration->SetState(1);
1848 int numero = myIterationParent->GetNumber() + 1;
1849 myIteration->SetNumber(numero);
1851 // Nombre d'iterations deja connues pour le cas, permettant
1852 // la creation d'un sous-répertoire unique
1853 int nbitercase = myCase->GetNumberofIter();
1854 char* nomDirIter = CreateDirNameIter(nomDirCase, nbitercase );
1855 myIteration->SetDirNameLoc(nomDirIter);
1857 // Le nom du fichier du maillage MED est indice par le nombre d'iterations du cas.
1858 // Si on a une chaine unique depuis le depart, ce nombre est le meme que le
1859 // numero d'iteration dans la sucession : maill.01.med, maill.02.med, etc... C'est la
1860 // situation la plus frequente.
1861 // Si on a plusieurs branches, donc des iterations du meme niveau d'adaptation, utiliser
1862 // le nombre d'iterations du cas permet d'eviter les collisions.
1864 if ( nbitercase < 100 ) { jaux = 2 ; }
1865 else if ( nbitercase < 1000 ) { jaux = 3 ; }
1866 else if ( nbitercase < 10000 ) { jaux = 4 ; }
1867 else if ( nbitercase < 100000 ) { jaux = 5 ; }
1869 std::ostringstream iaux ;
1870 iaux << std::setw(jaux) << std::setfill('0') << nbitercase ;
1871 std::stringstream MeshFile;
1872 MeshFile << nomDirCase << "/maill." << iaux.str() << ".med";
1873 myIteration->SetMeshFile(MeshFile.str().c_str());
1875 // Association avec le cas
1876 std::string label = "IterationHomard_" + std::string(nomIterParent);
1877 AssociateCaseIter(nomCas, NomIteration, label.c_str());
1878 // Lien avec l'iteration precedente
1879 myIterationParent->LinkNextIteration(NomIteration);
1880 myIteration->SetIterParentName(nomIterParent);
1881 // Gestion de l'arbre d'etudes
1882 SALOMEDS::SObject_var aIterSOParent = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIterationParent)));
1883 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
1884 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
1885 aStudyBuilder->NewCommand();
1886 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
1887 aStudyBuilder->Addreference(aSubSO, aIterSOParent);
1888 aStudyBuilder->CommitCommand();
1890 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1892 //=============================================================================
1893 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundary(const char* BoundaryName, CORBA::Long BoundaryType)
1895 MESSAGE ("CreateBoundary : BoundaryName = " << BoundaryName << ", BoundaryType = " << BoundaryType);
1898 // Controle du nom :
1899 if ((myStudyContext._mesBoundarys).find(BoundaryName)!=(myStudyContext._mesBoundarys).end())
1901 MESSAGE ("CreateBoundary : la frontiere " << BoundaryName << " existe deja");
1902 SALOME::ExceptionStruct es;
1903 es.type = SALOME::BAD_PARAM;
1904 es.text = "This boundary has already been defined";
1905 throw SALOME::SALOME_Exception(es);
1909 HOMARD::HOMARD_Boundary_var myBoundary = newBoundary();
1910 myBoundary->SetName(BoundaryName);
1911 myBoundary->SetType(BoundaryType);
1913 myStudyContext._mesBoundarys[BoundaryName] = myBoundary;
1915 SALOMEDS::SObject_var aSO;
1916 SALOMEDS::SObject_var aResultSO=PublishInStudy(aSO, myBoundary, BoundaryName);
1918 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1920 //=============================================================================
1921 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCAO(const char* BoundaryName, const char* CAOFile)
1923 INFOS ("CreateBoundaryCAO : BoundaryName = " << BoundaryName << ", CAOFile = " << CAOFile );
1924 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, -1);
1925 myBoundary->SetDataFile( CAOFile ) ;
1927 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1929 //=============================================================================
1930 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
1932 INFOS ("CreateBoundaryDi : BoundaryName = " << BoundaryName << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1933 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
1934 myBoundary->SetDataFile( MeshFile ) ;
1935 myBoundary->SetMeshName( MeshName ) ;
1937 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1939 //=============================================================================
1940 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCylinder(const char* BoundaryName,
1941 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1942 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1943 CORBA::Double Rayon)
1945 INFOS ("CreateBoundaryCylinder : BoundaryName = " << BoundaryName ) ;
1947 SALOME::ExceptionStruct es;
1950 { es.text = "The radius must be positive." ;
1952 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1953 if ( daux < 0.0000001 )
1954 { es.text = "The axis must be a non 0 vector." ;
1958 es.type = SALOME::BAD_PARAM;
1959 throw SALOME::SALOME_Exception(es);
1963 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 1) ;
1964 myBoundary->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon ) ;
1966 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1968 //=============================================================================
1969 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundarySphere(const char* BoundaryName,
1970 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1971 CORBA::Double Rayon)
1973 INFOS ("CreateBoundarySphere : BoundaryName = " << BoundaryName ) ;
1975 SALOME::ExceptionStruct es;
1978 { es.text = "The radius must be positive." ;
1982 es.type = SALOME::BAD_PARAM;
1983 throw SALOME::SALOME_Exception(es);
1987 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 2) ;
1988 myBoundary->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
1990 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1992 //=============================================================================
1993 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeA(const char* BoundaryName,
1994 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe, CORBA::Double Angle,
1995 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre)
1997 INFOS ("CreateBoundaryConeA : BoundaryName = " << BoundaryName ) ;
1999 SALOME::ExceptionStruct es;
2001 if ( Angle <= 0.0 || Angle >= 90.0 )
2002 { es.text = "The angle must be included higher than 0 degree and lower than 90 degrees." ;
2004 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2005 if ( daux < 0.0000001 )
2006 { es.text = "The axis must be a non 0 vector." ;
2010 es.type = SALOME::BAD_PARAM;
2011 throw SALOME::SALOME_Exception(es);
2015 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 3) ;
2016 myBoundary->SetConeA( Xaxe, Yaxe, Zaxe, Angle, Xcentre, Ycentre, Zcentre ) ;
2018 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2020 //=============================================================================
2021 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeR(const char* BoundaryName,
2022 CORBA::Double Xcentre1, CORBA::Double Ycentre1, CORBA::Double Zcentre1, CORBA::Double Rayon1,
2023 CORBA::Double Xcentre2, CORBA::Double Ycentre2, CORBA::Double Zcentre2, CORBA::Double Rayon2)
2025 INFOS ("CreateBoundaryConeR : BoundaryName = " << BoundaryName ) ;
2027 SALOME::ExceptionStruct es;
2029 if ( Rayon1 < 0.0 || Rayon2 < 0.0 )
2030 { es.text = "The radius must be positive." ;
2032 double daux = fabs(Rayon2-Rayon1) ;
2033 if ( daux < 0.0000001 )
2034 { es.text = "The radius must be different." ;
2036 daux = fabs(Xcentre2-Xcentre1) + fabs(Ycentre2-Ycentre1) + fabs(Zcentre2-Zcentre1) ;
2037 if ( daux < 0.0000001 )
2038 { es.text = "The centers must be different." ;
2042 es.type = SALOME::BAD_PARAM;
2043 throw SALOME::SALOME_Exception(es);
2047 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 4) ;
2048 myBoundary->SetConeR( Xcentre1, Ycentre1, Zcentre1, Rayon1, Xcentre2, Ycentre2, Zcentre2, Rayon2 ) ;
2050 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2052 //=============================================================================
2053 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryTorus(const char* BoundaryName,
2054 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2055 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2056 CORBA::Double RayonRev, CORBA::Double RayonPri)
2058 INFOS ("CreateBoundaryTorus : BoundaryName = " << BoundaryName ) ;
2060 SALOME::ExceptionStruct es;
2062 if ( ( RayonRev <= 0.0 ) || ( RayonPri <= 0.0 ) )
2063 { es.text = "The radius must be positive." ;
2065 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2066 if ( daux < 0.0000001 )
2067 { es.text = "The axis must be a non 0 vector." ;
2071 es.type = SALOME::BAD_PARAM;
2072 throw SALOME::SALOME_Exception(es);
2076 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 5) ;
2077 myBoundary->SetTorus( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, RayonRev, RayonPri ) ;
2079 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2081 //=============================================================================
2082 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZone(const char* ZoneName, CORBA::Long ZoneType)
2084 MESSAGE ("CreateZone : ZoneName = " << ZoneName << ", ZoneType = " << ZoneType);
2087 // Controle du nom :
2088 if ((myStudyContext._mesZones).find(ZoneName)!=(myStudyContext._mesZones).end())
2090 SALOME::ExceptionStruct es;
2091 es.type = SALOME::BAD_PARAM;
2092 es.text = "This zone has already been defined";
2093 throw SALOME::SALOME_Exception(es);
2097 HOMARD::HOMARD_Zone_var myZone = newZone();
2098 myZone->SetName(ZoneName);
2099 myZone->SetType(ZoneType);
2101 myStudyContext._mesZones[ZoneName] = myZone;
2103 SALOMEDS::SObject_var aSO;
2104 SALOMEDS::SObject_var aResultSO=PublishInStudy(aSO, myZone, ZoneName);
2106 return HOMARD::HOMARD_Zone::_duplicate(myZone);
2108 //=============================================================================
2109 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox(const char* ZoneName,
2110 CORBA::Double Xmini, CORBA::Double Xmaxi,
2111 CORBA::Double Ymini, CORBA::Double Ymaxi,
2112 CORBA::Double Zmini, CORBA::Double Zmaxi)
2114 INFOS ("CreateZoneBox : ZoneName = " << ZoneName ) ;
2116 SALOME::ExceptionStruct es;
2118 if ( Xmini > Xmaxi )
2119 { es.text = "The X coordinates are not coherent." ;
2121 if ( Ymini > Ymaxi )
2122 { es.text = "The Y coordinates are not coherent." ;
2124 if ( Zmini > Zmaxi )
2125 { es.text = "The Z coordinates are not coherent." ;
2129 es.type = SALOME::BAD_PARAM;
2130 throw SALOME::SALOME_Exception(es);
2134 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 2) ;
2135 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2137 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2139 //=============================================================================
2140 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneSphere(const char* ZoneName,
2141 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre, CORBA::Double Rayon)
2143 INFOS ("CreateZoneSphere : ZoneName = " << ZoneName ) ;
2145 SALOME::ExceptionStruct es;
2148 { es.text = "The radius must be positive." ;
2152 es.type = SALOME::BAD_PARAM;
2153 throw SALOME::SALOME_Exception(es);
2157 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 4) ;
2158 myZone->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
2160 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2162 //=============================================================================
2163 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneCylinder(const char* ZoneName,
2164 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2165 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2166 CORBA::Double Rayon, CORBA::Double Haut)
2168 INFOS ("CreateZoneCylinder : ZoneName = " << ZoneName ) ;
2170 SALOME::ExceptionStruct es;
2173 { es.text = "The radius must be positive." ;
2175 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2176 if ( daux < 0.0000001 )
2177 { es.text = "The axis must be a non 0 vector." ;
2180 { es.text = "The height must be positive." ;
2184 es.type = SALOME::BAD_PARAM;
2185 throw SALOME::SALOME_Exception(es);
2189 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 5) ;
2190 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut ) ;
2192 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2194 //=============================================================================
2195 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZonePipe(const char* ZoneName,
2196 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2197 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2198 CORBA::Double Rayon, CORBA::Double Haut, CORBA::Double Rayonint)
2200 INFOS ("CreateZonePipe : ZoneName = " << ZoneName ) ;
2202 SALOME::ExceptionStruct es;
2204 if ( Rayon <= 0.0 || Rayonint <= 0.0 )
2205 { es.text = "The radius must be positive." ;
2207 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2208 if ( daux < 0.0000001 )
2209 { es.text = "The axis must be a non 0 vector." ;
2212 { es.text = "The height must be positive." ;
2214 if ( Rayon <= Rayonint )
2215 { es.text = "The external radius must be higher than the internal radius." ;
2219 es.type = SALOME::BAD_PARAM;
2220 throw SALOME::SALOME_Exception(es);
2224 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 7) ;
2225 myZone->SetPipe( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut, Rayonint ) ;
2227 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2229 //=============================================================================
2230 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox2D(const char* ZoneName,
2231 CORBA::Double Umini, CORBA::Double Umaxi,
2232 CORBA::Double Vmini, CORBA::Double Vmaxi,
2235 INFOS ("CreateZoneBox2D : ZoneName = " << ZoneName ) ;
2236 // MESSAGE ("Umini = " << Umini << ", Umaxi =" << Umaxi ) ;
2237 // MESSAGE ("Vmini = " << Vmini << ", Vmaxi =" << Vmaxi ) ;
2238 // MESSAGE ("Orient = " << Orient ) ;
2240 SALOME::ExceptionStruct es;
2242 if ( Umini > Umaxi )
2243 { es.text = "The first coordinates are not coherent." ;
2245 if ( Vmini > Vmaxi )
2246 { es.text = "The second coordinates are not coherent." ;
2248 if ( Orient < 1 || Orient > 3 )
2249 { es.text = "The orientation must be 1, 2 or 3." ;
2253 es.type = SALOME::BAD_PARAM;
2254 throw SALOME::SALOME_Exception(es);
2258 double Xmini, Xmaxi ;
2259 double Ymini, Ymaxi ;
2260 double Zmini, Zmaxi ;
2268 else if ( Orient == 2 )
2275 else if ( Orient == 3 )
2282 else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2284 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 10+Orient) ;
2285 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2287 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2289 //=============================================================================
2290 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDisk(const char* ZoneName,
2291 CORBA::Double Ucentre, CORBA::Double Vcentre,
2292 CORBA::Double Rayon,
2295 INFOS ("CreateZoneDisk : ZoneName = " << ZoneName ) ;
2297 SALOME::ExceptionStruct es;
2300 { es.text = "The radius must be positive." ;
2302 if ( Orient < 1 || Orient > 3 )
2303 { es.text = "The orientation must be 1, 2 or 3." ;
2307 es.type = SALOME::BAD_PARAM;
2308 throw SALOME::SALOME_Exception(es);
2316 { Xcentre = Ucentre ;
2319 else if ( Orient == 2 )
2322 Zcentre = Vcentre ; }
2323 else if ( Orient == 3 )
2324 { Xcentre = Vcentre ;
2326 Zcentre = Ucentre ; }
2327 else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2329 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 30+Orient) ;
2330 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1. ) ;
2332 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2334 //=============================================================================
2335 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDiskWithHole(const char* ZoneName,
2336 CORBA::Double Ucentre, CORBA::Double Vcentre,
2337 CORBA::Double Rayon, CORBA::Double Rayonint,
2340 INFOS ("CreateZoneDiskWithHole : ZoneName = " << ZoneName ) ;
2342 SALOME::ExceptionStruct es;
2344 if ( Rayon <= 0.0 || Rayonint <= 0.0 )
2345 { es.text = "The radius must be positive." ;
2347 if ( Orient < 1 || Orient > 3 )
2348 { es.text = "The orientation must be 1, 2 or 3." ;
2350 if ( Rayon <= Rayonint )
2351 { es.text = "The external radius must be higher than the internal radius." ;
2355 es.type = SALOME::BAD_PARAM;
2356 throw SALOME::SALOME_Exception(es);
2364 { Xcentre = Ucentre ;
2367 else if ( Orient == 2 )
2370 Zcentre = Vcentre ; }
2371 else if ( Orient == 3 )
2372 { Xcentre = Vcentre ;
2374 Zcentre = Ucentre ; }
2375 else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2377 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 60+Orient) ;
2378 myZone->SetPipe( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1., Rayonint ) ;
2380 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2382 //=============================================================================
2383 //=============================================================================
2388 //=============================================================================
2389 //=============================================================================
2390 // Traitement d'une iteration
2391 // etatMenage = 1 : destruction du répertoire d'execution
2392 // modeHOMARD = 1 : adaptation
2393 // != 1 : information avec les options modeHOMARD
2394 // Option1 >0 : appel depuis python
2395 // <0 : appel depuis GUI
2396 // Option2 : multiple de nombres premiers
2397 // 1 : aucune option
2398 // x2 : publication du maillage dans SMESH
2399 //=============================================================================
2400 CORBA::Long HOMARD_Gen_i::Compute(const char* NomIteration, CORBA::Long etatMenage, CORBA::Long modeHOMARD, CORBA::Long Option1, CORBA::Long Option2)
2402 INFOS ( "Compute : traitement de " << NomIteration << ", avec modeHOMARD = " << modeHOMARD << ", Option1 = " << Option1 << ", Option2 = " << Option2 );
2407 // A.1. L'objet iteration
2408 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[NomIteration];
2409 ASSERT(!CORBA::is_nil(myIteration));
2411 // A.2. Controle de la possibilite d'agir
2412 // A.2.1. Etat de l'iteration
2413 int etat = myIteration->GetState();
2414 MESSAGE ( "etat = "<<etat );
2415 // A.2.2. On ne calcule pas l'iteration initiale, ni une iteration deja calculee
2416 if ( modeHOMARD == 1 )
2420 SALOME::ExceptionStruct es;
2421 es.type = SALOME::BAD_PARAM;
2422 es.text = "This iteration is the first of the case and cannot be computed.";
2423 throw SALOME::SALOME_Exception(es);
2426 else if ( ( etat == 2 ) & ( modeHOMARD == 1 ) )
2428 SALOME::ExceptionStruct es;
2429 es.type = SALOME::BAD_PARAM;
2430 es.text = "This iteration is already computed.";
2431 throw SALOME::SALOME_Exception(es);
2435 // A.2.3. On n'analyse pas une iteration non calculee
2440 SALOME::ExceptionStruct es;
2441 es.type = SALOME::BAD_PARAM;
2442 es.text = "This iteration is not computed.";
2443 throw SALOME::SALOME_Exception(es);
2448 // A.3. Numero de l'iteration
2449 // siterp1 : numero de l'iteration a traiter
2451 // siter : numero de l'iteration parent, ou 0 si deja au debut mais cela ne servira pas !
2452 // Ou si information :
2454 int NumeIter = myIteration->GetNumber();
2455 std::string siterp1 ;
2456 std::stringstream saux1 ;
2458 siterp1 = saux1.str() ;
2459 if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
2462 if ( modeHOMARD==1 )
2464 std::stringstream saux0 ;
2465 int iaux = max(0, NumeIter-1) ;
2467 siter = saux0.str() ;
2468 if (NumeIter < 11) { siter = "0" + siter ; }
2471 { siter = siterp1 ; }
2474 const char* nomCas = myIteration->GetCaseName();
2475 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
2476 ASSERT(!CORBA::is_nil(myCase));
2478 // B. Les répertoires
2479 // B.1. Le répertoire courant
2480 std::string nomDirWork = getenv("PWD") ;
2481 // B.2. Le sous-répertoire de l'iteration a traiter
2482 char* DirCompute = ComputeDirManagement(myCase, myIteration, etatMenage);
2483 MESSAGE( ". DirCompute = " << DirCompute );
2485 // C. Le fichier des messages
2486 // C.1. Le deroulement de l'execution de HOMARD
2487 std::string LogFile = DirCompute ;
2488 LogFile += "/Liste" ;
2489 if ( modeHOMARD == 1 ) { LogFile += "." + siter + ".vers." + siterp1 ; }
2491 MESSAGE (". LogFile = " << LogFile);
2492 if ( modeHOMARD == 1 ) { myIteration->SetLogFile(LogFile.c_str()); }
2493 // C.2. Le bilan de l'analyse du maillage
2494 std::string FileInfo = DirCompute ;
2496 if ( modeHOMARD == 1 ) { FileInfo += "apad" ; }
2498 { if ( NumeIter == 0 ) { FileInfo += "info_av" ; }
2499 else { FileInfo += "info_ap" ; }
2501 FileInfo += "." + siterp1 + ".bilan" ;
2502 myIteration->SetFileInfo(FileInfo.c_str());
2504 // D. On passe dans le répertoire de l'iteration a calculer
2505 MESSAGE ( ". On passe dans DirCompute = " << DirCompute );
2508 // E. Les données de l'exécution HOMARD
2509 // E.1. L'objet du texte du fichier de configuration
2510 HomardDriver* myDriver = new HomardDriver(siter, siterp1);
2511 myDriver->TexteInit(DirCompute, LogFile, _Langue);
2513 // E.2. Le maillage associe a l'iteration
2514 const char* NomMesh = myIteration->GetMeshName();
2515 MESSAGE ( ". NomMesh = " << NomMesh );
2516 const char* MeshFile = myIteration->GetMeshFile();
2517 MESSAGE ( ". MeshFile = " << MeshFile );
2519 // E.3. Les données du traitement HOMARD
2521 if ( modeHOMARD == 1 )
2524 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2525 myDriver->TexteMaillage(NomMesh, MeshFile, 1);
2526 codret = ComputeAdap(myCase, myIteration, etatMenage, myDriver, Option1, Option2) ;
2530 InvalideIterInfo(NomIteration);
2531 myDriver->TexteInfo( modeHOMARD, NumeIter ) ;
2533 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2534 myDriver->TexteMaillage(NomMesh, MeshFile, 0);
2535 myDriver->CreeFichierDonn();
2538 // E.4. Ajout des informations liees a l'eventuel suivi de frontiere
2539 int BoundaryOption = DriverTexteBoundary(myCase, myDriver) ;
2541 // E.5. Ecriture du texte dans le fichier
2542 MESSAGE ( ". Ecriture du texte dans le fichier de configuration ; codret = "<<codret );
2544 { myDriver->CreeFichier(); }
2548 int codretexec = 1789 ;
2551 codretexec = myDriver->ExecuteHomard(Option1);
2553 MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
2554 // En mode adaptation, on ajuste l'etat de l'iteration
2555 if ( modeHOMARD == 1 )
2557 if (codretexec == 0) { SetEtatIter(NomIteration,2); }
2558 else { SetEtatIter(NomIteration,1); }
2559 // GERALD -- QMESSAGE BOX
2563 // H. Gestion des resultats
2566 std::string Commentaire ;
2567 // H.1. Le fichier des messages, dans tous les cas
2568 Commentaire = "log" ;
2569 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2570 else { Commentaire += "Info" ; }
2571 PublishFileUnderIteration(NomIteration, LogFile.c_str(), Commentaire.c_str());
2573 // H.2. Si tout s'est bien passe :
2574 if (codretexec == 0)
2576 // H.2.1. Le fichier de bilan
2577 Commentaire = "Summary" ;
2578 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2579 else { Commentaire += "Info" ; }
2580 PublishFileUnderIteration(NomIteration, FileInfo.c_str(), Commentaire.c_str());
2581 // H.2.2. Le fichier de maillage obtenu
2582 if ( modeHOMARD == 1 )
2584 std::stringstream saux0 ;
2585 Commentaire = "Mesh" ;
2586 Commentaire += " " + siterp1 ;
2587 PublishFileUnderIteration(NomIteration, MeshFile, Commentaire.c_str());
2588 if ( Option2 % 2 == 0 ) { PublishResultInSmesh(MeshFile, 1); }
2591 // H.3 Message d'erreur
2592 if (codretexec != 0)
2594 std::string text = "" ;
2595 // Message d'erreur en cas de probleme en adaptation
2596 if ( modeHOMARD == 1 )
2598 text = "Error during the adaptation.\n" ;
2599 bool stopvu = false ;
2600 std::ifstream fichier( LogFile.c_str() );
2601 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
2603 std::string ligne; // variable contenant chaque ligne lue
2604 while ( std::getline( fichier, ligne ) )
2608 { text += ligne+ "\n"; }
2611 int position = ligne.find( "===== HOMARD ===== STOP =====" ) ;
2612 if ( position > 0 ) { stopvu = true ; }
2617 text += "\n\nSee the file " + LogFile + "\n" ;
2619 SALOME::ExceptionStruct es;
2620 es.type = SALOME::BAD_PARAM;
2621 es.text = CORBA::string_dup(text.c_str());
2622 throw SALOME::SALOME_Exception(es);
2624 // En mode information, on force le succes pour pouvoir consulter le fichier log
2625 if ( modeHOMARD != 1 ) { codretexec = 0 ; }
2629 // I. Menage et retour dans le répertoire du cas
2633 MESSAGE ( ". On retourne dans nomDirWork = " << nomDirWork );
2635 CHDIR(nomDirWork.c_str());
2638 // J. Suivi de la frontière CAO
2639 // std::cout << "- codret : " << codret << std::endl;
2640 // std::cout << "- modeHOMARD : " << modeHOMARD << std::endl;
2641 // std::cout << "- BoundaryOption : " << BoundaryOption << std::endl;
2642 // std::cout << "- codretexec : " << codretexec << std::endl;
2645 if ( ( modeHOMARD == 1 ) && ( BoundaryOption % 5 == 0 ) && (codretexec == 0) )
2647 INFOS ( "Suivi de frontière CAO" );
2648 codret = ComputeCAO(myCase, myIteration, Option1, Option2) ;
2654 //=============================================================================
2655 // Calcul d'une iteration : partie spécifique à l'adaptation
2656 //=============================================================================
2657 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)
2659 MESSAGE ( "ComputeAdap avec Option1 = " << Option1 << ", Option2 = " << Option2 );
2664 // Numero de l'iteration
2665 int NumeIter = myIteration->GetNumber();
2666 std::stringstream saux0 ;
2667 saux0 << NumeIter-1 ;
2668 std::string siter = saux0.str() ;
2669 if (NumeIter < 11) { siter = "0" + siter ; }
2671 // A.2. On verifie qu il y a une hypothese (erreur improbable);
2672 const char* nomHypo = myIteration->GetHypoName();
2673 if (std::string(nomHypo) == std::string(""))
2675 SALOME::ExceptionStruct es;
2676 es.type = SALOME::BAD_PARAM;
2677 es.text = "This iteration does not have any associated hypothesis.";
2678 throw SALOME::SALOME_Exception(es);
2681 HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
2682 ASSERT(!CORBA::is_nil(myHypo));
2684 // B. L'iteration parent
2685 const char* nomIterationParent = myIteration->GetIterParentName();
2686 HOMARD::HOMARD_Iteration_var myIterationParent = myStudyContext._mesIterations[nomIterationParent];
2687 ASSERT(!CORBA::is_nil(myIterationParent));
2688 // Si l'iteration parent n'est pas calculee, on le fait (recursivite amont)
2689 if ( myIterationParent->GetState() == 1 )
2692 int codret = Compute(nomIterationParent, etatMenage, iaux, Option1, Option2);
2695 // GERALD -- QMESSAGE BOX
2696 VERIFICATION("Pb au calcul de l'iteration precedente" == 0);
2700 // C. Le sous-répertoire de l'iteration precedente
2701 char* DirComputePa = ComputeDirPaManagement(myCase, myIteration);
2702 MESSAGE( ". DirComputePa = " << DirComputePa );
2704 // D. Les données de l'adaptation HOMARD
2705 // D.1. Le type de conformite
2706 int ConfType = myCase->GetConfType();
2707 MESSAGE ( ". ConfType = " << ConfType );
2709 // D.1. Le type externe
2710 int ExtType = myCase->GetExtType();
2711 MESSAGE ( ". ExtType = " << ExtType );
2713 // D.3. Le maillage de depart
2714 const char* NomMeshParent = myIterationParent->GetMeshName();
2715 MESSAGE ( ". NomMeshParent = " << NomMeshParent );
2716 const char* MeshFileParent = myIterationParent->GetMeshFile();
2717 MESSAGE ( ". MeshFileParent = " << MeshFileParent );
2719 // D.4. Le maillage associe a l'iteration
2720 const char* MeshFile = myIteration->GetMeshFile();
2721 MESSAGE ( ". MeshFile = " << MeshFile );
2722 FILE *file = fopen(MeshFile,"r");
2726 if (etatMenage == 0)
2728 SALOME::ExceptionStruct es;
2729 es.type = SALOME::BAD_PARAM;
2730 std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
2731 es.text = CORBA::string_dup(text.c_str());
2732 throw SALOME::SALOME_Exception(es);
2737 std::string commande = "rm -f " + std::string(MeshFile);
2738 codret = system(commande.c_str());
2741 SALOME::ExceptionStruct es;
2742 es.type = SALOME::BAD_PARAM;
2743 es.text = "The mesh file cannot be deleted.";
2744 throw SALOME::SALOME_Exception(es);
2750 // D.5. Les types de raffinement et de deraffinement
2751 // Les appels corba sont lourds, il vaut mieux les grouper
2752 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
2753 ASSERT(ListTypes->length() == 3);
2754 int TypeAdap = (*ListTypes)[0];
2755 int TypeRaff = (*ListTypes)[1];
2756 int TypeDera = (*ListTypes)[2];
2757 // MESSAGE ( ". TypeAdap = " << TypeAdap << ", TypeRaff = " << TypeRaff << ", TypeDera = " << TypeDera );
2759 // E. Texte du fichier de configuration
2760 // E.1. Incontournables du texte
2761 myDriver->TexteAdap(ExtType);
2763 myDriver->TexteMaillageHOMARD( DirComputePa, siter, iaux ) ;
2764 myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
2765 myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
2767 // E.2. Ajout des informations liees aux zones eventuelles
2768 if ( TypeAdap == 0 )
2769 { DriverTexteZone(myHypo, myDriver) ; }
2771 // E.3. Ajout des informations liees aux champs eventuels
2772 if ( TypeAdap == 1 )
2773 { DriverTexteField(myIteration, myHypo, myDriver) ; }
2775 // E.4. Ajout des informations liees au filtrage eventuel par les groupes
2776 HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
2777 int numberOfGroups = listeGroupes->length();
2778 MESSAGE( ". Filtrage par " << numberOfGroups << " groupes");
2779 if (numberOfGroups > 0)
2781 for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
2783 std::string GroupName = std::string((*listeGroupes)[NumGroup]);
2784 MESSAGE( "... GroupName = " << GroupName );
2785 myDriver->TexteGroup(GroupName);
2789 // E.5. Ajout des informations liees a l'eventuelle interpolation des champs
2790 DriverTexteFieldInterp(myIteration, myHypo, myDriver) ;
2792 // E.6. Ajout des options avancees
2793 int Pyram = myCase->GetPyram();
2794 MESSAGE ( ". Pyram = " << Pyram );
2795 int NivMax = myHypo->GetNivMax();
2796 MESSAGE ( ". NivMax = " << NivMax );
2797 double DiamMin = myHypo->GetDiamMin() ;
2798 MESSAGE ( ". DiamMin = " << DiamMin );
2799 int AdapInit = myHypo->GetAdapInit();
2800 MESSAGE ( ". AdapInit = " << AdapInit );
2801 int ExtraOutput = myHypo->GetExtraOutput();
2802 MESSAGE ( ". ExtraOutput = " << ExtraOutput );
2803 myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, ExtraOutput);
2805 // E.7. Ajout des informations sur le deroulement de l'execution
2806 int MessInfo = myIteration->GetInfoCompute();
2807 MESSAGE ( ". MessInfo = " << MessInfo );
2808 myDriver->TexteInfoCompute(MessInfo);
2812 //=============================================================================
2813 // Calcul d'une iteration : partie spécifique au suivi de frontière CAO
2814 //=============================================================================
2815 CORBA::Long HOMARD_Gen_i::ComputeCAO(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long Option1, CORBA::Long Option2)
2817 MESSAGE ( "ComputeCAO avec Option1 = " << Option1 << ", Option2 = " << Option2 );
2822 // A.2. Le sous-répertoire de l'iteration en cours de traitement
2823 char* DirCompute = myIteration->GetDirName();
2824 // A.3. Le maillage résultat de l'iteration en cours de traitement
2825 char* MeshFile = myIteration->GetMeshFile();
2827 // B. Les données pour FrontTrack
2828 // B.1. Le maillage à modifier
2829 const std::string theInputMedFile = MeshFile;
2830 MESSAGE ( ". theInputMedFile = " << theInputMedFile );
2832 // B.2. Le maillage après modification : fichier identique
2833 const std::string theOutputMedFile = MeshFile ;
2834 MESSAGE ( ". theOutputMedFile = " << theInputMedFile );
2836 // B.3. La liste des fichiers contenant les numéros des noeuds à bouger
2837 std::vector< std::string > theInputNodeFiles ;
2838 MESSAGE ( ". DirCompute = " << DirCompute );
2843 struct dirent *dirp;
2844 dp = opendir(DirCompute);
2845 while ( (dirp = readdir(dp)) != NULL )
2847 std::string file_name(dirp->d_name);
2848 bilan = file_name.find("fr") ;
2849 if ( bilan != string::npos )
2851 std::stringstream filename_total ;
2852 filename_total << DirCompute << "/" << file_name ;
2853 theInputNodeFiles.push_back(filename_total.str()) ;
2858 HANDLE hFind = INVALID_HANDLE_VALUE;
2859 WIN32_FIND_DATA ffd;
2860 hFind = FindFirstFile(DirNameStart, &ffd);
2861 if (INVALID_HANDLE_VALUE != hFind) {
2862 while (FindNextFile(hFind, &ffd) != 0) {
2863 std::string file_name(ffd.cFileName);
2864 bilan = file_name.find("fr") ;
2865 if ( bilan != string::npos )
2867 std::stringstream filename_total ;
2868 filename_total << DirCompute << "/" << file_name ;
2869 theInputNodeFiles.push_back(filename_total.str()) ;
2876 for ( int i = 0; i < icpt; i++ )
2877 { MESSAGE ( ". theInputNodeFiles["<< i << "] = " << theInputNodeFiles[i] ); }
2879 // B.4. Le fichier de la CAO
2880 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
2881 std::string BoundaryName = std::string((*ListBoundaryGroupType)[0]);
2882 MESSAGE ( ". BoundaryName = " << BoundaryName );
2883 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
2884 const std::string theXaoFileName = myBoundary->GetDataFile();
2885 MESSAGE ( ". theXaoFileName = " << theXaoFileName );
2887 // B.5. Parallélisme
2888 bool theIsParallel = false;
2890 // C. Lancement des projections
2891 MESSAGE ( ". Lancement des projections" );
2892 FrontTrack* myFrontTrack = new FrontTrack();
2893 myFrontTrack->track(theInputMedFile, theOutputMedFile, theInputNodeFiles, theXaoFileName, theIsParallel);
2895 // D. Transfert des coordonnées modifiées dans le fichier historique de HOMARD
2896 // On lance une exécution spéciale de HOMARD en attendant de savoir le faire avec MEDCoupling
2897 MESSAGE ( ". Transfert des coordonnées" );
2898 codret = ComputeCAObis(myIteration, Option1, Option2) ;
2902 //=============================================================================
2903 //=============================================================================
2904 // Transfert des coordonnées en suivi de frontière CAO
2905 // Option1 >0 : appel depuis python
2906 // <0 : appel depuis GUI
2907 // Option2 : multiple de nombres premiers
2908 // 1 : aucune option
2909 // x2 : publication du maillage dans SMESH
2910 //=============================================================================
2911 CORBA::Long HOMARD_Gen_i::ComputeCAObis(HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long Option1, CORBA::Long Option2)
2913 MESSAGE ( "ComputeCAObis, avec Option1 = " << Option1 << ", Option2 = " << Option2 );
2918 // A.1. Controle de la possibilite d'agir
2919 // A.1.1. Etat de l'iteration
2920 int etat = myIteration->GetState();
2921 MESSAGE ( "etat = "<<etat );
2922 // A.1.2. L'iteration doit être calculee
2925 SALOME::ExceptionStruct es;
2926 es.type = SALOME::BAD_PARAM;
2927 es.text = "This iteration is not computed.";
2928 throw SALOME::SALOME_Exception(es);
2931 // A.2. Numero de l'iteration
2932 // siterp1 : numero de l'iteration a traiter
2933 int NumeIter = myIteration->GetNumber();
2934 std::string siterp1 ;
2935 std::stringstream saux1 ;
2937 siterp1 = saux1.str() ;
2938 if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
2939 MESSAGE ( "siterp1 = "<<siterp1 );
2942 const char* CaseName = myIteration->GetCaseName();
2943 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[CaseName];
2944 ASSERT(!CORBA::is_nil(myCase));
2946 // A.4. Le sous-répertoire de l'iteration a traiter
2947 char* DirCompute = myIteration->GetDirName();
2948 MESSAGE( ". DirCompute = " << DirCompute );
2950 // C. Le fichier des messages
2951 std::string LogFile = DirCompute ;
2952 LogFile += "/Liste." + siterp1 + ".maj_coords.log" ;
2953 MESSAGE (". LogFile = " << LogFile);
2954 myIteration->SetFileInfo(LogFile.c_str());
2956 // D. On passe dans le répertoire de l'iteration a calculer
2957 MESSAGE ( ". On passe dans DirCompute = " << DirCompute );
2960 // E. Les données de l'exécution HOMARD
2961 // E.1. L'objet du texte du fichier de configuration
2962 HomardDriver* myDriver = new HomardDriver("", siterp1);
2963 myDriver->TexteInit(DirCompute, LogFile, _Langue);
2965 // E.2. Le maillage associe a l'iteration
2966 const char* NomMesh = myIteration->GetMeshName();
2967 MESSAGE ( ". NomMesh = " << NomMesh );
2968 const char* MeshFile = myIteration->GetMeshFile();
2969 MESSAGE ( ". MeshFile = " << MeshFile );
2971 // E.3. Les données du traitement HOMARD
2973 myDriver->TexteMajCoords( NumeIter ) ;
2975 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2976 myDriver->TexteMaillage(NomMesh, MeshFile, 0);
2978 // E.4. Ecriture du texte dans le fichier
2979 MESSAGE ( ". Ecriture du texte dans le fichier de configuration ; codret = "<<codret );
2981 { myDriver->CreeFichier(); }
2985 int codretexec = 1789 ;
2988 codretexec = myDriver->ExecuteHomard(Option1);
2989 MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
2992 // G. Gestion des resultats
2995 // G.1. Le fichier des messages, dans tous les cas
2996 const char* NomIteration = myIteration->GetName();
2997 std::string Commentaire = "logmaj_coords" ;
2998 PublishFileUnderIteration(NomIteration, LogFile.c_str(), Commentaire.c_str());
2999 // G.2 Message d'erreur
3000 if (codretexec != 0)
3002 std::string text = "\n\nSee the file " + LogFile + "\n" ;
3004 SALOME::ExceptionStruct es;
3005 es.type = SALOME::BAD_PARAM;
3006 es.text = CORBA::string_dup(text.c_str());
3007 throw SALOME::SALOME_Exception(es);
3009 // On force le succes pour pouvoir consulter le fichier log
3014 // H. Menage et retour dans le répertoire du cas
3015 if (codret == 0) { delete myDriver; }
3019 //=============================================================================
3020 // Creation d'un nom de sous-répertoire pour l'iteration au sein d'un répertoire parent
3021 // nomrep : nom du répertoire parent
3022 // num : le nom du sous-répertoire est sous la forme 'In', n est >= num
3023 //=============================================================================
3024 char* HOMARD_Gen_i::CreateDirNameIter(const char* nomrep, CORBA::Long num )
3026 MESSAGE ( "CreateDirNameIter : nomrep ="<< nomrep << ", num = "<<num);
3027 // On verifie que le répertoire parent existe
3028 int codret = CHDIR(nomrep) ;
3031 SALOME::ExceptionStruct es;
3032 es.type = SALOME::BAD_PARAM;
3033 es.text = "The directory of the case does not exist.";
3034 throw SALOME::SALOME_Exception(es);
3037 std::string nomDirActuel = getenv("PWD") ;
3038 std::string DirName ;
3039 // On boucle sur tous les noms possibles jusqu'a trouver un nom correspondant a un répertoire inconnu
3040 bool a_chercher = true ;
3041 while ( a_chercher )
3043 // On passe dans le répertoire parent
3046 // On recherche un nom sous la forme Iabc, avec abc representant le numero
3048 if ( num < 100 ) { jaux = 2 ; }
3049 else if ( num < 1000 ) { jaux = 3 ; }
3050 else if ( num < 10000 ) { jaux = 4 ; }
3051 else if ( num < 100000 ) { jaux = 5 ; }
3053 std::ostringstream iaux ;
3054 iaux << std::setw(jaux) << std::setfill('0') << num ;
3055 std::ostringstream DirNameA ;
3056 DirNameA << "I" << iaux.str();
3057 // Si on ne pas peut entrer dans le répertoire, on doit verifier
3058 // que c'est bien un probleme d'absence
3059 if ( CHDIR(DirNameA.str().c_str()) != 0 )
3061 bool existe = false ;
3064 struct dirent *dirp;
3065 dp = opendir(nomrep);
3066 while ( (dirp = readdir(dp)) != NULL )
3068 std::string file_name(dirp->d_name);
3070 HANDLE hFind = INVALID_HANDLE_VALUE;
3071 WIN32_FIND_DATA ffd;
3072 hFind = FindFirstFile(nomrep, &ffd);
3073 if (INVALID_HANDLE_VALUE != hFind) {
3074 while (FindNextFile(hFind, &ffd) != 0) {
3075 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
3076 std::string file_name(ffd.cFileName);
3078 if ( file_name == DirNameA.str() ) { existe = true ; }
3087 DirName = DirNameA.str() ;
3088 a_chercher = false ;
3095 MESSAGE ( "==> DirName = " << DirName);
3096 MESSAGE ( ". On retourne dans nomDirActuel = " << nomDirActuel );
3097 CHDIR(nomDirActuel.c_str());
3098 return CORBA::string_dup( DirName.c_str() );
3100 //=============================================================================
3101 // Calcul d'une iteration : gestion du répertoire de calcul
3102 // Si le sous-répertoire existe :
3103 // etatMenage = 0 : on sort en erreur si le répertoire n'est pas vide
3104 // etatMenage = 1 : on fait le menage du répertoire
3105 // etatMenage = -1 : on ne fait rien
3106 //=============================================================================
3107 char* HOMARD_Gen_i::ComputeDirManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage)
3109 MESSAGE ( "ComputeDirManagement : répertoires pour le calcul" );
3110 // B.2. Le répertoire du cas
3111 const char* nomDirCase = myCase->GetDirName();
3112 MESSAGE ( ". nomDirCase = " << nomDirCase );
3114 // B.3. Le sous-répertoire de l'iteration a calculer, puis le répertoire complet a creer
3115 // B.3.1. Le nom du sous-répertoire
3116 const char* nomDirIt = myIteration->GetDirNameLoc();
3118 // B.3.2. Le nom complet du sous-répertoire
3119 std::stringstream DirCompute ;
3120 DirCompute << nomDirCase << "/" << nomDirIt;
3121 MESSAGE (". DirCompute = " << DirCompute.str() );
3123 // B.3.3. Si le sous-répertoire n'existe pas, on le cree
3124 if (CHDIR(DirCompute.str().c_str()) != 0)
3127 if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
3129 if (_mkdir(DirCompute.str().c_str()) != 0)
3132 // GERALD -- QMESSAGE BOX
3133 std::cerr << "Pb Creation du répertoire DirCompute = " << DirCompute.str() << std::endl;
3134 VERIFICATION("Pb a la creation du répertoire" == 0);
3139 // Le répertoire existe
3140 // On demande de faire le menage de son contenu :
3141 if (etatMenage == 1)
3143 MESSAGE (". Menage du répertoire DirCompute = " << DirCompute.str());
3144 std::string commande = "rm -rf " + DirCompute.str()+"/*" ;
3145 int codret = system(commande.c_str());
3148 // GERALD -- QMESSAGE BOX
3149 std::cerr << ". Menage du répertoire de calcul" << DirCompute.str() << std::endl;
3150 VERIFICATION("Pb au menage du répertoire de calcul" == 0);
3153 // On n'a pas demande de faire le menage de son contenu : on sort en erreur :
3156 if (etatMenage == 0)
3160 struct dirent *dirp;
3161 dp = opendir(DirCompute.str().c_str());
3163 while ((dirp = readdir(dp)) != NULL && result )
3165 std::string file_name(dirp->d_name);
3166 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
3170 HANDLE hFind = INVALID_HANDLE_VALUE;
3171 WIN32_FIND_DATA ffd;
3172 hFind = FindFirstFile(DirCompute.str().c_str(), &ffd);
3174 if (INVALID_HANDLE_VALUE != hFind) {
3175 while (FindNextFile(hFind, &ffd) != 0) {
3176 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
3177 std::string file_name(ffd.cFileName);
3178 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
3183 if ( result == false)
3185 SALOME::ExceptionStruct es;
3186 es.type = SALOME::BAD_PARAM;
3187 std::string text = "Directory : " + DirCompute.str() + " is not empty";
3188 es.text = CORBA::string_dup(text.c_str());
3189 throw SALOME::SALOME_Exception(es);
3190 VERIFICATION("Directory is not empty" == 0);
3196 return CORBA::string_dup( DirCompute.str().c_str() );
3198 //=============================================================================
3199 // Calcul d'une iteration : gestion du répertoire de calcul de l'iteration parent
3200 //=============================================================================
3201 char* HOMARD_Gen_i::ComputeDirPaManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration)
3203 MESSAGE ( "ComputeDirPaManagement : répertoires pour le calcul" );
3204 // Le répertoire du cas
3205 const char* nomDirCase = myCase->GetDirName();
3206 MESSAGE ( ". nomDirCase = " << nomDirCase );
3208 // Le sous-répertoire de l'iteration precedente
3210 const char* nomIterationParent = myIteration->GetIterParentName();
3211 HOMARD::HOMARD_Iteration_var myIterationParent = myStudyContext._mesIterations[nomIterationParent];
3212 const char* nomDirItPa = myIterationParent->GetDirNameLoc();
3213 std::stringstream DirComputePa ;
3214 DirComputePa << nomDirCase << "/" << nomDirItPa;
3215 MESSAGE( ". nomDirItPa = " << nomDirItPa);
3216 MESSAGE( ". DirComputePa = " << DirComputePa.str() );
3218 return CORBA::string_dup( DirComputePa.str().c_str() );
3220 //=============================================================================
3221 // Calcul d'une iteration : ecriture des zones dans le fichier de configuration
3222 //=============================================================================
3223 void HOMARD_Gen_i::DriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3225 MESSAGE ( "... DriverTexteZone" );
3226 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
3227 int numberOfZonesx2 = ListZone->length();
3230 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
3232 std::string ZoneName = std::string((*ListZone)[iaux]);
3233 MESSAGE ( "... ZoneName = " << ZoneName);
3234 HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
3235 ASSERT(!CORBA::is_nil(myZone));
3237 int ZoneType = myZone->GetType();
3238 std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
3239 int TypeUse = atoi( TypeUsestr.c_str() );
3240 MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
3241 NumZone = iaux/2 + 1 ;
3242 HOMARD::double_array* zone = myZone->GetCoords();
3243 if ( ZoneType == 2 || ( ZoneType>=11 && ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
3244 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.); }
3245 else if ( ZoneType == 4 ) // Cas d une sphere
3246 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.); }
3247 else if ( ZoneType == 5 || ( ZoneType>=31 && ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
3248 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.); }
3249 else if ( ZoneType == 7 || ( ZoneType>=61 && ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
3250 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]); }
3251 else { VERIFICATION("ZoneType est incorrect." == 0) ; }
3256 //=============================================================================
3257 // Calcul d'une iteration : ecriture des champs dans le fichier de configuration
3258 //=============================================================================
3259 void HOMARD_Gen_i::DriverTexteField(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3261 MESSAGE ( "... DriverTexteField" );
3262 // Le fichier du champ
3263 char* FieldFile = myIteration->GetFieldFile();
3264 MESSAGE ( ". FieldFile = " << FieldFile );
3265 if (strlen(FieldFile) == 0)
3267 // GERALD -- QMESSAGE BOX
3268 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
3269 VERIFICATION("The file for the field is not given." == 0);
3271 // Les caracteristiques d'instants du champ de pilotage
3272 int TimeStep = myIteration->GetTimeStep();
3273 MESSAGE( ". TimeStep = " << TimeStep );
3274 int Rank = myIteration->GetRank();
3275 MESSAGE( ". Rank = " << Rank );
3276 // Les informations sur les champs
3277 HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
3279 const char* FieldName = aInfosHypo->FieldName;
3281 int TypeThR = aInfosHypo->TypeThR;
3282 double ThreshR = aInfosHypo->ThreshR;
3283 int TypeThC = aInfosHypo->TypeThC;
3284 double ThreshC = aInfosHypo->ThreshC;
3285 // Saut entre mailles ou non ?
3286 int UsField = aInfosHypo->UsField;
3287 MESSAGE( ". UsField = " << UsField );
3288 // L'usage des composantes
3289 int UsCmpI = aInfosHypo->UsCmpI;
3290 MESSAGE( ". UsCmpI = " << UsCmpI );
3292 myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
3295 HOMARD::listeComposantsHypo* mescompo = myHypo->GetComps();
3296 int numberOfCompos = mescompo->length();
3297 MESSAGE( ". numberOfCompos = " << numberOfCompos );
3298 for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
3300 std::string nomCompo = std::string((*mescompo)[NumeComp]);
3301 MESSAGE( "... nomCompo = " << nomCompo );
3302 myDriver->TexteCompo(NumeComp, nomCompo);
3306 //=============================================================================
3307 // Calcul d'une iteration : ecriture des frontieres dans le fichier de configuration
3308 // On ecrit dans l'ordre :
3309 // 1. la definition des frontieres
3310 // 2. les liens avec les groupes
3311 // 3. un entier resumant le type de comportement pour les frontieres
3312 //=============================================================================
3313 int HOMARD_Gen_i::DriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, HomardDriver* myDriver)
3315 MESSAGE ( "... DriverTexteBoundary" );
3316 // 1. Recuperation des frontieres
3317 std::list<std::string> ListeBoundaryTraitees ;
3318 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
3319 int numberOfitems = ListBoundaryGroupType->length();
3320 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
3321 int BoundaryOption = 1 ;
3322 // 2. Parcours des frontieres pour ecrire leur description
3323 int NumBoundaryAnalytical = 0 ;
3324 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3326 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3327 MESSAGE ( "... BoundaryName = " << BoundaryName);
3328 // 2.1. La frontiere a-t-elle deja ete ecrite ?
3329 // Cela arrive quand elle est liee a plusieurs groupes. Il ne faut l'ecrire que la premiere fois
3331 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
3332 while (it != ListeBoundaryTraitees.end())
3334 MESSAGE ( "..... BoundaryNameTraitee = " << *it);
3335 if ( BoundaryName == *it ) { A_faire = 0 ; }
3338 // 2.2. Ecriture de la frontiere
3341 // 2.2.1. Caracteristiques de la frontiere
3342 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
3343 ASSERT(!CORBA::is_nil(myBoundary));
3344 int BoundaryType = myBoundary->GetType();
3345 MESSAGE ( "... BoundaryType = " << BoundaryType );
3346 // 2.2.2. Ecriture selon le type
3347 // 2.2.2.1. Cas d une frontiere CAO
3348 if (BoundaryType == -1)
3350 // const char* CAOFile = myBoundary->GetDataFile() ;
3351 // MESSAGE ( ". CAOFile = " << CAOFile );
3352 if ( BoundaryOption % 5 != 0 ) { BoundaryOption = BoundaryOption*5 ; }
3354 // 2.2.2.2. Cas d une frontiere discrete
3355 else if (BoundaryType == 0)
3357 const char* MeshName = myBoundary->GetMeshName() ;
3358 MESSAGE ( ". MeshName = " << MeshName );
3359 const char* MeshFile = myBoundary->GetDataFile() ;
3360 MESSAGE ( ". MeshFile = " << MeshFile );
3361 myDriver->TexteBoundaryDi( MeshName, MeshFile);
3362 if ( BoundaryOption % 2 != 0 ) { BoundaryOption = BoundaryOption*2 ; }
3364 // 2.2.2.3. Cas d une frontiere analytique
3367 NumBoundaryAnalytical++ ;
3368 HOMARD::double_array* coor = myBoundary->GetCoords();
3369 if (BoundaryType == 1) // Cas d un cylindre
3371 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3372 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3374 else if (BoundaryType == 2) // Cas d une sphere
3376 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0., 0.);
3377 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3379 else if (BoundaryType == 3) // Cas d un cone defini par un axe et un angle
3381 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3382 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3384 else if (BoundaryType == 4) // Cas d un cone defini par les 2 rayons
3386 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3387 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3389 else if (BoundaryType == 5) // Cas d un tore
3391 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3392 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3395 // 2.2.3. Memorisation du traitement
3396 ListeBoundaryTraitees.push_back( BoundaryName );
3399 // 3. Parcours des frontieres pour ecrire les liens avec les groupes
3400 NumBoundaryAnalytical = 0 ;
3401 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3403 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3404 MESSAGE ( "... BoundaryName = " << BoundaryName);
3405 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
3406 ASSERT(!CORBA::is_nil(myBoundary));
3407 int BoundaryType = myBoundary->GetType();
3408 MESSAGE ( "... BoundaryType = " << BoundaryType );
3409 // 3.1. Recuperation du nom du groupe
3410 std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
3411 MESSAGE ( "... GroupName = " << GroupName);
3412 // 3.2. Cas d une frontiere CAO
3413 if ( BoundaryType == -1 )
3415 if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryCAOGr ( GroupName ) ; }
3417 // 3.3. Cas d une frontiere discrete
3418 else if ( BoundaryType == 0 )
3420 if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
3422 // 3.4. Cas d une frontiere analytique
3425 NumBoundaryAnalytical++ ;
3426 myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
3429 // 4. Ecriture de l'option finale
3430 myDriver->TexteBoundaryOption(BoundaryOption);
3432 return BoundaryOption ;
3434 //=============================================================================
3435 // Calcul d'une iteration : ecriture des interpolations dans le fichier de configuration
3436 //=============================================================================
3437 void HOMARD_Gen_i::DriverTexteFieldInterp(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3439 MESSAGE ( "... DriverTexteFieldInterp" );
3440 int TypeFieldInterp = myHypo->GetTypeFieldInterp();
3441 MESSAGE ( "... TypeFieldInterp = " << TypeFieldInterp);
3442 if (TypeFieldInterp != 0)
3444 // Le fichier des champs
3445 char* FieldFile = myIteration->GetFieldFile();
3446 MESSAGE ( ". FieldFile = " << FieldFile );
3447 if (strlen(FieldFile) == 0)
3449 // GERALD -- QMESSAGE BOX
3450 VERIFICATION("The file for the field is not given." == 0);
3453 const char* MeshFile = myIteration->GetMeshFile();
3454 myDriver->TexteFieldInterp(FieldFile, MeshFile);
3457 // Interpolation de tous les champs
3458 if ( TypeFieldInterp == 1 )
3460 myDriver->TexteFieldInterpAll();
3462 // Interpolation de certains champs
3463 else if (TypeFieldInterp == 2)
3465 // Les champs et leurs instants pour l'iteration
3466 HOMARD::listeFieldInterpTSRsIter* ListFieldTSR = myIteration->GetFieldInterpsTimeStepRank();
3467 int numberOfFieldsx3 = ListFieldTSR->length();
3468 MESSAGE( ". pour iteration, numberOfFields = " << numberOfFieldsx3/3 );
3469 // Les champs pour l'hypothese
3470 HOMARD::listeFieldInterpsHypo* ListField = myHypo->GetFieldInterps();
3471 int numberOfFieldsx2 = ListField->length();
3472 MESSAGE( ". pour hypothese, numberOfFields = " << numberOfFieldsx2/2 );
3473 // On parcourt tous les champs de l'hypothese
3475 for (int iaux = 0; iaux< numberOfFieldsx2; iaux++)
3478 std::string FieldName = std::string((*ListField)[iaux]) ;
3479 // Le type d'interpolation
3480 std::string TypeInterpstr = std::string((*ListField)[iaux+1]) ;
3481 MESSAGE( "... FieldName = " << FieldName << ", TypeInterp = " << TypeInterpstr );
3482 // On cherche ?? savoir si des instants ont ??t?? pr??cis??s pour cette it??ration
3484 for (int jaux = 0; jaux< numberOfFieldsx3; jaux++)
3487 std::string FieldName2 = std::string((*ListFieldTSR)[jaux]) ;
3488 MESSAGE( "..... FieldName2 = " << FieldName2 );
3489 // Quand c'est le bon champ, on ecrit le pas de temps
3490 if ( FieldName == FieldName2 )
3494 std::string TimeStepstr = std::string((*ListFieldTSR)[jaux+1]) ;
3495 // Le numero d'ordre
3496 std::string Rankstr = std::string((*ListFieldTSR)[jaux+2]) ;
3497 MESSAGE( "..... TimeStepstr = " << TimeStepstr <<", Rankstr = "<<Rankstr );
3499 int TimeStep = atoi( TimeStepstr.c_str() );
3500 int Rank = atoi( Rankstr.c_str() );
3501 myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, TimeStep, Rank);
3505 // Si aucun instant n'a été défini
3509 myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, -1, -1);
3517 //===========================================================================
3518 //===========================================================================
3521 //===========================================================================
3522 //===========================================================================
3524 //===========================================================================
3525 //===========================================================================
3526 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::SObject_ptr theSObject,
3527 CORBA::Object_ptr theObject,
3528 const char* theName)
3530 MESSAGE("PublishInStudy pour " << theName);
3531 SALOMEDS::SObject_var aResultSO;
3532 if (CORBA::is_nil(myStudy))
3534 SALOME::ExceptionStruct es;
3535 es.type = SALOME::BAD_PARAM;
3536 es.text = "Invalid study context";
3537 throw SALOME::SALOME_Exception(es);
3541 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
3542 // Rq : Iteration est publiee ailleurs
3543 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
3544 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(theObject);
3545 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
3546 HOMARD::HOMARD_YACS_var aYACS = HOMARD::HOMARD_YACS::_narrow(theObject);
3547 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
3551 // Controle de la non publication d'un objet de meme nom
3552 if ( (!aBoundary->_is_nil()) || (!aHypo->_is_nil()) || (!aYACS->_is_nil()) || (!aZone->_is_nil()) )
3554 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(theName, ComponentDataType());
3555 if (listSO->length() >= 1)
3557 MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
3558 aResultSO = listSO[0];
3559 return aResultSO._retn();
3563 // Caracteristiques de l'etude
3564 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
3565 aStudyBuilder->NewCommand();
3566 if(!aBoundary->_is_nil())
3567 aResultSO = PublishBoundaryInStudy(aStudyBuilder, aBoundary, theName);
3568 else if(!aCase->_is_nil())
3569 aResultSO = PublishCaseInStudy(aStudyBuilder, aCase, theName);
3570 else if(!aHypo->_is_nil())
3571 aResultSO = PublishHypotheseInStudy(aStudyBuilder, aHypo, theName);
3572 else if(!aYACS->_is_nil())
3573 aResultSO = PublishYACSInStudy(aStudyBuilder, aYACS, theName);
3574 else if(!aZone->_is_nil())
3575 aResultSO = PublishZoneInStudy(aStudyBuilder, aZone, theName);
3577 aStudyBuilder->CommitCommand();
3579 return aResultSO._retn();
3581 //=============================================================================
3582 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy( SALOMEDS::StudyBuilder_var aStudyBuilder,
3583 HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
3585 MESSAGE("PublishBoundaryStudy pour "<<theName);
3586 SALOMEDS::SObject_var aResultSO;
3588 // Caracteristique de la Boundary
3589 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[theName];
3591 // On recupere le module pere dans l etude
3592 SALOMEDS::SComponent_var theFatherHomard = myStudy->FindComponent(ComponentDataType());
3593 if (theFatherHomard->_is_nil())
3595 MESSAGE("theFatherHomard->_is_nil()");
3596 return aResultSO._retn();
3599 // On ajoute la categorie des boundarys dans l etude si necessaire
3600 if ( _tag_boun == 0 )
3603 _tag_boun = _tag_gene ;
3605 MESSAGE("PublishBoundaryInStudy _tag_gene = "<<_tag_gene << ", _tag_boun = "<<_tag_boun );
3606 SALOMEDS::SObject_var aSObject;
3607 if (!theFatherHomard->FindSubObject(_tag_boun, aSObject))
3609 MESSAGE("Ajout de la categorie des boundarys");
3610 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_boun);
3611 PublishInStudyAttr(aStudyBuilder, aSObject, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
3613 else { MESSAGE("La categorie des boundarys existe deja."); }
3615 CORBA::Long BoundaryType = myBoundary->GetType();
3616 // MESSAGE("BoundaryType : "<<BoundaryType);
3619 switch (BoundaryType)
3622 { value = "BoundaryCAOHomard" ;
3623 icone = "geometry.png" ;
3627 { value = "BoundaryDiHomard" ;
3628 icone = "mesh_tree_mesh.png" ;
3632 { value = "BoundaryAnHomard" ;
3633 icone = "cylinderpointvector_2.png" ;
3637 { value = "BoundaryAnHomard" ;
3638 icone = "spherepoint_2.png" ;
3642 { value = "BoundaryAnHomard" ;
3643 icone = "conepointvector.png" ;
3647 { value = "BoundaryAnHomard" ;
3648 icone = "conedxyz.png" ;
3652 { value = "BoundaryAnHomard" ;
3653 icone = "toruspointvector.png" ;
3657 aResultSO = aStudyBuilder->NewObject(aSObject);
3658 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value.c_str(), icone.c_str(), _orb->object_to_string(theObject));
3659 return aResultSO._retn();
3661 //=============================================================================
3662 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::StudyBuilder_var aStudyBuilder,
3663 HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
3665 MESSAGE("PublishCaseInStudy pour "<<theName);
3666 SALOMEDS::SObject_var aResultSO;
3668 if (CORBA::is_nil(theObject)) {
3669 MESSAGE("HOMARD_Gen_i::theObject->_is_nil()");
3670 return aResultSO._retn();
3672 if (myStudy->_is_nil()) {
3673 MESSAGE("HOMARD_Gen_i::myStudy->_is_nil()");
3674 return aResultSO._retn();
3677 // On recupere le module pere dans l etude
3678 SALOMEDS::SComponent_var theFatherHomard = myStudy->FindComponent(ComponentDataType());
3679 if (theFatherHomard->_is_nil())
3681 MESSAGE("theFatherHomard->_is_nil()");
3682 return aResultSO._retn();
3686 MESSAGE("PublishCaseInStudy _tag_gene = "<<_tag_gene );
3687 aResultSO = aStudyBuilder->NewObject(theFatherHomard);
3688 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
3689 _orb->object_to_string(theObject) ) ;
3691 return aResultSO._retn();
3693 //=============================================================================
3694 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::StudyBuilder_var aStudyBuilder,
3695 HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
3697 MESSAGE("PublishHypotheseInStudy pour "<<theName);
3698 SALOMEDS::SObject_var aResultSO;
3700 // On recupere le module pere dans l etude
3701 // On ajoute la categorie des hypotheses dans l etude si necessaire
3702 SALOMEDS::SComponent_var theFatherHomard = myStudy->FindComponent(ComponentDataType());
3703 if (theFatherHomard->_is_nil())
3705 MESSAGE("theFatherHomard->_is_nil()");
3706 return aResultSO._retn();
3709 // On ajoute la categorie des hypotheses dans l etude si necessaire
3710 SALOMEDS::SObject_var aSObject;
3711 if ( _tag_hypo == 0 )
3714 _tag_hypo = _tag_gene ;
3716 MESSAGE("PublishHypotheseInStudy _tag_gene = "<<_tag_gene << ", _tag_hypo = "<<_tag_hypo );
3717 if (!theFatherHomard->FindSubObject(_tag_hypo, aSObject))
3719 MESSAGE("Ajout de la categorie des hypotheses");
3720 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_hypo);
3721 PublishInStudyAttr(aStudyBuilder, aSObject, "Hypothesis", "HypoList", "hypotheses.png", NULL);
3723 else { MESSAGE("La categorie des hypotheses existe deja."); }
3725 // Creation du resultat dans l'etude
3726 aResultSO = aStudyBuilder->NewObject(aSObject);
3727 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
3729 return aResultSO._retn();
3731 //=============================================================================
3732 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishYACSInStudy(SALOMEDS::StudyBuilder_var aStudyBuilder,
3733 HOMARD::HOMARD_YACS_ptr theObject, const char* theName)
3735 MESSAGE("PublishYACSInStudy pour "<<theName);
3736 SALOMEDS::SObject_var aResultSO;
3738 // On recupere le module pere dans l etude
3739 // On ajoute la categorie des schemas YACS dans l etude si necessaire
3740 SALOMEDS::SComponent_var theFatherHomard = myStudy->FindComponent(ComponentDataType());
3741 if (theFatherHomard->_is_nil())
3743 MESSAGE("theFatherHomard->_is_nil()");
3744 return aResultSO._retn();
3746 // On ajoute la categorie des schemas YACS dans l etude si necessaire
3747 if ( _tag_yacs == 0 )
3750 _tag_yacs = _tag_gene ;
3752 MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_yacs = "<<_tag_yacs );
3753 SALOMEDS::SObject_var aSObject;
3754 if (!theFatherHomard->FindSubObject(_tag_yacs, aSObject))
3756 MESSAGE("Ajout de la categorie des schemas YACS");
3757 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_yacs);
3758 PublishInStudyAttr(aStudyBuilder, aSObject, "YACS", "YACSList", "full_view.png", NULL);
3760 else { MESSAGE("La categorie des schemas YACS existe deja."); }
3762 // Creation du resultat dans l'etude
3763 aResultSO = aStudyBuilder->NewObject(aSObject);
3764 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "YACSHomard", "schema.png", _orb->object_to_string(theObject) ) ;
3766 return aResultSO._retn();
3769 //=============================================================================
3770 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::StudyBuilder_var aStudyBuilder,
3771 HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
3773 MESSAGE("PublishZoneStudy pour "<<theName);
3774 SALOMEDS::SObject_var aResultSO;
3775 if (CORBA::is_nil(theObject))
3777 MESSAGE("PublishZoneInStudy : theObject->_is_nil()");
3778 return aResultSO._retn();
3780 if (myStudy->_is_nil())
3782 MESSAGE("PublishZoneInStudy : myStudy->_is_nil()");
3783 return aResultSO._retn();
3785 SALOMEDS::SComponent_var theFatherHomard = myStudy->FindComponent(ComponentDataType());
3786 if (theFatherHomard->_is_nil())
3788 MESSAGE("PublishZoneInStudy : theFatherHomard->_is_nil()");
3789 return aResultSO._retn();
3792 // Caracteristique de la zone
3793 HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[theName];
3794 CORBA::Long ZoneType = myZone->GetType();
3796 // On ajoute la categorie des zones dans l etude si necessaire
3797 if ( _tag_zone == 0 )
3800 _tag_zone = _tag_gene ;
3802 MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_zone = "<<_tag_zone );
3803 SALOMEDS::SObject_var aSObject;
3804 if (!theFatherHomard->FindSubObject(_tag_zone, aSObject))
3806 MESSAGE("Ajout de la categorie des zones");
3807 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_zone);
3808 PublishInStudyAttr(aStudyBuilder, aSObject, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
3810 else { MESSAGE("La categorie des zones existe deja."); }
3812 aResultSO = aStudyBuilder->NewObject(aSObject);
3821 { icone = "boxdxy_2.png" ;
3825 { icone = "boxdxyz_2.png" ;
3833 { icone = "disk_2.png" ;
3837 { icone = "spherepoint_2.png" ;
3841 { icone = "cylinderpointvector_2.png" ;
3849 { icone = "diskwithhole_2.png" ;
3853 { icone = "pipe_2.png" ;
3857 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone.c_str(), _orb->object_to_string(theObject) ) ;
3859 return aResultSO._retn();
3861 //===========================================================================
3862 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
3863 SALOMEDS::SObject_var aResultSO,
3864 const char* name, const char* comment, const char* icone, const char* ior)
3866 MESSAGE("PublishInStudyAttr pour name = "<<name<<", comment = "<<comment);
3867 // MESSAGE("icone = "<<icone);
3868 // MESSAGE("ior = "<<ior);
3869 SALOMEDS::GenericAttribute_var anAttr ;
3873 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
3874 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
3875 aNameAttrib->SetValue(name);
3878 // Ajout du commentaire
3879 if ( comment != NULL )
3881 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
3882 SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
3883 aCommentAttrib->SetValue(comment);
3887 if ( icone != NULL )
3889 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
3890 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
3891 aPixmap->SetPixMap(icone);
3897 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
3898 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3899 anIOR->SetValue(ior);
3903 //=====================================================================================
3904 void HOMARD_Gen_i::PublishBoundaryUnderCase(const char* CaseName, const char* BoundaryName)
3906 MESSAGE ( "PublishBoundaryUnderCase : CaseName = " << CaseName << ", BoundaryName= " << BoundaryName );
3908 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[CaseName];
3909 ASSERT(!CORBA::is_nil(myCase));
3910 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3911 ASSERT(!CORBA::is_nil(aCaseSO));
3913 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
3914 ASSERT(!CORBA::is_nil(myBoundary));
3915 SALOMEDS::SObject_var aBoundarySO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myBoundary)));
3916 ASSERT(!CORBA::is_nil(aBoundarySO));
3918 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
3920 aStudyBuilder->NewCommand();
3922 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aCaseSO);
3923 aStudyBuilder->Addreference(aSubSO, aBoundarySO);
3924 // aStudyBuilder->RemoveReference(aSubSO);
3926 aStudyBuilder->CommitCommand();
3929 //=====================================================================================
3930 void HOMARD_Gen_i::PublishCaseUnderYACS(const char* nomYACS, const char* CaseName)
3932 MESSAGE ( "PublishCaseUnderYACS : nomYACS = " << nomYACS << ", CaseName= " << CaseName );
3934 HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
3935 ASSERT(!CORBA::is_nil(myYACS));
3936 SALOMEDS::SObject_var aYACSSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3937 ASSERT(!CORBA::is_nil(aYACSSO));
3939 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[CaseName];
3940 ASSERT(!CORBA::is_nil(myCase));
3941 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3942 ASSERT(!CORBA::is_nil(aCaseSO));
3944 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
3946 aStudyBuilder->NewCommand();
3948 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3949 aStudyBuilder->Addreference(aSubSO, aCaseSO);
3951 aStudyBuilder->CommitCommand();
3954 //=============================================================================
3955 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long Option)
3956 // Option = 0 : fichier issu d'une importation
3957 // Option = 1 : fichier issu d'une execution HOMARD
3959 MESSAGE( "PublishResultInSmesh " << NomFich << ", avec Option = " << Option);
3960 if (CORBA::is_nil(myStudy))
3962 SALOME::ExceptionStruct es;
3963 es.type = SALOME::BAD_PARAM;
3964 es.text = "Invalid study context";
3965 throw SALOME::SALOME_Exception(es);
3969 // Le module SMESH est-il actif ?
3970 SALOMEDS::SObject_var aSmeshSO = myStudy->FindComponent("SMESH");
3972 if (!CORBA::is_nil(aSmeshSO))
3974 // On verifie que le fichier n est pas deja publie
3975 SALOMEDS::ChildIterator_var aIter = myStudy->NewChildIterator(aSmeshSO);
3976 for (; aIter->More(); aIter->Next())
3978 SALOMEDS::SObject_var aSO = aIter->Value();
3979 SALOMEDS::GenericAttribute_var aGAttr;
3980 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3982 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3983 CORBA::String_var value=anAttr->Value();
3984 if (strcmp((const char*)value,NomFich) == 0)
3986 MESSAGE ( "PublishResultInSmesh : le fichier " << NomFich << " est deja publie." );
3987 // Pour un fichier importe, on ne republie pas
3988 if ( Option == 0 ) { return; }
3989 // Pour un fichier calcule, on commence par faire la depublication
3992 MESSAGE ( "PublishResultInSmesh : depublication" );
3993 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3994 CORBA::String_var value2=anAttr2->Value();
3995 std::string MeshName = string(value2) ;
3996 MESSAGE ( "PublishResultInSmesh : depublication de " << MeshName );
3997 DeleteResultInSmesh(NomFich, MeshName) ;
4004 // On enregistre le fichier
4005 MESSAGE( "Enregistrement du fichier");
4006 SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
4007 SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
4008 ASSERT(!CORBA::is_nil(aSmeshEngine));
4009 aSmeshEngine->UpdateStudy();
4010 SMESH::DriverMED_ReadStatus theStatus;
4011 //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
4013 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
4014 SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
4015 for (int i = 0; i < mesMaillages->length(); i++)
4017 MESSAGE( ". Mise a jour des attributs du maillage");
4018 SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
4019 SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
4020 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
4021 SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
4022 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
4023 anAttr->SetValue(NomFich);
4024 SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
4025 SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
4027 if ( Option == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
4028 else { icone = "mesh_tree_mesh.png" ; }
4029 anAttr2->SetPixMap( icone );
4033 //=============================================================================
4034 void HOMARD_Gen_i::DeleteResultInSmesh(std::string NomFich, std::string MeshName)
4036 MESSAGE ("DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich );
4037 if (CORBA::is_nil(myStudy))
4039 SALOME::ExceptionStruct es;
4040 es.type = SALOME::BAD_PARAM;
4041 es.text = "Invalid study context";
4042 throw SALOME::SALOME_Exception(es);
4046 // Le module SMESH est-il actif ?
4047 SALOMEDS::SObject_var aSmeshSO = myStudy->FindComponent("SMESH");
4049 if (CORBA::is_nil(aSmeshSO))
4053 // On verifie que le fichier est deja publie
4054 SALOMEDS::StudyBuilder_var myBuilder = myStudy->NewBuilder();
4055 SALOMEDS::ChildIterator_var aIter = myStudy->NewChildIterator(aSmeshSO);
4056 for (; aIter->More(); aIter->Next())
4058 SALOMEDS::SObject_var aSO = aIter->Value();
4059 SALOMEDS::GenericAttribute_var aGAttr;
4060 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
4062 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
4063 CORBA::String_var value=anAttr->Value();
4064 if (strcmp((const char*)value,NomFich.c_str()) == 0)
4066 if (aSO->FindAttribute(aGAttr,"AttributeName"))
4068 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
4069 CORBA::String_var value2=anAttr2->Value();
4070 if (strcmp((const char*)value2,MeshName.c_str()) == 0)
4072 myBuilder->RemoveObjectWithChildren( aSO ) ;
4080 //=============================================================================
4081 void HOMARD_Gen_i::PublishMeshIterInSmesh(const char* NomIter)
4083 MESSAGE( "PublishMeshIterInSmesh " << NomIter);
4084 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[NomIter];
4086 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
4087 if (CORBA::is_nil(myIteration))
4089 SALOME::ExceptionStruct es;
4090 es.type = SALOME::BAD_PARAM;
4091 es.text = "Invalid iterationStudy Object";
4092 throw SALOME::SALOME_Exception(es);
4095 const char* MeshFile = myIteration->GetMeshFile() ;
4096 const char* MeshName = myIteration->GetMeshName() ;
4097 CORBA::Long Option = -1 ;
4098 int etat = myIteration->GetState();
4099 // Iteration initiale
4100 if ( etat <= 0 ) { Option = 0 ; }
4101 // ou iteration calculee
4102 else if ( etat == 2 ) { Option = 1 ; }
4103 // Publication effective apres menage eventuel
4106 DeleteResultInSmesh(MeshFile, MeshName) ;
4107 PublishResultInSmesh(MeshFile, Option) ;
4111 //=============================================================================
4112 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
4114 // MESSAGE ("PublishFileUnderIteration pour l'iteration " << NomIter << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
4115 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[NomIter];
4117 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
4118 if (CORBA::is_nil(myIteration))
4120 SALOME::ExceptionStruct es;
4121 es.type = SALOME::BAD_PARAM;
4122 es.text = "Invalid iterationStudy Object";
4123 throw SALOME::SALOME_Exception(es);
4127 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
4129 aStudyBuilder->NewCommand();
4131 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
4132 // Pour les fichiers med, on affiche une icone de maillage
4133 // Pour les fichiers qui sont du texte, on affiche une icone de fichier texte 'texte'
4134 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
4136 std::string ior = " " ;
4137 if ( Commentaire[0] == 'M' )
4138 { icone = "med.png" ; }
4140 { icone = "texte_2.png" ; }
4141 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
4143 aStudyBuilder->CommitCommand();
4146 //=============================================================================
4147 void HOMARD_Gen_i::PublishFileUnderYACS(const char* nomYACS, const char* NomFich, const char* Commentaire)
4149 // MESSAGE ("PublishFileUnderYACS pour le schema " << nomYACS << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
4150 HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
4152 SALOMEDS::SObject_var aYACSSO=SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
4153 if (CORBA::is_nil(myYACS))
4155 SALOME::ExceptionStruct es;
4156 es.type = SALOME::BAD_PARAM;
4157 es.text = "Invalid YACSStudy Object";
4158 throw SALOME::SALOME_Exception(es);
4162 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
4164 aStudyBuilder->NewCommand();
4166 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
4167 std::string icone = "texte_2.png" ;
4168 std::string ior = " " ;
4169 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
4171 aStudyBuilder->CommitCommand();
4174 //=============================================================================
4175 //=============================================================================
4177 //=============================================================================
4178 //=============================================================================
4179 //=============================================================================
4180 // Creation d'un schema YACS
4181 // nomCas : nom du cas a traiter
4182 // FileName : nom du fichier contenant le script de lancement du calcul
4183 // DirName : le répertoire de lancement des calculs du schéma
4184 //=============================================================================
4185 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::CreateYACSSchema (const char* nomYACS, const char* nomCas, const char* ScriptFile, const char* DirName, const char* MeshFile)
4187 INFOS ( "CreateYACSSchema : Schema YACS " << nomYACS );
4188 INFOS ( ". nomCas : " << nomCas);
4189 INFOS ( ". ScriptFile : " << ScriptFile);
4190 INFOS ( ". DirName : " << DirName);
4191 INFOS ( ". MeshFile : " << MeshFile);
4193 // A. Controle du nom :
4194 if ((myStudyContext._mesYACSs).find(nomYACS) != (myStudyContext._mesYACSs).end())
4196 SALOME::ExceptionStruct es;
4197 es.type = SALOME::BAD_PARAM;
4198 es.text = "This schema YACS has already been defined.";
4199 throw SALOME::SALOME_Exception(es);
4203 // B. Creation de l'objet
4204 HOMARD::HOMARD_YACS_var myYACS = newYACS();
4205 if (CORBA::is_nil(myYACS))
4207 SALOME::ExceptionStruct es;
4208 es.type = SALOME::BAD_PARAM;
4209 es.text = "Unable to create the schema YACS";
4210 throw SALOME::SALOME_Exception(es);
4213 myYACS->SetName( nomYACS ) ;
4215 // C. Enregistrement
4216 myStudyContext._mesYACSs[nomYACS] = myYACS;
4218 SALOMEDS::SObject_var aSO;
4219 SALOMEDS::SObject_var aResultSO=PublishInStudy(aSO, myYACS, nomYACS);
4221 PublishCaseUnderYACS(nomYACS, nomCas);
4223 // D. Caracterisation
4225 myYACS->SetDirName( DirName ) ;
4226 myYACS->SetMeshFile( MeshFile ) ;
4227 myYACS->SetScriptFile( ScriptFile ) ;
4228 myYACS->SetCaseName( nomCas ) ;
4231 // D.2.1. Type constant
4232 myYACS->SetType( 1 ) ;
4233 // D.2.2. Convergence
4234 defaut_i = GetYACSMaxIter() ;
4235 myYACS->SetMaxIter( defaut_i ) ;
4236 defaut_i = GetYACSMaxNode() ;
4237 myYACS->SetMaxNode( defaut_i ) ;
4238 defaut_i = GetYACSMaxElem() ;
4239 myYACS->SetMaxElem( defaut_i ) ;
4240 // D.3. Fichier de sauvegarde dans le répertoire du cas
4241 HOMARD::HOMARD_Cas_ptr caseyacs = GetCase(nomCas) ;
4242 std::string dirnamecase = caseyacs->GetDirName() ;
4243 std::string XMLFile ;
4244 XMLFile = dirnamecase + "/schema.xml" ;
4245 myYACS->SetXMLFile( XMLFile.c_str() ) ;
4247 return HOMARD::HOMARD_YACS::_duplicate(myYACS);
4249 //=============================================================================
4250 // Ecriture d'un schema YACS
4251 //=============================================================================
4252 CORBA::Long HOMARD_Gen_i::YACSWrite(const char* nomYACS)
4254 INFOS ( "YACSWrite : Ecriture de " << nomYACS );
4255 // Le répertoire du cas
4256 HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
4257 ASSERT(!CORBA::is_nil(myYACS));
4258 // Le nom du fichier du schema
4259 std::string XMLFile ;
4260 XMLFile = myYACS->GetXMLFile() ;
4262 int codret = YACSWriteOnFile(nomYACS, XMLFile.c_str()) ;
4266 //=============================================================================
4267 // Ecriture d'un schema YACS sur un fichier donne
4268 //=============================================================================
4269 CORBA::Long HOMARD_Gen_i::YACSWriteOnFile(const char* nomYACS, const char* XMLFile)
4271 INFOS ( "YACSWriteOnFile : Ecriture de " << nomYACS << " sur " << XMLFile );
4278 HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
4279 ASSERT(!CORBA::is_nil(myYACS));
4280 // B.2. Les caracteristiques
4281 std::string DirName = myYACS->GetDirName() ;
4282 std::string MeshFile = myYACS->GetMeshFile() ;
4283 std::string ScriptFile = myYACS->GetScriptFile() ;
4284 // B.3. Les caracteristiques de convergence
4285 int MaxIter = myYACS->GetMaxIter() ;
4286 int MaxNode = myYACS->GetMaxNode() ;
4287 int MaxElem = myYACS->GetMaxElem() ;
4291 const char* nomCas = myYACS->GetCaseName();
4292 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
4293 ASSERT(!CORBA::is_nil(myCase));
4294 // C.2. Les instructions python associees au cas
4295 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4296 std::string pythonCas = dumpCorbaCase.in();
4297 MESSAGE ("pythonCas :\n"<<pythonCas<<"\n");
4299 // D. Les iterations
4300 // D.1. L'iteration initiale
4301 HOMARD::HOMARD_Iteration_var Iter0 = myCase->GetIter0() ;
4302 std::string Iter0Name = myCase->GetIter0Name() ;
4303 MESSAGE (". Iter0Name = " << Iter0Name);
4304 std::string MeshName = Iter0->GetMeshName();
4305 MESSAGE (". MeshName = " << MeshName);
4306 // D.2. L'iteration numero 1
4307 HOMARD::listeIterFilles* maListe = Iter0->GetIterations();
4308 int numberOfIter = maListe->length();
4309 if ( numberOfIter > 1 )
4311 MESSAGE (". numberOfIter = " << numberOfIter);
4312 SALOME::ExceptionStruct es ;
4313 es.type = SALOME::BAD_PARAM;
4314 std::string text = "Une seule iteration est permise." ;
4315 es.text = CORBA::string_dup(text.c_str());
4316 throw SALOME::SALOME_Exception(es);
4319 std::string Iter1Name = std::string((*maListe)[0]);
4320 MESSAGE ("... Iter1Name = " << Iter1Name);
4321 HOMARD::HOMARD_Iteration_var Iter1 = GetIteration(Iter1Name.c_str()) ;
4322 // D.3. Les instructions python associees a l'iteration
4323 CORBA::String_var dumpCorbaIter = Iter1->GetDumpPython();
4324 std::string pythonIter = dumpCorbaIter.in();
4325 MESSAGE ("pythonIter :\n"<<pythonIter<<"\n");
4327 // E. L'hypothese pour passer de l'iteration initiale a la suivante
4328 // E.1. La structure
4329 std::string nomHypo = Iter1->GetHypoName();
4330 MESSAGE (". nomHypo = " << nomHypo);
4331 HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
4332 ASSERT(!CORBA::is_nil(myHypo));
4333 // E.2. Les caracteristiques de l'adaptation
4334 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
4335 ASSERT(ListTypes->length() == 3);
4336 int TypeAdap = (*ListTypes)[0];
4337 // int TypeRaff = (*ListTypes)[1];
4338 // int TypeDera = (*ListTypes)[2];
4339 // E.3. Les instructions python associees a l'hypothese
4340 CORBA::String_var dumpCorbaHypo = myHypo->GetDumpPython();
4341 std::string pythonHypo = dumpCorbaHypo.in();
4342 MESSAGE ("pythonHypo :\n"<<pythonHypo<<"\n");
4344 // F. Le fichier du schema de reference
4345 // HOMARD_ROOT_DIR : répertoire ou se trouve le module HOMARD
4346 std::string XMLFile_base ;
4347 if ( getenv("HOMARD_ROOT_DIR") != NULL ) { XMLFile_base = getenv("HOMARD_ROOT_DIR") ; }
4350 SALOME::ExceptionStruct es ;
4351 es.type = SALOME::BAD_PARAM;
4352 std::string text = "HOMARD_ROOT_DIR est inconnu." ;
4353 es.text = CORBA::string_dup(text.c_str());
4354 throw SALOME::SALOME_Exception(es);
4357 XMLFile_base += "/share/salome/resources/homard/yacs_01." + _LangueShort + ".xml" ;
4359 MESSAGE("XMLFile_base ="<<XMLFile_base);
4361 // G. Lecture du schema de reference et insertion des données propres au fil de la rencontre des mots-cles
4362 YACSDriver* myDriver = new YACSDriver(XMLFile, DirName, _LangueShort);
4363 std::ifstream fichier( XMLFile_base.c_str() );
4364 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
4366 // G.1. Lecture du schema de reference et insertion des données propres au fil de la rencontre des mots-cles
4367 std::string ligne; // variable contenant chaque ligne lue
4368 std::string mot_cle;
4369 while ( std::getline( fichier, ligne ) )
4371 // G.1.1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
4372 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
4373 ligne_bis >> mot_cle ;
4374 // G.1.2. Le maillage initial
4375 if ( mot_cle == "DataInit_MeshFile" )
4376 { myDriver->Texte_DataInit_MeshFile(MeshFile); }
4377 // G.1.3. Le script de lancement
4378 else if ( mot_cle == "Alternance_Calcul_HOMARD_Calcul" )
4379 { myDriver->Texte_Alternance_Calcul_HOMARD_Calcul(ScriptFile); }
4380 // G.1.4. Les options du cas
4381 else if ( mot_cle == "Iter_1_Case_Options" )
4382 { myDriver->Texte_Iter_1_Case_Options(pythonCas); }
4383 // G.1.5. Execution de HOMARD : le répertoire du cas
4384 else if ( mot_cle == "HOMARD_Exec_DirName" )
4385 { myDriver->Texte_HOMARD_Exec_DirName(); }
4386 // G.1.6. Execution de HOMARD : le nom du maillage
4387 else if ( mot_cle == "HOMARD_Exec_MeshName" )
4389 myDriver->Texte_HOMARD_Exec_MeshName(MeshName);
4391 if ( _LangueShort == "fr" ) { node = "Boucle_de_convergence.Alternance_Calcul_HOMARD" ; }
4392 else { node = "Convergence_Loop.Alternation_Computation_HOMARD" ; }
4393 node += ".Adaptation.p0_Adaptation_HOMARD.HOMARD_Initialisation.p1_Iter_1.CreateCase" ;
4394 myDriver->TexteParametre( node, "MeshName", "string", MeshName ) ;
4396 // G.1.7. Execution de HOMARD : les options de l'hypothese
4397 else if ( mot_cle == "HOMARD_Exec_Hypo_Options" )
4398 { myDriver->Texte_python_1( pythonHypo, 3, "Hypo" ) ; }
4399 // G.1.8. Execution de HOMARD : les options de l'iteration
4400 else if ( mot_cle == "HOMARD_Exec_Iter_Options" )
4401 { myDriver->Texte_python_2( pythonIter, "TimeStep", "Iter" ) ; }
4402 // G.1.9. a. Creation eventuelles des zones et frontieres
4404 else if ( mot_cle == "Iter_1" )
4406 std::string texte_control = "" ;
4407 if ( TypeAdap == 0 ) { texte_control += YACSDriverTexteZone( myHypo, myDriver ) ; }
4408 texte_control += YACSDriverTexteBoundary( myCase, myDriver ) ;
4409 texte_control += myDriver->Texte_Iter_1_control() ;
4410 myDriver->TexteAdd(texte_control);
4412 // G.1.10. Les tests de convergence
4413 else if ( mot_cle == "Analyse_Test_Convergence" )
4414 { myDriver->TexteAnalyse_Test_Convergence(MaxIter, MaxNode, MaxElem); }
4415 // G.1.11. Les parametres
4416 else if ( mot_cle == "PARAMETRES" )
4417 { myDriver->TexteAddParametres(); }
4418 // G.1.n. La ligne est recopiee telle quelle
4419 else { myDriver->TexteAdd(ligne); }
4421 // G.2. Ecriture du texte dans le fichier
4423 { myDriver->CreeFichier(); }
4427 SALOME::ExceptionStruct es;
4428 es.type = SALOME::BAD_PARAM;
4429 std::string text = "The reference file for the YACS schema cannot be read." ;
4430 es.text = CORBA::string_dup(text.c_str());
4431 throw SALOME::SALOME_Exception(es);
4436 // H. Publication du fichier dans l'arbre
4438 std::string Commentaire = "xml" ;
4439 PublishFileUnderYACS(nomYACS, XMLFile, Commentaire.c_str());
4443 //=============================================================================
4444 // Ecriture d'un schema YACS : ecriture des zones associees a une hypothese
4445 //=============================================================================
4446 std::string HOMARD_Gen_i::YACSDriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, YACSDriver* myDriver)
4448 MESSAGE ( "YACSDriverTexteZone" );
4449 // A. Les zones associees a cette hypothese
4450 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
4451 int numberOfZonesx2 = ListZone->length();
4453 // B. Parcours des zones
4454 std::string texte_control ;
4455 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
4457 // 1. Reperage de la zone
4458 std::string ZoneName = std::string((*ListZone)[iaux]);
4459 MESSAGE ( "\n. ZoneName = " << ZoneName << " - " <<iaux);
4460 HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
4461 ASSERT(!CORBA::is_nil(myZone));
4462 // 2. Les instructions python associees a la zone
4463 // La premiere ligne est un commentaire a eliminer
4464 // La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4465 CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4466 std::string pythonStructure_0 = dumpCorbaZone.in();
4467 MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4468 std::istringstream tout (pythonStructure_0) ;
4470 std::string pythonStructure ;
4471 while ( std::getline( tout, ligne ) )
4472 { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4473 MESSAGE ("pythonStructure :\n"<<pythonStructure);
4474 // 3. Decodage du nom du service
4475 std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4476 MESSAGE ( "... methode = " << methode);
4477 // 4. Mise en place des instructions
4478 int ZoneType = myZone->GetType();
4479 MESSAGE ( "... ZoneType = " << ZoneType);
4480 std::string texte_control_0 ;
4481 texte_control_0 = myDriver->Texte_Iter_1_Zone(ZoneType, pythonStructure, methode, ZoneName );
4482 texte_control += texte_control_0 ;
4487 return texte_control ;
4489 //=============================================================================
4490 // Ecriture d'un schema YACS : ecriture des frontieres associees au cas
4491 //=============================================================================
4492 std::string HOMARD_Gen_i::YACSDriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, YACSDriver* myDriver)
4494 MESSAGE ( "YACSDriverTexteBoundary" );
4495 // A. Les frontieres associees au cas
4496 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
4497 int numberOfitems = ListBoundaryGroupType->length();
4499 // B. Parcours des frontieres
4500 std::string texte_control ;
4501 std::list<std::string> ListeBoundaryTraitees ;
4502 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
4504 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
4505 MESSAGE ( "... BoundaryName = " << BoundaryName);
4506 // Attention a n'ecrire la definition qu'une seule fois car elle peut se trouver
4507 // plusieurs fois dans la definition du cas, d'ou la liste ListeBoundaryTraitees
4509 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
4510 while (it != ListeBoundaryTraitees.end())
4512 MESSAGE ( "..... BoundaryNameTraitee = " << *it);
4513 if ( BoundaryName == *it ) { A_faire = 0 ; }
4518 // 1. Caracteristiques de la frontiere
4519 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
4520 ASSERT(!CORBA::is_nil(myBoundary));
4521 // 2. Les instructions python associees a la frontiere
4522 // La premiere ligne est un commentaire a eliminer
4523 // La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4524 CORBA::String_var dumpCorbaBoundary = myBoundary->GetDumpPython();
4525 std::string pythonStructure_0 = dumpCorbaBoundary.in();
4526 MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4527 std::istringstream tout (pythonStructure_0) ;
4529 std::string pythonStructure ;
4530 while ( std::getline( tout, ligne ) )
4531 { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4532 MESSAGE ("pythonStructure :\n"<<pythonStructure);
4533 // 3. Decodage du nom du service
4534 std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4535 MESSAGE ( "... methode = " << methode);
4536 // 4. Mise en place des instructions
4537 int BoundaryType = myBoundary->GetType();
4538 MESSAGE ( "... BoundaryType = " << BoundaryType);
4539 const char* MeshName ;
4540 const char* DataFile ;
4541 if (BoundaryType == -1)
4543 DataFile = myBoundary->GetDataFile() ;
4544 MESSAGE ( ". CAOFile = " << DataFile );
4546 else if (BoundaryType == 0)
4548 MeshName = myBoundary->GetMeshName() ;
4549 MESSAGE ( ". MeshName = " << MeshName );
4550 DataFile = myBoundary->GetDataFile() ;
4551 MESSAGE ( ". MeshFile = " << DataFile );
4553 std::string texte_control_0 ;
4554 texte_control_0 = myDriver->Texte_Iter_1_Boundary(BoundaryType, pythonStructure, methode, BoundaryName, MeshName, DataFile );
4555 texte_control += texte_control_0 ;
4556 // 5. Memorisation du traitement
4557 ListeBoundaryTraitees.push_back( BoundaryName );
4561 return texte_control ;
4564 //=============================================================================
4565 //=============================================================================
4566 // Next functions are inherited from SALOMEDS::Driver interface
4567 //=============================================================================
4568 //=============================================================================
4569 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
4571 CORBA::Boolean isMultiFile)
4573 MESSAGE ("Save for theURL = "<< theURL);
4574 SALOMEDS::TMPFile_var aStreamFile;
4576 // get temporary directory name
4577 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4579 StudyContext& context = myStudyContext;
4581 // HOMARD data file name
4582 std::string aFileName = "";
4584 aFileName = SALOMEDS_Tool::GetNameFromPath(Kernel_Utils::encode(SMESH_Gen_i::getStudyServant()->URL()));
4585 aFileName += "_HOMARD.dat";
4587 // initialize sequence of file names
4588 SALOMEDS_Tool::ListOfFiles aFileSeq;
4589 aFileSeq.reserve(1);
4590 aFileSeq.push_back(CORBA::string_dup(aFileName.c_str())) ;
4592 // get full path to the data file
4593 aFileName = tmpDir + aFileName;
4597 std::ofstream f(aFileName.c_str());
4599 // clear temporary id map
4600 context._idmap.clear();
4605 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
4606 for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
4607 HOMARD::HOMARD_Cas_var aCas = it_case->second;
4608 PortableServer::ServantBase_var aServant = GetServant(aCas);
4609 HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4611 f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
4612 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
4616 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4617 for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
4618 HOMARD::HOMARD_Zone_var aZone = it_zone->second;
4619 PortableServer::ServantBase_var aServant = GetServant(aZone);
4620 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4622 f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
4623 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4626 // -> save hypotheses
4627 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4628 for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
4629 HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
4630 PortableServer::ServantBase_var aServant = GetServant(aHypo);
4631 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4633 f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
4634 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4637 // -> save iterations
4638 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4639 for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
4640 HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
4641 PortableServer::ServantBase_var aServant = GetServant(aIter);
4642 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4644 f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
4645 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4648 // -> save boundaries
4649 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4650 for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
4651 HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
4652 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4653 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4654 if (aBoundaryServant) {
4655 f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
4656 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4660 MESSAGE ("close file");
4663 // put temporary files to the stream
4664 MESSAGE ("put temporary files to the stream");
4665 aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq, isMultiFile);
4667 // remove temporary files
4668 MESSAGE ("remove temporary files");
4669 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq, true);
4671 // return data stream
4672 MESSAGE ("return data stream");
4673 return aStreamFile._retn();
4676 //===========================================================================
4677 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
4679 CORBA::Boolean isMultiFile)
4681 // No specific ASCII persistence
4682 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
4683 return aStreamFile._retn();
4686 //===========================================================================
4687 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
4688 const SALOMEDS::TMPFile& theStream,
4690 CORBA::Boolean isMultiFile)
4692 MESSAGE ("Load pour theURL = "<< theURL);
4694 // set current study
4695 if (myStudy->_is_nil())
4698 // get temporary directory name
4699 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4701 // Convert the stream into sequence of files to process
4702 SALOMEDS_Tool::ListOfFiles aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
4705 // HOMARD data file name
4706 std::string aFileName = "";
4708 aFileName = SALOMEDS_Tool::GetNameFromPath(Kernel_Utils::encode(SMESH_Gen_i::getStudyServant()->URL()));
4709 aFileName = tmpDir + aFileName + "_HOMARD.dat";
4711 StudyContext& context = myStudyContext;
4715 std::ifstream f(aFileName.c_str());
4718 context._mesCas.clear();
4719 context._mesHypotheses.clear();
4720 context._mesIterations.clear();
4721 context._mesZones.clear();
4722 context._mesBoundarys.clear();
4723 context._idmap.clear();
4729 std::getline(f, line);
4730 std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
4731 std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
4732 std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
4733 std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
4734 std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
4735 std::string yacsSignature = HOMARD::GetSignature(HOMARD::YACS);
4736 if (line.substr(0, bounSignature.size()) == bounSignature) {
4737 // re-create boundary
4738 MESSAGE ("Recreation de la frontiere" );
4739 HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
4740 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4741 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4742 if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
4743 context._mesBoundarys[aBoundary->GetName()] = aBoundary;
4744 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4747 else if (line.substr(0, caseSignature.size()) == caseSignature) {
4749 MESSAGE ("Recreation du cas" );
4750 HOMARD::HOMARD_Cas_var aCase = newCase();
4751 PortableServer::ServantBase_var aServant = GetServant(aCase);
4752 HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4753 if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
4754 context._mesCas[aCase->GetName()] = aCase;
4755 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
4758 else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
4759 // re-create hypothesis
4760 MESSAGE ("Recreation de l hypothese" );
4761 HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
4762 PortableServer::ServantBase_var aServant = GetServant(aHypo);
4763 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4764 if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
4765 context._mesHypotheses[aHypo->GetName()] = aHypo;
4766 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4769 else if (line.substr(0, iterSignature.size()) == iterSignature) {
4770 // re-create iteration
4771 MESSAGE ("Recreation de l'iteration" );
4772 HOMARD::HOMARD_Iteration_var aIter = newIteration();
4773 PortableServer::ServantBase_var aServant = GetServant(aIter);
4774 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4775 if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
4776 context._mesIterations[aIter->GetName()] = aIter;
4777 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4780 else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
4781 MESSAGE ("Recreation de la zone" );
4783 HOMARD::HOMARD_Zone_var aZone = newZone();
4784 PortableServer::ServantBase_var aServant = GetServant(aZone);
4785 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4786 if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
4787 context._mesZones[aZone->GetName()] = aZone;
4788 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4791 else if (line.substr(0, zoneSignature.size()) == yacsSignature) {
4792 MESSAGE ("Recreation du schema YACS" );
4794 HOMARD::HOMARD_YACS_var aYACS = newYACS();
4795 PortableServer::ServantBase_var aServant = GetServant(aYACS);
4796 HOMARD_YACS_i* aYACSServant = dynamic_cast<HOMARD_YACS_i*>(aServant.in());
4797 if (aYACSServant && aYACSServant->Restore(line.substr(yacsSignature.size()))) {
4798 context._mesYACSs[aYACS->GetName()] = aYACS;
4799 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aYACSServant);
4808 // Remove temporary files created from the stream
4810 SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq, true);
4815 //===========================================================================
4816 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
4817 const SALOMEDS::TMPFile& theStream,
4819 CORBA::Boolean isMultiFile)
4821 // No specific ASCII persistence
4822 return Load(theComponent, theStream, theURL, isMultiFile);
4825 //===========================================================================
4826 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
4830 //===========================================================================
4831 char* HOMARD_Gen_i::ComponentDataType()
4833 return CORBA::string_dup("HOMARD");
4836 //===========================================================================
4837 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
4838 const char* IORString,
4839 CORBA::Boolean isMultiFile,
4840 CORBA::Boolean isASCII)
4842 CORBA::String_var aString("");
4843 if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
4844 StudyContext context = myStudyContext;
4845 CORBA::Object_var anObj = _orb->string_to_object(IORString);
4846 if (!CORBA::is_nil(anObj)) {
4847 PortableServer::ServantBase_var aServant = GetServant(anObj);
4848 PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
4850 std::map<int, PortableServer::ServantBase*>::const_iterator it;
4851 for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
4852 if (it->second == aStorable) {
4853 std::stringstream os;
4855 aString = CORBA::string_dup(os.str().c_str());
4861 return aString._retn();
4864 //===========================================================================
4865 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
4866 const char* aLocalPersistentID,
4867 CORBA::Boolean isMultiFile,
4868 CORBA::Boolean isASCII)
4870 CORBA::String_var aString("");
4871 if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
4872 StudyContext context = myStudyContext;
4873 int id = atoi(aLocalPersistentID);
4874 if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
4875 CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
4876 if (!CORBA::is_nil(object)) {
4877 aString = _orb->object_to_string(object);
4881 return aString._retn();
4884 //===========================================================================
4885 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
4887 if(CORBA::is_nil(myStudy))
4890 HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
4891 if(!aCas->_is_nil())
4894 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
4895 if(!aHypo->_is_nil())
4898 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
4899 if(!aZone->_is_nil())
4902 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
4903 if(!aBoundary->_is_nil())
4906 /* Iteration is not published directly
4907 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
4908 if(!aIter->_is_nil())
4914 //===========================================================================
4915 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
4917 // No Copy/Paste support
4921 //===========================================================================
4922 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
4923 CORBA::Long& theObjectID)
4925 // No Copy/Paste support
4926 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
4927 return aStreamFile._retn();
4930 //===========================================================================
4931 CORBA::Boolean HOMARD_Gen_i::CanPaste(const char *theComponentName,
4932 CORBA::Long theObjectID)
4934 // No Copy/Paste support
4938 //===========================================================================
4939 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
4940 CORBA::Long theObjectID,
4941 SALOMEDS::SObject_ptr theSObject)
4943 // No Copy/Paste support
4944 SALOMEDS::SObject_var aResultSO;
4945 return aResultSO._retn();
4948 //===========================================================================
4949 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
4951 PortableServer::Servant aServant = 0;
4952 if (!CORBA::is_nil(theObject)) {
4954 aServant = _poa->reference_to_servant(theObject);
4962 //==========================================================================
4963 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Boolean isPublished,
4964 CORBA::Boolean isMultiFile,
4965 CORBA::Boolean& isValidScript)
4967 MESSAGE ("Entree dans DumpPython");
4970 SALOMEDS::SObject_var aSO = SMESH_Gen_i::getStudyServant()->FindComponent("HOMARD");
4971 if(CORBA::is_nil(aSO))
4972 return new Engines::TMPFile(0);
4974 std::string aScript = "\"\"\"\n";
4975 aScript += "Python script for HOMARD\n";
4976 aScript += "Copyright 1996, 2011, 2015 EDF\n";
4977 aScript += "\"\"\"\n";
4978 aScript += "__revision__ = \"V1.2\"\n";
4979 aScript += "import HOMARD\n";
4981 aScript += "import salome\n";
4982 aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
4983 aScript += "\thomard.UpdateStudy()\n";
4984 MESSAGE (". Au depart \n"<<aScript);
4987 if (myStudyContext._mesBoundarys.size() > 0)
4989 MESSAGE (". Ecritures des frontieres");
4990 aScript += "#\n# Creation of the boundaries";
4991 aScript += "\n# ==========================";
4993 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4994 for (it_boundary = myStudyContext._mesBoundarys.begin();
4995 it_boundary != myStudyContext._mesBoundarys.end(); ++it_boundary)
4997 HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
4998 CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
4999 std::string dumpBoundary = dumpCorbaBoundary.in();
5000 MESSAGE (dumpBoundary<<"\n");
5001 aScript += dumpBoundary;
5005 if (myStudyContext._mesZones.size() > 0)
5007 MESSAGE (". Ecritures des zones");
5008 aScript += "#\n# Creation of the zones";
5009 aScript += "\n# =====================";
5011 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
5012 for ( it_zone = myStudyContext._mesZones.begin();
5013 it_zone != myStudyContext._mesZones.end(); ++it_zone)
5015 HOMARD::HOMARD_Zone_var myZone = (*it_zone).second;
5016 CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
5017 std::string dumpZone = dumpCorbaZone.in();
5018 MESSAGE (dumpZone<<"\n");
5019 aScript += dumpZone;
5023 if (myStudyContext._mesHypotheses.size() > 0)
5025 MESSAGE (". Ecritures des hypotheses");
5026 aScript += "#\n# Creation of the hypotheses";
5027 aScript += "\n# ==========================";
5029 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
5030 for ( it_hypo = myStudyContext._mesHypotheses.begin();
5031 it_hypo != myStudyContext._mesHypotheses.end(); it_hypo++)
5033 HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
5034 CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
5035 std::string dumpHypo = dumpCorbaHypo.in();
5036 MESSAGE (dumpHypo<<"\n");
5037 aScript += dumpHypo;
5041 if (myStudyContext._mesCas.size() > 0)
5043 MESSAGE (". Ecritures des cas");
5044 aScript += "#\n# Creation of the cases";
5045 aScript += "\n# =====================";
5047 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
5048 for (it_cas = myStudyContext._mesCas.begin();
5049 it_cas != myStudyContext._mesCas.end(); it_cas++)
5051 std::string nomCas = (*it_cas).first;
5052 std::string dumpCas = std::string("\n# Creation of the case ") ;
5053 dumpCas += nomCas + std::string("\n");
5054 dumpCas += std::string("\t") + nomCas;
5055 dumpCas += std::string(" = homard.CreateCase(\"") + nomCas + std::string("\", \"");
5057 HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
5058 CORBA::String_var cIter0= myCase->GetIter0Name();
5059 std::string iter0 = cIter0.in();
5061 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[iter0];
5062 CORBA::String_var cMesh0= myIteration->GetMeshFile();
5063 std::string mesh0 = cMesh0.in();
5064 CORBA::String_var cMeshName0= myIteration->GetMeshName();
5065 std::string meshName0 = cMeshName0.in();
5066 dumpCas += meshName0 + std::string("\", \"")+ mesh0 + std::string("\")\n");
5067 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
5068 std::string dumpCas2= dumpCorbaCase.in();
5070 MESSAGE (dumpCas<<dumpCas2<<"\n");
5071 aScript += dumpCas + dumpCas2;
5075 if (myStudyContext._mesIterations.size() > 0)
5077 MESSAGE (". Ecritures des iterations");
5078 aScript += "#\n# Creation of the iterations" ;
5079 aScript += "\n# ==========================";
5081 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
5082 for (it_iter = myStudyContext._mesIterations.begin();
5083 it_iter != myStudyContext._mesIterations.end(); ++it_iter)
5085 HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
5086 CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
5087 std::string dumpIter = dumpCorbaIter.in();
5088 MESSAGE (dumpIter<<"\n");
5089 aScript += dumpIter;
5093 if (myStudyContext._mesYACSs.size() > 0)
5095 MESSAGE (". Ecritures des schemas YACS");
5096 aScript += "#\n# Creation of the schemas YACS";
5097 aScript += "\n# ============================";
5099 std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it_yacs;
5100 for ( it_yacs = myStudyContext._mesYACSs.begin();
5101 it_yacs != myStudyContext._mesYACSs.end(); ++it_yacs)
5103 HOMARD::HOMARD_YACS_var myYACS = (*it_yacs).second;
5104 CORBA::String_var dumpCorbaYACS = myYACS->GetDumpPython();
5105 std::string dumpYACS = dumpCorbaYACS.in();
5106 MESSAGE (dumpYACS<<"\n");
5107 aScript += dumpYACS;
5110 MESSAGE (". Ecritures finales");
5112 aScript += "\n\tpass";
5115 if( !isMultiFile ) // remove unnecessary tabulation
5116 aScript = RemoveTabulation( aScript );
5118 // MESSAGE ("A ecrire \n"<<aScript);
5119 const size_t aLen = strlen(aScript.c_str());
5120 char* aBuffer = new char[aLen+1];
5121 strcpy(aBuffer, aScript.c_str());
5123 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
5124 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
5126 MESSAGE ("Sortie de DumpPython");
5127 return aStreamFile._retn();
5131 //=============================================================================
5132 //=============================================================================
5134 //=============================================================================
5135 //=============================================================================
5136 void HOMARD_Gen_i::IsValidStudy( )
5138 // MESSAGE( "IsValidStudy" );
5139 if (CORBA::is_nil(SMESH_Gen_i::getStudyServant()))
5141 SALOME::ExceptionStruct es;
5142 es.type = SALOME::BAD_PARAM;
5143 es.text = "Invalid study context";
5144 throw SALOME::SALOME_Exception(es);
5149 //=============================================================================
5150 char* HOMARD_Gen_i::VerifieDir(const char* nomDir)
5152 std::string casename = std::string("") ;
5153 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
5154 for (it = myStudyContext._mesCas.begin();
5155 it != myStudyContext._mesCas.end(); it++)
5157 if (std::string(nomDir) == std::string(it->second->GetDirName()))
5159 casename = std::string(it->second->GetName()) ;
5163 return CORBA::string_dup( casename.c_str() );
5165 /*//=============================================================================
5166 void SALOMEException( std::string message )
5168 SALOME::ExceptionStruct es;
5169 es.type = SALOME::BAD_PARAM;
5171 throw SALOME::SALOME_Exception(es);
5174 //=============================================================================
5175 char* HOMARD_Gen_i::getVersion()
5177 #if HOMARD_DEVELOPMENT
5178 return CORBA::string_dup(HOMARD_VERSION_STR"dev");
5180 return CORBA::string_dup(HOMARD_VERSION_STR);
5183 //===============================================================================
5184 // Recuperation de la chaine de caracteres par rapport a l'apparition d'un caractere
5185 // ligne : la ligne a manipuler
5186 // caractere : le caractere a reperer
5187 // option : 0 : la chaine avant la premiere apparition du caractere
5188 // 1 : la chaine apres la premiere apparition du caractere
5189 // 2 : la chaine avant la derniere apparition du caractere
5190 // 3 : la chaine apres la derniere apparition du caractere
5191 // Si le caractere est absent, on retourne la chaine totale
5192 //===============================================================================
5193 std::string HOMARD_Gen_i::GetStringInTexte( const std::string ligne, const std::string caractere, int option )
5195 // MESSAGE("GetStringInTexte, recherche de '"<<caractere<<"' dans '"<<ligne<<"'"<<", option = "<<option);
5197 std::string chaine = ligne ;
5199 if ( option < 2 ) { position = ligne.find_first_of( caractere ) ; }
5200 else { position = ligne.find_last_of( caractere ) ; }
5201 // MESSAGE("position = "<<position);
5202 // MESSAGE("a = "<<ligne.substr( 0, position ).c_str());
5203 // MESSAGE("b = "<<ligne.substr( position+1 ).c_str());
5205 if ( position != std::string::npos )
5207 if ( ( option == 0 ) || ( option == 2 ) ) { chaine = ligne.substr( 0, position ) ; }
5208 else { chaine = ligne.substr( position+1 ) ; }
5213 //=============================================================================
5214 //=============================================================================
5215 // Gestion des preferences
5216 //=============================================================================
5217 //=============================================================================
5218 // Decodage du fichier d'arcihvage des preferences
5220 void HOMARD_Gen_i::SetPreferences( )
5222 MESSAGE ( "SetPreferences" );
5224 std::string ligne, mot_cle, salome_version ;
5227 // A. Les valeurs par defaut ; elles doivent etre coherentes
5228 std::string LanguageShort = "en" ;
5229 int PublisMeshIN = 0 ;
5230 int PublisMeshOUT = 0 ;
5231 int YACSMaxIter = 0 ;
5232 int YACSMaxNode = 0 ;
5233 int YACSMaxElem = 0 ;
5234 std::string YACSTypeTestchaine = "None" ;
5236 // B. La version de salome
5237 // Cela se presente sous la forme :
5238 // [SALOME KERNEL] : 7.3.0
5240 File = getenv("KERNEL_ROOT_DIR") ;
5241 File += "/bin/salome/VERSION" ;
5242 MESSAGE ( "File = "<<File ) ;
5243 std::ifstream fichier0( File.c_str() ) ;
5244 if ( fichier0 ) // ce test échoue si le fichier n'est pas ouvert
5246 std::string ligne; // variable contenant chaque ligne lue
5247 while ( std::getline( fichier0, ligne ) )
5249 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
5250 ligne_bis >> mot_cle ;
5251 if ( mot_cle == "[SALOME" )
5253 salome_version = GetStringInTexte ( ligne, " ", 3 ) ;
5254 // MESSAGE ( "salome_version = "<<salome_version<<"|||");
5259 else { ok = false ; }
5261 // B. Decodage du fichier de preferences
5264 std::string PrefFile ;
5265 PrefFile = Kernel_Utils::HomePath() ;
5266 PrefFile += "/.config/salome/SalomeApprc." + salome_version ;
5267 MESSAGE ( "PrefFile = "<<PrefFile ) ;
5269 std::ifstream fichier( PrefFile.c_str() );
5270 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
5272 bool section_langue = false ;
5273 bool section_homard = false ;
5274 while ( std::getline( fichier, ligne ) )
5276 std::string chaine ;
5277 // 1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
5278 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
5279 ligne_bis >> mot_cle ;
5282 // 2.1. Debut d'une section
5283 // MESSAGE(mot_cle);
5284 if ( mot_cle == "<section" )
5285 { /*MESSAGE ( "Debut de la section : "<< ligne);*/
5286 ligne_bis >> mot_cle ;
5287 chaine = GetStringInTexte ( mot_cle, "\"", 1 ) ;
5288 chaine = GetStringInTexte ( chaine, "\"", 0 ) ;
5289 if ( chaine == "language" ) { section_langue = true ; }
5290 if ( chaine == "HOMARD" ) { section_homard = true ; }
5291 // MESSAGE ( "section_langue = "<<section_langue<<", section_homard = "<<section_homard);
5293 // 2.2. Fin d'une section
5294 else if ( mot_cle == "</section>" )
5295 { /*MESSAGE ( "Fin de la section : "<< ligne<<", section_langue = "<<section_langue<<", section_homard = "<<section_homard);*/
5296 section_langue = false ;
5297 section_homard = false ; }
5301 else if ( section_langue || section_homard )
5302 { MESSAGE ( "a decoder : "<< ligne);
5303 // La valeur : entre les deux premieres quotes
5304 chaine = GetStringInTexte ( ligne, "\"", 1 ) ;
5305 // MESSAGE("chaine 1 = |"<<chaine<<"|");
5306 chaine = GetStringInTexte ( chaine, "\"", 0 ) ;
5307 // MESSAGE("chaine = |"<<chaine<<"|");
5308 // Le mot_cle : entre les deux dernieres quotes
5309 std::string chaine2 = GetStringInTexte ( ligne, "\"", 2 ) ;
5310 // MESSAGE("chaine2 1 = |"<<chaine2<<"|");
5311 chaine2 = GetStringInTexte ( chaine2, "\"", 3 ) ;
5312 // MESSAGE("chaine2 = |"<<chaine2<<"|");
5314 if ( section_langue )
5315 { if ( chaine2 == "language" ) { LanguageShort = chaine ; } }
5317 if ( section_homard )
5319 std::istringstream chainebis( chaine ) ;
5320 // 3.2.1. Les publications
5321 if ( chaine2 == "publish_mesh_in" ) { chainebis >> PublisMeshIN ; }
5322 if ( chaine2 == "publish_mesh_out" ) { chainebis >> PublisMeshOUT ; }
5323 // 3.2.2. Les maximum pour YACS
5324 if ( chaine2 == "yacs_max_iter" ) { chainebis >> YACSMaxIter ; }
5325 if ( chaine2 == "yacs_max_node" ) { chainebis >> YACSMaxNode ; }
5326 if ( chaine2 == "yacs_max_elem" ) { chainebis >> YACSMaxElem ; }
5327 if ( chaine2 == "yacs_type_test" ) { YACSTypeTestchaine = chaine ; }
5334 // C. Enregistrements
5335 MESSAGE ("Enregistrement de LanguageShort = " << LanguageShort );
5336 SetLanguageShort( LanguageShort.c_str() ) ;
5338 MESSAGE ("Enregistrement de PublisMeshIN = " << PublisMeshIN<<", PublisMeshOUT = "<< PublisMeshOUT);
5339 SetPublisMesh(PublisMeshIN, PublisMeshOUT) ;
5341 MESSAGE ("Enregistrement de YACSMaxIter = " << YACSMaxIter<<", YACSMaxNode = "<< YACSMaxNode<<", YACSMaxElem = "<< YACSMaxElem);
5342 SetYACSMaximum(YACSMaxIter, YACSMaxNode, YACSMaxElem) ;
5344 MESSAGE ("Enregistrement de TypeTest = " << YACSTypeTestchaine.c_str() );
5346 if ( ( YACSTypeTestchaine == "VTest > VRef" ) || ( YACSTypeTestchaine == "VTest > VRef" ) ) { YACSTypeTest = 1 ; }
5347 else if ( ( YACSTypeTestchaine == "VTest < VRef" ) || ( YACSTypeTestchaine == "VTest < VRef" ) ) { YACSTypeTest = 2 ; }
5348 else { YACSTypeTest = 0 ; }
5349 MESSAGE ("==> TypeTest = " << YACSTypeTest );
5350 SetYACSConvergenceType( YACSTypeTest ) ;
5354 //===============================================================================
5356 //===============================================================================
5357 void HOMARD_Gen_i::SetLanguageShort(const char* LanguageShort)
5359 // MESSAGE ("SetLanguageShort pour LanguageShort = " << LanguageShort );
5360 _LangueShort = LanguageShort ;
5361 if ( _LangueShort == "fr" ) { _Langue = "Francais" ; }
5362 else { _Langue = "English" ; }
5365 char* HOMARD_Gen_i::GetLanguageShort()
5367 // MESSAGE ("GetLanguageShort");
5368 return CORBA::string_dup( _LangueShort.c_str() );
5370 //===============================================================================
5371 // Options de publications
5372 //===============================================================================
5373 void HOMARD_Gen_i::SetPublisMesh(CORBA::Long PublisMeshIN, CORBA::Long PublisMeshOUT)
5375 _PublisMeshIN = PublisMeshIN ;
5376 _PublisMeshOUT = PublisMeshOUT ;
5379 CORBA::Long HOMARD_Gen_i::GetPublisMeshIN()
5381 return _PublisMeshIN ;
5383 CORBA::Long HOMARD_Gen_i::GetPublisMeshOUT()
5385 return _PublisMeshOUT ;
5387 //===============================================================================
5388 // YACS - test de convergence
5389 //===============================================================================
5390 void HOMARD_Gen_i::SetYACSMaximum(CORBA::Long YACSMaxIter, CORBA::Long YACSMaxNode, CORBA::Long YACSMaxElem)
5392 _YACSMaxIter = YACSMaxIter ;
5393 _YACSMaxNode = YACSMaxNode ;
5394 _YACSMaxElem = YACSMaxElem ;
5397 CORBA::Long HOMARD_Gen_i::GetYACSMaxIter()
5399 return _YACSMaxIter ;
5401 CORBA::Long HOMARD_Gen_i::GetYACSMaxNode()
5403 return _YACSMaxNode ;
5405 CORBA::Long HOMARD_Gen_i::GetYACSMaxElem()
5407 return _YACSMaxElem ;
5409 void HOMARD_Gen_i::SetYACSConvergenceType(CORBA::Long YACSTypeTest)
5411 _YACSTypeTest = YACSTypeTest ;
5414 CORBA::Long HOMARD_Gen_i::GetYACSConvergenceType()
5416 return _YACSTypeTest ;
5419 //=============================================================================
5423 PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
5424 PortableServer::POA_ptr poa,
5425 PortableServer::ObjectId* contId,
5426 const char* instanceName,
5427 const char* interfaceName)
5429 MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
5430 HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
5431 return myHOMARD_Gen->getId();